Skip to content

Commit 7517e89

Browse files
shenxiaochenbp3tk0v
authored andcommitted
x86/resctrl: Fix memory bandwidth counter width for Hygon
The memory bandwidth calculation relies on reading the hardware counter and measuring the delta between samples. To ensure accurate measurement, the software reads the counter frequently enough to prevent it from rolling over twice between reads. The default Memory Bandwidth Monitoring (MBM) counter width is 24 bits. Hygon CPUs provide a 32-bit width counter, but they do not support the MBM capability CPUID leaf (0xF.[ECX=1]:EAX) to report the width offset (from 24 bits). Consequently, the kernel falls back to the 24-bit default counter width, which causes incorrect overflow handling on Hygon CPUs. Fix this by explicitly setting the counter width offset to 8 bits (resulting in a 32-bit total counter width) for Hygon CPUs. Fixes: d8df126 ("x86/cpu/hygon: Add missing resctrl_cpu_detect() in bsp_init helper") Signed-off-by: Xiaochen Shen <shenxiaochen@open-hieco.net> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Reviewed-by: Tony Luck <tony.luck@intel.com> Reviewed-by: Reinette Chatre <reinette.chatre@intel.com> Cc: stable@vger.kernel.org Link: https://patch.msgid.link/20251209062650.1536952-3-shenxiaochen@open-hieco.net
1 parent 6ee98aa commit 7517e89

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

arch/x86/kernel/cpu/resctrl/core.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,8 +1021,19 @@ void resctrl_cpu_detect(struct cpuinfo_x86 *c)
10211021
c->x86_cache_occ_scale = ebx;
10221022
c->x86_cache_mbm_width_offset = eax & 0xff;
10231023

1024-
if (c->x86_vendor == X86_VENDOR_AMD && !c->x86_cache_mbm_width_offset)
1025-
c->x86_cache_mbm_width_offset = MBM_CNTR_WIDTH_OFFSET_AMD;
1024+
if (!c->x86_cache_mbm_width_offset) {
1025+
switch (c->x86_vendor) {
1026+
case X86_VENDOR_AMD:
1027+
c->x86_cache_mbm_width_offset = MBM_CNTR_WIDTH_OFFSET_AMD;
1028+
break;
1029+
case X86_VENDOR_HYGON:
1030+
c->x86_cache_mbm_width_offset = MBM_CNTR_WIDTH_OFFSET_HYGON;
1031+
break;
1032+
default:
1033+
/* Leave c->x86_cache_mbm_width_offset as 0 */
1034+
break;
1035+
}
1036+
}
10261037
}
10271038
}
10281039

arch/x86/kernel/cpu/resctrl/internal.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414

1515
#define MBM_CNTR_WIDTH_OFFSET_AMD 20
1616

17+
/* Hygon MBM counter width as an offset from MBM_CNTR_WIDTH_BASE */
18+
#define MBM_CNTR_WIDTH_OFFSET_HYGON 8
19+
1720
#define RMID_VAL_ERROR BIT_ULL(63)
1821

1922
#define RMID_VAL_UNAVAIL BIT_ULL(62)

0 commit comments

Comments
 (0)