[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251107123450.664001-20-ben.horgan@arm.com>
Date: Fri, 7 Nov 2025 12:34:36 +0000
From: Ben Horgan <ben.horgan@....com>
To: james.morse@....com
Cc: amitsinght@...vell.com,
baisheng.gao@...soc.com,
baolin.wang@...ux.alibaba.com,
bobo.shaobowang@...wei.com,
carl@...amperecomputing.com,
catalin.marinas@....com,
dakr@...nel.org,
dave.martin@....com,
david@...hat.com,
dfustini@...libre.com,
fenghuay@...dia.com,
gregkh@...uxfoundation.org,
gshan@...hat.com,
guohanjun@...wei.com,
jeremy.linton@....com,
jonathan.cameron@...wei.com,
kobak@...dia.com,
lcherian@...vell.com,
lenb@...nel.org,
linux-acpi@...r.kernel.org,
linux-arm-kernel@...ts.infradead.org,
linux-kernel@...r.kernel.org,
lpieralisi@...nel.org,
peternewman@...gle.com,
quic_jiles@...cinc.com,
rafael@...nel.org,
robh@...nel.org,
rohit.mathew@....com,
scott@...amperecomputing.com,
sdonthineni@...dia.com,
sudeep.holla@....com,
tan.shaopeng@...itsu.com,
will@...nel.org,
xhao@...ux.alibaba.com,
Ben Horgan <ben.horgan@....com>,
Shaopeng Tan <tan.shaopeng@...fujitsu.com>
Subject: [PATCH 19/33] arm_mpam: Add a helper to touch an MSC from any CPU
From: James Morse <james.morse@....com>
Resetting RIS entries from the cpuhp callback is easy as the
callback occurs on the correct CPU. This won't be true for any other
caller that wants to reset or configure an MSC.
Add a helper that schedules the provided function if necessary.
Callers should take the cpuhp lock to prevent the cpuhp callbacks from
changing the MSC state.
Signed-off-by: James Morse <james.morse@....com>
Reviewed-by: Ben Horgan <ben.horgan@....com>
Reviewed-by: Jonathan Cameron <jonathan.cameron@...wei.com>
Reviewed-by: Fenghua Yu <fenghuay@...dia.com>
Tested-by: Fenghua Yu <fenghuay@...dia.com>
Tested-by: Shaopeng Tan <tan.shaopeng@...fujitsu.com>
Tested-by: Peter Newman <peternewman@...gle.com>
Signed-off-by: Ben Horgan <ben.horgan@....com>
---
drivers/resctrl/mpam_devices.c | 37 +++++++++++++++++++++++++++++++---
1 file changed, 34 insertions(+), 3 deletions(-)
diff --git a/drivers/resctrl/mpam_devices.c b/drivers/resctrl/mpam_devices.c
index 6a01247317b7..bcdf4fbc3941 100644
--- a/drivers/resctrl/mpam_devices.c
+++ b/drivers/resctrl/mpam_devices.c
@@ -807,20 +807,51 @@ static void mpam_reset_ris_partid(struct mpam_msc_ris *ris, u16 partid)
mutex_unlock(&msc->part_sel_lock);
}
-static void mpam_reset_ris(struct mpam_msc_ris *ris)
+/*
+ * Called via smp_call_on_cpu() to prevent migration, while still being
+ * pre-emptible.
+ */
+static int mpam_reset_ris(void *arg)
{
u16 partid, partid_max;
+ struct mpam_msc_ris *ris = arg;
WARN_ON_ONCE(!srcu_read_lock_held((&mpam_srcu)));
if (ris->in_reset_state)
- return;
+ return 0;
spin_lock(&partid_max_lock);
partid_max = mpam_partid_max;
spin_unlock(&partid_max_lock);
for (partid = 0; partid <= partid_max; partid++)
mpam_reset_ris_partid(ris, partid);
+
+ return 0;
+}
+
+/*
+ * Get the preferred CPU for this MSC. If it is accessible from this CPU,
+ * this CPU is preferred. This can be preempted/migrated, it will only result
+ * in more work.
+ */
+static int mpam_get_msc_preferred_cpu(struct mpam_msc *msc)
+{
+ int cpu = raw_smp_processor_id();
+
+ if (cpumask_test_cpu(cpu, &msc->accessibility))
+ return cpu;
+
+ return cpumask_first_and(&msc->accessibility, cpu_online_mask);
+}
+
+static int mpam_touch_msc(struct mpam_msc *msc, int (*fn)(void *a), void *arg)
+{
+ lockdep_assert_irqs_enabled();
+ lockdep_assert_cpus_held();
+ WARN_ON_ONCE(!srcu_read_lock_held((&mpam_srcu)));
+
+ return smp_call_on_cpu(mpam_get_msc_preferred_cpu(msc), fn, arg, true);
}
static void mpam_reset_msc(struct mpam_msc *msc, bool online)
@@ -828,7 +859,7 @@ static void mpam_reset_msc(struct mpam_msc *msc, bool online)
struct mpam_msc_ris *ris;
list_for_each_entry_srcu(ris, &msc->ris, msc_list, srcu_read_lock_held(&mpam_srcu)) {
- mpam_reset_ris(ris);
+ mpam_touch_msc(msc, &mpam_reset_ris, ris);
/*
* Set in_reset_state when coming online. The reset state
--
2.43.0
Powered by blists - more mailing lists