* [PATCH] ARM: Thumb2: align ALT_UP() sections sufficiently
@ 2022-01-18 10:27 Ard Biesheuvel
2022-01-18 11:21 ` Russell King (Oracle)
0 siblings, 1 reply; 4+ messages in thread
From: Ard Biesheuvel @ 2022-01-18 10:27 UTC (permalink / raw)
To: linux; +Cc: linux-arm-kernel, arnd, linus.walleij, Ard Biesheuvel, stable
When building for Thumb2, the .alt.smp.init sections that are emitted by
the ALT_UP() patching code may not be 32-bit aligned, even though the
fixup_smp_on_up() routine expects that. This results in alignment faults
at module load time, which need to be fixed up by the fault handler.
So let's align those sections explicitly, and avoid this from occurring.
Cc: <stable@vger.kernel.org>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
arch/arm/include/asm/assembler.h | 2 ++
arch/arm/include/asm/processor.h | 1 +
2 files changed, 3 insertions(+)
diff --git a/arch/arm/include/asm/assembler.h b/arch/arm/include/asm/assembler.h
index 5a530e25ea1a..51ae4674ca49 100644
--- a/arch/arm/include/asm/assembler.h
+++ b/arch/arm/include/asm/assembler.h
@@ -261,6 +261,7 @@ THUMB( fpreg .req r7 )
*/
#define ALT_UP(instr...) \
.pushsection ".alt.smp.init", "a" ;\
+ .align 2 ;\
.long 9998b - . ;\
9997: instr ;\
.if . - 9997b == 2 ;\
@@ -272,6 +273,7 @@ THUMB( fpreg .req r7 )
.popsection
#define ALT_UP_B(label) \
.pushsection ".alt.smp.init", "a" ;\
+ .align 2 ;\
.long 9998b - . ;\
W(b) . + (label - 9998b) ;\
.popsection
diff --git a/arch/arm/include/asm/processor.h b/arch/arm/include/asm/processor.h
index 6af68edfa53a..bdc35c0e8dfb 100644
--- a/arch/arm/include/asm/processor.h
+++ b/arch/arm/include/asm/processor.h
@@ -96,6 +96,7 @@ unsigned long __get_wchan(struct task_struct *p);
#define __ALT_SMP_ASM(smp, up) \
"9998: " smp "\n" \
" .pushsection \".alt.smp.init\", \"a\"\n" \
+ " .align 2\n" \
" .long 9998b - .\n" \
" " up "\n" \
" .popsection\n"
--
2.30.2
_______________________________________________
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] 4+ messages in thread
* Re: [PATCH] ARM: Thumb2: align ALT_UP() sections sufficiently
2022-01-18 10:27 [PATCH] ARM: Thumb2: align ALT_UP() sections sufficiently Ard Biesheuvel
@ 2022-01-18 11:21 ` Russell King (Oracle)
2022-01-18 11:32 ` Ard Biesheuvel
0 siblings, 1 reply; 4+ messages in thread
From: Russell King (Oracle) @ 2022-01-18 11:21 UTC (permalink / raw)
To: Ard Biesheuvel; +Cc: linux-arm-kernel, arnd, linus.walleij, stable
On Tue, Jan 18, 2022 at 11:27:56AM +0100, Ard Biesheuvel wrote:
> When building for Thumb2, the .alt.smp.init sections that are emitted by
> the ALT_UP() patching code may not be 32-bit aligned, even though the
> fixup_smp_on_up() routine expects that. This results in alignment faults
> at module load time, which need to be fixed up by the fault handler.
>
> So let's align those sections explicitly, and avoid this from occurring.
Are you seeing a problem that this patch fixes?
This really should not matter. .alt.smp.init contents are always a whole
number of 32-bit words. These are gathered by the linker into the
.init.smpalt section, so the contents should always be a whole number
of 32-bit words.
This follows the .init.tagtable section, which is also a 32-bit word
aligned structure built by the linker... which follows the
.init.arch.info section and .init.proc.info sections which all have
32-bit alignment requirements.
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps 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] 4+ messages in thread
* Re: [PATCH] ARM: Thumb2: align ALT_UP() sections sufficiently
2022-01-18 11:21 ` Russell King (Oracle)
@ 2022-01-18 11:32 ` Ard Biesheuvel
2022-01-18 11:35 ` Russell King (Oracle)
0 siblings, 1 reply; 4+ messages in thread
From: Ard Biesheuvel @ 2022-01-18 11:32 UTC (permalink / raw)
To: Russell King (Oracle); +Cc: Linux ARM, Arnd Bergmann, Linus Walleij, # 3.4.x
On Tue, 18 Jan 2022 at 12:21, Russell King (Oracle)
<linux@armlinux.org.uk> wrote:
>
> On Tue, Jan 18, 2022 at 11:27:56AM +0100, Ard Biesheuvel wrote:
> > When building for Thumb2, the .alt.smp.init sections that are emitted by
> > the ALT_UP() patching code may not be 32-bit aligned, even though the
> > fixup_smp_on_up() routine expects that. This results in alignment faults
> > at module load time, which need to be fixed up by the fault handler.
> >
> > So let's align those sections explicitly, and avoid this from occurring.
>
> Are you seeing a problem that this patch fixes?
>
> This really should not matter. .alt.smp.init contents are always a whole
> number of 32-bit words. These are gathered by the linker into the
> .init.smpalt section, so the contents should always be a whole number
> of 32-bit words.
>
> This follows the .init.tagtable section, which is also a 32-bit word
> aligned structure built by the linker... which follows the
> .init.arch.info section and .init.proc.info sections which all have
> 32-bit alignment requirements.
>
This only affects modules, not the core kernel. The .alt.smp.init
section in a module is visible to the module loader, which means the
module loader will make no attempt to position it at a 32-bit aligned
address if the ELF alignment is only 16 bits, which appears to be the
default in my Thumb2 build [gcc version 10.3.1 20211117 (Debian
10.3.0-13)]
I only spotted this because do_fixup_smp_on_up() was shown as the most
recent in-kernel fixup location in /proc/cpu/alignment.
_______________________________________________
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] 4+ messages in thread
* Re: [PATCH] ARM: Thumb2: align ALT_UP() sections sufficiently
2022-01-18 11:32 ` Ard Biesheuvel
@ 2022-01-18 11:35 ` Russell King (Oracle)
0 siblings, 0 replies; 4+ messages in thread
From: Russell King (Oracle) @ 2022-01-18 11:35 UTC (permalink / raw)
To: Ard Biesheuvel; +Cc: Linux ARM, Arnd Bergmann, Linus Walleij, # 3.4.x
On Tue, Jan 18, 2022 at 12:32:55PM +0100, Ard Biesheuvel wrote:
> On Tue, 18 Jan 2022 at 12:21, Russell King (Oracle)
> <linux@armlinux.org.uk> wrote:
> >
> > On Tue, Jan 18, 2022 at 11:27:56AM +0100, Ard Biesheuvel wrote:
> > > When building for Thumb2, the .alt.smp.init sections that are emitted by
> > > the ALT_UP() patching code may not be 32-bit aligned, even though the
> > > fixup_smp_on_up() routine expects that. This results in alignment faults
> > > at module load time, which need to be fixed up by the fault handler.
> > >
> > > So let's align those sections explicitly, and avoid this from occurring.
> >
> > Are you seeing a problem that this patch fixes?
> >
> > This really should not matter. .alt.smp.init contents are always a whole
> > number of 32-bit words. These are gathered by the linker into the
> > .init.smpalt section, so the contents should always be a whole number
> > of 32-bit words.
> >
> > This follows the .init.tagtable section, which is also a 32-bit word
> > aligned structure built by the linker... which follows the
> > .init.arch.info section and .init.proc.info sections which all have
> > 32-bit alignment requirements.
> >
>
> This only affects modules, not the core kernel. The .alt.smp.init
> section in a module is visible to the module loader, which means the
> module loader will make no attempt to position it at a 32-bit aligned
> address if the ELF alignment is only 16 bits, which appears to be the
> default in my Thumb2 build [gcc version 10.3.1 20211117 (Debian
> 10.3.0-13)]
>
> I only spotted this because do_fixup_smp_on_up() was shown as the most
> recent in-kernel fixup location in /proc/cpu/alignment.
Ok, thanks for the explanation.
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps 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] 4+ messages in thread
end of thread, other threads:[~2022-01-18 11:36 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-01-18 10:27 [PATCH] ARM: Thumb2: align ALT_UP() sections sufficiently Ard Biesheuvel
2022-01-18 11:21 ` Russell King (Oracle)
2022-01-18 11:32 ` Ard Biesheuvel
2022-01-18 11:35 ` 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).