]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
x86/resctrl: Fix arch_mbm_* array overrun on SNC
authorPeter Newman <peternewman@google.com>
Thu, 22 Aug 2024 19:02:11 +0000 (12:02 -0700)
committerBorislav Petkov (AMD) <bp@alien8.de>
Wed, 28 Aug 2024 09:13:08 +0000 (11:13 +0200)
When using resctrl on systems with Sub-NUMA Clustering enabled, monitoring
groups may be allocated RMID values which would overrun the
arch_mbm_{local,total} arrays.

This is due to inconsistencies in whether the SNC-adjusted num_rmid value or
the unadjusted value in resctrl_arch_system_num_rmid_idx() is used. The
num_rmid value for the L3 resource is currently:

  resctrl_arch_system_num_rmid_idx() / snc_nodes_per_l3_cache

As a simple fix, make resctrl_arch_system_num_rmid_idx() return the
SNC-adjusted, L3 num_rmid value on x86.

Fixes: e13db55b5a0d ("x86/resctrl: Introduce snc_nodes_per_l3_cache")
Signed-off-by: Peter Newman <peternewman@google.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Link: https://lore.kernel.org/r/20240822190212.1848788-1-peternewman@google.com
arch/x86/include/asm/resctrl.h
arch/x86/kernel/cpu/resctrl/core.c
include/linux/resctrl.h

index 12dbd2588ca7ccdaa1ea641327b5cbf866f50a68..8b1b6ce1e51b211ba2ce9f786bfa0922bdc6e38b 100644 (file)
@@ -156,12 +156,6 @@ static inline void resctrl_sched_in(struct task_struct *tsk)
                __resctrl_sched_in(tsk);
 }
 
-static inline u32 resctrl_arch_system_num_rmid_idx(void)
-{
-       /* RMID are independent numbers for x86. num_rmid_idx == num_rmid */
-       return boot_cpu_data.x86_cache_max_rmid + 1;
-}
-
 static inline void resctrl_arch_rmid_idx_decode(u32 idx, u32 *closid, u32 *rmid)
 {
        *rmid = idx;
index 1930fce9dfe96d5c323cb9000fb06149916a5a3c..8591d53c144bb17bd7f33077da05a9330e7c5e5e 100644 (file)
@@ -119,6 +119,14 @@ struct rdt_hw_resource rdt_resources_all[] = {
        },
 };
 
+u32 resctrl_arch_system_num_rmid_idx(void)
+{
+       struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;
+
+       /* RMID are independent numbers for x86. num_rmid_idx == num_rmid */
+       return r->num_rmid;
+}
+
 /*
  * cache_alloc_hsw_probe() - Have to probe for Intel haswell server CPUs
  * as they do not have CPUID enumeration support for Cache allocation.
index b0875b99e8111e2d98e5664cceb1decf46f380a4..d94abba1c716e93b709d22a81d9e30242a0c0675 100644 (file)
@@ -248,6 +248,7 @@ struct resctrl_schema {
 
 /* The number of closid supported by this resource regardless of CDP */
 u32 resctrl_arch_get_num_closid(struct rdt_resource *r);
+u32 resctrl_arch_system_num_rmid_idx(void);
 int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid);
 
 /*