Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp273184pxa; Tue, 4 Aug 2020 05:24:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxwqKuMlKXabgJAN592VOjC6dJcYioM8ayWDyw8CUP8hBBPI1ffoMRno1lr2aea+H6y1HeY X-Received: by 2002:a17:906:8595:: with SMTP id v21mr3559863ejx.347.1596543882818; Tue, 04 Aug 2020 05:24:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596543882; cv=none; d=google.com; s=arc-20160816; b=KDtxKI6Etr9zaVGNkGA17Gr4dDp9y9OYm9M8hp6pE9OazrnSZaNCzgKi3qsCublSMQ CrxjAEVRfql/TXnoZw6ztdbQFwqTHLVAye39PBXT6FGeKnOan73+XUw8wIq0TmSszsZ9 x5Mibib3tdMvZkH0aQxv+vzqxToPSm987asMPj2NDfVBk03tr9lH9yVBUhAHI8e6dPw2 0KUbnVFY3ekvVgKHqKsEmlK+Sido7OqOTmquQSBz8XTic7JYJ+w4B0g2yoEl3zzfxwQw J1SA7FBHcJ/lDwBC0d2TAL08sfkJekkXRdl0p3kO94H8X+HXmJh99PLPO4GzDc8K4KF7 jQNg== 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 :dkim-signature; bh=R1BpYLpY9SppDsEqsOomEhp8dPWGGoK9Ld+yLP0ESbw=; b=X8ag3loIz+s/Ds6pIEgsKBFSYvRuG3DnZDw4gTuEbdLH+EmtF9SqMpJ19HwAWEMXlV wWqMQvnTukIcxbkn2WpXy6AbrMyQZinAgnlwybQZ0q6tARhR1ABNOeeKXRSW5GkT9x82 HqXGlz2kLPnPoeRG/P+3f9TsnFA5jCtKaKhW4PnkQOJXqT+JJDD0ihvml6J4lQzfEHnv QiG01zuG8UxruLG9l3GJtSkybQtlry2s6rMLxm62VC7Esq3U8Q+LRZ2SZh0j/40YnygE aViaU87FfKznL2kDDb0gDPEWNPcJLgJlwoYCphR/mNlig+J7zdSefKKGIEnD1rbipwIP Mqlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=LVS9izSi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a12si11823492ejv.186.2020.08.04.05.24.20; Tue, 04 Aug 2020 05:24:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=LVS9izSi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730378AbgHDLxA (ORCPT + 99 others); Tue, 4 Aug 2020 07:53:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729698AbgHDLtN (ORCPT ); Tue, 4 Aug 2020 07:49:13 -0400 Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E73BC06174A for ; Tue, 4 Aug 2020 04:49:12 -0700 (PDT) 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; bh=R1BpYLpY9SppDsEqsOomEhp8dPWGGoK9Ld+yLP0ESbw=; b=LVS9izSi8A2kiEYk7U8ynr0ABC D7e+g3UqysEvd+4IaEwceeZr2Ht8YdHWzxX7yBZboNpe65/d8MLykxgbyrfoinHZfCUMvHoPTS53O imeCwhytPSKHa1lDoVBlD8IZjHwuiPax9HMUfB7yyBF4BudMqrtKscJfVbNfa+G/YsOOhmLDrAwIG aWHY/7YniodHTySFsOO0hRg0e/WIbsdtkQoV8OrO3W+atkq7VC/VOF4Dt8XlcbQghVCGNt3DPdLIs FTQKboyrbCH+48oBttt0E2gybVQUqY4ZlB2Uknfg6pq9LH3XNifP1OkcbACj2O63dFBUwKiET52CW 0LDLdvgg==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1k2vRF-000858-W1; Tue, 04 Aug 2020 11:49:02 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 649E5301E02; Tue, 4 Aug 2020 13:49:00 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 408DA2BDB8C9E; Tue, 4 Aug 2020 13:49:00 +0200 (CEST) Date: Tue, 4 Aug 2020 13:49:00 +0200 From: peterz@infradead.org To: Jin Yao Cc: mingo@redhat.com, oleg@redhat.com, acme@kernel.org, jolsa@kernel.org, Linux-kernel@vger.kernel.org, ak@linux.intel.com, kan.liang@intel.com, yao.jin@intel.com, alexander.shishkin@linux.intel.com, mark.rutland@arm.com Subject: Re: [PATCH v1 2/2] perf/core: Fake regs for leaked kernel samples Message-ID: <20200804114900.GI2657@hirez.programming.kicks-ass.net> References: <20200731025617.16243-1-yao.jin@linux.intel.com> <20200731025617.16243-2-yao.jin@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200731025617.16243-2-yao.jin@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 31, 2020 at 10:56:17AM +0800, Jin Yao wrote: > @@ -6973,7 +6973,8 @@ static struct perf_callchain_entry __empty_callchain = { .nr = 0, }; > struct perf_callchain_entry * > perf_callchain(struct perf_event *event, struct pt_regs *regs) > { > - bool kernel = !event->attr.exclude_callchain_kernel; > + bool kernel = !event->attr.exclude_callchain_kernel && > + !event->attr.exclude_kernel; This seems weird; how can we get there. Also it seems to me that if you have !exclude_callchain_kernel you already have permission for kernel bits, so who cares. > bool user = !event->attr.exclude_callchain_user; > /* Disallow cross-task user callchains. */ > bool crosstask = event->ctx->task && event->ctx->task != current; > @@ -6988,12 +6989,39 @@ perf_callchain(struct perf_event *event, struct pt_regs *regs) > return callchain ?: &__empty_callchain; > } > > +static struct pt_regs *leak_check(struct perf_event_header *header, > + struct perf_event *event, > + struct pt_regs *regs) > +{ > + struct pt_regs *regs_fake = NULL; > + > + if (event->attr.exclude_kernel && !user_mode(regs)) { > + if (!(current->flags & PF_KTHREAD)) { > + regs_fake = task_pt_regs(current); > + if (!user_mode(regs_fake)) { > + regs_fake = NULL; > + instruction_pointer_set(regs, -1L); > + } > + } else > + instruction_pointer_set(regs, -1L); That violates coding style, also: if (!(current->flags & PF_KTHREAD)) { regs_fake = task_pt_regs(current); if (!user_mode(regs_fake)) /* is this not a BUG? */ regs_fake = NULL; } if (!regs_fake) instruction_pointer_set(regs, -1L); Seems simpler to me. > + if ((header->misc & PERF_RECORD_MISC_CPUMODE_MASK) == > + PERF_RECORD_MISC_KERNEL) { > + header->misc &= ~PERF_RECORD_MISC_CPUMODE_MASK; > + header->misc |= PERF_RECORD_MISC_USER; > + } Why the conditional? At this point it had better be unconditionally user, no? headers->misc &= ~PERF_RECORD_MISC_CPUMODE_MASK; headers->misc |= PERF_RECORD_MISC_USER; > + } > + > + return regs_fake; > +}