All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] x86/apicv: fix RTC periodic timer and apicv issue
@ 2016-12-16  9:40 Xuquan (Quan Xu)
  2016-12-20  5:37 ` Tian, Kevin
  0 siblings, 1 reply; 14+ messages in thread
From: Xuquan (Quan Xu) @ 2016-12-16  9:40 UTC (permalink / raw)
  To: xen-devel
  Cc: yang.zhang.wz, Lan Tianyu, Tian, Kevin, Nakajima, Jun,
	Andrew Cooper, George Dunlap, Xuquan (Quan Xu),
	Jan Beulich

[-- Attachment #1: Type: text/plain, Size: 3563 bytes --]

>From 89fffdd6b563b2723e24d17231715bb8c9f24f90 Mon Sep 17 00:00:00 2001
From: Quan Xu <xuquan8@huawei.com>
Date: Fri, 16 Dec 2016 17:24:01 +0800
Subject: [PATCH v3] x86/apicv: fix RTC periodic timer and apicv issue

When Xen apicv is enabled, wall clock time is faster on Windows7-32
guest with high payload (with 2vCPU, captured from xentrace, in
high payload, the count of IPI interrupt increases rapidly between
these vCPUs).

If IPI intrrupt (vector 0xe1) and periodic timer interrupt (vector 0xd1)
are both pending (index of bit set in vIRR), unfortunately, the IPI
intrrupt is high priority than periodic timer interrupt. Xen updates
IPI interrupt bit set in vIRR to guest interrupt status (RVI) as a high
priority and apicv (Virtual-Interrupt Delivery) delivers IPI interrupt
within VMX non-root operation without a VM-Exit. Within VMX non-root
operation, if periodic timer interrupt index of bit is set in vIRR and
highest, the apicv delivers periodic timer interrupt within VMX non-root
operation as well.

But in current code, if Xen doesn't update periodic timer interrupt bit
set in vIRR to guest interrupt status (RVI) directly, Xen is not aware
of this case to decrease the count (pending_intr_nr) of pending periodic
timer interrupt, then Xen will deliver a periodic timer interrupt again.

And that we update periodic timer interrupt in every VM-entry, there is
a chance that already-injected instance (before EOI-induced exit happens)
will incur another pending IRR setting if there is a VM-exit happens
between virtual interrupt injection (vIRR->0, vISR->1) and EOI-induced
exit (vISR->0), since pt_intr_post hasn't been invoked yet, then the
guest receives more periodic timer interrupt.

So we set eoi_exit_bitmap for intack.vector when it's higher than
pending periodic time interrupts. This way we can guarantee there's
always a chance to post periodic time interrupts when periodic time
interrupts becomes the highest one.

Signed-off-by: Quan Xu <xuquan8@huawei.com>
---
 xen/arch/x86/hvm/vmx/intr.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/xen/arch/x86/hvm/vmx/intr.c b/xen/arch/x86/hvm/vmx/intr.c
index 639a705..d7a5716 100644
--- a/xen/arch/x86/hvm/vmx/intr.c
+++ b/xen/arch/x86/hvm/vmx/intr.c
@@ -315,9 +315,17 @@ void vmx_intr_assist(void)
         * Set eoi_exit_bitmap for periodic timer interrup to cause EOI-induced VM
         * exit, then pending periodic time interrups have the chance to be injected
         * for compensation
+        * Set eoi_exit_bitmap for intack.vector when it's higher than pending
+        * periodic time interrupts. This way we can guarantee there's always a chance
+        * to post periodic time interrupts when periodic time interrupts becomes the
+        * highest one
         */
-        if (pt_vector != -1)
-            vmx_set_eoi_exit_bitmap(v, pt_vector);
+        if ( pt_vector != -1 ) {
+            if ( intack.vector > pt_vector )
+                vmx_set_eoi_exit_bitmap(v, intack.vector);
+            else
+                vmx_set_eoi_exit_bitmap(v, pt_vector);
+        }

         /* we need update the RVI field */
         __vmread(GUEST_INTR_STATUS, &status);
@@ -334,7 +342,8 @@ void vmx_intr_assist(void)
             __vmwrite(EOI_EXIT_BITMAP(i), v->arch.hvm_vmx.eoi_exit_bitmap[i]);
         }

-        pt_intr_post(v, intack);
+        if ( intack.vector == pt_vector )
+            pt_intr_post(v, intack);
     }
     else
     {
--
1.7.12.4

[-- Attachment #2: 0001-x86-apicv-fix-RTC-periodic-timer-and-apicv-issue.patch --]
[-- Type: application/octet-stream, Size: 3488 bytes --]

From 89fffdd6b563b2723e24d17231715bb8c9f24f90 Mon Sep 17 00:00:00 2001
From: Quan Xu <xuquan8@huawei.com>
Date: Fri, 16 Dec 2016 17:24:01 +0800
Subject: [PATCH v3] x86/apicv: fix RTC periodic timer and apicv issue

When Xen apicv is enabled, wall clock time is faster on Windows7-32
guest with high payload (with 2vCPU, captured from xentrace, in
high payload, the count of IPI interrupt increases rapidly between
these vCPUs).

If IPI intrrupt (vector 0xe1) and periodic timer interrupt (vector 0xd1)
are both pending (index of bit set in vIRR), unfortunately, the IPI
intrrupt is high priority than periodic timer interrupt. Xen updates
IPI interrupt bit set in vIRR to guest interrupt status (RVI) as a high
priority and apicv (Virtual-Interrupt Delivery) delivers IPI interrupt
within VMX non-root operation without a VM-Exit. Within VMX non-root
operation, if periodic timer interrupt index of bit is set in vIRR and
highest, the apicv delivers periodic timer interrupt within VMX non-root
operation as well.

But in current code, if Xen doesn't update periodic timer interrupt bit
set in vIRR to guest interrupt status (RVI) directly, Xen is not aware
of this case to decrease the count (pending_intr_nr) of pending periodic
timer interrupt, then Xen will deliver a periodic timer interrupt again.

And that we update periodic timer interrupt in every VM-entry, there is
a chance that already-injected instance (before EOI-induced exit happens)
will incur another pending IRR setting if there is a VM-exit happens
between virtual interrupt injection (vIRR->0, vISR->1) and EOI-induced
exit (vISR->0), since pt_intr_post hasn't been invoked yet, then the
guest receives more periodic timer interrupt.

So we set eoi_exit_bitmap for intack.vector when it's higher than
pending periodic time interrupts. This way we can guarantee there's
always a chance to post periodic time interrupts when periodic time
interrupts becomes the highest one.

Signed-off-by: Quan Xu <xuquan8@huawei.com>
---
 xen/arch/x86/hvm/vmx/intr.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/xen/arch/x86/hvm/vmx/intr.c b/xen/arch/x86/hvm/vmx/intr.c
index 639a705..d7a5716 100644
--- a/xen/arch/x86/hvm/vmx/intr.c
+++ b/xen/arch/x86/hvm/vmx/intr.c
@@ -315,9 +315,17 @@ void vmx_intr_assist(void)
         * Set eoi_exit_bitmap for periodic timer interrup to cause EOI-induced VM
         * exit, then pending periodic time interrups have the chance to be injected
         * for compensation
+        * Set eoi_exit_bitmap for intack.vector when it's higher than pending
+        * periodic time interrupts. This way we can guarantee there's always a chance
+        * to post periodic time interrupts when periodic time interrupts becomes the
+        * highest one
         */
-        if (pt_vector != -1)
-            vmx_set_eoi_exit_bitmap(v, pt_vector);
+        if ( pt_vector != -1 ) {
+            if ( intack.vector > pt_vector )
+                vmx_set_eoi_exit_bitmap(v, intack.vector);
+            else
+                vmx_set_eoi_exit_bitmap(v, pt_vector);
+        }
 
         /* we need update the RVI field */
         __vmread(GUEST_INTR_STATUS, &status);
@@ -334,7 +342,8 @@ void vmx_intr_assist(void)
             __vmwrite(EOI_EXIT_BITMAP(i), v->arch.hvm_vmx.eoi_exit_bitmap[i]);
         }
 
-        pt_intr_post(v, intack);
+        if ( intack.vector == pt_vector )
+            pt_intr_post(v, intack);
     }
     else
     {
-- 
1.7.12.4


[-- Attachment #3: Type: text/plain, Size: 127 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

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

end of thread, other threads:[~2016-12-21  4:59 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-16  9:40 [PATCH v3] x86/apicv: fix RTC periodic timer and apicv issue Xuquan (Quan Xu)
2016-12-20  5:37 ` Tian, Kevin
2016-12-20  5:54   ` Xuquan (Quan Xu)
2016-12-20  8:32     ` Jan Beulich
2016-12-20  9:38       ` Xuquan (Quan Xu)
2016-12-20  9:57         ` Jan Beulich
2016-12-21  2:32         ` Tian, Kevin
2016-12-20  8:34   ` Jan Beulich
2016-12-20  8:53     ` Tian, Kevin
2016-12-20  8:57       ` Jan Beulich
2016-12-20  9:33       ` Xuquan (Quan Xu)
2016-12-20 13:12   ` Xuquan (Quan Xu)
2016-12-21  2:29     ` Tian, Kevin
2016-12-21  4:59       ` Xuquan (Quan Xu)

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