[PATCH v4 20/31] x86/resctrl: Check for adequate MMIO space

Tony Luck posted 31 patches 7 months, 3 weeks ago
There is a newer version of this series
[PATCH v4 20/31] x86/resctrl: Check for adequate MMIO space
Posted by Tony Luck 7 months, 3 weeks ago
The MMIO space for each telemetry aggregator is arranged as a array of
count registers for each event for RMID 0, followed by RMID 1, and so on.
After all event counters there are three status registers.  All registers
are 8 bytes each.

The total size of MMIO space as described by the XML files is thus:

	(NUM_RMIDS * NUM_COUNTERS + 3) * 8

Add an "mmio_size" field to the event_group structure and a sanity
check that the size reported in the telemetry_region structure obtained
from intel_pmt_get_regions_by_feature() is as large as expected.

Signed-off-by: Tony Luck <tony.luck@intel.com>
---
 arch/x86/kernel/cpu/resctrl/intel_aet.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kernel/cpu/resctrl/intel_aet.c b/arch/x86/kernel/cpu/resctrl/intel_aet.c
index 7e4f6a6672d4..37dd493df250 100644
--- a/arch/x86/kernel/cpu/resctrl/intel_aet.c
+++ b/arch/x86/kernel/cpu/resctrl/intel_aet.c
@@ -49,6 +49,7 @@ struct pmt_event {
  *                      retrieved from intel_pmt_get_regions_by_feature().
  * @pfg:		The pmt_feature_group for this event group
  * @guid:		Unique number per XML description file
+ * @mmio_size:		Number of bytes of mmio registers for this group
  * @pkginfo:		Per-package MMIO addresses
  * @num_events:		Number of events in this group
  * @evts:		Array of event descriptors
@@ -56,6 +57,7 @@ struct pmt_event {
 struct event_group {
 	struct pmt_feature_group	*pfg;
 	int				guid;
+	int				mmio_size;
 	struct mmio_info		**pkginfo;
 	int				num_events;
 	struct pmt_event		evts[] __counted_by(num_events);
@@ -64,6 +66,7 @@ struct event_group {
 /* Link: https://github.com/intel/Intel-PMT xml/CWF/OOBMSM/RMID-ENERGY *.xml */
 static struct event_group energy_0x26696143 = {
 	.guid		= 0x26696143,
+	.mmio_size	= (576 * 2 + 3) * 8,
 	.num_events	= 2,
 	.evts				= {
 		EVT(PMT_EVENT_ENERGY, 0),
@@ -74,6 +77,7 @@ static struct event_group energy_0x26696143 = {
 /* Link: https://github.com/intel/Intel-PMT xml/CWF/OOBMSM/RMID-PERF *.xml */
 static struct event_group perf_0x26557651 = {
 	.guid		= 0x26557651,
+	.mmio_size	= (576 * 7 + 3) * 8,
 	.num_events	= 7,
 	.evts				= {
 		EVT(PMT_EVENT_STALLS_LLC_HIT, 0),
@@ -134,6 +138,10 @@ static bool configure_events(struct event_group *e, struct pmt_feature_group *p)
 			pr_warn_once("Bad package %d\n", tr->plat_info.package_id);
 			continue;
 		}
+		if (tr->size < e->mmio_size) {
+			pr_warn_once("MMIO space too small for guid 0x%x\n", e->guid);
+			continue;
+		}
 		pkgcounts[tr->plat_info.package_id]++;
 	}
 
@@ -151,7 +159,8 @@ static bool configure_events(struct event_group *e, struct pmt_feature_group *p)
 	/* Save MMIO address(es) for each aggregator in per-package structures */
 	for (int i = 0; i < p->count; i++) {
 		tr = &p->regions[i];
-		if (tr->guid != e->guid || tr->plat_info.package_id >= num_pkgs)
+		if (tr->guid != e->guid || tr->plat_info.package_id >= num_pkgs ||
+		    tr->size < e->mmio_size)
 			continue;
 		mmi = pkginfo[tr->plat_info.package_id];
 		mmi->addrs[--pkgcounts[tr->plat_info.package_id]] = tr->addr;
-- 
2.48.1
Re: [PATCH v4 20/31] x86/resctrl: Check for adequate MMIO space
Posted by Reinette Chatre 7 months, 2 weeks ago
Hi Tony,

On 4/28/25 5:33 PM, Tony Luck wrote:
> The MMIO space for each telemetry aggregator is arranged as a array of

"a array" -> "an array"

> count registers for each event for RMID 0, followed by RMID 1, and so on.

"count registers" -> "counter registers"?

"followed by RMID 1" -> "followed by each event for RMID 1"?

> After all event counters there are three status registers.  All registers
> are 8 bytes each.
> 
> The total size of MMIO space as described by the XML files is thus:
> 
> 	(NUM_RMIDS * NUM_COUNTERS + 3) * 8
> 
> Add an "mmio_size" field to the event_group structure and a sanity
> check that the size reported in the telemetry_region structure obtained
> from intel_pmt_get_regions_by_feature() is as large as expected.
> 
> Signed-off-by: Tony Luck <tony.luck@intel.com>
> ---
>  arch/x86/kernel/cpu/resctrl/intel_aet.c | 11 ++++++++++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/x86/kernel/cpu/resctrl/intel_aet.c b/arch/x86/kernel/cpu/resctrl/intel_aet.c
> index 7e4f6a6672d4..37dd493df250 100644
> --- a/arch/x86/kernel/cpu/resctrl/intel_aet.c
> +++ b/arch/x86/kernel/cpu/resctrl/intel_aet.c
> @@ -49,6 +49,7 @@ struct pmt_event {
>   *                      retrieved from intel_pmt_get_regions_by_feature().
>   * @pfg:		The pmt_feature_group for this event group
>   * @guid:		Unique number per XML description file
> + * @mmio_size:		Number of bytes of mmio registers for this group

mmio -> MMIO
Can append "(from XML file)".

>   * @pkginfo:		Per-package MMIO addresses
>   * @num_events:		Number of events in this group
>   * @evts:		Array of event descriptors
> @@ -56,6 +57,7 @@ struct pmt_event {
>  struct event_group {
>  	struct pmt_feature_group	*pfg;
>  	int				guid;
> +	int				mmio_size;

Should this be size_t?

>  	struct mmio_info		**pkginfo;
>  	int				num_events;
>  	struct pmt_event		evts[] __counted_by(num_events);
> @@ -64,6 +66,7 @@ struct event_group {
>  /* Link: https://github.com/intel/Intel-PMT xml/CWF/OOBMSM/RMID-ENERGY *.xml */
>  static struct event_group energy_0x26696143 = {
>  	.guid		= 0x26696143,
> +	.mmio_size	= (576 * 2 + 3) * 8,
>  	.num_events	= 2,
>  	.evts				= {
>  		EVT(PMT_EVENT_ENERGY, 0),
> @@ -74,6 +77,7 @@ static struct event_group energy_0x26696143 = {
>  /* Link: https://github.com/intel/Intel-PMT xml/CWF/OOBMSM/RMID-PERF *.xml */
>  static struct event_group perf_0x26557651 = {
>  	.guid		= 0x26557651,
> +	.mmio_size	= (576 * 7 + 3) * 8,
>  	.num_events	= 7,
>  	.evts				= {
>  		EVT(PMT_EVENT_STALLS_LLC_HIT, 0),
> @@ -134,6 +138,10 @@ static bool configure_events(struct event_group *e, struct pmt_feature_group *p)
>  			pr_warn_once("Bad package %d\n", tr->plat_info.package_id);
>  			continue;
>  		}
> +		if (tr->size < e->mmio_size) {
> +			pr_warn_once("MMIO space too small for guid 0x%x\n", e->guid);
> +			continue;
> +		}
>  		pkgcounts[tr->plat_info.package_id]++;
>  	}
>  
> @@ -151,7 +159,8 @@ static bool configure_events(struct event_group *e, struct pmt_feature_group *p)
>  	/* Save MMIO address(es) for each aggregator in per-package structures */
>  	for (int i = 0; i < p->count; i++) {
>  		tr = &p->regions[i];
> -		if (tr->guid != e->guid || tr->plat_info.package_id >= num_pkgs)
> +		if (tr->guid != e->guid || tr->plat_info.package_id >= num_pkgs ||
> +		    tr->size < e->mmio_size)
>  			continue;
>  		mmi = pkginfo[tr->plat_info.package_id];
>  		mmi->addrs[--pkgcounts[tr->plat_info.package_id]] = tr->addr;

Reinette