Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp1624621imd; Thu, 1 Nov 2018 20:05:21 -0700 (PDT) X-Google-Smtp-Source: AJdET5dr152hW3s12/FfiZq6jijCq7Dz27zvcpbnprSr6HBayArSfKch4NgTD2tdFWDiAfW21Fp1 X-Received: by 2002:a63:7e5b:: with SMTP id o27mr9375735pgn.214.1541127921559; Thu, 01 Nov 2018 20:05:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541127921; cv=none; d=google.com; s=arc-20160816; b=BhXfMYJzy35k58BJPgHwEKarfyLvAcJ7nvnfzx4BxzdGaB7aFTV3jPxBQOy8kaLZBm Ezk5dXOkDtR15Kg+H8UQPa7oddYn4EQ67eQwqyecjxh5lJMkna3O1SlGKY3HfOj9m5CL QiMPYe//jqY7yv20GcGETahpVHDfp6adWJ9LdWNICSlzfboxLIfNGA1/coxvd/4hVmmh kt+nLPjWPk0H4iF9rJHAzlvofMyRZaT0v/u/FqcoVgfHw+jMQJfHongmPSB9jtgEhmg4 8Q9ZbdbRm0cKlptKlNukoYBYpeRog3ei8JJxc2bwtgfWlQWVogsjdHTbi2i70jXXCXC/ QkrQ== 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 :dkim-signature; bh=RcN5cmknhJjFp/PMSz1vjP7W6KrypgDF9R6IHZd0NGs=; b=DA3bE9+X5REUJtycLox/4FHDh7V009NILe005py8qd9JNUmNdwIF4SC0HvNcwk2dID dcTXhAETefgVj/PxDlo9gA5MzHY9XtQRTy5BBD6HWoWcRydRF5ZP8eNAXiyStt8K/LWK 5CAJWWte9VlhOwTbBWGZiorVPBAg+x9wYUGvUkeU098VVPGH/eqEj62szKLqmXGG4Mjk 7DbzQ7hesdhdM3M0QN2fRwH3hl1hiyUpwvDbFUiPkLbK7ndSxO6boydAU+QvhMYn6FFo fpSMM3pu2y/8R5SilewSJ9ZAMJwcSXTZ0xuXOVKkA3Nre2QufFCPzX4RmYpbdYoxJ2vb KPIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=coLW0SK5; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s17-v6si31656951pgm.317.2018.11.01.20.05.06; Thu, 01 Nov 2018 20:05:21 -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; dkim=pass header.i=@kernel.org header.s=default header.b=coLW0SK5; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726770AbeKBMKT (ORCPT + 99 others); Fri, 2 Nov 2018 08:10:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:34934 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726223AbeKBMKT (ORCPT ); Fri, 2 Nov 2018 08:10:19 -0400 Received: from devbox (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (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 4C39520657; Fri, 2 Nov 2018 03:04:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541127886; bh=5yoh2QqeUskIX0mOuJvCADphgslvrmNqjFp1M6kqTQo=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=coLW0SK56O9XhxI/Uf/pIwSd+krVlxuXGm1oxDLUkTOJ3VoNglBjeQ2YLtgb0hZ5a 1pgfeM9pu9LE9gMKvR7YD0Job0rN24O/9XIMNLE1DX4A7i8xvE1OG7rHnCxGJDe56+ 8PEckxDgbEubeLXLLWZK2cBg90k/f420MZe8aY5o= Date: Fri, 2 Nov 2018 12:04:41 +0900 From: Masami Hiramatsu To: Aleksa Sarai Cc: "Naveen N. Rao" , Anil S Keshavamurthy , "David S. Miller" , Jonathan Corbet , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Steven Rostedt , 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 Subject: Re: [PATCH v3 1/2] kretprobe: produce sane stack traces Message-Id: <20181102120441.d00af1b57e6a739d0e7c7a91@kernel.org> In-Reply-To: <20181101211343.yooxwqfnoloprb5h@yavin> References: <20181101083551.3805-1-cyphar@cyphar.com> <20181101083551.3805-2-cyphar@cyphar.com> <20181102002039.8f22c10fa47cae75fa709165@kernel.org> <20181101211343.yooxwqfnoloprb5h@yavin> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-redhat-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 Fri, 2 Nov 2018 08:13:43 +1100 Aleksa Sarai wrote: > On 2018-11-02, Masami Hiramatsu wrote: > > Please split the test case as an independent patch. > > Will do. Should the Documentation/ change also be a separate patch? I think the Documentation change can be coupled with code change if the change is small. But selftests is different, that can be backported soon for testing the stable kernels. > > > new file mode 100644 > > > index 000000000000..03146c6a1a3c > > > --- /dev/null > > > +++ b/tools/testing/selftests/ftrace/test.d/kprobe/kretprobe_stacktrace.tc > > > @@ -0,0 +1,25 @@ > > > +#!/bin/sh > > > +# SPDX-License-Identifier: GPL-2.0+ > > > +# description: Kretprobe dynamic event with a stacktrace > > > + > > > +[ -f kprobe_events ] || exit_unsupported # this is configurable > > > + > > > +echo 0 > events/enable > > > +echo 1 > options/stacktrace > > > + > > > +echo 'r:teststackprobe sched_fork $retval' > kprobe_events > > > +grep teststackprobe kprobe_events > > > +test -d events/kprobes/teststackprobe > > > > Hmm, what happen if we have 2 or more kretprobes on same stack? > > It seems you just save stack in pre_handler, but that stack can already > > includes another kretprobe's trampline address... > > Yeah, you're quite right... > > My first instinct was to do something awful like iterate over the set of > "kretprobe_instance"s with ->task == current, and then correct > kretprobe_trampoline entries using ->ret_addr. (I think this would be > correct because each task can only be in one context at once, and in > order to get to a particular kretprobe all of your caller kretprobes > were inserted before you and any sibling or later kretprobe_instances > will have been removed. But I might be insanely wrong on this front.) yeah, you are right. > > However (as I noted in the other thread), there is a problem where > kretprobe_trampoline actually stops the unwinder in its tracks and thus > you only get the first kretprobe_trampoline. This is something I'm going > to look into some more (despite not having made progress on it last > time) since now it's something that actually needs to be fixed (and > as I mentioned in the other thread, show_stack() actually works on x86 > in this context unlike the other stack_trace users). I should read the unwinder code, but anyway, fixing it up in kretprobe handler context is not hard. Since each instance is on an hlist, so when we hit the kretprobe_trampoline, we can search it. However, the problem is the case where the out of kretprobe handler context. In that context we need to try to lock the hlist and search the list, which will be a costful operation. On the other hand, func-graph tracer introduces a shadow return address stack for each task (thread), and when we hit its trampoline on the stack, we can easily search the entry from "current" task without locking the shadow stack (and we already did it). This may need to pay a cost (1 page) for each task, but smarter than kretprobe, which makes a system-wide hash-table and need to search from hlist which has return addresses of other context coexist. Thank you, -- Masami Hiramatsu