From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (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 0D211272E43 for ; Mon, 29 Sep 2025 08:05:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.156.1 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759133143; cv=none; b=u5L+01QvhTeyI7VcRBfpna2bFvEsbJm/wMo/lsw7GAwvBAlzex3ExZxKhBWcgFfZxofFU1G9O/GqkWHKa7nbP50B2Cc89VhqZc11e2963EqX7jZv4Tc++aO+5lHQhpnulDtiB3TbvgAXSGS3WfVdVReRL2mi7e1jWUcclMkTUjE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759133143; c=relaxed/simple; bh=KlVQLKa1V6X9bCF4DgysyiTgT3kBvwCl0Ym7pyNksFw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DUiECwgNXQKEbUSaVgkEiXHlM5HvFVJYcVm+aCJxFcZezrQuILzuvPZIj0OILUnaUiV/fLDxPBAebBldQttWNSFwCnpzYlDMwp751qg1qqXZ/kbuoZ10X4UCGWjbYyOxps85kVLTewiVXCbd4DOEUpFKnP1geINqrzDzhGEqceo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=Y/Atz2jg; arc=none smtp.client-ip=148.163.156.1 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.b="Y/Atz2jg" Received: from pps.filterd (m0356517.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 58SJw2Jt026144; Mon, 29 Sep 2025 08:05:23 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=kpj2wI8T/OaE9GeJo z696ii6ZcwFQmeiphgGBkLYvPM=; b=Y/Atz2jg8IEytqHC8SN/TfM23faMBtcpE 9P45aTP+swXbUBYV1HfMv3kz8QzOYZO4ylbqgZuN/t2E8j0uUeinpl8KbiVcF+Jg JHPpSG5k+6zXM42ZpujSysIybf9nloCH3ab6m4RLEBxHviRoO6zMziGxioH12kWC 4avcUp0Cvopk9p7bbJwIWiIilE7j6ciXCLdFt+eRBiARWZVZ+v5AQoVP29u29uRc YyGWfhS1F3ekNhq+SfkwKRdQVWOSX5d1ISDT9LvbinB8rjXGBT6oTABI8L3W3EvR UNCExumqRsxbuauRLh31odJRiFrmUa0DMF+rvHJ7AVWAk5lKaHrmQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 49e7n7gyf8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 29 Sep 2025 08:05:23 +0000 (GMT) Received: from m0356517.ppops.net (m0356517.ppops.net [127.0.0.1]) by pps.reinject (8.18.1.12/8.18.0.8) with ESMTP id 58T83E85020078; Mon, 29 Sep 2025 08:05:22 GMT 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 49e7n7gyf0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 29 Sep 2025 08:05:22 +0000 (GMT) Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 58T3UNOO003369; Mon, 29 Sep 2025 08:05:21 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 49etmxn7nn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 29 Sep 2025 08:05:21 +0000 Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 58T85Hdw46268756 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Sep 2025 08:05:17 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7BE162005A; Mon, 29 Sep 2025 08:05:17 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2E72A2004F; Mon, 29 Sep 2025 08:05:14 +0000 (GMT) Received: from li-2fa77bcc-2701-11b2-a85c-cd621c23b6bd.ibm.com (unknown [9.39.16.189]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 29 Sep 2025 08:05:13 +0000 (GMT) From: Sathvika Vasireddy To: linux-kbuild@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Cc: nathan@kernel.org, masahiroy@kernel.org, kees@kernel.org, naveen@kernel.org, jpoimboe@kernel.org, peterz@infradead.org, npiggin@gmail.com, maddy@linux.ibm.com, segher@kernel.crashing.org, christophe.leroy@csgroup.eu, mingo@kernel.org, mpe@ellerman.id.au, mahesh@linux.ibm.com, sv@linux.ibm.com Subject: [RFC PATCH v2 3/3] powerpc: Enable build-time feature fixup processing by default Date: Mon, 29 Sep 2025 13:34:56 +0530 Message-ID: <20250929080456.26538-4-sv@linux.ibm.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250929080456.26538-1-sv@linux.ibm.com> References: <20250929080456.26538-1-sv@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 01T8Ybk8Z7DuJ3RMfQKuFJk49i_0r1jS X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwOTI3MDAyNSBTYWx0ZWRfX9zNQ5BqVyPo5 iVsj5Nm2LYLYEIDqqVhn+0NJPORDETouaGD3YzENvbIdnsF826c080w99xQjfPIpMZyuAhNefA/ 2FUYuBpbcUrjekUjvAlP5Kg9lXfYAJ0JD9GfdSX2/ykYEjzzijDJh8mC2wWX7YNZYdQk+1rAJfx GMktyg/kjxdnGuKiS9bJCwa4/O6MFL+DqU0YrsjRA85B3fGEo+AVUU8dSSIWaQXEcqdUXN7aQbh JJ1943un2w3uqdtWpTWE1277otTEZx5WIGD/QYAqVf42sDiVk5SR7S5BHJhkSNJJ1kj4uvWuXns Vlfh8Z81ZZO4vzHNQojAdddCR6ZSBctDFooOZ0kQfdX0X1pyjcTtP+Hvr9xSoZxlKDv9Ys9lFp9 4t6xwrpn5yeiU2irhypCtOmNEq7qlg== X-Proofpoint-GUID: ZTpU8exGN9KxnKjGL5l0Xv4oikXtgHED X-Authority-Analysis: v=2.4 cv=T7qBjvKQ c=1 sm=1 tr=0 ts=68da3dc3 cx=c_pps a=5BHTudwdYE3Te8bg5FgnPg==:117 a=5BHTudwdYE3Te8bg5FgnPg==:17 a=yJojWOMRYYMA:10 a=pGLkceISAAAA:8 a=VnNF1IyMAAAA:8 a=bHuNbHJxFghEMexBxHIA:9 a=cPQSjfK2_nFv0Q5t_7PE:22 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1117,Hydra:6.1.9,FMLib:17.12.80.40 definitions=2025-09-29_02,2025-09-29_01,2025-03-28_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 impostorscore=0 lowpriorityscore=0 malwarescore=0 spamscore=0 clxscore=1011 suspectscore=0 bulkscore=0 phishscore=0 priorityscore=1501 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2509150000 definitions=main-2509270025 Enable HAVE_OBJTOOL_FTR_FIXUP by default on PowerPC architecture. - Remove runtime branch translation logic from patch_alt_instruction() - Add --emit-relocs linker flags for post-link fixup processing - Update ftr_alt section attributes to include executable flag Co-developed-by: Nicholas Piggin Signed-off-by: Nicholas Piggin Signed-off-by: Sathvika Vasireddy --- arch/powerpc/Kconfig | 3 +++ arch/powerpc/Makefile | 5 +++++ arch/powerpc/include/asm/feature-fixups.h | 2 +- arch/powerpc/kernel/vmlinux.lds.S | 8 ++++++-- arch/powerpc/lib/feature-fixups.c | 12 ------------ 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig index 325c1171894d..450b5822786d 100644 --- a/arch/powerpc/Kconfig +++ b/arch/powerpc/Kconfig @@ -23,6 +23,9 @@ config 64BIT bool default y if PPC64 +config HAVE_OBJTOOL_FTR_FIXUP + def_bool y + config LIVEPATCH_64 def_bool PPC64 depends on LIVEPATCH diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile index a58b1029592c..8e1dab5f3c9a 100644 --- a/arch/powerpc/Makefile +++ b/arch/powerpc/Makefile @@ -105,6 +105,11 @@ LDFLAGS_vmlinux-$(CONFIG_RELOCATABLE) := -pie --no-dynamic-linker LDFLAGS_vmlinux-$(CONFIG_RELOCATABLE) += -z notext LDFLAGS_vmlinux := $(LDFLAGS_vmlinux-y) +# --emit-relocs required for post-link fixup of alternate feature +# text section relocations. +LDFLAGS_vmlinux += --emit-relocs +KBUILD_LDFLAGS_MODULE += --emit-relocs + ifdef CONFIG_PPC64 ifndef CONFIG_PPC_KERNEL_PCREL # -mcmodel=medium breaks modules because it uses 32bit offsets from diff --git a/arch/powerpc/include/asm/feature-fixups.h b/arch/powerpc/include/asm/feature-fixups.h index 756a6c694018..d6ae92a292ec 100644 --- a/arch/powerpc/include/asm/feature-fixups.h +++ b/arch/powerpc/include/asm/feature-fixups.h @@ -32,7 +32,7 @@ #define FTR_SECTION_ELSE_NESTED(label) \ label##2: \ - .pushsection __ftr_alt_##label,"a"; \ + .pushsection __ftr_alt_##label, "ax"; \ .align 2; \ label##3: diff --git a/arch/powerpc/kernel/vmlinux.lds.S b/arch/powerpc/kernel/vmlinux.lds.S index de6ee7d35cff..961ef49f8bd3 100644 --- a/arch/powerpc/kernel/vmlinux.lds.S +++ b/arch/powerpc/kernel/vmlinux.lds.S @@ -99,8 +99,8 @@ SECTIONS .text : AT(ADDR(.text) - LOAD_OFFSET) { ALIGN_FUNCTION(); #endif - /* careful! __ftr_alt_* sections need to be close to .text */ - *(.text.hot .text.hot.* TEXT_MAIN .text.fixup .text.unlikely .text.unlikely.* .fixup __ftr_alt_* .ref.text); + *(.text.hot .text.hot.* TEXT_MAIN .text.fixup .text.unlikely + .text.unlikely.* .fixup .ref.text); *(.tramp.ftrace.text); NOINSTR_TEXT SCHED_TEXT @@ -267,6 +267,10 @@ SECTIONS _einittext = .; } :text + .__ftr_alternates.text : AT(ADDR(.__ftr_alternates.text) - LOAD_OFFSET) { + *(__ftr_alt*); + } + /* .exit.text is discarded at runtime, not link time, * to deal with references from __bug_table */ diff --git a/arch/powerpc/lib/feature-fixups.c b/arch/powerpc/lib/feature-fixups.c index 587c8cf1230f..269e992b1631 100644 --- a/arch/powerpc/lib/feature-fixups.c +++ b/arch/powerpc/lib/feature-fixups.c @@ -53,22 +53,10 @@ static u32 *calc_addr(struct fixup_entry *fcur, long offset) static int patch_alt_instruction(u32 *src, u32 *dest, u32 *alt_start, u32 *alt_end) { - int err; ppc_inst_t instr; instr = ppc_inst_read(src); - if (instr_is_relative_branch(ppc_inst_read(src))) { - u32 *target = (u32 *)branch_target(src); - - /* Branch within the section doesn't need translating */ - if (target < alt_start || target > alt_end) { - err = translate_branch(&instr, dest, src); - if (err) - return 1; - } - } - raw_patch_instruction(dest, instr); return 0; -- 2.43.0