linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ARM: Fix userspace enter on LPAE with CC_OPTIMIZE_FOR_SIZE=y
@ 2024-05-15 14:02 Geert Uytterhoeven
  2024-05-15 15:43 ` Ard Biesheuvel
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Geert Uytterhoeven @ 2024-05-15 14:02 UTC (permalink / raw)
  To: Russell King, Linus Walleij, Catalin Marinas, Kees Cook,
	Russell King, Florian Fainelli, Ard Biesheuvel, Arnd Bergmann,
	Stefan Wahren
  Cc: linux-arm-kernel, linux-renesas-soc, linux-kernel,
	Geert Uytterhoeven

Booting an LPAE-enabled kernel built with CONFIG_CC_OPTIMIZE_FOR_SIZE=y
fails when starting userspace:

    Kernel panic - not syncing: Attempted to kill init! exitcode=0x00000004
    CPU: 1 PID: 1 Comm: init Tainted: G        W        N 6.9.0-rc1-koelsch-00004-g7af5b901e847 #1930
    Hardware name: Generic R-Car Gen2 (Flattened Device Tree)
    Call trace:
     unwind_backtrace from show_stack+0x10/0x14
     show_stack from dump_stack_lvl+0x78/0xa8
     dump_stack_lvl from panic+0x118/0x398
     panic from do_exit+0x1ec/0x938
     do_exit from sys_exit_group+0x0/0x10
    ---[ end Kernel panic - not syncing: Attempted to kill init!  exitcode=0x00000004 ]---

Add the missing memory clobber to cpu_set_ttbcr(), as suggested by
Russell King.

Force inlining of uaccess_save_and_enable(), as suggested by Ard
Biesheuvel.

The latter fixes booting on Koelsch.

Fixes: 7af5b901e84743c6 ("ARM: 9358/2: Implement PAN for LPAE by TTBR0 page table walks disablement")
Closes: https://lore.kernel.org/r/CAMuHMdWTAJcZ9BReWNhpmsgkOzQxLNb5OhNYxzxv6D5TSh2fwQ@mail.gmail.com/
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
Feel free to fold into the original commit.

Apparently the "From: Catalin Marinas <catalin.marinas@arm.com>" in
https://lore.kernel.org/r/20240312-arm32-lpae-pan-v3-4-532647afcd38@linaro.org
is not reflected in commit 7af5b901e84743c6?
---
 arch/arm/include/asm/proc-fns.h | 2 +-
 arch/arm/include/asm/uaccess.h  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm/include/asm/proc-fns.h b/arch/arm/include/asm/proc-fns.h
index 9b3105a2a5e0691e..b4986a23d8528a50 100644
--- a/arch/arm/include/asm/proc-fns.h
+++ b/arch/arm/include/asm/proc-fns.h
@@ -187,7 +187,7 @@ static inline unsigned int cpu_get_ttbcr(void)
 
 static inline void cpu_set_ttbcr(unsigned int ttbcr)
 {
-	asm("mcr p15, 0, %0, c2, c0, 2" : : "r" (ttbcr));
+	asm volatile("mcr p15, 0, %0, c2, c0, 2" : : "r" (ttbcr) : "memory");
 }
 
 #else	/*!CONFIG_MMU */
diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
index 25d21d7d6e3efee0..6c9c16d767cfd5df 100644
--- a/arch/arm/include/asm/uaccess.h
+++ b/arch/arm/include/asm/uaccess.h
@@ -47,7 +47,7 @@ static __always_inline void uaccess_restore(unsigned int flags)
 
 #elif defined(CONFIG_CPU_TTBR0_PAN)
 
-static inline unsigned int uaccess_save_and_enable(void)
+static __always_inline unsigned int uaccess_save_and_enable(void)
 {
 	unsigned int old_ttbcr = cpu_get_ttbcr();
 
-- 
2.34.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] ARM: Fix userspace enter on LPAE with CC_OPTIMIZE_FOR_SIZE=y
  2024-05-15 14:02 [PATCH] ARM: Fix userspace enter on LPAE with CC_OPTIMIZE_FOR_SIZE=y Geert Uytterhoeven
@ 2024-05-15 15:43 ` Ard Biesheuvel
  2024-05-15 19:33 ` Linus Walleij
  2024-05-15 19:46 ` Florian Fainelli
  2 siblings, 0 replies; 5+ messages in thread
From: Ard Biesheuvel @ 2024-05-15 15:43 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Russell King, Linus Walleij, Catalin Marinas, Kees Cook,
	Russell King, Florian Fainelli, Arnd Bergmann, Stefan Wahren,
	linux-arm-kernel, linux-renesas-soc, linux-kernel

On Wed, 15 May 2024 at 16:02, Geert Uytterhoeven
<geert+renesas@glider.be> wrote:
>
> Booting an LPAE-enabled kernel built with CONFIG_CC_OPTIMIZE_FOR_SIZE=y
> fails when starting userspace:
>
>     Kernel panic - not syncing: Attempted to kill init! exitcode=0x00000004
>     CPU: 1 PID: 1 Comm: init Tainted: G        W        N 6.9.0-rc1-koelsch-00004-g7af5b901e847 #1930
>     Hardware name: Generic R-Car Gen2 (Flattened Device Tree)
>     Call trace:
>      unwind_backtrace from show_stack+0x10/0x14
>      show_stack from dump_stack_lvl+0x78/0xa8
>      dump_stack_lvl from panic+0x118/0x398
>      panic from do_exit+0x1ec/0x938
>      do_exit from sys_exit_group+0x0/0x10
>     ---[ end Kernel panic - not syncing: Attempted to kill init!  exitcode=0x00000004 ]---
>
> Add the missing memory clobber to cpu_set_ttbcr(), as suggested by
> Russell King.
>
> Force inlining of uaccess_save_and_enable(), as suggested by Ard
> Biesheuvel.
>
> The latter fixes booting on Koelsch.
>
> Fixes: 7af5b901e84743c6 ("ARM: 9358/2: Implement PAN for LPAE by TTBR0 page table walks disablement")
> Closes: https://lore.kernel.org/r/CAMuHMdWTAJcZ9BReWNhpmsgkOzQxLNb5OhNYxzxv6D5TSh2fwQ@mail.gmail.com/
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>

This works around what appears to be a compiler bug (see my reply to
the other thread), and this change (the __always_inline in particular)
seems to work around it, so

Acked-by: Ard Biesheuvel <ardb@kernel.org>


> ---
> Feel free to fold into the original commit.
>
> Apparently the "From: Catalin Marinas <catalin.marinas@arm.com>" in
> https://lore.kernel.org/r/20240312-arm32-lpae-pan-v3-4-532647afcd38@linaro.org
> is not reflected in commit 7af5b901e84743c6?
> ---
>  arch/arm/include/asm/proc-fns.h | 2 +-
>  arch/arm/include/asm/uaccess.h  | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/arch/arm/include/asm/proc-fns.h b/arch/arm/include/asm/proc-fns.h
> index 9b3105a2a5e0691e..b4986a23d8528a50 100644
> --- a/arch/arm/include/asm/proc-fns.h
> +++ b/arch/arm/include/asm/proc-fns.h
> @@ -187,7 +187,7 @@ static inline unsigned int cpu_get_ttbcr(void)
>
>  static inline void cpu_set_ttbcr(unsigned int ttbcr)
>  {
> -       asm("mcr p15, 0, %0, c2, c0, 2" : : "r" (ttbcr));
> +       asm volatile("mcr p15, 0, %0, c2, c0, 2" : : "r" (ttbcr) : "memory");
>  }
>
>  #else  /*!CONFIG_MMU */
> diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
> index 25d21d7d6e3efee0..6c9c16d767cfd5df 100644
> --- a/arch/arm/include/asm/uaccess.h
> +++ b/arch/arm/include/asm/uaccess.h
> @@ -47,7 +47,7 @@ static __always_inline void uaccess_restore(unsigned int flags)
>
>  #elif defined(CONFIG_CPU_TTBR0_PAN)
>
> -static inline unsigned int uaccess_save_and_enable(void)
> +static __always_inline unsigned int uaccess_save_and_enable(void)
>  {
>         unsigned int old_ttbcr = cpu_get_ttbcr();
>
> --
> 2.34.1
>

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] ARM: Fix userspace enter on LPAE with CC_OPTIMIZE_FOR_SIZE=y
  2024-05-15 14:02 [PATCH] ARM: Fix userspace enter on LPAE with CC_OPTIMIZE_FOR_SIZE=y Geert Uytterhoeven
  2024-05-15 15:43 ` Ard Biesheuvel
@ 2024-05-15 19:33 ` Linus Walleij
  2024-05-15 19:46 ` Florian Fainelli
  2 siblings, 0 replies; 5+ messages in thread
From: Linus Walleij @ 2024-05-15 19:33 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Russell King, Catalin Marinas, Kees Cook, Russell King,
	Florian Fainelli, Ard Biesheuvel, Arnd Bergmann, Stefan Wahren,
	linux-arm-kernel, linux-renesas-soc, linux-kernel

On Wed, May 15, 2024 at 4:02 PM Geert Uytterhoeven
<geert+renesas@glider.be> wrote:

> Booting an LPAE-enabled kernel built with CONFIG_CC_OPTIMIZE_FOR_SIZE=y
> fails when starting userspace:
>
>     Kernel panic - not syncing: Attempted to kill init! exitcode=0x00000004
>     CPU: 1 PID: 1 Comm: init Tainted: G        W        N 6.9.0-rc1-koelsch-00004-g7af5b901e847 #1930
>     Hardware name: Generic R-Car Gen2 (Flattened Device Tree)
>     Call trace:
>      unwind_backtrace from show_stack+0x10/0x14
>      show_stack from dump_stack_lvl+0x78/0xa8
>      dump_stack_lvl from panic+0x118/0x398
>      panic from do_exit+0x1ec/0x938
>      do_exit from sys_exit_group+0x0/0x10
>     ---[ end Kernel panic - not syncing: Attempted to kill init!  exitcode=0x00000004 ]---
>
> Add the missing memory clobber to cpu_set_ttbcr(), as suggested by
> Russell King.
>
> Force inlining of uaccess_save_and_enable(), as suggested by Ard
> Biesheuvel.
>
> The latter fixes booting on Koelsch.
>
> Fixes: 7af5b901e84743c6 ("ARM: 9358/2: Implement PAN for LPAE by TTBR0 page table walks disablement")
> Closes: https://lore.kernel.org/r/CAMuHMdWTAJcZ9BReWNhpmsgkOzQxLNb5OhNYxzxv6D5TSh2fwQ@mail.gmail.com/
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Thanks for digging into this, both you and Ard! And we found the root
cause it seems.

Yours,
Linus Walleij

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] ARM: Fix userspace enter on LPAE with CC_OPTIMIZE_FOR_SIZE=y
  2024-05-15 14:02 [PATCH] ARM: Fix userspace enter on LPAE with CC_OPTIMIZE_FOR_SIZE=y Geert Uytterhoeven
  2024-05-15 15:43 ` Ard Biesheuvel
  2024-05-15 19:33 ` Linus Walleij
@ 2024-05-15 19:46 ` Florian Fainelli
  2024-05-16  9:26   ` Russell King (Oracle)
  2 siblings, 1 reply; 5+ messages in thread
From: Florian Fainelli @ 2024-05-15 19:46 UTC (permalink / raw)
  To: Geert Uytterhoeven, Russell King, Linus Walleij, Catalin Marinas,
	Kees Cook, Russell King, Ard Biesheuvel, Arnd Bergmann,
	Stefan Wahren
  Cc: linux-arm-kernel, linux-renesas-soc, linux-kernel


[-- Attachment #1.1: Type: text/plain, Size: 1307 bytes --]

On 5/15/24 07:02, Geert Uytterhoeven wrote:
> Booting an LPAE-enabled kernel built with CONFIG_CC_OPTIMIZE_FOR_SIZE=y
> fails when starting userspace:
> 
>      Kernel panic - not syncing: Attempted to kill init! exitcode=0x00000004
>      CPU: 1 PID: 1 Comm: init Tainted: G        W        N 6.9.0-rc1-koelsch-00004-g7af5b901e847 #1930
>      Hardware name: Generic R-Car Gen2 (Flattened Device Tree)
>      Call trace:
>       unwind_backtrace from show_stack+0x10/0x14
>       show_stack from dump_stack_lvl+0x78/0xa8
>       dump_stack_lvl from panic+0x118/0x398
>       panic from do_exit+0x1ec/0x938
>       do_exit from sys_exit_group+0x0/0x10
>      ---[ end Kernel panic - not syncing: Attempted to kill init!  exitcode=0x00000004 ]---
> 
> Add the missing memory clobber to cpu_set_ttbcr(), as suggested by
> Russell King.
> 
> Force inlining of uaccess_save_and_enable(), as suggested by Ard
> Biesheuvel.
> 
> The latter fixes booting on Koelsch.
> 
> Fixes: 7af5b901e84743c6 ("ARM: 9358/2: Implement PAN for LPAE by TTBR0 page table walks disablement")
> Closes: https://lore.kernel.org/r/CAMuHMdWTAJcZ9BReWNhpmsgkOzQxLNb5OhNYxzxv6D5TSh2fwQ@mail.gmail.com/
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>

Tested-by: Florian Fainelli <florian.fainelli@broadcom.com>
-- 
Florian


[-- Attachment #1.2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4221 bytes --]

[-- Attachment #2: Type: text/plain, Size: 176 bytes --]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] ARM: Fix userspace enter on LPAE with CC_OPTIMIZE_FOR_SIZE=y
  2024-05-15 19:46 ` Florian Fainelli
@ 2024-05-16  9:26   ` Russell King (Oracle)
  0 siblings, 0 replies; 5+ messages in thread
From: Russell King (Oracle) @ 2024-05-16  9:26 UTC (permalink / raw)
  To: Florian Fainelli
  Cc: Geert Uytterhoeven, Linus Walleij, Catalin Marinas, Kees Cook,
	Ard Biesheuvel, Arnd Bergmann, Stefan Wahren, linux-arm-kernel,
	linux-renesas-soc, linux-kernel

On Wed, May 15, 2024 at 12:46:38PM -0700, Florian Fainelli wrote:
> On 5/15/24 07:02, Geert Uytterhoeven wrote:
> > Booting an LPAE-enabled kernel built with CONFIG_CC_OPTIMIZE_FOR_SIZE=y
> > fails when starting userspace:
> > 
> >      Kernel panic - not syncing: Attempted to kill init! exitcode=0x00000004
> >      CPU: 1 PID: 1 Comm: init Tainted: G        W        N 6.9.0-rc1-koelsch-00004-g7af5b901e847 #1930
> >      Hardware name: Generic R-Car Gen2 (Flattened Device Tree)
> >      Call trace:
> >       unwind_backtrace from show_stack+0x10/0x14
> >       show_stack from dump_stack_lvl+0x78/0xa8
> >       dump_stack_lvl from panic+0x118/0x398
> >       panic from do_exit+0x1ec/0x938
> >       do_exit from sys_exit_group+0x0/0x10
> >      ---[ end Kernel panic - not syncing: Attempted to kill init!  exitcode=0x00000004 ]---
> > 
> > Add the missing memory clobber to cpu_set_ttbcr(), as suggested by
> > Russell King.
> > 
> > Force inlining of uaccess_save_and_enable(), as suggested by Ard
> > Biesheuvel.
> > 
> > The latter fixes booting on Koelsch.
> > 
> > Fixes: 7af5b901e84743c6 ("ARM: 9358/2: Implement PAN for LPAE by TTBR0 page table walks disablement")
> > Closes: https://lore.kernel.org/r/CAMuHMdWTAJcZ9BReWNhpmsgkOzQxLNb5OhNYxzxv6D5TSh2fwQ@mail.gmail.com/
> > Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> 
> Tested-by: Florian Fainelli <florian.fainelli@broadcom.com>

This should be in linux-next now, if not by tomorrow - it was pushed
out yesterday.

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2024-05-16  9:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-15 14:02 [PATCH] ARM: Fix userspace enter on LPAE with CC_OPTIMIZE_FOR_SIZE=y Geert Uytterhoeven
2024-05-15 15:43 ` Ard Biesheuvel
2024-05-15 19:33 ` Linus Walleij
2024-05-15 19:46 ` Florian Fainelli
2024-05-16  9:26   ` Russell King (Oracle)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).