Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2416341imu; Tue, 6 Nov 2018 14:17:26 -0800 (PST) X-Google-Smtp-Source: AJdET5e9FElhQlDNyQCXZWl6SNYaIr1pVD0AF6DMthQQ35kkUgjyghVaoDx/eqnfFowdq59ujvRn X-Received: by 2002:a17:902:24a5:: with SMTP id w34-v6mr27864250pla.91.1541542646773; Tue, 06 Nov 2018 14:17:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541542646; cv=none; d=google.com; s=arc-20160816; b=La8ApiUMTMST7ch4PG9XssQ01wMfgDAPbOWRw8Fn1DtVLzDav6bU38cFiyAbqHkzy9 nvwFbSAnwslb5CZCE50y0XItbPnM/n083gYWbwoGo4p+u0AzDz1jtjTTYH2sW+EuAYeX /EuZrsJ3/E0GP8R5ICVYzfpOYH1/Rdr605jdaWtwH6c07yWQvswakAKUzo4LKOH4DNu7 P2HhpPiB7nuXmjJAbIz/RDLT5HCXkgg5l7FsuychbId0hCWEnmCwfMGtrti96Vouy1LG LhelU3u62vzjgJLCf4f04udYAqncycwMy7PuwxzCggVic4RjCC/48+4xGzKH8FJzdauG qH1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=3trpXL7T2Erk8AmC+CbvcoY9Qss2j4KK3EafkOLmGdQ=; b=BX3waZ5Pj0qgbUyPO4vce/Fmh9VI8X1xRq8jOvGyKPug8Gbj4XjfyjhGxi42Eq1J17 HOsF9ghgPe9xrGUG37/VLP0y0TmjRMPiU2tYVCoBw4/ensfsGlkRWe0CxPSVlfwrLrZr OuueqJeoiODNrWspfU0GjVgsK7DttbNxpbH/PkmwjvOeVtyg1mLIvGnQGOdp2aVonuxB DJ7HnLZ8oMdwMdJ1NG/0NpW92sXH1DnC2lORPwBWVpxzIZDbHvMPpdr7DRfXmCm1DIdq ZA7oJ82a6SOU/tkm9BylV9f5y8rppOl94Gt8ZPpc1wlZQ9Sr8mo8bE37zK0+zmVdC/gs pimw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v26-v6si23723782pge.101.2018.11.06.14.17.11; Tue, 06 Nov 2018 14:17:26 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730733AbeKGHma (ORCPT + 99 others); Wed, 7 Nov 2018 02:42:30 -0500 Received: from mail.kernel.org ([198.145.29.99]:52496 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726446AbeKGHm3 (ORCPT ); Wed, 7 Nov 2018 02:42:29 -0500 Received: from gandalf.local.home (cpe-66-24-56-78.stny.res.rr.com [66.24.56.78]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 37B7220830; Tue, 6 Nov 2018 22:15:03 +0000 (UTC) Date: Tue, 6 Nov 2018 17:15:01 -0500 From: Steven Rostedt To: Aleksa Sarai Cc: "Naveen N. Rao" , Anil S Keshavamurthy , "David S. Miller" , Masami Hiramatsu , Jonathan Corbet , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Shuah Khan , Alexei Starovoitov , Daniel Borkmann , Brendan Gregg , Christian Brauner , Aleksa Sarai , netdev@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Josh Poimboeuf Subject: Re: [PATCH v3 1/2] kretprobe: produce sane stack traces Message-ID: <20181106171501.59ccabbc@gandalf.local.home> In-Reply-To: <20181104115913.74l4yzecisvtt2j5@yavin> References: <20181101083551.3805-1-cyphar@cyphar.com> <20181101083551.3805-2-cyphar@cyphar.com> <20181101204720.6ed3fe37@vmware.local.home> <20181102050509.tw3dhvj5urudvtjl@yavin> <20181102065932.bdt4pubbrkvql4mp@yavin> <20181102091658.1bc979a4@gandalf.local.home> <20181103070253.ajrqzs5xu2vf5stu@yavin> <20181104115913.74l4yzecisvtt2j5@yavin> X-Mailer: Claws Mail 3.16.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, 4 Nov 2018 22:59:13 +1100 Aleksa Sarai wrote: > The same issue is present in __save_stack_trace > (arch/x86/kernel/stacktrace.c). This is likely the only reason that -- > as Steven said -- stacktraces wouldn't work with ftrace-graph (and thus > with the refactor both of you are discussing). By the way, I was playing with the the orc unwinder and stack traces from the function graph tracer return code, and got it working with the below patch. Caution, that patch also has a stack trace hardcoded in the return path of the function graph tracer, so you don't want to run function graph tracing without filtering. You can apply the patch and do: # cd /sys/kernel/debug/tracing # echo schedule > set_ftrace_filter # echo function_graph > current_tracer # cat trace 3) | schedule() { rcu_preempt-10 [003] .... 91.160297: => ftrace_return_to_handler => return_to_handler => schedule_timeout => rcu_gp_kthread => kthread => ret_from_fork 3) # 4009.085 us | } 3) | schedule() { kworker/1:0-17 [001] .... 91.163288: => ftrace_return_to_handler => return_to_handler => worker_thread => kthread => ret_from_fork 1) # 7000.070 us | } 1) | schedule() { rcu_preempt-10 [003] .... 91.164311: => ftrace_return_to_handler => return_to_handler => schedule_timeout => rcu_gp_kthread => kthread => ret_from_fork 3) # 4006.540 us | } Where just adding the stack trace without the other code, these traces ended at "return_to_handler". This patch is not for inclusion, it was just a test to see how to make this work. -- Steve diff --git a/arch/x86/kernel/ftrace_64.S b/arch/x86/kernel/ftrace_64.S index 91b2cff4b79a..4bcd646ae1f4 100644 --- a/arch/x86/kernel/ftrace_64.S +++ b/arch/x86/kernel/ftrace_64.S @@ -320,13 +320,15 @@ ENTRY(ftrace_graph_caller) ENDPROC(ftrace_graph_caller) ENTRY(return_to_handler) - UNWIND_HINT_EMPTY - subq $24, %rsp + subq $8, %rsp + UNWIND_HINT_FUNC + subq $16, %rsp /* Save the return values */ movq %rax, (%rsp) movq %rdx, 8(%rsp) movq %rbp, %rdi + leaq 16(%rsp), %rsi call ftrace_return_to_handler diff --git a/kernel/trace/trace_functions_graph.c b/kernel/trace/trace_functions_graph.c index 169b3c44ee97..aaeca73218cc 100644 --- a/kernel/trace/trace_functions_graph.c +++ b/kernel/trace/trace_functions_graph.c @@ -242,13 +242,16 @@ ftrace_pop_return_trace(struct ftrace_graph_ret *trace, unsigned long *ret, trace->calltime = current->ret_stack[index].calltime; trace->overrun = atomic_read(¤t->trace_overrun); trace->depth = index; + + trace_dump_stack(0); } /* * Send the trace to the ring-buffer. * @return the original return address. */ -unsigned long ftrace_return_to_handler(unsigned long frame_pointer) +unsigned long ftrace_return_to_handler(unsigned long frame_pointer, + unsigned long *ptr) { struct ftrace_graph_ret trace; unsigned long ret; @@ -257,6 +260,8 @@ unsigned long ftrace_return_to_handler(unsigned long frame_pointer) trace.rettime = trace_clock_local(); barrier(); current->curr_ret_stack--; + *ptr = ret; + /* * The curr_ret_stack can be less than -1 only if it was * filtered out and it's about to return from the function.