From: Wang ShaoBo bobo.shaobowang@huawei.com
hulk inclusion category: feature bugzilla: 34278 CVE: NA
-------------------------------------------------
Resctrl ctrlmon write/read functions should be moved to mpam_ctrlmon.c to make code clear.
Signed-off-by: Wang ShaoBo bobo.shaobowang@huawei.com Reviewed-by: Xiongfeng Wang wangxiongfeng2@huawei.com Reviewed-by: Cheng Jian cj.chengjian@huawei.com Signed-off-by: Yang Yingliang yangyingliang@huawei.com Signed-off-by: Cheng Jian cj.chengjian@huawei.com --- arch/arm64/include/asm/mpam.h | 6 ++ arch/arm64/kernel/mpam/mpam_ctrlmon.c | 109 +++++++++++++++++++++++++ arch/arm64/kernel/mpam/mpam_resctrl.c | 110 -------------------------- 3 files changed, 115 insertions(+), 110 deletions(-)
diff --git a/arch/arm64/include/asm/mpam.h b/arch/arm64/include/asm/mpam.h index d4cb6672f7b9..b81aec481784 100644 --- a/arch/arm64/include/asm/mpam.h +++ b/arch/arm64/include/asm/mpam.h @@ -355,6 +355,12 @@ union mon_data_bits { struct rdt_domain *mpam_find_domain(struct resctrl_resource *r, int id, struct list_head **pos);
+ssize_t resctrl_group_ctrlmon_write(struct kernfs_open_file *of, + char *buf, size_t nbytes, loff_t off); + +int resctrl_group_ctrlmon_show(struct kernfs_open_file *of, + struct seq_file *s, void *v); + int resctrl_group_alloc_mon(struct rdtgroup *grp);
void mon_init(void); diff --git a/arch/arm64/kernel/mpam/mpam_ctrlmon.c b/arch/arm64/kernel/mpam/mpam_ctrlmon.c index f04b90667095..481b4d54f2ba 100644 --- a/arch/arm64/kernel/mpam/mpam_ctrlmon.c +++ b/arch/arm64/kernel/mpam/mpam_ctrlmon.c @@ -489,6 +489,115 @@ static int mkdir_mondata_subdir(struct kernfs_node *parent_kn, return ret; }
+int resctrl_ctrlmon_enable(struct kernfs_node *parent_kn, + struct resctrl_group *prgrp, + struct kernfs_node **dest_kn) +{ + int ret; + + /* only for RDTCTRL_GROUP */ + if (prgrp->type == RDTMON_GROUP) + return 0; + + ret = alloc_mon(); + if (ret < 0) { + rdt_last_cmd_puts("out of monitors\n"); + pr_info("out of monitors: ret %d\n", ret); + return ret; + } + prgrp->mon.mon = ret; + prgrp->mon.rmid = 0; + + ret = mkdir_mondata_all(parent_kn, prgrp, dest_kn); + if (ret) { + rdt_last_cmd_puts("kernfs subdir error\n"); + free_mon(ret); + } + + return ret; +} + +void resctrl_ctrlmon_disable(struct kernfs_node *kn_mondata, + struct resctrl_group *prgrp) +{ + struct mpam_resctrl_res *r; + struct resctrl_resource *resctrl_res; + struct raw_resctrl_resource *rr; + struct rdt_domain *dom; + int mon = prgrp->mon.mon; + + /* only for RDTCTRL_GROUP */ + if (prgrp->type == RDTMON_GROUP) + return; + + for_each_resctrl_exports(r) { + resctrl_res = &r->resctrl_res; + + if (resctrl_res->mon_enabled) { + rr = (struct raw_resctrl_resource *)resctrl_res->res; + + list_for_each_entry(dom, &resctrl_res->domains, list) { + rr->mon_write(dom, prgrp, false); + } + } + } + + free_mon(mon); + kernfs_remove(kn_mondata); +} + +ssize_t resctrl_group_ctrlmon_write(struct kernfs_open_file *of, + char *buf, size_t nbytes, loff_t off) +{ + struct rdtgroup *rdtgrp; + int ret = 0; + int ctrlmon; + + if (kstrtoint(strstrip(buf), 0, &ctrlmon) || ctrlmon < 0) + return -EINVAL; + rdtgrp = resctrl_group_kn_lock_live(of->kn); + rdt_last_cmd_clear(); + + if (!rdtgrp) { + ret = -ENOENT; + goto unlock; + } + + if ((rdtgrp->flags & RDT_CTRLMON) && !ctrlmon) { + /* disable & remove mon_data dir */ + rdtgrp->flags &= ~RDT_CTRLMON; + resctrl_ctrlmon_disable(rdtgrp->mon.mon_data_kn, rdtgrp); + } else if (!(rdtgrp->flags & RDT_CTRLMON) && ctrlmon) { + ret = resctrl_ctrlmon_enable(rdtgrp->kn, rdtgrp, + &rdtgrp->mon.mon_data_kn); + if (!ret) + rdtgrp->flags |= RDT_CTRLMON; + } else { + ret = -ENOENT; + } + +unlock: + resctrl_group_kn_unlock(of->kn); + return ret ?: nbytes; +} + +int resctrl_group_ctrlmon_show(struct kernfs_open_file *of, + struct seq_file *s, void *v) +{ + struct rdtgroup *rdtgrp; + int ret = 0; + + rdtgrp = resctrl_group_kn_lock_live(of->kn); + if (rdtgrp) + seq_printf(s, "%d", !!(rdtgrp->flags & RDT_CTRLMON)); + else + ret = -ENOENT; + resctrl_group_kn_unlock(of->kn); + + return ret; +} + + static int mkdir_mondata_subdir_alldom(struct kernfs_node *parent_kn, struct resctrl_resource *r, struct resctrl_group *prgrp) diff --git a/arch/arm64/kernel/mpam/mpam_resctrl.c b/arch/arm64/kernel/mpam/mpam_resctrl.c index bfee2845236a..df327de7fe48 100644 --- a/arch/arm64/kernel/mpam/mpam_resctrl.c +++ b/arch/arm64/kernel/mpam/mpam_resctrl.c @@ -1138,116 +1138,6 @@ static int resctrl_group_tasks_show(struct kernfs_open_file *of, return ret; }
-int resctrl_ctrlmon_enable(struct kernfs_node *parent_kn, - struct resctrl_group *prgrp, - struct kernfs_node **dest_kn) -{ - int ret; - - /* only for RDTCTRL_GROUP */ - if (prgrp->type == RDTMON_GROUP) - return 0; - - ret = alloc_mon(); - if (ret < 0) { - rdt_last_cmd_puts("out of monitors\n"); - pr_info("out of monitors: ret %d\n", ret); - return ret; - } - prgrp->mon.mon = ret; - prgrp->mon.rmid = 0; - - ret = mkdir_mondata_all(parent_kn, prgrp, dest_kn); - if (ret) { - rdt_last_cmd_puts("kernfs subdir error\n"); - free_mon(ret); - } - - return ret; -} - -void resctrl_ctrlmon_disable(struct kernfs_node *kn_mondata, - struct resctrl_group *prgrp) -{ - struct mpam_resctrl_res *r; - struct resctrl_resource *resctrl_res; - struct raw_resctrl_resource *rr; - struct rdt_domain *dom; - int mon = prgrp->mon.mon; - - /* only for RDTCTRL_GROUP */ - if (prgrp->type == RDTMON_GROUP) - return; - - for_each_supported_resctrl_exports(r) { - resctrl_res = &r->resctrl_res; - - if (resctrl_res->mon_enabled) { - rr = (struct raw_resctrl_resource *)resctrl_res->res; - - list_for_each_entry(dom, &resctrl_res->domains, list) { - rr->mon_write(dom, prgrp, false); - } - } - } - - free_mon(mon); - kernfs_remove(kn_mondata); - - return; -} - -static ssize_t resctrl_group_ctrlmon_write(struct kernfs_open_file *of, - char *buf, size_t nbytes, loff_t off) -{ - struct rdtgroup *rdtgrp; - int ret = 0; - int ctrlmon; - - if (kstrtoint(strstrip(buf), 0, &ctrlmon) || ctrlmon < 0) - return -EINVAL; - rdtgrp = resctrl_group_kn_lock_live(of->kn); - rdt_last_cmd_clear(); - - if (!rdtgrp) { - ret = -ENOENT; - goto unlock; - } - - if ((rdtgrp->flags & RDT_CTRLMON) && !ctrlmon) { - /* disable & remove mon_data dir */ - rdtgrp->flags &= ~RDT_CTRLMON; - resctrl_ctrlmon_disable(rdtgrp->mon.mon_data_kn, rdtgrp); - } else if (!(rdtgrp->flags & RDT_CTRLMON) && ctrlmon) { - ret = resctrl_ctrlmon_enable(rdtgrp->kn, rdtgrp, - &rdtgrp->mon.mon_data_kn); - if (!ret) - rdtgrp->flags |= RDT_CTRLMON; - } else { - ret = -ENOENT; - } - -unlock: - resctrl_group_kn_unlock(of->kn); - return ret ?: nbytes; -} - -static int resctrl_group_ctrlmon_show(struct kernfs_open_file *of, - struct seq_file *s, void *v) -{ - struct rdtgroup *rdtgrp; - int ret = 0; - - rdtgrp = resctrl_group_kn_lock_live(of->kn); - if (rdtgrp) - seq_printf(s, "%d", !!(rdtgrp->flags & RDT_CTRLMON)); - else - ret = -ENOENT; - resctrl_group_kn_unlock(of->kn); - - return ret; -} - /* rdtgroup information files for one cache resource. */ static struct rftype res_specific_files[] = { {