diff -r bc9b31af8865 tools/libxc/xc_domain_save.c --- a/tools/libxc/xc_domain_save.c Mon Nov 08 15:13:56 2010 -0500 +++ b/tools/libxc/xc_domain_save.c Mon Nov 08 15:26:34 2010 -0500 @@ -827,7 +827,9 @@ static xen_pfn_t *map_and_save_p2m_table } xcnt_size = domctl.u.vcpuextstate.size + 2 * sizeof(uint64_t); - tot_sz = (chunk1_sz + 8) + (chunk2_sz + 8) + (chunk3_sz + 8); + tot_sz = (chunk1_sz + 8) + (chunk2_sz + 8); + if ( domctl.u.vcpuextstate.xfeature_mask ) + tot_sz += chunk3_sz + 8; if ( write_exact(io_fd, &signature, sizeof(signature)) || write_exact(io_fd, &tot_sz, sizeof(tot_sz)) || @@ -836,9 +838,11 @@ static xen_pfn_t *map_and_save_p2m_table write_exact(io_fd, &ctxt, chunk1_sz) || write_exact(io_fd, "extv", 4) || write_exact(io_fd, &chunk2_sz, sizeof(chunk2_sz)) || - write_exact(io_fd, "xcnt", 4) || - write_exact(io_fd, &chunk3_sz, sizeof(chunk3_sz)) || - write_exact(io_fd, &xcnt_size, 4) ) + (domctl.u.vcpuextstate.xfeature_mask) ? + (write_exact(io_fd, "xcnt", 4) || + write_exact(io_fd, &chunk3_sz, sizeof(chunk3_sz)) || + write_exact(io_fd, &xcnt_size, 4)) : + 0 ) { PERROR("write: extended info"); goto out; @@ -1824,6 +1828,9 @@ int xc_domain_save(xc_interface *xch, in goto out; } + if ( !domctl.u.vcpuextstate.xfeature_mask ) + continue; + /* Getting eXtended states data */ buffer = xc_hypercall_buffer_alloc(xch, buffer, domctl.u.vcpuextstate.size); if ( !buffer ) @@ -1836,24 +1843,18 @@ int xc_domain_save(xc_interface *xch, in if ( xc_domctl(xch, &domctl) < 0 ) { PERROR("No eXtended states (XSAVE) for VCPU%d", i); + xc_hypercall_buffer_free(xch, buffer); goto out; } if ( wrexact(io_fd, &domctl.u.vcpuextstate.xfeature_mask, - sizeof(domctl.u.vcpuextstate.xfeature_mask)) ) - { - PERROR("Error when writing to state file (2)"); - goto out; - } - if ( wrexact(io_fd, &domctl.u.vcpuextstate.size, - sizeof(domctl.u.vcpuextstate.size)) ) - { - PERROR("Error when writing to state file (2)"); - goto out; - } - if ( wrexact(io_fd, buffer, domctl.u.vcpuextstate.size) ) - { - PERROR("Error when writing to state file (2)"); + sizeof(domctl.u.vcpuextstate.xfeature_mask)) || + wrexact(io_fd, &domctl.u.vcpuextstate.size, + sizeof(domctl.u.vcpuextstate.size)) || + wrexact(io_fd, buffer, domctl.u.vcpuextstate.size) ) + { + PERROR("Error when writing to state file VCPU extended state"); + xc_hypercall_buffer_free(xch, buffer); goto out; } xc_hypercall_buffer_free(xch, buffer); diff -r bc9b31af8865 xen/arch/x86/domctl.c --- a/xen/arch/x86/domctl.c Mon Nov 08 15:13:56 2010 -0500 +++ b/xen/arch/x86/domctl.c Mon Nov 08 15:14:50 2010 -0500 @@ -1424,9 +1424,6 @@ long arch_do_domctl( ret = -ESRCH; - if ( !cpu_has_xsave ) - break; - d = rcu_lock_domain_by_id(domctl->domain); if ( d == NULL ) break;