Message ID | 31ce5305-a76b-13d7-ea55-afca82c46cf2@kalray.eu (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Fix __kcrctab+* sections alignment | expand |
On Thu, 25 Aug 2022 at 14:10, Yann Sionneau <ysionneau@kalray.eu> wrote: > > Forwarding also the actual patch to linux-kbuild and linux-arch > > -------- Forwarded Message -------- > Subject: [RFC PATCH 1/1] Fix __kcrctab+* sections alignment > Date: Wed, 17 Aug 2022 18:14:38 +0200 > From: Yann Sionneau <ysionneau@kalray.eu> > To: linux-kernel@vger.kernel.org > CC: Nicolas Schier <nicolas@fjasle.eu>, Masahiro Yamada > <masahiroy@kernel.org>, Jules Maselbas <jmaselbas@kalray.eu>, Julian > Vetter <jvetter@kalray.eu>, Yann Sionneau <ysionneau@kalray.eu> > > > What happened to the commit log? > Signed-off-by: Yann Sionneau <ysionneau@kalray.eu> > --- > include/linux/export-internal.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/include/linux/export-internal.h > b/include/linux/export-internal.h > index c2b1d4fd5987..d86bfbd7fa6d 100644 > --- a/include/linux/export-internal.h > +++ b/include/linux/export-internal.h > @@ -12,6 +12,6 @@ > /* __used is needed to keep __crc_* for LTO */ > #define SYMBOL_CRC(sym, crc, sec) \ > - u32 __section("___kcrctab" sec "+" #sym) __used __crc_##sym = crc > + u32 __section("___kcrctab" sec "+" #sym) __used __aligned(4) __aligned(4) is the default for u32 so this should not be needed. > __crc_##sym = crc > #endif /* __LINUX_EXPORT_INTERNAL_H__ */ > > -- > 2.37.2 > > > > >
Hello Ard, On 25/08/2022 14:12, Ard Biesheuvel wrote: > On Thu, 25 Aug 2022 at 14:10, Yann Sionneau <ysionneau@kalray.eu> wrote: >> Forwarding also the actual patch to linux-kbuild and linux-arch >> >> -------- Forwarded Message -------- >> Subject: [RFC PATCH 1/1] Fix __kcrctab+* sections alignment >> Date: Wed, 17 Aug 2022 18:14:38 +0200 >> From: Yann Sionneau <ysionneau@kalray.eu> >> To: linux-kernel@vger.kernel.org >> CC: Nicolas Schier <nicolas@fjasle.eu>, Masahiro Yamada >> <masahiroy@kernel.org>, Jules Maselbas <jmaselbas@kalray.eu>, Julian >> Vetter <jvetter@kalray.eu>, Yann Sionneau <ysionneau@kalray.eu> >> >> >> > What happened to the commit log? This is a forward of this thread: https://lkml.org/lkml/2022/8/17/868 Either I did something wrong with my email agent or maybe the email containing the cover letter is taking some time to reach you? > >> Signed-off-by: Yann Sionneau <ysionneau@kalray.eu> >> --- >> include/linux/export-internal.h | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/include/linux/export-internal.h >> b/include/linux/export-internal.h >> index c2b1d4fd5987..d86bfbd7fa6d 100644 >> --- a/include/linux/export-internal.h >> +++ b/include/linux/export-internal.h >> @@ -12,6 +12,6 @@ >> /* __used is needed to keep __crc_* for LTO */ >> #define SYMBOL_CRC(sym, crc, sec) \ >> - u32 __section("___kcrctab" sec "+" #sym) __used __crc_##sym = crc >> + u32 __section("___kcrctab" sec "+" #sym) __used __aligned(4) > __aligned(4) is the default for u32 so this should not be needed. Well, I am not completely sure about that. See my cover letter, previous mechanism for symbol CRC was actually enforcing the section alignment to 4 bytes boundary as well. Also, I'm not sure it is forbidden for an architecture/compiler implementation to actually enforce a stronger alignment on u32, which in theory would not break anything. But in this precise case it does break something since it will cause "gaps" in the end result vmlinux binary segment. For this to work I think we really want to enforce a 4 bytes alignment on the section. > > >> __crc_##sym = crc >> #endif /* __LINUX_EXPORT_INTERNAL_H__ */ >> >> -- >> 2.37.2 Thanks for your review :)
(cc Arnd) On Thu, 25 Aug 2022 at 14:21, Yann Sionneau <ysionneau@kalray.eu> wrote: > > Hello Ard, > > On 25/08/2022 14:12, Ard Biesheuvel wrote: > > On Thu, 25 Aug 2022 at 14:10, Yann Sionneau <ysionneau@kalray.eu> wrote: > >> Forwarding also the actual patch to linux-kbuild and linux-arch > >> > >> -------- Forwarded Message -------- > >> Subject: [RFC PATCH 1/1] Fix __kcrctab+* sections alignment > >> Date: Wed, 17 Aug 2022 18:14:38 +0200 > >> From: Yann Sionneau <ysionneau@kalray.eu> > >> To: linux-kernel@vger.kernel.org > >> CC: Nicolas Schier <nicolas@fjasle.eu>, Masahiro Yamada > >> <masahiroy@kernel.org>, Jules Maselbas <jmaselbas@kalray.eu>, Julian > >> Vetter <jvetter@kalray.eu>, Yann Sionneau <ysionneau@kalray.eu> > >> > >> > >> > > What happened to the commit log? > > This is a forward of this thread: https://lkml.org/lkml/2022/8/17/868 > > Either I did something wrong with my email agent or maybe the email > containing the cover letter is taking some time to reach you? > Never mind, i see the other thread as well. Exec summary: out-of-tree port for kvx architecture appears to impose 8 byte alignment for u32 types in some cases. > > > >> Signed-off-by: Yann Sionneau <ysionneau@kalray.eu> > >> --- > >> include/linux/export-internal.h | 2 +- > >> 1 file changed, 1 insertion(+), 1 deletion(-) > >> > >> diff --git a/include/linux/export-internal.h > >> b/include/linux/export-internal.h > >> index c2b1d4fd5987..d86bfbd7fa6d 100644 > >> --- a/include/linux/export-internal.h > >> +++ b/include/linux/export-internal.h > >> @@ -12,6 +12,6 @@ > >> /* __used is needed to keep __crc_* for LTO */ > >> #define SYMBOL_CRC(sym, crc, sec) \ > >> - u32 __section("___kcrctab" sec "+" #sym) __used __crc_##sym = crc > >> + u32 __section("___kcrctab" sec "+" #sym) __used __aligned(4) > > __aligned(4) is the default for u32 so this should not be needed. > > Well, I am not completely sure about that. See my cover letter, previous > mechanism for symbol CRC was actually enforcing the section alignment to > 4 bytes boundary as well. > > Also, I'm not sure it is forbidden for an architecture/compiler > implementation to actually enforce a stronger alignment on u32, which in > theory would not break anything. > u32 is a Linux type, and Linux expects natural alignment (and padding). So if your toolchain/architecture violates this rule, I suggest you typedef u32 to 'unsigned int __aligned(4)' explicitly. so that things don't break in other places. However, even then, I am highly skeptical. This really seems like an issue in your toolchain that could cause problems all over the place. > But in this precise case it does break something since it will cause > "gaps" in the end result vmlinux binary segment. For this to work I > think we really want to enforce a 4 bytes alignment on the section. > You are addressing one of many potential issues that could be caused by this, so I don't think this patch is a good idea tbh. > > > > > >> __crc_##sym = crc > >> #endif /* __LINUX_EXPORT_INTERNAL_H__ */ > >> > >> -- > >> 2.37.2 > > Thanks for your review :) > > -- > > Yann > > > > >
Hi Ard, On Thu, Aug 25, 2022 at 2:56 PM Ard Biesheuvel <ardb@kernel.org> wrote: > On Thu, 25 Aug 2022 at 14:21, Yann Sionneau <ysionneau@kalray.eu> wrote: > > Well, I am not completely sure about that. See my cover letter, previous > > mechanism for symbol CRC was actually enforcing the section alignment to > > 4 bytes boundary as well. Yes, because else it may become 2-byte aligned on m68k. > > Also, I'm not sure it is forbidden for an architecture/compiler > > implementation to actually enforce a stronger alignment on u32, which in > > theory would not break anything. > > > > u32 is a Linux type, and Linux expects natural alignment (and padding). Is it? You probably mean its alignment should not be larger than 4 bytes? Less has been working since basically forever. > So if your toolchain/architecture violates this rule, I suggest you > typedef u32 to 'unsigned int __aligned(4)' explicitly. so that things > don't break in other places. > > However, even then, I am highly skeptical. This really seems like an > issue in your toolchain that could cause problems all over the place. > > > But in this precise case it does break something since it will cause > > "gaps" in the end result vmlinux binary segment. For this to work I > > think we really want to enforce a 4 bytes alignment on the section. > > You are addressing one of many potential issues that could be caused > by this, so I don't think this patch is a good idea tbh. Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
On Thu, 25 Aug 2022 at 20:01, Geert Uytterhoeven <geert@linux-m68k.org> wrote: > > Hi Ard, > > On Thu, Aug 25, 2022 at 2:56 PM Ard Biesheuvel <ardb@kernel.org> wrote: > > On Thu, 25 Aug 2022 at 14:21, Yann Sionneau <ysionneau@kalray.eu> wrote: > > > Well, I am not completely sure about that. See my cover letter, previous > > > mechanism for symbol CRC was actually enforcing the section alignment to > > > 4 bytes boundary as well. > > Yes, because else it may become 2-byte aligned on m68k. > > > > Also, I'm not sure it is forbidden for an architecture/compiler > > > implementation to actually enforce a stronger alignment on u32, which in > > > theory would not break anything. > > > > > > > u32 is a Linux type, and Linux expects natural alignment (and padding). > > Is it? You probably mean its alignment should not be larger than > 4 bytes? Less has been working since basically forever. > You are quite right. of course. And indeed, the issue here is padding not alignment. > > So if your toolchain/architecture violates this rule, I suggest you > > typedef u32 to 'unsigned int __aligned(4)' explicitly. so that things > > don't break in other places. > > > > However, even then, I am highly skeptical. This really seems like an > > issue in your toolchain that could cause problems all over the place. > > > > > But in this precise case it does break something since it will cause > > > "gaps" in the end result vmlinux binary segment. For this to work I > > > think we really want to enforce a 4 bytes alignment on the section. > > > > You are addressing one of many potential issues that could be caused > > by this, so I don't think this patch is a good idea tbh. > > Gr{oetje,eeting}s, > > Geert > > -- > Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org > > In personal conversations with technical people, I call myself a hacker. But > when I'm talking to journalists I just say "programmer" or something like that. > -- Linus Torvalds
On Thu, Aug 25, 2022 at 9:21 PM Yann Sionneau <ysionneau@kalray.eu> wrote: > > Hello Ard, > > On 25/08/2022 14:12, Ard Biesheuvel wrote: > > On Thu, 25 Aug 2022 at 14:10, Yann Sionneau <ysionneau@kalray.eu> wrote: > >> Forwarding also the actual patch to linux-kbuild and linux-arch > >> > >> -------- Forwarded Message -------- > >> Subject: [RFC PATCH 1/1] Fix __kcrctab+* sections alignment > >> Date: Wed, 17 Aug 2022 18:14:38 +0200 > >> From: Yann Sionneau <ysionneau@kalray.eu> > >> To: linux-kernel@vger.kernel.org > >> CC: Nicolas Schier <nicolas@fjasle.eu>, Masahiro Yamada > >> <masahiroy@kernel.org>, Jules Maselbas <jmaselbas@kalray.eu>, Julian > >> Vetter <jvetter@kalray.eu>, Yann Sionneau <ysionneau@kalray.eu> > >> > >> > >> > > What happened to the commit log? > > This is a forward of this thread: https://lkml.org/lkml/2022/8/17/868 > > Either I did something wrong with my email agent or maybe the email > containing the cover letter is taking some time to reach you? > > > > >> Signed-off-by: Yann Sionneau <ysionneau@kalray.eu> > >> --- > >> include/linux/export-internal.h | 2 +- > >> 1 file changed, 1 insertion(+), 1 deletion(-) > >> > >> diff --git a/include/linux/export-internal.h > >> b/include/linux/export-internal.h > >> index c2b1d4fd5987..d86bfbd7fa6d 100644 > >> --- a/include/linux/export-internal.h > >> +++ b/include/linux/export-internal.h > >> @@ -12,6 +12,6 @@ > >> /* __used is needed to keep __crc_* for LTO */ > >> #define SYMBOL_CRC(sym, crc, sec) \ > >> - u32 __section("___kcrctab" sec "+" #sym) __used __crc_##sym = crc > >> + u32 __section("___kcrctab" sec "+" #sym) __used __aligned(4) > > __aligned(4) is the default for u32 so this should not be needed. > > Well, I am not completely sure about that. See my cover letter, previous > mechanism for symbol CRC was actually enforcing the section alignment to > 4 bytes boundary as well. I do not think so. I do not see such alignment in for __CRC_SYMBOL() in include/linux/export.h If you are talking about KCRC_ALIGN in include/asm-generic/export.h, it is only used by *.S. Most of EXPORT_SYMBOL's are defined in *.c files, which include <linux/export.h> If I am missing something, please point me to the code. > > Also, I'm not sure it is forbidden for an architecture/compiler > implementation to actually enforce a stronger alignment on u32, which in > theory would not break anything. It seems like an interesting compiler. Does it also enforce 8 byte alignment to u8? (that is, 7-byte padding for u8 ?) > > But in this precise case it does break something since it will cause > "gaps" in the end result vmlinux binary segment. For this to work I > think we really want to enforce a 4 bytes alignment on the section. My best guess it, it was previously working for the kvm compiler because include/linux/export.h previously used an inline assembler. The kvm toolchain presumably gives natural alignment/padding to '.long' assembly directive, but enforces 8-byte to u32.
On Thu, Aug 25, 2022 at 9:21 PM Yann Sionneau <ysionneau@kalray.eu> wrote: > > Hello Ard, > > On 25/08/2022 14:12, Ard Biesheuvel wrote: > > On Thu, 25 Aug 2022 at 14:10, Yann Sionneau <ysionneau@kalray.eu> wrote: > >> Forwarding also the actual patch to linux-kbuild and linux-arch > >> > >> -------- Forwarded Message -------- > >> Subject: [RFC PATCH 1/1] Fix __kcrctab+* sections alignment > >> Date: Wed, 17 Aug 2022 18:14:38 +0200 > >> From: Yann Sionneau <ysionneau@kalray.eu> > >> To: linux-kernel@vger.kernel.org > >> CC: Nicolas Schier <nicolas@fjasle.eu>, Masahiro Yamada > >> <masahiroy@kernel.org>, Jules Maselbas <jmaselbas@kalray.eu>, Julian > >> Vetter <jvetter@kalray.eu>, Yann Sionneau <ysionneau@kalray.eu> > >> > >> > >> > > What happened to the commit log? > > This is a forward of this thread: https://lkml.org/lkml/2022/8/17/868 > > Either I did something wrong with my email agent or maybe the email > containing the cover letter is taking some time to reach you? > > > > >> Signed-off-by: Yann Sionneau <ysionneau@kalray.eu> > >> --- > >> include/linux/export-internal.h | 2 +- > >> 1 file changed, 1 insertion(+), 1 deletion(-) > >> > >> diff --git a/include/linux/export-internal.h > >> b/include/linux/export-internal.h > >> index c2b1d4fd5987..d86bfbd7fa6d 100644 > >> --- a/include/linux/export-internal.h > >> +++ b/include/linux/export-internal.h > >> @@ -12,6 +12,6 @@ > >> /* __used is needed to keep __crc_* for LTO */ > >> #define SYMBOL_CRC(sym, crc, sec) \ > >> - u32 __section("___kcrctab" sec "+" #sym) __used __crc_##sym = crc > >> + u32 __section("___kcrctab" sec "+" #sym) __used __aligned(4) > > __aligned(4) is the default for u32 so this should not be needed. > > Well, I am not completely sure about that. See my cover letter, previous > mechanism for symbol CRC was actually enforcing the section alignment to > 4 bytes boundary as well. > > Also, I'm not sure it is forbidden for an architecture/compiler > implementation to actually enforce a stronger alignment on u32, which in > theory would not break anything. > > But in this precise case it does break something since it will cause > "gaps" in the end result vmlinux binary segment. For this to work I > think we really want to enforce a 4 bytes alignment on the section. Please teach me a bit more about the kvm compiler. How does it get access to an array of u32? u32 foo[2] = { 1, 2 }; Does the compiler insert padding between each element so that both of &foo[0] and &foo[1] are 8-byte aligned? Or, no padding, and the address of &foo[1] is 8 n + 4?
On Fri, Aug 26, 2022 at 7:17 PM Ard Biesheuvel <ardb@kernel.org> wrote: > > On Thu, 25 Aug 2022 at 20:01, Geert Uytterhoeven <geert@linux-m68k.org> wrote: > > > > Hi Ard, > > > > On Thu, Aug 25, 2022 at 2:56 PM Ard Biesheuvel <ardb@kernel.org> wrote: > > > On Thu, 25 Aug 2022 at 14:21, Yann Sionneau <ysionneau@kalray.eu> wrote: > > > > Well, I am not completely sure about that. See my cover letter, previous > > > > mechanism for symbol CRC was actually enforcing the section alignment to > > > > 4 bytes boundary as well. > > > > Yes, because else it may become 2-byte aligned on m68k. > > > > > > Also, I'm not sure it is forbidden for an architecture/compiler > > > > implementation to actually enforce a stronger alignment on u32, which in > > > > theory would not break anything. > > > > > > > > > > u32 is a Linux type, and Linux expects natural alignment (and padding). > > > > Is it? You probably mean its alignment should not be larger than > > 4 bytes? Less has been working since basically forever. > > > > You are quite right. of course. And indeed, the issue here is padding > not alignment. > I do not know if __align(4) should be used to avoid the padding issue. Do you think it is a good idea to use an inline assembler, as prior to 7b4537199a4a8480b8c3ba37a2d44765ce76cd9b ? This patch: diff --git a/include/linux/export-internal.h b/include/linux/export-internal.h index c2b1d4fd5987..fb90f326b1b5 100644 --- a/include/linux/export-internal.h +++ b/include/linux/export-internal.h @@ -12,6 +12,9 @@ /* __used is needed to keep __crc_* for LTO */ #define SYMBOL_CRC(sym, crc, sec) \ - u32 __section("___kcrctab" sec "+" #sym) __used __crc_##sym = crc + asm(".section \"___kcrctab" sec "+" #sym "\",\"a\"" "\n" \ + "__crc_" #sym ":" "\n" \ + ".long " #crc "\n" \ + ".previous" "\n") #endif /* __LINUX_EXPORT_INTERNAL_H__ */ -- Best Regards Masahiro Yamada
Hello Masahiro, On 8/28/22 15:59, Masahiro Yamada wrote: > On Thu, Aug 25, 2022 at 9:21 PM Yann Sionneau <ysionneau@kalray.eu> wrote: >> Hello Ard, >> >> On 25/08/2022 14:12, Ard Biesheuvel wrote: >>> On Thu, 25 Aug 2022 at 14:10, Yann Sionneau <ysionneau@kalray.eu> wrote: >>>> Forwarding also the actual patch to linux-kbuild and linux-arch >>>> >>>> -------- Forwarded Message -------- >>>> Subject: [RFC PATCH 1/1] Fix __kcrctab+* sections alignment >>>> Date: Wed, 17 Aug 2022 18:14:38 +0200 >>>> From: Yann Sionneau <ysionneau@kalray.eu> >>>> To: linux-kernel@vger.kernel.org >>>> CC: Nicolas Schier <nicolas@fjasle.eu>, Masahiro Yamada >>>> <masahiroy@kernel.org>, Jules Maselbas <jmaselbas@kalray.eu>, Julian >>>> Vetter <jvetter@kalray.eu>, Yann Sionneau <ysionneau@kalray.eu> >>>> >>>> >>>> >>> What happened to the commit log? >> This is a forward of this thread: https://lkml.org/lkml/2022/8/17/868 >> >> Either I did something wrong with my email agent or maybe the email >> containing the cover letter is taking some time to reach you? >> >>>> Signed-off-by: Yann Sionneau <ysionneau@kalray.eu> >>>> --- >>>> include/linux/export-internal.h | 2 +- >>>> 1 file changed, 1 insertion(+), 1 deletion(-) >>>> >>>> diff --git a/include/linux/export-internal.h >>>> b/include/linux/export-internal.h >>>> index c2b1d4fd5987..d86bfbd7fa6d 100644 >>>> --- a/include/linux/export-internal.h >>>> +++ b/include/linux/export-internal.h >>>> @@ -12,6 +12,6 @@ >>>> /* __used is needed to keep __crc_* for LTO */ >>>> #define SYMBOL_CRC(sym, crc, sec) \ >>>> - u32 __section("___kcrctab" sec "+" #sym) __used __crc_##sym = crc >>>> + u32 __section("___kcrctab" sec "+" #sym) __used __aligned(4) >>> __aligned(4) is the default for u32 so this should not be needed. >> Well, I am not completely sure about that. See my cover letter, previous >> mechanism for symbol CRC was actually enforcing the section alignment to >> 4 bytes boundary as well. >> >> Also, I'm not sure it is forbidden for an architecture/compiler >> implementation to actually enforce a stronger alignment on u32, which in >> theory would not break anything. >> >> But in this precise case it does break something since it will cause >> "gaps" in the end result vmlinux binary segment. For this to work I >> think we really want to enforce a 4 bytes alignment on the section. > > > Please teach me a bit more about the kvm compiler. > > > > How does it get access to an array of u32? > > u32 foo[2] = { 1, 2 }; > > > Does the compiler insert padding between each element > so that both of &foo[0] and &foo[1] are 8-byte aligned? > > Or, no padding, and the address of &foo[1] is 8 n + 4? Here is what's happening: https://godbolt.org/z/Yz74W7jGY unsignedintfoo[2] = { 1, 2}; intget_foo_sum(unsignedint*foo) { returnfoo[0] + foo[1]; } gets compiled to: get_foo_sum: lwz$r1=0[$r0] ;; # (end cycle 0) lwz$r0=4[$r0] ;; # (end cycle 1) addw$r0=$r1, $r0 ret ;; # (end cycle 4) foo: .long1 .long2 So it seems that no padding is inserted. Which looks sane ^^
Hello Masahiro, On 8/28/22 16:05, Masahiro Yamada wrote: > On Fri, Aug 26, 2022 at 7:17 PM Ard Biesheuvel <ardb@kernel.org> wrote: >> On Thu, 25 Aug 2022 at 20:01, Geert Uytterhoeven <geert@linux-m68k.org> wrote: >>> Hi Ard, >>> >>> On Thu, Aug 25, 2022 at 2:56 PM Ard Biesheuvel <ardb@kernel.org> wrote: >>>> On Thu, 25 Aug 2022 at 14:21, Yann Sionneau <ysionneau@kalray.eu> wrote: >>>>> Well, I am not completely sure about that. See my cover letter, previous >>>>> mechanism for symbol CRC was actually enforcing the section alignment to >>>>> 4 bytes boundary as well. >>> Yes, because else it may become 2-byte aligned on m68k. >>> >>>>> Also, I'm not sure it is forbidden for an architecture/compiler >>>>> implementation to actually enforce a stronger alignment on u32, which in >>>>> theory would not break anything. >>>>> >>>> u32 is a Linux type, and Linux expects natural alignment (and padding). >>> Is it? You probably mean its alignment should not be larger than >>> 4 bytes? Less has been working since basically forever. >>> >> You are quite right. of course. And indeed, the issue here is padding >> not alignment. >> > I do not know if __align(4) should be used to avoid the padding issue. > > > > Do you think it is a good idea to use an inline assembler, > as prior to 7b4537199a4a8480b8c3ba37a2d44765ce76cd9b ? > > > This patch: > > diff --git a/include/linux/export-internal.h b/include/linux/export-internal.h > index c2b1d4fd5987..fb90f326b1b5 100644 > --- a/include/linux/export-internal.h > +++ b/include/linux/export-internal.h > @@ -12,6 +12,9 @@ > > /* __used is needed to keep __crc_* for LTO */ > #define SYMBOL_CRC(sym, crc, sec) \ > - u32 __section("___kcrctab" sec "+" #sym) __used __crc_##sym = crc > + asm(".section \"___kcrctab" sec "+" #sym "\",\"a\"" "\n" \ > + "__crc_" #sym ":" "\n" \ > + ".long " #crc "\n" \ > + ".previous" "\n") > > #endif /* __LINUX_EXPORT_INTERNAL_H__ */ I can confirm that this patch solves my kernel module CRC issues on kvx port. Thanks,
On 8/28/22 16:05, Masahiro Yamada wrote: > On Fri, Aug 26, 2022 at 7:17 PM Ard Biesheuvel <ardb@kernel.org> wrote: >> On Thu, 25 Aug 2022 at 20:01, Geert Uytterhoeven <geert@linux-m68k.org> wrote: >>> Hi Ard, >>> >>> On Thu, Aug 25, 2022 at 2:56 PM Ard Biesheuvel <ardb@kernel.org> wrote: >>>> On Thu, 25 Aug 2022 at 14:21, Yann Sionneau <ysionneau@kalray.eu> wrote: >>>>> Well, I am not completely sure about that. See my cover letter, previous >>>>> mechanism for symbol CRC was actually enforcing the section alignment to >>>>> 4 bytes boundary as well. >>> Yes, because else it may become 2-byte aligned on m68k. >>> >>>>> Also, I'm not sure it is forbidden for an architecture/compiler >>>>> implementation to actually enforce a stronger alignment on u32, which in >>>>> theory would not break anything. >>>>> >>>> u32 is a Linux type, and Linux expects natural alignment (and padding). >>> Is it? You probably mean its alignment should not be larger than >>> 4 bytes? Less has been working since basically forever. >>> >> You are quite right. of course. And indeed, the issue here is padding >> not alignment. >> > I do not know if __align(4) should be used to avoid the padding issue. > > > > Do you think it is a good idea to use an inline assembler, > as prior to 7b4537199a4a8480b8c3ba37a2d44765ce76cd9b ? > > > This patch: > > diff --git a/include/linux/export-internal.h b/include/linux/export-internal.h > index c2b1d4fd5987..fb90f326b1b5 100644 > --- a/include/linux/export-internal.h > +++ b/include/linux/export-internal.h > @@ -12,6 +12,9 @@ > > /* __used is needed to keep __crc_* for LTO */ > #define SYMBOL_CRC(sym, crc, sec) \ > - u32 __section("___kcrctab" sec "+" #sym) __used __crc_##sym = crc > + asm(".section \"___kcrctab" sec "+" #sym "\",\"a\"" "\n" \ > + "__crc_" #sym ":" "\n" \ > + ".long " #crc "\n" \ > + ".previous" "\n") > > #endif /* __LINUX_EXPORT_INTERNAL_H__ */ Ping on this topic, should we "fix our toolchain"? Or should Linux code be modified to add either __align(4) or use the inline assembler? (I've tried your inline asm patch and it seems to fix the issue I'm having). Or both? Thanks, Yann
On Mon, Sep 26, 2022 at 5:48 PM Yann Sionneau <ysionneau@kalray.eu> wrote: > > > On 8/28/22 16:05, Masahiro Yamada wrote: > > On Fri, Aug 26, 2022 at 7:17 PM Ard Biesheuvel <ardb@kernel.org> wrote: > >> On Thu, 25 Aug 2022 at 20:01, Geert Uytterhoeven <geert@linux-m68k.org> wrote: > >>> Hi Ard, > >>> > >>> On Thu, Aug 25, 2022 at 2:56 PM Ard Biesheuvel <ardb@kernel.org> wrote: > >>>> On Thu, 25 Aug 2022 at 14:21, Yann Sionneau <ysionneau@kalray.eu> wrote: > >>>>> Well, I am not completely sure about that. See my cover letter, previous > >>>>> mechanism for symbol CRC was actually enforcing the section alignment to > >>>>> 4 bytes boundary as well. > >>> Yes, because else it may become 2-byte aligned on m68k. > >>> > >>>>> Also, I'm not sure it is forbidden for an architecture/compiler > >>>>> implementation to actually enforce a stronger alignment on u32, which in > >>>>> theory would not break anything. > >>>>> > >>>> u32 is a Linux type, and Linux expects natural alignment (and padding). > >>> Is it? You probably mean its alignment should not be larger than > >>> 4 bytes? Less has been working since basically forever. > >>> > >> You are quite right. of course. And indeed, the issue here is padding > >> not alignment. > >> > > I do not know if __align(4) should be used to avoid the padding issue. > > > > > > > > Do you think it is a good idea to use an inline assembler, > > as prior to 7b4537199a4a8480b8c3ba37a2d44765ce76cd9b ? > > > > > > This patch: > > > > diff --git a/include/linux/export-internal.h b/include/linux/export-internal.h > > index c2b1d4fd5987..fb90f326b1b5 100644 > > --- a/include/linux/export-internal.h > > +++ b/include/linux/export-internal.h > > @@ -12,6 +12,9 @@ > > > > /* __used is needed to keep __crc_* for LTO */ > > #define SYMBOL_CRC(sym, crc, sec) \ > > - u32 __section("___kcrctab" sec "+" #sym) __used __crc_##sym = crc > > + asm(".section \"___kcrctab" sec "+" #sym "\",\"a\"" "\n" \ > > + "__crc_" #sym ":" "\n" \ > > + ".long " #crc "\n" \ > > + ".previous" "\n") > > > > #endif /* __LINUX_EXPORT_INTERNAL_H__ */ > > Ping on this topic, should we "fix our toolchain"? > > Or should Linux code be modified to add either __align(4) or use the > inline assembler? (I've tried your inline asm patch and it seems to fix > the issue I'm having). > > Or both? > > Thanks, > > Yann > > > > > I queued up the patch. You can see it in linux-next. Once it lands in the mainline, it will be back-ported. masahiro@zoe:~/ref/linux-next$ git log -1 next-20220923 -- include/linux/export-internal.h commit 60ecfddd7a092f9cbd2398dbc55da3abbb803ff0 Author: Masahiro Yamada <masahiroy@kernel.org> Date: Fri Sep 16 15:29:53 2022 +0900 linux/export: use inline assembler to populate symbol CRCs Since commit 7b4537199a4a ("kbuild: link symbol CRCs at final link, removing CONFIG_MODULE_REL_CRCS"), the module versioning on the (non-upstreamed-yet) kvx Linux port is broken due to unexpected padding for __crc_* symbols. The kvx GCC adds padding so u32 gets 8-byte alignment instead of 4. I do not know if this happens for upstream architectures in general, but any compiler has the freedom to insert padding for faster access. Use the inline assembler to directly specify the wanted data layout. This is how we previously did before the breakage. Link: https://lore.kernel.org/lkml/20220817161438.32039-1-ysionneau@kalray.eu/ Link: https://lore.kernel.org/linux-kbuild/31ce5305-a76b-13d7-ea55-afca82c46cf2@kalray.eu/ Fixes: 7b4537199a4a ("kbuild: link symbol CRCs at final link, removing CONFIG_MODULE_REL_CRCS") Reported-by: Yann Sionneau <ysionneau@kalray.eu> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> Tested-by: Yann Sionneau <ysionneau@kalray.eu>
On Mon, 26 Sept 2022 at 10:48, Yann Sionneau <ysionneau@kalray.eu> wrote: > > > On 8/28/22 16:05, Masahiro Yamada wrote: > > On Fri, Aug 26, 2022 at 7:17 PM Ard Biesheuvel <ardb@kernel.org> wrote: > >> On Thu, 25 Aug 2022 at 20:01, Geert Uytterhoeven <geert@linux-m68k.org> wrote: > >>> Hi Ard, > >>> > >>> On Thu, Aug 25, 2022 at 2:56 PM Ard Biesheuvel <ardb@kernel.org> wrote: > >>>> On Thu, 25 Aug 2022 at 14:21, Yann Sionneau <ysionneau@kalray.eu> wrote: > >>>>> Well, I am not completely sure about that. See my cover letter, previous > >>>>> mechanism for symbol CRC was actually enforcing the section alignment to > >>>>> 4 bytes boundary as well. > >>> Yes, because else it may become 2-byte aligned on m68k. > >>> > >>>>> Also, I'm not sure it is forbidden for an architecture/compiler > >>>>> implementation to actually enforce a stronger alignment on u32, which in > >>>>> theory would not break anything. > >>>>> > >>>> u32 is a Linux type, and Linux expects natural alignment (and padding). > >>> Is it? You probably mean its alignment should not be larger than > >>> 4 bytes? Less has been working since basically forever. > >>> > >> You are quite right. of course. And indeed, the issue here is padding > >> not alignment. > >> > > I do not know if __align(4) should be used to avoid the padding issue. > > > > > > > > Do you think it is a good idea to use an inline assembler, > > as prior to 7b4537199a4a8480b8c3ba37a2d44765ce76cd9b ? > > > > > > This patch: > > > > diff --git a/include/linux/export-internal.h b/include/linux/export-internal.h > > index c2b1d4fd5987..fb90f326b1b5 100644 > > --- a/include/linux/export-internal.h > > +++ b/include/linux/export-internal.h > > @@ -12,6 +12,9 @@ > > > > /* __used is needed to keep __crc_* for LTO */ > > #define SYMBOL_CRC(sym, crc, sec) \ > > - u32 __section("___kcrctab" sec "+" #sym) __used __crc_##sym = crc > > + asm(".section \"___kcrctab" sec "+" #sym "\",\"a\"" "\n" \ > > + "__crc_" #sym ":" "\n" \ > > + ".long " #crc "\n" \ > > + ".previous" "\n") > > > > #endif /* __LINUX_EXPORT_INTERNAL_H__ */ > > Ping on this topic, should we "fix our toolchain"? > > Or should Linux code be modified to add either __align(4) or use the > inline assembler? (I've tried your inline asm patch and it seems to fix > the issue I'm having). > > Or both? > There are other cases where we rely on sections containing arrays of u32 to be concatenated without gaps. If you would ever want to enable HAVE_ARCH_PREL32_RELOCATIONS for your architecture (in order to save some space in the binary wasted on absolute addresses or RELA relocations) you'd run into the same issue afaict. So I'd recommend fixing this in your compiler or linker asap.
On Mon, 26 Sept 2022 at 11:06, Masahiro Yamada <masahiroy@kernel.org> wrote: > > On Mon, Sep 26, 2022 at 5:48 PM Yann Sionneau <ysionneau@kalray.eu> wrote: > > > > > > On 8/28/22 16:05, Masahiro Yamada wrote: > > > On Fri, Aug 26, 2022 at 7:17 PM Ard Biesheuvel <ardb@kernel.org> wrote: > > >> On Thu, 25 Aug 2022 at 20:01, Geert Uytterhoeven <geert@linux-m68k.org> wrote: > > >>> Hi Ard, > > >>> > > >>> On Thu, Aug 25, 2022 at 2:56 PM Ard Biesheuvel <ardb@kernel.org> wrote: > > >>>> On Thu, 25 Aug 2022 at 14:21, Yann Sionneau <ysionneau@kalray.eu> wrote: > > >>>>> Well, I am not completely sure about that. See my cover letter, previous > > >>>>> mechanism for symbol CRC was actually enforcing the section alignment to > > >>>>> 4 bytes boundary as well. > > >>> Yes, because else it may become 2-byte aligned on m68k. > > >>> > > >>>>> Also, I'm not sure it is forbidden for an architecture/compiler > > >>>>> implementation to actually enforce a stronger alignment on u32, which in > > >>>>> theory would not break anything. > > >>>>> > > >>>> u32 is a Linux type, and Linux expects natural alignment (and padding). > > >>> Is it? You probably mean its alignment should not be larger than > > >>> 4 bytes? Less has been working since basically forever. > > >>> > > >> You are quite right. of course. And indeed, the issue here is padding > > >> not alignment. > > >> > > > I do not know if __align(4) should be used to avoid the padding issue. > > > > > > > > > > > > Do you think it is a good idea to use an inline assembler, > > > as prior to 7b4537199a4a8480b8c3ba37a2d44765ce76cd9b ? > > > > > > > > > This patch: > > > > > > diff --git a/include/linux/export-internal.h b/include/linux/export-internal.h > > > index c2b1d4fd5987..fb90f326b1b5 100644 > > > --- a/include/linux/export-internal.h > > > +++ b/include/linux/export-internal.h > > > @@ -12,6 +12,9 @@ > > > > > > /* __used is needed to keep __crc_* for LTO */ > > > #define SYMBOL_CRC(sym, crc, sec) \ > > > - u32 __section("___kcrctab" sec "+" #sym) __used __crc_##sym = crc > > > + asm(".section \"___kcrctab" sec "+" #sym "\",\"a\"" "\n" \ > > > + "__crc_" #sym ":" "\n" \ > > > + ".long " #crc "\n" \ > > > + ".previous" "\n") > > > > > > #endif /* __LINUX_EXPORT_INTERNAL_H__ */ > > > > Ping on this topic, should we "fix our toolchain"? > > > > Or should Linux code be modified to add either __align(4) or use the > > inline assembler? (I've tried your inline asm patch and it seems to fix > > the issue I'm having). > > > > Or both? > > > > Thanks, > > > > Yann > > > > > > > > > > > > > I queued up the patch. > You can see it in linux-next. > > > Once it lands in the mainline, > it will be back-ported. > > > > > > > masahiro@zoe:~/ref/linux-next$ git log -1 next-20220923 -- > include/linux/export-internal.h > commit 60ecfddd7a092f9cbd2398dbc55da3abbb803ff0 > Author: Masahiro Yamada <masahiroy@kernel.org> > Date: Fri Sep 16 15:29:53 2022 +0900 > > linux/export: use inline assembler to populate symbol CRCs > > Since commit 7b4537199a4a ("kbuild: link symbol CRCs at final link, > removing CONFIG_MODULE_REL_CRCS"), the module versioning on the > (non-upstreamed-yet) kvx Linux port is broken due to unexpected padding > for __crc_* symbols. The kvx GCC adds padding so u32 gets 8-byte > alignment instead of 4. > > I do not know if this happens for upstream architectures in general, > but any compiler has the freedom to insert padding for faster access. > > Use the inline assembler to directly specify the wanted data layout. > This is how we previously did before the breakage. > > Link: https://lore.kernel.org/lkml/20220817161438.32039-1-ysionneau@kalray.eu/ > Link: https://lore.kernel.org/linux-kbuild/31ce5305-a76b-13d7-ea55-afca82c46cf2@kalray.eu/ > Fixes: 7b4537199a4a ("kbuild: link symbol CRCs at final link, > removing CONFIG_MODULE_REL_CRCS") > Reported-by: Yann Sionneau <ysionneau@kalray.eu> > Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> > Tested-by: Yann Sionneau <ysionneau@kalray.eu> > I don't think we should merge this. kvm is an experimental out of tree port, and everywhere else, we already rely heavily on array sections constructed by the linker where it just concatenate sections from the input objects, and assumes there will be no padding.
diff --git a/include/linux/export-internal.h b/include/linux/export-internal.h index c2b1d4fd5987..d86bfbd7fa6d 100644 --- a/include/linux/export-internal.h +++ b/include/linux/export-internal.h @@ -12,6 +12,6 @@ /* __used is needed to keep __crc_* for LTO */ #define SYMBOL_CRC(sym, crc, sec) \ - u32 __section("___kcrctab" sec "+" #sym) __used __crc_##sym = crc + u32 __section("___kcrctab" sec "+" #sym) __used __aligned(4) __crc_##sym = crc #endif /* __LINUX_EXPORT_INTERNAL_H__ */