Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4119779yba; Sun, 19 May 2019 11:09:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqyVC+EUKjeaX/nKmdb876g8euOCMwfTzSfZCk8qBlZq+GF6eRLd0VqRrC7r9fYr9PMo1ZG4 X-Received: by 2002:a17:902:a605:: with SMTP id u5mr22066241plq.43.1558289347109; Sun, 19 May 2019 11:09:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558289347; cv=none; d=google.com; s=arc-20160816; b=qVzVmu9KccF8wbpVMJx726/Z0xSjyZicMb2f0fr56ECKlPer9Ig8+Vg7Js9I7Ecq7r NZ1nJS+P7Vb2hbACzhgnspx9jVo49/OJFiZw19ZrZEMaICl+nsNr2gVp2hEijBjAb8Bk hO7RgNcDa6qGllri1sWs4CF2TSuSNtrxaKDh8lEUf6d1y7Z9vbZa/1v+VtXgyq2oZRxP QtFDau+f61TUXdUWEi7Yavit5/SQSHw3c8jHyCsz3C08UT61/1EAShLkXqmtuUW0pyuJ 4b4Uj6aZurxSb3PJWvQ0oEnehScuMFTBVBo9j6B4COafJLfTyXflfhyMi130DLz9UEyW rT2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=w7S1JiY5XMndUySOPpCBhO3vugzf338c54HkvkOEdUI=; b=Pg6xkLxvkSwJbJOYJHDZyqxR4zbDO6BdjK96cRhlIA6jFgQCFbt/kBiWTmtSfsKHIB W+yxP8npctfCDI97UhUIN9RDJ2gMgBptI7kT/q0PKf5B+iP1qwtYyOYMKNb3ebFiLsXP uehhZYugM/xIht/nMqrwHcf+paH0CGE8a6z/2v6X2asoeUBGN1MYh3a1dRvTp+cy5Bc/ 41TJUqn66RzByF8ioCUvaQYnZT0y5+D1Pzx/H1WsHz+qF2hRtsMVEIHbDMf1Q15rGuKV Vo+lRw1pJdILN9CtHE3gyxKIYotYoonL+4HJ067v0Df2ohTKRGipzTdd/MbKrKrcKHdj WrNA== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b8si3054832plr.184.2019.05.19.11.08.52; Sun, 19 May 2019 11:09:07 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729583AbfESSHa (ORCPT + 99 others); Sun, 19 May 2019 14:07:30 -0400 Received: from mail-it1-f196.google.com ([209.85.166.196]:40252 "EHLO mail-it1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729552AbfESSH3 (ORCPT ); Sun, 19 May 2019 14:07:29 -0400 Received: by mail-it1-f196.google.com with SMTP id g71so19615342ita.5 for ; Sun, 19 May 2019 11:07:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=w7S1JiY5XMndUySOPpCBhO3vugzf338c54HkvkOEdUI=; b=Lj5W4lPyxHETuoM6XjTL2ZdKowHojfbzwCsVBvZMh9MqsV+oal3A8yDMlxLUqw5msL +6JEFnLOyRK3zH3ytEn3c11iMaJn/RlOI7lUvRrIWRpnWBh14Pxklmw2Q5m3Y2DmPDhW SK2ZDQum94izdLXpaF76VDeqQDMS12L7h5fmv2nLEPGi5PlTSqabX55kDrHT54vB+T3u xCfAYzISmdv7QZAwvkE4kwScOVQBjzNAnRECbqrjut9q5cTW5v/oI63I3Vr1J/WrgLtW 77Cpp5DsmpDeHlBEf9tvLF888jw/myWZq9CTpfGhf5JhrOEYzucOQnRvOmy+lrRZhbRe DOgA== X-Gm-Message-State: APjAAAWgzOAXtkadVwtWTEu19BAy1Uer7DpoFpmD/ltxJEJvJKNZkixJ 7Gm8FCTTXThVvHeNPdH/bPqytfQwXcTMQIXpmsvk6w== X-Received: by 2002:a24:7a90:: with SMTP id a138mr25523149itc.95.1558289248398; Sun, 19 May 2019 11:07:28 -0700 (PDT) MIME-Version: 1.0 References: <3CD3EE63-0CD2-404A-A403-E11DCF2DF8D9@fb.com> <20190517074600.GJ2623@hirez.programming.kicks-ass.net> <20190517081057.GQ2650@hirez.programming.kicks-ass.net> <20190517091044.GM2606@hirez.programming.kicks-ass.net> <8C814E68-B0B6-47E4-BDD6-917B01EC62D0@fb.com> <8449BBF3-E754-4ABC-BFEF-A8F264297F2D@fb.com> In-Reply-To: <8449BBF3-E754-4ABC-BFEF-A8F264297F2D@fb.com> From: Kairui Song Date: Mon, 20 May 2019 02:07:19 +0800 Message-ID: Subject: Re: Getting empty callchain from perf_callchain_kernel() To: Song Liu Cc: Alexei Starovoitov , Peter Zijlstra , lkml , Kernel Team , Josh Poimboeuf , Alexei Starovoitov , Daniel Borkmann , "bpf@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, May 18, 2019 at 5:48 AM Song Liu wrote: > > > > > On May 17, 2019, at 2:06 PM, Alexei Starovoitov wrote: > > > > On 5/17/19 11:40 AM, Song Liu wrote: > >> +Alexei, Daniel, and bpf > >> > >>> On May 17, 2019, at 2:10 AM, Peter Zijlstra wrote: > >>> > >>> On Fri, May 17, 2019 at 04:15:39PM +0800, Kairui Song wrote: > >>>> Hi, I think the actual problem is that bpf_get_stackid_tp (and maybe > >>>> some other bfp functions) is now broken, or, strating an unwind > >>>> directly inside a bpf program will end up strangely. It have following > >>>> kernel message: > >>> > >>> Urgh, what is that bpf_get_stackid_tp() doing to get the regs? I can't > >>> follow. > >> > >> I guess we need something like the following? (we should be able to > >> optimize the PER_CPU stuff). > >> > >> Thanks, > >> Song > >> > >> > >> diff --git i/kernel/trace/bpf_trace.c w/kernel/trace/bpf_trace.c > >> index f92d6ad5e080..c525149028a7 100644 > >> --- i/kernel/trace/bpf_trace.c > >> +++ w/kernel/trace/bpf_trace.c > >> @@ -696,11 +696,13 @@ static const struct bpf_func_proto bpf_perf_event_output_proto_tp = { > >> .arg5_type = ARG_CONST_SIZE_OR_ZERO, > >> }; > >> > >> +static DEFINE_PER_CPU(struct pt_regs, bpf_stackid_tp_regs); > >> BPF_CALL_3(bpf_get_stackid_tp, void *, tp_buff, struct bpf_map *, map, > >> u64, flags) > >> { > >> - struct pt_regs *regs = *(struct pt_regs **)tp_buff; > >> + struct pt_regs *regs = this_cpu_ptr(&bpf_stackid_tp_regs); > >> > >> + perf_fetch_caller_regs(regs); > > > > No. pt_regs is already passed in. It's the first argument. > > If we call perf_fetch_caller_regs() again the stack trace will be wrong. > > bpf prog should not see itself, interpreter or all the frames in between. > > Thanks Alexei! I get it now. > > In bpf_get_stackid_tp(), the pt_regs is get by dereferencing the first field > of tp_buff: > > struct pt_regs *regs = *(struct pt_regs **)tp_buff; > > tp_buff points to something like > > struct sched_switch_args { > unsigned long long pad; > char prev_comm[16]; > int prev_pid; > int prev_prio; > long long prev_state; > char next_comm[16]; > int next_pid; > int next_prio; > }; > > where the first field "pad" is a pointer to pt_regs. > > @Kairui, I think you confirmed that current code will give empty call trace > with ORC unwinder? If that's the case, can we add regs->ip back? (as in the > first email of this thread. > > Thanks, > Song > Hi thanks for the suggestion, yes we can add it should be good an idea to always have IP when stack trace is not available. But stack trace is actually still broken, it will always give only one level of stacktrace (the IP). -- Best Regards, Kairui Song