From patchwork Thu Mar 13 10:13:50 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 3825121 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id D8AB1BF540 for ; Thu, 13 Mar 2014 11:19:44 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E7F40201CE for ; Thu, 13 Mar 2014 11:19:43 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E3741201BA for ; Thu, 13 Mar 2014 11:19:42 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WO2hC-0003BO-CN; Thu, 13 Mar 2014 10:17:02 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WO2gZ-0002xE-Jr; Thu, 13 Mar 2014 10:16:23 +0000 Received: from mail-pb0-f41.google.com ([209.85.160.41]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WO2fo-0002pU-KN for linux-arm-kernel@lists.infradead.org; Thu, 13 Mar 2014 10:15:41 +0000 Received: by mail-pb0-f41.google.com with SMTP id jt11so904561pbb.0 for ; Thu, 13 Mar 2014 03:15:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Thfp9W8SUcYUP1Db2L/Wlvo5LjAvidPsQjbaa3MOkN0=; b=eq01wEtoO4AEtooxs85AI7ZlQvKPMWBmGw7PyWaGPZYYnWp+gpQXj5G12NY3UCaaPe Yb2NHsfY3HAPrOzYUsvsRaZlCNlcNXfU2TQX+KwJpSOM3yAu5TA5daW6TgK+rataifw4 X1lW5pO2usCb7Qjpp9YXQdyNP1SBz5N10r6jjmuZJ5L3jjUdYgEbeSC35pFFUsvpY31F 6Ep771Oq5RzCnsgXEsAsZax7Al633wLx+KGeesdf9r18EzLc0qxqH5RTXXWdYisTm4jM vMAOEXoZDMmq2vB0kxoOI3Q1iqjt0Mdf1jyoI4ohpWGWwNJQgj8yhH8XLhvs9lJuDPUO qp2g== X-Gm-Message-State: ALoCoQnUCYz92xuzHmVWu5w7HqMIfL+XDZQ+NQbowMo8IMVWPxwfjattaq9Bwq0V1xiJwpDNJDVp X-Received: by 10.68.143.34 with SMTP id sb2mr1129699pbb.135.1394705715237; Thu, 13 Mar 2014 03:15:15 -0700 (PDT) Received: from localhost.localdomain (KD182249091179.au-net.ne.jp. [182.249.91.179]) by mx.google.com with ESMTPSA id yj1sm7505037pab.30.2014.03.13.03.15.09 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 13 Mar 2014 03:15:13 -0700 (PDT) From: AKASHI Takahiro To: rostedt@goodmis.org, fweisbec@gmail.com, mingo@redhat.com, catalin.marinas@arm.com, will.deacon@arm.com, tim.bird@sonymobile.com Subject: [PATCH v6 7/7] arm64: ftrace: Add system call tracepoint Date: Thu, 13 Mar 2014 19:13:50 +0900 Message-Id: <1394705630-12384-8-git-send-email-takahiro.akashi@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1394705630-12384-1-git-send-email-takahiro.akashi@linaro.org> References: <1393564724-3966-1-git-send-email-takahiro.akashi@linaro.org> <1394705630-12384-1-git-send-email-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140313_061536_878791_C16CB1DA X-CRM114-Status: GOOD ( 17.09 ) X-Spam-Score: -2.6 (--) Cc: linaro-kernel@lists.linaro.org, arndb@arndb.de, linux-kernel@vger.kernel.org, AKASHI Takahiro , dsaxena@linaro.org, gkulkarni@caviumnetworks.com, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch allows system call entry or exit to be traced as ftrace events, ie. sys_enter_*/sys_exit_*, if CONFIG_FTRACE_SYSCALLS is enabled. Those events appear and can be controlled under ${sysfs}/tracing/events/syscalls/ Please note that we can't trace compat system calls here because AArch32 mode does not share the same syscall table with AArch64. Just define ARCH_TRACE_IGNORE_COMPAT_SYSCALLS in order to avoid unexpected results (bogus syscalls reported or even hang-up). Signed-off-by: AKASHI Takahiro --- arch/arm64/Kconfig | 1 + arch/arm64/include/asm/ftrace.h | 20 ++++++++++++++++ arch/arm64/include/asm/syscall.h | 1 + arch/arm64/include/asm/unistd.h | 2 ++ arch/arm64/kernel/ptrace.c | 48 ++++++++++++++++++++++---------------- 5 files changed, 52 insertions(+), 20 deletions(-) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 6954959..b1dcdb4 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -43,6 +43,7 @@ config ARM64 select HAVE_MEMBLOCK select HAVE_PATA_PLATFORM select HAVE_PERF_EVENTS + select HAVE_SYSCALL_TRACEPOINTS select IRQ_DOMAIN select MODULES_USE_ELF_RELA select NO_BOOTMEM diff --git a/arch/arm64/include/asm/ftrace.h b/arch/arm64/include/asm/ftrace.h index c44c4b1..4ef06f1 100644 --- a/arch/arm64/include/asm/ftrace.h +++ b/arch/arm64/include/asm/ftrace.h @@ -44,6 +44,26 @@ static inline unsigned long ftrace_call_adjust(unsigned long addr) #define CALLER_ADDR4 ((unsigned long)return_address(4)) #define CALLER_ADDR5 ((unsigned long)return_address(5)) #define CALLER_ADDR6 ((unsigned long)return_address(6)) + +#include + +/* + * Because AArch32 mode does not share the same syscall table with AArch64, + * tracing compat syscalls may result in reporting bogus syscalls or even + * hang-up, so just do not trace them. + * See kernel/trace/trace_syscalls.c + * + * x86 code says: + * If the user realy wants these, then they should use the + * raw syscall tracepoints with filtering. + */ +#define ARCH_TRACE_IGNORE_COMPAT_SYSCALLS 1 +static inline bool arch_trace_is_compat_syscall(struct pt_regs *regs) +{ + if (is_compat_task()) + return true; + return false; +} #endif /* ifndef __ASSEMBLY__ */ #endif /* __ASM_FTRACE_H */ diff --git a/arch/arm64/include/asm/syscall.h b/arch/arm64/include/asm/syscall.h index 70ba9d4..383771e 100644 --- a/arch/arm64/include/asm/syscall.h +++ b/arch/arm64/include/asm/syscall.h @@ -18,6 +18,7 @@ #include +extern const void *sys_call_table[]; static inline int syscall_get_nr(struct task_struct *task, struct pt_regs *regs) diff --git a/arch/arm64/include/asm/unistd.h b/arch/arm64/include/asm/unistd.h index 82ce217..c335479 100644 --- a/arch/arm64/include/asm/unistd.h +++ b/arch/arm64/include/asm/unistd.h @@ -28,3 +28,5 @@ #endif #define __ARCH_WANT_SYS_CLONE #include + +#define NR_syscalls (__NR_syscalls) diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c index 9993a8f..9c52b3e 100644 --- a/arch/arm64/kernel/ptrace.c +++ b/arch/arm64/kernel/ptrace.c @@ -41,6 +41,9 @@ #include #include +#define CREATE_TRACE_POINTS +#include + /* * TODO: does not yet catch signals sent when the child dies. * in exit.c or in signal.c. @@ -1062,29 +1065,31 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs) { unsigned long saved_reg; - if (!test_thread_flag(TIF_SYSCALL_TRACE)) - return regs->syscallno; + if (test_thread_flag(TIF_SYSCALL_TRACE)) { + /* + * A scrach register (ip(r12) on AArch32, x7 on AArch64) is + * used to denote syscall entry/exit: + * 0 -> entry + */ + if (is_compat_task()) { + saved_reg = regs->regs[12]; + regs->regs[12] = 0; + } else { + saved_reg = regs->regs[7]; + regs->regs[7] = 0; + } - /* - * A scrach register (ip(r12) on AArch32, x7 on AArch64) is - * used to denote syscall entry/exit: - * 0 -> entry - */ - if (is_compat_task()) { - saved_reg = regs->regs[12]; - regs->regs[12] = 0; - } else { - saved_reg = regs->regs[7]; - regs->regs[7] = 0; - } + if (tracehook_report_syscall_entry(regs)) + regs->syscallno = ~0UL; - if (tracehook_report_syscall_entry(regs)) - regs->syscallno = ~0UL; + if (is_compat_task()) + regs->regs[12] = saved_reg; + else + regs->regs[7] = saved_reg; + } - if (is_compat_task()) - regs->regs[12] = saved_reg; - else - regs->regs[7] = saved_reg; + if (test_thread_flag(TIF_SYSCALL_TRACEPOINT)) + trace_sys_enter(regs, regs->syscallno); return regs->syscallno; } @@ -1093,6 +1098,9 @@ asmlinkage void syscall_trace_exit(struct pt_regs *regs) { unsigned long saved_reg; + if (test_thread_flag(TIF_SYSCALL_TRACEPOINT)) + trace_sys_exit(regs, regs_return_value(regs)); + if (!test_thread_flag(TIF_SYSCALL_TRACE)) return;