| From c5fc9c5a2902b3ad44cc6a58260a4a1d12deb59b Mon Sep 17 00:00:00 2001 |
| From: David Stevens <stevensd@chromium.org> |
| Date: Mon, 29 Nov 2021 12:43:15 +0900 |
| Subject: [PATCH] CHROMIUM: KVM: x86/mmu: use gfn_to_pfn_page |
| |
| Covert usages of the deprecated gfn_to_pfn functions to the new |
| gfn_to_pfn_page functions. |
| |
| Signed-off-by: David Stevens <stevensd@chromium.org> |
| Change-Id: I79889b0f4ad402969b77f36aab2e087c7366d6de |
| |
| [rebase61(tzungbi): |
| Pre-pended "CHROMIUM" prefix. The FROMLIST version from |
| https://patchwork.kernel.org/project/kvm/patch/20211129034317.2964790-3-stevensd@google.com/ |
| conflicted with v6.1. See also b/260366568#comment4. |
| ] |
| Signed-off-by: Tzung-Bi Shih <tzungbi@chromium.org> |
| --- |
| arch/x86/kvm/mmu/mmu.c | 19 ++++++++++++------- |
| arch/x86/kvm/mmu/mmu_internal.h | 1 + |
| arch/x86/kvm/mmu/paging_tmpl.h | 9 ++++++--- |
| arch/x86/kvm/x86.c | 6 ++++-- |
| 4 files changed, 23 insertions(+), 12 deletions(-) |
| |
| diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c |
| index fd04a0c4e6de73877dc8c241c08a26ad78730a64..ef2679ca95076418b23c715b57cdfcd64745bdbe 100644 |
| --- a/arch/x86/kvm/mmu/mmu.c |
| +++ b/arch/x86/kvm/mmu/mmu.c |
| @@ -3104,6 +3104,9 @@ void kvm_mmu_hugepage_adjust(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault |
| if (unlikely(fault->max_level == PG_LEVEL_4K)) |
| return; |
| |
| + if (!fault->page) |
| + return; |
| + |
| if (is_error_noslot_pfn(fault->pfn)) |
| return; |
| |
| @@ -4229,9 +4232,9 @@ static int __kvm_faultin_pfn(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault |
| } |
| |
| async = false; |
| - fault->pfn = __gfn_to_pfn_memslot(slot, fault->gfn, false, false, &async, |
| - fault->write, &fault->map_writable, |
| - &fault->hva); |
| + fault->pfn = __gfn_to_pfn_page_memslot(slot, fault->gfn, false, false, &async, |
| + fault->write, &fault->map_writable, |
| + &fault->hva, &fault->page); |
| if (!async) |
| return RET_PF_CONTINUE; /* *pfn has correct page already */ |
| |
| @@ -4251,9 +4254,10 @@ static int __kvm_faultin_pfn(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault |
| * to wait for IO. Note, gup always bails if it is unable to quickly |
| * get a page and a fatal signal, i.e. SIGKILL, is pending. |
| */ |
| - fault->pfn = __gfn_to_pfn_memslot(slot, fault->gfn, false, true, NULL, |
| - fault->write, &fault->map_writable, |
| - &fault->hva); |
| + fault->pfn = __gfn_to_pfn_page_memslot(slot, fault->gfn, false, |
| + false, NULL, fault->write, |
| + &fault->map_writable, |
| + &fault->hva, &fault->page); |
| return RET_PF_CONTINUE; |
| } |
| |
| @@ -4339,7 +4343,8 @@ static int direct_page_fault(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault |
| |
| out_unlock: |
| write_unlock(&vcpu->kvm->mmu_lock); |
| - kvm_release_pfn_clean(fault->pfn); |
| + if (fault->page) |
| + put_page(fault->page); |
| return r; |
| } |
| |
| diff --git a/arch/x86/kvm/mmu/mmu_internal.h b/arch/x86/kvm/mmu/mmu_internal.h |
| index cc58631e233682c103a1549f6a79b4e50d01222e..f1d726f3efab94a0f2ec5081b2cd06ced1edf7bb 100644 |
| --- a/arch/x86/kvm/mmu/mmu_internal.h |
| +++ b/arch/x86/kvm/mmu/mmu_internal.h |
| @@ -239,6 +239,7 @@ struct kvm_page_fault { |
| unsigned long mmu_seq; |
| kvm_pfn_t pfn; |
| hva_t hva; |
| + struct page *page; |
| bool map_writable; |
| }; |
| |
| diff --git a/arch/x86/kvm/mmu/paging_tmpl.h b/arch/x86/kvm/mmu/paging_tmpl.h |
| index 57f0b75c80f9d52a8d0401e8ebadb39f2d6d1283..ae1e1ad2e3a6c794699f0ad0bed4fdc63b59835f 100644 |
| --- a/arch/x86/kvm/mmu/paging_tmpl.h |
| +++ b/arch/x86/kvm/mmu/paging_tmpl.h |
| @@ -525,6 +525,7 @@ FNAME(prefetch_gpte)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp, |
| unsigned pte_access; |
| gfn_t gfn; |
| kvm_pfn_t pfn; |
| + struct page *page; |
| |
| if (FNAME(prefetch_invalid_gpte)(vcpu, sp, spte, gpte)) |
| return false; |
| @@ -540,12 +541,13 @@ FNAME(prefetch_gpte)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp, |
| if (!slot) |
| return false; |
| |
| - pfn = gfn_to_pfn_memslot_atomic(slot, gfn); |
| + pfn = gfn_to_pfn_page_memslot_atomic(slot, gfn, &page); |
| if (is_error_pfn(pfn)) |
| return false; |
| |
| mmu_set_spte(vcpu, slot, spte, pte_access, gfn, pfn, NULL); |
| - kvm_release_pfn_clean(pfn); |
| + if (page) |
| + put_page(page); |
| return true; |
| } |
| |
| @@ -871,7 +873,8 @@ static int FNAME(page_fault)(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault |
| |
| out_unlock: |
| write_unlock(&vcpu->kvm->mmu_lock); |
| - kvm_release_pfn_clean(fault->pfn); |
| + if (fault->page) |
| + put_page(fault->page); |
| return r; |
| } |
| |
| diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c |
| index 99f5809c96b7917728bd26695e430dd0109ac89f..8012889278f3f1633a76236fe900e0d10cec7c65 100644 |
| --- a/arch/x86/kvm/x86.c |
| +++ b/arch/x86/kvm/x86.c |
| @@ -8476,6 +8476,7 @@ static bool reexecute_instruction(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa, |
| { |
| gpa_t gpa = cr2_or_gpa; |
| kvm_pfn_t pfn; |
| + struct page *page; |
| |
| if (!(emulation_type & EMULTYPE_ALLOW_RETRY_PF)) |
| return false; |
| @@ -8505,7 +8506,7 @@ static bool reexecute_instruction(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa, |
| * retry instruction -> write #PF -> emulation fail -> retry |
| * instruction -> ... |
| */ |
| - pfn = gfn_to_pfn(vcpu->kvm, gpa_to_gfn(gpa)); |
| + pfn = gfn_to_pfn_page(vcpu->kvm, gpa_to_gfn(gpa), &page); |
| |
| /* |
| * If the instruction failed on the error pfn, it can not be fixed, |
| @@ -8514,7 +8515,8 @@ static bool reexecute_instruction(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa, |
| if (is_error_noslot_pfn(pfn)) |
| return false; |
| |
| - kvm_release_pfn_clean(pfn); |
| + if (page) |
| + put_page(page); |
| |
| /* The instructions are well-emulated on direct mmu. */ |
| if (vcpu->arch.mmu->root_role.direct) { |
| -- |
| 2.38.3 |
| |