From: Wang ShaoBo bobo.shaobowang@huawei.com
hulk inclusion category: bugfix bugzilla: 34278 CVE: NA
-------------------------------------------------
This fixes two problems:
1) when cpu offline, we should clear cpu mask from all associated resctrl group but not only default group.
2) when cpu online, we should set cpu mask for default group and update default group's cpus to default state if cdp on, this operation is to fill code and data fields of mpam sysregs with appropriate value.
Fixes: 2e2c511ff49d ("arm64/mpam: resctrl: Handle cpuhp and resctrl_dom allocation") Signed-off-by: Wang ShaoBo bobo.shaobowang@huawei.com Reviewed-by: Jian Cheng 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/resctrl.h | 25 +++++++++++++++++++++++++ arch/arm64/kernel/mpam/mpam_resctrl.c | 15 ++++++++++++--- fs/resctrlfs.c | 22 ---------------------- 3 files changed, 37 insertions(+), 25 deletions(-)
diff --git a/arch/arm64/include/asm/resctrl.h b/arch/arm64/include/asm/resctrl.h index 95148e1bb232..a31df7fdc477 100644 --- a/arch/arm64/include/asm/resctrl.h +++ b/arch/arm64/include/asm/resctrl.h @@ -447,6 +447,31 @@ int parse_rdtgroupfs_options(char *data);
int resctrl_group_add_files(struct kernfs_node *kn, unsigned long fflags);
+static inline void resctrl_cdp_update_cpus_state(struct resctrl_group *rdtgrp) +{ + int cpu; + + /* + * If cdp on, tasks in resctrl default group with closid=0 + * and rmid=0 don't know how to fill proper partid_i/pmg_i + * and partid_d/pmg_d into MPAMx_ELx sysregs by mpam_sched_in() + * called by __switch_to(), it's because current cpu's default + * closid and rmid are also equal to 0 and make the operation + * modifying configuration passed. Update per cpu default closid + * of none-zero value, call update_closid_rmid() to update each + * cpu's mpam proper MPAMx_ELx sysregs for setting partid and + * pmg when mounting resctrl sysfs, which is a practical method; + * Besides, to support cpu online and offline we should set + * cur_closid to 0. + */ + for_each_cpu(cpu, &rdtgrp->cpu_mask) { + per_cpu(pqr_state.default_closid, cpu) = ~0; + per_cpu(pqr_state.cur_closid, cpu) = 0; + } + + update_closid_rmid(&rdtgrp->cpu_mask, NULL); +} + #define RESCTRL_MAX_CBM 32
/* diff --git a/arch/arm64/kernel/mpam/mpam_resctrl.c b/arch/arm64/kernel/mpam/mpam_resctrl.c index 05d34181df90..a7fef0ac36f2 100644 --- a/arch/arm64/kernel/mpam/mpam_resctrl.c +++ b/arch/arm64/kernel/mpam/mpam_resctrl.c @@ -90,15 +90,24 @@ static bool resctrl_cdp_enabled;
int mpam_resctrl_set_default_cpu(unsigned int cpu) { - /* The cpu is set in default rdtgroup after online. */ + /* The cpu is set in default rdtgroup after online. */ cpumask_set_cpu(cpu, &resctrl_group_default.cpu_mask); + + /* Update CPU mpam sysregs' default setting when cdp enabled */ + if (resctrl_cdp_enabled) + resctrl_cdp_update_cpus_state(&resctrl_group_default); + return 0; }
void mpam_resctrl_clear_default_cpu(unsigned int cpu) { - /* The cpu is set in default rdtgroup after online. */ - cpumask_clear_cpu(cpu, &resctrl_group_default.cpu_mask); + struct resctrl_group *rdtgrp; + + list_for_each_entry(rdtgrp, &resctrl_all_groups, resctrl_group_list) { + /* The cpu is clear in associated rdtgroup after offline. */ + cpumask_clear_cpu(cpu, &rdtgrp->cpu_mask); + } }
bool is_resctrl_cdp_enabled(void) diff --git a/fs/resctrlfs.c b/fs/resctrlfs.c index 6a51212afdac..7779d6ec3e27 100644 --- a/fs/resctrlfs.c +++ b/fs/resctrlfs.c @@ -320,28 +320,6 @@ static int mkdir_mondata_all(struct kernfs_node *parent_kn, return ret; }
-static void resctrl_cdp_update_cpus_state(struct resctrl_group *r) -{ - int cpu; - - /* - * If cdp on, tasks in resctrl default group with closid=0 - * and rmid=0 don't know how to fill proper partid_i/pmg_i - * and partid_d/pmg_d into MPAMx_ELx sysregs by mpam_sched_in() - * called by __switch_to(), it's because current cpu's default - * closid and rmid are also equal to 0 and to make the operation - * modifying configuration passed. Update per cpu default closid - * of none-zero value, call update_closid_rmid() to update each - * cpu's mpam proper MPAMx_ELx sysregs for setting partid and - * pmg when mounting resctrl sysfs, it looks like a practical - * method. - */ - for_each_cpu(cpu, &r->cpu_mask) - per_cpu(pqr_state.default_closid, cpu) = ~0; - - update_closid_rmid(&r->cpu_mask, NULL); -} - static struct dentry *resctrl_mount(struct file_system_type *fs_type, int flags, const char *unused_dev_name, void *data)