From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=148.163.156.1 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796197314; b=hCbGsBvcm0KlOFK59t2TrLyoEWYwZaMuFNL1mVj9dFYiuGBnLmkf4sMgS3/iuxlMbsJk 7XqFlDVNqABRntpZbq1aekaXAWPRYaiI9TsmdbUJit1AfG37fFBLExlmaLtVTvN/II6df O4HI9cBj0uVypBczMP3us1PkzypcVDJ4UOQ6kLC9mSeaOoyIRXphxUgEej4euy/MLMdQ1 8lhDsXCN58xKe+2xhEZFLxQKirALDk/A49bpud6uEK1SiBlZrCfFJjwFhCLe4+7DMSvih vM1+/GeqSd8cEkj1hYwUb6xzL2ZJzb7RsbMGdPg4JL/vuS47Q67abdp3LwlXnR4RqJw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796197314; h=DMARC-Filter:Received:DKIM-Signature:Received:Received:Received: Received:Received:Received:Received:From:To:Cc:Subject:Date: Message-ID:X-Mailer:MIME-Version:Content-Transfer-Encoding: X-TM-AS-GCONF:X-Proofpoint-Reinject:X-Proofpoint-Spam-Info: X-Proofpoint-ORIG-GUID:X-Proofpoint-GUID:X-Authority-Analysis: X-Proofpoint-Spam-Details-Enc:X-Proofpoint-Virus-Version: X-Proofpoint-Spam-Details; bh=w3fKPQlmYC70m3KBruEH5SfUm3oaUiRjEeATxPzSpnw=; b=s5tR9KXh90MnlSTA5Y4WmEES23w3su4FwHi7XKeStepMk/sDXCVFTNCo7SrkiN9VMyfk NgHxy/6UabppQYLNXv04Rj56+YwQnYEeh6U2eU4zivwdSSXyaLtjR9iT9TerTaG2eqnw6 TA2JFizR1FeVwMNsoN30RJTONsT0AlpPwngWJrCcB6TryZjjHprBllODN10HLORM3OH+T jnpknEnByOUqUNGxwRTbJ417+2WJtxNvSD+DN8ZzK/Zc/nK2sjNhun5xf3kHhdcL2bnVa dS7xfmpu1tY4Nwa+i5eWmme0E4AQ45EDtUMH44QxPEX8+nUGvlSHmkyswBS4G0oAU4A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=Apx6S4e4; arc=none smtp.remote-ip=148.163.156.1 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7BCE0606A31A for ; Wed, 2 Dec 2026 07:41:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7BCE0606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=Apx6S4e4 Received: from pps.filterd (m0360083.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6B274Ue14176871; Wed, 2 Dec 2026 07:41:21 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:message-id:mime-version :subject:to; s=pp1; bh=w3fKPQlmYC70m3KBruEH5SfUm3oaUiRjEeATxPzSp nw=; b=Apx6S4e4gg8+3RcQB+0AAXHGFOnp63hfFESLGmh9KOFLIYrRTprls1/3o EVX3SYO6X6ppzQk7LX981PKQYF04m6zRwvEyms+8+6b0YQLtLFr4ccbmaqI+GgHV XE5V1gJpFjPjqFI28qSj7giNg8n9KNIBt498pdK8bleLD5rDyld/erZ6NYQ52p5l ZlCdFSOWfmIEOKhl9Eij67u/GOr6uzUGINqxRJKGtQYsxstDjkurekALpCC8na3S +Oj3OaJrWbocX7BST7wgz2EH9Osdls4/2Gqp2MbGnRWHu7uMejeCz1q3pUgPCy7O atsYSG7ynNgR037QfBhVOb6v1Vf7g== Received: from ppma12.dal12v.mail.ibm.com (dc.9e.1632.ip4.static.sl-reverse.com [50.22.158.220]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4j7pf40pd6-1 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 02 Dec 2026 07:41:20 +0000 (GMT) Received: from pps.filterd (ppma12.dal12v.mail.ibm.com [127.0.0.1]) by ppma12.dal12v.mail.ibm.com (8.18.1.11/8.18.1.11) with ESMTP id 6B26nENv2682923; Wed, 2 Dec 2026 07:41:19 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 4j9ujnm62m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 02 Dec 2026 07:41:19 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 6B27fDgE56492480 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 2 Dec 2026 07:41:13 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C17262004B; Wed, 2 Dec 2026 07:41:13 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9B3EE2004E; Wed, 2 Dec 2026 07:41:06 +0000 (GMT) Received: from shivang.com (unknown [9.67.68.246]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 2 Dec 2026 07:41:06 +0000 (GMT) From: Shivang Upadhyay To: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Cc: maddy@linux.ibm.com, mpe@ellerman.id.au, npiggin@gmail.com, chleroy@kernel.org, ritesh.list@gmail.com, sshegde@linux.ibm.com, jpoimboe@kernel.org, peterz@infradead.org, shivangu@linux.ibm.com, ardb@kernel.org, will@kernel.org, sv@linux.ibm.com, joe.lawrence@redhat.com, song@kernel.org, mingo@kernel.org, mbenes@suse.cz Subject: [PATCH v3 00/11] objtool/powerpc: Fix up feature section alternatives at build time Date: Wed, 2 Dec 2026 13:10:47 +0530 Message-ID: <20261202074059.899491-1-shivangu@linux.ibm.com> X-Mailer: git-send-email 2.56.1 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Proofpoint-Spam-Info: AW1haW4tMjYxMjAyMDAzMCBTYWx0ZWRfX22PFvG+H//45 KPor2QqcPPIKVI2BhQhWGDnXWyJR9PFAPX1bZgM9LNbSj9gUj2uU4Su68/EM2rYZEGZxq/plgNl 0t6pXUE7zVaNo0ve3R6ouW2FH1u5SFw= X-Proofpoint-ORIG-GUID: pMGlICWTsQ3k-DnFvkNXV-dzhXDZeOJq X-Proofpoint-GUID: BZdUSBaq1N2i13XL41jqiVh35IgJKQTB X-Authority-Analysis: v=2.4 cv=R6eWitRX c=1 sm=1 tr=0 ts=6b0fcba0 cx=c_pps a=bLidbwmWQ0KltjZqbj+ezA==:117 a=bLidbwmWQ0KltjZqbj+ezA==:17 a=pUM-KoujPXoA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=iQ6ETzBq9ecOQQE5vZCe:22 a=voM4FWlXAAAA:8 a=pGLkceISAAAA:8 a=VwQbUJbxAAAA:8 a=VnNF1IyMAAAA:8 a=HMO4SIoWILKxtUVEoPgA:9 a=IC2XNlieTeVoXbcui8wp:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMjAyMDAzMCBTYWx0ZWRfX0FZmRjkjkirE iWJx4iijQGNITRhVKhTdU8OpErxzQcMXF2g78lwn7I0ABLGw+bGbR2TCrexC6dSWjGhydxPdYCD v4DLGS66is2+kNbwcMXEGDA7BXaMXCoXOgCXP8iqYcGbpcjY0zC8jBLoQvbtdPy4/g6c2W9wXeu 2/ZHRD//14vwog7TALUDKfiKLprdBsLRM/VR+1qrleKYuDfRph/6etkv2e+dGizUoNAyqu/AJcq nCwwNpfvSEngBY/J1tC5/RnhJ0dijr5l58Vd6iIL2/s9a0IsLkry5mr/61W988JuBNMoB9//Iau p99iTosrJqZRNsYeHJnEqxP5jYbg9aZTjuDi2TcYO/tfT91dpUa+0VTB251R3dDKkXsWMpDFNH8 F5IL4rR3vFlkQk4nyXCYfSuGgXeE1XRFKpHlprPwLWkWaGxD2HV4gI3cmUpiTZz+07pG6KOcVVy 8pRFMT2jtyM21kl/6Ew== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-12-02_02,2026-12-01_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 priorityscore=1501 adultscore=0 spamscore=0 bulkscore=0 phishscore=0 suspectscore=0 malwarescore=0 clxscore=1011 impostorscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2612020030 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. - The branches are translated on every boot, although everything needed to do it is known at link time. 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. 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. Patch overview: 1-3 Teach objtool about linked objects (sections with a non-zero address): make symbol and relocation offsets section relative, and keep the file layout when writing it back. 4-6 Add --alt-fixup, built on top of the existing alternatives handling, and describe the powerpc feature fixup tables to it. 7-8 Share the powerpc branch helpers between the kernel and objtool, and implement arch_support_alt_relocation() for powerpc. 9-11 Make __ftr_alt_* executable, always build objtool for powerpc, run it post-link, and stop translating branches at boot for the core kernel. This patchset applies atop upstream master branch. Testing: verfied build and boot on ppc64le, ppc64, ppc32be. [1] Original powerpc tool approach: http://patchwork.ozlabs.org/project/linuxppc-dev/patch/20170521010130.13552-1-npiggin@gmail.com/ --- ===== Changelog ====== Changes since v2: https://lore.kernel.org/all/20260929055138.43489-1-shivangu@linux.ibm.com/ - Reworked after Peter Zijlstra's review: objtool now understands linked objects (sections with a non-zero address) instead of special casing --ftr-fixup. Symbol and relocation offsets are made section relative (1-2/11), which replaces the find_insn() offset hack. - ELF_F_LAYOUT is now set for every non-ET_REL file instead of only with --ftr-fixup (3/11). - --ftr-fixup and its powerpc specific parsing are replaced by --alt-fixup, which reuses the generic alternatives code and arch_support_alt_relocation() (4-6/11, 8/11). The hacks that skipped add_jump_destinations() and silenced intra-function call warnings are gone, objtool just stops after processing the alternatives. - The powerpc branch helpers are shared between the kernel and objtool through code-patching-branch.c rather than duplicated (7/11). - Dropped HAVE_OBJTOOL_FTR_FIXUP and the top level kbuild changes; ARCH_VMLINUX_NEEDS_RELOCS and a vmlinux.unstripped rule in Makefile.postlink are used instead (10/11). The runtime branch translation is kept for modules and the VDSO (11/11). v1: https://lore.kernel.org/all/20260505084628.17940-1-sv@linux.ibm.com/ ======================= Shivang Upadhyay (11): objtool: Make symbol offsets section relative in linked objects objtool: Make relocation offsets section relative in linked objects objtool: Keep the layout of linked objects when writing them back objtool: Pass the objtool_file to arch_support_alt_relocation() objtool: Add --alt-fixup objtool: Describe special_entry parsing for --alt-fixup powerpc/lib: Extract branch patching helpers to code-patching-branch.c objtool/powerpc: Implement arch_support_alt_relocation() powerpc: Mark feature section alternatives as executable powerpc: Always build objtool for powerpc powerpc: Remove runtime checking of jumps in core kernel feature-fixup arch/powerpc/Kconfig | 1 + arch/powerpc/Makefile | 2 +- arch/powerpc/Makefile.postlink | 4 + arch/powerpc/include/asm/feature-fixups.h | 2 +- arch/powerpc/include/asm/text-patching.h | 3 + arch/powerpc/kernel/vmlinux.lds.S | 7 +- arch/powerpc/lib/code-patching-branch.c | 128 ++++++++++++++++++ arch/powerpc/lib/code-patching.c | 110 +-------------- arch/powerpc/lib/feature-fixups.c | 46 ++++--- tools/arch/powerpc/include/asm/inst.h | 41 ++++++ .../arch/powerpc/include/asm/text-patching.h | 67 +++++++++ tools/objtool/arch/loongarch/special.c | 3 +- tools/objtool/arch/powerpc/decode.c | 6 +- .../arch/powerpc/include/arch/special.h | 16 +++ tools/objtool/arch/powerpc/special.c | 42 +++++- tools/objtool/arch/x86/special.c | 3 +- tools/objtool/builtin-check.c | 4 +- tools/objtool/check.c | 7 +- tools/objtool/elf.c | 13 ++ tools/objtool/include/objtool/builtin.h | 1 + tools/objtool/include/objtool/elf.h | 14 +- tools/objtool/include/objtool/special.h | 3 +- tools/objtool/special.c | 80 ++++++++++- 23 files changed, 456 insertions(+), 147 deletions(-) create mode 100644 arch/powerpc/lib/code-patching-branch.c create mode 100644 tools/arch/powerpc/include/asm/inst.h create mode 100644 tools/arch/powerpc/include/asm/text-patching.h -- 2.56.1