From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BD60A40244F for ; Wed, 12 Aug 2026 21:52:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786571525; cv=none; b=tZQSbBaM8QgRYrmshRQjV5M5AwM/Rcjz1SRtWA3R7VVWjoTbJW8SlZvnnBOjjH67lfA9tA79WK8ABfiZm+hySZ2+oURzDko9LSGrFy1jDt7aB4oquFN77oTlOR9yFQLb1hfjJTRIMJ5MazhvUwFd0xGqjR+INlpYIOllVcHieBs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786571525; c=relaxed/simple; bh=IKAN8RWM1t+WHKi3NjrdPzY5lydARVmM5Pn5JSm5Xok=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=fQT5hLkZMaGKznx89r0KcZJrBZ7dA06WMO7G7uTa+mDNF/PgvthtMMIaTHmAlfjPXfYDM//0y0ZuN5Y8pL8AoTyDiDJunzUUW4rk92yaoCdZEfr4AU89g6mlRozZQVUFNffuw4baZTxYiDS32qZDJcsrheg4LLHTvpa1MkaAqwI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KNwY8jZ4; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="KNwY8jZ4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 91EA71F000E9; Wed, 12 Aug 2026 21:52:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1786571524; bh=CYPwjDiA3bK/c7SyYMxuJGZm3FmtOLaYbnDMIYbMtws=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=KNwY8jZ4Q7lMe7IO3qZCIoKNXlD+kuH03v8c/xRnJ4C6f5hwm8iYwPCyrpN/A2YKp cSOf8K7qRltTCxDTpeGbu3lBRCRSPWhi9gQYuQnmoO/BRTgjwMXs8lfxFyzEPlYUme Hpvs2eI4RM94NlsyLX9HJQOngAe/hLdYpEBGSxhAD7+T8FygHjZiaDorwkz7i9K+bX XEEWP/3sklQGgk4MLoYozFFOvIRsYsUCCnoPBs0iUUG6B/A5HG3v3zXUOciNkNo3eh Ft7A/se0FFYfSAFmU1XtUFITJCGnfz49JidwfkicQ31wlu0BZS7rM6R+7XQPKipnWw vKvGKqlDk0WqA== Date: Wed, 12 Aug 2026 14:52:01 -0700 From: Josh Poimboeuf To: Ard Biesheuvel Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, will@kernel.org, catalin.marinas@arm.com, mark.rutland@arm.com, Mark Brown , Nick Desaulniers Subject: Re: [PATCH 1/2] arm64: module: Emit BTI veneers for cross-section calls Message-ID: References: <20260812162058.612202-4-ardb@kernel.org> <20260812162058.612202-5-ardb@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20260812162058.612202-5-ardb@kernel.org> 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 > --- > 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". So either ARM64_BTI_KERNEL needs to depend on !LIVEPATCH (which will keep BTI disabled for most distros), or we need a different approach which uses __vmalloc_node_range() to allocate a veneer within 128MB of the target. I can try to write that up. -- Josh