Skip to contentSkip to conversation

vmx, apicv: fix save/restore issue with apicv

PATCH Superseded Yang Zhang 4 participants 11 messages Oct 11, 2014 – Oct 16, 2014

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Yang Zhang

author
#0 lore raw

PATCH 1/1 vmx, apicv: fix save/restore issue with apicv

From: Yang Zhang <[email protected]>

This patch fix two issues:

1. Interrupts on PIR are lost during save/restore. Syncing the PIR into IRR during save will fix it.

2. EOI exit bitmap doesn't setup correctly after restore. Here we will construct the eoi exit bimap via (IRR | ISR). Though it may cause unnecessary eoi exit of the interrupts that pending in IRR or ISR during save/resotre, each pending interrupt only causes one vmexit. The subsequent interrupts will adjust the eoi exit bitmap correctly. So the performace hurt can be ignored.

---
Hi Olaf and Malcolm, Can you help to retest it? Because the key part is changed in this patch, so i'm not sure whether it still works in your side.

Also, Olaf, is it ok to add your SOB in this patch? If yes, I can resend it to do it.

 xen/arch/x86/hvm/vlapic.c  |    3 +++
 xen/arch/x86/hvm/vmx/vmx.c |   27 ++++++++++++++++++++++++++-
 2 files changed, 29 insertions(+), 1 deletions(-)
xen/arch/x86/hvm/vlapic.c +3 -0
index 99ae1be..e702ed3 100644
@@ -1259,6 +1259,9 @@ static int lapic_save_regs(struct domain *d, hvm_domain_context_t *h)
 
     for_each_vcpu ( d, v )
     {
+        if ( hvm_funcs.sync_pir_to_irr )
+            hvm_funcs.sync_pir_to_irr(v);
+
         s = vcpu_vlapic(v);
         if ( (rc = hvm_save_entry(LAPIC_REGS, v->vcpu_id, h, s->regs)) != 0 )
             break;
xen/arch/x86/hvm/vmx/vmx.c +26 -1
index 304aeea..fb38d15 100644
@@ -1583,7 +1583,9 @@ static int vmx_virtual_intr_delivery_enabled(void)
 static void vmx_process_isr(int isr, struct vcpu *v)
 {
     unsigned long status;
-    u8 old;
+    u8 old, i;
+    unsigned int *eoi_exit_bitmap, val;
+    struct vlapic *vlapic = vcpu_vlapic(v);
 
     if ( isr < 0 )
         isr = 0;
@@ -1597,6 +1599,29 @@ static void vmx_process_isr(int isr, struct vcpu *v)
         status |= isr << VMX_GUEST_INTR_STATUS_SVI_OFFSET;
         __vmwrite(GUEST_INTR_STATUS, status);
     }
+
+    eoi_exit_bitmap = (unsigned int *)v->arch.hvm_vmx.eoi_exit_bitmap;
+    /*
+     * We cannot simple copy the TMR as eoi exit bitmap due to the special
+     * periodic timer interrupt which is edge trigger but need a mandatory
+     * EOI-induced VM exit to let pending periodic timer interrupts have the
+     * chance to be injected for compensation.
+     * Here we will construct the eoi exit bimap via (IRR | ISR). Though it
+     * may cause unnecessary eoi exit of the interrupts that pending in IRR or
+     * ISR during save/resotre, each pending interrupt only causes one vmexit.
+     * The subsequent interrupts will adjust the eoi exit bitmap correctly. So
+     * the performace hurt can be ingored.
+     */
+    for ( i = 0x10; i < 0x80; i += 0x10 )
+    {
+        val = vlapic_get_reg(vlapic, APIC_IRR + i);
+        val |= vlapic_get_reg(vlapic, APIC_ISR + i);
+        eoi_exit_bitmap[i >> 4] |= val;
+    }
+
+    for ( i = 0; i < 4; i++ )
+        __vmwrite(EOI_EXIT_BITMAP(i), v->arch.hvm_vmx.eoi_exit_bitmap[i]);
+
     vmx_vmcs_exit(v);
 }
 
Signature · 1 line
1.7.6.3
#1 lore raw

xen/arch/x86/hvm/vmx/vmx.c static int vmx_virtual_intr_delivery_enabled(void) · line 1586

Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 11.10.14 at 09:54, <[email protected]> wrote:
xen/arch/x86/hvm/vmx/vmx.c +1 -1
@@ -1583,7 +1583,9 @@ static int vmx_virtual_intr_delivery_enabled(void)
 static void vmx_process_isr(int isr, struct vcpu *v)
 {
     unsigned long status;
-    u8 old;
+    u8 old, i;

There is absolutely no point in i being u8 - this can be plain unsigned int.

xen/arch/x86/hvm/vmx/vmx.c static void vmx_process_isr(int isr, struct vcpu *v) · line 1603

Quoted 11 lines
xen/arch/x86/hvm/vmx/vmx.c +4 -0
+    unsigned int *eoi_exit_bitmap, val;
+    struct vlapic *vlapic = vcpu_vlapic(v);
 
     if ( isr < 0 )
         isr = 0;
@@ -1597,6 +1599,29 @@ static void vmx_process_isr(int isr, struct vcpu *v)
         status |= isr << VMX_GUEST_INTR_STATUS_SVI_OFFSET;
         __vmwrite(GUEST_INTR_STATUS, status);
     }
+
+    eoi_exit_bitmap = (unsigned int *)v->arch.hvm_vmx.eoi_exit_bitmap;

No casts like this please. This is a bitmap and would hence preferably be treated that way consistently. The code here isn't performance critical.

xen/arch/x86/hvm/vmx/vmx.c static void vmx_process_isr(int isr, struct vcpu *v) · line 1615

Quoted 12 lines
xen/arch/x86/hvm/vmx/vmx.c +12 -0
+    /*
+     * We cannot simple copy the TMR as eoi exit bitmap due to the special
+     * periodic timer interrupt which is edge trigger but need a mandatory
+     * EOI-induced VM exit to let pending periodic timer interrupts have the
+     * chance to be injected for compensation.
+     * Here we will construct the eoi exit bimap via (IRR | ISR). Though it
+     * may cause unnecessary eoi exit of the interrupts that pending in IRR or
+     * ISR during save/resotre, each pending interrupt only causes one vmexit.
+     * The subsequent interrupts will adjust the eoi exit bitmap correctly. So
+     * the performace hurt can be ingored.
+     */
+    for ( i = 0x10; i < 0x80; i += 0x10 )

So you skip the first 32 vectors instead of just the first 16. That's not in line with the APIC definitions. Also basing the loop variable on APIC register numbers is kind of odd. I'd really suggest using something more natural, like vector space (which would also allow you to use existing helper functions/macros).

xen/arch/x86/hvm/vmx/vmx.c static void vmx_process_isr(int isr, struct vcpu *v) · line 1618

Quoted 3 lines
xen/arch/x86/hvm/vmx/vmx.c +3 -0
+    {
+        val = vlapic_get_reg(vlapic, APIC_IRR + i);
+        val |= vlapic_get_reg(vlapic, APIC_ISR + i);

The comment above doesn't really make clear why not just IRR.

Also please check the spelling in that comment.

Jan

#2 lore raw

Jan Beulich wrote on 2014-10-13:

Quoted 11 lines

xen/arch/x86/hvm/vmx/vmx.c static int · line 1586

Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 11.10.14 at 09:54, <[email protected]> wrote:
xen/arch/x86/hvm/vmx/vmx.c +1 -1
@@ -1583,7 +1583,9 @@ static int
 vmx_virtual_intr_delivery_enabled(void)
 static void vmx_process_isr(int isr, struct vcpu *v)  {
     unsigned long status;
-    u8 old;
+    u8 old, i;

There is absolutely no point in i being u8 - this can be plain unsigned int.

It's ok to change it to unsigned int.

Quoted 15 lines

xen/arch/x86/hvm/vmx/vmx.c static void vmx_process_isr(int isr, struct vcpu

Quoted 7 lines
xen/arch/x86/hvm/vmx/vmx.c +2 -0
+    unsigned int *eoi_exit_bitmap, val;
+    struct vlapic *vlapic = vcpu_vlapic(v);
 
     if ( isr < 0 )
         isr = 0;
@@ -1597,6 +1599,29 @@ static void vmx_process_isr(int isr, struct vcpu

*v)

xen/arch/x86/hvm/vmx/vmx.c static void vmx_process_isr(int isr, struct vcpu *v)

Quoted 6 lines
xen/arch/x86/hvm/vmx/vmx.c +3 -0
         status |= isr << VMX_GUEST_INTR_STATUS_SVI_OFFSET;
         __vmwrite(GUEST_INTR_STATUS, status);
     }
+
+    eoi_exit_bitmap = (unsigned int
+ *)v->arch.hvm_vmx.eoi_exit_bitmap;
Quoted 2 lines

No casts like this please. This is a bitmap and would hence preferably be treated that way consistently. The code here isn't performance critical.

Yes, it's performance critical from the live migration's point and that's why I use the cast here and

Quoted 18 lines

xen/arch/x86/hvm/vmx/vmx.c static void vmx_process_isr(int isr, struct vcpu *v)

Quoted 5 lines
xen/arch/x86/hvm/vmx/vmx.c +4 -0
+    /*
+     * We cannot simple copy the TMR as eoi exit bitmap due to the special
+     * periodic timer interrupt which is edge trigger but need a mandatory
+     * EOI-induced VM exit to let pending periodic timer interrupts have

the

xen/arch/x86/hvm/vmx/vmx.c static void vmx_process_isr(int isr, struct vcpu *v)

Quoted 3 lines
xen/arch/x86/hvm/vmx/vmx.c +3 -0
+     * chance to be injected for compensation.
+     * Here we will construct the eoi exit bimap via (IRR | ISR). Though it
+     * may cause unnecessary eoi exit of the interrupts that pending in IRR

or

xen/arch/x86/hvm/vmx/vmx.c static void vmx_process_isr(int isr, struct vcpu · line 1612

Quoted 1 line
xen/arch/x86/hvm/vmx/vmx.c +1 -0
+     * ISR during save/resotre, each pending interrupt only causes one

vmexit.

xen/arch/x86/hvm/vmx/vmx.c static void vmx_process_isr(int isr, struct vcpu · line 1613

Quoted 1 line
xen/arch/x86/hvm/vmx/vmx.c +1 -0
+     * The subsequent interrupts will adjust the eoi exit bitmap correctly.

So

xen/arch/x86/hvm/vmx/vmx.c static void vmx_process_isr(int isr, struct vcpu *v) · line 1615

Quoted 3 lines
xen/arch/x86/hvm/vmx/vmx.c +3 -0
+     * the performace hurt can be ingored.
+     */
+    for ( i = 0x10; i < 0x80; i += 0x10 )
Quoted 7 lines

So you skip the first 32 vectors instead of just the first 16. That's not in line with

the APIC definitions. Also basing the loop variable on APIC register numbers is kind of odd. I'd really suggest using something more natural, like vector space (which would also allow you to use existing helper functions/macros).

...skip the first 32 vectors and operates based on group instead vector

Also, Spec says "21-31 - Intel reserved. Do not use." So it's ok to skip them.

Quoted 5 lines

xen/arch/x86/hvm/vmx/vmx.c static void vmx_process_isr(int isr, struct vcpu *v) · line 1618

Quoted 3 lines
xen/arch/x86/hvm/vmx/vmx.c +3 -0
+    {
+        val = vlapic_get_reg(vlapic, APIC_IRR + i);
+        val |= vlapic_get_reg(vlapic, APIC_ISR + i);

The comment above doesn't really make clear why not just IRR.

Upon acceptance of an interrupt into the IRR, the corresponding TMR will be changed. This means an interrupt either in IRR or in ISR has no chance to update the TMR and eoi exit bitmap. So we need to check IRR + ISR while rebuilding the eoi exit bitmap. It is not enough to check only IRR.

Quoted 2 lines

Also please check the spelling in that comment.

Sorry for my poor English.

Quoted 2 lines

Jan

Best regards,
Yang

#3 lore raw
Quoted 26 lines · Yang Z

Jan Beulich wrote on 2014-10-13:

Quoted 10 lines

xen/arch/x86/hvm/vmx/vmx.c static int · line 1586

Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 11.10.14 at 09:54, <[email protected]> wrote:
xen/arch/x86/hvm/vmx/vmx.c +1 -1
@@ -1583,7 +1583,9 @@ static int
 vmx_virtual_intr_delivery_enabled(void)
 static void vmx_process_isr(int isr, struct vcpu *v)  {
     unsigned long status;
-    u8 old;
+    u8 old, i;

There is absolutely no point in i being u8 - this can be plain unsigned int.

It's ok to change it to unsigned int.

Quoted 13 lines

xen/arch/x86/hvm/vmx/vmx.c static void vmx_process_isr(int isr, struct vcpu

Quoted 6 lines
xen/arch/x86/hvm/vmx/vmx.c +2 -0
+    unsigned int *eoi_exit_bitmap, val;
+    struct vlapic *vlapic = vcpu_vlapic(v);
 
     if ( isr < 0 )
         isr = 0;
@@ -1597,6 +1599,29 @@ static void vmx_process_isr(int isr, struct vcpu

*v)

Quoted 6 lines
xen/arch/x86/hvm/vmx/vmx.c +3 -0
         status |= isr << VMX_GUEST_INTR_STATUS_SVI_OFFSET;
         __vmwrite(GUEST_INTR_STATUS, status);
     }
+
+    eoi_exit_bitmap = (unsigned int
+ *)v->arch.hvm_vmx.eoi_exit_bitmap;
Quoted 3 lines
Quoted 2 lines

No casts like this please. This is a bitmap and would hence preferably be treated that way consistently. The code here isn't performance critical.

Yes, it's performance critical from the live migration's point and that's why I use the cast here and

It is run once per vLAPIC on restore. I would not qualify it as performance critical, but I would also advocate the efficient method of word accesses over the inefficient bit accesses where it makes sense.

Quoted 19 lines
Quoted 18 lines

xen/arch/x86/hvm/vmx/vmx.c static void vmx_process_isr(int isr, struct vcpu *v)

Quoted 5 lines
xen/arch/x86/hvm/vmx/vmx.c +4 -0
+    /*
+     * We cannot simple copy the TMR as eoi exit bitmap due to the special
+     * periodic timer interrupt which is edge trigger but need a mandatory
+     * EOI-induced VM exit to let pending periodic timer interrupts have

the

xen/arch/x86/hvm/vmx/vmx.c static void vmx_process_isr(int isr, struct vcpu *v)

Quoted 3 lines
xen/arch/x86/hvm/vmx/vmx.c +3 -0
+     * chance to be injected for compensation.
+     * Here we will construct the eoi exit bimap via (IRR | ISR). Though it
+     * may cause unnecessary eoi exit of the interrupts that pending in IRR

or

xen/arch/x86/hvm/vmx/vmx.c static void vmx_process_isr(int isr, struct vcpu · line 1612

Quoted 1 line
xen/arch/x86/hvm/vmx/vmx.c +1 -0
+     * ISR during save/resotre, each pending interrupt only causes one

vmexit.

xen/arch/x86/hvm/vmx/vmx.c static void vmx_process_isr(int isr, struct vcpu · line 1613

Quoted 1 line
xen/arch/x86/hvm/vmx/vmx.c +1 -0
+     * The subsequent interrupts will adjust the eoi exit bitmap correctly.

So

xen/arch/x86/hvm/vmx/vmx.c static void vmx_process_isr(int isr, struct vcpu *v) · line 1615

Quoted 3 lines
xen/arch/x86/hvm/vmx/vmx.c +3 -0
+     * the performace hurt can be ingored.
+     */
+    for ( i = 0x10; i < 0x80; i += 0x10 )

So you skip the first 32 vectors instead of just the first 16. That's not in line with

Quoted 7 lines
Quoted 4 lines

the APIC definitions. Also basing the loop variable on APIC register numbers is kind of odd. I'd really suggest using something more natural, like vector space (which would also allow you to use existing helper functions/macros).

...skip the first 32 vectors and operates based on group instead vector

Also, Spec says "21-31 - Intel reserved. Do not use." So it's ok to skip them.

And what do you expect will happen to DoS guests which continue to use the legacy PICs?

This range cannot possibly be skipped.

~Andrew

#4 lore raw

Andrew Cooper wrote on 2014-10-14:

Quoted 28 lines · Yang Z
Quoted 27 lines

Jan Beulich wrote on 2014-10-13:

Quoted 10 lines

xen/arch/x86/hvm/vmx/vmx.c static int · line 1586

Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 11.10.14 at 09:54, <[email protected]> wrote:
xen/arch/x86/hvm/vmx/vmx.c +1 -1
@@ -1583,7 +1583,9 @@ static int
 vmx_virtual_intr_delivery_enabled(void)
 static void vmx_process_isr(int isr, struct vcpu *v)  {
     unsigned long status;
-    u8 old;
+    u8 old, i;

There is absolutely no point in i being u8 - this can be plain unsigned int.

It's ok to change it to unsigned int.

Quoted 14 lines
Quoted 7 lines
xen/arch/x86/hvm/vmx/vmx.c +2 -0
+    unsigned int *eoi_exit_bitmap, val;
+    struct vlapic *vlapic = vcpu_vlapic(v);
 
     if ( isr < 0 )
         isr = 0;
@@ -1597,6 +1599,29 @@ static void vmx_process_isr(int isr, struct

vcpu

*v)

Quoted 6 lines
         status |= isr << VMX_GUEST_INTR_STATUS_SVI_OFFSET;
         __vmwrite(GUEST_INTR_STATUS, status);
     }
xen/arch/x86/hvm/vmx/vmx.c +3 -0
+
+    eoi_exit_bitmap = (unsigned int
+ *)v->arch.hvm_vmx.eoi_exit_bitmap;
Quoted 8 lines
Quoted 2 lines
Quoted 2 lines

No casts like this please. This is a bitmap and would hence preferably be treated that way consistently. The code here isn't

performance critical.

Quoted 2 lines

Yes, it's performance critical from the live migration's point and that's why I use the cast here and

It is run once per vLAPIC on restore. I would not qualify it as performance critical, but I would also advocate the efficient method

Since the live migration is largely used in cloud, and the downtime of live migration is very important to cloud user. So it is worth to put the restore code path as performance critical area in future. BTW, I am working on KVM to reduce the downtime now.

Quoted 25 lines

of word accesses over the inefficient bit accesses where it makes sense.

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

+ /* + * We cannot simple copy the TMR as eoi exit bitmap due
to + the special + * periodic timer interrupt which is edge
trigger but need a mandatory + * EOI-induced VM exit to let
pending periodic timer + interrupts have the + * chance to be
injected for compensation. + * Here we will construct the eoi
exit bimap via (IRR | ISR). Though it + * may cause unnecessary
eoi exit of the interrupts that + pending in IRR or + * ISR
during save/resotre, each pending interrupt only + causes one vmexit.
+ * The subsequent interrupts will adjust the eoi exit bitmap

correctly.

Quoted 12 lines
Quoted 12 lines

So

xen/arch/x86/hvm/vmx/vmx.c static void vmx_process_isr(int isr, struct vcpu *v) · line 1615

Quoted 3 lines
xen/arch/x86/hvm/vmx/vmx.c +3 -0
+     * the performace hurt can be ingored.
+     */
+    for ( i = 0x10; i < 0x80; i += 0x10 )

So you skip the first 32 vectors instead of just the first 16. That's not in line with

the APIC definitions. Also basing the loop variable on APIC register numbers is kind of odd. I'd really suggest using something more natural, like vector space (which would also allow you to use existing helper functions/macros).

Quoted 7 lines
Quoted 4 lines

...skip the first 32 vectors and operates based on group instead vector

Also, Spec says "21-31 - Intel reserved. Do not use." So it's ok to skip them.

And what do you expect will happen to DoS guests which continue to use the legacy PICs?

I didn't get you point. Can you explain more?

Quoted 4 lines

This range cannot possibly be skipped.

~Andrew

Best regards,
Yang

#5 lore raw
In reply to Zhang, Yang Z
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 14.10.14 at 07:43, <[email protected]> wrote:

Jan Beulich wrote on 2014-10-13:

Quoted 10 lines

Review static void vmx_process_isr(int isr, struct vcpu

Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 11.10.14 at 09:54, <[email protected]> wrote:
(quoted diff) +0 -0
@@ -1597,6 +1599,29 @@ static void vmx_process_isr(int isr, struct vcpu

*v)

Quoted 6 lines
xen/arch/x86/hvm/vmx/vmx.c +3 -0
         status |= isr << VMX_GUEST_INTR_STATUS_SVI_OFFSET;
         __vmwrite(GUEST_INTR_STATUS, status);
     }
+
+    eoi_exit_bitmap = (unsigned int
+ *)v->arch.hvm_vmx.eoi_exit_bitmap;
Quoted 5 lines
Quoted 2 lines

No casts like this please. This is a bitmap and would hence preferably be treated that way consistently. The code here isn't performance critical.

Yes, it's performance critical from the live migration's point and that's why I use the cast here and

Compared to everything else involved in migration, a few extra cycles here surely don't matter at all. What does matter is maintainability of this already not always easy to understand code.

Quoted 23 lines
Quoted 13 lines

xen/arch/x86/hvm/vmx/vmx.c static void vmx_process_isr(int isr, struct vcpu *v)

Quoted 4 lines
xen/arch/x86/hvm/vmx/vmx.c +4 -0
+    /*
+     * We cannot simple copy the TMR as eoi exit bitmap due to the special
+     * periodic timer interrupt which is edge trigger but need a mandatory
+     * EOI-induced VM exit to let pending periodic timer interrupts have

the

xen/arch/x86/hvm/vmx/vmx.c static void vmx_process_isr(int isr, struct vcpu *v)

Quoted 3 lines
xen/arch/x86/hvm/vmx/vmx.c +3 -0
+     * chance to be injected for compensation.
+     * Here we will construct the eoi exit bimap via (IRR | ISR). Though it
+     * may cause unnecessary eoi exit of the interrupts that pending in IRR

or

Review static void vmx_process_isr(int isr, struct vcpu · line 1612

Quoted 1 line
(quoted diff) +1 -0
+     * ISR during save/resotre, each pending interrupt only causes one

vmexit.

Review static void vmx_process_isr(int isr, struct vcpu · line 1613

Quoted 1 line
(quoted diff) +1 -0
+     * The subsequent interrupts will adjust the eoi exit bitmap correctly.

So

Quoted 9 lines

xen/arch/x86/hvm/vmx/vmx.c static void vmx_process_isr(int isr, struct vcpu *v) · line 1615

Quoted 3 lines
xen/arch/x86/hvm/vmx/vmx.c +3 -0
+     * the performace hurt can be ingored.
+     */
+    for ( i = 0x10; i < 0x80; i += 0x10 )

So you skip the first 32 vectors instead of just the first 16. That's not in line with the APIC definitions. Also basing the loop variable on APIC register numbers is kind of odd. I'd really suggest using something more natural, like vector space (which would also allow you to use existing helper functions/macros).

Quoted 3 lines

...skip the first 32 vectors and operates based on group instead vector

Also, Spec says "21-31 - Intel reserved. Do not use." So it's ok to skip them.

Please distinguish APIC specification and CPU specification here. The APIC one only really precludes 0...15 to be used.

Quoted 10 lines
Quoted 5 lines

xen/arch/x86/hvm/vmx/vmx.c static void vmx_process_isr(int isr, struct vcpu *v) · line 1618

Quoted 3 lines
xen/arch/x86/hvm/vmx/vmx.c +3 -0
+    {
+        val = vlapic_get_reg(vlapic, APIC_IRR + i);
+        val |= vlapic_get_reg(vlapic, APIC_ISR + i);

The comment above doesn't really make clear why not just IRR.

Upon acceptance of an interrupt into the IRR, the corresponding TMR will be changed. This means an interrupt either in IRR or in ISR has no chance to update the TMR and eoi exit bitmap. So we need to check IRR + ISR while rebuilding the eoi exit bitmap. It is not enough to check only IRR.

But then why not look at TMR right away? It's being kept up to date as long as the guest is running, and gets migrated over afterwards. Considering what vmx_update_eoi_exit_bitmap()) does, you really want to or TMR into EOI_EXIT_BITMAP (which post-migration could just be an assignment rather than an or).

Jan

#6 lore raw

Jan Beulich wrote on 2014-10-14:

Quoted 13 lines
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 14.10.14 at 07:43, <[email protected]> wrote:

Jan Beulich wrote on 2014-10-13:

Quoted 11 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 11.10.14 at 09:54, <[email protected]> wrote:
(quoted diff) +0 -0
@@ -1597,6 +1599,29 @@ static void vmx_process_isr(int isr, struct

vcpu

*v)

Quoted 6 lines
         status |= isr << VMX_GUEST_INTR_STATUS_SVI_OFFSET;
         __vmwrite(GUEST_INTR_STATUS, status);
     }
(quoted diff) +3 -0
+
+    eoi_exit_bitmap = (unsigned int
+ *)v->arch.hvm_vmx.eoi_exit_bitmap;
Quoted 8 lines
Quoted 2 lines
Quoted 2 lines

No casts like this please. This is a bitmap and would hence preferably be treated that way consistently. The code here isn't

performance critical.

Quoted 3 lines

Yes, it's performance critical from the live migration's point and that's why I use the cast here and

Compared to everything else involved in migration, a few extra cycles here

Xen is far behind KVM on live migration. If we want to remain the competitive, I'd suggest doing a cleanup on current migration logic to make it more effective.

Quoted 34 lines

surely don't matter at all. What does matter is maintainability of this already not always easy to understand code.

Quoted 2 lines
Quoted 2 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+    /*
+     * We cannot simple copy the TMR as eoi exit bitmap due to the

special

Quoted 1 line
Quoted 1 line
Quoted 1 line

+ * periodic timer interrupt which is edge trigger but need a

mandatory

Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

+ * EOI-induced VM exit to let pending periodic timer
+ interrupts have

the

Quoted 2 lines
(quoted diff) +2 -0
+     * chance to be injected for compensation.
+     * Here we will construct the eoi exit bimap via (IRR | ISR). Though

it

Quoted 7 lines
Quoted 7 lines
Quoted 2 lines

+ * may cause unnecessary eoi exit of the interrupts that
+ pending in IRR

or

Quoted 2 lines

+ * ISR during save/resotre, each pending interrupt only causes
+ one

vmexit.

Quoted 1 line

+ * The subsequent interrupts will adjust the eoi exit bitmap

correctly.

Quoted 9 lines
Quoted 9 lines

So

xen/arch/x86/hvm/vmx/vmx.c static void vmx_process_isr(int isr, struct vcpu *v) · line 1615

Quoted 3 lines
xen/arch/x86/hvm/vmx/vmx.c +3 -0
+     * the performace hurt can be ingored.
+     */
+    for ( i = 0x10; i < 0x80; i += 0x10 )

So you skip the first 32 vectors instead of just the first 16. That's not in line with the APIC definitions. Also basing the loop variable on APIC register numbers is kind of odd. I'd really suggest using something more natural, like vector space (which would also allow you to

use existing helper functions/macros).

Quoted 2 lines
Quoted 1 line
Quoted 7 lines
Quoted 4 lines

...skip the first 32 vectors and operates based on group instead vector

Also, Spec says "21-31 - Intel reserved. Do not use." So it's ok to skip them.

Please distinguish APIC specification and CPU specification here. The APIC one only really precludes 0...15 to be used.

Ok. I will check the APIC specification.

Quoted 11 lines
Quoted 11 lines
Quoted 6 lines

xen/arch/x86/hvm/vmx/vmx.c static void vmx_process_isr(int isr, struct vcpu *v) · line 1618

Quoted 4 lines
xen/arch/x86/hvm/vmx/vmx.c +3 -0
+    {
+        val = vlapic_get_reg(vlapic, APIC_IRR + i);
+        val |= vlapic_get_reg(vlapic, APIC_ISR + i);

The comment above doesn't really make clear why not just IRR.

Upon acceptance of an interrupt into the IRR, the corresponding TMR will be changed. This means an interrupt either in IRR or in ISR has no chance to update the TMR and eoi exit bitmap. So we need to check IRR + ISR while rebuilding the eoi exit bitmap. It is not enough to check only

Quoted 7 lines

IRR.

But then why not look at TMR right away? It's being kept up to date as long as the guest is running, and gets migrated over afterwards. Considering what vmx_update_eoi_exit_bitmap()) does, you really want to or TMR into EOI_EXIT_BITMAP (which post-migration could just be an assignment rather than an or).

No, we cannot use TMR directly. As I said in the comments, the periodic timer interrupt is tricky which is edge-trigger but need an EOI vmexit to let the pending interrupts have the chance to be injected for compensation.

Quoted 2 lines

Jan

Best regards,
Yang

#7 lore raw
Quoted 19 lines
Quoted 1 line
Quoted 1 line · On 14.10.14 at 15:10, <[email protected]> wrote:

Jan Beulich wrote on 2014-10-14:

Quoted 17 lines
Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 14.10.14 at 07:43, <[email protected]> wrote:

Jan Beulich wrote on 2014-10-13:

Quoted 13 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 11.10.14 at 09:54, <[email protected]> wrote:
(quoted diff) +0 -0
@@ -1597,6 +1599,29 @@ static void vmx_process_isr(int isr, struct

vcpu

*v)

Review

Quoted 6 lines
         status |= isr << VMX_GUEST_INTR_STATUS_SVI_OFFSET;
         __vmwrite(GUEST_INTR_STATUS, status);
     }
(quoted diff) +3 -0
+
+    eoi_exit_bitmap = (unsigned int
+ *)v->arch.hvm_vmx.eoi_exit_bitmap;

No casts like this please. This is a bitmap and would hence preferably be treated that way consistently. The code here isn't

performance critical.

Quoted 1 line
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Yes, it's performance critical from the live migration's point and that's why I use the cast here and

Compared to everything else involved in migration, a few extra cycles here

Xen is far behind KVM on live migration. If we want to remain the competitive, I'd suggest doing a cleanup on current migration logic to make it more effective.

But that surely needs to be done elsewhere, where more than a couple of nanoseconds are to be gained.

Quoted 18 lines
Quoted 10 lines
Quoted 10 lines
Quoted 5 lines

xen/arch/x86/hvm/vmx/vmx.c static void vmx_process_isr(int isr, struct vcpu *v) · line 1618

Quoted 3 lines
xen/arch/x86/hvm/vmx/vmx.c +3 -0
+    {
+        val = vlapic_get_reg(vlapic, APIC_IRR + i);
+        val |= vlapic_get_reg(vlapic, APIC_ISR + i);

The comment above doesn't really make clear why not just IRR.

Upon acceptance of an interrupt into the IRR, the corresponding TMR will be changed. This means an interrupt either in IRR or in ISR has no chance to update the TMR and eoi exit bitmap. So we need to check IRR + ISR while rebuilding the eoi exit bitmap. It is not enough to check only

Quoted 7 lines

IRR.

But then why not look at TMR right away? It's being kept up to date as long as the guest is running, and gets migrated over afterwards. Considering what vmx_update_eoi_exit_bitmap()) does, you really want to or TMR into EOI_EXIT_BITMAP (which post-migration could just be an assignment rather than an or).

Quoted 3 lines

No, we cannot use TMR directly. As I said in the comments, the periodic timer interrupt is tricky which is edge-trigger but need an EOI vmexit to let the pending interrupts have the chance to be injected for compensation.

The respective "normal" (non-migration) handling of this being in vmx_intr_assist(), involving pt_vector? If so, I think I understand now.

Thanks, Jan

#8 lore raw

Jan Beulich wrote on 2014-10-14:

Quoted 25 lines
Quoted 25 lines
Quoted 1 line
Quoted 1 line · On 14.10.14 at 15:10, <[email protected]> wrote:

Jan Beulich wrote on 2014-10-14:

Quoted 22 lines
Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 14.10.14 at 07:43, <[email protected]> wrote:

Jan Beulich wrote on 2014-10-13:

Quoted 13 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 11.10.14 at 09:54, <[email protected]> wrote:
(quoted diff) +0 -0
@@ -1597,6 +1599,29 @@ static void vmx_process_isr(int isr,

struct vcpu

*v)

Review

Quoted 6 lines
         status |= isr << VMX_GUEST_INTR_STATUS_SVI_OFFSET;
         __vmwrite(GUEST_INTR_STATUS, status);
     }
(quoted diff) +3 -0
+
+    eoi_exit_bitmap = (unsigned int
+ *)v->arch.hvm_vmx.eoi_exit_bitmap;

No casts like this please. This is a bitmap and would hence preferably be treated that way consistently. The code here isn't

performance critical.

Quoted 3 lines

Yes, it's performance critical from the live migration's point and that's why I use the cast here and

Compared to everything else involved in migration, a few extra cycles here

Quoted 6 lines
Quoted 3 lines

Xen is far behind KVM on live migration. If we want to remain the competitive, I'd suggest doing a cleanup on current migration logic to make it more effective.

But that surely needs to be done elsewhere, where more than a couple of nanoseconds are to be gained.

If you think it is ok, I will use vector based operations:

+ for ( vector = 0x10; vector < NR_VECTORS; vector++ )
+ if (vlapic_test_vector(vector, &s->regs->data[APIC_IRR]) ||
+ vlapic_test_vector(vector, &s->regs->data[APIC_ISR]))
+ set_bit(vector, v->arch.hvm_vmx.eoi_exit_bitmap);

Andrew, is it ok for you?

Quoted 21 lines
Quoted 21 lines
Quoted 20 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
xen/arch/x86/hvm/vmx/vmx.c +3 -0
+    {
+        val = vlapic_get_reg(vlapic, APIC_IRR + i);
+        val |= vlapic_get_reg(vlapic, APIC_ISR + i);
Quoted 7 lines
Quoted 1 line

The comment above doesn't really make clear why not just IRR.

Upon acceptance of an interrupt into the IRR, the corresponding TMR will be changed. This means an interrupt either in IRR or in ISR has no chance to update the TMR and eoi exit bitmap. So we need to check IRR + ISR while rebuilding the eoi exit bitmap. It is not enough to check only

IRR.

But then why not look at TMR right away? It's being kept up to date as long as the guest is running, and gets migrated over afterwards. Considering what
vmx_update_eoi_exit_bitmap()) does, you really want to or TMR into EOI_EXIT_BITMAP (which post-migration could just be an assignment rather than an or).

Quoted 8 lines
Quoted 4 lines

No, we cannot use TMR directly. As I said in the comments, the periodic timer interrupt is tricky which is edge-trigger but need an EOI vmexit to let the pending interrupts have the chance to be injected for

compensation.

The respective "normal" (non-migration) handling of this being in vmx_intr_assist(), involving pt_vector? If so, I think I understand now.

Yes.

Quoted 2 lines

Thanks, Jan

Best regards,
Yang

#9 lore raw
Quoted 34 lines · Yang Z

Jan Beulich wrote on 2014-10-14:

Quoted 19 lines
Quoted 19 lines
Quoted 1 line
Quoted 1 line · On 14.10.14 at 15:10, <[email protected]> wrote:

Jan Beulich wrote on 2014-10-14:

Quoted 17 lines
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 14.10.14 at 07:43, <[email protected]> wrote:

Jan Beulich wrote on 2014-10-13:

Quoted 12 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 11.10.14 at 09:54, <[email protected]> wrote:
(quoted diff) +0 -0
@@ -1597,6 +1599,29 @@ static void vmx_process_isr(int isr,

struct vcpu

*v)

Review

Quoted 6 lines
         status |= isr << VMX_GUEST_INTR_STATUS_SVI_OFFSET;
         __vmwrite(GUEST_INTR_STATUS, status);
     }
(quoted diff) +3 -0
+
+    eoi_exit_bitmap = (unsigned int
+ *)v->arch.hvm_vmx.eoi_exit_bitmap;

No casts like this please. This is a bitmap and would hence preferably be treated that way consistently. The code here isn't

performance critical.

Quoted 2 lines

Yes, it's performance critical from the live migration's point and that's why I use the cast here and

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Compared to everything else involved in migration, a few extra cycles here

Xen is far behind KVM on live migration. If we want to remain the competitive, I'd suggest doing a cleanup on current migration logic to make it more effective.

But that surely needs to be done elsewhere, where more than a couple of nanoseconds are to be gained.

If you think it is ok, I will use vector based operations:

(quoted diff) +4 -0
+    for ( vector = 0x10; vector < NR_VECTORS; vector++ )
+        if (vlapic_test_vector(vector, &s->regs->data[APIC_IRR]) ||
+                vlapic_test_vector(vector, &s->regs->data[APIC_ISR]))
+            set_bit(vector,  v->arch.hvm_vmx.eoi_exit_bitmap);
Quoted 1 line

Andrew, is it ok for you?

That covers the appropriate vector range, (and getting a working fix is far more important than arguing its efficiency at this point in the release).

This looks fine to me.

#10 lore raw
In reply to Yang Zhang
Quoted 14 lines · Yang Zhang

From: Yang Zhang <[email protected]>

This patch fix two issues:

1. Interrupts on PIR are lost during save/restore. Syncing the PIR into IRR during save will fix it.

2. EOI exit bitmap doesn't setup correctly after restore. Here we will construct the eoi exit bimap via (IRR | ISR). Though it may cause unnecessary eoi exit of the interrupts that pending in IRR or ISR during save/resotre, each pending interrupt only causes one vmexit. The subsequent interrupts will adjust the eoi exit bitmap correctly. So the performace hurt can be ignored.

Quoted 8 lines

---
Hi Olaf and Malcolm, Can you help to retest it? Because the key part is changed in this patch, so i'm not sure whether it still works in your side.

Also, Olaf, is it ok to add your SOB in this patch? If yes, I can resend it to do it.

Yes, thats fine.

I have tested this version and save/restore still works with current staging.

Olaf