From: "Edgecombe, Rick P" <rick.p.edgecombe@intel.com>
To: "kvm@vger.kernel.org" <kvm@vger.kernel.org>,
"Yamahata, Isaku" <isaku.yamahata@intel.com>
Cc: "seanjc@google.com" <seanjc@google.com>,
"Huang, Kai" <kai.huang@intel.com>,
"federico.parola@polito.it" <federico.parola@polito.it>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"isaku.yamahata@gmail.com" <isaku.yamahata@gmail.com>,
"dmatlack@google.com" <dmatlack@google.com>,
"michael.roth@amd.com" <michael.roth@amd.com>,
"pbonzini@redhat.com" <pbonzini@redhat.com>
Subject: Re: [PATCH v2 03/10] KVM: x86/mmu: Extract __kvm_mmu_do_page_fault()
Date: Tue, 16 Apr 2024 14:36:31 +0000 [thread overview]
Message-ID: <621c260399a05338ba6d034e275e19714ad3665c.camel@intel.com> (raw)
In-Reply-To: <ddf1d98420f562707b11e12c416cce8fdb986bb1.1712785629.git.isaku.yamahata@intel.com>
On Wed, 2024-04-10 at 15:07 -0700, isaku.yamahata@intel.com wrote:
> From: Isaku Yamahata <isaku.yamahata@intel.com>
>
> Extract out __kvm_mmu_do_page_fault() from kvm_mmu_do_page_fault(). The
> inner function is to initialize struct kvm_page_fault and to call the fault
> handler, and the outer function handles updating stats and converting
> return code. KVM_MAP_MEMORY will call the KVM page fault handler.
>
> This patch makes the emulation_type always set irrelevant to the return
a comma would help parse this better ^
> code.
> kvm_mmu_page_fault() is the only caller of kvm_mmu_do_page_fault(),
Not technically correct, there are other callers that pass NULL for
emulation_type.
> and references the value only when PF_RET_EMULATE is returned. Therefore,
> this adjustment doesn't affect functionality.
Is there a problem with dropping the argument then?
>
> No functional change intended.
Can we not use the "intended"? It sounds like hedging for excuses.
>
> Suggested-by: Sean Christopherson <seanjc@google.com>
> Signed-off-by: Isaku Yamahata <isaku.yamahata@intel.com>
> ---
> v2:
> - Newly introduced. (Sean)
> ---
> arch/x86/kvm/mmu/mmu_internal.h | 32 +++++++++++++++++++++-----------
> 1 file changed, 21 insertions(+), 11 deletions(-)
>
> diff --git a/arch/x86/kvm/mmu/mmu_internal.h b/arch/x86/kvm/mmu/mmu_internal.h
> index e68a60974cf4..9baae6c223ee 100644
> --- a/arch/x86/kvm/mmu/mmu_internal.h
> +++ b/arch/x86/kvm/mmu/mmu_internal.h
> @@ -287,8 +287,8 @@ static inline void
> kvm_mmu_prepare_memory_fault_exit(struct kvm_vcpu *vcpu,
> fault->is_private);
> }
>
> -static inline int kvm_mmu_do_page_fault(struct kvm_vcpu *vcpu, gpa_t
> cr2_or_gpa,
> - u64 err, bool prefetch, int
> *emulation_type)
> +static inline int __kvm_mmu_do_page_fault(struct kvm_vcpu *vcpu, gpa_t
> cr2_or_gpa,
> + u64 err, bool prefetch, int
> *emulation_type)
> {
> struct kvm_page_fault fault = {
> .addr = cr2_or_gpa,
> @@ -318,14 +318,6 @@ 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);
> }
>
> - /*
> - * 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
> - * original fault.
> - */
> - if (!prefetch)
> - vcpu->stat.pf_taken++;
> -
> if (IS_ENABLED(CONFIG_MITIGATION_RETPOLINE) && fault.is_tdp)
> r = kvm_tdp_page_fault(vcpu, &fault);
> else
> @@ -333,12 +325,30 @@ static inline int kvm_mmu_do_page_fault(struct kvm_vcpu
> *vcpu, gpa_t cr2_or_gpa,
>
> if (r == RET_PF_EMULATE && fault.is_private) {
> kvm_mmu_prepare_memory_fault_exit(vcpu, &fault);
> - return -EFAULT;
> + r = -EFAULT;
> }
>
> 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,
> + u64 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
> + * original fault.
> + */
> + if (!prefetch)
> + vcpu->stat.pf_taken++;
From the name, it makes sense to not count KVM_MAP_MEMORY as a pf_taken. But
kvm_arch_async_page_ready() increments it as well. Which makes it more like a
"faulted-in" count. I think the code in this patch is ok.
> +
> + 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
> * async #PF path doesn't do emulation. Do count faults that are
> fixed
next prev parent reply other threads:[~2024-04-16 14:36 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-10 22:07 [PATCH v2 00/10] KVM: Guest Memory Pre-Population API isaku.yamahata
2024-04-10 22:07 ` [PATCH v2 01/10] KVM: Document KVM_MAP_MEMORY ioctl isaku.yamahata
2024-04-15 23:27 ` Edgecombe, Rick P
2024-04-15 23:47 ` Isaku Yamahata
2024-04-17 11:56 ` Paolo Bonzini
2024-04-10 22:07 ` [PATCH v2 02/10] KVM: Add KVM_MAP_MEMORY vcpu ioctl to pre-populate guest memory isaku.yamahata
2024-04-16 14:20 ` Edgecombe, Rick P
2024-04-10 22:07 ` [PATCH v2 03/10] KVM: x86/mmu: Extract __kvm_mmu_do_page_fault() isaku.yamahata
2024-04-16 8:22 ` Chao Gao
2024-04-16 23:43 ` Isaku Yamahata
2024-04-16 14:36 ` Edgecombe, Rick P [this message]
2024-04-16 23:52 ` Isaku Yamahata
2024-04-17 15:41 ` Paolo Bonzini
2024-04-10 22:07 ` [PATCH v2 04/10] KVM: x86/mmu: Make __kvm_mmu_do_page_fault() return mapped level isaku.yamahata
2024-04-16 14:40 ` Edgecombe, Rick P
2024-04-16 23:59 ` Isaku Yamahata
2024-04-10 22:07 ` [PATCH v2 05/10] KVM: x86/mmu: Introduce kvm_tdp_map_page() to populate guest memory isaku.yamahata
2024-04-16 14:46 ` Edgecombe, Rick P
2024-04-17 18:39 ` Isaku Yamahata
2024-04-17 7:04 ` Chao Gao
2024-04-17 18:44 ` Isaku Yamahata
2024-04-10 22:07 ` [PATCH v2 06/10] KVM: x86: Implement kvm_arch_vcpu_map_memory() isaku.yamahata
2024-04-16 15:12 ` Edgecombe, Rick P
2024-04-17 7:20 ` Chao Gao
2024-04-17 12:18 ` Paolo Bonzini
2024-04-10 22:07 ` [PATCH v2 07/10] KVM: x86: Always populate L1 GPA for KVM_MAP_MEMORY isaku.yamahata
2024-04-15 19:12 ` Edgecombe, Rick P
2024-04-15 21:17 ` Sean Christopherson
2024-04-15 21:36 ` Edgecombe, Rick P
2024-04-15 22:59 ` Sean Christopherson
2024-04-16 1:49 ` Isaku Yamahata
2024-04-16 14:22 ` Sean Christopherson
2024-04-16 21:41 ` Paolo Bonzini
2024-04-16 23:00 ` Sean Christopherson
2024-04-17 10:28 ` Paolo Bonzini
2024-04-15 19:37 ` Edgecombe, Rick P
2024-04-16 17:11 ` Edgecombe, Rick P
2024-04-10 22:07 ` [PATCH v2 08/10] KVM: x86: Add a hook in kvm_arch_vcpu_map_memory() isaku.yamahata
2024-04-16 14:57 ` Edgecombe, Rick P
2024-04-17 12:26 ` Paolo Bonzini
2024-04-10 22:07 ` [PATCH v2 09/10] KVM: SVM: Implement pre_mmu_map_page() to refuse KVM_MAP_MEMORY isaku.yamahata
2024-04-10 22:07 ` [PATCH v2 10/10] KVM: selftests: x86: Add test for KVM_MAP_MEMORY 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=621c260399a05338ba6d034e275e19714ad3665c.camel@intel.com \
--to=rick.p.edgecombe@intel.com \
--cc=dmatlack@google.com \
--cc=federico.parola@polito.it \
--cc=isaku.yamahata@gmail.com \
--cc=isaku.yamahata@intel.com \
--cc=kai.huang@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®