Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3911327imu; Mon, 12 Nov 2018 02:37:16 -0800 (PST) X-Google-Smtp-Source: AJdET5eiOP+EL1j9/Hu0inAvlM3jAURylbBcWKF+qabagV7/Cjw1ph8I32vrBOQkPowp7ZdcDF99 X-Received: by 2002:aa7:8348:: with SMTP id z8-v6mr371624pfm.81.1542019036216; Mon, 12 Nov 2018 02:37:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542019036; cv=none; d=google.com; s=arc-20160816; b=lZ/Hte0s/Oqv5xLbinZ+HIcvHB7kui1Z4MS62sCQpCg+zlsm7FqO5m1SZO12gvVjNT xc62tNnkOgG8/UX7D3NDKFgEglQ6vm6Ruk90odR0muMJ5B54jHSmXujg2LL07tvB1ezj 1F6zn/EmDkBG9U8uNAsblE03rwah+3HBKLCAXUVJZp95AXixehB+OgxlvgKI4MEPm9iA lkuFRf6ztO7D/2AYiJvE5amAXOM9nSkNhSuLEwR36dlQ9JWwewTxhj8ozZhneIFWpgiD qgUpY37mfICHraaZtVQf94VTOoP1uEljutvlsqrUyKcitNGXGqcE4hoDYqQm0GycvDU2 wGQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=d0TOXH870/nLM+GuMlWzhHOa+O23cG5JE/+s5mVdlvU=; b=UBdU/GX3vRLHatTSl7KDC4mTEarfh/SpswLfJWUBOj2XaAYKvLnqbEkg7KSF54hNLS 73lfuxRPu6s3GVSa+mzkyTJx476S1sFWJ5XA/6COMWFuP1vusW63EWJ0ERAxU0b6UeOR nJxB1jfjzhwmI8+c9lvfw77lh3BdZs/PYFDJohxyBdEwPOlxbgSbCfrrymVd7L3UN4JA 9dz6pP71FBOry13JRDWm/Nq4NtVYAB2HMSkiKdUdcBxKkJe3G2KJsJEPRsgRuiCaLHxV IKohqYeamYeSMYxXFGBmZXiJQ5uDhg4XezkB4lgQgv6AUEQt+PJVJC/+wU5icqSz5jlV Pfog== 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 y9-v6si7360459plr.338.2018.11.12.02.37.01; Mon, 12 Nov 2018 02:37:16 -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 S1729267AbeKLU3V (ORCPT + 99 others); Mon, 12 Nov 2018 15:29:21 -0500 Received: from mx2.suse.de ([195.135.220.15]:44550 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726190AbeKLU3V (ORCPT ); Mon, 12 Nov 2018 15:29:21 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 69FFEB033; Mon, 12 Nov 2018 10:36:40 +0000 (UTC) Date: Mon, 12 Nov 2018 21:38:22 +1100 From: Aleksa Sarai To: Masami Hiramatsu Cc: Aleksa Sarai , Steven Rostedt , "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 , 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: <20181112103822.ktd4fx7o4cqpfk4q@mikami> References: <20181102065932.bdt4pubbrkvql4mp@yavin> <20181102091658.1bc979a4@gandalf.local.home> <20181103070253.ajrqzs5xu2vf5stu@yavin> <20181104115913.74l4yzecisvtt2j5@yavin> <20181106171501.59ccabbc@gandalf.local.home> <20181108074612.ldy6rozdpsdps6bf@yavin> <20181108080448.rggfn4zawi3por23@yavin> <20181109161551.6b96bd7d932c71432ac65e83@kernel.org> <20181109150629.wpedwxsgbftkl3ab@mikami> <20181111003137.c9df7a077d983cde57c06ee8@kernel.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="7k6zcwip3nr62atq" Content-Disposition: inline In-Reply-To: <20181111003137.c9df7a077d983cde57c06ee8@kernel.org> User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --7k6zcwip3nr62atq Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2018-11-11, Masami Hiramatsu wrote: > > > > + addr =3D kretprobe_ret_addr(current, addr, stack_addr(regs)); > > >=20 > > > But since kretprobe will be an event, which can kick the stackdump. > > > BTW, from kretprobe, regs->ip should always be the trampoline handler= ,=20 > > > see arch/x86/kernel/kprobes/core.c:772 :-) > > > So it must be fixed always. > >=20 > > Right, but kretprobe_ret_addr() is returning the *original* return > > address (and we need to do an (addr =3D=3D kretprobe_trampoline)). The > > real problem is that stack_addr(regs) isn't the same as it is during > > kretprobe setup (but kretprobe_ret_addr() works everywhere else). >=20 > I think stack_addr(regs) should be same when this is called from kretprobe > handler context. Otherwise, yes, it is not same, but in that case, regs->= ip > is not kretprobe_trampoline too. I figured it out. It should be (regs->sp - 1) (just like it is inside the relevant unwinder function for ORC). I now have a prototype which works under the frame unwinder[*] -- however under ORC you can only see the top-most function (the unwinder doesn't see the other function calls). I'm playing with ORC hints with kretprobe_trampoline to try to improve things but it's still a bit screwy. [*]: However, I've noticed that the stack traces between the two traces no longer match. On kprobe you get function_name+1, but on kretprobe you get function_caller+foo. Obviously it's working but the return address results in slightly different stack traces. This means that stack trace aggregation between kprobe and kretprobe won't work anymore -- at least not like it did in my original patch. So I'm really not sure where to go from here. I can send around another patchset to illustrate the problem if you like (as well as show how the current unwinding code works). --=20 Aleksa Sarai Senior Software Engineer (Containers) SUSE Linux GmbH --7k6zcwip3nr62atq Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEXzbGxhtUYBJKdfWmnhiqJn3bjbQFAlvpWBsACgkQnhiqJn3b jbSy7A/+IEFpapcvq94nrWh9OjRuEOAjfNmAk1UzkaA7UdzuGQeqZXNI7My55evY 52fDICDJTrwUz1dJwgjqz7DBgmDUnTSVzt5/5Ypc43Z2xrYVZ0ivffA+P2y5aW6t kXeQUhh52mMHtOsLucR/lu8OuYzZvJ8XqmOH2n93OXyX5B26KcKb7av4NT9hn4Vv 67YgTPScGt/zxk5mPTbV8lsnqU0rMWsCPZLTlXspFzwNHsPQfGcZ9avqj6h6HU7m E3bxhCANzy2Wl9TbgKW0Mq7z5nbEyNSF26hpQh0dsFulHlN++lxpeZgBjtCvGgdX mnLVjWtE47z2fgGRpgERa4eemZXRNLMcLbcOQwBDSuIT3bh9izXu97gQaqeVtY2C PtnG1MG6dVmo1SzsNnmu3YZc41CGofmyc2wdssBtFnqY1rKZI73zPTgSgfNEK2V2 FqCjI4HNfYzns/pcrE7XiRUUrZnkdfEi1NmO9xRrpRP1SzZdgryCZWO5x1QMZdW0 ceN9JK6sh5ZHN64qoGXgsC51gwdPXgNrtZkEzuPA9nLeiZWi2GJEiMejN3ocMTvu miqStmedFrJrYWbgLtK/J1ypJesnOURvU38H/OKwcQf4HkDxde115mw3AP4Wq2CT EkJ4ataA2lfyA6IwOtprtlePn7GJl/iCD0whahftumKTWDshz7Y= =OSID -----END PGP SIGNATURE----- --7k6zcwip3nr62atq--