Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp497844ybb; Wed, 25 Mar 2020 04:09:50 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtOxyGat4eHstDhkzcHeb7xod+u4ZVZIYlnFqM1z1/jEGiNr05DyP6bnSUfO5dEu0cDXEnW X-Received: by 2002:a9d:22e9:: with SMTP id y96mr2000465ota.217.1585134590654; Wed, 25 Mar 2020 04:09:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585134590; cv=none; d=google.com; s=arc-20160816; b=x+uEE4V7Po5fZbZfymCXcNg82W/boDuQwF8MSfCccwSbgoJG3YBo+iFDHZqz/SHLbi Ml4r9ZC2MQlXs6/tB1C1m+wRNgcpk3y47Qt8f5tvaVfwaAYSWeks9oZ2kA813WKsoXAw vMfguLPH/uTJ9PqPxG/rBKhbgh7B236WGF9U/QLUD28WHceb+yW/IJxszBaI4/eGFSza RwlpXIAzPi1zWaJ6Psl8kHQRAgblS1/AJkkgS4egOY94T5gUwChG/4U3V9y0MWHlUByg 9shX5ieesS585e1nj0/LQ0pCk8UtKkuLIKmbsVwlsTqqmLXv9plY9ucE5LaCy25oFbhC kYTQ== 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=ZzVib+XMCENErpWLWFN6YmFibjOIg91gwzlR3wW18B8=; b=fH/Ds0/D7yMMHLWdgA8fbc/6dT0FihA9ymtZpgCmg++0SH5SuwGIOcqcbnYNb5Uxiu rnzc1rWmjA7nADyDvMzLATo5qRaM+ctt+Dzc0w1brTA8VXihRYSv7AS4SC1st93vYE9d gHqYv3wVE8erLkB4AB12iZlce4r8dd7wJ/a8rFRSrxtbRhH2itycS4b8Q+BtWNdrxfxj GSL4JkKfpTRF+EYgXxsza9YHKYYWdG6BHj0d3Ihh1qYmOLFsU5bZ/8dbb9RB0XbvQjLv ppmpShp9iBkjlwqZamOb0AfzAnughvTMIZl9F5XlJxEZ8kw7RcS/7g8bt27HV3L3F3sV aecw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=N4BlLzeN; 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=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 l3si1515594oie.6.2020.03.25.04.09.33; Wed, 25 Mar 2020 04:09:50 -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=@redhat.com header.s=mimecast20190719 header.b=N4BlLzeN; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726998AbgCYLJG (ORCPT + 99 others); Wed, 25 Mar 2020 07:09:06 -0400 Received: from us-smtp-delivery-74.mimecast.com ([63.128.21.74]:29974 "EHLO us-smtp-delivery-74.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726043AbgCYLJG (ORCPT ); Wed, 25 Mar 2020 07:09:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585134545; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=ZzVib+XMCENErpWLWFN6YmFibjOIg91gwzlR3wW18B8=; b=N4BlLzeNNM44WQFFVHjTKUgAUX8eVFCi0akGNgaik2jpODOID0sjkCCIPy+FfWYqCAah/E 4YazwqruGMz43L7/fkQOen9a0DhpeNUjye6PUrodfwgpI4za0LiWpZbPadsL547YXABvRE LB3V6n4T7pPBNsOS+7C5LCyE7a59qwc= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-262-JP4jV16sOIycpUQ-MCCuzQ-1; Wed, 25 Mar 2020 07:09:03 -0400 X-MC-Unique: JP4jV16sOIycpUQ-MCCuzQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1A82D8017CC; Wed, 25 Mar 2020 11:09:02 +0000 (UTC) Received: from krava (unknown [10.40.192.119]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6D4411001938; Wed, 25 Mar 2020 11:09:00 +0000 (UTC) Date: Wed, 25 Mar 2020 12:08:57 +0100 From: Jiri Olsa To: Stephane Eranian Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, mingo@elte.hu, acme@redhat.com, irogers@google.com Subject: Re: [PATCH] perf/tools: fix perf_evsel__fallback() for paranoid=2 and -b Message-ID: <20200325110857.GB1856035@krava> References: <20200324181020.229914-1-eranian@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200324181020.229914-1-eranian@google.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 24, 2020 at 11:10:20AM -0700, Stephane Eranian wrote: > When perf_event_paranoid=2, regular users are prevented from sampling > at the kernel level. However, it the user passes an event without > a privilege level, the tool will force :u when it detects paranoid>1. > This works well, except when branch sampling is requested. It has a more > stringent requirement especially with exclude_hv. > $ perf record ls > [ perf record: Woken up 1 times to write data ] > [ perf record: Captured and wrote 0.001 MB /tmp/perf.data ] > > But: > $ perf record -b ls > 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). > > The current value is 2: > > -1: Allow use of (almost) all events by all users > >= 0: Disallow raw tracepoint access by users without CAP_IOC_LOCK > >= 1: Disallow CPU event access by users without CAP_SYS_ADMIN > >= 2: Disallow kernel profiling by users without CAP_SYS_ADMIN > > To make this setting permanent, edit /etc/sysctl.conf too, e.g.: > > kernel.perf_event_paranoid = -1 > > The problem is that in the fallback cod only exclude_kernel is checked and > if set, then exclude_hv is not forced to 1. When branch sampling is enabled > exclude_hv must be set. > > This patch fixes the bug in the fallback code by considering the value of > exclude_hv and not just exclude_kernel. We prefer this approach to give a > chance to exclude_hv=0. > > Signed-off-by: Stephane Eranian Acked-by: Jiri Olsa thanks, jirka > --- > tools/perf/util/evsel.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c > index 816d930d774e7..db0e6112992e5 100644 > --- a/tools/perf/util/evsel.c > +++ b/tools/perf/util/evsel.c > @@ -2424,7 +2424,8 @@ bool perf_evsel__fallback(struct evsel *evsel, int err, > > zfree(&evsel->name); > return true; > - } else if (err == EACCES && !evsel->core.attr.exclude_kernel && > + } else if (err == EACCES && > + (!evsel->core.attr.exclude_kernel || !evsel->core.attr.exclude_hv) && > (paranoid = perf_event_paranoid()) > 1) { > const char *name = perf_evsel__name(evsel); > char *new_name; > -- > 2.25.1.696.g5e7596f4ac-goog >