Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3475330yba; Tue, 23 Apr 2019 04:36:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqxUGF6VfDbvAApsP3XTdGdd3pfcW+wz9xrxIW44m5jzdtnsT1iGuq/9GTC+iHypyQG5PZSb X-Received: by 2002:a17:902:6bc8:: with SMTP id m8mr16378104plt.21.1556019380529; Tue, 23 Apr 2019 04:36:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556019380; cv=none; d=google.com; s=arc-20160816; b=twNH6ShK8klgPAXr9Ou6cuiTNrb/VlMNLCv7RGKNf4g1ESbQEFJp4DhR/gc9PGPnYI 9rTQjylfU0f1oegBiaJDZdayQtuZzQ21KcY8mvKDtS6menaW3TFUwFI8jb10KC/QsozM QiIR/TCoF1qALCn9vKk25E9chDSspreKn4BjoRRe0yDoKtDUwIffp/RAkjUSa2uoCvSZ wpg4ay69W3ZtiIDyvTpEECR1rQ+8XjvHVlbD7IE05ykdq5boOOAnWL5UpSvGYzRwfq8Z d3N2xlS95SH/hzMtWe0ZF+p70dMr8UgO77SspR/ct7k+n3/oRHQKulDecUfBCjUYBVlS Tc4Q== 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:dkim-signature; bh=6rBI7PHc5YdcJ73QAsnbPgyOmLDrCsr5wLMdGKq6ogg=; b=ykiUCAW9AVc+9a0NxYof3sV+qtp/gEBZWXrl5iR4nBaQ/zuirNbI5pm9tm0M9Xxapw dOVPK2raiGh0AFYq3taKnv7jgDu36g1TA51seIlBW9vfsXwO71h4vkv4Bg6lOikjym8z Gte2WNdS1SbTXoedQAgvFUBRvdIHM6WOmLcL9KYAXCbydQnLRlHvuH6j2mQDd+YhOlHp mFPFtCjKll29euOMfrEtebgTTu4uHzvu3E1UrkgaR5k6wp1gWov2ypgsQ9i8tptUyVVb cId+k8kvy07qnLYGy/RPK4ts3LGfEPzbr8ao1Xl1rFwfzaMlFNx9T+xsJSGRucxbS5bu h+Mg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=JgIPY+dy; 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 o11si2116521plk.413.2019.04.23.04.36.04; Tue, 23 Apr 2019 04:36:20 -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=fail header.i=@infradead.org header.s=merlin.20170209 header.b=JgIPY+dy; 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 S1727180AbfDWLfM (ORCPT + 99 others); Tue, 23 Apr 2019 07:35:12 -0400 Received: from merlin.infradead.org ([205.233.59.134]:47948 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726033AbfDWLfL (ORCPT ); Tue, 23 Apr 2019 07:35:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=6rBI7PHc5YdcJ73QAsnbPgyOmLDrCsr5wLMdGKq6ogg=; b=JgIPY+dyIcUanQ3/Dj8Fth0Aw rnLuaE9GPlBhpeLx3eBDcQ9P66VcCw5uOblDW11DTzM13NJPA9Wj5mcQaL1z5fqh/uS9TOikckF4o paAg+7S63cXg+bwBso2PYWJL3iIIrkrCp7CHbQjK1yFFxNe2pSLb6ZqqPkP52b8mVDPeelciVO548 pJNv2gQdODHK5AoxAlGad8y+hYVb1L7DZj+h+zwShP0p6uEzu7UMvIxMp7yYUp4H/7/Sv2AoFYDPW XEM9Um+5B16J2IVye5ZkxaThQ3apyufEbc+cTlwOuonq+5VYUtUTiEjNKWxpqR5/WWgWmhdJgP/+N Du0RPN0Jg==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1hIthW-0003Pz-R5; Tue, 23 Apr 2019 11:35:03 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 94A7529B8F6FE; Tue, 23 Apr 2019 13:35:01 +0200 (CEST) Date: Tue, 23 Apr 2019 13:35:01 +0200 From: Peter Zijlstra To: Kairui Song Cc: linux-kernel@vger.kernel.org, Josh Poimboeuf , Ingo Molnar , Arnaldo Carvalho de Melo , Alexander Shishkin , Jiri Olsa , Alexei Starovoitov , Namhyung Kim , Thomas Gleixner , Borislav Petkov , Dave Young Subject: Re: [RFC PATCH v4] perf/x86: make perf callchain work without CONFIG_FRAME_POINTER Message-ID: <20190423113501.GN11158@hirez.programming.kicks-ass.net> References: <20190422162652.15483-1-kasong@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190422162652.15483-1-kasong@redhat.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 23, 2019 at 12:26:52AM +0800, Kairui Song wrote: > Currently perf callchain doesn't work well with ORC unwinder > when sampling from trace point. We'll get useless in kernel callchain > like this: > > perf 6429 [000] 22.498450: kmem:mm_page_alloc: page=0x176a17 pfn=1534487 order=0 migratetype=0 gfp_flags=GFP_KERNEL > ffffffffbe23e32e __alloc_pages_nodemask+0x22e (/lib/modules/5.1.0-rc3+/build/vmlinux) > 7efdf7f7d3e8 __poll+0x18 (/usr/lib64/libc-2.28.so) > 5651468729c1 [unknown] (/usr/bin/perf) > 5651467ee82a main+0x69a (/usr/bin/perf) > 7efdf7eaf413 __libc_start_main+0xf3 (/usr/lib64/libc-2.28.so) > 5541f689495641d7 [unknown] ([unknown]) > > The root cause is that, for trace point events, it doesn't provide a > real snapshot of the hardware registers. Instead perf tries to get > required caller's registers and compose a fake register snapshot > which suppose to contain enough information for start a unwinding. > However without CONFIG_FRAME_POINTER, if failed to get caller's BP as the > frame pointer, so current frame pointer is returned instead. We get > a invalid register combination which confuse the unwinder, and end the > stacktrace early. > > So in such case just don't try dump BP, and let the unwinder start > directly when the register is not a real snapshot. And Use SP > as the skip mark, unwinder will skip all the frames until it meet > the frame of the trace point caller. > > Tested with frame pointer unwinder and ORC unwinder, this make perf > callchain get the full kernel space stacktrace again like this: > > perf 6503 [000] 1567.570191: kmem:mm_page_alloc: page=0x16c904 pfn=1493252 order=0 migratetype=0 gfp_flags=GFP_KERNEL > ffffffffb523e2ae __alloc_pages_nodemask+0x22e (/lib/modules/5.1.0-rc3+/build/vmlinux) > ffffffffb52383bd __get_free_pages+0xd (/lib/modules/5.1.0-rc3+/build/vmlinux) > ffffffffb52fd28a __pollwait+0x8a (/lib/modules/5.1.0-rc3+/build/vmlinux) > ffffffffb521426f perf_poll+0x2f (/lib/modules/5.1.0-rc3+/build/vmlinux) > ffffffffb52fe3e2 do_sys_poll+0x252 (/lib/modules/5.1.0-rc3+/build/vmlinux) > ffffffffb52ff027 __x64_sys_poll+0x37 (/lib/modules/5.1.0-rc3+/build/vmlinux) > ffffffffb500418b do_syscall_64+0x5b (/lib/modules/5.1.0-rc3+/build/vmlinux) > ffffffffb5a0008c entry_SYSCALL_64_after_hwframe+0x44 (/lib/modules/5.1.0-rc3+/build/vmlinux) > 7f71e92d03e8 __poll+0x18 (/usr/lib64/libc-2.28.so) > 55a22960d9c1 [unknown] (/usr/bin/perf) > 55a22958982a main+0x69a (/usr/bin/perf) > 7f71e9202413 __libc_start_main+0xf3 (/usr/lib64/libc-2.28.so) > 5541f689495641d7 [unknown] ([unknown]) > > Co-developed-by: Josh Poimboeuf > Signed-off-by: Kairui Song Thanks! > diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h > index e47ef764f613..ab135abe62e0 100644 > --- a/include/linux/perf_event.h > +++ b/include/linux/perf_event.h > @@ -1059,7 +1059,7 @@ static inline void perf_arch_fetch_caller_regs(struct pt_regs *regs, unsigned lo > * the nth caller. We only need a few of the regs: > * - ip for PERF_SAMPLE_IP > * - cs for user_mode() tests > - * - bp for callchains > + * - sp for callchains > * - eflags, for future purposes, just in case > */ > static inline void perf_fetch_caller_regs(struct pt_regs *regs) I've extended that like so: --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h @@ -1058,12 +1058,18 @@ static inline void perf_arch_fetch_calle #endif /* - * Take a snapshot of the regs. Skip ip and frame pointer to - * the nth caller. We only need a few of the regs: + * When generating a perf sample in-line, instead of from an interrupt / + * exception, we lack a pt_regs. This is typically used from software events + * like: SW_CONTEXT_SWITCHES, SW_MIGRATIONS and the tie-in with tracepoints. + * + * We typically don't need a full set, but (for x86) do require: * - ip for PERF_SAMPLE_IP * - cs for user_mode() tests - * - sp for callchains - * - eflags, for future purposes, just in case + * - sp for PERF_SAMPLE_CALLCHAIN + * - eflags for MISC bits and CALLCHAIN (see: perf_hw_regs()) + * + * NOTE: assumes @regs is otherwise already 0 filled; this is important for + * things like PERF_SAMPLE_REGS_INTR. */ static inline void perf_fetch_caller_regs(struct pt_regs *regs) {