Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp6319237imm; Wed, 27 Jun 2018 06:00:18 -0700 (PDT) X-Google-Smtp-Source: ADUXVKILFXSW1FKsu7u7LkLqmt908CUKjDf2LRC+5QdAhAOKhi6+7XGbeyw/cHWpM3WouJmSWb1d X-Received: by 2002:a63:b543:: with SMTP id u3-v6mr5091183pgo.365.1530104418753; Wed, 27 Jun 2018 06:00:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530104418; cv=none; d=google.com; s=arc-20160816; b=ONX01KL4gPdNEQpycr7ZjJLW+wKW6W8BSIN1A6Ezu8n3LnWTBH6i2f6wB6d1U3utWP FKw/W8tQyJUBJswn2jsfUuuHl0dK6ewXQNW1Fmk1WYP+Mqt8fhTQdyLZ5EzEQcvwY/3M Pjy++FmbQWm4aKVUsJiP4xq7NbyB6q5k4oqtMxE9G+OgbSUWbeyeEiDXX1/bTWl9UXD7 HLVm5VP+eG1HLzFXWs0xgajDr+iJ9ADTcdRexU6vY00z00jcT/52RWxbQsg8/IxmxUI4 AO1rO6n4aM26jcYR6GSpP6IsZUAghZ1ZapIR0Qi0Ub9C2O8dcxjTNZTxQc+bPbCX7RRT 7vbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=yX2dZgRVkvLUNJtW7opA6Mz7H+VFrIakW15vYf2gdLA=; b=Sl93BMdSuOAxLNBLgrAZDe/1plP56Rils6QSj03QlW3O6WtvG2FRzI09XQQFpNUqOS wglBZI7C5hIZ8bynTxLZaC9Xyd3hXGLTJ1cttNkLDDQiCaXvEu9/LASEHisc4DUArKUq iUXbq60LvzPZwPgJCtdMRO/ZXJyGgQT94GeBLpTvfnXPZVsMryfcnpWfezDpyYo9P4um CudZKwuhBveEcz4rN1OyAfVBH+PPianPeb9XqyhnJauW6LiiVhX8NXP2eNeyaSfNOCQO x+zmyrZn7u8HCu0KQdnkmpAR/BHKhcapEHFOpajS0L68h0RZ1bfW0dN03ZgNgGBNzEb3 q43w== 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=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z4-v6si3324771pgv.621.2018.06.27.06.00.04; Wed, 27 Jun 2018 06:00:18 -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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754451AbeF0M6i (ORCPT + 99 others); Wed, 27 Jun 2018 08:58:38 -0400 Received: from mga12.intel.com ([192.55.52.136]:24776 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754277AbeF0M6h (ORCPT ); Wed, 27 Jun 2018 08:58:37 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jun 2018 05:58:37 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,278,1526367600"; d="scan'208";a="53312522" Received: from linux.intel.com ([10.54.29.200]) by orsmga006.jf.intel.com with ESMTP; 27 Jun 2018 05:58:36 -0700 Received: from [10.125.252.135] (abudanko-mobl.ccr.corp.intel.com [10.125.252.135]) by linux.intel.com (Postfix) with ESMTP id 9F16F5800E9; Wed, 27 Jun 2018 05:58:33 -0700 (PDT) Subject: Re: [RFC 3/4] perf: Allow per PMU access control To: Tvrtko Ursulin , linux-kernel@vger.kernel.org Cc: Tvrtko Ursulin , Thomas Gleixner , Peter Zijlstra , Ingo Molnar , "H. Peter Anvin" , Arnaldo Carvalho de Melo , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Madhavan Srinivasan , Andi Kleen , x86@kernel.org References: <20180626153642.5587-1-tvrtko.ursulin@linux.intel.com> <20180626153642.5587-4-tvrtko.ursulin@linux.intel.com> <59478e35-4ac9-7be5-172a-c8301d9e11fd@ursulin.net> <2d389cf9-e284-0557-159a-e70a758d357b@linux.intel.com> <3b774f2e-56da-3d39-6fda-a4240a195377@ursulin.net> From: Alexey Budankov Message-ID: <8351504c-022a-e0d3-581d-a6a80b42607a@linux.intel.com> Date: Wed, 27 Jun 2018 15:58:32 +0300 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: <3b774f2e-56da-3d39-6fda-a4240a195377@ursulin.net> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 27.06.2018 13:05, Tvrtko Ursulin wrote: > > On 27/06/18 10:47, Alexey Budankov wrote: >> >> >> On 27.06.2018 12:15, Tvrtko Ursulin wrote: >>> >>> On 26/06/18 18:25, Alexey Budankov wrote: >>>> Hi, >>>> >>>> On 26.06.2018 18:36, Tvrtko Ursulin wrote: >>>>> From: Tvrtko Ursulin >>>>> >>>>> For situations where sysadmins might want to allow different level of >>>>> access control for different PMUs, we start creating per-PMU >>>>> perf_event_paranoid controls in sysfs. >>>>> >>>>> These work in equivalent fashion as the existing perf_event_paranoid >>>>> sysctl, which now becomes the parent control for each PMU. >>>>> >>>>> On PMU registration the global/parent value will be inherited by each PMU, >>>>> as it will be propagated to all registered PMUs when the sysctl is >>>>> updated. >>>>> >>>>> At any later point individual PMU access controls, located in >>>>> /device//perf_event_paranoid, can be adjusted to achieve >>>>> fine grained access control. >>>>> >>>>> Signed-off-by: Tvrtko Ursulin >>>>> Cc: Thomas Gleixner >>>>> Cc: Peter Zijlstra >>>>> Cc: Ingo Molnar >>>>> Cc: "H. Peter Anvin" >>>>> Cc: Arnaldo Carvalho de Melo >>>>> Cc: Alexander Shishkin >>>>> Cc: Jiri Olsa >>>>> Cc: Namhyung Kim >>>>> Cc: Madhavan Srinivasan >>>>> Cc: Andi Kleen >>>>> Cc: Alexey Budankov >>>>> Cc: linux-kernel@vger.kernel.org >>>>> Cc: x86@kernel.org >>>>> --- >>>>>    include/linux/perf_event.h | 12 ++++++-- >>>>>    kernel/events/core.c       | 59 ++++++++++++++++++++++++++++++++++++++ >>>>>    kernel/sysctl.c            |  4 ++- >>>>>    3 files changed, 71 insertions(+), 4 deletions(-) >>>>> >>>>> diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h >>>>> index d7938d88c028..22e91cc2d9e1 100644 >>>>> --- a/include/linux/perf_event.h >>>>> +++ b/include/linux/perf_event.h >>>>> @@ -271,6 +271,9 @@ struct pmu { >>>>>        /* number of address filters this PMU can do */ >>>>>        unsigned int            nr_addr_filters; >>>>>    +    /* per PMU access control */ >>>>> +    int                perf_event_paranoid; >>>> >>>> It looks like it needs to be declared as atomic and atomic_read/atomic_write >>>> operations need to be explicitly used below in the patch as far this >>>> variable may be manipulated by different threads at the same time >>>> without explicit locking. >>> >>> It is just a write of an integer from either sysfs access or sysctl. As such I don't think going atomic would change anything. There is no RMW or increment or anything on it. >>> >>> Unless there are architectures where int stores are not atomic? But then the existing sysctl would have the same issue. So I suspect we can indeed rely on int store being atomic. >> >> Yep, aligned word read/write is atomic on Intel and there is no runtime issue >> currently, but the implementation itself is multithread and implicitly relies >> on that atomicity so my suggestion is just explicitly code that assumption :). >> Also, as you mentioned, that makes the arch independent part of code more portable. > > Perhaps we are not on the same page, but my argument was that the current sysctl (or sysctl via proc) has the same issue with multiple threads potentially writing to it. Well, yes, currently the issue exists but it could be addressed in the new design. As long as the end result is a valid value it is not a problem. So I don't see what this patch changes in that respect. Different tasks writing either of the sysctl/sysfs values race, but end up with valid values everywhere. If we can rely on int stores to be atomic on all architectures I don't see an effective difference after changing to atomic_t, or even taking the pmu mutex over the per PMU sysfs writes. So I don't see value in complicating the code with either approach but am happy to be proved wrong if that is the case. > > Regards, > > Tvrtko >