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

arm64/mpam: Fix unreset resources when mkdir ctrl group or umount resctrl



hulk inclusion
category: bugfix
bugzilla: 48265
CVE: NA

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

There are two problems related to schemata:

1) When rmdir a group and then mkdir a new group under resctrl
   root directory, the new group still inherits the schemata
   configuration from old.
   e.g.
       > mount -t resctrl resctrl /sys/fs/resctrl
       > cd /sys/fs/resctrl
       > mkdir p1 && cd p1
       > echo 'L3:0=7f' > schemata
       > cd .. && rmdir p1 && mkdir p1 && cd p1
       > cat schemata
         L3:0=7f;1=7fff;2=7fff;3=7fff
         MB:0=100;1=100;2=100;3=100

2) It still exists when umount /sys/fs/resctrl and remount.
   e.g.
       > mount -t resctrl resctrl /sys/fs/resctrl
       > cd /sys/fs/resctrl
       > echo 'L3:0=7f' > schemata
       > umount /sys/fs/resctrl
       > mount -t resctrl resctrl /sys/fs/resctrl
       > cat schemata
         L3:0=7f;1=7fff;2=7fff;3=7fff
         MB:0=100;1=100;2=100;3=100

Firstly we make each resctrl resource obtains their corresponding
default configuration. NOTE we use zero to initialize L3 default
value instead of max cpbm bits, as zero configurarion equals to
maximum configuration for L3 MSCs. And we use max-percentage masks
of max bandwidth to generate maximum configuration for MB.

Then we reset resources' configuration settings to default value
and back MSCs to default state, when mkdir or umount happended.

Fixes: caf75b6b2540 ("resctrlfs: mpam: init struct for mpam")
Fixes: 916dd9321e3c ("resctrlfs: init support resctrlfs")
Signed-off-by: default avatarWang ShaoBo <bobo.shaobowang@huawei.com>
Reviewed-by: default avatarXie XiuQi <xiexiuqi@huawei.com>
Signed-off-by: default avatarYang Yingliang <yangyingliang@huawei.com>
Reviewed-by: default avatarCheng Jian <cj.chengjian@huawei.com>
Signed-off-by: default avatarZheng Zengkai <zhengzengkai@huawei.com>
parent d43a6c0c
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -89,6 +89,10 @@
/* [FIXME] hard code for hardlim */
#define MBW_MAX_SET(v)		(MBW_MAX_HARDLIM|((v) << (16 - BWA_WD)))
#define MBW_MAX_GET(v)		(((v) & MBW_MAX_MASK) >> (16 - BWA_WD))

/* hard code for mbw_max max-percentage's cresponding masks */
#define MBA_MAX_WD 63u

/*
 * emulate the mpam nodes
 * These should be reported by ACPI MPAM Table.
+2 −0
Original line number Diff line number Diff line
@@ -65,4 +65,6 @@ int
mongroup_create_dir(struct kernfs_node *parent_kn, struct resctrl_group *prgrp,
		    char *name, struct kernfs_node **dest_kn);

int rdtgroup_init_alloc(struct rdtgroup *rdtgrp);

#endif /* _ASM_ARM64_RESCTRL_H */
+17 −0
Original line number Diff line number Diff line
@@ -86,6 +86,9 @@ static inline void mpam_node_assign_val(struct mpam_node *n,
	n->addr = hwpage_address;
	n->component_id = component_id;
	n->cpus_list = "0";

	if (n->type == MPAM_RESOURCE_MC)
		n->default_ctrl = MBA_MAX_WD;
}

#define MPAM_NODE_NAME_SIZE (10)
@@ -544,6 +547,20 @@ void post_resctrl_mount(void)

static int reset_all_ctrls(struct resctrl_resource *r)
{
	struct raw_resctrl_resource *rr;
	struct rdt_domain *d;
	int partid;

	rr = (struct raw_resctrl_resource *)r->res;
	for (partid = 0; partid < rr->num_partid; partid++) {
		list_for_each_entry(d, &r->domains, list) {
			d->new_ctrl = rr->default_ctrl;
			d->ctrl_val[partid] = rr->default_ctrl;
			d->have_new_ctrl = true;
			rr->msr_update(d, partid);
		}
	}

	return 0;
}

+28 −0
Original line number Diff line number Diff line
@@ -585,3 +585,31 @@ int resctrl_mkdir_ctrlmon_mondata(struct kernfs_node *parent_kn,
	}
	return ret;
}

/* Initialize the RDT group's allocations. */
int rdtgroup_init_alloc(struct rdtgroup *rdtgrp)
{
	struct resctrl_resource *r;
	struct raw_resctrl_resource *rr;
	struct rdt_domain *d;
	int ret;

	for_each_resctrl_resource(r) {
		if (!r->alloc_enabled)
			continue;

		rr = (struct raw_resctrl_resource *)r->res;
		list_for_each_entry(d, &r->domains, list) {
			d->new_ctrl = rr->default_ctrl;
			d->have_new_ctrl = true;
		}

		ret = update_domains(r, rdtgrp);
		if (ret < 0) {
			rdt_last_cmd_puts("Failed to initialize allocations\n");
			return ret;
		}
	}

	return 0;
}
+5 −0
Original line number Diff line number Diff line
@@ -708,6 +708,11 @@ static int resctrl_group_mkdir_ctrl_mon(struct kernfs_node *parent_kn,
	ret = 0;

	rdtgrp->closid = closid;

	ret = rdtgroup_init_alloc(rdtgrp);
	if (ret < 0)
		goto out_id_free;

	list_add(&rdtgrp->resctrl_group_list, &resctrl_all_groups);

	if (resctrl_mon_capable) {