Commit b3a23e33 authored by Wang ShaoBo's avatar Wang ShaoBo Committed by Zheng Zengkai
Browse files

arm64/mpam: Filter schema control type with ctrl features



hulk inclusion
category: feature
feature: ARM MPAM support
bugzilla: 48265
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: default avatarWang ShaoBo <bobo.shaobowang@huawei.com>
Reviewed-by: default avatarXiongfeng Wang <wangxiongfeng2@huawei.com>
Reviewed-by: default avatarCheng Jian <cj.chengjian@huawei.com>
Signed-off-by: default avatarYang Yingliang <yangyingliang@huawei.com>
Signed-off-by: default avatarZheng Zengkai <zhengzengkai@huawei.com>
parent 2ae8305b
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -195,6 +195,8 @@ struct resctrl_ctrl_feature {
	int        default_ctrl;
	bool       capable;
	bool       enabled;

	const char *ctrl_suffix;
};

struct msr_param {
+9 −15
Original line number Diff line number Diff line
@@ -42,12 +42,9 @@ static int add_schema(enum resctrl_conf_type t, struct resctrl_resource *r)
{
	int ret = 0;
	char *suffix = "";
	char *ctrl_suffix = "";
	struct resctrl_schema *s;
	struct raw_resctrl_resource *rr;
	struct resctrl_schema_ctrl *sc, *sc_tmp;
	struct resctrl_schema_ctrl *sc_pri = NULL;
	struct resctrl_schema_ctrl *sc_hdl = NULL;
	struct resctrl_schema_ctrl *sc, *tmp;
	enum resctrl_ctrl_type type;

	s = kzalloc(sizeof(*s), GFP_KERNEL);
@@ -93,6 +90,9 @@ static int add_schema(enum resctrl_conf_type t, struct resctrl_resource *r)
	rr = r->res;
	INIT_LIST_HEAD(&s->schema_ctrl_list);
	for_each_extend_ctrl_type(type) {
		struct resctrl_ctrl_feature *feature =
			&rr->ctrl_features[type];

		if (!rr->ctrl_features[type].enabled ||
			!rr->ctrl_features[type].max_wd)
			continue;
@@ -103,25 +103,19 @@ static int add_schema(enum resctrl_conf_type t, struct resctrl_resource *r)
			goto err;
		}
		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) +
			strlen(ctrl_suffix) + 1 > RESCTRL_NAME_LEN);
		snprintf(sc->name, sizeof(sc->name), "%s%s%s",
			r->name, suffix, ctrl_suffix);
			strlen(feature->ctrl_suffix) + 1 > RESCTRL_NAME_LEN);
		snprintf(sc->name, sizeof(sc->name), "%s%s%s", r->name,
			suffix, feature->ctrl_suffix);

		list_add_tail(&sc->list, &s->schema_ctrl_list);
	}

	return 0;

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);
		kfree(sc);
	}
+18 −14
Original line number Diff line number Diff line
@@ -1048,19 +1048,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;
	struct resctrl_resource *r;
	struct raw_resctrl_resource *rr;
	struct mpam_resctrl_res *res;
	struct resctrl_ctrl_feature *feature;
	enum resctrl_ctrl_type type;

	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) {
				rr->ctrl_features[type].enabled = true;
				match = true;
			}
		}
	}

	if (!match)
		return -EINVAL;
@@ -1103,16 +1114,9 @@ int parse_rdtgroupfs_options(char *data)
			ret = cdpl2_enable();
			if (ret)
				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 {
			ret = -EINVAL;
			ret = extend_ctrl_enable(token);
			if (ret)
				goto out;
		}
	}