Skip to content

Commit f6b25be

Browse files
James Morsebp3tk0v
authored andcommitted
x86/resctrl: Always initialise rid field in rdt_resources_all[]
x86 has an array, rdt_resources_all[], of all possible resources. The for-each-resource walkers depend on the rid field of all resources being initialised. If the array ever grows due to another architecture adding a resource type that is not defined on x86, the for-each-resources walkers will loop forever. Initialise all the rid values in resctrl_arch_late_init() before any for-each-resource walker can be called. Signed-off-by: James Morse <james.morse@arm.com> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Reviewed-by: Reinette Chatre <reinette.chatre@intel.com> Reviewed-by: Fenghua Yu <fenghuay@nvidia.com> Tested-by: Fenghua Yu <fenghuay@nvidia.com> Tested-by: Babu Moger <babu.moger@amd.com> Tested-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com> Tested-by: Tony Luck <tony.luck@intel.com> Link: https://lore.kernel.org/20250515165855.31452-24-james.morse@arm.com
1 parent b7b57ed commit f6b25be

File tree

1 file changed

+5
-5
lines changed
  • arch/x86/kernel/cpu/resctrl

1 file changed

+5
-5
lines changed

arch/x86/kernel/cpu/resctrl/core.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ struct rdt_hw_resource rdt_resources_all[RDT_NUM_RESOURCES] = {
6060
[RDT_RESOURCE_L3] =
6161
{
6262
.r_resctrl = {
63-
.rid = RDT_RESOURCE_L3,
6463
.name = "L3",
6564
.ctrl_scope = RESCTRL_L3_CACHE,
6665
.mon_scope = RESCTRL_L3_CACHE,
@@ -74,7 +73,6 @@ struct rdt_hw_resource rdt_resources_all[RDT_NUM_RESOURCES] = {
7473
[RDT_RESOURCE_L2] =
7574
{
7675
.r_resctrl = {
77-
.rid = RDT_RESOURCE_L2,
7876
.name = "L2",
7977
.ctrl_scope = RESCTRL_L2_CACHE,
8078
.ctrl_domains = ctrl_domain_init(RDT_RESOURCE_L2),
@@ -86,7 +84,6 @@ struct rdt_hw_resource rdt_resources_all[RDT_NUM_RESOURCES] = {
8684
[RDT_RESOURCE_MBA] =
8785
{
8886
.r_resctrl = {
89-
.rid = RDT_RESOURCE_MBA,
9087
.name = "MB",
9188
.ctrl_scope = RESCTRL_L3_CACHE,
9289
.ctrl_domains = ctrl_domain_init(RDT_RESOURCE_MBA),
@@ -96,7 +93,6 @@ struct rdt_hw_resource rdt_resources_all[RDT_NUM_RESOURCES] = {
9693
[RDT_RESOURCE_SMBA] =
9794
{
9895
.r_resctrl = {
99-
.rid = RDT_RESOURCE_SMBA,
10096
.name = "SMBA",
10197
.ctrl_scope = RESCTRL_L3_CACHE,
10298
.ctrl_domains = ctrl_domain_init(RDT_RESOURCE_SMBA),
@@ -996,7 +992,11 @@ void resctrl_cpu_detect(struct cpuinfo_x86 *c)
996992
static int __init resctrl_arch_late_init(void)
997993
{
998994
struct rdt_resource *r;
999-
int state, ret;
995+
int state, ret, i;
996+
997+
/* for_each_rdt_resource() requires all rid to be initialised. */
998+
for (i = 0; i < RDT_NUM_RESOURCES; i++)
999+
rdt_resources_all[i].r_resctrl.rid = i;
10001000

10011001
/*
10021002
* Initialize functions(or definitions) that are different

0 commit comments

Comments
 (0)