From: Wang ShaoBo bobo.shaobowang@huawei.com
hulk inclusion category: feature bugzilla: 34278 CVE: NA
-------------------------------------------------
Store default priority in mpam class structure from reading devices' intpri_wd and dspri_wd.
intpri_wd and dspri_wd represent the number of implemented bits in the internal/downstream priority field in MPAMCFG_PRI, when INTPRI_0_IS_LOW /DSPRI_0_IS_LOW is not set, we need to rotate input priority(higher value higher priority) from user space to target priority (higher value lower priority) and this is restricted by implemented bits.
Signed-off-by: Wang ShaoBo bobo.shaobowang@huawei.com Reviewed-by: Xiongfeng Wang wangxiongfeng2@huawei.com Reviewed-by: Cheng Jian cj.chengjian@huawei.com Signed-off-by: Yang Yingliang yangyingliang@huawei.com --- arch/arm64/kernel/mpam/mpam_device.c | 13 +++++++++++-- arch/arm64/kernel/mpam/mpam_device.h | 4 ++++ arch/arm64/kernel/mpam/mpam_setup.c | 10 +++++++--- 3 files changed, 22 insertions(+), 5 deletions(-)
diff --git a/arch/arm64/kernel/mpam/mpam_device.c b/arch/arm64/kernel/mpam/mpam_device.c index b8686e6c6669..0413eac0ba5e 100644 --- a/arch/arm64/kernel/mpam/mpam_device.c +++ b/arch/arm64/kernel/mpam/mpam_device.c @@ -362,6 +362,8 @@ static void mpam_enable_squash_features(void) class->num_pmg = dev->num_pmg; class->num_csu_mon = dev->num_csu_mon; class->num_mbwu_mon = dev->num_mbwu_mon; + class->hwdef_intpri = dev->hwdef_intpri; + class->hwdef_dspri = dev->hwdef_dspri; spin_unlock_irqrestore(&dev->lock, flags); }
@@ -764,10 +766,17 @@ static void mpam_reset_device_config(struct mpam_component *comp, intpri = dev->hwdef_intpri; dspri = dev->hwdef_dspri;
- if (mpam_has_feature(mpam_feat_intpri_part, dev->features)) + if (mpam_has_feature(mpam_feat_intpri_part, dev->features)) { + if (!mpam_has_feature(mpam_feat_intpri_part_0_low, dev->features)) + intpri = GENMASK(dev->intpri_wd - 1, 0) & ~intpri; pri_val |= intpri; - if (mpam_has_feature(mpam_feat_dspri_part, dev->features)) + } + + if (mpam_has_feature(mpam_feat_dspri_part, dev->features)) { + if (!mpam_has_feature(mpam_feat_dspri_part_0_low, dev->features)) + dspri = GENMASK(dev->dspri_wd - 1, 0) & ~dspri; pri_val |= (dspri << MPAMCFG_PRI_DSPRI_SHIFT); + }
mpam_write_reg(dev, MPAMCFG_PRI, pri_val); } diff --git a/arch/arm64/kernel/mpam/mpam_device.h b/arch/arm64/kernel/mpam/mpam_device.h index b1f852e65d83..fc5f7c292b6f 100644 --- a/arch/arm64/kernel/mpam/mpam_device.h +++ b/arch/arm64/kernel/mpam/mpam_device.h @@ -118,6 +118,10 @@ struct mpam_class { u16 num_pmg; u16 num_csu_mon; u16 num_mbwu_mon; + + /* for reset class MPAMCFG_PRI */ + u16 hwdef_intpri; + u16 hwdef_dspri; };
/* System wide properties */ diff --git a/arch/arm64/kernel/mpam/mpam_setup.c b/arch/arm64/kernel/mpam/mpam_setup.c index a06bd19be485..dc7490890349 100644 --- a/arch/arm64/kernel/mpam/mpam_setup.c +++ b/arch/arm64/kernel/mpam/mpam_setup.c @@ -465,10 +465,14 @@ static int mpam_resctrl_resource_init(struct mpam_resctrl_res *res) rr->num_intpartid = class->num_intpartid; rr->num_pmg = class->num_pmg;
- /* Export priority setting, default highest priority */ + /* + * Export priority setting, default priority from hardware, + * no clever here, we don't need to define another default + * value. + */ rr->pri_wd = max(class->intpri_wd, class->dspri_wd); - r->default_ctrl[SCHEMA_PRI] = (rr->pri_wd > 0) ? - rr->pri_wd - 1 : 0; + r->default_ctrl[SCHEMA_PRI] = max(class->hwdef_intpri, + class->hwdef_dspri); }
return 0;