From nobody Thu Apr 2 15:41:21 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.21]) (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 95B583542F4 for ; Fri, 27 Mar 2026 23:02:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.21 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774652563; cv=none; b=rIBKPCEgqV1eaHBRBTpWnnVKX25JVHYj9xwipMG0awRhfbbN6UUKrhgMllowDZ3S7WH+yRS2P+sisIxWORjWuWVy7yZ1htpPeH+mtsNEGWwlRMEXjdOnxDjBIxO8imcoagLiLxt8mzmvUCjAhIGtHpM/Vo4DoE8WpceSBjyff5U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774652563; c=relaxed/simple; bh=JeiQHXv+lAk/aEcbaYPKYv6PqQufxOxQZD0OfzAcX8U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=od3GyVKMAWBnE6RtzvFqDF+RiEnMfK9XRL2H+sgQKe6TqwYI+StkFNsB/Mr+ZQuCIE6xkHIBeiYzuL+TE5ymTpM1J9vXlsARHCCnqNSUT18NoJ9DKFE8Rt2AHL0kqgxrgJiOD33l/3x+yCCMHeC5Nv99/Ayl0Hbjj4kxs0McfK0= 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=ETzAVk5L; arc=none smtp.client-ip=198.175.65.21 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="ETzAVk5L" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1774652562; x=1806188562; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=JeiQHXv+lAk/aEcbaYPKYv6PqQufxOxQZD0OfzAcX8U=; b=ETzAVk5LpB/So8b4+1QZtpMjdqm3I+gHY7GI0XVHnhyJN8niFpAXk1KH 3vp+ZY6PBQmuFk6geN4CoXOrAt7DDzt/HQ+x5NHVzqffc8nv7spPLI1U/ e0UsLmduJJtnx2Aoi7IqAbX2qyFs6nOh9mkmMcbxeO4cnrDtXGYBoB+/b hStPtoE696x6NWX+lvE6kmoCCeocfrJLmLbG4Ppwlgbe3K6Ny4IEeO0qn Vj3jeRoPEdA9eKPAh1jeOwHSMtMX670b1WeeVV30wnML+/HsMpEoruzwG j1M+mP/toPvC5mBgad2NY0Q72rCZeXstv16rxPaautRH5tPFAATBjUp4l g==; X-CSE-ConnectionGUID: 8elfZ8iKRv6PvvOQ6+lisQ== X-CSE-MsgGUID: vxhKvkvpQ1qzXRfBNZT6Og== X-IronPort-AV: E=McAfee;i="6800,10657,11742"; a="75613287" X-IronPort-AV: E=Sophos;i="6.23,145,1770624000"; d="scan'208";a="75613287" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa113.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Mar 2026 16:02:39 -0700 X-CSE-ConnectionGUID: 7eOKjYShSAevpFLNV1i17g== X-CSE-MsgGUID: 0AuwQNDcRWCtmazjBCh6Mg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,145,1770624000"; d="scan'208";a="218816031" Received: from rfrazer-mobl3.amr.corp.intel.com (HELO agluck-desk3.home.arpa) ([10.124.222.83]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Mar 2026 16:02:15 -0700 From: Tony Luck To: Fenghua Yu , Reinette Chatre , Maciej Wieczor-Retman , Peter Newman , James Morse , Babu Moger , Drew Fustini , Dave Martin , Chen Yu , David E Box , x86@kernel.org Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev, Tony Luck Subject: [PATCH v3 5/7] x86/resctrl: Allow AET to use PMT/TPMI as loadable modules Date: Fri, 27 Mar 2026 16:02:06 -0700 Message-ID: <20260327230208.18094-6-tony.luck@intel.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260327230208.18094-1-tony.luck@intel.com> References: <20260323163452.25044-1-tony.luck@intel.com> <20260327230208.18094-1-tony.luck@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The resctrl subsystem is always built into the base kernel. Currently, enumerating Application Event Tracing (AET) features requires functions from INTEL_PMT_TELEMETRY and INTEL_TPMI. Because resctrl makes direct calls to these functions, it enforces a strict dependency requiring both PMT and TPMI to be built-in. This is overly restrictive. Use the symbol_get() mechanism to allow resctrl to resolve these symbols at runtime, whether they reside in the base kernel or in loadable modules. Use symbol_get() to obtain the addresses of intel_pmt_get_regions_by_featur= e() and intel_pmt_put_feature_group() and use indirect calls using function pointers. Change the pre-mount hook from once-only on first mount to call the hook every time. Add hooks for mount success/failure and unmount so that the hold on the INTEL_PMT_TELEMETRY module is only while the resctrl file system is mounted. Unmount now cleans up all AET structures and disables AET events. Signed-off-by: Tony Luck --- arch/x86/kernel/cpu/resctrl/intel_aet.c | 97 ++++++++++++++++++++++--- 1 file changed, 87 insertions(+), 10 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/intel_aet.c b/arch/x86/kernel/cpu/= resctrl/intel_aet.c index 743a1894fe9a..2d5766904fd8 100644 --- a/arch/x86/kernel/cpu/resctrl/intel_aet.c +++ b/arch/x86/kernel/cpu/resctrl/intel_aet.c @@ -23,6 +23,8 @@ #include #include #include +#include +#include #include #include #include @@ -289,6 +291,9 @@ static enum pmt_feature_id lookup_pfid(const char *pfna= me) return FEATURE_INVALID; } =20 +static struct pmt_feature_group *(*get_feature)(enum pmt_feature_id id); +static void (*put_feature)(struct pmt_feature_group *p); + /* * Request a copy of struct pmt_feature_group for each event group. If the= re is * one, the returned structure has an array of telemetry_region structures, @@ -300,7 +305,7 @@ static enum pmt_feature_id lookup_pfid(const char *pfna= me) * struct pmt_feature_group to indicate that its events are successfully * enabled. */ -bool intel_aet_get_events(void) +static bool get_events(void) { struct pmt_feature_group *p; enum pmt_feature_id pfid; @@ -309,14 +314,14 @@ bool intel_aet_get_events(void) =20 for_each_event_group(peg) { pfid =3D lookup_pfid((*peg)->pfname); - p =3D intel_pmt_get_regions_by_feature(pfid); + p =3D get_feature(pfid); if (IS_ERR_OR_NULL(p)) continue; if (enable_events(*peg, p)) { (*peg)->pfg =3D p; ret =3D true; } else { - intel_pmt_put_feature_group(p); + put_feature(p); } } =20 @@ -325,27 +330,99 @@ bool intel_aet_get_events(void) =20 void __exit intel_aet_exit(void) { - struct event_group **peg; +} =20 - for_each_event_group(peg) { - if ((*peg)->pfg) { - intel_pmt_put_feature_group((*peg)->pfg); - (*peg)->pfg =3D NULL; - } +static bool get_pmt_references(void) +{ + get_feature =3D symbol_get(intel_pmt_get_regions_by_feature); + if (!get_feature) + return false; + put_feature =3D symbol_get(intel_pmt_put_feature_group); + if (!put_feature) { + symbol_put(intel_pmt_get_regions_by_feature); + get_feature =3D NULL; + return false; + } + + return true; +} + +static void put_pmt_references(void) +{ + if (get_feature) { + symbol_put(intel_pmt_get_regions_by_feature); + get_feature =3D NULL; + } + if (put_feature) { + symbol_put(intel_pmt_put_feature_group); + put_feature =3D NULL; } } =20 +static DEFINE_MUTEX(pmt_lock); + +static enum { + AET_UNINITIALIZED, + AET_PRESENT, + AET_NOT_PRESENT +} aet_state; + bool intel_aet_pre_mount(void) { - return false; // Temporary stub + bool ret; + + mutex_lock(&pmt_lock); + + if (aet_state =3D=3D AET_PRESENT) + return true; + + if (aet_state =3D=3D AET_NOT_PRESENT || !get_pmt_references()) + return false; + + ret =3D get_events(); + + if (ret) { + aet_state =3D AET_PRESENT; + } else { + aet_state =3D AET_NOT_PRESENT; + put_pmt_references(); + } + + return ret; +} + +static void aet_cleanup(void) +{ + struct event_group **peg; + + if (aet_state =3D=3D AET_PRESENT) { + for_each_event_group(peg) { + if ((*peg)->pfg) { + struct event_group *e =3D *peg; + + for (int j =3D 0; j < e->num_events; j++) + resctrl_disable_mon_event(e->evts[j].id); + put_feature((*peg)->pfg); + (*peg)->pfg =3D NULL; + } + } + put_pmt_references(); + aet_state =3D AET_UNINITIALIZED; + } } =20 void intel_aet_mount_result(int ret) { + if (ret && ret !=3D -EBUSY) + aet_cleanup(); + mutex_unlock(&pmt_lock); } =20 void intel_aet_unmount(void) { + mutex_lock(&pmt_lock); + aet_cleanup(); + mutex_unlock(&pmt_lock); } =20 #define DATA_VALID BIT_ULL(63) --=20 2.53.0