From nobody Fri Dec 19 04:49:44 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 C519A204F77 for ; Tue, 3 Dec 2024 19:46:30 +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=1733255192; cv=none; b=bczSWoXQb8MGTvIw52w5ottzioB0qtND28cvpS/blAmVrfX6MqOfv7pSUw3XMUiSDLae3rdf8Wz9WMi2f/nXEbdXXi5vJr0ZDgl0NZENLIGE5334odY6QxexziUC7LCPr4OEJvwV/5Bt53fQ679IT6vO9p7/vmNVSjmzagckyEU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733255192; c=relaxed/simple; bh=ayjJhvEnqmcVSyaBeb998Pk3PUd3CnrM4zKpciianxY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Z7+lKrnnoNzv/e8bRYrQS/hIhEN1xfnCfSVpGs2hQdbxO9OBpSvZ5/6nGGNvflbHaoQ//MqEuvzI0jaw6SQ3xNC1x9y3kDlLlJSiDH+WIB8rwtVxMk9pc2C05UlBA2sJUEt03s14fZoclN/HK0O1tCCZRn0TObLl1tRqvu27wQ4= 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 4Y2rkT2frSz9stG; Tue, 3 Dec 2024 20:46:25 +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 UCG2vu4-nnmU; Tue, 3 Dec 2024 20:46:25 +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 4Y2rkT1jk9z9stD; Tue, 3 Dec 2024 20:46:25 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 212AB8B763; Tue, 3 Dec 2024 20:46:25 +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 7pxtHpRMStCP; Tue, 3 Dec 2024 20:46:25 +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 50EC78B76C; Tue, 3 Dec 2024 20:46:24 +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 1/4] static_call_inline: Provide trampoline address when updating sites Date: Tue, 3 Dec 2024 20:44:49 +0100 Message-ID: <5efe0cffc38d6f69b1ec13988a99f1acff551abf.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=1424; i=christophe.leroy@csgroup.eu; s=20211009; h=from:subject:message-id; bh=ayjJhvEnqmcVSyaBeb998Pk3PUd3CnrM4zKpciianxY=; b=02Xc17llbaI9+HAI9fOhqoUpXP83GAbmDUMspEMI0XYRDQgjtkrcMaERuxOP1mNS67iZtKewZ UgUC4pDJ0qpDkFH9z99XF7s8DNM0Zhc9ouFoi9BG6F7WIgo+TnQk8yj 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" In preparation of support of inline static calls on powerpc, provide trampoline address when updating sites, so that when the destination function is too far for a direct function call, the call site is patched with a call to the trampoline. Signed-off-by: Christophe Leroy --- arch/x86/kernel/static_call.c | 2 +- kernel/static_call_inline.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/static_call.c b/arch/x86/kernel/static_call.c index 4eefaac64c6c..00b2ea40cbef 100644 --- a/arch/x86/kernel/static_call.c +++ b/arch/x86/kernel/static_call.c @@ -158,7 +158,7 @@ void arch_static_call_transform(void *site, void *tramp= , void *func, bool tail) { mutex_lock(&text_mutex); =20 - if (tramp) { + if (tramp && !site) { __static_call_validate(tramp, true, true); __static_call_transform(tramp, __sc_insn(!func, true), func, false); } diff --git a/kernel/static_call_inline.c b/kernel/static_call_inline.c index 5259cda486d0..7fefbb3d8074 100644 --- a/kernel/static_call_inline.c +++ b/kernel/static_call_inline.c @@ -206,7 +206,7 @@ void __static_call_update(struct static_call_key *key, = void *tramp, void *func) continue; } =20 - arch_static_call_transform(site_addr, NULL, func, + arch_static_call_transform(site_addr, tramp, func, static_call_is_tail(site)); } } --=20 2.47.0 From nobody Fri Dec 19 04:49:44 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 E73F91FF60C for ; Tue, 3 Dec 2024 19:46:34 +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=1733255197; cv=none; b=hR9gMbYGAkweTKvsEkIgKLh+q98h5SHlhBXx9dpvKWu6ZF2E+yiO2KzenMeHJbnTZb5OlJpaHG+6Oot04azGPRHyA++IRl2LH3V3nEsYj097wuZxjwnU9OV+v12DZWCfmdhp8LSWuAVgODaUGzV0+fuzkm7P6uulayFS5lSIG64= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733255197; c=relaxed/simple; bh=rkc6rbl9zc2WEtrRWE9QRdGj1KrdadCRvxADO58Yds0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OlmslLzQrJHXDenQmM22pNz5Jph/6Y4HplU6P518RGXdSiGiWEMmwHlSf0Dx8Ez+E6FWS1nyypC0nHh2wYUKDBdIDZN3MqzrNYVjscxDG96iDY68iEYDHG3EHzSD84vMBeoSOR6j9KKJ1Q0duqkFZ87oCxAawldfhXKlWS5KZyA= 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 4Y2rkV1Dg1z9stH; Tue, 3 Dec 2024 20:46:26 +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 aV_W0aAXLTr7; Tue, 3 Dec 2024 20:46:26 +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 4Y2rkV0Sl9z9stD; Tue, 3 Dec 2024 20:46:26 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id E2E0B8B763; Tue, 3 Dec 2024 20:46:25 +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 SLEBpkwrXIB1; Tue, 3 Dec 2024 20:46:25 +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 243048B767; Tue, 3 Dec 2024 20:46:25 +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 2/4] objtool/powerpc: Add support for decoding all types of uncond branches Date: Tue, 3 Dec 2024 20:44:50 +0100 Message-ID: <0ca71a4b0ac679ea52bd9fdd1f607195d72b499f.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=1411; i=christophe.leroy@csgroup.eu; s=20211009; h=from:subject:message-id; bh=rkc6rbl9zc2WEtrRWE9QRdGj1KrdadCRvxADO58Yds0=; b=MUTxe8REiHlw+JI/+u8V3K4lDnK/5EtJEVeqBc6ax4BfVURzLhLCDA5tDY/ZXNLL09g8PwuEo 4I2ho4Wdd6PCfriQVC/4QrKAKoaSfaqZq4Pz3Z0LEHDb7gyYbbbNSI5 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" Add support for 'bla' instruction. This is done by 'flagging' the address as an absolute address so that arch_jump_destination() can calculate it as expected. Because code is _always_ 4 bytes aligned, use bit 30 as flag. Also add support for 'b' and 'ba' instructions. Objtool call them jumps. Signed-off-by: Christophe Leroy Reviewed-by: Segher Boessenkool --- tools/objtool/arch/powerpc/decode.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tools/objtool/arch/powerpc/decode.c b/tools/objtool/arch/power= pc/decode.c index 53b55690f320..c1228fef3dec 100644 --- a/tools/objtool/arch/powerpc/decode.c +++ b/tools/objtool/arch/powerpc/decode.c @@ -55,12 +55,15 @@ int arch_decode_instruction(struct objtool_file *file, = const struct section *sec =20 switch (opcode) { case 18: /* b[l][a] */ - if ((ins & 3) =3D=3D 1) /* bl */ + if (ins & 1) /* bl[a] */ typ =3D INSN_CALL; + else /* b[a] */ + typ =3D INSN_JUMP_UNCONDITIONAL; =20 imm =3D ins & 0x3fffffc; if (imm & 0x2000000) imm -=3D 0x4000000; + imm |=3D ins & 2; /* AA flag */ break; } =20 @@ -77,6 +80,9 @@ int arch_decode_instruction(struct objtool_file *file, co= nst struct section *sec =20 unsigned long arch_jump_destination(struct instruction *insn) { + if (insn->immediate & 2) + return insn->immediate & ~2; + return insn->offset + insn->immediate; } =20 --=20 2.47.0 From nobody Fri Dec 19 04:49:44 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 0C2F31FF7C3 for ; Tue, 3 Dec 2024 19:46:40 +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=1733255201; cv=none; b=fDuQM022dpyeVsxNMKwyd3S4ebKVFndZkaYNJXt7kJXIB5G6S7mzUaKG1lkpxwTXBh77HFgtva4vYEOaPS2NKhpdnJCI9z1q0/m3D9kfNtKleYak5BXn0MzPawn7dctU3Tu6pEFrGkosMqGJRGc5ADNfoJUjC+FfUEFzCFgjP40= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733255201; c=relaxed/simple; bh=w7NfWT76IPUH9paNfP5yUZDDBPDoYj5iPurgT8mFaks=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cxEZ6Kf8I7WnUlxjVha9dYEegonsRo6jUO4WO9Loack67Dze9pUq/SwFBjSNzVz/9yk4X46TfyCd/yab1pQqbgWSUpUTbw8q1ELA8ro87/l9W5uy1n89gWSpEtrYrsCUoQhj4xEIrES9lFqHmN+PMoetF96sy4/WPCmtcdjR7YQ= 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 4Y2rkX2QyNz9stL; Tue, 3 Dec 2024 20:46:28 +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 dwoS2xF3MyfF; Tue, 3 Dec 2024 20:46:28 +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 4Y2rkV5pZyz9stJ; Tue, 3 Dec 2024 20:46:26 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id B26FB8B763; Tue, 3 Dec 2024 20:46:26 +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 Rf4C0-DpdxVp; Tue, 3 Dec 2024 20:46:26 +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 E48148B76C; Tue, 3 Dec 2024 20:46:25 +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 3/4] powerpc: Prepare arch_static_call_transform() for supporting inline static calls Date: Tue, 3 Dec 2024 20:44:51 +0100 Message-ID: <7a8b9245e773307c315c2548a4c6cad570ac2648.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=2238; i=christophe.leroy@csgroup.eu; s=20211009; h=from:subject:message-id; bh=w7NfWT76IPUH9paNfP5yUZDDBPDoYj5iPurgT8mFaks=; b=UOFid3geEIRWDqJio8hU372DJOg+8AyEgiUGBUMnBXwKYm/SVRPlnDeDmt1++gQNbOeuTqlfr sf+HWoDWPi6ADxLk81h3DPc5/BrTjlhwlf1wNxG/vL53eylhLICuWGI 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" Reorganise arch_static_call_transform() in order to ease the support of inline static calls in following patch: - remove 'target' to nhide whether it is a 'return 0' or not. - Don't bail out if 'tramp' is NULL, just do nothing until next patch. Note that 'target' was 'tramp + PPC_SCT_RET0', is_short was perforce true. So in the 'if (func && !is_short)' leg, target was perforce equal to 'func'. Signed-off-by: Christophe Leroy --- arch/powerpc/kernel/static_call.c | 36 ++++++++++++++++++------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/arch/powerpc/kernel/static_call.c b/arch/powerpc/kernel/static= _call.c index 7cfd0710e757..1b106fbcc567 100644 --- a/arch/powerpc/kernel/static_call.c +++ b/arch/powerpc/kernel/static_call.c @@ -8,26 +8,32 @@ void arch_static_call_transform(void *site, void *tramp, = void *func, bool tail) { int err; bool is_ret0 =3D (func =3D=3D __static_call_return0); - unsigned long target =3D (unsigned long)(is_ret0 ? tramp + PPC_SCT_RET0 := func); - bool is_short =3D is_offset_in_branch_range((long)target - (long)tramp); - - if (!tramp) - return; + unsigned long _tramp =3D (unsigned long)tramp; + unsigned long _func =3D (unsigned long)func; + unsigned long _ret0 =3D _tramp + PPC_SCT_RET0; + bool is_short =3D is_offset_in_branch_range((long)func - (long)(site ? : = tramp)); =20 mutex_lock(&text_mutex); =20 - if (func && !is_short) { - err =3D patch_ulong(tramp + PPC_SCT_DATA, target); - if (err) - goto out; + if (tramp) { + if (func && !is_short) { + err =3D patch_ulong(tramp + PPC_SCT_DATA, _func); + if (err) + goto out; + } + + if (!func) + err =3D patch_instruction(tramp, ppc_inst(PPC_RAW_BLR())); + else if (is_ret0) + err =3D patch_branch(tramp, _ret0, 0); + else if (is_short) + err =3D patch_branch(tramp, _func, 0); + else + err =3D patch_instruction(tramp, ppc_inst(PPC_RAW_NOP())); + } else { + err =3D 0; } =20 - if (!func) - err =3D patch_instruction(tramp, ppc_inst(PPC_RAW_BLR())); - else if (is_short) - err =3D patch_branch(tramp, target, 0); - else - err =3D patch_instruction(tramp, ppc_inst(PPC_RAW_NOP())); out: mutex_unlock(&text_mutex); =20 --=20 2.47.0 From nobody Fri Dec 19 04:49:44 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