All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ard Biesheuvel <ardb@kernel.org>
To: Arnd Bergmann <arnd@kernel.org>
Cc: Russell King <linux@armlinux.org.uk>,
	Arnd Bergmann <arnd@arndb.de>, "# 3.4.x" <stable@vger.kernel.org>,
	Daniel Thompson <daniel.thompson@linaro.org>,
	Marek Vasut <marek.vasut@gmail.com>,
	Nathan Chancellor <nathan@kernel.org>,
	Nick Desaulniers <ndesaulniers@google.com>,
	Linus Walleij <linus.walleij@linaro.org>,
	Nicolas Pitre <nico@fluxnic.net>,
	Geert Uytterhoeven <geert+renesas@glider.be>,
	Mike Rapoport <rppt@kernel.org>,
	Linux ARM <linux-arm-kernel@lists.infradead.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	clang-built-linux <clang-built-linux@googlegroups.com>
Subject: Re: [PATCH] ARM: fix gcc-10 thumb2-kernel regression
Date: Wed, 12 May 2021 14:38:36 +0200	[thread overview]
Message-ID: <CAMj1kXECGjpxx5ouWuvnKUigzMGu=GcE8_ab2rrxt98yU1jUnw@mail.gmail.com> (raw)
In-Reply-To: <20210512081211.200025-1-arnd@kernel.org>

On Wed, 12 May 2021 at 10:13, Arnd Bergmann <arnd@kernel.org> wrote:
>
> From: Arnd Bergmann <arnd@arndb.de>
>
> When building the kernel wtih gcc-10 or higher using the
> CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE=y flag, the compiler picks a slightly
> different set of registers for the inline assembly in cpu_init() that
> subsequently results in a corrupt kernel stack as well as remaining in
> FIQ mode. If a banked register is used for the last argument, the wrong
> version of that register gets loaded into CPSR_c.  When building in Arm
> mode, the arguments are passed as immediate values and the bug cannot
> happen.
>
> This got introduced when Daniel reworked the FIQ handling and was
> technically always broken, but happened to work with both clang and gcc
> before gcc-10 as long as they picked one of the lower registers.
> This is probably an indication that still very few people build the
> kernel in Thumb2 mode.
>
> Marek pointed out the problem on IRC, Arnd narrowed it down to this
> inline assembly and Russell pinpointed the exact bug.
>
> Change the constraints to force the final mode switch to use a non-banked
> register for the argument to ensure that the correct constant gets loaded.
> Another alternative would be to always use registers for the constant
> arguments to avoid the #ifdef that has now become more complex.
>
> Cc: <stable@vger.kernel.org> # v3.18+
> Cc: Daniel Thompson <daniel.thompson@linaro.org>
> Reported-by: Marek Vasut <marek.vasut@gmail.com>
> Fixes: c0e7f7ee717e ("ARM: 8150/3: fiq: Replace default FIQ handler")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Nice bug!

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

> ---
>  arch/arm/kernel/setup.c | 16 +++++++++-------
>  1 file changed, 9 insertions(+), 7 deletions(-)
>
> diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
> index 1a5edf562e85..73ca7797b92f 100644
> --- a/arch/arm/kernel/setup.c
> +++ b/arch/arm/kernel/setup.c
> @@ -545,9 +545,11 @@ void notrace cpu_init(void)
>          * In Thumb-2, msr with an immediate value is not allowed.
>          */
>  #ifdef CONFIG_THUMB2_KERNEL
> -#define PLC    "r"
> +#define PLC_l  "l"
> +#define PLC_r  "r"
>  #else
> -#define PLC    "I"
> +#define PLC_l  "I"
> +#define PLC_r  "I"
>  #endif
>
>         /*
> @@ -569,15 +571,15 @@ void notrace cpu_init(void)
>         "msr    cpsr_c, %9"
>             :
>             : "r" (stk),
> -             PLC (PSR_F_BIT | PSR_I_BIT | IRQ_MODE),
> +             PLC_r (PSR_F_BIT | PSR_I_BIT | IRQ_MODE),
>               "I" (offsetof(struct stack, irq[0])),
> -             PLC (PSR_F_BIT | PSR_I_BIT | ABT_MODE),
> +             PLC_r (PSR_F_BIT | PSR_I_BIT | ABT_MODE),
>               "I" (offsetof(struct stack, abt[0])),
> -             PLC (PSR_F_BIT | PSR_I_BIT | UND_MODE),
> +             PLC_r (PSR_F_BIT | PSR_I_BIT | UND_MODE),
>               "I" (offsetof(struct stack, und[0])),
> -             PLC (PSR_F_BIT | PSR_I_BIT | FIQ_MODE),
> +             PLC_r (PSR_F_BIT | PSR_I_BIT | FIQ_MODE),
>               "I" (offsetof(struct stack, fiq[0])),
> -             PLC (PSR_F_BIT | PSR_I_BIT | SVC_MODE)
> +             PLC_l (PSR_F_BIT | PSR_I_BIT | SVC_MODE)
>             : "r14");
>  #endif
>  }
> --
> 2.29.2
>

WARNING: multiple messages have this Message-ID (diff)
From: Ard Biesheuvel <ardb@kernel.org>
To: Arnd Bergmann <arnd@kernel.org>
Cc: Russell King <linux@armlinux.org.uk>,
	Arnd Bergmann <arnd@arndb.de>,
	 "# 3.4.x" <stable@vger.kernel.org>,
	Daniel Thompson <daniel.thompson@linaro.org>,
	 Marek Vasut <marek.vasut@gmail.com>,
	Nathan Chancellor <nathan@kernel.org>,
	 Nick Desaulniers <ndesaulniers@google.com>,
	Linus Walleij <linus.walleij@linaro.org>,
	 Nicolas Pitre <nico@fluxnic.net>,
	Geert Uytterhoeven <geert+renesas@glider.be>,
	Mike Rapoport <rppt@kernel.org>,
	Linux ARM <linux-arm-kernel@lists.infradead.org>,
	 Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	 clang-built-linux <clang-built-linux@googlegroups.com>
Subject: Re: [PATCH] ARM: fix gcc-10 thumb2-kernel regression
Date: Wed, 12 May 2021 14:38:36 +0200	[thread overview]
Message-ID: <CAMj1kXECGjpxx5ouWuvnKUigzMGu=GcE8_ab2rrxt98yU1jUnw@mail.gmail.com> (raw)
In-Reply-To: <20210512081211.200025-1-arnd@kernel.org>

On Wed, 12 May 2021 at 10:13, Arnd Bergmann <arnd@kernel.org> wrote:
>
> From: Arnd Bergmann <arnd@arndb.de>
>
> When building the kernel wtih gcc-10 or higher using the
> CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE=y flag, the compiler picks a slightly
> different set of registers for the inline assembly in cpu_init() that
> subsequently results in a corrupt kernel stack as well as remaining in
> FIQ mode. If a banked register is used for the last argument, the wrong
> version of that register gets loaded into CPSR_c.  When building in Arm
> mode, the arguments are passed as immediate values and the bug cannot
> happen.
>
> This got introduced when Daniel reworked the FIQ handling and was
> technically always broken, but happened to work with both clang and gcc
> before gcc-10 as long as they picked one of the lower registers.
> This is probably an indication that still very few people build the
> kernel in Thumb2 mode.
>
> Marek pointed out the problem on IRC, Arnd narrowed it down to this
> inline assembly and Russell pinpointed the exact bug.
>
> Change the constraints to force the final mode switch to use a non-banked
> register for the argument to ensure that the correct constant gets loaded.
> Another alternative would be to always use registers for the constant
> arguments to avoid the #ifdef that has now become more complex.
>
> Cc: <stable@vger.kernel.org> # v3.18+
> Cc: Daniel Thompson <daniel.thompson@linaro.org>
> Reported-by: Marek Vasut <marek.vasut@gmail.com>
> Fixes: c0e7f7ee717e ("ARM: 8150/3: fiq: Replace default FIQ handler")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Nice bug!

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

> ---
>  arch/arm/kernel/setup.c | 16 +++++++++-------
>  1 file changed, 9 insertions(+), 7 deletions(-)
>
> diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
> index 1a5edf562e85..73ca7797b92f 100644
> --- a/arch/arm/kernel/setup.c
> +++ b/arch/arm/kernel/setup.c
> @@ -545,9 +545,11 @@ void notrace cpu_init(void)
>          * In Thumb-2, msr with an immediate value is not allowed.
>          */
>  #ifdef CONFIG_THUMB2_KERNEL
> -#define PLC    "r"
> +#define PLC_l  "l"
> +#define PLC_r  "r"
>  #else
> -#define PLC    "I"
> +#define PLC_l  "I"
> +#define PLC_r  "I"
>  #endif
>
>         /*
> @@ -569,15 +571,15 @@ void notrace cpu_init(void)
>         "msr    cpsr_c, %9"
>             :
>             : "r" (stk),
> -             PLC (PSR_F_BIT | PSR_I_BIT | IRQ_MODE),
> +             PLC_r (PSR_F_BIT | PSR_I_BIT | IRQ_MODE),
>               "I" (offsetof(struct stack, irq[0])),
> -             PLC (PSR_F_BIT | PSR_I_BIT | ABT_MODE),
> +             PLC_r (PSR_F_BIT | PSR_I_BIT | ABT_MODE),
>               "I" (offsetof(struct stack, abt[0])),
> -             PLC (PSR_F_BIT | PSR_I_BIT | UND_MODE),
> +             PLC_r (PSR_F_BIT | PSR_I_BIT | UND_MODE),
>               "I" (offsetof(struct stack, und[0])),
> -             PLC (PSR_F_BIT | PSR_I_BIT | FIQ_MODE),
> +             PLC_r (PSR_F_BIT | PSR_I_BIT | FIQ_MODE),
>               "I" (offsetof(struct stack, fiq[0])),
> -             PLC (PSR_F_BIT | PSR_I_BIT | SVC_MODE)
> +             PLC_l (PSR_F_BIT | PSR_I_BIT | SVC_MODE)
>             : "r14");
>  #endif
>  }
> --
> 2.29.2
>

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

  reply	other threads:[~2021-05-12 12:38 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-12  8:12 [PATCH] ARM: fix gcc-10 thumb2-kernel regression Arnd Bergmann
2021-05-12  8:12 ` Arnd Bergmann
2021-05-12 12:38 ` Ard Biesheuvel [this message]
2021-05-12 12:38   ` Ard Biesheuvel
2021-05-13 11:07   ` Daniel Thompson
2021-05-13 11:07     ` Daniel Thompson
2021-05-17 10:18 ` Linus Walleij
2021-05-17 10:18   ` Linus Walleij
2021-05-14 10:24 Arnd Bergmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAMj1kXECGjpxx5ouWuvnKUigzMGu=GcE8_ab2rrxt98yU1jUnw@mail.gmail.com' \
    --to=ardb@kernel.org \
    --cc=arnd@arndb.de \
    --cc=arnd@kernel.org \
    --cc=clang-built-linux@googlegroups.com \
    --cc=daniel.thompson@linaro.org \
    --cc=geert+renesas@glider.be \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=marek.vasut@gmail.com \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=nico@fluxnic.net \
    --cc=rppt@kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.