KVM: vfio: Hide KVM internals from others
Sean Christopherson
maintainercover KVM: vfio: Hide KVM internals from others
This is a borderline RFC series to hide KVM's internals from the rest of the kernel, where "internals" means data structures, enums, #defines, APIs, etc. that are intended to be KVM-only, but are exposed everywhere due to kvm_host.h (and other headers) living in the global include paths.
The motiviation for hiding KVM's internals is to allow *safely* loading a "new" KVM module without having to reboot the host. Where "new" doesn't have to be strictly newer, just a different incarnation of KVM. Hiding KVM's internals means those assets can change across KVM instances without breaking things, e.g. would allow modifying the layout of struct kvm_vcpu to introduce new fields related to a new feature or mitigation for hardware bugs.
The end goal for all of this is to allow loading and running multiple instances of KVM (the module) simultaneously on a single host, e.g. to deploy fixes, mitigations, and/or new features without having to drain all VMs from the host.
For now, the immediate goal is to get KVM to a state where KVM x86 doesn't expose anything to the broader world that isn't intended for external consumption, e.g. the page write-tracking APIs used by KVM-GT.
I say this is borderline RFC because I don't think I've "formally" proposed the idea of hiding KVM internals before now. I decided not to tag this RFC because the changes ended up being not _that_ invasive, and everything before the last six patches is worthwhile even if hiding internals is ultimately rejected (IMO).
This would ideally be ~5 separate series, and I certainly have no objection if that's how we want to get this stuff merged. E.g. (1) VFIO cleanups,
(2) drop HAVE_KVM, (3) clean up makefiles, (4) x86 perf cleanup, and
(5) final push for hiding state. The HAVE_KVM and virt/kvm include stuff isn't strictly necessary, but I included them here because they're relatively minor (in the grand scheme).
We've explore several alternatives to the #ifdef __KVM__ approach, and they all sucked, hard. What I really wanted (and still want) to do, is to bury the bulk of kvm_host.h (and other KVM headers) in virt/kvm, but every attempt to do that ended in flames. Even with the __KVM__ guards in place, each architecture's kvm_host.h is too intertwined with the common kvm_host.h, and trying to extract small-ish pieces just doesn't work (each patch inevitably snowballed into a gigantic beast).
The other idea we considered (which I thought of, and feel dirty for even proposing it internally), is to move all headers under virt/kvm, add virt/kvm/include to the global header path, and then have KVM x86 omit virt/kvm/include when configured to hide KVM internals. I hate this idea because it sets a bad precedent, and requires a lot of file movement without providing any benefit to other architectures. E.g. I hope that guarding KVM internals with #ifdef __KVM__ will allow us to slowly clean things up so that some day KVM only exposes a handful of APIs to the rest of the kernel (probably a pipe dream).
Anish Ghulati (1):
KVM: arm64: Move arm_{psci,hypercalls}.h to an internal KVM path
Sean Christopherson (25):
vfio: Wrap KVM helpers with CONFIG_KVM instead of CONFIG_HAVE_KVM
vfio: Move KVM get/put helpers to colocate it with other KVM related
code
virt: Declare and define vfio_file_set_kvm() iff CONFIG_KVM is enabled
vfio: Add struct to hold KVM assets and dedup group vs. iommufd code
vfio: KVM: Pass get/put helpers from KVM to VFIO, don't do circular
lookup
KVM: Drop CONFIG_KVM_VFIO and just look at KVM+VFIO x86/idt: Wrap KVM logic with CONFIG_KVM instead of CONFIG_HAVE_KVM
KVM: x86: Stop selecting and depending on HAVE_KVM
KVM: arm64: Stop selecting and depending on HAVE_KVM
KVM: s390: Stop selecting and depending on HAVE_KVM
KVM: MIPS: Make HAVE_KVM a MIPS-only Kconfig
KVM: arm64: Include KVM headers to get forward declarations
KVM: arm64: Move ARM specific headers in include/kvm to arch directory
KVM: Move include/kvm/iodev.h to include/linux as kvm_iodev.h
KVM: MIPS: Stop adding virt/kvm to the arch include path
KVM: PPC: Stop adding virt/kvm to the arch include path
KVM: s390: Stop adding virt/kvm to the arch include path
KVM: Standardize include paths across all architectures perf/x86: KVM: Have perf define a dedicated struct for getting guest
PEBS data
entry/kvm: Drop @vcpu param from arch_xfer_to_guest_mode_handle_work() entry/kvm: KVM: Move KVM details related to signal/-EINTR into KVM
proper
KVM: arm64: Move and consolidate "public" functions in asm/kvm_host.h powerpc/xics: Move declaration of xics_wake_cpu() out of kvm_ppc.h
KVM: PPC: Rearrange code in kvm_ppc.h to isolate "public" information
KVM: Hide KVM internal data structures and values from kernel at-large
MAINTAINERS | 1 -
arch/arm64/Kconfig | 1 -
.../arm64/include/asm/kvm_arch_timer.h | 2 +
arch/arm64/include/asm/kvm_emulate.h | 3 +
arch/arm64/include/asm/kvm_host.h | 57 ++--
arch/arm64/include/asm/kvm_mmu.h | 4 +
.../arm64/include/asm/kvm_pmu.h | 2 +
.../arm64/include/asm/kvm_vgic.h | 2 +-
arch/arm64/kernel/asm-offsets.c | 2 +
arch/arm64/kvm/Kconfig | 2 -
arch/arm64/kvm/Makefile | 2 -
arch/arm64/kvm/arch_timer.c | 5 +-
arch/arm64/kvm/arm.c | 9 +-
{include => arch/arm64}/kvm/arm_hypercalls.h | 0
{include => arch/arm64}/kvm/arm_psci.h | 0
arch/arm64/kvm/guest.c | 2 +-
arch/arm64/kvm/handle_exit.c | 2 +-
arch/arm64/kvm/hyp/Makefile | 4 +-
arch/arm64/kvm/hyp/include/hyp/switch.h | 4 +-
arch/arm64/kvm/hyp/nvhe/Makefile | 3 +-
arch/arm64/kvm/hyp/nvhe/switch.c | 4 +-
arch/arm64/kvm/hyp/vhe/Makefile | 2 +-
arch/arm64/kvm/hyp/vhe/switch.c | 4 +-
arch/arm64/kvm/hypercalls.c | 4 +-
arch/arm64/kvm/pmu-emul.c | 6 +-
arch/arm64/kvm/psci.c | 4 +-
arch/arm64/kvm/pvtime.c | 2 +-
arch/arm64/kvm/reset.c | 3 +-
arch/arm64/kvm/trace_arm.h | 2 +-
arch/arm64/kvm/trng.c | 2 +-
arch/arm64/kvm/vgic/vgic-debug.c | 2 +-
arch/arm64/kvm/vgic/vgic-init.c | 2 +-
arch/arm64/kvm/vgic/vgic-irqfd.c | 2 +-
arch/arm64/kvm/vgic/vgic-kvm-device.c | 2 +-
arch/arm64/kvm/vgic/vgic-mmio-v2.c | 4 +-
arch/arm64/kvm/vgic/vgic-mmio-v3.c | 4 +-
arch/arm64/kvm/vgic/vgic-mmio.c | 6 +-
arch/arm64/kvm/vgic/vgic-v2.c | 2 +-
arch/arm64/kvm/vgic/vgic-v3.c | 2 +-
arch/mips/include/asm/kvm_host.h | 5 +-
arch/mips/kernel/asm-offsets.c | 2 +
arch/mips/kvm/Kconfig | 3 +
arch/mips/kvm/Makefile | 2 -
arch/powerpc/include/asm/kvm_book3s.h | 3 +
arch/powerpc/include/asm/kvm_book3s_64.h | 2 +
arch/powerpc/include/asm/kvm_booke.h | 4 +
arch/powerpc/include/asm/kvm_host.h | 7 +-
arch/powerpc/include/asm/kvm_ppc.h | 306 +++++++++---------
arch/powerpc/include/asm/xics.h | 3 +
arch/powerpc/kernel/asm-offsets.c | 1 +
arch/powerpc/kvm/Kconfig | 1 -
arch/powerpc/kvm/Makefile | 2 -
arch/powerpc/kvm/mpic.c | 2 +-
arch/riscv/include/asm/kvm_host.h | 3 +
arch/riscv/kernel/asm-offsets.c | 1 +
arch/riscv/kvm/Makefile | 2 -
arch/riscv/kvm/aia_aplic.c | 2 +-
arch/riscv/kvm/aia_imsic.c | 2 +-
arch/riscv/kvm/vcpu.c | 2 +-
arch/s390/Kconfig | 1 -
arch/s390/include/asm/kvm_host.h | 7 +-
arch/s390/kernel/asm-offsets.c | 1 +
arch/s390/kvm/Kconfig | 2 -
arch/s390/kvm/Makefile | 2 -
arch/x86/Kconfig | 1 -
arch/x86/events/core.c | 5 +-
arch/x86/events/intel/core.c | 18 +-
arch/x86/events/perf_event.h | 3 +-
arch/x86/include/asm/hardirq.h | 2 +-
arch/x86/include/asm/idtentry.h | 2 +-
arch/x86/include/asm/irq.h | 2 +-
arch/x86/include/asm/irq_vectors.h | 2 +-
arch/x86/include/asm/kvm_host.h | 12 +-
arch/x86/include/asm/perf_event.h | 12 +-
arch/x86/kernel/idt.c | 2 +-
arch/x86/kernel/irq.c | 4 +-
arch/x86/kvm/Kconfig | 3 -
arch/x86/kvm/Makefile | 1 -
arch/x86/kvm/i8254.h | 2 +-
arch/x86/kvm/ioapic.h | 2 +-
arch/x86/kvm/irq.h | 2 +-
arch/x86/kvm/lapic.h | 2 +-
arch/x86/kvm/vmx/pmu_intel.c | 16 +-
arch/x86/kvm/vmx/vmx.c | 11 +-
arch/x86/kvm/vmx/vmx.h | 2 +-
arch/x86/kvm/x86.c | 3 +-
drivers/s390/crypto/vfio_ap_drv.c | 1 +
drivers/s390/crypto/vfio_ap_ops.c | 2 +
drivers/vfio/device_cdev.c | 9 +-
drivers/vfio/group.c | 18 +-
drivers/vfio/vfio.h | 26 +-
drivers/vfio/vfio_main.c | 139 ++++----
include/linux/entry-kvm.h | 10 +-
include/linux/kvm_host.h | 17 +-
include/{kvm/iodev.h => linux/kvm_iodev.h} | 0
include/linux/kvm_types.h | 3 +
include/linux/vfio.h | 6 +-
include/trace/events/kvm.h | 5 +
kernel/entry/kvm.c | 13 +-
scripts/gdb/linux/constants.py.in | 2 +-
scripts/gdb/linux/interrupts.py | 2 +-
tools/arch/x86/include/asm/irq_vectors.h | 2 +-
virt/kvm/Kconfig | 6 -
virt/kvm/Makefile.kvm | 6 +-
virt/kvm/coalesced_mmio.c | 3 +-
virt/kvm/eventfd.c | 2 +-
virt/kvm/kvm_main.c | 3 +-
virt/kvm/vfio.c | 9 +-
virt/kvm/vfio.h | 2 +-
109 files changed, 489 insertions(+), 440 deletions(-)
rename include/kvm/arm_arch_timer.h => arch/arm64/include/asm/kvm_arch_timer.h (98%)
rename include/kvm/arm_pmu.h => arch/arm64/include/asm/kvm_pmu.h (99%)
rename include/kvm/arm_vgic.h => arch/arm64/include/asm/kvm_vgic.h (99%)
rename {include => arch/arm64}/kvm/arm_hypercalls.h (100%)
rename {include => arch/arm64}/kvm/arm_psci.h (100%)
rename include/{kvm/iodev.h => linux/kvm_iodev.h} (100%)base-commit: 0bb80ecc33a8fb5a682236443c1e740d5c917d1d
Signature · 1 line
2.42.0.459.ge4e396fd5e-goog
Sean Christopherson
maintainerPATCH 1/26 vfio: Wrap KVM helpers with CONFIG_KVM instead of CONFIG_HAVE_KVM
Wrap the helpers for getting references to KVM instances with a check on CONFIG_KVM being enabled, not on CONFIG_HAVE_KVM being defined. PPC does NOT select HAVE_KVM, despite obviously supporting KVM, and guarding code to get references to KVM based on whether or not the architecture supports KVM is nonsensical.
Drop the guard around linux/kvm_host.h entirely, conditionally including a generic headers is completely unnecessary.
--- drivers/vfio/vfio.h | 2 +- drivers/vfio/vfio_main.c | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-)
drivers/vfio/vfio.h +1 -1
@@ -434,7 +434,7 @@ static inline void vfio_virqfd_exit(void) }#endif -#ifdef CONFIG_HAVE_KVM +#if IS_ENABLED (CONFIG_KVM )void vfio_device_get_kvm_safe (struct vfio_device *device,struct kvm *kvm);void vfio_device_put_kvm (struct vfio_device *device);#else
drivers/vfio/vfio_main.c +1 -3
@@ -16,9 +16,7 @@#include <linux/fs.h> #include <linux/idr.h> #include <linux/iommu.h> -#ifdef CONFIG_HAVE_KVM #include <linux/kvm_host.h> -#endif #include <linux/list.h> #include <linux/miscdevice.h> #include <linux/module.h>
@@ -383,7 +381,7 @@ void vfio_unregister_group_dev(struct vfio_device *device) }EXPORT_SYMBOL_GPL (vfio_unregister_group_dev); -#ifdef CONFIG_HAVE_KVM +#if IS_ENABLED (CONFIG_KVM )void vfio_device_get_kvm_safe (struct vfio_device *device,struct kvm *kvm) {void (*pfn)(struct kvm *kvm);
Signature · 1 line
2.42.0.459.ge4e396fd5e-goog
Re: [PATCH 01/26] vfio: Wrap KVM helpers with CONFIG_KVM instead of CONFIG_HAVE_KVM
Quoted 6 lines · Sean Christopherson
Wrap the helpers for getting references to KVM instances with a check on
CONFIG_KVMbeing enabled, not onCONFIG_HAVE_KVMbeing defined. PPC does NOT selectHAVE_KVM, despite obviously supporting KVM, and guarding code to get references to KVM based on whether or not the architecture supports KVM is nonsensical.
Quoted 8 lines
Drop the guard around
linux/kvm_host.hentirely, conditionally including a generic headers is completely unnecessary.Signed-off-by Sean Christopherson <[email protected]>--- drivers/vfio/vfio.h | 2 +- drivers/vfio/vfio_main.c | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-)
Jason
Re: [PATCH 01/26] vfio: Wrap KVM helpers with CONFIG_KVM instead of CONFIG_HAVE_KVM
In reply to Sean ChristophersonQuoted 6 lines · On Fri, 15 Sep 2023 17:30:53 -0700 Sean Christopherson <[email protected]>…
Wrap the helpers for getting references to KVM instances with a check on
CONFIG_KVMbeing enabled, not onCONFIG_HAVE_KVMbeing defined. PPC does NOT selectHAVE_KVM, despite obviously supporting KVM, and guarding code to get references to KVM based on whether or not the architecture supports KVM is nonsensical.
Quoted 8 lines
Drop the guard around
linux/kvm_host.hentirely, conditionally including a generic headers is completely unnecessary.Signed-off-by Sean Christopherson <[email protected]>--- drivers/vfio/vfio.h | 2 +- drivers/vfio/vfio_main.c | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-)
Quoted 36 lines
drivers/vfio/vfio.h +1
-1@@ -434,7 +434,7 @@ static inline void vfio_virqfd_exit(void) }#endif -#ifdef CONFIG_HAVE_KVM +#if IS_ENABLED (CONFIG_KVM )void vfio_device_get_kvm_safe (struct vfio_device *device,struct kvm *kvm);void vfio_device_put_kvm (struct vfio_device *device);#else drivers/vfio/vfio_main.c +1
-3@@ -16,9 +16,7 @@#include <linux/fs.h> #include <linux/idr.h> #include <linux/iommu.h> -#ifdef CONFIG_HAVE_KVM #include <linux/kvm_host.h> -#endif #include <linux/list.h> #include <linux/miscdevice.h> #include <linux/module.h> @@ -383,7 +381,7 @@ void vfio_unregister_group_dev(struct vfio_device *device) }EXPORT_SYMBOL_GPL (vfio_unregister_group_dev); -#ifdef CONFIG_HAVE_KVM +#if IS_ENABLED (CONFIG_KVM )void vfio_device_get_kvm_safe (struct vfio_device *device,struct kvm *kvm) {void (*pfn)(struct kvm *kvm);
Sean Christopherson
maintainerPATCH 2/26 vfio: Move KVM get/put helpers to colocate it with other KVM related code
In reply to Sean ChristophersonMove the definitions of vfio_device_get_kvm_safe() and vfio_device_put_kvm() down in vfio_main.c to colocate them with other KVM-specific functions, e.g. to allow wrapping them all with a single CONFIG_KVM check.
--- drivers/vfio/vfio_main.c | 104 +++++++++++++++++++-------------------- 1 file changed, 52 insertions(+), 52 deletions(-)
drivers/vfio/vfio_main.c +52 -52
@@ -381,58 +381,6 @@ void vfio_unregister_group_dev(struct vfio_device *device) }EXPORT_SYMBOL_GPL (vfio_unregister_group_dev); -#if IS_ENABLED (CONFIG_KVM ) -void vfio_device_get_kvm_safe (struct vfio_device *device,struct kvm *kvm) -{ -void (*pfn)(struct kvm *kvm); -bool (*fn)(struct kvm *kvm); -bool ret; - -lockdep_assert_held (&device->dev_set->lock); - -if (!kvm) -return ; - - pfn =symbol_get (kvm_put_kvm); -if (WARN_ON (!pfn)) -return ; - - fn =symbol_get (kvm_get_kvm_safe); -if (WARN_ON (!fn)) { -symbol_put (kvm_put_kvm); -return ; - } - - ret =fn (kvm); -symbol_put (kvm_get_kvm_safe); -if (!ret) { -symbol_put (kvm_put_kvm); -return ; - } - - device->put_kvm = pfn; - device->kvm = kvm; -} - -void vfio_device_put_kvm (struct vfio_device *device) -{ -lockdep_assert_held (&device->dev_set->lock); - -if (!device->kvm) -return ; - -if (WARN_ON (!device->put_kvm)) - goto clear; - - device->put_kvm (device->kvm); - device->put_kvm =NULL ; -symbol_put (kvm_put_kvm); - -clear: - device->kvm =NULL ; -} -#endif -/* true if the vfio_device has open_device() called but not close_device() */ static bool vfio_assert_device_open (struct vfio_device *device) {
@@ -1354,6 +1302,58 @@ bool vfio_file_enforced_coherent(struct file *file) }EXPORT_SYMBOL_GPL (vfio_file_enforced_coherent); +#if IS_ENABLED (CONFIG_KVM ) +void vfio_device_get_kvm_safe (struct vfio_device *device,struct kvm *kvm) +{ +void (*pfn)(struct kvm *kvm); +bool (*fn)(struct kvm *kvm); +bool ret; + +lockdep_assert_held (&device->dev_set->lock); + +if (!kvm) +return ; + + pfn =symbol_get (kvm_put_kvm); +if (WARN_ON (!pfn)) +return ; + + fn =symbol_get (kvm_get_kvm_safe); +if (WARN_ON (!fn)) { +symbol_put (kvm_put_kvm); +return ; + } + + ret =fn (kvm); +symbol_put (kvm_get_kvm_safe); +if (!ret) { +symbol_put (kvm_put_kvm); +return ; + } + + device->put_kvm = pfn; + device->kvm = kvm; +} + +void vfio_device_put_kvm (struct vfio_device *device) +{ +lockdep_assert_held (&device->dev_set->lock); + +if (!device->kvm) +return ; + +if (WARN_ON (!device->put_kvm)) + goto clear; + + device->put_kvm (device->kvm); + device->put_kvm =NULL ; +symbol_put (kvm_put_kvm); + +clear: + device->kvm =NULL ; +} +#endif +static void vfio_device_file_set_kvm (struct file *file,struct kvm *kvm) {struct vfio_device_file *df = file->private_data;
Signature · 1 line
2.42.0.459.ge4e396fd5e-goog
Re: [PATCH 02/26] vfio: Move KVM get/put helpers to colocate it with other KVM related code
Quoted 8 lines · Sean Christopherson
Move the definitions of
vfio_device_get_kvm_safe()andvfio_device_put_kvm()down invfio_main.cto colocate them with other KVM-specific functions, e.g. to allow wrapping them all with a singleCONFIG_KVMcheck.Signed-off-by Sean Christopherson <[email protected]>--- drivers/vfio/vfio_main.c | 104 +++++++++++++++++++-------------------- 1 file changed, 52 insertions(+), 52 deletions(-)
Jason
Re: [PATCH 02/26] vfio: Move KVM get/put helpers to colocate it with other KVM related code
In reply to Sean ChristophersonQuoted 8 lines · On Fri, 15 Sep 2023 17:30:54 -0700 Sean Christopherson <[email protected]>…
Move the definitions of
vfio_device_get_kvm_safe()andvfio_device_put_kvm()down invfio_main.cto colocate them with other KVM-specific functions, e.g. to allow wrapping them all with a singleCONFIG_KVMcheck.Signed-off-by Sean Christopherson <[email protected]>--- drivers/vfio/vfio_main.c | 104 +++++++++++++++++++-------------------- 1 file changed, 52 insertions(+), 52 deletions(-)
Quoted 122 lines
drivers/vfio/vfio_main.c +52
-52@@ -381,58 +381,6 @@ void vfio_unregister_group_dev(struct vfio_device *device) }EXPORT_SYMBOL_GPL (vfio_unregister_group_dev); -#if IS_ENABLED (CONFIG_KVM ) -void vfio_device_get_kvm_safe (struct vfio_device *device,struct kvm *kvm) -{ -void (*pfn)(struct kvm *kvm); -bool (*fn)(struct kvm *kvm); -bool ret; - -lockdep_assert_held (&device->dev_set->lock); - -if (!kvm) -return ; - - pfn =symbol_get (kvm_put_kvm); -if (WARN_ON (!pfn)) -return ; - - fn =symbol_get (kvm_get_kvm_safe); -if (WARN_ON (!fn)) { -symbol_put (kvm_put_kvm); -return ; - } - - ret =fn (kvm); -symbol_put (kvm_get_kvm_safe); -if (!ret) { -symbol_put (kvm_put_kvm); -return ; - } - - device->put_kvm = pfn; - device->kvm = kvm; -} - -void vfio_device_put_kvm (struct vfio_device *device) -{ -lockdep_assert_held (&device->dev_set->lock); - -if (!device->kvm) -return ; - -if (WARN_ON (!device->put_kvm)) - goto clear; - - device->put_kvm (device->kvm); - device->put_kvm =NULL ; -symbol_put (kvm_put_kvm); - -clear: - device->kvm =NULL ; -} -#endif -/* true if the vfio_device has open_device() called but not close_device() */ static bool vfio_assert_device_open (struct vfio_device *device) {@@ -1354,6 +1302,58 @@ bool vfio_file_enforced_coherent(struct file *file) }EXPORT_SYMBOL_GPL (vfio_file_enforced_coherent); +#if IS_ENABLED (CONFIG_KVM ) +void vfio_device_get_kvm_safe (struct vfio_device *device,struct kvm *kvm) +{ +void (*pfn)(struct kvm *kvm); +bool (*fn)(struct kvm *kvm); +bool ret; + +lockdep_assert_held (&device->dev_set->lock); + +if (!kvm) +return ; + + pfn =symbol_get (kvm_put_kvm); +if (WARN_ON (!pfn)) +return ; + + fn =symbol_get (kvm_get_kvm_safe); +if (WARN_ON (!fn)) { +symbol_put (kvm_put_kvm); +return ; + } + + ret =fn (kvm); +symbol_put (kvm_get_kvm_safe); +if (!ret) { +symbol_put (kvm_put_kvm); +return ; + } + + device->put_kvm = pfn; + device->kvm = kvm; +} + +void vfio_device_put_kvm (struct vfio_device *device) +{ +lockdep_assert_held (&device->dev_set->lock); + +if (!device->kvm) +return ; + +if (WARN_ON (!device->put_kvm)) + goto clear; + + device->put_kvm (device->kvm); + device->put_kvm =NULL ; +symbol_put (kvm_put_kvm); + +clear: + device->kvm =NULL ; +} +#endif +static void vfio_device_file_set_kvm (struct file *file,struct kvm *kvm) {struct vfio_device_file *df = file->private_data;
Sean Christopherson
maintainerPATCH 3/26 virt: Declare and define vfio_file_set_kvm() iff CONFIG_KVM is enabled
In reply to Sean ChristophersonHide vfio_file_set_kvm() and its unique helpers if KVM is not enabled, nothing else in the kernel (or out of the kernel) should be using a KVM specific helper.
--- drivers/vfio/vfio_main.c | 2 +- include/linux/vfio.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-)
drivers/vfio/vfio_main.c +1 -1
@@ -1352,7 +1352,6 @@ void vfio_device_put_kvm(struct vfio_device *device) clear: device->kvm =NULL ; } -#endif static void vfio_device_file_set_kvm (struct file *file,struct kvm *kvm) {
@@ -1388,6 +1387,7 @@ void vfio_file_set_kvm(struct file *file, struct kvm *kvm) vfio_device_file_set_kvm(file, kvm); }EXPORT_SYMBOL_GPL (vfio_file_set_kvm); +#endif /* * Sub-module support
include/linux/vfio.h +2 -0
@@ -311,7 +311,9 @@ static inline bool vfio_file_has_dev(struct file *file, struct vfio_device *devi#endif bool vfio_file_is_valid (struct file *file);bool vfio_file_enforced_coherent (struct file *file); +#if IS_ENABLED (CONFIG_KVM )void vfio_file_set_kvm (struct file *file,struct kvm *kvm); +#endif #define VFIO_PIN_PAGES_MAX_ENTRIES (PAGE_SIZE/sizeof(unsigned long))
Signature · 1 line
2.42.0.459.ge4e396fd5e-goog
Re: [PATCH 03/26] virt: Declare and define vfio_file_set_kvm() iff CONFIG_KVM is enabled
Quoted 9 lines · Sean Christopherson
Hide
vfio_file_set_kvm()and its unique helpers if KVM is not enabled, nothing else in the kernel (or out of the kernel) should be using a KVM specific helper.Signed-off-by Sean Christopherson <[email protected]>--- drivers/vfio/vfio_main.c | 2 +- include/linux/vfio.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-)
Patch subject should be vfio not virt
drivers/vfio/vfio_main.c void vfio_file_set_kvm(struct file *file, struct kvm *kvm) · line 1390
Quoted 5 lines
drivers/vfio/vfio_main.c +1
-0@@ -1388,6 +1387,7 @@ void vfio_file_set_kvm(struct file *file, struct kvm *kvm) vfio_device_file_set_kvm(file, kvm); }EXPORT_SYMBOL_GPL (vfio_file_set_kvm); +#endif
We could even put this in a symbol namespace..
Jason
Re: [PATCH 03/26] virt: Declare and define vfio_file_set_kvm() iff CONFIG_KVM is enabled
In reply to Sean ChristophersonQuoted 9 lines · On Fri, 15 Sep 2023 17:30:55 -0700 Sean Christopherson <[email protected]>…
Hide
vfio_file_set_kvm()and its unique helpers if KVM is not enabled, nothing else in the kernel (or out of the kernel) should be using a KVM specific helper.Signed-off-by Sean Christopherson <[email protected]>--- drivers/vfio/vfio_main.c | 2 +- include/linux/vfio.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-)
As Jason noted, s/virt/vfio/ in title.
Quoted 34 lines
drivers/vfio/vfio_main.c +1
-1@@ -1352,7 +1352,6 @@ void vfio_device_put_kvm(struct vfio_device *device) clear: device->kvm =NULL ; } -#endif static void vfio_device_file_set_kvm (struct file *file,struct kvm *kvm) {@@ -1388,6 +1387,7 @@ void vfio_file_set_kvm(struct file *file, struct kvm *kvm) vfio_device_file_set_kvm(file, kvm); }EXPORT_SYMBOL_GPL (vfio_file_set_kvm); +#endif /* * Sub-module support include/linux/vfio.h +2
-0@@ -311,7 +311,9 @@ static inline bool vfio_file_has_dev(struct file *file, struct vfio_device *devi#endif bool vfio_file_is_valid (struct file *file);bool vfio_file_enforced_coherent (struct file *file); +#if IS_ENABLED (CONFIG_KVM )void vfio_file_set_kvm (struct file *file,struct kvm *kvm); +#endif #define VFIO_PIN_PAGES_MAX_ENTRIES (PAGE_SIZE/sizeof(unsigned long))
Sean Christopherson
maintainerPATCH 4/26 vfio: Add struct to hold KVM assets and dedup group vs. iommufd code
In reply to Sean ChristophersonAdd a struct to hold the KVM assets need to manage and pass along KVM references to VFIO devices. Providing a common struct deduplicates the group vs. iommufd code, and will make it easier to rework the attachment logic so that VFIO doesn't have to do a symbol lookup to retrieve the get/put helpers from KVM.
--- drivers/vfio/device_cdev.c | 9 +------- drivers/vfio/group.c | 18 ++-------------- drivers/vfio/vfio.h | 22 +++++++++---------- drivers/vfio/vfio_main.c | 43 +++++++++++++++++++++++++++----------- 4 files changed, 45 insertions(+), 47 deletions(-)
drivers/vfio/device_cdev.c +1 -8
@@ -46,13 +46,6 @@ int vfio_device_fops_cdev_open(struct inode *inode, struct file *filep)return ret; } -static void vfio_df_get_kvm_safe (struct vfio_device_file *df) -{ -spin_lock (&df->kvm_ref_lock); -vfio_device_get_kvm_safe (df->device, df->kvm); -spin_unlock (&df->kvm_ref_lock); -} -long vfio_df_ioctl_bind_iommufd (struct vfio_device_file *df,struct vfio_device_bind_iommufd __user *arg) {
@@ -99,7 +92,7 @@ long vfio_df_ioctl_bind_iommufd(struct vfio_device_file *df,* a reference. This reference is held until device closed. * Save the pointer in the device for use by drivers. */ -vfio_df_get_kvm_safe (df); +vfio_device_get_kvm_safe (df->device, &df->kvm_ref); ret =vfio_df_open (df);if (ret)
drivers/vfio/group.c +2 -16
@@ -157,13 +157,6 @@ static int vfio_group_ioctl_set_container(struct vfio_group *group,return ret; } -static void vfio_device_group_get_kvm_safe (struct vfio_device *device) -{ -spin_lock (&device->group->kvm_ref_lock); -vfio_device_get_kvm_safe (device, device->group->kvm); -spin_unlock (&device->group->kvm_ref_lock); -} -static int vfio_df_group_open (struct vfio_device_file *df) {struct vfio_device *device = df->device;
@@ -184,7 +177,7 @@ static int vfio_df_group_open(struct vfio_device_file *df)* the pointer in the device for use by drivers. */ if (device->open_count ==0 ) -vfio_device_group_get_kvm_safe (device); +vfio_device_get_kvm_safe (device, &device->group->kvm_ref); df->iommufd = device->group->iommufd;if (df->iommufd &&vfio_device_is_noiommu (device) && device->open_count ==0 ) {
@@ -560,7 +553,7 @@ static struct vfio_group *vfio_group_alloc(struct iommu_group *iommu_group,refcount_set (&group->drivers,1 );mutex_init (&group->group_lock); -spin_lock_init (&group->kvm_ref_lock); +spin_lock_init (&group->kvm_ref.lock);INIT_LIST_HEAD (&group->device_list);mutex_init (&group->device_lock); group->iommu_group = iommu_group;
@@ -884,13 +877,6 @@ bool vfio_group_enforced_coherent(struct vfio_group *group)return ret; } -void vfio_group_set_kvm (struct vfio_group *group,struct kvm *kvm) -{ -spin_lock (&group->kvm_ref_lock); - group->kvm = kvm; -spin_unlock (&group->kvm_ref_lock); -} -/** * vfio_file_has_dev - True if the VFIO file is a handle for device * @file: VFIO file to check
drivers/vfio/vfio.h +11 -11
@@ -12,18 +12,23 @@#include <linux/module.h> #include <linux/vfio.h> +struct kvm ;struct iommufd_ctx ;struct iommu_group ;struct vfio_container ; +struct vfio_kvm_reference { +struct kvm *kvm; +spinlock_t lock; +}; +struct vfio_device_file {struct vfio_device *device;struct vfio_group *group;u8 access_granted;u32 devid;/* only valid when iommufd is valid */ -spinlock_t kvm_ref_lock;/* protect kvm field */ -struct kvm *kvm; +struct vfio_kvm_reference kvm_ref;struct iommufd_ctx *iommufd;/* protected by struct vfio_device_set::lock */ };
@@ -88,11 +93,10 @@ struct vfio_group {#endif enum vfio_group_type type;struct mutex group_lock; -struct kvm *kvm; +struct vfio_kvm_reference kvm_ref;struct file *opened_file;struct blocking_notifier_head notifier;struct iommufd_ctx *iommufd; -spinlock_t kvm_ref_lock;unsigned int cdev_device_open_cnt; };
@@ -108,7 +112,6 @@ void vfio_device_group_unuse_iommu(struct vfio_device *device);void vfio_df_group_close (struct vfio_device_file *df);struct vfio_group *vfio_group_from_file (struct file *file);bool vfio_group_enforced_coherent (struct vfio_group *group); -void vfio_group_set_kvm (struct vfio_group *group,struct kvm *kvm);bool vfio_device_has_container (struct vfio_device *device);int __init vfio_group_init (void );void vfio_group_cleanup (void );
@@ -171,10 +174,6 @@ static inline bool vfio_group_enforced_coherent(struct vfio_group *group)return true; } -static inline void vfio_group_set_kvm (struct vfio_group *group,struct kvm *kvm) -{ -} -static inline bool vfio_device_has_container (struct vfio_device *device) {return false;
@@ -435,11 +434,12 @@ static inline void vfio_virqfd_exit(void)#endif #if IS_ENABLED (CONFIG_KVM ) -void vfio_device_get_kvm_safe (struct vfio_device *device,struct kvm *kvm); +void vfio_device_get_kvm_safe (struct vfio_device *device, +struct vfio_kvm_reference *ref);void vfio_device_put_kvm (struct vfio_device *device);#else static inline void vfio_device_get_kvm_safe (struct vfio_device *device, -struct kvm *kvm) +struct vfio_kvm_reference *ref) { }
drivers/vfio/vfio_main.c +31 -12
88 lines not on this page · raw message
Signature · 1 line
2.42.0.459.ge4e396fd5e-goog
Re: [PATCH 04/26] vfio: Add struct to hold KVM assets and dedup group vs. iommufd code
Quoted 6 lines · On Fri, 15 Sep 2023 17:30:56 -0700 Sean Christopherson <[email protected]>…
Add a struct to hold the KVM assets need to manage and pass along KVM references to VFIO devices. Providing a common struct deduplicates the group vs. iommufd code, and will make it easier to rework the attachment logic so that VFIO doesn't have to do a symbol lookup to retrieve the get/put helpers from KVM.
Quoted 7 lines
Signed-off-by Sean Christopherson <[email protected]>--- drivers/vfio/device_cdev.c | 9 +------- drivers/vfio/group.c | 18 ++-------------- drivers/vfio/vfio.h | 22 +++++++++---------- drivers/vfio/vfio_main.c | 43 +++++++++++++++++++++++++++----------- 4 files changed, 45 insertions(+), 47 deletions(-)
Quoted 251 lines
drivers/vfio/device_cdev.c +1
-8@@ -46,13 +46,6 @@ int vfio_device_fops_cdev_open(struct inode *inode, struct file *filep)return ret; } -static void vfio_df_get_kvm_safe (struct vfio_device_file *df) -{ -spin_lock (&df->kvm_ref_lock); -vfio_device_get_kvm_safe (df->device, df->kvm); -spin_unlock (&df->kvm_ref_lock); -} -long vfio_df_ioctl_bind_iommufd (struct vfio_device_file *df,struct vfio_device_bind_iommufd __user *arg) {@@ -99,7 +92,7 @@ long vfio_df_ioctl_bind_iommufd(struct vfio_device_file *df,* a reference. This reference is held until device closed. * Save the pointer in the device for use by drivers. */ -vfio_df_get_kvm_safe (df); +vfio_device_get_kvm_safe (df->device, &df->kvm_ref); ret =vfio_df_open (df);if (ret)drivers/vfio/group.c +2
-16@@ -157,13 +157,6 @@ static int vfio_group_ioctl_set_container(struct vfio_group *group,return ret; } -static void vfio_device_group_get_kvm_safe (struct vfio_device *device) -{ -spin_lock (&device->group->kvm_ref_lock); -vfio_device_get_kvm_safe (device, device->group->kvm); -spin_unlock (&device->group->kvm_ref_lock); -} -static int vfio_df_group_open (struct vfio_device_file *df) {struct vfio_device *device = df->device;@@ -184,7 +177,7 @@ static int vfio_df_group_open(struct vfio_device_file *df)* the pointer in the device for use by drivers. */ if (device->open_count ==0 ) -vfio_device_group_get_kvm_safe (device); +vfio_device_get_kvm_safe (device, &device->group->kvm_ref); df->iommufd = device->group->iommufd;if (df->iommufd &&vfio_device_is_noiommu (device) && device->open_count ==0 ) {@@ -560,7 +553,7 @@ static struct vfio_group *vfio_group_alloc(struct iommu_group *iommu_group,refcount_set (&group->drivers,1 );mutex_init (&group->group_lock); -spin_lock_init (&group->kvm_ref_lock); +spin_lock_init (&group->kvm_ref.lock);INIT_LIST_HEAD (&group->device_list);mutex_init (&group->device_lock); group->iommu_group = iommu_group;@@ -884,13 +877,6 @@ bool vfio_group_enforced_coherent(struct vfio_group *group)return ret; } -void vfio_group_set_kvm (struct vfio_group *group,struct kvm *kvm) -{ -spin_lock (&group->kvm_ref_lock); - group->kvm = kvm; -spin_unlock (&group->kvm_ref_lock); -} -/** * vfio_file_has_dev - True if the VFIO file is a handle for device * @file: VFIO file to check drivers/vfio/vfio.h +11
-11@@ -12,18 +12,23 @@#include <linux/module.h> #include <linux/vfio.h> +struct kvm ;struct iommufd_ctx ;struct iommu_group ;struct vfio_container ; +struct vfio_kvm_reference { +struct kvm *kvm; +spinlock_t lock; +}; +struct vfio_device_file {struct vfio_device *device;struct vfio_group *group;u8 access_granted;u32 devid;/* only valid when iommufd is valid */ -spinlock_t kvm_ref_lock;/* protect kvm field */ -struct kvm *kvm; +struct vfio_kvm_reference kvm_ref;struct iommufd_ctx *iommufd;/* protected by struct vfio_device_set::lock */ };@@ -88,11 +93,10 @@ struct vfio_group {#endif enum vfio_group_type type;struct mutex group_lock; -struct kvm *kvm; +struct vfio_kvm_reference kvm_ref;struct file *opened_file;struct blocking_notifier_head notifier;struct iommufd_ctx *iommufd; -spinlock_t kvm_ref_lock;unsigned int cdev_device_open_cnt; };@@ -108,7 +112,6 @@ void vfio_device_group_unuse_iommu(struct vfio_device *device);void vfio_df_group_close (struct vfio_device_file *df);struct vfio_group *vfio_group_from_file (struct file *file);bool vfio_group_enforced_coherent (struct vfio_group *group); -void vfio_group_set_kvm (struct vfio_group *group,struct kvm *kvm);bool vfio_device_has_container (struct vfio_device *device);int __init vfio_group_init (void );void vfio_group_cleanup (void );@@ -171,10 +174,6 @@ static inline bool vfio_group_enforced_coherent(struct vfio_group *group)return true; } -static inline void vfio_group_set_kvm (struct vfio_group *group,struct kvm *kvm) -{ -} -static inline bool vfio_device_has_container (struct vfio_device *device) {return false;@@ -435,11 +434,12 @@ static inline void vfio_virqfd_exit(void)#endif #if IS_ENABLED (CONFIG_KVM ) -void vfio_device_get_kvm_safe (struct vfio_device *device,struct kvm *kvm); +void vfio_device_get_kvm_safe (struct vfio_device *device, +struct vfio_kvm_reference *ref);void vfio_device_put_kvm (struct vfio_device *device);#else static inline void vfio_device_get_kvm_safe (struct vfio_device *device, -struct kvm *kvm) +struct vfio_kvm_reference *ref) { }drivers/vfio/vfio_main.c +31
-12@@ -397,7 +397,7 @@ vfio_allocate_device_file(struct vfio_device *device)return ERR_PTR (-ENOMEM ); df->device = device; -spin_lock_init (&df->kvm_ref_lock); +spin_lock_init (&df->kvm_ref.lock);return df; }@@ -1303,7 +1303,8 @@ bool vfio_file_enforced_coherent(struct file *file)EXPORT_SYMBOL_GPL (vfio_file_enforced_coherent);#if IS_ENABLED (CONFIG_KVM ) -void vfio_device_get_kvm_safe (struct vfio_device *device,struct kvm *kvm) +void vfio_device_get_kvm_safe (struct vfio_device *device, +struct vfio_kvm_reference *ref) {void (*pfn)(struct kvm *kvm);bool (*fn)(struct kvm *kvm);@@ -1311,28 +1312,33 @@ void vfio_device_get_kvm_safe(struct vfio_device *device, struct kvm *kvm)lockdep_assert_held (&device->dev_set->lock); -if (!kvm) -return ; +spin_lock (&ref->lock); + +if (!ref->kvm) + goto out; pfn =symbol_get (kvm_put_kvm);if (WARN_ON (!pfn)) -return ; + goto out; fn =symbol_get (kvm_get_kvm_safe);if (WARN_ON (!fn)) {symbol_put (kvm_put_kvm); -return ; + goto out; } - ret =fn (kvm); + ret =fn (ref->kvm);symbol_put (kvm_get_kvm_safe);if (!ret) {symbol_put (kvm_put_kvm); -return ; + goto out; } device->put_kvm = pfn; - device->kvm = kvm; + device->kvm = ref->kvm; + +out: +spin_unlock (&ref->lock); }void vfio_device_put_kvm (struct vfio_device *device)@@ -1353,6 +1359,21 @@ void vfio_device_put_kvm(struct vfio_device *device) device->kvm =NULL ; } +static void vfio_device_set_kvm (struct vfio_kvm_reference *ref, +struct kvm *kvm) +{ +spin_lock (&ref->lock); + ref->kvm = kvm; +spin_unlock (&ref->lock); +} + +static void vfio_group_set_kvm (struct vfio_group *group,struct kvm *kvm) +{ +#if IS_ENABLED (CONFIG_VFIO_GROUP ) +vfio_device_set_kvm (&group->kvm_ref, kvm); +#endif +} +static void vfio_device_file_set_kvm (struct file *file,struct kvm *kvm) {struct vfio_device_file *df = file->private_data;@@ -1362,9 +1383,7 @@ static void vfio_device_file_set_kvm(struct file *file, struct kvm *kvm)* be propagated to vfio_device::kvm when the file is bound to * iommufd successfully in the vfio device cdev path. */ -spin_lock (&df->kvm_ref_lock); - df->kvm = kvm; -spin_unlock (&df->kvm_ref_lock); +vfio_device_set_kvm (&df->kvm_ref, kvm); }/**
Sean Christopherson
maintainerPATCH 5/26 vfio: KVM: Pass get/put helpers from KVM to VFIO, don't do circular lookup
In reply to Sean ChristophersonExplicitly pass KVM's get/put helpers to VFIO when attaching a VM to VFIO instead of having VFIO do a symbol lookup back into KVM. Having both KVM and VFIO do symbol lookups increases the overall complexity and places an unnecessary dependency on KVM (from VFIO) without adding any value.
--- drivers/vfio/vfio.h | 2 ++ drivers/vfio/vfio_main.c | 74 +++++++++++++++++++--------------------- include/linux/vfio.h | 4 ++- virt/kvm/vfio.c | 9 +++-- 4 files changed, 47 insertions(+), 42 deletions(-)
drivers/vfio/vfio.h +2 -0
@@ -19,6 +19,8 @@ struct vfio_container;struct vfio_kvm_reference {struct kvm *kvm; +bool (*get_kvm)(struct kvm *kvm); +void (*put_kvm)(struct kvm *kvm);spinlock_t lock; };
drivers/vfio/vfio_main.c +35 -39
135 lines not on this page · raw message
include/linux/vfio.h +3 -1
@@ -312,7 +312,9 @@ static inline bool vfio_file_has_dev(struct file *file, struct vfio_device *devibool vfio_file_is_valid (struct file *file);bool vfio_file_enforced_coherent (struct file *file);#if IS_ENABLED (CONFIG_KVM ) -void vfio_file_set_kvm (struct file *file,struct kvm *kvm); +void vfio_file_set_kvm (struct file *file,struct kvm *kvm, +bool (*get_kvm)(struct kvm *kvm), +void (*put_kvm)(struct kvm *kvm));#endif #define VFIO_PIN_PAGES_MAX_ENTRIES (PAGE_SIZE/sizeof(unsigned long))
virt/kvm/vfio.c +7 -2
@@ -37,13 +37,18 @@ struct kvm_vfio {static void kvm_vfio_file_set_kvm (struct file *file,struct kvm *kvm) { -void (*fn)(struct file *file,struct kvm *kvm); +void (*fn)(struct file *file,struct kvm *kvm, +bool (*get_kvm)(struct kvm *kvm), +void (*put_kvm)(struct kvm *kvm)); fn =symbol_get (vfio_file_set_kvm);if (!fn)return ; -fn (file, kvm); +if (kvm) +fn (file, kvm, kvm_get_kvm_safe, kvm_put_kvm); +else +fn (file, kvm,NULL ,NULL );symbol_put (vfio_file_set_kvm); }
Signature · 1 line
2.42.0.459.ge4e396fd5e-goog
Re: [PATCH 05/26] vfio: KVM: Pass get/put helpers from KVM to VFIO, don't do circular lookup
Quoted 5 lines · Sean Christopherson
Explicitly pass KVM's get/put helpers to VFIO when attaching a VM to VFIO instead of having VFIO do a symbol lookup back into KVM. Having both KVM and VFIO do symbol lookups increases the overall complexity and places an unnecessary dependency on KVM (from VFIO) without adding any value.
Quoted 7 lines
Signed-off-by Sean Christopherson <[email protected]>--- drivers/vfio/vfio.h | 2 ++ drivers/vfio/vfio_main.c | 74 +++++++++++++++++++--------------------- include/linux/vfio.h | 4 ++- virt/kvm/vfio.c | 9 +++-- 4 files changed, 47 insertions(+), 42 deletions(-)
I don't mind this, but Christoph had disliked my prior attempt to do this with function pointers..
The get can be inlined, IIRC, what about putting a pointer to the put inside the kvm struct?
The the normal kvm get/put don't have to exported symbols at all?
Jason
Sean Christopherson
maintainerRe: [PATCH 05/26] vfio: KVM: Pass get/put helpers from KVM to VFIO, don't do circular lookup
Quoted 14 lines · Jason Gunthorpe
Quoted 5 lines · Sean Christopherson
Explicitly pass KVM's get/put helpers to VFIO when attaching a VM to VFIO instead of having VFIO do a symbol lookup back into KVM. Having both KVM and VFIO do symbol lookups increases the overall complexity and places an unnecessary dependency on KVM (from VFIO) without adding any value.
Quoted 7 lines
Signed-off-by Sean Christopherson <[email protected]>--- drivers/vfio/vfio.h | 2 ++ drivers/vfio/vfio_main.c | 74 +++++++++++++++++++--------------------- include/linux/vfio.h | 4 ++- virt/kvm/vfio.c | 9 +++-- 4 files changed, 47 insertions(+), 42 deletions(-)
Quoted 5 lines
I don't mind this, but Christoph had disliked my prior attempt to do this with function pointers..
The get can be inlined, IIRC, what about putting a pointer to the put inside the kvm struct?
That wouldn't allow us to achieve our goal, which is to hide the details of "struct kvm" from VFIO (and the rest of the kernel).
What's the objection to handing VFIO a function pointer?
Quoted 1 line
The the normal kvm get/put don't have to exported symbols at all?
The export of kvm_get_kvm_safe() can go away (I forgot to do that in this series), but kvm_get_kvm() will hang around as it's needed by KVM sub-modules (PPC and x86), KVMGT (x86), and drivers/s390/crypto/vfio_ap_ops.c (no idea what to call that beast).
Gah, KVMGT doesn't actually need to call get/put, that can be handled by kvm_page_track_register_notifier().
I am planning on making exports for sub-modules conditional on there actually being submodules, so that's 2 of the 3 gone, but tackling the s390 crypto driver is an entirely different story.
Re: [PATCH 05/26] vfio: KVM: Pass get/put helpers from KVM to VFIO, don't do circular lookup
Quoted 18 lines · Sean Christopherson
Quoted 17 lines · Jason Gunthorpe
Quoted 5 lines · Sean Christopherson
Explicitly pass KVM's get/put helpers to VFIO when attaching a VM to VFIO instead of having VFIO do a symbol lookup back into KVM. Having both KVM and VFIO do symbol lookups increases the overall complexity and places an unnecessary dependency on KVM (from VFIO) without adding any value.
Quoted 7 lines
Signed-off-by Sean Christopherson <[email protected]>--- drivers/vfio/vfio.h | 2 ++ drivers/vfio/vfio_main.c | 74 +++++++++++++++++++--------------------- include/linux/vfio.h | 4 ++- virt/kvm/vfio.c | 9 +++-- 4 files changed, 47 insertions(+), 42 deletions(-)I don't mind this, but Christoph had disliked my prior attempt to do this with function pointers..
Quoted 7 lines
Quoted 2 lines
The get can be inlined, IIRC, what about putting a pointer to the put inside the kvm struct?
That wouldn't allow us to achieve our goal, which is to hide the details of "struct kvm" from VFIO (and the rest of the kernel).
What's the objection to handing VFIO a function pointer?
Hmm, looks like it was this thread:
https://lore.kernel.org/r/0-v1-33906a626da1+16b0-vfio_kvm_no_group_jgg at nvidia.com
Your rational looks a little better to me.
Quoted 5 lines
Quoted 1 line
The the normal kvm get/put don't have to exported symbols at all?
The export of
kvm_get_kvm_safe()can go away (I forgot to do that in this series), butkvm_get_kvm()will hang around as it's needed by KVM sub-modules (PPC and x86), KVMGT (x86), anddrivers/s390/crypto/vfio_ap_ops.c(no idea what to call that beast).
My thought would be to keep it as an inline, there should be some way to do that without breaking your desire to hide the bulk of the kvm struct content. Like put the refcount as the first element in the struct and just don't ifdef it away?.
Jason
Sean Christopherson
maintainerRe: [PATCH 05/26] vfio: KVM: Pass get/put helpers from KVM to VFIO, don't do circular lookup
Quoted 35 lines · Jason Gunthorpe
Quoted 18 lines · Sean Christopherson
Quoted 17 lines · Jason Gunthorpe
Quoted 5 lines · Sean Christopherson
Explicitly pass KVM's get/put helpers to VFIO when attaching a VM to VFIO instead of having VFIO do a symbol lookup back into KVM. Having both KVM and VFIO do symbol lookups increases the overall complexity and places an unnecessary dependency on KVM (from VFIO) without adding any value.
Quoted 7 lines
Signed-off-by Sean Christopherson <[email protected]>--- drivers/vfio/vfio.h | 2 ++ drivers/vfio/vfio_main.c | 74 +++++++++++++++++++--------------------- include/linux/vfio.h | 4 ++- virt/kvm/vfio.c | 9 +++-- 4 files changed, 47 insertions(+), 42 deletions(-)I don't mind this, but Christoph had disliked my prior attempt to do this with function pointers..
Quoted 7 lines
Quoted 2 lines
The get can be inlined, IIRC, what about putting a pointer to the put inside the kvm struct?
That wouldn't allow us to achieve our goal, which is to hide the details of "struct kvm" from VFIO (and the rest of the kernel).
What's the objection to handing VFIO a function pointer?
Hmm, looks like it was this thread:
https://lore.kernel.org/r/0-v1-33906a626da1+16b0-vfio_kvm_no_group_jgg at nvidia.com
Your rational looks a little better to me.
Quoted 2 lines
Quoted 1 line
The the normal kvm get/put don't have to exported symbols at all?
Quoted 8 lines
Quoted 3 lines
The export of
kvm_get_kvm_safe()can go away (I forgot to do that in this series), butkvm_get_kvm()will hang around as it's needed by KVM sub-modules (PPC and x86), KVMGT (x86), anddrivers/s390/crypto/vfio_ap_ops.c(no idea what to call that beast).My thought would be to keep it as an inline, there should be some way to do that without breaking your desire to hide the bulk of the kvm struct content. Like put the refcount as the first element in the struct and just don't ifdef it away?.
That doesn't work because of the need to invoke kvm_destroy_vm() when the last reference is put, i.e. all of kvm_destroy_vm() would need to be inlined (LOL) or VFIO would need to do a symbol lookup on kvm_destroy_vm(), which puts back us at square one.
There's one more wrinkle: this patch is buggy in that it doesn't ensure the liveliness of KVM-the-module, i.e. nothing prevents userspace from unloading kvm.ko while VFIO still holds a reference to a kvm structure, and so invoking ->put_kvm() could jump into freed code. To fix that, KVM would also need to pass along a module pointer :-(
One thought would be to have vac.ko (tentative name), which is the "base" module that will hold the KVM/virtualization bits that need to be singletons, i.e. can't be per-KVM, provide the symbols needed for VFIO to manage references. But that just ends up moving the module reference trickiness into VAC+KVM, e.g. vac.ko would still need to be handed a function pointer in order to call back into the correct kvm.ko code.
Hrm, but I suspect the vac.ko <=> kvm.ko interactions will need to deal with module shenanigans anyways, and the shenanigans would only affect crazy people like us that actually want multiple KVM modules.
I'll plan on going that route. The very worst case scenario is that it just punts this conversation down to a possibile future. Dropping this patch and the previous prep patch won't meaningful affect the goals of this series, as only kvm_get_kvm_safe() and kvm_get_kvm() would need to be exposed outside of #ifdef __KVM__. Then we can figure out what to do with them if/when the whole multi-KVM thing comes along.
Re: [PATCH 05/26] vfio: KVM: Pass get/put helpers from KVM to VFIO, don't do circular lookup
Quoted 4 lines · Sean Christopherson
There's one more wrinkle: this patch is buggy in that it doesn't ensure the liveliness of KVM-the-module, i.e. nothing prevents userspace from unloading kvm.ko while VFIO still holds a reference to a kvm structure, and so invoking ->put_kvm() could jump into freed code. To fix that, KVM would also need to pass along a module pointer :-(
Maybe we should be refcounting the struct file not the struct kvm?
Then we don't need special helpers and it keeps the module alive correctly.
Jason
Sean Christopherson
maintainerRe: [PATCH 05/26] vfio: KVM: Pass get/put helpers from KVM to VFIO, don't do circular lookup
Quoted 10 lines · Jason Gunthorpe
Quoted 4 lines · Sean Christopherson
There's one more wrinkle: this patch is buggy in that it doesn't ensure the liveliness of KVM-the-module, i.e. nothing prevents userspace from unloading kvm.ko while VFIO still holds a reference to a kvm structure, and so invoking ->put_kvm() could jump into freed code. To fix that, KVM would also need to pass along a module pointer :-(
Maybe we should be refcounting the struct file not the struct kvm?
Then we don't need special helpers and it keeps the module alive correctly.
Huh. It took my brain a while to catch up, but this seems comically obvious in hindsight. I *love* this approach, both conceptually and from a code perspective.
Handing VFIO (and any other external entities) a file makes it so that KVM effectively interacts with users via files, regardless of whether the user lives in userspace or the kernel. That makes it easier to reason about the safety of operations, e.g. in addition to ensuring KVM-the-module is pinned, having a file pointer allows KVM to verify that the incoming pointer does indeed represent a VM. Which isn't necessary by any means, but it's a nice sanity check.
From a code perspective, it's far cleaner than manually grabbing module references, and having only a file pointers makes it a wee bit harder for non-KVM code to poke into KVM, e.g. keeps us honest.
Assuming nothing blows up in testing, I'll go this route for v2.
Thanks!
Re: [PATCH 05/26] vfio: KVM: Pass get/put helpers from KVM to VFIO, don't do circular lookup
In reply to Sean ChristophersonQuoted 5 lines · On Fri, 15 Sep 2023 17:30:57 -0700 Sean Christopherson <[email protected]>…
Explicitly pass KVM's get/put helpers to VFIO when attaching a VM to VFIO instead of having VFIO do a symbol lookup back into KVM. Having both KVM and VFIO do symbol lookups increases the overall complexity and places an unnecessary dependency on KVM (from VFIO) without adding any value.
Quoted 7 lines
Signed-off-by Sean Christopherson <[email protected]>--- drivers/vfio/vfio.h | 2 ++ drivers/vfio/vfio_main.c | 74 +++++++++++++++++++--------------------- include/linux/vfio.h | 4 ++- virt/kvm/vfio.c | 9 +++-- 4 files changed, 47 insertions(+), 42 deletions(-)
Quoted 196 lines
drivers/vfio/vfio.h +2
-0@@ -19,6 +19,8 @@ struct vfio_container;struct vfio_kvm_reference {struct kvm *kvm; +bool (*get_kvm)(struct kvm *kvm); +void (*put_kvm)(struct kvm *kvm);spinlock_t lock; };drivers/vfio/vfio_main.c +35
-39@@ -16,7 +16,6 @@#include <linux/fs.h> #include <linux/idr.h> #include <linux/iommu.h> -#include <linux/kvm_host.h> #include <linux/list.h> #include <linux/miscdevice.h> #include <linux/module.h> @@ -1306,38 +1305,22 @@ EXPORT_SYMBOL_GPL(vfio_file_enforced_coherent);void vfio_device_get_kvm_safe (struct vfio_device *device,struct vfio_kvm_reference *ref) { -void (*pfn)(struct kvm *kvm); -bool (*fn)(struct kvm *kvm); -bool ret; -lockdep_assert_held (&device->dev_set->lock); +/* +* Note! The "kvm" and "put_kvm" pointers *must* be transferred to the +* device so that the device can put its reference to KVM. KVM can +* invoke vfio_device_set_kvm() to detach from VFIO, i.e. nullify all +* pointers in @ref, even if a device holds a reference to KVM! That +* also means that detaching KVM from VFIO only prevents "new" devices +* from using KVM, it doesn't invalidate KVM references in existing +* devices. +*/ spin_lock (&ref->lock); - -if (!ref->kvm) - goto out; - - pfn =symbol_get (kvm_put_kvm); -if (WARN_ON (!pfn)) - goto out; - - fn =symbol_get (kvm_get_kvm_safe); -if (WARN_ON (!fn)) { -symbol_put (kvm_put_kvm); - goto out; +if (ref->kvm && ref->get_kvm (ref->kvm)) { + device->kvm = ref->kvm; + device->put_kvm = ref->put_kvm; } - - ret =fn (ref->kvm); -symbol_put (kvm_get_kvm_safe); -if (!ret) { -symbol_put (kvm_put_kvm); - goto out; - } - - device->put_kvm = pfn; - device->kvm = ref->kvm; - -out:spin_unlock (&ref->lock); }@@ -1353,28 +1336,37 @@ void vfio_device_put_kvm(struct vfio_device *device) device->put_kvm (device->kvm); device->put_kvm =NULL ; -symbol_put (kvm_put_kvm); - clear: device->kvm =NULL ; }static void vfio_device_set_kvm (struct vfio_kvm_reference *ref, -struct kvm *kvm) +struct kvm *kvm, +bool (*get_kvm)(struct kvm *kvm), +void (*put_kvm)(struct kvm *kvm)) { +if (WARN_ON_ONCE (kvm && (!get_kvm || !put_kvm))) +return ; +spin_lock (&ref->lock); ref->kvm = kvm; + ref->get_kvm = get_kvm; + ref->put_kvm = put_kvm;spin_unlock (&ref->lock); } -static void vfio_group_set_kvm (struct vfio_group *group,struct kvm *kvm) +static void vfio_group_set_kvm (struct vfio_group *group,struct kvm *kvm, +bool (*get_kvm)(struct kvm *kvm), +void (*put_kvm)(struct kvm *kvm)) {#if IS_ENABLED (CONFIG_VFIO_GROUP ) -vfio_device_set_kvm (&group->kvm_ref, kvm); +vfio_device_set_kvm (&group->kvm_ref, kvm, get_kvm, put_kvm);#endif } -static void vfio_device_file_set_kvm (struct file *file,struct kvm *kvm) +static void vfio_device_file_set_kvm (struct file *file,struct kvm *kvm, +bool (*get_kvm)(struct kvm *kvm), +void (*put_kvm)(struct kvm *kvm)) {struct vfio_device_file *df = file->private_data;@@ -1383,27 +1375,31 @@ static void vfio_device_file_set_kvm(struct file *file, struct kvm *kvm)* be propagated to vfio_device::kvm when the file is bound to * iommufd successfully in the vfio device cdev path. */ - vfio_device_set_kvm(&df->kvm_ref, kvm); + vfio_device_set_kvm(&df->kvm_ref, kvm, get_kvm, put_kvm); }/** * vfio_file_set_kvm - Link a kvm with VFIO drivers * @file: VFIO group file or VFIO device file * @kvm: KVM to link +* @get_kvm: Callback to get a reference to @kvm +* @put_kvm: Callback to put a reference to @kvm * * When a VFIO device is first opened the KVM will be available in * device->kvm if one was associated with the file. */ -void vfio_file_set_kvm (struct file *file,struct kvm *kvm) +void vfio_file_set_kvm (struct file *file,struct kvm *kvm, +bool (*get_kvm)(struct kvm *kvm), +void (*put_kvm)(struct kvm *kvm)) {struct vfio_group *group; group =vfio_group_from_file (file);if (group) -vfio_group_set_kvm (group, kvm); +vfio_group_set_kvm (group, kvm, get_kvm, put_kvm);if (vfio_device_from_file (file)) -vfio_device_file_set_kvm (file, kvm); +vfio_device_file_set_kvm (file, kvm, get_kvm, put_kvm); }EXPORT_SYMBOL_GPL (vfio_file_set_kvm);#endif include/linux/vfio.h +3
-1@@ -312,7 +312,9 @@ static inline bool vfio_file_has_dev(struct file *file, struct vfio_device *devibool vfio_file_is_valid (struct file *file);bool vfio_file_enforced_coherent (struct file *file);#if IS_ENABLED (CONFIG_KVM ) -void vfio_file_set_kvm (struct file *file,struct kvm *kvm); +void vfio_file_set_kvm (struct file *file,struct kvm *kvm, +bool (*get_kvm)(struct kvm *kvm), +void (*put_kvm)(struct kvm *kvm));#endif #define VFIO_PIN_PAGES_MAX_ENTRIES (PAGE_SIZE/sizeof(unsigned long))virt/kvm/vfio.c +7
-2@@ -37,13 +37,18 @@ struct kvm_vfio {static void kvm_vfio_file_set_kvm (struct file *file,struct kvm *kvm) { -void (*fn)(struct file *file,struct kvm *kvm); +void (*fn)(struct file *file,struct kvm *kvm, +bool (*get_kvm)(struct kvm *kvm), +void (*put_kvm)(struct kvm *kvm)); fn =symbol_get (vfio_file_set_kvm);if (!fn)return ; -fn (file, kvm); +if (kvm) +fn (file, kvm, kvm_get_kvm_safe, kvm_put_kvm); +else +fn (file, kvm,NULL ,NULL );symbol_put (vfio_file_set_kvm); }
Sean Christopherson
maintainerPATCH 6/26 KVM: Drop CONFIG_KVM_VFIO and just look at KVM+VFIO
In reply to Sean ChristophersonDrop KVM's KVM_VFIO Kconfig, and instead compile in VFIO support if and only if VFIO itself is enabled. Similar to the recent change to have VFIO stop looking at HAVE_KVM, compiling in support for talking to VFIO just because the architecture supports VFIO is nonsensical.
This fixes a bug where RISC-V doesn't select KVM_VFIO, i.e. would silently fail to do connect KVM and VFIO, even though RISC-V supports VFIO. The bug is benign as the only driver in all of Linux that actually uses the KVM reference provided by VFIO is KVM-GT, which is x86/Intel specific.
--- arch/arm64/kvm/Kconfig | 1 - arch/powerpc/kvm/Kconfig | 1 - arch/s390/kvm/Kconfig | 1 - arch/x86/kvm/Kconfig | 1 - virt/kvm/Kconfig | 3 --- virt/kvm/Makefile.kvm | 4 +++- virt/kvm/vfio.h | 2 +- 7 files changed, 4 insertions(+), 9 deletions(-)
arch/arm64/kvm/Kconfig +0 -1
@@ -28,7 +28,6 @@ menuconfig KVM select KVM_MMIO select KVM_GENERIC_DIRTYLOG_READ_PROTECT select KVM_XFER_TO_GUEST_WORK - select KVM_VFIO select HAVE_KVM_EVENTFD select HAVE_KVM_IRQFD select HAVE_KVM_DIRTY_RING_ACQ_REL
arch/powerpc/kvm/Kconfig +0 -1
@@ -22,7 +22,6 @@ config KVM select PREEMPT_NOTIFIERS select HAVE_KVM_EVENTFD select HAVE_KVM_VCPU_ASYNC_IOCTL - select KVM_VFIO select IRQ_BYPASS_MANAGER select HAVE_KVM_IRQ_BYPASS select INTERVAL_TREE
arch/s390/kvm/Kconfig +0 -1
@@ -31,7 +31,6 @@ config KVM select HAVE_KVM_IRQ_ROUTING select HAVE_KVM_INVALID_WAKEUPS select HAVE_KVM_NO_POLL - select KVM_VFIO select INTERVAL_TREE select MMU_NOTIFIER help
arch/x86/kvm/Kconfig +0 -1
@@ -45,7 +45,6 @@ config KVM select HAVE_KVM_NO_POLL select KVM_XFER_TO_GUEST_WORK select KVM_GENERIC_DIRTYLOG_READ_PROTECT - select KVM_VFIO select INTERVAL_TREE select HAVE_KVM_PM_NOTIFIER if PM select KVM_GENERIC_HARDWARE_ENABLING
virt/kvm/Kconfig +0 -3
@@ -59,9 +59,6 @@ config HAVE_KVM_MSI config HAVE_KVM_CPU_RELAX_INTERCEPT bool -config KVM_VFIO - bool - config HAVE_KVM_INVALID_WAKEUPS bool
virt/kvm/Makefile.kvm +3 -1
@@ -6,7 +6,9 @@ KVM ?= ../../../virt/kvm kvm-y := $(KVM)/kvm_main.o $(KVM)/eventfd.o $(KVM)/binary_stats.o -kvm-$(CONFIG_KVM_VFIO) += $(KVM)/vfio.o +ifdef CONFIG_VFIO +kvm-y += $(KVM)/vfio.o +endif kvm-$(CONFIG_KVM_MMIO) += $(KVM)/coalesced_mmio.o kvm-$(CONFIG_KVM_ASYNC_PF) += $(KVM)/async_pf.o kvm-$(CONFIG_HAVE_KVM_IRQ_ROUTING) += $(KVM)/irqchip.o
virt/kvm/vfio.h +1 -1
@@ -2,7 +2,7 @@#ifndef __KVM_VFIO_H#define __KVM_VFIO_H -#ifdef CONFIG_KVM_VFIO +#if IS_ENABLED (CONFIG_KVM ) &&IS_ENABLED (CONFIG_VFIO )int kvm_vfio_ops_init (void );void kvm_vfio_ops_exit (void );#else
Signature · 1 line
2.42.0.459.ge4e396fd5e-goog
Re: [PATCH 06/26] KVM: Drop CONFIG_KVM_VFIO and just look at KVM+VFIO
Quoted 9 lines · Sean Christopherson
Drop KVM's
KVM_VFIOKconfig, and instead compile in VFIO support if and only if VFIO itself is enabled. Similar to the recent change to have VFIO stop looking atHAVE_KVM, compiling in support for talking to VFIO just because the architecture supports VFIO is nonsensical.This fixes a bug where RISC-V doesn't select
KVM_VFIO, i.e. would silently fail to do connect KVM and VFIO, even though RISC-V supports VFIO. The bug is benign as the only driver in all of Linux that actually uses the KVM reference provided by VFIO is KVM-GT, which is x86/Intel specific.
Hmm, I recall that all the S390 drivers need it as well.
static int vfio_ap_mdev_open_device(struct vfio_device *vdev)
{
struct ap_matrix_mdev *matrix_mdev =
container_of(vdev, struct ap_matrix_mdev, vdev);
if (!vdev->kvm)
return -EINVAL;
return vfio_ap_mdev_set_kvm(matrix_mdev, vdev->kvm);I wonder if we should be making the VFIO drivers that need the kvm to ask for it? 'select CONFIG_NEED_VFIO_KVM' or something?
Regardless, I fully agree with getting rid of the arch flag.
virt/kvm/Makefile.kvm line 11
Quoted 10 lines
virt/kvm/Makefile.kvm +3
-1@@ -6,7 +6,9 @@ KVM ?= ../../../virt/kvm kvm-y := $(KVM)/kvm_main.o $(KVM)/eventfd.o $(KVM)/binary_stats.o -kvm-$(CONFIG_KVM_VFIO) += $(KVM)/vfio.o +ifdef CONFIG_VFIO +kvm-y += $(KVM)/vfio.o +endif
I wonder if kvm-m magically works in kbuild so you don't need the ifdef?
Jason
Sean Christopherson
maintainerRe: [PATCH 06/26] KVM: Drop CONFIG_KVM_VFIO and just look at KVM+VFIO
Quoted 14 lines · Jason Gunthorpe
Quoted 9 lines · Sean Christopherson
Drop KVM's
KVM_VFIOKconfig, and instead compile in VFIO support if and only if VFIO itself is enabled. Similar to the recent change to have VFIO stop looking atHAVE_KVM, compiling in support for talking to VFIO just because the architecture supports VFIO is nonsensical.This fixes a bug where RISC-V doesn't select
KVM_VFIO, i.e. would silently fail to do connect KVM and VFIO, even though RISC-V supports VFIO. The bug is benign as the only driver in all of Linux that actually uses the KVM reference provided by VFIO is KVM-GT, which is x86/Intel specific.Hmm, I recall that all the S390 drivers need it as well.
static int
vfio_ap_mdev_open_device(struct vfio_device *vdev)
Quoted 8 lines
{
struct ap_matrix_mdev *matrix_mdev =
container_of(vdev, struct ap_matrix_mdev, vdev);
if (!vdev->kvm)
return -EINVAL;
return vfio_ap_mdev_set_kvm(matrix_mdev, vdev->kvm);Ah, I missed that the KVM reference was routed through VFIO in that case.
Quoted 2 lines
I wonder if we should be making the VFIO drivers that need the kvm to ask for it? 'select
CONFIG_NEED_VFIO_KVM' or something?
I wondered the same thing, if only to make it easier to track which drivers actually end up interacting directly with KVM.
Quoted 9 lines
Regardless, I fully agree with getting rid of the arch flag.
Reviewed-by Jason Gunthorpe <[email protected]>Quoted 5 lines
virt/kvm/Makefile.kvm +0
-0@@ -6,7 +6,9 @@ KVM ?= ../../../virt/kvm
Quoted 7 lines
virt/kvm/Makefile.kvm line 11
Quoted 5 lines
virt/kvm/Makefile.kvm +3
-1kvm-y := $(KVM)/kvm_main.o $(KVM)/eventfd.o $(KVM)/binary_stats.o -kvm-$(CONFIG_KVM_VFIO) += $(KVM)/vfio.o +ifdef CONFIG_VFIO +kvm-y += $(KVM)/vfio.o +endifI wonder if kvm-m magically works in kbuild so you don't need the ifdef?
Yeah, that should work, no idea why I added the ifdef.
Re: [PATCH 06/26] KVM: Drop CONFIG_KVM_VFIO and just look at KVM+VFIO
Quoted 5 lines · Sean Christopherson
Quoted 2 lines
I wonder if we should be making the VFIO drivers that need the kvm to ask for it? 'select
CONFIG_NEED_VFIO_KVM' or something?I wondered the same thing, if only to make it easier to track which drivers actually end up interacting directly with KVM.
There are two usages I've seen..
GVT's uage is just totally broken:
https://lore.kernel.org/kvm/661447fd-b041-c08d-cedc-341b31c405f8 at intel.com/
It is trying to use KVM to write protect IOVA DMA memory, and it just doesn't work. If we want to do something like this the core vfio code should provide this service and it should be wired into KVM properly.
power and s390 have actual architectural "virtual machines" and they need actual arch operations to install VFIO devices into those things. In this regard having the arch opt into the integration would make some sense. I expect this will get worse in our CC future where VFIO devices will need to be passed into arch specific CC code somehow.
This arch stuff isn't cleanly done, the code is sprinkled all over the place. Some in mdevs, some in PCI arch code, some in #ifdefs..
Maybe the CC people will clean it up instead of making the mess bigger :)
Jason
Re: [PATCH 06/26] KVM: Drop CONFIG_KVM_VFIO and just look at KVM+VFIO
In reply to Sean ChristophersonQuoted 11 lines · On Fri, 15 Sep 2023 17:30:58 -0700 Sean Christopherson <[email protected]>…
Drop KVM's
KVM_VFIOKconfig, and instead compile in VFIO support if and only if VFIO itself is enabled. Similar to the recent change to have VFIO stop looking atHAVE_KVM, compiling in support for talking to VFIO just because the architecture supports VFIO is nonsensical.This fixes a bug where RISC-V doesn't select
KVM_VFIO, i.e. would silently fail to do connect KVM and VFIO, even though RISC-V supports VFIO. The bug is benign as the only driver in all of Linux that actually uses the KVM reference provided by VFIO is KVM-GT, which is x86/Intel specific.Signed-off-by Sean Christopherson <[email protected]>
Quoted 9 lines
--- arch/arm64/kvm/Kconfig | 1 - arch/powerpc/kvm/Kconfig | 1 - arch/s390/kvm/Kconfig | 1 - arch/x86/kvm/Kconfig | 1 - virt/kvm/Kconfig | 3 --- virt/kvm/Makefile.kvm | 4 +++- virt/kvm/vfio.h | 2 +- 7 files changed, 4 insertions(+), 9 deletions(-)
Quoted 90 lines
arch/arm64/kvm/Kconfig +0
-1@@ -28,7 +28,6 @@ menuconfig KVM select KVM_MMIO select KVM_GENERIC_DIRTYLOG_READ_PROTECT select KVM_XFER_TO_GUEST_WORK - select KVM_VFIO select HAVE_KVM_EVENTFD select HAVE_KVM_IRQFD select HAVE_KVM_DIRTY_RING_ACQ_RELarch/powerpc/kvm/Kconfig +0
-1@@ -22,7 +22,6 @@ config KVM select PREEMPT_NOTIFIERS select HAVE_KVM_EVENTFD select HAVE_KVM_VCPU_ASYNC_IOCTL - select KVM_VFIO select IRQ_BYPASS_MANAGER select HAVE_KVM_IRQ_BYPASS select INTERVAL_TREEarch/s390/kvm/Kconfig +0
-1@@ -31,7 +31,6 @@ config KVM select HAVE_KVM_IRQ_ROUTING select HAVE_KVM_INVALID_WAKEUPS select HAVE_KVM_NO_POLL - select KVM_VFIO select INTERVAL_TREE select MMU_NOTIFIER helparch/x86/kvm/Kconfig +0
-1@@ -45,7 +45,6 @@ config KVM select HAVE_KVM_NO_POLL select KVM_XFER_TO_GUEST_WORK select KVM_GENERIC_DIRTYLOG_READ_PROTECT - select KVM_VFIO select INTERVAL_TREE select HAVE_KVM_PM_NOTIFIER if PM select KVM_GENERIC_HARDWARE_ENABLINGvirt/kvm/Kconfig +0
-3@@ -59,9 +59,6 @@ config HAVE_KVM_MSI config HAVE_KVM_CPU_RELAX_INTERCEPT bool -config KVM_VFIO - bool - config HAVE_KVM_INVALID_WAKEUPS boolvirt/kvm/Makefile.kvm +3
-1@@ -6,7 +6,9 @@ KVM ?= ../../../virt/kvm kvm-y := $(KVM)/kvm_main.o $(KVM)/eventfd.o $(KVM)/binary_stats.o -kvm-$(CONFIG_KVM_VFIO) += $(KVM)/vfio.o +ifdef CONFIG_VFIO +kvm-y += $(KVM)/vfio.o +endif kvm-$(CONFIG_KVM_MMIO) += $(KVM)/coalesced_mmio.o kvm-$(CONFIG_KVM_ASYNC_PF) += $(KVM)/async_pf.o kvm-$(CONFIG_HAVE_KVM_IRQ_ROUTING) += $(KVM)/irqchip.ovirt/kvm/vfio.h +1
-1@@ -2,7 +2,7 @@#ifndef __KVM_VFIO_H#define __KVM_VFIO_H -#ifdef CONFIG_KVM_VFIO +#if IS_ENABLED (CONFIG_KVM ) &&IS_ENABLED (CONFIG_VFIO )int kvm_vfio_ops_init (void );void kvm_vfio_ops_exit (void );#else
Sean Christopherson
maintainerPATCH 7/26 x86/idt: Wrap KVM logic with CONFIG_KVM instead of CONFIG_HAVE_KVM
In reply to Sean ChristophersonWrap all of the IDT-related code that deals with KVM in CONFIG_KVM instead of CONFIG_HAVE_KVM. x86 always "has" KVM, i.e. checking CONFIG_HAVE_KVM is pointless.
Alternatively, the #ifdefs could simply be deleted, but the only potential value is in printing the number of posted interrupts that end up being handled by the host, everything else is completely dead code when KVM is disabled. And if KVM is disabled, there should not be any posted interrupts, i.e. NOT wiring up the "dummy" handlers and treating IRQs on those vectors as spurious is the right thing to do.
--- arch/x86/include/asm/hardirq.h | 2 +- arch/x86/include/asm/idtentry.h | 2 +- arch/x86/include/asm/irq.h | 2 +- arch/x86/include/asm/irq_vectors.h | 2 +- arch/x86/kernel/idt.c | 2 +- arch/x86/kernel/irq.c | 4 ++-- scripts/gdb/linux/constants.py.in | 2 +- scripts/gdb/linux/interrupts.py | 2 +- tools/arch/x86/include/asm/irq_vectors.h | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-)
arch/x86/include/asm/hardirq.h +1 -1
@@ -15,7 +15,7 @@ typedef struct {unsigned int irq_spurious_count;unsigned int icr_read_retry_count;#endif -#ifdef CONFIG_HAVE_KVM +#if IS_ENABLED (CONFIG_KVM )unsigned int kvm_posted_intr_ipis;unsigned int kvm_posted_intr_wakeup_ipis;unsigned int kvm_posted_intr_nested_ipis;
arch/x86/include/asm/idtentry.h +1 -1
@@ -671,7 +671,7 @@ DECLARE_IDTENTRY_SYSVEC(IRQ_WORK_VECTOR, sysvec_irq_work);# endif #endif -#ifdef CONFIG_HAVE_KVM +#if IS_ENABLED (CONFIG_KVM )DECLARE_IDTENTRY_SYSVEC (POSTED_INTR_VECTOR , sysvec_kvm_posted_intr_ipi);DECLARE_IDTENTRY_SYSVEC (POSTED_INTR_WAKEUP_VECTOR , sysvec_kvm_posted_intr_wakeup_ipi);DECLARE_IDTENTRY_SYSVEC (POSTED_INTR_NESTED_VECTOR , sysvec_kvm_posted_intr_nested_ipi);
arch/x86/include/asm/irq.h +1 -1
@@ -29,7 +29,7 @@ struct irq_desc;extern void fixup_irqs (void ); -#ifdef CONFIG_HAVE_KVM +#if IS_ENABLED (CONFIG_KVM )extern void kvm_set_posted_intr_wakeup_handler (void (*handler)(void ));#endif
arch/x86/include/asm/irq_vectors.h +1 -1
@@ -84,7 +84,7 @@#define HYPERVISOR_CALLBACK_VECTOR 0xf3/* Vector for KVM to deliver posted interrupt IPI */ -#ifdef CONFIG_HAVE_KVM +#if IS_ENABLED (CONFIG_KVM )#define POSTED_INTR_VECTOR 0xf2#define POSTED_INTR_WAKEUP_VECTOR 0xf1#define POSTED_INTR_NESTED_VECTOR 0xf0
arch/x86/kernel/idt.c +1 -1
@@ -149,7 +149,7 @@ static const __initconst struct idt_data apic_idts[] = {#ifdef CONFIG_X86_LOCAL_APIC INTG (LOCAL_TIMER_VECTOR , asm_sysvec_apic_timer_interrupt),INTG (X86_PLATFORM_IPI_VECTOR , asm_sysvec_x86_platform_ipi), -# ifdef CONFIG_HAVE_KVM +#if IS_ENABLED(CONFIG_KVM)INTG (POSTED_INTR_VECTOR , asm_sysvec_kvm_posted_intr_ipi),INTG (POSTED_INTR_WAKEUP_VECTOR , asm_sysvec_kvm_posted_intr_wakeup_ipi), INTG(POSTED_INTR_NESTED_VECTOR, asm_sysvec_kvm_posted_intr_nested_ipi),
arch/x86/kernel/irq.c +2 -2
@@ -164,7 +164,7 @@ int arch_show_interrupts(struct seq_file *p, int prec)#if defined(CONFIG_X86_IO_APIC )seq_printf (p,"%*s: %10u\n" , prec,"MIS" ,atomic_read (&irq_mis_count));#endif -#ifdef CONFIG_HAVE_KVM +#if IS_ENABLED (CONFIG_KVM )seq_printf (p,"%*s: " , prec,"PIN" );for_each_online_cpu (j)seq_printf (p,"%10u " ,irq_stats (j)->kvm_posted_intr_ipis);
@@ -290,7 +290,7 @@ DEFINE_IDTENTRY_SYSVEC(sysvec_x86_platform_ipi) }#endif -#ifdef CONFIG_HAVE_KVM +#if IS_ENABLED (CONFIG_KVM )static void dummy_handler (void ) {}static void (*kvm_posted_intr_wakeup_handler)(void ) = dummy_handler;
scripts/gdb/linux/constants.py.in +1 -1
@@ -129,7 +129,7 @@ LX_CONFIG(CONFIG_X86_MCE_THRESHOLD) LX_CONFIG(CONFIG_X86_MCE_AMD) LX_CONFIG(CONFIG_X86_MCE) LX_CONFIG(CONFIG_X86_IO_APIC) -LX_CONFIG(CONFIG_HAVE_KVM) +LX_CONFIG(CONFIG_KVM) LX_CONFIG(CONFIG_NUMA) LX_CONFIG(CONFIG_ARM64) LX_CONFIG(CONFIG_ARM64_4K_PAGES)
scripts/gdb/linux/interrupts.py +1 -1
@@ -151,7 +151,7 @@ def x86_show_interupts(prec): if cnt is not None: text += "%*s: %10u\n" % (prec, "MIS", cnt['counter']) - if constants.LX_CONFIG_HAVE_KVM: + if constants.LX_CONFIG_KVM: text += x86_show_irqstat(prec, "PIN", 'kvm_posted_intr_ipis', 'Posted-interrupt notification event') text += x86_show_irqstat(prec, "NPI", 'kvm_posted_intr_nested_ipis', 'Nested posted-interrupt event') text += x86_show_irqstat(prec, "PIW", 'kvm_posted_intr_wakeup_ipis', 'Posted-interrupt wakeup event')
tools/arch/x86/include/asm/irq_vectors.h +1 -1
@@ -84,7 +84,7 @@#define HYPERVISOR_CALLBACK_VECTOR 0xf3/* Vector for KVM to deliver posted interrupt IPI */ -#ifdef CONFIG_HAVE_KVM +#if IS_ENABLED (CONFIG_KVM )#define POSTED_INTR_VECTOR 0xf2#define POSTED_INTR_WAKEUP_VECTOR 0xf1#define POSTED_INTR_NESTED_VECTOR 0xf0
Signature · 1 line
2.42.0.459.ge4e396fd5e-goog
Sean Christopherson
maintainerPATCH 8/26 KVM: x86: Stop selecting and depending on HAVE_KVM
In reply to Sean ChristophersonNow that nothing in x86 or architecture agnostic code consumes HAVE_KVM, stop selecting it in x86. This is one of several steps towards deleting HAVE_KVM from the common KVM Kconfig.
--- arch/x86/Kconfig | 1 - arch/x86/kvm/Kconfig | 2 -- 2 files changed, 3 deletions(-)
arch/x86/Kconfig +0 -1
@@ -240,7 +240,6 @@ config X86 select HAVE_FUNCTION_ERROR_INJECTION select HAVE_KRETPROBES select HAVE_RETHOOK - select HAVE_KVM select HAVE_LIVEPATCH if X86_64 select HAVE_MIXED_BREAKPOINTS_REGS select HAVE_MOD_ARCH_SPECIFIC
arch/x86/kvm/Kconfig +0 -2
@@ -7,7 +7,6 @@ source "virt/kvm/Kconfig" menuconfig VIRTUALIZATION bool "Virtualization" - depends on HAVE_KVM || X86 default y help Say Y here to get to see options for using your Linux host to run other
@@ -20,7 +19,6 @@ if VIRTUALIZATION config KVM tristate "Kernel-based Virtual Machine (KVM) support" - depends on HAVE_KVM depends on HIGH_RES_TIMERS depends on X86_LOCAL_APIC select PREEMPT_NOTIFIERS
Signature · 1 line
2.42.0.459.ge4e396fd5e-goog
Sean Christopherson
maintainerPATCH 9/26 KVM: arm64: Stop selecting and depending on HAVE_KVM
In reply to Sean ChristophersonNow that nothing in arm64 or architecture agnostic code consumes HAVE_KVM, stop selecting it in arm64. This is one of several steps towards deleting HAVE_KVM from the common KVM Kconfig.
--- arch/arm64/Kconfig | 1 - arch/arm64/kvm/Kconfig | 1 - 2 files changed, 2 deletions(-)
arch/arm64/Kconfig +0 -1
@@ -214,7 +214,6 @@ config ARM64 select HAVE_HW_BREAKPOINT if PERF_EVENTS select HAVE_IOREMAP_PROT select HAVE_IRQ_TIME_ACCOUNTING - select HAVE_KVM select HAVE_MOD_ARCH_SPECIFIC select HAVE_NMI select HAVE_PERF_EVENTS
arch/arm64/kvm/Kconfig +0 -1
@@ -20,7 +20,6 @@ if VIRTUALIZATION menuconfig KVM bool "Kernel-based Virtual Machine (KVM) support" - depends on HAVE_KVM select KVM_GENERIC_HARDWARE_ENABLING select MMU_NOTIFIER select PREEMPT_NOTIFIERS
Signature · 1 line
2.42.0.459.ge4e396fd5e-goog
Sean Christopherson
maintainerPATCH 10/26 KVM: s390: Stop selecting and depending on HAVE_KVM
In reply to Sean ChristophersonNow that nothing in s390 or architecture agnostic code consumes HAVE_KVM, stop selecting it in s390. This is one of several steps towards deleting HAVE_KVM from the common KVM Kconfig.
--- arch/s390/Kconfig | 1 - arch/s390/kvm/Kconfig | 1 - 2 files changed, 2 deletions(-)
arch/s390/Kconfig +0 -1
@@ -193,7 +193,6 @@ config S390 select HAVE_KPROBES select HAVE_KPROBES_ON_FTRACE select HAVE_KRETPROBES - select HAVE_KVM select HAVE_LIVEPATCH select HAVE_MEMBLOCK_PHYS_MAP select HAVE_MOD_ARCH_SPECIFIC
arch/s390/kvm/Kconfig +0 -1
@@ -19,7 +19,6 @@ if VIRTUALIZATION config KVM def_tristate y prompt "Kernel-based Virtual Machine (KVM) support" - depends on HAVE_KVM select PREEMPT_NOTIFIERS select HAVE_KVM_CPU_RELAX_INTERCEPT select HAVE_KVM_VCPU_ASYNC_IOCTL
Signature · 1 line
2.42.0.459.ge4e396fd5e-goog
Re: [PATCH 10/26] KVM: s390: Stop selecting and depending on HAVE_KVM
Quoted 27 lines · On Fri, 15 Sep 2023 17:31:02 -0700 Sean Christopherson <[email protected]>…
Now that nothing in s390 or architecture agnostic code consumes
HAVE_KVM, stop selecting it in s390. This is one of several steps towards deletingHAVE_KVMfrom the common KVMKconfig.Signed-off-by Sean Christopherson <[email protected]>--- arch/s390/Kconfig | 1 - arch/s390/kvm/Kconfig | 1 - 2 files changed, 2 deletions(-)arch/s390/Kconfig +0
-1@@ -193,7 +193,6 @@ config S390 select HAVE_KPROBES select HAVE_KPROBES_ON_FTRACE select HAVE_KRETPROBES - select HAVE_KVM select HAVE_LIVEPATCH select HAVE_MEMBLOCK_PHYS_MAP select HAVE_MOD_ARCH_SPECIFICarch/s390/kvm/Kconfig +0
-0
arch/s390/kvm/Kconfig if VIRTUALIZATION · line 24
Quoted 7 lines
arch/s390/kvm/Kconfig +0
-1@@ -19,7 +19,6 @@ if VIRTUALIZATION config KVM def_tristate y prompt "Kernel-based Virtual Machine (KVM) support" - depends on HAVE_KVM select PREEMPT_NOTIFIERS select HAVE_KVM_CPU_RELAX_INTERCEPT select HAVE_KVM_VCPU_ASYNC_IOCTL
it looks like we don't use HAVE_KVM on s390x
Sean Christopherson
maintainerPATCH 11/26 KVM: MIPS: Make HAVE_KVM a MIPS-only Kconfig
In reply to Sean ChristophersonNow that MIPS is the sole remaining user of HAVE_KVM, make HAVE_KVM a MIPS-only Kconfig. Because most architectures unconditionally support virtualization, advertising to the kernel at-large that an arch has KVM just led to a bunch of useless and misguided #ifdefs.
--- arch/mips/kvm/Kconfig | 3 +++ virt/kvm/Kconfig | 3 --- 2 files changed, 3 insertions(+), 3 deletions(-)
arch/mips/kvm/Kconfig +3 -0
@@ -4,6 +4,9 @@ # source "virt/kvm/Kconfig" +config HAVE_KVM + bool + menuconfig VIRTUALIZATION bool "Virtualization" help
virt/kvm/Kconfig +0 -3
@@ -1,9 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 # KVM common configuration items and defaults -config HAVE_KVM - bool - config HAVE_KVM_PFNCACHE bool
Signature · 1 line
2.42.0.459.ge4e396fd5e-goog
Sean Christopherson
maintainerPATCH 12/26 KVM: arm64: Move arm_{psci,hypercalls}.h to an internal KVM path
In reply to Sean ChristophersonFrom: Anish Ghulati <[email protected]>
Move arm_hypercalls.h and arm_psci.h into arch/arm64/kvm now that KVM no longer supports 32-bit ARM, i.e. now that there's no reason to make the hypercall and PSCI APIs "public".
---
arch/arm64/kvm/arm.c | 5 +++--
{include => arch/arm64}/kvm/arm_hypercalls.h | 0
{include => arch/arm64}/kvm/arm_psci.h | 0
arch/arm64/kvm/guest.c | 2 +-
arch/arm64/kvm/handle_exit.c | 2 +-
arch/arm64/kvm/hyp/Makefile | 4 ++--
arch/arm64/kvm/hyp/include/hyp/switch.h | 4 ++--
arch/arm64/kvm/hyp/nvhe/switch.c | 4 ++--
arch/arm64/kvm/hyp/vhe/switch.c | 4 ++--
arch/arm64/kvm/hypercalls.c | 4 ++--
arch/arm64/kvm/psci.c | 4 ++--
arch/arm64/kvm/pvtime.c | 2 +-
arch/arm64/kvm/trng.c | 2 +-
13 files changed, 19 insertions(+), 18 deletions(-)
rename {include => arch/arm64}/kvm/arm_hypercalls.h (100%)
rename {include => arch/arm64}/kvm/arm_psci.h (100%)arch/arm64/kvm/arm.c +3 -2
@@ -41,9 +41,10 @@#include <asm/kvm_emulate.h> #include <asm/sections.h> -#include <kvm/arm_hypercalls.h> #include <kvm/arm_pmu.h> -#include <kvm/arm_psci.h> + +#include "arm_hypercalls.h" +#include "arm_psci.h" static enum kvm_mode kvm_mode =KVM_MODE_DEFAULT ;
arch/arm64/kvm/arm_hypercalls.h renamed from include/kvm/arm_hypercalls.h +0 -0
arch/arm64/kvm/arm_psci.h renamed from include/kvm/arm_psci.h +0 -0
arch/arm64/kvm/guest.c +1 -1
@@ -18,7 +18,6 @@#include <linux/string.h> #include <linux/vmalloc.h> #include <linux/fs.h> -#include <kvm/arm_hypercalls.h> #include <asm/cputype.h> #include <linux/uaccess.h> #include <asm/fpsimd.h>
@@ -27,6 +26,7 @@#include <asm/kvm_nested.h> #include <asm/sigcontext.h> +#include "arm_hypercalls.h" #include "trace.h" const struct _kvm_stats_desc kvm_vm_stats_desc[] = {
arch/arm64/kvm/handle_exit.c +1 -1
@@ -21,7 +21,7 @@#include <asm/stacktrace/nvhe.h> #include <asm/traps.h> -#include <kvm/arm_hypercalls.h> +#include "arm_hypercalls.h" #define CREATE_TRACE_POINTS #include "trace_handle_exit.h"
arch/arm64/kvm/hyp/Makefile +2 -2
@@ -4,7 +4,7 @@ # incdir := $(srctree)/$(src)/include -subdir-asflags-y := -I$(incdir) -subdir-ccflags-y := -I$(incdir) +subdir-asflags-y := -I$(incdir) -I$(srctree)/arch/arm64/kvm +subdir-ccflags-y := -I$(incdir) -I$(srctree)/arch/arm64/kvm obj-$(CONFIG_KVM) += vhe/ nvhe/ pgtable.o
arch/arm64/kvm/hyp/include/hyp/switch.h +2 -2
@@ -16,8 +16,6 @@#include <linux/jump_label.h> #include <uapi/linux/psci.h> -#include <kvm/arm_psci.h> -#include <asm/barrier.h> #include <asm/cpufeature.h> #include <asm/extable.h>
@@ -31,6 +29,8 @@#include <asm/debug-monitors.h> #include <asm/processor.h> +#include "arm_psci.h" +struct kvm_exception_table_entry {int insn, fixup; };
arch/arm64/kvm/hyp/nvhe/switch.c +2 -2
@@ -13,8 +13,6 @@#include <linux/jump_label.h> #include <uapi/linux/psci.h> -#include <kvm/arm_psci.h> -#include <asm/barrier.h> #include <asm/cpufeature.h> #include <asm/kprobes.h>
@@ -29,6 +27,8 @@#include <nvhe/fixed_config.h> #include <nvhe/mem_protect.h> +#include "arm_psci.h" +/* Non-VHE specific context */ DEFINE_PER_CPU(struct kvm_host_data, kvm_host_data); DEFINE_PER_CPU(struct kvm_cpu_context, kvm_hyp_ctxt);
arch/arm64/kvm/hyp/vhe/switch.c +2 -2
@@ -13,8 +13,6 @@#include <linux/percpu.h> #include <uapi/linux/psci.h> -#include <kvm/arm_psci.h> -#include <asm/barrier.h> #include <asm/cpufeature.h> #include <asm/kprobes.h>
@@ -28,6 +26,8 @@#include <asm/thread_info.h> #include <asm/vectors.h> +#include "arm_psci.h" +/* VHE specific context */ DEFINE_PER_CPU(struct kvm_host_data, kvm_host_data); DEFINE_PER_CPU(struct kvm_cpu_context, kvm_hyp_ctxt);
arch/arm64/kvm/hypercalls.c +2 -2
@@ -6,8 +6,8 @@#include <asm/kvm_emulate.h> -#include <kvm/arm_hypercalls.h> -#include <kvm/arm_psci.h> +#include "arm_hypercalls.h" +#include "arm_psci.h" #define KVM_ARM_SMCCC_STD_FEATURES \ GENMASK(KVM_REG_ARM_STD_BMAP_BIT_COUNT - 1, 0)
arch/arm64/kvm/psci.c +2 -2
@@ -13,8 +13,8 @@#include <asm/cputype.h> #include <asm/kvm_emulate.h> -#include <kvm/arm_psci.h> -#include <kvm/arm_hypercalls.h> +#include "arm_hypercalls.h" +#include "arm_psci.h" /* * This is an implementation of the Power State Coordination Interface
arch/arm64/kvm/pvtime.c +1 -1
@@ -8,7 +8,7 @@#include <asm/kvm_mmu.h> #include <asm/pvclock-abi.h> -#include <kvm/arm_hypercalls.h> +#include "arm_hypercalls.h" void kvm_update_stolen_time (struct kvm_vcpu *vcpu) {
arch/arm64/kvm/trng.c +1 -1
@@ -6,7 +6,7 @@#include <asm/kvm_emulate.h> -#include <kvm/arm_hypercalls.h> +#include "arm_hypercalls.h" #define ARM_SMCCC_TRNG_VERSION_1_0 0x10000UL
Signature · 1 line
2.42.0.459.ge4e396fd5e-goog
Sean Christopherson
maintainerPATCH 13/26 KVM: arm64: Include KVM headers to get forward declarations
In reply to Sean ChristophersonInclude include/uapi/linux/kvm.h and include/linux/kvm_types.h in ARM's public arm_arch_timer.h and arm_pmu.h headers to get forward declarations of things like "struct kvm_vcpu" and "struct kvm_device_attr", which are referenced but never declared (neither file includes *any* KVM headers).
The missing includes don't currently cause problems because of the order of includes in parent files, but that order is largely arbitrary and is subject to change, e.g. a future commit will move the ARM specific headers to arch/arm64/include/asm and reorder parent includes to maintain alphabetic ordering.
--- include/kvm/arm_arch_timer.h | 2 ++ include/kvm/arm_pmu.h | 2 ++ 2 files changed, 4 insertions(+)
include/kvm/arm_arch_timer.h +2 -0
@@ -7,6 +7,8 @@#ifndef __ASM_ARM_KVM_ARCH_TIMER_H#define __ASM_ARM_KVM_ARCH_TIMER_H +#include <linux/kvm.h> +#include <linux/kvm_types.h> #include <linux/clocksource.h> #include <linux/hrtimer.h>
include/kvm/arm_pmu.h +2 -0
@@ -7,6 +7,8 @@#ifndef __ASM_ARM_KVM_PMU_H#define __ASM_ARM_KVM_PMU_H +#include <linux/kvm.h> +#include <linux/kvm_types.h> #include <linux/perf_event.h> #include <linux/perf/arm_pmuv3.h>
Signature · 1 line
2.42.0.459.ge4e396fd5e-goog
Sean Christopherson
maintainerPATCH 14/26 KVM: arm64: Move ARM specific headers in include/kvm to arch directory
In reply to Sean ChristophersonMove kvm/arm_{arch_timer,pmu,vgic}.h to arch/arm64/include/asm and drop the "arm" prefix from all file names. Now that KVM no longer supports 32-bit ARM, there is no reason to expose ARM specific headers to other architectures beyond arm64.
--- .../arm64/include/asm/kvm_arch_timer.h | 0 arch/arm64/include/asm/kvm_host.h | 7 +++---- include/kvm/arm_pmu.h => arch/arm64/include/asm/kvm_pmu.h | 0 .../kvm/arm_vgic.h => arch/arm64/include/asm/kvm_vgic.h | 0 arch/arm64/kvm/arch_timer.c | 5 ++--- arch/arm64/kvm/arm.c | 3 +-- arch/arm64/kvm/pmu-emul.c | 6 +++--- arch/arm64/kvm/reset.c | 3 +-- arch/arm64/kvm/trace_arm.h | 2 +- arch/arm64/kvm/vgic/vgic-debug.c | 2 +- arch/arm64/kvm/vgic/vgic-init.c | 2 +- arch/arm64/kvm/vgic/vgic-irqfd.c | 2 +- arch/arm64/kvm/vgic/vgic-kvm-device.c | 2 +- arch/arm64/kvm/vgic/vgic-mmio-v2.c | 2 +- arch/arm64/kvm/vgic/vgic-mmio-v3.c | 2 +- arch/arm64/kvm/vgic/vgic-mmio.c | 4 ++-- arch/arm64/kvm/vgic/vgic-v2.c | 2 +- arch/arm64/kvm/vgic/vgic-v3.c | 2 +- 18 files changed, 21 insertions(+), 25 deletions(-) rename include/kvm/arm_arch_timer.h => arch/arm64/include/asm/kvm_arch_timer.h (100%) rename include/kvm/arm_pmu.h => arch/arm64/include/asm/kvm_pmu.h (100%) rename include/kvm/arm_vgic.h => arch/arm64/include/asm/kvm_vgic.h (100%)
arch/arm64/include/asm/kvm_arch_timer.h renamed from include/kvm/arm_arch_timer.h +0 -0
arch/arm64/include/asm/kvm_host.h +3 -4
@@ -26,16 +26,15 @@#include <asm/daifflags.h> #include <asm/fpsimd.h> #include <asm/kvm.h> +#include <asm/kvm_arch_timer.h> #include <asm/kvm_asm.h> +#include <asm/kvm_pmu.h> +#include <asm/kvm_vgic.h> #define __KVM_HAVE_ARCH_INTC_INITIALIZED#define KVM_HALT_POLL_NS_DEFAULT 500000 -#include <kvm/arm_vgic.h> -#include <kvm/arm_arch_timer.h> -#include <kvm/arm_pmu.h> -#define KVM_MAX_VCPUS VGIC_V3_MAX_CPUS#define KVM_VCPU_MAX_FEATURES 7
arch/arm64/include/asm/kvm_pmu.h renamed from include/kvm/arm_pmu.h +0 -0
arch/arm64/include/asm/kvm_vgic.h renamed from include/kvm/arm_vgic.h +0 -0
arch/arm64/kvm/arch_timer.c +2 -3
@@ -14,12 +14,11 @@#include <clocksource/arm_arch_timer.h> #include <asm/arch_timer.h> +#include <asm/kvm_arch_timer.h> #include <asm/kvm_emulate.h> #include <asm/kvm_hyp.h> #include <asm/kvm_nested.h> - -#include <kvm/arm_vgic.h> -#include <kvm/arm_arch_timer.h> +#include <asm/kvm_vgic.h> #include "trace.h"
arch/arm64/kvm/arm.c +1 -2
@@ -39,10 +39,9 @@#include <asm/kvm_nested.h> #include <asm/kvm_pkvm.h> #include <asm/kvm_emulate.h> +#include <asm/kvm_pmu.h> #include <asm/sections.h> -#include <kvm/arm_pmu.h> -#include "arm_hypercalls.h" #include "arm_psci.h"
arch/arm64/kvm/pmu-emul.c +3 -3
@@ -11,10 +11,10 @@#include <linux/perf_event.h> #include <linux/perf/arm_pmu.h> #include <linux/uaccess.h> -#include <asm/kvm_emulate.h> -#include <kvm/arm_pmu.h> -#include <kvm/arm_vgic.h> #include <asm/arm_pmuv3.h> +#include <asm/kvm_emulate.h> +#include <asm/kvm_pmu.h> +#include <asm/kvm_vgic.h> #define PERF_ATTR_CFG1_COUNTER_64BIT BIT(0)
arch/arm64/kvm/reset.c +1 -2
@@ -17,12 +17,11 @@#include <linux/string.h> #include <linux/types.h> -#include <kvm/arm_arch_timer.h> -#include <asm/cpufeature.h> #include <asm/cputype.h> #include <asm/fpsimd.h> #include <asm/ptrace.h> +#include <asm/kvm_arch_timer.h> #include <asm/kvm_arm.h> #include <asm/kvm_asm.h> #include <asm/kvm_emulate.h>
arch/arm64/kvm/trace_arm.h +1 -1
@@ -3,7 +3,7 @@#define _TRACE_ARM_ARM64_KVM_H#include <asm/kvm_emulate.h> -#include <kvm/arm_arch_timer.h> +#include <asm/kvm_arch_timer.h> #include <linux/tracepoint.h> #undef TRACE_SYSTEM
arch/arm64/kvm/vgic/vgic-debug.c +1 -1
@@ -9,7 +9,7 @@#include <linux/interrupt.h> #include <linux/kvm_host.h> #include <linux/seq_file.h> -#include <kvm/arm_vgic.h> +#include <asm/kvm_vgic.h> #include <asm/kvm_mmu.h> #include "vgic.h"
arch/arm64/kvm/vgic/vgic-init.c +1 -1
@@ -7,7 +7,7 @@#include <linux/interrupt.h> #include <linux/cpu.h> #include <linux/kvm_host.h> -#include <kvm/arm_vgic.h> +#include <asm/kvm_vgic.h> #include <asm/kvm_emulate.h> #include <asm/kvm_mmu.h> #include "vgic.h"
arch/arm64/kvm/vgic/vgic-irqfd.c +1 -1
@@ -6,7 +6,7 @@#include <linux/kvm.h> #include <linux/kvm_host.h> #include <trace/events/kvm.h> -#include <kvm/arm_vgic.h> +#include <asm/kvm_vgic.h> #include "vgic.h" /**
arch/arm64/kvm/vgic/vgic-kvm-device.c +1 -1
@@ -6,7 +6,7 @@* Author: Marc Zyngier <[email protected]> */ #include <linux/kvm_host.h> -#include <kvm/arm_vgic.h> +#include <asm/kvm_vgic.h> #include <linux/uaccess.h> #include <asm/kvm_mmu.h> #include <asm/cputype.h>
arch/arm64/kvm/vgic/vgic-mmio-v2.c +1 -1
@@ -9,7 +9,7 @@#include <linux/nospec.h> #include <kvm/iodev.h> -#include <kvm/arm_vgic.h> +#include <asm/kvm_vgic.h> #include "vgic.h" #include "vgic-mmio.h"
arch/arm64/kvm/vgic/vgic-mmio-v3.c +1 -1
@@ -9,11 +9,11 @@#include <linux/kvm_host.h> #include <linux/interrupt.h> #include <kvm/iodev.h> -#include <kvm/arm_vgic.h> #include <asm/kvm_emulate.h> #include <asm/kvm_arm.h> #include <asm/kvm_mmu.h> +#include <asm/kvm_vgic.h> #include "vgic.h" #include "vgic-mmio.h"
arch/arm64/kvm/vgic/vgic-mmio.c +2 -2
@@ -10,8 +10,8 @@#include <linux/kvm.h> #include <linux/kvm_host.h> #include <kvm/iodev.h> -#include <kvm/arm_arch_timer.h> -#include <kvm/arm_vgic.h> +#include <asm/kvm_arch_timer.h> +#include <asm/kvm_vgic.h> #include "vgic.h" #include "vgic-mmio.h"
arch/arm64/kvm/vgic/vgic-v2.c +1 -1
@@ -6,7 +6,7 @@#include <linux/irqchip/arm-gic.h> #include <linux/kvm.h> #include <linux/kvm_host.h> -#include <kvm/arm_vgic.h> +#include <asm/kvm_vgic.h> #include <asm/kvm_mmu.h> #include "vgic.h"
arch/arm64/kvm/vgic/vgic-v3.c +1 -1
@@ -6,7 +6,7 @@#include <linux/kstrtox.h> #include <linux/kvm.h> #include <linux/kvm_host.h> -#include <kvm/arm_vgic.h> +#include <asm/kvm_vgic.h> #include <asm/kvm_hyp.h> #include <asm/kvm_mmu.h> #include <asm/kvm_asm.h>
Signature · 1 line
2.42.0.459.ge4e396fd5e-goog
Sean Christopherson
maintainerPATCH 15/26 KVM: Move include/kvm/iodev.h to include/linux as kvm_iodev.h
In reply to Sean ChristophersonMove iodev.h, the last remaining holdout in include/kvm, to the standard include/linux directory as kvm_iodev.h and delete include/kvm.
---
MAINTAINERS | 1 -
arch/arm64/include/asm/kvm_vgic.h | 2 +-
arch/arm64/kvm/vgic/vgic-mmio-v2.c | 2 +-
arch/arm64/kvm/vgic/vgic-mmio-v3.c | 2 +-
arch/arm64/kvm/vgic/vgic-mmio.c | 2 +-
arch/mips/include/asm/kvm_host.h | 3 +--
arch/powerpc/kvm/mpic.c | 2 +-
arch/riscv/kvm/aia_aplic.c | 2 +-
arch/riscv/kvm/aia_imsic.c | 2 +-
arch/x86/kvm/i8254.h | 2 +-
arch/x86/kvm/ioapic.h | 2 +-
arch/x86/kvm/irq.h | 2 +-
arch/x86/kvm/lapic.h | 2 +-
include/{kvm/iodev.h => linux/kvm_iodev.h} | 0
virt/kvm/coalesced_mmio.c | 3 +--
virt/kvm/eventfd.c | 2 +-
virt/kvm/kvm_main.c | 3 +--
17 files changed, 15 insertions(+), 19 deletions(-)
rename include/{kvm/iodev.h => linux/kvm_iodev.h} (100%)MAINTAINERS +0 -1
@@ -11498,7 +11498,6 @@ W: http://www.linux-kvm.org T: git git://git.kernel.org/pub/scm/virt/kvm/kvm.git F: Documentation/virt/kvm/ F: include/asm-generic/kvm* -F: include/kvm/iodev.h F: include/linux/kvm* F: include/trace/events/kvm.h F: include/uapi/asm-generic/kvm*
arch/arm64/include/asm/kvm_vgic.h +1 -1
@@ -13,7 +13,7 @@#include <linux/spinlock.h> #include <linux/static_key.h> #include <linux/types.h> -#include <kvm/iodev.h> +#include <linux/kvm_iodev.h> #include <linux/list.h> #include <linux/jump_label.h>
arch/arm64/kvm/vgic/vgic-mmio-v2.c +1 -1
@@ -6,9 +6,9 @@#include <linux/irqchip/arm-gic.h> #include <linux/kvm.h> #include <linux/kvm_host.h> +#include <linux/kvm_iodev.h> #include <linux/nospec.h> -#include <kvm/iodev.h> #include <asm/kvm_vgic.h> #include "vgic.h"
arch/arm64/kvm/vgic/vgic-mmio-v3.c +1 -1
@@ -7,8 +7,8 @@#include <linux/irqchip/arm-gic-v3.h> #include <linux/kvm.h> #include <linux/kvm_host.h> +#include <linux/kvm_iodev.h> #include <linux/interrupt.h> -#include <kvm/iodev.h> #include <asm/kvm_emulate.h> #include <asm/kvm_arm.h>
arch/arm64/kvm/vgic/vgic-mmio.c +1 -1
@@ -9,7 +9,7 @@#include <linux/irq.h> #include <linux/kvm.h> #include <linux/kvm_host.h> -#include <kvm/iodev.h> +#include <linux/kvm_iodev.h> #include <asm/kvm_arch_timer.h> #include <asm/kvm_vgic.h>
arch/mips/include/asm/kvm_host.h +1 -2
@@ -16,6 +16,7 @@#include <linux/interrupt.h> #include <linux/types.h> #include <linux/kvm.h> +#include <linux/kvm_iodev.h> #include <linux/kvm_types.h> #include <linux/threads.h> #include <linux/spinlock.h>
@@ -24,8 +25,6 @@#include <asm/inst.h> #include <asm/mipsregs.h> -#include <kvm/iodev.h> -/* MIPS KVM register ids */ #define MIPS_CP0_32 (_R, _S) \ (KVM_REG_MIPS_CP0 | KVM_REG_SIZE_U32 | (8 * (_R) + (_S)))
arch/powerpc/kvm/mpic.c +1 -1
@@ -26,6 +26,7 @@#include <linux/slab.h> #include <linux/mutex.h> #include <linux/kvm_host.h> +#include <linux/kvm_iodev.h> #include <linux/errno.h> #include <linux/fs.h> #include <linux/anon_inodes.h>
@@ -33,7 +34,6 @@#include <asm/mpic.h> #include <asm/kvm_para.h> #include <asm/kvm_ppc.h> -#include <kvm/iodev.h> #define MAX_CPU 32#define MAX_SRC 256
arch/riscv/kvm/aia_aplic.c +1 -1
@@ -11,7 +11,7 @@#include <linux/math.h> #include <linux/spinlock.h> #include <linux/swab.h> -#include <kvm/iodev.h> +#include <linux/kvm_iodev.h> #include <asm/kvm_aia_aplic.h> struct aplic_irq {
arch/riscv/kvm/aia_imsic.c +1 -1
@@ -10,10 +10,10 @@#include <linux/atomic.h> #include <linux/bitmap.h> #include <linux/kvm_host.h> +#include <linux/kvm_iodev.h> #include <linux/math.h> #include <linux/spinlock.h> #include <linux/swab.h> -#include <kvm/iodev.h> #include <asm/csr.h> #include <asm/kvm_aia_imsic.h>
arch/x86/kvm/i8254.h +1 -1
@@ -4,7 +4,7 @@#include <linux/kthread.h> -#include <kvm/iodev.h> +#include <linux/kvm_iodev.h> struct kvm_kpit_channel_state {u32 count;/* can be 65536 */
arch/x86/kvm/ioapic.h +1 -1
@@ -3,7 +3,7 @@#define __KVM_IO_APIC_H#include <linux/kvm_host.h> -#include <kvm/iodev.h> +#include <linux/kvm_iodev.h> #include "irq.h" struct kvm ;
arch/x86/kvm/irq.h +1 -1
@@ -13,9 +13,9 @@#include <linux/mm_types.h> #include <linux/hrtimer.h> #include <linux/kvm_host.h> +#include <linux/kvm_iodev.h> #include <linux/spinlock.h> -#include <kvm/iodev.h> #include "lapic.h" #define PIC_NUM_PINS 16
arch/x86/kvm/lapic.h +1 -1
@@ -2,7 +2,7 @@#ifndef __KVM_X86_LAPIC_H#define __KVM_X86_LAPIC_H -#include <kvm/iodev.h> +#include <linux/kvm_iodev.h> #include <linux/kvm_host.h>
include/linux/kvm_iodev.h renamed from include/kvm/iodev.h +0 -0
virt/kvm/coalesced_mmio.c +1 -2
@@ -9,8 +9,7 @@* */ -#include <kvm/iodev.h> - +#include <linux/kvm_iodev.h> #include <linux/kvm_host.h> #include <linux/slab.h> #include <linux/kvm.h>
virt/kvm/eventfd.c +1 -1
@@ -26,7 +26,7 @@#include <linux/irqbypass.h> #include <trace/events/kvm.h> -#include <kvm/iodev.h> +#include <linux/kvm_iodev.h> #ifdef CONFIG_HAVE_KVM_IRQFD
virt/kvm/kvm_main.c +1 -2
@@ -13,9 +13,8 @@* Yaniv Kamay <[email protected]> */ -#include <kvm/iodev.h> -#include <linux/kvm_host.h> +#include <linux/kvm_iodev.h> #include <linux/kvm.h> #include <linux/module.h> #include <linux/errno.h>
Signature · 1 line
2.42.0.459.ge4e396fd5e-goog
Re: [PATCH 15/26] KVM: Move include/kvm/iodev.h to include/linux as kvm_iodev.h
Quoted 5 lines · On Sat, Sep 16, 2023 at 6:01?AM Sean Christopherson <[email protected]> wrote:
Move
iodev.h, the last remaining holdout ininclude/kvm, to the standardinclude/linuxdirectory askvm_iodev.hand deleteinclude/kvm.Signed-off-by Sean Christopherson <[email protected]>
For KVM RISC-V:
Regards,
Anup
Quoted 261 lines
--- MAINTAINERS | 1 - arch/arm64/include/asm/kvm_vgic.h | 2 +- arch/arm64/kvm/vgic/vgic-mmio-v2.c | 2 +- arch/arm64/kvm/vgic/vgic-mmio-v3.c | 2 +- arch/arm64/kvm/vgic/vgic-mmio.c | 2 +- arch/mips/include/asm/kvm_host.h | 3 +-- arch/powerpc/kvm/mpic.c | 2 +- arch/riscv/kvm/aia_aplic.c | 2 +- arch/riscv/kvm/aia_imsic.c | 2 +- arch/x86/kvm/i8254.h | 2 +- arch/x86/kvm/ioapic.h | 2 +- arch/x86/kvm/irq.h | 2 +- arch/x86/kvm/lapic.h | 2 +- include/{kvm/iodev.h => linux/kvm_iodev.h} | 0 virt/kvm/coalesced_mmio.c | 3 +-- virt/kvm/eventfd.c | 2 +- virt/kvm/kvm_main.c | 3 +-- 17 files changed, 15 insertions(+), 19 deletions(-) rename include/{kvm/iodev.h => linux/kvm_iodev.h} (100%)MAINTAINERS +0
-1@@ -11498,7 +11498,6 @@ W: http://www.linux-kvm.org T: git git://git.kernel.org/pub/scm/virt/kvm/kvm.git F: Documentation/virt/kvm/ F: include/asm-generic/kvm* -F: include/kvm/iodev.h F: include/linux/kvm* F: include/trace/events/kvm.h F: include/uapi/asm-generic/kvm*arch/arm64/include/asm/kvm_vgic.h +1
-1@@ -13,7 +13,7 @@#include <linux/spinlock.h> #include <linux/static_key.h> #include <linux/types.h> -#include <kvm/iodev.h> +#include <linux/kvm_iodev.h> #include <linux/list.h> #include <linux/jump_label.h> arch/arm64/kvm/vgic/vgic-mmio-v2.c +1
-1@@ -6,9 +6,9 @@#include <linux/irqchip/arm-gic.h> #include <linux/kvm.h> #include <linux/kvm_host.h> +#include <linux/kvm_iodev.h> #include <linux/nospec.h> -#include <kvm/iodev.h> #include <asm/kvm_vgic.h> #include "vgic.h" arch/arm64/kvm/vgic/vgic-mmio-v3.c +1
-1@@ -7,8 +7,8 @@#include <linux/irqchip/arm-gic-v3.h> #include <linux/kvm.h> #include <linux/kvm_host.h> +#include <linux/kvm_iodev.h> #include <linux/interrupt.h> -#include <kvm/iodev.h> #include <asm/kvm_emulate.h> #include <asm/kvm_arm.h> arch/arm64/kvm/vgic/vgic-mmio.c +1
-1@@ -9,7 +9,7 @@#include <linux/irq.h> #include <linux/kvm.h> #include <linux/kvm_host.h> -#include <kvm/iodev.h> +#include <linux/kvm_iodev.h> #include <asm/kvm_arch_timer.h> #include <asm/kvm_vgic.h> arch/mips/include/asm/kvm_host.h +1
-2@@ -16,6 +16,7 @@#include <linux/interrupt.h> #include <linux/types.h> #include <linux/kvm.h> +#include <linux/kvm_iodev.h> #include <linux/kvm_types.h> #include <linux/threads.h> #include <linux/spinlock.h> @@ -24,8 +25,6 @@#include <asm/inst.h> #include <asm/mipsregs.h> -#include <kvm/iodev.h> -/* MIPS KVM register ids */ #define MIPS_CP0_32 (_R, _S) \ (KVM_REG_MIPS_CP0 | KVM_REG_SIZE_U32 | (8 * (_R) + (_S)))arch/powerpc/kvm/mpic.c +1
-1@@ -26,6 +26,7 @@#include <linux/slab.h> #include <linux/mutex.h> #include <linux/kvm_host.h> +#include <linux/kvm_iodev.h> #include <linux/errno.h> #include <linux/fs.h> #include <linux/anon_inodes.h> @@ -33,7 +34,6 @@#include <asm/mpic.h> #include <asm/kvm_para.h> #include <asm/kvm_ppc.h> -#include <kvm/iodev.h> #define MAX_CPU 32#define MAX_SRC 256arch/riscv/kvm/aia_aplic.c +1
-1@@ -11,7 +11,7 @@#include <linux/math.h> #include <linux/spinlock.h> #include <linux/swab.h> -#include <kvm/iodev.h> +#include <linux/kvm_iodev.h> #include <asm/kvm_aia_aplic.h> struct aplic_irq {arch/riscv/kvm/aia_imsic.c +1
-1@@ -10,10 +10,10 @@#include <linux/atomic.h> #include <linux/bitmap.h> #include <linux/kvm_host.h> +#include <linux/kvm_iodev.h> #include <linux/math.h> #include <linux/spinlock.h> #include <linux/swab.h> -#include <kvm/iodev.h> #include <asm/csr.h> #include <asm/kvm_aia_imsic.h> arch/x86/kvm/i8254.h +1
-1@@ -4,7 +4,7 @@#include <linux/kthread.h> -#include <kvm/iodev.h> +#include <linux/kvm_iodev.h> struct kvm_kpit_channel_state {u32 count;/* can be 65536 */ arch/x86/kvm/ioapic.h +1
-1@@ -3,7 +3,7 @@#define __KVM_IO_APIC_H#include <linux/kvm_host.h> -#include <kvm/iodev.h> +#include <linux/kvm_iodev.h> #include "irq.h" struct kvm ;arch/x86/kvm/irq.h +1
-1@@ -13,9 +13,9 @@#include <linux/mm_types.h> #include <linux/hrtimer.h> #include <linux/kvm_host.h> +#include <linux/kvm_iodev.h> #include <linux/spinlock.h> -#include <kvm/iodev.h> #include "lapic.h" #define PIC_NUM_PINS 16arch/x86/kvm/lapic.h +1
-1@@ -2,7 +2,7 @@#ifndef __KVM_X86_LAPIC_H#define __KVM_X86_LAPIC_H -#include <kvm/iodev.h> +#include <linux/kvm_iodev.h> #include <linux/kvm_host.h> include/linux/kvm_iodev.h renamed from include/kvm/iodev.h +0
-0virt/kvm/coalesced_mmio.c +1
-2@@ -9,8 +9,7 @@* */ -#include <kvm/iodev.h> - +#include <linux/kvm_iodev.h> #include <linux/kvm_host.h> #include <linux/slab.h> #include <linux/kvm.h> virt/kvm/eventfd.c +1
-1@@ -26,7 +26,7 @@#include <linux/irqbypass.h> #include <trace/events/kvm.h> -#include <kvm/iodev.h> +#include <linux/kvm_iodev.h> #ifdef CONFIG_HAVE_KVM_IRQFD virt/kvm/kvm_main.c +1
-3@@ -13,9 +13,8 @@* Yaniv Kamay <[email protected]> */ -#include <kvm/iodev.h> -#include <linux/kvm_host.h> +#include <linux/kvm_iodev.h> #include <linux/kvm.h> #include <linux/module.h> #include <linux/errno.h> --2.42.0.459.ge4e396fd5e-goog
Sean Christopherson
maintainerPATCH 16/26 KVM: MIPS: Stop adding virt/kvm to the arch include path
In reply to Sean ChristophersonDon't add virt/kvm to KVM MIPS' include path, the headers in virt/kvm are intended to be used only by other code in virt/kvm, i.e. are "private" to the core KVM code. It's not clear that MIPS *ever* included a header from virt/kvm, i.e. odds are good the "-Ivirt/kvm" was copied from a different architecture's Makefile when MIPS support was first added.
--- arch/mips/kvm/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/mips/kvm/Makefile +1 -1
@@ -4,7 +4,7 @@ include $(srctree)/virt/kvm/Makefile.kvm -ccflags-y += -Ivirt/kvm -Iarch/mips/kvm +ccflags-y += -Iarch/mips/kvm kvm-$(CONFIG_CPU_HAS_MSA) += msa.o
Signature · 1 line
2.42.0.459.ge4e396fd5e-goog
Sean Christopherson
maintainerPATCH 17/26 KVM: PPC: Stop adding virt/kvm to the arch include path
In reply to Sean ChristophersonDon't add virt/kvm to KVM PPC's include path, the headers in virt/kvm are intended to be used only by other code in virt/kvm, i.e. are "private" to the core KVM code. It's not clear that PPC *ever* included a header from virt/kvm, i.e. odds are good the "-Ivirt/kvm" was copied from a different architecture's Makefile when PPC support was first added.
--- arch/powerpc/kvm/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/kvm/Makefile +1 -1
@@ -3,7 +3,7 @@ # Makefile for Kernel-based Virtual Machine module # -ccflags-y := -Ivirt/kvm -Iarch/powerpc/kvm +ccflags-y := -Iarch/powerpc/kvm include $(srctree)/virt/kvm/Makefile.kvm
Signature · 1 line
2.42.0.459.ge4e396fd5e-goog
Sean Christopherson
maintainerPATCH 18/26 KVM: s390: Stop adding virt/kvm to the arch include path
In reply to Sean ChristophersonDon't add virt/kvm to KVM s390's include path, the headers in virt/kvm are intended to be used only by other code in virt/kvm, i.e. are "private" to the core KVM code. It's not clear that s390 *ever* included a header from virt/kvm, i.e. odds are good the "-Ivirt/kvm" was copied from a x86's Makefile when s390 support was first added.
The only headers in virt/kvm at the time were the x86 specific ioapic.h, and iodev.h, neither of which shows up as an #include in the diff for the commit range 37817f2982d0f..e976a2b997fc4.
--- arch/s390/kvm/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/s390/kvm/Makefile +1 -1
@@ -5,7 +5,7 @@ include $(srctree)/virt/kvm/Makefile.kvm -ccflags-y := -Ivirt/kvm -Iarch/s390/kvm +ccflags-y := -Iarch/s390/kvm kvm-y += kvm-s390.o intercept.o interrupt.o priv.o sigp.o kvm-y += diag.o gaccess.o guestdbg.o vsie.o pv.o
Signature · 1 line
2.42.0.459.ge4e396fd5e-goog
Re: [PATCH 18/26] KVM: s390: Stop adding virt/kvm to the arch include path
Quoted 20 lines · Sean Christopherson
Don't add
virt/kvmto KVM s390's include path, the headers invirt/kvmare intended to be used only by other code invirt/kvm, i.e. are "private" to the core KVM code. It's not clear that s390 *ever* included a header fromvirt/kvm, i.e. odds are good the "-Ivirt/kvm" was copied from a x86'sMakefilewhen s390 support was first added.The only headers in
virt/kvmat the time were the x86 specificioapic.h, andiodev.h, neither of which shows up as an #include in the diff for the commit range37817f2982d0f..e976a2b997fc4.Signed-off-by Sean Christopherson <[email protected]>--- arch/s390/kvm/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/s390/kvm/Makefile +0
-0
arch/s390/kvm/Makefile line 11
Quoted 8 lines
arch/s390/kvm/Makefile +1
-1@@ -5,7 +5,7 @@ include $(srctree)/virt/kvm/Makefile.kvm -ccflags-y := -Ivirt/kvm -Iarch/s390/kvm +ccflags-y := -Iarch/s390/kvm kvm-y += kvm-s390.o intercept.o interrupt.o priv.o sigp.o kvm-y += diag.o gaccess.o guestdbg.o vsie.o pv.o
Re: [PATCH 18/26] KVM: s390: Stop adding virt/kvm to the arch include path
In reply to Sean ChristophersonQuoted 20 lines · On Fri, 15 Sep 2023 17:31:10 -0700 Sean Christopherson <[email protected]>…
Don't add
virt/kvmto KVM s390's include path, the headers invirt/kvmare intended to be used only by other code invirt/kvm, i.e. are "private" to the core KVM code. It's not clear that s390 *ever* included a header fromvirt/kvm, i.e. odds are good the "-Ivirt/kvm" was copied from a x86'sMakefilewhen s390 support was first added.The only headers in
virt/kvmat the time were the x86 specificioapic.h, andiodev.h, neither of which shows up as an #include in the diff for the commit range37817f2982d0f..e976a2b997fc4.Signed-off-by Sean Christopherson <[email protected]>--- arch/s390/kvm/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/s390/kvm/Makefile +0
-0
arch/s390/kvm/Makefile line 11
Quoted 8 lines
arch/s390/kvm/Makefile +1
-1@@ -5,7 +5,7 @@ include $(srctree)/virt/kvm/Makefile.kvm -ccflags-y := -Ivirt/kvm -Iarch/s390/kvm +ccflags-y := -Iarch/s390/kvm kvm-y += kvm-s390.o intercept.o interrupt.o priv.o sigp.o kvm-y += diag.o gaccess.o guestdbg.o vsie.o pv.o
Sean Christopherson
maintainerPATCH 19/26 KVM: Standardize include paths across all architectures
In reply to Sean ChristophersonStandardize KVM's include paths across all architectures by declaring the KVM-specific includes in the common Makefile.kvm. Having common KVM "own" the included paths reduces the temptation to unnecessarily add virt/kvm to arch include paths, and conversely if allowing arch code to grab headers from virt/kvm becomes desirable, virt/kvm can be added to all architecture's include path with a single line update.
Having the common KVM makefile append to ccflags also provides a convenient location to append other things, e.g. KVM-specific #defines.
Note, this changes the behavior of s390 and PPC, as s390 and PPC previously overwrote ccflags-y instead of adding on. There is no evidence that overwriting ccflags-y was necessary or even deliberate, as both s390 and PPC switched to the overwrite behavior without so much as a passing mention when EXTRA_CFLAGS was replaced with ccflags-y (commit c73028a02887 ("s390: change to new flag variable") and commit 4108d9ba9091 ("powerpc/Makefiles: Change to new flag variables")).
--- arch/arm64/kvm/Makefile | 2 -- arch/mips/kvm/Makefile | 2 -- arch/powerpc/kvm/Makefile | 2 -- arch/riscv/kvm/Makefile | 2 -- arch/s390/kvm/Makefile | 2 -- arch/x86/kvm/Makefile | 1 - virt/kvm/Makefile.kvm | 2 ++ 7 files changed, 2 insertions(+), 11 deletions(-)
arch/arm64/kvm/Makefile +0 -2
@@ -3,8 +3,6 @@ # Makefile for Kernel-based Virtual Machine module # -ccflags-y += -I $(srctree)/$(src) - include $(srctree)/virt/kvm/Makefile.kvm obj-$(CONFIG_KVM) += kvm.o
arch/mips/kvm/Makefile +0 -2
@@ -4,8 +4,6 @@ include $(srctree)/virt/kvm/Makefile.kvm -ccflags-y += -Iarch/mips/kvm - kvm-$(CONFIG_CPU_HAS_MSA) += msa.o kvm-y += mips.o emulate.o entry.o \
arch/powerpc/kvm/Makefile +0 -2
@@ -3,8 +3,6 @@ # Makefile for Kernel-based Virtual Machine module # -ccflags-y := -Iarch/powerpc/kvm - include $(srctree)/virt/kvm/Makefile.kvm common-objs-y += powerpc.o emulate_loadstore.o
arch/riscv/kvm/Makefile +0 -2
@@ -3,8 +3,6 @@ # Makefile for RISC-V KVM support # -ccflags-y += -I $(srctree)/$(src) - include $(srctree)/virt/kvm/Makefile.kvm obj-$(CONFIG_KVM) += kvm.o
arch/s390/kvm/Makefile +0 -2
@@ -5,8 +5,6 @@ include $(srctree)/virt/kvm/Makefile.kvm -ccflags-y := -Iarch/s390/kvm - kvm-y += kvm-s390.o intercept.o interrupt.o priv.o sigp.o kvm-y += diag.o gaccess.o guestdbg.o vsie.o pv.o
arch/x86/kvm/Makefile +0 -1
@@ -1,6 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 -ccflags-y += -I $(srctree)/arch/x86/kvm ccflags-$(CONFIG_KVM_WERROR) += -Werror ifeq ($(CONFIG_FRAME_POINTER),y)
virt/kvm/Makefile.kvm +2 -0
@@ -3,6 +3,8 @@ # Makefile for Kernel-based Virtual Machine module # +ccflags-y += -I$(srctree)/$(src) + KVM ?= ../../../virt/kvm kvm-y := $(KVM)/kvm_main.o $(KVM)/eventfd.o $(KVM)/binary_stats.o
Signature · 1 line
2.42.0.459.ge4e396fd5e-goog
Re: [PATCH 19/26] KVM: Standardize include paths across all architectures
Quoted 19 lines · On Sat, Sep 16, 2023 at 6:01?AM Sean Christopherson <[email protected]> wrote:
Standardize KVM's include paths across all architectures by declaring the KVM-specific includes in the common Makefile.kvm. Having common KVM "own" the included paths reduces the temptation to unnecessarily add
virt/kvmto arch include paths, and conversely if allowing arch code to grab headers fromvirt/kvmbecomes desirable,virt/kvmcan be added to all architecture's include path with a single line update.Having the common KVM makefile append to ccflags also provides a convenient location to append other things, e.g. KVM-specific #defines.
Note, this changes the behavior of s390 and PPC, as s390 and PPC previously overwrote ccflags-y instead of adding on. There is no evidence that overwriting ccflags-y was necessary or even deliberate, as both s390 and PPC switched to the overwrite behavior without so much as a passing mention when
EXTRA_CFLAGSwas replaced with ccflags-y (commitc73028a02887("s390: change to new flag variable") and commit4108d9ba9091("powerpc/Makefiles: Change to new flag variables")).
Quoted 1 line
Signed-off-by Sean Christopherson <[email protected]>
For KVM RISC-V:
Regards,
Anup
Quoted 102 lines
--- arch/arm64/kvm/Makefile | 2 -- arch/mips/kvm/Makefile | 2 -- arch/powerpc/kvm/Makefile | 2 -- arch/riscv/kvm/Makefile | 2 -- arch/s390/kvm/Makefile | 2 -- arch/x86/kvm/Makefile | 1 - virt/kvm/Makefile.kvm | 2 ++ 7 files changed, 2 insertions(+), 11 deletions(-)arch/arm64/kvm/Makefile +0
-2@@ -3,8 +3,6 @@ # Makefile for Kernel-based Virtual Machine module # -ccflags-y += -I $(srctree)/$(src) - include $(srctree)/virt/kvm/Makefile.kvm obj-$(CONFIG_KVM) += kvm.oarch/mips/kvm/Makefile +0
-2@@ -4,8 +4,6 @@ include $(srctree)/virt/kvm/Makefile.kvm -ccflags-y += -Iarch/mips/kvm - kvm-$(CONFIG_CPU_HAS_MSA) += msa.o kvm-y += mips.o emulate.o entry.o \arch/powerpc/kvm/Makefile +0
-2@@ -3,8 +3,6 @@ # Makefile for Kernel-based Virtual Machine module # -ccflags-y := -Iarch/powerpc/kvm - include $(srctree)/virt/kvm/Makefile.kvm common-objs-y += powerpc.o emulate_loadstore.oarch/riscv/kvm/Makefile +0
-2@@ -3,8 +3,6 @@ # Makefile for RISC-V KVM support # -ccflags-y += -I $(srctree)/$(src) - include $(srctree)/virt/kvm/Makefile.kvm obj-$(CONFIG_KVM) += kvm.oarch/s390/kvm/Makefile +0
-2@@ -5,8 +5,6 @@ include $(srctree)/virt/kvm/Makefile.kvm -ccflags-y := -Iarch/s390/kvm - kvm-y += kvm-s390.o intercept.o interrupt.o priv.o sigp.o kvm-y += diag.o gaccess.o guestdbg.o vsie.o pv.oarch/x86/kvm/Makefile +0
-1@@ -1,6 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 -ccflags-y += -I $(srctree)/arch/x86/kvm ccflags-$(CONFIG_KVM_WERROR) += -Werror ifeq ($(CONFIG_FRAME_POINTER),y)virt/kvm/Makefile.kvm +2
-1@@ -3,6 +3,8 @@ # Makefile for Kernel-based Virtual Machine module # +ccflags-y += -I$(srctree)/$(src) + KVM ?= ../../../virt/kvm kvm-y := $(KVM)/kvm_main.o $(KVM)/eventfd.o $(KVM)/binary_stats.o --2.42.0.459.ge4e396fd5e-goog
Sean Christopherson
maintainerPATCH 20/26 perf/x86: KVM: Have perf define a dedicated struct for getting guest PEBS data
In reply to Sean ChristophersonHave perf define a struct for getting guest PEBS data from KVM instead of poking into the kvm_pmu structure. Passing in an entire "struct kvm_pmu" _as an opaque pointer_ to get at three fields is silly, especially since one of the fields exists purely to convey information to perf, i.e. isn't used by KVM.
Perf should also own its APIs, i.e. define what fields/data it needs, not rely on KVM to throw fields into data structures that effectively hold KVM-internal state.
--- arch/x86/events/core.c | 5 +++-- arch/x86/events/intel/core.c | 18 +++++++++--------- arch/x86/events/perf_event.h | 3 ++- arch/x86/include/asm/kvm_host.h | 9 --------- arch/x86/include/asm/perf_event.h | 12 ++++++++++-- arch/x86/kvm/vmx/pmu_intel.c | 16 +++++++++++++--- arch/x86/kvm/vmx/vmx.c | 10 ++++++---- arch/x86/kvm/vmx/vmx.h | 2 +- 8 files changed, 44 insertions(+), 31 deletions(-)
arch/x86/events/core.c +3 -2
@@ -695,9 +695,10 @@ void x86_pmu_disable_all(void) } } -struct perf_guest_switch_msr *perf_guest_get_msrs (int *nr,void *data) +struct perf_guest_switch_msr *perf_guest_get_msrs (int *nr, +struct x86_guest_pebs *guest_pebs) { -return static_call (x86_pmu_guest_get_msrs)(nr, data); +return static_call (x86_pmu_guest_get_msrs)(nr, guest_pebs); }EXPORT_SYMBOL_GPL (perf_guest_get_msrs);
arch/x86/events/intel/core.c +9 -9
@@ -14,7 +14,6 @@#include <linux/slab.h> #include <linux/export.h> #include <linux/nmi.h> -#include <linux/kvm_host.h> #include <asm/cpufeature.h> #include <asm/hardirq.h>
@@ -4053,11 +4052,11 @@ static int intel_pmu_hw_config(struct perf_event *event)* when it uses {RD,WR}MSR, which should be handled by the KVM context, * specifically in the intel_pmu_{get,set}_msr(). */ -static struct perf_guest_switch_msr *intel_guest_get_msrs (int *nr,void *data) +static struct perf_guest_switch_msr *intel_guest_get_msrs (int *nr, +struct x86_guest_pebs *guest_pebs) {struct cpu_hw_events *cpuc =this_cpu_ptr (&cpu_hw_events);struct perf_guest_switch_msr *arr = cpuc->guest_switch_msrs; -struct kvm_pmu *kvm_pmu = (struct kvm_pmu *)data;u64 intel_ctrl =hybrid (cpuc->pmu, intel_ctrl);u64 pebs_mask = cpuc->pebs_enabled & x86_pmu.pebs_capable;int global_ctrl, pebs_enable;
@@ -4090,20 +4089,20 @@ static struct perf_guest_switch_msr *intel_guest_get_msrs(int *nr, void *data)return arr; } -if (!kvm_pmu || !x86_pmu.pebs_ept) +if (!guest_pebs || !x86_pmu.pebs_ept)return arr; arr[(*nr)++] = (struct perf_guest_switch_msr ){ .msr =MSR_IA32_DS_AREA , .host = (unsigned long )cpuc->ds, - .guest = kvm_pmu->ds_area, + .guest = guest_pebs->ds_area, };if (x86_pmu.intel_cap.pebs_baseline) { arr[(*nr)++] = (struct perf_guest_switch_msr ){ .msr =MSR_PEBS_DATA_CFG , .host = cpuc->active_pebs_data_cfg, - .guest = kvm_pmu->pebs_data_cfg, + .guest = guest_pebs->data_cfg, }; }
@@ -4119,8 +4118,8 @@ static struct perf_guest_switch_msr *intel_guest_get_msrs(int *nr, void *data) arr[pebs_enable].guest =0 ; }else {/* Disable guest PEBS thoroughly for cross-mapped PEBS counters. */ - arr[pebs_enable].guest &= ~kvm_pmu->host_cross_mapped_mask; - arr[global_ctrl].guest &= ~kvm_pmu->host_cross_mapped_mask; + arr[pebs_enable].guest &= ~guest_pebs->cross_mapped_mask; + arr[global_ctrl].guest &= ~guest_pebs->cross_mapped_mask;/* Set hw GLOBAL_CTRL bits for PEBS counter when it runs for guest */ arr[global_ctrl].guest |= arr[pebs_enable].guest; }
@@ -4128,7 +4127,8 @@ static struct perf_guest_switch_msr *intel_guest_get_msrs(int *nr, void *data)return arr; } -static struct perf_guest_switch_msr *core_guest_get_msrs (int *nr,void *data) +static struct perf_guest_switch_msr *core_guest_get_msrs (int *nr, +struct x86_guest_pebs *guest_pebs) {struct cpu_hw_events *cpuc =this_cpu_ptr (&cpu_hw_events);struct perf_guest_switch_msr *arr = cpuc->guest_switch_msrs;
arch/x86/events/perf_event.h +2 -1
@@ -920,7 +920,8 @@ struct x86_pmu {/* * Intel host/guest support (KVM) */ -struct perf_guest_switch_msr *(*guest_get_msrs)(int *nr,void *data); +struct perf_guest_switch_msr *(*guest_get_msrs)(int *nr, +struct x86_guest_pebs *guest_pebs);/* * Check period value for PERF_EVENT_IOC_PERIOD ioctl.
arch/x86/include/asm/kvm_host.h +0 -9
@@ -548,15 +548,6 @@ struct kvm_pmu {u64 pebs_data_cfg;u64 pebs_data_cfg_mask; -/* -* If a guest counter is cross-mapped to host counter with different -* index, its PEBS capability will be temporarily disabled. -* -* The user should make sure that this mask is updated -* after disabling interrupts and before perf_guest_get_msrs(); -*/ -u64 host_cross_mapped_mask; -/* * The gate to release perf_events not marked in * pmc_in_use only once in a vcpu time slice.
arch/x86/include/asm/perf_event.h +10 -2
@@ -564,11 +564,19 @@ static inline void perf_events_lapic_init(void) { }static inline void perf_check_microcode (void ) { }#endif +struct x86_guest_pebs { +u64 ds_area; +u64 data_cfg; +u64 cross_mapped_mask; +}; +#if defined(CONFIG_PERF_EVENTS ) && defined(CONFIG_CPU_SUP_INTEL ) -extern struct perf_guest_switch_msr *perf_guest_get_msrs (int *nr,void *data); +extern struct perf_guest_switch_msr *perf_guest_get_msrs (int *nr, +struct x86_guest_pebs *guest_pebs);extern void x86_perf_get_lbr (struct x86_pmu_lbr *lbr);#else -struct perf_guest_switch_msr *perf_guest_get_msrs (int *nr,void *data); +struct perf_guest_switch_msr *perf_guest_get_msrs (int *nr, +struct x86_guest_pebs *guest_pebs);static inline void x86_perf_get_lbr (struct x86_pmu_lbr *lbr) {memset (lbr,0 ,sizeof (*lbr));
arch/x86/kvm/vmx/pmu_intel.c +13 -3
@@ -765,11 +765,20 @@ static void intel_pmu_cleanup(struct kvm_vcpu *vcpu)intel_pmu_release_guest_lbr_event (vcpu); } -void intel_pmu_cross_mapped_check (struct kvm_pmu *pmu) +u64 intel_pmu_get_cross_mapped_mask (struct kvm_pmu *pmu) { -struct kvm_pmc *pmc =NULL ; +u64 host_cross_mapped_mask; +struct kvm_pmc *pmc;int bit, hw_idx; +if (!(pmu->pebs_enable & pmu->global_ctrl)) +return 0 ; + +/* +* If a guest counter is cross-mapped to host counter with different +* index, its PEBS capability will be temporarily disabled. +*/ + host_cross_mapped_mask =0 ;for_each_set_bit (bit, (unsigned long *)&pmu->global_ctrl,X86_PMC_IDX_MAX ) { pmc =intel_pmc_idx_to_pmc (pmu, bit);
@@ -784,8 +793,9 @@ void intel_pmu_cross_mapped_check(struct kvm_pmu *pmu)*/ hw_idx = pmc->perf_event->hw.idx;if (hw_idx != pmc->idx && hw_idx >-1 ) - pmu->host_cross_mapped_mask |=BIT_ULL (hw_idx); + host_cross_mapped_mask |=BIT_ULL (hw_idx); } +return host_cross_mapped_mask; }struct kvm_pmu_ops intel_pmu_ops__initdata = {
arch/x86/kvm/vmx/vmx.c +6 -4
@@ -7131,12 +7131,14 @@ static void atomic_switch_perf_msrs(struct vcpu_vmx *vmx)struct perf_guest_switch_msr *msrs;struct kvm_pmu *pmu =vcpu_to_pmu (&vmx->vcpu); - pmu->host_cross_mapped_mask =0 ; -if (pmu->pebs_enable & pmu->global_ctrl) -intel_pmu_cross_mapped_check (pmu); +struct x86_guest_pebs guest_pebs = { + .ds_area = pmu->ds_area, + .data_cfg = pmu->pebs_data_cfg, + .cross_mapped_mask =intel_pmu_get_cross_mapped_mask (pmu), + };/* Note, nr_msrs may be garbage if perf_guest_get_msrs() returns NULL. */ - msrs =perf_guest_get_msrs (&nr_msrs, (void *)pmu); + msrs =perf_guest_get_msrs (&nr_msrs, &guest_pebs);if (!msrs)return ;
arch/x86/kvm/vmx/vmx.h +1 -1
@@ -670,7 +670,7 @@ static inline bool intel_pmu_lbr_is_enabled(struct kvm_vcpu *vcpu)return !!vcpu_to_lbr_records (vcpu)->nr; } -void intel_pmu_cross_mapped_check (struct kvm_pmu *pmu); +u64 intel_pmu_get_cross_mapped_mask (struct kvm_pmu *pmu);int intel_pmu_create_guest_lbr_event (struct kvm_vcpu *vcpu);void vmx_passthrough_lbr_msrs (struct kvm_vcpu *vcpu);
Signature · 1 line
2.42.0.459.ge4e396fd5e-goog
Sean Christopherson
maintainerPATCH 21/26 entry/kvm: Drop @vcpu param from arch_xfer_to_guest_mode_handle_work()
In reply to Sean ChristophersonDrop the "struct kvm_vcpu" parameter from arch_xfer_to_guest_mode_handle_work() as a preparatory step towards removing the vCPU parameter from xfer_to_guest_mode_work() as well.
--- include/linux/entry-kvm.h | 7 ++----- kernel/entry/kvm.c | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-)
include/linux/entry-kvm.h +2 -5
@@ -25,18 +25,15 @@ struct kvm_vcpu;/** * arch_xfer_to_guest_mode_handle_work - Architecture specific xfer to guest * mode work handling function. -* @vcpu: Pointer to current's VCPU data * @ti_work: Cached TIF flags gathered in xfer_to_guest_mode_handle_work() * * Invoked from xfer_to_guest_mode_handle_work(). Defaults to NOOP. Can be * replaced by architecture specific code. */ -static inline int arch_xfer_to_guest_mode_handle_work (struct kvm_vcpu *vcpu, -unsigned long ti_work); +static inline int arch_xfer_to_guest_mode_handle_work (unsigned long ti_work);#ifndef arch_xfer_to_guest_mode_work -static inline int arch_xfer_to_guest_mode_handle_work (struct kvm_vcpu *vcpu, -unsigned long ti_work) +static inline int arch_xfer_to_guest_mode_handle_work (unsigned long ti_work) {return 0 ; }
kernel/entry/kvm.c +1 -1
@@ -19,7 +19,7 @@ static int xfer_to_guest_mode_work(struct kvm_vcpu *vcpu, unsigned long ti_work)if (ti_work & _TIF_NOTIFY_RESUME)resume_user_mode_work (NULL ); - ret =arch_xfer_to_guest_mode_handle_work (vcpu, ti_work); + ret =arch_xfer_to_guest_mode_handle_work (ti_work);if (ret)return ret;
Signature · 1 line
2.42.0.459.ge4e396fd5e-goog
Sean Christopherson
maintainerPATCH 22/26 entry/kvm: KVM: Move KVM details related to signal/-EINTR into KVM proper
In reply to Sean ChristophersonMove KVM's morphing of pending signals into exits to userspace into KVM proper, and drop the @vcpu param from xfer_to_guest_mode_handle_work(). How KVM responds to -EINTR is a detail that really belongs in KVM itself, and removing the non-KVM call to kvm_handle_signal_exit() will allow hiding said API and the definition of "struct kvm_vcpu" from the kernel.
Alternatively, entry/kvm.c could be treated as part of KVM, i.e. be given access to KVM internals, but that's not obviously better than having KVM react to -EINTR (though it's not obviously worse either).
--- arch/arm64/kvm/arm.c | 3 +-- arch/riscv/kvm/vcpu.c | 2 +- arch/x86/kvm/vmx/vmx.c | 1 - arch/x86/kvm/x86.c | 3 +-- include/linux/entry-kvm.h | 3 +-- include/linux/kvm_host.h | 13 ++++++++++++- kernel/entry/kvm.c | 11 ++++------- 7 files changed, 20 insertions(+), 16 deletions(-)
arch/arm64/kvm/arm.c +1 -2
@@ -6,7 +6,6 @@#include <linux/bug.h> #include <linux/cpu_pm.h> -#include <linux/entry-kvm.h> #include <linux/errno.h> #include <linux/err.h> #include <linux/kvm_host.h>
@@ -929,7 +928,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)/* * Check conditions before entering the guest */ - ret =xfer_to_guest_mode_handle_work (vcpu); + ret =kvm_xfer_to_guest_mode_handle_work (vcpu);if (!ret) ret =1 ;
arch/riscv/kvm/vcpu.c +1 -1
@@ -667,7 +667,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) run->exit_reason =KVM_EXIT_UNKNOWN ;while (ret >0 ) {/* Check conditions before entering the guest */ - ret =xfer_to_guest_mode_handle_work (vcpu); + ret =kvm_xfer_to_guest_mode_handle_work (vcpu);if (ret)continue ; ret =1 ;
arch/x86/kvm/vmx/vmx.c +0 -1
@@ -28,7 +28,6 @@#include <linux/slab.h> #include <linux/tboot.h> #include <linux/trace_events.h> -#include <linux/entry-kvm.h> #include <asm/apic.h> #include <asm/asm.h>
arch/x86/kvm/x86.c +1 -2
@@ -59,7 +59,6 @@#include <linux/sched/stat.h> #include <linux/sched/isolation.h> #include <linux/mem_encrypt.h> -#include <linux/entry-kvm.h> #include <linux/suspend.h> #include <linux/smp.h>
@@ -10987,7 +10986,7 @@ static int vcpu_run(struct kvm_vcpu *vcpu)if (__xfer_to_guest_mode_work_pending ()) {kvm_vcpu_srcu_read_unlock (vcpu); - r =xfer_to_guest_mode_handle_work (vcpu); + r =kvm_xfer_to_guest_mode_handle_work (vcpu);kvm_vcpu_srcu_read_lock (vcpu);if (r)return r;
include/linux/entry-kvm.h +1 -2
@@ -42,11 +42,10 @@ static inline int arch_xfer_to_guest_mode_handle_work(unsigned long ti_work)/** * xfer_to_guest_mode_handle_work - Check and handle pending work which needs * to be handled before going to guest mode -* @vcpu: Pointer to current's VCPU data * * Returns: 0 or an error code */ -int xfer_to_guest_mode_handle_work (struct kvm_vcpu *vcpu); +int xfer_to_guest_mode_handle_work (void );/** * xfer_to_guest_mode_prepare - Perform last minute preparation work that
include/linux/kvm_host.h +12 -1
@@ -2,7 +2,7 @@#ifndef __KVM_HOST_H#define __KVM_HOST_H - +#include <linux/entry-kvm.h> #include <linux/types.h> #include <linux/hardirq.h> #include <linux/list.h>
@@ -2293,6 +2293,17 @@ static inline void kvm_handle_signal_exit(struct kvm_vcpu *vcpu) vcpu->run->exit_reason =KVM_EXIT_INTR ; vcpu->stat.signal_exits++; } + +static inline int kvm_xfer_to_guest_mode_handle_work (struct kvm_vcpu *vcpu) +{ +int r =xfer_to_guest_mode_handle_work (); + +if (r) { +WARN_ON_ONCE (r != -EINTR ); +kvm_handle_signal_exit (vcpu); + } +return r; +}#endif /* CONFIG_KVM_XFER_TO_GUEST_WORK */ /*
kernel/entry/kvm.c +4 -7
@@ -1,17 +1,14 @@// SPDX-License-Identifier: GPL-2.0 #include <linux/entry-kvm.h> -#include <linux/kvm_host.h> -static int xfer_to_guest_mode_work (struct kvm_vcpu *vcpu,unsigned long ti_work) +static int xfer_to_guest_mode_work (unsigned long ti_work) { do { int ret; - if (ti_work & (_TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL)) { - kvm_handle_signal_exit(vcpu); + if (ti_work & (_TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL)) return -EINTR; - } if (ti_work & _TIF_NEED_RESCHED) schedule();
@@ -28,7 +25,7 @@ static int xfer_to_guest_mode_work(struct kvm_vcpu *vcpu, unsigned long ti_work)return 0 ; } -int xfer_to_guest_mode_handle_work (struct kvm_vcpu *vcpu) +int xfer_to_guest_mode_handle_work (void ) {unsigned long ti_work;
@@ -44,6 +41,6 @@ int xfer_to_guest_mode_handle_work(struct kvm_vcpu *vcpu)if (!(ti_work &XFER_TO_GUEST_MODE_WORK ))return 0 ; -return xfer_to_guest_mode_work (vcpu, ti_work); +return xfer_to_guest_mode_work (ti_work); }EXPORT_SYMBOL_GPL (xfer_to_guest_mode_handle_work);
Signature · 1 line
2.42.0.459.ge4e396fd5e-goog
Anup Patel
maintainerRe: [PATCH 22/26] entry/kvm: KVM: Move KVM details related to signal/-EINTR into KVM proper
Quoted 7 lines · On Sat, Sep 16, 2023 at 6:02?AM Sean Christopherson <[email protected]> wrote:
Move KVM's morphing of pending signals into exits to userspace into KVM proper, and drop the @vcpu param from
xfer_to_guest_mode_handle_work(). How KVM responds to-EINTRis a detail that really belongs in KVM itself, and removing the non-KVM call tokvm_handle_signal_exit()will allow hiding said API and the definition of "structkvm_vcpu" from the kernel.
Quoted 5 lines
Alternatively,
entry/kvm.ccould be treated as part of KVM, i.e. be given access to KVM internals, but that's not obviously better than having KVM react to-EINTR(though it's not obviously worse either).Signed-off-by Sean Christopherson <[email protected]>
For KVM RISC-V:
Anup Patel <[email protected]>
Regards,
Anup
Quoted 169 lines
--- arch/arm64/kvm/arm.c | 3 +-- arch/riscv/kvm/vcpu.c | 2 +- arch/x86/kvm/vmx/vmx.c | 1 - arch/x86/kvm/x86.c | 3 +-- include/linux/entry-kvm.h | 3 +-- include/linux/kvm_host.h | 13 ++++++++++++- kernel/entry/kvm.c | 11 ++++------- 7 files changed, 20 insertions(+), 16 deletions(-)arch/arm64/kvm/arm.c +1
-2@@ -6,7 +6,6 @@#include <linux/bug.h> #include <linux/cpu_pm.h> -#include <linux/entry-kvm.h> #include <linux/errno.h> #include <linux/err.h> #include <linux/kvm_host.h> @@ -929,7 +928,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)/* * Check conditions before entering the guest */ - ret =xfer_to_guest_mode_handle_work (vcpu); + ret =kvm_xfer_to_guest_mode_handle_work (vcpu);if (!ret) ret =1 ;arch/riscv/kvm/vcpu.c +1
-1@@ -667,7 +667,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) run->exit_reason =KVM_EXIT_UNKNOWN ;while (ret >0 ) {/* Check conditions before entering the guest */ - ret =xfer_to_guest_mode_handle_work (vcpu); + ret =kvm_xfer_to_guest_mode_handle_work (vcpu);if (ret)continue ; ret =1 ;arch/x86/kvm/vmx/vmx.c +0
-1@@ -28,7 +28,6 @@#include <linux/slab.h> #include <linux/tboot.h> #include <linux/trace_events.h> -#include <linux/entry-kvm.h> #include <asm/apic.h> #include <asm/asm.h> arch/x86/kvm/x86.c +1
-2@@ -59,7 +59,6 @@#include <linux/sched/stat.h> #include <linux/sched/isolation.h> #include <linux/mem_encrypt.h> -#include <linux/entry-kvm.h> #include <linux/suspend.h> #include <linux/smp.h> @@ -10987,7 +10986,7 @@ static int vcpu_run(struct kvm_vcpu *vcpu)if (__xfer_to_guest_mode_work_pending ()) {kvm_vcpu_srcu_read_unlock (vcpu); - r =xfer_to_guest_mode_handle_work (vcpu); + r =kvm_xfer_to_guest_mode_handle_work (vcpu);kvm_vcpu_srcu_read_lock (vcpu);if (r)return r;include/linux/entry-kvm.h +1
-2@@ -42,11 +42,10 @@ static inline int arch_xfer_to_guest_mode_handle_work(unsigned long ti_work)/** * xfer_to_guest_mode_handle_work - Check and handle pending work which needs * to be handled before going to guest mode -* @vcpu: Pointer to current's VCPU data * * Returns: 0 or an error code */ -int xfer_to_guest_mode_handle_work (struct kvm_vcpu *vcpu); +int xfer_to_guest_mode_handle_work (void );/** * xfer_to_guest_mode_prepare - Perform last minute preparation work that include/linux/kvm_host.h +12
-1@@ -2,7 +2,7 @@#ifndef __KVM_HOST_H#define __KVM_HOST_H - +#include <linux/entry-kvm.h> #include <linux/types.h> #include <linux/hardirq.h> #include <linux/list.h> @@ -2293,6 +2293,17 @@ static inline void kvm_handle_signal_exit(struct kvm_vcpu *vcpu) vcpu->run->exit_reason =KVM_EXIT_INTR ; vcpu->stat.signal_exits++; } + +static inline int kvm_xfer_to_guest_mode_handle_work (struct kvm_vcpu *vcpu) +{ +int r =xfer_to_guest_mode_handle_work (); + +if (r) { +WARN_ON_ONCE (r != -EINTR ); +kvm_handle_signal_exit (vcpu); + } +return r; +}#endif /* CONFIG_KVM_XFER_TO_GUEST_WORK */ /* kernel/entry/kvm.c +4
-8@@ -1,17 +1,14 @@// SPDX-License-Identifier: GPL-2.0 #include <linux/entry-kvm.h> -#include <linux/kvm_host.h> -static int xfer_to_guest_mode_work (struct kvm_vcpu *vcpu,unsigned long ti_work) +static int xfer_to_guest_mode_work (unsigned long ti_work) { do { int ret; - if (ti_work & (_TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL)) { - kvm_handle_signal_exit(vcpu); + if (ti_work & (_TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL)) return -EINTR; - } if (ti_work & _TIF_NEED_RESCHED) schedule();@@ -28,7 +25,7 @@ static int xfer_to_guest_mode_work(struct kvm_vcpu *vcpu, unsigned long ti_work)return 0 ; } -int xfer_to_guest_mode_handle_work (struct kvm_vcpu *vcpu) +int xfer_to_guest_mode_handle_work (void ) {unsigned long ti_work;@@ -44,6 +41,6 @@ int xfer_to_guest_mode_handle_work(struct kvm_vcpu *vcpu)if (!(ti_work &XFER_TO_GUEST_MODE_WORK ))return 0 ; -return xfer_to_guest_mode_work (vcpu, ti_work); +return xfer_to_guest_mode_work (ti_work); }EXPORT_SYMBOL_GPL (xfer_to_guest_mode_handle_work); --2.42.0.459.ge4e396fd5e-goog
Sean Christopherson
maintainerPATCH 23/26 KVM: arm64: Move and consolidate "public" functions in asm/kvm_host.h
In reply to Sean ChristophersonMove a variety of "public" symbols in arm64's kvm_host.h, i.e. symbols and functions that are used by non-KVM code, towards the top of the header. This will allow hiding the "private" code in kvm_host.h, i.e. the stuff that is intended to be KVM-internal, with a minimal amount of #ifdeffery.
--- arch/arm64/include/asm/kvm_host.h | 48 ++++++++++++++----------------- 1 file changed, 22 insertions(+), 26 deletions(-)
arch/arm64/include/asm/kvm_host.h +22 -26
@@ -67,10 +67,32 @@ enum kvm_mode { };#ifdef CONFIG_KVM enum kvm_mode kvm_get_mode (void ); + +extern phys_addr_t hyp_mem_base; +extern phys_addr_t hyp_mem_size; +void __init kvm_hyp_reserve (void ); + +void kvm_set_pmu_events (u32 set,struct perf_event_attr *attr); +void kvm_clr_pmu_events (u32 clr); +bool kvm_set_pmuserenr (u64 val);#else static inline enum kvm_mode kvm_get_mode (void ) {return KVM_MODE_NONE ; }; + +static inline void kvm_hyp_reserve (void ) { } + +static inline void kvm_set_pmu_events (u32 set,struct perf_event_attr *attr) {} +static inline void kvm_clr_pmu_events (u32 clr) {} +static inline bool kvm_set_pmuserenr (u64 val) +{ +return false; +}#endif +static inline bool kvm_pmu_counter_deferred (struct perf_event_attr *attr) +{ +return (!has_vhe () && attr->exclude_host); +} +DECLARE_STATIC_KEY_FALSE (userspace_irqchip_in_use);extern unsigned int __ro_after_init kvm_sve_max_vl;
@@ -1086,28 +1108,10 @@ void kvm_arch_vcpu_ctxsync_fp(struct kvm_vcpu *vcpu);void kvm_arch_vcpu_put_fp (struct kvm_vcpu *vcpu);void kvm_vcpu_unshare_task_fp (struct kvm_vcpu *vcpu); -static inline bool kvm_pmu_counter_deferred (struct perf_event_attr *attr) -{ -return (!has_vhe () && attr->exclude_host); -} -/* Flags for host debug state */ void kvm_arch_vcpu_load_debug_state_flags (struct kvm_vcpu *vcpu);void kvm_arch_vcpu_put_debug_state_flags (struct kvm_vcpu *vcpu); -#ifdef CONFIG_KVM -void kvm_set_pmu_events (u32 set,struct perf_event_attr *attr); -void kvm_clr_pmu_events (u32 clr); -bool kvm_set_pmuserenr (u64 val); -#else -static inline void kvm_set_pmu_events (u32 set,struct perf_event_attr *attr) {} -static inline void kvm_clr_pmu_events (u32 clr) {} -static inline bool kvm_set_pmuserenr (u64 val) -{ -return false; -} -#endif -void kvm_vcpu_load_sysregs_vhe (struct kvm_vcpu *vcpu);void kvm_vcpu_put_sysregs_vhe (struct kvm_vcpu *vcpu);
@@ -1142,14 +1146,6 @@ bool kvm_arm_vcpu_is_finalized(struct kvm_vcpu *vcpu); (test_bit(KVM_ARCH_FLAG_HAS_RAN_ONCE, &(kvm)->arch.flags))int kvm_trng_call (struct kvm_vcpu *vcpu); -#ifdef CONFIG_KVM -extern phys_addr_t hyp_mem_base; -extern phys_addr_t hyp_mem_size; -void __init kvm_hyp_reserve (void ); -#else -static inline void kvm_hyp_reserve (void ) { } -#endif -void kvm_arm_vcpu_power_off (struct kvm_vcpu *vcpu);bool kvm_arm_vcpu_stopped (struct kvm_vcpu *vcpu);
Signature · 1 line
2.42.0.459.ge4e396fd5e-goog
Sean Christopherson
maintainerPATCH 24/26 powerpc/xics: Move declaration of xics_wake_cpu() out of kvm_ppc.h
In reply to Sean Christophersonxics_wake_cpu() is provided by core PPC code, not by KVM. Move its declaration out of kvm_ppc.h and into xics.h.
--- arch/powerpc/include/asm/kvm_ppc.h | 2 -- arch/powerpc/include/asm/xics.h | 3 +++ 2 files changed, 3 insertions(+), 2 deletions(-)
arch/powerpc/include/asm/kvm_ppc.h +0 -2
@@ -1072,6 +1072,4 @@ static inline ulong kvmppc_get_ea_indexed(struct kvm_vcpu *vcpu, int ra, int rb) return ea; } -extern void xics_wake_cpu (int cpu); -#endif /* __POWERPC_KVM_PPC_H__ */
arch/powerpc/include/asm/xics.h +3 -0
@@ -32,6 +32,9 @@extern int icp_native_init (void );extern void icp_native_flush_interrupt (void );extern void icp_native_cause_ipi_rm (int cpu); +#ifdef CONFIG_SMP +extern void xics_wake_cpu (int cpu); +#endif #else static inline int icp_native_init (void ) {return -ENODEV ; }#endif
Signature · 1 line
2.42.0.459.ge4e396fd5e-goog
Sean Christopherson
maintainerPATCH 25/26 KVM: PPC: Rearrange code in kvm_ppc.h to isolate "public" information
In reply to Sean ChristophersonMove all declarations and definitions in kvm_ppc.h that are consumed by things other than KVM to the top of the file. This will allow wrapping the parts of kvm_ppc.h that are intended only for KVM, i.e. are intended to be "private" to KVM, with an #ifdef to hide KVM's internal details from the kernel at-large.
--- arch/powerpc/include/asm/kvm_ppc.h | 302 +++++++++++++++-------------- 1 file changed, 153 insertions(+), 149 deletions(-)
arch/powerpc/include/asm/kvm_ppc.h +153 -149
@@ -30,6 +30,159 @@#endif #include <asm/inst.h> +struct openpic ; + +#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE +extern void kvm_cma_reserve (void )__init ; +static inline void kvmppc_set_xics_phys (int cpu,unsigned long addr) +{ + paca_ptrs[cpu]->kvm_hstate.xics_phys = (void __iomem *)addr; +} + +static inline void kvmppc_set_xive_tima (int cpu, +unsigned long phys_addr, +void __iomem *virt_addr) +{ + paca_ptrs[cpu]->kvm_hstate.xive_tima_phys = (void __iomem *)phys_addr; + paca_ptrs[cpu]->kvm_hstate.xive_tima_virt = virt_addr; +} + +static inline u32 kvmppc_get_xics_latch (void ) +{ +u32 xirr; + + xirr =get_paca ()->kvm_hstate.saved_xirr; +get_paca ()->kvm_hstate.saved_xirr =0 ; +return xirr; +} + +/* +* To avoid the need to unnecessarily exit fully to the host kernel, an IPI to +* a CPU thread that's running/napping inside of a guest is by default regarded +* as a request to wake the CPU (if needed) and continue execution within the +* guest, potentially to process new state like externally-generated +* interrupts or IPIs sent from within the guest itself (e.g. H_PROD/H_IPI). +* +* To force an exit to the host kernel, kvmppc_set_host_ipi() must be called +* prior to issuing the IPI to set the corresponding 'host_ipi' flag in the +* target CPU's PACA. To avoid unnecessary exits to the host, this flag should +* be immediately cleared via kvmppc_clear_host_ipi() by the IPI handler on +* the receiving side prior to processing the IPI work. +* +* NOTE: +* +* We currently issue an smp_mb() at the beginning of kvmppc_set_host_ipi(). +* This is to guard against sequences such as the following: +* +* CPU +* X: smp_muxed_ipi_set_message(): +* X: smp_mb() +* X: message[RESCHEDULE] = 1 +* X: doorbell_global_ipi(42): +* X: kvmppc_set_host_ipi(42) +* X: ppc_msgsnd_sync()/smp_mb() +* X: ppc_msgsnd() -> 42 +* 42: doorbell_exception(): // from CPU X +* 42: ppc_msgsync() +* 105: smp_muxed_ipi_set_message(): +* 105: smb_mb() +* // STORE DEFERRED DUE TO RE-ORDERING +* --105: message[CALL_FUNCTION] = 1 +* | 105: doorbell_global_ipi(42): +* | 105: kvmppc_set_host_ipi(42) +* | 42: kvmppc_clear_host_ipi(42) +* | 42: smp_ipi_demux_relaxed() +* | 42: // returns to executing guest +* | // RE-ORDERED STORE COMPLETES +* ->105: message[CALL_FUNCTION] = 1 +* 105: ppc_msgsnd_sync()/smp_mb() +* 105: ppc_msgsnd() -> 42 +* 42: local_paca->kvm_hstate.host_ipi == 0 // IPI ignored +* 105: // hangs waiting on 42 to process messages/call_single_queue +* +* We also issue an smp_mb() at the end of kvmppc_clear_host_ipi(). This is +* to guard against sequences such as the following (as well as to create +* a read-side pairing with the barrier in kvmppc_set_host_ipi()): +* +* CPU +* X: smp_muxed_ipi_set_message(): +* X: smp_mb() +* X: message[RESCHEDULE] = 1 +* X: doorbell_global_ipi(42): +* X: kvmppc_set_host_ipi(42) +* X: ppc_msgsnd_sync()/smp_mb() +* X: ppc_msgsnd() -> 42 +* 42: doorbell_exception(): // from CPU X +* 42: ppc_msgsync() +* // STORE DEFERRED DUE TO RE-ORDERING +* -- 42: kvmppc_clear_host_ipi(42) +* | 42: smp_ipi_demux_relaxed() +* | 105: smp_muxed_ipi_set_message(): +* | 105: smb_mb() +* | 105: message[CALL_FUNCTION] = 1 +* | 105: doorbell_global_ipi(42): +* | 105: kvmppc_set_host_ipi(42) +* | // RE-ORDERED STORE COMPLETES +* -> 42: kvmppc_clear_host_ipi(42) +* 42: // returns to executing guest +* 105: ppc_msgsnd_sync()/smp_mb() +* 105: ppc_msgsnd() -> 42 +* 42: local_paca->kvm_hstate.host_ipi == 0 // IPI ignored +* 105: // hangs waiting on 42 to process messages/call_single_queue +*/ +static inline void kvmppc_set_host_ipi (int cpu) +{ +/* +* order stores of IPI messages vs. setting of host_ipi flag +* +* pairs with the barrier in kvmppc_clear_host_ipi() +*/ +smp_mb (); +WRITE_ONCE (paca_ptrs[cpu]->kvm_hstate.host_ipi,1 ); +} + +static inline void kvmppc_clear_host_ipi (int cpu) +{ +WRITE_ONCE (paca_ptrs[cpu]->kvm_hstate.host_ipi,0 ); +/* +* order clearing of host_ipi flag vs. processing of IPI messages +* +* pairs with the barrier in kvmppc_set_host_ipi() +*/ +smp_mb (); +} + +extern void kvmppc_xics_ipi_action (void ); + +extern void kvm_hv_vm_activated (void ); +extern void kvm_hv_vm_deactivated (void ); +extern bool kvm_hv_mode_active (void ); +#else +static inline void __init kvm_cma_reserve (void ) +{} + +static inline void kvmppc_set_xics_phys (int cpu,unsigned long addr) +{} + +static inline void kvmppc_set_xive_tima (int cpu, +unsigned long phys_addr, +void __iomem *virt_addr) +{} + +static inline u32 kvmppc_get_xics_latch (void ) +{ +return 0 ; +} + +static inline void kvmppc_set_host_ipi (int cpu) +{} + +static inline void kvmppc_clear_host_ipi (int cpu) +{} + +static inline bool kvm_hv_mode_active (void ) {return false; } +#endif +/* * KVMPPC_INST_SW_BREAKPOINT is debug Instruction * for supporting software breakpoint.
@@ -443,166 +596,18 @@ void kvmppc_set_pid(struct kvm_vcpu *vcpu, u32 pid);struct openpic ;#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE -extern void kvm_cma_reserve (void )__init ; -static inline void kvmppc_set_xics_phys (int cpu,unsigned long addr) -{ - paca_ptrs[cpu]->kvm_hstate.xics_phys = (void __iomem *)addr; -} - -static inline void kvmppc_set_xive_tima (int cpu, -unsigned long phys_addr, -void __iomem *virt_addr) -{ - paca_ptrs[cpu]->kvm_hstate.xive_tima_phys = (void __iomem *)phys_addr; - paca_ptrs[cpu]->kvm_hstate.xive_tima_virt = virt_addr; -} - -static inline u32 kvmppc_get_xics_latch (void ) -{ -u32 xirr; - - xirr =get_paca ()->kvm_hstate.saved_xirr; -get_paca ()->kvm_hstate.saved_xirr =0 ; -return xirr; -} - -/* -* To avoid the need to unnecessarily exit fully to the host kernel, an IPI to -* a CPU thread that's running/napping inside of a guest is by default regarded -* as a request to wake the CPU (if needed) and continue execution within the -* guest, potentially to process new state like externally-generated -* interrupts or IPIs sent from within the guest itself (e.g. H_PROD/H_IPI). -* -* To force an exit to the host kernel, kvmppc_set_host_ipi() must be called -* prior to issuing the IPI to set the corresponding 'host_ipi' flag in the -* target CPU's PACA. To avoid unnecessary exits to the host, this flag should -* be immediately cleared via kvmppc_clear_host_ipi() by the IPI handler on -* the receiving side prior to processing the IPI work. -* -* NOTE: -* -* We currently issue an smp_mb() at the beginning of kvmppc_set_host_ipi(). -* This is to guard against sequences such as the following: -* -* CPU -* X: smp_muxed_ipi_set_message(): -* X: smp_mb() -* X: message[RESCHEDULE] = 1 -* X: doorbell_global_ipi(42): -* X: kvmppc_set_host_ipi(42) -* X: ppc_msgsnd_sync()/smp_mb() -* X: ppc_msgsnd() -> 42 -* 42: doorbell_exception(): // from CPU X -* 42: ppc_msgsync() -* 105: smp_muxed_ipi_set_message(): -* 105: smb_mb() -* // STORE DEFERRED DUE TO RE-ORDERING -* --105: message[CALL_FUNCTION] = 1 -* | 105: doorbell_global_ipi(42): -* | 105: kvmppc_set_host_ipi(42) -* | 42: kvmppc_clear_host_ipi(42) -* | 42: smp_ipi_demux_relaxed() -* | 42: // returns to executing guest -* | // RE-ORDERED STORE COMPLETES -* ->105: message[CALL_FUNCTION] = 1 -* 105: ppc_msgsnd_sync()/smp_mb() -* 105: ppc_msgsnd() -> 42 -* 42: local_paca->kvm_hstate.host_ipi == 0 // IPI ignored -* 105: // hangs waiting on 42 to process messages/call_single_queue -* -* We also issue an smp_mb() at the end of kvmppc_clear_host_ipi(). This is -* to guard against sequences such as the following (as well as to create -* a read-side pairing with the barrier in kvmppc_set_host_ipi()): -* -* CPU -* X: smp_muxed_ipi_set_message(): -* X: smp_mb() -* X: message[RESCHEDULE] = 1 -* X: doorbell_global_ipi(42): -* X: kvmppc_set_host_ipi(42) -* X: ppc_msgsnd_sync()/smp_mb() -* X: ppc_msgsnd() -> 42 -* 42: doorbell_exception(): // from CPU X -* 42: ppc_msgsync() -* // STORE DEFERRED DUE TO RE-ORDERING -* -- 42: kvmppc_clear_host_ipi(42) -* | 42: smp_ipi_demux_relaxed() -* | 105: smp_muxed_ipi_set_message(): -* | 105: smb_mb() -* | 105: message[CALL_FUNCTION] = 1 -* | 105: doorbell_global_ipi(42): -* | 105: kvmppc_set_host_ipi(42) -* | // RE-ORDERED STORE COMPLETES -* -> 42: kvmppc_clear_host_ipi(42) -* 42: // returns to executing guest -* 105: ppc_msgsnd_sync()/smp_mb() -* 105: ppc_msgsnd() -> 42 -* 42: local_paca->kvm_hstate.host_ipi == 0 // IPI ignored -* 105: // hangs waiting on 42 to process messages/call_single_queue -*/ -static inline void kvmppc_set_host_ipi (int cpu) -{ -/* -* order stores of IPI messages vs. setting of host_ipi flag -* -* pairs with the barrier in kvmppc_clear_host_ipi() -*/ -smp_mb (); -WRITE_ONCE (paca_ptrs[cpu]->kvm_hstate.host_ipi,1 ); -} - -static inline void kvmppc_clear_host_ipi (int cpu) -{ -WRITE_ONCE (paca_ptrs[cpu]->kvm_hstate.host_ipi,0 ); -/* -* order clearing of host_ipi flag vs. processing of IPI messages -* -* pairs with the barrier in kvmppc_set_host_ipi() -*/ -smp_mb (); -} -static inline void kvmppc_fast_vcpu_kick (struct kvm_vcpu *vcpu) { vcpu->kvm->arch.kvm_ops->fast_vcpu_kick (vcpu); } -extern void kvm_hv_vm_activated (void ); -extern void kvm_hv_vm_deactivated (void ); -extern bool kvm_hv_mode_active (void ); -extern void kvmppc_check_need_tlb_flush (struct kvm *kvm,int pcpu);#else -static inline void __init kvm_cma_reserve (void ) -{} - -static inline void kvmppc_set_xics_phys (int cpu,unsigned long addr) -{} - -static inline void kvmppc_set_xive_tima (int cpu, -unsigned long phys_addr, -void __iomem *virt_addr) -{} - -static inline u32 kvmppc_get_xics_latch (void ) -{ -return 0 ; -} - -static inline void kvmppc_set_host_ipi (int cpu) -{} - -static inline void kvmppc_clear_host_ipi (int cpu) -{} -static inline void kvmppc_fast_vcpu_kick (struct kvm_vcpu *vcpu) {kvm_vcpu_kick (vcpu); } - -static inline bool kvm_hv_mode_active (void ) {return false; } -#endif #ifdef CONFIG_PPC_PSERIES
@@ -642,7 +647,6 @@ extern u64 kvmppc_xics_get_icp(struct kvm_vcpu *vcpu);extern int kvmppc_xics_set_icp (struct kvm_vcpu *vcpu,u64 icpval);extern int kvmppc_xics_connect_vcpu (struct kvm_device *dev,struct kvm_vcpu *vcpu,u32 cpu); -extern void kvmppc_xics_ipi_action (void );extern void kvmppc_xics_set_mapped (struct kvm *kvm,unsigned long guest_irq,unsigned long host_irq); extern void kvmppc_xics_clr_mapped(struct kvm *kvm, unsigned long guest_irq,
Signature · 1 line
2.42.0.459.ge4e396fd5e-goog
Sean Christopherson
maintainerPATCH 26/26 KVM: Hide KVM internal data structures and values from kernel at-large
In reply to Sean ChristophersonWrap all KVM internal APIs, data structures, values, etc. in public headers with "#ifdef __KVM__" to effectively hide KVM's internal details from other subsystems and the kernel at-large. Hiding KVM details for all architectures will, in the very distant future, allow loading a new (or old) KVM module without needing to rebuild and reboot the entire kernel, or to even allow loading and running multiple versions of KVM simultaneously on a single host.
To allow different instances of KVM modules to freely modify KVM data structures, enums, #defines, etc., e.g. the struct kvm_vcpu layout, there must be exactly zero dereferences of KVM-defined structures/values in non-KVM code (excepting code for architectures that don't support such shenanigans). Any such references could lead to latent bugs, e.g. as the kernel would think a KVM structure has layout X, but in reality the current incarnation of KVM uses layout Y.
In KVM x86, all remaining non-KVM references to KVM details have been now eliminated. To harden KVM against new references being introduced, hide KVM's details to ensure that KVM doesn?t create a de facto ABI with the rest of the kernel.
Use #ifdeffery to hide KVM details as doing so requires, by far, the least amount of churn and impact on architectures that freely share select KVM details with the rest of the kernel, e.g. s390, ARM64 and PPC, have significant usage of KVM-defined APIs, structures, values, etc. E.g. attempting to extract the "private" chunks into dedicated KVM-internal headers would require massive churn, even on x86, and it's not obvious the end result would be a net positive (all attempts at moving code around failed long before getting anywhere near compiling cleanly).
Another (bad) alternative that would be relative churn-free would be to move the KVM headers to a dedicated KVM-specific path while maintaining the generic layout, e.g. something like virt/kvm/include/linux. That would allow x86 to simply omit the KVM-specific include path. But that would require modifying the global include path, i.e. would make KVM a really special snowflake and set the awful precedent that it's "ok" to add subsystem specific directories to the global include path.
Grant exceptions to asm-offsets.c as needed, and to s390's VFIO AP driver. Creating a KVM-specific asm-offsets, as was done for x86, adds no value (x86 did so to avoid exposing vendor specific headers) and doesn't create much of a "slippery slope" risk. s390's VFIO AP driver on the other hand is simply too intertwined with KVM to realistically treat it as anything other than KVM code, despite it living in crypto drivers, e.g. the driver has some rather crazy lock ordering rules between the device and KVM.
Add a static assert that __KVM__ is defined in trace/events/kvm.h, as that is effectively a private KVM header that just happens to live in a public path.
Shuffle a few PPC includes and an s390 declaration as needed, and opportunistically include kvm_host.h in trace/events.kvm.h instead of relying on the parent to provide the right includes.
--- arch/arm64/include/asm/kvm_emulate.h | 3 +++ arch/arm64/include/asm/kvm_host.h | 2 ++ arch/arm64/include/asm/kvm_mmu.h | 4 ++++ arch/arm64/kernel/asm-offsets.c | 2 ++ arch/arm64/kvm/hyp/Makefile | 2 +- arch/arm64/kvm/hyp/nvhe/Makefile | 3 ++- arch/arm64/kvm/hyp/vhe/Makefile | 2 +- arch/mips/include/asm/kvm_host.h | 2 ++ arch/mips/kernel/asm-offsets.c | 2 ++ arch/powerpc/include/asm/kvm_book3s.h | 3 +++ arch/powerpc/include/asm/kvm_book3s_64.h | 2 ++ arch/powerpc/include/asm/kvm_booke.h | 4 ++++ arch/powerpc/include/asm/kvm_host.h | 7 ++++--- arch/powerpc/include/asm/kvm_ppc.h | 2 ++ arch/powerpc/kernel/asm-offsets.c | 1 + arch/riscv/include/asm/kvm_host.h | 3 +++ arch/riscv/kernel/asm-offsets.c | 1 + arch/s390/include/asm/kvm_host.h | 7 +++++-- arch/s390/kernel/asm-offsets.c | 1 + arch/x86/include/asm/kvm_host.h | 3 +++ drivers/s390/crypto/vfio_ap_drv.c | 1 + drivers/s390/crypto/vfio_ap_ops.c | 2 ++ include/linux/kvm_host.h | 4 ++++ include/linux/kvm_types.h | 3 +++ include/trace/events/kvm.h | 5 +++++ virt/kvm/Makefile.kvm | 2 +- 26 files changed, 64 insertions(+), 9 deletions(-)
arch/arm64/include/asm/kvm_emulate.h +3 -0
@@ -21,6 +21,8 @@#include <asm/cputype.h> #include <asm/virt.h> +#ifdef __KVM__ +#define CURRENT_EL_SP_EL0_VECTOR 0x0#define CURRENT_EL_SP_ELx_VECTOR 0x200#define LOWER_EL_AArch64_VECTOR 0x400
@@ -615,4 +617,5 @@ static __always_inline void kvm_reset_cptr_el2(struct kvm_vcpu *vcpu)kvm_write_cptr_el2 (val); } +#endif /* __KVM__ */ #endif /* __ARM64_KVM_EMULATE_H__ */
arch/arm64/include/asm/kvm_host.h +2 -0
@@ -93,6 +93,7 @@ static inline bool kvm_pmu_counter_deferred(struct perf_event_attr *attr)return (!has_vhe () && attr->exclude_host); } +#ifdef __KVM__DECLARE_STATIC_KEY_FALSE (userspace_irqchip_in_use);extern unsigned int __ro_after_init kvm_sve_max_vl;
@@ -1149,4 +1150,5 @@ int kvm_trng_call(struct kvm_vcpu *vcpu);void kvm_arm_vcpu_power_off (struct kvm_vcpu *vcpu);bool kvm_arm_vcpu_stopped (struct kvm_vcpu *vcpu); +#endif /* __KVM__ */ #endif /* __ARM64_KVM_HOST_H__ */
arch/arm64/include/asm/kvm_mmu.h +4 -0
@@ -125,6 +125,8 @@ void kvm_update_va_mask(struct alt_instr *alt,void kvm_compute_layout (void );void kvm_apply_hyp_relocations (void ); +#ifdef __KVM__ +#define __hyp_pa (x) (((phys_addr_t)(x)) + hyp_physvirt_offset)static __always_inline unsigned long __kern_hyp_va (unsigned long v)
@@ -314,5 +316,7 @@ static inline struct kvm *kvm_s2_mmu_to_kvm(struct kvm_s2_mmu *mmu) { return container_of(mmu->arch, struct kvm, arch); } + +#endif /* __KVM__ */ #endif /* __ASSEMBLY__ */ #endif /* __ARM64_KVM_MMU_H__ */
arch/arm64/kernel/asm-offsets.c +2 -0
@@ -7,6 +7,8 @@* Copyright (C) 2012 ARM Ltd. */ +#define __KVM__ +#include <linux/arm_sdei.h> #include <linux/sched.h> #include <linux/ftrace.h>
arch/arm64/kvm/hyp/Makefile +1 -1
@@ -5,6 +5,6 @@ incdir := $(srctree)/$(src)/include subdir-asflags-y := -I$(incdir) -I$(srctree)/arch/arm64/kvm -subdir-ccflags-y := -I$(incdir) -I$(srctree)/arch/arm64/kvm +subdir-ccflags-y := -I$(incdir) -I$(srctree)/arch/arm64/kvm -D__KVM__ obj-$(CONFIG_KVM) += vhe/ nvhe/ pgtable.o
arch/arm64/kvm/hyp/nvhe/Makefile +2 -1
@@ -9,7 +9,8 @@ asflags-y := -D__KVM_NVHE_HYPERVISOR__ -D__DISABLE_EXPORTS # there is no way to execute them and any such MMIO access from nVHE KVM # will explode instantly (Words of Marc Zyngier). So introduce a generic flag # __DISABLE_TRACE_MMIO__ to disable MMIO tracing for nVHE KVM. -ccflags-y := -D__KVM_NVHE_HYPERVISOR__ -D__DISABLE_EXPORTS -D__DISABLE_TRACE_MMIO__ +ccflags-y := -D__KVM_NVHE_HYPERVISOR__ -D__DISABLE_EXPORTS \ + -D__DISABLE_TRACE_MMIO__ -D__KVM__ ccflags-y += -fno-stack-protector \ -DDISABLE_BRANCH_PROFILING \ $(DISABLE_STACKLEAK_PLUGIN)
arch/arm64/kvm/hyp/vhe/Makefile +1 -1
@@ -4,7 +4,7 @@ # asflags-y := -D__KVM_VHE_HYPERVISOR__ -ccflags-y := -D__KVM_VHE_HYPERVISOR__ +ccflags-y := -D__KVM_VHE_HYPERVISOR__ -D__KVM__ obj-y := timer-sr.o sysreg-sr.o debug-sr.o switch.o tlb.o obj-y += ../vgic-v3-sr.o ../aarch32.o ../vgic-v2-cpuif-proxy.o ../entry.o \
arch/mips/include/asm/kvm_host.h +2 -0
@@ -25,6 +25,7 @@#include <asm/inst.h> #include <asm/mipsregs.h> +#ifdef __KVM__/* MIPS KVM register ids */ #define MIPS_CP0_32 (_R, _S) \ (KVM_REG_MIPS_CP0 | KVM_REG_SIZE_U32 | (8 * (_R) + (_S)))
@@ -897,4 +898,5 @@ static inline void kvm_arch_vcpu_unblocking(struct kvm_vcpu *vcpu) {}#define __KVM_HAVE_ARCH_FLUSH_REMOTE_TLBS +#endif /* __KVM__ */ #endif /* __MIPS_KVM_HOST_H__ */
arch/mips/kernel/asm-offsets.c +2 -0
@@ -9,6 +9,8 @@* Kevin Kissell, kevink at mips.com and Carsten Langgaard, carstenl at mips.com * Copyright (C) 2000 MIPS Technologies, Inc. */ +#define __KVM__ +#include <linux/compat.h> #include <linux/types.h> #include <linux/sched.h>
arch/powerpc/include/asm/kvm_book3s.h +3 -0
@@ -13,6 +13,8 @@#include <linux/kvm_host.h> #include <asm/kvm_book3s_asm.h> +#ifdef __KVM__ + struct kvmppc_bat { u64 raw; u32 bepi;
@@ -483,4 +485,5 @@ static inline u32 kvmppc_pack_vcpu_id(struct kvm *kvm, u32 id)return packed_id; } +#endif /* __KVM__ */ #endif /* __ASM_KVM_BOOK3S_H__ */
arch/powerpc/include/asm/kvm_book3s_64.h +2 -0
@@ -16,6 +16,7 @@#include <asm/ppc-opcode.h> #include <asm/pte-walk.h> +#ifdef __KVM__/* * Structure for a nested guest, that is, for a guest that is managed by * one of our guests.
@@ -679,4 +680,5 @@ extern pte_t *find_kvm_nested_guest_pte(struct kvm *kvm, unsigned long lpid,#endif /* CONFIG_KVM_BOOK3S_HV_POSSIBLE */ +#endif /* __KVM__ */ #endif /* __ASM_KVM_BOOK3S_64_H__ */
arch/powerpc/include/asm/kvm_booke.h +4 -0
@@ -12,6 +12,8 @@#include <linux/types.h> #include <linux/kvm_host.h> +#ifdef __KVM__ +/* * Number of available lpids. Only the low-order 6 bits of LPID rgister are * implemented on e500mc+ cores.
@@ -105,4 +107,6 @@ static inline bool kvmppc_supports_magic_page(struct kvm_vcpu *vcpu)return false;#endif } + +#endif /* __KVM__ */ #endif /* __ASM_KVM_BOOKE_H__ */
arch/powerpc/include/asm/kvm_host.h +4 -3
@@ -14,6 +14,7 @@#include <linux/interrupt.h> #include <linux/types.h> #include <linux/kvm_types.h> +#include <linux/mmu_notifier.h> #include <linux/threads.h> #include <linux/spinlock.h> #include <linux/kvm_para.h>
@@ -25,13 +26,14 @@#include <asm/cacheflush.h> #include <asm/hvcall.h> #include <asm/mce.h> +#include <asm/cputhreads.h> +#ifdef __KVM__#define __KVM_HAVE_ARCH_VCPU_DEBUGFS#define KVM_MAX_VCPUS NR_CPUS#define KVM_MAX_VCORES NR_CPUS -#include <asm/cputhreads.h> #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE #include <asm/kvm_book3s_asm.h> /* for MAX_SMT_THREADS */
@@ -60,8 +62,6 @@#define KVM_REQ_EPR_EXIT KVM_ARCH_REQ(1)#define KVM_REQ_PENDING_TIMER KVM_ARCH_REQ(2) -#include <linux/mmu_notifier.h> -#define KVM_ARCH_WANT_MMU_NOTIFIER #define HPTEG_CACHE_NUM (1 << 15)
@@ -883,4 +883,5 @@ static inline void kvm_arch_sched_in(struct kvm_vcpu *vcpu, int cpu) {}static inline void kvm_arch_vcpu_blocking (struct kvm_vcpu *vcpu) {}static inline void kvm_arch_vcpu_unblocking (struct kvm_vcpu *vcpu) {} +#endif /* __KVM__ */ #endif /* __POWERPC_KVM_HOST_H__ */
arch/powerpc/include/asm/kvm_ppc.h +2 -0
@@ -183,6 +183,7 @@ static inline void kvmppc_clear_host_ipi(int cpu)static inline bool kvm_hv_mode_active (void ) {return false; }#endif +#ifdef __KVM__/* * KVMPPC_INST_SW_BREAKPOINT is debug Instruction * for supporting software breakpoint.
@@ -1076,4 +1077,5 @@ static inline ulong kvmppc_get_ea_indexed(struct kvm_vcpu *vcpu, int ra, int rb)return ea; } +#endif /* __KVM__ */ #endif /* __POWERPC_KVM_PPC_H__ */
arch/powerpc/kernel/asm-offsets.c +1 -0
@@ -8,6 +8,7 @@* compile this file to assembler, and then extract the * #defines from the assembly-language output. */ +#define __KVM__#include <linux/compat.h> #include <linux/signal.h>
arch/riscv/include/asm/kvm_host.h +3 -0
@@ -22,6 +22,8 @@#include <asm/kvm_vcpu_timer.h> #include <asm/kvm_vcpu_pmu.h> +#ifdef __KVM__ +#define KVM_MAX_VCPUS 1024#define KVM_HALT_POLL_NS_DEFAULT 500000
@@ -354,4 +356,5 @@ bool kvm_riscv_vcpu_has_interrupts(struct kvm_vcpu *vcpu, u64 mask);void kvm_riscv_vcpu_power_off (struct kvm_vcpu *vcpu);void kvm_riscv_vcpu_power_on (struct kvm_vcpu *vcpu); +#endif /* __KVM__ */ #endif /* __RISCV_KVM_HOST_H__ */
arch/riscv/kernel/asm-offsets.c +1 -0
@@ -5,6 +5,7 @@*/ #define GENERATING_ASM_OFFSETS +#define __KVM__#include <linux/kbuild.h> #include <linux/mm.h>
arch/s390/include/asm/kvm_host.h +5 -2
@@ -380,6 +380,10 @@ struct sie_page {__u8 reserved700[2304 ];/* 0x0700 */ }; +extern char sie_exit; + +#ifdef __KVM__ + struct kvm_vcpu_stat { struct kvm_vcpu_stat_generic generic; u64 exit_userspace;
@@ -1028,8 +1032,6 @@ static inline int sie64a(struct kvm_s390_sie_block *sie_block, u64 *rsa)return __sie64a (virt_to_phys (sie_block), sie_block, rsa); } -extern char sie_exit; -bool kvm_s390_pv_is_protected (struct kvm *kvm);bool kvm_s390_pv_cpu_is_protected (struct kvm_vcpu *vcpu);
@@ -1049,6 +1051,7 @@ static inline void kvm_arch_vcpu_unblocking(struct kvm_vcpu *vcpu) {}#define __KVM_HAVE_ARCH_VM_FREEvoid kvm_arch_free_vm (struct kvm *kvm); +#endif /* __KVM__ */ struct zpci_kvm_hook {int (*kvm_register)(void *opaque,struct kvm *kvm);
arch/s390/kernel/asm-offsets.c +1 -0
@@ -6,6 +6,7 @@*/ #define ASM_OFFSETS_C +#define __KVM__#include <linux/kbuild.h> #include <linux/kvm_host.h>
arch/x86/include/asm/kvm_host.h +3 -0
@@ -37,6 +37,8 @@#include <asm/kvm_vcpu_regs.h> #include <asm/hyperv-tlfs.h> +#ifdef __KVM__ +#define __KVM_HAVE_ARCH_VCPU_DEBUGFS#define KVM_MAX_VCPUS 1024
@@ -2229,4 +2231,5 @@ int memslot_rmap_alloc(struct kvm_memory_slot *slot, unsigned long npages);*/ #define KVM_EXIT_HYPERCALL_MBZ GENMASK_ULL(31, 1) +#endif /* __KVM__ */ #endif /* _ASM_X86_KVM_HOST_H */
drivers/s390/crypto/vfio_ap_drv.c +1 -0
@@ -7,6 +7,7 @@* Author(s): Tony Krowiak <[email protected]> * Pierre Morel <[email protected]> */ +#define __KVM__#include <linux/module.h> #include <linux/mod_devicetable.h>
drivers/s390/crypto/vfio_ap_ops.c +2 -0
@@ -8,6 +8,8 @@* Halil Pasic <[email protected]> * Pierre Morel <[email protected]> */ +#define __KVM__ +#include <linux/string.h> #include <linux/vfio.h> #include <linux/device.h>
include/linux/kvm_host.h +4 -0
@@ -45,6 +45,8 @@#include <asm/kvm_host.h> #include <linux/kvm_dirty_ring.h> +#ifdef __KVM__ +#ifndef KVM_MAX_VCPU_IDS #define KVM_MAX_VCPU_IDS KVM_MAX_VCPUS#endif
@@ -2329,4 +2331,6 @@ static inline void kvm_account_pgtable_pages(void *virt, int nr)/* Max number of entries allowed for each kvm dirty ring */ #define KVM_DIRTY_RING_MAX_ENTRIES 65536 +#endif /* __KVM__ */ +#endif
include/linux/kvm_types.h +3 -0
@@ -48,6 +48,8 @@ typedef u64 hfn_t;typedef hfn_t kvm_pfn_t ; +#ifdef __KVM__ +enum pfn_cache_usage {KVM_GUEST_USES_PFN =BIT (0 ), KVM_HOST_USES_PFN = BIT(1),
@@ -123,4 +125,5 @@ struct kvm_vcpu_stat_generic {#define KVM_STATS_NAME_SIZE 48 +#endif /* __KVM__ */ #endif /* __KVM_TYPES_H__ */
include/trace/events/kvm.h +5 -0
@@ -2,8 +2,13 @@#if !defined(_TRACE_KVM_MAIN_H) || defined(TRACE_HEADER_MULTI_READ )#define _TRACE_KVM_MAIN_H +#include <linux/kvm_host.h> #include <linux/tracepoint.h> +#ifndef __KVM__ +static_assert (0 ,"Do not include trace/events/kvm.h from non-KVM code" ); +#endif +#undef TRACE_SYSTEM#define TRACE_SYSTEM kvm
virt/kvm/Makefile.kvm +1 -1
@@ -3,7 +3,7 @@ # Makefile for Kernel-based Virtual Machine module # -ccflags-y += -I$(srctree)/$(src) +ccflags-y += -I$(srctree)/$(src) -D__KVM__ KVM ?= ../../../virt/kvm
Signature · 1 line
2.42.0.459.ge4e396fd5e-goog
Anup Patel
maintainerRe: [PATCH 26/26] KVM: Hide KVM internal data structures and values from kernel at-large
Quoted 51 lines · On Sat, Sep 16, 2023 at 6:02?AM Sean Christopherson <[email protected]> wrote:
Wrap all KVM internal APIs, data structures, values, etc. in public headers with "#ifdef
__KVM__" to effectively hide KVM's internal details from other subsystems and the kernel at-large. Hiding KVM details for all architectures will, in the very distant future, allow loading a new (or old) KVM module without needing to rebuild and reboot the entire kernel, or to even allow loading and running multiple versions of KVM simultaneously on a single host.To allow different instances of KVM modules to freely modify KVM data structures, enums, #defines, etc., e.g. the struct
kvm_vcpulayout, there must be exactly zero dereferences of KVM-defined structures/values in non-KVM code (excepting code for architectures that don't support such shenanigans). Any such references could lead to latent bugs, e.g. as the kernel would think a KVM structure has layout X, but in reality the current incarnation of KVM uses layout Y.In KVM x86, all remaining non-KVM references to KVM details have been now eliminated. To harden KVM against new references being introduced, hide KVM's details to ensure that KVM doesn?t create a de facto ABI with the rest of the kernel.
Use #ifdeffery to hide KVM details as doing so requires, by far, the least amount of churn and impact on architectures that freely share select KVM details with the rest of the kernel, e.g. s390, ARM64 and PPC, have significant usage of KVM-defined APIs, structures, values, etc. E.g. attempting to extract the "private" chunks into dedicated KVM-internal headers would require massive churn, even on x86, and it's not obvious the end result would be a net positive (all attempts at moving code around failed long before getting anywhere near compiling cleanly).
Another (bad) alternative that would be relative churn-free would be to move the KVM headers to a dedicated KVM-specific path while maintaining the generic layout, e.g. something like
virt/kvm/include/linux. That would allow x86 to simply omit the KVM-specific include path. But that would require modifying the global include path, i.e. would make KVM a really special snowflake and set the awful precedent that it's "ok" to add subsystem specific directories to the global include path.Grant exceptions to
asm-offsets.cas needed, and to s390's VFIO AP driver. Creating a KVM-specific asm-offsets, as was done for x86, adds no value (x86 did so to avoid exposing vendor specific headers) and doesn't create much of a "slippery slope" risk. s390's VFIO AP driver on the other hand is simply too intertwined with KVM to realistically treat it as anything other than KVM code, despite it living in crypto drivers, e.g. the driver has some rather crazy lock ordering rules between the device and KVM.Add a static assert that
__KVM__is defined intrace/events/kvm.h, as that is effectively a private KVM header that just happens to live in a public path.
Quoted 8 lines
Shuffle a few PPC includes and an s390 declaration as needed, and opportunistically include
kvm_host.hintrace/events.kvm.hinstead of relying on the parent to provide the right includes.Cc Anish Ghulati <[email protected]>Cc Venkatesh Srinivas <[email protected]>Cc Andrew Thornton <[email protected]>Signed-off-by Sean Christopherson <[email protected]>
For KVM RISC-V:
Anup Patel <[email protected]>
Regards,
Anup
Quoted 492 lines
--- arch/arm64/include/asm/kvm_emulate.h | 3 +++ arch/arm64/include/asm/kvm_host.h | 2 ++ arch/arm64/include/asm/kvm_mmu.h | 4 ++++ arch/arm64/kernel/asm-offsets.c | 2 ++ arch/arm64/kvm/hyp/Makefile | 2 +- arch/arm64/kvm/hyp/nvhe/Makefile | 3 ++- arch/arm64/kvm/hyp/vhe/Makefile | 2 +- arch/mips/include/asm/kvm_host.h | 2 ++ arch/mips/kernel/asm-offsets.c | 2 ++ arch/powerpc/include/asm/kvm_book3s.h | 3 +++ arch/powerpc/include/asm/kvm_book3s_64.h | 2 ++ arch/powerpc/include/asm/kvm_booke.h | 4 ++++ arch/powerpc/include/asm/kvm_host.h | 7 ++++--- arch/powerpc/include/asm/kvm_ppc.h | 2 ++ arch/powerpc/kernel/asm-offsets.c | 1 + arch/riscv/include/asm/kvm_host.h | 3 +++ arch/riscv/kernel/asm-offsets.c | 1 + arch/s390/include/asm/kvm_host.h | 7 +++++-- arch/s390/kernel/asm-offsets.c | 1 + arch/x86/include/asm/kvm_host.h | 3 +++ drivers/s390/crypto/vfio_ap_drv.c | 1 + drivers/s390/crypto/vfio_ap_ops.c | 2 ++ include/linux/kvm_host.h | 4 ++++ include/linux/kvm_types.h | 3 +++ include/trace/events/kvm.h | 5 +++++ virt/kvm/Makefile.kvm | 2 +- 26 files changed, 64 insertions(+), 9 deletions(-)arch/arm64/include/asm/kvm_emulate.h +3
-0@@ -21,6 +21,8 @@#include <asm/cputype.h> #include <asm/virt.h> +#ifdef __KVM__ +#define CURRENT_EL_SP_EL0_VECTOR 0x0#define CURRENT_EL_SP_ELx_VECTOR 0x200#define LOWER_EL_AArch64_VECTOR 0x400@@ -615,4 +617,5 @@ static __always_inline void kvm_reset_cptr_el2(struct kvm_vcpu *vcpu)kvm_write_cptr_el2 (val); } +#endif /* __KVM__ */ #endif /* __ARM64_KVM_EMULATE_H__ */ arch/arm64/include/asm/kvm_host.h +2
-0@@ -93,6 +93,7 @@ static inline bool kvm_pmu_counter_deferred(struct perf_event_attr *attr)return (!has_vhe () && attr->exclude_host); } +#ifdef __KVM__DECLARE_STATIC_KEY_FALSE (userspace_irqchip_in_use);extern unsigned int __ro_after_init kvm_sve_max_vl;@@ -1149,4 +1150,5 @@ int kvm_trng_call(struct kvm_vcpu *vcpu);void kvm_arm_vcpu_power_off (struct kvm_vcpu *vcpu);bool kvm_arm_vcpu_stopped (struct kvm_vcpu *vcpu); +#endif /* __KVM__ */ #endif /* __ARM64_KVM_HOST_H__ */ arch/arm64/include/asm/kvm_mmu.h +4
-0@@ -125,6 +125,8 @@ void kvm_update_va_mask(struct alt_instr *alt,void kvm_compute_layout (void );void kvm_apply_hyp_relocations (void ); +#ifdef __KVM__ +#define __hyp_pa (x) (((phys_addr_t)(x)) + hyp_physvirt_offset)static __always_inline unsigned long __kern_hyp_va (unsigned long v)@@ -314,5 +316,7 @@ static inline struct kvm *kvm_s2_mmu_to_kvm(struct kvm_s2_mmu *mmu) { return container_of(mmu->arch, struct kvm, arch); } + +#endif /* __KVM__ */ #endif /* __ASSEMBLY__ */ #endif /* __ARM64_KVM_MMU_H__ */ arch/arm64/kernel/asm-offsets.c +2
-0@@ -7,6 +7,8 @@* Copyright (C) 2012 ARM Ltd. */ +#define __KVM__ +#include <linux/arm_sdei.h> #include <linux/sched.h> #include <linux/ftrace.h> arch/arm64/kvm/hyp/Makefile +1
-1@@ -5,6 +5,6 @@ incdir := $(srctree)/$(src)/include subdir-asflags-y := -I$(incdir) -I$(srctree)/arch/arm64/kvm -subdir-ccflags-y := -I$(incdir) -I$(srctree)/arch/arm64/kvm +subdir-ccflags-y := -I$(incdir) -I$(srctree)/arch/arm64/kvm -D__KVM__ obj-$(CONFIG_KVM) += vhe/ nvhe/ pgtable.oarch/arm64/kvm/hyp/nvhe/Makefile +2
-1@@ -9,7 +9,8 @@ asflags-y := -D__KVM_NVHE_HYPERVISOR__ -D__DISABLE_EXPORTS # there is no way to execute them and any such MMIO access from nVHE KVM # will explode instantly (Words of Marc Zyngier). So introduce a generic flag # __DISABLE_TRACE_MMIO__ to disable MMIO tracing for nVHE KVM. -ccflags-y := -D__KVM_NVHE_HYPERVISOR__ -D__DISABLE_EXPORTS -D__DISABLE_TRACE_MMIO__ +ccflags-y := -D__KVM_NVHE_HYPERVISOR__ -D__DISABLE_EXPORTS \ + -D__DISABLE_TRACE_MMIO__ -D__KVM__ ccflags-y += -fno-stack-protector \ -DDISABLE_BRANCH_PROFILING \ $(DISABLE_STACKLEAK_PLUGIN)arch/arm64/kvm/hyp/vhe/Makefile +1
-1@@ -4,7 +4,7 @@ # asflags-y := -D__KVM_VHE_HYPERVISOR__ -ccflags-y := -D__KVM_VHE_HYPERVISOR__ +ccflags-y := -D__KVM_VHE_HYPERVISOR__ -D__KVM__ obj-y := timer-sr.o sysreg-sr.o debug-sr.o switch.o tlb.o obj-y += ../vgic-v3-sr.o ../aarch32.o ../vgic-v2-cpuif-proxy.o ../entry.o \arch/mips/include/asm/kvm_host.h +2
-0@@ -25,6 +25,7 @@#include <asm/inst.h> #include <asm/mipsregs.h> +#ifdef __KVM__/* MIPS KVM register ids */ #define MIPS_CP0_32 (_R, _S) \ (KVM_REG_MIPS_CP0 | KVM_REG_SIZE_U32 | (8 * (_R) + (_S)))@@ -897,4 +898,5 @@ static inline void kvm_arch_vcpu_unblocking(struct kvm_vcpu *vcpu) {}#define __KVM_HAVE_ARCH_FLUSH_REMOTE_TLBS +#endif /* __KVM__ */ #endif /* __MIPS_KVM_HOST_H__ */ arch/mips/kernel/asm-offsets.c +2
-0@@ -9,6 +9,8 @@* Kevin Kissell, kevink at mips.com and Carsten Langgaard, carstenl at mips.com * Copyright (C) 2000 MIPS Technologies, Inc. */ +#define __KVM__ +#include <linux/compat.h> #include <linux/types.h> #include <linux/sched.h> arch/powerpc/include/asm/kvm_book3s.h +3
-0@@ -13,6 +13,8 @@#include <linux/kvm_host.h> #include <asm/kvm_book3s_asm.h> +#ifdef __KVM__ + struct kvmppc_bat { u64 raw; u32 bepi;@@ -483,4 +485,5 @@ static inline u32 kvmppc_pack_vcpu_id(struct kvm *kvm, u32 id)return packed_id; } +#endif /* __KVM__ */ #endif /* __ASM_KVM_BOOK3S_H__ */ arch/powerpc/include/asm/kvm_book3s_64.h +2
-0@@ -16,6 +16,7 @@#include <asm/ppc-opcode.h> #include <asm/pte-walk.h> +#ifdef __KVM__/* * Structure for a nested guest, that is, for a guest that is managed by * one of our guests. @@ -679,4 +680,5 @@ extern pte_t *find_kvm_nested_guest_pte(struct kvm *kvm, unsigned long lpid,#endif /* CONFIG_KVM_BOOK3S_HV_POSSIBLE */ +#endif /* __KVM__ */ #endif /* __ASM_KVM_BOOK3S_64_H__ */ arch/powerpc/include/asm/kvm_booke.h +4
-0@@ -12,6 +12,8 @@#include <linux/types.h> #include <linux/kvm_host.h> +#ifdef __KVM__ +/* * Number of available lpids. Only the low-order 6 bits of LPID rgister are * implemented on e500mc+ cores. @@ -105,4 +107,6 @@ static inline bool kvmppc_supports_magic_page(struct kvm_vcpu *vcpu)return false;#endif } + +#endif /* __KVM__ */ #endif /* __ASM_KVM_BOOKE_H__ */ arch/powerpc/include/asm/kvm_host.h +4
-3@@ -14,6 +14,7 @@#include <linux/interrupt.h> #include <linux/types.h> #include <linux/kvm_types.h> +#include <linux/mmu_notifier.h> #include <linux/threads.h> #include <linux/spinlock.h> #include <linux/kvm_para.h> @@ -25,13 +26,14 @@#include <asm/cacheflush.h> #include <asm/hvcall.h> #include <asm/mce.h> +#include <asm/cputhreads.h> +#ifdef __KVM__#define __KVM_HAVE_ARCH_VCPU_DEBUGFS#define KVM_MAX_VCPUS NR_CPUS#define KVM_MAX_VCORES NR_CPUS -#include <asm/cputhreads.h> #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE #include <asm/kvm_book3s_asm.h> /* for MAX_SMT_THREADS */ @@ -60,8 +62,6 @@#define KVM_REQ_EPR_EXIT KVM_ARCH_REQ(1)#define KVM_REQ_PENDING_TIMER KVM_ARCH_REQ(2) -#include <linux/mmu_notifier.h> -#define KVM_ARCH_WANT_MMU_NOTIFIER #define HPTEG_CACHE_NUM (1 << 15)@@ -883,4 +883,5 @@ static inline void kvm_arch_sched_in(struct kvm_vcpu *vcpu, int cpu) {}static inline void kvm_arch_vcpu_blocking (struct kvm_vcpu *vcpu) {}static inline void kvm_arch_vcpu_unblocking (struct kvm_vcpu *vcpu) {} +#endif /* __KVM__ */ #endif /* __POWERPC_KVM_HOST_H__ */ arch/powerpc/include/asm/kvm_ppc.h +2
-0@@ -183,6 +183,7 @@ static inline void kvmppc_clear_host_ipi(int cpu)static inline bool kvm_hv_mode_active (void ) {return false; }#endif +#ifdef __KVM__/* * KVMPPC_INST_SW_BREAKPOINT is debug Instruction * for supporting software breakpoint. @@ -1076,4 +1077,5 @@ static inline ulong kvmppc_get_ea_indexed(struct kvm_vcpu *vcpu, int ra, int rb)return ea; } +#endif /* __KVM__ */ #endif /* __POWERPC_KVM_PPC_H__ */ arch/powerpc/kernel/asm-offsets.c +1
-0@@ -8,6 +8,7 @@* compile this file to assembler, and then extract the * #defines from the assembly-language output. */ +#define __KVM__#include <linux/compat.h> #include <linux/signal.h> arch/riscv/include/asm/kvm_host.h +3
-0@@ -22,6 +22,8 @@#include <asm/kvm_vcpu_timer.h> #include <asm/kvm_vcpu_pmu.h> +#ifdef __KVM__ +#define KVM_MAX_VCPUS 1024#define KVM_HALT_POLL_NS_DEFAULT 500000@@ -354,4 +356,5 @@ bool kvm_riscv_vcpu_has_interrupts(struct kvm_vcpu *vcpu, u64 mask);void kvm_riscv_vcpu_power_off (struct kvm_vcpu *vcpu);void kvm_riscv_vcpu_power_on (struct kvm_vcpu *vcpu); +#endif /* __KVM__ */ #endif /* __RISCV_KVM_HOST_H__ */ arch/riscv/kernel/asm-offsets.c +1
-0@@ -5,6 +5,7 @@*/ #define GENERATING_ASM_OFFSETS +#define __KVM__#include <linux/kbuild.h> #include <linux/mm.h> arch/s390/include/asm/kvm_host.h +5
-2@@ -380,6 +380,10 @@ struct sie_page {__u8 reserved700[2304 ];/* 0x0700 */ }; +extern char sie_exit; + +#ifdef __KVM__ + struct kvm_vcpu_stat { struct kvm_vcpu_stat_generic generic; u64 exit_userspace;@@ -1028,8 +1032,6 @@ static inline int sie64a(struct kvm_s390_sie_block *sie_block, u64 *rsa)return __sie64a (virt_to_phys (sie_block), sie_block, rsa); } -extern char sie_exit; -bool kvm_s390_pv_is_protected (struct kvm *kvm);bool kvm_s390_pv_cpu_is_protected (struct kvm_vcpu *vcpu);@@ -1049,6 +1051,7 @@ static inline void kvm_arch_vcpu_unblocking(struct kvm_vcpu *vcpu) {}#define __KVM_HAVE_ARCH_VM_FREEvoid kvm_arch_free_vm (struct kvm *kvm); +#endif /* __KVM__ */ struct zpci_kvm_hook {int (*kvm_register)(void *opaque,struct kvm *kvm);arch/s390/kernel/asm-offsets.c +1
-0@@ -6,6 +6,7 @@*/ #define ASM_OFFSETS_C +#define __KVM__#include <linux/kbuild.h> #include <linux/kvm_host.h> arch/x86/include/asm/kvm_host.h +3
-0@@ -37,6 +37,8 @@#include <asm/kvm_vcpu_regs.h> #include <asm/hyperv-tlfs.h> +#ifdef __KVM__ +#define __KVM_HAVE_ARCH_VCPU_DEBUGFS#define KVM_MAX_VCPUS 1024@@ -2229,4 +2231,5 @@ int memslot_rmap_alloc(struct kvm_memory_slot *slot, unsigned long npages);*/ #define KVM_EXIT_HYPERCALL_MBZ GENMASK_ULL(31, 1) +#endif /* __KVM__ */ #endif /* _ASM_X86_KVM_HOST_H */ drivers/s390/crypto/vfio_ap_drv.c +1
-0@@ -7,6 +7,7 @@* Author(s): Tony Krowiak <[email protected]> * Pierre Morel <[email protected]> */ +#define __KVM__#include <linux/module.h> #include <linux/mod_devicetable.h> drivers/s390/crypto/vfio_ap_ops.c +2
-0@@ -8,6 +8,8 @@* Halil Pasic <[email protected]> * Pierre Morel <[email protected]> */ +#define __KVM__ +#include <linux/string.h> #include <linux/vfio.h> #include <linux/device.h> include/linux/kvm_host.h +4
-0@@ -45,6 +45,8 @@#include <asm/kvm_host.h> #include <linux/kvm_dirty_ring.h> +#ifdef __KVM__ +#ifndef KVM_MAX_VCPU_IDS #define KVM_MAX_VCPU_IDS KVM_MAX_VCPUS#endif @@ -2329,4 +2331,6 @@ static inline void kvm_account_pgtable_pages(void *virt, int nr)/* Max number of entries allowed for each kvm dirty ring */ #define KVM_DIRTY_RING_MAX_ENTRIES 65536 +#endif /* __KVM__ */ +#endif include/linux/kvm_types.h +3
-0@@ -48,6 +48,8 @@ typedef u64 hfn_t;typedef hfn_t kvm_pfn_t ; +#ifdef __KVM__ +enum pfn_cache_usage {KVM_GUEST_USES_PFN =BIT (0 ), KVM_HOST_USES_PFN = BIT(1),@@ -123,4 +125,5 @@ struct kvm_vcpu_stat_generic {#define KVM_STATS_NAME_SIZE 48 +#endif /* __KVM__ */ #endif /* __KVM_TYPES_H__ */ include/trace/events/kvm.h +5
-0@@ -2,8 +2,13 @@#if !defined(_TRACE_KVM_MAIN_H) || defined(TRACE_HEADER_MULTI_READ )#define _TRACE_KVM_MAIN_H +#include <linux/kvm_host.h> #include <linux/tracepoint.h> +#ifndef __KVM__ +static_assert (0 ,"Do not include trace/events/kvm.h from non-KVM code" ); +#endif +#undef TRACE_SYSTEM#define TRACE_SYSTEM kvmvirt/kvm/Makefile.kvm +1
-2@@ -3,7 +3,7 @@ # Makefile for Kernel-based Virtual Machine module # -ccflags-y += -I$(srctree)/$(src) +ccflags-y += -I$(srctree)/$(src) -D__KVM__ KVM ?= ../../../virt/kvm --2.42.0.459.ge4e396fd5e-goog
Quoted 62 lines
-----Original Message-----
From: Sean Christopherson <[email protected]>
Sent: Saturday, September 16, 2023 1:31 AM
To: Catalin Marinas <[email protected]>; Will Deacon <[email protected]>; Marc Zyngier <[email protected]>; Oliver Upton <[email protected]>; Huacai Chen <[email protected]>; Michael Ellerman <[email protected]>; Anup Patel <[email protected]>; Paul Walmsley <[email protected]>; Palmer Dabbelt <[email protected]>; Albert Ou <[email protected]>; Heiko Carstens <[email protected]>; Vasily Gorbik <[email protected]>; Alexander Gordeev <[email protected]>; Christian Borntraeger <[email protected]>; Janosch Frank <[email protected]>; Claudio Imbrenda <[email protected]>; Thomas Gleixner <[email protected]>; Ingo Molnar <[email protected]>; Borislav Petkov <[email protected]>; Dave Hansen <[email protected]>;
x86 at kernel.org; Peter Zijlstra <[email protected]>; Arnaldo Carvalho de Melo <[email protected]>; Sean Christopherson <[email protected]>; Paolo Bonzini <[email protected]>; Tony Krowiak <[email protected]>; Halil Pasic <[email protected]>; Jason Herne <[email protected]>; Harald Freudenberger <[email protected]>; Alex Williamson <[email protected]>; Andy Lutomirski <[email protected]>
Cc: linux-arm-kernel at lists.infradead.org; kvmarm at lists.linux.dev; linux- mips at vger.kernel.org; kvm at vger.kernel.org; linuxppc-dev at lists.ozlabs.org; kvm-riscv at lists.infradead.org; linux-riscv at lists.infradead.org; linux- s390 at vger.kernel.org; linux-kernel at vger.kernel.org; linux-perf- users at vger.kernel.org; Anish Ghulati <[email protected]>; Venkatesh Srinivas <[email protected]>; Andrew Thornton <[email protected]>
Subject: [PATCH 00/26] KVM: vfio: Hide KVM internals from othersThis is a borderline RFC series to hide KVM's internals from the rest of the kernel, where "internals" means data structures, enums, #defines, APIs, etc. that are intended to be KVM-only, but are exposed everywhere due to
kvm_host.h(and other headers) living in the global include paths.The motiviation for hiding KVM's internals is to allow *safely* loading a "new" KVM module without having to reboot the host. Where "new" doesn't have to be strictly newer, just a different incarnation of KVM. Hiding KVM's internals means those assets can change across KVM instances without
breaking things, e.g. would allow modifying the layout of structkvm_vcputo introduce new fields related to a new feature or mitigation for hardware bugs.The end goal for all of this is to allow loading and running multiple instances of KVM (the module) simultaneously on a single host, e.g. to deploy fixes, mitigations, and/or new features without having to drain all VMs from the host.
For now, the immediate goal is to get KVM to a state where KVM x86 doesn't expose anything to the broader world that isn't intended for external consumption, e.g. the page write-tracking APIs used by KVM-GT.
I say this is borderline RFC because I don't think I've "formally" proposed the idea of hiding KVM internals before now. I decided not to tag this RFC because the changes ended up being not _that_ invasive, and everything before the last six patches is worthwhile even if hiding internals is ultimately rejected (IMO).
Quoted 6 lines
This would ideally be ~5 separate series, and I certainly have no objection if that's how we want to get this stuff merged. E.g. (1) VFIO cleanups,
(2) dropHAVE_KVM, (3) clean up makefiles, (4) x86 perf cleanup, and
(5) final push for hiding state. TheHAVE_KVMandvirt/kvminclude stuff isn't strictly necessary, but I included them here because they're relatively minor (in the grand scheme).
Hi Sean,
Just thought of checking with you on this series. Do you have plans to revive this series? The reason I am asking is, on ARM64/KVM side we do have a requirement to share the KVM VMID with SMMUV3. Please see the RFC I sent out earlier this year[1]. The series basically provides a way for KVM to pin a VMID and also associates an iommufd ctx with a struct kvm * to retrieve that VMID.
As mentioned above, some of the patches in this series(especially 1-4 & 6) that does the VFIO cleanups and dropping CONFIG_KVM_VFIO looks very straightforward and useful. I am thinking of including those when I re-spin my RFC series, if that?s ok.
Please let me know your thoughts.
Thanks,
Shameer
[1]. https://lore.kernel.org/linux-iommu/20240209115824.GA2922446 at myrica/
Sean Christopherson
maintainerQuoted 9 lines · Shameerali Kolothum Thodi
Quoted 4 lines
This is a borderline RFC series to hide KVM's internals from the rest of the kernel, where "internals" means data structures, enums, #defines, APIs, etc. that are intended to be KVM-only, but are exposed everywhere due to
kvm_host.h(and other headers) living in the global include paths.Hi Sean,
Just thought of checking with you on this series. Do you have plans to revive this series?
Yep!
Quoted 9 lines
The reason I am asking is, on ARM64/KVM side we do have a requirement to share the KVM VMID with SMMUV3. Please see the RFC I sent out earlier this year[1]. The series basically provides a way for KVM to pin a VMID and also associates an iommufd ctx with a struct kvm * to retrieve that VMID.
As mentioned above, some of the patches in this
series(especially 1-4 & 6)that does the VFIO cleanups and droppingCONFIG_KVM_VFIOlooks very straightforward and useful. I am thinking of including those when I re-spin my RFC series, if that?s ok.
Please don't include them, as the patch they build towards (patch 5) is buggy[*], and I am fairly certain that at least some of the patches will change significantly.
I expect to re-start working on the series in ~2 weeks, and am planning on actively pushing the series (i.e. not ignoring it for months on end).
[*] https://lore.kernel.org/all/ZWp_q1w01NCZi8KX at google.com
Quoted 3 lines
Please let me know your thoughts.
[1]. https://lore.kernel.org/linux-iommu/20240209115824.GA2922446 at myrica
Quoted 56 lines
-----Original Message-----
From: Sean Christopherson <[email protected]>
Sent: Monday, June 24, 2024 4:32 PM
To: Shameerali Kolothum Thodi <[email protected]>
Cc: Catalin Marinas <[email protected]>; Will Deacon <[email protected]>; Marc Zyngier <[email protected]>; Oliver Upton <[email protected]>; Huacai Chen <[email protected]>; Michael Ellerman <[email protected]>; Anup Patel <[email protected]>; Paul Walmsley <[email protected]>; Palmer Dabbelt <[email protected]>; Albert Ou <[email protected]>; Heiko Carstens <[email protected]>; Vasily Gorbik <[email protected]>; Alexander Gordeev <[email protected]>; Christian Borntraeger <[email protected]>; Janosch Frank <[email protected]>; Claudio Imbrenda <[email protected]>; Thomas Gleixner <[email protected]>; Ingo Molnar <[email protected]>; Borislav Petkov <[email protected]>; Dave Hansen <[email protected]>;
x86 at kernel.org; Peter Zijlstra <[email protected]>; Arnaldo Carvalho de Melo <[email protected]>; Paolo Bonzini <[email protected]>; Tony Krowiak <[email protected]>; Halil Pasic <[email protected]>; Jason Herne <[email protected]>; Harald Freudenberger <[email protected]>; Alex Williamson <[email protected]>; Andy Lutomirski <[email protected]>; linux-arm-kernel at lists.infradead.org; kvmarm at lists.linux.dev; linux-mips at vger.kernel.org; kvm at vger.kernel.org; linuxppc-dev at lists.ozlabs.org; kvm-riscv at lists.infradead.org; linux- riscv at lists.infradead.org; linux-s390 at vger.kernel.org; linux- kernel at vger.kernel.org; linux-perf-users at vger.kernel.org; Anish Ghulati <[email protected]>; Venkatesh Srinivas <[email protected]>; Andrew Thornton <[email protected]>
Subject: Re: [PATCH 00/26] KVM: vfio: Hide KVM internals from othersQuoted 3 lines · Shameerali Kolothum Thodi
Quoted 3 lines
This is a borderline RFC series to hide KVM's internals from the rest of the kernel, where "internals" means data structures, enums, #defines, APIs, etc. that are intended to be KVM-only, but are exposed
everywhere
Quoted 5 lines
Quoted 1 line
due to
kvm_host.h(and other headers) living in the global include paths.Hi Sean,
Just thought of checking with you on this series. Do you have plans to
revive this
Quoted 1 line
series?
Yep!
Quoted 2 lines
The reason I am asking is, on ARM64/KVM side we do have a requirement to share the KVM VMID with SMMUV3. Please see the RFC I sent out
earlier this
Quoted 4 lines
year[1]. The series basically provides a way for KVM to pin a VMID and also associates an iommufd ctx with a struct kvm * to retrieve that VMID.
As mentioned above, some of the patches in this
series(especially 1-4 & 6)that
Quoted 1 line
does the VFIO cleanups and dropping
CONFIG_KVM_VFIOlooks very
Quoted 8 lines
straightforward
Quoted 2 lines
and useful. I am thinking of including those when I re-spin my RFC series, if that?s ok.
Please don't include them, as the patch they build towards (patch 5) is buggy[*],
and I am fairly certain that at least some of the patches will change significantly.
Ok. Got it. Thanks for taking a look at the KVM pinned VMID series and comments there.
Shameer