From: Wang ShaoBo <bobo.shaobowang(a)huawei.com>
commit a2bb0448956594c7cb5b9176e6f46d5cf9c6ef10 openEuler-1.0
hulk inclusion
category: bugfix
bugzilla: 34588
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: Wang ShaoBo <bobo.shaobowang(a)huawei.com>
Reviewed-by: Xie XiuQi <xiexiuqi(a)huawei.com>
Signed-off-by: Yang Yingliang <yangyingliang(a)huawei.com>
Signed-off-by: Xin Hao <haoxing990(a)gmail.com>
---
arch/arm64/include/asm/mpam_resource.h | 4 ++++
arch/arm64/include/asm/resctrl.h | 2 ++
arch/arm64/kernel/mpam.c | 17 ++++++++++++++++
arch/arm64/kernel/mpam_ctrlmon.c | 28 ++++++++++++++++++++++++++
fs/resctrlfs.c | 5 +++++
5 files changed, 56 insertions(+)
diff --git a/arch/arm64/include/asm/mpam_resource.h
b/arch/arm64/include/asm/mpam_resource.h
index ab90596c9194..1a6904c22b9c 100644
--- a/arch/arm64/include/asm/mpam_resource.h
+++ b/arch/arm64/include/asm/mpam_resource.h
@@ -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.
diff --git a/arch/arm64/include/asm/resctrl.h b/arch/arm64/include/asm/resctrl.h
index 0a0a12b17ab3..fb5fa6c13843 100644
--- a/arch/arm64/include/asm/resctrl.h
+++ b/arch/arm64/include/asm/resctrl.h
@@ -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 */
diff --git a/arch/arm64/kernel/mpam.c b/arch/arm64/kernel/mpam.c
index 4007a31b5249..dc6dd566fc37 100644
--- a/arch/arm64/kernel/mpam.c
+++ b/arch/arm64/kernel/mpam.c
@@ -91,6 +91,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)
@@ -549,6 +552,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;
}
diff --git a/arch/arm64/kernel/mpam_ctrlmon.c b/arch/arm64/kernel/mpam_ctrlmon.c
index c9d306a93b24..90f34987e5b8 100644
--- a/arch/arm64/kernel/mpam_ctrlmon.c
+++ b/arch/arm64/kernel/mpam_ctrlmon.c
@@ -589,3 +589,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;
+}
diff --git a/fs/resctrlfs.c b/fs/resctrlfs.c
index 4ae00a60efcd..94ad8e0c4413 100644
--- a/fs/resctrlfs.c
+++ b/fs/resctrlfs.c
@@ -672,6 +672,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) {
--
2.31.0