Skip to contentSkip to conversation

x86/vvmx: fixes to interrupt injection

PATCH In review Roger Pau Monne 3 participants 12 messages Feb 3, 2020 – Feb 4, 2020

lore
Share & tools
lore
#0 lore raw

v2 cover x86/vvmx: fixes to interrupt injection

Hello,

The following series contain fixes for nested interrupt injection.

Thanks, Roger.

Roger Pau Monne (4):
x86/vvmx: fix virtual interrupt injection when Ack on exit control is
used
x86/vvmx: fix VM_EXIT_ACK_INTR_ON_EXIT handling
x86/vvmx: don't enable interrupt window when using virt intr delivery Revert "tools/libxc: disable x2APIC when using nested virtualization"

 tools/libxc/xc_cpuid_x86.c  | 11 -----------
 xen/arch/x86/hvm/vmx/intr.c |  2 +-
 xen/arch/x86/hvm/vmx/vvmx.c | 13 ++++++++++---
 3 files changed, 11 insertions(+), 15 deletions(-)
Signature · 7 lines
2.25.0


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

PATCH v2 1/4 x86/vvmx: fix virtual interrupt injection when Ack on exit control is used

When doing a virtual vmexit (ie: a vmexit handled by the L1 VMM) interrupts shouldn't be injected using the virtual interrupt delivery mechanism unless the Ack on exit vmexit control bit isn't set in the nested vmcs.

Gate the call to nvmx_update_apicv helper on whether the nested vmcs has the Ack on exit bit set in the vmexit control field.

Note that this fixes the usage of x2APIC by the L1 VMM, at least when the L1 VMM is Xen.

---
Changes since v1:
- Call nvmx_update_apicv if the "Ack on exit" vmexit control bit isn't set.

---
 xen/arch/x86/hvm/vmx/vvmx.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
xen/arch/x86/hvm/vmx/vvmx.c +6 -1
index d8ab167d62..3d97a293b2 100644
@@ -1393,7 +1393,12 @@ static void virtual_vmexit(struct cpu_user_regs *regs)
     /* updating host cr0 to sync TS bit */
     __vmwrite(HOST_CR0, v->arch.hvm.vmx.host_cr0);
 
-    if ( cpu_has_vmx_virtual_intr_delivery )
+    if ( cpu_has_vmx_virtual_intr_delivery &&
+         /*
+          * Only inject the vector if the Ack on exit bit is not set, else the
+          * interrupt will be signaled in the vmcs VM_EXIT_INTR_INFO field.
+          */
+         !(get_vvmcs(v, VM_EXIT_CONTROLS) & VM_EXIT_ACK_INTR_ON_EXIT) )
         nvmx_update_apicv(v);
 
     nvcpu->nv_vmswitch_in_progress = 0;
Signature · 7 lines
2.25.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v2 1/4
#2 lore raw

Re: [Xen-devel] [PATCH v2 1/4] x86/vvmx: fix virtual interrupt injection when Ack on exit control is used

Quoted 8 lines

From: Roger Pau Monne <[email protected]>
Sent: Monday, February 3, 2020 8:19 PM

When doing a virtual vmexit (ie: a vmexit handled by the L1 VMM) interrupts shouldn't be injected using the virtual interrupt delivery mechanism unless the Ack on exit vmexit control bit isn't set in the nested vmcs.

Quoted 7 lines

Gate the call to nvmx_update_apicv helper on whether the nested vmcs has the Ack on exit bit set in the vmexit control field.

Note that this fixes the usage of x2APIC by the L1 VMM, at least when the L1 VMM is Xen.

Quoted 14 lines

---
Changes since v1:
- Call nvmx_update_apicv if the "Ack on exit" vmexit control bit isn't set.

---
 xen/arch/x86/hvm/vmx/vvmx.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
xen/arch/x86/hvm/vmx/vvmx.c +0 -0
index d8ab167d62..3d97a293b2 100644
@@ -1393,7 +1393,12 @@ static void virtual_vmexit(struct cpu_user_regs
 *regs)

xen/arch/x86/hvm/vmx/vvmx.c static void virtual_vmexit(struct cpu_user_regs · line 1402

Quoted 10 lines
xen/arch/x86/hvm/vmx/vvmx.c +6 -1
     /* updating host cr0 to sync TS bit */
     __vmwrite(HOST_CR0, v->arch.hvm.vmx.host_cr0);
 
-    if ( cpu_has_vmx_virtual_intr_delivery )
+    if ( cpu_has_vmx_virtual_intr_delivery &&
+         /*
+          * Only inject the vector if the Ack on exit bit is not set, else the
+          * interrupt will be signaled in the vmcs VM_EXIT_INTR_INFO field.
+          */
+         !(get_vvmcs(v, VM_EXIT_CONTROLS) & VM_EXIT_ACK_INTR_ON_EXIT) )

It's a bit odd to put comment between code lines. Can you move it to the line before 'if'?

Quoted 5 lines
xen/arch/x86/hvm/vmx/vvmx.c +0 -0
         nvmx_update_apicv(v);
 
     nvcpu->nv_vmswitch_in_progress = 0;

--
2.25.0

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

#3 lore raw

Re: [Xen-devel] [PATCH v2 1/4] x86/vvmx: fix virtual interrupt injection when Ack on exit control is used

Quoted 35 lines · Kevin
Quoted 8 lines

From: Roger Pau Monne <[email protected]>
Sent: Monday, February 3, 2020 8:19 PM

When doing a virtual vmexit (ie: a vmexit handled by the L1 VMM) interrupts shouldn't be injected using the virtual interrupt delivery mechanism unless the Ack on exit vmexit control bit isn't set in the nested vmcs.

Quoted 7 lines

Gate the call to nvmx_update_apicv helper on whether the nested vmcs has the Ack on exit bit set in the vmexit control field.

Note that this fixes the usage of x2APIC by the L1 VMM, at least when the L1 VMM is Xen.

Quoted 17 lines

---
Changes since v1:
- Call nvmx_update_apicv if the "Ack on exit" vmexit control bit isn't set.

---
 xen/arch/x86/hvm/vmx/vvmx.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
xen/arch/x86/hvm/vmx/vvmx.c +0 -0
index d8ab167d62..3d97a293b2 100644
@@ -1393,7 +1393,12 @@ static void virtual_vmexit(struct cpu_user_regs
 *regs)
     /* updating host cr0 to sync TS bit */
     __vmwrite(HOST_CR0, v->arch.hvm.vmx.host_cr0);
 
Quoted 10 lines

xen/arch/x86/hvm/vmx/vvmx.c static void virtual_vmexit(struct cpu_user_regs *regs) · line 1401

Quoted 7 lines
xen/arch/x86/hvm/vmx/vvmx.c +6 -1
-    if ( cpu_has_vmx_virtual_intr_delivery )
+    if ( cpu_has_vmx_virtual_intr_delivery &&
+         /*
+          * Only inject the vector if the Ack on exit bit is not set, else the
+          * interrupt will be signaled in the vmcs VM_EXIT_INTR_INFO field.
+          */
+         !(get_vvmcs(v, VM_EXIT_CONTROLS) & VM_EXIT_ACK_INTR_ON_EXIT) )

It's a bit odd to put comment between code lines. Can you move it to the line before 'if'?

I usually try to keep the comments as close to the code it references as possible, even if that means adding them in the middle of an if condition.

I don't mind moving it, but maybe the committer can do it at commit time?

Thanks, Roger.

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

#4 lore raw

Re: [Xen-devel] [PATCH v2 1/4] x86/vvmx: fix virtual interrupt injection when Ack on exit control is used

Quoted 47 lines · Roger Pau Monné
Quoted 35 lines · Kevin
Quoted 8 lines

From: Roger Pau Monne <[email protected]>
Sent: Monday, February 3, 2020 8:19 PM

When doing a virtual vmexit (ie: a vmexit handled by the L1 VMM) interrupts shouldn't be injected using the virtual interrupt delivery mechanism unless the Ack on exit vmexit control bit isn't set in the nested vmcs.

Quoted 7 lines

Gate the call to nvmx_update_apicv helper on whether the nested vmcs has the Ack on exit bit set in the vmexit control field.

Note that this fixes the usage of x2APIC by the L1 VMM, at least when the L1 VMM is Xen.

Quoted 17 lines

---
Changes since v1:
- Call nvmx_update_apicv if the "Ack on exit" vmexit control bit isn't set.

---
 xen/arch/x86/hvm/vmx/vvmx.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
xen/arch/x86/hvm/vmx/vvmx.c +0 -0
index d8ab167d62..3d97a293b2 100644
@@ -1393,7 +1393,12 @@ static void virtual_vmexit(struct cpu_user_regs
 *regs)
     /* updating host cr0 to sync TS bit */
     __vmwrite(HOST_CR0, v->arch.hvm.vmx.host_cr0);
 
Quoted 10 lines

xen/arch/x86/hvm/vmx/vvmx.c static void virtual_vmexit(struct cpu_user_regs *regs) · line 1401

Quoted 7 lines
xen/arch/x86/hvm/vmx/vvmx.c +6 -1
-    if ( cpu_has_vmx_virtual_intr_delivery )
+    if ( cpu_has_vmx_virtual_intr_delivery &&
+         /*
+          * Only inject the vector if the Ack on exit bit is not set, else the
+          * interrupt will be signaled in the vmcs VM_EXIT_INTR_INFO field.
+          */
+         !(get_vvmcs(v, VM_EXIT_CONTROLS) & VM_EXIT_ACK_INTR_ON_EXIT) )

It's a bit odd to put comment between code lines. Can you move it to the line before 'if'?

Quoted 6 lines

I usually try to keep the comments as close to the code it references as possible, even if that means adding them in the middle of an if condition.

I don't mind moving it, but maybe the committer can do it at commit time?

This should be easy enough, but - Kevin, I agree with Roger that the chose placement is better than what you suggest. You're the maintainer of the file, so if you really think the comment should be moved - so be it. But please re-confirm one or the other way.

Jan

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

#5 lore raw

Re: [Xen-devel] [PATCH v2 1/4] x86/vvmx: fix virtual interrupt injection when Ack on exit control is used

Quoted 58 lines

From: Jan Beulich
Sent: Tuesday, February 4, 2020 5:50 PM

Quoted 27 lines · Roger Pau Monné
Quoted 26 lines · Kevin
Quoted 8 lines

From: Roger Pau Monne <[email protected]>
Sent: Monday, February 3, 2020 8:19 PM

When doing a virtual vmexit (ie: a vmexit handled by the L1 VMM) interrupts shouldn't be injected using the virtual interrupt delivery mechanism unless the Ack on exit vmexit control bit isn't set in the nested vmcs.

Quoted 7 lines

Gate the call to nvmx_update_apicv helper on whether the nested vmcs has the Ack on exit bit set in the vmexit control field.

Note that this fixes the usage of x2APIC by the L1 VMM, at least when the L1 VMM is Xen.

Quoted 8 lines

---
Changes since v1:
- Call nvmx_update_apicv if the "Ack on exit" vmexit control bit isn't set.

---
 xen/arch/x86/hvm/vmx/vvmx.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
Quoted 1 line
Quoted 1 line

Review

Quoted 1 line
(quoted diff) +0 -0

b/xen/arch/x86/hvm/vmx/vvmx.c

Quoted 4 lines
Quoted 4 lines

xen/arch/x86/hvm/vmx/vvmx.c static void virtual_vmexit(struct

Quoted 4 lines

index d8ab167d62..3d97a293b2 100644

xen/arch/x86/hvm/vmx/vvmx.c +0 -0
@@ -1393,7 +1393,12 @@ static void virtual_vmexit(struct

cpu_user_regs

Quoted 11 lines
Quoted 11 lines

xen/arch/x86/hvm/vmx/vvmx.c static void virtual_vmexit(struct cpu_user_regs *regs)

Quoted 11 lines
xen/arch/x86/hvm/vmx/vvmx.c +6 -1
 *regs)
     /* updating host cr0 to sync TS bit */
     __vmwrite(HOST_CR0, v->arch.hvm.vmx.host_cr0);
 
-    if ( cpu_has_vmx_virtual_intr_delivery )
+    if ( cpu_has_vmx_virtual_intr_delivery &&
+         /*
+          * Only inject the vector if the Ack on exit bit is not set, else the
+          * interrupt will be signaled in the vmcs VM_EXIT_INTR_INFO field.
+          */
+         !(get_vvmcs(v, VM_EXIT_CONTROLS) &

VM_EXIT_ACK_INTR_ON_EXIT) )

Quoted 8 lines
Quoted 3 lines

It's a bit odd to put comment between code lines. Can you move it to the line before 'if'?

I usually try to keep the comments as close to the code it references as possible, even if that means adding them in the middle of an if condition.

Quoted 8 lines
Quoted 2 lines

I don't mind moving it, but maybe the committer can do it at commit time?

This should be easy enough, but - Kevin, I agree with Roger that the chose placement is better than what you suggest. You're the maintainer of the file, so if you really think the comment should be moved - so be it. But please re-confirm one or the other way.

Then leave it as it is. I'm not strong on this request.
_______________________________________________
Xen-devel mailing list [email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#6 lore raw

PATCH v2 2/4 x86/vvmx: fix VM_EXIT_ACK_INTR_ON_EXIT handling

In reply to Roger Pau Monne

When VM_EXIT_ACK_INTR_ON_EXIT is set in the vmexit control vmcs register the bit 31 of VM_EXIT_INTR_INFO must be 0, in order to denote that the field doesn't contain any interrupt information. This is not currently acknowledged as the field always get filled with valid interrupt information, regardless of whether VM_EXIT_ACK_INTR_ON_EXIT is set.

Fix this and only fill VM_EXIT_INTR_INFO when VM_EXIT_ACK_INTR_ON_EXIT is not set. Note that this requires one minor change in nvmx_update_apicv in order to obtain the interrupt information from the internal state rather than the nested vmcs register.

---
Changes since v1:
- New in this version.

---
 xen/arch/x86/hvm/vmx/vvmx.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
xen/arch/x86/hvm/vmx/vvmx.c +4 -2
index 3d97a293b2..47eee1e5b9 100644
@@ -1283,6 +1283,7 @@ static void load_vvmcs_host_state(struct vcpu *v)
 static void sync_exception_state(struct vcpu *v)
 {
     struct nestedvmx *nvmx = &vcpu_2_nvmx(v);
+    uint32_t exit_ctrl = get_vvmcs(v, VM_EXIT_CONTROLS);
 
     if ( !(nvmx->intr.intr_info & INTR_INFO_VALID_MASK) )
         return;
@@ -1294,7 +1295,8 @@ static void sync_exception_state(struct vcpu *v)
         set_vvmcs(v, VM_EXIT_REASON, EXIT_REASON_EXTERNAL_INTERRUPT);
         set_vvmcs(v, EXIT_QUALIFICATION, 0);
         set_vvmcs(v, VM_EXIT_INTR_INFO,
-                    nvmx->intr.intr_info);
+                  (exit_ctrl & VM_EXIT_ACK_INTR_ON_EXIT) ? nvmx->intr.intr_info
+                                                         : 0);
         break;
 
     case X86_EVENTTYPE_HW_EXCEPTION:
@@ -1320,7 +1322,7 @@ static void nvmx_update_apicv(struct vcpu *v)
 {
     struct nestedvmx *nvmx = &vcpu_2_nvmx(v);
     unsigned long reason = get_vvmcs(v, VM_EXIT_REASON);
-    uint32_t intr_info = get_vvmcs(v, VM_EXIT_INTR_INFO);
+    uint32_t intr_info = nvmx->intr.intr_info;
 
     if ( reason == EXIT_REASON_EXTERNAL_INTERRUPT &&
          nvmx->intr.source == hvm_intsrc_lapic &&
Signature · 7 lines
2.25.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v2 2/4
#7 lore raw

Re: [Xen-devel] [PATCH v2 2/4] x86/vvmx: fix VM_EXIT_ACK_INTR_ON_EXIT handling

Quoted 4 lines

From: Roger Pau Monne <[email protected]>
Sent: Monday, February 3, 2020 8:19 PM

When VM_EXIT_ACK_INTR_ON_EXIT is set in the vmexit control vmcs

set->cleared

Quoted 8 lines

register the bit 31 of VM_EXIT_INTR_INFO must be 0, in order to denote that the field doesn't contain any interrupt information. This is not currently acknowledged as the field always get filled with valid interrupt information, regardless of whether VM_EXIT_ACK_INTR_ON_EXIT is set.

Fix this and only fill VM_EXIT_INTR_INFO when VM_EXIT_ACK_INTR_ON_EXIT is not set. Note that this requires one minor change in

not set -> set

Quoted 4 lines

nvmx_update_apicv in order to obtain the interrupt information from the internal state rather than the nested vmcs register.

with above fixed,

Quoted 39 lines

---
Changes since v1:
- New in this version.

---
 xen/arch/x86/hvm/vmx/vvmx.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
xen/arch/x86/hvm/vmx/vvmx.c +4 -3
index 3d97a293b2..47eee1e5b9 100644
@@ -1283,6 +1283,7 @@ static void load_vvmcs_host_state(struct vcpu *v)
 static void sync_exception_state(struct vcpu *v)
 {
     struct nestedvmx *nvmx = &vcpu_2_nvmx(v);
+    uint32_t exit_ctrl = get_vvmcs(v, VM_EXIT_CONTROLS);
 
     if ( !(nvmx->intr.intr_info & INTR_INFO_VALID_MASK) )
         return;
@@ -1294,7 +1295,8 @@ static void sync_exception_state(struct vcpu *v)
         set_vvmcs(v, VM_EXIT_REASON, EXIT_REASON_EXTERNAL_INTERRUPT);
         set_vvmcs(v, EXIT_QUALIFICATION, 0);
         set_vvmcs(v, VM_EXIT_INTR_INFO,
-                    nvmx->intr.intr_info);
+                  (exit_ctrl & VM_EXIT_ACK_INTR_ON_EXIT) ? nvmx->intr.intr_info
+                                                         : 0);
         break;
 
     case X86_EVENTTYPE_HW_EXCEPTION:
@@ -1320,7 +1322,7 @@ static void nvmx_update_apicv(struct vcpu *v)
 {
     struct nestedvmx *nvmx = &vcpu_2_nvmx(v);
     unsigned long reason = get_vvmcs(v, VM_EXIT_REASON);
-    uint32_t intr_info = get_vvmcs(v, VM_EXIT_INTR_INFO);
+    uint32_t intr_info = nvmx->intr.intr_info;
 
     if ( reason == EXIT_REASON_EXTERNAL_INTERRUPT &&
          nvmx->intr.source == hvm_intsrc_lapic &&
--
Quoted 1 line

2.25.0

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

#8 lore raw

Re: [Xen-devel] [PATCH v2 2/4] x86/vvmx: fix VM_EXIT_ACK_INTR_ON_EXIT handling

Quoted 16 lines · Kevin
Quoted 4 lines

From: Roger Pau Monne <[email protected]>
Sent: Monday, February 3, 2020 8:19 PM

When VM_EXIT_ACK_INTR_ON_EXIT is set in the vmexit control vmcs

set->cleared

Quoted 8 lines

register the bit 31 of VM_EXIT_INTR_INFO must be 0, in order to denote that the field doesn't contain any interrupt information. This is not currently acknowledged as the field always get filled with valid interrupt information, regardless of whether VM_EXIT_ACK_INTR_ON_EXIT is set.

Fix this and only fill VM_EXIT_INTR_INFO when VM_EXIT_ACK_INTR_ON_EXIT is not set. Note that this requires one minor change in

Quoted 8 lines

not set -> set

Quoted 4 lines

nvmx_update_apicv in order to obtain the interrupt information from the internal state rather than the nested vmcs register.

with above fixed,

Ouch yes, I've inverted the conditions. Thanks for noticing.

Quoted 2 lines

To whoever picks this patch for committing: let me know if you would like me to resend with the commit log fixed.

Roger.

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

#9 lore raw

PATCH v2 3/4 x86/vvmx: don't enable interrupt window when using virt intr delivery

In reply to Roger Pau Monne

If virtual interrupt delivery is used to inject the interrupt to the guest the interrupt window shouldn't be enabled, as the interrupt is already injected using the GUEST_INTR_STATUS vmcs field.

---
Changes since v1:
- New in this version.

---
 xen/arch/x86/hvm/vmx/intr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/x86/hvm/vmx/intr.c +1 -1
index 2eaf3f8d36..49a1295f09 100644
@@ -209,7 +209,7 @@ static int nvmx_intr_intercept(struct vcpu *v, struct hvm_intack intack)
                 if ( unlikely(intack.source != hvm_intsrc_none) )
                     vmx_enable_intr_window(v, intack);
             }
-            else
+            else if ( !cpu_has_vmx_virtual_intr_delivery )
                 vmx_enable_intr_window(v, intack);
 
             return 1;
Signature · 7 lines
2.25.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v2 3/4
#10 lore raw

Re: [Xen-devel] [PATCH v2 3/4] x86/vvmx: don't enable interrupt window when using virt intr delivery

Quoted 9 lines

From: Roger Pau Monne <[email protected]>
Sent: Monday, February 3, 2020 8:19 PM

If virtual interrupt delivery is used to inject the interrupt to the guest the interrupt window shouldn't be enabled, as the interrupt is already injected using the GUEST_INTR_STATUS vmcs field.

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

#11 lore raw

PATCH v2 4/4 Revert "tools/libxc: disable x2APIC when using nested virtualization"

In reply to Roger Pau Monne

This reverts commit 7b3c5b70a32303b46d0d051e695f18d72cce5ed0 and re-enables the usage of x2APIC with nested virtualization.

---
 tools/libxc/xc_cpuid_x86.c | 11 -----------
 1 file changed, 11 deletions(-)
tools/libxc/xc_cpuid_x86.c +0 -11
index ac38c1406e..2540aa1e1c 100644
@@ -653,17 +653,6 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid,
         p->extd.itsc = true;
         p->basic.vmx = true;
         p->extd.svm = true;
-
-        /*
-         * BODGE: don't announce x2APIC mode when using nested virtualization,
-         * as it doesn't work properly. This should be removed once the
-         * underlying bug(s) are fixed.
-         */
-        rc = xc_hvm_param_get(xch, domid, HVM_PARAM_NESTEDHVM, &val);
-        if ( rc )
-            goto out;
-        if ( val )
-            p->basic.x2apic = false;
     }
 
     rc = x86_cpuid_copy_to_buffer(p, leaves, &nr_leaves);
Signature · 7 lines
2.25.0


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