Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Ard Biesheuvel" <ardb@kernel.org>
To: "Josh Poimboeuf" <jpoimboe@kernel.org>
Cc: linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, "Will Deacon" <will@kernel.org>,
	"Catalin Marinas" <catalin.marinas@arm.com>,
	"Mark Rutland" <mark.rutland@arm.com>,
	"Mark Brown" <broonie@kernel.org>,
	"Nick Desaulniers" <ndesaulniers@google.com>
Subject: Re: [PATCH 1/2] arm64: module: Emit BTI veneers for cross-section calls
Date: Thu, 13 Aug 2026 10:53:34 +0300	[thread overview]
Message-ID: <e75e5fd3-d7c7-43f0-bd30-d7f2ac834942@app.fastmail.com> (raw)
In-Reply-To: <ba248b4e-958d-4eef-bb66-22a737a6412d@app.fastmail.com>


On Thu, 13 Aug 2026, at 09:34, Ard Biesheuvel wrote:
> On Thu, 13 Aug 2026, at 00:52, Josh Poimboeuf wrote:
>> On Wed, Aug 12, 2026 at 06:21:00PM +0200, Ard Biesheuvel wrote:
>>> The compiler is permitted to omit BTI landing pads from static functions
>>> that never have their address taken, but are only called directly, even
>>> if those calls originate from other code sections.
>>> 
>>> This means that calls into a module's .text section from .init.text,
>>> which may need to be routed via a PLT if .text is out of direct
>>> branching range, may result in BTI exceptions due to the indirect calls
>>> performed by the PLT veneers. (Note that calls to .init.text from .text
>>> are not allowed.)
>>> 
>>> The 'solution' is to emit yet another veneer - this is what the ELF
>>> psABI for AArch64 mandates in this case.
>>> 
>>> So derive an upper bound for the number of veneers that may be needed in
>>> the core module region to ensure that any call from init code that ends
>>> up needing a PLT can be directed at a veneer with a BTI landing pad, and
>>> allocate the additional space.
>>> 
>>> Then, emit these veneers as needed, i.e., only when emitting a PLT entry
>>> for a call from an init code section to a normal code section in the
>>> same module. In practice, this only occurs when a module's .init.text
>>> happens to be allocated far away from its .text section, which might
>>> happen when the initial 128M 'near' module region runs out of space
>>> between allocating the core module and allocating its init region.
>>> 
>>> Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
>>> ---
>>>  arch/arm64/Kconfig                  |   2 -
>>>  arch/arm64/include/asm/module.h     |  12 ++
>>>  arch/arm64/include/asm/module.lds.h |   3 +
>>>  arch/arm64/kernel/module-plts.c     | 128 +++++++++++++++++++-
>>>  4 files changed, 138 insertions(+), 7 deletions(-)
>>> 
>>> diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
>>> index b3afe0688919..25fa80b5591d 100644
>>> --- a/arch/arm64/Kconfig
>>> +++ b/arch/arm64/Kconfig
>>> @@ -2114,8 +2114,6 @@ config ARM64_BTI_KERNEL
>>>  	depends on CC_HAS_BRANCH_PROT_PAC_RET_BTI
>>>  	# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94697
>>>  	depends on !CC_IS_GCC || GCC_VERSION >= 100100
>>> -	# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106671
>>> -	depends on !CC_IS_GCC
>>
>> This doesn't work for livepatch though, and removing the "depends on
>> !CC_IS_GCC" is a livepatch regression as it broadly increases the
>> likelihood of ARM64_BTI_KERNEL (default y) getting enabled.
>>
>> So "livepatch broken on arm64 clang 21+" now becomes "livepatch broken 
>> on arm64".
>>
>
> ... when kernel mode BTI is enabled.
>
> I have no insight into which pieces of livepatch for arm64 are actually
> upstream. Is it just the tooling that is missing? In this case, though,
> I think HAVE_LIVEPATCH should depend on !ARM64_BTI_KERNEL, rather than
> the other way around. I can add that in v2.
>

BTW we may still try and get the compiler folks to add a command line
option to force BTI landing pads to be emitted for static functions, and
enable it for vmlinux only when livepatch is enabled. That way, we can
re-enable kernel mode BTI for all toolchains for the common case, and
have livepatch on arm64 (with BTI) depend on recent versions that implement
this option.




  reply	other threads:[~2026-08-13  7:54 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-12 16:20 [PATCH 0/2] arm64: Implement support for BTI veneers Ard Biesheuvel
2026-08-12 16:21 ` [PATCH 1/2] arm64: module: Emit BTI veneers for cross-section calls Ard Biesheuvel
2026-08-12 21:52   ` Josh Poimboeuf
2026-08-13  2:25     ` Josh Poimboeuf
2026-08-13  6:34     ` Ard Biesheuvel
2026-08-13  7:53       ` Ard Biesheuvel [this message]
2026-08-12 16:21 ` [PATCH 2/2] DONOTMERGE: arm64: module: Test module for BTI veneers Ard Biesheuvel

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=e75e5fd3-d7c7-43f0-bd30-d7f2ac834942@app.fastmail.com \
    --to=ardb@kernel.org \
    --cc=broonie@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=jpoimboe@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=ndesaulniers@google.com \
    --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