From: Wang ShaoBo bobo.shaobowang@huawei.com
hulk inclusion category: bugfix bugzilla: 34278 CVE: NA
-------------------------------------------------
When cpu online, domains inserted into resctrl_resource structure's domains list may be out of order, so sort them with domain id.
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 --- arch/arm64/kernel/mpam/mpam_setup.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/arch/arm64/kernel/mpam/mpam_setup.c b/arch/arm64/kernel/mpam/mpam_setup.c index 51817091f119..8fd76dc38d89 100644 --- a/arch/arm64/kernel/mpam/mpam_setup.c +++ b/arch/arm64/kernel/mpam/mpam_setup.c @@ -59,12 +59,14 @@ mpam_get_domain_from_cpu(int cpu, struct mpam_resctrl_res *res) static int mpam_resctrl_setup_domain(unsigned int cpu, struct mpam_resctrl_res *res) { + struct rdt_domain *d; struct mpam_resctrl_dom *dom; struct mpam_class *class = res->class; struct mpam_component *comp_iter, *comp; u32 num_partid; u32 **ctrlval_ptr; enum resctrl_ctrl_type type; + struct list_head *tmp;
num_partid = mpam_sysprops_num_partid();
@@ -99,8 +101,17 @@ static int mpam_resctrl_setup_domain(unsigned int cpu, } }
- /* TODO: this list should be sorted */ - list_add_tail(&dom->resctrl_dom.list, &res->resctrl_res.domains); + tmp = &res->resctrl_res.domains; + /* insert domains in id ascending order */ + list_for_each_entry(d, &res->resctrl_res.domains, list) { + /* find the last domain with id greater than this domain */ + if (dom->resctrl_dom.id > d->id) + tmp = &d->list; + if (dom->resctrl_dom.id < d->id) + break; + } + list_add(&dom->resctrl_dom.list, tmp); + res->resctrl_res.dom_num++;
return 0;