All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] x86: correct asm() constraints when dealing with immediate selector values
@ 2021-09-13  6:26 Jan Beulich
  2022-06-23 12:03 ` Ping: " Jan Beulich
  2022-06-28 12:59 ` Roger Pau Monné
  0 siblings, 2 replies; 3+ messages in thread
From: Jan Beulich @ 2021-09-13  6:26 UTC (permalink / raw)
  To: xen-devel; +Cc: Andrew Cooper, Wei Liu, Roger Pau Monné

asm() constraints need to fit both the intended insn(s) which the
respective operands are going to be used with as well as the actual kind
of value specified. "m" (alone) together with a constant, however, leads
to gcc saying

error: memory input <N> is not directly addressable

while clang complains

error: invalid lvalue in asm input for constraint 'm'

And rightly so - in order to access a memory operand, an address needs
to be specified to the insn. In some cases it might be possible for a
compiler to synthesize a memory operand holding the requested constant,
but I think any solution there would have sharp edges.

If "m" alone doesn't work with constants, it is at best pointless (and
perhaps misleading or even risky - the compiler might decide to actually
pick "m" and not try very hard to find a suitable register) to specify
it alongside "r". And indeed clang does, oddly enough despite its
objection to "m" alone. Which means there the change also improves the
generated code.

While there also switch the two operand case to using named operands.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
---
v2: Use named operands in do_double_fault().

--- a/xen/arch/x86/cpu/amd.c
+++ b/xen/arch/x86/cpu/amd.c
@@ -736,7 +736,7 @@ void __init detect_zen2_null_seg_behavio
 	uint64_t base;
 
 	wrmsrl(MSR_FS_BASE, 1);
-	asm volatile ( "mov %0, %%fs" :: "rm" (0) );
+	asm volatile ( "mov %0, %%fs" :: "r" (0) );
 	rdmsrl(MSR_FS_BASE, base);
 
 	if (base == 0)
--- a/xen/arch/x86/x86_64/traps.c
+++ b/xen/arch/x86/x86_64/traps.c
@@ -248,7 +248,8 @@ void do_double_fault(struct cpu_user_reg
 
     console_force_unlock();
 
-    asm ( "lsll %1, %0" : "=r" (cpu) : "rm" (PER_CPU_SELECTOR) );
+    asm ( "lsll %[sel], %[limit]" : [limit] "=r" (cpu)
+                                  : [sel] "r" (PER_CPU_SELECTOR) );
 
     /* Find information saved during fault and dump it to the console. */
     printk("*** DOUBLE FAULT ***\n");



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

* Ping: [PATCH v2] x86: correct asm() constraints when dealing with immediate selector values
  2021-09-13  6:26 [PATCH v2] x86: correct asm() constraints when dealing with immediate selector values Jan Beulich
@ 2022-06-23 12:03 ` Jan Beulich
  2022-06-28 12:59 ` Roger Pau Monné
  1 sibling, 0 replies; 3+ messages in thread
From: Jan Beulich @ 2022-06-23 12:03 UTC (permalink / raw)
  To: Andrew Cooper, Roger Pau Monné; +Cc: Wei Liu, xen-devel

On 13.09.2021 08:26, Jan Beulich wrote:
> asm() constraints need to fit both the intended insn(s) which the
> respective operands are going to be used with as well as the actual kind
> of value specified. "m" (alone) together with a constant, however, leads
> to gcc saying
> 
> error: memory input <N> is not directly addressable
> 
> while clang complains
> 
> error: invalid lvalue in asm input for constraint 'm'
> 
> And rightly so - in order to access a memory operand, an address needs
> to be specified to the insn. In some cases it might be possible for a
> compiler to synthesize a memory operand holding the requested constant,
> but I think any solution there would have sharp edges.
> 
> If "m" alone doesn't work with constants, it is at best pointless (and
> perhaps misleading or even risky - the compiler might decide to actually
> pick "m" and not try very hard to find a suitable register) to specify
> it alongside "r". And indeed clang does, oddly enough despite its
> objection to "m" alone. Which means there the change also improves the
> generated code.
> 
> While there also switch the two operand case to using named operands.
> 
> Signed-off-by: Jan Beulich <jbeulich@suse.com>
> ---
> v2: Use named operands in do_double_fault().

This has been pending for over 9 months. May I ask for feedback?

Thanks, Jan

> --- a/xen/arch/x86/cpu/amd.c
> +++ b/xen/arch/x86/cpu/amd.c
> @@ -736,7 +736,7 @@ void __init detect_zen2_null_seg_behavio
>  	uint64_t base;
>  
>  	wrmsrl(MSR_FS_BASE, 1);
> -	asm volatile ( "mov %0, %%fs" :: "rm" (0) );
> +	asm volatile ( "mov %0, %%fs" :: "r" (0) );
>  	rdmsrl(MSR_FS_BASE, base);
>  
>  	if (base == 0)
> --- a/xen/arch/x86/x86_64/traps.c
> +++ b/xen/arch/x86/x86_64/traps.c
> @@ -248,7 +248,8 @@ void do_double_fault(struct cpu_user_reg
>  
>      console_force_unlock();
>  
> -    asm ( "lsll %1, %0" : "=r" (cpu) : "rm" (PER_CPU_SELECTOR) );
> +    asm ( "lsll %[sel], %[limit]" : [limit] "=r" (cpu)
> +                                  : [sel] "r" (PER_CPU_SELECTOR) );
>  
>      /* Find information saved during fault and dump it to the console. */
>      printk("*** DOUBLE FAULT ***\n");



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

* Re: [PATCH v2] x86: correct asm() constraints when dealing with immediate selector values
  2021-09-13  6:26 [PATCH v2] x86: correct asm() constraints when dealing with immediate selector values Jan Beulich
  2022-06-23 12:03 ` Ping: " Jan Beulich
@ 2022-06-28 12:59 ` Roger Pau Monné
  1 sibling, 0 replies; 3+ messages in thread
From: Roger Pau Monné @ 2022-06-28 12:59 UTC (permalink / raw)
  To: Jan Beulich; +Cc: xen-devel, Andrew Cooper, Wei Liu

On Mon, Sep 13, 2021 at 08:26:21AM +0200, Jan Beulich wrote:
> asm() constraints need to fit both the intended insn(s) which the
> respective operands are going to be used with as well as the actual kind
> of value specified. "m" (alone) together with a constant, however, leads
> to gcc saying
> 
> error: memory input <N> is not directly addressable
> 
> while clang complains
> 
> error: invalid lvalue in asm input for constraint 'm'
> 
> And rightly so - in order to access a memory operand, an address needs
> to be specified to the insn. In some cases it might be possible for a
> compiler to synthesize a memory operand holding the requested constant,
> but I think any solution there would have sharp edges.
> 
> If "m" alone doesn't work with constants, it is at best pointless (and
> perhaps misleading or even risky - the compiler might decide to actually
> pick "m" and not try very hard to find a suitable register) to specify
> it alongside "r". And indeed clang does, oddly enough despite its
> objection to "m" alone. Which means there the change also improves the
> generated code.
> 
> While there also switch the two operand case to using named operands.
> 
> Signed-off-by: Jan Beulich <jbeulich@suse.com>

Acked-by: Roger Pau Monné <roger.pau@citrix.com>

Thanks, and sorry for the delay.

Roger.


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

end of thread, other threads:[~2022-06-28 12:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-13  6:26 [PATCH v2] x86: correct asm() constraints when dealing with immediate selector values Jan Beulich
2022-06-23 12:03 ` Ping: " Jan Beulich
2022-06-28 12:59 ` Roger Pau Monné

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.