mirror of
https://github.com/torvalds/linux.git
synced 2026-06-03 20:14:06 +02:00
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
This commit is contained in:
parent
f8f9c1f4d0
commit
03eb578b37
|
|
@ -464,7 +464,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 (!domain_header_is_valid(hdr, RESCTRL_CTRL_DOMAIN, r->rid))
|
||||
return;
|
||||
d = container_of(hdr, struct rdt_ctrl_domain, hdr);
|
||||
|
||||
|
|
@ -481,6 +481,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);
|
||||
|
|
@ -520,7 +521,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 (!domain_header_is_valid(hdr, RESCTRL_MON_DOMAIN, r->rid))
|
||||
return;
|
||||
d = container_of(hdr, struct rdt_mon_domain, hdr);
|
||||
|
||||
|
|
@ -538,6 +539,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;
|
||||
ci = get_cpu_cacheinfo_level(cpu, RESCTRL_L3_CACHE);
|
||||
if (!ci) {
|
||||
pr_warn_once("Can't find L3 cache for CPU:%d resource %s\n", cpu, r->name);
|
||||
|
|
@ -598,7 +600,7 @@ static void domain_remove_cpu_ctrl(int cpu, struct rdt_resource *r)
|
|||
return;
|
||||
}
|
||||
|
||||
if (WARN_ON_ONCE(hdr->type != RESCTRL_CTRL_DOMAIN))
|
||||
if (!domain_header_is_valid(hdr, RESCTRL_CTRL_DOMAIN, r->rid))
|
||||
return;
|
||||
|
||||
d = container_of(hdr, struct rdt_ctrl_domain, hdr);
|
||||
|
|
@ -644,7 +646,7 @@ static void domain_remove_cpu_mon(int cpu, struct rdt_resource *r)
|
|||
return;
|
||||
}
|
||||
|
||||
if (WARN_ON_ONCE(hdr->type != RESCTRL_MON_DOMAIN))
|
||||
if (!domain_header_is_valid(hdr, RESCTRL_MON_DOMAIN, r->rid))
|
||||
return;
|
||||
|
||||
d = container_of(hdr, struct rdt_mon_domain, hdr);
|
||||
|
|
|
|||
|
|
@ -653,7 +653,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 || !domain_header_is_valid(hdr, RESCTRL_MON_DOMAIN, resid)) {
|
||||
ret = -ENOENT;
|
||||
goto out;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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: resource id for this instance
|
||||
* @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 domain_header_is_valid(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
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user