From mboxrd@z Thu Jan 1 00:00:00 1970 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 11BB913AA27 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=1745886854; cv=none; b=huZdx8LNNloPks3suqkH8UjdS7ArIdpVgvtuf4bm0qq0qIVXO+fTKwoJYaFvVQrx85j+d1pYmc0a5cz059dpDyhlFBcgm4v0tz4WeAbJ5sI8qZ03HmnXTluyQQiDcU/kHgI7wuhE7j2YktfkvIvTqAz5r3o3G0H336/tnkOk4gA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886854; c=relaxed/simple; bh=XdBbnNk26unl/dT0dgAYz9UaGNxAlb+T4myEQeuJLsY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=unAU5OU9rQJByjHUwrlkaicRq8ZPrAtMo0NOkQ8zJn5fxfLOwJVwQjR+KjRnPuSAzh3lHL4xIV7TpBN0fmCnJS0YbvE7Q8yTEiS8A9OMNWxK81CnJfEy4+Cc0N4//ezDHi4TLGixdEfChXkqfwD6qEL5zxbUok6ua28Ms1apkNA= 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: G0KoBPhgTSq/gNxdUYsHXg== X-CSE-MsgGUID: J9oCHOzxRn6yc0zM/RmgHw== X-IronPort-AV: E=McAfee;i="6700,10204,11417"; a="58148096" X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="58148096" 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: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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; }; +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 != type || hdr->rid != rid); +} + /** * struct rdt_ctrl_domain - group of CPUs sharing a resctrl control resource * @hdr: common header for different domain types diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resctrl/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_resource *r) hdr = resctrl_find_domain(&r->ctrl_domains, id, &add_pos); if (hdr) { - if (WARN_ON_ONCE(hdr->type != RESCTRL_CTRL_DOMAIN)) + if (check_domain_header(hdr, RESCTRL_CTRL_DOMAIN, r->rid)) return; d = container_of(hdr, struct rdt_ctrl_domain, hdr); @@ -473,6 +473,7 @@ static void domain_add_cpu_ctrl(int cpu, struct rdt_resource *r) d = &hw_dom->d_resctrl; d->hdr.id = id; d->hdr.type = RESCTRL_CTRL_DOMAIN; + d->hdr.rid = r->rid; cpumask_set_cpu(cpu, &d->hdr.cpu_mask); rdt_domain_reconfigure_cdp(r); @@ -511,7 +512,7 @@ static void domain_add_cpu_mon(int cpu, struct rdt_resource *r) hdr = resctrl_find_domain(&r->mon_domains, id, &add_pos); if (hdr) { - if (WARN_ON_ONCE(hdr->type != RESCTRL_MON_DOMAIN)) + if (check_domain_header(hdr, RESCTRL_MON_DOMAIN, r->rid)) return; d = container_of(hdr, struct rdt_mon_domain, hdr); @@ -526,6 +527,7 @@ static void domain_add_cpu_mon(int cpu, struct rdt_resource *r) d = &hw_dom->d_resctrl; d->hdr.id = id; d->hdr.type = RESCTRL_MON_DOMAIN; + d->hdr.rid = r->rid; d->ci = 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->name); @@ -581,7 +583,7 @@ static void domain_remove_cpu_ctrl(int cpu, struct rdt_resource *r) return; } - if (WARN_ON_ONCE(hdr->type != RESCTRL_CTRL_DOMAIN)) + if (check_domain_header(hdr, RESCTRL_CTRL_DOMAIN, r->rid)) return; d = container_of(hdr, struct rdt_ctrl_domain, hdr); @@ -627,7 +629,7 @@ static void domain_remove_cpu_mon(int cpu, struct rdt_resource *r) return; } - if (WARN_ON_ONCE(hdr->type != RESCTRL_MON_DOMAIN)) + if (check_domain_header(hdr, RESCTRL_MON_DOMAIN, r->rid)) return; d = 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 = resctrl_find_domain(&r->mon_domains, domid, NULL); - if (!hdr || WARN_ON_ONCE(hdr->type != RESCTRL_MON_DOMAIN)) { + if (!hdr || check_domain_header(hdr, RESCTRL_MON_DOMAIN, r->rid)) { ret = -ENOENT; goto out; } -- 2.48.1