Skip to content

Commit 5b6fac3

Browse files
babumogerbp3tk0v
authored andcommitted
x86/resctrl: Detect and configure Slow Memory Bandwidth Allocation
The QoS slow memory configuration details are available via CPUID_Fn80000020_EDX_x02. Detect the available details and initialize the rest to defaults. Signed-off-by: Babu Moger <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Reviewed-by: Reinette Chatre <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent a76f65c commit 5b6fac3

File tree

4 files changed

+41
-6
lines changed

4 files changed

+41
-6
lines changed

arch/x86/include/asm/msr-index.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,7 @@
10611061

10621062
/* - AMD: */
10631063
#define MSR_IA32_MBA_BW_BASE 0xc0000200
1064+
#define MSR_IA32_SMBA_BW_BASE 0xc0000280
10641065

10651066
/* MSR_IA32_VMX_MISC bits */
10661067
#define MSR_IA32_VMX_MISC_INTEL_PT (1ULL << 14)

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

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,13 @@ bool is_mba_sc(struct rdt_resource *r)
162162
if (!r)
163163
return rdt_resources_all[RDT_RESOURCE_MBA].r_resctrl.membw.mba_sc;
164164

165+
/*
166+
* The software controller support is only applicable to MBA resource.
167+
* Make sure to check for resource type.
168+
*/
169+
if (r->rid != RDT_RESOURCE_MBA)
170+
return false;
171+
165172
return r->membw.mba_sc;
166173
}
167174

@@ -225,9 +232,15 @@ static bool __rdt_get_mem_config_amd(struct rdt_resource *r)
225232
struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r);
226233
union cpuid_0x10_3_eax eax;
227234
union cpuid_0x10_x_edx edx;
228-
u32 ebx, ecx;
235+
u32 ebx, ecx, subleaf;
229236

230-
cpuid_count(0x80000020, 1, &eax.full, &ebx, &ecx, &edx.full);
237+
/*
238+
* Query CPUID_Fn80000020_EDX_x01 for MBA and
239+
* CPUID_Fn80000020_EDX_x02 for SMBA
240+
*/
241+
subleaf = (r->rid == RDT_RESOURCE_SMBA) ? 2 : 1;
242+
243+
cpuid_count(0x80000020, subleaf, &eax.full, &ebx, &ecx, &edx.full);
231244
hw_res->num_closid = edx.split.cos_max + 1;
232245
r->default_ctrl = MAX_MBA_BW_AMD;
233246

@@ -750,6 +763,19 @@ static __init bool get_mem_config(void)
750763
return false;
751764
}
752765

766+
static __init bool get_slow_mem_config(void)
767+
{
768+
struct rdt_hw_resource *hw_res = &rdt_resources_all[RDT_RESOURCE_SMBA];
769+
770+
if (!rdt_cpu_has(X86_FEATURE_SMBA))
771+
return false;
772+
773+
if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD)
774+
return __rdt_get_mem_config_amd(&hw_res->r_resctrl);
775+
776+
return false;
777+
}
778+
753779
static __init bool get_rdt_alloc_resources(void)
754780
{
755781
struct rdt_resource *r;
@@ -780,6 +806,9 @@ static __init bool get_rdt_alloc_resources(void)
780806
if (get_mem_config())
781807
ret = true;
782808

809+
if (get_slow_mem_config())
810+
ret = true;
811+
783812
return ret;
784813
}
785814

@@ -869,6 +898,9 @@ static __init void rdt_init_res_defs_amd(void)
869898
} else if (r->rid == RDT_RESOURCE_MBA) {
870899
hw_res->msr_base = MSR_IA32_MBA_BW_BASE;
871900
hw_res->msr_update = mba_wrmsr_amd;
901+
} else if (r->rid == RDT_RESOURCE_SMBA) {
902+
hw_res->msr_base = MSR_IA32_SMBA_BW_BASE;
903+
hw_res->msr_update = mba_wrmsr_amd;
872904
}
873905
}
874906
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ static int parse_line(char *line, struct resctrl_schema *s,
209209
unsigned long dom_id;
210210

211211
if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP &&
212-
r->rid == RDT_RESOURCE_MBA) {
212+
(r->rid == RDT_RESOURCE_MBA || r->rid == RDT_RESOURCE_SMBA)) {
213213
rdt_last_cmd_puts("Cannot pseudo-lock MBA resource\n");
214214
return -EINVAL;
215215
}

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,7 +1210,7 @@ static bool rdtgroup_mode_test_exclusive(struct rdtgroup *rdtgrp)
12101210

12111211
list_for_each_entry(s, &resctrl_schema_all, list) {
12121212
r = s->res;
1213-
if (r->rid == RDT_RESOURCE_MBA)
1213+
if (r->rid == RDT_RESOURCE_MBA || r->rid == RDT_RESOURCE_SMBA)
12141214
continue;
12151215
has_cache = true;
12161216
list_for_each_entry(d, &r->domains, list) {
@@ -1399,7 +1399,8 @@ static int rdtgroup_size_show(struct kernfs_open_file *of,
13991399
ctrl = resctrl_arch_get_config(r, d,
14001400
closid,
14011401
type);
1402-
if (r->rid == RDT_RESOURCE_MBA)
1402+
if (r->rid == RDT_RESOURCE_MBA ||
1403+
r->rid == RDT_RESOURCE_SMBA)
14031404
size = ctrl;
14041405
else
14051406
size = rdtgroup_cbm_to_size(r, d, ctrl);
@@ -2842,7 +2843,8 @@ static int rdtgroup_init_alloc(struct rdtgroup *rdtgrp)
28422843

28432844
list_for_each_entry(s, &resctrl_schema_all, list) {
28442845
r = s->res;
2845-
if (r->rid == RDT_RESOURCE_MBA) {
2846+
if (r->rid == RDT_RESOURCE_MBA ||
2847+
r->rid == RDT_RESOURCE_SMBA) {
28462848
rdtgroup_init_mba(r, rdtgrp->closid);
28472849
if (is_mba_sc(r))
28482850
continue;

0 commit comments

Comments
 (0)