Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

x86,fs/resctrl: Improve domain type checking

Every resctrl resource has a list of domain structures. struct rdt_ctrl_domain
and struct rdt_mon_domain both begin with struct rdt_domain_hdr with
rdt_domain_hdr::type used in validity checks before accessing the domain of
a particular type.

Add the resource id to struct rdt_domain_hdr in preparation for a new monitoring
domain structure that will be associated with a new monitoring resource. Improve
existing domain validity checks with a new helper domain_header_is_valid()
that checks both domain type and resource id. domain_header_is_valid() should
be used before every call to container_of() that accesses a domain structure.

Signed-off-by: Tony Luck <tony.luck@intel.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Link: https://lore.kernel.org/20251217172121.12030-1-tony.luck@intel.com

authored by

Tony Luck and committed by
Borislav Petkov (AMD)
03eb578b f8f9c1f4

+16 -5
+6 -4
arch/x86/kernel/cpu/resctrl/core.c
··· 464 464 465 465 hdr = resctrl_find_domain(&r->ctrl_domains, id, &add_pos); 466 466 if (hdr) { 467 - if (WARN_ON_ONCE(hdr->type != RESCTRL_CTRL_DOMAIN)) 467 + if (!domain_header_is_valid(hdr, RESCTRL_CTRL_DOMAIN, r->rid)) 468 468 return; 469 469 d = container_of(hdr, struct rdt_ctrl_domain, hdr); 470 470 ··· 481 481 d = &hw_dom->d_resctrl; 482 482 d->hdr.id = id; 483 483 d->hdr.type = RESCTRL_CTRL_DOMAIN; 484 + d->hdr.rid = r->rid; 484 485 cpumask_set_cpu(cpu, &d->hdr.cpu_mask); 485 486 486 487 rdt_domain_reconfigure_cdp(r); ··· 521 520 522 521 hdr = resctrl_find_domain(&r->mon_domains, id, &add_pos); 523 522 if (hdr) { 524 - if (WARN_ON_ONCE(hdr->type != RESCTRL_MON_DOMAIN)) 523 + if (!domain_header_is_valid(hdr, RESCTRL_MON_DOMAIN, r->rid)) 525 524 return; 526 525 d = container_of(hdr, struct rdt_mon_domain, hdr); 527 526 ··· 539 538 d = &hw_dom->d_resctrl; 540 539 d->hdr.id = id; 541 540 d->hdr.type = RESCTRL_MON_DOMAIN; 541 + d->hdr.rid = r->rid; 542 542 ci = get_cpu_cacheinfo_level(cpu, RESCTRL_L3_CACHE); 543 543 if (!ci) { 544 544 pr_warn_once("Can't find L3 cache for CPU:%d resource %s\n", cpu, r->name); ··· 600 598 return; 601 599 } 602 600 603 - if (WARN_ON_ONCE(hdr->type != RESCTRL_CTRL_DOMAIN)) 601 + if (!domain_header_is_valid(hdr, RESCTRL_CTRL_DOMAIN, r->rid)) 604 602 return; 605 603 606 604 d = container_of(hdr, struct rdt_ctrl_domain, hdr); ··· 646 644 return; 647 645 } 648 646 649 - if (WARN_ON_ONCE(hdr->type != RESCTRL_MON_DOMAIN)) 647 + if (!domain_header_is_valid(hdr, RESCTRL_MON_DOMAIN, r->rid)) 650 648 return; 651 649 652 650 d = container_of(hdr, struct rdt_mon_domain, hdr);
+1 -1
fs/resctrl/ctrlmondata.c
··· 653 653 * the resource to find the domain with "domid". 654 654 */ 655 655 hdr = resctrl_find_domain(&r->mon_domains, domid, NULL); 656 - if (!hdr || WARN_ON_ONCE(hdr->type != RESCTRL_MON_DOMAIN)) { 656 + if (!hdr || !domain_header_is_valid(hdr, RESCTRL_MON_DOMAIN, resid)) { 657 657 ret = -ENOENT; 658 658 goto out; 659 659 }
+9
include/linux/resctrl.h
··· 131 131 * @list: all instances of this resource 132 132 * @id: unique id for this instance 133 133 * @type: type of this instance 134 + * @rid: resource id for this instance 134 135 * @cpu_mask: which CPUs share this resource 135 136 */ 136 137 struct rdt_domain_hdr { 137 138 struct list_head list; 138 139 int id; 139 140 enum resctrl_domain_type type; 141 + enum resctrl_res_level rid; 140 142 struct cpumask cpu_mask; 141 143 }; 144 + 145 + static inline bool domain_header_is_valid(struct rdt_domain_hdr *hdr, 146 + enum resctrl_domain_type type, 147 + enum resctrl_res_level rid) 148 + { 149 + return !WARN_ON_ONCE(hdr->type != type || hdr->rid != rid); 150 + } 142 151 143 152 /** 144 153 * struct rdt_ctrl_domain - group of CPUs sharing a resctrl control resource