From nobody Sat Jun 20 01:51:50 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BD621C433EF for ; Thu, 24 Mar 2022 14:32:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351148AbiCXOeI (ORCPT ); Thu, 24 Mar 2022 10:34:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351060AbiCXOdJ (ORCPT ); Thu, 24 Mar 2022 10:33:09 -0400 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8A61AC928 for ; Thu, 24 Mar 2022 07:31:22 -0700 (PDT) Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4KPSM72Rvlz9sTm; Thu, 24 Mar 2022 15:30:59 +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 3y8FJrRGWf4I; Thu, 24 Mar 2022 15:30:59 +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 4KPSLy6CFZz9sTn; Thu, 24 Mar 2022 15:30:50 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id BF9DA8B780; Thu, 24 Mar 2022 15:30:50 +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 mDVJ1tvagV3h; Thu, 24 Mar 2022 15:30:50 +0100 (CET) Received: from PO20335.IDSI0.si.c-s.fr (unknown [192.168.203.77]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 9C56E8B786; Thu, 24 Mar 2022 15:30:49 +0100 (CET) Received: from PO20335.IDSI0.si.c-s.fr (localhost [127.0.0.1]) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.16.1) with ESMTPS id 22OEUfho1811682 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 24 Mar 2022 15:30:41 +0100 Received: (from chleroy@localhost) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.17.1/Submit) id 22OEUfZo1811681; Thu, 24 Mar 2022 15:30:41 +0100 X-Authentication-Warning: PO20335.IDSI0.si.c-s.fr: chleroy set sender to christophe.leroy@csgroup.eu using -f From: Christophe Leroy To: "Naveen N . Rao" , Steven Rostedt , Ingo Molnar , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman Cc: Christophe Leroy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v1 01/22] powerpc/ftrace: Refactor prepare_ftrace_return() Date: Thu, 24 Mar 2022 15:29:51 +0100 Message-Id: X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1648132150; l=1899; s=20211009; h=from:subject:message-id; bh=zXRjPYU7QaID1rculDvXRerDW2vtk7P4KyqgYPe84dw=; b=U7z+n5XgLJWzFTAW/v6lPqNVyN1ZdZiFY9a6LocS3k9ki0kkEyeAvnc4mc1d92kD7P2MzYQ4A920 esG61C4xCFc0lBFD743p3cdDXxxPP7Ywj87/wEhkw5vQjZm75Iwz X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" When we have CONFIG_DYNAMIC_FTRACE_WITH_ARGS, prepare_ftrace_return() is called by ftrace_graph_func() otherwise prepare_ftrace_return() is called from assembly. Refactor prepare_ftrace_return() into a static __prepare_ftrace_return() that will be called by both prepare_ftrace_return() and ftrace_graph_func(). It will allow GCC to fold __prepare_ftrace_return() inside ftrace_graph_func(). Signed-off-by: Christophe Leroy --- arch/powerpc/kernel/trace/ftrace.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/arch/powerpc/kernel/trace/ftrace.c b/arch/powerpc/kernel/trace= /ftrace.c index 4ee04aacf9f1..7a266fd469b7 100644 --- a/arch/powerpc/kernel/trace/ftrace.c +++ b/arch/powerpc/kernel/trace/ftrace.c @@ -939,8 +939,8 @@ int ftrace_disable_ftrace_graph_caller(void) * Hook the return address and push it in the stack of return addrs * in current thread info. Return the address we want to divert to. */ -unsigned long prepare_ftrace_return(unsigned long parent, unsigned long ip, - unsigned long sp) +static unsigned long +__prepare_ftrace_return(unsigned long parent, unsigned long ip, unsigned l= ong sp) { unsigned long return_hooker; int bit; @@ -969,7 +969,13 @@ unsigned long prepare_ftrace_return(unsigned long pare= nt, unsigned long ip, void ftrace_graph_func(unsigned long ip, unsigned long parent_ip, struct ftrace_ops *op, struct ftrace_regs *fregs) { - fregs->regs.link =3D prepare_ftrace_return(parent_ip, ip, fregs->regs.gpr= [1]); + fregs->regs.link =3D __prepare_ftrace_return(parent_ip, ip, fregs->regs.g= pr[1]); +} +#else +unsigned long prepare_ftrace_return(unsigned long parent, unsigned long ip, + unsigned long sp) +{ + return __prepare_ftrace_return(parent, ip, sp); } #endif #endif /* CONFIG_FUNCTION_GRAPH_TRACER */ --=20 2.35.1 From nobody Sat Jun 20 01:51:50 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E3F1CC433EF for ; Thu, 24 Mar 2022 14:33:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351202AbiCXOet (ORCPT ); Thu, 24 Mar 2022 10:34:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40052 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351059AbiCXOdw (ORCPT ); Thu, 24 Mar 2022 10:33:52 -0400 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A33A9AD113 for ; Thu, 24 Mar 2022 07:32:05 -0700 (PDT) Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4KPSMN13tvz9sV6; Thu, 24 Mar 2022 15:31:12 +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 vgZREsIefgYc; Thu, 24 Mar 2022 15:31:12 +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 4KPSLz21m6z9sTc; Thu, 24 Mar 2022 15:30:51 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 326538B763; Thu, 24 Mar 2022 15:30:51 +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 fKmCTQZdkbZD; Thu, 24 Mar 2022 15:30:51 +0100 (CET) Received: from PO20335.IDSI0.si.c-s.fr (unknown [192.168.203.77]) by messagerie.si.c-s.fr (Postfix) with ESMTP id B9DAC8B790; Thu, 24 Mar 2022 15:30:49 +0100 (CET) Received: from PO20335.IDSI0.si.c-s.fr (localhost [127.0.0.1]) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.16.1) with ESMTPS id 22OEUfCV1811686 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 24 Mar 2022 15:30:41 +0100 Received: (from chleroy@localhost) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.17.1/Submit) id 22OEUfbb1811685; Thu, 24 Mar 2022 15:30:41 +0100 X-Authentication-Warning: PO20335.IDSI0.si.c-s.fr: chleroy set sender to christophe.leroy@csgroup.eu using -f From: Christophe Leroy To: "Naveen N . Rao" , Steven Rostedt , Ingo Molnar , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman Cc: Christophe Leroy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v1 02/22] powerpc/ftrace: Remove redundant create_branch() calls Date: Thu, 24 Mar 2022 15:29:52 +0100 Message-Id: <2d8e845d4329372c6204612bee70b4f36f27e35e.1648131740.git.christophe.leroy@csgroup.eu> X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1648132150; l=2368; s=20211009; h=from:subject:message-id; bh=92KxuX0pLpQCITr7vgjlWnrEBj5V6cm1CJL4gIXJC9A=; b=dUWsc4MtUmN0jjbntgP7dTOuC78Ry2hUoY+sxYUOFNKWEkp/VyAev3THZUiCvA9j7W8wCtFJfDnH 6fBDYJltDBQ5Gz+TgRvBDx+SqpV5rGrJEOzsIXqhk6uICYfpTg9+ X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Since commit d5937db114e4 ("powerpc/code-patching: Fix patch_branch() return on out-of-range failure") patch_branch() fails with -ERANGE when trying to branch out of range. No need to perform the test twice. Remove redundant create_branch() calls. Signed-off-by: Christophe Leroy --- arch/powerpc/kernel/trace/ftrace.c | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/arch/powerpc/kernel/trace/ftrace.c b/arch/powerpc/kernel/trace= /ftrace.c index 7a266fd469b7..3ce3697e8a7c 100644 --- a/arch/powerpc/kernel/trace/ftrace.c +++ b/arch/powerpc/kernel/trace/ftrace.c @@ -301,7 +301,6 @@ static int setup_mcount_compiler_tramp(unsigned long tr= amp) int i; ppc_inst_t op; unsigned long ptr; - ppc_inst_t instr; static unsigned long ftrace_plt_tramps[NUM_FTRACE_TRAMPS]; =20 /* Is this a known long jump tramp? */ @@ -344,12 +343,6 @@ static int setup_mcount_compiler_tramp(unsigned long t= ramp) #else ptr =3D ppc_global_function_entry((void *)ftrace_caller); #endif - if (create_branch(&instr, (void *)tramp, ptr, 0)) { - pr_debug("%ps is not reachable from existing mcount tramp\n", - (void *)ptr); - return -1; - } - if (patch_branch((u32 *)tramp, ptr, 0)) { pr_debug("REL24 out of range!\n"); return -1; @@ -490,7 +483,6 @@ static int __ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr) { ppc_inst_t op[2]; - ppc_inst_t instr; void *ip =3D (void *)rec->ip; unsigned long entry, ptr, tramp; struct module *mod =3D rec->arch.mod; @@ -539,12 +531,6 @@ __ftrace_make_call(struct dyn_ftrace *rec, unsigned lo= ng addr) return -EINVAL; } =20 - /* Ensure branch is within 24 bits */ - if (create_branch(&instr, ip, tramp, BRANCH_SET_LINK)) { - pr_err("Branch out of range\n"); - return -EINVAL; - } - if (patch_branch(ip, tramp, BRANCH_SET_LINK)) { pr_err("REL24 out of range!\n"); return -EINVAL; @@ -770,12 +756,6 @@ __ftrace_modify_call(struct dyn_ftrace *rec, unsigned = long old_addr, return -EINVAL; } =20 - /* Ensure branch is within 24 bits */ - if (create_branch(&op, (u32 *)ip, tramp, BRANCH_SET_LINK)) { - pr_err("Branch out of range\n"); - return -EINVAL; - } - if (patch_branch((u32 *)ip, tramp, BRANCH_SET_LINK)) { pr_err("REL24 out of range!\n"); return -EINVAL; --=20 2.35.1 From nobody Sat Jun 20 01:51:50 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 65C90C433EF for ; Thu, 24 Mar 2022 14:31:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350992AbiCXOcq (ORCPT ); Thu, 24 Mar 2022 10:32:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350964AbiCXOcf (ORCPT ); Thu, 24 Mar 2022 10:32:35 -0400 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F3F7AC937 for ; Thu, 24 Mar 2022 07:31:01 -0700 (PDT) Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4KPSM14KfFz9sTg; Thu, 24 Mar 2022 15:30:53 +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 I89REFKzlHa5; Thu, 24 Mar 2022 15:30:53 +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 4KPSLy2jG9z9sTf; Thu, 24 Mar 2022 15:30:50 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 478D88B7AD; Thu, 24 Mar 2022 15:30:50 +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 A8Jb1u5ZUwKe; Thu, 24 Mar 2022 15:30:50 +0100 (CET) Received: from PO20335.IDSI0.si.c-s.fr (unknown [192.168.203.77]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 8DEB08B763; Thu, 24 Mar 2022 15:30:49 +0100 (CET) Received: from PO20335.IDSI0.si.c-s.fr (localhost [127.0.0.1]) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.16.1) with ESMTPS id 22OEUfKZ1811690 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 24 Mar 2022 15:30:41 +0100 Received: (from chleroy@localhost) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.17.1/Submit) id 22OEUfAW1811689; Thu, 24 Mar 2022 15:30:41 +0100 X-Authentication-Warning: PO20335.IDSI0.si.c-s.fr: chleroy set sender to christophe.leroy@csgroup.eu using -f From: Christophe Leroy To: "Naveen N . Rao" , Steven Rostedt , Ingo Molnar , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman Cc: Christophe Leroy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v1 03/22] powerpc/code-patching: Inline is_offset_in_{cond}_branch_range() Date: Thu, 24 Mar 2022 15:29:53 +0100 Message-Id: <6caf53ffb2f80fb7dac9423a9b4da4e9fa495d8f.1648131740.git.christophe.leroy@csgroup.eu> X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1648132150; l=3156; s=20211009; h=from:subject:message-id; bh=gLaYW1av0GijX4+cqYkHFoJkNFVZ0gQqCQkmFifsN0M=; b=I9KGZmVdJpwvF+IvtFOFjv70QdaW/e0gQzxjWFh4ZXy5yQOKchTBg430+Xg8kkXBBBBoLstagD+v X7YWe8FXA6RY4Y48x3HSZN7Cv1UOZsKqom7Tj7uESKmn8QSwJoGI X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Test in is_offset_in_branch_range() and is_offset_in_cond_branch_range() are simple tests that are worth inlining. Signed-off-by: Christophe Leroy --- arch/powerpc/include/asm/code-patching.h | 29 ++++++++++++++++++++++-- arch/powerpc/lib/code-patching.c | 27 ---------------------- 2 files changed, 27 insertions(+), 29 deletions(-) diff --git a/arch/powerpc/include/asm/code-patching.h b/arch/powerpc/includ= e/asm/code-patching.h index 409483b2d0ce..e7c5df50cb4e 100644 --- a/arch/powerpc/include/asm/code-patching.h +++ b/arch/powerpc/include/asm/code-patching.h @@ -22,8 +22,33 @@ #define BRANCH_SET_LINK 0x1 #define BRANCH_ABSOLUTE 0x2 =20 -bool is_offset_in_branch_range(long offset); -bool is_offset_in_cond_branch_range(long offset); +/* + * Powerpc branch instruction is : + * + * 0 6 30 31 + * +---------+----------------+---+---+ + * | opcode | LI |AA |LK | + * +---------+----------------+---+---+ + * Where AA =3D 0 and LK =3D 0 + * + * LI is a signed 24 bits integer. The real branch offset is computed + * by: imm32 =3D SignExtend(LI:'0b00', 32); + * + * So the maximum forward branch should be: + * (0x007fffff << 2) =3D 0x01fffffc =3D 0x1fffffc + * The maximum backward branch should be: + * (0xff800000 << 2) =3D 0xfe000000 =3D -0x2000000 + */ +static inline bool is_offset_in_branch_range(long offset) +{ + return (offset >=3D -0x2000000 && offset <=3D 0x1fffffc && !(offset & 0x3= )); +} + +static inline bool is_offset_in_cond_branch_range(long offset) +{ + return offset >=3D -0x8000 && offset <=3D 0x7fff && !(offset & 0x3); +} + int create_branch(ppc_inst_t *instr, const u32 *addr, unsigned long target, int flags); int create_cond_branch(ppc_inst_t *instr, const u32 *addr, diff --git a/arch/powerpc/lib/code-patching.c b/arch/powerpc/lib/code-patch= ing.c index 00c68e7fb11e..58262c7e447c 100644 --- a/arch/powerpc/lib/code-patching.c +++ b/arch/powerpc/lib/code-patching.c @@ -208,33 +208,6 @@ int patch_branch(u32 *addr, unsigned long target, int = flags) return patch_instruction(addr, instr); } =20 -bool is_offset_in_branch_range(long offset) -{ - /* - * Powerpc branch instruction is : - * - * 0 6 30 31 - * +---------+----------------+---+---+ - * | opcode | LI |AA |LK | - * +---------+----------------+---+---+ - * Where AA =3D 0 and LK =3D 0 - * - * LI is a signed 24 bits integer. The real branch offset is computed - * by: imm32 =3D SignExtend(LI:'0b00', 32); - * - * So the maximum forward branch should be: - * (0x007fffff << 2) =3D 0x01fffffc =3D 0x1fffffc - * The maximum backward branch should be: - * (0xff800000 << 2) =3D 0xfe000000 =3D -0x2000000 - */ - return (offset >=3D -0x2000000 && offset <=3D 0x1fffffc && !(offset & 0x3= )); -} - -bool is_offset_in_cond_branch_range(long offset) -{ - return offset >=3D -0x8000 && offset <=3D 0x7fff && !(offset & 0x3); -} - /* * Helper to check if a given instruction is a conditional branch * Derived from the conditional checks in analyse_instr() --=20 2.35.1 From nobody Sat Jun 20 01:51:50 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1738AC433EF for ; Thu, 24 Mar 2022 14:33:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237338AbiCXOeg (ORCPT ); Thu, 24 Mar 2022 10:34:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351106AbiCXOdL (ORCPT ); Thu, 24 Mar 2022 10:33:11 -0400 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27541AC900 for ; Thu, 24 Mar 2022 07:31:40 -0700 (PDT) Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4KPSMD0wk1z9sTs; Thu, 24 Mar 2022 15:31:04 +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 dbWzCh9ugxq4; Thu, 24 Mar 2022 15:31:04 +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 4KPSLz0530z9sTw; Thu, 24 Mar 2022 15:30:51 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id E8A498B780; Thu, 24 Mar 2022 15:30:50 +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 iL0nVEGK8aqY; Thu, 24 Mar 2022 15:30:50 +0100 (CET) Received: from PO20335.IDSI0.si.c-s.fr (unknown [192.168.203.77]) by messagerie.si.c-s.fr (Postfix) with ESMTP id C89348B794; Thu, 24 Mar 2022 15:30:49 +0100 (CET) Received: from PO20335.IDSI0.si.c-s.fr (localhost [127.0.0.1]) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.16.1) with ESMTPS id 22OEUfQG1811694 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 24 Mar 2022 15:30:41 +0100 Received: (from chleroy@localhost) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.17.1/Submit) id 22OEUf7P1811693; Thu, 24 Mar 2022 15:30:41 +0100 X-Authentication-Warning: PO20335.IDSI0.si.c-s.fr: chleroy set sender to christophe.leroy@csgroup.eu using -f From: Christophe Leroy To: "Naveen N . Rao" , Steven Rostedt , Ingo Molnar , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman Cc: Christophe Leroy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v1 04/22] powerpc/ftrace: Use is_offset_in_branch_range() Date: Thu, 24 Mar 2022 15:29:54 +0100 Message-Id: X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1648132151; l=1631; s=20211009; h=from:subject:message-id; bh=OWDdhcCtR60EJOCWc6cwIHh4xDhD5orD3drnjJOkPJg=; b=R5nyRGuj8ht2rQYbKC52j94uH0d5CMW8dnEJ87IEaRoi9cSUhWquC0kV0SAWhQU9ot7ixbEx9b23 Fwd0ds1VBxTIp443RcLjfbRk7zgWHz50EoIM86V1Jtbw5mTgHJpo X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Use is_offset_in_branch_range() instead of create_branch() to check if a target is within branch range. This patch together with the previous one improves ftrace activation time by 7% Signed-off-by: Christophe Leroy --- arch/powerpc/kernel/trace/ftrace.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/arch/powerpc/kernel/trace/ftrace.c b/arch/powerpc/kernel/trace= /ftrace.c index 3ce3697e8a7c..41c45b9c7f39 100644 --- a/arch/powerpc/kernel/trace/ftrace.c +++ b/arch/powerpc/kernel/trace/ftrace.c @@ -89,11 +89,9 @@ ftrace_modify_code(unsigned long ip, ppc_inst_t old, ppc= _inst_t new) */ static int test_24bit_addr(unsigned long ip, unsigned long addr) { - ppc_inst_t op; addr =3D ppc_function_entry((void *)addr); =20 - /* use the create_branch to verify that this offset can be branched */ - return create_branch(&op, (u32 *)ip, addr, 0) =3D=3D 0; + return is_offset_in_branch_range(addr - ip); } =20 static int is_bl_op(ppc_inst_t op) @@ -261,7 +259,6 @@ __ftrace_make_nop(struct module *mod, static unsigned long find_ftrace_tramp(unsigned long ip) { int i; - ppc_inst_t instr; =20 /* * We have the compiler generated long_branch tramps at the end @@ -270,8 +267,7 @@ static unsigned long find_ftrace_tramp(unsigned long ip) for (i =3D NUM_FTRACE_TRAMPS - 1; i >=3D 0; i--) if (!ftrace_tramps[i]) continue; - else if (create_branch(&instr, (void *)ip, - ftrace_tramps[i], 0) =3D=3D 0) + else if (is_offset_in_branch_range(ftrace_tramps[i] - ip)) return ftrace_tramps[i]; =20 return 0; --=20 2.35.1 From nobody Sat Jun 20 01:51:50 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D8B18C433EF for ; Thu, 24 Mar 2022 14:32:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351071AbiCXOeL (ORCPT ); Thu, 24 Mar 2022 10:34:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351116AbiCXOdO (ORCPT ); Thu, 24 Mar 2022 10:33:14 -0400 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78960A27DD for ; Thu, 24 Mar 2022 07:31:42 -0700 (PDT) Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4KPSMF1CF9z9sTw; Thu, 24 Mar 2022 15:31:05 +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 qK301kmQHGwi; Thu, 24 Mar 2022 15:31:05 +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 4KPSLz007qz9sTv; Thu, 24 Mar 2022 15:30:51 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id D71E88B787; Thu, 24 Mar 2022 15:30:50 +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 E0ElFNK7xCR3; Thu, 24 Mar 2022 15:30:50 +0100 (CET) Received: from PO20335.IDSI0.si.c-s.fr (unknown [192.168.203.77]) by messagerie.si.c-s.fr (Postfix) with ESMTP id D371E8B798; Thu, 24 Mar 2022 15:30:49 +0100 (CET) Received: from PO20335.IDSI0.si.c-s.fr (localhost [127.0.0.1]) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.16.1) with ESMTPS id 22OEUfjb1811698 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 24 Mar 2022 15:30:41 +0100 Received: (from chleroy@localhost) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.17.1/Submit) id 22OEUf5a1811697; Thu, 24 Mar 2022 15:30:41 +0100 X-Authentication-Warning: PO20335.IDSI0.si.c-s.fr: chleroy set sender to christophe.leroy@csgroup.eu using -f From: Christophe Leroy To: "Naveen N . Rao" , Steven Rostedt , Ingo Molnar , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman Cc: Christophe Leroy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v1 05/22] powerpc/code-patching: Inline create_branch() Date: Thu, 24 Mar 2022 15:29:55 +0100 Message-Id: <2b0c4291fbf2e467fbae9c504bf671bfc29df70a.1648131740.git.christophe.leroy@csgroup.eu> X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1648132151; l=2728; s=20211009; h=from:subject:message-id; bh=d2swIJrMmUDKV+uH13vJ0j/DNa2ajgVmApWQwP8siB0=; b=9oT4lBmjHqdBffgfNdni0A6cjFBJAmWNr4erXH3Omj1NVKy0IFtDpVriLqKgkCdzUXn0cxgyMiqq 0D8opGd1AEylddQg+yiIEDFKgigtk+fBbnW+MTCly8Y2pA32UZQ1 X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" create_branch() is a good candidate for inlining because: - Flags can be folded in. - Range tests are likely to be already done. Hence reducing the create_branch() to only a set of instructions. So inline it. It improves ftrace activation by 10%. Signed-off-by: Christophe Leroy --- arch/powerpc/include/asm/code-patching.h | 22 ++++++++++++++++++++-- arch/powerpc/lib/code-patching.c | 20 -------------------- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/arch/powerpc/include/asm/code-patching.h b/arch/powerpc/includ= e/asm/code-patching.h index e7c5df50cb4e..4260e89f62b1 100644 --- a/arch/powerpc/include/asm/code-patching.h +++ b/arch/powerpc/include/asm/code-patching.h @@ -49,8 +49,26 @@ static inline bool is_offset_in_cond_branch_range(long o= ffset) return offset >=3D -0x8000 && offset <=3D 0x7fff && !(offset & 0x3); } =20 -int create_branch(ppc_inst_t *instr, const u32 *addr, - unsigned long target, int flags); +static inline int create_branch(ppc_inst_t *instr, const u32 *addr, + unsigned long target, int flags) +{ + long offset; + + *instr =3D ppc_inst(0); + offset =3D target; + if (! (flags & BRANCH_ABSOLUTE)) + offset =3D offset - (unsigned long)addr; + + /* Check we can represent the target in the instruction format */ + if (!is_offset_in_branch_range(offset)) + return 1; + + /* Mask out the flags and target, so they don't step on each other. */ + *instr =3D ppc_inst(0x48000000 | (flags & 0x3) | (offset & 0x03FFFFFC)); + + return 0; +} + int create_cond_branch(ppc_inst_t *instr, const u32 *addr, unsigned long target, int flags); int patch_branch(u32 *addr, unsigned long target, int flags); diff --git a/arch/powerpc/lib/code-patching.c b/arch/powerpc/lib/code-patch= ing.c index 58262c7e447c..7adbdb05fee7 100644 --- a/arch/powerpc/lib/code-patching.c +++ b/arch/powerpc/lib/code-patching.c @@ -230,26 +230,6 @@ bool is_conditional_branch(ppc_inst_t instr) } NOKPROBE_SYMBOL(is_conditional_branch); =20 -int create_branch(ppc_inst_t *instr, const u32 *addr, - unsigned long target, int flags) -{ - long offset; - - *instr =3D ppc_inst(0); - offset =3D target; - if (! (flags & BRANCH_ABSOLUTE)) - offset =3D offset - (unsigned long)addr; - - /* Check we can represent the target in the instruction format */ - if (!is_offset_in_branch_range(offset)) - return 1; - - /* Mask out the flags and target, so they don't step on each other. */ - *instr =3D ppc_inst(0x48000000 | (flags & 0x3) | (offset & 0x03FFFFFC)); - - return 0; -} - int create_cond_branch(ppc_inst_t *instr, const u32 *addr, unsigned long target, int flags) { --=20 2.35.1 From nobody Sat Jun 20 01:51:50 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EAFE0C433F5 for ; Thu, 24 Mar 2022 14:32:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351010AbiCXOdm (ORCPT ); Thu, 24 Mar 2022 10:33:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351081AbiCXOdJ (ORCPT ); Thu, 24 Mar 2022 10:33:09 -0400 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1237BAD106 for ; Thu, 24 Mar 2022 07:31:27 -0700 (PDT) Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4KPSM81FZkz9sTn; Thu, 24 Mar 2022 15:31:00 +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 Y8HmYW9t7ODM; Thu, 24 Mar 2022 15:31:00 +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 4KPSLy6jK9z9sTp; Thu, 24 Mar 2022 15:30:50 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id CFC668B763; Thu, 24 Mar 2022 15:30:50 +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 z7O4qnOkc6XT; Thu, 24 Mar 2022 15:30:50 +0100 (CET) Received: from PO20335.IDSI0.si.c-s.fr (unknown [192.168.203.77]) by messagerie.si.c-s.fr (Postfix) with ESMTP id C474B8B792; Thu, 24 Mar 2022 15:30:49 +0100 (CET) Received: from PO20335.IDSI0.si.c-s.fr (localhost [127.0.0.1]) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.16.1) with ESMTPS id 22OEUfu11811702 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 24 Mar 2022 15:30:42 +0100 Received: (from chleroy@localhost) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.17.1/Submit) id 22OEUfT81811701; Thu, 24 Mar 2022 15:30:41 +0100 X-Authentication-Warning: PO20335.IDSI0.si.c-s.fr: chleroy set sender to christophe.leroy@csgroup.eu using -f From: Christophe Leroy To: "Naveen N . Rao" , Steven Rostedt , Ingo Molnar , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman Cc: Christophe Leroy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v1 06/22] powerpc/ftrace: Inline ftrace_modify_code() Date: Thu, 24 Mar 2022 15:29:56 +0100 Message-Id: <3b651381f4c53988ede62f4a1505e7e8ccab56b4.1648131740.git.christophe.leroy@csgroup.eu> X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1648132151; l=752; s=20211009; h=from:subject:message-id; bh=wl3POSoxBr8XY5BnerFiiulTu0vpof390KEu8pzei0s=; b=Hg0Qb98i+mqMY1rUSqyHWDk2mttT7AHAAbpHZM+2J5TuTtGGs1GlH7OzAH747Vvt0pzT1TL6Daq1 bB6qNbokA2l7ic4J6A9j1mAo9CCQKezcMGCyN5hg1BGAiI2YfxSU X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Inlining ftrace_modify_code(), it increases a bit the size of ftrace code but brings 5% improvment on ftrace activation. Signed-off-by: Christophe Leroy --- arch/powerpc/kernel/trace/ftrace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/powerpc/kernel/trace/ftrace.c b/arch/powerpc/kernel/trace= /ftrace.c index 41c45b9c7f39..98e82fa4980f 100644 --- a/arch/powerpc/kernel/trace/ftrace.c +++ b/arch/powerpc/kernel/trace/ftrace.c @@ -53,7 +53,7 @@ ftrace_call_replace(unsigned long ip, unsigned long addr,= int link) return op; } =20 -static int +static inline int ftrace_modify_code(unsigned long ip, ppc_inst_t old, ppc_inst_t new) { ppc_inst_t replaced; --=20 2.35.1 From nobody Sat Jun 20 01:51:50 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A5AD6C433EF for ; Thu, 24 Mar 2022 14:33:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351195AbiCXOeo (ORCPT ); Thu, 24 Mar 2022 10:34:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351004AbiCXOde (ORCPT ); Thu, 24 Mar 2022 10:33:34 -0400 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DCD80A27E6 for ; Thu, 24 Mar 2022 07:32:01 -0700 (PDT) Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4KPSMM1XlDz9sV2; Thu, 24 Mar 2022 15:31:11 +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 rxycMU_PF0o0; Thu, 24 Mar 2022 15:31:11 +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 4KPSLz0XNvz9sV1; Thu, 24 Mar 2022 15:30:51 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id F311D8B781; Thu, 24 Mar 2022 15:30:50 +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 l4iX8fWQY25n; Thu, 24 Mar 2022 15:30:50 +0100 (CET) Received: from PO20335.IDSI0.si.c-s.fr (unknown [192.168.203.77]) by messagerie.si.c-s.fr (Postfix) with ESMTP id E37E18B79E; Thu, 24 Mar 2022 15:30:49 +0100 (CET) Received: from PO20335.IDSI0.si.c-s.fr (localhost [127.0.0.1]) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.16.1) with ESMTPS id 22OEUg3V1811706 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 24 Mar 2022 15:30:42 +0100 Received: (from chleroy@localhost) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.17.1/Submit) id 22OEUgo01811705; Thu, 24 Mar 2022 15:30:42 +0100 X-Authentication-Warning: PO20335.IDSI0.si.c-s.fr: chleroy set sender to christophe.leroy@csgroup.eu using -f From: Christophe Leroy To: "Naveen N . Rao" , Steven Rostedt , Ingo Molnar , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman Cc: Christophe Leroy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v1 07/22] powerpc/ftrace: Use patch_instruction() return directly Date: Thu, 24 Mar 2022 15:29:57 +0100 Message-Id: X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1648132151; l=2477; s=20211009; h=from:subject:message-id; bh=PJRWF5zilgXFq2l/yg0VrSmcXU+NGwvO/WufSwrFK+0=; b=8uNjnaYtWGp+q2mgdCMtZiuzz+gG6F1oGYN6JadbN2Xb8ADYwE/wtt2nrh4wpyUuXPiH/sSsUyWO oGo7nZ4+CkR/K0PFzcwJlJ3i3uF7Gzirx1EvRhKwm9W/nQqKVs5W X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Instead of returning -EPERM when patch_instruction() fails, just return what patch_instruction returns. That simplifies ftrace_modify_code(): 0: 94 21 ff c0 stwu r1,-64(r1) 4: 93 e1 00 3c stw r31,60(r1) 8: 7c 7f 1b 79 mr. r31,r3 c: 40 80 00 30 bge 3c 10: 93 c1 00 38 stw r30,56(r1) 14: 7c 9e 23 78 mr r30,r4 18: 7c a4 2b 78 mr r4,r5 1c: 80 bf 00 00 lwz r5,0(r31) 20: 7c 1e 28 40 cmplw r30,r5 24: 40 82 00 34 bne 58 28: 83 c1 00 38 lwz r30,56(r1) 2c: 7f e3 fb 78 mr r3,r31 30: 83 e1 00 3c lwz r31,60(r1) 34: 38 21 00 40 addi r1,r1,64 38: 48 00 00 00 b 38 38: R_PPC_REL24 patch_instruction Before: 0: 94 21 ff c0 stwu r1,-64(r1) 4: 93 e1 00 3c stw r31,60(r1) 8: 7c 7f 1b 79 mr. r31,r3 c: 40 80 00 4c bge 58 10: 93 c1 00 38 stw r30,56(r1) 14: 7c 9e 23 78 mr r30,r4 18: 7c a4 2b 78 mr r4,r5 1c: 80 bf 00 00 lwz r5,0(r31) 20: 7c 08 02 a6 mflr r0 24: 90 01 00 44 stw r0,68(r1) 28: 7c 1e 28 40 cmplw r30,r5 2c: 40 82 00 48 bne 74 30: 7f e3 fb 78 mr r3,r31 34: 48 00 00 01 bl 34 34: R_PPC_REL24 patch_instruction 38: 80 01 00 44 lwz r0,68(r1) 3c: 20 63 00 00 subfic r3,r3,0 40: 83 c1 00 38 lwz r30,56(r1) 44: 7c 63 19 10 subfe r3,r3,r3 48: 7c 08 03 a6 mtlr r0 4c: 83 e1 00 3c lwz r31,60(r1) 50: 38 21 00 40 addi r1,r1,64 54: 4e 80 00 20 blr It improves ftrace activation/deactivation duration by about 3%. Signed-off-by: Christophe Leroy --- arch/powerpc/kernel/trace/ftrace.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/arch/powerpc/kernel/trace/ftrace.c b/arch/powerpc/kernel/trace= /ftrace.c index 98e82fa4980f..1b05d33f96c6 100644 --- a/arch/powerpc/kernel/trace/ftrace.c +++ b/arch/powerpc/kernel/trace/ftrace.c @@ -78,10 +78,7 @@ ftrace_modify_code(unsigned long ip, ppc_inst_t old, ppc= _inst_t new) } =20 /* replace the text with the new text */ - if (patch_instruction((u32 *)ip, new)) - return -EPERM; - - return 0; + return patch_instruction((u32 *)ip, new); } =20 /* --=20 2.35.1 From nobody Sat Jun 20 01:51:50 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8B3DAC433EF for ; Thu, 24 Mar 2022 14:33:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351169AbiCXOed (ORCPT ); Thu, 24 Mar 2022 10:34:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351003AbiCXOdc (ORCPT ); Thu, 24 Mar 2022 10:33:32 -0400 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1EB5CAC922 for ; Thu, 24 Mar 2022 07:31:58 -0700 (PDT) Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4KPSML1bSVz9sV0; Thu, 24 Mar 2022 15:31:10 +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 1YKqJW-0bzco; Thu, 24 Mar 2022 15:31:10 +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 4KPSLz0qQcz9sV2; Thu, 24 Mar 2022 15:30:51 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 066018B786; Thu, 24 Mar 2022 15:30:51 +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 x9Ib-xYEu1Id; Thu, 24 Mar 2022 15:30:50 +0100 (CET) Received: from PO20335.IDSI0.si.c-s.fr (unknown [192.168.203.77]) by messagerie.si.c-s.fr (Postfix) with ESMTP id EA3418B79F; Thu, 24 Mar 2022 15:30:49 +0100 (CET) Received: from PO20335.IDSI0.si.c-s.fr (localhost [127.0.0.1]) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.16.1) with ESMTPS id 22OEUgsx1811710 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 24 Mar 2022 15:30:42 +0100 Received: (from chleroy@localhost) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.17.1/Submit) id 22OEUgpB1811709; Thu, 24 Mar 2022 15:30:42 +0100 X-Authentication-Warning: PO20335.IDSI0.si.c-s.fr: chleroy set sender to christophe.leroy@csgroup.eu using -f From: Christophe Leroy To: "Naveen N . Rao" , Steven Rostedt , Ingo Molnar , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman Cc: Christophe Leroy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v1 08/22] powerpc/ftrace: Make __ftrace_make_{nop/call}() common to PPC32 and PPC64 Date: Thu, 24 Mar 2022 15:29:58 +0100 Message-Id: X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1648132151; l=5520; s=20211009; h=from:subject:message-id; bh=fu95AZd5FCaJwPMbMGXXiOSwiaAzLnBguw3AN73/rHU=; b=c57TYtigamK9L6iS+hoKb5BfbBfbpqatqfGhnG01f9CeAFCk5o9x63y1Mu3iq3supveTng05F8FX RlFTPDGKAhSlbV4jOmHVIgYhvUeQtsr1Xyoy3KCpbPZgd0ExX1G8 X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Since c93d4f6ecf4b ("powerpc/ftrace: Add module_trampoline_target() for PPC32"), __ftrace_make_nop() for PPC32 is very similar to the one for PPC64. Same for __ftrace_make_call(). Make them common. Signed-off-by: Christophe Leroy --- arch/powerpc/kernel/trace/ftrace.c | 108 +++-------------------------- 1 file changed, 8 insertions(+), 100 deletions(-) diff --git a/arch/powerpc/kernel/trace/ftrace.c b/arch/powerpc/kernel/trace= /ftrace.c index 1b05d33f96c6..2c7e42e439bb 100644 --- a/arch/powerpc/kernel/trace/ftrace.c +++ b/arch/powerpc/kernel/trace/ftrace.c @@ -114,7 +114,6 @@ static unsigned long find_bl_target(unsigned long ip, p= pc_inst_t op) } =20 #ifdef CONFIG_MODULES -#ifdef CONFIG_PPC64 static int __ftrace_make_nop(struct module *mod, struct dyn_ftrace *rec, unsigned long addr) @@ -154,10 +153,11 @@ __ftrace_make_nop(struct module *mod, return -EINVAL; } =20 -#ifdef CONFIG_MPROFILE_KERNEL - /* When using -mkernel_profile there is no load to jump over */ + /* When using -mkernel_profile or PPC32 there is no load to jump over */ pop =3D ppc_inst(PPC_RAW_NOP()); =20 +#ifdef CONFIG_PPC64 +#ifdef CONFIG_MPROFILE_KERNEL if (copy_inst_from_kernel_nofault(&op, (void *)(ip - 4))) { pr_err("Fetching instruction at %lx failed.\n", ip - 4); return -EFAULT; @@ -201,6 +201,7 @@ __ftrace_make_nop(struct module *mod, return -EINVAL; } #endif /* CONFIG_MPROFILE_KERNEL */ +#endif /* PPC64 */ =20 if (patch_instruction((u32 *)ip, pop)) { pr_err("Patching NOP failed.\n"); @@ -209,48 +210,6 @@ __ftrace_make_nop(struct module *mod, =20 return 0; } - -#else /* !PPC64 */ -static int -__ftrace_make_nop(struct module *mod, - struct dyn_ftrace *rec, unsigned long addr) -{ - ppc_inst_t op; - unsigned long ip =3D rec->ip; - unsigned long tramp, ptr; - - if (copy_from_kernel_nofault(&op, (void *)ip, MCOUNT_INSN_SIZE)) - return -EFAULT; - - /* Make sure that that this is still a 24bit jump */ - if (!is_bl_op(op)) { - pr_err("Not expected bl: opcode is %s\n", ppc_inst_as_str(op)); - return -EINVAL; - } - - /* lets find where the pointer goes */ - tramp =3D find_bl_target(ip, op); - - /* Find where the trampoline jumps to */ - if (module_trampoline_target(mod, tramp, &ptr)) { - pr_err("Failed to get trampoline target\n"); - return -EFAULT; - } - - if (ptr !=3D addr) { - pr_err("Trampoline location %08lx does not match addr\n", - tramp); - return -EINVAL; - } - - op =3D ppc_inst(PPC_RAW_NOP()); - - if (patch_instruction((u32 *)ip, op)) - return -EPERM; - - return 0; -} -#endif /* PPC64 */ #endif /* CONFIG_MODULES */ =20 static unsigned long find_ftrace_tramp(unsigned long ip) @@ -437,13 +396,12 @@ int ftrace_make_nop(struct module *mod, } =20 #ifdef CONFIG_MODULES -#ifdef CONFIG_PPC64 /* * Examine the existing instructions for __ftrace_make_call. * They should effectively be a NOP, and follow formal constraints, * depending on the ABI. Return false if they don't. */ -#ifndef CONFIG_MPROFILE_KERNEL +#ifndef CONFIG_DYNAMIC_FTRACE_WITH_REGS static int expected_nop_sequence(void *ip, ppc_inst_t op0, ppc_inst_t op1) { @@ -465,7 +423,7 @@ expected_nop_sequence(void *ip, ppc_inst_t op0, ppc_ins= t_t op1) static int expected_nop_sequence(void *ip, ppc_inst_t op0, ppc_inst_t op1) { - /* look for patched "NOP" on ppc64 with -mprofile-kernel */ + /* look for patched "NOP" on ppc64 with -mprofile-kernel or ppc32 */ if (!ppc_inst_equal(op0, ppc_inst(PPC_RAW_NOP()))) return 0; return 1; @@ -484,8 +442,10 @@ __ftrace_make_call(struct dyn_ftrace *rec, unsigned lo= ng addr) if (copy_inst_from_kernel_nofault(op, ip)) return -EFAULT; =20 +#ifndef CONFIG_DYNAMIC_FTRACE_WITH_REGS if (copy_inst_from_kernel_nofault(op + 1, ip + 4)) return -EFAULT; +#endif =20 if (!expected_nop_sequence(ip, op[0], op[1])) { pr_err("Unexpected call sequence at %p: %s %s\n", @@ -531,58 +491,6 @@ __ftrace_make_call(struct dyn_ftrace *rec, unsigned lo= ng addr) =20 return 0; } - -#else /* !CONFIG_PPC64: */ -static int -__ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr) -{ - int err; - ppc_inst_t op; - u32 *ip =3D (u32 *)rec->ip; - struct module *mod =3D rec->arch.mod; - unsigned long tramp; - - /* read where this goes */ - if (copy_inst_from_kernel_nofault(&op, ip)) - return -EFAULT; - - /* It should be pointing to a nop */ - if (!ppc_inst_equal(op, ppc_inst(PPC_RAW_NOP()))) { - pr_err("Expected NOP but have %s\n", ppc_inst_as_str(op)); - return -EINVAL; - } - - /* If we never set up a trampoline to ftrace_caller, then bail */ -#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS - if (!mod->arch.tramp || !mod->arch.tramp_regs) { -#else - if (!mod->arch.tramp) { -#endif - pr_err("No ftrace trampoline\n"); - return -EINVAL; - } - -#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS - if (rec->flags & FTRACE_FL_REGS) - tramp =3D mod->arch.tramp_regs; - else -#endif - tramp =3D mod->arch.tramp; - /* create the branch to the trampoline */ - err =3D create_branch(&op, ip, tramp, BRANCH_SET_LINK); - if (err) { - pr_err("REL24 out of range!\n"); - return -EINVAL; - } - - pr_devel("write to %lx\n", rec->ip); - - if (patch_instruction(ip, op)) - return -EPERM; - - return 0; -} -#endif /* CONFIG_PPC64 */ #endif /* CONFIG_MODULES */ =20 static int __ftrace_make_call_kernel(struct dyn_ftrace *rec, unsigned long= addr) --=20 2.35.1 From nobody Sat Jun 20 01:51:50 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CC7CAC433EF for ; Thu, 24 Mar 2022 14:31:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242049AbiCXOd2 (ORCPT ); Thu, 24 Mar 2022 10:33:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350985AbiCXOcl (ORCPT ); Thu, 24 Mar 2022 10:32:41 -0400 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 663A4A27DD for ; Thu, 24 Mar 2022 07:31:09 -0700 (PDT) Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4KPSM31cDsz9sTh; Thu, 24 Mar 2022 15:30:55 +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 oBXtvjH293qZ; Thu, 24 Mar 2022 15:30:55 +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 4KPSLy3Ndlz9sTk; Thu, 24 Mar 2022 15:30:50 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 5D19D8B781; Thu, 24 Mar 2022 15:30:50 +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 5Ju7wkLVnki8; Thu, 24 Mar 2022 15:30:50 +0100 (CET) Received: from PO20335.IDSI0.si.c-s.fr (unknown [192.168.203.77]) by messagerie.si.c-s.fr (Postfix) with ESMTP id A38EE8B788; Thu, 24 Mar 2022 15:30:49 +0100 (CET) Received: from PO20335.IDSI0.si.c-s.fr (localhost [127.0.0.1]) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.16.1) with ESMTPS id 22OEUgPc1811714 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 24 Mar 2022 15:30:42 +0100 Received: (from chleroy@localhost) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.17.1/Submit) id 22OEUgR31811713; Thu, 24 Mar 2022 15:30:42 +0100 X-Authentication-Warning: PO20335.IDSI0.si.c-s.fr: chleroy set sender to christophe.leroy@csgroup.eu using -f From: Christophe Leroy To: "Naveen N . Rao" , Steven Rostedt , Ingo Molnar , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman Cc: Christophe Leroy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v1 09/22] powerpc/ftrace: Don't include ftrace.o for CONFIG_FTRACE_SYSCALLS Date: Thu, 24 Mar 2022 15:29:59 +0100 Message-Id: <0b06b90955384b784586b1bb7e989f46c4fc48f8.1648131740.git.christophe.leroy@csgroup.eu> X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1648132151; l=797; s=20211009; h=from:subject:message-id; bh=dBT+4KIjHuCkAQQu4k+Tl2VRVeqnuyJrNn++RX40GAM=; b=1NXTQ14ZCFshKyO/mSyPMaQon1saWar+tLQaZxlyvrR4/rJxtcWPfM5Xxc4mZR/1T+zsP/tRFF/4 hIpqFjqbDXooPeepXWcQ639xEHKiikjGGV/FGa6bxsg5dvAjY94z X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Since commit 7bea7ac0ca01 ("powerpc/syscalls: Fix syscall tracing") ftrace.o is not needed anymore for CONFIG_FTRACE_SYSCALLS. Signed-off-by: Christophe Leroy --- arch/powerpc/kernel/trace/Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/arch/powerpc/kernel/trace/Makefile b/arch/powerpc/kernel/trace= /Makefile index 542aa7a8b2b4..fc32ec30b297 100644 --- a/arch/powerpc/kernel/trace/Makefile +++ b/arch/powerpc/kernel/trace/Makefile @@ -17,7 +17,6 @@ endif obj-$(CONFIG_FUNCTION_TRACER) +=3D ftrace_low.o obj-$(CONFIG_DYNAMIC_FTRACE) +=3D ftrace.o obj-$(CONFIG_FUNCTION_GRAPH_TRACER) +=3D ftrace.o -obj-$(CONFIG_FTRACE_SYSCALLS) +=3D ftrace.o obj-$(CONFIG_TRACING) +=3D trace_clock.o =20 obj-$(CONFIG_PPC64) +=3D $(obj64-y) --=20 2.35.1 From nobody Sat Jun 20 01:51:50 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D8225C433F5 for ; Thu, 24 Mar 2022 14:31:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351038AbiCXOc4 (ORCPT ); Thu, 24 Mar 2022 10:32:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350971AbiCXOci (ORCPT ); Thu, 24 Mar 2022 10:32:38 -0400 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75207AC060 for ; Thu, 24 Mar 2022 07:31:05 -0700 (PDT) Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4KPSM22h5Wz9sTf; Thu, 24 Mar 2022 15:30:54 +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 SsVy4jWI__nD; Thu, 24 Mar 2022 15:30:54 +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 4KPSLy35sBz9sTh; Thu, 24 Mar 2022 15:30:50 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 55EA58B763; Thu, 24 Mar 2022 15:30:50 +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 t6C-KzDmjo-b; Thu, 24 Mar 2022 15:30:50 +0100 (CET) Received: from PO20335.IDSI0.si.c-s.fr (unknown [192.168.203.77]) by messagerie.si.c-s.fr (Postfix) with ESMTP id A01CB8B787; Thu, 24 Mar 2022 15:30:49 +0100 (CET) Received: from PO20335.IDSI0.si.c-s.fr (localhost [127.0.0.1]) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.16.1) with ESMTPS id 22OEUg2G1811718 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 24 Mar 2022 15:30:42 +0100 Received: (from chleroy@localhost) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.17.1/Submit) id 22OEUgp31811717; Thu, 24 Mar 2022 15:30:42 +0100 X-Authentication-Warning: PO20335.IDSI0.si.c-s.fr: chleroy set sender to christophe.leroy@csgroup.eu using -f From: Christophe Leroy To: "Naveen N . Rao" , Steven Rostedt , Ingo Molnar , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman Cc: Christophe Leroy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v1 10/22] powerpc/ftrace: Use CONFIG_FUNCTION_TRACER instead of CONFIG_DYNAMIC_FTRACE Date: Thu, 24 Mar 2022 15:30:00 +0100 Message-Id: <72070995f96acaa9a387963e3848bd24a436a847.1648131740.git.christophe.leroy@csgroup.eu> X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1648132151; l=6898; s=20211009; h=from:subject:message-id; bh=7a3n3vVzipjhc9wdEDaF2vM9nWN6CKOUlXyd7asESRc=; b=W6S2xOdjmipBzbwj+Eihns5K2pIYCoNq9sncWg6XBUYDzKZbcXHljQsI0m97EX1UGZgGsLDPiZZc P/iY5+38CBRJGAfG1L2bvdXiE4FpER9XuPzq8Ekuchs27Wtlv0co X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Since commit 0c0c52306f47 ("powerpc: Only support DYNAMIC_FTRACE not static"), CONFIG_DYNAMIC_FTRACE is always selected when CONFIG_FUNCTION_TRACER is selected. To avoid confusion and have the reader wonder what's happen when CONFIG_FUNCTION_TRACER is selected and CONFIG_DYNAMIC_FTRACE is not, use CONFIG_FUNCTION_TRACER in ifdefs instead of CONFIG_DYNAMIC_FTRACE. As CONFIG_FUNCTION_GRAPH_TRACER depends on CONFIG_FUNCTION_TRACER, ftrace.o doesn't need to appear for both symbols in Makefile. Then as ftrace.o is built only when CONFIG_FUNCTION_TRACER is selected ifdef CONFIG_FUNCTION_TRACER is not needed in ftrace.c Signed-off-by: Christophe Leroy --- arch/powerpc/include/asm/book3s/32/pgtable.h | 2 +- arch/powerpc/include/asm/book3s/64/pgtable.h | 2 +- arch/powerpc/include/asm/module.h | 4 ++-- arch/powerpc/include/asm/nohash/pgtable.h | 2 +- arch/powerpc/kernel/module_32.c | 4 ++-- arch/powerpc/kernel/module_64.c | 6 +++--- arch/powerpc/kernel/trace/Makefile | 4 +--- arch/powerpc/kernel/trace/ftrace.c | 4 ---- 8 files changed, 11 insertions(+), 17 deletions(-) diff --git a/arch/powerpc/include/asm/book3s/32/pgtable.h b/arch/powerpc/in= clude/asm/book3s/32/pgtable.h index 772e00dc4ef1..992aed626eb4 100644 --- a/arch/powerpc/include/asm/book3s/32/pgtable.h +++ b/arch/powerpc/include/asm/book3s/32/pgtable.h @@ -124,7 +124,7 @@ static inline bool pte_user(pte_t pte) * on platforms where such control is possible. */ #if defined(CONFIG_KGDB) || defined(CONFIG_XMON) || defined(CONFIG_BDI_SWI= TCH) ||\ - defined(CONFIG_KPROBES) || defined(CONFIG_DYNAMIC_FTRACE) + defined(CONFIG_KPROBES) || defined(CONFIG_FUNCTION_TRACER) #define PAGE_KERNEL_TEXT PAGE_KERNEL_X #else #define PAGE_KERNEL_TEXT PAGE_KERNEL_ROX diff --git a/arch/powerpc/include/asm/book3s/64/pgtable.h b/arch/powerpc/in= clude/asm/book3s/64/pgtable.h index 875730d5af40..cf01b609572f 100644 --- a/arch/powerpc/include/asm/book3s/64/pgtable.h +++ b/arch/powerpc/include/asm/book3s/64/pgtable.h @@ -169,7 +169,7 @@ * on platforms where such control is possible. */ #if defined(CONFIG_KGDB) || defined(CONFIG_XMON) || defined(CONFIG_BDI_SWI= TCH) || \ - defined(CONFIG_KPROBES) || defined(CONFIG_DYNAMIC_FTRACE) + defined(CONFIG_KPROBES) || defined(CONFIG_FUNCTION_TRACER) #define PAGE_KERNEL_TEXT PAGE_KERNEL_X #else #define PAGE_KERNEL_TEXT PAGE_KERNEL_ROX diff --git a/arch/powerpc/include/asm/module.h b/arch/powerpc/include/asm/m= odule.h index 857d9ff24295..e6f5963fd96e 100644 --- a/arch/powerpc/include/asm/module.h +++ b/arch/powerpc/include/asm/module.h @@ -39,7 +39,7 @@ struct mod_arch_specific { unsigned int init_plt_section; #endif /* powerpc64 */ =20 -#ifdef CONFIG_DYNAMIC_FTRACE +#ifdef CONFIG_FUNCTION_TRACER unsigned long tramp; #ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS unsigned long tramp_regs; @@ -68,7 +68,7 @@ struct mod_arch_specific { # endif /* MODULE */ #endif =20 -#ifdef CONFIG_DYNAMIC_FTRACE +#ifdef CONFIG_FUNCTION_TRACER # ifdef MODULE asm(".section .ftrace.tramp,\"ax\",@nobits; .align 3; .previous"); # endif /* MODULE */ diff --git a/arch/powerpc/include/asm/nohash/pgtable.h b/arch/powerpc/inclu= de/asm/nohash/pgtable.h index ac75f4ab0dba..2e8cf217a191 100644 --- a/arch/powerpc/include/asm/nohash/pgtable.h +++ b/arch/powerpc/include/asm/nohash/pgtable.h @@ -23,7 +23,7 @@ * on platforms where such control is possible. */ #if defined(CONFIG_KGDB) || defined(CONFIG_XMON) || defined(CONFIG_BDI_SWI= TCH) ||\ - defined(CONFIG_KPROBES) || defined(CONFIG_DYNAMIC_FTRACE) + defined(CONFIG_KPROBES) || defined(CONFIG_FUNCTION_TRACER) #define PAGE_KERNEL_TEXT PAGE_KERNEL_X #else #define PAGE_KERNEL_TEXT PAGE_KERNEL_ROX diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_3= 2.c index a0432ef46967..2aa368ce21c9 100644 --- a/arch/powerpc/kernel/module_32.c +++ b/arch/powerpc/kernel/module_32.c @@ -39,7 +39,7 @@ static unsigned int count_relocs(const Elf32_Rela *rela, = unsigned int num) r_addend =3D rela[i].r_addend; } =20 -#ifdef CONFIG_DYNAMIC_FTRACE +#ifdef CONFIG_FUNCTION_TRACER _count_relocs++; /* add one for ftrace_caller */ #endif return _count_relocs; @@ -288,7 +288,7 @@ int apply_relocate_add(Elf32_Shdr *sechdrs, return 0; } =20 -#ifdef CONFIG_DYNAMIC_FTRACE +#ifdef CONFIG_FUNCTION_TRACER int module_trampoline_target(struct module *mod, unsigned long addr, unsigned long *target) { diff --git a/arch/powerpc/kernel/module_64.c b/arch/powerpc/kernel/module_6= 4.c index 794720530442..b13a72665eee 100644 --- a/arch/powerpc/kernel/module_64.c +++ b/arch/powerpc/kernel/module_64.c @@ -207,7 +207,7 @@ static unsigned long get_stubs_size(const Elf64_Ehdr *h= dr, } } =20 -#ifdef CONFIG_DYNAMIC_FTRACE +#ifdef CONFIG_FUNCTION_TRACER /* make the trampoline to the ftrace_caller */ relocs++; #ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS @@ -372,7 +372,7 @@ static bool is_mprofile_ftrace_call(const char *name) { if (!strcmp("_mcount", name)) return true; -#ifdef CONFIG_DYNAMIC_FTRACE +#ifdef CONFIG_FUNCTION_TRACER if (!strcmp("ftrace_caller", name)) return true; #ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS @@ -740,7 +740,7 @@ int apply_relocate_add(Elf64_Shdr *sechdrs, return 0; } =20 -#ifdef CONFIG_DYNAMIC_FTRACE +#ifdef CONFIG_FUNCTION_TRACER int module_trampoline_target(struct module *mod, unsigned long addr, unsigned long *target) { diff --git a/arch/powerpc/kernel/trace/Makefile b/arch/powerpc/kernel/trace= /Makefile index fc32ec30b297..af8527538fe4 100644 --- a/arch/powerpc/kernel/trace/Makefile +++ b/arch/powerpc/kernel/trace/Makefile @@ -14,9 +14,7 @@ obj64-$(CONFIG_FUNCTION_TRACER) +=3D ftrace_mprofile.o else obj64-$(CONFIG_FUNCTION_TRACER) +=3D ftrace_64_pg.o endif -obj-$(CONFIG_FUNCTION_TRACER) +=3D ftrace_low.o -obj-$(CONFIG_DYNAMIC_FTRACE) +=3D ftrace.o -obj-$(CONFIG_FUNCTION_GRAPH_TRACER) +=3D ftrace.o +obj-$(CONFIG_FUNCTION_TRACER) +=3D ftrace_low.o ftrace.o obj-$(CONFIG_TRACING) +=3D trace_clock.o =20 obj-$(CONFIG_PPC64) +=3D $(obj64-y) diff --git a/arch/powerpc/kernel/trace/ftrace.c b/arch/powerpc/kernel/trace= /ftrace.c index 2c7e42e439bb..188f59f4ee4a 100644 --- a/arch/powerpc/kernel/trace/ftrace.c +++ b/arch/powerpc/kernel/trace/ftrace.c @@ -28,9 +28,6 @@ #include #include =20 - -#ifdef CONFIG_DYNAMIC_FTRACE - /* * We generally only have a single long_branch tramp and at most 2 or 3 plt * tramps generated. But, we don't use the plt tramps currently. We also a= llot @@ -783,7 +780,6 @@ int __init ftrace_dyn_arch_init(void) return 0; } #endif -#endif /* CONFIG_DYNAMIC_FTRACE */ =20 #ifdef CONFIG_FUNCTION_GRAPH_TRACER =20 --=20 2.35.1 From nobody Sat Jun 20 01:51:50 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 36932C433EF for ; Thu, 24 Mar 2022 14:31:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350974AbiCXOcj (ORCPT ); Thu, 24 Mar 2022 10:32:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350985AbiCXOcf (ORCPT ); Thu, 24 Mar 2022 10:32:35 -0400 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9BABAC904 for ; Thu, 24 Mar 2022 07:30:58 -0700 (PDT) Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4KPSM04rHzz9sV4; Thu, 24 Mar 2022 15:30:52 +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 7Tx_OdezBQfe; Thu, 24 Mar 2022 15:30:52 +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 4KPSLy2rCrz9sTg; Thu, 24 Mar 2022 15:30:50 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 4B8498B780; Thu, 24 Mar 2022 15:30:50 +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 wc8Ix20xu7pd; Thu, 24 Mar 2022 15:30:50 +0100 (CET) Received: from PO20335.IDSI0.si.c-s.fr (unknown [192.168.203.77]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 990748B783; Thu, 24 Mar 2022 15:30:49 +0100 (CET) Received: from PO20335.IDSI0.si.c-s.fr (localhost [127.0.0.1]) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.16.1) with ESMTPS id 22OEUgIN1811722 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 24 Mar 2022 15:30:43 +0100 Received: (from chleroy@localhost) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.17.1/Submit) id 22OEUghe1811721; Thu, 24 Mar 2022 15:30:42 +0100 X-Authentication-Warning: PO20335.IDSI0.si.c-s.fr: chleroy set sender to christophe.leroy@csgroup.eu using -f From: Christophe Leroy To: "Naveen N . Rao" , Steven Rostedt , Ingo Molnar , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman Cc: Christophe Leroy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v1 11/22] powerpc/ftrace: Remove ftrace_plt_tramps[] Date: Thu, 24 Mar 2022 15:30:01 +0100 Message-Id: <28451f97a8cdb81df3815e782cbf7667cb3fc2e1.1648131740.git.christophe.leroy@csgroup.eu> X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1648132151; l=1209; s=20211009; h=from:subject:message-id; bh=dZRIRMj2lQWqilcKJIhxE8xIuJIJKrLrXF3bOa75tG0=; b=Jm5S2lkZJ1ZbTPIGJG7ai1Ps7p6F+hBFwYko30rigipKhirNyFtFQvkWB6tNmfeC4t7ZlaS23HZD 62dwgV8LCupttGxc6AWPs0dK5+GiO6zES0ugxRwoeux3OsVhTHVs X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" ftrace_plt_tramps table is never filled so it is useless. Remove it. Signed-off-by: Christophe Leroy --- arch/powerpc/kernel/trace/ftrace.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/arch/powerpc/kernel/trace/ftrace.c b/arch/powerpc/kernel/trace= /ftrace.c index 188f59f4ee4a..b6c5223e26b2 100644 --- a/arch/powerpc/kernel/trace/ftrace.c +++ b/arch/powerpc/kernel/trace/ftrace.c @@ -250,7 +250,6 @@ static int setup_mcount_compiler_tramp(unsigned long tr= amp) int i; ppc_inst_t op; unsigned long ptr; - static unsigned long ftrace_plt_tramps[NUM_FTRACE_TRAMPS]; =20 /* Is this a known long jump tramp? */ for (i =3D 0; i < NUM_FTRACE_TRAMPS; i++) @@ -259,13 +258,6 @@ static int setup_mcount_compiler_tramp(unsigned long t= ramp) else if (ftrace_tramps[i] =3D=3D tramp) return 0; =20 - /* Is this a known plt tramp? */ - for (i =3D 0; i < NUM_FTRACE_TRAMPS; i++) - if (!ftrace_plt_tramps[i]) - break; - else if (ftrace_plt_tramps[i] =3D=3D tramp) - return -1; - /* New trampoline -- read where this goes */ if (copy_inst_from_kernel_nofault(&op, (void *)tramp)) { pr_debug("Fetching opcode failed.\n"); --=20 2.35.1 From nobody Sat Jun 20 01:51:50 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3CAF1C433F5 for ; Thu, 24 Mar 2022 14:32:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351031AbiCXOeE (ORCPT ); Thu, 24 Mar 2022 10:34:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351084AbiCXOdJ (ORCPT ); Thu, 24 Mar 2022 10:33:09 -0400 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9A95AD108 for ; Thu, 24 Mar 2022 07:31:30 -0700 (PDT) Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4KPSM9104mz9sTp; Thu, 24 Mar 2022 15:31:01 +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 qo1VWAWzjVoN; Thu, 24 Mar 2022 15:31:01 +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 4KPSLy6lM4z9sTq; Thu, 24 Mar 2022 15:30:50 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id D6DEF8B786; Thu, 24 Mar 2022 15:30:50 +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 8Dh_e7lJLxk7; Thu, 24 Mar 2022 15:30:50 +0100 (CET) Received: from PO20335.IDSI0.si.c-s.fr (unknown [192.168.203.77]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 0A2A78B7A9; Thu, 24 Mar 2022 15:30:49 +0100 (CET) Received: from PO20335.IDSI0.si.c-s.fr (localhost [127.0.0.1]) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.16.1) with ESMTPS id 22OEUhhm1811726 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 24 Mar 2022 15:30:43 +0100 Received: (from chleroy@localhost) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.17.1/Submit) id 22OEUh0f1811725; Thu, 24 Mar 2022 15:30:43 +0100 X-Authentication-Warning: PO20335.IDSI0.si.c-s.fr: chleroy set sender to christophe.leroy@csgroup.eu using -f From: Christophe Leroy To: "Naveen N . Rao" , Steven Rostedt , Ingo Molnar , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman Cc: Christophe Leroy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v1 12/22] powerpc/ftrace: Use BRANCH_SET_LINK instead of value 1 Date: Thu, 24 Mar 2022 15:30:02 +0100 Message-Id: <157272d7b716d52fcd05830fa46d24487c80040d.1648131740.git.christophe.leroy@csgroup.eu> X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1648132151; l=800; s=20211009; h=from:subject:message-id; bh=aC7ftZIPVyIcv1nQ2WxxsrICRFi5QRDPh2KvoWv6tO8=; b=PkwjP+WdBQqe9IxACA7Bld2W2plJPs305qntisF32BlHOnX+JQwq6azxMDtMQZpG9bSnOCPmV88/ GZfYEkrzBziI0OVBEkHQdj8FFbroZKjQ3Jf6XsHVFr++g9C7GLYH X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" To make it explicit, use BRANCH_SET_LINK instead of value 1 when calling create_branch(). Signed-off-by: Christophe Leroy --- arch/powerpc/kernel/trace/ftrace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/powerpc/kernel/trace/ftrace.c b/arch/powerpc/kernel/trace= /ftrace.c index b6c5223e26b2..fdc0412c1d8a 100644 --- a/arch/powerpc/kernel/trace/ftrace.c +++ b/arch/powerpc/kernel/trace/ftrace.c @@ -45,7 +45,7 @@ ftrace_call_replace(unsigned long ip, unsigned long addr,= int link) addr =3D ppc_function_entry((void *)addr); =20 /* if (link) set op to 'bl' else 'b' */ - create_branch(&op, (u32 *)ip, addr, link ? 1 : 0); + create_branch(&op, (u32 *)ip, addr, link ? BRANCH_SET_LINK : 0); =20 return op; } --=20 2.35.1 From nobody Sat Jun 20 01:51:50 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5371EC433EF for ; Thu, 24 Mar 2022 14:32:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351008AbiCXOdg (ORCPT ); Thu, 24 Mar 2022 10:33:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38714 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351028AbiCXOcu (ORCPT ); Thu, 24 Mar 2022 10:32:50 -0400 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6717DA27E6 for ; Thu, 24 Mar 2022 07:31:16 -0700 (PDT) Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4KPSM542QVz9sTd; Thu, 24 Mar 2022 15:30:57 +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 E72FP5nJgv9L; Thu, 24 Mar 2022 15:30:57 +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 4KPSLy4mnbz9sTl; Thu, 24 Mar 2022 15:30:50 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 8FB168B780; Thu, 24 Mar 2022 15:30:50 +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 i0hCn0b1i4Nh; Thu, 24 Mar 2022 15:30:50 +0100 (CET) Received: from PO20335.IDSI0.si.c-s.fr (unknown [192.168.203.77]) by messagerie.si.c-s.fr (Postfix) with ESMTP id B68F18B78F; Thu, 24 Mar 2022 15:30:49 +0100 (CET) Received: from PO20335.IDSI0.si.c-s.fr (localhost [127.0.0.1]) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.16.1) with ESMTPS id 22OEUhg11811730 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 24 Mar 2022 15:30:43 +0100 Received: (from chleroy@localhost) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.17.1/Submit) id 22OEUhX11811729; Thu, 24 Mar 2022 15:30:43 +0100 X-Authentication-Warning: PO20335.IDSI0.si.c-s.fr: chleroy set sender to christophe.leroy@csgroup.eu using -f From: Christophe Leroy To: "Naveen N . Rao" , Steven Rostedt , Ingo Molnar , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman Cc: Christophe Leroy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v1 13/22] powerpc/ftrace: Use PPC_RAW_xxx() macros instead of opencoding. Date: Thu, 24 Mar 2022 15:30:03 +0100 Message-Id: X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1648132151; l=3990; s=20211009; h=from:subject:message-id; bh=L4Cwq1gLkMCkjjBN0wT65BKj7kA0es8AXhR8S18nacw=; b=CTgmkiBqRnsX5ISpbGSkjgXwtqAS60f/ixxWPDxoUl4JaGyHR6aEO6Au8r6/0x7Y9g77iUbnZ3tl HFbUsm1wCD5JGw+HhfhMyOdHaeQt2pEEavaALTQeoOppeH2w2Yjx X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" PPC_RAW_xxx() macros are self explanatory and less error prone than open coding. Use them in ftrace.c Signed-off-by: Christophe Leroy --- arch/powerpc/include/asm/ppc-opcode.h | 3 +++ arch/powerpc/kernel/trace/ftrace.c | 32 +++++++++------------------ 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/arch/powerpc/include/asm/ppc-opcode.h b/arch/powerpc/include/a= sm/ppc-opcode.h index 82f1f0041c6f..281754aca0a3 100644 --- a/arch/powerpc/include/asm/ppc-opcode.h +++ b/arch/powerpc/include/asm/ppc-opcode.h @@ -294,6 +294,8 @@ #define PPC_INST_BL 0x48000001 #define PPC_INST_BRANCH_COND 0x40800000 =20 +#define PPC_INST_OFFSET24_MASK 0x03fffffc + /* Prefixes */ #define PPC_INST_LFS 0xc0000000 #define PPC_INST_STFS 0xd0000000 @@ -572,6 +574,7 @@ #define PPC_RAW_EIEIO() (0x7c0006ac) =20 #define PPC_RAW_BRANCH(addr) (PPC_INST_BRANCH | ((addr) & 0x03fffffc)) +#define PPC_RAW_BL(offset) (0x48000001 | ((offset) & PPC_INST_OFFSET24_MA= SK)) =20 /* Deal with instructions that older assemblers aren't aware of */ #define PPC_BCCTR_FLUSH stringify_in_c(.long PPC_INST_BCCTR_FLUSH) diff --git a/arch/powerpc/kernel/trace/ftrace.c b/arch/powerpc/kernel/trace= /ftrace.c index fdc0412c1d8a..afb1d12838c9 100644 --- a/arch/powerpc/kernel/trace/ftrace.c +++ b/arch/powerpc/kernel/trace/ftrace.c @@ -90,19 +90,19 @@ static int test_24bit_addr(unsigned long ip, unsigned l= ong addr) =20 static int is_bl_op(ppc_inst_t op) { - return (ppc_inst_val(op) & 0xfc000003) =3D=3D 0x48000001; + return (ppc_inst_val(op) & ~PPC_INST_OFFSET24_MASK) =3D=3D PPC_RAW_BL(0); } =20 static int is_b_op(ppc_inst_t op) { - return (ppc_inst_val(op) & 0xfc000003) =3D=3D 0x48000000; + return (ppc_inst_val(op) & ~PPC_INST_OFFSET24_MASK) =3D=3D PPC_RAW_BRANCH= (0); } =20 static unsigned long find_bl_target(unsigned long ip, ppc_inst_t op) { int offset; =20 - offset =3D (ppc_inst_val(op) & 0x03fffffc); + offset =3D (ppc_inst_val(op) & PPC_INST_OFFSET24_MASK); /* make it signed */ if (offset & 0x02000000) offset |=3D 0xfe000000; @@ -182,7 +182,7 @@ __ftrace_make_nop(struct module *mod, * Use a b +8 to jump over the load. */ =20 - pop =3D ppc_inst(PPC_INST_BRANCH | 8); /* b +8 */ + pop =3D ppc_inst(PPC_RAW_BRANCH(8)); /* b +8 */ =20 /* * Check what is in the next instruction. We can see ld r2,40(r1), but @@ -394,17 +394,8 @@ int ftrace_make_nop(struct module *mod, static int expected_nop_sequence(void *ip, ppc_inst_t op0, ppc_inst_t op1) { - /* - * We expect to see: - * - * b +8 - * ld r2,XX(r1) - * - * The load offset is different depending on the ABI. For simplicity - * just mask it out when doing the compare. - */ - if (!ppc_inst_equal(op0, ppc_inst(0x48000008)) || - (ppc_inst_val(op1) & 0xffff0000) !=3D 0xe8410000) + if (!ppc_inst_equal(op0, ppc_inst(PPC_RAW_BRANCH(8))) || + !ppc_inst_equal(op1, ppc_inst(PPC_INST_LD_TOC))) return 0; return 1; } @@ -412,7 +403,6 @@ expected_nop_sequence(void *ip, ppc_inst_t op0, ppc_ins= t_t op1) static int expected_nop_sequence(void *ip, ppc_inst_t op0, ppc_inst_t op1) { - /* look for patched "NOP" on ppc64 with -mprofile-kernel or ppc32 */ if (!ppc_inst_equal(op0, ppc_inst(PPC_RAW_NOP()))) return 0; return 1; @@ -738,11 +728,11 @@ int __init ftrace_dyn_arch_init(void) int i; unsigned int *tramp[] =3D { ftrace_tramp_text, ftrace_tramp_init }; u32 stub_insns[] =3D { - 0xe98d0000 | PACATOC, /* ld r12,PACATOC(r13) */ - 0x3d8c0000, /* addis r12,r12, */ - 0x398c0000, /* addi r12,r12, */ - 0x7d8903a6, /* mtctr r12 */ - 0x4e800420, /* bctr */ + PPC_RAW_LD(_R12, _R13, PACATOC), + PPC_RAW_ADDIS(_R12, _R12, 0), + PPC_RAW_ADDIS(_R12, _R12, 0), + PPC_RAW_MTCTR(_R12), + PPC_RAW_BCTR() }; #ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS unsigned long addr =3D ppc_global_function_entry((void *)ftrace_regs_call= er); --=20 2.35.1 From nobody Sat Jun 20 01:51:50 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D9433C433F5 for ; Thu, 24 Mar 2022 14:30:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350957AbiCXOc2 (ORCPT ); Thu, 24 Mar 2022 10:32:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350103AbiCXOcY (ORCPT ); Thu, 24 Mar 2022 10:32:24 -0400 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 214F0A27E5 for ; Thu, 24 Mar 2022 07:30:51 -0700 (PDT) Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4KPSLy3NbKz9sTj; Thu, 24 Mar 2022 15:30:50 +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 I6_Zpiq0aEnR; Thu, 24 Mar 2022 15:30:50 +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 4KPSLy2cZ4z9sTd; Thu, 24 Mar 2022 15:30:50 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 3E0208B7AB; Thu, 24 Mar 2022 15:30:50 +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 Z1xOuLcmgbBw; Thu, 24 Mar 2022 15:30:50 +0100 (CET) Received: from PO20335.IDSI0.si.c-s.fr (unknown [192.168.203.77]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 8F9198B780; Thu, 24 Mar 2022 15:30:49 +0100 (CET) Received: from PO20335.IDSI0.si.c-s.fr (localhost [127.0.0.1]) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.16.1) with ESMTPS id 22OEUhVD1811734 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 24 Mar 2022 15:30:43 +0100 Received: (from chleroy@localhost) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.17.1/Submit) id 22OEUhmj1811733; Thu, 24 Mar 2022 15:30:43 +0100 X-Authentication-Warning: PO20335.IDSI0.si.c-s.fr: chleroy set sender to christophe.leroy@csgroup.eu using -f From: Christophe Leroy To: "Naveen N . Rao" , Steven Rostedt , Ingo Molnar , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman Cc: Christophe Leroy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v1 14/22] powerpc/ftrace: Use size macro instead of opencoding Date: Thu, 24 Mar 2022 15:30:04 +0100 Message-Id: <056a239ae39c9abe65a240650055fa631be6f703.1648131740.git.christophe.leroy@csgroup.eu> X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1648132151; l=734; s=20211009; h=from:subject:message-id; bh=RUXVTqzUfeMqpyoa0teddcGlImseatgcJSYZfDaLf2U=; b=dFJxV57+nQL637ye6e6KyXvKHGLxLIAYiwjtvfKG6VHN8jWydK+abm223BNsU8P5uVXcqqgg29aD SekSoEzjCN4KLQENAgTkqPuJRnRzVioZJGuoKnB88PztSBoTNpyx X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 0x80000000 is SZ_2G. Use it. Signed-off-by: Christophe Leroy --- arch/powerpc/kernel/trace/ftrace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/powerpc/kernel/trace/ftrace.c b/arch/powerpc/kernel/trace= /ftrace.c index afb1d12838c9..15e0746806f8 100644 --- a/arch/powerpc/kernel/trace/ftrace.c +++ b/arch/powerpc/kernel/trace/ftrace.c @@ -741,7 +741,7 @@ int __init ftrace_dyn_arch_init(void) #endif long reladdr =3D addr - kernel_toc_addr(); =20 - if (reladdr > 0x7FFFFFFF || reladdr < -(0x80000000L)) { + if (reladdr >=3D SZ_2G || reladdr < -SZ_2G) { pr_err("Address of %ps out of range of kernel_toc.\n", (void *)addr); return -1; --=20 2.35.1 From nobody Sat Jun 20 01:51:50 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0417BC433F5 for ; Thu, 24 Mar 2022 14:32:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351019AbiCXOeQ (ORCPT ); Thu, 24 Mar 2022 10:34:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351134AbiCXOdR (ORCPT ); Thu, 24 Mar 2022 10:33:17 -0400 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D854FA27DB for ; Thu, 24 Mar 2022 07:31:45 -0700 (PDT) Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4KPSMG1QSwz9sTv; Thu, 24 Mar 2022 15:31:06 +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 IGDEJ7dX8uNF; Thu, 24 Mar 2022 15:31:06 +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 4KPSLz0NDXz9sTy; Thu, 24 Mar 2022 15:30:51 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id ED49B8B78C; Thu, 24 Mar 2022 15:30:50 +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 lFfgi1jTid_n; Thu, 24 Mar 2022 15:30:50 +0100 (CET) Received: from PO20335.IDSI0.si.c-s.fr (unknown [192.168.203.77]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 087988B7A7; Thu, 24 Mar 2022 15:30:49 +0100 (CET) Received: from PO20335.IDSI0.si.c-s.fr (localhost [127.0.0.1]) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.16.1) with ESMTPS id 22OEUhEb1811738 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 24 Mar 2022 15:30:43 +0100 Received: (from chleroy@localhost) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.17.1/Submit) id 22OEUhrT1811737; Thu, 24 Mar 2022 15:30:43 +0100 X-Authentication-Warning: PO20335.IDSI0.si.c-s.fr: chleroy set sender to christophe.leroy@csgroup.eu using -f From: Christophe Leroy To: "Naveen N . Rao" , Steven Rostedt , Ingo Molnar , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman Cc: Christophe Leroy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v1 15/22] powerpc/ftrace: Simplify expected_nop_sequence() Date: Thu, 24 Mar 2022 15:30:05 +0100 Message-Id: X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1648132151; l=1538; s=20211009; h=from:subject:message-id; bh=1DO4SNrhdDjZCmpTrZccuhk4GnTHpfT7IFl/43Z7Mzk=; b=t1sodoXfuNbA+ivfoI3lfiedDazUkAAiCrLsklOB7EZxEyTbmrotABfxcs8nUfrA0tBOezSZi/8l TTIzt2utCiaguP+bDLpODCey2X7U/QBRCYT6rkRJ8xzLliYQLVVw X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Avoid ifdefs around expected_nop_sequence(). While at it make it a bool. Signed-off-by: Christophe Leroy --- arch/powerpc/kernel/trace/ftrace.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/arch/powerpc/kernel/trace/ftrace.c b/arch/powerpc/kernel/trace= /ftrace.c index 15e0746806f8..ffedf8c82ea8 100644 --- a/arch/powerpc/kernel/trace/ftrace.c +++ b/arch/powerpc/kernel/trace/ftrace.c @@ -390,24 +390,14 @@ int ftrace_make_nop(struct module *mod, * They should effectively be a NOP, and follow formal constraints, * depending on the ABI. Return false if they don't. */ -#ifndef CONFIG_DYNAMIC_FTRACE_WITH_REGS -static int -expected_nop_sequence(void *ip, ppc_inst_t op0, ppc_inst_t op1) -{ - if (!ppc_inst_equal(op0, ppc_inst(PPC_RAW_BRANCH(8))) || - !ppc_inst_equal(op1, ppc_inst(PPC_INST_LD_TOC))) - return 0; - return 1; -} -#else -static int -expected_nop_sequence(void *ip, ppc_inst_t op0, ppc_inst_t op1) +static bool expected_nop_sequence(void *ip, ppc_inst_t op0, ppc_inst_t op1) { - if (!ppc_inst_equal(op0, ppc_inst(PPC_RAW_NOP()))) - return 0; - return 1; + if (IS_ENABLED(CONFIG_DYNAMIC_FTRACE_WITH_REGS)) + return ppc_inst_equal(op0, ppc_inst(PPC_RAW_NOP())); + else + return ppc_inst_equal(op0, ppc_inst(PPC_RAW_BRANCH(8))) && + ppc_inst_equal(op1, ppc_inst(PPC_INST_LD_TOC)); } -#endif =20 static int __ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr) --=20 2.35.1 From nobody Sat Jun 20 01:51:50 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5F905C433EF for ; Thu, 24 Mar 2022 14:32:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350991AbiCXOdb (ORCPT ); Thu, 24 Mar 2022 10:33:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38450 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351011AbiCXOcq (ORCPT ); Thu, 24 Mar 2022 10:32:46 -0400 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65F1DAC924 for ; Thu, 24 Mar 2022 07:31:12 -0700 (PDT) Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4KPSM41byKz9sTk; Thu, 24 Mar 2022 15:30:56 +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 jeWIDnk8A2ig; Thu, 24 Mar 2022 15:30:56 +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 4KPSLy4QSXz9sTd; Thu, 24 Mar 2022 15:30:50 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 840CC8B763; Thu, 24 Mar 2022 15:30:50 +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 HVoIDf7g5BBb; Thu, 24 Mar 2022 15:30:50 +0100 (CET) Received: from PO20335.IDSI0.si.c-s.fr (unknown [192.168.203.77]) by messagerie.si.c-s.fr (Postfix) with ESMTP id A57548B78B; Thu, 24 Mar 2022 15:30:49 +0100 (CET) Received: from PO20335.IDSI0.si.c-s.fr (localhost [127.0.0.1]) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.16.1) with ESMTPS id 22OEUhFQ1811742 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 24 Mar 2022 15:30:43 +0100 Received: (from chleroy@localhost) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.17.1/Submit) id 22OEUhLs1811741; Thu, 24 Mar 2022 15:30:43 +0100 X-Authentication-Warning: PO20335.IDSI0.si.c-s.fr: chleroy set sender to christophe.leroy@csgroup.eu using -f From: Christophe Leroy To: "Naveen N . Rao" , Steven Rostedt , Ingo Molnar , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman Cc: Christophe Leroy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v1 16/22] powerpc/ftrace: Minimise number of #ifdefs Date: Thu, 24 Mar 2022 15:30:06 +0100 Message-Id: <7ef4015badd5f1861cfc327a7641c84e0e5630ca.1648131740.git.christophe.leroy@csgroup.eu> X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1648132151; l=14141; s=20211009; h=from:subject:message-id; bh=xNDuxmOg37Uw0k7n3Xp9UFxk0u4Ye+KrXTF3IF7X/Bs=; b=WPkKV/kUoGre81+Uh0uezXtxErpcZUNIgEWY+QXRJIvKD8hIuYVH//GuIoRyvVny6LNmYbB20AyO TMSAdwf2DkvW6L7qTba2NiCo3fYGXeRJUk08IE5f7BqW5uIdg4CK X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" A lot of #ifdefs can be replaced by IS_ENABLED() Do so. This requires to have kernel_toc_addr() defined at all time and PPC_INST_LD_TOC as well. Signed-off-by: Christophe Leroy --- arch/powerpc/include/asm/code-patching.h | 2 - arch/powerpc/include/asm/module.h | 2 - arch/powerpc/include/asm/sections.h | 24 +-- arch/powerpc/kernel/trace/ftrace.c | 201 ++++++++++++----------- 4 files changed, 113 insertions(+), 116 deletions(-) diff --git a/arch/powerpc/include/asm/code-patching.h b/arch/powerpc/includ= e/asm/code-patching.h index 4260e89f62b1..071fcbec31c5 100644 --- a/arch/powerpc/include/asm/code-patching.h +++ b/arch/powerpc/include/asm/code-patching.h @@ -217,7 +217,6 @@ static inline unsigned long ppc_kallsyms_lookup_name(co= nst char *name) return addr; } =20 -#ifdef CONFIG_PPC64 /* * Some instruction encodings commonly used in dynamic ftracing * and function live patching. @@ -234,6 +233,5 @@ static inline unsigned long ppc_kallsyms_lookup_name(co= nst char *name) =20 /* usually preceded by a mflr r0 */ #define PPC_INST_STD_LR PPC_RAW_STD(_R0, _R1, PPC_LR_STKOFF) -#endif /* CONFIG_PPC64 */ =20 #endif /* _ASM_POWERPC_CODE_PATCHING_H */ diff --git a/arch/powerpc/include/asm/module.h b/arch/powerpc/include/asm/m= odule.h index e6f5963fd96e..700d7ecd9012 100644 --- a/arch/powerpc/include/asm/module.h +++ b/arch/powerpc/include/asm/module.h @@ -41,9 +41,7 @@ struct mod_arch_specific { =20 #ifdef CONFIG_FUNCTION_TRACER unsigned long tramp; -#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS unsigned long tramp_regs; -#endif #endif =20 /* List of BUG addresses, source line numbers and filenames */ diff --git a/arch/powerpc/include/asm/sections.h b/arch/powerpc/include/asm= /sections.h index 8be2c491c733..6980eaeb16fe 100644 --- a/arch/powerpc/include/asm/sections.h +++ b/arch/powerpc/include/asm/sections.h @@ -29,18 +29,6 @@ extern char start_virt_trampolines[]; extern char end_virt_trampolines[]; #endif =20 -/* - * This assumes the kernel is never compiled -mcmodel=3Dsmall or - * the total .toc is always less than 64k. - */ -static inline unsigned long kernel_toc_addr(void) -{ - unsigned long toc_ptr; - - asm volatile("mr %0, 2" : "=3Dr" (toc_ptr)); - return toc_ptr; -} - static inline int overlaps_interrupt_vector_text(unsigned long start, unsigned long end) { @@ -60,5 +48,17 @@ static inline int overlaps_kernel_text(unsigned long sta= rt, unsigned long end) =20 #endif =20 +/* + * This assumes the kernel is never compiled -mcmodel=3Dsmall or + * the total .toc is always less than 64k. + */ +static inline unsigned long kernel_toc_addr(void) +{ + unsigned long toc_ptr; + + asm volatile("mr %0, 2" : "=3Dr" (toc_ptr)); + return toc_ptr; +} + #endif /* __KERNEL__ */ #endif /* _ASM_POWERPC_SECTIONS_H */ diff --git a/arch/powerpc/kernel/trace/ftrace.c b/arch/powerpc/kernel/trace= /ftrace.c index ffedf8c82ea8..4dd30e396026 100644 --- a/arch/powerpc/kernel/trace/ftrace.c +++ b/arch/powerpc/kernel/trace/ftrace.c @@ -150,55 +150,55 @@ __ftrace_make_nop(struct module *mod, return -EINVAL; } =20 - /* When using -mkernel_profile or PPC32 there is no load to jump over */ - pop =3D ppc_inst(PPC_RAW_NOP()); + if (IS_ENABLED(CONFIG_MPROFILE_KERNEL)) { + /* When using -mkernel_profile or PPC32 there is no load to jump over */ + pop =3D ppc_inst(PPC_RAW_NOP()); =20 -#ifdef CONFIG_PPC64 -#ifdef CONFIG_MPROFILE_KERNEL - if (copy_inst_from_kernel_nofault(&op, (void *)(ip - 4))) { - pr_err("Fetching instruction at %lx failed.\n", ip - 4); - return -EFAULT; - } + if (copy_inst_from_kernel_nofault(&op, (void *)(ip - 4))) { + pr_err("Fetching instruction at %lx failed.\n", ip - 4); + return -EFAULT; + } =20 - /* We expect either a mflr r0, or a std r0, LRSAVE(r1) */ - if (!ppc_inst_equal(op, ppc_inst(PPC_RAW_MFLR(_R0))) && - !ppc_inst_equal(op, ppc_inst(PPC_INST_STD_LR))) { - pr_err("Unexpected instruction %s around bl _mcount\n", - ppc_inst_as_str(op)); - return -EINVAL; - } -#else - /* - * Our original call site looks like: - * - * bl - * ld r2,XX(r1) - * - * Milton Miller pointed out that we can not simply nop the branch. - * If a task was preempted when calling a trace function, the nops - * will remove the way to restore the TOC in r2 and the r2 TOC will - * get corrupted. - * - * Use a b +8 to jump over the load. - */ + /* We expect either a mflr r0, or a std r0, LRSAVE(r1) */ + if (!ppc_inst_equal(op, ppc_inst(PPC_RAW_MFLR(_R0))) && + !ppc_inst_equal(op, ppc_inst(PPC_INST_STD_LR))) { + pr_err("Unexpected instruction %s around bl _mcount\n", + ppc_inst_as_str(op)); + return -EINVAL; + } + } else if (IS_ENABLED(CONFIG_PPC64)) { + /* + * Our original call site looks like: + * + * bl + * ld r2,XX(r1) + * + * Milton Miller pointed out that we can not simply nop the branch. + * If a task was preempted when calling a trace function, the nops + * will remove the way to restore the TOC in r2 and the r2 TOC will + * get corrupted. + * + * Use a b +8 to jump over the load. + */ =20 - pop =3D ppc_inst(PPC_RAW_BRANCH(8)); /* b +8 */ + pop =3D ppc_inst(PPC_RAW_BRANCH(8)); /* b +8 */ =20 - /* - * Check what is in the next instruction. We can see ld r2,40(r1), but - * on first pass after boot we will see mflr r0. - */ - if (copy_inst_from_kernel_nofault(&op, (void *)(ip + 4))) { - pr_err("Fetching op failed.\n"); - return -EFAULT; - } + /* + * Check what is in the next instruction. We can see ld r2,40(r1), but + * on first pass after boot we will see mflr r0. + */ + if (copy_inst_from_kernel_nofault(&op, (void *)(ip + 4))) { + pr_err("Fetching op failed.\n"); + return -EFAULT; + } =20 - if (!ppc_inst_equal(op, ppc_inst(PPC_INST_LD_TOC))) { - pr_err("Expected %08lx found %s\n", PPC_INST_LD_TOC, ppc_inst_as_str(op)= ); - return -EINVAL; + if (!ppc_inst_equal(op, ppc_inst(PPC_INST_LD_TOC))) { + pr_err("Expected %08lx found %s\n", PPC_INST_LD_TOC, ppc_inst_as_str(op= )); + return -EINVAL; + } + } else { + pop =3D ppc_inst(PPC_RAW_NOP()); } -#endif /* CONFIG_MPROFILE_KERNEL */ -#endif /* PPC64 */ =20 if (patch_instruction((u32 *)ip, pop)) { pr_err("Patching NOP failed.\n"); @@ -207,6 +207,11 @@ __ftrace_make_nop(struct module *mod, =20 return 0; } +#else +static int __ftrace_make_nop(struct module *mod, struct dyn_ftrace *rec, u= nsigned long addr) +{ + return 0; +} #endif /* CONFIG_MODULES */ =20 static unsigned long find_ftrace_tramp(unsigned long ip) @@ -279,11 +284,11 @@ static int setup_mcount_compiler_tramp(unsigned long = tramp) } =20 /* Let's re-write the tramp to go to ftrace_[regs_]caller */ -#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS - ptr =3D ppc_global_function_entry((void *)ftrace_regs_caller); -#else - ptr =3D ppc_global_function_entry((void *)ftrace_caller); -#endif + if (IS_ENABLED(CONFIG_DYNAMIC_FTRACE_WITH_REGS)) + ptr =3D ppc_global_function_entry((void *)ftrace_regs_caller); + else + ptr =3D ppc_global_function_entry((void *)ftrace_caller); + if (patch_branch((u32 *)tramp, ptr, 0)) { pr_debug("REL24 out of range!\n"); return -1; @@ -352,10 +357,12 @@ int ftrace_make_nop(struct module *mod, old =3D ftrace_call_replace(ip, addr, 1); new =3D ppc_inst(PPC_RAW_NOP()); return ftrace_modify_code(ip, old, new); - } else if (core_kernel_text(ip)) + } else if (core_kernel_text(ip)) { return __ftrace_make_nop_kernel(rec, addr); + } else if (!IS_ENABLED(CONFIG_MODULES)) { + return -EINVAL; + } =20 -#ifdef CONFIG_MODULES /* * Out of range jumps are called from modules. * We should either already have a pointer to the module @@ -378,10 +385,6 @@ int ftrace_make_nop(struct module *mod, mod =3D rec->arch.mod; =20 return __ftrace_make_nop(mod, rec, addr); -#else - /* We should not get here without modules */ - return -EINVAL; -#endif /* CONFIG_MODULES */ } =20 #ifdef CONFIG_MODULES @@ -411,10 +414,9 @@ __ftrace_make_call(struct dyn_ftrace *rec, unsigned lo= ng addr) if (copy_inst_from_kernel_nofault(op, ip)) return -EFAULT; =20 -#ifndef CONFIG_DYNAMIC_FTRACE_WITH_REGS - if (copy_inst_from_kernel_nofault(op + 1, ip + 4)) + if (!IS_ENABLED(CONFIG_DYNAMIC_FTRACE_WITH_REGS) && + copy_inst_from_kernel_nofault(op + 1, ip + 4)) return -EFAULT; -#endif =20 if (!expected_nop_sequence(ip, op[0], op[1])) { pr_err("Unexpected call sequence at %p: %s %s\n", @@ -423,20 +425,15 @@ __ftrace_make_call(struct dyn_ftrace *rec, unsigned l= ong addr) } =20 /* If we never set up ftrace trampoline(s), then bail */ -#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS - if (!mod->arch.tramp || !mod->arch.tramp_regs) { -#else - if (!mod->arch.tramp) { -#endif + if (!mod->arch.tramp || + (IS_ENABLED(CONFIG_DYNAMIC_FTRACE_WITH_REGS) && !mod->arch.tramp_regs= )) { pr_err("No ftrace trampoline\n"); return -EINVAL; } =20 -#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS - if (rec->flags & FTRACE_FL_REGS) + if (IS_ENABLED(CONFIG_DYNAMIC_FTRACE_WITH_REGS) && rec->flags & FTRACE_FL= _REGS) tramp =3D mod->arch.tramp_regs; else -#endif tramp =3D mod->arch.tramp; =20 if (module_trampoline_target(mod, tramp, &ptr)) { @@ -460,6 +457,11 @@ __ftrace_make_call(struct dyn_ftrace *rec, unsigned lo= ng addr) =20 return 0; } +#else +static int __ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr) +{ + return 0; +} #endif /* CONFIG_MODULES */ =20 static int __ftrace_make_call_kernel(struct dyn_ftrace *rec, unsigned long= addr) @@ -472,16 +474,12 @@ static int __ftrace_make_call_kernel(struct dyn_ftrac= e *rec, unsigned long addr) entry =3D ppc_global_function_entry((void *)ftrace_caller); ptr =3D ppc_global_function_entry((void *)addr); =20 - if (ptr !=3D entry) { -#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS + if (ptr !=3D entry && IS_ENABLED(CONFIG_DYNAMIC_FTRACE_WITH_REGS)) entry =3D ppc_global_function_entry((void *)ftrace_regs_caller); - if (ptr !=3D entry) { -#endif - pr_err("Unknown ftrace addr to patch: %ps\n", (void *)ptr); - return -EINVAL; -#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS - } -#endif + + if (ptr !=3D entry) { + pr_err("Unknown ftrace addr to patch: %ps\n", (void *)ptr); + return -EINVAL; } =20 /* Make sure we have a nop */ @@ -524,10 +522,13 @@ int ftrace_make_call(struct dyn_ftrace *rec, unsigned= long addr) old =3D ppc_inst(PPC_RAW_NOP()); new =3D ftrace_call_replace(ip, addr, 1); return ftrace_modify_code(ip, old, new); - } else if (core_kernel_text(ip)) + } else if (core_kernel_text(ip)) { return __ftrace_make_call_kernel(rec, addr); + } else if (!IS_ENABLED(CONFIG_MODULES)) { + /* We should not get here without modules */ + return -EINVAL; + } =20 -#ifdef CONFIG_MODULES /* * Out of range jumps are called from modules. * Being that we are converting from nop, it had better @@ -539,10 +540,6 @@ int ftrace_make_call(struct dyn_ftrace *rec, unsigned = long addr) } =20 return __ftrace_make_call(rec, addr); -#else - /* We should not get here without modules */ - return -EINVAL; -#endif /* CONFIG_MODULES */ } =20 #ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS @@ -633,6 +630,11 @@ __ftrace_modify_call(struct dyn_ftrace *rec, unsigned = long old_addr, =20 return 0; } +#else +static int __ftrace_modify_call(struct dyn_ftrace *rec, unsigned long old_= addr, unsigned long addr) +{ + return 0; +} #endif =20 int ftrace_modify_call(struct dyn_ftrace *rec, unsigned long old_addr, @@ -657,9 +659,11 @@ int ftrace_modify_call(struct dyn_ftrace *rec, unsigne= d long old_addr, * variant, so there is nothing to do here */ return 0; + } else if (!IS_ENABLED(CONFIG_MODULES)) { + /* We should not get here without modules */ + return -EINVAL; } =20 -#ifdef CONFIG_MODULES /* * Out of range jumps are called from modules. */ @@ -669,10 +673,6 @@ int ftrace_modify_call(struct dyn_ftrace *rec, unsigne= d long old_addr, } =20 return __ftrace_modify_call(rec, old_addr, addr); -#else - /* We should not get here without modules */ - return -EINVAL; -#endif /* CONFIG_MODULES */ } #endif =20 @@ -686,15 +686,13 @@ int ftrace_update_ftrace_func(ftrace_func_t func) new =3D ftrace_call_replace(ip, (unsigned long)func, 1); ret =3D ftrace_modify_code(ip, old, new); =20 -#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS /* Also update the regs callback function */ - if (!ret) { + if (IS_ENABLED(CONFIG_DYNAMIC_FTRACE_WITH_REGS) && !ret) { ip =3D (unsigned long)(&ftrace_regs_call); old =3D ppc_inst_read((u32 *)&ftrace_regs_call); new =3D ftrace_call_replace(ip, (unsigned long)func, 1); ret =3D ftrace_modify_code(ip, old, new); } -#endif =20 return ret; } @@ -710,6 +708,9 @@ void arch_ftrace_update_code(int command) =20 #ifdef CONFIG_PPC64 #define PACATOC offsetof(struct paca_struct, kernel_toc) +#else +#define PACATOC 0 +#endif =20 extern unsigned int ftrace_tramp_text[], ftrace_tramp_init[]; =20 @@ -724,12 +725,18 @@ int __init ftrace_dyn_arch_init(void) PPC_RAW_MTCTR(_R12), PPC_RAW_BCTR() }; -#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS - unsigned long addr =3D ppc_global_function_entry((void *)ftrace_regs_call= er); -#else - unsigned long addr =3D ppc_global_function_entry((void *)ftrace_caller); -#endif - long reladdr =3D addr - kernel_toc_addr(); + unsigned long addr; + long reladdr; + + if (IS_ENABLED(CONFIG_PPC32)) + return 0; + + if (IS_ENABLED(CONFIG_DYNAMIC_FTRACE_WITH_REGS)) + addr =3D ppc_global_function_entry((void *)ftrace_regs_caller); + else + addr =3D ppc_global_function_entry((void *)ftrace_caller); + + reladdr =3D addr - kernel_toc_addr(); =20 if (reladdr >=3D SZ_2G || reladdr < -SZ_2G) { pr_err("Address of %ps out of range of kernel_toc.\n", @@ -746,12 +753,6 @@ int __init ftrace_dyn_arch_init(void) =20 return 0; } -#else -int __init ftrace_dyn_arch_init(void) -{ - return 0; -} -#endif =20 #ifdef CONFIG_FUNCTION_GRAPH_TRACER =20 --=20 2.35.1 From nobody Sat Jun 20 01:51:50 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A4530C433F5 for ; Thu, 24 Mar 2022 14:32:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351027AbiCXOdv (ORCPT ); Thu, 24 Mar 2022 10:33:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351085AbiCXOdK (ORCPT ); Thu, 24 Mar 2022 10:33:10 -0400 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0455A27DD for ; Thu, 24 Mar 2022 07:31:33 -0700 (PDT) Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4KPSMB0qj8z9sTq; Thu, 24 Mar 2022 15:31:02 +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 4fwzZXCaaTDa; Thu, 24 Mar 2022 15:31:02 +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 4KPSLy6mjrz9sTr; Thu, 24 Mar 2022 15:30:50 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id D09408B781; Thu, 24 Mar 2022 15:30:50 +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 81EnaXSMAd2w; Thu, 24 Mar 2022 15:30:50 +0100 (CET) Received: from PO20335.IDSI0.si.c-s.fr (unknown [192.168.203.77]) by messagerie.si.c-s.fr (Postfix) with ESMTP id D876C8B799; Thu, 24 Mar 2022 15:30:49 +0100 (CET) Received: from PO20335.IDSI0.si.c-s.fr (localhost [127.0.0.1]) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.16.1) with ESMTPS id 22OEUim51811746 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 24 Mar 2022 15:30:44 +0100 Received: (from chleroy@localhost) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.17.1/Submit) id 22OEUiBn1811745; Thu, 24 Mar 2022 15:30:44 +0100 X-Authentication-Warning: PO20335.IDSI0.si.c-s.fr: chleroy set sender to christophe.leroy@csgroup.eu using -f From: Christophe Leroy To: "Naveen N . Rao" , Steven Rostedt , Ingo Molnar , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman Cc: Christophe Leroy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v1 17/22] powerpc/inst: Add __copy_inst_from_kernel_nofault() Date: Thu, 24 Mar 2022 15:30:07 +0100 Message-Id: <3ff47a837d8dfb6305592f3d8caef6aa2d85fbc2.1648131740.git.christophe.leroy@csgroup.eu> X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1648132151; l=1534; s=20211009; h=from:subject:message-id; bh=uNUWZzzzPfrKXF6jD9unCulUYAF0cNf3EZC4MAgTHXc=; b=EGbvzHqpKG4FYz/NL7buG6q98rlXZaZujqm1KTTL7aeMlPD3bSu65ZmJjbUEWDyz+vsGtgM8KoCP NtpwT7sZAbOEMmExdeDaXGk21cAHDplor+sHP/FAsTzMlQP+g2dZ X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" On the same model as get_user() versus __get_user(), introduce __copy_inst_from_kernel_nofault() which doesn't check address. To be used by callers that have already checked that the adress is a kernel address. Signed-off-by: Christophe Leroy --- arch/powerpc/include/asm/inst.h | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/arch/powerpc/include/asm/inst.h b/arch/powerpc/include/asm/ins= t.h index 80b6d74146c6..b49aae9f6f27 100644 --- a/arch/powerpc/include/asm/inst.h +++ b/arch/powerpc/include/asm/inst.h @@ -158,13 +158,10 @@ static inline char *__ppc_inst_as_str(char str[PPC_IN= ST_STR_LEN], ppc_inst_t x) __str; \ }) =20 -static inline int copy_inst_from_kernel_nofault(ppc_inst_t *inst, u32 *src) +static inline int __copy_inst_from_kernel_nofault(ppc_inst_t *inst, u32 *s= rc) { unsigned int val, suffix; =20 - if (unlikely(!is_kernel_addr((unsigned long)src))) - return -ERANGE; - /* See https://github.com/ClangBuiltLinux/linux/issues/1521 */ #if defined(CONFIG_CC_IS_CLANG) && CONFIG_CLANG_VERSION < 140000 val =3D suffix =3D 0; @@ -181,4 +178,12 @@ static inline int copy_inst_from_kernel_nofault(ppc_in= st_t *inst, u32 *src) return -EFAULT; } =20 +static inline int copy_inst_from_kernel_nofault(ppc_inst_t *inst, u32 *src) +{ + if (unlikely(!is_kernel_addr((unsigned long)src))) + return -ERANGE; + + return __copy_inst_from_kernel_nofault(inst, src); +} + #endif /* _ASM_POWERPC_INST_H */ --=20 2.35.1 From nobody Sat Jun 20 01:51:50 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3A39DC433EF for ; Thu, 24 Mar 2022 14:31:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350967AbiCXOc3 (ORCPT ); Thu, 24 Mar 2022 10:32:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350232AbiCXOc1 (ORCPT ); Thu, 24 Mar 2022 10:32:27 -0400 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9147AA27DB for ; Thu, 24 Mar 2022 07:30:55 -0700 (PDT) Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4KPSLz0wTJz9sV3; Thu, 24 Mar 2022 15:30:51 +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 xITyY5qnQeet; Thu, 24 Mar 2022 15:30:51 +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 4KPSLy2b5Kz9sTc; Thu, 24 Mar 2022 15:30:50 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 3DE9C8B7AA; Thu, 24 Mar 2022 15:30:50 +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 Wra1eX0Kb7pj; Thu, 24 Mar 2022 15:30:50 +0100 (CET) Received: from PO20335.IDSI0.si.c-s.fr (unknown [192.168.203.77]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 924DD8B781; Thu, 24 Mar 2022 15:30:49 +0100 (CET) Received: from PO20335.IDSI0.si.c-s.fr (localhost [127.0.0.1]) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.16.1) with ESMTPS id 22OEUiNo1811750 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 24 Mar 2022 15:30:44 +0100 Received: (from chleroy@localhost) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.17.1/Submit) id 22OEUiL81811749; Thu, 24 Mar 2022 15:30:44 +0100 X-Authentication-Warning: PO20335.IDSI0.si.c-s.fr: chleroy set sender to christophe.leroy@csgroup.eu using -f From: Christophe Leroy To: "Naveen N . Rao" , Steven Rostedt , Ingo Molnar , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman Cc: Christophe Leroy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v1 18/22] powerpc/ftrace: Don't use copy_from_kernel_nofault() in module_trampoline_target() Date: Thu, 24 Mar 2022 15:30:08 +0100 Message-Id: X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1648132152; l=1852; s=20211009; h=from:subject:message-id; bh=Dkafy5NvUjSHjq7KoYZeDuZLfb4PxqJ6RzfaxFY7ijA=; b=mGsxDCVO37ZGzOz43c9mDE1B71zJx+va/Y7Gu0M7jRs4SyLb2NS+dAgYbW+DyKNCOTHin7c/TzVt gNXsfn30CWIpdD7J0kmV67ozOTUV+acOkA7vA1S9fLtQb9UbtfMC X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" module_trampoline_target() is quite a hot path used when activating/deactivating function tracer. Avoid the heavy copy_from_kernel_nofault() by doing four calls to copy_inst_from_kernel_nofault(). Use __copy_inst_from_kernel_nofault() for the 3 last calls. First call is done to copy_from_kernel_nofault() to check address is within kernel space. No risk to wrap out the top of kernel space because the last page is never mapped so if address is in last page the first copy will fails and the other ones will never be performed. And also make it notrace just like all functions that call it. Signed-off-by: Christophe Leroy --- arch/powerpc/kernel/module_32.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_3= 2.c index 2aa368ce21c9..1282cfd672f2 100644 --- a/arch/powerpc/kernel/module_32.c +++ b/arch/powerpc/kernel/module_32.c @@ -289,13 +289,19 @@ int apply_relocate_add(Elf32_Shdr *sechdrs, } =20 #ifdef CONFIG_FUNCTION_TRACER -int module_trampoline_target(struct module *mod, unsigned long addr, - unsigned long *target) +notrace int module_trampoline_target(struct module *mod, unsigned long add= r, + unsigned long *target) { unsigned int jmp[4]; =20 /* Find where the trampoline jumps to */ - if (copy_from_kernel_nofault(jmp, (void *)addr, sizeof(jmp))) + if (copy_inst_from_kernel_nofault(jmp, (void *)addr)) + return -EFAULT; + if (__copy_inst_from_kernel_nofault(jmp + 1, (void *)addr + 4)) + return -EFAULT; + if (__copy_inst_from_kernel_nofault(jmp + 2, (void *)addr + 8)) + return -EFAULT; + if (__copy_inst_from_kernel_nofault(jmp + 3, (void *)addr + 12)) return -EFAULT; =20 /* verify that this is what we expect it to be */ --=20 2.35.1 From nobody Sat Jun 20 01:51:50 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9E457C433EF for ; Thu, 24 Mar 2022 14:33:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351069AbiCXOe3 (ORCPT ); Thu, 24 Mar 2022 10:34:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350905AbiCXOd0 (ORCPT ); Thu, 24 Mar 2022 10:33:26 -0400 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A823DAC900 for ; Thu, 24 Mar 2022 07:31:54 -0700 (PDT) Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4KPSMK2d9lz9sTt; Thu, 24 Mar 2022 15:31:09 +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 gkadQe_OGiUn; Thu, 24 Mar 2022 15:31:09 +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 4KPSLz0S8Gz9sV0; Thu, 24 Mar 2022 15:30:51 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id EE3088B763; Thu, 24 Mar 2022 15:30:50 +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 UUs8ZWDRuTvz; Thu, 24 Mar 2022 15:30:50 +0100 (CET) Received: from PO20335.IDSI0.si.c-s.fr (unknown [192.168.203.77]) by messagerie.si.c-s.fr (Postfix) with ESMTP id F17998B7A0; Thu, 24 Mar 2022 15:30:49 +0100 (CET) Received: from PO20335.IDSI0.si.c-s.fr (localhost [127.0.0.1]) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.16.1) with ESMTPS id 22OEUiXW1811756 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 24 Mar 2022 15:30:44 +0100 Received: (from chleroy@localhost) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.17.1/Submit) id 22OEUixv1811753; Thu, 24 Mar 2022 15:30:44 +0100 X-Authentication-Warning: PO20335.IDSI0.si.c-s.fr: chleroy set sender to christophe.leroy@csgroup.eu using -f From: Christophe Leroy To: "Naveen N . Rao" , Steven Rostedt , Ingo Molnar , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman Cc: Christophe Leroy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v1 19/22] powerpc/inst: Remove PPC_INST_BRANCH Date: Thu, 24 Mar 2022 15:30:09 +0100 Message-Id: <43a4ee9fd77f774fa1e9b72a2fc674fc8f084fed.1648131740.git.christophe.leroy@csgroup.eu> X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1648132152; l=1716; s=20211009; h=from:subject:message-id; bh=reTiO1OPvuqXdGLn3x7Xk8PpudfBNZlji7IfAzSFmik=; b=YizvpT7xNAy/R0PmHc8ZrS4TX2jZyTgAdWk4r5Ql5brRoG3FESq4bjF0VxUxMpSc/NVDa27igWuW Mp5vGL6pBfJR9k5SgxBFC+q5CYtI2FQHCg3ddj8iz/jxKKhkvt+J X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Convert last users of PPC_INST_BRANCH to PPC_RAW_BRANCH() And remove PPC_INST_BRANCH. Signed-off-by: Christophe Leroy --- arch/powerpc/include/asm/ppc-opcode.h | 3 +-- arch/powerpc/lib/feature-fixups.c | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/arch/powerpc/include/asm/ppc-opcode.h b/arch/powerpc/include/a= sm/ppc-opcode.h index 281754aca0a3..ada8fe17b199 100644 --- a/arch/powerpc/include/asm/ppc-opcode.h +++ b/arch/powerpc/include/asm/ppc-opcode.h @@ -290,7 +290,6 @@ #define PPC_INST_ADDIS 0x3c000000 #define PPC_INST_ADD 0x7c000214 #define PPC_INST_DIVD 0x7c0003d2 -#define PPC_INST_BRANCH 0x48000000 #define PPC_INST_BL 0x48000001 #define PPC_INST_BRANCH_COND 0x40800000 =20 @@ -573,7 +572,7 @@ #define PPC_RAW_MTSPR(spr, d) (0x7c0003a6 | ___PPC_RS(d) | __PPC_SPR(spr)) #define PPC_RAW_EIEIO() (0x7c0006ac) =20 -#define PPC_RAW_BRANCH(addr) (PPC_INST_BRANCH | ((addr) & 0x03fffffc)) +#define PPC_RAW_BRANCH(offset) (0x48000000 | ((offset) & PPC_INST_OFFSET2= 4_MASK)) #define PPC_RAW_BL(offset) (0x48000001 | ((offset) & PPC_INST_OFFSET24_MA= SK)) =20 /* Deal with instructions that older assemblers aren't aware of */ diff --git a/arch/powerpc/lib/feature-fixups.c b/arch/powerpc/lib/feature-f= ixups.c index 343a78826035..993d3f31832a 100644 --- a/arch/powerpc/lib/feature-fixups.c +++ b/arch/powerpc/lib/feature-fixups.c @@ -451,7 +451,7 @@ static int __do_rfi_flush_fixups(void *data) =20 if (types & L1D_FLUSH_FALLBACK) /* b .+16 to fallback flush */ - instrs[0] =3D PPC_INST_BRANCH | 16; + instrs[0] =3D PPC_RAW_BRANCH(16); =20 i =3D 0; if (types & L1D_FLUSH_ORI) { --=20 2.35.1 From nobody Sat Jun 20 01:51:50 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 80023C433F5 for ; Thu, 24 Mar 2022 14:32:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351078AbiCXOeT (ORCPT ); Thu, 24 Mar 2022 10:34:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351145AbiCXOdU (ORCPT ); Thu, 24 Mar 2022 10:33:20 -0400 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E9185A27DB for ; Thu, 24 Mar 2022 07:31:48 -0700 (PDT) Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4KPSMH20Vhz9sTy; Thu, 24 Mar 2022 15:31:07 +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 u-W6Est-0pkC; Thu, 24 Mar 2022 15:31:07 +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 4KPSLz0Hr5z9sTx; Thu, 24 Mar 2022 15:30:51 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id DF60F8B78B; Thu, 24 Mar 2022 15:30:50 +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 32nCd3AEpQVs; Thu, 24 Mar 2022 15:30:50 +0100 (CET) Received: from PO20335.IDSI0.si.c-s.fr (unknown [192.168.203.77]) by messagerie.si.c-s.fr (Postfix) with ESMTP id E28C08B79C; Thu, 24 Mar 2022 15:30:49 +0100 (CET) Received: from PO20335.IDSI0.si.c-s.fr (localhost [127.0.0.1]) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.16.1) with ESMTPS id 22OEUiPI1811760 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 24 Mar 2022 15:30:44 +0100 Received: (from chleroy@localhost) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.17.1/Submit) id 22OEUiwf1811759; Thu, 24 Mar 2022 15:30:44 +0100 X-Authentication-Warning: PO20335.IDSI0.si.c-s.fr: chleroy set sender to christophe.leroy@csgroup.eu using -f From: Christophe Leroy To: "Naveen N . Rao" , Steven Rostedt , Ingo Molnar , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman Cc: Christophe Leroy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v1 20/22] powerpc/modules: Use PPC_INST_BRANCH_MASK instead of opencoding Date: Thu, 24 Mar 2022 15:30:10 +0100 Message-Id: X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1648132152; l=2135; s=20211009; h=from:subject:message-id; bh=+hpUyk5a1199l2+WP/AdaKunGqwu6Qoeoc6PngqTufs=; b=JPmeYBLVclnVxlOKg4+3av5sIUFxL2DOsI9D62gGNWM+KF0b0fus4PRJUaBsh44i4s6mBFTzZj+u o+x0bcKBD2drjXUZgRB9xOTMKrx4dvQG+eG0ZaKcM4T4Qez2uR3/ X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Use PPC_INST_BRANCH_MASK instead of opencoding. Signed-off-by: Christophe Leroy --- arch/powerpc/kernel/module_32.c | 13 ++++++------- arch/powerpc/kernel/module_64.c | 4 ++-- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_3= 2.c index 1282cfd672f2..344941855e9e 100644 --- a/arch/powerpc/kernel/module_32.c +++ b/arch/powerpc/kernel/module_32.c @@ -256,9 +256,8 @@ int apply_relocate_add(Elf32_Shdr *sechdrs, value, (uint32_t)location); pr_debug("Location before: %08X.\n", *(uint32_t *)location); - value =3D (*(uint32_t *)location & ~0x03fffffc) - | ((value - (uint32_t)location) - & 0x03fffffc); + value =3D (*(uint32_t *)location & ~PPC_INST_OFFSET24_MASK) | + ((value - (uint32_t)location) & PPC_INST_OFFSET24_MASK); =20 if (patch_instruction(location, ppc_inst(value))) return -EFAULT; @@ -266,10 +265,10 @@ int apply_relocate_add(Elf32_Shdr *sechdrs, pr_debug("Location after: %08X.\n", *(uint32_t *)location); pr_debug("ie. jump to %08X+%08X =3D %08X\n", - *(uint32_t *)location & 0x03fffffc, - (uint32_t)location, - (*(uint32_t *)location & 0x03fffffc) - + (uint32_t)location); + *(uint32_t *)location & PPC_INST_OFFSET24_MASK, + (uint32_t)location, + (*(uint32_t *)location & PPC_INST_OFFSET24_MASK) + + (uint32_t)location); break; =20 case R_PPC_REL32: diff --git a/arch/powerpc/kernel/module_64.c b/arch/powerpc/kernel/module_6= 4.c index b13a72665eee..8f70a04aac6c 100644 --- a/arch/powerpc/kernel/module_64.c +++ b/arch/powerpc/kernel/module_64.c @@ -653,8 +653,8 @@ int apply_relocate_add(Elf64_Shdr *sechdrs, } =20 /* Only replace bits 2 through 26 */ - value =3D (*(uint32_t *)location & ~0x03fffffc) - | (value & 0x03fffffc); + value =3D (*(uint32_t *)location & ~PPC_INST_OFFSET24_MASK) | + (value & PPC_INST_OFFSET24_MASK); =20 if (patch_instruction((u32 *)location, ppc_inst(value))) return -EFAULT; --=20 2.35.1 From nobody Sat Jun 20 01:51:50 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D9005C433F5 for ; Thu, 24 Mar 2022 14:32:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351036AbiCXOd6 (ORCPT ); Thu, 24 Mar 2022 10:33:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351045AbiCXOdB (ORCPT ); Thu, 24 Mar 2022 10:33:01 -0400 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A836EAC900 for ; Thu, 24 Mar 2022 07:31:19 -0700 (PDT) Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4KPSM62Rznz9sTl; Thu, 24 Mar 2022 15:30:58 +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 qAR13Swuuv32; Thu, 24 Mar 2022 15:30:58 +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 4KPSLy5P8tz9sTm; Thu, 24 Mar 2022 15:30:50 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id AECA58B763; Thu, 24 Mar 2022 15:30:50 +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 iwBCbJ26OgYm; Thu, 24 Mar 2022 15:30:50 +0100 (CET) Received: from PO20335.IDSI0.si.c-s.fr (unknown [192.168.203.77]) by messagerie.si.c-s.fr (Postfix) with ESMTP id B34CA8B78D; Thu, 24 Mar 2022 15:30:49 +0100 (CET) Received: from PO20335.IDSI0.si.c-s.fr (localhost [127.0.0.1]) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.16.1) with ESMTPS id 22OEUi5r1811764 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 24 Mar 2022 15:30:45 +0100 Received: (from chleroy@localhost) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.17.1/Submit) id 22OEUixg1811763; Thu, 24 Mar 2022 15:30:44 +0100 X-Authentication-Warning: PO20335.IDSI0.si.c-s.fr: chleroy set sender to christophe.leroy@csgroup.eu using -f From: Christophe Leroy To: "Naveen N . Rao" , Steven Rostedt , Ingo Molnar , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman Cc: Christophe Leroy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v1 21/22] powerpc/inst: Remove PPC_INST_BL Date: Thu, 24 Mar 2022 15:30:11 +0100 Message-Id: <43f418a2d7377669f10738be374c3dd78f5d0351.1648131740.git.christophe.leroy@csgroup.eu> X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1648132152; l=1328; s=20211009; h=from:subject:message-id; bh=d/0sxDLqKwCM/yFYRKIyBRndGeNibtd5T3dOKw3MQJc=; b=pyjWcSj8RzaW7zHcMj/KcQkTwTflEA/lc9eWqCI/EkBSbaY9M9sIUtfCB/hMaxx987RGOe7wok2G AR7kYOXiBjXQAP+/lWqsxERvSULzVE4hTSRq42R7y/v+cCLr383d X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Convert last users of PPC_INST_BL to PPC_RAW_BL() And remove PPC_INST_BL. Signed-off-by: Christophe Leroy --- arch/powerpc/include/asm/ppc-opcode.h | 1 - arch/powerpc/net/bpf_jit.h | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/arch/powerpc/include/asm/ppc-opcode.h b/arch/powerpc/include/a= sm/ppc-opcode.h index ada8fe17b199..810a28af9dce 100644 --- a/arch/powerpc/include/asm/ppc-opcode.h +++ b/arch/powerpc/include/asm/ppc-opcode.h @@ -290,7 +290,6 @@ #define PPC_INST_ADDIS 0x3c000000 #define PPC_INST_ADD 0x7c000214 #define PPC_INST_DIVD 0x7c0003d2 -#define PPC_INST_BL 0x48000001 #define PPC_INST_BRANCH_COND 0x40800000 =20 #define PPC_INST_OFFSET24_MASK 0x03fffffc diff --git a/arch/powerpc/net/bpf_jit.h b/arch/powerpc/net/bpf_jit.h index 979701d360da..c63324ff9f04 100644 --- a/arch/powerpc/net/bpf_jit.h +++ b/arch/powerpc/net/bpf_jit.h @@ -35,7 +35,7 @@ } while (0) =20 /* bl (unconditional 'branch' with link) */ -#define PPC_BL(dest) EMIT(PPC_INST_BL | (((dest) - (unsigned long)(image += ctx->idx)) & 0x03fffffc)) +#define PPC_BL(dest) EMIT(PPC_RAW_BL((dest) - (unsigned long)(image + ctx-= >idx))) =20 /* "cond" here covers BO:BI fields. */ #define PPC_BCC_SHORT(cond, dest) \ --=20 2.35.1 From nobody Sat Jun 20 01:51:50 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B0EA2C433EF for ; Thu, 24 Mar 2022 14:33:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351191AbiCXOej (ORCPT ); Thu, 24 Mar 2022 10:34:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38714 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351105AbiCXOdL (ORCPT ); Thu, 24 Mar 2022 10:33:11 -0400 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF898AC060 for ; Thu, 24 Mar 2022 07:31:36 -0700 (PDT) Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4KPSMC0fVCz9sTr; Thu, 24 Mar 2022 15:31:03 +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 fXX7av9XKH1u; Thu, 24 Mar 2022 15:31:03 +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 4KPSLy6msRz9sTs; Thu, 24 Mar 2022 15:30:50 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id D32148B783; Thu, 24 Mar 2022 15:30:50 +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 OEhdD3TccBAo; Thu, 24 Mar 2022 15:30:50 +0100 (CET) Received: from PO20335.IDSI0.si.c-s.fr (unknown [192.168.203.77]) by messagerie.si.c-s.fr (Postfix) with ESMTP id C99528B796; Thu, 24 Mar 2022 15:30:49 +0100 (CET) Received: from PO20335.IDSI0.si.c-s.fr (localhost [127.0.0.1]) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.16.1) with ESMTPS id 22OEUjqY1811768 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 24 Mar 2022 15:30:45 +0100 Received: (from chleroy@localhost) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.17.1/Submit) id 22OEUjUL1811767; Thu, 24 Mar 2022 15:30:45 +0100 X-Authentication-Warning: PO20335.IDSI0.si.c-s.fr: chleroy set sender to christophe.leroy@csgroup.eu using -f From: Christophe Leroy To: "Naveen N . Rao" , Steven Rostedt , Ingo Molnar , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman Cc: Christophe Leroy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v1 22/22] powerpc/opcodes: Remove unused PPC_INST_XXX macros Date: Thu, 24 Mar 2022 15:30:12 +0100 Message-Id: <636d1c500bcd2d09709abca49d4e05ec5c79666a.1648131740.git.christophe.leroy@csgroup.eu> X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1648132152; l=2951; s=20211009; h=from:subject:message-id; bh=UdaOSaO9Qo6g4wVcEhBoMxZ4qqP0e+8Vq+hajWDgYgg=; b=CnDAKVjJyVv4yODoM9pBi5Y4cj64PmspAw78jKlEUahakcKyE290mvmMv8nrlD8KSK3KQMTcLkzt t/Fa6WBxAhIMopyor4pQkPUimqo9PvMC+toJmtVUNzcK0WQ9EGyK X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The following PPC_INST_XXX macros are not used anymore outside ppc-opcode.h: - PPC_INST_LD - PPC_INST_STD - PPC_INST_ADDIS - PPC_INST_ADD - PPC_INST_DIVD Remove them. Signed-off-by: Christophe Leroy --- arch/powerpc/include/asm/ppc-opcode.h | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/arch/powerpc/include/asm/ppc-opcode.h b/arch/powerpc/include/a= sm/ppc-opcode.h index 810a28af9dce..4cdda507e816 100644 --- a/arch/powerpc/include/asm/ppc-opcode.h +++ b/arch/powerpc/include/asm/ppc-opcode.h @@ -285,11 +285,6 @@ #define PPC_INST_TRECHKPT 0x7c0007dd #define PPC_INST_TRECLAIM 0x7c00075d #define PPC_INST_TSR 0x7c0005dd -#define PPC_INST_LD 0xe8000000 -#define PPC_INST_STD 0xf8000000 -#define PPC_INST_ADDIS 0x3c000000 -#define PPC_INST_ADD 0x7c000214 -#define PPC_INST_DIVD 0x7c0003d2 #define PPC_INST_BRANCH_COND 0x40800000 =20 #define PPC_INST_OFFSET24_MASK 0x03fffffc @@ -460,10 +455,10 @@ (0x100000c7 | ___PPC_RT(vrt) | ___PPC_RA(vra) | ___PPC_RB(vrb) | __PPC_RC= 21) #define PPC_RAW_VCMPEQUB_RC(vrt, vra, vrb) \ (0x10000006 | ___PPC_RT(vrt) | ___PPC_RA(vra) | ___PPC_RB(vrb) | __PPC_RC= 21) -#define PPC_RAW_LD(r, base, i) (PPC_INST_LD | ___PPC_RT(r) | ___PPC_RA(ba= se) | IMM_DS(i)) +#define PPC_RAW_LD(r, base, i) (0xe8000000 | ___PPC_RT(r) | ___PPC_RA(bas= e) | IMM_DS(i)) #define PPC_RAW_LWZ(r, base, i) (0x80000000 | ___PPC_RT(r) | ___PPC_RA(ba= se) | IMM_L(i)) #define PPC_RAW_LWZX(t, a, b) (0x7c00002e | ___PPC_RT(t) | ___PPC_RA(a) |= ___PPC_RB(b)) -#define PPC_RAW_STD(r, base, i) (PPC_INST_STD | ___PPC_RS(r) | ___PPC_RA(= base) | IMM_DS(i)) +#define PPC_RAW_STD(r, base, i) (0xf8000000 | ___PPC_RS(r) | ___PPC_RA(ba= se) | IMM_DS(i)) #define PPC_RAW_STDCX(s, a, b) (0x7c0001ad | ___PPC_RS(s) | ___PPC_RA(a) = | ___PPC_RB(b)) #define PPC_RAW_LFSX(t, a, b) (0x7c00042e | ___PPC_RT(t) | ___PPC_RA(a) |= ___PPC_RB(b)) #define PPC_RAW_STFSX(s, a, b) (0x7c00052e | ___PPC_RS(s) | ___PPC_RA(a) = | ___PPC_RB(b)) @@ -474,8 +469,8 @@ #define PPC_RAW_ADDE(t, a, b) (0x7c000114 | ___PPC_RT(t) | ___PPC_RA(a) |= ___PPC_RB(b)) #define PPC_RAW_ADDZE(t, a) (0x7c000194 | ___PPC_RT(t) | ___PPC_RA(a)) #define PPC_RAW_ADDME(t, a) (0x7c0001d4 | ___PPC_RT(t) | ___PPC_RA(a)) -#define PPC_RAW_ADD(t, a, b) (PPC_INST_ADD | ___PPC_RT(t) | ___PPC_RA(a) = | ___PPC_RB(b)) -#define PPC_RAW_ADD_DOT(t, a, b) (PPC_INST_ADD | ___PPC_RT(t) | ___PPC_RA(= a) | ___PPC_RB(b) | 0x1) +#define PPC_RAW_ADD(t, a, b) (0x7c000214 | ___PPC_RT(t) | ___PPC_RA(a) | = ___PPC_RB(b)) +#define PPC_RAW_ADD_DOT(t, a, b) (0x7c000214 | ___PPC_RT(t) | ___PPC_RA(a)= | ___PPC_RB(b) | 0x1) #define PPC_RAW_ADDC(t, a, b) (0x7c000014 | ___PPC_RT(t) | ___PPC_RA(a) |= ___PPC_RB(b)) #define PPC_RAW_ADDC_DOT(t, a, b) (0x7c000014 | ___PPC_RT(t) | ___PPC_RA(a= ) | ___PPC_RB(b) | 0x1) #define PPC_RAW_NOP() PPC_RAW_ORI(0, 0, 0) --=20 2.35.1