Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp1703555imd; Thu, 1 Nov 2018 22:08:47 -0700 (PDT) X-Google-Smtp-Source: AJdET5cuveLrEkYQH2ibg9F04RTxO5B0eG9KTk/ujZN+US5M/uPiJ/pDPP2SX/+gC2MhYGHOkMkP X-Received: by 2002:a63:ac02:: with SMTP id v2-v6mr9710753pge.414.1541135327806; Thu, 01 Nov 2018 22:08:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541135327; cv=none; d=google.com; s=arc-20160816; b=WsS0m0YZOIVoz9BYD7gYOjAH7cVKPuVV/Dn7d3VYQXRGmKrriOw9TzLyr661eKk/yK XvGAf7nIH8PQxHT7Rj540QRufZaizUZsrAmi2NkmSSg0FtR2fDVgMcBt2FzMbu79J+/A GcmrzQins9a/lp8Ki7670I0Y9lSoJ8BkHNsapyZ+KXp3PYHcG18n1WtaJ27neiVpwxka jA0dezS0mVyBlBJNZZ9ONE1nVKHQBuSjQAP92pa02+I0gTMbCZNu9jrIrzIFqUjW+j5R 50eCa/OkNP3z2y78iqMyL50YRSUYk2mGRo0+bmtz4go1mz3FDSC9wnmjTjJJPLHvLAlu v5Uw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=dSHQgpO2JdW5ylKDgqKQIAvIlsahb3aVsGe9UNUuaXc=; b=TNFGJdW3oijIkHBPyJV74I39MsG4HOUTRrEC4Gdzlhzpmgt657edW6sJKTaC5s8ug6 Zq+d363ClVjtV4xuGaWbiUb0riPYwF+jbneTo8QAUslzpaMXh/ntnPchx7JowsK3ULNj KV3enaDcJ9yf9tex1j+spIhRb2TtrqIctDhmhqv3BzKdLU1B71g1t8LoedVmVfMgOyzr mLVZ33BFAYvveB5q9k2SEiyi2wNcbMJnglTIGROTGOuqDJu2xHMYymwobFT4+KFwAzDW Od3JhGBn7p0dVONY4JvY7l7RnkhJdP5vJR/+ZHV4tF8B62ZxqDP6V6GfXDv8ZBs1hAlC wnTA== 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 q15-v6si31589450pgm.595.2018.11.01.22.08.18; Thu, 01 Nov 2018 22:08:47 -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 S1727610AbeKBOLZ (ORCPT + 99 others); Fri, 2 Nov 2018 10:11:25 -0400 Received: from mx2.mailbox.org ([80.241.60.215]:8428 "EHLO mx2.mailbox.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727462AbeKBOLZ (ORCPT ); Fri, 2 Nov 2018 10:11:25 -0400 Received: from smtp2.mailbox.org (smtp2.mailbox.org [80.241.60.241]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mx2.mailbox.org (Postfix) with ESMTPS id 03941A1107; Fri, 2 Nov 2018 06:05:28 +0100 (CET) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp2.mailbox.org ([80.241.60.241]) by gerste.heinlein-support.de (gerste.heinlein-support.de [91.198.250.173]) (amavisd-new, port 10030) with ESMTP id 5888h3bBCDBv; Fri, 2 Nov 2018 06:05:24 +0100 (CET) Date: Fri, 2 Nov 2018 16:05:09 +1100 From: Aleksa Sarai To: Steven Rostedt 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: <20181102050509.tw3dhvj5urudvtjl@yavin> References: <20181101083551.3805-1-cyphar@cyphar.com> <20181101083551.3805-2-cyphar@cyphar.com> <20181101204720.6ed3fe37@vmware.local.home> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="6gjrsgidzixwxeap" Content-Disposition: inline In-Reply-To: <20181101204720.6ed3fe37@vmware.local.home> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --6gjrsgidzixwxeap Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2018-11-01, Steven Rostedt wrote: > On Thu, 1 Nov 2018 19:35:50 +1100 > Aleksa Sarai wrote: > > @@ -1834,6 +1853,11 @@ static int pre_handler_kretprobe(struct kprobe *= p, struct pt_regs *regs) > > ri->rp =3D rp; > > ri->task =3D current; > > =20 > > + trace.entries =3D &ri->entry.entries[0]; > > + trace.max_entries =3D KRETPROBE_TRACE_SIZE; > > + save_stack_trace_regs(regs, &trace); > > + ri->entry.nr_entries =3D trace.nr_entries; > > + >=20 > So basically your saving a copy of the stack trace for each probe, for > something that may not ever be used? >=20 > This adds quite a lot of overhead for something not used often. >=20 > I think the real answer is to fix kretprobes (and I just checked, the > return call of function graph tracer stack trace doesn't go past the > return_to_handler function either. It's just that a stack trace was > never done on the return side). >=20 > The more I look at this patch, the less I like it. That's more than fair. There's also an issue that Masami noted -- nested kretprobes don't give you the full stack trace with this solution since the stack was already overwritten. I think that the only real option is to fix the unwinder to work in a kretprobe context -- which is what I'm looking at now. Unfortunately, I'm having a lot of trouble understanding how the current ftrace hooking works -- ORC has a couple of ftrace hooks that seem reasonable on the surface but I don't understand (for instance) how HAVE_FUNCTION_GRAPH_RET_ADDR_PTR *actually* works. Though your comment appears to indicate that it doesn't work for stack traces? For kretprobes I think it would be fairly easy to reconstruct what landed you into a kretprobe_trampoline by walking the set of kretprobe_instances (since all new ones are added to the head, you can get the real return address in-order). But I still have to figure out what is actually stopping the save_stack_trace() unwinder that isn't stopping the show_stacks() unwinder (though the show_stacks() code is more ... liberal with the degree of certainty it has about the unwind). Am I barking up the wrong tree? --=20 Aleksa Sarai Senior Software Engineer (Containers) SUSE Linux GmbH --6gjrsgidzixwxeap Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEb6Gz4/mhjNy+aiz1Snvnv3Dem58FAlvb2wIACgkQSnvnv3De m5+l3A/9G/bIFwCfq09RMkpdTMo9ODJiwOqb+JS0KFwOpNNoapaT9gDPymIMbJzu F7kjiIfbtzWlodDjIBqU2hMLMvFrSrKK38kEyOFXYpVd5hvqX+U7CEV7LM3a+Gt8 eRxUqbWQDochrJVOVyNGJYdB0yGlHFlJYisYejQKKlr18p1h5xM7zWgbhxzbM3I4 LewMrs1i5PuVgAfux5xscHJ9kkFP2bhQsC9LDeFNVTGaCmL4+ebSEBdAz2y678eh rO+Pv/URk/wqL6jbSNb5LJguYP892mK7Ezsmhw4k+6IfwrWavlLvok8WRr5GKLqU jF3C4H/1VJsBwSx/sCgw9WCWNvKrwGjyAQDmlGJmbLpK9PyO4mh4VtYFpDQAYbVi YfxgtP6IFTguzDY1gLD2ruzfHcKkhqVnR2VitqtsUZY4amRIdJbNnj7+tS/87Opk cO4x8cLgh+fbNKN/CVEa18+2HC+710lKlApjKmOs+s8LH/kZJ3VtuheT9b14RXPE 0P/BjM4T5kixY2VaxTUdmxgQmcq02O9fMrWIAuJPLjVpT7smGVcOmWbseGWf4kmU mz+qcvlWIJFA91O5xfK2kNOUwtMha8+Z8WsjYWfk4P6vHuGwn/zyXyIhFJ7kpOXJ 7VK0+zZnfqszf9Mf4RwZDCt8PcQPJ1m9r4tbVavf8wKFSdGceAk= =ipcF -----END PGP SIGNATURE----- --6gjrsgidzixwxeap--