All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/setup: Correct register clobbers for the asm statement when resyncing the stack
@ 2014-10-20 17:30 Andrew Cooper
  2014-10-20 20:21 ` Daniel Kiper
  2014-10-21  8:44 ` Jan Beulich
  0 siblings, 2 replies; 5+ messages in thread
From: Andrew Cooper @ 2014-10-20 17:30 UTC (permalink / raw)
  To: Xen-devel; +Cc: Andrew Cooper, Daniel Kiper, Keir Fraser, Jan Beulich

When resyncing the stack, the asm statement does not identify %rsi, %rdi and
%rcx as clobbered by the 'rep movsq'.

Luckily, there are no functional problems in the generated code.  GCC decides
not to save any of them before calling boostrap_map(), which clobbers them.

Correct the clobbers, by listing them as earlyclobber discarded outputs.

Reported-by: Daniel Kiper <daniel.kiper@oracle.com>
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
CC: Keir Fraser <keir@xen.org>
CC: Jan Beulich <JBeulich@suse.com>

---

I have done an audit of the other uses of `rep $STRINGOP` and this is the only
asm statement with incorrect clobbers.
---
 xen/arch/x86/setup.c |    9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c
index 8c8b91f..f470c4a 100644
--- a/xen/arch/x86/setup.c
+++ b/xen/arch/x86/setup.c
@@ -836,6 +836,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
             l2_pgentry_t *pl2e;
             uint64_t load_start;
             int i, j, k;
+            long _discard;
 
             /* Select relocation address. */
             e = end - reloc_size;
@@ -902,11 +903,13 @@ void __init noreturn __start_xen(unsigned long mbi_p)
                 "movq %%cr4,%%rsi ; "
                 "andb $0x7f,%%sil ; "
                 "movq %%rsi,%%cr4 ; " /* CR4.PGE == 0 */
-                "movq %0,%%cr3    ; " /* CR3 == new pagetables */
+                "movq %6,%%cr3    ; " /* CR3 == new pagetables */
                 "orb $0x80,%%sil  ; "
                 "movq %%rsi,%%cr4   " /* CR4.PGE == 1 */
-                : : "r" (__pa(idle_pg_table)), "S" (cpu0_stack),
-                "D" (__va(__pa(cpu0_stack))), "c" (STACK_SIZE / 8) : "memory" );
+                : "=&S"(_discard), "=&D"(_discard), "=&c"(_discard)
+                : "0"(cpu0_stack), "1"(__va(__pa(cpu0_stack))),
+                  "2"(STACK_SIZE / 8), "r"(__pa(idle_pg_table))
+                : "memory" );
 
             bootstrap_map(NULL);
         }
-- 
1.7.10.4

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

* Re: [PATCH] x86/setup: Correct register clobbers for the asm statement when resyncing the stack
  2014-10-20 17:30 [PATCH] x86/setup: Correct register clobbers for the asm statement when resyncing the stack Andrew Cooper
@ 2014-10-20 20:21 ` Daniel Kiper
  2014-10-21  8:44 ` Jan Beulich
  1 sibling, 0 replies; 5+ messages in thread
From: Daniel Kiper @ 2014-10-20 20:21 UTC (permalink / raw)
  To: Andrew Cooper; +Cc: Keir Fraser, Jan Beulich, Xen-devel

On Mon, Oct 20, 2014 at 06:30:07PM +0100, Andrew Cooper wrote:
> When resyncing the stack, the asm statement does not identify %rsi, %rdi and
> %rcx as clobbered by the 'rep movsq'.
>
> Luckily, there are no functional problems in the generated code.  GCC decides
> not to save any of them before calling boostrap_map(), which clobbers them.
>
> Correct the clobbers, by listing them as earlyclobber discarded outputs.
>
> Reported-by: Daniel Kiper <daniel.kiper@oracle.com>
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
> CC: Keir Fraser <keir@xen.org>
> CC: Jan Beulich <JBeulich@suse.com>
>
> ---
>
> I have done an audit of the other uses of `rep $STRINGOP` and this is the only
> asm statement with incorrect clobbers.
> ---
>  xen/arch/x86/setup.c |    9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)

Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
Tested-by: Daniel Kiper <daniel.kiper@oracle.com>

Daniel

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

* Re: [PATCH] x86/setup: Correct register clobbers for the asm statement when resyncing the stack
  2014-10-20 17:30 [PATCH] x86/setup: Correct register clobbers for the asm statement when resyncing the stack Andrew Cooper
  2014-10-20 20:21 ` Daniel Kiper
@ 2014-10-21  8:44 ` Jan Beulich
  2014-10-21 10:03   ` Andrew Cooper
  1 sibling, 1 reply; 5+ messages in thread
From: Jan Beulich @ 2014-10-21  8:44 UTC (permalink / raw)
  To: Andrew Cooper; +Cc: Daniel Kiper, Keir Fraser, Xen-devel

>>> On 20.10.14 at 19:30, <andrew.cooper3@citrix.com> wrote:
> When resyncing the stack, the asm statement does not identify %rsi, %rdi and
> %rcx as clobbered by the 'rep movsq'.
> 
> Luckily, there are no functional problems in the generated code.  GCC 
> decides
> not to save any of them before calling boostrap_map(), which clobbers them.
> 
> Correct the clobbers, by listing them as earlyclobber discarded outputs.
> 
> Reported-by: Daniel Kiper <daniel.kiper@oracle.com>
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
> CC: Keir Fraser <keir@xen.org>
> CC: Jan Beulich <JBeulich@suse.com>
> 
> ---
> 
> I have done an audit of the other uses of `rep $STRINGOP` and this is the 
> only
> asm statement with incorrect clobbers.
> ---
>  xen/arch/x86/setup.c |    9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c
> index 8c8b91f..f470c4a 100644
> --- a/xen/arch/x86/setup.c
> +++ b/xen/arch/x86/setup.c
> @@ -836,6 +836,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
>              l2_pgentry_t *pl2e;
>              uint64_t load_start;
>              int i, j, k;
> +            long _discard;

I can't see why you couldn't use i, j, or k for the discarding purposes.

> @@ -902,11 +903,13 @@ void __init noreturn __start_xen(unsigned long mbi_p)
>                  "movq %%cr4,%%rsi ; "
>                  "andb $0x7f,%%sil ; "
>                  "movq %%rsi,%%cr4 ; " /* CR4.PGE == 0 */
> -                "movq %0,%%cr3    ; " /* CR3 == new pagetables */
> +                "movq %6,%%cr3    ; " /* CR3 == new pagetables */
>                  "orb $0x80,%%sil  ; "
>                  "movq %%rsi,%%cr4   " /* CR4.PGE == 1 */
> -                : : "r" (__pa(idle_pg_table)), "S" (cpu0_stack),
> -                "D" (__va(__pa(cpu0_stack))), "c" (STACK_SIZE / 8) : "memory" );
> +                : "=&S"(_discard), "=&D"(_discard), "=&c"(_discard)
> +                : "0"(cpu0_stack), "1"(__va(__pa(cpu0_stack))),
> +                  "2"(STACK_SIZE / 8), "r"(__pa(idle_pg_table))
> +                : "memory" );

Among the inputs, please put the one actively used by number first,
or convert to labeled operands. Also please don't corrupt the
formatting - there ought to be a blank between the closing constraint
quote and the opening parenthesis in all operands.

Jan

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

* Re: [PATCH] x86/setup: Correct register clobbers for the asm statement when resyncing the stack
  2014-10-21  8:44 ` Jan Beulich
@ 2014-10-21 10:03   ` Andrew Cooper
  2014-10-21 14:31     ` Jan Beulich
  0 siblings, 1 reply; 5+ messages in thread
From: Andrew Cooper @ 2014-10-21 10:03 UTC (permalink / raw)
  To: Jan Beulich; +Cc: Daniel Kiper, Keir Fraser, Xen-devel

On 21/10/14 09:44, Jan Beulich wrote:
>>>> On 20.10.14 at 19:30, <andrew.cooper3@citrix.com> wrote:
>> When resyncing the stack, the asm statement does not identify %rsi, %rdi and
>> %rcx as clobbered by the 'rep movsq'.
>>
>> Luckily, there are no functional problems in the generated code.  GCC 
>> decides
>> not to save any of them before calling boostrap_map(), which clobbers them.
>>
>> Correct the clobbers, by listing them as earlyclobber discarded outputs.
>>
>> Reported-by: Daniel Kiper <daniel.kiper@oracle.com>
>> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
>> CC: Keir Fraser <keir@xen.org>
>> CC: Jan Beulich <JBeulich@suse.com>
>>
>> ---
>>
>> I have done an audit of the other uses of `rep $STRINGOP` and this is the 
>> only
>> asm statement with incorrect clobbers.
>> ---
>>  xen/arch/x86/setup.c |    9 ++++++---
>>  1 file changed, 6 insertions(+), 3 deletions(-)
>>
>> diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c
>> index 8c8b91f..f470c4a 100644
>> --- a/xen/arch/x86/setup.c
>> +++ b/xen/arch/x86/setup.c
>> @@ -836,6 +836,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
>>              l2_pgentry_t *pl2e;
>>              uint64_t load_start;
>>              int i, j, k;
>> +            long _discard;
> I can't see why you couldn't use i, j, or k for the discarding purposes.

A parameter with the name "_discard" is far more explicit about its
purpose when read as part of the output parameter list.

I could switch to i and leave a comment by the parameters if you insist.

>
>> @@ -902,11 +903,13 @@ void __init noreturn __start_xen(unsigned long mbi_p)
>>                  "movq %%cr4,%%rsi ; "
>>                  "andb $0x7f,%%sil ; "
>>                  "movq %%rsi,%%cr4 ; " /* CR4.PGE == 0 */
>> -                "movq %0,%%cr3    ; " /* CR3 == new pagetables */
>> +                "movq %6,%%cr3    ; " /* CR3 == new pagetables */
>>                  "orb $0x80,%%sil  ; "
>>                  "movq %%rsi,%%cr4   " /* CR4.PGE == 1 */
>> -                : : "r" (__pa(idle_pg_table)), "S" (cpu0_stack),
>> -                "D" (__va(__pa(cpu0_stack))), "c" (STACK_SIZE / 8) : "memory" );
>> +                : "=&S"(_discard), "=&D"(_discard), "=&c"(_discard)
>> +                : "0"(cpu0_stack), "1"(__va(__pa(cpu0_stack))),
>> +                  "2"(STACK_SIZE / 8), "r"(__pa(idle_pg_table))
>> +                : "memory" );
> Among the inputs, please put the one actively used by number first,
> or convert to labeled operands.

As far as I can tell, it is impossible to get the idle pagetables to
parameter %0 as it is not present in the output list.  I have switched
to a named parameter.

>  Also please don't corrupt the
> formatting - there ought to be a blank between the closing constraint
> quote and the opening parenthesis in all operands.

Done

~Andrew

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

* Re: [PATCH] x86/setup: Correct register clobbers for the asm statement when resyncing the stack
  2014-10-21 10:03   ` Andrew Cooper
@ 2014-10-21 14:31     ` Jan Beulich
  0 siblings, 0 replies; 5+ messages in thread
From: Jan Beulich @ 2014-10-21 14:31 UTC (permalink / raw)
  To: Andrew Cooper; +Cc: Daniel Kiper, Keir Fraser, Xen-devel

>>> On 21.10.14 at 12:03, <andrew.cooper3@citrix.com> wrote:
> On 21/10/14 09:44, Jan Beulich wrote:
>>>>> On 20.10.14 at 19:30, <andrew.cooper3@citrix.com> wrote:
>>> --- a/xen/arch/x86/setup.c
>>> +++ b/xen/arch/x86/setup.c
>>> @@ -836,6 +836,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
>>>              l2_pgentry_t *pl2e;
>>>              uint64_t load_start;
>>>              int i, j, k;
>>> +            long _discard;
>> I can't see why you couldn't use i, j, or k for the discarding purposes.
> 
> A parameter with the name "_discard" is far more explicit about its
> purpose when read as part of the output parameter list.
> 
> I could switch to i and leave a comment by the parameters if you insist.

I don't strictly insist, but I dislike variables to be added without real
need. At the very least the leading underscore needs to be dropped
as needlessly being in conflict with C library standard naming rules.

>>> @@ -902,11 +903,13 @@ void __init noreturn __start_xen(unsigned long mbi_p)
>>>                  "movq %%cr4,%%rsi ; "
>>>                  "andb $0x7f,%%sil ; "
>>>                  "movq %%rsi,%%cr4 ; " /* CR4.PGE == 0 */
>>> -                "movq %0,%%cr3    ; " /* CR3 == new pagetables */
>>> +                "movq %6,%%cr3    ; " /* CR3 == new pagetables */
>>>                  "orb $0x80,%%sil  ; "
>>>                  "movq %%rsi,%%cr4   " /* CR4.PGE == 1 */
>>> -                : : "r" (__pa(idle_pg_table)), "S" (cpu0_stack),
>>> -                "D" (__va(__pa(cpu0_stack))), "c" (STACK_SIZE / 8) : 
> "memory" );
>>> +                : "=&S"(_discard), "=&D"(_discard), "=&c"(_discard)
>>> +                : "0"(cpu0_stack), "1"(__va(__pa(cpu0_stack))),
>>> +                  "2"(STACK_SIZE / 8), "r"(__pa(idle_pg_table))
>>> +                : "memory" );
>> Among the inputs, please put the one actively used by number first,
>> or convert to labeled operands.
> 
> As far as I can tell, it is impossible to get the idle pagetables to
> parameter %0 as it is not present in the output list.  I have switched
> to a named parameter.

I didn't say make it %0 again (and specifically said "among the
inputs"), but it could have been moved ahead of all the other
inputs.

Jan

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

end of thread, other threads:[~2014-10-21 14:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-20 17:30 [PATCH] x86/setup: Correct register clobbers for the asm statement when resyncing the stack Andrew Cooper
2014-10-20 20:21 ` Daniel Kiper
2014-10-21  8:44 ` Jan Beulich
2014-10-21 10:03   ` Andrew Cooper
2014-10-21 14:31     ` 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.