KVM: VMX: check apicv is active before using VT-d posted interrupt
PATCH 1/1 KVM: VMX: check apicv is active before using VT-d posted interrupt
VT-d posted interrupt is relying on the CPU side's posted interrupt. Need to check whether VCPU's APICv is active before enabing VT-d posted interrupt.
--- arch/x86/kvm/vmx.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
arch/x86/kvm/vmx.c +10 -5
@@ -2072,7 +2072,8 @@ static void vmx_vcpu_pi_load(struct kvm_vcpu *vcpu, int cpu)unsigned int dest;if (!kvm_arch_has_assigned_device (vcpu->kvm) || - !irq_remapping_cap (IRQ_POSTING_CAP )) + !irq_remapping_cap (IRQ_POSTING_CAP ) || + !kvm_vcpu_apicv_active (vcpu))return ; do {
@@ -2180,7 +2181,8 @@ static void vmx_vcpu_pi_put(struct kvm_vcpu *vcpu)struct pi_desc *pi_desc =vcpu_to_pi_desc (vcpu);if (!kvm_arch_has_assigned_device (vcpu->kvm) || - !irq_remapping_cap (IRQ_POSTING_CAP )) + !irq_remapping_cap (IRQ_POSTING_CAP ) || + !kvm_vcpu_apicv_active (vcpu))return ;/* Set SN when the vCPU is preempted */
@@ -10698,7 +10700,8 @@ static int vmx_pre_block(struct kvm_vcpu *vcpu)struct pi_desc *pi_desc =vcpu_to_pi_desc (vcpu);if (!kvm_arch_has_assigned_device (vcpu->kvm) || - !irq_remapping_cap (IRQ_POSTING_CAP )) + !irq_remapping_cap (IRQ_POSTING_CAP ) || + !kvm_vcpu_apicv_active (vcpu))return 0 ; vcpu->pre_pcpu = vcpu->cpu;
@@ -10764,7 +10767,8 @@ static void vmx_post_block(struct kvm_vcpu *vcpu)unsigned long flags;if (!kvm_arch_has_assigned_device (vcpu->kvm) || - !irq_remapping_cap (IRQ_POSTING_CAP )) + !irq_remapping_cap (IRQ_POSTING_CAP ) || + !kvm_vcpu_apicv_active (vcpu))return ; do {
@@ -10817,7 +10821,8 @@ static int vmx_update_pi_irte(struct kvm *kvm, unsigned int host_irq,int idx, ret = -EINVAL ;if (!kvm_arch_has_assigned_device (kvm) || - !irq_remapping_cap (IRQ_POSTING_CAP )) + !irq_remapping_cap (IRQ_POSTING_CAP ) || + !kvm_vcpu_apicv_active (kvm->vcpus[0 ]))return 0 ; idx =srcu_read_lock (&kvm->irq_srcu);
Signature · 1 line
1.8.2.1
Quoted 11 lines
-----Original Message-----
From: Yang Zhang [mailto:[email protected]]
Sent: Friday, May 20, 2016 3:51 PM
To: Paolo Bonzini <[email protected]>; [email protected]; Wu, Feng <[email protected]>
Cc: [email protected]
Subject: [PATCH] KVM: VMX: check apicv is active before using VT-d posted interrupt
Quoted 3 lines
VT-d posted interrupt is relying on the CPU side's posted interrupt. Need to check whether VCPU's APICv is active before enabing VT-d posted interrupt.
Yes, the extra check is good. Just curious, Do you see some hardware with VT-d PI but no CPU side PI. I remember I was told this cannot happen in real world.
Thanks,
feng
Quoted 65 lines
Signed-off-by Yang Zhang <[email protected]>Signed-off-by Shengge Ding <[email protected]>--- arch/x86/kvm/vmx.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)arch/x86/kvm/vmx.c +2
-1@@ -2072,7 +2072,8 @@ static void vmx_vcpu_pi_load(struct kvm_vcpu *vcpu, int cpu)unsigned int dest;if (!kvm_arch_has_assigned_device (vcpu->kvm) || - !irq_remapping_cap (IRQ_POSTING_CAP )) + !irq_remapping_cap (IRQ_POSTING_CAP ) || + !kvm_vcpu_apicv_active (vcpu))return ;do {arch/x86/kvm/vmx.c +8
-4@@ -2180,7 +2181,8 @@ static void vmx_vcpu_pi_put(struct kvm_vcpu *vcpu)struct pi_desc *pi_desc =vcpu_to_pi_desc (vcpu);if (!kvm_arch_has_assigned_device (vcpu->kvm) || - !irq_remapping_cap (IRQ_POSTING_CAP )) + !irq_remapping_cap (IRQ_POSTING_CAP ) || + !kvm_vcpu_apicv_active (vcpu))return ;/* Set SN when the vCPU is preempted */ @@ -10698,7 +10700,8 @@ static int vmx_pre_block(struct kvm_vcpu *vcpu)struct pi_desc *pi_desc =vcpu_to_pi_desc (vcpu);if (!kvm_arch_has_assigned_device (vcpu->kvm) || - !irq_remapping_cap (IRQ_POSTING_CAP )) + !irq_remapping_cap (IRQ_POSTING_CAP ) || + !kvm_vcpu_apicv_active (vcpu))return 0 ; vcpu->pre_pcpu = vcpu->cpu;@@ -10764,7 +10767,8 @@ static void vmx_post_block(struct kvm_vcpu *vcpu)unsigned long flags;if (!kvm_arch_has_assigned_device (vcpu->kvm) || - !irq_remapping_cap (IRQ_POSTING_CAP )) + !irq_remapping_cap (IRQ_POSTING_CAP ) || + !kvm_vcpu_apicv_active (vcpu))return ; do {@@ -10817,7 +10821,8 @@ static int vmx_update_pi_irte(struct kvm *kvm,unsigned int host_irq, int idx, ret = -EINVAL;if (!kvm_arch_has_assigned_device (kvm) || - !irq_remapping_cap (IRQ_POSTING_CAP )) + !irq_remapping_cap (IRQ_POSTING_CAP ) || + !kvm_vcpu_apicv_active (kvm->vcpus[0 ]))return 0 ;idx =
srcu_read_lock(&kvm->irq_srcu);
--
1.8.2.1
Quoted 11 lines · Feng
Quoted 11 lines
-----Original Message-----
From: Yang Zhang [mailto:[email protected]]
Sent: Friday, May 20, 2016 3:51 PM
To: Paolo Bonzini <[email protected]>; [email protected]; Wu, Feng <[email protected]>
Cc: [email protected]
Subject: [PATCH] KVM: VMX: check apicv is active before using VT-d posted interrupt
Quoted 7 lines
Quoted 3 lines
VT-d posted interrupt is relying on the CPU side's posted interrupt. Need to check whether VCPU's APICv is active before enabing VT-d posted interrupt.
Yes, the extra check is good. Just curious, Do you see some hardware with VT-d PI but no CPU side PI. I remember I was told this cannot happen in real world.
Hardware is ok. The problem is user can turn off the APICv manually which cause the device fails to work inside guest.
Quoted 69 lines
Thanks,
fengQuoted 65 lines
Signed-off-by Yang Zhang <[email protected]>Signed-off-by Shengge Ding <[email protected]>--- arch/x86/kvm/vmx.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)arch/x86/kvm/vmx.c +2
-1@@ -2072,7 +2072,8 @@ static void vmx_vcpu_pi_load(struct kvm_vcpu *vcpu, int cpu)unsigned int dest;if (!kvm_arch_has_assigned_device (vcpu->kvm) || - !irq_remapping_cap (IRQ_POSTING_CAP )) + !irq_remapping_cap (IRQ_POSTING_CAP ) || + !kvm_vcpu_apicv_active (vcpu))return ;do {arch/x86/kvm/vmx.c +8
-4@@ -2180,7 +2181,8 @@ static void vmx_vcpu_pi_put(struct kvm_vcpu *vcpu)struct pi_desc *pi_desc =vcpu_to_pi_desc (vcpu);if (!kvm_arch_has_assigned_device (vcpu->kvm) || - !irq_remapping_cap (IRQ_POSTING_CAP )) + !irq_remapping_cap (IRQ_POSTING_CAP ) || + !kvm_vcpu_apicv_active (vcpu))return ;/* Set SN when the vCPU is preempted */ @@ -10698,7 +10700,8 @@ static int vmx_pre_block(struct kvm_vcpu *vcpu)struct pi_desc *pi_desc =vcpu_to_pi_desc (vcpu);if (!kvm_arch_has_assigned_device (vcpu->kvm) || - !irq_remapping_cap (IRQ_POSTING_CAP )) + !irq_remapping_cap (IRQ_POSTING_CAP ) || + !kvm_vcpu_apicv_active (vcpu))return 0 ; vcpu->pre_pcpu = vcpu->cpu;@@ -10764,7 +10767,8 @@ static void vmx_post_block(struct kvm_vcpu *vcpu)unsigned long flags;if (!kvm_arch_has_assigned_device (vcpu->kvm) || - !irq_remapping_cap (IRQ_POSTING_CAP )) + !irq_remapping_cap (IRQ_POSTING_CAP ) || + !kvm_vcpu_apicv_active (vcpu))return ; do {@@ -10817,7 +10821,8 @@ static int vmx_update_pi_irte(struct kvm *kvm,unsigned int host_irq, int idx, ret = -EINVAL;if (!kvm_arch_has_assigned_device (kvm) || - !irq_remapping_cap (IRQ_POSTING_CAP )) + !irq_remapping_cap (IRQ_POSTING_CAP ) || + !kvm_vcpu_apicv_active (kvm->vcpus[0 ]))return 0 ;idx =
srcu_read_lock(&kvm->irq_srcu);
--
1.8.2.1
Signature · 2 lines
best regards yang
Paolo Bonzini
maintainerQuoted 6 lines · Yang Zhang
VT-d posted interrupt is relying on the CPU side's posted interrupt. Need to check whether VCPU's APICv is active before enabing VT-d posted interrupt.
Signed-off-by Yang Zhang <[email protected]>Signed-off-by Shengge Ding <[email protected]>
Please resend this patch without format=flowed (just use git-send-email), as it cannot be applied otherwise.
Thanks,
Paolo
Quoted 60 lines
--- arch/x86/kvm/vmx.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)arch/x86/kvm/vmx.c +2
-1@@ -2072,7 +2072,8 @@ static void vmx_vcpu_pi_load(struct kvm_vcpu *vcpu, int cpu)unsigned int dest;if (!kvm_arch_has_assigned_device (vcpu->kvm) || - !irq_remapping_cap (IRQ_POSTING_CAP )) + !irq_remapping_cap (IRQ_POSTING_CAP ) || + !kvm_vcpu_apicv_active (vcpu))return ;do {arch/x86/kvm/vmx.c +8
-4@@ -2180,7 +2181,8 @@ static void vmx_vcpu_pi_put(struct kvm_vcpu *vcpu)struct pi_desc *pi_desc =vcpu_to_pi_desc (vcpu);if (!kvm_arch_has_assigned_device (vcpu->kvm) || - !irq_remapping_cap (IRQ_POSTING_CAP )) + !irq_remapping_cap (IRQ_POSTING_CAP ) || + !kvm_vcpu_apicv_active (vcpu))return ;/* Set SN when the vCPU is preempted */ @@ -10698,7 +10700,8 @@ static int vmx_pre_block(struct kvm_vcpu *vcpu)struct pi_desc *pi_desc =vcpu_to_pi_desc (vcpu);if (!kvm_arch_has_assigned_device (vcpu->kvm) || - !irq_remapping_cap (IRQ_POSTING_CAP )) + !irq_remapping_cap (IRQ_POSTING_CAP ) || + !kvm_vcpu_apicv_active (vcpu))return 0 ; vcpu->pre_pcpu = vcpu->cpu;@@ -10764,7 +10767,8 @@ static void vmx_post_block(struct kvm_vcpu *vcpu)unsigned long flags;if (!kvm_arch_has_assigned_device (vcpu->kvm) || - !irq_remapping_cap (IRQ_POSTING_CAP )) + !irq_remapping_cap (IRQ_POSTING_CAP ) || + !kvm_vcpu_apicv_active (vcpu))return ; do {@@ -10817,7 +10821,8 @@ static int vmx_update_pi_irte(struct kvm *kvm,unsigned int host_irq, int idx, ret = -EINVAL;if (!kvm_arch_has_assigned_device (kvm) || - !irq_remapping_cap (IRQ_POSTING_CAP )) + !irq_remapping_cap (IRQ_POSTING_CAP ) || + !kvm_vcpu_apicv_active (kvm->vcpus[0 ]))return 0 ;idx = srcu_read_lock(&kvm->irq_srcu);
Quoted 10 lines · Paolo Bonzini
Quoted 6 lines · Yang Zhang
VT-d posted interrupt is relying on the CPU side's posted interrupt. Need to check whether VCPU's APICv is active before enabing VT-d posted interrupt.
Signed-off-by Yang Zhang <[email protected]>Signed-off-by Shengge Ding <[email protected]>Please resend this patch without format=flowed (just use git-send-email), as it cannot be applied otherwise.
Sorry, my git proxy is broken recently. I will resend it ASAP once the problem got fixed.
Quoted 65 lines
Thanks,
Paolo
Quoted 60 lines
--- arch/x86/kvm/vmx.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)arch/x86/kvm/vmx.c +2
-1@@ -2072,7 +2072,8 @@ static void vmx_vcpu_pi_load(struct kvm_vcpu *vcpu, int cpu)unsigned int dest;if (!kvm_arch_has_assigned_device (vcpu->kvm) || - !irq_remapping_cap (IRQ_POSTING_CAP )) + !irq_remapping_cap (IRQ_POSTING_CAP ) || + !kvm_vcpu_apicv_active (vcpu))return ;do {arch/x86/kvm/vmx.c +8
-4@@ -2180,7 +2181,8 @@ static void vmx_vcpu_pi_put(struct kvm_vcpu *vcpu)struct pi_desc *pi_desc =vcpu_to_pi_desc (vcpu);if (!kvm_arch_has_assigned_device (vcpu->kvm) || - !irq_remapping_cap (IRQ_POSTING_CAP )) + !irq_remapping_cap (IRQ_POSTING_CAP ) || + !kvm_vcpu_apicv_active (vcpu))return ;/* Set SN when the vCPU is preempted */ @@ -10698,7 +10700,8 @@ static int vmx_pre_block(struct kvm_vcpu *vcpu)struct pi_desc *pi_desc =vcpu_to_pi_desc (vcpu);if (!kvm_arch_has_assigned_device (vcpu->kvm) || - !irq_remapping_cap (IRQ_POSTING_CAP )) + !irq_remapping_cap (IRQ_POSTING_CAP ) || + !kvm_vcpu_apicv_active (vcpu))return 0 ; vcpu->pre_pcpu = vcpu->cpu;@@ -10764,7 +10767,8 @@ static void vmx_post_block(struct kvm_vcpu *vcpu)unsigned long flags;if (!kvm_arch_has_assigned_device (vcpu->kvm) || - !irq_remapping_cap (IRQ_POSTING_CAP )) + !irq_remapping_cap (IRQ_POSTING_CAP ) || + !kvm_vcpu_apicv_active (vcpu))return ; do {@@ -10817,7 +10821,8 @@ static int vmx_update_pi_irte(struct kvm *kvm,unsigned int host_irq, int idx, ret = -EINVAL;if (!kvm_arch_has_assigned_device (kvm) || - !irq_remapping_cap (IRQ_POSTING_CAP )) + !irq_remapping_cap (IRQ_POSTING_CAP ) || + !kvm_vcpu_apicv_active (kvm->vcpus[0 ]))return 0 ;idx = srcu_read_lock(&kvm->irq_srcu);
Signature · 2 lines
best regards yang