xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] x86/hvm: implement save/restore for posted interrupts
@ 2014-07-03 15:09 Olaf Hering
  2014-07-03 15:27 ` Jan Beulich
                   ` (2 more replies)
  0 siblings, 3 replies; 60+ messages in thread
From: Olaf Hering @ 2014-07-03 15:09 UTC (permalink / raw)
  To: xen-devel
  Cc: Kevin Tian, Keir Fraser, Jan Beulich, Eddie Dong, Olaf Hering,
	Dongxiao Xu, Jun Nakajima

Saving and restoring a PVonHVM guest on a host which has the VMX
"Posted Interrupt Processing" feature enabled will fail because the
xen-platform-pci device does not receive interrupts anymore after
restore. The reason is that the IRQs are not maintained in APIC_IRR,
but in a separate PIR array. This info is lost during the save
operation.

Syncing the PIR state into IRR during save, and restoring the state
later will fix 'xm save/restore' of a PVonHVM guest.

Signed-off-by: Olaf Hering <olaf@aepfle.de>
---

Jan suggested to use the TMR flag to set 'trig' for vlapic_set_irq.
We are not sure if thats the correct approach, instead of forcing
trig=1. 
Comments are welcome.


 xen/arch/x86/hvm/vlapic.c        |  4 ++++
 xen/arch/x86/hvm/vmx/vmx.c       | 14 ++++++++++++++
 xen/include/asm-x86/hvm/hvm.h    |  1 +
 xen/include/asm-x86/hvm/vlapic.h |  2 ++
 4 files changed, 21 insertions(+)

diff --git a/xen/arch/x86/hvm/vlapic.c b/xen/arch/x86/hvm/vlapic.c
index cd7e872..7201544 100644
--- a/xen/arch/x86/hvm/vlapic.c
+++ b/xen/arch/x86/hvm/vlapic.c
@@ -1179,6 +1179,8 @@ 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;
@@ -1230,6 +1232,8 @@ static int lapic_load_regs(struct domain *d, hvm_domain_context_t *h)
     if ( hvm_load_entry(LAPIC_REGS, h, s->regs) != 0 ) 
         return -EINVAL;
 
+    if ( hvm_funcs.sync_irr_to_pir )
+        hvm_funcs.sync_irr_to_pir(v);
     if ( hvm_funcs.process_isr )
         hvm_funcs.process_isr(vlapic_find_highest_isr(s), v);
 
diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c
index 2caa04a..85df77d 100644
--- a/xen/arch/x86/hvm/vmx/vmx.c
+++ b/xen/arch/x86/hvm/vmx/vmx.c
@@ -1654,6 +1654,18 @@ static void vmx_sync_pir_to_irr(struct vcpu *v)
         vlapic_set_vector(i, &vlapic->regs->data[APIC_IRR]);
 }
 
+static void vmx_sync_irr_to_pir(struct vcpu *v)
+{
+    struct vlapic *vlapic = vcpu_vlapic(v);
+    unsigned int vector;
+
+    for ( vector = 0; vector < NR_VECTORS; vector++ ) {
+        if ( vlapic_test_vector(vector, &vlapic->regs->data[APIC_IRR]) )
+            vlapic_set_irq(vlapic, vector,
+                    vlapic_test_vector(vector, &vlapic->regs->data[APIC_TMR]));
+    }
+}
+
 static void vmx_handle_eoi(u8 vector)
 {
     unsigned long status;
@@ -1737,6 +1749,7 @@ static struct hvm_function_table __initdata vmx_function_table = {
     .process_isr          = vmx_process_isr,
     .deliver_posted_intr  = vmx_deliver_posted_intr,
     .sync_pir_to_irr      = vmx_sync_pir_to_irr,
+    .sync_irr_to_pir      = vmx_sync_irr_to_pir,
     .handle_eoi           = vmx_handle_eoi,
     .nhvm_hap_walk_L1_p2m = nvmx_hap_walk_L1_p2m,
     .hypervisor_cpuid_leaf = vmx_hypervisor_cpuid_leaf,
@@ -1783,6 +1796,7 @@ const struct hvm_function_table * __init start_vmx(void)
     {
         vmx_function_table.deliver_posted_intr = NULL;
         vmx_function_table.sync_pir_to_irr = NULL;
+        vmx_function_table.sync_irr_to_pir = NULL;
     }
 
     if ( cpu_has_vmx_ept
diff --git a/xen/include/asm-x86/hvm/hvm.h b/xen/include/asm-x86/hvm/hvm.h
index 0ebd478..c762f1e 100644
--- a/xen/include/asm-x86/hvm/hvm.h
+++ b/xen/include/asm-x86/hvm/hvm.h
@@ -194,6 +194,7 @@ struct hvm_function_table {
     void (*process_isr)(int isr, struct vcpu *v);
     void (*deliver_posted_intr)(struct vcpu *v, u8 vector);
     void (*sync_pir_to_irr)(struct vcpu *v);
+    void (*sync_irr_to_pir)(struct vcpu *v);
     void (*handle_eoi)(u8 vector);
 
     /*Walk nested p2m  */
diff --git a/xen/include/asm-x86/hvm/vlapic.h b/xen/include/asm-x86/hvm/vlapic.h
index 66f0aff..2a83a1e 100644
--- a/xen/include/asm-x86/hvm/vlapic.h
+++ b/xen/include/asm-x86/hvm/vlapic.h
@@ -58,6 +58,8 @@
 
 #define VEC_POS(v) ((v) % 32)
 #define REG_POS(v) (((v) / 32) * 0x10)
+#define vlapic_test_vector(vec, bitmap)                         \
+    test_bit(VEC_POS(vec), (uint32_t *)((bitmap) + REG_POS(vec)))
 #define vlapic_test_and_set_vector(vec, bitmap)                         \
     test_and_set_bit(VEC_POS(vec), (uint32_t *)((bitmap) + REG_POS(vec)))
 #define vlapic_test_and_clear_vector(vec, bitmap)                       \

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

end of thread, other threads:[~2014-10-10  0:52 UTC | newest]

Thread overview: 60+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-03 15:09 [PATCH] x86/hvm: implement save/restore for posted interrupts Olaf Hering
2014-07-03 15:27 ` Jan Beulich
2014-07-09 11:24 ` Zhang, Yang Z
2014-07-09 21:14   ` Tian, Kevin
2014-07-16 14:28     ` Olaf Hering
2014-07-16 16:11       ` Tian, Kevin
2014-07-17  7:11         ` Olaf Hering
2014-07-17  9:29           ` Zhang, Yang Z
2014-07-18 13:58             ` Olaf Hering
2014-07-22 23:06               ` Zhang, Yang Z
2014-07-23  8:03                 ` Olaf Hering
2014-07-25 21:38             ` Tian, Kevin
2014-07-28  6:52               ` Olaf Hering
2014-07-29  7:48                 ` Zhang, Yang Z
2014-07-29  8:27                   ` Jan Beulich
2014-08-02 10:59                   ` Olaf Hering
2014-08-04  1:08                     ` Zhang, Yang Z
2014-08-04  7:50                       ` Olaf Hering
2014-08-04  7:57                         ` Zhang, Yang Z
2014-08-05 10:32                           ` Olaf Hering
2014-08-08  0:18                             ` Zhang, Yang Z
2014-09-01  6:44                             ` Zhang, Yang Z
2014-09-18  3:29                             ` Zhang, Yang Z
2014-09-19 13:32                               ` Olaf Hering
2014-09-19 13:39                                 ` Jan Beulich
2014-09-19 17:51                                   ` Andrew Cooper
2014-09-22 22:43                                     ` Tian, Kevin
2014-09-24 16:26                                       ` Malcolm Crossley
2014-09-30 16:19                                 ` Jan Beulich
2014-10-01  8:07                                   ` Olaf Hering
2014-10-01  8:29                                     ` Jan Beulich
2014-10-01 20:13                                       ` Olaf Hering
2014-10-02  6:51                                         ` Jan Beulich
2014-10-02  8:10                                           ` Andrew Cooper
2014-10-02  8:20                                             ` Olaf Hering
2014-10-08  7:37                                         ` Zhang, Yang Z
2014-10-08  7:40                                           ` Olaf Hering
2014-10-08  7:55                                             ` Zhang, Yang Z
2014-10-08  8:28                                           ` Olaf Hering
2014-10-08  8:35                                             ` Zhang, Yang Z
2014-10-08  8:54                                               ` Olaf Hering
2014-10-09  7:24                                                 ` Zhang, Yang Z
2014-10-09  8:41                                                   ` Fabio Fantoni
2014-10-09  8:43                                                     ` Zhang, Yang Z
2014-10-09 12:49                                                       ` Fabio Fantoni
2014-10-09 11:35                                                   ` Malcolm Crossley
2014-10-09 13:19                                                   ` Andrew Cooper
2014-10-10  0:48                                                     ` Zhang, Yang Z
2014-10-09 13:31                                                   ` Olaf Hering
2014-10-09 14:11                                                     ` Olaf Hering
2014-10-10  0:52                                                       ` Zhang, Yang Z
2014-07-25  9:40 ` Jan Beulich
2014-07-25 12:49   ` Tian, Kevin
2014-07-25 13:59     ` Jan Beulich
2014-07-25 21:31       ` Tian, Kevin
2014-07-28  6:46         ` Jan Beulich
2014-07-28  7:52           ` Wu, Feng
2014-07-28  8:17           ` Zhang, Yang Z
2014-07-28  9:02             ` Jan Beulich
2014-07-28  9:50               ` Liuqiming (John)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).