Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1348128pxb; Thu, 24 Mar 2022 18:23:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxFj5ObUFAzE1gsxZ/WozAT7udPL87D4+qmbv58j+6lRBF4vhpFC8cS6/2E4ToME/8PwJip X-Received: by 2002:aa7:91d5:0:b0:4fa:6d3c:55d9 with SMTP id z21-20020aa791d5000000b004fa6d3c55d9mr7901049pfa.41.1648171396471; Thu, 24 Mar 2022 18:23:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648171396; cv=none; d=google.com; s=arc-20160816; b=u2eYqv0WDxBVhTvqmlEw1oP0xbKuHkJ6HCGrU8wzJFmi8HHRTfS0VH89CsBFizIN4+ tv8xfQR5wxpiMVBr1bzpWaF+XD6zQKzh30Ij8vUskwGjB+ShVawLJVeECLBfn5xFC7Bh qXFFl60m4EagGvtZ6NNtjcDuV/QR+X3CGS+O22QTXdNx9ud45Dxbhqj5J8OqlhUeS5aS NffMkvR+hzuJrF7dHcBjfP+00DA3BVdBwTSc/CDyO7Hvxxt7+OJM5lYBUJMpF9RwM1L8 DZOeHmiDMVwxUL9xLGmHyepokabo/6ZxE/nffi1PCsYownroI92mN72qRimlurYgqlol gU9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=o1Mb5MS5qzEbx61+G31ojC0TJWFA0IODkiJ9cPGfR9U=; b=mbDtSV9MU1jw7J4wBEcVO94oa5KdASObAROqb7qTawzrdS3WCSziV4isUKIhoUR78G zDxBZXHLpA6U9U8mI+R8/beBi7rPDrDhYMY9uhLLxprYEYKQrUlBDQrLF3jug5gEOTAP RcwEPjyKCV0U6iSvkQknWpYnBifdkOyGI6ZkwASlgLxFZs/STqAmwbVWSq0Z6Nlw2yaj u9dWQ4VPFALQK5exwL1AHM7kdiZU1xOmEVctAS9Ry59MOaVSxQSH2MC2aP1ovz38s74H 0NLauLmaJyGaWk1k15XSNLXhPc7DwPBEropkpNkgU2sRHsj1PdQAMHa8PfXzwsva00RA vJwA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i5-20020a636d05000000b003816043ee66si976986pgc.91.2022.03.24.18.23.02; Thu, 24 Mar 2022 18:23:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351020AbiCXOdd (ORCPT + 99 others); Thu, 24 Mar 2022 10:33:33 -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: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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/asm/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 +#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) #define PPC_RAW_BRANCH(addr) (PPC_INST_BRANCH | ((addr) & 0x03fffffc)) +#define PPC_RAW_BL(offset) (0x48000001 | ((offset) & PPC_INST_OFFSET24_MASK)) /* 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 long addr) static int is_bl_op(ppc_inst_t op) { - return (ppc_inst_val(op) & 0xfc000003) == 0x48000001; + return (ppc_inst_val(op) & ~PPC_INST_OFFSET24_MASK) == PPC_RAW_BL(0); } static int is_b_op(ppc_inst_t op) { - return (ppc_inst_val(op) & 0xfc000003) == 0x48000000; + return (ppc_inst_val(op) & ~PPC_INST_OFFSET24_MASK) == PPC_RAW_BRANCH(0); } static unsigned long find_bl_target(unsigned long ip, ppc_inst_t op) { int offset; - offset = (ppc_inst_val(op) & 0x03fffffc); + offset = (ppc_inst_val(op) & PPC_INST_OFFSET24_MASK); /* make it signed */ if (offset & 0x02000000) offset |= 0xfe000000; @@ -182,7 +182,7 @@ __ftrace_make_nop(struct module *mod, * Use a b +8 to jump over the load. */ - pop = ppc_inst(PPC_INST_BRANCH | 8); /* b +8 */ + pop = ppc_inst(PPC_RAW_BRANCH(8)); /* b +8 */ /* * 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) != 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_inst_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[] = { ftrace_tramp_text, ftrace_tramp_init }; u32 stub_insns[] = { - 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 = ppc_global_function_entry((void *)ftrace_regs_caller); -- 2.35.1