[RFC PATCH PoC 01/11] x86/linkage: Add SYM_PI_ALIAS() macro helper to emit symbol aliases

Ard Biesheuvel posted 11 patches 8 months ago
There is a newer version of this series
[RFC PATCH PoC 01/11] x86/linkage: Add SYM_PI_ALIAS() macro helper to emit symbol aliases
Posted by Ard Biesheuvel 8 months ago
From: Ard Biesheuvel <ardb@kernel.org>

Startup code that may execute from the early 1:1 mapping of memory will
be confined into its own address space, and only be permitted to access
ordinary kernel symbols if this is known to be safe.

Introduce a macro helper PI_ALIAS() that emits a __pi_ prefixed alias
for a symbol, which allows startup code to access it.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
 arch/x86/include/asm/linkage.h | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/arch/x86/include/asm/linkage.h b/arch/x86/include/asm/linkage.h
index b51d8a4673f5..ad59ff384f72 100644
--- a/arch/x86/include/asm/linkage.h
+++ b/arch/x86/include/asm/linkage.h
@@ -141,5 +141,11 @@
 #define SYM_FUNC_START_WEAK_NOALIGN(name)		\
 	SYM_START(name, SYM_L_WEAK, SYM_A_NONE)
 
+#ifdef __ASSEMBLER__
+#define SYM_PI_ALIAS(sym)	SYM_ALIAS(__pi_ ## sym, sym, SYM_L_GLOBAL)
+#else
+#define SYM_PI_ALIAS(sym)	extern typeof(sym) __PASTE(__pi_, sym) __alias(sym)
+#endif
+
 #endif /* _ASM_X86_LINKAGE_H */
 
-- 
2.49.0.805.g082f7c87e0-goog
Re: [RFC PATCH PoC 01/11] x86/linkage: Add SYM_PI_ALIAS() macro helper to emit symbol aliases
Posted by Ingo Molnar 7 months, 4 weeks ago
* Ard Biesheuvel <ardb+git@google.com> wrote:

> From: Ard Biesheuvel <ardb@kernel.org>
> 
> Startup code that may execute from the early 1:1 mapping of memory will
> be confined into its own address space, and only be permitted to access
> ordinary kernel symbols if this is known to be safe.
> 
> Introduce a macro helper PI_ALIAS() that emits a __pi_ prefixed alias
> for a symbol, which allows startup code to access it.

s/PI_ALIAS
 /SYM_PI_ALIAS

What does 'PI' stand for? 'Physical memory Identity' map?

Thanks,

	Ingo
Re: [RFC PATCH PoC 01/11] x86/linkage: Add SYM_PI_ALIAS() macro helper to emit symbol aliases
Posted by Ard Biesheuvel 7 months, 4 weeks ago
On Thu, 24 Apr 2025 at 20:05, Ingo Molnar <mingo@kernel.org> wrote:
>
>
> * Ard Biesheuvel <ardb+git@google.com> wrote:
>
> > From: Ard Biesheuvel <ardb@kernel.org>
> >
> > Startup code that may execute from the early 1:1 mapping of memory will
> > be confined into its own address space, and only be permitted to access
> > ordinary kernel symbols if this is known to be safe.
> >
> > Introduce a macro helper PI_ALIAS() that emits a __pi_ prefixed alias
> > for a symbol, which allows startup code to access it.
>
> s/PI_ALIAS
>  /SYM_PI_ALIAS
>
> What does 'PI' stand for? 'Physical memory Identity' map?
>

'position independent' - it's what we ended up with on arm64, but I'm
not attached to it so happy to switch to something better.
Re: [RFC PATCH PoC 01/11] x86/linkage: Add SYM_PI_ALIAS() macro helper to emit symbol aliases
Posted by Ingo Molnar 7 months, 4 weeks ago
* Ard Biesheuvel <ardb@kernel.org> wrote:

> On Thu, 24 Apr 2025 at 20:05, Ingo Molnar <mingo@kernel.org> wrote:
> >
> >
> > * Ard Biesheuvel <ardb+git@google.com> wrote:
> >
> > > From: Ard Biesheuvel <ardb@kernel.org>
> > >
> > > Startup code that may execute from the early 1:1 mapping of memory will
> > > be confined into its own address space, and only be permitted to access
> > > ordinary kernel symbols if this is known to be safe.
> > >
> > > Introduce a macro helper PI_ALIAS() that emits a __pi_ prefixed alias
> > > for a symbol, which allows startup code to access it.
> >
> > s/PI_ALIAS
> >  /SYM_PI_ALIAS
> >
> > What does 'PI' stand for? 'Physical memory Identity' map?
> >
> 
> 'position independent'

/facepalm

Clearly it's getting late here :)

> - it's what we ended up with on arm64, but I'm
> not attached to it so happy to switch to something better.

Could we make it something like SYM_PIC_ALIAS() at least? Because 'PIC' 
is something most people will recognize in this context. PI goes for 
3.1415. ;-)

Thanks,

	Ingo