From mboxrd@z Thu Jan 1 00:00:00 1970 From: Razvan Cojocaru Subject: Getting the XSAVE size from userspace Date: Thu, 5 Nov 2015 11:52:34 +0200 Message-ID: <563B26E2.3070208@bitdefender.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: "xen-devel@lists.xen.org" List-Id: xen-devel@lists.xenproject.org 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