diff mbox series

[v2,2/4] modules: Ensure 64-bit alignment on __ksymtab_* sections

Message ID 20240129192644.3359978-3-mcgrof@kernel.org (mailing list archive)
State New
Headers show
Series modules: few of alignment fixes | expand

Commit Message

Luis Chamberlain Jan. 29, 2024, 7:26 p.m. UTC
From: Helge Deller <deller@gmx.de>

On 64-bit architectures without CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
(e.g. ppc64, ppc64le, parisc, s390x,...) the __KSYM_REF() macro stores
64-bit pointers into the __ksymtab* sections.
Make sure that those sections will be correctly aligned at module link time,
otherwise unaligned memory accesses may happen at runtime.

The __kcrctab* sections store 32-bit entities, so use ALIGN(4) for those.

Testing with the kallsyms selftest on x86_64 we see a savings of about
1,958,153 ns in the worst case which may or not be within noise. Testing
on parisc would be useful and welcomed.

On x86_64 before:

 Performance counter stats for '/sbin/modprobe test_kallsyms_b':

        86,430,119 ns   duration_time
        84,407,000 ns   system_time
               213      page-faults

       0.086430119 seconds time elapsed

       0.000000000 seconds user
       0.084407000 seconds sys

 Performance counter stats for '/sbin/modprobe test_kallsyms_b':

        85,777,474 ns   duration_time
        82,581,000 ns   system_time
               212      page-faults

       0.085777474 seconds time elapsed

       0.000000000 seconds user
       0.082581000 seconds sys

 Performance counter stats for '/sbin/modprobe test_kallsyms_b':

        87,906,053 ns   duration_time
        87,939,000 ns   system_time
               212      page-faults

       0.087906053 seconds time elapsed

       0.000000000 seconds user
       0.087939000 seconds sys

After:

 Performance counter stats for '/sbin/modprobe test_kallsyms_b':

        82,925,631 ns   duration_time
        83,000,000 ns   system_time
               212      page-faults

       0.082925631 seconds time elapsed

       0.000000000 seconds user
       0.083000000 seconds sys

 Performance counter stats for '/sbin/modprobe test_kallsyms_b':

        87,776,380 ns   duration_time
        86,678,000 ns   system_time
               213      page-faults

       0.087776380 seconds time elapsed

       0.000000000 seconds user
       0.086678000 seconds sys

 Performance counter stats for '/sbin/modprobe test_kallsyms_b':

        85,947,900 ns   duration_time
        82,006,000 ns   system_time
               212      page-faults

       0.085947900 seconds time elapsed

       0.000000000 seconds user
       0.082006000 seconds sys

Signed-off-by: Helge Deller <deller@gmx.de>
[mcgrof: ran kallsyms selftests on x86_64]
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
 scripts/module.lds.S | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/scripts/module.lds.S b/scripts/module.lds.S
index bf5bcf2836d8..b00415a9ff27 100644
--- a/scripts/module.lds.S
+++ b/scripts/module.lds.S
@@ -15,10 +15,10 @@  SECTIONS {
 		*(.discard.*)
 	}
 
-	__ksymtab		0 : { *(SORT(___ksymtab+*)) }
-	__ksymtab_gpl		0 : { *(SORT(___ksymtab_gpl+*)) }
-	__kcrctab		0 : { *(SORT(___kcrctab+*)) }
-	__kcrctab_gpl		0 : { *(SORT(___kcrctab_gpl+*)) }
+	__ksymtab		0 : ALIGN(8) { *(SORT(___ksymtab+*)) }
+	__ksymtab_gpl		0 : ALIGN(8) { *(SORT(___ksymtab_gpl+*)) }
+	__kcrctab		0 : ALIGN(4) { *(SORT(___kcrctab+*)) }
+	__kcrctab_gpl		0 : ALIGN(4) { *(SORT(___kcrctab_gpl+*)) }
 
 	.ctors			0 : ALIGN(8) { *(SORT(.ctors.*)) *(.ctors) }
 	.init_array		0 : ALIGN(8) { *(SORT(.init_array.*)) *(.init_array) }