|
5 | 5 | #include <asm/cpu.h>
|
6 | 6 |
|
7 | 7 | #include "lapic.h"
|
| 8 | +#include "irq.h" |
8 | 9 | #include "posted_intr.h"
|
9 | 10 | #include "trace.h"
|
10 | 11 | #include "vmx.h"
|
@@ -77,13 +78,18 @@ void vmx_vcpu_pi_load(struct kvm_vcpu *vcpu, int cpu)
|
77 | 78 | pi_set_on(pi_desc);
|
78 | 79 | }
|
79 | 80 |
|
| 81 | +static bool vmx_can_use_vtd_pi(struct kvm *kvm) |
| 82 | +{ |
| 83 | + return irqchip_in_kernel(kvm) && enable_apicv && |
| 84 | + kvm_arch_has_assigned_device(kvm) && |
| 85 | + irq_remapping_cap(IRQ_POSTING_CAP); |
| 86 | +} |
| 87 | + |
80 | 88 | void vmx_vcpu_pi_put(struct kvm_vcpu *vcpu)
|
81 | 89 | {
|
82 | 90 | struct pi_desc *pi_desc = vcpu_to_pi_desc(vcpu);
|
83 | 91 |
|
84 |
| - if (!kvm_arch_has_assigned_device(vcpu->kvm) || |
85 |
| - !irq_remapping_cap(IRQ_POSTING_CAP) || |
86 |
| - !kvm_vcpu_apicv_active(vcpu)) |
| 92 | + if (!vmx_can_use_vtd_pi(vcpu->kvm)) |
87 | 93 | return;
|
88 | 94 |
|
89 | 95 | /* Set SN when the vCPU is preempted */
|
@@ -141,9 +147,7 @@ int pi_pre_block(struct kvm_vcpu *vcpu)
|
141 | 147 | struct pi_desc old, new;
|
142 | 148 | struct pi_desc *pi_desc = vcpu_to_pi_desc(vcpu);
|
143 | 149 |
|
144 |
| - if (!kvm_arch_has_assigned_device(vcpu->kvm) || |
145 |
| - !irq_remapping_cap(IRQ_POSTING_CAP) || |
146 |
| - !kvm_vcpu_apicv_active(vcpu)) |
| 150 | + if (!vmx_can_use_vtd_pi(vcpu->kvm)) |
147 | 151 | return 0;
|
148 | 152 |
|
149 | 153 | WARN_ON(irqs_disabled());
|
@@ -270,9 +274,7 @@ int pi_update_irte(struct kvm *kvm, unsigned int host_irq, uint32_t guest_irq,
|
270 | 274 | struct vcpu_data vcpu_info;
|
271 | 275 | int idx, ret = 0;
|
272 | 276 |
|
273 |
| - if (!kvm_arch_has_assigned_device(kvm) || |
274 |
| - !irq_remapping_cap(IRQ_POSTING_CAP) || |
275 |
| - !kvm_vcpu_apicv_active(kvm->vcpus[0])) |
| 277 | + if (!vmx_can_use_vtd_pi(kvm)) |
276 | 278 | return 0;
|
277 | 279 |
|
278 | 280 | idx = srcu_read_lock(&kvm->irq_srcu);
|
|
0 commit comments