x86/resctrl: Fix arch_mbm_* array overrun on SNC
Subsystems (2)
PATCH v2 1/1 x86/resctrl: Fix arch_mbm_* array overrun on SNC
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.
---v1->v2:
- Squashed blank lines added to linux/resctrl.h
- Reviewed-by Reinette
v1: https://lore.kernel.org/lkml/[email protected]/
arch/x86/include/asm/resctrl.h | 6 ------ arch/x86/kernel/cpu/resctrl/core.c | 8 ++++++++ include/linux/resctrl.h | 1 + 3 files changed, 9 insertions(+), 6 deletions(-)
arch/x86/include/asm/resctrl.h +0 -6
@@ -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;
arch/x86/kernel/cpu/resctrl/core.c +8 -0
@@ -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.
include/linux/resctrl.h +1 -0
@@ -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);/*
base-commit: 47ac09b91befbb6a235ab620c32af719f8208399
Signature · 1 line
2.46.0.295.g3b9ea8a38a-goog
Reinette Chatre
maintainerThank you very much Peter.
Boris, could you please consider this for inclusion?
Thank you
Reinette
Quoted 78 lines · Peter Newman
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_rmidvalue or the unadjusted value inresctrl_arch_system_num_rmid_idx()is used. Thenum_rmidvalue for the L3 resource is currently:
resctrl_arch_system_num_rmid_idx()/snc_nodes_per_l3_cacheAs a simple fix, make
resctrl_arch_system_num_rmid_idx()return the SNC-adjusted, L3num_rmidvalue on x86.Fixes e13db55b5a0d ("x86/resctrl: Introduce snc_nodes_per_l3_cache")Signed-off-by Peter Newman <[email protected]>Reviewed-by Reinette Chatre <[email protected]>---
v1->v2:
- Squashed blank lines added tolinux/resctrl.h
- Reviewed-by Reinettev1: https://lore.kernel.org/lkml/[email protected]/
arch/x86/include/asm/resctrl.h | 6 ------ arch/x86/kernel/cpu/resctrl/core.c | 8 ++++++++ include/linux/resctrl.h | 1 + 3 files changed, 9 insertions(+), 6 deletions(-)arch/x86/include/asm/resctrl.h +0
-6@@ -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;arch/x86/kernel/cpu/resctrl/core.c +8
-0@@ -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. include/linux/resctrl.h +1
-0@@ -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);/* base-commit:
47ac09b91befbb6a235ab620c32af719f8208399
The following commit has been merged into the x86/urgent branch of tip:
The following commit has been merged into the x86/urgent branch of tip:
Commit-ID: a547a5880cba6f287179135381f1b484b251be31 Gitweb: https://git.kernel.org/tip/a547a5880cba6f287179135381f1b484b251be31 Author: Peter Newman <[email protected]> AuthorDate: Thu, 22 Aug 2024 12:02:11 -07:00 Committer: Borislav Petkov (AMD) <[email protected]> CommitterDate: Wed, 28 Aug 2024 11:13:08 +02:00
x86/resctrl: Fix arch_mbm_* array overrun on SNC
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.
--- arch/x86/include/asm/resctrl.h | 6 ------ arch/x86/kernel/cpu/resctrl/core.c | 8 ++++++++ include/linux/resctrl.h | 1 + 3 files changed, 9 insertions(+), 6 deletions(-)
arch/x86/include/asm/resctrl.h +0 -6
@@ -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;
arch/x86/kernel/cpu/resctrl/core.c +8 -0
@@ -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.
include/linux/resctrl.h +1 -0
@@ -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);/*