Received: by 2002:a25:b323:0:0:0:0:0 with SMTP id l35csp2534787ybj; Mon, 23 Sep 2019 05:34:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqyjOy2QaHxgktc9zn1n+A9n592Ermsxku8ec2ZVcgfXQs/W2t6/1iG8M3v9QiIeC7n8fHqO X-Received: by 2002:a17:906:6c98:: with SMTP id s24mr20146454ejr.28.1569242049417; Mon, 23 Sep 2019 05:34:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569242049; cv=none; d=google.com; s=arc-20160816; b=vslBqdRCtdoD11SN/mjUZtnR2X0h0ThnuugKiCfFfDnD0uVnjmliqO6F8FbpMtCzFr VFTMb6+biMT650Yq/X+h/3HXECBnVZS/FBI02gzbZcrhgjgDkTU8LFJTtXzs13al1A30 mTW61/X0JZjGsmvCDgdiix64Wq4cj3J6K2GAqv0O2PoVRFmLZ5NfViBJd58dRqs6qCDU BsLdpir8wpfsCHHkwXp7AhlUHOlquojCzVlUYkUIqOqUGaVjpXcrtZus7E/4dEl/a/+n zHnmG6/yNqaai7PzZa2EcunPmmVx0H8ZQRSzKNiEbWvyMz6mVrqXBMVbUIMtYugbahdo ldSA== 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:dkim-signature; bh=rGpXWgfcyYZWJL8n2+Ik9dQNFelwopW6WQlt8ye2PV8=; b=Kse24KMMIb7RrV9Zw8Qg1m7qbd4RgD21wVrQctVxi4NfCcV/chRAWlzGexcOmpKQlq JaAjJWhD2I8cj2uD8vCVBkTEJ2r6W995j2bsDVXUIdAuokw9xXOHJ+b2zLYJzXE2xycL rVDw0GEW5hLJum3U8Z3zGPJ4QtMMboNCCOG0XTfiUsFdqY/tvQRCAvyEXWorpIbD2LFJ n5VFcE4Ve5KaFeV+t3Zd7HIqxC/QKhHXdbbPAYBbBsH9j6p6RcK72ebB6s2NFwbF4wue aqWiamCdjsSJ/bHqVQ+j9a6iJ4aK9wdweebTqPuoviVumuRmZywQ2qa4u8oOmMmqP3at WBAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=eJpkOX5i; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j34si6281299ede.10.2019.09.23.05.33.45; Mon, 23 Sep 2019 05:34:09 -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=pass header.i=@google.com header.s=20161025 header.b=eJpkOX5i; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2407038AbfITXFp (ORCPT + 99 others); Fri, 20 Sep 2019 19:05:45 -0400 Received: from mail-io1-f65.google.com ([209.85.166.65]:46604 "EHLO mail-io1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2407007AbfITXFo (ORCPT ); Fri, 20 Sep 2019 19:05:44 -0400 Received: by mail-io1-f65.google.com with SMTP id c6so6650539ioo.13 for ; Fri, 20 Sep 2019 16:05:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=rGpXWgfcyYZWJL8n2+Ik9dQNFelwopW6WQlt8ye2PV8=; b=eJpkOX5iM6q92V4fU+lzNxm/1cbcyChsBVXC+577aFux9yT4bNcahng78RT2btI63z Kx6Fc1EzmSn5p+V1PVpi4aSN19Htl4m6qNqLCg6WueRY7e2WYkxWbxZtngklzI+9DYMV JsukC9oLoKjcNNboCOBGSNn7mj+0jFdMtxLTJtmROYZtAkNCtrY9uQHqDcoXKJpSJlle 85F3UWgzZjuWrPYjMmjcXMXEPlNr8A2HPz+pFC1M4OxM/r2jHZrAjtD3Nxf8WZtE/gHp c0ZvzfRCh0pVyRLcOIjStwzfwdRfB5RmGxUTRa8z/BBlKfxJZPOt01WZu4T1ffukJYzb i6CQ== 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=rGpXWgfcyYZWJL8n2+Ik9dQNFelwopW6WQlt8ye2PV8=; b=hkiyV43Oow6jwAmtarkeOhOwxOaoTN6Aq8taWiSn8K/+5/Vz9snGgws8jiKpk/bVXo 9rXU/kFmaMnnzr+WVHVvAUIjOXgPGevUq6sho+C99mXOGKGt6q/kqybCEyJ3Mhx+M6Fd UtAEx7wGD9YR0Z5OCc5j/SnDLikzk6rJwE9EnZZi18aQCxjHDDbpANzfbPddSwSWlweD SkWoYjLvPMTHuPHxxyocpzFGNEcSzOMrHIRLvsnZx3ejMZaucnkKPWi9h7HzRtRVjLDE gGq829xra/4ZigAvsi6qlYtAea0GIIB4ic/ZOJgBu0DNqaWBFDJdVywmNnY6ex33W4XH hgFQ== X-Gm-Message-State: APjAAAXrA6M0J3jLcISdZbJaWCXess2cOXLhWJPI2zmSfljJ6LySZchk 2bITzf7IIkkkMlfFtDneKzbyywdE2ovpmVIFZNeU1A== X-Received: by 2002:a5d:8908:: with SMTP id b8mr585572ion.237.1569020743892; Fri, 20 Sep 2019 16:05:43 -0700 (PDT) MIME-Version: 1.0 References: <20190904062603.90165-1-eranian@google.com> <20190920191223.GC26850@krava> In-Reply-To: <20190920191223.GC26850@krava> From: Stephane Eranian Date: Fri, 20 Sep 2019 16:05:32 -0700 Message-ID: Subject: Re: [PATCH] perf record: fix priv level with branch sampling for paranoid=2 To: Jiri Olsa Cc: LKML , Peter Zijlstra , mingo@elte.hu, Arnaldo Carvalho de Melo , Namhyung Kim 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 Fri, Sep 20, 2019 at 12:12 PM Jiri Olsa wrote: > > On Tue, Sep 03, 2019 at 11:26:03PM -0700, Stephane Eranian wrote: > > Now that the default perf_events paranoid level is set to 2, a regular user > > cannot monitor kernel level activity anymore. As such, with the following > > cmdline: > > > > $ perf record -e cycles date > > > > The perf tool first tries cycles:uk but then falls back to cycles:u > > as can be seen in the perf report --header-only output: > > > > cmdline : /export/hda3/tmp/perf.tip record -e cycles ls > > event : name = cycles:u, , id = { 436186, ... } > > > > This is okay as long as there is way to learn the priv level was changed > > internally by the tool. > > > > But consider a similar example: > > > > $ perf record -b -e cycles date > > Error: > > You may not have permission to collect stats. > > > > Consider tweaking /proc/sys/kernel/perf_event_paranoid, > > which controls use of the performance events system by > > unprivileged users (without CAP_SYS_ADMIN). > > ... > > > > Why is that treated differently given that the branch sampling inherits the > > priv level of the first event in this case, i.e., cycles:u? It turns out > > that the branch sampling code is more picky and also checks exclude_hv. > > > > In the fallback path, perf record is setting exclude_kernel = 1, but it > > does not change exclude_hv. This does not seem to match the restriction > > imposed by paranoid = 2. > > > > This patch fixes the problem by forcing exclude_hv = 1 in the fallback > > for paranoid=2. With this in place: > > > > $ perf record -b -e cycles date > > cmdline : /export/hda3/tmp/perf.tip record -b -e cycles ls > > event : name = cycles:u, , id = { 436847, ... } > > > > And the command succeeds as expected. > > > > Signed-off-by: Stephane Eranian > > --- > > tools/perf/util/evsel.c | 6 ++++-- > > 1 file changed, 4 insertions(+), 2 deletions(-) > > > > diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c > > index 85825384f9e8..3cbe06fdf7f7 100644 > > --- a/tools/perf/util/evsel.c > > +++ b/tools/perf/util/evsel.c > > @@ -2811,9 +2811,11 @@ bool perf_evsel__fallback(struct evsel *evsel, int err, > > if (evsel->name) > > free(evsel->name); > > evsel->name = new_name; > > - scnprintf(msg, msgsize, > > -"kernel.perf_event_paranoid=%d, trying to fall back to excluding kernel samples", paranoid); > > + scnprintf(msg, msgsize, "kernel.perf_event_paranoid=%d, trying " > > + "to fall back to excluding kernel and hypervisor " > > + " samples", paranoid); > > extra space in here ^ > > Warning: > kernel.perf_event_paranoid=2, trying to fall back to excluding kernel and hypervisor samples > > other than that it looks good to me > Fixed in v2. > Acked-by: Jiri Olsa > > thanks, > jirka