提交 e79aa56b 编写于 作者: W Wang ShaoBo 提交者: Laibin Qiu

arm64/mpam: realign step entry when traversing rmid_transform

hulk inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I4SE03
CVE: NA

---------------------------------------------------

This makes step entry aligned with step_size*step_cnt but not step_size,
and check for alignment before traversing rmid_transform.

When modifying rmid with a value not aligned with step_size*step_cnt,
for_each_rmid_transform_point_step_from might miss next step point if
it has been occupied in case step_cnt or step_size not equals to 1,
which will cause the actual allocated rmid to be inconsistent with the
expected one.

Fixes: b47b9a81 ("arm64/mpam: rmid: refine allocation and release process")
Signed-off-by: NWang ShaoBo <bobo.shaobowang@huawei.com>
Reviewed-by: NCheng Jian <cj.chengjian@huawei.com>
Signed-off-by: NLaibin Qiu <qiulaibin@huawei.com>
上级 880b1947
......@@ -839,7 +839,8 @@ static inline unsigned long **__rmid_remap_bmp(u32 col)
#define __step_xy_initialize(step, x, y, from) \
(x = from, step = 1, y = 0)
#define __step_align(from) \
(!(from % rmid_remap_matrix.step_size))
(!(from % (rmid_remap_matrix.step_size * \
rmid_remap_matrix.step_cnt)))
#define __step_overflow(step) \
(__xy_overflow(x, y) || \
(step > rmid_remap_matrix.step_cnt))
......@@ -913,7 +914,7 @@ static int is_rmid_remap_bmp_full(unsigned long *bmp)
bitmap_full(bmp, rmid_remap_matrix.rows));
}
static int rmid_remap_bmp_find_first_avail_partid(int partid)
static int rmid_remap_bmp_find_step_entry(int partid)
{
int x, y;
unsigned long **bmp;
......@@ -922,17 +923,18 @@ static int rmid_remap_bmp_find_first_avail_partid(int partid)
rmid_remap_matrix.cols)
return 0;
/* step entry should be non-occupied and aligned */
bmp = __rmid_remap_bmp(partid);
if (bmp && !is_rmid_remap_bmp_occ(*bmp))
return partid;
if (bmp)
return (is_rmid_remap_bmp_occ(*bmp) ||
!__step_align(partid)) ? -ENOSPC : partid;
for_each_rmid_transform_point_from(bmp, x, y, 0) {
/*
* do not waste partid resource, start
* from step_size aligned position.
* from step aligned position.
*/
if (!is_rmid_remap_bmp_occ(*bmp) &&
(x % rmid_remap_matrix.step_size) == 0)
if (__step_align(x) && !is_rmid_remap_bmp_occ(*bmp))
return x;
}
......@@ -1026,8 +1028,8 @@ static int __rmid_alloc(int partid, int pmg)
if (pmg >= 0)
checkpmg = true;
/* traverse from first non-occupied and step_size aligned entry */
ret = rmid_remap_bmp_find_first_avail_partid(partid);
/* traverse from first non-occupied and step-aligned entry */
ret = rmid_remap_bmp_find_step_entry(partid);
if (ret < 0)
goto out;
partid = ret;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册