mbox series

[0/3] KVM: x86: skip gfn_track allocation when possible

Message ID 20210921081010.457591-1-stevensd@google.com (mailing list archive)
Headers show
Series KVM: x86: skip gfn_track allocation when possible | expand

Message

David Stevens Sept. 21, 2021, 8:10 a.m. UTC
From: David Stevens <stevensd@chromium.org>

Skip allocating gfn_track arrays when tracking of guest write access to
pages is not required. For VMs where the allocation can be avoided, this
saves 2 bytes per 4KB of guest memory.

Write tracking is used to manage shadow page tables in three cases -
when tdp is not supported, when nested virtualization is used, and for
GVT-g. By combining the existing tdp_enable flag and nested module param
with a new config that indicates when something outside of KVM (i.e.
GVT-g) needs write tracking, KVM can determine when initializing a VM
if gfn_track arrays are definitely not necessary.

This straightforward approach has the downside that for VMs where nested
virtualization is enabled but never used, gfn_track arrays are still
allocated. Instead of going so far as to try to initialize things on
demand, key off of whether or not X86_FEATURE_VMX is set in the guest's
cpuid to support per-VM configuration instead of system wide
configuration based on the nested module param.

David Stevens (3):
  KVM: x86: add config for non-kvm users of page tracking
  KVM: x86/mmu: skip page tracking when possible
  KVM: VMX: skip page tracking based on cpuid

 arch/x86/include/asm/kvm-x86-ops.h    |  1 +
 arch/x86/include/asm/kvm_host.h       |  4 +-
 arch/x86/include/asm/kvm_page_track.h |  7 ++-
 arch/x86/kvm/Kconfig                  |  3 ++
 arch/x86/kvm/cpuid.c                  | 55 +++++++++++++++-----
 arch/x86/kvm/mmu/page_track.c         | 74 +++++++++++++++++++++++++--
 arch/x86/kvm/svm/svm.c                | 10 +++-
 arch/x86/kvm/vmx/vmx.c                | 13 ++++-
 arch/x86/kvm/x86.c                    |  5 +-
 drivers/gpu/drm/i915/Kconfig          |  1 +
 10 files changed, 150 insertions(+), 23 deletions(-)

Comments

Paolo Bonzini Sept. 21, 2021, 10:27 a.m. UTC | #1
On 21/09/21 10:10, David Stevens wrote:
> This straightforward approach has the downside that for VMs where nested
> virtualization is enabled but never used, gfn_track arrays are still
> allocated. Instead of going so far as to try to initialize things on
> demand, key off of whether or not X86_FEATURE_VMX is set in the guest's
> cpuid to support per-VM configuration instead of system wide
> configuration based on the nested module param.

Can you allocate it lazily like we do for the rmap?

Paolo