Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp756726imd; Sat, 3 Nov 2018 09:37:00 -0700 (PDT) X-Google-Smtp-Source: AJdET5ezJ8ebMW7YxKQQpjDR5QPQlN/MM8ZWR1o4Hyel5dnn9urodvNIGV/kqeaNPMoAacgksvF7 X-Received: by 2002:a63:d513:: with SMTP id c19mr14638003pgg.287.1541263020447; Sat, 03 Nov 2018 09:37:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541263020; cv=none; d=google.com; s=arc-20160816; b=xtjXj3vrWpZxWudJj4r8+jMyp6Oj+Wrr1KCcOLekKemFT2+Ft8/Z+nuCPBj4whcwn4 85YDtcCIJwdoIm+UExU33VAQx33BT2pNj4W0YkSWSbd9AsNjPAEiD9WUMaDgusTntyWi UgaG0YVzDKQyMJ05aIAKZeGzN8QIWfSzWa14KIVja+CGgfgObySwXfdWkxXC+yVRPU3O lsJBe5FaFrl3NDVJ0/B6wO/hXIhxJX2YbIgJxnnOJvdN3aGmvMgyBHNchTOEMpH/AZ9a U/S0xD4GW/EYSgZSNUMhcMknQetYexK3kNFtlNyAxPHuYaMZwva9XE82uCyv9SBtn9MW KAuA== 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=omU2YWRDurRhlg45no6rAqzk7wmgTB2bjOclfWUDQTE=; b=dd7g4J8QCn5umWWenewrgLhWZon1aeMqbu8vPy5Cnqz1BSBKv4tgt1AgghsiYGgu3P IFJV9ziKoW1Hyvk0HvmRRF59vbHNM/HihuIUbLj9WhQQwFkbgFjAuRD0y6bvPEA+eBq2 mt1SwQ8DqW5y1pqfqXbzMekenRWhJXYqanQVvuXuQARiTWvEx6/p5W/kp22ovR12ikiY yn9asYXvswOSHgU7hU4akIWLPLSh22GWdn6KnaTIltYRxB9SHIt1rb+F7ZC7GOzqo9li PkoALcJc3AKmmjVUWPJfxktTiYbkhrMpxqFp9tpLo2lZOJbEgmhwXj2dVnpyqX1ba0jF IK4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=kLCrB8lz; 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 o10-v6si36452465plk.295.2018.11.03.09.36.45; Sat, 03 Nov 2018 09:37:00 -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=kLCrB8lz; 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 S1728543AbeKDBqW (ORCPT + 99 others); Sat, 3 Nov 2018 21:46:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:56614 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726888AbeKDBqV (ORCPT ); Sat, 3 Nov 2018 21:46:21 -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 8D4042082E; Sat, 3 Nov 2018 16:34:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541262874; bh=Iy6FmRR8ErwQkljBCA7TBtflb5SxeaOb6vsXk6FDi34=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=kLCrB8lzfGqQ2SYSgHANtGqeAfb4/8MTo+6N5ETzqvfOY4MZgS8HeLazuYtOQxiHK t0tUeAOARqX+eUlXF3epNQjyBmtzesKHmi0eYO0tdc0LKyJugoH8a2bJgfTQeitY0y P4aCr0WRlaVSe2HvK8c4DqU41bPujqsafadIgQDM= Date: Sun, 4 Nov 2018 01:34:30 +0900 From: Masami Hiramatsu To: Steven Rostedt Cc: Josh Poimboeuf , Aleksa Sarai , "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 , 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: <20181104013430.9d3e91b8ebbae7dcb6860ef1@kernel.org> In-Reply-To: <20181103091341.3d32683e@vmware.local.home> 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> <20181102154325.bt6xoysl4xdl33wd@treble> <20181102121307.32e99414@gandalf.local.home> <20181103220012.55ecd97e671c43e4959c8b62@kernel.org> <20181103091341.3d32683e@vmware.local.home> 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 Sat, 3 Nov 2018 09:13:41 -0400 Steven Rostedt wrote: > On Sat, 3 Nov 2018 22:00:12 +0900 > Masami Hiramatsu wrote: > > > On Fri, 2 Nov 2018 12:13:07 -0400 > > Steven Rostedt wrote: > > > > > > Because that means if function graph tracer is active, then you can't > > > do a kretprobe, and vice versa. I'd really like to have it working for > > > multiple users, then we could trace different graph functions and store > > > them in different buffers. It would also allow for perf to use function > > > graph tracer too. > > > > Steve, how woul you allow multiple users on it? Something like this? > > > > ret_trampoline_multiple(){ > > list_for_each(handler, &shadow_entry[i].handlers, list) > > handler(shadow_entry[i]); > > restore_retval_and_jump_to(shadow_entry[i].orig); > > } > > > > Something like that. But since it's not a single mapping between shadow > entries and handlers, that is we have multiple tasks with multiple > shadow entries and multiple handlers, we can't use a link list (two > different parents per handler). Yes, I understand it. > I was thinking of a bitmask that represents the handlers, and use that > to map which handler gets called for which shadow entry for a > particular task. Hmm, I doubt that is too complicated and not scalable. I rather like to see the open shadow entry... entry: [[original_retaddr][function][modified_retaddr]] So if there are many users on same function, the entries will be like this [[original_return_address][function][trampoline_A]] [[trampline_A][function][trampoline_B]] [[trampline_B][function][trampoline_C]] And on the top of the stack, there is trampline_C instead of original_return_address. In this case, return to trampoline_C(), it jumps back to trampline_B() and then it jumps back to trampline_A(). And eventually it jumps back to original_return_address. This way, we don't need allocate another bitmap/pages for the shadow stack. We only need a shadow stack for each task. Also, unwinder can easily find the trampline_C from the shadow stack and restores original_return_address. (of course trampline_A,B,C must be registered so that search function can skip it.) Thank you, -- Masami Hiramatsu