Re: [PATCH v5 2/4] KVM: x86/mmu: use gfn_to_pfn_page

From: Sean Christopherson
Date: Thu Dec 30 2021 - 14:31:03 EST


On Mon, Nov 29, 2021, David Stevens wrote:
> From: David Stevens <stevensd@xxxxxxxxxxxx>
>
> Covert usages of the deprecated gfn_to_pfn functions to the new
> gfn_to_pfn_page functions.
>
> Signed-off-by: David Stevens <stevensd@xxxxxxxxxxxx>
> ---
> arch/x86/kvm/mmu.h | 1 +
> arch/x86/kvm/mmu/mmu.c | 18 +++++++++++-------
> arch/x86/kvm/mmu/paging_tmpl.h | 9 ++++++---
> arch/x86/kvm/x86.c | 6 ++++--
> 4 files changed, 22 insertions(+), 12 deletions(-)
>
> diff --git a/arch/x86/kvm/mmu.h b/arch/x86/kvm/mmu.h
> index 9ae6168d381e..97d94a9612b6 100644
> --- a/arch/x86/kvm/mmu.h
> +++ b/arch/x86/kvm/mmu.h
> @@ -164,6 +164,7 @@ struct kvm_page_fault {
> /* Outputs of kvm_faultin_pfn. */
> kvm_pfn_t pfn;
> hva_t hva;
> + struct page *page;
> bool map_writable;
> };
>
> diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
> index 04c00c34517e..0626395ff1d9 100644
> --- a/arch/x86/kvm/mmu/mmu.c
> +++ b/arch/x86/kvm/mmu/mmu.c
> @@ -2891,6 +2891,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) || kvm_is_reserved_pfn(fault->pfn))

These two checks can go away as they're made obsolete by the new !fault->page check.

> return;
>