From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 876B62D7DDD; Wed, 27 May 2026 03:34:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.10 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779852857; cv=none; b=DHWVVRfxHZd9TBlXvmxQhJUG7mfPdrEemgo2JprNNX2k4pNen5gJtoHwWQyH5XszWYWJI6WvD0e9OOzT7EAtcoNDtNRSTOcQiXEDX8sgsbUx03BIeD83A43s2bFjHlvL9Lkfvvn7ZsNX57MYHWUUMcMPykkTwCNAQyvI3v/JkXM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779852857; c=relaxed/simple; bh=JsriVoaHDbR6VPYqZpYIfpQS0+Q66rzOuV5vrK18h54=; h=Date:Message-ID:From:To:Cc:Subject:In-Reply-To:References: MIME-Version:Content-Type; b=kur6jbr5Dp1J2V/sxYdoJ8u9GAaYEdZZxYIgplf7RemZJT2y8riP0FQa3kNQZnGZNc170QziW1yulL/rPC31rkssuK9y5SVb7YN67OiERLIPjvkz16gXvF2heAz+nS1c5BJJ5l5mX3W0AK0qVf+IDFRHOZazTdTpc6gAqzr5yRk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=UzkkNkev; arc=none smtp.client-ip=198.175.65.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="UzkkNkev" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1779852857; x=1811388857; h=date:message-id:from:to:cc:subject:in-reply-to: references:mime-version; bh=JsriVoaHDbR6VPYqZpYIfpQS0+Q66rzOuV5vrK18h54=; b=UzkkNkev890gZX6NZNXRCpQp3RdiexJV4VvAFKeh7TP0xlhB5FkiMFDv QRFr0jxk4DmkrFvZDFLP4Eag1KwvnK0agjXp9CQbFikSjMCZ/x/8ZRnS7 thvufNUqFVKyMT/2EINbDtjFY8v6EluRJtcDS14jgb3skIKx7JTIMQdVY iVFoKaSxk9Ff47fDES/1TQavMYgzizOlHWJAqLE44FdlyHM9gF4S6yGaJ EWC85MkOQfVUy+7ZBvkfoP/ZZhi0wj7ba1NQtvggaikONTfLC49wmmY3A uTyv/nRuO6ty2WW/2PCoDAaH1Mnx9vQjDuPF+Taq5ThL/aI/80Mr/Y7n8 A==; X-CSE-ConnectionGUID: PDwFMWZvSnqO6rHMngwPMA== X-CSE-MsgGUID: aU4PtF3XT+yqZFO/2yRS0Q== X-IronPort-AV: E=McAfee;i="6800,10657,11798"; a="98101424" X-IronPort-AV: E=Sophos;i="6.24,170,1774335600"; d="scan'208";a="98101424" Received: from orviesa006.jf.intel.com ([10.64.159.146]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 May 2026 20:34:16 -0700 X-CSE-ConnectionGUID: b+jIGZ3PR3u3QDGANc1WlA== X-CSE-MsgGUID: 6UECSbfrS9K9iRUF3ep3Rg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.24,170,1774335600"; d="scan'208";a="241065613" Received: from gauravga-mobl1.amr.corp.intel.com (HELO adixit-MOBL3.intel.com) ([10.125.67.21]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 May 2026 20:34:15 -0700 Date: Tue, 26 May 2026 20:34:14 -0700 Message-ID: <87fr3dv83t.wl-ashutosh.dixit@intel.com> From: "Dixit, Ashutosh" To: John Hubbard Cc: Matthew Brost , Thomas =?ISO-8859-1?Q?Hellstr?= =?ISO-8859-1?Q?=F6m?= , Rodrigo Vivi , David Airlie , Simona Vetter , Peter Zijlstra , "Ingo Molnar" , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , "Ian Rogers" , Adrian Hunter , "James Clark" ,, ,, LKML Subject: Re: [PATCH v2 1/2] perf/core: out-of-line and export perf_allow_cpu/tracepoint() In-Reply-To: <20260523013326.129491-2-jhubbard@nvidia.com> References: <20260523013326.129491-1-jhubbard@nvidia.com> <20260523013326.129491-2-jhubbard@nvidia.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?ISO-8859-4?Q?Goj=F2?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/30.2 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) Precedence: bulk X-Mailing-List: linux-perf-users@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII On Fri, 22 May 2026 18:33:25 -0700, John Hubbard wrote: > > These helpers are static inline in and reach > into sysctl_perf_event_paranoid and security_perf_event_open(), > neither of which is itself exported. The perf_allow_* trio is > therefore asymmetric: built-in callers can use any of the three, but > modular code can only call perf_allow_kernel(). > > Move both bodies into kernel/events/core.c next to perf_allow_kernel() > and export them with EXPORT_SYMBOL_GPL, following the shape of > commit 5e9629d0ae97 ("drivers/perf: arm_spe: Use perf_allow_kernel() > for permissions"). Existing in-tree callers live in built-in arch and > tracing code, so the change is invisible to them. > > Provide !CONFIG_PERF_EVENTS stubs that fall back to perfmon_capable(), > so the helpers stay callable when perf is compiled out. > > Signed-off-by: John Hubbard Reviewed-by: Ashutosh Dixit > --- > include/linux/perf_event.h | 31 +++++++++++++++---------------- > kernel/events/core.c | 18 ++++++++++++++++++ > 2 files changed, 33 insertions(+), 16 deletions(-) > > diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h > index 48d851fbd8ea..5842552294c1 100644 > --- a/include/linux/perf_event.h > +++ b/include/linux/perf_event.h > @@ -1791,22 +1791,8 @@ static inline int perf_is_paranoid(void) > } > > extern int perf_allow_kernel(void); > - > -static inline int perf_allow_cpu(void) > -{ > - if (sysctl_perf_event_paranoid > 0 && !perfmon_capable()) > - return -EACCES; > - > - return security_perf_event_open(PERF_SECURITY_CPU); > -} > - > -static inline int perf_allow_tracepoint(void) > -{ > - if (sysctl_perf_event_paranoid > -1 && !perfmon_capable()) > - return -EPERM; > - > - return security_perf_event_open(PERF_SECURITY_TRACEPOINT); > -} > +extern int perf_allow_cpu(void); > +extern int perf_allow_tracepoint(void); > > extern int perf_exclude_event(struct perf_event *event, struct pt_regs *regs); > > @@ -2023,6 +2009,19 @@ perf_event_pause(struct perf_event *event, bool reset) { return 0; } > static inline int > perf_exclude_event(struct perf_event *event, struct pt_regs *regs) { return 0; } > > +static inline int perf_allow_kernel(void) > +{ > + return perfmon_capable() ? 0 : -EACCES; > +} > +static inline int perf_allow_cpu(void) > +{ > + return perfmon_capable() ? 0 : -EACCES; > +} > +static inline int perf_allow_tracepoint(void) > +{ > + return perfmon_capable() ? 0 : -EPERM; > +} > + > #endif /* !CONFIG_PERF_EVENTS */ > > #if defined(CONFIG_PERF_EVENTS) && defined(CONFIG_CPU_SUP_INTEL) > diff --git a/kernel/events/core.c b/kernel/events/core.c > index 7935d5663944..cb13f3ad11a3 100644 > --- a/kernel/events/core.c > +++ b/kernel/events/core.c > @@ -14731,6 +14731,24 @@ int perf_allow_kernel(void) > } > EXPORT_SYMBOL_GPL(perf_allow_kernel); > > +int perf_allow_cpu(void) > +{ > + if (sysctl_perf_event_paranoid > 0 && !perfmon_capable()) > + return -EACCES; > + > + return security_perf_event_open(PERF_SECURITY_CPU); > +} > +EXPORT_SYMBOL_GPL(perf_allow_cpu); > + > +int perf_allow_tracepoint(void) > +{ > + if (sysctl_perf_event_paranoid > -1 && !perfmon_capable()) > + return -EPERM; > + > + return security_perf_event_open(PERF_SECURITY_TRACEPOINT); > +} > +EXPORT_SYMBOL_GPL(perf_allow_tracepoint); > + > /* > * Inherit an event from parent task to child task. > * > -- > 2.54.0 >