Skip to contentSkip to conversation

VMX: Properly handle pi descriptor and per-cpu blocking list

PATCH Superseded Feng Wu 2 participants 22 messages Oct 28, 2016 – Nov 3, 2016

v6 of 8 Superseded Latest is v8 →

lore
Share & tools
lore

Feng Wu

author
#0 lore raw

v6 cover VMX: Properly handle pi descriptor and per-cpu blocking list

The current VT-d PI related code may operate incorrectly in the following scenarios:
1. When the last assigned device is dettached from the domain, all the PI related hooks are removed then, however, the vCPU can be blocked, switched to another pCPU, etc, all without the aware of PI. After the next time we attach another device to the domain, which makes the PI realted hooks avaliable again, the status of the pi descriptor is not true. Beside that, the blocking vcpu may still remain in the per-cpu blocking in this case. Patch [1/7] and [2/7] handle this.

2. After the domain is destroyed, the the blocking vcpu may also remain in the per-cpu blocking. Handled in patch [3/7].

3. When IRTE is in posted mode, we don't need to set the irq affinity for it, since the destination of these interrupts is vCPU and the vCPU affinity is set during vCPU scheduling. Patch [5/7] handles this.

4. [6/7] is a cleanup patch

5. When a pCPU is unplugged, and there might be vCPUs on its list. Since the pCPU is offline, those vCPUs might not be woken up again. [7/7] addresses it.

Feng Wu (7):
VMX: Permanently assign PI hook vmx_pi_switch_to()
VMX: Properly handle pi when all the assigned devices are removed
VMX: Cleanup PI per-cpu blocking list when vcpu is destroyed
VMX: Make sure PI is in proper state before install the hooks
VT-d: No need to set irq affinity for posted format IRTE
VT-d: Some cleanups
VMX: Fixup PI descriptor when cpu is offline

 xen/arch/x86/hvm/vmx/vmcs.c            |  14 ++--
 xen/arch/x86/hvm/vmx/vmx.c             | 135 +++++++++++++++++++++++++++++++--
 xen/drivers/passthrough/vtd/intremap.c |  74 +++++++++++++++---
 xen/include/asm-x86/hvm/vmx/vmx.h      |   3 +
 4 files changed, 202 insertions(+), 24 deletions(-)
Signature · 7 lines
2.1.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
author
#1 lore raw

PATCH v6 1/7 VMX: Permanently assign PI hook vmx_pi_switch_to()

PI hook vmx_pi_switch_to() is needed even when any previously assigned device is detached from the domain. Since 'SN' bit is also used to control the CPU side PI and we change the state of SN bit in these two functions, then evaluate this bit in vmx_deliver_posted_intr() when trying to deliver the interrupt in posted way via software. The problem is if we deassign the hooks while the vCPU is runnable in the runqueue with 'SN' set, all the furture notificaton event will be suppressed. This patch makes these two hooks statically assigned.

---
v6:
- Adjust the comments and wording.

v5:
- Zap "pi_switch_from" hook

v4:
- Don't zap vmx_pi_switch_from() and vmx_pi_switch_to() when any previously assigned device is detached from the domain.
- Comments changes.

 xen/arch/x86/hvm/vmx/vmx.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
xen/arch/x86/hvm/vmx/vmx.c +7 -2
index 3d330b6..faaa987 100644
@@ -221,9 +221,14 @@ void vmx_pi_hooks_deassign(struct domain *d)
     ASSERT(d->arch.hvm_domain.vmx.vcpu_block);
 
     d->arch.hvm_domain.vmx.vcpu_block = NULL;
-    d->arch.hvm_domain.vmx.pi_switch_from = NULL;
-    d->arch.hvm_domain.vmx.pi_switch_to = NULL;
     d->arch.hvm_domain.vmx.pi_do_resume = NULL;
+    d->arch.hvm_domain.vmx.pi_switch_from = NULL;
+
+    /*
+     * In fact, we can remove 'vmx_pi_switch_to' inside itself if no new device
+     * is in the process of getting assigned and "from" hook is NULL. However,
+     * it is not straightforward to find a clear solution, so just leave it here.
+     */
 }
 
 static int vmx_domain_initialise(struct domain *d)
Signature · 7 lines
2.1.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#2 lore raw

Re: [PATCH v6 1/7] VMX: Permanently assign PI hook vmx_pi_switch_to()

Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 28.10.16 at 04:37, <[email protected]> wrote:

PI hook vmx_pi_switch_to() is needed even when any previously assigned device is detached from the domain. Since 'SN' bit is also used to control the CPU side PI and we change the state of SN bit in these two functions,

There's just one function you've mentioned up to here.

xen/arch/x86/hvm/vmx/vmx.c void vmx_pi_hooks_deassign(struct domain *d) · line 225

Quoted 8 lines
xen/arch/x86/hvm/vmx/vmx.c +0 -2
@@ -221,9 +221,14 @@ void vmx_pi_hooks_deassign(struct domain *d)
     ASSERT(d->arch.hvm_domain.vmx.vcpu_block);
 
     d->arch.hvm_domain.vmx.vcpu_block = NULL;
-    d->arch.hvm_domain.vmx.pi_switch_from = NULL;
-    d->arch.hvm_domain.vmx.pi_switch_to = NULL;

And with the commit message as it is right now, it is completely unclear why the from hook also gets zapped. In fact, with the description pointing out a problem with just the SN=1 case, I don't see what you need the from hook for without devices assigned, as that's where SN gets set (and you want to avoid that).

xen/arch/x86/hvm/vmx/vmx.c void vmx_pi_hooks_deassign(struct domain *d) · line 228

Quoted 5 lines
xen/arch/x86/hvm/vmx/vmx.c +4 -0
     d->arch.hvm_domain.vmx.pi_do_resume = NULL;
+    d->arch.hvm_domain.vmx.pi_switch_from = NULL;
+
+    /*
+     * In fact, we can remove 'vmx_pi_switch_to' inside itself if no new device

s/can/could/

xen/arch/x86/hvm/vmx/vmx.c void vmx_pi_hooks_deassign(struct domain *d) · line 234

Quoted 6 lines
xen/arch/x86/hvm/vmx/vmx.c +3 -0
+     * is in the process of getting assigned and "from" hook is NULL. However,
+     * it is not straightforward to find a clear solution, so just leave it here.
+     */
 }
 
 static int vmx_domain_initialise(struct domain *d)

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#3 lore raw

Re: [PATCH v6 1/7] VMX: Permanently assign PI hook vmx_pi_switch_to()

Quoted 7 lines
Quoted 7 lines
Quoted 2 lines · On 28.10.16 at 15:04, <[email protected]> wrote:
Quoted 1 line · On 28.10.16 at 04:37, <[email protected]> wrote:
xen/arch/x86/hvm/vmx/vmx.c +0 -0
@@ -221,9 +221,14 @@ void vmx_pi_hooks_deassign(struct domain *d)
     ASSERT(d->arch.hvm_domain.vmx.vcpu_block);
 
Quoted 13 lines

xen/arch/x86/hvm/vmx/vmx.c void vmx_pi_hooks_deassign(struct domain *d) · line 225

Quoted 3 lines
xen/arch/x86/hvm/vmx/vmx.c +0 -2
     d->arch.hvm_domain.vmx.vcpu_block = NULL;
-    d->arch.hvm_domain.vmx.pi_switch_from = NULL;
-    d->arch.hvm_domain.vmx.pi_switch_to = NULL;

And with the commit message as it is right now, it is completely unclear why the from hook also gets zapped. In fact, with the description pointing out a problem with just the SN=1 case, I don't see what you need the from hook for without devices assigned, as that's where SN gets set (and you want to avoid that).

Quoted 2 lines
xen/arch/x86/hvm/vmx/vmx.c +1 -0
     d->arch.hvm_domain.vmx.pi_do_resume = NULL;
+    d->arch.hvm_domain.vmx.pi_switch_from = NULL;

Oh, I'm sorry - I paid attention only to the lines getting removed above, not the one line getting re-inserted here. That addresses my comment, of course; I just can't see why the line needs to be moved.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

author
#4 lore raw

Re: [PATCH v6 1/7] VMX: Permanently assign PI hook vmx_pi_switch_to()

Quoted 30 lines

-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: Friday, October 28, 2016 9:18 PM
To: Wu, Feng <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; Tian, Kevin <[email protected]>; xen- [email protected]
Subject: Re: [Xen-devel] [PATCH v6 1/7] VMX: Permanently assign PI hook vmx_pi_switch_to()

Quoted 18 lines

xen/arch/x86/hvm/vmx/vmx.c void vmx_pi_hooks_deassign(struct domain *d) · line 225

Quoted 10 lines
Quoted 2 lines · On 28.10.16 at 15:04, <[email protected]> wrote:
Quoted 1 line · On 28.10.16 at 04:37, <[email protected]> wrote:
xen/arch/x86/hvm/vmx/vmx.c +0 -2
@@ -221,9 +221,14 @@ void vmx_pi_hooks_deassign(struct domain *d)
     ASSERT(d->arch.hvm_domain.vmx.vcpu_block);
 
     d->arch.hvm_domain.vmx.vcpu_block = NULL;
-    d->arch.hvm_domain.vmx.pi_switch_from = NULL;
-    d->arch.hvm_domain.vmx.pi_switch_to = NULL;

And with the commit message as it is right now, it is completely unclear why the from hook also gets zapped. In fact, with the description pointing out a problem with just the SN=1 case, I don't see what you need the from hook for without devices assigned, as that's where SN gets set (and you want to avoid that).

Quoted 7 lines
Quoted 2 lines

xen/arch/x86/hvm/vmx/vmx.c void vmx_pi_hooks_deassign(struct domain *d) · line 225

Quoted 2 lines
xen/arch/x86/hvm/vmx/vmx.c +1 -0
     d->arch.hvm_domain.vmx.pi_do_resume = NULL;
+    d->arch.hvm_domain.vmx.pi_switch_from = NULL;

Oh, I'm sorry - I paid attention only to the lines getting removed above, not the one line getting re-inserted here. That addresses my comment, of course; I just can't see why the line needs to be moved.

Yes, we could just reuse the original line. Thanks!

Thanks,
Feng

Quoted 2 lines

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

author
#5 lore raw

PATCH v6 2/7 VMX: Properly handle pi when all the assigned devices are removed

In reply to Feng Wu

This patch handles some corner cases when the last assigned device is removed from the domain. In this case we should carefully handle pi descriptor and the per-cpu blocking list, to make sure:
- all the PI descriptor are in the right state when next time a devices is assigned to the domain again.
- No remaining vcpus of the domain in the per-cpu blocking list.

Here we call vmx_pi_list_remove() to remove the vCPU from the blocking list if it is on the list. However, this could happen when vmx_vcpu_block() is being called, hence we might incorrectly add the vCPU to the blocking list while the last devcie is detached from the domain. Consider that the situation can only occur when detaching the last device from the domain and it is not a frequent operation, so we use domain_pause before that, which is considered as an clean and maintainable solution for the situation.

---
v6:
- Comments changes
- Rename vmx_pi_list_remove() to vmx_pi_unblock_vcpu()

v5:
- Remove a no-op wrapper

v4:
- Rename some functions:

	vmx_pi_remove_vcpu_from_blocking_list() -> vmx_pi_list_remove()
	vmx_pi_blocking_cleanup() -> vmx_pi_list_cleanup()

- Remove the check in vmx_pi_list_cleanup()
- Comments adjustment

 xen/arch/x86/hvm/vmx/vmx.c | 28 ++++++++++++++++++++++++----
 1 file changed, 24 insertions(+), 4 deletions(-)
xen/arch/x86/hvm/vmx/vmx.c +24 -4
index faaa987..508be7c 100644
@@ -158,14 +158,12 @@ static void vmx_pi_switch_to(struct vcpu *v)
     pi_clear_sn(pi_desc);
 }
 
-static void vmx_pi_do_resume(struct vcpu *v)
+static void vmx_pi_unblock_vcpu(struct vcpu *v)
 {
     unsigned long flags;
     spinlock_t *pi_blocking_list_lock;
     struct pi_desc *pi_desc = &v->arch.hvm_vmx.pi_desc;
 
-    ASSERT(!test_bit(_VPF_blocked, &v->pause_flags));
-
     /*
      * Set 'NV' field back to posted_intr_vector, so the
      * Posted-Interrupts can be delivered to the vCPU when
@@ -173,12 +171,12 @@ static void vmx_pi_do_resume(struct vcpu *v)
      */
     write_atomic(&pi_desc->nv, posted_intr_vector);
 
-    /* The vCPU is not on any blocking list. */
     pi_blocking_list_lock = v->arch.hvm_vmx.pi_blocking.lock;
 
     /* Prevent the compiler from eliminating the local variable.*/
     smp_rmb();
 
+    /* The vCPU is not on any blocking list. */
     if ( pi_blocking_list_lock == NULL )
         return;
 
@@ -198,6 +196,13 @@ static void vmx_pi_do_resume(struct vcpu *v)
     spin_unlock_irqrestore(pi_blocking_list_lock, flags);
 }
 
+static void vmx_pi_do_resume(struct vcpu *v)
+{
+    ASSERT(!test_bit(_VPF_blocked, &v->pause_flags));
+
+    vmx_pi_unblock_vcpu(v);
+}
+
 /* This function is called when pcidevs_lock is held */
 void vmx_pi_hooks_assign(struct domain *d)
 {
@@ -215,11 +220,21 @@ void vmx_pi_hooks_assign(struct domain *d)
 /* This function is called when pcidevs_lock is held */
 void vmx_pi_hooks_deassign(struct domain *d)
 {
+    struct vcpu *v;
+
     if ( !iommu_intpost || !has_hvm_container_domain(d) )
         return;
 
     ASSERT(d->arch.hvm_domain.vmx.vcpu_block);
 
+    /*
+     * Pausing the domain can make sure the vCPU is not
+     * running and hence not calling the hooks simultaneously
+     * when deassigning the PI hooks and removing the vCPU
+     * from the blocking list.
+     */
+    domain_pause(d);
+
     d->arch.hvm_domain.vmx.vcpu_block = NULL;
     d->arch.hvm_domain.vmx.pi_do_resume = NULL;
     d->arch.hvm_domain.vmx.pi_switch_from = NULL;
@@ -229,6 +244,11 @@ void vmx_pi_hooks_deassign(struct domain *d)
      * is in the process of getting assigned and "from" hook is NULL. However,
      * it is not straightforward to find a clear solution, so just leave it here.
      */
+
+    for_each_vcpu ( d, v )
+        vmx_pi_unblock_vcpu(v);
+
+    domain_unpause(d);
 }
 
 static int vmx_domain_initialise(struct domain *d)
Signature · 7 lines
2.1.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#6 lore raw

Re: [PATCH v6 2/7] VMX: Properly handle pi when all the assigned devices are removed

Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 28.10.16 at 04:37, <[email protected]> wrote:
xen/arch/x86/hvm/vmx/vmx.c +2 -0
@@ -215,11 +220,21 @@ void vmx_pi_hooks_assign(struct domain *d)
 /* This function is called when pcidevs_lock is held */
 void vmx_pi_hooks_deassign(struct domain *d)
 {
+    struct vcpu *v;
+
     if ( !iommu_intpost || !has_hvm_container_domain(d) )
         return;

xen/arch/x86/hvm/vmx/vmx.c void vmx_pi_hooks_assign(struct domain *d) · line 236

Quoted 10 lines
xen/arch/x86/hvm/vmx/vmx.c +7 -0
 
     ASSERT(d->arch.hvm_domain.vmx.vcpu_block);
 
+    /*
+     * Pausing the domain can make sure the vCPU is not
+     * running and hence not calling the hooks simultaneously
+     * when deassigning the PI hooks and removing the vCPU
+     * from the blocking list.
+     */
+    domain_pause(d);

There's one additional caveat here which no-one of us so far thought
of: Currently there's nothing preventing the domctl-s under which this sits from being issued by the control domain for itself. Various other domctl-s, however, guard against this case when intending to pause the target domain. The same needs to be done for the ones leading here.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

author
#7 lore raw

Re: [PATCH v6 2/7] VMX: Properly handle pi when all the assigned devices are removed

Quoted 24 lines

-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: Friday, October 28, 2016 9:19 PM
To: Wu, Feng <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; Tian, Kevin <[email protected]>; xen- [email protected]
Subject: Re: [PATCH v6 2/7] VMX: Properly handle pi when all the assigned devices are removed

Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 28.10.16 at 04:37, <[email protected]> wrote:
xen/arch/x86/hvm/vmx/vmx.c +2 -0
@@ -215,11 +220,21 @@ void vmx_pi_hooks_assign(struct domain *d)
 /* This function is called when pcidevs_lock is held */
 void vmx_pi_hooks_deassign(struct domain *d)
 {
+    struct vcpu *v;
+
     if ( !iommu_intpost || !has_hvm_container_domain(d) )
         return;
 
     ASSERT(d->arch.hvm_domain.vmx.vcpu_block);
 
Quoted 14 lines

xen/arch/x86/hvm/vmx/vmx.c void vmx_pi_hooks_assign(struct domain *d) · line 236

Quoted 7 lines
xen/arch/x86/hvm/vmx/vmx.c +7 -0
+    /*
+     * Pausing the domain can make sure the vCPU is not
+     * running and hence not calling the hooks simultaneously
+     * when deassigning the PI hooks and removing the vCPU
+     * from the blocking list.
+     */
+    domain_pause(d);

There's one additional caveat here which no-one of us so far thought
of: Currently there's nothing preventing the domctl-s under which this sits from being issued by the control domain for itself. Various other domctl-s, however, guard against this case when intending to pause the target domain. The same needs to be done for the ones leading here.

Thanks for the comments! Could you share in which case can a domain attach/detach a device for itself? Thanks!

Thanks,
Feng

Quoted 2 lines

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#8 lore raw

Re: [PATCH v6 2/7] VMX: Properly handle pi when all the assigned devices are removed

Quoted 40 lines
Quoted 25 lines
Quoted 1 line · On 03.11.16 at 08:45, <[email protected]> wrote:

-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: Friday, October 28, 2016 9:19 PM
To: Wu, Feng <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; Tian, Kevin <[email protected]>; xen- [email protected]
Subject: Re: [PATCH v6 2/7] VMX: Properly handle pi when all the assigned devices are removed

Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 28.10.16 at 04:37, <[email protected]> wrote:
xen/arch/x86/hvm/vmx/vmx.c +2 -0
@@ -215,11 +220,21 @@ void vmx_pi_hooks_assign(struct domain *d)
 /* This function is called when pcidevs_lock is held */
 void vmx_pi_hooks_deassign(struct domain *d)
 {
+    struct vcpu *v;
+
     if ( !iommu_intpost || !has_hvm_container_domain(d) )
         return;
 
     ASSERT(d->arch.hvm_domain.vmx.vcpu_block);
 
Quoted 14 lines

xen/arch/x86/hvm/vmx/vmx.c void vmx_pi_hooks_assign(struct domain *d) · line 236

Quoted 7 lines
xen/arch/x86/hvm/vmx/vmx.c +7 -0
+    /*
+     * Pausing the domain can make sure the vCPU is not
+     * running and hence not calling the hooks simultaneously
+     * when deassigning the PI hooks and removing the vCPU
+     * from the blocking list.
+     */
+    domain_pause(d);

There's one additional caveat here which no-one of us so far thought
of: Currently there's nothing preventing the domctl-s under which this sits from being issued by the control domain for itself. Various other domctl-s, however, guard against this case when intending to pause the target domain. The same needs to be done for the ones leading here.

Quoted 2 lines

Thanks for the comments! Could you share in which case can a domain attach/detach a device for itself? Thanks!

That's not the question. The code path needs to be safe, just like all others (which we also expect Dom0 - or any other eligible domain
- to not use with itself as the target domain).

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

author
#9 lore raw

Re: [PATCH v6 2/7] VMX: Properly handle pi when all the assigned devices are removed

Quoted 52 lines

-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: Thursday, November 3, 2016 5:08 PM
To: Wu, Feng <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; Tian, Kevin <[email protected]>; xen- [email protected]
Subject: RE: [PATCH v6 2/7] VMX: Properly handle pi when all the assigned devices are removed

Quoted 40 lines
Quoted 39 lines
Quoted 1 line · On 03.11.16 at 08:45, <[email protected]> wrote:

-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: Friday, October 28, 2016 9:19 PM
To: Wu, Feng <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; Tian, Kevin <[email protected]>; xen- [email protected]
Subject: Re: [PATCH v6 2/7] VMX: Properly handle pi when all the assigned devices are removed

Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 28.10.16 at 04:37, <[email protected]> wrote:
xen/arch/x86/hvm/vmx/vmx.c +2 -0
@@ -215,11 +220,21 @@ void vmx_pi_hooks_assign(struct domain *d)
 /* This function is called when pcidevs_lock is held */
 void vmx_pi_hooks_deassign(struct domain *d)
 {
+    struct vcpu *v;
+
     if ( !iommu_intpost || !has_hvm_container_domain(d) )
         return;

xen/arch/x86/hvm/vmx/vmx.c void vmx_pi_hooks_assign(struct domain *d) · line 236

Quoted 10 lines
xen/arch/x86/hvm/vmx/vmx.c +7 -0
 
     ASSERT(d->arch.hvm_domain.vmx.vcpu_block);
 
+    /*
+     * Pausing the domain can make sure the vCPU is not
+     * running and hence not calling the hooks simultaneously
+     * when deassigning the PI hooks and removing the vCPU
+     * from the blocking list.
+     */
+    domain_pause(d);

There's one additional caveat here which no-one of us so far thought
of: Currently there's nothing preventing the domctl-s under which this sits from being issued by the control domain for itself. Various other domctl-s, however, guard against this case when intending to pause the target domain. The same needs to be done for the ones leading here.

Quoted 6 lines
Quoted 2 lines

Thanks for the comments! Could you share in which case can a domain attach/detach a device for itself? Thanks!

That's not the question. The code path needs to be safe, just like all others (which we also expect Dom0 - or any other eligible domain
- to not use with itself as the target domain).

Sure, got it!

Thanks,
Feng

Quoted 2 lines

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

author
#10 lore raw

PATCH v6 3/7 VMX: Cleanup PI per-cpu blocking list when vcpu is destroyed

In reply to Feng Wu

We should remove the vCPU from the per-cpu blocking list if it is going to be destroyed.

---
v6:
- Use vmx_pi_unblock_vcpu() instead of vmx_pi_list_remove()

v5:
- Use vmx_pi_list_remove() instead of vmx_pi_list_cleanup()

v4:
- Call vmx_pi_list_cleanup() before vmx_destroy_vmcs()

 xen/arch/x86/hvm/vmx/vmx.c | 1 +
 1 file changed, 1 insertion(+)
xen/arch/x86/hvm/vmx/vmx.c +1 -0
index 508be7c..eb4770c 100644
@@ -338,6 +338,7 @@ static void vmx_vcpu_destroy(struct vcpu *v)
      * separately here.
      */
     vmx_vcpu_disable_pml(v);
+    vmx_pi_unblock_vcpu(v);
     vmx_destroy_vmcs(v);
     vpmu_destroy(v);
     passive_domain_destroy(v);
Signature · 7 lines
2.1.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#11 lore raw

Re: [PATCH v6 3/7] VMX: Cleanup PI per-cpu blocking list when vcpu is destroyed

Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 28.10.16 at 04:37, <[email protected]> wrote:

We should remove the vCPU from the per-cpu blocking list if it is going to be destroyed.

I think I did raise this question at least once before: Why can it still be on the list in the first place, after patch 2? This is even more odd with ...

xen/arch/x86/hvm/vmx/vmx.c static void vmx_vcpu_destroy(struct vcpu *v) · line 341

Quoted 7 lines
xen/arch/x86/hvm/vmx/vmx.c +1 -0
@@ -338,6 +338,7 @@ static void vmx_vcpu_destroy(struct vcpu *v)
      * separately here.
      */
     vmx_vcpu_disable_pml(v);
+    vmx_pi_unblock_vcpu(v);

... the renamed function: A vCPU being destroyed can hardly get unblocked.

If the apparently proper solution (removing devices from a domain before destroying its vCPU-s) is not possible or feasible for some reason, then the commit message should say so (and explain why).

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

author
#12 lore raw

PATCH v6 4/7 VMX: Make sure PI is in proper state before install the hooks

In reply to Feng Wu

We may hit the last ASSERT() in vmx_vcpu_block in the current code, since vmx_vcpu_block() may get called before vmx_pi_switch_to() has been installed or executed. Here We use cmpxchg to update the NDST field, this can make sure we only update the NDST when vmx_pi_switch_to() has not been called. So the NDST is in a proper state in vmx_vcpu_block().

---
v6:
- Comments changes
- Define macro 'APIC_INVALID_DEST' for '0xffffffff'

v5:
- Use 0xffffffff as the invalid value for NDST field.

v4:
- This patch is previously called "Pause/Unpause the domain before/after assigning PI hooks"
- Remove the pause/unpause method
- Use cmpxchg to update NDST

 xen/arch/x86/hvm/vmx/vmcs.c       | 13 +++++--------
 xen/arch/x86/hvm/vmx/vmx.c        | 27 ++++++++++++++++++++++++++-
 xen/include/asm-x86/hvm/vmx/vmx.h |  2 ++
 3 files changed, 33 insertions(+), 9 deletions(-)
xen/arch/x86/hvm/vmx/vmcs.c +5 -8
index 1bd875a..e8e3616 100644
@@ -956,16 +956,13 @@ void virtual_vmcs_vmwrite(const struct vcpu *v, u32 vmcs_encoding, u64 val)
  */
 static void pi_desc_init(struct vcpu *v)
 {
-    uint32_t dest;
-
     v->arch.hvm_vmx.pi_desc.nv = posted_intr_vector;
 
-    dest = cpu_physical_id(v->processor);
-
-    if ( x2apic_enabled )
-        v->arch.hvm_vmx.pi_desc.ndst = dest;
-    else
-        v->arch.hvm_vmx.pi_desc.ndst = MASK_INSR(dest, PI_xAPIC_NDST_MASK);
+    /*
+     * Mark NDST as invalid, then we can use this invalid value as a
+     * marker to whether update NDST or not in vmx_pi_hooks_assign().
+     */
+    v->arch.hvm_vmx.pi_desc.ndst = APIC_INVALID_DEST;
 }
 
 static int construct_vmcs(struct vcpu *v)
xen/arch/x86/hvm/vmx/vmx.c +26 -1
index eb4770c..58694ce 100644
@@ -206,14 +206,39 @@ static void vmx_pi_do_resume(struct vcpu *v)
 /* This function is called when pcidevs_lock is held */
 void vmx_pi_hooks_assign(struct domain *d)
 {
+    struct vcpu *v;
+
     if ( !iommu_intpost || !has_hvm_container_domain(d) )
         return;
 
     ASSERT(!d->arch.hvm_domain.vmx.vcpu_block);
 
-    d->arch.hvm_domain.vmx.vcpu_block = vmx_vcpu_block;
+    /*
+     * We carefully handle the timing here:
+     * - Install the context switch first
+     * - Then set the NDST field
+     * - Install the block and resume hooks in the end
+     *
+     * This can make sure the PI (especially the NDST feild) is
+     * in proper state when we call vmx_vcpu_block().
+     */
     d->arch.hvm_domain.vmx.pi_switch_from = vmx_pi_switch_from;
     d->arch.hvm_domain.vmx.pi_switch_to = vmx_pi_switch_to;
+
+    for_each_vcpu ( d, v )
+    {
+        unsigned int dest = cpu_physical_id(v->processor);
+        struct pi_desc *pi_desc = &v->arch.hvm_vmx.pi_desc;
+
+        /*
+         * We don't need to update NDST if vmx_pi_switch_to()
+         * has already got called.
+         */
+        (void)cmpxchg(&pi_desc->ndst, APIC_INVALID_DEST,
+                x2apic_enabled ? dest : MASK_INSR(dest, PI_xAPIC_NDST_MASK));
+    }
+
+    d->arch.hvm_domain.vmx.vcpu_block = vmx_vcpu_block;
     d->arch.hvm_domain.vmx.pi_do_resume = vmx_pi_do_resume;
 }
 
xen/include/asm-x86/hvm/vmx/vmx.h +2 -0
index 4cdd9b1..2f0435c 100644
@@ -573,6 +573,8 @@ void vmx_pi_per_cpu_init(unsigned int cpu);
 void vmx_pi_hooks_assign(struct domain *d);
 void vmx_pi_hooks_deassign(struct domain *d);
 
+#define APIC_INVALID_DEST           0xffffffff
+
 /* EPT violation qualifications definitions */
 #define _EPT_READ_VIOLATION         0
 #define EPT_READ_VIOLATION          (1UL<<_EPT_READ_VIOLATION)
Signature · 7 lines
2.1.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Reviewed-by on v6 4/7
#13 lore raw

Re: [PATCH v6 4/7] VMX: Make sure PI is in proper state before install the hooks

Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 28.10.16 at 04:37, <[email protected]> wrote:

We may hit the last ASSERT() in vmx_vcpu_block in the current code, since vmx_vcpu_block() may get called before vmx_pi_switch_to() has been installed or executed. Here We use cmpxchg to update the NDST field, this can make sure we only update the NDST when vmx_pi_switch_to() has not been called. So the NDST is in a proper state in vmx_vcpu_block().

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

author
#14 lore raw

PATCH v6 5/7 VT-d: No need to set irq affinity for posted format IRTE

In reply to Feng Wu

We don't set the affinity for posted format IRTE, since the destination of these interrupts is vCPU and the vCPU affinity is set during vCPU scheduling.

---
v6:
- Make pi_can_suppress_irte_update() a check-only function
- Introduce another function pi_get_new_irte() to update the 'new_ire' if needed

v5:
- Only suppress affinity related IRTE updates for PI

v4:
- Keep the construction of new_ire and only modify the hardware IRTE when it is not in posted mode.

 xen/drivers/passthrough/vtd/intremap.c | 61 ++++++++++++++++++++++++++++++++--
 1 file changed, 58 insertions(+), 3 deletions(-)
xen/drivers/passthrough/vtd/intremap.c +58 -3
index bfd468b..97e80a6 100644
@@ -547,6 +547,54 @@ static int remap_entry_to_msi_msg(
     return 0;
 }
 
+static bool pi_can_suppress_irte_update(const struct iremap_entry *new,
+    const struct iremap_entry *old)
+{
+    ASSERT( old && new );
+
+    if ( !old->remap.p || !old->remap.im || !new->remap.p || new->remap.im )
+        return false;
+
+    /*
+     * We are updating posted IRTE to remapped one, check whether
+     * the common fields are going to be changed.
+     */
+    if ( ( new->remap.fpd != old->post.fpd ) ||
+         ( new->remap.sid != old->post.sid ) ||
+         ( new->remap.sq != old->post.sq ) ||
+         ( new->remap.svt != old->post.svt ) )
+        return false;
+
+    return true;
+}
+
+static void pi_get_new_irte(struct iremap_entry *new,
+    const struct iremap_entry *old)
+{
+    u16 fpd, sid, sq, svt;
+
+    ASSERT( old && new );
+
+    fpd = new->remap.fpd;
+    sid = new->remap.sid;
+    sq = new->remap.sq;
+    svt = new->remap.svt;
+
+    *new = *old;
+
+    if ( fpd != old->post.fpd )
+        new->post.fpd = fpd;
+
+    if ( sid != old->post.sid )
+        new->post.sid = sid;
+
+    if ( sq != old->post.sq )
+        new->post.sq = sq;
+
+    if ( svt != old->post.svt )
+        new->post.svt = svt;
+}
+
 static int msi_msg_to_remap_entry(
     struct iommu *iommu, struct pci_dev *pdev,
     struct msi_desc *msi_desc, struct msi_msg *msg)
@@ -637,9 +685,16 @@ static int msi_msg_to_remap_entry(
     remap_rte->address_hi = 0;
     remap_rte->data = index - i;
 
-    memcpy(iremap_entry, &new_ire, sizeof(struct iremap_entry));
-    iommu_flush_cache_entry(iremap_entry, sizeof(struct iremap_entry));
-    iommu_flush_iec_index(iommu, 0, index);
+    if ( !pi_can_suppress_irte_update(&new_ire, iremap_entry) )
+    {
+        if ( iremap_entry->remap.p && iremap_entry->remap.im &&
+             new_ire.remap.p && !new_ire.remap.im )
+            pi_get_new_irte(&new_ire, iremap_entry);
+
+        memcpy(iremap_entry, &new_ire, sizeof(struct iremap_entry));
+        iommu_flush_cache_entry(iremap_entry, sizeof(struct iremap_entry));
+        iommu_flush_iec_index(iommu, 0, index);
+    }
 
     unmap_vtd_domain_page(iremap_entries);
     spin_unlock_irqrestore(&ir_ctrl->iremap_lock, flags);
Signature · 7 lines
2.1.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#15 lore raw

Re: [PATCH v6 5/7] VT-d: No need to set irq affinity for posted format IRTE

Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 28.10.16 at 04:37, <[email protected]> wrote:

v6:
- Make pi_can_suppress_irte_update() a check-only function
- Introduce another function pi_get_new_irte() to update the 'new_ire' if needed

I don't see what you need this function for. My earlier comments were not meant to make you split the function, but to drop all this secondary modification (unless there's actually a reason for this, which so far I haven't seen any proof of). Apart from that there already is setup_posted_irte(), which seems to do most if not all of what you really need.

In any event, the sequence of operations should be
1) create full new entry
2) check whether update is needed (i.e. whether old and new entries have meaningful differences)
3) do update
4) flush.

xen/drivers/passthrough/vtd/intremap.c static int remap_entry_to_msi_msg( · line 551

Quoted 8 lines
xen/drivers/passthrough/vtd/intremap.c +2 -0
@@ -547,6 +547,54 @@ static int remap_entry_to_msi_msg(
     return 0;
 }
 
+static bool pi_can_suppress_irte_update(const struct iremap_entry *new,
+    const struct iremap_entry *old)

The two parameter declarations should be aligned with one another.

xen/drivers/passthrough/vtd/intremap.c static int remap_entry_to_msi_msg( · line 556

Quoted 5 lines
xen/drivers/passthrough/vtd/intremap.c +5 -0
+{
+    ASSERT( old && new );
+
+    if ( !old->remap.p || !old->remap.im || !new->remap.p || new->remap.im )
+        return false;

The asymmetry regarding the IM bit is confusing, and imo indicates a problem with the logic.

xen/drivers/passthrough/vtd/intremap.c static int remap_entry_to_msi_msg( · line 565

Quoted 8 lines
xen/drivers/passthrough/vtd/intremap.c +8 -0
+    /*
+     * We are updating posted IRTE to remapped one, check whether
+     * the common fields are going to be changed.
+     */
+    if ( ( new->remap.fpd != old->post.fpd ) ||
+         ( new->remap.sid != old->post.sid ) ||
+         ( new->remap.sq != old->post.sq ) ||
+         ( new->remap.svt != old->post.svt ) )

Stray blanks inside the inner parentheses.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

author
#16 lore raw

Re: [PATCH v6 5/7] VT-d: No need to set irq affinity for posted format IRTE

Quoted 25 lines

-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: Monday, October 31, 2016 10:57 PM
To: Wu, Feng <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; Tian, Kevin <[email protected]>; xen- [email protected]
Subject: Re: [PATCH v6 5/7] VT-d: No need to set irq affinity for posted format IRTE

Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 28.10.16 at 04:37, <[email protected]> wrote:

v6:
- Make pi_can_suppress_irte_update() a check-only function
- Introduce another function pi_get_new_irte() to update the 'new_ire' if needed

I don't see what you need this function for. My earlier comments were not meant to make you split the function, but to drop all this secondary modification (unless there's actually a reason for this, which so far I haven't seen any proof of). Apart from that there already is setup_posted_irte(), which seems to do most if not all of what you really need.

Quoted 6 lines

In any event, the sequence of operations should be
1) create full new entry
2) check whether update is needed (i.e. whether old and new entries have meaningful differences)
3) do update
4) flush.

Your early comment suggest we only suppress the affinity related field. So the modification here is to handle the following case:

When the IRTE is currently in posted mode and this function tries to update it he remapped mode, then we need to suppress the affinity related bit, however, if the common fields (fpd, sid sq, svt) in the new remapped IRTE is different from the value in the old posted IRTE, what do you suggest we should do? Here I copy these fields to the new IRTE and update them accordingly.

Quoted 12 lines

xen/drivers/passthrough/vtd/intremap.c static int remap_entry_to_msi_msg( · line 551

Quoted 9 lines
xen/drivers/passthrough/vtd/intremap.c +2 -0
@@ -547,6 +547,54 @@ static int remap_entry_to_msi_msg(
     return 0;
 }
 
+static bool pi_can_suppress_irte_update(const struct iremap_entry *new,
+    const struct iremap_entry *old)

The two parameter declarations should be aligned with one another.

Quoted 8 lines

xen/drivers/passthrough/vtd/intremap.c static int remap_entry_to_msi_msg( · line 556

Quoted 5 lines
xen/drivers/passthrough/vtd/intremap.c +5 -0
+{
+    ASSERT( old && new );
+
+    if ( !old->remap.p || !old->remap.im || !new->remap.p || new->remap.im )
+        return false;

The asymmetry regarding the IM bit is confusing, and imo indicates a problem with the logic.

Would you please share what the problem is here? If we get here, that means we are updating a posted IRTE to remapped one.

Thanks,
Feng

Quoted 10 lines

xen/drivers/passthrough/vtd/intremap.c static int remap_entry_to_msi_msg( · line 565

Quoted 9 lines
xen/drivers/passthrough/vtd/intremap.c +8 -0
+    /*
+     * We are updating posted IRTE to remapped one, check whether
+     * the common fields are going to be changed.
+     */
+    if ( ( new->remap.fpd != old->post.fpd ) ||
+         ( new->remap.sid != old->post.sid ) ||
+         ( new->remap.sq != old->post.sq ) ||
+         ( new->remap.svt != old->post.svt ) )
Quoted 3 lines

Stray blanks inside the inner parentheses.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#17 lore raw

Re: [PATCH v6 5/7] VT-d: No need to set irq affinity for posted format IRTE

Quoted 26 lines
Quoted 16 lines
Quoted 1 line · On 03.11.16 at 08:46, <[email protected]> wrote:

From: Jan Beulich [mailto:[email protected]]
Sent: Monday, October 31, 2016 10:57 PM

Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 28.10.16 at 04:37, <[email protected]> wrote:

v6:
- Make pi_can_suppress_irte_update() a check-only function
- Introduce another function pi_get_new_irte() to update the 'new_ire' if needed

I don't see what you need this function for. My earlier comments were not meant to make you split the function, but to drop all this secondary modification (unless there's actually a reason for this, which so far I haven't seen any proof of). Apart from that there already is setup_posted_irte(), which seems to do most if not all of what you really need.

Quoted 6 lines

In any event, the sequence of operations should be
1) create full new entry
2) check whether update is needed (i.e. whether old and new entries have meaningful differences)
3) do update
4) flush.

Your early comment suggest we only suppress the affinity related field. So the modification here is to handle the following case:

Quoted 7 lines

When the IRTE is currently in posted mode and this function tries to update it he remapped mode, then we need to suppress the affinity related bit, however, if the common fields (fpd, sid sq, svt) in the new remapped IRTE is different from the value in the old posted IRTE, what do you suggest we should do? Here I copy these fields to the new IRTE and update them accordingly.

You continue to look at this from what I think is the wrong angle:
msi_msg_to_remap_entry() should not make assumptions or special case either of the formats. It should construct the new entry (whichever format that's supposed to be) and compare all relevant (for the given format) fields with those of the old entry. If they all match, skip the flush.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
xen/drivers/passthrough/vtd/intremap.c +0 -0
@@ -547,6 +547,54 @@ static int remap_entry_to_msi_msg(
     return 0;
 }
 
Quoted 7 lines
Quoted 7 lines

xen/drivers/passthrough/vtd/intremap.c static int remap_entry_to_msi_msg( · line 551

Quoted 2 lines
xen/drivers/passthrough/vtd/intremap.c +2 -0
+static bool pi_can_suppress_irte_update(const struct iremap_entry *new,
+    const struct iremap_entry *old)

The two parameter declarations should be aligned with one another.

Quoted 2 lines
xen/drivers/passthrough/vtd/intremap.c +2 -0
+{
+    ASSERT( old && new );

Btw, stray blanks here (in case I didn't point this out before).

Quoted 8 lines
Quoted 5 lines

xen/drivers/passthrough/vtd/intremap.c static int remap_entry_to_msi_msg( · line 555

Quoted 2 lines
xen/drivers/passthrough/vtd/intremap.c +2 -0
+    if ( !old->remap.p || !old->remap.im || !new->remap.p || new->remap.im )
+        return false;

The asymmetry regarding the IM bit is confusing, and imo indicates a problem with the logic.

Would you please share what the problem is here? If we get here, that means we are updating a posted IRTE to remapped one.

It's the assumption expressed by the second sentence of your reply which is the problem: You're making an assumption here which you shouldn't make - I don't see the caller guaranteeing that assumption, and even if this one caller did, a function like the one here should be generic enough so that future callers won't need to worry about preconditions.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

author
#18 lore raw

PATCH v6 6/7 VT-d: Some cleanups

In reply to Feng Wu

Use type-safe structure assignment instead of memcpy() Use sizeof(*iremap_entry). Besides that, this patch also handle another cleanup, in msi_msg_to_remap_entry() we don't need to copy all the content of old IRTE to the new IRE, we only need to save the 'IM' field to 'new_ire' if the entry is present.

---
v6:
- More descripion about the patch

 xen/drivers/passthrough/vtd/intremap.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
xen/drivers/passthrough/vtd/intremap.c +9 -8
index 97e80a6..39dcb3a 100644
@@ -183,8 +183,8 @@ static void free_remap_entry(struct iommu *iommu, int index)
     GET_IREMAP_ENTRY(ir_ctrl->iremap_maddr, index,
                      iremap_entries, iremap_entry);
 
-    memset(iremap_entry, 0, sizeof(struct iremap_entry));
-    iommu_flush_cache_entry(iremap_entry, sizeof(struct iremap_entry));
+    memset(iremap_entry, 0, sizeof(*iremap_entry));
+    iommu_flush_cache_entry(iremap_entry, sizeof(*iremap_entry));
     iommu_flush_iec_index(iommu, 0, index);
 
     unmap_vtd_domain_page(iremap_entries);
@@ -310,7 +310,7 @@ static int ioapic_rte_to_remap_entry(struct iommu *iommu,
     GET_IREMAP_ENTRY(ir_ctrl->iremap_maddr, index,
                      iremap_entries, iremap_entry);
 
-    memcpy(&new_ire, iremap_entry, sizeof(struct iremap_entry));
+    new_ire = *iremap_entry;
 
     if ( rte_upper )
     {
@@ -353,8 +353,8 @@ static int ioapic_rte_to_remap_entry(struct iommu *iommu,
         remap_rte->format = 1;    /* indicate remap format */
     }
 
-    memcpy(iremap_entry, &new_ire, sizeof(struct iremap_entry));
-    iommu_flush_cache_entry(iremap_entry, sizeof(struct iremap_entry));
+    *iremap_entry = new_ire;
+    iommu_flush_cache_entry(iremap_entry, sizeof(*iremap_entry));
     iommu_flush_iec_index(iommu, 0, index);
 
     unmap_vtd_domain_page(iremap_entries);
@@ -643,7 +643,8 @@ static int msi_msg_to_remap_entry(
     GET_IREMAP_ENTRY(ir_ctrl->iremap_maddr, index,
                      iremap_entries, iremap_entry);
 
-    memcpy(&new_ire, iremap_entry, sizeof(struct iremap_entry));
+    if ( iremap_entry->remap.p )
+        new_ire.remap.im = iremap_entry->remap.im;
 
     /* Set interrupt remapping table entry */
     new_ire.remap.fpd = 0;
@@ -691,8 +692,8 @@ static int msi_msg_to_remap_entry(
              new_ire.remap.p && !new_ire.remap.im )
             pi_get_new_irte(&new_ire, iremap_entry);
 
-        memcpy(iremap_entry, &new_ire, sizeof(struct iremap_entry));
-        iommu_flush_cache_entry(iremap_entry, sizeof(struct iremap_entry));
+        *iremap_entry = new_ire;
+        iommu_flush_cache_entry(iremap_entry, sizeof(*iremap_entry));
         iommu_flush_iec_index(iommu, 0, index);
     }
 
Signature · 7 lines
2.1.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#19 lore raw

Re: [PATCH v6 6/7] VT-d: Some cleanups

xen/drivers/passthrough/vtd/intremap.c static int msi_msg_to_remap_entry( · line 647

Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 28.10.16 at 04:37, <[email protected]> wrote:
xen/drivers/passthrough/vtd/intremap.c +2 -1
@@ -643,7 +643,8 @@ static int msi_msg_to_remap_entry(
     GET_IREMAP_ENTRY(ir_ctrl->iremap_maddr, index,
                      iremap_entries, iremap_entry);
 
-    memcpy(&new_ire, iremap_entry, sizeof(struct iremap_entry));
+    if ( iremap_entry->remap.p )
+        new_ire.remap.im = iremap_entry->remap.im;

I don't understand this change, but I also don't think the change is going to be wanted/needed once the issues with the previous patch got sorted out.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

author
#20 lore raw

PATCH v6 7/7 VMX: Fixup PI descriptor when cpu is offline

In reply to Feng Wu

When cpu is offline, we need to move all the vcpus in its blocking list to another online cpu, this patch handles it.

---
v6:
- Carefully suppress 'SN' to avoid missing notification event during moving the vcpu to the new list

v5:
- Add some comments to explain why it doesn't cause deadlock for the ABBA deadlock scenario.

v4:
- Remove the pointless check since we are in machine stop context and no other cpus go down in parallel.

 xen/arch/x86/hvm/vmx/vmcs.c       |  1 +
 xen/arch/x86/hvm/vmx/vmx.c        | 70 +++++++++++++++++++++++++++++++++++++++
 xen/include/asm-x86/hvm/vmx/vmx.h |  1 +
 3 files changed, 72 insertions(+)
xen/arch/x86/hvm/vmx/vmcs.c +1 -0
index e8e3616..1846e25 100644
@@ -578,6 +578,7 @@ void vmx_cpu_dead(unsigned int cpu)
     vmx_free_vmcs(per_cpu(vmxon_region, cpu));
     per_cpu(vmxon_region, cpu) = 0;
     nvmx_cpu_dead(cpu);
+    vmx_pi_desc_fixup(cpu);
 }
 
 int vmx_cpu_up(void)
xen/arch/x86/hvm/vmx/vmx.c +70 -0

76 lines not on this page · raw message

xen/include/asm-x86/hvm/vmx/vmx.h +1 -0
index 2f0435c..7aed01d 100644
@@ -569,6 +569,7 @@ void free_p2m_hap_data(struct p2m_domain *p2m);
 void p2m_init_hap_data(struct p2m_domain *p2m);
 
 void vmx_pi_per_cpu_init(unsigned int cpu);
+void vmx_pi_desc_fixup(int cpu);
 
 void vmx_pi_hooks_assign(struct domain *d);
 void vmx_pi_hooks_deassign(struct domain *d);
Signature · 7 lines
2.1.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Reviewed-by on v6 7/7
#21 lore raw

Re: [PATCH v6 7/7] VMX: Fixup PI descriptor when cpu is offline

xen/arch/x86/hvm/vmx/vmx.c static void vmx_pi_do_resume(struct vcpu *v) · line 206

Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 28.10.16 at 04:37, <[email protected]> wrote:
xen/arch/x86/hvm/vmx/vmx.c +1 -0
@@ -203,6 +203,76 @@ static void vmx_pi_do_resume(struct vcpu *v)
     vmx_pi_unblock_vcpu(v);
 }
 
+void vmx_pi_desc_fixup(int cpu)

unsigned int

With that fixed,

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel