From nobody Sun Feb 8 20:36:47 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 90FAC13D893 for ; Tue, 29 Apr 2025 00:34:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886856; cv=none; b=u/Q6K7FawMRyTxHtuztJ79FmMRoY2t6CCaXQtnXhVbdwZPNIqGAZqgZV+a7r2Z8D0xO0xe+rhpxDDWvvfaLIBkoqZIAgcKQ0cAeL0mafXcHYcj2lINCaFWrstbvQSVki1HwZck5/siWqb71dZ1l+LZdGZyoI6KCMqqPkkCyz614= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886856; c=relaxed/simple; bh=XdBbnNk26unl/dT0dgAYz9UaGNxAlb+T4myEQeuJLsY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dvOL9UgiBR2WLHfnXMZlVAwC16C6jskopjDEm/4USOWA85QvXHKzP4XrRPeSPVyrIe072OrwM67g0TvpEchjuYpibFzO9JbrIgXhse87vB9PFPtqDCMqdQKWqXEIgP4ThQmcGXxcKgq76tBo+y8wRJ6gKcPKnbxIrwuM7KMrOV4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=UkctVA4K; arc=none smtp.client-ip=192.198.163.9 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="UkctVA4K" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1745886853; x=1777422853; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XdBbnNk26unl/dT0dgAYz9UaGNxAlb+T4myEQeuJLsY=; b=UkctVA4KZXh6J1eqSjaAZij6E2StQovvy+nbOcWw/ncUVNw1QwrYB7s4 qADfNkeE2xKIKiBHOYcuLgAyTOoJMnpAbiJYj2D8Yw+beGxuFnBei3OqK fanZMvM0rf4cV1BZ3THZGRhzZUXeQHVZxiA4HeBR3JXkyprfwmpEQ+xvP WNzS9sWx6WaVqIkwL6vZ1HoGMBNCVCoQMHdxGEWJfNw78jUdAK+aEUmdq mL/SMjqCWfGY9rHkgwmnQCzdSSNrH0AdzO11Nzk6nUTV065PMzQkMNQ7N c3M/wa8iJ+1ijTBQG3oeS/0JpQZkdLbBsEkj4do7j0852qhiLyJVTSTQd w==; X-CSE-ConnectionGUID: x/21Of/mQHqjgTstiJ/l5w== X-CSE-MsgGUID: 3cP1f/jESmGooqDIA/5Q2A== X-IronPort-AV: E=McAfee;i="6700,10204,11417"; a="58148095" X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="58148095" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:11 -0700 X-CSE-ConnectionGUID: wkO7nFdURt+1Nnqy5BIYiA== X-CSE-MsgGUID: s2fjPK8dTpG++tQRy+COIw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="133393976" Received: from agluck-desk3.sc.intel.com ([172.25.222.70]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:10 -0700 From: Tony Luck To: Fenghua Yu , Reinette Chatre , Maciej Wieczor-Retman , Peter Newman , James Morse , Babu Moger , Drew Fustini , Dave Martin , Anil Keshavamurthy , Chen Yu Cc: x86@kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev, Tony Luck Subject: [PATCH v4 07/31] x86,fs/resctrl: Improve domain type checking Date: Mon, 28 Apr 2025 17:33:33 -0700 Message-ID: <20250429003359.375508-8-tony.luck@intel.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250429003359.375508-1-tony.luck@intel.com> References: <20250429003359.375508-1-tony.luck@intel.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" The rdt_domain_hdr structure is used in both control and monitor domain structures to provide common methods for operations such as adding a CPU to a domain, removing a CPU from a domain, accessing the mask of all CPUs in a domain. The "type" field provides a simple check whether a domain is a control or monitor domain so that programming errors operating on domains will be quickly caught. To prepare for additional domain types that depend on the rdt_resource to which they are connected add the resource id into the header and check that in addition to the type. Signed-off-by: Tony Luck --- include/linux/resctrl.h | 9 +++++++++ arch/x86/kernel/cpu/resctrl/core.c | 10 ++++++---- fs/resctrl/ctrlmondata.c | 2 +- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index cef9b0ed984c..e700f58b5af5 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -131,15 +131,24 @@ enum resctrl_domain_type { * @list: all instances of this resource * @id: unique id for this instance * @type: type of this instance + * @rid: index of resource for this domain * @cpu_mask: which CPUs share this resource */ struct rdt_domain_hdr { struct list_head list; int id; enum resctrl_domain_type type; + enum resctrl_res_level rid; struct cpumask cpu_mask; }; =20 +static inline bool check_domain_header(struct rdt_domain_hdr *hdr, + enum resctrl_domain_type type, + enum resctrl_res_level rid) +{ + return !!WARN_ON_ONCE(hdr->type !=3D type || hdr->rid !=3D rid); +} + /** * struct rdt_ctrl_domain - group of CPUs sharing a resctrl control resour= ce * @hdr: common header for different domain types diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resct= rl/core.c index e5c91d21e8f7..bdd4d08a3912 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -456,7 +456,7 @@ static void domain_add_cpu_ctrl(int cpu, struct rdt_res= ource *r) =20 hdr =3D resctrl_find_domain(&r->ctrl_domains, id, &add_pos); if (hdr) { - if (WARN_ON_ONCE(hdr->type !=3D RESCTRL_CTRL_DOMAIN)) + if (check_domain_header(hdr, RESCTRL_CTRL_DOMAIN, r->rid)) return; d =3D container_of(hdr, struct rdt_ctrl_domain, hdr); =20 @@ -473,6 +473,7 @@ static void domain_add_cpu_ctrl(int cpu, struct rdt_res= ource *r) d =3D &hw_dom->d_resctrl; d->hdr.id =3D id; d->hdr.type =3D RESCTRL_CTRL_DOMAIN; + d->hdr.rid =3D r->rid; cpumask_set_cpu(cpu, &d->hdr.cpu_mask); =20 rdt_domain_reconfigure_cdp(r); @@ -511,7 +512,7 @@ static void domain_add_cpu_mon(int cpu, struct rdt_reso= urce *r) =20 hdr =3D resctrl_find_domain(&r->mon_domains, id, &add_pos); if (hdr) { - if (WARN_ON_ONCE(hdr->type !=3D RESCTRL_MON_DOMAIN)) + if (check_domain_header(hdr, RESCTRL_MON_DOMAIN, r->rid)) return; d =3D container_of(hdr, struct rdt_mon_domain, hdr); =20 @@ -526,6 +527,7 @@ static void domain_add_cpu_mon(int cpu, struct rdt_reso= urce *r) d =3D &hw_dom->d_resctrl; d->hdr.id =3D id; d->hdr.type =3D RESCTRL_MON_DOMAIN; + d->hdr.rid =3D r->rid; d->ci =3D get_cpu_cacheinfo_level(cpu, RESCTRL_L3_CACHE); if (!d->ci) { pr_warn_once("Can't find L3 cache for CPU:%d resource %s\n", cpu, r->nam= e); @@ -581,7 +583,7 @@ static void domain_remove_cpu_ctrl(int cpu, struct rdt_= resource *r) return; } =20 - if (WARN_ON_ONCE(hdr->type !=3D RESCTRL_CTRL_DOMAIN)) + if (check_domain_header(hdr, RESCTRL_CTRL_DOMAIN, r->rid)) return; =20 d =3D container_of(hdr, struct rdt_ctrl_domain, hdr); @@ -627,7 +629,7 @@ static void domain_remove_cpu_mon(int cpu, struct rdt_r= esource *r) return; } =20 - if (WARN_ON_ONCE(hdr->type !=3D RESCTRL_MON_DOMAIN)) + if (check_domain_header(hdr, RESCTRL_MON_DOMAIN, r->rid)) return; =20 d =3D container_of(hdr, struct rdt_mon_domain, hdr); diff --git a/fs/resctrl/ctrlmondata.c b/fs/resctrl/ctrlmondata.c index 53388281ff7d..3cbacfe52430 100644 --- a/fs/resctrl/ctrlmondata.c +++ b/fs/resctrl/ctrlmondata.c @@ -616,7 +616,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg) * the resource to find the domain with "domid". */ hdr =3D resctrl_find_domain(&r->mon_domains, domid, NULL); - if (!hdr || WARN_ON_ONCE(hdr->type !=3D RESCTRL_MON_DOMAIN)) { + if (!hdr || check_domain_header(hdr, RESCTRL_MON_DOMAIN, r->rid)) { ret =3D -ENOENT; goto out; } --=20 2.48.1