From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=148.163.158.5 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796197394; b=Y4schteLDufqEQYzRzK9iak94L/ItjohqU5FoXJIyKvfrVe98ksPaXvc/XgDRTXJk/AA qZJBHjviR4V9uGiOsAk/GnkD3ZdtsygNiR+7GBwzPbifRMsViCjr4DlX5WH9r3/AncKHb Fx+nHBIfWdLrg2JwXJ680i7g53d7c5GYGIXzokZ9QxUeVU9kubW6rgcDZeaA8MkRktqjg QyzmsWb3bTWwwOagHNqri9JweBnkoBBwSz/Qi8RRkJPI+AFOK2xqfEifbjZVbVeSLrzvK FSfNXgqBsJfJsL1HVE/ZLSh4c4hIm+wN8/VH1O9Aw9rDsKoMjzdev7R1liNC/fpG3LQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796197394; h=DMARC-Filter:Received:DKIM-Signature:Received:Received:Received: Received:Received:Received:Received:From:To:Cc:Subject:Date: Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-TM-AS-GCONF:X-Proofpoint-Reinject: X-Proofpoint-Spam-Details-Enc:X-Authority-Analysis: X-Proofpoint-ORIG-GUID:X-Proofpoint-GUID:X-Proofpoint-Spam-Info: X-Proofpoint-Virus-Version:X-Proofpoint-Spam-Details; bh=aY2XxzsxJbJ3G1/bnyW/bGll6v4LXj7Tx/UI4PqDPTU=; b=h+b3ZAis0Wwsiihaxvkw0nSfTk1sKd/fcoFeWpo0Jnbc/hRpmIuKBem7pdbut8QPbFIg 6kbBv3LgYM1WA/KnkKisxUrDNseN45WvekENs2BFfTBymVXCywHVf1poGJ6i+pDhhi+wW mrBg5a4K1bA8NW4umhKiS5zg9MCC/6gmDiB/DuKNLRyRrkcrQML41n+0y82MPKyLeLMG2 XcD3fDiBuICxjyPw8DtOn+mnfWOhpsV5O543AwlLdkUH5IMP0Hz7oNxDZhZE2EH5QQHYu CEXsJYLKSU5yMmScDbJI49kmDVP2PFdh9cTTlK3GhKr7E7rxPWk6+RMRVNJNLA4DJgA== 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=KeQvbe71; arc=none smtp.remote-ip=148.163.158.5 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (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 3D74C606A323 for ; Wed, 2 Dec 2026 07:43:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3D74C606A323 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=KeQvbe71 Received: from pps.filterd (m0353725.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6B274dLr2760097; Wed, 2 Dec 2026 07:42:49 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=aY2XxzsxJbJ3G1/bn yW/bGll6v4LXj7Tx/UI4PqDPTU=; b=KeQvbe71A642jqEGSCArTebxS6Ib4fD9Y mnm3iMzhXoWw75gnLVjijNv4iXUedOWVPsmi3rmUh8Kg10F3h7MvBYHYds5V+SBe JVGLyVXBSi4/GrXNNlkJxNVAfSuf/txq7d5KnTwtyjrlqXIJdyQlfAeVfzCiaZQ6 uYhn2AmUux9dOLsgRQiL+HyJxRjs/C5BARdu7GTOepkvp24sJsokKw5J+s/8bieZ +IiCqkNOQQx3RDcJMSgvGAN0c9LryS1NdY77LdUjE2IFZQrXCTmkbqPtYhYqoXRD PXvKXAcobWRPeqiuJirzl7yICXD4xOKmGhE32YraDQYEXkcu8kb1A== Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4j7nchrhg1-1 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 02 Dec 2026 07:42:49 +0000 (GMT) Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.18.1.11/8.18.1.11) with ESMTP id 6B26nFkg2046194; Wed, 2 Dec 2026 07:42:48 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4jaajs8tvw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 02 Dec 2026 07:42:48 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 6B27ggfn24511100 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 2 Dec 2026 07:42:42 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 913A62004B; Wed, 2 Dec 2026 07:42:42 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 68D6120043; Wed, 2 Dec 2026 07:42:35 +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:42:35 +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 11/11] powerpc: Remove runtime checking of jumps in core kernel feature-fixup Date: Wed, 2 Dec 2026 13:10:58 +0530 Message-ID: <20261202074059.899491-12-shivangu@linux.ibm.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261202074059.899491-1-shivangu@linux.ibm.com> References: <20261202074059.899491-1-shivangu@linux.ibm.com> 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-Details-Enc: AW1haW4tMjYxMjAyMDAzMCBTYWx0ZWRfX1G1tG77Kt+yq Knh2rwX/lc7sMVDdPIfgKTTDiEG1uyMf/5nL70krELbw6IRKuYoFwp0ubeyA3Qpb7a08lR6Z25t daTtcvP3gUu6m/3OP4jFg+YdQFwgU+xg6nIlw/OJOSdZ8J0ERjv6HLImdKHgBjg0J99omrHRy3y vb22Pr8SEwGG0IQ+1P+RdyNx8jH2D8iWYMwNIw9er9TOti9qoAM55ofxFlvWNuI5lvo4EYnGavy VCXqIgdYEhHu0uXsnZzvn/lMeTwGfzI6vdgammKy9DmOc95gHJ8crgBKg0NIPk/wso/CAjTOaA8 v8xRhA7w2bhh2JMfC15zSaug2FI1s71QSWvKnSLx4h4lm7x+/F3W/gEz8SxeySkBm/wcTwMLw2s LdcgZgLGCblhl+c9ajeOUDSRDLaUXHg6qj4+wq4vPhrGjeHug0PMutj1tmZT/VpEJhMaYPbe9v+ GRAMUwrWI5CRiWmwatQ== X-Authority-Analysis: v=2.4 cv=Tt5zFzXh c=1 sm=1 tr=0 ts=6b0fcbf9 cx=c_pps a=5BHTudwdYE3Te8bg5FgnPg==:117 a=5BHTudwdYE3Te8bg5FgnPg==:17 a=pUM-KoujPXoA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=V8glGbnc2Ofi9Qvn3v5h:22 a=pGLkceISAAAA:8 a=VnNF1IyMAAAA:8 a=UMA_C90I3ARIe2MMYcgA:9 X-Proofpoint-ORIG-GUID: MoJiX8yNSN_2H1gLgzuETVUAFjCx720I X-Proofpoint-GUID: eltUXlAGjh_1IyTIi76mTUutZDWJc2N- X-Proofpoint-Spam-Info: AW1haW4tMjYxMjAyMDAzMCBTYWx0ZWRfX7jPfvhZaZbM1 EYGfngs5j8vA8MqO2gX+44AcXJcOMTTfugZr2bVjDqGXnBxH9ff8gVfWkXeeXnriH5mcLTqjPJF yAnG+4ShHwDK3HM1j1qtcZ8h6CkYscc= 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 priorityscore=1501 suspectscore=0 spamscore=0 bulkscore=0 clxscore=1015 adultscore=0 malwarescore=0 impostorscore=0 lowpriorityscore=0 phishscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2612020030 Relative branches in the core kernel's alternative code are now fixed up at build time by objtool (--alt-fixup), so skip the runtime translation for them. objtool does not process the VDSO or modules, so keep translating branches for those. Add a 'translate' argument to the patching path: do_feature_fixups() (used by modules and the VDSO) and the selftests pass true, while the core kernel fixups pass false. Now the fixup of alterate section is handled at boot time, We can remove the runtime checking of jumps. Co-developed-by: Nicholas Piggin Signed-off-by: Nicholas Piggin Co-developed-by: Sathvika Vasireddy Signed-off-by: Sathvika Vasireddy Signed-off-by: Shivang Upadhyay --- arch/powerpc/lib/feature-fixups.c | 46 +++++++++++++++++++------------ 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/arch/powerpc/lib/feature-fixups.c b/arch/powerpc/lib/feature-fixups.c index 587c8cf1230f..f127f45d9331 100644 --- a/arch/powerpc/lib/feature-fixups.c +++ b/arch/powerpc/lib/feature-fixups.c @@ -51,14 +51,22 @@ static u32 *calc_addr(struct fixup_entry *fcur, long offset) return (u32 *)((unsigned long)fcur + offset); } -static int patch_alt_instruction(u32 *src, u32 *dest, u32 *alt_start, u32 *alt_end) +/* + * Relative branches in the alternative code of the core kernel have been + * fixed up for where they get copied to at build time, by objtool + * (--alt-fixup), so @translate is false for the core kernel. The VDSO and + * modules are not processed by objtool, so their relative branches still + * need to be translated at patch time. + */ +static int patch_alt_instruction(u32 *src, u32 *dest, u32 *alt_start, + u32 *alt_end, bool translate) { int err; ppc_inst_t instr; instr = ppc_inst_read(src); - if (instr_is_relative_branch(ppc_inst_read(src))) { + if (translate && instr_is_relative_branch(ppc_inst_read(src))) { u32 *target = (u32 *)branch_target(src); /* Branch within the section doesn't need translating */ @@ -75,7 +83,7 @@ static int patch_alt_instruction(u32 *src, u32 *dest, u32 *alt_start, u32 *alt_e } static int patch_feature_section_mask(unsigned long value, unsigned long mask, - struct fixup_entry *fcur) + struct fixup_entry *fcur, bool translate) { u32 *start, *end, *alt_start, *alt_end, *src, *dest; @@ -95,7 +103,8 @@ static int patch_feature_section_mask(unsigned long value, unsigned long mask, for (; src < alt_end; src = ppc_inst_next(src, src), dest = ppc_inst_next(dest, dest)) { - if (patch_alt_instruction(src, dest, alt_start, alt_end)) + if (patch_alt_instruction(src, dest, alt_start, alt_end, + translate)) return 1; } @@ -106,7 +115,8 @@ static int patch_feature_section_mask(unsigned long value, unsigned long mask, } static void do_feature_fixups_mask(unsigned long value, unsigned long mask, - void *fixup_start, void *fixup_end) + void *fixup_start, void *fixup_end, + bool translate) { struct fixup_entry *fcur, *fend; @@ -114,7 +124,7 @@ static void do_feature_fixups_mask(unsigned long value, unsigned long mask, fend = fixup_end; for (; fcur < fend; fcur++) { - if (patch_feature_section_mask(value, mask, fcur)) { + if (patch_feature_section_mask(value, mask, fcur, translate)) { WARN_ON(1); printk("Unable to patch feature section at %p - %p" \ " with %p - %p\n", @@ -126,9 +136,10 @@ static void do_feature_fixups_mask(unsigned long value, unsigned long mask, } } +/* Used for modules and the VDSO, whose branches must be translated. */ void do_feature_fixups(unsigned long value, void *fixup_start, void *fixup_end) { - do_feature_fixups_mask(value, ~0, fixup_start, fixup_end); + do_feature_fixups_mask(value, ~0, fixup_start, fixup_end, true); } #ifdef CONFIG_PPC_BARRIER_NOSPEC @@ -645,13 +656,13 @@ void __init apply_feature_fixups(void) * Apply the CPU-specific and firmware specific fixups to kernel text * (nop out sections not relevant to this CPU or this firmware). */ - do_feature_fixups(spec->cpu_features, - PTRRELOC(&__start___ftr_fixup), - PTRRELOC(&__stop___ftr_fixup)); + do_feature_fixups_mask(spec->cpu_features, ~0, + PTRRELOC(&__start___ftr_fixup), + PTRRELOC(&__stop___ftr_fixup), false); - do_feature_fixups(spec->mmu_features, - PTRRELOC(&__start___mmu_ftr_fixup), - PTRRELOC(&__stop___mmu_ftr_fixup)); + do_feature_fixups_mask(spec->mmu_features, ~0, + PTRRELOC(&__start___mmu_ftr_fixup), + PTRRELOC(&__stop___mmu_ftr_fixup), false); do_lwsync_fixups(spec->cpu_features, PTRRELOC(&__start___lwsync_fixup), @@ -659,8 +670,9 @@ void __init apply_feature_fixups(void) #ifdef CONFIG_PPC64 saved_firmware_features = powerpc_firmware_features; - do_feature_fixups(powerpc_firmware_features, - &__start___fw_ftr_fixup, &__stop___fw_ftr_fixup); + do_feature_fixups_mask(powerpc_firmware_features, ~0, + &__start___fw_ftr_fixup, &__stop___fw_ftr_fixup, + false); #endif do_final_fixups(); } @@ -672,7 +684,7 @@ void __init update_mmu_feature_fixups(unsigned long mask) do_feature_fixups_mask(cur_cpu_spec->mmu_features, mask, PTRRELOC(&__start___mmu_ftr_fixup), - PTRRELOC(&__stop___mmu_ftr_fixup)); + PTRRELOC(&__stop___mmu_ftr_fixup), false); mmu_feature_keys_init(); } @@ -711,7 +723,7 @@ late_initcall(check_features); static int patch_feature_section(unsigned long value, struct fixup_entry *fcur) { - return patch_feature_section_mask(value, ~0, fcur); + return patch_feature_section_mask(value, ~0, fcur, true); } /* This must be after the text it fixes up, vmlinux.lds.S enforces that atm */ -- 2.56.1