From: Wang ShaoBo bobo.shaobowang@huawei.com
hulk inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I61CPK CVE: NA
--------------------------------
Writing bandwidth control value to /sys/fs/resctrl/schemata may return an incorrect value.
For instance:
$ cat /sys/fs/resctrl/schemata L3:0=7fff;1=7fff;2=7fff;3=7fff MB:0=100;1=100;2=100;3=100 $ echo 'MB:0=20' > /sys/fs/resctrl/schemata $ cat /sys/fs/resctrl/schemata L3:0=7fff;1=7fff;2=7fff;3=7fff MB:0=18;1=100;2=100;3=100
Assuming that bwa_wd(given in MPAMF_MBW_IDR.BWA_WD) is greater than or equal to 6 (fraction is 64), we can divide mbw_max/min with a granularity of at least 2 in the range between 0 to 100, if we calculate mbw_max/min with this formula1: mbw_max/min = (Input * range) / Scale
Then we turn to ask for Input with this formula2: Input = (mbw_max/min * Scale) / range
But if calculated deviation is too large in formula1, we can no longer use formula2 to get our original value at a granularity of 2. Therefore, we need to correct the calculation result of formula1.
Signed-off-by: Wang ShaoBo bobo.shaobowang@huawei.com Signed-off-by: Jialin Zhang zhangjialin11@huawei.com Reviewed-by: Xie XiuQi xiexiuqi@huawei.com Signed-off-by: Zheng Zengkai zhengzengkai@huawei.com --- arch/arm64/kernel/mpam/mpam_resctrl.c | 4 ++++ 1 file changed, 4 insertions(+)
diff --git a/arch/arm64/kernel/mpam/mpam_resctrl.c b/arch/arm64/kernel/mpam/mpam_resctrl.c index e9e77064bdb2..d00746c08922 100644 --- a/arch/arm64/kernel/mpam/mpam_resctrl.c +++ b/arch/arm64/kernel/mpam/mpam_resctrl.c @@ -2280,6 +2280,8 @@ mpam_update_from_resctrl_cfg(struct mpam_resctrl_res *res, case QOS_MBA_MAX_EVENT_ID: range = MBW_MAX_BWA_FRACT(res->class->bwa_wd); mpam_cfg->mbw_max = (resctrl_cfg * range) / (MAX_MBA_BW - 1); + /* correct mbw_max if remainder is too large */ + mpam_cfg->mbw_max += ((resctrl_cfg * range) % (MAX_MBA_BW - 1)) / range; mpam_cfg->mbw_max = (mpam_cfg->mbw_max > range) ? range : mpam_cfg->mbw_max; mpam_set_feature(mpam_feat_mbw_max, &mpam_cfg->valid); @@ -2287,6 +2289,8 @@ mpam_update_from_resctrl_cfg(struct mpam_resctrl_res *res, case QOS_MBA_MIN_EVENT_ID: range = MBW_MAX_BWA_FRACT(res->class->bwa_wd); mpam_cfg->mbw_min = (resctrl_cfg * range) / (MAX_MBA_BW - 1); + /* correct mbw_min if remainder is too large */ + mpam_cfg->mbw_min += ((resctrl_cfg * range) % (MAX_MBA_BW - 1)) / range; mpam_cfg->mbw_min = (mpam_cfg->mbw_min > range) ? range : mpam_cfg->mbw_min; mpam_set_feature(mpam_feat_mbw_min, &mpam_cfg->valid);