Skip to content

KVM: Rework kvm_init() and hardware enabling

Sean Christopherson kvm kvm-riscv kvmarm linux-arm-kernel linux-mips linux-riscv linux-s390 linuxppc-dev lkml 2 versions – Applied

Status from this message: Applied this series and verified that an attempt to online incompatible

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest50 patches 26 repliesApplied
  2. v144 patches 82 repliesSuperseded

Changes in v2 from the cover letter

- Collect reviews/acks.
- Reset eVMCS controls in VP assist page when disabling hardware. [Vitaly]
- Clean up labels in kvm_init(). [Chao]
- Fix a goof where VMX compat checks used boot_cpu_has. [Kai]
- Reorder patches and/or tweak changelogs to not require time travel. [Paolo, Kai]
- Rewrite the changelog for the patch to move ARM away from kvm_arch_init() to call out that it fixes theoretical bugs. [Philippe]
- Document why it's safe to allow preemption and/or migration when accessing kvm_usage_count.

Patches in v2 Applied

#Subject and filesSizeRepliesApplied
1/50KVM: Register /dev/kvm as the _very_ last thing during initializationvirt/kvm/kvm_main.c+22 -90 replies
2/50KVM: Initialize IRQ FD after arch hardware setupvirt/kvm/kvm_main.c+18 -190 replies
3/50KVM: Allocate cpus_hardware_enabled after arch hardware setupvirt/kvm/kvm_main.c+7 -70 replies
4/50KVM: Teardown VFIO ops earlier in kvm_exit()virt/kvm/kvm_main.c+1 -10 replies
5/50KVM: s390: Unwind kvm_arch_init() piece-by-piece() if a step failsarch/s390/kvm/kvm-s390.c+14 -70 replies
6/50KVM: s390: Move hardware setup/unsetup to init/exitarch/s390/kvm/kvm-s390.c+13 -100 replies
7/50KVM: x86: Do timer initialization after XCR0 configurationarch/x86/kvm/x86.c+2 -20 replies
8/50KVM: x86: Move hardware setup/unsetup to init/exitarch/x86/kvm/x86.c+63 -580 replies
9/50KVM: Drop arch hardware (un)setup hooksarch/arm64/include/asm/kvm_host.h arch/arm64/kvm/arm.c arch/mips/include/asm/kvm_host.h +9 more+0 -530 replies
10/50KVM: VMX: Reset eVMCS controls in VP assist page during hardware disablingarch/x86/kvm/vmx/vmx.c+30 -201 reply
11/50KVM: VMX: Don't bother disabling eVMCS static key on module exitarch/x86/kvm/vmx/vmx.c+0 -40 replies
12/50KVM: VMX: Move Hyper-V eVMCS initialization to helperarch/x86/kvm/vmx/vmx.c+43 -301 reply
13/50KVM: x86: Move guts of kvm_arch_init() to standalone helperarch/x86/include/asm/kvm_host.h arch/x86/kvm/svm/svm.c arch/x86/kvm/vmx/vmx.c +1 more+52 -100 replies
14/50KVM: VMX: Do _all_ initialization before exposing /dev/kvm to userspacearch/x86/kvm/vmx/vmx.c+21 -130 replies
15/50KVM: x86: Serialize vendor module initialization (hardware setup)Documentation/virt/kvm/locking.rst arch/x86/kvm/x86.c+22 -20 replies
16/50KVM: arm64: Simplify the CPUHP logicarch/arm64/kvm/arch_timer.c arch/arm64/kvm/arm.c arch/arm64/kvm/vgic/vgic-init.c +3 more+33 -370 replies
17/50KVM: arm64: Free hypervisor allocations if vector slot init failsarch/arm64/kvm/arm.c+8 -70 replies
18/50KVM: arm64: Unregister perf callbacks if hypervisor finalization failsarch/arm64/kvm/arm.c+11 -20 replies
19/50KVM: arm64: Do arm/arch initialization without bouncing through kvm_init()arch/arm64/kvm/arm.c+16 -90 replies
20/50KVM: arm64: Mark kvm_arm_init() and its unique descendants as __initarch/arm64/include/asm/kvm_host.h arch/arm64/include/asm/kvm_mmu.h arch/arm64/kvm/arch_timer.c +6 more+44 -440 replies
21/50KVM: MIPS: Hardcode callbacks to hardware virtualization extensionsarch/mips/include/asm/kvm_host.h arch/mips/kvm/Makefile arch/mips/kvm/callback.c +2 more+8 -262 replies
22/50KVM: MIPS: Setup VZ emulation? directly from kvm_mips_init()arch/mips/kvm/mips.c+5 -10 replies
23/50KVM: MIPS: Register die notifier prior to kvm_init()arch/mips/kvm/mips.c+5 -40 replies
24/50KVM: RISC-V: Do arch init directly in riscv_kvm_init()arch/riscv/kvm/main.c+9 -90 replies
25/50KVM: RISC-V: Tag init functions and data with __init, __ro_after_initarch/riscv/include/asm/kvm_host.h arch/riscv/kvm/mmu.c arch/riscv/kvm/vmid.c+11 -110 replies
26/50KVM: PPC: Move processor compatibility check to module initarch/powerpc/include/asm/kvm_ppc.h arch/powerpc/kvm/book3s.c arch/powerpc/kvm/e500.c +2 more+7 -142 replies
27/50KVM: s390: Do s390 specific init without bouncing through kvm_init()arch/s390/kvm/kvm-s390.c+25 -40 replies
28/50KVM: s390: Mark __kvm_s390_init() and its descendants as __initarch/s390/kvm/interrupt.c arch/s390/kvm/kvm-s390.c arch/s390/kvm/kvm-s390.h +2 more+6 -60 replies
29/50KVM: Drop kvm_arch_{init,exit}() hooksarch/arm64/kvm/arm.c arch/mips/kvm/mips.c arch/powerpc/include/asm/kvm_host.h +6 more+2 -760 replies
30/50KVM: VMX: Make VMCS configuration/capabilities structs read-only after initarch/x86/kvm/vmx/capabilities.h arch/x86/kvm/vmx/vmx.c+4 -40 replies
31/50KVM: x86: Do CPU compatibility checks in x86 codearch/x86/kvm/svm/svm.c arch/x86/kvm/vmx/vmx.c arch/x86/kvm/x86.c+40 -133 replies
32/50KVM: Drop kvm_arch_check_processor_compat() hookarch/arm64/kvm/arm.c arch/mips/kvm/mips.c arch/powerpc/kvm/book3s.c +10 more+13 -671 reply
33/50KVM: x86: Use KBUILD_MODNAME to specify vendor module namearch/x86/kvm/svm/svm.c arch/x86/kvm/vmx/vmx.c+2 -20 replies
34/50KVM: x86: Unify pr_fmt to use module name for all KVM modulesarch/x86/kvm/cpuid.c arch/x86/kvm/debugfs.c arch/x86/kvm/emulate.c +35 more+97 -701 reply
35/50KVM: VMX: Use current CPU's info to perform "disabled by BIOS?" checksarch/x86/kvm/vmx/vmx.c+2 -21 reply
36/50KVM: x86: Do VMX/SVM support checks directly in vendor codearch/x86/include/asm/kvm_host.h arch/x86/kvm/svm/svm.c arch/x86/kvm/vmx/vmx.c +1 more+37 -510 replies
37/50KVM: VMX: Shuffle support checks and hardware enabling code aroundarch/x86/kvm/vmx/vmx.c+108 -1080 replies
38/50KVM: SVM: Check for SVM support in CPU compatibility checksarch/x86/kvm/svm/svm.c+8 -50 replies
39/50KVM: x86: Move CPU compat checks hook to kvm_x86_ops (from kvm_x86_init_ops)arch/x86/include/asm/kvm-x86-ops.h arch/x86/include/asm/kvm_host.h arch/x86/kvm/svm/svm.c +2 more+25 -312 replies
40/50KVM: x86: Do compatibility checks when onlining CPUarch/x86/kvm/svm/svm.c arch/x86/kvm/vmx/vmx.c arch/x86/kvm/x86.c+18 -103 replies
41/50KVM: Rename and move CPUHP_AP_KVM_STARTING to ONLINE sectionarch/x86/kvm/x86.c include/linux/cpuhotplug.h virt/kvm/kvm_main.c+23 -112 replies
42/50KVM: Disable CPU hotplug during hardware enabling/disablingarch/x86/kvm/x86.c virt/kvm/kvm_main.c+22 -12 replies
43/50KVM: Ensure CPU is stable during low level hardware enable/disablevirt/kvm/kvm_main.c+2 -20 replies
44/50KVM: Drop kvm_count_lock and instead protect kvm_usage_count with kvm_lockDocumentation/virt/kvm/locking.rst virt/kvm/kvm_main.c+34 -210 replies
45/50KVM: Remove on_each_cpu(hardware_disable_nolock) in kvm_exit()virt/kvm/kvm_main.c+0 -10 replies
46/50KVM: Use a per-CPU variable to track which CPUs have enabled virtualizationvirt/kvm/kvm_main.c+18 -230 replies
47/50KVM: Make hardware_enable_failed a local variable in the "enable all" pathvirt/kvm/kvm_main.c+16 -190 replies
48/50KVM: Register syscore (suspend/resume) ops early in kvm_init()virt/kvm/kvm_main.c+34 -340 replies
49/50KVM: Opt out of generic hardware enabling on s390 and PPCarch/arm64/kvm/Kconfig arch/mips/kvm/Kconfig arch/powerpc/include/asm/kvm_host.h +8 more+35 -190 replies
50/50KVM: Clean up error labels in kvm_init()virt/kvm/kvm_main.c+4 -40 replies

Reviews trailers per patch

24 of 50 patches have a Reviewed-by or Acked-by.

PatchYuan YaoCornelia HuckEric FarmanAnup PatelPhilippe Mathieu-DaudéMichael EllermanPaul DurrantVitaly KuznetsovKai HuangIsaku Yamahata
1/50
2/50
3/50R-b
4/50R-b R-b
5/50R-b
6/50R-b
7/50
8/50
9/50R-b A-b
10/50R-b
11/50
12/50R-b
13/50
14/50
15/50
16/50
17/50
18/50
19/50
20/50
21/50R-b
22/50R-b
23/50R-b
24/50A-b R-b
25/50A-b
26/50A-b
27/50R-b R-b
28/50R-b
29/50R-b A-b R-b
30/50
31/50R-b R-b
32/50R-b A-b R-b R-b
33/50
34/50R-b
35/50R-b
36/50
37/50
38/50
39/50R-b
40/50A-b
41/50R-b
42/50
43/50
44/50
45/50
46/50
47/50
48/50
49/50A-b
50/50

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 10 reviewers.

Read the v2 thread

Cover letter [PATCH v2 00/50] KVM: Rework kvm_init() and hardware enabling

The main theme of this series is to kill off kvm_arch_init(), kvm_arch_hardware_(un)setup(), and kvm_arch_check_processor_compat(), which all originated in x86 code from way back when, and needlessly complicate both common KVM code and architecture code. E.g. many architectures don't mark functions/data as __init/__ro_after_init purely because kvm_init() isn't marked __init to support x86's separate vendor modules.

The idea/hope is that with those hooks gone (moved to arch code), it will be easier for x86 (and other architectures) to modify their module init sequences as needed without having to fight common KVM code. E.g. I'm hoping that ARM can build on this to simplify its hardware enabling logic, especially the pKVM side of things.

There are bug fixes throughout this series. They are more scattered than I would usually prefer, but getting the sequencing correct was a gigantic pain for many of the x86 fixes due to needing to fix common code in order for the x86 fix to have any meaning. And while the bugs are often fatal, they aren't all that interesting for most users as they either require a malicious admin or broken hardware, i.e. aren't likely to be encountered by the vast majority of KVM users. So unless someone _really_ wants a particular fix isolated for backporting, I'm not planning on shuffling patches.

v2:
- Collect reviews/acks.
- Reset eVMCS controls in VP assist page when disabling hardware. [Vitaly]
- Clean up labels in kvm_init(). [Chao]
- Fix a goof where VMX compat checks used boot_cpu_has. [Kai]
- Reorder patches and/or tweak changelogs to not require time travel. [Paolo, Kai]
- Rewrite the changelog for the patch to move ARM away from kvm_arch_init() to call out that it fixes theoretical bugs. [Philippe]
- Document why it's safe to allow preemption and/or migration when accessing kvm_usage_count.

v1: https://lore.kernel.org/all/20221102231911.3107438-1-seanjc at google.com

Chao Gao (3):
KVM: x86: Do compatibility checks when onlining CPU
KVM: Rename and move CPUHP_AP_KVM_STARTING to ONLINE section
KVM: Disable CPU hotplug during hardware enabling/disabling

Isaku Yamahata (3):
KVM: Drop kvm_count_lock and instead protect kvm_usage_count with
kvm_lock
KVM: Remove on_each_cpu(hardware_disable_nolock) in kvm_exit()
KVM: Make hardware_enable_failed a local variable in the "enable all"
path

Marc Zyngier (1):
KVM: arm64: Simplify the CPUHP logic

Sean Christopherson (43):
KVM: Register /dev/kvm as the _very_ last thing during initialization
KVM: Initialize IRQ FD after arch hardware setup
KVM: Allocate cpus_hardware_enabled after arch hardware setup
KVM: Teardown VFIO ops earlier in kvm_exit()
KVM: s390: Unwind kvm_arch_init() piece-by-piece() if a step fails
KVM: s390: Move hardware setup/unsetup to init/exit
KVM: x86: Do timer initialization after XCR0 configuration
KVM: x86: Move hardware setup/unsetup to init/exit
KVM: Drop arch hardware (un)setup hooks
KVM: VMX: Reset eVMCS controls in VP assist page during hardware
disabling
KVM: VMX: Don't bother disabling eVMCS static key on module exit
KVM: VMX: Move Hyper-V eVMCS initialization to helper
KVM: x86: Move guts of kvm_arch_init() to standalone helper
KVM: VMX: Do _all_ initialization before exposing /dev/kvm to
userspace
KVM: x86: Serialize vendor module initialization (hardware setup)
KVM: arm64: Free hypervisor allocations if vector slot init fails
KVM: arm64: Unregister perf callbacks if hypervisor finalization fails
KVM: arm64: Do arm/arch initialization without bouncing through

    kvm_init()
  KVM: arm64: Mark kvm_arm_init() and its unique descendants as __init
  KVM: MIPS: Hardcode callbacks to hardware virtualization extensions
  KVM: MIPS: Setup VZ emulation? directly from kvm_mips_init()
  KVM: MIPS: Register die notifier prior to kvm_init()
  KVM: RISC-V: Do arch init directly in riscv_kvm_init()
  KVM: RISC-V: Tag init functions and data with __init, __ro_after_init
  KVM: PPC: Move processor compatibility check to module init
  KVM: s390: Do s390 specific init without bouncing through kvm_init()
  KVM: s390: Mark __kvm_s390_init() and its descendants as __init
  KVM: Drop kvm_arch_{init,exit}() hooks
  KVM: VMX: Make VMCS configuration/capabilities structs read-only after
    init
  KVM: x86: Do CPU compatibility checks in x86 code
  KVM: Drop kvm_arch_check_processor_compat() hook
  KVM: x86: Use KBUILD_MODNAME to specify vendor module name
  KVM: x86: Unify pr_fmt to use module name for all KVM modules
  KVM: VMX: Use current CPU's info to perform "disabled by BIOS?" checks
  KVM: x86: Do VMX/SVM support checks directly in vendor code
  KVM: VMX: Shuffle support checks and hardware enabling code around
  KVM: SVM: Check for SVM support in CPU compatibility checks
  KVM: x86: Move CPU compat checks hook to kvm_x86_ops (from
    kvm_x86_init_ops)

KVM: Ensure CPU is stable during low level hardware enable/disable
KVM: Use a per-CPU variable to track which CPUs have enabled
virtualization
KVM: Register syscore (suspend/resume) ops early in kvm_init()
KVM: Opt out of generic hardware enabling on s390 and PPC
KVM: Clean up error labels in kvm_init()

 Documentation/virt/kvm/locking.rst  |  25 +-
 arch/arm64/include/asm/kvm_host.h   |  15 +-
 arch/arm64/include/asm/kvm_mmu.h    |   4 +-
 arch/arm64/kvm/Kconfig              |   1 +
 arch/arm64/kvm/arch_timer.c         |  29 +-
 arch/arm64/kvm/arm.c                |  93 +++---
 arch/arm64/kvm/mmu.c                |  12 +-
 arch/arm64/kvm/reset.c              |   8 +-
 arch/arm64/kvm/sys_regs.c           |   6 +-
 arch/arm64/kvm/vgic/vgic-init.c     |  19 +-
 arch/arm64/kvm/vmid.c               |   6 +-
 arch/mips/include/asm/kvm_host.h    |   3 +-
 arch/mips/kvm/Kconfig               |   1 +
 arch/mips/kvm/Makefile              |   2 +-
 arch/mips/kvm/callback.c            |  14 -
 arch/mips/kvm/mips.c                |  34 +--
 arch/mips/kvm/vz.c                  |   7 +-
 arch/powerpc/include/asm/kvm_host.h |   3 -
 arch/powerpc/include/asm/kvm_ppc.h  |   1 -
 arch/powerpc/kvm/book3s.c           |  12 +-
 arch/powerpc/kvm/e500.c             |   6 +-
 arch/powerpc/kvm/e500mc.c           |   6 +-
 arch/powerpc/kvm/powerpc.c          |  20 --
 arch/riscv/include/asm/kvm_host.h   |   7 +-
 arch/riscv/kvm/Kconfig              |   1 +
 arch/riscv/kvm/main.c               |  23 +-
 arch/riscv/kvm/mmu.c                |  12 +-
 arch/riscv/kvm/vmid.c               |   4 +-
 arch/s390/include/asm/kvm_host.h    |   1 -
 arch/s390/kvm/interrupt.c           |   2 +-
 arch/s390/kvm/kvm-s390.c            |  84 +++---
 arch/s390/kvm/kvm-s390.h            |   2 +-
 arch/s390/kvm/pci.c                 |   2 +-
 arch/s390/kvm/pci.h                 |   2 +-
 arch/x86/include/asm/kvm-x86-ops.h  |   1 +
 arch/x86/include/asm/kvm_host.h     |   8 +-
 arch/x86/kvm/Kconfig                |   1 +
 arch/x86/kvm/cpuid.c                |   1 +
 arch/x86/kvm/debugfs.c              |   2 +
 arch/x86/kvm/emulate.c              |   1 +
 arch/x86/kvm/hyperv.c               |   1 +
 arch/x86/kvm/i8254.c                |   4 +-
 arch/x86/kvm/i8259.c                |   4 +-
 arch/x86/kvm/ioapic.c               |   1 +
 arch/x86/kvm/irq.c                  |   1 +
 arch/x86/kvm/irq_comm.c             |   7 +-
 arch/x86/kvm/kvm_onhyperv.c         |   1 +
 arch/x86/kvm/lapic.c                |   8 +-
 arch/x86/kvm/mmu/mmu.c              |   6 +-
 arch/x86/kvm/mmu/page_track.c       |   1 +
 arch/x86/kvm/mmu/spte.c             |   4 +-
 arch/x86/kvm/mmu/spte.h             |   4 +-
 arch/x86/kvm/mmu/tdp_iter.c         |   1 +
 arch/x86/kvm/mmu/tdp_mmu.c          |   1 +
 arch/x86/kvm/mtrr.c                 |   1 +
 arch/x86/kvm/pmu.c                  |   1 +
 arch/x86/kvm/smm.c                  |   1 +
 arch/x86/kvm/svm/avic.c             |   2 +-
 arch/x86/kvm/svm/nested.c           |   2 +-
 arch/x86/kvm/svm/pmu.c              |   2 +
 arch/x86/kvm/svm/sev.c              |   1 +
 arch/x86/kvm/svm/svm.c              |  89 +++---
 arch/x86/kvm/svm/svm_onhyperv.c     |   1 +
 arch/x86/kvm/svm/svm_onhyperv.h     |   4 +-
 arch/x86/kvm/vmx/capabilities.h     |   4 +-
 arch/x86/kvm/vmx/hyperv.c           |   1 +
 arch/x86/kvm/vmx/hyperv.h           |   4 +-
 arch/x86/kvm/vmx/nested.c           |   3 +-
 arch/x86/kvm/vmx/pmu_intel.c        |   5 +-
 arch/x86/kvm/vmx/posted_intr.c      |   2 +
 arch/x86/kvm/vmx/sgx.c              |   5 +-
 arch/x86/kvm/vmx/vmcs12.c           |   1 +
 arch/x86/kvm/vmx/vmx.c              | 438 +++++++++++++++-------------
 arch/x86/kvm/vmx/vmx_ops.h          |   4 +-
 arch/x86/kvm/x86.c                  | 248 +++++++++-------
 arch/x86/kvm/xen.c                  |   1 +
 include/kvm/arm_arch_timer.h        |   6 +-
 include/kvm/arm_vgic.h              |   4 +
 include/linux/cpuhotplug.h          |   5 +-
 include/linux/kvm_host.h            |  13 +-
 virt/kvm/Kconfig                    |   3 +
 virt/kvm/kvm_main.c                 | 303 ++++++++++---------
 82 files changed, 863 insertions(+), 816 deletions(-)
 delete mode 100644 arch/mips/kvm/callback.c

base-commit: 3e04435fe60590a1c79ec94d60e9897c3ff7d73b

Signature · 1 line
2.38.1.584.g0f3c55d4c2-goog