linux-modules.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Luis Chamberlain <mcgrof@kernel.org>
To: masahiroy@kernel.org, deller@gmx.de
Cc: mcgrof@kernel.org, arnd@arndb.de, linux-arch@vger.kernel.org,
	linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2 2/4] modules: Ensure 64-bit alignment on __ksymtab_* sections
Date: Mon, 29 Jan 2024 11:26:41 -0800	[thread overview]
Message-ID: <20240129192644.3359978-3-mcgrof@kernel.org> (raw)
In-Reply-To: <20240129192644.3359978-1-mcgrof@kernel.org>

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 --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


  parent reply	other threads:[~2024-01-29 19:26 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-29 19:26 [PATCH v2 0/3] modules: few of alignment fixes Luis Chamberlain
2024-01-29 19:26 ` [PATCH v2 1/4] selftests: add new kallsyms selftests Luis Chamberlain
2024-01-29 19:26 ` Luis Chamberlain [this message]
2024-01-29 19:26 ` [PATCH v2 3/4] vmlinux.lds.h: add missing alignment for symbol CRCs Luis Chamberlain
2024-01-29 19:26 ` [PATCH v2 4/4] modules: Add missing entry for __ex_table Luis Chamberlain
2024-01-31 22:11 ` [PATCH v2 0/3] modules: few of alignment fixes Luis Chamberlain
2024-02-01 18:05   ` Luis Chamberlain
2024-02-02 15:20     ` Masahiro Yamada
2024-02-02 18:23       ` Luis Chamberlain
2024-10-21 19:22         ` Luis Chamberlain
2024-10-21 20:07           ` Helge Deller
2024-10-23  4:55             ` Masahiro Yamada

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240129192644.3359978-3-mcgrof@kernel.org \
    --to=mcgrof@kernel.org \
    --cc=arnd@arndb.de \
    --cc=deller@gmx.de \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-modules@vger.kernel.org \
    --cc=masahiroy@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).