From: Wang ShaoBo bobo.shaobowang@huawei.com
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@huawei.com Reviewed-by: Xie XiuQi xiexiuqi@huawei.com Signed-off-by: Yang Yingliang yangyingliang@huawei.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 ab90596..1a6904c 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 0a0a12b..fb5fa6c 100644 --- a/arch/arm64/include/asm/resctrl.h +++ b/arch/arm64/include/asm/resctrl.h @@ -65,4 +65,6 @@ int mkdir_mondata_all(struct kernfs_node *parent_kn, 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 202e49a..120795e 100644 --- a/arch/arm64/kernel/mpam.c +++ b/arch/arm64/kernel/mpam.c @@ -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; }
diff --git a/arch/arm64/kernel/mpam_ctrlmon.c b/arch/arm64/kernel/mpam_ctrlmon.c index b9f9495..2b94efc 100644 --- a/arch/arm64/kernel/mpam_ctrlmon.c +++ b/arch/arm64/kernel/mpam_ctrlmon.c @@ -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; +} diff --git a/fs/resctrlfs.c b/fs/resctrlfs.c index 09e56384..8d463b8 100644 --- a/fs/resctrlfs.c +++ b/fs/resctrlfs.c @@ -670,6 +670,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) {
From: Wang ShaoBo bobo.shaobowang@huawei.com
hulk inclusion category: bugfix bugzilla: 34588 CVE: NA
-----------------------------------------------
In many cases writing resctrl interface may return failure, but err tips in info/last_cmd_status remain ok. e.g. > echo 'L3:5=7fff' > schemata -bash: echo: write error: Invalid argument > cat info/last_cmd_status ok > cat ctrlmon 1 > echo 1 > ctrlmon -bash: echo: write error: No such file or directory > cat info/last_cmd_status ok We add extra tips when goes to this branches.
Signed-off-by: Wang ShaoBo bobo.shaobowang@huawei.com Reviewed-by: Xie XiuQi xiexiuqi@huawei.com Signed-off-by: Yang Yingliang yangyingliang@huawei.com --- arch/arm64/kernel/mpam.c | 7 ++++++- arch/arm64/kernel/mpam_ctrlmon.c | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/arch/arm64/kernel/mpam.c b/arch/arm64/kernel/mpam.c index 120795e..3f89cec 100644 --- a/arch/arm64/kernel/mpam.c +++ b/arch/arm64/kernel/mpam.c @@ -858,7 +858,7 @@ static int resctrl_num_mon_show(struct kernfs_open_file *of, int cpus_mon_write(struct rdtgroup *rdtgrp, cpumask_var_t newmask, cpumask_var_t tmpmask) { - pr_info("unsupported on mon_groups, please use ctrlmon groups\n"); + rdt_last_cmd_puts("temporarily unsupported write cpus on mon_groups\n"); return -EINVAL; }
@@ -1143,6 +1143,7 @@ static ssize_t resctrl_group_ctrlmon_write(struct kernfs_open_file *of,
if (!rdtgrp) { ret = -ENOENT; + rdt_last_cmd_puts("directory was removed\n"); goto unlock; }
@@ -1156,6 +1157,10 @@ static ssize_t resctrl_group_ctrlmon_write(struct kernfs_open_file *of, if (!ret) rdtgrp->flags |= RDT_CTRLMON; } else { + if (ctrlmon) + rdt_last_cmd_printf("ctrlmon has been enabled\n"); + else + rdt_last_cmd_printf("ctrlmon has been disabled\n"); ret = -ENOENT; }
diff --git a/arch/arm64/kernel/mpam_ctrlmon.c b/arch/arm64/kernel/mpam_ctrlmon.c index 2b94efc..850c52f 100644 --- a/arch/arm64/kernel/mpam_ctrlmon.c +++ b/arch/arm64/kernel/mpam_ctrlmon.c @@ -171,6 +171,9 @@ static int parse_line(char *line, struct resctrl_resource *r) goto next; } } + + rdt_last_cmd_printf("unknown domain (%lu)\n", dom_id); + return -EINVAL; }
@@ -224,6 +227,7 @@ ssize_t resctrl_group_schemata_write(struct kernfs_open_file *of, rdtgrp = resctrl_group_kn_lock_live(of->kn); if (!rdtgrp) { resctrl_group_kn_unlock(of->kn); + rdt_last_cmd_puts("directory was removed\n"); return -ENOENT; } rdt_last_cmd_clear();