From patchwork Sat Mar 13 06:41:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Huang Pei X-Patchwork-Id: 12136527 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EFE02C43332 for ; Sat, 13 Mar 2021 06:43:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DC37964F21 for ; Sat, 13 Mar 2021 06:43:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231392AbhCMGmt (ORCPT ); Sat, 13 Mar 2021 01:42:49 -0500 Received: from mail.loongson.cn ([114.242.206.163]:42726 "EHLO loongson.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S232440AbhCMGmj (ORCPT ); Sat, 13 Mar 2021 01:42:39 -0500 Received: from localhost.localdomain (unknown [222.209.9.50]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9AxGda4XkxgjLUYAA--.9506S3; Sat, 13 Mar 2021 14:42:09 +0800 (CST) From: Huang Pei To: Thomas Bogendoerfer , ambrosehua@gmail.com Cc: Bibo Mao , linux-mips@vger.kernel.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, Jiaxun Yang , Paul Burton , Li Xuefeng , Yang Tiezhu , Gao Juxin , Huacai Chen , Jinyang He , "Maciej W . Rozycki" , Steven Rostedt , Jisheng Zhang , Masami Hiramatsu Subject: [PATCH 1/6] MIPS: replace -pg with CC_FLAGS_FTRACE Date: Sat, 13 Mar 2021 14:41:44 +0800 Message-Id: <20210313064149.29276-2-huangpei@loongson.cn> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210313064149.29276-1-huangpei@loongson.cn> References: <20210313064149.29276-1-huangpei@loongson.cn> X-CM-TRANSID: AQAAf9AxGda4XkxgjLUYAA--.9506S3 X-Coremail-Antispam: 1UD129KBjvJXoW7CrWxCw43AF48try7Zr13urg_yoW5Jryxpa nak3Z7Xw4xurW8Kr92yFyUZrsrArWvqrW0qF9rKryUJFySvFnYgr4xtFy5tr95WryxJa48 W348WF47JrySv3JanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPC14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_Jr4l82xGYIkIc2 x26xkF7I0E14v26r4j6ryUM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_JFI_Gr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr0_Cr1l84 ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVCY1x0267AKxVWxJr0_GcWl e2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI 8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJVW8JwAC jcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lFIxGxcIEc7CjxVA2Y2ka0x kIwI1lc2xSY4AK67AK6r47MxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4U MI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67 AKxVW8ZVWrXwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0 cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z2 80aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI 43ZEXa7VUUnjjDUUUUU== X-CM-SenderInfo: xkxd0whshlqz5rrqw2lrqou0/ Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org Signed-off-by: Huang Pei Acked-by: Steven Rostedt (VMware) --- arch/mips/boot/compressed/Makefile | 2 +- arch/mips/kernel/Makefile | 8 ++++---- arch/mips/vdso/Makefile | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/arch/mips/boot/compressed/Makefile b/arch/mips/boot/compressed/Makefile index d66511825fe1..8fc9ceeec709 100644 --- a/arch/mips/boot/compressed/Makefile +++ b/arch/mips/boot/compressed/Makefile @@ -18,7 +18,7 @@ include $(srctree)/arch/mips/Kbuild.platforms BOOT_HEAP_SIZE := 0x400000 # Disable Function Tracer -KBUILD_CFLAGS := $(filter-out -pg, $(KBUILD_CFLAGS)) +KBUILD_CFLAGS := $(filter-out $(CC_FLAGS_FTRACE), $(KBUILD_CFLAGS)) KBUILD_CFLAGS := $(filter-out -fstack-protector, $(KBUILD_CFLAGS)) diff --git a/arch/mips/kernel/Makefile b/arch/mips/kernel/Makefile index 2a05b923f579..33e31ea10234 100644 --- a/arch/mips/kernel/Makefile +++ b/arch/mips/kernel/Makefile @@ -17,10 +17,10 @@ obj-y += cpu-probe.o endif ifdef CONFIG_FUNCTION_TRACER -CFLAGS_REMOVE_ftrace.o = -pg -CFLAGS_REMOVE_early_printk.o = -pg -CFLAGS_REMOVE_perf_event.o = -pg -CFLAGS_REMOVE_perf_event_mipsxx.o = -pg +CFLAGS_REMOVE_ftrace.o = $(CC_FLAGS_FTRACE) +CFLAGS_REMOVE_early_printk.o = $(CC_FLAGS_FTRACE) +CFLAGS_REMOVE_perf_event.o = $(CC_FLAGS_FTRACE) +CFLAGS_REMOVE_perf_event_mipsxx.o = $(CC_FLAGS_FTRACE) endif obj-$(CONFIG_CEVT_BCM1480) += cevt-bcm1480.o diff --git a/arch/mips/vdso/Makefile b/arch/mips/vdso/Makefile index 5810cc12bc1d..f21cf88f7ae3 100644 --- a/arch/mips/vdso/Makefile +++ b/arch/mips/vdso/Makefile @@ -49,7 +49,7 @@ CFLAGS_vgettimeofday-o32.o = -include $(srctree)/$(src)/config-n32-o32-env.c -in CFLAGS_vgettimeofday-n32.o = -include $(srctree)/$(src)/config-n32-o32-env.c -include $(c-gettimeofday-y) endif -CFLAGS_REMOVE_vgettimeofday.o = -pg +CFLAGS_REMOVE_vgettimeofday.o = $(CC_FLAGS_FTRACE) ifdef CONFIG_MIPS_DISABLE_VDSO ifndef CONFIG_MIPS_LD_CAN_LINK_VDSO @@ -63,7 +63,7 @@ ldflags-y := -Bsymbolic --no-undefined -soname=linux-vdso.so.1 \ $(filter -E%,$(KBUILD_CFLAGS)) -nostdlib -shared \ -G 0 --eh-frame-hdr --hash-style=sysv --build-id=sha1 -T -CFLAGS_REMOVE_vdso.o = -pg +CFLAGS_REMOVE_vdso.o = $(CC_FLAGS_FTRACE) GCOV_PROFILE := n UBSAN_SANITIZE := n From patchwork Sat Mar 13 06:41:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Huang Pei X-Patchwork-Id: 12136521 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8DEEBC433DB for ; Sat, 13 Mar 2021 06:43:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5ACE164F1B for ; Sat, 13 Mar 2021 06:43:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231383AbhCMGmt (ORCPT ); Sat, 13 Mar 2021 01:42:49 -0500 Received: from mail.loongson.cn ([114.242.206.163]:42682 "EHLO loongson.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230309AbhCMGmh (ORCPT ); Sat, 13 Mar 2021 01:42:37 -0500 Received: from localhost.localdomain (unknown [222.209.9.50]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9AxGda4XkxgjLUYAA--.9506S4; Sat, 13 Mar 2021 14:42:10 +0800 (CST) From: Huang Pei To: Thomas Bogendoerfer , ambrosehua@gmail.com Cc: Bibo Mao , linux-mips@vger.kernel.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, Jiaxun Yang , Paul Burton , Li Xuefeng , Yang Tiezhu , Gao Juxin , Huacai Chen , Jinyang He , "Maciej W . Rozycki" , Steven Rostedt , Jisheng Zhang , Masami Hiramatsu Subject: [PATCH 2/6] MIPS: move FTRACE_SYSCALLS from ftrace.c into syscall.c Date: Sat, 13 Mar 2021 14:41:45 +0800 Message-Id: <20210313064149.29276-3-huangpei@loongson.cn> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210313064149.29276-1-huangpei@loongson.cn> References: <20210313064149.29276-1-huangpei@loongson.cn> X-CM-TRANSID: AQAAf9AxGda4XkxgjLUYAA--.9506S4 X-Coremail-Antispam: 1UD129KBjvJXoWxAF4ktr1xZr15Xry3WF4UJwb_yoWrGFykpF s8Z3ZrG395WF10y347ZryFkrZ3Jw4kZryay3ZrK34rZ3Wxt3W5XrZ29a4ktryktFWq9FW8 uFWxGr15Cr4ru3JanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUmj14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_Jryl82xGYIkIc2 x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_JFI_Gr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Cr0_Gr1UM2 8EF7xvwVC2z280aVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Cr1j6rxd M2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjx v20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1l F7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7M4IIrI8v6xkF7I0E8cxan2 IY04v7MxkIecxEwVAFwVW8AwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8 JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1V AFwI0_GFv_WrylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xII jxv20xvEc7CjxVAFwI0_Cr0_Gr1UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I 8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r4UJVWxJrUvcSsGvfC2Kfnx nUUI43ZEXa7VUjkhLUUUUUU== X-CM-SenderInfo: xkxd0whshlqz5rrqw2lrqou0/ Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org Signed-off-by: Huang Pei --- arch/mips/kernel/Makefile | 1 - arch/mips/kernel/ftrace.c | 33 --------------------------------- arch/mips/kernel/syscall.c | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 34 deletions(-) diff --git a/arch/mips/kernel/Makefile b/arch/mips/kernel/Makefile index 33e31ea10234..5b2b551058ac 100644 --- a/arch/mips/kernel/Makefile +++ b/arch/mips/kernel/Makefile @@ -39,7 +39,6 @@ obj-$(CONFIG_DEBUG_FS) += segment.o obj-$(CONFIG_STACKTRACE) += stacktrace.o obj-$(CONFIG_MODULES) += module.o -obj-$(CONFIG_FTRACE_SYSCALLS) += ftrace.o obj-$(CONFIG_FUNCTION_TRACER) += mcount.o ftrace.o sw-y := r4k_switch.o diff --git a/arch/mips/kernel/ftrace.c b/arch/mips/kernel/ftrace.c index f57e68f40a34..5156b2e54bfe 100644 --- a/arch/mips/kernel/ftrace.c +++ b/arch/mips/kernel/ftrace.c @@ -12,14 +12,11 @@ #include #include #include -#include #include #include #include -#include #include -#include #include @@ -382,33 +379,3 @@ void prepare_ftrace_return(unsigned long *parent_ra_addr, unsigned long self_ra, WARN_ON(1); } #endif /* CONFIG_FUNCTION_GRAPH_TRACER */ - -#ifdef CONFIG_FTRACE_SYSCALLS - -#ifdef CONFIG_32BIT -unsigned long __init arch_syscall_addr(int nr) -{ - return (unsigned long)sys_call_table[nr - __NR_O32_Linux]; -} -#endif - -#ifdef CONFIG_64BIT - -unsigned long __init arch_syscall_addr(int nr) -{ -#ifdef CONFIG_MIPS32_N32 - if (nr >= __NR_N32_Linux && nr < __NR_N32_Linux + __NR_N32_Linux_syscalls) - return (unsigned long)sysn32_call_table[nr - __NR_N32_Linux]; -#endif - if (nr >= __NR_64_Linux && nr < __NR_64_Linux + __NR_64_Linux_syscalls) - return (unsigned long)sys_call_table[nr - __NR_64_Linux]; -#ifdef CONFIG_MIPS32_O32 - if (nr >= __NR_O32_Linux && nr < __NR_O32_Linux + __NR_O32_Linux_syscalls) - return (unsigned long)sys32_call_table[nr - __NR_O32_Linux]; -#endif - - return (unsigned long) &sys_ni_syscall; -} -#endif - -#endif /* CONFIG_FTRACE_SYSCALLS */ diff --git a/arch/mips/kernel/syscall.c b/arch/mips/kernel/syscall.c index 2afa3eef486a..797d9ce478da 100644 --- a/arch/mips/kernel/syscall.c +++ b/arch/mips/kernel/syscall.c @@ -39,7 +39,9 @@ #include #include #include +#include #include +#include /* * For historic reasons the pipe(2) syscall on MIPS has an unusual calling @@ -233,6 +235,36 @@ SYSCALL_DEFINE3(sysmips, long, cmd, long, arg1, long, arg2) return -EINVAL; } +#ifdef CONFIG_FTRACE_SYSCALLS + +#ifdef CONFIG_32BIT +unsigned long __init arch_syscall_addr(int nr) +{ + return (unsigned long)sys_call_table[nr - __NR_O32_Linux]; +} +#endif + +#ifdef CONFIG_64BIT + +unsigned long __init arch_syscall_addr(int nr) +{ +#ifdef CONFIG_MIPS32_N32 + if (nr >= __NR_N32_Linux && nr < __NR_N32_Linux + __NR_N32_Linux_syscalls) + return (unsigned long)sysn32_call_table[nr - __NR_N32_Linux]; +#endif + if (nr >= __NR_64_Linux && nr < __NR_64_Linux + __NR_64_Linux_syscalls) + return (unsigned long)sys_call_table[nr - __NR_64_Linux]; +#ifdef CONFIG_MIPS32_O32 + if (nr >= __NR_O32_Linux && nr < __NR_O32_Linux + __NR_O32_Linux_syscalls) + return (unsigned long)sys32_call_table[nr - __NR_O32_Linux]; +#endif + + return (unsigned long) &sys_ni_syscall; +} +#endif + +#endif /* CONFIG_FTRACE_SYSCALLS */ + /* * No implemented yet ... */ From patchwork Sat Mar 13 06:41:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Huang Pei X-Patchwork-Id: 12136529 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1BF11C432C3 for ; Sat, 13 Mar 2021 06:43:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 09F6F64F1C for ; Sat, 13 Mar 2021 06:43:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232316AbhCMGmt (ORCPT ); Sat, 13 Mar 2021 01:42:49 -0500 Received: from mail.loongson.cn ([114.242.206.163]:42676 "EHLO loongson.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231392AbhCMGmi (ORCPT ); Sat, 13 Mar 2021 01:42:38 -0500 Received: from localhost.localdomain (unknown [222.209.9.50]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9AxGda4XkxgjLUYAA--.9506S5; Sat, 13 Mar 2021 14:42:12 +0800 (CST) From: Huang Pei To: Thomas Bogendoerfer , ambrosehua@gmail.com Cc: Bibo Mao , linux-mips@vger.kernel.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, Jiaxun Yang , Paul Burton , Li Xuefeng , Yang Tiezhu , Gao Juxin , Huacai Chen , Jinyang He , "Maciej W . Rozycki" , Steven Rostedt , Jisheng Zhang , Masami Hiramatsu Subject: [PATCH 3/6] MIPS: prepare for new ftrace implementation Date: Sat, 13 Mar 2021 14:41:46 +0800 Message-Id: <20210313064149.29276-4-huangpei@loongson.cn> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210313064149.29276-1-huangpei@loongson.cn> References: <20210313064149.29276-1-huangpei@loongson.cn> X-CM-TRANSID: AQAAf9AxGda4XkxgjLUYAA--.9506S5 X-Coremail-Antispam: 1UD129KBjvJXoW7ArW5Jr1xZr4ktw1UZw1rCrg_yoW8GF17pa n7Aas8Gw4xZFWvy34SkryrGFy3JwsYvrWFgFZrtw4rtFnYqFs8Xrn2yr15trW0gr1xKay8 Wa48Wr17A3sYv3JanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUmj14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JrWl82xGYIkIc2 x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_JFI_Gr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Cr0_Gr1UM2 8EF7xvwVC2z280aVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Cr1j6rxd M2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjx v20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1l F7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7M4IIrI8v6xkF7I0E8cxan2 IY04v7MxkIecxEwVAFwVW8AwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8 JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1V AFwI0_GFv_WrylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xII jxv20xvEc7CjxVAFwI0_Cr0_Gr1UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I 8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r4UJVWxJrUvcSsGvfC2Kfnx nUUI43ZEXa7VUjPku7UUUUU== X-CM-SenderInfo: xkxd0whshlqz5rrqw2lrqou0/ Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org No function change Signed-off-by: Huang Pei --- arch/mips/kernel/Makefile | 4 ++-- arch/mips/kernel/{ftrace.c => ftrace-mcount.c} | 0 2 files changed, 2 insertions(+), 2 deletions(-) rename arch/mips/kernel/{ftrace.c => ftrace-mcount.c} (100%) diff --git a/arch/mips/kernel/Makefile b/arch/mips/kernel/Makefile index 5b2b551058ac..3e7b0ee54cfb 100644 --- a/arch/mips/kernel/Makefile +++ b/arch/mips/kernel/Makefile @@ -17,7 +17,7 @@ obj-y += cpu-probe.o endif ifdef CONFIG_FUNCTION_TRACER -CFLAGS_REMOVE_ftrace.o = $(CC_FLAGS_FTRACE) +CFLAGS_REMOVE_ftrace-mcount.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_early_printk.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_perf_event.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_perf_event_mipsxx.o = $(CC_FLAGS_FTRACE) @@ -39,7 +39,7 @@ obj-$(CONFIG_DEBUG_FS) += segment.o obj-$(CONFIG_STACKTRACE) += stacktrace.o obj-$(CONFIG_MODULES) += module.o -obj-$(CONFIG_FUNCTION_TRACER) += mcount.o ftrace.o +obj-$(CONFIG_FUNCTION_TRACER) += mcount.o ftrace-mcount.o sw-y := r4k_switch.o sw-$(CONFIG_CPU_R3000) := r2300_switch.o diff --git a/arch/mips/kernel/ftrace.c b/arch/mips/kernel/ftrace-mcount.c similarity index 100% rename from arch/mips/kernel/ftrace.c rename to arch/mips/kernel/ftrace-mcount.c From patchwork Sat Mar 13 06:41:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Huang Pei X-Patchwork-Id: 12136531 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5274EC4321A for ; Sat, 13 Mar 2021 06:43:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 30FB164F1A for ; Sat, 13 Mar 2021 06:43:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232779AbhCMGmu (ORCPT ); Sat, 13 Mar 2021 01:42:50 -0500 Received: from mail.loongson.cn ([114.242.206.163]:42756 "EHLO loongson.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S232627AbhCMGms (ORCPT ); Sat, 13 Mar 2021 01:42:48 -0500 Received: from localhost.localdomain (unknown [222.209.9.50]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9AxGda4XkxgjLUYAA--.9506S6; Sat, 13 Mar 2021 14:42:13 +0800 (CST) From: Huang Pei To: Thomas Bogendoerfer , ambrosehua@gmail.com Cc: Bibo Mao , linux-mips@vger.kernel.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, Jiaxun Yang , Paul Burton , Li Xuefeng , Yang Tiezhu , Gao Juxin , Huacai Chen , Jinyang He , "Maciej W . Rozycki" , Steven Rostedt , Jisheng Zhang , Masami Hiramatsu , "Naveen N . Rao" Subject: [PATCH 4/6] kprobes/ftrace: Use ftrace_location() when [dis]arming probes Date: Sat, 13 Mar 2021 14:41:47 +0800 Message-Id: <20210313064149.29276-5-huangpei@loongson.cn> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210313064149.29276-1-huangpei@loongson.cn> References: <20210313064149.29276-1-huangpei@loongson.cn> X-CM-TRANSID: AQAAf9AxGda4XkxgjLUYAA--.9506S6 X-Coremail-Antispam: 1UD129KBjvJXoW7Kw43WFy7tF4rKryrtw43Wrg_yoW8KrWrpa s0kwn8tr48JFWvgF9Fgw4kZr1rtrn8t347ArW2y3yYyrnxJr1YgF42v3yDtrn8GrZYyFWS yF42vFyjya1xu3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUmF14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Gr0_Xr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Cr0_Gr 1UM28EF7xvwVC2z280aVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Cr1j 6rxdM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6x IIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_ Gr1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7M4IIrI8v6xkF7I0E8c xan2IY04v7MxkIecxEwVAFwVW8AwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWU JVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67 kF1VAFwI0_GFv_WrylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY 6xIIjxv20xvEc7CjxVAFwI0_Cr0_Gr1UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42 IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r4UJVWxJrUvcSsGvfC2 KfnxnUUI43ZEXa7VUjgo2UUUUUU== X-CM-SenderInfo: xkxd0whshlqz5rrqw2lrqou0/ Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org From: Jisheng Zhang Ftrace location could include more than a single instruction in case of some architectures (powerpc64, for now). In this case, kprobe is permitted on any of those instructions, and uses ftrace infrastructure for functioning. However, [dis]arm_kprobe_ftrace() uses the kprobe address when setting up ftrace filter IP. This won't work if the address points to any instruction apart from the one that has a branch to _mcount(). To resolve this, have [dis]arm_kprobe_ftrace() use ftrace_function() to identify the filter IP. Signed-off-by: Naveen N. Rao Acked-by: Masami Hiramatsu --- kernel/kprobes.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/kernel/kprobes.c b/kernel/kprobes.c index 41fdbb7953c6..66ee28b071c2 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c @@ -1045,9 +1045,10 @@ static int prepare_kprobe(struct kprobe *p) static int __arm_kprobe_ftrace(struct kprobe *p, struct ftrace_ops *ops, int *cnt) { + unsigned long ftrace_ip = ftrace_location((unsigned long)p->addr); int ret = 0; - ret = ftrace_set_filter_ip(ops, (unsigned long)p->addr, 0, 0); + ret = ftrace_set_filter_ip(ops, ftrace_ip, 0, 0); if (ret) { pr_debug("Failed to arm kprobe-ftrace at %pS (%d)\n", p->addr, ret); @@ -1070,7 +1071,7 @@ static int __arm_kprobe_ftrace(struct kprobe *p, struct ftrace_ops *ops, * At this point, sinec ops is not registered, we should be sefe from * registering empty filter. */ - ftrace_set_filter_ip(ops, (unsigned long)p->addr, 1, 0); + ftrace_set_filter_ip(ops, ftrace_ip, 1, 0); return ret; } @@ -1087,6 +1088,7 @@ static int arm_kprobe_ftrace(struct kprobe *p) static int __disarm_kprobe_ftrace(struct kprobe *p, struct ftrace_ops *ops, int *cnt) { + unsigned long ftrace_ip = ftrace_location((unsigned long)p->addr); int ret = 0; if (*cnt == 1) { @@ -1097,7 +1099,7 @@ static int __disarm_kprobe_ftrace(struct kprobe *p, struct ftrace_ops *ops, (*cnt)--; - ret = ftrace_set_filter_ip(ops, (unsigned long)p->addr, 1, 0); + ret = ftrace_set_filter_ip(ops, ftrace_ip, 1, 0); WARN_ONCE(ret < 0, "Failed to disarm kprobe-ftrace at %pS (%d)\n", p->addr, ret); return ret; From patchwork Sat Mar 13 06:41:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Huang Pei X-Patchwork-Id: 12136525 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C0AA0C4332D for ; Sat, 13 Mar 2021 06:43:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A8EBC64F27 for ; Sat, 13 Mar 2021 06:43:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232731AbhCMGmu (ORCPT ); Sat, 13 Mar 2021 01:42:50 -0500 Received: from mail.loongson.cn ([114.242.206.163]:42738 "EHLO loongson.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S232462AbhCMGmk (ORCPT ); Sat, 13 Mar 2021 01:42:40 -0500 Received: from localhost.localdomain (unknown [222.209.9.50]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9AxGda4XkxgjLUYAA--.9506S7; Sat, 13 Mar 2021 14:42:16 +0800 (CST) From: Huang Pei To: Thomas Bogendoerfer , ambrosehua@gmail.com Cc: Bibo Mao , linux-mips@vger.kernel.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, Jiaxun Yang , Paul Burton , Li Xuefeng , Yang Tiezhu , Gao Juxin , Huacai Chen , Jinyang He , "Maciej W . Rozycki" , Steven Rostedt , Jisheng Zhang , Masami Hiramatsu Subject: [PATCH 5/6] ftrace: introduce FTRACE_IP_EXTENSION Date: Sat, 13 Mar 2021 14:41:48 +0800 Message-Id: <20210313064149.29276-6-huangpei@loongson.cn> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210313064149.29276-1-huangpei@loongson.cn> References: <20210313064149.29276-1-huangpei@loongson.cn> X-CM-TRANSID: AQAAf9AxGda4XkxgjLUYAA--.9506S7 X-Coremail-Antispam: 1UD129KBjvJXoW7Kw43Xw4rWFyrtFyfur45Jrb_yoW8AF15pF 9rC3WkGFWxJFWqkryv93s5Gr9rCw4kZrW7Ga9rGw4Yqr9xtF1vgrnFvrs2vr1xJrZ7GFWa vFyj9ryUCw4UZFDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUmI14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Gr0_Xr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26r4UJVWxJr1l84ACjcxK6I8E87Iv6xkF7I0E14v26F4U JVW0owAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7V C0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j 6r4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x0262 8vn2kIc2xKxwCY02Avz4vE14v_GF1l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_ Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1V AY17CE14v26r4a6rW5MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_JFI_Gr1lIxAI cVC0I7IYx2IY6xkF7I0E14v26r4UJVWxJr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMI IF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr1j6F4UJbIYCTnI WIevJa73UjIFyTuYvjfUn5l8UUUUU X-CM-SenderInfo: xkxd0whshlqz5rrqw2lrqou0/ Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org From: Jisheng Zhang On some architectures, the DYNAMIC_FTRACE_WITH_REGS is implemented by gcc's -fpatchable-function-entry option. Take arm64 for example, arm64 makes use of GCC -fpatchable-function-entry=2 option to insert two nops. When the function is traced, the first nop will be modified to the LR saver, then the second nop to "bl ". we need to update ftrace_location() to recognise these two instructions as being part of ftrace. To do this, we introduce FTRACE_IP_EXTENSION to let ftrace_location search IP, IP + FTRACE_IP_EXTENSION range. Signed-off-by: Jisheng Zhang Suggested-by: Steven Rostedt (VMware) --- include/linux/ftrace.h | 4 ++++ kernel/trace/ftrace.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h index 1bd3a0356ae4..c1e1fbde8a04 100644 --- a/include/linux/ftrace.h +++ b/include/linux/ftrace.h @@ -20,6 +20,10 @@ #include +#ifndef FTRACE_IP_EXTENSION +#define FTRACE_IP_EXTENSION 0 +#endif + /* * If the arch supports passing the variable contents of * function_trace_op as the third parameter back from the diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index 9c1bba8cc51b..a6f0e3db2479 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -1583,7 +1583,7 @@ unsigned long ftrace_location_range(unsigned long start, unsigned long end) */ unsigned long ftrace_location(unsigned long ip) { - return ftrace_location_range(ip, ip); + return ftrace_location_range(ip, ip + FTRACE_IP_EXTENSION); } /** From patchwork Sat Mar 13 06:41:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Huang Pei X-Patchwork-Id: 12136523 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B5B20C433E9 for ; Sat, 13 Mar 2021 06:43:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 85E3964F23 for ; Sat, 13 Mar 2021 06:43:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232702AbhCMGmt (ORCPT ); Sat, 13 Mar 2021 01:42:49 -0500 Received: from mail.loongson.cn ([114.242.206.163]:42710 "EHLO loongson.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231383AbhCMGmh (ORCPT ); Sat, 13 Mar 2021 01:42:37 -0500 Received: from localhost.localdomain (unknown [222.209.9.50]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9AxGda4XkxgjLUYAA--.9506S8; Sat, 13 Mar 2021 14:42:18 +0800 (CST) From: Huang Pei To: Thomas Bogendoerfer , ambrosehua@gmail.com Cc: Bibo Mao , linux-mips@vger.kernel.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, Jiaxun Yang , Paul Burton , Li Xuefeng , Yang Tiezhu , Gao Juxin , Huacai Chen , Jinyang He , "Maciej W . Rozycki" , Steven Rostedt , Jisheng Zhang , Masami Hiramatsu Subject: [PATCH 6/6] MIPS: add DYNAMIC_FTRACE_WITH_REGS and KPROBES_ON_FTACE Date: Sat, 13 Mar 2021 14:41:49 +0800 Message-Id: <20210313064149.29276-7-huangpei@loongson.cn> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210313064149.29276-1-huangpei@loongson.cn> References: <20210313064149.29276-1-huangpei@loongson.cn> X-CM-TRANSID: AQAAf9AxGda4XkxgjLUYAA--.9506S8 X-Coremail-Antispam: 1UD129KBjvAXoW3KrWUXr1xWw45WFWUtF47Arb_yoW8XrW3to WS93ZIvws5JFyIqan5uay5Gr15XF15KF98Ja1Syw45WFn8tr17XFn8Ca1Dtw15ur1FyFsx ZFW3ZF48JF40yr9rn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7v73VFW2AGmfu7bjvjm3 AaLaJ3UjIYCTnIWjp_UUUOI7AC8VAFwI0_Wr0E3s1l1xkIjI8I6I8E6xAIw20EY4v20xva j40_Wr0E3s1l1IIY67AEw4v_Jr0_Jr4l82xGYIkIc2x26280x7IE14v26r126s0DM28Irc Ia0xkI8VCY1x0267AKxVW5JVCq3wA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK021l 84ACjcxK6xIIjxv20xvE14v26r4j6ryUM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4UJV WxJr1l84ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVCY1x0267AKxVWx Jr0_GcWle2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx 0E2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbVWU JVW8JwACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lFIxGxcIEc7CjxV A2Y2ka0xkIwI1lc2xSY4AK67AK6r47MxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY 6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17 CEb7AF67AKxVW8ZVWrXwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1I6r4UMIIF 0xvE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr1UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCw CI42IY6I8E87Iv67AKxVW8JVWxJwCI42IY6I8E87Iv6xkF7I0E14v26r4UJVWxJrUvcSsG vfC2KfnxnUUI43ZEXa7VUjgo2UUUUUU== X-CM-SenderInfo: xkxd0whshlqz5rrqw2lrqou0/ Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org Add DYNAMIC_FTRACE_WITH_REGS and KPROBES_ON_FTACE suppport with another ftrace implementation in parallel with mcount-based ftrace +. Depend on GCC with -fpatchable-function-entry. +. Depend on DYNAMIC_FTRACE. +. Use 3 nops for stub in module and vmlinux, smaller than old one. +. Simplify ftrace_regs_caller/ftrace_caller handling, especially on MIPS O32. +. No adjustment on sp, so callee(the traced function) can get caller's sp, very friendly to livepatch. Signed-off-by: Huang Pei Reported-by: kernel test robot --- arch/mips/Kconfig | 4 + arch/mips/Makefile | 16 +- arch/mips/include/asm/ftrace.h | 9 ++ arch/mips/kernel/Makefile | 5 +- arch/mips/kernel/entry-ftrace.S | 188 ++++++++++++++++++++++ arch/mips/kernel/ftrace.c | 271 ++++++++++++++++++++++++++++++++ 6 files changed, 488 insertions(+), 5 deletions(-) create mode 100644 arch/mips/kernel/entry-ftrace.S create mode 100644 arch/mips/kernel/ftrace.c diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig index 5741dae35b74..dafc65b0226a 100644 --- a/arch/mips/Kconfig +++ b/arch/mips/Kconfig @@ -56,6 +56,10 @@ config MIPS select HAVE_DEBUG_STACKOVERFLOW select HAVE_DMA_CONTIGUOUS select HAVE_DYNAMIC_FTRACE + select HAVE_DYNAMIC_FTRACE_WITH_REGS \ + if $(cc-option, -fpatchable-function-entry=3) + select HAVE_KPROBES_ON_FTRACE \ + if $(cc-option, -fpatchable-function-entry=3) select HAVE_EBPF_JIT if 64BIT && !CPU_MICROMIPS && TARGET_ISA_REV >= 2 select HAVE_EXIT_THREAD select HAVE_FAST_GUP diff --git a/arch/mips/Makefile b/arch/mips/Makefile index 0d0f29d662c9..1d6553f0623e 100644 --- a/arch/mips/Makefile +++ b/arch/mips/Makefile @@ -56,13 +56,16 @@ ifneq ($(SUBARCH),$(ARCH)) endif endif -ifdef CONFIG_FUNCTION_GRAPH_TRACER - ifndef KBUILD_MCOUNT_RA_ADDRESS - ifeq ($(call cc-option-yn,-mmcount-ra-address), y) - cflags-y += -mmcount-ra-address -DKBUILD_MCOUNT_RA_ADDRESS +ifndef CONFIG_DYNMAIC_FTRACE_WITH_REGS + ifdef CONFIG_FUNCTION_GRAPH_TRACER + ifndef KBUILD_MCOUNT_RA_ADDRESS + ifeq ($(call cc-option-yn,-mmcount-ra-address), y) + cflags-y += -mmcount-ra-address -DKBUILD_MCOUNT_RA_ADDRESS + endif endif endif endif + cflags-y += $(call cc-option, -mno-check-zero-division) ifdef CONFIG_32BIT @@ -293,6 +296,11 @@ ifdef CONFIG_64BIT bootvars-y += ADDR_BITS=64 endif +ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS + KBUILD_CPPFLAGS += -DCC_USING_PATCHABLE_FUNCTION_ENTRY + CC_FLAGS_FTRACE := -fpatchable-function-entry=3 +endif + # This is required to get dwarf unwinding tables into .debug_frame # instead of .eh_frame so we don't discard them. KBUILD_CFLAGS += -fno-asynchronous-unwind-tables diff --git a/arch/mips/include/asm/ftrace.h b/arch/mips/include/asm/ftrace.h index b463f2aa5a61..5508890566ea 100644 --- a/arch/mips/include/asm/ftrace.h +++ b/arch/mips/include/asm/ftrace.h @@ -14,6 +14,7 @@ #define MCOUNT_ADDR ((unsigned long)(_mcount)) #define MCOUNT_INSN_SIZE 4 /* sizeof mcount call */ +#define FTRACE_IP_EXTENSION (2 * MCOUNT_INSN_SIZE) #ifndef __ASSEMBLY__ extern void _mcount(void); @@ -87,4 +88,12 @@ struct dyn_arch_ftrace { #endif /* CONFIG_DYNAMIC_FTRACE */ #endif /* __ASSEMBLY__ */ #endif /* CONFIG_FUNCTION_TRACER */ + +#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS +#define ARCH_SUPPORTS_FTRACE_OPS 1 +struct dyn_ftrace; +int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec); +#define ftrace_init_nop ftrace_init_nop +#endif + #endif /* _ASM_MIPS_FTRACE_H */ diff --git a/arch/mips/kernel/Makefile b/arch/mips/kernel/Makefile index 3e7b0ee54cfb..7b07d80aadd5 100644 --- a/arch/mips/kernel/Makefile +++ b/arch/mips/kernel/Makefile @@ -21,6 +21,7 @@ CFLAGS_REMOVE_ftrace-mcount.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_early_printk.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_perf_event.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_perf_event_mipsxx.o = $(CC_FLAGS_FTRACE) +CFLAGS_REMOVE_ftrace.o = $(CC_FLAGS_FTRACE) endif obj-$(CONFIG_CEVT_BCM1480) += cevt-bcm1480.o @@ -39,7 +40,9 @@ obj-$(CONFIG_DEBUG_FS) += segment.o obj-$(CONFIG_STACKTRACE) += stacktrace.o obj-$(CONFIG_MODULES) += module.o -obj-$(CONFIG_FUNCTION_TRACER) += mcount.o ftrace-mcount.o +ft-$(CONFIG_FUNCTION_TRACER) += mcount.o ftrace-mcount.o +ft-$(CONFIG_DYNAMIC_FTRACE_WITH_REGS) := entry-ftrace.o ftrace.o +obj-y += $(ft-y) sw-y := r4k_switch.o sw-$(CONFIG_CPU_R3000) := r2300_switch.o diff --git a/arch/mips/kernel/entry-ftrace.S b/arch/mips/kernel/entry-ftrace.S new file mode 100644 index 000000000000..c920a568ce77 --- /dev/null +++ b/arch/mips/kernel/entry-ftrace.S @@ -0,0 +1,188 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * arch/mips/kernel/entry_ftrace.S + * + * Copyright (C) 2021 Loongson Corp + * Author: Huang Pei + */ + +#include +#include +#include + +/* + * ftrace_regs_caller() is the function that replaces _mcount() when ftrace + * is active. + * + * we arrive here after a function A calls function B, and B is what we + * are tracing for. When we enter, sp points to A's stack frame, B has not + * yet had a chance to allocate one yet. (This is different from -pg case + * , in which the B's stack is allocated)) + + * when ftrace initialized, it replace three nops from all function with + * "lui + nop + move" + * B: + * lui at, %hi(ftrace_regs_caller) + * nop + * li t0, 0 + * # B's real start + * + * at B's entry, when tracing enabled, replace the 'nop' with 'jalr' + * + * # B's entry, three nop for both in vmlinux and in kernel modules + * B: + * lui at, %hi(ftrace_regs_caller) + * jalr at, at + * move t0, zero + * # B's real start + * + * if set t0 to 1, then calling ftrace_regs_caller with partial regs saved + * + * B: + * lui at, %hi(ftrace_regs_caller) + * jalr at, at + * li t0, 1 + * # B's real start + * + * we make ftrace_regs_caller 64KB aligned, when entring ftrace_regs_caller + * AT points to the return address to B, and ra points to return address + * to A, + * + * if patched to new funcition, then clobbered the first real instruction + * + * B: + * lui at, %hi(new_B) + * addiu at, at, %lo(new_B) + * jr at + * # B's real start, now clobbered with zero + * nop + * + */ + .text + .set push + .set noreorder + .set noat + .align 16 +NESTED(ftrace_regs_caller, PT_SIZE, ra) + PTR_ADDIU sp, sp, -PT_SIZE + .globl ftrace_caller +ftrace_caller: +#ifdef CONFIG_64BIT + PTR_S a4, PT_R8(sp) + PTR_S a5, PT_R9(sp) + PTR_S a6, PT_R10(sp) + PTR_S a7, PT_R11(sp) +#endif + PTR_S a0, PT_R4(sp) + PTR_S a1, PT_R5(sp) + PTR_S a2, PT_R6(sp) + + bnez t0, 1f + PTR_S a3, PT_R7(sp) + + PTR_S t0, PT_R12(sp) + PTR_S t1, PT_R13(sp) + PTR_S t2, PT_R14(sp) + PTR_S t3, PT_R15(sp) + + PTR_S s0, PT_R16(sp) + PTR_S s1, PT_R17(sp) + PTR_S s2, PT_R18(sp) + PTR_S s3, PT_R19(sp) + + PTR_S s4, PT_R20(sp) + PTR_S s5, PT_R21(sp) + PTR_S s6, PT_R22(sp) + PTR_S s7, PT_R23(sp) + + + PTR_S t8, PT_R24(sp) + PTR_S t9, PT_R25(sp) + PTR_S s8, PT_R30(sp) + PTR_S gp, PT_R28(sp) + + PTR_S AT, PT_R1(sp) +1: + PTR_LA t0, PT_SIZE(sp) + PTR_S AT, PT_R0(sp) //R0 for expected epc + PTR_S t0, PT_R29(sp) + + PTR_S ra, PT_R31(sp) + PTR_S AT, PT_EPC(sp) //PT_EPC maybe changed by kprobe handler + + END(ftrace_regs_caller) + +ftrace_common: + PTR_ADDIU a0, AT, -12 //a0 points to B's entry address + move a1, ra //a1 points to return address to A + PTR_L a2, function_trace_op //a2 points to function_trace op + + .globl ftrace_call +ftrace_call: + jal ftrace_stub + move a3, sp //a3 point to pt_regs + +#ifdef CONFIG_FUNCTION_GRAPH_TRACER + .globl ftrace_graph_call +ftrace_graph_call: + nop + nop +#endif + +ftrace_common_return: + PTR_L AT, PT_R31(sp) +ftrace_graph_return: + PTR_L ra, PT_EPC(sp) + PTR_L a0, PT_R4(sp) + PTR_L a1, PT_R5(sp) + PTR_L a2, PT_R6(sp) + PTR_L a3, PT_R7(sp) +#ifdef CONFIG_64BIT + PTR_L a4, PT_R8(sp) + PTR_L a5, PT_R9(sp) + PTR_L a6, PT_R10(sp) + PTR_L a7, PT_R11(sp) +#endif + PTR_ADDIU sp, sp, PT_SIZE //retore stack frame + jr ra + move ra, AT + + + .globl ftrace_stub +ftrace_stub: + jr ra + nop + +#ifdef CONFIG_FUNCTION_GRAPH_TRACER + .globl ftrace_graph_caller +ftrace_graph_caller: + PTR_L a0, PT_R31(sp) + PTR_L a1, PT_EPC(sp) + jal prepare_ftrace_return + PTR_ADDIU a2, sp, PT_SIZE + + b ftrace_graph_return + move AT, v0 + + + .align 2 + .globl return_to_handler +return_to_handler: + PTR_SUBU sp, PT_SIZE + PTR_S v0, PT_R2(sp) + + PTR_S v1, PT_R3(sp) + jal ftrace_return_to_handler + PTR_LA a0, PT_SIZE(sp) + + /* restore the real parent address: v0 -> ra */ + move ra, v0 + + PTR_L v0, PT_R2(sp) + PTR_L v1, PT_R3(sp) + jr ra + PTR_ADDIU sp, PT_SIZE + + .set at + .set reorder +#endif /* CONFIG_FUNCTION_GRAPH_TRACER */ diff --git a/arch/mips/kernel/ftrace.c b/arch/mips/kernel/ftrace.c new file mode 100644 index 000000000000..c3baa2e692c1 --- /dev/null +++ b/arch/mips/kernel/ftrace.c @@ -0,0 +1,271 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * arch/mips/kernel/ftrace.c + * + * Copyright (C) 2021 Loongson Limited Corp. + * Author: Huang Pei + */ + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + + +#define INSN_NOP 0x00000000 /* nop */ +#define INSN_JALR_AT2 0x00200809 /* jalr at, at */ +#define INSN_LI_0 0x240c0000 /* li t0, 0 */ +#define INSN_LI_1 0x240c0001 /* li t0, 1 */ +#define FTRACE_CALL_IP ((unsigned long)(&ftrace_call)) +#define JAL 0x0c000000 /* jump & link: ip --> ra, jump to target */ +#define ADDR_MASK 0x03ffffff /* op_code|addr : 31...26|25 ....0 */ +#define INSN_JAL(addr) \ + ((unsigned int)(JAL | (((addr) >> 2) & ADDR_MASK))) + +extern void ftrace_graph_call(void); + +static unsigned int insn_lui __read_mostly; + +/* Arch override because MIPS doesn't need to run this from stop_machine() */ +void arch_ftrace_update_code(int command) +{ + ftrace_modify_all_code(command); +} + +static int ftrace_modify_code(unsigned long ip, unsigned int new_code) +{ + int faulted; + mm_segment_t old_fs; + + /* *(unsigned int *)ip = new_code; */ + safe_store_code(new_code, ip, faulted); + + if (unlikely(faulted)) + return -EFAULT; + + old_fs = get_fs(); + set_fs(KERNEL_DS); + flush_icache_range(ip, ip + 8); + set_fs(old_fs); + + return 0; +} + +int ftrace_update_ftrace_func(ftrace_func_t func) +{ + unsigned int new; + + new = INSN_JAL((unsigned long)func); + + return ftrace_modify_code(FTRACE_CALL_IP, new); +} + +/* + * enable tracing by replacing the middle nop with jalr, like + * + * lui at, %hi(ftrace_regs_all) + * jalr at, at + * li t0, 0 + */ +int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr) +{ + unsigned long ip = rec->ip; + + ftrace_modify_code(ip + 4, INSN_JALR_AT2); + return 0; +} + +/* + * disable recording regs by replacing + * + * li t0, 0 + * + * with + * + * li, t0, 1 + * + * or vesa + */ +int ftrace_modify_call(struct dyn_ftrace *rec, unsigned long old_addr, + unsigned long addr) +{ + unsigned long ip = rec->ip; + + if (abs(old_addr - addr) == 4) { + if (addr == (unsigned long)ftrace_regs_caller) + return ftrace_modify_code(ip + 4, INSN_LI_0); + + if (addr == (unsigned long)ftrace_caller) + return ftrace_modify_code(ip + 4, INSN_LI_1); + + } + + /* we do not support direct call or trampoline now */ + + return -1; + +} + +/* + * replace all three nop at the entry with + * + * lui at, %hi(ftrace_regs_all) + * nop + * li t0, 1 + */ + +int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec) +{ + unsigned long ip = rec->ip; + + ftrace_modify_code(ip, insn_lui); + + ftrace_modify_code(ip + 8, INSN_LI_1); + return 0; +} + + + +/* + * disable tracing by replacing + * + * jalr at, at + * + * with + * + * nop + * + */ + +int ftrace_make_nop(struct module *mod, struct dyn_ftrace *rec, + unsigned long addr) + +{ + unsigned int new = INSN_NOP; + unsigned long ip = rec->ip + 4; + + return ftrace_modify_code(ip, new); +} + +int __init ftrace_dyn_arch_init(void) +{ + u32 *buf; + int reg; + + reg = 1; + /* lui at, %hi(ftrace_regs_all) */ + buf = (u32*)&insn_lui; + uasm_i_lui(&buf, reg, uasm_rel_hi((long)ftrace_regs_caller)); + + return 0; +} + +void kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip, + struct ftrace_ops *ops, struct pt_regs *regs) +{ + struct kprobe *p; + struct kprobe_ctlblk *kcb; + unsigned long orig_ip; + + p = get_kprobe((kprobe_opcode_t *)ip); + if (unlikely(!p) || kprobe_disabled(p)) + return; + + kcb = get_kprobe_ctlblk(); + if (kprobe_running()) { + kprobes_inc_nmissed_count(p); + } else { + /* + * pre_handler need epc point to the kprobe + * + */ + orig_ip = instruction_pointer(regs); + instruction_pointer_set(regs, (unsigned long)p->addr); + __this_cpu_write(current_kprobe, p); + kcb->kprobe_status = KPROBE_HIT_ACTIVE; + if (!p->pre_handler || !p->pre_handler(p, regs)) { + /* + * Emulate singlestep (and also recover regs->nip) + * as if there is a nop + */ + if (unlikely(p->post_handler)) { + kcb->kprobe_status = KPROBE_HIT_SSDONE; + if ((unsigned long)p->addr == (ip + 4)) + + ip = (unsigned long)p->addr + 8; + else + ip = (unsigned long)p->addr + 4; + instruction_pointer_set(regs, ip); + p->post_handler(p, regs, 0); + } + } + instruction_pointer_set(regs, orig_ip); + /* + * If pre_handler returns !0, we have to + * skip emulating post_handler. + */ + __this_cpu_write(current_kprobe, NULL); + } + +} + +int arch_prepare_kprobe_ftrace(struct kprobe *p) +{ + p->ainsn.insn = NULL; + return 0; +} + +#ifdef CONFIG_FUNCTION_GRAPH_TRACER +unsigned long prepare_ftrace_return(unsigned long parent, unsigned long self_ra, + unsigned long fp) +{ + unsigned long return_hooker = (unsigned long)&return_to_handler; + + if (unlikely(ftrace_graph_is_dead())) + goto out; + + if (unlikely(atomic_read(¤t->tracing_graph_pause))) + goto out; + + self_ra -= 8; + if (!function_graph_enter(parent, self_ra, fp, NULL)) + parent = return_hooker; +out: + return parent; +} + +/* + * Turn on/off the call to ftrace_graph_caller() in ftrace_caller() + * depending on @enable. + */ +static int ftrace_modify_graph_caller(bool enable) +{ + unsigned long pc = (unsigned long)ftrace_graph_call; + unsigned new; + + if (enable) + new = INSN_JAL((unsigned long)ftrace_graph_caller); + else + new = INSN_NOP; + + return ftrace_modify_code(pc, new); +} + +int ftrace_enable_ftrace_graph_caller(void) +{ + return ftrace_modify_graph_caller(true); +} + +int ftrace_disable_ftrace_graph_caller(void) +{ + return ftrace_modify_graph_caller(false); +} + +#endif /* CONFIG_FUNCTION_GRAPH_TRACER */