]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
KVM: Update gfn_to_pfn_cache khva when it moves within the same page
authorDavid Woodhouse <dwmw@amazon.co.uk>
Sat, 19 Nov 2022 09:25:39 +0000 (09:25 +0000)
committerDavid Woodhouse <dwmw@amazon.co.uk>
Mon, 21 Nov 2022 12:21:51 +0000 (12:21 +0000)
In the case where a GPC is refreshed to a different location within the
same page, we didn't bother to update it. Mostly we don't need to, but
since the ->khva field also includes the offset within the page, that
does have to be updated.

Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
Reviewed-by: <paul@xen.org>
Cc: stable@kernel.org
virt/kvm/pfncache.c

index bd4a46aee384bba3eb90ff5d88c9e962621ca29e..5f83321bfd2a03bc424b9122f2ccd784ab67a110 100644 (file)
@@ -297,7 +297,12 @@ int kvm_gfn_to_pfn_cache_refresh(struct kvm *kvm, struct gfn_to_pfn_cache *gpc,
        if (!gpc->valid || old_uhva != gpc->uhva) {
                ret = hva_to_pfn_retry(kvm, gpc);
        } else {
-               /* If the HVA→PFN mapping was already valid, don't unmap it. */
+               /*
+                * If the HVA→PFN mapping was already valid, don't unmap it.
+                * But do update gpc->khva because the offset within the page
+                * may have changed.
+                */
+               gpc->khva = old_khva + page_offset;
                old_pfn = KVM_PFN_ERR_FAULT;
                old_khva = NULL;
                ret = 0;