Skip to contentSkip to conversation

tools/libxc: Correct use of X86_XSS_MASK in guest xstate generation

PATCH Applied Andrew Cooper 3 participants 3 messages Apr 19, 2016 – Apr 20, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools/libxc: Correct use of X86_XSS_MASK in guest xstate generation

c/s 75f9455e "tools/libxc: Calculate xstate cpuid leaf from guest information" incorrectly inverted the shift and mask when using X86_XSS_MASK. Luckily, the mask is currently zero, avoiding incorrect calculations.

While adjusting this, use an explcit uint32_t cast rather than masking against 0xffffffff.

---
CC: Ian Jackson <[email protected]>
CC: Wei Liu <[email protected]>
CC: Jan Beulich <[email protected]>

Submitted-from: A punt, on the Cam, during the the hackathon, because.

---
 tools/libxc/xc_cpuid_x86.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
tools/libxc/xc_cpuid_x86.c +3 -3
index 6d14904..84f4e08 100644
@@ -460,7 +460,7 @@ static void xc_cpuid_config_xsave(xc_interface *xch,
     {
     case 0:
         /* EAX: low 32bits of xfeature_enabled_mask */
-        regs[0] = guest_xfeature_mask & 0xFFFFFFFF;
+        regs[0] = (uint32_t)guest_xfeature_mask;
         /* EDX: high 32bits of xfeature_enabled_mask */
         regs[3] = guest_xfeature_mask >> 32;
         /* ECX: max size required by all HW features */
@@ -487,8 +487,8 @@ static void xc_cpuid_config_xsave(xc_interface *xch,
 
         if ( test_bit(X86_FEATURE_XSAVES, info->featureset) )
         {
-            regs[2] = guest_xfeature_mask & X86_XSS_MASK & 0xFFFFFFFF;
-            regs[3] = (guest_xfeature_mask >> 32) & X86_XSS_MASK;
+            regs[2] = (uint32_t)(guest_xfeature_mask & X86_XSS_MASK);
+            regs[3] = (guest_xfeature_mask & X86_XSS_MASK) >> 32;
         }
         else
             regs[2] = regs[3] = 0;
Signature · 7 lines
1.9.1


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Acked-by on v1 1/1
#1 lore raw
Quoted 7 lines · Andrew Cooper

c/s 75f9455e "tools/libxc: Calculate xstate cpuid leaf from guest information" incorrectly inverted the shift and mask when using X86_XSS_MASK. Luckily, the mask is currently zero, avoiding incorrect calculations.

While adjusting this, use an explcit uint32_t cast rather than masking against 0xffffffff.

Quoted 7 lines

---
CC: Ian Jackson <[email protected]>
CC: Wei Liu <[email protected]>
CC: Jan Beulich <[email protected]>

Submitted-from: A punt, on the Cam, during the the hackathon, because.

On a punt, too, because

Quoted 31 lines
---
 tools/libxc/xc_cpuid_x86.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
tools/libxc/xc_cpuid_x86.c +3 -3
index 6d14904..84f4e08 100644
@@ -460,7 +460,7 @@ static void xc_cpuid_config_xsave(xc_interface *xch,
     {
     case 0:
         /* EAX: low 32bits of xfeature_enabled_mask */
-        regs[0] = guest_xfeature_mask & 0xFFFFFFFF;
+        regs[0] = (uint32_t)guest_xfeature_mask;
         /* EDX: high 32bits of xfeature_enabled_mask */
         regs[3] = guest_xfeature_mask >> 32;
         /* ECX: max size required by all HW features */
@@ -487,8 +487,8 @@ static void xc_cpuid_config_xsave(xc_interface *xch,
 
         if ( test_bit(X86_FEATURE_XSAVES, info->featureset) )
         {
-            regs[2] = guest_xfeature_mask & X86_XSS_MASK & 0xFFFFFFFF;
-            regs[3] = (guest_xfeature_mask >> 32) & X86_XSS_MASK;
+            regs[2] = (uint32_t)(guest_xfeature_mask & X86_XSS_MASK);
+            regs[3] = (guest_xfeature_mask & X86_XSS_MASK) >> 32;
         }
         else
             regs[2] = regs[3] = 0;
Signature · 1 line
1.9.1

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

Applied
#2 lore raw

Wei Liu writes ("Re: [PATCH] tools/libxc: Correct use of X86_XSS_MASK in guest xstate generation"):

Quoted 7 lines · Andrew Cooper
Quoted 1 line

Submitted-from: A punt, on the Cam, during the the hackathon, because.

On a punt, too, because

Queued, thanks.

Ian.
(at his desk)

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel