Re: [PATCH 2/2] alpha: read $gp and $sp explicitly for clang

Magnus Lindholm <[email protected]> Mon, 3 Aug 2026 23:15:51 +0200
Newsgroups org.kernel.vger.linux-kbuild,dev.linux.lists.llvm,org.kernel.vger.linux-alpha,org.kernel.vger.linux-kernel
Message-ID <CA+=Fv5R0tdFeEKWgSVTjfXbs=guZmR8zy8FGbqUZNSKiyB24aA@mail.gmail.com>
Hi Matt,

On Mon, Aug 3, 2026 at 7:08=E2=80=AFPM Matt Turner <[email protected]> wro=
te:
>
> clang honors a local `register unsigned long x __asm__("$N")` variable
> only where it appears as an inline-asm operand; merely reading it does
> not produce the contents of that register.  So trap_init() passed an
> undefined global pointer to PAL_wrkgp, and load_PCB() stored an undefined
> stack pointer into the PCB that swpctx then loaded.  Either one wedges an
> early boot.
>
> Read the registers explicitly instead: an inline mov for $gp in
> trap_init(), and the file-scope current_stack_pointer for $sp in
> load_PCB().  A file-scope register-asm variable is the form clang does
> support.
>
> Signed-off-by: Matt Turner <[email protected]>
> ---
>  arch/alpha/kernel/traps.c | 4 +++-
>  arch/alpha/mm/init.c      | 3 +--
>  2 files changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/arch/alpha/kernel/traps.c b/arch/alpha/kernel/traps.c
> index 7631129ac914..5b4f1ae2b74b 100644
> --- a/arch/alpha/kernel/traps.c
> +++ b/arch/alpha/kernel/traps.c
> @@ -925,7 +925,9 @@ void
>  trap_init(void)
>  {
>         /* Tell PAL-code what global pointer we want in the kernel.  */
> -       register unsigned long gptr __asm__("$29");
> +       unsigned long gptr;
> +
> +       __asm__ volatile("mov $29, %0" : "=3Dr"(gptr));
>         wrkgp(gptr);
>
>         wrent(entArith, 1);
> diff --git a/arch/alpha/mm/init.c b/arch/alpha/mm/init.c
> index 9531cbc761c0..f4d65a60c869 100644
> --- a/arch/alpha/mm/init.c
> +++ b/arch/alpha/mm/init.c
> @@ -63,8 +63,7 @@ pgd_alloc(struct mm_struct *mm)
>  static inline unsigned long
>  load_PCB(struct pcb_struct *pcb)
>  {
> -       register unsigned long sp __asm__("$30");
> -       pcb->ksp =3D sp;
> +       pcb->ksp =3D (unsigned long)current_stack_pointer;
>         return __reload_thread(pcb);
>  }
>
>
> --
> 2.54.0
>

This looks good to me. The explicit $gp read and use of
current_stack_pointer avoid relying on the unsupported local
register-asm behavior.

I also built and booted the patched kernel successfully with GCC on an
AlphaStation DS10.

Reviewed-by: Magnus Lindholm [email protected]
Tested-by: Magnus Lindholm [email protected]

I am happy to take this through the Alpha tree.

Thanks,
Magnus