From: Razvan Cojocaru <rcojocaru@bitdefender.com>
To: "xen-devel@lists.xen.org" <xen-devel@lists.xen.org>
Subject: Getting the XSAVE size from userspace
Date: Thu, 5 Nov 2015 11:52:34 +0200 [thread overview]
Message-ID: <563B26E2.3070208@bitdefender.com> (raw)
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
next reply other threads:[~2015-11-05 9:52 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-05 9:52 Razvan Cojocaru [this message]
2015-11-05 10:42 ` Getting the XSAVE size from userspace Jan Beulich
2015-11-05 10:47 ` Razvan Cojocaru
2015-11-05 10:52 ` Jan Beulich
2015-11-05 10:53 ` Andrew Cooper
2015-11-05 10:49 ` Andrew Cooper
2015-11-05 10:51 ` Jan Beulich
2015-11-05 11:35 ` Andrei LUTAS
2015-11-05 11:44 ` Andrew Cooper
2015-11-05 12:26 ` Razvan Cojocaru
2015-11-05 14:05 ` Andrew Cooper
2015-11-05 14:13 ` Razvan Cojocaru
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=563B26E2.3070208@bitdefender.com \
--to=rcojocaru@bitdefender.com \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.