]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
KVM: x86: Add module param to control and enumerate device posted IRQs
authorSean Christopherson <seanjc@google.com>
Tue, 1 Apr 2025 16:18:04 +0000 (09:18 -0700)
committerSean Christopherson <seanjc@google.com>
Thu, 24 Apr 2025 18:18:38 +0000 (11:18 -0700)
Add a module param to each KVM vendor module to allow disabling device
posted interrupts without having to sacrifice all of APICv/AVIC, and to
also effectively enumerate to userspace whether or not KVM may be
utilizing device posted IRQs.  Disabling device posted interrupts is
very desirable for testing, and can even be desirable for production
environments, e.g. if the host kernel wants to interpose on device
interrupts.

Put the module param in kvm-{amd,intel}.ko instead of kvm.ko to match
the overall APICv/AVIC controls, and to avoid complications with said
controls.  E.g. if the param is in kvm.ko, KVM needs to be snapshot the
original user-defined value to play nice with a vendor module being
reloaded with different enable_apicv settings.

Link: https://lore.kernel.org/r/20250401161804.842968-4-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/include/asm/kvm_host.h
arch/x86/kvm/svm/svm.c
arch/x86/kvm/vmx/vmx.c
arch/x86/kvm/x86.c

index 89102b65827fbb4a8b74c61aa077b6aeb2f03273..1609cc46323a1c4d2f7ca16fbc60d2c54082c850 100644 (file)
@@ -1942,6 +1942,7 @@ struct kvm_arch_async_pf {
 extern u32 __read_mostly kvm_nr_uret_msrs;
 extern bool __read_mostly allow_smaller_maxphyaddr;
 extern bool __read_mostly enable_apicv;
+extern bool __read_mostly enable_device_posted_irqs;
 extern struct kvm_x86_ops kvm_x86_ops;
 
 #define kvm_x86_call(func) static_call(kvm_x86_##func)
@@ -2445,7 +2446,7 @@ int memslot_rmap_alloc(struct kvm_memory_slot *slot, unsigned long npages);
 
 static inline bool kvm_arch_has_irq_bypass(void)
 {
-       return enable_apicv && irq_remapping_cap(IRQ_POSTING_CAP);
+       return enable_device_posted_irqs;
 }
 
 #endif /* _ASM_X86_KVM_HOST_H */
index cc1c721ba067da0ace5e4ec969c9d877356a6a44..8eb482ca3359d9f1a21572a93030c197b29eb951 100644 (file)
@@ -231,6 +231,8 @@ module_param(tsc_scaling, int, 0444);
 static bool avic;
 module_param(avic, bool, 0444);
 
+module_param(enable_device_posted_irqs, bool, 0444);
+
 bool __read_mostly dump_invalid_vmcb;
 module_param(dump_invalid_vmcb, bool, 0644);
 
index ef2d7208dd208a4ccad3ea5a0cf4b657f7a50f11..ba08a7edc712aadc32420a04fabf7d61f19fc277 100644 (file)
@@ -116,6 +116,8 @@ module_param(enable_apicv, bool, 0444);
 bool __read_mostly enable_ipiv = true;
 module_param(enable_ipiv, bool, 0444);
 
+module_param(enable_device_posted_irqs, bool, 0444);
+
 /*
  * If nested=1, nested virtualization is supported, i.e., guests may use
  * VMX and be a hypervisor for its own guests. If nested=0, guests may not
index e15af894f414fd7bba03cf7a838afbfab0cbd753..f35f4456e388aef2f7496c7347fc2af517597554 100644 (file)
@@ -226,6 +226,9 @@ EXPORT_SYMBOL_GPL(allow_smaller_maxphyaddr);
 bool __read_mostly enable_apicv = true;
 EXPORT_SYMBOL_GPL(enable_apicv);
 
+bool __read_mostly enable_device_posted_irqs = true;
+EXPORT_SYMBOL_GPL(enable_device_posted_irqs);
+
 const struct _kvm_stats_desc kvm_vm_stats_desc[] = {
        KVM_GENERIC_VM_STATS(),
        STATS_DESC_COUNTER(VM, mmu_shadow_zapped),
@@ -9809,6 +9812,9 @@ int kvm_x86_vendor_init(struct kvm_x86_init_ops *ops)
        if (r != 0)
                goto out_mmu_exit;
 
+       enable_device_posted_irqs &= enable_apicv &&
+                                    irq_remapping_cap(IRQ_POSTING_CAP);
+
        kvm_ops_update(ops);
 
        for_each_online_cpu(cpu) {