lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Tue, 21 Nov 2023 22:35:42 +0000
From:   David Woodhouse <dwmw2@...radead.org>
To:     Paul Durrant <paul@....org>,
        Sean Christopherson <seanjc@...gle.com>,
        Paolo Bonzini <pbonzini@...hat.com>,
        Thomas Gleixner <tglx@...utronix.de>,
        Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
        Dave Hansen <dave.hansen@...ux.intel.com>, x86@...nel.org,
        "H. Peter Anvin" <hpa@...or.com>, kvm@...r.kernel.org,
        linux-kernel@...r.kernel.org
Subject: Re: [PATCH v8 07/15] KVM: pfncache: include page offset in uhva and
 use it consistently

On Tue, 2023-11-21 at 18:02 +0000, Paul Durrant wrote:
> @@ -242,8 +242,7 @@ static int __kvm_gpc_refresh(struct gfn_to_pfn_cache *gpc, gpa_t gpa,
>         }
>  
>         old_pfn = gpc->pfn;
> -       old_khva = gpc->khva - offset_in_page(gpc->khva);
> -       old_uhva = gpc->uhva;
> +       old_khva = (void *)PAGE_ALIGN_DOWN((uintptr_t)gpc->khva);
>  
>         /* If the userspace HVA is invalid, refresh that first */
>         if (gpc->gpa != gpa || gpc->generation != slots->generation ||
> @@ -259,13 +258,25 @@ static int __kvm_gpc_refresh(struct gfn_to_pfn_cache *gpc, gpa_t gpa,
>                         ret = -EFAULT;
>                         goto out;
>                 }


There's a subtle behaviour change here, isn't there? I'd *really* like
you do say 'No functional change intended' where that is true, and then
the absence of that sentence in this one would be meaningful.

You are now calling hva_to_pfn_retry() even when the uhva page hasn't
changed. Which is harmless and probably not important, but IIUC fixable
by the addition of:

 +              if (gpc->uhva != PAGE_ALIGN_DOWN(old_uhva)) 
> +               hva_change = true;
> +       } else {
> +               /*
> +                * No need to do any re-mapping if the only thing that has
> +                * changed is the page offset. Just page align it to allow the
> +                * new offset to be added in.
> +                */
> +               gpc->uhva = PAGE_ALIGN_DOWN(gpc->uhva);
>         }
>  
> +       /* Note: the offset must be correct before calling hva_to_pfn_retry() */
> +       gpc->uhva += page_offset;
> +
>         /*
>          * If the userspace HVA changed or the PFN was already invalid,
>          * drop the lock and do the HVA to PFN lookup again.
>          */
> -       if (!gpc->valid || old_uhva != gpc->uhva) {
> +       if (!gpc->valid || hva_change) {
>                 ret = hva_to_pfn_retry(gpc);
>         } else {
>                 /*
> -- 

But I don't really think it's that important if you can come up with a
coherent justification for the change and note it in the commit
message. So either way:

Reviewed-by: David Woodhouse <dwmw@...zon.co.uk>

Download attachment "smime.p7s" of type "application/pkcs7-signature" (5965 bytes)

Powered by blists - more mailing lists