[v2,0/6] KVM: x86/mmu: refine memtype related mmu zap

Message ID 20230509134825.1523-1-yan.y.zhao@intel.com
Headers
Series KVM: x86/mmu: refine memtype related mmu zap |

Message

Yan Zhao May 9, 2023, 1:48 p.m. UTC
  This series refines mmu zap caused by EPT memory type update.

The first 3 patches will only do mmu zap when the target is to update
memory type of EPT entries by introducing a help in patch 1 to skip
non-EPT cases.

The 4th patch will trigger zapping of EPT leaf entries if non-coherent
DMA devices count goes from 0 to 1 or from 1 to 0.

The 5th-6th patches reduces EPT zap count by introducing a per-VM based
guest MTRR and only zap EPT entries when this per-VM based guest MTRR
changes.

Changelog:
v1 --> v2:
1. Added a helper to skip non EPT case in patch 1
2. Added patch 2 to skip mmu zap when guest CR0_CD changes if EPT is not
   enabled. (Chao Gao)
3. Added patch 3 to skip mmu zap when guest MTRR changes if EPT is not
   enabled.
4. Do not mention TDX in patch 4 as the code is not merged yet (Chao Gao)
5. Added patches 5-6 to reduce EPT zap during guest bootup.

v1:
https://lore.kernel.org/all/20230508034700.7686-1-yan.y.zhao@intel.com/

Yan Zhao (6):
  KVM: x86/mmu: add a new mmu zap helper to indicate memtype changes
  KVM: x86/mmu: only zap EPT when guest CR0_CD changes
  KVM: x86/mmu: only zap EPT when guest MTRR changes
  KVM: x86/mmu: Zap all EPT leaf entries according noncoherent DMA count
  KVM: x86: Keep a per-VM MTRR state
  KVM: x86/mmu: use per-VM based MTRR for EPT

 arch/x86/include/asm/kvm_host.h |   3 +
 arch/x86/kvm/mmu.h              |   1 +
 arch/x86/kvm/mmu/mmu.c          |  18 ++++-
 arch/x86/kvm/mtrr.c             | 112 +++++++++++++++++++++++++-------
 arch/x86/kvm/vmx/vmx.c          |   2 +-
 arch/x86/kvm/x86.c              |  10 ++-
 arch/x86/kvm/x86.h              |   6 +-
 7 files changed, 122 insertions(+), 30 deletions(-)


base-commit: 5c291b93e5d665380dbecc6944973583f9565ee5
  

Comments

Sean Christopherson May 24, 2023, 12:15 a.m. UTC | #1
On Tue, May 09, 2023, Yan Zhao wrote:
> This series refines mmu zap caused by EPT memory type update.
> Yan Zhao (6):
>   KVM: x86/mmu: add a new mmu zap helper to indicate memtype changes
>   KVM: x86/mmu: only zap EPT when guest CR0_CD changes
>   KVM: x86/mmu: only zap EPT when guest MTRR changes
>   KVM: x86/mmu: Zap all EPT leaf entries according noncoherent DMA count
>   KVM: x86: Keep a per-VM MTRR state
>   KVM: x86/mmu: use per-VM based MTRR for EPT
> 
>  arch/x86/include/asm/kvm_host.h |   3 +
>  arch/x86/kvm/mmu.h              |   1 +
>  arch/x86/kvm/mmu/mmu.c          |  18 ++++-
>  arch/x86/kvm/mtrr.c             | 112 +++++++++++++++++++++++++-------
>  arch/x86/kvm/vmx/vmx.c          |   2 +-
>  arch/x86/kvm/x86.c              |  10 ++-
>  arch/x86/kvm/x86.h              |   6 +-
>  7 files changed, 122 insertions(+), 30 deletions(-)
> 
> 
> base-commit: 5c291b93e5d665380dbecc6944973583f9565ee5
> -- 

To save us both a bit of pain, can you base the next version on top of my PAT
cleanup[*]?  I am planning on applying that series "soon".  Thanks!

[*] https://lore.kernel.org/all/20230511233351.635053-1-seanjc@google.com
  
Yan Zhao May 24, 2023, 11:04 a.m. UTC | #2
On Tue, May 23, 2023 at 05:15:52PM -0700, Sean Christopherson wrote:
> On Tue, May 09, 2023, Yan Zhao wrote:
> > This series refines mmu zap caused by EPT memory type update.
> > Yan Zhao (6):
> >   KVM: x86/mmu: add a new mmu zap helper to indicate memtype changes
> >   KVM: x86/mmu: only zap EPT when guest CR0_CD changes
> >   KVM: x86/mmu: only zap EPT when guest MTRR changes
> >   KVM: x86/mmu: Zap all EPT leaf entries according noncoherent DMA count
> >   KVM: x86: Keep a per-VM MTRR state
> >   KVM: x86/mmu: use per-VM based MTRR for EPT
> > 
> >  arch/x86/include/asm/kvm_host.h |   3 +
> >  arch/x86/kvm/mmu.h              |   1 +
> >  arch/x86/kvm/mmu/mmu.c          |  18 ++++-
> >  arch/x86/kvm/mtrr.c             | 112 +++++++++++++++++++++++++-------
> >  arch/x86/kvm/vmx/vmx.c          |   2 +-
> >  arch/x86/kvm/x86.c              |  10 ++-
> >  arch/x86/kvm/x86.h              |   6 +-
> >  7 files changed, 122 insertions(+), 30 deletions(-)
> > 
> > 
> > base-commit: 5c291b93e5d665380dbecc6944973583f9565ee5
> > -- 
> 
> To save us both a bit of pain, can you base the next version on top of my PAT
> cleanup[*]?  I am planning on applying that series "soon".  Thanks!
> 
> [*] https://lore.kernel.org/all/20230511233351.635053-1-seanjc@google.com 
Sure, will do it!