[PATCH] ARM: select HAVE_FUTEX_CMPXCHG

5 views
Skip to first unread message

Nick Desaulniers

unread,
Aug 30, 2021, 5:38:52 PM8/30/21
to linux-ar...@lists.infradead.org, ll...@lists.linux.dev, Nick Desaulniers, Arnd Bergmann, Nathan Chancellor, Thomas Gleixner, Russell King, Geert Uytterhoeven, Linus Walleij, Andrew Morton, Anshuman Khandual, Ard Biesheuvel, YiFei Zhu, Uwe Kleine-König, Mike Rapoport, linux-...@vger.kernel.org, clang-bu...@googlegroups.com
tglx notes:
This function [futex_detect_cmpxchg] is only needed when an
architecture has to runtime discover whether the CPU supports it or
not. ARM has unconditional support for this, so the obvious thing to
do is the below.

Fixes linkage failure from Clang randconfigs:
kernel/futex.o:(.text.fixup+0x5c): relocation truncated to fit: R_ARM_JUMP24 against `.init.text'
and boot failures for CONFIG_THUMB2_KERNEL.

Link: https://github.com/ClangBuiltLinux/linux/issues/325
Reported-by: Arnd Bergmann <ar...@arndb.de>
Reported-by: Nathan Chancellor <nat...@kernel.org>
Suggested-by: Thomas Gleixner <tg...@linutronix.de>
Signed-off-by: Nick Desaulniers <ndesau...@google.com>
---
arch/arm/Kconfig | 1 +
1 file changed, 1 insertion(+)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index fc196421b2ce..b760dd45b734 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -92,6 +92,7 @@ config ARM
select HAVE_FTRACE_MCOUNT_RECORD if !XIP_KERNEL
select HAVE_FUNCTION_GRAPH_TRACER if !THUMB2_KERNEL && !CC_IS_CLANG
select HAVE_FUNCTION_TRACER if !XIP_KERNEL
+ select HAVE_FUTEX_CMPXCHG if FUTEX
select HAVE_GCC_PLUGINS
select HAVE_HW_BREAKPOINT if PERF_EVENTS && (CPU_V6 || CPU_V6K || CPU_V7)
select HAVE_IRQ_TIME_ACCOUNTING
--
2.33.0.259.gc128427fd7-goog

Thomas Gleixner

unread,
Aug 30, 2021, 7:17:48 PM8/30/21
to Nick Desaulniers, linux-ar...@lists.infradead.org, ll...@lists.linux.dev, Nick Desaulniers, Arnd Bergmann, Nathan Chancellor, Russell King, Geert Uytterhoeven, Linus Walleij, Andrew Morton, Anshuman Khandual, Ard Biesheuvel, YiFei Zhu, Uwe Kleine-König, Mike Rapoport, linux-...@vger.kernel.org, clang-bu...@googlegroups.com
On Mon, Aug 30 2021 at 14:38, Nick Desaulniers wrote:

> tglx notes:
> This function [futex_detect_cmpxchg] is only needed when an
> architecture has to runtime discover whether the CPU supports it or
> not. ARM has unconditional support for this, so the obvious thing to
> do is the below.
>
> Fixes linkage failure from Clang randconfigs:
> kernel/futex.o:(.text.fixup+0x5c): relocation truncated to fit: R_ARM_JUMP24 against `.init.text'
> and boot failures for CONFIG_THUMB2_KERNEL.
>
> Link: https://github.com/ClangBuiltLinux/linux/issues/325
> Reported-by: Arnd Bergmann <ar...@arndb.de>
> Reported-by: Nathan Chancellor <nat...@kernel.org>
> Suggested-by: Thomas Gleixner <tg...@linutronix.de>
> Signed-off-by: Nick Desaulniers <ndesau...@google.com>

Reviewed-by: Thomas Gleixner <tg...@linutronix.de>

Nathan Chancellor

unread,
Aug 30, 2021, 7:31:51 PM8/30/21
to Nick Desaulniers, linux-ar...@lists.infradead.org, ll...@lists.linux.dev, Arnd Bergmann, Thomas Gleixner, Russell King, Geert Uytterhoeven, Linus Walleij, Andrew Morton, Anshuman Khandual, Ard Biesheuvel, YiFei Zhu, Uwe Kleine-König, Mike Rapoport, linux-...@vger.kernel.org, clang-bu...@googlegroups.com
On Mon, Aug 30, 2021 at 02:38:43PM -0700, Nick Desaulniers wrote:
> tglx notes:
> This function [futex_detect_cmpxchg] is only needed when an
> architecture has to runtime discover whether the CPU supports it or
> not. ARM has unconditional support for this, so the obvious thing to
> do is the below.
>
> Fixes linkage failure from Clang randconfigs:
> kernel/futex.o:(.text.fixup+0x5c): relocation truncated to fit: R_ARM_JUMP24 against `.init.text'
> and boot failures for CONFIG_THUMB2_KERNEL.
>
> Link: https://github.com/ClangBuiltLinux/linux/issues/325
> Reported-by: Arnd Bergmann <ar...@arndb.de>
> Reported-by: Nathan Chancellor <nat...@kernel.org>
> Suggested-by: Thomas Gleixner <tg...@linutronix.de>
> Signed-off-by: Nick Desaulniers <ndesau...@google.com>

Tested-by: Nathan Chancellor <nat...@kernel.org>

Linus Walleij

unread,
Sep 16, 2021, 6:40:56 PM9/16/21
to Nick Desaulniers, Linux ARM, ll...@lists.linux.dev, Arnd Bergmann, Nathan Chancellor, Thomas Gleixner, Russell King, Geert Uytterhoeven, Andrew Morton, Anshuman Khandual, Ard Biesheuvel, YiFei Zhu, Uwe Kleine-König, Mike Rapoport, linux-kernel, clang-built-linux
On Mon, Aug 30, 2021 at 11:38 PM Nick Desaulniers
<ndesau...@google.com> wrote:

> tglx notes:
> This function [futex_detect_cmpxchg] is only needed when an
> architecture has to runtime discover whether the CPU supports it or
> not. ARM has unconditional support for this, so the obvious thing to
> do is the below.
>
> Fixes linkage failure from Clang randconfigs:
> kernel/futex.o:(.text.fixup+0x5c): relocation truncated to fit: R_ARM_JUMP24 against `.init.text'
> and boot failures for CONFIG_THUMB2_KERNEL.
>
> Link: https://github.com/ClangBuiltLinux/linux/issues/325
> Reported-by: Arnd Bergmann <ar...@arndb.de>
> Reported-by: Nathan Chancellor <nat...@kernel.org>
> Suggested-by: Thomas Gleixner <tg...@linutronix.de>
> Signed-off-by: Nick Desaulniers <ndesau...@google.com>

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

Please put this into Russell's patch tracker!

Yours,
Linus Walleij

Nick Desaulniers

unread,
Sep 16, 2021, 7:26:56 PM9/16/21
to Linus Walleij, Linux ARM, ll...@lists.linux.dev, Arnd Bergmann, Nathan Chancellor, Thomas Gleixner, Russell King, Geert Uytterhoeven, Andrew Morton, Anshuman Khandual, Ard Biesheuvel, YiFei Zhu, Uwe Kleine-König, Mike Rapoport, linux-kernel, clang-built-linux
Done!
https://www.armlinux.org.uk/developer/patches/viewpatch.php?id=9122/1
Thanks for the review!

--
Thanks,
~Nick Desaulniers

Arnd Bergmann

unread,
Sep 17, 2021, 3:11:42 AM9/17/21
to Nick Desaulniers, Linux ARM, ll...@lists.linux.dev, Arnd Bergmann, Nathan Chancellor, Thomas Gleixner, Russell King, Geert Uytterhoeven, Linus Walleij, Andrew Morton, Anshuman Khandual, Ard Biesheuvel, YiFei Zhu, Uwe Kleine-König, Mike Rapoport, Linux Kernel Mailing List, clang-built-linux
On Mon, Aug 30, 2021 at 11:38 PM 'Nick Desaulniers' via Clang Built
Linux <clang-bu...@googlegroups.com> wrote:
>
> tglx notes:
> This function [futex_detect_cmpxchg] is only needed when an
> architecture has to runtime discover whether the CPU supports it or
> not. ARM has unconditional support for this, so the obvious thing to
> do is the below.
>
> Fixes linkage failure from Clang randconfigs:
> kernel/futex.o:(.text.fixup+0x5c): relocation truncated to fit: R_ARM_JUMP24 against `.init.text'
> and boot failures for CONFIG_THUMB2_KERNEL.
>
> Link: https://github.com/ClangBuiltLinux/linux/issues/325
> Reported-by: Arnd Bergmann <ar...@arndb.de>
> Reported-by: Nathan Chancellor <nat...@kernel.org>
> Suggested-by: Thomas Gleixner <tg...@linutronix.de>
> Signed-off-by: Nick Desaulniers <ndesau...@google.com>
> ---

Nice! I did remember that we had come up with a number of solutions
for the build error and that at least one of them was an obvious and
nice fix, but I could never figure out what it was. This is clearly better
than any of the other ones I had found when I last looked.

I would add a reference to the commit that introduced the conditional,
and a request for backports as well:

See-also: 03b8c7b623c8 ("futex: Allow architectures to skip
futex_atomic_cmpxchg_inatomic() test")
Cc: sta...@vger.kernel.org # v3.14+
Reviewed-by: Arnd Bergmann <ar...@arndb.de>

Arnd Bergmann

unread,
Sep 17, 2021, 4:34:09 PM9/17/21
to Arnd Bergmann, Nick Desaulniers, Linux ARM, ll...@lists.linux.dev, Nathan Chancellor, Thomas Gleixner, Russell King, Geert Uytterhoeven, Linus Walleij, Andrew Morton, Anshuman Khandual, Ard Biesheuvel, YiFei Zhu, Uwe Kleine-König, Mike Rapoport, Linux Kernel Mailing List, clang-built-linux
On Fri, Sep 17, 2021 at 9:11 AM Arnd Bergmann <ar...@arndb.de> wrote:
>
> Nice! I did remember that we had come up with a number of solutions
> for the build error and that at least one of them was an obvious and
> nice fix, but I could never figure out what it was. This is clearly better
> than any of the other ones I had found when I last looked.

Actually it turns out that I had come up with another approach, removing
the need for HAVE_FUTEX_CMPXCHG and the boot time check altogether:

https://git.kernel.org/pub/scm/linux/kernel/git/arnd/playground.git/commit/?h=randconfig-5.13&id=7bbd7403526a2a9f398f360fcb97f256052ca6bf

Guo Ren fixed the missing csky bit in there, but since the sparc32 support
is still missing, I never sent this before forgetting about it.
I think the only users of sparc32 these days are LEON CPUs, which have
usable atomics and could implement this properly but support for that was
not upstreamed.

Arnd

Jesse T

unread,
Oct 23, 2021, 9:38:40 PM10/23/21
to Clang Built Linux
Hai all,
This seems to fix another issue i have encountered at
https://github.com/Mr-Bossman/linux/tree/imxrt_test
On this system it accesses a null pointer due to this test and causes a hard fault.
there is no MMU which may be the problem.
Thomas Gleixner's fix for this seems to work, but the patch 7bbd7403526a2a9f398f360fcb97f256052ca6bf does not.
Any ideas as to what could be a fix.

Im very sorry about inline responses and broken reply, i dont know why i can reply all.
Reply all
Reply to author
Forward
0 new messages