Hello,

I need to get the XSAVE size from userspace. The easiest way seems to be
to use the XEN_DOMCTL_getvcpuextstate hypercall, but that hypercall is
not public / there's no xenctrl.h wrapper for it.

There's also struct hvm_hw_cpu_xsave, which I can get to, but it doesn't
have a size member:

542 /*
543  * The save area of XSAVE/XRSTOR.
544  */
545
546 struct hvm_hw_cpu_xsave {
547     uint64_t xfeature_mask;        /* Ignored */
548     uint64_t xcr0;                 /* Updated by XSETBV */
549     uint64_t xcr0_accum;           /* Updated by XSETBV */
550     struct {
551         struct { char x[512]; } fpu_sse;
552
553         struct {
554             uint64_t xstate_bv;         /* Updated by XRSTOR */
555             uint64_t reserved[7];
556         } xsave_hdr;                    /* The 64-byte header */
557
558         struct { char x[0]; } ymm;    /* YMM */
559     } save_area;
560 };

I see that in the hypervisor code the length is computed by using the
HVM_CPU_XSAVE_SIZE() macro:

2126 #define HVM_CPU_XSAVE_SIZE(xcr0) (offsetof(struct hvm_hw_cpu_xsave, \
2127                                            save_area) + \
2128                                   xstate_ctxt_size(xcr0))

where:

256 static unsigned int _xstate_ctxt_size(u64 xcr0)
257 {
258     u64 act_xcr0 = get_xcr0();
259     u32 eax, ebx = 0, ecx, edx;
260     bool_t ok = set_xcr0(xcr0);
261
262     ASSERT(ok);
263     cpuid_count(XSTATE_CPUID, 0, &eax, &ebx, &ecx, &edx);
264     ASSERT(ebx <= ecx);
265     ok = set_xcr0(act_xcr0);
266     ASSERT(ok);
267
268     return ebx;
269 }
270
271 /* Fastpath for common xstate size requests, avoiding reloads of
xcr0. */
272 unsigned int xstate_ctxt_size(u64 xcr0)
273 {
274     if ( xcr0 == xfeature_mask )
275         return xsave_cntxt_size;
276
277     if ( xcr0 == 0 )
278         return 0;
279
280     return _xstate_ctxt_size(xcr0);
281 }

But that doesn't seem to translate cleanly to userspace code.

I had hoped that I would be able to get this with no custom Xen patches,
is there a simpler way I'm not aware of to get to this information? And
if there isn't, would you prefer a libxc patch that exposes
XEN_DOMCTL_getvcpuextstate, or one that adds a size member to struct
hvm_hw_cpu_xsave (I'd guess the latter)?


Thanks,
Razvan

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

Reply via email to