Live Patching
 help / color / mirror / Atom feed
From: "Ard Biesheuvel" <ardb@kernel.org>
To: "Josh Poimboeuf" <jpoimboe@kernel.org>,
	"Catalin Marinas" <catalin.marinas@arm.com>,
	"Will Deacon" <will@kernel.org>
Cc: linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	live-patching@vger.kernel.org, "Song Liu" <song@kernel.org>,
	"Miroslav Benes" <mbenes@suse.cz>,
	"Petr Mladek" <pmladek@suse.com>,
	"Joe Lawrence" <joe.lawrence@redhat.com>,
	"Mark Rutland" <mark.rutland@arm.com>,
	"Mark Brown" <broonie@kernel.org>,
	"Nick Desaulniers" <ndesaulniers@google.com>,
	"Kees Cook" <kees@kernel.org>,
	"Nathan Chancellor" <nathan@kernel.org>,
	linux-toolchains@vger.kernel.org
Subject: Re: [PATCH 03/12] arm64/bti: Fix BTI linker failures with long branches into .idmap.text
Date: Mon, 17 Aug 2026 14:05:36 +0300	[thread overview]
Message-ID: <73bdec09-a2dd-4693-aa30-12fab36e7a18@app.fastmail.com> (raw)
In-Reply-To: <a9662e64de17882d2ef2401bad0d8172ef48bc4b.1786768375.git.jpoimboe@kernel.org>

Hi Josh,

On Sat, 15 Aug 2026, at 07:45, Josh Poimboeuf wrote:
> On a kernel whose text exceeds the +/128MB direct branch range, the
> linker inserts veneers.  With BTI enabled, the veneers' indirect branch
> targets need a BTI landing pad, which not all functions have starting
> with Clang 21 (and for all versions of GCC).
>
> In such cases the linker can emit a second veneer close to the target
> which has the landing pad along with a direct branch to the target.  But
> a long branch to .idmap.text never gets one because it's missing the
> executable section flag.
>
> With the LLVM linker, it's a silent failure, presumably only discovered
> by a BTI exception at runtime.  With the GNU linker it's even worse, as
> it dereferences the missing stub/veneer group entry and seg faults (this
> was how I discovered it).
>
> Make sure the section is executable by adding the "x" flag to all the
> creators of the input section.
>
> Also manually add "bti c" to primary_entry() and enter_vhe(), otherwise
> the linker-generated veneer page pushes the .idmap.text past its
> asserted 4KB size:
>
>   ld.bfd: ID map text too big or misaligned
>
> Link: https://sourceware.org/bugzilla/show_bug.cgi?id=34525
> Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
> ---
>  arch/arm64/kernel/cpu-reset.S | 2 +-
>  arch/arm64/kernel/head.S      | 7 ++++---
>  arch/arm64/kernel/hyp-stub.S  | 1 +
>  arch/arm64/kernel/sleep.S     | 2 +-
>  arch/arm64/mm/proc.S          | 8 ++++----
>  5 files changed, 11 insertions(+), 9 deletions(-)
>
> diff --git a/arch/arm64/kernel/cpu-reset.S b/arch/arm64/kernel/cpu-reset.S
> index c87445dde6745..9943a7c70f6b0 100644
> --- a/arch/arm64/kernel/cpu-reset.S
> +++ b/arch/arm64/kernel/cpu-reset.S
> @@ -14,7 +14,7 @@
>  #include <asm/virt.h>
> 
>  .text
> -.pushsection    .idmap.text, "a"
> +.pushsection    .idmap.text, "ax"
> 

We've had issues in the past with this change.

The problem is that the ID map is restricted to a single page, and
[some versions of] the GNU linker concatenate generated veneers onto
whichever executable input section came last in the input, which was
this one at that point.

That resulted in the ID map start/end boundaries being placed further
apart than the linker asserts would tolerate, even though the generated
code in question would never be called via the 1:1 mapping.

Not sure whether that problem has simply disappeared by now, or older
versions of the linker may still trigger it. But it is something to be
aware of.

  reply	other threads:[~2026-08-17 11:06 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-15  4:45 [PATCH 00/12] arm64/bti: Fix kernel BTI issues with livepatch, large kernels, toolchains Josh Poimboeuf
2026-08-15  4:45 ` [PATCH 01/12] arm64/bti: Add BTI landing pad to __sdei_asm_handler() Josh Poimboeuf
2026-08-15  5:01   ` sashiko-bot
2026-08-15  4:45 ` [PATCH 02/12] arm64/module: Fix BTI exceptions caused by omitted landing pads in Clang 21 Josh Poimboeuf
2026-08-15  5:00   ` sashiko-bot
2026-08-15  9:56   ` Ard Biesheuvel
2026-08-15 18:57     ` Josh Poimboeuf
2026-08-17 11:11       ` Ard Biesheuvel
2026-08-16  9:41     ` Will Deacon
2026-08-16 13:49       ` Ard Biesheuvel
2026-08-16 18:46         ` Josh Poimboeuf
2026-08-15  4:45 ` [PATCH 03/12] arm64/bti: Fix BTI linker failures with long branches into .idmap.text Josh Poimboeuf
2026-08-17 11:05   ` Ard Biesheuvel [this message]
2026-08-15  4:45 ` [PATCH 04/12] arm64/bti: Work around ld crash caused by linker script aliases Josh Poimboeuf
2026-08-15  4:45 ` [PATCH 05/12] arm64/bti: Add link error for large kernels with BTI and unsupported toolchains Josh Poimboeuf
2026-08-15  4:45 ` [PATCH 06/12] arm64/bti: Add link error for large kernels with BTI and livepatch Josh Poimboeuf
2026-08-15  4:45 ` [PATCH 07/12] arm64/bti: Advertise BTI in assembly objects Josh Poimboeuf
2026-08-15  5:03   ` sashiko-bot
2026-08-15 21:53   ` Mark Brown
2026-08-15  4:45 ` [PATCH 08/12] arm64/bti: Enable BTI in the pi/ startup code Josh Poimboeuf
2026-08-15  4:45 ` [PATCH 09/12] efi/libstub: Preserve the GNU property note Josh Poimboeuf
2026-08-15  4:45 ` [PATCH 10/12] efi/libstub: Remove obsolete .note.gnu.property workaround Josh Poimboeuf
2026-08-15  4:45 ` [PATCH 11/12] arm64/bti: Force-enable BTI linker veneers Josh Poimboeuf
2026-08-15  5:00   ` sashiko-bot
2026-08-15  4:45 ` [PATCH 12/12] arm64/bti: Enable kernel BTI for GCC 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=73bdec09-a2dd-4693-aa30-12fab36e7a18@app.fastmail.com \
    --to=ardb@kernel.org \
    --cc=broonie@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=joe.lawrence@redhat.com \
    --cc=jpoimboe@kernel.org \
    --cc=kees@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-toolchains@vger.kernel.org \
    --cc=live-patching@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mbenes@suse.cz \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=pmladek@suse.com \
    --cc=song@kernel.org \
    --cc=will@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