All of lore.kernel.org
 help / color / mirror / Atom feed
From: Isaku Yamahata <isaku.yamahata@intel.com>
To: Sean Christopherson <seanjc@google.com>
Cc: isaku.yamahata@intel.com, kvm@vger.kernel.org,
	isaku.yamahata@gmail.com, linux-kernel@vger.kernel.org,
	Paolo Bonzini <pbonzini@redhat.com>,
	Michael Roth <michael.roth@amd.com>,
	David Matlack <dmatlack@google.com>,
	Federico Parola <federico.parola@polito.it>,
	isaku.yamahata@linux.intel.com
Subject: Re: [RFC PATCH 3/8] KVM: x86/mmu: Introduce initialier macro for struct kvm_page_fault
Date: Mon, 11 Mar 2024 15:56:11 -0700	[thread overview]
Message-ID: <20240311225611.GB935089@ls.amr.corp.intel.com> (raw)
In-Reply-To: <Ze8-YlvprcKou-Ho@google.com>

On Mon, Mar 11, 2024 at 10:24:50AM -0700,
Sean Christopherson <seanjc@google.com> wrote:

> On Fri, Mar 01, 2024, isaku.yamahata@intel.com wrote:
> > From: Isaku Yamahata <isaku.yamahata@intel.com>
> > 
> > Another function will initialize struct kvm_page_fault.  Add initializer
> > macro to unify the big struct initialization.
> > 
> > No functional change intended.
> > 
> > Signed-off-by: Isaku Yamahata <isaku.yamahata@intel.com>
> > ---
> >  arch/x86/kvm/mmu/mmu_internal.h | 44 +++++++++++++++++++--------------
> >  1 file changed, 26 insertions(+), 18 deletions(-)
> > 
> > diff --git a/arch/x86/kvm/mmu/mmu_internal.h b/arch/x86/kvm/mmu/mmu_internal.h
> > index 0669a8a668ca..72ef09fc9322 100644
> > --- a/arch/x86/kvm/mmu/mmu_internal.h
> > +++ b/arch/x86/kvm/mmu/mmu_internal.h
> > @@ -279,27 +279,35 @@ enum {
> >  	RET_PF_SPURIOUS,
> >  };
> >  
> > +#define KVM_PAGE_FAULT_INIT(_vcpu, _cr2_or_gpa, _err, _prefetch, _max_level) {	\
> > +	.addr = (_cr2_or_gpa),							\
> > +	.error_code = (_err),							\
> > +	.exec = (_err) & PFERR_FETCH_MASK,					\
> > +	.write = (_err) & PFERR_WRITE_MASK,					\
> > +	.present = (_err) & PFERR_PRESENT_MASK,					\
> > +	.rsvd = (_err) & PFERR_RSVD_MASK,					\
> > +	.user = (_err) & PFERR_USER_MASK,					\
> > +	.prefetch = (_prefetch),						\
> > +	.is_tdp =								\
> > +	likely((_vcpu)->arch.mmu->page_fault == kvm_tdp_page_fault),		\
> > +	.nx_huge_page_workaround_enabled =					\
> > +	is_nx_huge_page_enabled((_vcpu)->kvm),					\
> > +										\
> > +	.max_level = (_max_level),						\
> > +	.req_level = PG_LEVEL_4K,						\
> > +	.goal_level = PG_LEVEL_4K,						\
> > +	.is_private =								\
> > +	kvm_mem_is_private((_vcpu)->kvm, (_cr2_or_gpa) >> PAGE_SHIFT),		\
> > +										\
> > +	.pfn = KVM_PFN_ERR_FAULT,						\
> > +	.hva = KVM_HVA_ERR_BAD, }
> > +
> 
> Oof, no.  I would much rather refactor kvm_mmu_do_page_fault() as needed than
> have to maintain a macro like this.

Ok, I updated it as follows.

diff --git a/arch/x86/kvm/mmu/mmu_internal.h b/arch/x86/kvm/mmu/mmu_internal.h
index 0669a8a668ca..e57cc3c56a6d 100644
--- a/arch/x86/kvm/mmu/mmu_internal.h
+++ b/arch/x86/kvm/mmu/mmu_internal.h
@@ -279,8 +279,8 @@ enum {
 	RET_PF_SPURIOUS,
 };
 
-static inline int kvm_mmu_do_page_fault(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa,
-					u32 err, bool prefetch, int *emulation_type)
+static inline int __kvm_mmu_do_page_fault(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa,
+					  u32 err, bool prefetch, int *emulation_type)
 {
 	struct kvm_page_fault fault = {
 		.addr = cr2_or_gpa,
@@ -307,6 +307,21 @@ static inline int kvm_mmu_do_page_fault(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa,
 		fault.slot = kvm_vcpu_gfn_to_memslot(vcpu, fault.gfn);
 	}
 
+	if (IS_ENABLED(CONFIG_RETPOLINE) && fault.is_tdp)
+		r = kvm_tdp_page_fault(vcpu, &fault);
+	else
+		r = vcpu->arch.mmu->page_fault(vcpu, &fault);
+
+	if (fault.write_fault_to_shadow_pgtable && emulation_type)
+		*emulation_type |= EMULTYPE_WRITE_PF_TO_SP;
+	return r;
+}
+
+static inline int kvm_mmu_do_page_fault(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa,
+					u32 err, bool prefetch, int *emulation_type)
+{
+	int r;
+
 	/*
 	 * Async #PF "faults", a.k.a. prefetch faults, are not faults from the
 	 * guest perspective and have already been counted at the time of the
@@ -315,13 +330,7 @@ static inline int kvm_mmu_do_page_fault(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa,
 	if (!prefetch)
 		vcpu->stat.pf_taken++;
 
-	if (IS_ENABLED(CONFIG_RETPOLINE) && fault.is_tdp)
-		r = kvm_tdp_page_fault(vcpu, &fault);
-	else
-		r = vcpu->arch.mmu->page_fault(vcpu, &fault);
-
-	if (fault.write_fault_to_shadow_pgtable && emulation_type)
-		*emulation_type |= EMULTYPE_WRITE_PF_TO_SP;
+	r = __kvm_mmu_do_page_fault(vcpu, cr2_or_gpa, err, prefetch, emulation_type);
 
 	/*
 	 * Similar to above, prefetch faults aren't truly spurious, and the
-- 
2.43.2

-- 
Isaku Yamahata <isaku.yamahata@intel.com>

  reply	other threads:[~2024-03-11 22:56 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-01 17:28 [RFC PATCH 0/8] KVM: Prepopulate guest memory API isaku.yamahata
2024-03-01 17:28 ` [RFC PATCH 1/8] KVM: Document KVM_MAP_MEMORY ioctl isaku.yamahata
2024-03-07  0:43   ` David Matlack
2024-03-07  1:29     ` Isaku Yamahata
2024-03-07 12:30   ` Huang, Kai
2024-03-07 20:33     ` Isaku Yamahata
2024-03-08  0:20       ` Huang, Kai
2024-03-08  0:56         ` David Matlack
2024-03-08  1:28           ` Sean Christopherson
2024-03-08  2:19             ` Isaku Yamahata
2024-03-10 23:12               ` Michael Roth
2024-03-11  1:05               ` Huang, Kai
2024-03-11  1:08                 ` Huang, Kai
2024-03-12  1:34                   ` Isaku Yamahata
2024-03-01 17:28 ` [RFC PATCH 2/8] KVM: Add KVM_MAP_MEMORY vcpu ioctl to pre-populate guest memory isaku.yamahata
2024-03-07  0:49   ` David Matlack
2024-03-07  2:52     ` Isaku Yamahata
2024-03-07 12:45   ` Huang, Kai
2024-03-07 20:41     ` Isaku Yamahata
2024-03-11 17:23   ` Sean Christopherson
2024-03-11 22:19     ` Isaku Yamahata
2024-03-01 17:28 ` [RFC PATCH 3/8] KVM: x86/mmu: Introduce initialier macro for struct kvm_page_fault isaku.yamahata
2024-03-11 17:24   ` Sean Christopherson
2024-03-11 22:56     ` Isaku Yamahata [this message]
2024-03-01 17:28 ` [RFC PATCH 4/8] KVM: x86/mmu: Factor out kvm_mmu_do_page_fault() isaku.yamahata
2024-03-01 17:28 ` [RFC PATCH 5/8] KVM: x86/mmu: Introduce kvm_mmu_map_page() for prepopulating guest memory isaku.yamahata
2024-03-07  0:38   ` David Matlack
2024-03-19 15:53     ` Isaku Yamahata
2024-03-11 17:29   ` Sean Christopherson
2024-03-11 22:57     ` Isaku Yamahata
2024-03-01 17:28 ` [RFC PATCH 6/8] KVM: x86: Implement kvm_arch_{, pre_}vcpu_map_memory() isaku.yamahata
2024-03-07  0:30   ` David Matlack
2024-03-07  0:36     ` David Matlack
2024-03-07  1:51       ` Isaku Yamahata
2024-03-19 16:26         ` Isaku Yamahata
2024-04-03 23:15           ` Sean Christopherson
2024-03-07  1:34     ` Isaku Yamahata
2024-03-11 23:26   ` Sean Christopherson
2024-03-12 12:38     ` Huang, Kai
2024-03-12 14:20       ` Sean Christopherson
2024-03-12 21:41         ` Huang, Kai
2024-03-12 21:46           ` Huang, Kai
2024-03-12 23:03             ` Sean Christopherson
2024-03-01 17:28 ` [RFC PATCH 7/8] KVM: x86: Add hooks in kvm_arch_vcpu_map_memory() isaku.yamahata
2024-03-01 17:28 ` [RFC PATCH 8/8] KVM: selftests: x86: Add test for KVM_MAP_MEMORY isaku.yamahata
2024-03-07  0:53 ` [RFC PATCH 0/8] KVM: Prepopulate guest memory API David Matlack
2024-03-07  2:09   ` Isaku Yamahata
2024-03-19 16:33     ` Isaku Yamahata
2024-04-03 18:30       ` Sean Christopherson
2024-04-03 22:00         ` Isaku Yamahata
2024-04-03 22:42           ` Sean Christopherson
2024-03-11  3:20 ` Michael Roth
2024-03-11 23:44   ` Sean Christopherson
2024-03-12  1:32     ` Isaku Yamahata

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240311225611.GB935089@ls.amr.corp.intel.com \
    --to=isaku.yamahata@intel.com \
    --cc=dmatlack@google.com \
    --cc=federico.parola@polito.it \
    --cc=isaku.yamahata@gmail.com \
    --cc=isaku.yamahata@linux.intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michael.roth@amd.com \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.