mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Shivang Upadhyay <shivangu@linux.ibm.com>
To: Josh Poimboeuf <jpoimboe@kernel.org>
Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org,
	maddy@linux.ibm.com, mpe@ellerman.id.au, npiggin@gmail.com,
	chleroy@kernel.org, ritesh.list@gmail.com, sshegde@linux.ibm.com,
	peterz@infradead.org, ardb@kernel.org, will@kernel.org,
	sv@linux.ibm.com, joe.lawrence@redhat.com, song@kernel.org,
	mingo@kernel.org, mbenes@suse.cz
Subject: Re: [PATCH v3 00/11] objtool/powerpc: Fix up feature section alternatives at build time
Date: Thu, 03 Dec 2026 12:36:43 +0530	[thread overview]
Message-ID: <3c3f8c66080fbd98257ecbde0dc9162dbabfd48a.camel@linux.ibm.com> (raw)
In-Reply-To: <axCJHIhmBcbdlVFH@jpoimboe>

On Wed, 2026-12-02 at 13:25 -0800, Josh Poimboeuf wrote:
> On Wed, Dec 02, 2026 at 01:10:47PM +0530, Shivang Upadhyay wrote:
> > The replacement code of a powerpc feature section
> > (BEGIN_FTR_SECTION /
> > FTR_SECTION_ELSE / ALT_FTR_SECTION_END macros) is emitted into a
> > __ftr_alt_*
> > section.  At boot, apply_feature_fixups() copies the replacement
> > code over it.
> > Since the copy lands at a different address than the one it was
> > linked for, the
> > PC-relative branches in it have to be translated, which is
> > currently done at
> > runtime by patch_feature_section().
> > 
> > This has two drawbacks:
> > 
> >  - __ftr_alt_* sections are allocatable but not executable, so the
> >    linker cannot insert branch stubs for them.  They therefore have
> > to
> >    be placed close to .text, and every branch in them must reach
> > its
> >    target directly.  This can break the build as the kernel grows.
> 
> Is this a real issue or is it theoretical?
Hi Josh,

  I haven't hit this myself, but Nick and Sathvika ran into it while
working on alt features. I believe the failing case was conditional
branches (bc, R_PPC_REL14), which can only reach ±32KB. On ppc64le the
sections are aligned to the page size, commonly 64KB, so a branch from
an alt section can easily end up out of range of its target, specially
when alt section adds length to top of head section.

> 
> >  - The branches are translated on every boot, although everything
> >    needed to do it is known at link time.
> 
> x86 also does something similar for its alternatives, I'm not sure
> that's much of a drawback though.
> 
> Presumably objtool-on-vmlinux adds some slowness to the build.
> 
Not much, There are not many instructions to patch.

 time ./tools/objtool/objtool --link --alt-fixup ./vmlinux.unstripped 

 real    0m0.901s
 user    0m0.582s
 sys     0m0.309s

> > This series moves the translation to build time.  After vmlinux is
> > linked, objtool is run on it with the new --alt-fixup option.  It
> > parses
> > the __ftr_fixup, __mmu_ftr_fixup and __fw_ftr_fixup tables, and for
> > each
> > PC-relative relocation in the replacement code, asks the arch to
> > rewrite
> > the instruction so that it is valid at the place it will be copied
> > to.
> > With that, the __ftr_alt_* sections are marked executable and moved
> > out
> > of .text into their own output section, so the linker can insert
> > stubs
> > where needed.
> > 
> > Objtool does not process modules or the VDSO, so the runtime
> > translation
> > is kept for those and only skipped for the core kernel.
> 
> So now there are two translation methods of instead of one?
> 
> Is there any reason why objtool coudn't be run on linked vDSO and
> modules as well?
> 
It should not be hard to achieve. Currently I could not find any
example for alt feature implemented for VDSO or modules, to test.

~Shivang.
> > Previously, Nicholas Piggin proposed a build-time solution using a
> > custom
> > powerpc tool [1].  The approach here builds on that idea, but uses
> > objtool's existing ELF parsing and instruction patching
> > infrastructure
> > instead of a separate tool.
> 
> I notice that last approach was almost 10 years ago, just wondering
> if
> this is a real problem that people are hitting.

      reply	other threads:[~2026-12-03  7:07 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02  7:40 Shivang Upadhyay
2026-12-02  7:40 ` [PATCH v3 01/11] objtool: Make symbol offsets section relative in linked objects Shivang Upadhyay
2026-12-02  7:40 ` [PATCH v3 02/11] objtool: Make relocation " Shivang Upadhyay
2026-12-02  7:40 ` [PATCH v3 03/11] objtool: Keep the layout of linked objects when writing them back Shivang Upadhyay
2026-12-02  7:40 ` [PATCH v3 04/11] objtool: Pass the objtool_file to arch_support_alt_relocation() Shivang Upadhyay
2026-12-02  7:40 ` [PATCH v3 05/11] objtool: Add --alt-fixup Shivang Upadhyay
2026-12-02  7:40 ` [PATCH v3 06/11] objtool: Describe special_entry parsing for --alt-fixup Shivang Upadhyay
2026-12-02  7:40 ` [PATCH v3 07/11] powerpc/lib: Extract branch patching helpers to code-patching-branch.c Shivang Upadhyay
2026-12-02  7:40 ` [PATCH v3 08/11] objtool/powerpc: Implement arch_support_alt_relocation() Shivang Upadhyay
2026-12-02  7:40 ` [PATCH v3 09/11] powerpc: Mark feature section alternatives as executable Shivang Upadhyay
2026-12-02  7:40 ` [PATCH v3 10/11] powerpc: Always build objtool for powerpc Shivang Upadhyay
2026-12-03  5:51   ` kernel test robot
2026-12-02  7:40 ` [PATCH v3 11/11] powerpc: Remove runtime checking of jumps in core kernel feature-fixup Shivang Upadhyay
2026-12-02 21:25 ` [PATCH v3 00/11] objtool/powerpc: Fix up feature section alternatives at build time Josh Poimboeuf
2026-12-03  7:06   ` Shivang Upadhyay [this message]

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=3c3f8c66080fbd98257ecbde0dc9162dbabfd48a.camel@linux.ibm.com \
    --to=shivangu@linux.ibm.com \
    --cc=ardb@kernel.org \
    --cc=chleroy@kernel.org \
    --cc=joe.lawrence@redhat.com \
    --cc=jpoimboe@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=maddy@linux.ibm.com \
    --cc=mbenes@suse.cz \
    --cc=mingo@kernel.org \
    --cc=mpe@ellerman.id.au \
    --cc=npiggin@gmail.com \
    --cc=peterz@infradead.org \
    --cc=ritesh.list@gmail.com \
    --cc=song@kernel.org \
    --cc=sshegde@linux.ibm.com \
    --cc=sv@linux.ibm.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

all inboxes | Powered by JetHome®