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

[PATCH] x86/hvm: Don't save or load HVM context of a domain with no vCPUs



XEN_DOMCTL_createdomain allocates d->vcpu[] but the vCPUs themselves are
only created by a later XEN_DOMCTL_max_vcpus.  In that window
XEN_DOMCTL_gethvmcontext{,_partial} on the domain reach the per-domain
save handlers with d->vcpu[0] == NULL.  A dom0 tool polling xen-hvmctx
across all domains while a VM was being restored took the host down:

  (XEN) HVM d25 save: PIC
  (XEN) RIP:    e008:[<ffff82d04030dc98>] arch/x86/hvm/vpic.c#vpic_save+0x8/0x8f
  (XEN) rdi: 0000000000000000
  (XEN) Xen call trace:
  (XEN)    [<ffff82d04030dc98>] R arch/x86/hvm/vpic.c#vpic_save+0x8/0x8f
  (XEN)    [<ffff82d04021009f>] S arch/x86/hvm/save.c#hvm_save.cold+0x9b/0xf7
  (XEN)    [<ffff82d04036d99c>] S arch_do_domctl+0x1a2c/0x28a6
  (XEN)    [<ffff82d04025341a>] S do_domctl+0x139a/0x1642
  (XEN)    [<ffff82d04033331e>] S pv_hypercall+0x3ae/0x59a
  (XEN)    [<ffff82d0402003b5>] S lstar_enter+0x105/0x10a
  (XEN)
  (XEN) Panic on CPU 0:
  (XEN) FATAL PAGE FAULT
  (XEN) [error_code=0000]
  (XEN) Faulting linear address: 0000000000000018

XEN_DOMCTL_sethvmcontext has the same problem on the load side, e.g.
pit_load() uses d->vcpu[0] for the guest time.

Refuse to save or load the whole context until vCPU 0 exists, and look up
the vCPU in hvm_save_one() with domain_vcpu(), failing with -ENOENT as
for other absent vCPUs.

Fixes: d0d8980138c4 ("x86/hvm: remove redundant save functions")
Assisted-by: Claude:claude-opus-5
Signed-off-by: Lin Liu <lin.liu01@xxxxxxxxxx>
---
 xen/arch/x86/hvm/save.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/xen/arch/x86/hvm/save.c b/xen/arch/x86/hvm/save.c
index 8ab6405706..48f8229061 100644
--- a/xen/arch/x86/hvm/save.c
+++ b/xen/arch/x86/hvm/save.c
@@ -139,12 +139,11 @@ int hvm_save_one(struct domain *d, unsigned int typecode, 
unsigned int instance,
          !hvm_sr_handlers[typecode].save )
         return -EINVAL;
 
-    if ( hvm_sr_handlers[typecode].kind != HVMSR_PER_VCPU )
-        v = d->vcpu[0];
-    else if ( instance >= d->max_vcpus || !d->vcpu[instance] )
+    /* Per-domain records are saved via vCPU 0, absent before max_vcpus. */
+    v = domain_vcpu(d, hvm_sr_handlers[typecode].kind == HVMSR_PER_VCPU
+                       ? instance : 0);
+    if ( !v )
         return -ENOENT;
-    else
-        v = d->vcpu[instance];
     ctxt.size = hvm_sr_handlers[typecode].size;
     ctxt.data = xmalloc_bytes(ctxt.size);
     if ( !ctxt.data )
@@ -203,7 +202,8 @@ int hvm_save(struct domain *d, hvm_domain_context_t *h)
     struct hvm_save_end end;
     unsigned int i;
 
-    if ( d->is_dying )
+    /* Per-domain handlers are passed vCPU 0. */
+    if ( d->is_dying || !d->vcpu[0] )
         return -EINVAL;
 
     hdr.magic = HVM_FILE_MAGIC;
@@ -291,7 +291,8 @@ int hvm_load(struct domain *d, bool real, 
hvm_domain_context_t *h)
     struct hvm_save_descriptor *desc;
     int rc;
 
-    if ( d->is_dying )
+    /* Some per-domain loaders use vCPU 0. */
+    if ( d->is_dying || !d->vcpu[0] )
         return -EINVAL;
 
     /* Get at the save header, which must be first */
-- 
2.52.0




 


Rackspace

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