From nobody Fri Dec 19 06:35:48 2025 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) (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 A3677204F7E for ; Tue, 3 Dec 2024 19:46:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=93.17.235.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733255207; cv=none; b=A1dLcH6a3vRp7ob3HQDlLSDatplEJv9noWCLm/Kz7AFOIwktn+vrkXwSF2S8mR4Oq37nlgvf7KPmKywGL709RL5ZMv+Y3C4Z76Uxb0B8Hos4FHeyey5BHeV0yxQAMnL2TfS+fRZp0kRrrZywPgJ550Ok8oUzwYYzPxV5ORAlrkI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733255207; c=relaxed/simple; bh=zg0V8okVh2HcUM+I7hCx9fsftgdLb74b1p7T4df88FM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VdJhI9DtWj8rqlnaMrfUgTN8kmiHjdzuuMhgNZVV5MHUStHyQslmz7imFZjEoVLzFmm1wsGf+9p+mUpkOyiA6vQ4c5bMs5IvfvkInkfPND4tjIHOEwYJpSZd/7a802SMK8ehopWrl4JvbfPGPAPbLq+VMvjMmSlMq2W/+nTgtwc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=csgroup.eu; spf=pass smtp.mailfrom=csgroup.eu; arc=none smtp.client-ip=93.17.235.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=csgroup.eu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=csgroup.eu Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4Y2rkY0ytrz9stJ; Tue, 3 Dec 2024 20:46:29 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from pegase2.c-s.fr ([172.26.127.65]) by localhost (pegase2.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id F1DaesogsHDn; Tue, 3 Dec 2024 20:46:29 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase2.c-s.fr (Postfix) with ESMTP id 4Y2rkW4TSmz9stD; Tue, 3 Dec 2024 20:46:27 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 85FDF8B763; Tue, 3 Dec 2024 20:46:27 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id xC4QlQoN6kLD; Tue, 3 Dec 2024 20:46:27 +0100 (CET) Received: from PO20335.idsi0.si.c-s.fr (unknown [192.168.232.97]) by messagerie.si.c-s.fr (Postfix) with ESMTP id B2B7B8B767; Tue, 3 Dec 2024 20:46:26 +0100 (CET) From: Christophe Leroy To: Shrikanth Hegde , Peter Zijlstra , Josh Poimboeuf , Jason Baron , Steven Rostedt , Ard Biesheuvel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Michael Ellerman , Nicholas Piggin , Naveen N Rao , Madhavan Srinivasan Cc: Christophe Leroy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v4 4/4] powerpc/static_call: Implement inline static calls Date: Tue, 3 Dec 2024 20:44:52 +0100 Message-ID: <3dbd0b2ba577c942729235d0211d04a406653d81.1733245362.git.christophe.leroy@csgroup.eu> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733255162; l=2956; i=christophe.leroy@csgroup.eu; s=20211009; h=from:subject:message-id; bh=zg0V8okVh2HcUM+I7hCx9fsftgdLb74b1p7T4df88FM=; b=jSBMxVv18VlXpPuDupbIyS5plVVdoSdXqAPZOJsldhnjbLavWN3Ndh72UGg82KviTra0e+M3P hCKRZRhv9Q4AQVQ/dJOxisbTfOoMv6GCOPbkcYtTdTMX/qsmDcSOEJ0 X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Implement inline static calls: - Put a 'bl' to the destination function ('b' if tail call) - Put a 'nop' when the destination function is NULL ('blr' if tail call) - Put a 'li r3,0' when the destination is the RET0 function and not a tail call. If the destination is too far (over the 32Mb limit), go via the trampoline. Signed-off-by: Christophe Leroy --- arch/powerpc/Kconfig | 1 + arch/powerpc/include/asm/static_call.h | 2 ++ arch/powerpc/kernel/static_call.c | 24 +++++++++++++++++++++++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig index a0ce777f9706..285bc1ae17dd 100644 --- a/arch/powerpc/Kconfig +++ b/arch/powerpc/Kconfig @@ -282,6 +282,7 @@ config PPC select HAVE_STACKPROTECTOR if PPC32 && $(cc-option,$(m32-flag) -mstack-p= rotector-guard=3Dtls -mstack-protector-guard-reg=3Dr2 -mstack-protector-gua= rd-offset=3D0) select HAVE_STACKPROTECTOR if PPC64 && $(cc-option,$(m64-flag) -mstack-p= rotector-guard=3Dtls -mstack-protector-guard-reg=3Dr13 -mstack-protector-gu= ard-offset=3D0) select HAVE_STATIC_CALL if PPC32 + select HAVE_STATIC_CALL_INLINE if PPC32 select HAVE_SYSCALL_TRACEPOINTS select HAVE_VIRT_CPU_ACCOUNTING select HAVE_VIRT_CPU_ACCOUNTING_GEN diff --git a/arch/powerpc/include/asm/static_call.h b/arch/powerpc/include/= asm/static_call.h index de1018cc522b..e3d5d3823dac 100644 --- a/arch/powerpc/include/asm/static_call.h +++ b/arch/powerpc/include/asm/static_call.h @@ -26,4 +26,6 @@ #define ARCH_DEFINE_STATIC_CALL_NULL_TRAMP(name) __PPC_SCT(name, "blr") #define ARCH_DEFINE_STATIC_CALL_RET0_TRAMP(name) __PPC_SCT(name, "b .+20") =20 +#define CALL_INSN_SIZE 4 + #endif /* _ASM_POWERPC_STATIC_CALL_H */ diff --git a/arch/powerpc/kernel/static_call.c b/arch/powerpc/kernel/static= _call.c index 1b106fbcc567..ec3101f95e53 100644 --- a/arch/powerpc/kernel/static_call.c +++ b/arch/powerpc/kernel/static_call.c @@ -15,7 +15,29 @@ void arch_static_call_transform(void *site, void *tramp,= void *func, bool tail) =20 mutex_lock(&text_mutex); =20 - if (tramp) { + if (site && tail) { + if (!func) + err =3D patch_instruction(site, ppc_inst(PPC_RAW_BLR())); + else if (is_ret0) + err =3D patch_branch(site, _ret0, 0); + else if (is_short) + err =3D patch_branch(site, _func, 0); + else if (tramp) + err =3D patch_branch(site, _tramp, 0); + else + err =3D 0; + } else if (site) { + if (!func) + err =3D patch_instruction(site, ppc_inst(PPC_RAW_NOP())); + else if (is_ret0) + err =3D patch_instruction(site, ppc_inst(PPC_RAW_LI(_R3, 0))); + else if (is_short) + err =3D patch_branch(site, _func, BRANCH_SET_LINK); + else if (tramp) + err =3D patch_branch(site, _tramp, BRANCH_SET_LINK); + else + err =3D 0; + } else if (tramp) { if (func && !is_short) { err =3D patch_ulong(tramp + PPC_SCT_DATA, _func); if (err) --=20 2.47.0