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

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



commit a2c44636b17816ebee5e6f156f2d4d67f76a9400
Author:     Lin Liu <lin.liu01@xxxxxxxxxx>
AuthorDate: Wed Nov 25 14:35:10 2026 +0100
Commit:     Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Wed Nov 25 14:35:10 2026 +0100

    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>
    Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>
    Reviewed-by: Teddy Astie <teddy.astie@xxxxxxxxxx>
    master commit: 811d4c7a283b81ab18c42edceeb2173f86e64e8b
    master date: 2026-11-19 10:38:04 +0100
---
 xen/arch/x86/hvm/save.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/xen/arch/x86/hvm/save.c b/xen/arch/x86/hvm/save.c
index 8ab6405706..f300c8ac2a 100644
--- a/xen/arch/x86/hvm/save.c
+++ b/xen/arch/x86/hvm/save.c
@@ -139,12 +139,12 @@ 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 +203,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 +292,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 */
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.22



 


Rackspace

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