Commit 5df3ca93 authored by James Morse's avatar James Morse Committed by Borislav Petkov

x86/resctrl: Merge AMD/Intel parse_bw() calls

Now after arch_needs_linear has been added, the parse_bw() calls are
almost the same between AMD and Intel.

The difference is '!is_mba_sc()', which is not checked on AMD. This
will always be true on AMD CPUs as mba_sc cannot be enabled as
is_mba_linear() is false.

Removing this duplication means user-space visible behaviour and
error messages are not validated or generated in different places.

Reviewed-by : Babu Moger <babu.moger@amd.com>
Signed-off-by: default avatarJames Morse <james.morse@arm.com>
Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
Reviewed-by: default avatarReinette Chatre <reinette.chatre@intel.com>
Link: https://lkml.kernel.org/r/20200708163929.2783-9-james.morse@arm.com
parent 41215b79
...@@ -168,6 +168,7 @@ struct rdt_resource rdt_resources_all[] = { ...@@ -168,6 +168,7 @@ struct rdt_resource rdt_resources_all[] = {
.name = "MB", .name = "MB",
.domains = domain_init(RDT_RESOURCE_MBA), .domains = domain_init(RDT_RESOURCE_MBA),
.cache_level = 3, .cache_level = 3,
.parse_ctrlval = parse_bw,
.format_str = "%d=%*u", .format_str = "%d=%*u",
.fflags = RFTYPE_RES_MB, .fflags = RFTYPE_RES_MB,
}, },
...@@ -926,7 +927,6 @@ static __init void rdt_init_res_defs_intel(void) ...@@ -926,7 +927,6 @@ static __init void rdt_init_res_defs_intel(void)
else if (r->rid == RDT_RESOURCE_MBA) { else if (r->rid == RDT_RESOURCE_MBA) {
r->msr_base = MSR_IA32_MBA_THRTL_BASE; r->msr_base = MSR_IA32_MBA_THRTL_BASE;
r->msr_update = mba_wrmsr_intel; r->msr_update = mba_wrmsr_intel;
r->parse_ctrlval = parse_bw_intel;
} }
} }
} }
...@@ -946,7 +946,6 @@ static __init void rdt_init_res_defs_amd(void) ...@@ -946,7 +946,6 @@ static __init void rdt_init_res_defs_amd(void)
else if (r->rid == RDT_RESOURCE_MBA) { else if (r->rid == RDT_RESOURCE_MBA) {
r->msr_base = MSR_IA32_MBA_BW_BASE; r->msr_base = MSR_IA32_MBA_BW_BASE;
r->msr_update = mba_wrmsr_amd; r->msr_update = mba_wrmsr_amd;
r->parse_ctrlval = parse_bw_amd;
} }
} }
} }
......
...@@ -21,59 +21,6 @@ ...@@ -21,59 +21,6 @@
#include <linux/slab.h> #include <linux/slab.h>
#include "internal.h" #include "internal.h"
/*
* Check whether MBA bandwidth percentage value is correct. The value is
* checked against the minimum and maximum bandwidth values specified by
* the hardware. The allocated bandwidth percentage is rounded to the next
* control step available on the hardware.
*/
static bool bw_validate_amd(char *buf, unsigned long *data,
struct rdt_resource *r)
{
unsigned long bw;
int ret;
/* temporary: always false on AMD */
if (!r->membw.delay_linear && r->membw.arch_needs_linear) {
rdt_last_cmd_puts("No support for non-linear MB domains\n");
return false;
}
ret = kstrtoul(buf, 10, &bw);
if (ret) {
rdt_last_cmd_printf("Non-decimal digit in MB value %s\n", buf);
return false;
}
if (bw < r->membw.min_bw || bw > r->default_ctrl) {
rdt_last_cmd_printf("MB value %ld out of range [%d,%d]\n", bw,
r->membw.min_bw, r->default_ctrl);
return false;
}
*data = roundup(bw, (unsigned long)r->membw.bw_gran);
return true;
}
int parse_bw_amd(struct rdt_parse_data *data, struct rdt_resource *r,
struct rdt_domain *d)
{
unsigned long bw_val;
if (d->have_new_ctrl) {
rdt_last_cmd_printf("Duplicate domain %d\n", d->id);
return -EINVAL;
}
if (!bw_validate_amd(data->buf, &bw_val, r))
return -EINVAL;
d->new_ctrl = bw_val;
d->have_new_ctrl = true;
return 0;
}
/* /*
* Check whether MBA bandwidth percentage value is correct. The value is * Check whether MBA bandwidth percentage value is correct. The value is
* checked against the minimum and max bandwidth values specified by the * checked against the minimum and max bandwidth values specified by the
...@@ -110,7 +57,7 @@ static bool bw_validate(char *buf, unsigned long *data, struct rdt_resource *r) ...@@ -110,7 +57,7 @@ static bool bw_validate(char *buf, unsigned long *data, struct rdt_resource *r)
return true; return true;
} }
int parse_bw_intel(struct rdt_parse_data *data, struct rdt_resource *r, int parse_bw(struct rdt_parse_data *data, struct rdt_resource *r,
struct rdt_domain *d) struct rdt_domain *d)
{ {
unsigned long bw_val; unsigned long bw_val;
......
...@@ -471,9 +471,7 @@ struct rdt_resource { ...@@ -471,9 +471,7 @@ struct rdt_resource {
int parse_cbm(struct rdt_parse_data *data, struct rdt_resource *r, int parse_cbm(struct rdt_parse_data *data, struct rdt_resource *r,
struct rdt_domain *d); struct rdt_domain *d);
int parse_bw_intel(struct rdt_parse_data *data, struct rdt_resource *r, int parse_bw(struct rdt_parse_data *data, struct rdt_resource *r,
struct rdt_domain *d);
int parse_bw_amd(struct rdt_parse_data *data, struct rdt_resource *r,
struct rdt_domain *d); struct rdt_domain *d);
extern struct mutex rdtgroup_mutex; extern struct mutex rdtgroup_mutex;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment