From nobody Tue Dec 16 13:25:12 2025 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8B43528B4F3 for ; Thu, 8 May 2025 17:20:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746724848; cv=none; b=UnCjZI8yceeCXQTqspnToe0OPeDDj8c/fLLCudF15QIsy1VnDUsbJyoQ8VwnZsH8Os/O5NIwBI6Kn7AVHLldydjDJC+eGixvxRbUgb6r37Cm/SvZnyTPtf3VVycfEU2CCKB53upGTT5gMYoRxlFDlgFd0j3ArwHo85dGe4DlgP0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746724848; c=relaxed/simple; bh=JwlJr1Hb3OVrajQizqxTLg607Ggjl6E+PK2SXxLRSIQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=tPer3Bdqa6O4ZDZ9pDSZP/m7w2EjevkgwjbcHhsj1mZ9WKeFFbyU+YSnNMocNXeif6Nqt1peI+ZOVJXgAaUENTJHNbllbdGmzydd0I+i90y74hfx7TjN12kLfHTyUoHoxT3xjU9NpD3ew4hfX1Y5QEb9eAjEe1xpibgrPA2J+7M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4CD0625E1; Thu, 8 May 2025 10:20:35 -0700 (PDT) Received: from merodach.members.linode.com (usa-sjc-mx-foss1.foss.arm.com [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 6E3063F58B; Thu, 8 May 2025 10:20:42 -0700 (PDT) From: James Morse To: x86@kernel.org, linux-kernel@vger.kernel.org Cc: Reinette Chatre , Thomas Gleixner , Ingo Molnar , Borislav Petkov , H Peter Anvin , Babu Moger , James Morse , shameerali.kolothum.thodi@huawei.com, D Scott Phillips OS , carl@os.amperecomputing.com, lcherian@marvell.com, bobo.shaobowang@huawei.com, tan.shaopeng@fujitsu.com, baolin.wang@linux.alibaba.com, Jamie Iles , Xin Hao , peternewman@google.com, dfustini@baylibre.com, amitsinght@marvell.com, David Hildenbrand , Rex Nie , Dave Martin , Koba Ko , Shanker Donthineni , fenghuay@nvidia.com, Babu Moger , Shaopeng Tan Subject: [PATCH v10 23/30] x86/resctrl: Always initialise rid field in rdt_resources_all[] Date: Thu, 8 May 2025 17:18:51 +0000 Message-Id: <20250508171858.9197-24-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20250508171858.9197-1-james.morse@arm.com> References: <20250508171858.9197-1-james.morse@arm.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" 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 Tested-by: Babu Moger Tested-by: Shaopeng Tan Reviewed-by: Reinette Chatre --- Changes since v8: * Clarified a comment. Changes since v7: * Split out of a previous patch due to a botched merged conflict. --- arch/x86/kernel/cpu/resctrl/core.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resct= rl/core.c index 58d7c6accdf2..224bed28f341 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -60,7 +60,6 @@ struct rdt_hw_resource rdt_resources_all[RDT_NUM_RESOURCE= S] =3D { [RDT_RESOURCE_L3] =3D { .r_resctrl =3D { - .rid =3D RDT_RESOURCE_L3, .name =3D "L3", .ctrl_scope =3D RESCTRL_L3_CACHE, .mon_scope =3D RESCTRL_L3_CACHE, @@ -74,7 +73,6 @@ struct rdt_hw_resource rdt_resources_all[RDT_NUM_RESOURCE= S] =3D { [RDT_RESOURCE_L2] =3D { .r_resctrl =3D { - .rid =3D RDT_RESOURCE_L2, .name =3D "L2", .ctrl_scope =3D RESCTRL_L2_CACHE, .ctrl_domains =3D ctrl_domain_init(RDT_RESOURCE_L2), @@ -86,7 +84,6 @@ struct rdt_hw_resource rdt_resources_all[RDT_NUM_RESOURCE= S] =3D { [RDT_RESOURCE_MBA] =3D { .r_resctrl =3D { - .rid =3D RDT_RESOURCE_MBA, .name =3D "MB", .ctrl_scope =3D RESCTRL_L3_CACHE, .ctrl_domains =3D ctrl_domain_init(RDT_RESOURCE_MBA), @@ -96,7 +93,6 @@ struct rdt_hw_resource rdt_resources_all[RDT_NUM_RESOURCE= S] =3D { [RDT_RESOURCE_SMBA] =3D { .r_resctrl =3D { - .rid =3D RDT_RESOURCE_SMBA, .name =3D "SMBA", .ctrl_scope =3D RESCTRL_L3_CACHE, .ctrl_domains =3D ctrl_domain_init(RDT_RESOURCE_SMBA), @@ -996,7 +992,11 @@ void resctrl_cpu_detect(struct cpuinfo_x86 *c) static int __init resctrl_arch_late_init(void) { struct rdt_resource *r; - int state, ret; + int state, ret, i; + + /* for_each_rdt_resource() requires all rid to be initialised. */ + for (i =3D 0; i < RDT_NUM_RESOURCES; i++) + rdt_resources_all[i].r_resctrl.rid =3D i; =20 /* * Initialize functions(or definitions) that are different --=20 2.39.5