All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86: properly macroize the two XRSTOR flavors
@ 2015-11-27 11:54 Jan Beulich
  2015-11-27 13:49 ` Andrew Cooper
  0 siblings, 1 reply; 3+ messages in thread
From: Jan Beulich @ 2015-11-27 11:54 UTC (permalink / raw)
  To: xen-devel; +Cc: Andrew Cooper, Keir Fraser, Shuai Ruan

[-- Attachment #1: Type: text/plain, Size: 3356 bytes --]

All they differ by is the REX64 prefix. Create a single macro covering
both, at once allowing to get rid of the disconnect between the current
partial macro and its two use sites.

No change in generated code.

Signed-off-by: Jan Beulich <jbeulich@suse.com>

--- a/xen/arch/x86/xstate.c
+++ b/xen/arch/x86/xstate.c
@@ -334,16 +334,6 @@ void xsave(struct vcpu *v, uint64_t mask
         ptr->fpu_sse.x[FPU_WORD_SIZE_OFFSET] = word_size;
 }
 
-#define XRSTOR_FIXUP   ".section .fixup,\"ax\"           \n"    \
-                       "2: mov %[size],%%ecx             \n"    \
-                       "   xor %[lmask_out],%[lmask_out] \n"    \
-                       "   rep stosb                     \n"    \
-                       "   lea %[mem],%[ptr]             \n"    \
-                       "   mov %[lmask_in],%[lmask_out]  \n"    \
-                       "   jmp 1b                        \n"    \
-                       ".previous                        \n"    \
-                       _ASM_EXTABLE(1b, 2b)
-
 void xrstor(struct vcpu *v, uint64_t mask)
 {
     uint32_t hmask = mask >> 32;
@@ -372,29 +362,33 @@ void xrstor(struct vcpu *v, uint64_t mas
      */
     switch ( __builtin_expect(ptr->fpu_sse.x[FPU_WORD_SIZE_OFFSET], 8) )
     {
+#define XRSTOR(pfx) \
+        alternative_io("1: .byte " pfx "0x0f,0xae,0x2f\n" \
+                       "   .section .fixup,\"ax\"\n" \
+                       "2: mov %[size],%%ecx\n" \
+                       "   xor %[lmask_out],%[lmask_out]\n" \
+                       "   rep stosb\n" \
+                       "   lea %[mem],%[ptr]\n" \
+                       "   mov %[lmask_in],%[lmask_out]\n" \
+                       "   jmp 1b\n" \
+                       "   .previous\n" \
+                       _ASM_EXTABLE(1b, 2b), \
+                       ".byte " pfx "0x0f,0xc7,0x1f\n", \
+                       X86_FEATURE_XSAVES, \
+                       ASM_OUTPUT2([ptr] "+&D" (ptr), [lmask_out] "+&a" (lmask)), \
+                       [mem] "m" (*ptr), [lmask_in] "g" (lmask), \
+                       [hmask] "d" (hmask), [size] "m" (xsave_cntxt_size) \
+                       : "ecx")
+
     default:
-        alternative_io("1: .byte 0x48,0x0f,0xae,0x2f\n"
-                       XRSTOR_FIXUP,
-                       ".byte 0x48,0x0f,0xc7,0x1f\n",
-                       X86_FEATURE_XSAVES,
-                       ASM_OUTPUT2([ptr] "+&D" (ptr), [lmask_out] "+&a" (lmask)),
-                       [mem] "m" (*ptr), [lmask_in] "g" (lmask),
-                       [hmask] "d" (hmask), [size] "m" (xsave_cntxt_size)
-                       : "ecx");
+        XRSTOR("0x48,");
         break;
     case 4: case 2:
-        alternative_io("1: .byte 0x0f,0xae,0x2f\n"
-                       XRSTOR_FIXUP,
-                       ".byte 0x0f,0xc7,0x1f\n",
-                       X86_FEATURE_XSAVES,
-                       ASM_OUTPUT2([ptr] "+&D" (ptr), [lmask_out] "+&a" (lmask)),
-                       [mem] "m" (*ptr), [lmask_in] "g" (lmask),
-                       [hmask] "d" (hmask), [size] "m" (xsave_cntxt_size)
-                       : "ecx");
+        XRSTOR("");
         break;
+#undef XRSTOR
     }
 }
-#undef XRSTOR_FIXUP
 
 bool_t xsave_enabled(const struct vcpu *v)
 {




[-- Attachment #2: x86-xrstor-factoring.patch --]
[-- Type: text/plain, Size: 3399 bytes --]

x86: properly macroize the two XRSTOR flavors

All they differ by is the REX64 prefix. Create a single macro covering
both, at once allowing to get rid of the disconnect between the current
partial macro and its two use sites.

No change in generated code.

Signed-off-by: Jan Beulich <jbeulich@suse.com>

--- a/xen/arch/x86/xstate.c
+++ b/xen/arch/x86/xstate.c
@@ -334,16 +334,6 @@ void xsave(struct vcpu *v, uint64_t mask
         ptr->fpu_sse.x[FPU_WORD_SIZE_OFFSET] = word_size;
 }
 
-#define XRSTOR_FIXUP   ".section .fixup,\"ax\"           \n"    \
-                       "2: mov %[size],%%ecx             \n"    \
-                       "   xor %[lmask_out],%[lmask_out] \n"    \
-                       "   rep stosb                     \n"    \
-                       "   lea %[mem],%[ptr]             \n"    \
-                       "   mov %[lmask_in],%[lmask_out]  \n"    \
-                       "   jmp 1b                        \n"    \
-                       ".previous                        \n"    \
-                       _ASM_EXTABLE(1b, 2b)
-
 void xrstor(struct vcpu *v, uint64_t mask)
 {
     uint32_t hmask = mask >> 32;
@@ -372,29 +362,33 @@ void xrstor(struct vcpu *v, uint64_t mas
      */
     switch ( __builtin_expect(ptr->fpu_sse.x[FPU_WORD_SIZE_OFFSET], 8) )
     {
+#define XRSTOR(pfx) \
+        alternative_io("1: .byte " pfx "0x0f,0xae,0x2f\n" \
+                       "   .section .fixup,\"ax\"\n" \
+                       "2: mov %[size],%%ecx\n" \
+                       "   xor %[lmask_out],%[lmask_out]\n" \
+                       "   rep stosb\n" \
+                       "   lea %[mem],%[ptr]\n" \
+                       "   mov %[lmask_in],%[lmask_out]\n" \
+                       "   jmp 1b\n" \
+                       "   .previous\n" \
+                       _ASM_EXTABLE(1b, 2b), \
+                       ".byte " pfx "0x0f,0xc7,0x1f\n", \
+                       X86_FEATURE_XSAVES, \
+                       ASM_OUTPUT2([ptr] "+&D" (ptr), [lmask_out] "+&a" (lmask)), \
+                       [mem] "m" (*ptr), [lmask_in] "g" (lmask), \
+                       [hmask] "d" (hmask), [size] "m" (xsave_cntxt_size) \
+                       : "ecx")
+
     default:
-        alternative_io("1: .byte 0x48,0x0f,0xae,0x2f\n"
-                       XRSTOR_FIXUP,
-                       ".byte 0x48,0x0f,0xc7,0x1f\n",
-                       X86_FEATURE_XSAVES,
-                       ASM_OUTPUT2([ptr] "+&D" (ptr), [lmask_out] "+&a" (lmask)),
-                       [mem] "m" (*ptr), [lmask_in] "g" (lmask),
-                       [hmask] "d" (hmask), [size] "m" (xsave_cntxt_size)
-                       : "ecx");
+        XRSTOR("0x48,");
         break;
     case 4: case 2:
-        alternative_io("1: .byte 0x0f,0xae,0x2f\n"
-                       XRSTOR_FIXUP,
-                       ".byte 0x0f,0xc7,0x1f\n",
-                       X86_FEATURE_XSAVES,
-                       ASM_OUTPUT2([ptr] "+&D" (ptr), [lmask_out] "+&a" (lmask)),
-                       [mem] "m" (*ptr), [lmask_in] "g" (lmask),
-                       [hmask] "d" (hmask), [size] "m" (xsave_cntxt_size)
-                       : "ecx");
+        XRSTOR("");
         break;
+#undef XRSTOR
     }
 }
-#undef XRSTOR_FIXUP
 
 bool_t xsave_enabled(const struct vcpu *v)
 {

[-- Attachment #3: Type: text/plain, Size: 126 bytes --]

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] x86: properly macroize the two XRSTOR flavors
  2015-11-27 11:54 [PATCH] x86: properly macroize the two XRSTOR flavors Jan Beulich
@ 2015-11-27 13:49 ` Andrew Cooper
  2015-11-27 17:06   ` Jan Beulich
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Cooper @ 2015-11-27 13:49 UTC (permalink / raw)
  To: Jan Beulich, xen-devel; +Cc: Keir Fraser, Shuai Ruan

On 27/11/15 11:54, Jan Beulich wrote:
> All they differ by is the REX64 prefix. Create a single macro covering
> both, at once allowing to get rid of the disconnect between the current
> partial macro and its two use sites.
>
> No change in generated code.
>
> Signed-off-by: Jan Beulich <jbeulich@suse.com>
>
> --- a/xen/arch/x86/xstate.c
> +++ b/xen/arch/x86/xstate.c
> @@ -334,16 +334,6 @@ void xsave(struct vcpu *v, uint64_t mask
>          ptr->fpu_sse.x[FPU_WORD_SIZE_OFFSET] = word_size;
>  }
>  
> -#define XRSTOR_FIXUP   ".section .fixup,\"ax\"           \n"    \
> -                       "2: mov %[size],%%ecx             \n"    \
> -                       "   xor %[lmask_out],%[lmask_out] \n"    \
> -                       "   rep stosb                     \n"    \
> -                       "   lea %[mem],%[ptr]             \n"    \
> -                       "   mov %[lmask_in],%[lmask_out]  \n"    \
> -                       "   jmp 1b                        \n"    \
> -                       ".previous                        \n"    \
> -                       _ASM_EXTABLE(1b, 2b)
> -
>  void xrstor(struct vcpu *v, uint64_t mask)
>  {
>      uint32_t hmask = mask >> 32;
> @@ -372,29 +362,33 @@ void xrstor(struct vcpu *v, uint64_t mas
>       */
>      switch ( __builtin_expect(ptr->fpu_sse.x[FPU_WORD_SIZE_OFFSET], 8) )
>      {
> +#define XRSTOR(pfx) \
> +        alternative_io("1: .byte " pfx "0x0f,0xae,0x2f\n" \
> +                       "   .section .fixup,\"ax\"\n" \
> +                       "2: mov %[size],%%ecx\n" \
> +                       "   xor %[lmask_out],%[lmask_out]\n" \
> +                       "   rep stosb\n" \
> +                       "   lea %[mem],%[ptr]\n" \
> +                       "   mov %[lmask_in],%[lmask_out]\n" \
> +                       "   jmp 1b\n" \
> +                       "   .previous\n" \
> +                       _ASM_EXTABLE(1b, 2b), \
> +                       ".byte " pfx "0x0f,0xc7,0x1f\n", \
> +                       X86_FEATURE_XSAVES, \
> +                       ASM_OUTPUT2([ptr] "+&D" (ptr), [lmask_out] "+&a" (lmask)), \
> +                       [mem] "m" (*ptr), [lmask_in] "g" (lmask), \
> +                       [hmask] "d" (hmask), [size] "m" (xsave_cntxt_size) \
> +                       : "ecx")

Please align the \'s on the RHS.  It makes the resulting blob rather
easier to read, especially given the \n's in the text.

Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] x86: properly macroize the two XRSTOR flavors
  2015-11-27 13:49 ` Andrew Cooper
@ 2015-11-27 17:06   ` Jan Beulich
  0 siblings, 0 replies; 3+ messages in thread
From: Jan Beulich @ 2015-11-27 17:06 UTC (permalink / raw)
  To: Andrew Cooper; +Cc: xen-devel, Keir Fraser, Shuai Ruan

>>> On 27.11.15 at 14:49, <andrew.cooper3@citrix.com> wrote:
> On 27/11/15 11:54, Jan Beulich wrote:
>>      switch ( __builtin_expect(ptr->fpu_sse.x[FPU_WORD_SIZE_OFFSET], 8) )
>>      {
>> +#define XRSTOR(pfx) \
>> +        alternative_io("1: .byte " pfx "0x0f,0xae,0x2f\n" \
>> +                       "   .section .fixup,\"ax\"\n" \
>> +                       "2: mov %[size],%%ecx\n" \
>> +                       "   xor %[lmask_out],%[lmask_out]\n" \
>> +                       "   rep stosb\n" \
>> +                       "   lea %[mem],%[ptr]\n" \
>> +                       "   mov %[lmask_in],%[lmask_out]\n" \
>> +                       "   jmp 1b\n" \
>> +                       "   .previous\n" \
>> +                       _ASM_EXTABLE(1b, 2b), \
>> +                       ".byte " pfx "0x0f,0xc7,0x1f\n", \
>> +                       X86_FEATURE_XSAVES, \
>> +                       ASM_OUTPUT2([ptr] "+&D" (ptr), [lmask_out] "+&a" (lmask)), \
>> +                       [mem] "m" (*ptr), [lmask_in] "g" (lmask), \
>> +                       [hmask] "d" (hmask), [size] "m" (xsave_cntxt_size) \
>> +                       : "ecx")
> 
> Please align the \'s on the RHS.  It makes the resulting blob rather
> easier to read, especially given the \n's in the text.

Well, recent review of one of Roger's patches showed that this is not
generally a good idea, and hence I actually purposefully didn't align
them.

Jan

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-11-27 17:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-27 11:54 [PATCH] x86: properly macroize the two XRSTOR flavors Jan Beulich
2015-11-27 13:49 ` Andrew Cooper
2015-11-27 17:06   ` Jan Beulich

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.