All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: VMX: check apicv is active before using VT-d posted interrupt
@ 2016-05-20  7:50 Yang Zhang
  2016-05-20  8:22 ` Wu, Feng
  2016-05-23 14:23 ` Paolo Bonzini
  0 siblings, 2 replies; 5+ messages in thread
From: Yang Zhang @ 2016-05-20  7:50 UTC (permalink / raw)
  To: Paolo Bonzini, rkrcmar, Feng Wu; +Cc: kvm

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 <yang.zhang.wz@gmail.com>
Signed-off-by: Shengge Ding <shengge.dsg@alibaba-inc.com>
---
  arch/x86/kvm/vmx.c | 15 ++++++++++-----
  1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 7ebf27b..8ba87f3 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -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);
-- 
1.8.2.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* RE: [PATCH] KVM: VMX: check apicv is active before using VT-d posted interrupt
  2016-05-20  7:50 [PATCH] KVM: VMX: check apicv is active before using VT-d posted interrupt Yang Zhang
@ 2016-05-20  8:22 ` Wu, Feng
  2016-05-23  1:10   ` Yang Zhang
  2016-05-23 14:23 ` Paolo Bonzini
  1 sibling, 1 reply; 5+ messages in thread
From: Wu, Feng @ 2016-05-20  8:22 UTC (permalink / raw)
  To: Yang Zhang, Paolo Bonzini, rkrcmar; +Cc: kvm, Wu, Feng



> -----Original Message-----
> From: Yang Zhang [mailto:yang.zhang.wz@gmail.com]
> Sent: Friday, May 20, 2016 3:51 PM
> To: Paolo Bonzini <pbonzini@redhat.com>; rkrcmar@redhat.com; Wu, Feng
> <feng.wu@intel.com>
> Cc: kvm@vger.kernel.org
> Subject: [PATCH] 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.

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

> 
> Signed-off-by: Yang Zhang <yang.zhang.wz@gmail.com>
> Signed-off-by: Shengge Ding <shengge.dsg@alibaba-inc.com>
> ---
>   arch/x86/kvm/vmx.c | 15 ++++++++++-----
>   1 file changed, 10 insertions(+), 5 deletions(-)
> 
> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> index 7ebf27b..8ba87f3 100644
> --- a/arch/x86/kvm/vmx.c
> +++ b/arch/x86/kvm/vmx.c
> @@ -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);
> --
> 1.8.2.1

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] KVM: VMX: check apicv is active before using VT-d posted interrupt
  2016-05-20  8:22 ` Wu, Feng
@ 2016-05-23  1:10   ` Yang Zhang
  0 siblings, 0 replies; 5+ messages in thread
From: Yang Zhang @ 2016-05-23  1:10 UTC (permalink / raw)
  To: Wu, Feng, Paolo Bonzini, rkrcmar; +Cc: kvm

On 2016/5/20 16:22, Wu, Feng wrote:
>
>
>> -----Original Message-----
>> From: Yang Zhang [mailto:yang.zhang.wz@gmail.com]
>> Sent: Friday, May 20, 2016 3:51 PM
>> To: Paolo Bonzini <pbonzini@redhat.com>; rkrcmar@redhat.com; Wu, Feng
>> <feng.wu@intel.com>
>> Cc: kvm@vger.kernel.org
>> Subject: [PATCH] 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.
>
> 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.

>
> Thanks,
> feng
>
>>
>> Signed-off-by: Yang Zhang <yang.zhang.wz@gmail.com>
>> Signed-off-by: Shengge Ding <shengge.dsg@alibaba-inc.com>
>> ---
>>   arch/x86/kvm/vmx.c | 15 ++++++++++-----
>>   1 file changed, 10 insertions(+), 5 deletions(-)
>>
>> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
>> index 7ebf27b..8ba87f3 100644
>> --- a/arch/x86/kvm/vmx.c
>> +++ b/arch/x86/kvm/vmx.c
>> @@ -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);
>> --
>> 1.8.2.1


-- 
best regards
yang

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] KVM: VMX: check apicv is active before using VT-d posted interrupt
  2016-05-20  7:50 [PATCH] KVM: VMX: check apicv is active before using VT-d posted interrupt Yang Zhang
  2016-05-20  8:22 ` Wu, Feng
@ 2016-05-23 14:23 ` Paolo Bonzini
  2016-05-24  1:26   ` Yang Zhang
  1 sibling, 1 reply; 5+ messages in thread
From: Paolo Bonzini @ 2016-05-23 14:23 UTC (permalink / raw)
  To: Yang Zhang, rkrcmar, Feng Wu; +Cc: kvm

On 20/05/2016 09:50, Yang Zhang wrote:
> 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 <yang.zhang.wz@gmail.com>
> Signed-off-by: Shengge Ding <shengge.dsg@alibaba-inc.com>

Please resend this patch without format=flowed (just use
git-send-email), as it cannot be applied otherwise.

Thanks,

Paolo

> ---
>  arch/x86/kvm/vmx.c | 15 ++++++++++-----
>  1 file changed, 10 insertions(+), 5 deletions(-)
> 
> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> index 7ebf27b..8ba87f3 100644
> --- a/arch/x86/kvm/vmx.c
> +++ b/arch/x86/kvm/vmx.c
> @@ -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);

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] KVM: VMX: check apicv is active before using VT-d posted interrupt
  2016-05-23 14:23 ` Paolo Bonzini
@ 2016-05-24  1:26   ` Yang Zhang
  0 siblings, 0 replies; 5+ messages in thread
From: Yang Zhang @ 2016-05-24  1:26 UTC (permalink / raw)
  To: Paolo Bonzini, rkrcmar, Feng Wu; +Cc: kvm

On 2016/5/23 22:23, Paolo Bonzini wrote:
> On 20/05/2016 09:50, Yang Zhang wrote:
>> 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 <yang.zhang.wz@gmail.com>
>> Signed-off-by: Shengge Ding <shengge.dsg@alibaba-inc.com>
>
> 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.

>
> Thanks,
>
> Paolo
>
>> ---
>>  arch/x86/kvm/vmx.c | 15 ++++++++++-----
>>  1 file changed, 10 insertions(+), 5 deletions(-)
>>
>> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
>> index 7ebf27b..8ba87f3 100644
>> --- a/arch/x86/kvm/vmx.c
>> +++ b/arch/x86/kvm/vmx.c
>> @@ -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);


-- 
best regards
yang

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-05-24  1:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-20  7:50 [PATCH] KVM: VMX: check apicv is active before using VT-d posted interrupt Yang Zhang
2016-05-20  8:22 ` Wu, Feng
2016-05-23  1:10   ` Yang Zhang
2016-05-23 14:23 ` Paolo Bonzini
2016-05-24  1:26   ` Yang Zhang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.