mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] compiler: remove stringification from __ADDRESSABLE_ASM()
@ 2025-02-12 15:11 Jan Beulich
  2025-02-12 23:32 ` Josh Poimboeuf
  0 siblings, 1 reply; 3+ messages in thread
From: Jan Beulich @ 2025-02-12 15:11 UTC (permalink / raw)
  To: lkml; +Cc: Juergen Gross, Josh Poimboeuf, Peter Zijlstra, Luc Van Oostenryck

__ADDRESSABLE_ASM_STR() is where the necessary stringification happens.
As long as "sym" doesn't contain any odd characters, no quoting is
required for its use with .quad / .long. In fact the quotation gets in
the way with gas 2.25; it's only from 2.26 onwards that quoted symbols
are half-way properly supported.

Fixes: 0ef8047b737d ("x86/static-call: provide a way to do very early static-call updates")
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Cc: stable@vger.kernel.org
---
I think that __ADDRESSABLE_ASM{,_STR}() better would have a separate
comment, as that presently kind of shared with {_,}__ADDRESSABLE() isn't
really applicable to assembly code.

Is data allocation actually necessary in __ADDRESSABLE_ASM()? Aiui the
sole goal is to have sym in the symbol table. That could be achieved by
a simple .global (or e.g. .hidden) directive.

Shouldn't Xen's __ADDRESSABLE_xen_hypercall use STATIC_CALL_KEY() rather
than open-coding it?

--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -245,7 +245,7 @@ static inline void *offset_to_ptr(const
 #define __ADDRESSABLE_ASM(sym)						\
 	.pushsection .discard.addressable,"aw";				\
 	.align ARCH_SEL(8,4);						\
-	ARCH_SEL(.quad, .long) __stringify(sym);			\
+	ARCH_SEL(.quad, .long) sym;					\
 	.popsection;
 
 #define __ADDRESSABLE_ASM_STR(sym) __stringify(__ADDRESSABLE_ASM(sym))

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

* Re: [PATCH] compiler: remove stringification from __ADDRESSABLE_ASM()
  2025-02-12 15:11 [PATCH] compiler: remove stringification from __ADDRESSABLE_ASM() Jan Beulich
@ 2025-02-12 23:32 ` Josh Poimboeuf
  2025-02-12 23:41   ` Josh Poimboeuf
  0 siblings, 1 reply; 3+ messages in thread
From: Josh Poimboeuf @ 2025-02-12 23:32 UTC (permalink / raw)
  To: Jan Beulich; +Cc: lkml, Juergen Gross, Peter Zijlstra, Luc Van Oostenryck

On Wed, Feb 12, 2025 at 04:11:51PM +0100, Jan Beulich wrote:
> __ADDRESSABLE_ASM_STR() is where the necessary stringification happens.
> As long as "sym" doesn't contain any odd characters, no quoting is
> required for its use with .quad / .long. In fact the quotation gets in
> the way with gas 2.25; it's only from 2.26 onwards that quoted symbols
> are half-way properly supported.
> 
> Fixes: 0ef8047b737d ("x86/static-call: provide a way to do very early static-call updates")
> Signed-off-by: Jan Beulich <jbeulich@suse.com>
> Cc: stable@vger.kernel.org
> ---
> I think that __ADDRESSABLE_ASM{,_STR}() better would have a separate
> comment, as that presently kind of shared with {_,}__ADDRESSABLE() isn't
> really applicable to assembly code.
> 
> Is data allocation actually necessary in __ADDRESSABLE_ASM()? Aiui the
> sole goal is to have sym in the symbol table. That could be achieved by
> a simple .global (or e.g. .hidden) directive.

Hm, yes, but isn't that a bug?  It shouldn't be defining the symbol, as
that will already be defined elsewhere.  So it would link to the local
symbol instead of the actual static key defined in another object.

Even worse, the local symbol gets discarded during linking?  Not sure
how that works without a linker error...

.global sounds like it would work, then we can just remove all the
__ADDRESSABLE_ASM() cruft.

> Shouldn't Xen's __ADDRESSABLE_xen_hypercall use STATIC_CALL_KEY() rather
> than open-coding it?

Indeed...

> --- a/include/linux/compiler.h
> +++ b/include/linux/compiler.h
> @@ -245,7 +245,7 @@ static inline void *offset_to_ptr(const
>  #define __ADDRESSABLE_ASM(sym)						\
>  	.pushsection .discard.addressable,"aw";				\
>  	.align ARCH_SEL(8,4);						\
> -	ARCH_SEL(.quad, .long) __stringify(sym);			\
> +	ARCH_SEL(.quad, .long) sym;					\
>  	.popsection;
>  
>  #define __ADDRESSABLE_ASM_STR(sym) __stringify(__ADDRESSABLE_ASM(sym))

-- 
Josh

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

* Re: [PATCH] compiler: remove stringification from __ADDRESSABLE_ASM()
  2025-02-12 23:32 ` Josh Poimboeuf
@ 2025-02-12 23:41   ` Josh Poimboeuf
  0 siblings, 0 replies; 3+ messages in thread
From: Josh Poimboeuf @ 2025-02-12 23:41 UTC (permalink / raw)
  To: Jan Beulich; +Cc: lkml, Juergen Gross, Peter Zijlstra, Luc Van Oostenryck

On Wed, Feb 12, 2025 at 03:32:44PM -0800, Josh Poimboeuf wrote:
> > I think that __ADDRESSABLE_ASM{,_STR}() better would have a separate
> > comment, as that presently kind of shared with {_,}__ADDRESSABLE() isn't
> > really applicable to assembly code.
> > 
> > Is data allocation actually necessary in __ADDRESSABLE_ASM()? Aiui the
> > sole goal is to have sym in the symbol table. That could be achieved by
> > a simple .global (or e.g. .hidden) directive.
> 
> Hm, yes, but isn't that a bug?  It shouldn't be defining the symbol, as
> that will already be defined elsewhere.  So it would link to the local
> symbol instead of the actual static key defined in another object.
> 
> Even worse, the local symbol gets discarded during linking?  Not sure
> how that works without a linker error...

Oh, I forgot how my patch worked.  __ADDRESSABLE_ASM is defining a
pointer to the symbol, not defining the symbol itself.  So forget all
that :-)

But yes, using .global with STATIC_CALL_KEY() sounds like a much easier
way.

-- 
Josh

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

end of thread, other threads:[~2025-02-12 23:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-12 15:11 [PATCH] compiler: remove stringification from __ADDRESSABLE_ASM() Jan Beulich
2025-02-12 23:32 ` Josh Poimboeuf
2025-02-12 23:41   ` Josh Poimboeuf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®