live-patching.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Carlos Llamas <cmllamas@google.com>
To: Josh Poimboeuf <jpoimboe@kernel.org>
Cc: x86@kernel.org, linux-kernel@vger.kernel.org,
	Petr Mladek <pmladek@suse.com>, Miroslav Benes <mbenes@suse.cz>,
	Joe Lawrence <joe.lawrence@redhat.com>,
	live-patching@vger.kernel.org, Song Liu <song@kernel.org>,
	laokz <laokz@foxmail.com>, Jiri Kosina <jikos@kernel.org>,
	Marcos Paulo de Souza <mpdesouza@suse.com>,
	Weinan Liu <wnliu@google.com>,
	Fazla Mehrab <a.mehrab@bytedance.com>,
	Chen Zhongjin <chenzhongjin@huawei.com>,
	Puranjay Mohan <puranjay@kernel.org>,
	Dylan Hatch <dylanbhatch@google.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Heiko Carstens <hca@linux.ibm.com>,
	Vasily Gorbik <gor@linux.ibm.com>,
	Alexander Gordeev <agordeev@linux.ibm.com>,
	Ard Biesheuvel <ardb@kernel.org>,
	Sami Tolvanen <samitolvanen@google.com>,
	Will Deacon <will@kernel.org>,
	kernel-team@android.com
Subject: Re: [PATCH v4 02/63] vmlinux.lds: Unify TEXT_MAIN, DATA_MAIN, and related macros
Date: Sat, 20 Dec 2025 16:25:50 +0000	[thread overview]
Message-ID: <aUbODsjSuIBBLyo_@google.com> (raw)
In-Reply-To: <97d8b7710a8f5389e323d0933dec68888fec5f1f.1758067942.git.jpoimboe@kernel.org>

On Wed, Sep 17, 2025 at 09:03:10AM -0700, Josh Poimboeuf wrote:
> TEXT_MAIN, DATA_MAIN and friends are defined differently depending on
> whether certain config options enable -ffunction-sections and/or
> -fdata-sections.
> 
> There's no technical reason for that beyond voodoo coding.  Keeping the
> separate implementations adds unnecessary complexity, fragments the
> logic, and increases the risk of subtle bugs.
> 
> Unify the macros by using the same input section patterns across all
> configs.
> 
> This is a prerequisite for the upcoming livepatch klp-build tooling
> which will manually enable -ffunction-sections and -fdata-sections via
> KCFLAGS.
> 
> Cc: Heiko Carstens <hca@linux.ibm.com>
> Cc: Vasily Gorbik <gor@linux.ibm.com>
> Cc: Alexander Gordeev <agordeev@linux.ibm.com>
> Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
> ---
>  include/asm-generic/vmlinux.lds.h | 40 ++++++++++---------------------
>  scripts/module.lds.S              | 12 ++++------
>  2 files changed, 17 insertions(+), 35 deletions(-)
> 
> diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
> index ae2d2359b79e9..6b2311fa41393 100644
> --- a/include/asm-generic/vmlinux.lds.h
> +++ b/include/asm-generic/vmlinux.lds.h
> @@ -87,39 +87,24 @@
>  #define ALIGN_FUNCTION()  . = ALIGN(CONFIG_FUNCTION_ALIGNMENT)
>  
>  /*
> - * LD_DEAD_CODE_DATA_ELIMINATION option enables -fdata-sections, which
> - * generates .data.identifier sections, which need to be pulled in with
> - * .data. We don't want to pull in .data..other sections, which Linux
> - * has defined. Same for text and bss.
> + * Support -ffunction-sections by matching .text and .text.*,
> + * but exclude '.text..*'.
>   *
> - * With LTO_CLANG, the linker also splits sections by default, so we need
> - * these macros to combine the sections during the final link.
> - *
> - * With AUTOFDO_CLANG and PROPELLER_CLANG, by default, the linker splits
> - * text sections and regroups functions into subsections.
> - *
> - * RODATA_MAIN is not used because existing code already defines .rodata.x
> - * sections to be brought in with rodata.
> + * Special .text.* sections that are typically grouped separately, such as
> + * .text.unlikely or .text.hot, must be matched explicitly before using
> + * TEXT_MAIN.
>   */
> -#if defined(CONFIG_LD_DEAD_CODE_DATA_ELIMINATION) || defined(CONFIG_LTO_CLANG) || \
> -defined(CONFIG_AUTOFDO_CLANG) || defined(CONFIG_PROPELLER_CLANG)
>  #define TEXT_MAIN .text .text.[0-9a-zA-Z_]*
> -#else
> -#define TEXT_MAIN .text
> -#endif
> -#if defined(CONFIG_LD_DEAD_CODE_DATA_ELIMINATION) || defined(CONFIG_LTO_CLANG)
> +
> +/*
> + * Support -fdata-sections by matching .data, .data.*, and others,
> + * but exclude '.data..*'.
> + */
>  #define DATA_MAIN .data .data.[0-9a-zA-Z_]* .data.rel.* .data..L* .data..compoundliteral* .data.$__unnamed_* .data.$L*
>  #define SDATA_MAIN .sdata .sdata.[0-9a-zA-Z_]*
>  #define RODATA_MAIN .rodata .rodata.[0-9a-zA-Z_]* .rodata..L*
>  #define BSS_MAIN .bss .bss.[0-9a-zA-Z_]* .bss..L* .bss..compoundliteral*
>  #define SBSS_MAIN .sbss .sbss.[0-9a-zA-Z_]*
> -#else
> -#define DATA_MAIN .data .data.rel .data.rel.local
> -#define SDATA_MAIN .sdata
> -#define RODATA_MAIN .rodata
> -#define BSS_MAIN .bss
> -#define SBSS_MAIN .sbss
> -#endif
>  
>  /*
>   * GCC 4.5 and later have a 32 bytes section alignment for structures.
> @@ -580,9 +565,8 @@ defined(CONFIG_AUTOFDO_CLANG) || defined(CONFIG_PROPELLER_CLANG)
>   * during second ld run in second ld pass when generating System.map
>   *
>   * TEXT_MAIN here will match symbols with a fixed pattern (for example,
> - * .text.hot or .text.unlikely) if dead code elimination or
> - * function-section is enabled. Match these symbols first before
> - * TEXT_MAIN to ensure they are grouped together.
> + * .text.hot or .text.unlikely).  Match those before TEXT_MAIN to ensure
> + * they get grouped together.
>   *
>   * Also placing .text.hot section at the beginning of a page, this
>   * would help the TLB performance.
> diff --git a/scripts/module.lds.S b/scripts/module.lds.S
> index ee79c41059f3d..2632c6cb8ebe7 100644
> --- a/scripts/module.lds.S
> +++ b/scripts/module.lds.S
> @@ -38,12 +38,10 @@ SECTIONS {
>  	__kcfi_traps 		: { KEEP(*(.kcfi_traps)) }
>  #endif
>  
> -#ifdef CONFIG_LTO_CLANG
> -	/*
> -	 * With CONFIG_LTO_CLANG, LLD always enables -fdata-sections and
> -	 * -ffunction-sections, which increases the size of the final module.
> -	 * Merge the split sections in the final binary.
> -	 */
> +	.text : {
> +		*(.text .text.[0-9a-zA-Z_]*)
> +	}
> +

Cc: Ard Biesheuvel <ardb@kernel.org>
Cc: Sami Tolvanen <samitolvanen@google.com>

I'm seeing some KP when trying to load modules after this change. I
believe there is some sort of incompatibility with the SCS (Shadow Call
Stack) code in arm64? The panic is always on __pi_scs_handle_fde_frame:

  init: Loading module [...]/drivers/net/wireless/virtual/mac80211_hwsim.ko
  Unable to handle kernel paging request at virtual address ffffffe6468f0ffc
  [...]
  pc : __pi_scs_handle_fde_frame+0xd8/0x15c
  lr : __pi_$x+0x74/0x138
  sp : ffffffc08005bb10
  x29: ffffffc08005bb10 x28: ffffffc081873010 x27: 0000000000000000
  x26: 0000000000000007 x25: 0000000000000000 x24: 0000000000000000
  x23: 0000000000000001 x22: ffffffe649794fa0 x21: ffffffe6469190b4
  x20: 000000000000182c x19: 0000000000000001 x18: ffffffc080053000
  x17: 000000000000002d x16: ffffffe6469190c5 x15: ffffffe6468f1000
  x14: 000000000000003e x13: ffffffe6469190c6 x12: 00000000d50323bf
  x11: 00000000d503233f x10: ffffffe649119cb8 x9 : ffffffe6468f1000
  x8 : 0000000000000100 x7 : 00656d6172665f68 x6 : 0000000000000001
  x5 : 6372610000000000 x4 : 0000008000000000 x3 : 0000000000000000
  x2 : ffffffe647e528f4 x1 : 0000000000000001 x0 : 0000000000000004
  Call trace:
   __pi_scs_handle_fde_frame+0xd8/0x15c (P)
   module_finalize+0xfc/0x164
   post_relocation+0xbc/0xd8
   load_module+0xfd4/0x11a8
   __arm64_sys_finit_module+0x23c/0x328
   invoke_syscall+0x58/0xe4
   el0_svc_common+0x80/0xdc
   do_el0_svc+0x1c/0x28
   el0_svc+0x54/0x1c4
   el0t_64_sync_handler+0x68/0xdc
   el0t_64_sync+0x1c4/0x1c8
  Code: 54fffd4c 1400001f 3707ff63 aa0903ef (b85fcdf0)

This is not a problem if I disable UNWIND_PATCH_PAC_INTO_SCS but I have
no idea why. Looking around it seems like this might related:

  $ cat arch/arm64/include/asm/module.lds.h
  SECTIONS {
  [...]
  #ifdef CONFIG_UNWIND_TABLES
        /*
         * Currently, we only use unwind info at module load time, so we can
         * put it into the .init allocation.
         */
        .init.eh_frame : { *(.eh_frame) }
  #endif

I must note that I've only seen this in Android kernels and I have not
tried to reproduce the issue elsewhere. However, the incompatibility
seems like it could be applicable upstream too and I'm hoping that the
issue is evident to others (I can't understand any of this).

Thanks,
--
Carlos Llamas

  reply	other threads:[~2025-12-20 16:25 UTC|newest]

Thread overview: 91+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-17 16:03 [PATCH v4 00/63] objtool,livepatch: klp-build livepatch module generation Josh Poimboeuf
2025-09-17 16:03 ` [PATCH v4 01/63] s390/vmlinux.lds.S: Prevent thunk functions from getting placed with normal text Josh Poimboeuf
2025-09-17 16:03 ` [PATCH v4 02/63] vmlinux.lds: Unify TEXT_MAIN, DATA_MAIN, and related macros Josh Poimboeuf
2025-12-20 16:25   ` Carlos Llamas [this message]
2025-09-17 16:03 ` [PATCH v4 03/63] x86/module: Improve relocation error messages Josh Poimboeuf
2025-09-17 16:03 ` [PATCH v4 04/63] x86/kprobes: Remove STACK_FRAME_NON_STANDARD annotation Josh Poimboeuf
2025-09-17 16:03 ` [PATCH v4 05/63] compiler: Tweak __UNIQUE_ID() naming Josh Poimboeuf
2025-09-17 16:03 ` [PATCH v4 06/63] compiler.h: Make addressable symbols less of an eyesore Josh Poimboeuf
2025-09-17 16:03 ` [PATCH v4 07/63] elfnote: Change ELFNOTE() to use __UNIQUE_ID() Josh Poimboeuf
2025-09-17 16:03 ` [PATCH v4 08/63] kbuild: Remove 'kmod_' prefix from __KBUILD_MODNAME Josh Poimboeuf
2025-10-20 12:20   ` Alexander Stein
2025-10-20 17:22     ` Josh Poimboeuf
2025-10-22  9:53       ` Anders Roxell
2025-10-20 12:59   ` Marek Szyprowski
2025-10-20 16:34   ` Mark Brown
2025-10-20 16:37   ` Cosmin Tanislav
2025-09-17 16:03 ` [PATCH v4 09/63] modpost: Ignore unresolved section bounds symbols Josh Poimboeuf
2025-09-17 16:03 ` [PATCH v4 10/63] x86/alternative: Refactor INT3 call emulation selftest Josh Poimboeuf
2025-09-17 16:03 ` [PATCH v4 11/63] interval_tree: Sync interval_tree_generic.h with tools Josh Poimboeuf
2025-09-17 16:03 ` [PATCH v4 12/63] interval_tree: Fix ITSTATIC usage for *_subtree_search() Josh Poimboeuf
2025-09-18 16:30   ` [PATCH v4.1 " Josh Poimboeuf
2025-09-17 16:03 ` [PATCH v4 13/63] objtool: Make find_symbol_containing() less arbitrary Josh Poimboeuf
2025-09-17 16:03 ` [PATCH v4 14/63] objtool: Fix broken error handling in read_symbols() Josh Poimboeuf
2025-09-17 16:03 ` [PATCH v4 15/63] objtool: Propagate elf_truncate_section() error in elf_write() Josh Poimboeuf
2025-09-17 16:03 ` [PATCH v4 16/63] objtool: Remove error handling boilerplate Josh Poimboeuf
2025-09-17 16:03 ` [PATCH v4 17/63] objtool: Add empty symbols to the symbol tree again Josh Poimboeuf
2025-09-17 16:03 ` [PATCH v4 18/63] objtool: Fix interval tree insertion for zero-length symbols Josh Poimboeuf
2025-09-17 16:03 ` [PATCH v4 19/63] objtool: Fix weak symbol detection Josh Poimboeuf
2025-09-17 16:03 ` [PATCH v4 20/63] objtool: Fix x86 addend calculation Josh Poimboeuf
2025-09-17 16:03 ` [PATCH v4 21/63] objtool: Fix __pa_symbol() relocation handling Josh Poimboeuf
2025-09-17 16:03 ` [PATCH v4 22/63] objtool: Fix "unexpected end of section" warning for alternatives Josh Poimboeuf
2025-09-17 16:03 ` [PATCH v4 23/63] objtool: Check for missing annotation entries in read_annotate() Josh Poimboeuf
2025-09-17 16:03 ` [PATCH v4 24/63] objtool: Const string cleanup Josh Poimboeuf
2025-09-17 16:03 ` [PATCH v4 25/63] objtool: Clean up compiler flag usage Josh Poimboeuf
2025-09-17 16:03 ` [PATCH v4 26/63] objtool: Remove .parainstructions reference Josh Poimboeuf
2025-09-17 16:03 ` [PATCH v4 27/63] objtool: Convert elf iterator macros to use 'struct elf' Josh Poimboeuf
2025-09-17 16:03 ` [PATCH v4 28/63] objtool: Add section/symbol type helpers Josh Poimboeuf
2025-09-17 16:03 ` [PATCH v4 29/63] objtool: Mark .cold subfunctions Josh Poimboeuf
2025-09-17 16:03 ` [PATCH v4 30/63] objtool: Fix weak symbol hole detection for .cold functions Josh Poimboeuf
2025-09-17 16:03 ` [PATCH v4 31/63] objtool: Mark prefix functions Josh Poimboeuf
2025-09-17 16:03 ` [PATCH v4 32/63] objtool: Simplify reloc offset calculation in unwind_read_hints() Josh Poimboeuf
2025-09-17 16:03 ` [PATCH v4 33/63] objtool: Avoid emptying lists for duplicate sections Josh Poimboeuf
2025-09-17 16:03 ` [PATCH v4 34/63] objtool: Rename --Werror to --werror Josh Poimboeuf
2025-09-17 16:03 ` [PATCH v4 35/63] objtool: Resurrect --backup option Josh Poimboeuf
2025-09-17 16:03 ` [PATCH v4 36/63] objtool: Reindent check_options[] Josh Poimboeuf
2025-09-17 16:03 ` [PATCH v4 37/63] objtool: Refactor add_jump_destinations() Josh Poimboeuf
2025-09-17 16:03 ` [PATCH v4 38/63] objtool: Simplify special symbol handling in elf_update_symbol() Josh Poimboeuf
2025-09-17 16:03 ` [PATCH v4 39/63] objtool: Generalize elf_create_symbol() Josh Poimboeuf
2025-09-17 16:03 ` [PATCH v4 40/63] objtool: Generalize elf_create_section() Josh Poimboeuf
2025-09-17 16:03 ` [PATCH v4 41/63] objtool: Add elf_create_data() Josh Poimboeuf
2025-09-17 16:03 ` [PATCH v4 42/63] objtool: Add elf_create_reloc() and elf_init_reloc() Josh Poimboeuf
2025-09-17 16:03 ` [PATCH v4 43/63] objtool: Add elf_create_file() Josh Poimboeuf
2025-09-17 16:03 ` [PATCH v4 44/63] objtool: Add annotype() helper Josh Poimboeuf
2025-09-17 16:03 ` [PATCH v4 45/63] objtool: Move ANNOTATE* macros to annotate.h Josh Poimboeuf
2025-09-17 16:03 ` [PATCH v4 46/63] objtool: Add ANNOTATE_DATA_SPECIAL Josh Poimboeuf
2025-09-17 16:03 ` [PATCH v4 47/63] x86/asm: Annotate special section entries Josh Poimboeuf
2025-09-17 16:03 ` [PATCH v4 48/63] objtool: Unify STACK_FRAME_NON_STANDARD entry sizes Josh Poimboeuf
2025-09-17 16:03 ` [PATCH v4 49/63] objtool/klp: Add --checksum option to generate per-function checksums Josh Poimboeuf
2025-10-27  1:19   ` Michael Kelley
2025-10-27 22:22     ` Josh Poimboeuf
2025-11-05 15:22       ` Michael Kelley
2025-11-11 20:09         ` Josh Poimboeuf
2025-11-12  1:39           ` Michael Kelley
2025-11-12  2:26             ` Michael Kelley
2025-11-12  4:04               ` Josh Poimboeuf
2025-11-12  4:32                 ` Michael Kelley
2025-11-12 13:25                   ` David Laight
2025-11-12 16:16                     ` Josh Poimboeuf
2025-11-12 21:39                       ` David Laight
2025-09-17 16:03 ` [PATCH v4 50/63] objtool/klp: Add --debug-checksum=<funcs> to show per-instruction checksums Josh Poimboeuf
2025-09-17 16:03 ` [PATCH v4 51/63] objtool/klp: Introduce klp diff subcommand for diffing object files Josh Poimboeuf
2025-10-08 14:01   ` Petr Mladek
2025-10-08 15:27     ` Josh Poimboeuf
2025-10-09 12:29       ` Petr Mladek
2025-10-09 23:19         ` Josh Poimboeuf
2025-09-17 16:04 ` [PATCH v4 52/63] objtool/klp: Add --debug option to show cloning decisions Josh Poimboeuf
2025-09-17 16:04 ` [PATCH v4 53/63] objtool/klp: Add post-link subcommand to finalize livepatch modules Josh Poimboeuf
2025-09-17 16:04 ` [PATCH v4 54/63] objtool: Refactor prefix symbol creation code Josh Poimboeuf
2025-09-17 16:04 ` [PATCH v4 55/63] objtool: Add base objtool support for livepatch modules Josh Poimboeuf
2025-09-17 16:04 ` [PATCH v4 56/63] livepatch: Add CONFIG_KLP_BUILD Josh Poimboeuf
2025-09-17 16:04 ` [PATCH v4 57/63] kbuild,objtool: Defer objtool validation step for CONFIG_KLP_BUILD Josh Poimboeuf
2025-09-17 16:04 ` [PATCH v4 58/63] livepatch/klp-build: Introduce fix-patch-lines script to avoid __LINE__ diff noise Josh Poimboeuf
2025-09-17 16:04 ` [PATCH v4 59/63] livepatch/klp-build: Add stub init code for livepatch modules Josh Poimboeuf
2025-09-17 16:04 ` [PATCH v4 60/63] livepatch/klp-build: Introduce klp-build script for generating " Josh Poimboeuf
2025-09-17 16:04 ` [PATCH v4 61/63] livepatch/klp-build: Add --debug option to show cloning decisions Josh Poimboeuf
2025-09-17 16:04 ` [PATCH v4 62/63] livepatch/klp-build: Add --show-first-changed option to show function divergence Josh Poimboeuf
2025-09-17 16:04 ` [PATCH v4 63/63] livepatch: Introduce source code helpers for livepatch modules Josh Poimboeuf
2025-09-18 16:32 ` [PATCH v4 00/63] objtool,livepatch: klp-build livepatch module generation Josh Poimboeuf
2025-10-07 17:38 ` Joe Lawrence
2025-10-10  7:30 ` Petr Mladek
2025-10-11  0:54   ` Josh Poimboeuf

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=aUbODsjSuIBBLyo_@google.com \
    --to=cmllamas@google.com \
    --cc=a.mehrab@bytedance.com \
    --cc=agordeev@linux.ibm.com \
    --cc=ardb@kernel.org \
    --cc=chenzhongjin@huawei.com \
    --cc=dylanbhatch@google.com \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=jikos@kernel.org \
    --cc=joe.lawrence@redhat.com \
    --cc=jpoimboe@kernel.org \
    --cc=kernel-team@android.com \
    --cc=laokz@foxmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=live-patching@vger.kernel.org \
    --cc=mbenes@suse.cz \
    --cc=mpdesouza@suse.com \
    --cc=peterz@infradead.org \
    --cc=pmladek@suse.com \
    --cc=puranjay@kernel.org \
    --cc=samitolvanen@google.com \
    --cc=song@kernel.org \
    --cc=will@kernel.org \
    --cc=wnliu@google.com \
    --cc=x86@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).