Skip to content

Commit 459074c

Browse files
committed
KVM: x86: Add module param to control and enumerate device posted IRQs
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/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent c364baa commit 459074c

File tree

4 files changed

+12
-1
lines changed

4 files changed

+12
-1
lines changed

arch/x86/include/asm/kvm_host.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1942,6 +1942,7 @@ struct kvm_arch_async_pf {
19421942
extern u32 __read_mostly kvm_nr_uret_msrs;
19431943
extern bool __read_mostly allow_smaller_maxphyaddr;
19441944
extern bool __read_mostly enable_apicv;
1945+
extern bool __read_mostly enable_device_posted_irqs;
19451946
extern struct kvm_x86_ops kvm_x86_ops;
19461947

19471948
#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);
24452446

24462447
static inline bool kvm_arch_has_irq_bypass(void)
24472448
{
2448-
return enable_apicv && irq_remapping_cap(IRQ_POSTING_CAP);
2449+
return enable_device_posted_irqs;
24492450
}
24502451

24512452
#endif /* _ASM_X86_KVM_HOST_H */

arch/x86/kvm/svm/svm.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,8 @@ module_param(tsc_scaling, int, 0444);
231231
static bool avic;
232232
module_param(avic, bool, 0444);
233233

234+
module_param(enable_device_posted_irqs, bool, 0444);
235+
234236
bool __read_mostly dump_invalid_vmcb;
235237
module_param(dump_invalid_vmcb, bool, 0644);
236238

arch/x86/kvm/vmx/vmx.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ module_param(enable_apicv, bool, 0444);
116116
bool __read_mostly enable_ipiv = true;
117117
module_param(enable_ipiv, bool, 0444);
118118

119+
module_param(enable_device_posted_irqs, bool, 0444);
120+
119121
/*
120122
* If nested=1, nested virtualization is supported, i.e., guests may use
121123
* VMX and be a hypervisor for its own guests. If nested=0, guests may not

arch/x86/kvm/x86.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,9 @@ EXPORT_SYMBOL_GPL(allow_smaller_maxphyaddr);
226226
bool __read_mostly enable_apicv = true;
227227
EXPORT_SYMBOL_GPL(enable_apicv);
228228

229+
bool __read_mostly enable_device_posted_irqs = true;
230+
EXPORT_SYMBOL_GPL(enable_device_posted_irqs);
231+
229232
const struct _kvm_stats_desc kvm_vm_stats_desc[] = {
230233
KVM_GENERIC_VM_STATS(),
231234
STATS_DESC_COUNTER(VM, mmu_shadow_zapped),
@@ -9809,6 +9812,9 @@ int kvm_x86_vendor_init(struct kvm_x86_init_ops *ops)
98099812
if (r != 0)
98109813
goto out_mmu_exit;
98119814

9815+
enable_device_posted_irqs &= enable_apicv &&
9816+
irq_remapping_cap(IRQ_POSTING_CAP);
9817+
98129818
kvm_ops_update(ops);
98139819

98149820
for_each_online_cpu(cpu) {

0 commit comments

Comments
 (0)