[PATCH OLK-6.6 00/13] arm_mpam: backport mpam bugfix patches.
From: Hongye Lin <linhongye@h-partners.com> driver inclusion category: bugfix bugzilla: https://atomgit.com/openeuler/kernel/issues/9840 ---------------------------------------------------------------------- James Morse (1): arm_mpam: Add mpam_msmon_read() to read monitor value Reinette Chatre (1): fs/resctrl: Fix UAF from worker threads when domains are removed Shanker Donthineni (1): arm_mpam: Add quirk framework Yifan Wu (10): arm_mpam: improve msmon read latency by replacing schedule_timeout with fsleep arm_mpam: Remove CPU from the header mask if this was the last CPU in the domain arm_mpam: Add debugfs entry for quirks field in class arm_mpam: Add ACPI platform matching for quirk framework arm_mpam: Add workaround for hisi pmg_max arm_mpam: Add workaround for hisi cpbm_wd arm_mpam: Add workaround for hisi min_cbm arm_mpam: Add workaround for hisi csu arm_mpam: Add workaround for hisi llc gran fs/resctrl: Add workaround for hisi mbm arch/x86/include/asm/resctrl.h | 2 + drivers/platform/mpam/mpam_devices.c | 468 +++++++++++++++++--------- drivers/platform/mpam/mpam_internal.h | 50 ++- drivers/platform/mpam/mpam_resctrl.c | 102 +++--- fs/resctrl/monitor.c | 40 ++- fs/resctrl/rdtgroup.c | 33 +- include/linux/arm_mpam.h | 2 +- include/linux/resctrl.h | 9 - 8 files changed, 482 insertions(+), 224 deletions(-) -- 2.33.0
From: James Morse <james.morse@arm.com> driver inclusion category: bugfix bugzilla: https://atomgit.com/openeuler/kernel/issues/9840 ---------------------------------------------------------------------- Reading a monitor involves configuring what you want to monitor, and reading the value. Components made up of multiple MSC may need values from each MSC. MSCs may take time to configure, returning 'not ready'. The maximum 'not ready' time should have been provided by firmware. Add mpam_msmon_read() to hide all this. If (one of) the MSC returns not ready, then wait the full timeout value before trying again. Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com> Reviewed-by: Gavin Shan <gshan@redhat.com> Reviewed-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com> Reviewed-by: Fenghua Yu <fenghuay@nvidia.com> Tested-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com> Tested-by: Peter Newman <peternewman@google.com> Tested-by: Carl Worth <carl@os.amperecomputing.com> Tested-by: Gavin Shan <gshan@redhat.com> Tested-by: Zeng Heng <zengheng4@huawei.com> Tested-by: Hanjun Guo <guohanjun@huawei.com> Signed-off-by: James Morse <james.morse@arm.com> Signed-off-by: Ben Horgan <ben.horgan@arm.com> Signed-off-by: Yifan Wu <wuyifan50@huawei.com> Signed-off-by: Hongye Lin <linhongye@h-partners.com> --- drivers/platform/mpam/mpam_devices.c | 48 +++++++++++++++++----------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/drivers/platform/mpam/mpam_devices.c b/drivers/platform/mpam/mpam_devices.c index e78352e2dcb2..e93797fbe61b 100644 --- a/drivers/platform/mpam/mpam_devices.c +++ b/drivers/platform/mpam/mpam_devices.c @@ -1214,9 +1214,7 @@ static void __ris_msmon_read(void *arg) static int _msmon_read(struct mpam_component *comp, struct mon_read *arg) { - int err = 0, idx; - bool read_again; - u64 wait_jiffies; + int err, any_err = 0, idx; struct mpam_msc *msc; struct mpam_msc_ris *ris; @@ -1225,38 +1223,34 @@ static int _msmon_read(struct mpam_component *comp, struct mon_read *arg) arg->ris = ris; msc = ris->msc; - read_again = false; -again: mutex_lock(&msc->lock); err = smp_call_function_any(&msc->accessibility, __ris_msmon_read, arg, true); mutex_unlock(&msc->lock); - if (arg->err == -EBUSY && !read_again) { - read_again = true; - - wait_jiffies = usecs_to_jiffies(comp->class->nrdy_usec); - while (wait_jiffies) - wait_jiffies = schedule_timeout_uninterruptible(wait_jiffies); - - goto again; - } - if (!err && arg->err) err = arg->err; + + /* + * Save one error to be returned to the caller, but + * keep reading counters so that get reprogrammed. On + * platforms with NRDY this lets us wait once. + */ if (err) - break; + any_err = err; } srcu_read_unlock(&mpam_srcu, idx); - return err; + return any_err; } int mpam_msmon_read(struct mpam_component *comp, struct mon_cfg *ctx, enum mpam_device_features type, u64 *val) { struct mon_read arg; + u64 wait_jiffies = 0; struct mpam_props *cprops = &comp->class->props; + int err = 0; might_sleep(); @@ -1273,7 +1267,25 @@ int mpam_msmon_read(struct mpam_component *comp, struct mon_cfg *ctx, arg.err = 0; *val = 0; - return _msmon_read(comp, &arg); + err = _msmon_read(comp, &arg); + if (err == -EBUSY && comp->class->nrdy_usec) + wait_jiffies = usecs_to_jiffies(comp->class->nrdy_usec); + + while (wait_jiffies) + wait_jiffies = schedule_timeout_uninterruptible(wait_jiffies); + + if (err == -EBUSY) { + arg = (struct mon_read) { + .ctx = ctx, + .type = type, + .val = val, + }; + *val = 0; + + err = _msmon_read(comp, &arg); + } + + return err; } void mpam_msmon_reset_all_mbwu(struct mpam_component *comp) -- 2.33.0
driver inclusion category: bugfix bugzilla: https://atomgit.com/openeuler/kernel/issues/9840 ---------------------------------------------------------------------- The current use of schedule_timeout_uninterruptible() for NRDY delays in msmon reads has significant timing inaccuracies. This is particularly problematic for control groups that aggregate data from child monitoring groups, where the delays can be amplified by tens to hundreds of times. A single read operation may experience delays of several seconds, which significantly impacts performance. To address this, replace schedule_timeout_uninterruptible() with fsleep() which uses high-resolution timers for more precise delays. Signed-off-by: Yifan Wu <wuyifan50@huawei.com> Signed-off-by: Hongye Lin <linhongye@h-partners.com> --- drivers/platform/mpam/mpam_devices.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/platform/mpam/mpam_devices.c b/drivers/platform/mpam/mpam_devices.c index e93797fbe61b..e1e8c6d2a838 100644 --- a/drivers/platform/mpam/mpam_devices.c +++ b/drivers/platform/mpam/mpam_devices.c @@ -11,6 +11,7 @@ #include <linux/cacheinfo.h> #include <linux/cpu.h> #include <linux/cpumask.h> +#include <linux/delay.h> #include <linux/device.h> #include <linux/errno.h> #include <linux/gfp.h> @@ -1248,7 +1249,6 @@ int mpam_msmon_read(struct mpam_component *comp, struct mon_cfg *ctx, enum mpam_device_features type, u64 *val) { struct mon_read arg; - u64 wait_jiffies = 0; struct mpam_props *cprops = &comp->class->props; int err = 0; @@ -1268,11 +1268,9 @@ int mpam_msmon_read(struct mpam_component *comp, struct mon_cfg *ctx, *val = 0; err = _msmon_read(comp, &arg); - if (err == -EBUSY && comp->class->nrdy_usec) - wait_jiffies = usecs_to_jiffies(comp->class->nrdy_usec); - - while (wait_jiffies) - wait_jiffies = schedule_timeout_uninterruptible(wait_jiffies); + if (err == -EBUSY && comp->class->nrdy_usec) { + fsleep(comp->class->nrdy_usec); + } if (err == -EBUSY) { arg = (struct mon_read) { -- 2.33.0
From: Reinette Chatre <reinette.chatre@intel.com> driver inclusion category: bugfix bugzilla: https://atomgit.com/openeuler/kernel/issues/9840 ---------------------------------------------------------------------- The mbm_handle_overflow() and cqm_handle_limbo() workers read event counters and may sleep while doing so. They are scheduled via delayed_work embedded in struct rdt_l3_mon_domain. Architecture allocates and frees these domains from CPU hotplug callbacks under cpus_write_lock(), and the workers acquire cpus_read_lock() to keep the domain alive across their access. A use-after-free can occur when a worker is blocked waiting for cpus_read_lock() while the hotplug core holds cpus_write_lock(): the architecture frees the rdt_l3_mon_domain that contains the worker's work_struct. When the worker unblocks, the container_of() it performs on the embedded work pointer dereferences freed memory. Drop cpus_read_lock() from the workers and instead drain pending and in-flight work synchronously before the architecture can free the domain. Since architecture offlines the domain under cpus_write_lock() after it has been unlinked from the RCU list and a grace period has elapsed, no new work can be scheduled. The cancel only needs to wait out existing work. Drop rdtgroup_mutex during CPU offline around cancel_delayed_work_sync() so that a worker waiting on the mutex can complete before re-pinning the work on a different CPU. When offlining a CPU the architecture may iterate over resources in any order. For example, the MBA control domain may be offlined before or after a corresponding L3 monitor domain. Ensure that resctrl fs cancels the workers no matter what order the architecture offlines the domains. Reported-by: Sashiko <sashiko-bot@kernel.org> Closes: https://sashiko.dev/#/patchset/20260429184858.36423-1-tony.luck%40intel.com # [1] Co-developed-by: Tony Luck <tony.luck@intel.com> Signed-off-by: Tony Luck <tony.luck@intel.com> Signed-off-by: Reinette Chatre <reinette.chatre@intel.com> Signed-off-by: Yifan Wu <wuyifan50@huawei.com> Signed-off-by: Hongye Lin <linhongye@h-partners.com> --- fs/resctrl/monitor.c | 40 ++++++++++++++++++++++++++++++++++++---- fs/resctrl/rdtgroup.c | 27 ++++++++++++++++++++++----- include/linux/resctrl.h | 9 --------- 3 files changed, 58 insertions(+), 18 deletions(-) diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c index e152c646f35b..73118cf9c07e 100644 --- a/fs/resctrl/monitor.c +++ b/fs/resctrl/monitor.c @@ -518,6 +518,7 @@ static void update_mba_bw(struct rdtgroup *rgrp, struct rdt_domain *dom_mbm) idx = resctrl_arch_rmid_idx_encode(closid, rmid); pmbm_data = &dom_mbm->mbm_local[idx]; + guard(rcu)(); dom_mba = resctrl_get_domain_from_cpu(smp_processor_id(), r_mba); if (!dom_mba) { pr_warn_once("Failure to get domain for MBA update\n"); @@ -628,11 +629,25 @@ void cqm_handle_limbo(struct work_struct *work) unsigned long delay = msecs_to_jiffies(CQM_LIMBOCHECK_INTERVAL); struct rdt_domain *d; - cpus_read_lock(); + /* + * Safe to run without CPU hotplug lock. Work is guaranteed to be + * canceled before the domain structure is removed. + */ mutex_lock(&rdtgroup_mutex); + /* + * Ensure the worker is dedicated to a CPU as intended and not + * relocated by workqueue subsystem as part of CPU going offline. + */ + if (!is_percpu_thread()) + goto out_unlock; + d = container_of(work, struct rdt_domain, cqm_limbo.work); + /* Domain is going offline */ + if (cpumask_empty(&d->cpu_mask)) + goto out_unlock; + __check_limbo(d, false); if (has_busy_rmid(d)) { @@ -642,8 +657,8 @@ void cqm_handle_limbo(struct work_struct *work) delay); } +out_unlock: mutex_unlock(&rdtgroup_mutex); - cpus_read_unlock(); } /** @@ -674,7 +689,10 @@ void mbm_handle_overflow(struct work_struct *work) struct list_head *head; struct rdt_domain *d; - cpus_read_lock(); + /* + * Safe to run without CPU hotplug lock. Work is guaranteed to be + * canceled before the domain structure is removed. + */ mutex_lock(&rdtgroup_mutex); /* @@ -684,8 +702,23 @@ void mbm_handle_overflow(struct work_struct *work) if (!resctrl_mounted || !resctrl_arch_mon_capable()) goto out_unlock; + /* + * Ensure the worker is dedicated to a CPU and not relocated by + * workqueue subsystem as part of CPU going offline since reading + * events depend on smp_processor_id(). After passing this check + * smp_processor_id() is valid for entire duration of this worker + * since it runs with rdtgroup_mutex held and the offline handler needs + * rdtgroup_mutex to offline the CPU being run on here. + */ + if (!is_percpu_thread()) + goto out_unlock; + d = container_of(work, struct rdt_domain, mbm_over.work); + /* Domain is going offline */ + if (cpumask_empty(&d->cpu_mask)) + goto out_unlock; + list_for_each_entry(prgrp, &rdt_all_groups, rdtgroup_list) { resctrl_arch_mbm_update(d, prgrp->closid, prgrp->mon.rmid); @@ -707,7 +740,6 @@ void mbm_handle_overflow(struct work_struct *work) out_unlock: mutex_unlock(&rdtgroup_mutex); - cpus_read_unlock(); } /** diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index c8c78db9da6a..58b070f76bb4 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -4049,6 +4049,22 @@ static void domain_destroy_mon_state(struct rdt_domain *d) void resctrl_offline_domain(struct rdt_resource *r, struct rdt_domain *d) { + /* + * Called by architecture under CPU hotplug lock as it prepares to remove + * the domain which is guaranteed to be accessible here. + * The domain has been unlinked from the RCU list and a grace period + * has elapsed, so no new worker can be scheduled. Drain any worker that + * is in flight or pending before letting architecture proceed to free + * the domain that has the workers' struct delayed_work embedded. + * Do so before taking rdtgroup_mutex since the workers also acquire it. + */ + if (r->mon_capable) { + if (resctrl_arch_is_mbm_enabled(r->rid) && resctrl_arch_would_mbm_overflow(r)) + cancel_delayed_work_sync(&d->mbm_over); + if (resctrl_arch_is_llc_occupancy_enabled() && has_busy_rmid(d)) + cancel_delayed_work_sync(&d->cqm_limbo); + } + mutex_lock(&rdtgroup_mutex); if (supports_mba_mbps() && r->rid == RDT_RESOURCE_MBA) @@ -4064,8 +4080,6 @@ void resctrl_offline_domain(struct rdt_resource *r, struct rdt_domain *d) if (resctrl_mounted && resctrl_arch_mon_capable()) rmdir_mondata_subdir_allrdtgrp(r, d->id); - if (resctrl_arch_is_mbm_enabled(r->rid) && resctrl_arch_would_mbm_overflow()) - cancel_delayed_work(&d->mbm_over); if (resctrl_arch_is_llc_occupancy_enabled() && has_busy_rmid(d)) { /* * When a package is going down, forcefully @@ -4076,7 +4090,6 @@ void resctrl_offline_domain(struct rdt_resource *r, struct rdt_domain *d) * package never comes back. */ __check_limbo(d, true); - cancel_delayed_work(&d->cqm_limbo); } domain_destroy_mon_state(d); @@ -4187,7 +4200,9 @@ void resctrl_setup_dom_overflow_exclude_cpu(struct rdt_resource *r, if (resctrl_arch_is_mbm_enabled(r->rid) && exclude_cpu == d->mbm_work_cpu && resctrl_arch_would_mbm_overflow()) { - cancel_delayed_work(&d->mbm_over); + mutex_unlock(&rdtgroup_mutex); + cancel_delayed_work_sync(&d->mbm_over); + mutex_lock(&rdtgroup_mutex); mbm_setup_overflow_handler(d, 0, exclude_cpu); } } @@ -4213,7 +4228,9 @@ void resctrl_offline_cpu(unsigned int cpu) if (d) { if (resctrl_arch_is_llc_occupancy_enabled() && cpu == d->cqm_work_cpu && has_busy_rmid(d)) { - cancel_delayed_work(&d->cqm_limbo); + mutex_unlock(&rdtgroup_mutex); + cancel_delayed_work_sync(&d->cqm_limbo); + mutex_lock(&rdtgroup_mutex); cqm_setup_limbo_handler(d, 0, cpu); } } diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index 1b8f89a5830e..b9e05bfc8b26 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -336,15 +336,6 @@ resctrl_get_domain_from_cpu(int cpu, struct rdt_resource *r) { struct rdt_domain *d; - /* - * Walking r->domains, ensure it can't race with cpuhp. - * Because this is called via IPI by rdt_ctrl_update(), assertions - * about locks this thread holds will lead to false positives. Check - * someone is holding the CPUs lock. - */ - if (IS_ENABLED(CONFIG_HOTPLUG_CPU) && IS_ENABLED(CONFIG_LOCKDEP)) - lockdep_is_cpus_held(); - list_for_each_entry_rcu(d, &r->domains, list) { /* Find the domain that contains this CPU */ if (cpumask_test_cpu(cpu, &d->cpu_mask)) -- 2.33.0
driver inclusion category: bugfix bugzilla: https://atomgit.com/openeuler/kernel/issues/9840 ---------------------------------------------------------------------- Offlines the domain under cpus_write_lock() after it has been unlinked from the RCU list and a grace period has elapsed, no new work can be scheduled. The cancel only needs to wait out existing work. Signed-off-by: Yifan Wu <wuyifan50@huawei.com> Signed-off-by: Hongye Lin <linhongye@h-partners.com> --- drivers/platform/mpam/mpam_resctrl.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/platform/mpam/mpam_resctrl.c b/drivers/platform/mpam/mpam_resctrl.c index 1c3df3ad8dba..a67fc24b3b04 100644 --- a/drivers/platform/mpam/mpam_resctrl.c +++ b/drivers/platform/mpam/mpam_resctrl.c @@ -1980,8 +1980,10 @@ int mpam_resctrl_offline_cpu(unsigned int cpu) if (!cpumask_empty(&d->cpu_mask)) continue; + list_del_rcu(&d->list); + synchronize_rcu(); resctrl_offline_domain(&res->resctrl_res, &dom->resctrl_dom); - list_del(&d->list); + kfree(dom); } -- 2.33.0
From: Shanker Donthineni <sdonthineni@nvidia.com> driver inclusion category: bugfix bugzilla: https://atomgit.com/openeuler/kernel/issues/9840 ---------------------------------------------------------------------- The MPAM specification includes the MPAMF_IIDR, which serves to uniquely identify the MSC implementation through a combination of implementer details, product ID, variant, and revision. Certain hardware issues/errata can be resolved using software workarounds. Introduce a quirk framework to allow workarounds to be enabled based on the MPAMF_IIDR value. Tested-by: Gavin Shan <gshan@redhat.com> Tested-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com> Tested-by: Zeng Heng <zengheng4@huawei.com> Tested-by: Punit Agrawal <punit.agrawal@oss.qualcomm.com> Reviewed-by: Zeng Heng <zengheng4@huawei.com> Reviewed-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com> Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com> Signed-off-by: Shanker Donthineni <sdonthineni@nvidia.com> Co-developed-by: James Morse <james.morse@arm.com> Signed-off-by: James Morse <james.morse@arm.com> Signed-off-by: Ben Horgan <ben.horgan@arm.com> Signed-off-by: Yifan Wu <wuyifan50@huawei.com> Signed-off-by: Hongye Lin <linhongye@h-partners.com> --- drivers/platform/mpam/mpam_devices.c | 29 +++++++++++++++++++++++++++ drivers/platform/mpam/mpam_internal.h | 29 +++++++++++++++++++++++++-- 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/drivers/platform/mpam/mpam_devices.c b/drivers/platform/mpam/mpam_devices.c index e1e8c6d2a838..0c64c1372e15 100644 --- a/drivers/platform/mpam/mpam_devices.c +++ b/drivers/platform/mpam/mpam_devices.c @@ -614,6 +614,30 @@ static struct mpam_msc_ris *mpam_get_or_create_ris(struct mpam_msc *msc, return found; } +static const struct mpam_quirk mpam_quirks[] = { + { NULL } /* Sentinel */ +}; + +static void mpam_enable_quirks(struct mpam_msc *msc) +{ + const struct mpam_quirk *quirk; + + for (quirk = &mpam_quirks[0]; quirk->iidr_mask; quirk++) { + int err = 0; + + if (quirk->iidr != (msc->iidr & quirk->iidr_mask)) + continue; + + if (quirk->init) + err = quirk->init(msc, quirk); + + if (err) + continue; + + mpam_set_quirk(quirk->workaround, msc); + } +} + u16 mpam_cpbm_wd_hisi_workaround(u16 cpbm_wd, enum mpam_device_features feat, u8 cache_level) { @@ -819,8 +843,11 @@ static int mpam_msc_hw_probe(struct mpam_msc *msc) } idr = mpam_msc_read_idr(msc); + msc->iidr = mpam_read_partsel_reg(msc, IIDR); spin_unlock(&msc->part_sel_lock); + mpam_enable_quirks(msc); + msc->ris_max = FIELD_GET(MPAMF_IDR_RIS_MAX, idr); /* Use these values so partid/pmg always starts with a valid value */ @@ -2220,6 +2247,8 @@ static void mpam_enable_merge_features(void) list_for_each_entry(ris, &comp->ris, comp_list) { if (!ris->msc->probed) continue; + /* Merge quirks */ + class->quirks |= ris->msc->quirks; __resource_props_mismatch(ris, class); diff --git a/drivers/platform/mpam/mpam_internal.h b/drivers/platform/mpam/mpam_internal.h index c7087ca35e20..5239eaf6fc21 100644 --- a/drivers/platform/mpam/mpam_internal.h +++ b/drivers/platform/mpam/mpam_internal.h @@ -63,6 +63,8 @@ struct mpam_msc u8 pmg_max; unsigned long ris_idxs[128 / BITS_PER_LONG]; u32 ris_max; + u32 iidr; + u16 quirks; /* mpam_msc_ris of this component */ struct list_head ris; @@ -144,6 +146,28 @@ static inline void mpam_clear_feature(enum mpam_device_features feat, *supported &= ~(1<<feat); } +/* Workaround bits for msc->quirks */ +enum mpam_device_quirks { + MPAM_QUIRK_LAST +}; + +#define mpam_has_quirk(_quirk, x) (1 << (_quirk) & (x)->quirks) +#define mpam_set_quirk(_quirk, x) ((x)->quirks |= (1 << (_quirk))) + +struct mpam_quirk { + int (*init)(struct mpam_msc *msc, const struct mpam_quirk *quirk); + + u32 iidr; + u32 iidr_mask; + + enum mpam_device_quirks workaround; +}; + +#define MPAM_IIDR_MATCH_ONE (FIELD_PREP_CONST(MPAMF_IIDR_PRODUCTID, 0xfff) | \ + FIELD_PREP_CONST(MPAMF_IIDR_VARIANT, 0xf) | \ + FIELD_PREP_CONST(MPAMF_IIDR_REVISION, 0xf) | \ + FIELD_PREP_CONST(MPAMF_IIDR_IMPLEMENTER, 0xfff)) + struct mpam_class { /* mpam_components in this class */ @@ -153,6 +177,7 @@ struct mpam_class struct mpam_props props; u32 nrdy_usec; + u16 quirks; u8 level; enum mpam_class_types type; @@ -462,8 +487,8 @@ u32 mpam_min_cbm_bits(enum resctrl_res_level rid); #define MPAMF_IIDR_PRODUCTID_SHIFT 20 #define MPAMF_IIDR_VARIANT GENMASK(19, 16) #define MPAMF_IIDR_VARIANT_SHIFT 16 -#define MPAMF_IIDR_REVISON GENMASK(15, 12) -#define MPAMF_IIDR_REVISON_SHIFT 12 +#define MPAMF_IIDR_REVISION GENMASK(15, 12) +#define MPAMF_IIDR_REVISION_SHIFT 12 #define MPAMF_IIDR_IMPLEMENTER GENMASK(11, 0) #define MPAMF_IIDR_IMPLEMENTER_SHIFT 0 -- 2.33.0
driver inclusion category: bugfix bugzilla: https://atomgit.com/openeuler/kernel/issues/9840 ---------------------------------------------------------------------- Add debugfs entry for quirks field in class structures to reveal why certain MPAM devices exhibit specific behaviors. Signed-off-by: Yifan Wu <wuyifan50@huawei.com> Signed-off-by: Hongye Lin <linhongye@h-partners.com> --- drivers/platform/mpam/mpam_devices.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/platform/mpam/mpam_devices.c b/drivers/platform/mpam/mpam_devices.c index 0c64c1372e15..748e2de48f54 100644 --- a/drivers/platform/mpam/mpam_devices.c +++ b/drivers/platform/mpam/mpam_devices.c @@ -2585,6 +2585,7 @@ static void mpam_debugfs_setup(void) debugfs_create_x32("nrdy_usec", 0400, d, &class->nrdy_usec); debugfs_create_x8("level", 0400, d, &class->level); debugfs_create_cpumask("affinity", 0400, d, &class->affinity); + debugfs_create_u16("quirks", 0400, d, &class->quirks); class->debugfs = d; list_for_each_entry_rcu(comp, &class->components, class_list) -- 2.33.0
driver inclusion category: bugfix bugzilla: https://atomgit.com/openeuler/kernel/issues/9840 ---------------------------------------------------------------------- Add ACPI platform matching for quirk framework, When a specific device cannot be identified through the IIDR or in the case of a specific MSC combination, the workaround can be enabled based on the ACPI firmware information. Signed-off-by: Yifan Wu <wuyifan50@huawei.com> Signed-off-by: Hongye Lin <linhongye@h-partners.com> --- drivers/platform/mpam/mpam_devices.c | 3 ++- drivers/platform/mpam/mpam_internal.h | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/platform/mpam/mpam_devices.c b/drivers/platform/mpam/mpam_devices.c index 748e2de48f54..39dd2826a7b3 100644 --- a/drivers/platform/mpam/mpam_devices.c +++ b/drivers/platform/mpam/mpam_devices.c @@ -625,7 +625,8 @@ static void mpam_enable_quirks(struct mpam_msc *msc) for (quirk = &mpam_quirks[0]; quirk->iidr_mask; quirk++) { int err = 0; - if (quirk->iidr != (msc->iidr & quirk->iidr_mask)) + if ((!quirk->iidr || quirk->iidr != (msc->iidr & quirk->iidr_mask)) && + (!quirk->plat || acpi_match_platform_list(quirk->plat) < 0)) continue; if (quirk->init) diff --git a/drivers/platform/mpam/mpam_internal.h b/drivers/platform/mpam/mpam_internal.h index 5239eaf6fc21..f70ad200beb9 100644 --- a/drivers/platform/mpam/mpam_internal.h +++ b/drivers/platform/mpam/mpam_internal.h @@ -160,6 +160,7 @@ struct mpam_quirk { u32 iidr; u32 iidr_mask; + struct acpi_platform_list *plat; enum mpam_device_quirks workaround; }; -- 2.33.0
driver inclusion category: bugfix bugzilla: https://atomgit.com/openeuler/kernel/issues/9840 ---------------------------------------------------------------------- Add workaround for hisi pmg_max When a specific device cannot be identified through the IIDR. Signed-off-by: Yifan Wu <wuyifan50@huawei.com> Signed-off-by: Hongye Lin <linhongye@h-partners.com> --- drivers/platform/mpam/mpam_devices.c | 27 ++++++++++++++++++--------- drivers/platform/mpam/mpam_internal.h | 1 + 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/drivers/platform/mpam/mpam_devices.c b/drivers/platform/mpam/mpam_devices.c index 39dd2826a7b3..217155f612e3 100644 --- a/drivers/platform/mpam/mpam_devices.c +++ b/drivers/platform/mpam/mpam_devices.c @@ -109,6 +109,11 @@ static const struct midr_range hisi_cpus[] = { { /* sentinel */ } }; +/* Values for the HISI workaround */ +#define HIP12_ACPI_PLAT { "HISI ", "HIP12 ", 0, ACPI_SIG_MPAM, all_versions } +#define HIP12B_ACPI_PLAT { "HISI ", "HIP12B ", 0, ACPI_SIG_MPAM, all_versions } +#define HIP13_ACPI_PLAT { "HISI ", "HIP13 ", 0, ACPI_SIG_MPAM, all_versions } + static u32 __mpam_read_reg(struct mpam_msc *msc, u16 reg) { WARN_ON_ONCE(reg + sizeof(u32) > msc->mapped_hwpage_sz); @@ -615,6 +620,15 @@ static struct mpam_msc_ris *mpam_get_or_create_ris(struct mpam_msc *msc, } static const struct mpam_quirk mpam_quirks[] = { + { + .iidr_mask = MPAM_IIDR_MATCH_ONE, + .plat = (struct acpi_platform_list[]) { + HIP12_ACPI_PLAT, + HIP12B_ACPI_PLAT, + HIP13_ACPI_PLAT, + {} }, + .workaround = HISI_SHRINK_PMG_MAX, + }, { NULL } /* Sentinel */ }; @@ -817,14 +831,6 @@ static void mpam_ris_hw_probe(struct mpam_msc_ris *ris) } } -static int mpam_pmg_max_workaround(u64 idr) -{ - if (is_midr_in_range_list(hisi_cpus)) - return 0; - - return FIELD_GET(MPAMF_IDR_PMG_MAX, idr); -} - static int mpam_msc_hw_probe(struct mpam_msc *msc) { u64 idr; @@ -853,7 +859,10 @@ static int mpam_msc_hw_probe(struct mpam_msc *msc) /* Use these values so partid/pmg always starts with a valid value */ msc->partid_max = FIELD_GET(MPAMF_IDR_PARTID_MAX, idr); - msc->pmg_max = mpam_pmg_max_workaround(idr); + msc->pmg_max = FIELD_GET(MPAMF_IDR_PMG_MAX, idr); + + if (mpam_has_quirk(HISI_SHRINK_PMG_MAX, msc)) + msc->pmg_max = 0; for (ris_idx = 0; ris_idx <= msc->ris_max; ris_idx++) { spin_lock(&msc->part_sel_lock); diff --git a/drivers/platform/mpam/mpam_internal.h b/drivers/platform/mpam/mpam_internal.h index f70ad200beb9..acce68708de2 100644 --- a/drivers/platform/mpam/mpam_internal.h +++ b/drivers/platform/mpam/mpam_internal.h @@ -148,6 +148,7 @@ static inline void mpam_clear_feature(enum mpam_device_features feat, /* Workaround bits for msc->quirks */ enum mpam_device_quirks { + HISI_SHRINK_PMG_MAX, MPAM_QUIRK_LAST }; -- 2.33.0
driver inclusion category: bugfix bugzilla: https://atomgit.com/openeuler/kernel/issues/9840 ---------------------------------------------------------------------- Add workaround for hisi cpbm_wd When a specific device cannot be identified through the IIDR. Signed-off-by: Yifan Wu <wuyifan50@huawei.com> Signed-off-by: Hongye Lin <linhongye@h-partners.com> --- drivers/platform/mpam/mpam_devices.c | 125 +++++++++++++++----------- drivers/platform/mpam/mpam_internal.h | 8 +- drivers/platform/mpam/mpam_resctrl.c | 39 ++++---- 3 files changed, 104 insertions(+), 68 deletions(-) diff --git a/drivers/platform/mpam/mpam_devices.c b/drivers/platform/mpam/mpam_devices.c index 217155f612e3..6b9b7433b360 100644 --- a/drivers/platform/mpam/mpam_devices.c +++ b/drivers/platform/mpam/mpam_devices.c @@ -113,6 +113,9 @@ static const struct midr_range hisi_cpus[] = { #define HIP12_ACPI_PLAT { "HISI ", "HIP12 ", 0, ACPI_SIG_MPAM, all_versions } #define HIP12B_ACPI_PLAT { "HISI ", "HIP12B ", 0, ACPI_SIG_MPAM, all_versions } #define HIP13_ACPI_PLAT { "HISI ", "HIP13 ", 0, ACPI_SIG_MPAM, all_versions } +u16 hisi_config_cpbm_wd; +u16 hisi_hardware_cpbm_wd; +u32 hisi_valid_cpbm_mask; static u32 __mpam_read_reg(struct mpam_msc *msc, u16 reg) { @@ -619,6 +622,19 @@ static struct mpam_msc_ris *mpam_get_or_create_ris(struct mpam_msc *msc, return found; } +static int mpam_enable_quirk_hisi_cpbm_wd(struct mpam_msc *msc, const struct mpam_quirk *quirk) +{ + struct mpam_msc_ris *ris; + + list_for_each_entry(ris, &msc->ris, msc_list) { + struct mpam_class *class = ris->comp->class; + + if (class->type == MPAM_CLASS_CACHE && class->level == 3) + return 0; + } + return -EINVAL; +} + static const struct mpam_quirk mpam_quirks[] = { { .iidr_mask = MPAM_IIDR_MATCH_ONE, @@ -629,6 +645,15 @@ static const struct mpam_quirk mpam_quirks[] = { {} }, .workaround = HISI_SHRINK_PMG_MAX, }, + { + .init = mpam_enable_quirk_hisi_cpbm_wd, + .iidr_mask = MPAM_IIDR_MATCH_ONE, + .plat = (struct acpi_platform_list[]) { + HIP12_ACPI_PLAT, + HIP13_ACPI_PLAT, + {} }, + .workaround = HISI_EXPAND_CPBM_WD, + }, { NULL } /* Sentinel */ }; @@ -653,21 +678,26 @@ static void mpam_enable_quirks(struct mpam_msc *msc) } } -u16 mpam_cpbm_wd_hisi_workaround(u16 cpbm_wd, enum mpam_device_features feat, - u8 cache_level) +void mpam_cpbm_wd_hisi_workaround(u16 cpor_idr_cpbm_wd, struct mpam_class *class) { - if (cache_level != 3) - return cpbm_wd; + struct cpu_cacheinfo *cpu_cinfo; + struct cacheinfo *cinfo; + + if (hisi_config_cpbm_wd) + return; - if (is_midr_in_range_list(hip12_cpus)) { - if (feat == mpam_feat_cpor_part) - return 19; - else if (feat == mpam_feat_ccap_part || - feat == mpam_feat_cmin) - return 21; + cpu_cinfo = get_cpu_cacheinfo(smp_processor_id()); + for (unsigned int i = 0; i < cpu_cinfo->num_leaves; i++) { + cinfo = &cpu_cinfo->info_list[i]; + if (cinfo->level == class->level) { + hisi_config_cpbm_wd = cinfo->ways_of_associativity; + hisi_hardware_cpbm_wd = hisi_config_cpbm_wd * 2 - cpor_idr_cpbm_wd; + hisi_valid_cpbm_mask = BIT_MASK(cpor_idr_cpbm_wd) - 1; + return; + } } - return cpbm_wd; + return; } static struct dentry *mpam_debugfs; @@ -700,9 +730,11 @@ static void mpam_ris_hw_probe(struct mpam_msc_ris *ris) if (FIELD_GET(MPAMF_IDR_HAS_CPOR_PART, ris->idr)) { ris->cpor_idr = mpam_read_partsel_reg(msc, CPOR_IDR); - props->cpbm_wd = mpam_cpbm_wd_hisi_workaround( - FIELD_GET(MPAMF_CPOR_IDR_CPBM_WD, ris->cpor_idr), - mpam_feat_cpor_part, class->level); + props->cpbm_wd = FIELD_GET(MPAMF_CPOR_IDR_CPBM_WD, ris->cpor_idr); + + if (mpam_has_quirk(HISI_EXPAND_CPBM_WD, msc)) + mpam_cpbm_wd_hisi_workaround(props->cpbm_wd, class); + if (props->cpbm_wd) mpam_set_feature(mpam_feat_cpor_part, props); } @@ -1399,37 +1431,25 @@ static void mpam_reset_msc_bitmap(struct mpam_msc *msc, u16 reg, u16 wd) __mpam_write_reg(msc, reg, bm); } -static u32 mpam_cpbm_hisi_workaround(u32 cpbm, u8 cache_level) +/* + * Hardware restriction: cpor_idr_cpbm_wd to hisi_hardware_cpbm_wd + * only have half the normal capacity. + */ +static u32 mpam_cpbm_hisi_workaround(u32 cpbm, struct mpam_class *class) { - if (cache_level != 3 || !is_midr_in_range_list(hip12_cpus)) - return cpbm; - - if (cpbm & BIT(18)) - cpbm |= (BIT(19) | BIT(20)); - - if (cpbm & BIT(17)) - cpbm |= BIT(18); - else - cpbm &= ~BIT(18); + u16 cpor_idr_cpbm_wd, shift, i; + cpor_idr_cpbm_wd = class->props.cpbm_wd; + for (i = hisi_config_cpbm_wd - 1; i >= cpor_idr_cpbm_wd; i--) { + shift = i * 2 - cpor_idr_cpbm_wd; + if (cpbm & BIT(i)) + cpbm |= GENMASK(shift + 1, shift); + else + cpbm &= ~GENMASK(shift + 1, shift); + } return cpbm; } -bool mpam_cpbm_hisi_check_invalid(struct rdt_resource *r, - unsigned long val) -{ - if (!is_midr_in_range_list(hip12_cpus)) - return false; - - if (r->cache_level != 3) - return false; - - if (val & ~(BIT(18) | BIT(17))) - return false; - - return true; -} - static u16 mpam_intpri_default_val(struct mpam_msc_ris *ris) { struct mpam_class *class = ris->comp->class; @@ -1486,16 +1506,21 @@ static void mpam_reprogram_ris_partid(struct mpam_msc_ris *ris, u16 partid, } if (mpam_has_feature(mpam_feat_cpor_part, rprops)) { - if (mpam_has_feature(mpam_feat_cpor_part, cfg)) - mpam_write_partsel_reg(msc, CPBM, - mpam_cpbm_hisi_workaround(cfg->cpbm, - ris->comp->class->level)); - else - mpam_reset_msc_bitmap(msc, MPAMCFG_CPBM, - mpam_cpbm_wd_hisi_workaround( - rprops->cpbm_wd, - mpam_feat_cpor_part, - ris->comp->class->level)); + if (mpam_has_feature(mpam_feat_cpor_part, cfg)) { + u32 cpbm = cfg->cpbm; + + if (mpam_has_quirk(HISI_EXPAND_CPBM_WD, msc)) + cpbm = mpam_cpbm_hisi_workaround(cpbm, ris->comp->class); + + mpam_write_partsel_reg(msc, CPBM, cpbm); + } else { + u16 cpbm_wd = rprops->cpbm_wd; + + if (mpam_has_quirk(HISI_EXPAND_CPBM_WD, msc)) + cpbm_wd = hisi_hardware_cpbm_wd; + + mpam_reset_msc_bitmap(msc, MPAMCFG_CPBM, cpbm_wd); + } } if (mpam_has_feature(mpam_feat_ccap_part, rprops)) { diff --git a/drivers/platform/mpam/mpam_internal.h b/drivers/platform/mpam/mpam_internal.h index acce68708de2..65bcae070d99 100644 --- a/drivers/platform/mpam/mpam_internal.h +++ b/drivers/platform/mpam/mpam_internal.h @@ -27,6 +27,11 @@ DECLARE_STATIC_KEY_FALSE(mpam_enabled); */ #define MPAM_RESTRL_EVT_CONFIG_VALID (READS_TO_LOCAL_MEM | NON_TEMP_WRITE_TO_LOCAL_MEM) +/* Values for the HISI workaround */ +extern u16 hisi_config_cpbm_wd; +extern u16 hisi_hardware_cpbm_wd; +extern u32 hisi_valid_cpbm_mask; + static inline bool mpam_is_enabled(void) { return static_branch_likely(&mpam_enabled); @@ -149,6 +154,7 @@ static inline void mpam_clear_feature(enum mpam_device_features feat, /* Workaround bits for msc->quirks */ enum mpam_device_quirks { HISI_SHRINK_PMG_MAX, + HISI_EXPAND_CPBM_WD, MPAM_QUIRK_LAST }; @@ -367,8 +373,6 @@ int mpam_resctrl_offline_cpu(unsigned int cpu); int mpam_resctrl_setup(void); void mpam_resctrl_exit(void); -u16 mpam_cpbm_wd_hisi_workaround(u16 cpbm_wd, enum mpam_device_features feat, u8 cache_level); -bool mpam_cpbm_hisi_check_invalid(struct rdt_resource *r, unsigned long val); u32 mpam_min_cbm_bits(enum resctrl_res_level rid); /* diff --git a/drivers/platform/mpam/mpam_resctrl.c b/drivers/platform/mpam/mpam_resctrl.c index a67fc24b3b04..d04e1f0b1911 100644 --- a/drivers/platform/mpam/mpam_resctrl.c +++ b/drivers/platform/mpam/mpam_resctrl.c @@ -880,7 +880,7 @@ static u16 percent_to_mbw_max(u32 pc, u8 wd) return value; } -static u16 percent_to_ca_max(u32 pc, u8 wd) +static u16 percent_to_ca_max(u32 pc, u8 wd, struct mpam_class *class) { struct rdt_resource *l3 = resctrl_arch_get_resource(RDT_RESOURCE_L3); u32 valid_max, ca_max; @@ -888,9 +888,10 @@ static u16 percent_to_ca_max(u32 pc, u8 wd) if (read_cpuid_implementor() != ARM_CPU_IMP_HISI) return percent_to_mbw_max(pc, wd); - valid_max = mpam_cpbm_wd_hisi_workaround(l3->cache.cbm_len, - mpam_feat_ccap_part, - l3->cache_level); + valid_max = l3->cache.cbm_len; + + if (mpam_has_quirk(HISI_EXPAND_CPBM_WD, class)) + valid_max = hisi_hardware_cpbm_wd; if (pc >= MAX_MBA_BW) return valid_max << (16 - wd); @@ -899,7 +900,7 @@ static u16 percent_to_ca_max(u32 pc, u8 wd) return ca_max << (16 - wd); } -static u16 ca_max_to_percent(u16 ca_max, u8 wd) +static u16 ca_max_to_percent(u16 ca_max, u8 wd, struct mpam_class *class) { struct rdt_resource *l3 = resctrl_arch_get_resource(RDT_RESOURCE_L3); u32 valid_max; @@ -907,9 +908,10 @@ static u16 ca_max_to_percent(u16 ca_max, u8 wd) if (read_cpuid_implementor() != ARM_CPU_IMP_HISI) return mbw_max_to_percent(ca_max, wd); - valid_max = mpam_cpbm_wd_hisi_workaround(l3->cache.cbm_len, - mpam_feat_ccap_part, - l3->cache_level); + valid_max = l3->cache.cbm_len; + + if (mpam_has_quirk(HISI_EXPAND_CPBM_WD, class)) + valid_max = hisi_hardware_cpbm_wd; ca_max = ca_max >> (16 - wd); if (ca_max >= valid_max) @@ -1157,13 +1159,17 @@ static int mpam_resctrl_resource_init(struct mpam_resctrl_res *res) struct rdt_resource *r = &res->resctrl_res; bool has_mbwu = class_has_usable_mbwu(class); bool has_csu = cache_has_usable_csu(class); + u16 cpbm_wd; /* Is this one of the two well-known caches? */ switch (res->resctrl_res.rid) { case RDT_RESOURCE_L2: case RDT_RESOURCE_L3: + cpbm_wd = class->props.cpbm_wd; + if (mpam_has_quirk(HISI_EXPAND_CPBM_WD, class)) + cpbm_wd = hisi_config_cpbm_wd; /* TODO: Scaling is not yet supported */ - r->cache.cbm_len = class->props.cpbm_wd; + r->cache.cbm_len = cpbm_wd; r->cache.arch_has_sparse_bitmasks = true; /* mpam_devices will reject empty bitmaps */ @@ -1173,8 +1179,8 @@ static int mpam_resctrl_resource_init(struct mpam_resctrl_res *res) r->format_str = "%d=%0*x"; r->schema_fmt = RESCTRL_SCHEMA_BITMAP; r->fflags = RFTYPE_RES_CACHE; - r->default_ctrl = BIT_MASK(class->props.cpbm_wd) - 1; - r->data_width = (class->props.cpbm_wd + 3) / 4; + r->default_ctrl = BIT_MASK(cpbm_wd) - 1; + r->data_width = (cpbm_wd + 3) / 4; r->cache_level = class->level; /* @@ -1653,9 +1659,9 @@ u32 resctrl_arch_get_config(struct rdt_resource *r, struct rdt_domain *d, /* TODO: Scaling is not yet supported */ return cfg->cpbm; case mpam_feat_ccap_part: - return ca_max_to_percent(cfg->cmax, cprops->cmax_wd); + return ca_max_to_percent(cfg->cmax, cprops->cmax_wd, res->class); case mpam_feat_cmin: - return ca_max_to_percent(cfg->cmin, cprops->cmax_wd); + return ca_max_to_percent(cfg->cmin, cprops->cmax_wd, res->class); case mpam_feat_intpri_part: return cfg->intpri; case mpam_feat_mbw_part: @@ -1709,7 +1715,8 @@ int resctrl_arch_update_one(struct rdt_resource *r, struct rdt_domain *d, switch (r->rid) { case RDT_RESOURCE_L2: case RDT_RESOURCE_L3: - if (mpam_cpbm_hisi_check_invalid(r, cfg_val)) + if (mpam_has_quirk(HISI_EXPAND_CPBM_WD, res->class) && + !(cfg_val & hisi_valid_cpbm_mask)) return -EINVAL; /* TODO: Scaling is not yet supported */ @@ -1718,12 +1725,12 @@ int resctrl_arch_update_one(struct rdt_resource *r, struct rdt_domain *d, break; case RDT_RESOURCE_L2_MAX: case RDT_RESOURCE_L3_MAX: - cfg.cmax = percent_to_ca_max(cfg_val, cprops->cmax_wd); + cfg.cmax = percent_to_ca_max(cfg_val, cprops->cmax_wd, res->class); mpam_set_feature(mpam_feat_ccap_part, &cfg); break; case RDT_RESOURCE_L2_MIN: case RDT_RESOURCE_L3_MIN: - cfg.cmin = percent_to_ca_max(cfg_val, cprops->cmax_wd); + cfg.cmin = percent_to_ca_max(cfg_val, cprops->cmax_wd, res->class); mpam_set_feature(mpam_feat_cmin, &cfg); break; case RDT_RESOURCE_L2_PRI: -- 2.33.0
driver inclusion category: bugfix bugzilla: https://atomgit.com/openeuler/kernel/issues/9840 ---------------------------------------------------------------------- Add workaround for hisi min_cbm When a specific device cannot be identified through the IIDR. Signed-off-by: Yifan Wu <wuyifan50@huawei.com> Signed-off-by: Hongye Lin <linhongye@h-partners.com> --- drivers/platform/mpam/mpam_devices.c | 31 ++++++++++++++++++--------- drivers/platform/mpam/mpam_internal.h | 3 +-- drivers/platform/mpam/mpam_resctrl.c | 6 +++++- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/drivers/platform/mpam/mpam_devices.c b/drivers/platform/mpam/mpam_devices.c index 6b9b7433b360..687dfa77d991 100644 --- a/drivers/platform/mpam/mpam_devices.c +++ b/drivers/platform/mpam/mpam_devices.c @@ -635,6 +635,19 @@ static int mpam_enable_quirk_hisi_cpbm_wd(struct mpam_msc *msc, const struct mpa return -EINVAL; } +static int mpam_enable_quirk_hisi_min_cbm(struct mpam_msc *msc, const struct mpam_quirk *quirk) +{ + struct mpam_msc_ris *ris; + + list_for_each_entry(ris, &msc->ris, msc_list) { + struct mpam_class *class = ris->comp->class; + + if (class->type == MPAM_CLASS_CACHE && class->level == 2) + return 0; + } + return -EINVAL; +} + static const struct mpam_quirk mpam_quirks[] = { { .iidr_mask = MPAM_IIDR_MATCH_ONE, @@ -654,6 +667,14 @@ static const struct mpam_quirk mpam_quirks[] = { {} }, .workaround = HISI_EXPAND_CPBM_WD, }, + { + .init = mpam_enable_quirk_hisi_min_cbm, + .iidr_mask = MPAM_IIDR_MATCH_ONE, + .plat = (struct acpi_platform_list[]) { + HIP13_ACPI_PLAT, + {} }, + .workaround = HISI_SHRINK_MIN_CBM, + }, { NULL } /* Sentinel */ }; @@ -1127,16 +1148,6 @@ static u64 mpam_csu_hisi_need_halved(struct mpam_msc_ris *ris, u64 now) return now >> 1; } -u32 mpam_min_cbm_bits(enum resctrl_res_level rid) -{ - if (rid == RDT_RESOURCE_L2) { - if (is_midr_in_range_list(hip13_cpus)) - return 0; - } - - return 1; -} - static bool read_msmon_mbwu_is_overflow(struct mpam_msc *msc) { u32 ctl; diff --git a/drivers/platform/mpam/mpam_internal.h b/drivers/platform/mpam/mpam_internal.h index 65bcae070d99..a3fa32d30ced 100644 --- a/drivers/platform/mpam/mpam_internal.h +++ b/drivers/platform/mpam/mpam_internal.h @@ -155,6 +155,7 @@ static inline void mpam_clear_feature(enum mpam_device_features feat, enum mpam_device_quirks { HISI_SHRINK_PMG_MAX, HISI_EXPAND_CPBM_WD, + HISI_SHRINK_MIN_CBM, MPAM_QUIRK_LAST }; @@ -373,8 +374,6 @@ int mpam_resctrl_offline_cpu(unsigned int cpu); int mpam_resctrl_setup(void); void mpam_resctrl_exit(void); -u32 mpam_min_cbm_bits(enum resctrl_res_level rid); - /* * MPAM MSCs have the following register layout. See: * Arm Architecture Reference Manual Supplement - Memory System Resource diff --git a/drivers/platform/mpam/mpam_resctrl.c b/drivers/platform/mpam/mpam_resctrl.c index d04e1f0b1911..5e937badb203 100644 --- a/drivers/platform/mpam/mpam_resctrl.c +++ b/drivers/platform/mpam/mpam_resctrl.c @@ -1173,7 +1173,11 @@ static int mpam_resctrl_resource_init(struct mpam_resctrl_res *res) r->cache.arch_has_sparse_bitmasks = true; /* mpam_devices will reject empty bitmaps */ - r->cache.min_cbm_bits = mpam_min_cbm_bits(res->resctrl_res.rid); + r->cache.min_cbm_bits = 1; + + /* HIP13 supports disabling L2 cache entirely by setting CPBM to zero */ + if (mpam_has_quirk(HISI_SHRINK_MIN_CBM, class)) + r->cache.min_cbm_bits = 0; /* TODO: kill these properties off as they are derivatives */ r->format_str = "%d=%0*x"; -- 2.33.0
driver inclusion category: bugfix bugzilla: https://atomgit.com/openeuler/kernel/issues/9840 ---------------------------------------------------------------------- Add workaround for hisi csu When a specific device cannot be identified through the IIDR. On specific platforms, __ris_msmon_read requires resetting the CSU. Multiple MSCs within the same component may not become nrdy simultaneously; setting reset_on_next_read separately within __ris_msmon_read could result in different reset_on_next_read values for different MSCs. Therefore, set the component's reset_on_next_read prior to invoking __ris_msmon_read. Signed-off-by: Yifan Wu <wuyifan50@huawei.com> Signed-off-by: Hongye Lin <linhongye@h-partners.com> --- drivers/platform/mpam/mpam_devices.c | 128 +++++++++++++++++--------- drivers/platform/mpam/mpam_internal.h | 6 ++ 2 files changed, 92 insertions(+), 42 deletions(-) diff --git a/drivers/platform/mpam/mpam_devices.c b/drivers/platform/mpam/mpam_devices.c index 687dfa77d991..74e02ca99e27 100644 --- a/drivers/platform/mpam/mpam_devices.c +++ b/drivers/platform/mpam/mpam_devices.c @@ -648,6 +648,19 @@ static int mpam_enable_quirk_hisi_min_cbm(struct mpam_msc *msc, const struct mpa return -EINVAL; } +static int mpam_enable_quirk_hisi_csu(struct mpam_msc *msc, const struct mpam_quirk *quirk) +{ + struct mpam_msc_ris *ris; + + list_for_each_entry(ris, &msc->ris, msc_list) { + struct mpam_class *class = ris->comp->class; + + if (class->type == MPAM_CLASS_CACHE && class->level == 3) + return 0; + } + return -EINVAL; +} + static const struct mpam_quirk mpam_quirks[] = { { .iidr_mask = MPAM_IIDR_MATCH_ONE, @@ -675,6 +688,16 @@ static const struct mpam_quirk mpam_quirks[] = { {} }, .workaround = HISI_SHRINK_MIN_CBM, }, + { + .init = mpam_enable_quirk_hisi_csu, + .iidr_mask = MPAM_IIDR_MATCH_ONE, + .plat = (struct acpi_platform_list[]) { + HIP12_ACPI_PLAT, + HIP12B_ACPI_PLAT, + HIP13_ACPI_PLAT, + {} }, + .workaround = HISI_CSU_WORKAROUND, + }, { NULL } /* Sentinel */ }; @@ -1058,22 +1081,6 @@ static void read_msmon_ctl_flt_vals(struct mon_read *m, u32 *ctl_val, } } -static bool mpam_csu_hisi_need_retrigger(struct mpam_msc_ris *ris, - bool read_again) -{ - if (ris->comp->class->type != MPAM_CLASS_CACHE || - ris->comp->class->level != 3) - return false; - - if (!is_midr_in_range_list(hisi_cpus)) - return false; - - if (read_again) - return false; - - return true; -} - static void write_msmon_ctl_flt_vals(struct mon_read *m, u32 ctl_val, u32 flt_val) { @@ -1136,18 +1143,6 @@ static bool mpam_ris_has_nrdy_bit(struct mpam_msc_ris *ris) return true; } -static u64 mpam_csu_hisi_need_halved(struct mpam_msc_ris *ris, u64 now) -{ - if (!is_midr_in_range_list(hisi_cpus)) - return now; - - if (ris->comp->class->type != MPAM_CLASS_CACHE || - ris->comp->class->level != 3) - return now; - - return now >> 1; -} - static bool read_msmon_mbwu_is_overflow(struct mpam_msc *msc) { u32 ctl; @@ -1176,6 +1171,7 @@ static void __ris_msmon_read(void *arg) struct mpam_msc_ris *ris = m->ris; struct mpam_msc *msc = m->ris->msc; struct msmon_mbwu_state *mbwu_state = NULL; + struct msmon_csu_state *csu_state = NULL; u32 mon_sel, ctl_val, flt_val, cur_ctl, cur_flt; lockdep_assert_held(&msc->lock); @@ -1187,8 +1183,8 @@ static void __ris_msmon_read(void *arg) /* Selects a monitor instance to configure PARTID. */ wmb(); - - if (m->type == mpam_feat_msmon_mbwu) { + switch (m->type) { + case mpam_feat_msmon_mbwu: mbwu_state = &ris->mbwu_state[ctx->mon]; if (mbwu_state) { reset_on_next_read = mbwu_state->reset_on_next_read; @@ -1199,6 +1195,16 @@ static void __ris_msmon_read(void *arg) } mbwu_overflow = read_msmon_mbwu_is_overflow(msc); + break; + case mpam_feat_msmon_csu: + csu_state = &ris->csu_state[ctx->mon]; + if (csu_state) { + reset_on_next_read = csu_state->reset_on_next_read; + csu_state->reset_on_next_read = false; + } + break; + default: + return; } /* @@ -1210,8 +1216,7 @@ static void __ris_msmon_read(void *arg) config_mismatch = cur_flt != flt_val || cur_ctl != (ctl_val | MSMON_CFG_x_CTL_EN); - if (config_mismatch || reset_on_next_read || - mpam_csu_hisi_need_retrigger(ris, m->err == -EBUSY)) { + if (config_mismatch || reset_on_next_read) { write_msmon_ctl_flt_vals(m, ctl_val, flt_val); if (mbwu_state) { mbwu_state->correction = 0; @@ -1230,7 +1235,9 @@ static void __ris_msmon_read(void *arg) now = mpam_read_monsel_reg(msc, CSU); nrdy = now & MSMON___NRDY; now = FIELD_GET(MSMON___VALUE, now); - now = mpam_csu_hisi_need_halved(ris, now); + if (!nrdy && mpam_has_quirk(HISI_CSU_WORKAROUND, msc)) { + now >>= 1; + } break; case mpam_feat_msmon_mbwu: /* @@ -1328,9 +1335,12 @@ static int _msmon_read(struct mpam_component *comp, struct mon_read *arg) int mpam_msmon_read(struct mpam_component *comp, struct mon_cfg *ctx, enum mpam_device_features type, u64 *val) { - struct mon_read arg; struct mpam_props *cprops = &comp->class->props; - int err = 0; + struct mpam_msc_ris *ris; + struct mpam_msc *msc; + struct mon_read arg; + unsigned long flags; + int err = 0, idx; might_sleep(); @@ -1347,6 +1357,18 @@ int mpam_msmon_read(struct mpam_component *comp, struct mon_cfg *ctx, arg.err = 0; *val = 0; + if (mpam_has_quirk(HISI_CSU_WORKAROUND, comp->class)) { + idx = srcu_read_lock(&mpam_srcu); + list_for_each_entry_rcu(ris, &comp->ris, comp_list) { + msc = ris->msc; + spin_lock_irqsave(&msc->mon_sel_lock, flags); + if (ris->csu_state) + ris->csu_state[ctx->mon].reset_on_next_read = true; + spin_unlock_irqrestore(&msc->mon_sel_lock, flags); + } + srcu_read_unlock(&mpam_srcu, idx); + } + err = _msmon_read(comp, &arg); if (err == -EBUSY && comp->class->nrdy_usec) { fsleep(comp->class->nrdy_usec); @@ -2478,6 +2500,7 @@ static void __destroy_component_cfg(struct mpam_component *comp) unsigned long flags; struct mpam_msc_ris *ris; struct msmon_mbwu_state *mbwu_state; + struct msmon_csu_state *csu_state; kfree(comp->cfg); comp->cfg = NULL; @@ -2485,11 +2508,14 @@ static void __destroy_component_cfg(struct mpam_component *comp) mutex_lock(&ris->msc->lock); spin_lock_irqsave(&ris->msc->mon_sel_lock, flags); mbwu_state = ris->mbwu_state; + csu_state = ris->csu_state; ris->mbwu_state = NULL; + ris->csu_state = NULL; spin_unlock_irqrestore(&ris->msc->mon_sel_lock, flags); mutex_unlock(&ris->msc->lock); kfree(mbwu_state); + kfree(csu_state); } } @@ -2497,7 +2523,8 @@ static int __allocate_component_cfg(struct mpam_component *comp) { unsigned long flags; struct mpam_msc_ris *ris; - struct msmon_mbwu_state *mbwu_state; + struct msmon_mbwu_state *mbwu_state = NULL; + struct msmon_csu_state *csu_state = NULL; if (comp->cfg) return 0; @@ -2508,24 +2535,41 @@ static int __allocate_component_cfg(struct mpam_component *comp) return -ENOMEM; list_for_each_entry(ris, &comp->ris, comp_list) { - if (!ris->props.num_mbwu_mon) + if (!ris->props.num_mbwu_mon && !ris->props.num_csu_mon) continue; - mbwu_state = kcalloc(ris->props.num_mbwu_mon, - sizeof(*ris->mbwu_state), GFP_KERNEL); - if (!mbwu_state) { - __destroy_component_cfg(comp); - return -ENOMEM; + mbwu_state = NULL; + csu_state = NULL; + + if (ris->props.num_mbwu_mon) { + mbwu_state = kcalloc(ris->props.num_mbwu_mon, + sizeof(*ris->mbwu_state), GFP_KERNEL); + if (!mbwu_state) + goto out; + } + + if (ris->props.num_csu_mon) { + csu_state = kcalloc(ris->props.num_csu_mon, + sizeof(*ris->csu_state), GFP_KERNEL); + if (!csu_state) + goto out; } mutex_lock(&ris->msc->lock); spin_lock_irqsave(&ris->msc->mon_sel_lock, flags); ris->mbwu_state = mbwu_state; + ris->csu_state = csu_state; spin_unlock_irqrestore(&ris->msc->mon_sel_lock, flags); mutex_unlock(&ris->msc->lock); } return 0; + +out: + kfree(mbwu_state); + kfree(csu_state); + __destroy_component_cfg(comp); + return -ENOMEM; } static int mpam_allocate_config(void) diff --git a/drivers/platform/mpam/mpam_internal.h b/drivers/platform/mpam/mpam_internal.h index a3fa32d30ced..33409472eb25 100644 --- a/drivers/platform/mpam/mpam_internal.h +++ b/drivers/platform/mpam/mpam_internal.h @@ -156,6 +156,7 @@ enum mpam_device_quirks { HISI_SHRINK_PMG_MAX, HISI_EXPAND_CPBM_WD, HISI_SHRINK_MIN_CBM, + HISI_CSU_WORKAROUND, MPAM_QUIRK_LAST }; @@ -275,6 +276,10 @@ struct msmon_mbwu_state { u64 correction; }; +struct msmon_csu_state { + bool reset_on_next_read; +}; + struct mpam_msc_ris { u8 ris_idx; u64 idr; @@ -297,6 +302,7 @@ struct mpam_msc_ris { /* msmon mbwu configuration is preserved over reset */ struct msmon_mbwu_state *mbwu_state; + struct msmon_csu_state *csu_state; struct dentry *debugfs; }; -- 2.33.0
driver inclusion category: bugfix bugzilla: https://atomgit.com/openeuler/kernel/issues/9840 ---------------------------------------------------------------------- Add workaround for hisi llc gran When a specific device cannot be identified through the IIDR. Signed-off-by: Yifan Wu <wuyifan50@huawei.com> Signed-off-by: Hongye Lin <linhongye@h-partners.com> --- drivers/platform/mpam/mpam_devices.c | 37 ++++++++++++++++++ drivers/platform/mpam/mpam_internal.h | 1 + drivers/platform/mpam/mpam_resctrl.c | 56 +++++++++++++-------------- 3 files changed, 66 insertions(+), 28 deletions(-) diff --git a/drivers/platform/mpam/mpam_devices.c b/drivers/platform/mpam/mpam_devices.c index 74e02ca99e27..d1686290ac35 100644 --- a/drivers/platform/mpam/mpam_devices.c +++ b/drivers/platform/mpam/mpam_devices.c @@ -110,6 +110,13 @@ static const struct midr_range hisi_cpus[] = { }; /* Values for the HISI workaround */ +#define HIP09_ACPI_PLAT { "HISI ", "HIP09 ", 0, ACPI_SIG_MPAM, all_versions } +#define HIP09A_ACPI_PLAT { "HISI ", "HIP09A ", 0, ACPI_SIG_MPAM, all_versions } +#define HIP10_ACPI_PLAT { "HISI ", "HIP10 ", 0, ACPI_SIG_MPAM, all_versions } +#define HIP10A_ACPI_PLAT { "HISI ", "HIP10A ", 0, ACPI_SIG_MPAM, all_versions } +#define HIP10B_ACPI_PLAT { "HISI ", "HIP10B ", 0, ACPI_SIG_MPAM, all_versions } +#define HIP10C_ACPI_PLAT { "HISI ", "HIP10C ", 0, ACPI_SIG_MPAM, all_versions } +#define HIP10D_ACPI_PLAT { "HISI ", "HIP10D ", 0, ACPI_SIG_MPAM, all_versions } #define HIP12_ACPI_PLAT { "HISI ", "HIP12 ", 0, ACPI_SIG_MPAM, all_versions } #define HIP12B_ACPI_PLAT { "HISI ", "HIP12B ", 0, ACPI_SIG_MPAM, all_versions } #define HIP13_ACPI_PLAT { "HISI ", "HIP13 ", 0, ACPI_SIG_MPAM, all_versions } @@ -661,6 +668,19 @@ static int mpam_enable_quirk_hisi_csu(struct mpam_msc *msc, const struct mpam_qu return -EINVAL; } +static int mpam_enable_quirk_hisi_llc_gran(struct mpam_msc *msc, const struct mpam_quirk *quirk) +{ + struct mpam_msc_ris *ris; + + list_for_each_entry(ris, &msc->ris, msc_list) { + struct mpam_class *class = ris->comp->class; + + if (class->type == MPAM_CLASS_CACHE && class->level == 3) + return 0; + } + return -EINVAL; +} + static const struct mpam_quirk mpam_quirks[] = { { .iidr_mask = MPAM_IIDR_MATCH_ONE, @@ -698,6 +718,23 @@ static const struct mpam_quirk mpam_quirks[] = { {} }, .workaround = HISI_CSU_WORKAROUND, }, + { + .init = mpam_enable_quirk_hisi_llc_gran, + .iidr_mask = MPAM_IIDR_MATCH_ONE, + .plat = (struct acpi_platform_list[]) { + HIP09_ACPI_PLAT, + HIP09A_ACPI_PLAT, + HIP10_ACPI_PLAT, + HIP10A_ACPI_PLAT, + HIP10B_ACPI_PLAT, + HIP10C_ACPI_PLAT, + HIP10D_ACPI_PLAT, + HIP12_ACPI_PLAT, + HIP12B_ACPI_PLAT, + HIP13_ACPI_PLAT, + {} }, + .workaround = HISI_EXPAND_LLC_GRAN, + }, { NULL } /* Sentinel */ }; diff --git a/drivers/platform/mpam/mpam_internal.h b/drivers/platform/mpam/mpam_internal.h index 33409472eb25..63e2b5c9a66f 100644 --- a/drivers/platform/mpam/mpam_internal.h +++ b/drivers/platform/mpam/mpam_internal.h @@ -157,6 +157,7 @@ enum mpam_device_quirks { HISI_EXPAND_CPBM_WD, HISI_SHRINK_MIN_CBM, HISI_CSU_WORKAROUND, + HISI_EXPAND_LLC_GRAN, MPAM_QUIRK_LAST }; diff --git a/drivers/platform/mpam/mpam_resctrl.c b/drivers/platform/mpam/mpam_resctrl.c index 5e937badb203..df9cc2201d24 100644 --- a/drivers/platform/mpam/mpam_resctrl.c +++ b/drivers/platform/mpam/mpam_resctrl.c @@ -885,19 +885,20 @@ static u16 percent_to_ca_max(u32 pc, u8 wd, struct mpam_class *class) struct rdt_resource *l3 = resctrl_arch_get_resource(RDT_RESOURCE_L3); u32 valid_max, ca_max; - if (read_cpuid_implementor() != ARM_CPU_IMP_HISI) - return percent_to_mbw_max(pc, wd); + if (mpam_has_quirk(HISI_EXPAND_LLC_GRAN, class)) { + valid_max = l3->cache.cbm_len; - valid_max = l3->cache.cbm_len; + if (mpam_has_quirk(HISI_EXPAND_CPBM_WD, class)) + valid_max = hisi_hardware_cpbm_wd; - if (mpam_has_quirk(HISI_EXPAND_CPBM_WD, class)) - valid_max = hisi_hardware_cpbm_wd; + if (pc >= MAX_MBA_BW) + return valid_max << (16 - wd); - if (pc >= MAX_MBA_BW) - return valid_max << (16 - wd); + ca_max = DIV_ROUND_UP(pc * valid_max, 100); + return ca_max << (16 - wd); + } - ca_max = DIV_ROUND_UP(pc * valid_max, 100); - return ca_max << (16 - wd); + return percent_to_mbw_max(pc, wd); } static u16 ca_max_to_percent(u16 ca_max, u8 wd, struct mpam_class *class) @@ -905,19 +906,20 @@ static u16 ca_max_to_percent(u16 ca_max, u8 wd, struct mpam_class *class) struct rdt_resource *l3 = resctrl_arch_get_resource(RDT_RESOURCE_L3); u32 valid_max; - if (read_cpuid_implementor() != ARM_CPU_IMP_HISI) - return mbw_max_to_percent(ca_max, wd); + if (mpam_has_quirk(HISI_EXPAND_LLC_GRAN, class)) { + valid_max = l3->cache.cbm_len; - valid_max = l3->cache.cbm_len; + if (mpam_has_quirk(HISI_EXPAND_CPBM_WD, class)) + valid_max = hisi_hardware_cpbm_wd; - if (mpam_has_quirk(HISI_EXPAND_CPBM_WD, class)) - valid_max = hisi_hardware_cpbm_wd; + ca_max = ca_max >> (16 - wd); + if (ca_max >= valid_max) + return MAX_MBA_BW; - ca_max = ca_max >> (16 - wd); - if (ca_max >= valid_max) - return MAX_MBA_BW; + return (ca_max * 100) / valid_max; + } - return (ca_max * 100) / valid_max; + return mbw_max_to_percent(ca_max, wd); } /* Test whether we can export MPAM_CLASS_CACHE:{2,3}? */ @@ -1138,18 +1140,16 @@ void resctrl_arch_reset_rmid_all(struct rdt_resource *r, struct rdt_domain *d) mpam_msmon_reset_all_mbwu(dom->comp); } -static void mpam_llc_gran_hisi_workaround(struct rdt_resource *r) +static void mpam_llc_gran_workaround(struct rdt_resource *r, struct mpam_class *class) { unsigned int cbm_len; - if (read_cpuid_implementor() != ARM_CPU_IMP_HISI) - return; - - if (r->fflags != RFTYPE_RES_CACHE || r->cache_level != 3) - return; + if (mpam_has_quirk(HISI_EXPAND_LLC_GRAN, class)) { + cbm_len = resctrl_arch_get_resource(RDT_RESOURCE_L3)->cache.cbm_len; + r->membw.bw_gran = max(100 / cbm_len, 1); + } - cbm_len = resctrl_arch_get_resource(RDT_RESOURCE_L3)->cache.cbm_len; - r->membw.bw_gran = max(100 / cbm_len, 1); + return; } static int mpam_resctrl_resource_init(struct mpam_resctrl_res *res) @@ -1277,7 +1277,7 @@ static int mpam_resctrl_resource_init(struct mpam_resctrl_res *res) r->membw.min_bw = 1; r->membw.bw_gran = max(100 / (1 << cprops->cmax_wd), 1); - mpam_llc_gran_hisi_workaround(r); + mpam_llc_gran_workaround(r, class); break; case RDT_RESOURCE_L3_MIN: @@ -1295,7 +1295,7 @@ static int mpam_resctrl_resource_init(struct mpam_resctrl_res *res) r->membw.min_bw = 0; r->membw.bw_gran = max(100 / (1 << cprops->cmax_wd), 1); - mpam_llc_gran_hisi_workaround(r); + mpam_llc_gran_workaround(r, class); break; case RDT_RESOURCE_MB_MIN: -- 2.33.0
driver inclusion category: bugfix bugzilla: https://atomgit.com/openeuler/kernel/issues/9840 ---------------------------------------------------------------------- Add workaround for hisi mbm When a specific device cannot be identified through the IIDR. Signed-off-by: Yifan Wu <wuyifan50@huawei.com> Signed-off-by: Hongye Lin <linhongye@h-partners.com> --- arch/x86/include/asm/resctrl.h | 2 ++ drivers/platform/mpam/mpam_devices.c | 47 ++++++++++----------------- drivers/platform/mpam/mpam_internal.h | 1 + drivers/platform/mpam/mpam_resctrl.c | 9 +++++ fs/resctrl/rdtgroup.c | 6 ++-- include/linux/arm_mpam.h | 2 +- 6 files changed, 34 insertions(+), 33 deletions(-) diff --git a/arch/x86/include/asm/resctrl.h b/arch/x86/include/asm/resctrl.h index 089742970cc1..6aa970e4beba 100644 --- a/arch/x86/include/asm/resctrl.h +++ b/arch/x86/include/asm/resctrl.h @@ -81,6 +81,8 @@ static inline void resctrl_arch_disable_mon(void) static_branch_dec_cpuslocked(&rdt_enable_key); } +static inline bool resctrl_arch_would_mbm_overflow(struct rdt_resource *r) { return true; } + /* * __resctrl_sched_in() - Writes the task's CLOSid/RMID to IA32_PQR_MSR * diff --git a/drivers/platform/mpam/mpam_devices.c b/drivers/platform/mpam/mpam_devices.c index d1686290ac35..8d0eb6d5a8ed 100644 --- a/drivers/platform/mpam/mpam_devices.c +++ b/drivers/platform/mpam/mpam_devices.c @@ -93,22 +93,6 @@ static DECLARE_WORK(mpam_broken_work, &mpam_disable); */ LIST_HEAD(mpam_classes); -static const struct midr_range hip12_cpus[] = { - MIDR_ALL_VERSIONS(MIDR_HISI_HIP12), - { /* sentinel */ } -}; - -static const struct midr_range hip13_cpus[] = { - MIDR_ALL_VERSIONS(MIDR_HISI_HIP13), - { /* sentinel */ } -}; - -static const struct midr_range hisi_cpus[] = { - MIDR_ALL_VERSIONS(MIDR_HISI_HIP12), - MIDR_ALL_VERSIONS(MIDR_HISI_HIP13), - { /* sentinel */ } -}; - /* Values for the HISI workaround */ #define HIP09_ACPI_PLAT { "HISI ", "HIP09 ", 0, ACPI_SIG_MPAM, all_versions } #define HIP09A_ACPI_PLAT { "HISI ", "HIP09A ", 0, ACPI_SIG_MPAM, all_versions } @@ -735,6 +719,22 @@ static const struct mpam_quirk mpam_quirks[] = { {} }, .workaround = HISI_EXPAND_LLC_GRAN, }, + { + .iidr_mask = MPAM_IIDR_MATCH_ONE, + .plat = (struct acpi_platform_list[]) { + /* Non-HiSilicon CPUs and HIP13 need overflow handling */ + HIP09_ACPI_PLAT, + HIP09A_ACPI_PLAT, + HIP10_ACPI_PLAT, + HIP10A_ACPI_PLAT, + HIP10B_ACPI_PLAT, + HIP10C_ACPI_PLAT, + HIP10D_ACPI_PLAT, + HIP12_ACPI_PLAT, + HIP12B_ACPI_PLAT, + {} }, + .workaround = HISI_SKIP_MBM_OVERFLOW, + }, { NULL } /* Sentinel */ }; @@ -1162,16 +1162,6 @@ static u64 mpam_msmon_overflow_val(struct mpam_msc_ris *ris) return GENMASK_ULL(30, 0) << ris->props.mbwu_scale; } -bool resctrl_arch_would_mbm_overflow(void) -{ - /* Non-HiSilicon CPUs and HIP13 need overflow handling */ - if (read_cpuid_implementor() != ARM_CPU_IMP_HISI) - return true; - - /* HIP13 is the exception among HiSilicon CPUs */ - return is_midr_in_range_list(hip13_cpus); -} - static bool mpam_ris_has_nrdy_bit(struct mpam_msc_ris *ris) { if (ris->comp->class->type == MPAM_CLASS_MEMORY) @@ -1311,9 +1301,8 @@ static void __ris_msmon_read(void *arg) * instead the scaled count of bytes transferred since the monitor * was last reset in the latest version (DDI0598D_b). */ - if (ris->comp->class->type == MPAM_CLASS_MEMORY) { - if (!resctrl_arch_would_mbm_overflow()) - break; + if (mpam_has_quirk(HISI_SKIP_MBM_OVERFLOW, msc)) { + break; } /* Add any pre-overflow value to the mbwu_state->val */ diff --git a/drivers/platform/mpam/mpam_internal.h b/drivers/platform/mpam/mpam_internal.h index 63e2b5c9a66f..023bf0240ce1 100644 --- a/drivers/platform/mpam/mpam_internal.h +++ b/drivers/platform/mpam/mpam_internal.h @@ -158,6 +158,7 @@ enum mpam_device_quirks { HISI_SHRINK_MIN_CBM, HISI_CSU_WORKAROUND, HISI_EXPAND_LLC_GRAN, + HISI_SKIP_MBM_OVERFLOW, MPAM_QUIRK_LAST }; diff --git a/drivers/platform/mpam/mpam_resctrl.c b/drivers/platform/mpam/mpam_resctrl.c index df9cc2201d24..938d3606209f 100644 --- a/drivers/platform/mpam/mpam_resctrl.c +++ b/drivers/platform/mpam/mpam_resctrl.c @@ -553,6 +553,15 @@ static bool mpam_skip_check_l2_overflow(struct mpam_component *comp, return ret; } +bool resctrl_arch_would_mbm_overflow(struct rdt_resource *r) +{ + struct mpam_resctrl_res *res; + + res = container_of(r, struct mpam_resctrl_res, resctrl_res); + + return !mpam_has_quirk(HISI_SKIP_MBM_OVERFLOW, res->class); +} + int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain *d, u32 closid, u32 rmid, enum resctrl_event_id eventid, u64 *val, void *arch_mon_ctx) diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index 58b070f76bb4..499848055cad 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -2692,7 +2692,7 @@ void resctrl_setup_dom_overflow(struct rdt_resource *r) struct rdt_domain *d; if (resctrl_arch_is_mbm_enabled(r->rid) && - resctrl_arch_would_mbm_overflow()) { + resctrl_arch_would_mbm_overflow(r)) { list_for_each_entry(d, &r->domains, list) mbm_setup_overflow_handler(d, MBM_OVERFLOW_INTERVAL, RESCTRL_PICK_ANY_CPU); @@ -4148,7 +4148,7 @@ int resctrl_online_domain(struct rdt_resource *r, struct rdt_domain *d) if (err) goto out_unlock; - if (resctrl_arch_is_mbm_enabled(r->rid) && resctrl_arch_would_mbm_overflow()) { + if (resctrl_arch_is_mbm_enabled(r->rid) && resctrl_arch_would_mbm_overflow(r)) { INIT_DELAYED_WORK(&d->mbm_over, mbm_handle_overflow); mbm_setup_overflow_handler(d, MBM_OVERFLOW_INTERVAL, RESCTRL_PICK_ANY_CPU); @@ -4199,7 +4199,7 @@ void resctrl_setup_dom_overflow_exclude_cpu(struct rdt_resource *r, if (resctrl_arch_is_mbm_enabled(r->rid) && exclude_cpu == d->mbm_work_cpu && - resctrl_arch_would_mbm_overflow()) { + resctrl_arch_would_mbm_overflow(r)) { mutex_unlock(&rdtgroup_mutex); cancel_delayed_work_sync(&d->mbm_over); mutex_lock(&rdtgroup_mutex); diff --git a/include/linux/arm_mpam.h b/include/linux/arm_mpam.h index 25c62a42bd2c..7487b28a792c 100644 --- a/include/linux/arm_mpam.h +++ b/include/linux/arm_mpam.h @@ -69,7 +69,6 @@ bool resctrl_arch_is_mbm_core_enabled(void); bool resctrl_arch_is_mbm_local_enabled(void); bool resctrl_arch_is_mbm_total_enabled(void); bool resctrl_arch_is_mbm_enabled(enum resctrl_res_level rid); -bool resctrl_arch_would_mbm_overflow(void); /* reset cached configurations, then all devices */ void resctrl_arch_reset_resources(void); @@ -104,6 +103,7 @@ void resctrl_arch_rmid_idx_decode(u32 idx, u32 *closid, u32 *rmid); u32 resctrl_arch_system_num_rmid_idx(void); struct rdt_resource; +bool resctrl_arch_would_mbm_overflow(struct rdt_resource *r); void *resctrl_arch_mon_ctx_alloc(struct rdt_resource *r, int evtid); void resctrl_arch_mon_ctx_free(struct rdt_resource *r, int evtid, void *ctx); -- 2.33.0
反馈: 您发送到kernel@openeuler.org的补丁/补丁集,已成功转换为PR! PR链接地址: https://atomgit.com/openeuler/kernel/merge_requests/30943 邮件列表地址:https://mailweb.openeuler.org/archives/list/kernel@openeuler.org/message/6PD... FeedBack: The patch(es) which you have sent to kernel@openeuler.org mailing list has been converted to a pull request successfully! Pull request link: https://atomgit.com/openeuler/kernel/merge_requests/30943 Mailing list address: https://mailweb.openeuler.org/archives/list/kernel@openeuler.org/message/6PD...
participants (2)
-
patchwork bot -
Yifan Wu