[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <04530097-a3b2-4acf-bf41-fba48143d4e1@xen.org>
Date: Wed, 22 Nov 2023 09:29:46 +0000
From: Paul Durrant <xadimgnik@...il.com>
To: David Woodhouse <dwmw2@...radead.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 21/11/2023 22:35, David Woodhouse wrote:
> 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))
True; I can keep that optimization and then I will indeed add 'no
functional change'... Didn't seem worth it at the time, but no harm.
>> + 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>
Thanks,
Paul
Powered by blists - more mailing lists