[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH] x86/hvm/viridian: save APIC assist vector



If any vcpu has a pending APIC assist when the domain is suspended
then the vector needs to be saved. If this is not done then it's
possible for the vector to remain pending in the vlapic ISR
indefinitely after resume.

This patch adds code to save the APIC assist vector value in the
viridian vcpu save record. This means that the record is now zero-
extended on load and, because this implies a loaded value of
zero means nothing is pending (for backwards compatibility with
hosts not implementing APIC assist), the rest of the viridian APIC
assist code is adjusted to treat a zero value in this way.

Signed-off-by: Paul Durrant <paul.durrant@xxxxxxxxxx>
Cc: Jan Beulich <jbeulich@xxxxxxxx>
---
 xen/arch/x86/hvm/viridian.c            | 27 ++++++++++++++++++---------
 xen/include/public/arch-x86/hvm/save.h |  3 ++-
 2 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/xen/arch/x86/hvm/viridian.c b/xen/arch/x86/hvm/viridian.c
index 410320c..8e858d2 100644
--- a/xen/arch/x86/hvm/viridian.c
+++ b/xen/arch/x86/hvm/viridian.c
@@ -252,7 +252,6 @@ static void initialize_apic_assist(struct vcpu *v)
     if ( viridian_feature_mask(v->domain) & HVMPV_apic_assist )
     {
         v->arch.hvm_vcpu.viridian.apic_assist.va = va;
-        v->arch.hvm_vcpu.viridian.apic_assist.vector = -1;
         return;
     }
 
@@ -293,10 +292,11 @@ void viridian_start_apic_assist(struct vcpu *v, int 
vector)
      * wrong and the VM will most likely hang so force a crash now
      * to make the problem clear.
      */
-    if ( v->arch.hvm_vcpu.viridian.apic_assist.vector >= 0 )
+    if ( v->arch.hvm_vcpu.viridian.apic_assist.vector != 0 )
         domain_crash(v->domain);
 
-    v->arch.hvm_vcpu.viridian.apic_assist.vector = vector;
+    /* Increment the value so that zero is always invalid. */
+    v->arch.hvm_vcpu.viridian.apic_assist.vector = vector + 1;
     *va |= 1u;
 }
 
@@ -311,8 +311,8 @@ int viridian_complete_apic_assist(struct vcpu *v)
     if ( *va & 1u )
         return -1; /* Interrupt not yet processed by the guest. */
 
-    vector = v->arch.hvm_vcpu.viridian.apic_assist.vector;
-    v->arch.hvm_vcpu.viridian.apic_assist.vector = -1;
+    vector = v->arch.hvm_vcpu.viridian.apic_assist.vector - 1;
+    v->arch.hvm_vcpu.viridian.apic_assist.vector = 0;
 
     return vector;
 }
@@ -325,7 +325,7 @@ void viridian_abort_apic_assist(struct vcpu *v)
         return;
 
     *va &= ~1u;
-    v->arch.hvm_vcpu.viridian.apic_assist.vector = -1;
+    v->arch.hvm_vcpu.viridian.apic_assist.vector = 0;
 }
 
 static void update_reference_tsc(struct domain *d, bool_t initialize)
@@ -806,7 +806,8 @@ static int viridian_save_vcpu_ctxt(struct domain *d, 
hvm_domain_context_t *h)
     for_each_vcpu( d, v ) {
         struct hvm_viridian_vcpu_context ctxt;
 
-        ctxt.apic_assist = v->arch.hvm_vcpu.viridian.apic_assist.msr.raw;
+        ctxt.apic_assist_msr = v->arch.hvm_vcpu.viridian.apic_assist.msr.raw;
+        ctxt.apic_assist_vector = v->arch.hvm_vcpu.viridian.apic_assist.vector;
 
         if ( hvm_save_entry(VIRIDIAN_VCPU, v->vcpu_id, h, &ctxt) != 0 )
             return 1;
@@ -829,13 +830,21 @@ static int viridian_load_vcpu_ctxt(struct domain *d, 
hvm_domain_context_t *h)
         return -EINVAL;
     }
 
-    if ( hvm_load_entry(VIRIDIAN_VCPU, h, &ctxt) != 0 )
+    if ( hvm_load_entry_zeroextend(VIRIDIAN_VCPU, h, &ctxt) != 0 )
         return -EINVAL;
 
-    v->arch.hvm_vcpu.viridian.apic_assist.msr.raw = ctxt.apic_assist;
+    v->arch.hvm_vcpu.viridian.apic_assist.msr.raw = ctxt.apic_assist_msr;
     if ( v->arch.hvm_vcpu.viridian.apic_assist.msr.fields.enabled )
         initialize_apic_assist(v);
 
+    /*
+     * Guests that were saved on a host that did not use APIC assist
+     * will clearly never have a pending assist, so reading the zero
+     * value for apic_assist_vector from the zero extended save record
+     * will always be correct.
+     */
+    v->arch.hvm_vcpu.viridian.apic_assist.vector = ctxt.apic_assist_vector;
+
     return 0;
 }
 
diff --git a/xen/include/public/arch-x86/hvm/save.h 
b/xen/include/public/arch-x86/hvm/save.h
index fbd1c6a..fc8e8f9 100644
--- a/xen/include/public/arch-x86/hvm/save.h
+++ b/xen/include/public/arch-x86/hvm/save.h
@@ -588,7 +588,8 @@ struct hvm_viridian_domain_context {
 DECLARE_HVM_SAVE_TYPE(VIRIDIAN_DOMAIN, 15, struct hvm_viridian_domain_context);
 
 struct hvm_viridian_vcpu_context {
-    uint64_t apic_assist;
+    uint64_t apic_assist_msr;
+    uint16_t apic_assist_vector;
 };
 
 DECLARE_HVM_SAVE_TYPE(VIRIDIAN_VCPU, 17, struct hvm_viridian_vcpu_context);
-- 
2.1.4


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

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.