]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
x86/resctrl: Configure mbm_event mode if supported
authorBabu Moger <babu.moger@amd.com>
Fri, 5 Sep 2025 21:34:31 +0000 (16:34 -0500)
committerBorislav Petkov (AMD) <bp@alien8.de>
Mon, 15 Sep 2025 10:52:04 +0000 (12:52 +0200)
Configure mbm_event mode on AMD platforms. On AMD platforms, it is
recommended to use the mbm_event mode, if supported, to prevent the
hardware from resetting counters between reads. This can result in
misleading values or display "Unavailable" if no counter is assigned
to the event.

Enable mbm_event mode, known as ABMC (Assignable Bandwidth Monitoring
Counters) on AMD, by default if the system supports it.

Update ABMC across all logical processors within the resctrl domain to
ensure proper functionality.

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
arch/x86/kernel/cpu/resctrl/core.c
arch/x86/kernel/cpu/resctrl/internal.h
arch/x86/kernel/cpu/resctrl/monitor.c

index 2e68aa02ad3f4c5000cf139872c1e348b103be26..06ca5a30140c2f6d2c8d0b7324df9c0c6ecab13b 100644 (file)
@@ -520,6 +520,9 @@ static void domain_add_cpu_mon(int cpu, struct rdt_resource *r)
                d = container_of(hdr, struct rdt_mon_domain, hdr);
 
                cpumask_set_cpu(cpu, &d->hdr.cpu_mask);
+               /* Update the mbm_assign_mode state for the CPU if supported */
+               if (r->mon.mbm_cntr_assignable)
+                       resctrl_arch_mbm_cntr_assign_set_one(r);
                return;
        }
 
@@ -539,6 +542,10 @@ static void domain_add_cpu_mon(int cpu, struct rdt_resource *r)
        d->ci_id = ci->id;
        cpumask_set_cpu(cpu, &d->hdr.cpu_mask);
 
+       /* Update the mbm_assign_mode state for the CPU if supported */
+       if (r->mon.mbm_cntr_assignable)
+               resctrl_arch_mbm_cntr_assign_set_one(r);
+
        arch_mon_domain_online(r, d);
 
        if (arch_domain_mbm_alloc(r->mon.num_rmid, hw_dom)) {
index e5edddb290c9d36a2ea014ae7ad95359f8b82a8f..9f4c2f0aaf5c805bfa37e1eb6449925d49925292 100644 (file)
@@ -215,5 +215,6 @@ bool rdt_cpu_has(int flag);
 void __init intel_rdt_mbm_apply_quirk(void);
 
 void rdt_domain_reconfigure_cdp(struct rdt_resource *r);
+void resctrl_arch_mbm_cntr_assign_set_one(struct rdt_resource *r);
 
 #endif /* _ASM_X86_RESCTRL_INTERNAL_H */
index 0b3c199e9e016d2c409a153933fe63173ea9091d..c8945610d45550790615c03dc31f28a0d5713ccd 100644 (file)
@@ -456,6 +456,7 @@ int __init rdt_get_mon_l3_config(struct rdt_resource *r)
                r->mon.mbm_cntr_assignable = true;
                cpuid_count(0x80000020, 5, &eax, &ebx, &ecx, &edx);
                r->mon.num_mbm_cntrs = (ebx & GENMASK(15, 0)) + 1;
+               hw_res->mbm_cntr_assign_enabled = true;
        }
 
        r->mon_capable = true;
@@ -557,3 +558,10 @@ void resctrl_arch_config_cntr(struct rdt_resource *r, struct rdt_mon_domain *d,
        if (am)
                memset(am, 0, sizeof(*am));
 }
+
+void resctrl_arch_mbm_cntr_assign_set_one(struct rdt_resource *r)
+{
+       struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r);
+
+       resctrl_abmc_set_one_amd(&hw_res->mbm_cntr_assign_enabled);
+}