]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
x86/resctrl: Refactor resctrl_arch_rmid_read()
authorBabu Moger <babu.moger@amd.com>
Mon, 20 Oct 2025 16:38:52 +0000 (12:38 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 23 Oct 2025 14:20:43 +0000 (16:20 +0200)
[ Upstream commit 7c9ac605e202c4668e441fc8146a993577131ca1 ]

resctrl_arch_rmid_read() adjusts the value obtained from MSR_IA32_QM_CTR to
account for the overflow for MBM events and apply counter scaling for all the
events. This logic is common to both reading an RMID and reading a hardware
counter directly.

Refactor the hardware value adjustment logic into get_corrected_val() to
prepare for support of reading a hardware counter.

Signed-off-by: Babu Moger <babu.moger@amd.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Link: https://lore.kernel.org/cover.1757108044.git.babu.moger@amd.com
Stable-dep-of: 15292f1b4c55 ("x86/resctrl: Fix miscount of bandwidth event when reactivating previously unavailable RMID")
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
arch/x86/kernel/cpu/resctrl/monitor.c

index 851b561850e0c2311683c860c20943e46e70c544..b8d0748c4f2dbe2e607379d7fc8d5f26c2fda243 100644 (file)
@@ -312,24 +312,13 @@ static u64 mbm_overflow_count(u64 prev_msr, u64 cur_msr, unsigned int width)
        return chunks >> shift;
 }
 
-int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_mon_domain *d,
-                          u32 unused, u32 rmid, enum resctrl_event_id eventid,
-                          u64 *val, void *ignored)
+static u64 get_corrected_val(struct rdt_resource *r, struct rdt_mon_domain *d,
+                            u32 rmid, enum resctrl_event_id eventid, u64 msr_val)
 {
        struct rdt_hw_mon_domain *hw_dom = resctrl_to_arch_mon_dom(d);
        struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r);
-       int cpu = cpumask_any(&d->hdr.cpu_mask);
        struct arch_mbm_state *am;
-       u64 msr_val, chunks;
-       u32 prmid;
-       int ret;
-
-       resctrl_arch_rmid_read_context_check();
-
-       prmid = logical_rmid_to_physical_rmid(cpu, rmid);
-       ret = __rmid_read_phys(prmid, eventid, &msr_val);
-       if (ret)
-               return ret;
+       u64 chunks;
 
        am = get_arch_mbm_state(hw_dom, rmid, eventid);
        if (am) {
@@ -341,7 +330,26 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_mon_domain *d,
                chunks = msr_val;
        }
 
-       *val = chunks * hw_res->mon_scale;
+       return chunks * hw_res->mon_scale;
+}
+
+int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_mon_domain *d,
+                          u32 unused, u32 rmid, enum resctrl_event_id eventid,
+                          u64 *val, void *ignored)
+{
+       int cpu = cpumask_any(&d->hdr.cpu_mask);
+       u64 msr_val;
+       u32 prmid;
+       int ret;
+
+       resctrl_arch_rmid_read_context_check();
+
+       prmid = logical_rmid_to_physical_rmid(cpu, rmid);
+       ret = __rmid_read_phys(prmid, eventid, &msr_val);
+       if (ret)
+               return ret;
+
+       *val = get_corrected_val(r, d, rmid, eventid, msr_val);
 
        return 0;
 }