[PATCH v19 17/20] x86/resctrl: Update CPU sanity checks when reading RMID counters
From: Tony Luck
Date: Tue May 28 2024 - 18:22:56 EST
When reading from a single domain the existing check that current CPU is
in the domain is accurate.
But when summing across multiple domains that share an L3 cache instance
it is sufficient to run on any CPU in the shared_map for that cache.
Split the check into the two separate cases.
Signed-off-by: Tony Luck <tony.luck@xxxxxxxxx>
---
arch/x86/kernel/cpu/resctrl/monitor.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/resctrl/monitor.c
index c9dd6ec68fcd..e7a8e96821e5 100644
--- a/arch/x86/kernel/cpu/resctrl/monitor.c
+++ b/arch/x86/kernel/cpu/resctrl/monitor.c
@@ -308,9 +308,6 @@ static int resctrl_arch_rmid_read_one(struct rdt_resource *r, struct rdt_mon_dom
resctrl_arch_rmid_read_context_check();
- if (!cpumask_test_cpu(smp_processor_id(), &d->hdr.cpu_mask))
- return -EINVAL;
-
ret = __rmid_read(cpu, rmid, eventid, &msr_val);
if (ret)
return ret;
@@ -338,8 +335,15 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_mon_domain *d,
int ret;
*val = 0;
- if (!sum)
+ if (!sum) {
+ if (!cpumask_test_cpu(cpu, &d->hdr.cpu_mask))
+ return -EINVAL;
+
return resctrl_arch_rmid_read_one(r, d, cpu, rmid, eventid, val);
+ }
+
+ if (!cpumask_test_cpu(cpu, &ci->shared_cpu_map))
+ return -EINVAL;
list_for_each_entry(d, &r->mon_domains, hdr.list) {
if (d->ci->id != ci->id)
--
2.45.0