libxc/x86: XSAVE related adjustments
PATCH 1/1 libxc/x86: XSAVE related adjustments
- don't unintentionally increase features reported by sub-leaf 0 EDX:EAX
- don't discard the known flags in sub-leaves 2..63 ECX
- handle components 32...62 (EDX) in sub-leaf 1 consistently with 0...31 (ECX)
- zap sub-leaves beyond 62
---
While obviously requiring re-basing on either end when taking Andrew's CPUID levelling series into account, the changes done here appear to be orthogonal to those done in his series.
tools/libxc/xc_cpuid_x86.c +13 -5
@@ -281,10 +281,14 @@ static void intel_xc_cpuid_policy(xc_int } } +/* Leaf 1, EAX: */ #define XSAVEOPT (1 << 0)#define XSAVEC (1 << 1)#define XGETBV1 (1 << 2)#define XSAVES (1 << 3) +/* Leaves beyond 1, ECX: */ +#define XSTATE_XSS (1 << 0) +#define XSTATE_ALIGN64 (1 << 1)/* Configure extended state enumeration leaves (0x0000000D for xsave) */ static void xc_cpuid_config_xsave(xc_interface *xch, const struct cpuid_domain_info *info,
@@ -300,9 +304,9 @@ static void xc_cpuid_config_xsave(xc_int {case 0 :/* EAX: low 32bits of xfeature_enabled_mask */ - regs[0 ] = info->xfeature_mask &0xFFFFFFFF ; + regs[0 ] &= info->xfeature_mask;/* EDX: high 32bits of xfeature_enabled_mask */ - regs[3 ] = (info->xfeature_mask >>32 ) &0xFFFFFFFF ; + regs[3 ] &= info->xfeature_mask >>32 ;/* ECX: max size required by all HW features */ {unsigned int _input[2 ] = {0xd ,0x0 }, _regs[4 ];
@@ -325,16 +329,20 @@ static void xc_cpuid_config_xsave(xc_intif ( !info->hvm ) regs[0 ] &= ~XSAVES ; regs[2 ] &= info->xfeature_mask; - regs[3 ] =0 ; + regs[3 ] &= info->xfeature_mask >>32 ;break ; - case 2 ... 63: /* sub-leaves */ + case 2 ... 62: /* per-component sub-leaves */if ( !(info->xfeature_mask & (1ULL << input[1 ])) ) { regs[0 ] = regs[1 ] = regs[2 ] = regs[3 ] =0 ;break ; }/* Don't touch EAX, EBX. Also cleanup ECX and EDX */ - regs[2 ] = regs[3 ] =0 ; + regs[2 ] &=XSTATE_XSS |XSTATE_ALIGN64 ; + regs[3 ] =0 ; +break ; +default : + regs[0 ] = regs[1 ] = regs[2 ] = regs[3 ] =0 ;break ; } }
libxc/x86: XSAVE related adjustments
- don't unintentionally increase features reported by sub-leaf 0 EDX:EAX
- don't discard the known flags in sub-leaves 2..63 ECX
- handle components 32...62 (EDX) in sub-leaf 1 consistently with 0...31 (ECX)
- zap sub-leaves beyond 62
---
While obviously requiring re-basing on either end when taking Andrew's CPUID levelling series into account, the changes done here appear to be orthogonal to those done in his series.
tools/libxc/xc_cpuid_x86.c +13 -5
@@ -281,10 +281,14 @@ static void intel_xc_cpuid_policy(xc_int } } +/* Leaf 1, EAX: */ #define XSAVEOPT (1 << 0)#define XSAVEC (1 << 1)#define XGETBV1 (1 << 2)#define XSAVES (1 << 3) +/* Leaves beyond 1, ECX: */ +#define XSTATE_XSS (1 << 0) +#define XSTATE_ALIGN64 (1 << 1)/* Configure extended state enumeration leaves (0x0000000D for xsave) */ static void xc_cpuid_config_xsave(xc_interface *xch, const struct cpuid_domain_info *info,
@@ -300,9 +304,9 @@ static void xc_cpuid_config_xsave(xc_int {case 0 :/* EAX: low 32bits of xfeature_enabled_mask */ - regs[0 ] = info->xfeature_mask &0xFFFFFFFF ; + regs[0 ] &= info->xfeature_mask;/* EDX: high 32bits of xfeature_enabled_mask */ - regs[3 ] = (info->xfeature_mask >>32 ) &0xFFFFFFFF ; + regs[3 ] &= info->xfeature_mask >>32 ;/* ECX: max size required by all HW features */ {unsigned int _input[2 ] = {0xd ,0x0 }, _regs[4 ];
@@ -325,16 +329,20 @@ static void xc_cpuid_config_xsave(xc_intif ( !info->hvm ) regs[0 ] &= ~XSAVES ; regs[2 ] &= info->xfeature_mask; - regs[3 ] =0 ; + regs[3 ] &= info->xfeature_mask >>32 ;break ; - case 2 ... 63: /* sub-leaves */ + case 2 ... 62: /* per-component sub-leaves */if ( !(info->xfeature_mask & (1ULL << input[1 ])) ) { regs[0 ] = regs[1 ] = regs[2 ] = regs[3 ] =0 ;break ; }/* Don't touch EAX, EBX. Also cleanup ECX and EDX */ - regs[2 ] = regs[3 ] =0 ; + regs[2 ] &=XSTATE_XSS |XSTATE_ALIGN64 ; + regs[3 ] =0 ; +break ; +default : + regs[0 ] = regs[1 ] = regs[2 ] = regs[3 ] =0 ;break ; } }
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 16 lines · Jan Beulich
- don't unintentionally increase features reported by sub-leaf 0 EDX:EAX
- don't discard the known flags in sub-leaves 2..63 ECX
- handle components 32...62 (EDX) in sub-leaf 1 consistently with 0...31 (ECX)
- zap sub-leaves beyond 62Signed-off-by Jan Beulich <[email protected]>---
While obviously requiring re-basing on either end when taking Andrew's CPUID levelling series into account, the changes done here appear to be orthogonal to those done in his series.
tools/libxc/xc_cpuid_x86.c static void intel_xc_cpuid_policy(xc_int · line 288
Quoted 8 lines
tools/libxc/xc_cpuid_x86.c +1
-0@@ -281,10 +281,14 @@ static void intel_xc_cpuid_policy(xc_int } } +/* Leaf 1, EAX: */ #define XSAVEOPT (1 << 0)#define XSAVEC (1 << 1)#define XGETBV1 (1 << 2)#define XSAVES (1 << 3)
Hmm - I should convert these to be X86_FEATURESET_xxx values.
Quoted 8 lines
tools/libxc/xc_cpuid_x86.c +3
-0+/* Leaves beyond 1, ECX: */ +#define XSTATE_XSS (1 << 0) +#define XSTATE_ALIGN64 (1 << 1)/* Configure extended state enumeration leaves (0x0000000D for xsave) */ static void xc_cpuid_config_xsave(xc_interface *xch, const struct cpuid_domain_info *info,@@ -300,9 +304,9 @@ static void xc_cpuid_config_xsave(xc_int {
tools/libxc/xc_cpuid_x86.c static void xc_cpuid_config_xsave(xc_int · line 312
Quoted 10 lines
tools/libxc/xc_cpuid_x86.c +2
-2case 0 :/* EAX: low 32bits of xfeature_enabled_mask */ - regs[0 ] = info->xfeature_mask &0xFFFFFFFF ; + regs[0 ] &= info->xfeature_mask;/* EDX: high 32bits of xfeature_enabled_mask */ - regs[3 ] = (info->xfeature_mask >>32 ) &0xFFFFFFFF ; + regs[3 ] &= info->xfeature_mask >>32 ;/* ECX: max size required by all HW features */ {unsigned int _input[2 ] = {0xd ,0x0 }, _regs[4 ];
This is an improvement on the code currently present, but is still superseded by the final patch of my cpuid series.
tools/libxc/xc_cpuid_x86.c static void xc_cpuid_config_xsave(xc_int
Quoted 1 line
tools/libxc/xc_cpuid_x86.c +0
-0@@ -325,16 +329,20 @@ static void xc_cpuid_config_xsave(xc_int
Between these two hunks, there is a loop bound which is also wrong.
tools/libxc/xc_cpuid_x86.c static void xc_cpuid_config_xsave(xc_int · line 335
Quoted 9 lines
tools/libxc/xc_cpuid_x86.c +2
-2if ( !info->hvm ) regs[0 ] &= ~XSAVES ; regs[2 ] &= info->xfeature_mask; - regs[3 ] =0 ; + regs[3 ] &= info->xfeature_mask >>32 ;break ; - case 2 ... 63: /* sub-leaves */ + case 2 ... 62: /* per-component sub-leaves */if ( !(info->xfeature_mask & (1ULL << input[1 ])) )
Now I think about it, this check is incomplete. xfeature_mask doesn't contain xss values.
For now its fine, but it will cause problems when support for Processor Trace is added.
tools/libxc/xc_cpuid_x86.c static void xc_cpuid_config_xsave(xc_int · line 346
Quoted 12 lines
tools/libxc/xc_cpuid_x86.c +5
-1{ regs[0 ] = regs[1 ] = regs[2 ] = regs[3 ] =0 ;break ; }/* Don't touch EAX, EBX. Also cleanup ECX and EDX */ - regs[2 ] = regs[3 ] =0 ; + regs[2 ] &=XSTATE_XSS |XSTATE_ALIGN64 ; + regs[3 ] =0 ; +break ; +default : + regs[0 ] = regs[1 ] = regs[2 ] = regs[3 ] =0 ;break ;
If you wish, I can fold this patch into the final patch of my cpuid series.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 16 lines
tools/libxc/xc_cpuid_x86.c static void xc_cpuid_config_xsave(xc_int · line 312
Quoted 13 lines
Quoted 1 line · On 22.03.16 at 14:48, <[email protected]> wrote:
tools/libxc/xc_cpuid_x86.c +2
-2@@ -300,9 +304,9 @@ static void xc_cpuid_config_xsave(xc_int {case 0 :/* EAX: low 32bits of xfeature_enabled_mask */ - regs[0 ] = info->xfeature_mask &0xFFFFFFFF ; + regs[0 ] &= info->xfeature_mask;/* EDX: high 32bits of xfeature_enabled_mask */ - regs[3 ] = (info->xfeature_mask >>32 ) &0xFFFFFFFF ; + regs[3 ] &= info->xfeature_mask >>32 ;/* ECX: max size required by all HW features */ {unsigned int _input[2 ] = {0xd ,0x0 }, _regs[4 ];This is an improvement on the code currently present, but is still superseded by the final patch of my cpuid series.
Is it? I did check your tree before sending, and you do only mechanical adjustments. In particular you don't switch to &= and you don't drop the pointless and-ing with 0xFFFFFFFF.
Quoted 3 lines
Review static void xc_cpuid_config_xsave(xc_int
Quoted 1 line
(quoted diff) +0
-0@@ -325,16 +329,20 @@ static void xc_cpuid_config_xsave(xc_intBetween these two hunks, there is a loop bound which is also wrong.
But seeing that your patches fix it I didn't bother stealing the fix from your patches.
Quoted 10 lines
tools/libxc/xc_cpuid_x86.c static void xc_cpuid_config_xsave(xc_int · line 335
Quoted 9 lines
tools/libxc/xc_cpuid_x86.c +2
-2if ( !info->hvm ) regs[0 ] &= ~XSAVES ; regs[2 ] &= info->xfeature_mask; - regs[3 ] =0 ; + regs[3 ] &= info->xfeature_mask >>32 ;break ; - case 2 ... 63: /* sub-leaves */ + case 2 ... 62: /* per-component sub-leaves */if ( !(info->xfeature_mask & (1ULL << input[1 ])) )
Quoted 2 lines
Now I think about it, this check is incomplete.
xfeature_maskdoesn't contain xss values.
For now the XSS bitmask is blank. Looking at everything together I do think though that once it becomes non-zero, info->xfeature_mask will need to become the OR of both masks.
Quoted 13 lines
tools/libxc/xc_cpuid_x86.c static void xc_cpuid_config_xsave(xc_int · line 346
Quoted 12 lines
tools/libxc/xc_cpuid_x86.c +5
-1{ regs[0 ] = regs[1 ] = regs[2 ] = regs[3 ] =0 ;break ; }/* Don't touch EAX, EBX. Also cleanup ECX and EDX */ - regs[2 ] = regs[3 ] =0 ; + regs[2 ] &=XSTATE_XSS |XSTATE_ALIGN64 ; + regs[3 ] =0 ; +break ; +default : + regs[0 ] = regs[1 ] = regs[2 ] = regs[3 ] =0 ;break ;
Quoted 1 line
If you wish, I can fold this patch into the final patch of my cpuid series.
I'd be fine with that, albeit (as said in the submission) the changes are independent of one another despite them causing conflicts.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 15 lines · Jan Beulich
Quoted 15 lines
tools/libxc/xc_cpuid_x86.c static void xc_cpuid_config_xsave(xc_int · line 312
Quoted 13 lines
Quoted 1 line · On 22.03.16 at 14:48, <[email protected]> wrote:
tools/libxc/xc_cpuid_x86.c +2
-2@@ -300,9 +304,9 @@ static void xc_cpuid_config_xsave(xc_int {case 0 :/* EAX: low 32bits of xfeature_enabled_mask */ - regs[0 ] = info->xfeature_mask &0xFFFFFFFF ; + regs[0 ] &= info->xfeature_mask;/* EDX: high 32bits of xfeature_enabled_mask */ - regs[3 ] = (info->xfeature_mask >>32 ) &0xFFFFFFFF ; + regs[3 ] &= info->xfeature_mask >>32 ;/* ECX: max size required by all HW features */ {unsigned int _input[2 ] = {0xd ,0x0 }, _regs[4 ];This is an improvement on the code currently present, but is still superseded by the final patch of my cpuid series.
Quoted 3 lines
Is it? I did check your tree before sending, and you do only mechanical adjustments. In particular you don't switch to &= and you don't drop the pointless and-ing with
0xFFFFFFFF.
Using &= is specifically wrong and buggy. My patch replaces info->xfeature_mask with guest_xfeature_mask, which itself is calculated from the guest feature availability.
The value in regs[] is dom0's view of the cpuid leaves, and are inappropriate to be combined to make the guests view. Observe that I have specifically been replacing masks with assignments.
Consider the (admittedly contrived scenario of) dom0 being denied access to xsave, while domU is intended to have access. A less contrived scenario is a 32bit dom0 trying to construct a 64bit PV guest. It only worked previously because dom0 used native cpuid which bypassed Xen hiding the LM bit.
Quoted 33 lines
Quoted 3 lines
Review static void xc_cpuid_config_xsave(xc_int
Quoted 2 lines
(quoted diff) +0
-0@@ -325,16 +329,20 @@ static void xc_cpuid_config_xsave(xc_intBetween these two hunks, there is a loop bound which is also wrong.
But seeing that your patches fix it I didn't bother stealing the fix from your patches.
Quoted 11 lines
tools/libxc/xc_cpuid_x86.c static void xc_cpuid_config_xsave(xc_int · line 335
Quoted 9 lines
tools/libxc/xc_cpuid_x86.c +2
-2if ( !info->hvm ) regs[0 ] &= ~XSAVES ; regs[2 ] &= info->xfeature_mask; - regs[3 ] =0 ; + regs[3 ] &= info->xfeature_mask >>32 ;break ; - case 2 ... 63: /* sub-leaves */ + case 2 ... 62: /* per-component sub-leaves */if ( !(info->xfeature_mask & (1ULL << input[1 ])) )Now I think about it, this check is incomplete.
xfeature_maskdoesn't contain xss values.For now the XSS bitmask is blank. Looking at everything together I do think though that once it becomes non-zero,
info->xfeature_maskwill need to become the OR of both masks.Quoted 12 lines
Quoted 12 lines
tools/libxc/xc_cpuid_x86.c +5
-1{ regs[0 ] = regs[1 ] = regs[2 ] = regs[3 ] =0 ;break ; }/* Don't touch EAX, EBX. Also cleanup ECX and EDX */ - regs[2 ] = regs[3 ] =0 ; + regs[2 ] &=XSTATE_XSS |XSTATE_ALIGN64 ; + regs[3 ] =0 ; +break ; +default : + regs[0 ] = regs[1 ] = regs[2 ] = regs[3 ] =0 ;break ;
Quoted 3 lines
Quoted 1 line
If you wish, I can fold this patch into the final patch of my cpuid series.
I'd be fine with that, albeit (as said in the submission) the changes are independent of one another despite them causing conflicts.
It would be clearer than having two different patches both fixing part of the code.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 17 lines
Quoted 1 line
Quoted 1 line · On 22.03.16 at 18:23, <[email protected]> wrote:
Quoted 15 lines · Jan Beulich
Quoted 15 lines
tools/libxc/xc_cpuid_x86.c static void xc_cpuid_config_xsave(xc_int · line 312
Quoted 13 lines
Quoted 1 line · On 22.03.16 at 14:48, <[email protected]> wrote:
tools/libxc/xc_cpuid_x86.c +2
-2@@ -300,9 +304,9 @@ static void xc_cpuid_config_xsave(xc_int {case 0 :/* EAX: low 32bits of xfeature_enabled_mask */ - regs[0 ] = info->xfeature_mask &0xFFFFFFFF ; + regs[0 ] &= info->xfeature_mask;/* EDX: high 32bits of xfeature_enabled_mask */ - regs[3 ] = (info->xfeature_mask >>32 ) &0xFFFFFFFF ; + regs[3 ] &= info->xfeature_mask >>32 ;/* ECX: max size required by all HW features */ {unsigned int _input[2 ] = {0xd ,0x0 }, _regs[4 ];This is an improvement on the code currently present, but is still superseded by the final patch of my cpuid series.
Quoted 7 lines
Quoted 3 lines
Is it? I did check your tree before sending, and you do only mechanical adjustments. In particular you don't switch to &= and you don't drop the pointless and-ing with
0xFFFFFFFF.Using &= is specifically wrong and buggy. My patch replaces
info->xfeature_maskwithguest_xfeature_mask, which itself is calculated from the guest feature availability.
Oh, right - if you imply buggy just if it was done with or after your change.
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
{ regs[0] = regs[1] = regs[2] = regs[3] = 0; break; } /* Don't touch EAX, EBX. Also cleanup ECX and EDX */tools/libxc/xc_cpuid_x86.c +5
-1- regs[2 ] = regs[3 ] =0 ; + regs[2 ] &=XSTATE_XSS |XSTATE_ALIGN64 ; + regs[3 ] =0 ; +break ; +default : + regs[0 ] = regs[1 ] = regs[2 ] = regs[3 ] =0 ;break ;
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
If you wish, I can fold this patch into the final patch of my cpuid series.
I'd be fine with that, albeit (as said in the submission) the changes are independent of one another despite them causing conflicts.
It would be clearer than having two different patches both fixing part of the code.
Especially with the above in mind - go ahead.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel