From: Yan Zhao <yan.y.zhao@intel.com>
To: Chao Gao <chao.gao@intel.com>
Cc: <kvm@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<pbonzini@redhat.com>, <seanjc@google.com>
Subject: Re: [PATCH v2 1/6] KVM: x86/mmu: add a new mmu zap helper to indicate memtype changes
Date: Wed, 10 May 2023 16:06:16 +0800 [thread overview]
Message-ID: <ZFtQeLNuXP6tDMne@yzhao56-desk.sh.intel.com> (raw)
In-Reply-To: <ZFsr9TynkA/CyPgg@chao-email>
On Wed, May 10, 2023 at 01:30:29PM +0800, Chao Gao wrote:
> On Tue, May 09, 2023 at 09:50:06PM +0800, Yan Zhao wrote:
> >Add a helper to indicate that the kvm_zap_gfn_range() request is to update
> >memory type.
> >
> >Then the zap can be avoided in cases:
> >1. TDP is not enabled.
> >2. EPT is not enabled.
> >
> >This is because only memory type of EPT leaf entries are subjected to
> >change when noncoherent DMA/guest CR0.CD/guest MTRR settings change.
> >
> >Signed-off-by: Yan Zhao <yan.y.zhao@intel.com>
> >---
> > arch/x86/kvm/mmu.h | 1 +
> > arch/x86/kvm/mmu/mmu.c | 16 ++++++++++++++++
> > 2 files changed, 17 insertions(+)
> >
> >diff --git a/arch/x86/kvm/mmu.h b/arch/x86/kvm/mmu.h
> >index 92d5a1924fc1..a04577afbc71 100644
> >--- a/arch/x86/kvm/mmu.h
> >+++ b/arch/x86/kvm/mmu.h
> >@@ -236,6 +236,7 @@ static inline u8 permission_fault(struct kvm_vcpu *vcpu, struct kvm_mmu *mmu,
> > }
> >
> > void kvm_zap_gfn_range(struct kvm *kvm, gfn_t gfn_start, gfn_t gfn_end);
> >+void kvm_zap_gfn_for_memtype(struct kvm *kvm, gfn_t gfn_start, gfn_t gfn_end);
> >
> > int kvm_arch_write_log_dirty(struct kvm_vcpu *vcpu);
> >
> >diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
> >index c8961f45e3b1..2706754794d1 100644
> >--- a/arch/x86/kvm/mmu/mmu.c
> >+++ b/arch/x86/kvm/mmu/mmu.c
> >@@ -6272,6 +6272,22 @@ static bool kvm_rmap_zap_gfn_range(struct kvm *kvm, gfn_t gfn_start, gfn_t gfn_e
> > return flush;
> > }
> >
> >+/*
> >+ * Invalidate (zap) TDP SPTEs that cover GFNs from gfn_start and up to gfn_end
> >+ * (not including it) for reason of memory type being updated.
> >+ */
> >+void kvm_zap_gfn_for_memtype(struct kvm *kvm, gfn_t gfn_start, gfn_t gfn_end)
> >+{
> >+ /* Currently only memory type of EPT leaf entries are affected by
> >+ * guest CR0.CD and guest MTRR.
> >+ * So skip invalidation (zap) in other cases
> >+ */
> >+ if (!shadow_memtype_mask)
>
> Do you need to check kvm_arch_has_noncoherent_dma()? if yes, maybe just extract
> the first if() statement and its associated comment from kvm_tdp_page_fault()?
>
This kvm_zap_gfn_for_memtype() helper will be called in
kvm_arch_unregister_noncoherent_dma() as well when noncoherent_dma_count
goes from 1 to 0.
So, checking kvm_arch_has_noncoherent_dma() is not desired.
> >+ return;
> >+
> >+ kvm_zap_gfn_range(kvm, gpa_to_gfn(0), gpa_to_gfn(~0ULL));
>
> This should be:
>
> kvm_zap_gfn_range(kvm, start, end);
>
Oops. sorry about this mistake. Will fix it in next version.
> >+}
> >+
> > /*
> > * Invalidate (zap) SPTEs that cover GFNs from gfn_start and up to gfn_end
> > * (not including it)
> >--
> >2.17.1
> >
next prev parent reply other threads:[~2023-05-10 8:33 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-09 13:48 [PATCH v2 0/6] KVM: x86/mmu: refine memtype related mmu zap Yan Zhao
2023-05-09 13:50 ` [PATCH v2 1/6] KVM: x86/mmu: add a new mmu zap helper to indicate memtype changes Yan Zhao
2023-05-10 5:30 ` Chao Gao
2023-05-10 8:06 ` Yan Zhao [this message]
2023-05-23 22:51 ` Sean Christopherson
2023-05-24 2:22 ` Yan Zhao
2023-05-24 14:50 ` Sean Christopherson
2023-05-25 10:14 ` Yan Zhao
2023-05-25 15:54 ` Sean Christopherson
2023-05-30 1:32 ` Yan Zhao
2023-05-30 9:48 ` Yan Zhao
2023-05-30 23:51 ` Sean Christopherson
2023-05-31 0:18 ` Yan Zhao
2023-05-09 13:51 ` [PATCH v2 2/6] KVM: x86/mmu: only zap EPT when guest CR0_CD changes Yan Zhao
2023-05-09 13:51 ` [PATCH v2 3/6] KVM: x86/mmu: only zap EPT when guest MTRR changes Yan Zhao
2023-05-10 5:39 ` Chao Gao
2023-05-10 8:00 ` Yan Zhao
2023-05-10 10:54 ` Huang, Kai
2023-05-11 0:15 ` Yan Zhao
2023-05-11 2:42 ` Huang, Kai
2023-05-11 2:31 ` Yan Zhao
2023-05-11 3:05 ` Huang, Kai
2023-05-09 13:52 ` [PATCH v2 4/6] KVM: x86/mmu: Zap all EPT leaf entries according noncoherent DMA count Yan Zhao
2023-05-09 13:53 ` [PATCH v2 5/6] KVM: x86: Keep a per-VM MTRR state Yan Zhao
2023-05-10 17:23 ` David Matlack
2023-05-21 3:44 ` Robert Hoo
2023-05-23 6:21 ` Yan Zhao
2023-05-24 0:13 ` Sean Christopherson
2023-05-24 11:03 ` Yan Zhao
2023-05-24 18:21 ` Sean Christopherson
2023-05-25 10:09 ` Yan Zhao
2023-05-25 14:53 ` Sean Christopherson
2023-05-26 7:54 ` Yan Zhao
2023-05-26 16:09 ` Sean Christopherson
2023-05-30 1:19 ` Yan Zhao
2023-05-25 7:21 ` Robert Hoo
2023-05-25 15:00 ` Sean Christopherson
2023-05-26 1:49 ` Robert Hoo
2023-05-09 13:53 ` [PATCH v2 6/6] KVM: x86/mmu: use per-VM based MTRR for EPT Yan Zhao
2023-05-24 0:15 ` [PATCH v2 0/6] KVM: x86/mmu: refine memtype related mmu zap Sean Christopherson
2023-05-24 11:04 ` Yan Zhao
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=ZFtQeLNuXP6tDMne@yzhao56-desk.sh.intel.com \
--to=yan.y.zhao@intel.com \
--cc=chao.gao@intel.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--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®