提交 5ac157bf 编写于 作者: W Wang ShaoBo 提交者: Yang Yingliang

arm64/mpam: Filter schema control type with ctrl features

hulk inclusion
category: feature
bugzilla: 34278
CVE: NA

-------------------------------------------------

ctrl_features array, introduced by 61fa56e1dd8a ("arm64/mpam: Add
resctrl_ctrl_feature structure to manage ctrl features"), which lives
in raw_resctrl_resource structure for listing ctrl features's type do
we support in total for this resource, this filters illegal parameters
outside from mount options and provides useful info for add_schema()
for registering a new control type node in schema list.

This action helps us to add new ctrl feature easier later.
Signed-off-by: NWang ShaoBo <bobo.shaobowang@huawei.com>
Reviewed-by: NXiongfeng Wang <wangxiongfeng2@huawei.com>
Reviewed-by: NCheng Jian <cj.chengjian@huawei.com>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
Signed-off-by: NCheng Jian <cj.chengjian@huawei.com>
上级 e0aed913
...@@ -195,6 +195,8 @@ struct resctrl_ctrl_feature { ...@@ -195,6 +195,8 @@ struct resctrl_ctrl_feature {
int default_ctrl; int default_ctrl;
bool capable; bool capable;
bool enabled; bool enabled;
const char *ctrl_suffix;
}; };
struct msr_param { struct msr_param {
......
...@@ -46,12 +46,9 @@ static int add_schema(enum resctrl_conf_type t, struct resctrl_resource *r) ...@@ -46,12 +46,9 @@ static int add_schema(enum resctrl_conf_type t, struct resctrl_resource *r)
{ {
int ret = 0; int ret = 0;
char *suffix = ""; char *suffix = "";
char *ctrl_suffix = "";
struct resctrl_schema *s; struct resctrl_schema *s;
struct raw_resctrl_resource *rr; struct raw_resctrl_resource *rr;
struct resctrl_schema_ctrl *sc, *sc_tmp; struct resctrl_schema_ctrl *sc, *tmp;
struct resctrl_schema_ctrl *sc_pri = NULL;
struct resctrl_schema_ctrl *sc_hdl = NULL;
enum resctrl_ctrl_type type; enum resctrl_ctrl_type type;
s = kzalloc(sizeof(*s), GFP_KERNEL); s = kzalloc(sizeof(*s), GFP_KERNEL);
...@@ -97,6 +94,9 @@ static int add_schema(enum resctrl_conf_type t, struct resctrl_resource *r) ...@@ -97,6 +94,9 @@ static int add_schema(enum resctrl_conf_type t, struct resctrl_resource *r)
rr = r->res; rr = r->res;
INIT_LIST_HEAD(&s->schema_ctrl_list); INIT_LIST_HEAD(&s->schema_ctrl_list);
for_each_extend_ctrl_type(type) { for_each_extend_ctrl_type(type) {
struct resctrl_ctrl_feature *feature =
&rr->ctrl_features[type];
if (!rr->ctrl_features[type].enabled || if (!rr->ctrl_features[type].enabled ||
!rr->ctrl_features[type].max_wd) !rr->ctrl_features[type].max_wd)
continue; continue;
...@@ -107,25 +107,19 @@ static int add_schema(enum resctrl_conf_type t, struct resctrl_resource *r) ...@@ -107,25 +107,19 @@ static int add_schema(enum resctrl_conf_type t, struct resctrl_resource *r)
goto err; goto err;
} }
sc->ctrl_type = type; sc->ctrl_type = type;
if (type == SCHEMA_PRI) {
sc_pri = sc;
ctrl_suffix = "PRI";
} else if (type == SCHEMA_HDL) {
sc_hdl = sc;
ctrl_suffix = "HDL";
}
WARN_ON_ONCE(strlen(r->name) + strlen(suffix) + WARN_ON_ONCE(strlen(r->name) + strlen(suffix) +
strlen(ctrl_suffix) + 1 > RESCTRL_NAME_LEN); strlen(feature->ctrl_suffix) + 1 > RESCTRL_NAME_LEN);
snprintf(sc->name, sizeof(sc->name), "%s%s%s", snprintf(sc->name, sizeof(sc->name), "%s%s%s", r->name,
r->name, suffix, ctrl_suffix); suffix, feature->ctrl_suffix);
list_add_tail(&sc->list, &s->schema_ctrl_list); list_add_tail(&sc->list, &s->schema_ctrl_list);
} }
return 0; return 0;
err: err:
list_for_each_entry_safe(sc, sc_tmp, &s->schema_ctrl_list, list) { list_for_each_entry_safe(sc, tmp, &s->schema_ctrl_list, list) {
list_del(&sc->list); list_del(&sc->list);
kfree(sc); kfree(sc);
} }
......
...@@ -1053,19 +1053,30 @@ static void basic_ctrl_enable(void) ...@@ -1053,19 +1053,30 @@ static void basic_ctrl_enable(void)
} }
} }
static int extend_ctrl_enable(enum resctrl_ctrl_type type) static int extend_ctrl_enable(char *tok)
{ {
bool match = false; bool match = false;
struct resctrl_resource *r;
struct raw_resctrl_resource *rr; struct raw_resctrl_resource *rr;
struct mpam_resctrl_res *res; struct mpam_resctrl_res *res;
struct resctrl_ctrl_feature *feature;
enum resctrl_ctrl_type type;
for_each_supported_resctrl_exports(res) { for_each_supported_resctrl_exports(res) {
rr = res->resctrl_res.res; r = &res->resctrl_res;
if (!r->alloc_capable)
continue;
rr = r->res;
for_each_ctrl_type(type) {
feature = &rr->ctrl_features[type];
if (strcmp(feature->name, tok))
continue;
if (rr->ctrl_features[type].capable) { if (rr->ctrl_features[type].capable) {
rr->ctrl_features[type].enabled = true; rr->ctrl_features[type].enabled = true;
match = true; match = true;
} }
} }
}
if (!match) if (!match)
return -EINVAL; return -EINVAL;
...@@ -1108,16 +1119,9 @@ int parse_rdtgroupfs_options(char *data) ...@@ -1108,16 +1119,9 @@ int parse_rdtgroupfs_options(char *data)
ret = cdpl2_enable(); ret = cdpl2_enable();
if (ret) if (ret)
goto out; goto out;
} else if (!strcmp(token, "priority")) {
ret = extend_ctrl_enable(SCHEMA_PRI);
if (ret)
goto out;
} else if (!strcmp(token, "hardlimit")) {
ret = extend_ctrl_enable(SCHEMA_HDL);
if (ret)
goto out;
} else { } else {
ret = -EINVAL; ret = extend_ctrl_enable(token);
if (ret)
goto out; goto out;
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册