Received: by 2002:a25:b323:0:0:0:0:0 with SMTP id l35csp2343623ybj; Mon, 23 Sep 2019 02:05:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqwdfG7YXS06+JckrP7FGaXzZdkONjZ1dpC7GVyrClpIquWdoUJi32kBLTELwqT7MYhbQSnr X-Received: by 2002:a17:906:1998:: with SMTP id g24mr18676880ejd.305.1569229555821; Mon, 23 Sep 2019 02:05:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569229555; cv=none; d=google.com; s=arc-20160816; b=L6DFXsOqEYz+PiGekrzU3dPO55HEWb9DiupeaQWj38Kczxb2LfA3saaGCbk8bdZzcV Xp1XW1DKXWUn3FVNU8bBUOI50yh7CBuIB6q+w/h1I2oYKli8hV19f93jqHmA66QJgj49 gmUKh6n+moj66nskcK33QpHfTOglJUG/RhViXOP8iLOBvkMv79y5ay5hDY6hPUmGQEi7 4Bpn15l+tWoHDqC9Nd05fEX4zET6scW16+7D5lq7zo5kShwTgUiKQqzFY9nfM5OGQhJG AbOX8NE9AjQCdTtFvjmrwxKpwlfwGjNEJBDbEY1z/tpsWLLEZ6vAQCduQapxJYZt6TWs g9qA== 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=sZUqbxM8LRjeplWfIaIQA8++brLY3ynAXyr/KZ8vkVY=; b=vsZ+wqxRzkFzx0CHNlS7mvtU4NMigDzjU5iq/2ykEV91lEJSu0gVMIhS/IqJ4pZUG/ 5/9Z0dHQ6EF3GoA3xKvUKbGKCAo5t1aqPVoLCCWDDW0kmshI5cTUXyb7PTDF3EjyHxA7 ktEEU+2vihenRlj/G0YLdtBFnx1as6sgr/aPrfONJEu7Rdyo2G9UOzTepLIL26nhkaMq IQOtW+m3VaMfkauZCt/UsZelGsbZT2boLurRC5sFk6cbO8ls9KqXWpuEgN9/gEqoeXJI f/Wqow8kN1NZ4NZsFpl14R22WG9+c+3qlzQOQ+taVc03CpNcy3mqS/065APGQp+38kyT itzA== 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 qh28si4635081ejb.210.2019.09.23.02.05.32; Mon, 23 Sep 2019 02:05:55 -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 S2406923AbfITTM1 (ORCPT + 99 others); Fri, 20 Sep 2019 15:12:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40570 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2406909AbfITTM0 (ORCPT ); Fri, 20 Sep 2019 15:12:26 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 88181307D84D; Fri, 20 Sep 2019 19:12:26 +0000 (UTC) Received: from krava (ovpn-204-62.brq.redhat.com [10.40.204.62]) by smtp.corp.redhat.com (Postfix) with SMTP id 66C915D9C3; Fri, 20 Sep 2019 19:12:24 +0000 (UTC) Date: Fri, 20 Sep 2019 21:12:23 +0200 From: Jiri Olsa To: Stephane Eranian Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, mingo@elte.hu, acme@redhat.com, namhyung@kernel.org Subject: Re: [PATCH] perf record: fix priv level with branch sampling for paranoid=2 Message-ID: <20190920191223.GC26850@krava> References: <20190904062603.90165-1-eranian@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190904062603.90165-1-eranian@google.com> User-Agent: Mutt/1.12.1 (2019-06-15) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Fri, 20 Sep 2019 19:12:26 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Acked-by: Jiri Olsa thanks, jirka