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

From: Luis Chamberlain
Date: Mon Jan 29 2024 - 14:27:26 EST


From: Helge Deller <deller@xxxxxx>

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@xxxxxx>
[mcgrof: ran kallsyms selftests on x86_64]
Signed-off-by: Luis Chamberlain <mcgrof@xxxxxxxxxx>
---
scripts/module.lds.S | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

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) }
--
2.42.0