Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp6215043imd; Wed, 31 Oct 2018 08:27:01 -0700 (PDT) X-Google-Smtp-Source: AJdET5cIam+7gOMdQBWipiRFQhbc8MA92FBTFiXvU+z7RnJcL/Ur0iYgHrU4dWZslHlhkkmLO5f2 X-Received: by 2002:a17:902:7b8e:: with SMTP id w14-v6mr3784119pll.289.1540999621765; Wed, 31 Oct 2018 08:27:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540999621; cv=none; d=google.com; s=arc-20160816; b=lVGrvxzKVyPa0bH1UXnNH74xAeGZqhl4QX90xSj7MYT3FqP+eFMd19ncr5DMXW+yHh 6C/NWnS+73AFqIVDxvZJQXOxwdmBb83JFtPVbWeBBILUtLBKDdX1hMxnpwR+7vzhMUje skhJHx8jzGt4VERY3K6Q+EIBVFJ7Qx1dDDfcOW64YxiMDrYYG25C9LnemSIuOyGB+Nll EfCE5JZv7sLrgchxnT4jXtY0NyZYOhI0HdQXXMS41IhxaOv6tLlg0U8wY//4uYZa6+7p 77LnMWcFnZzlvMukJt6rZST+qaEfoZ3wnIPaQ9tlIzGQwTMlP41ApuUlwGbhZb8PN3cV yi9A== 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 :message-id:date:subject:cc:to:from; bh=jupsOnYp3IUPFvTQtncoWkKnML2ksCDayEX2WUgKXKw=; b=HUGJk8trVhH8Cfuhbk2wCXryf79bIDv61x4Rv+WU7MG+qVVJMPYUqxjSS32k7vxoJG CzprzTAtMV8GtblwE4/8owwz3lWKPwnCJUOedQIXk7c3YZhenhvG/a677skqwidG3JW3 Ka6u9b8H9gLQfzlqLAkCLD3lDbx8RME/BAW8bfNzzO39l2Sir8QDM+uqBUNAcPf5si9b 26S6nDQqeAyKOjG790XAj0eO+aIDEeQTaeDvnVFYCpyRUdHvyA8Dv76/obpc7DqqgpNo wnFzdNaYkIvhjbMpN/SazWvmyv/cqk9hHF6VFXfE2lpFpxdkeemOoYuS9di8JJifxaib u7nw== 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 k6si1231456pgr.500.2018.10.31.08.26.44; Wed, 31 Oct 2018 08:27:01 -0700 (PDT) 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 S1729387AbeKAAYc (ORCPT + 99 others); Wed, 31 Oct 2018 20:24:32 -0400 Received: from mx1.mailbox.org ([80.241.60.212]:34102 "EHLO mx1.mailbox.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728698AbeKAAYb (ORCPT ); Wed, 31 Oct 2018 20:24:31 -0400 Received: from smtp1.mailbox.org (smtp1.mailbox.org [80.241.60.240]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mx1.mailbox.org (Postfix) with ESMTPS id C97C740564; Wed, 31 Oct 2018 16:26:00 +0100 (CET) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp1.mailbox.org ([80.241.60.240]) by spamfilter03.heinlein-hosting.de (spamfilter03.heinlein-hosting.de [80.241.56.117]) (amavisd-new, port 10030) with ESMTP id Wmb57fUIYHcm; Wed, 31 Oct 2018 16:25:58 +0100 (CET) From: Aleksa Sarai To: "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 , Steven Rostedt , Shuah Khan , Alexei Starovoitov , Daniel Borkmann Cc: Aleksa Sarai , Aleksa Sarai , Christian Brauner , Brendan Gregg , netdev@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v2 0/2] kretprobe: produce sane stack traces Date: Thu, 1 Nov 2018 02:25:41 +1100 Message-Id: <20181031152543.12138-1-cyphar@cyphar.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Historically, kretprobe has always produced unusable stack traces (kretprobe_trampoline is the only entry in most cases, because of the funky stack pointer overwriting). This has caused quite a few annoyances when using tracing to debug problems[1] -- since return values are only available with kretprobes but stack traces were only usable for kprobes, users had to probe both and then manually associate them. This patch series stores the stack trace within kretprobe_instance on the kprobe entry used to set up the kretprobe. This allows for DTrace-style stack aggregation between function entry and exit with tools like BPFtrace -- which would not really be doable if the stack unwinder understood kretprobe_trampoline. We also revert commit 76094a2cf46e ("ftrace: distinguish kretprobe'd functions in trace logs") and any follow-up changes because that code is no longer necessary now that stack traces are sane. *However* this patch might be a bit contentious since the original usecase (that ftrace returns shouldn't show kretprobe_trampoline) is arguably still an issue. Feel free to drop it if you think it is wrong. Patch changelog: v2: * documentation: mention kretprobe stack-stashing * ftrace: add self-test for fixed kretprobe stacktraces * ftrace: remove [unknown/kretprobe'd] handling * kprobe: remove needless EXPORT statements * kprobe: minor corrections to current_kretprobe_instance (switch away from hlist_for_each_entry_safe) * kprobe: make maximum stack size 127, which is the ftrace default (I forgot to Cc the BPF folks in v1, I've added them now.) Aleksa Sarai (2): kretprobe: produce sane stack traces trace: remove kretprobed checks Documentation/kprobes.txt | 6 +- include/linux/kprobes.h | 15 +++ kernel/events/callchain.c | 8 +- kernel/kprobes.c | 101 +++++++++++++++++- kernel/trace/trace.c | 11 +- kernel/trace/trace_output.c | 34 +----- .../test.d/kprobe/kretprobe_stacktrace.tc | 25 +++++ 7 files changed, 165 insertions(+), 35 deletions(-) create mode 100644 tools/testing/selftests/ftrace/test.d/kprobe/kretprobe_stacktrace.tc -- 2.19.1