Skip to content

KVM: x86: Conditional Hyper-V emulation enablement

Vitaly Kuznetsov kvm 2 versions – Applied

Status from this message: Queued, thanks.

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest15 patches 9 repliesApplied
  2. v17 patches 6 repliesSuperseded

Patches in v2 Applied

#Subject and filesSizeRepliesApplied
1/15selftests: kvm: Move kvm_get_supported_hv_cpuid() to common codetools/testing/selftests/kvm/include/x86_64/processor.h tools/testing/selftests/kvm/lib/x86_64/processor.c tools/testing/selftests/kvm/x86_64/hyperv_cpuid.c+39 -280 replies
2/15selftests: kvm: Properly set Hyper-V CPUIDs in evmcs_testtools/testing/selftests/kvm/x86_64/evmcs_test.c+38 -10 replies
3/15KVM: x86: hyper-v: Drop unused kvm_hv_vapic_assist_page_enabled()arch/x86/kvm/lapic.h+0 -50 replies
4/15KVM: x86: hyper-v: Rename vcpu_to_hv_vcpu() to to_hv_vcpu()arch/x86/kvm/hyperv.c arch/x86/kvm/hyperv.h+14 -140 replies
5/15KVM: x86: hyper-v: Rename vcpu_to_synic()/synic_to_vcpu()arch/x86/kvm/hyperv.c arch/x86/kvm/hyperv.h arch/x86/kvm/lapic.c +1 more+20 -200 replies
6/15KVM: x86: hyper-v: Rename vcpu_to_stimer()/stimer_to_vcpu()arch/x86/kvm/hyperv.c arch/x86/kvm/hyperv.h+21 -210 replies
7/15KVM: x86: hyper-v: Rename vcpu_to_hv_syndbg() to to_hv_syndbg()arch/x86/kvm/hyperv.c arch/x86/kvm/hyperv.h+5 -50 replies
8/15KVM: x86: hyper-v: Introduce to_kvm_hv() helperarch/x86/kvm/hyperv.c arch/x86/kvm/hyperv.h arch/x86/kvm/vmx/vmx.c +1 more+64 -530 replies
9/15KVM: x86: hyper-v: Stop shadowing global 'current_vcpu' variablearch/x86/kvm/hyperv.c+5 -60 replies
10/15KVM: x86: hyper-v: Always use to_hv_vcpu() accessor to get to 'struct kvm_vcpu_hv'arch/x86/kvm/hyperv.c arch/x86/kvm/hyperv.h arch/x86/kvm/lapic.h +2 more+21 -113 replies
11/15KVM: x86: hyper-v: Prepare to meet unallocated Hyper-V contextarch/x86/kvm/hyperv.c arch/x86/kvm/hyperv.h arch/x86/kvm/lapic.c +2 more+29 -143 replies
12/15KVM: x86: hyper-v: Allocate 'struct kvm_vcpu_hv' dynamicallyarch/x86/include/asm/kvm_host.h arch/x86/kvm/hyperv.c arch/x86/kvm/hyperv.h +1 more+27 -120 replies
13/15KVM: x86: hyper-v: Make Hyper-V emulation enablement conditionalarch/x86/include/asm/kvm_host.h arch/x86/kvm/cpuid.c arch/x86/kvm/hyperv.c +2 more+29 -60 replies
14/15KVM: x86: hyper-v: Allocate Hyper-V context lazilyarch/x86/kvm/hyperv.c arch/x86/kvm/hyperv.h arch/x86/kvm/x86.c+26 -180 replies
15/15KVM: x86: hyper-v: Drop hv_vcpu_to_vcpu() helperarch/x86/kvm/hyperv.h+4 -70 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [PATCH v2 00/15] KVM: x86: Conditional Hyper-V emulation enablement

Changes since v1 [Sean]:
- Add a few cleanup patches ("Rename vcpu_to_hv_vcpu() to to_hv_vcpu()", "Rename vcpu_to_synic()/synic_to_vcpu()", ...)
- Drop unused kvm_hv_vapic_assist_page_enabled()
- Stop shadowing global 'current_vcpu' variable in kvm_hv_flush_tlb()/ kvm_hv_send_ipi()

Original description:

Hyper-V emulation is enabled in KVM unconditionally even for Linux guests. This is bad at least from security standpoint as it is an extra attack surface. Ideally, there should be a per-VM capability explicitly enabled by VMM but currently it is not the case and we can't mandate one without breaking backwards compatibility. We can, however, check guest visible CPUIDs and only enable Hyper-V emulation when "Hv#1" interface was exposed in HYPERV_CPUID_INTERFACE.

Also (and while on it) per-vcpu Hyper-V context ('struct kvm_vcpu_hv') is currently part of 'struct kvm_vcpu_arch' and thus allocated unconditionally for each vCPU. The context, however, quite big and accounts for more than 1/4 of 'struct kvm_vcpu_arch' (e.g. 2912/9512 bytes). Switch to allocating it dynamically. This may come handy if we ever decide to raise KVM_MAX_VCPUS (and rumor has it some downstream distributions already have more than '288')

Vitaly Kuznetsov (15):
selftests: kvm: Move kvm_get_supported_hv_cpuid() to common code
selftests: kvm: Properly set Hyper-V CPUIDs in evmcs_test
KVM: x86: hyper-v: Drop unused kvm_hv_vapic_assist_page_enabled()
KVM: x86: hyper-v: Rename vcpu_to_hv_vcpu() to to_hv_vcpu()
KVM: x86: hyper-v: Rename vcpu_to_synic()/synic_to_vcpu()
KVM: x86: hyper-v: Rename vcpu_to_stimer()/stimer_to_vcpu()
KVM: x86: hyper-v: Rename vcpu_to_hv_syndbg() to to_hv_syndbg()
KVM: x86: hyper-v: Introduce to_kvm_hv() helper
KVM: x86: hyper-v: Stop shadowing global 'current_vcpu' variable
KVM: x86: hyper-v: Always use to_hv_vcpu() accessor to get to 'struct
kvm_vcpu_hv'
KVM: x86: hyper-v: Prepare to meet unallocated Hyper-V context
KVM: x86: hyper-v: Allocate 'struct kvm_vcpu_hv' dynamically
KVM: x86: hyper-v: Make Hyper-V emulation enablement conditional
KVM: x86: hyper-v: Allocate Hyper-V context lazily
KVM: x86: hyper-v: Drop hv_vcpu_to_vcpu() helper

 arch/x86/include/asm/kvm_host.h               |   4 +-
 arch/x86/kvm/cpuid.c                          |   2 +
 arch/x86/kvm/hyperv.c                         | 301 +++++++++++-------
 arch/x86/kvm/hyperv.h                         |  54 ++--
 arch/x86/kvm/lapic.c                          |   5 +-
 arch/x86/kvm/lapic.h                          |   7 +-
 arch/x86/kvm/vmx/vmx.c                        |   9 +-
 arch/x86/kvm/x86.c                            |  19 +-
 .../selftests/kvm/include/x86_64/processor.h  |   3 +
 .../selftests/kvm/lib/x86_64/processor.c      |  33 ++
 .../testing/selftests/kvm/x86_64/evmcs_test.c |  39 ++-
 .../selftests/kvm/x86_64/hyperv_cpuid.c       |  31 +-
 12 files changed, 314 insertions(+), 193 deletions(-)
Signature · 1 line
2.29.2