From patchwork Mon Sep 5 02:33:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pratyush Anand X-Patchwork-Id: 9312959 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BD91460760 for ; Mon, 5 Sep 2016 02:35:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AAD3E28807 for ; Mon, 5 Sep 2016 02:35:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9FA042880A; Mon, 5 Sep 2016 02:35:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 22EA128807 for ; Mon, 5 Sep 2016 02:35:17 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bgjjJ-0001x2-Lg; Mon, 05 Sep 2016 02:33:49 +0000 Received: from mail-yw0-f176.google.com ([209.85.161.176]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bgjjF-0001rT-Mb for linux-arm-kernel@lists.infradead.org; Mon, 05 Sep 2016 02:33:47 +0000 Received: by mail-yw0-f176.google.com with SMTP id s85so2374100ywg.3 for ; Sun, 04 Sep 2016 19:33:23 -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; bh=QAMHJSQgpCEHZeQYyvdQ5mKlD/nh5YxJhh965TTS0yE=; b=V6kozum+cGIl7AgUngji0jeLd8kS74/qK5ac7QK1Ho2zy/WpBx9GpBlLO5hic3PW6p QKWGXthxAJSaLOs0uFgqSMmJcToIw3scRcBbMOBi43xNxwViYkpU6tJkgPE92MSd+EcH 1dKUmddKXEcw8MjoWayqhqjcbwGCxrdvBILl9hFRHJPPFS7LOoSTMRFDeX8psp+EgJ7s uQk11oGFf7YniFZtu71EMG20z1nCOIW4E6RMlD9cY4wbWcRSy9+rE202aczNfldAziKR VcsYGFupeQ/6ipbvygOd4VBm96Q9DNs3LVQpQ5X/ex90Z4Tz8DGEc+aRQifR7J7ULXmC 57qA== X-Gm-Message-State: AE9vXwPj/6UtthnSaez+j3zpLQ/06YX/NbWV8MBJogMJDMmgwQMWv3T+pt09xqyzmy8z4Co3 X-Received: by 10.13.225.72 with SMTP id k69mr27740671ywe.32.1473042802058; Sun, 04 Sep 2016 19:33:22 -0700 (PDT) Received: from localhost ([122.162.149.17]) by smtp.gmail.com with ESMTPSA id b9sm9302377ywh.45.2016.09.04.19.33.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 04 Sep 2016 19:33:21 -0700 (PDT) From: Pratyush Anand To: will.deacon@arm.com Subject: [PATCH V3] arm64:ftrace: add save_stack_trace_regs() Date: Mon, 5 Sep 2016 08:03:16 +0530 Message-Id: <12a4a8e304fb26dbe533be0ea68e448df462a7c5.1473038514.git.panand@redhat.com> X-Mailer: git-send-email 2.7.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160904_193345_898176_8E27ACD2 X-CRM114-Status: GOOD ( 13.35 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: takahiro.akashi@linaro.org, james.morse@arm.com, dave.long@linaro.org, linux-arm-kernel@lists.infradead.org, catalin.marinas@arm.com MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Currently, enabling stacktrace of a kprobe events generates warning: echo stacktrace > /sys/kernel/debug/tracing/trace_options echo "p xhci_irq" > /sys/kernel/debug/tracing/kprobe_events echo 1 > /sys/kernel/debug/tracing/events/kprobes/enable save_stack_trace_regs() not implemented yet. ------------[ cut here ]------------ WARNING: CPU: 1 PID: 0 at ../kernel/stacktrace.c:74 save_stack_trace_regs+0x3c/0x48 Modules linked in: CPU: 1 PID: 0 Comm: swapper/1 Not tainted 4.8.0-rc4-dirty #5128 Hardware name: ARM Juno development board (r1) (DT) task: ffff800975dd1900 task.stack: ffff800975ddc000 PC is at save_stack_trace_regs+0x3c/0x48 LR is at save_stack_trace_regs+0x3c/0x48 pc : [] lr : [] pstate: 600003c5 sp : ffff80097ef52c00 Call trace: [] save_stack_trace_regs+0x3c/0x48 [] __ftrace_trace_stack+0x168/0x208 [] trace_buffer_unlock_commit_regs+0x5c/0x7c [] kprobe_trace_func+0x308/0x3d8 [] kprobe_dispatcher+0x58/0x60 [] kprobe_breakpoint_handler+0xbc/0x18c [] brk_handler+0x50/0x90 [] do_debug_exception+0x50/0xbc This patch implements save_stack_trace_regs(), so that stacktrace of a kprobe events can be obtained. After this patch, there is no warning and we can see the stacktrace for kprobe events in trace buffer. more /sys/kernel/debug/tracing/trace -0 [004] d.h. 1356.000496: p_xhci_irq_0:(xhci_irq+0x0/0x9ac) -0 [004] d.h. 1356.000497: => xhci_irq => __handle_irq_event_percpu => handle_irq_event_percpu => handle_irq_event => handle_fasteoi_irq => generic_handle_irq => __handle_domain_irq => gic_handle_irq => el1_irq => arch_cpu_idle => default_idle_call => cpu_startup_entry => secondary_start_kernel => Tested-by: David A. Long Reviewed-by: James Morse Signed-off-by: Pratyush Anand --- v1 to v2: Rebased with 4.8.0-rc4 v2 to v3: CONFIG_FUNCTION_GRAPH_TRACER fixup and improved commit log arch/arm64/kernel/stacktrace.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c index d9751a4769e7..ca01addf8c4c 100644 --- a/arch/arm64/kernel/stacktrace.c +++ b/arch/arm64/kernel/stacktrace.c @@ -152,6 +152,27 @@ static int save_trace(struct stackframe *frame, void *d) return trace->nr_entries >= trace->max_entries; } +void save_stack_trace_regs(struct pt_regs *regs, struct stack_trace *trace) +{ + struct stack_trace_data data; + struct stackframe frame; + + data.trace = trace; + data.skip = trace->skip; + data.no_sched_functions = 0; + + frame.fp = regs->regs[29]; + frame.sp = regs->sp; + frame.pc = regs->pc; +#ifdef CONFIG_FUNCTION_GRAPH_TRACER + frame.graph = current->curr_ret_stack; +#endif + + walk_stackframe(current, &frame, save_trace, &data); + if (trace->nr_entries < trace->max_entries) + trace->entries[trace->nr_entries++] = ULONG_MAX; +} + void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace) { struct stack_trace_data data;