提交 df092ea4 编写于 作者: W Wang ShaoBo 提交者: Zheng Zengkai

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: 8a2c07b5 ("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: NZheng Zengkai <zhengzengkai@huawei.com>
上级 8cfa786d
...@@ -834,7 +834,8 @@ static inline unsigned long **__rmid_remap_bmp(u32 col) ...@@ -834,7 +834,8 @@ static inline unsigned long **__rmid_remap_bmp(u32 col)
#define __step_xy_initialize(step, x, y, from) \ #define __step_xy_initialize(step, x, y, from) \
(x = from, step = 1, y = 0) (x = from, step = 1, y = 0)
#define __step_align(from) \ #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) \ #define __step_overflow(step) \
(__xy_overflow(x, y) || \ (__xy_overflow(x, y) || \
(step > rmid_remap_matrix.step_cnt)) (step > rmid_remap_matrix.step_cnt))
...@@ -908,7 +909,7 @@ static int is_rmid_remap_bmp_full(unsigned long *bmp) ...@@ -908,7 +909,7 @@ static int is_rmid_remap_bmp_full(unsigned long *bmp)
bitmap_full(bmp, rmid_remap_matrix.rows)); 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; int x, y;
unsigned long **bmp; unsigned long **bmp;
...@@ -917,17 +918,18 @@ static int rmid_remap_bmp_find_first_avail_partid(int partid) ...@@ -917,17 +918,18 @@ static int rmid_remap_bmp_find_first_avail_partid(int partid)
rmid_remap_matrix.cols) rmid_remap_matrix.cols)
return 0; return 0;
/* step entry should be non-occupied and aligned */
bmp = __rmid_remap_bmp(partid); bmp = __rmid_remap_bmp(partid);
if (bmp && !is_rmid_remap_bmp_occ(*bmp)) if (bmp)
return partid; return (is_rmid_remap_bmp_occ(*bmp) ||
!__step_align(partid)) ? -ENOSPC : partid;
for_each_rmid_transform_point_from(bmp, x, y, 0) { for_each_rmid_transform_point_from(bmp, x, y, 0) {
/* /*
* do not waste partid resource, start * do not waste partid resource, start
* from step_size aligned position. * from step aligned position.
*/ */
if (!is_rmid_remap_bmp_occ(*bmp) && if (__step_align(x) && !is_rmid_remap_bmp_occ(*bmp))
(x % rmid_remap_matrix.step_size) == 0)
return x; return x;
} }
...@@ -1021,8 +1023,8 @@ static int __rmid_alloc(int partid, int pmg) ...@@ -1021,8 +1023,8 @@ static int __rmid_alloc(int partid, int pmg)
if (pmg >= 0) if (pmg >= 0)
checkpmg = true; checkpmg = true;
/* traverse from first non-occupied and step_size aligned entry */ /* traverse from first non-occupied and step-aligned entry */
ret = rmid_remap_bmp_find_first_avail_partid(partid); ret = rmid_remap_bmp_find_step_entry(partid);
if (ret < 0) if (ret < 0)
goto out; goto out;
partid = ret; partid = ret;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册