Re: [PATCH v2 15/29] arm_mpam: Reset MSC controls from cpu hp callbacks

Jonathan Cameron
2025-09-12T11:55:40Z

On Wed, 10 Sep 2025 20:42:55 +0000
James Morse <james.morse@arm.com> wrote:

> When a CPU comes online, it may bring a newly accessible MSC with
> it. Only the default partid has its value reset by hardware, and
> even then the MSC might not have been reset since its config was
> previously dirtyied. e.g. Kexec.
>
> Any in-use partid must have its configuration restored, or reset.
> In-use partids may be held in caches and evicted later.
>
> MSC are also reset when CPUs are taken offline to cover cases where
> firmware doesn't reset the MSC over reboot using UEFI, or kexec
> where there is no firmware involvement.
>
> If the configuration for a RIS has not been touched since it was
> brought online, it does not need resetting again.
>
> To reset, write the maximum values for all discovered controls.
>
> CC: Rohit Mathew <Rohit.Mathew@arm.com>
> Signed-off-by: James Morse <james.morse@arm.com>
Just one trivial passing comment from me.

Jonathan

> ---
> Changes since RFC:
> * Last bitmap write will always be non-zero.
> * Dropped READ_ONCE() - teh value can no longer change.
> * Write 0 to proporitional stride, remove the bwa_fract variable.
> * Removed nested srcu lock, the assert should cover it.
> ---
> drivers/resctrl/mpam_devices.c | 117 ++++++++++++++++++++++++++++++++
> drivers/resctrl/mpam_internal.h | 8 +++
> 2 files changed, 125 insertions(+)
>
> diff --git a/drivers/resctrl/mpam_devices.c b/drivers/resctrl/mpam_devices.c
> index cd8e95fa5fd6..0353313cf284 100644
> --- a/drivers/resctrl/mpam_devices.c
> +++ b/drivers/resctrl/mpam_devices.c

>
> @@ -818,6 +921,20 @@ static int mpam_discovery_cpu_online(unsigned int cpu)
>
> static int mpam_cpu_offline(unsigned int cpu)
> {
> + int idx;
> + struct mpam_msc *msc;
> +
> + idx = srcu_read_lock(&mpam_srcu);

Might be worth using
guard(srcu)(&mpam_srcu);
here but only real advantage it bring is in hiding the local idx variable
away.

> + list_for_each_entry_srcu(msc, &mpam_all_msc, all_msc_list,
> + srcu_read_lock_held(&mpam_srcu)) {
> + if (!cpumask_test_cpu(cpu, &msc->accessibility))
> + continue;
> +
> + if (atomic_dec_and_test(&msc->online_refs))
> + mpam_reset_msc(msc, false);
> + }
> + srcu_read_unlock(&mpam_srcu, idx);
> +
> return 0;
> }