Re: [PATCH v3 14/16] arm_mpam: add MPAM-Fb MSC firmware access support

From: Jonathan Cameron

Date: Fri Jul 10 2026 - 15:58:49 EST


On Fri, 10 Jul 2026 16:45:18 +0200
Andre Przywara <andre.przywara@xxxxxxx> wrote:

> The Arm MPAM Firmware-backed (Fb) Profile document[1] describes an
> alternative way of accessing the "Memory System Components" (MSC) in an
> MPAM enabled system.

Blank line for consistency on paragraph breaks.

> Normally the MSCs are MMIO mapped, but in some implementations this

Hmm. Not sure what normal is in this case ;) Maybe make it something like

In systems supported before this patch the MSCs are MMIO mapped,

> might not be possible (MSC located outside of the local socket, MSC
> mapped secure-only) or desirable (direct MMIO access too slow or needs
> to be mediated through a control processor). MPAM-fb standardises a
> protocol to abstract MSC accesses, building on the SCMI protocol.
>
> Add functions that do an MSC read or write access by redirecting the
> request through a firmware interface. For now this done via an ACPI
> PCC shared memory and mailbox combination.
>
> Since the protocol used is only a small subset of the full SCMI spec,
> and the SCMI protocol has no full ACPI support anyway, open-code the
> SCMI message generation and handshake, for just the fields we need.
>
> [1] https://developer.arm.com/documentation/den0144/latest
>
> Signed-off-by: Andre Przywara <andre.przywara@xxxxxxx>

Hi Andre,

Various things inline.

Thanks,

Jonathan

...

> diff --git a/drivers/resctrl/mpam_devices.c b/drivers/resctrl/mpam_devices.c
> index ca73029654b6..4d3e642486d4 100644
> --- a/drivers/resctrl/mpam_devices.c
> +++ b/drivers/resctrl/mpam_devices.c

> @@ -1133,7 +1139,8 @@ static int mpam_msc_read_mbwu_l(struct mpam_msc *msc, u64 *res)
>
> mpam_mon_sel_lock_held(msc);
>
> - WARN_ON_ONCE((MSMON_MBWU_L + sizeof(u64)) > msc->mapped_hwpage_sz);
> + if (msc->iface == MPAM_IFACE_MMIO)
> + WARN_ON_ONCE((MSMON_MBWU_L + sizeof(u64)) > msc->mapped_hwpage_sz);
> WARN_ON_ONCE(!cpumask_test_cpu(smp_processor_id(), &msc->accessibility));
>
> ret = __mpam_read_reg(msc, MSMON_MBWU_L + 4, &mbwu_l_high2);
> @@ -1481,9 +1488,15 @@ static int _msmon_read(struct mpam_component *comp, struct mon_read *arg)
> srcu_read_lock_held(&mpam_srcu)) {
> arg->ris = ris;
>
> - err = smp_call_function_any(&msc->accessibility,
> - __ris_msmon_read, arg,
> - true);
> + if (msc->iface == MPAM_IFACE_MMIO) {
> + err = smp_call_function_any(&msc->accessibility,
> + __ris_msmon_read,
> + arg, true);
> + } else {
> + __ris_msmon_read(arg);
> + err = 0;
> + }
> +
> if (!err && arg->err)
> err = arg->err;
FWIW
The arg->err check here seems pointless

if (!err)
err = arg->err;

is at most going to set a 0 to 0.

Maybe lift this into the if else as it should end up simpler in the else.

if (msc->iface == MPAM_IFACE_MMIO) {
err = smp_call_function_any(&msc->accessibility,
__ris_msmon_read,
arg, true);
if (!err)
err = arg->err;
} else {
__ris_msmon_read(arg);
err = arg->err;
}

if (err)
any_err = err;


...

> diff --git a/drivers/resctrl/mpam_fb.c b/drivers/resctrl/mpam_fb.c
> new file mode 100644
> index 000000000000..7d7409910f28
> --- /dev/null
> +++ b/drivers/resctrl/mpam_fb.c
> @@ -0,0 +1,208 @@
> +// SPDX-License-Identifier: GPL-2.0
> +// Copyright (C) 2024 Arm Ltd.

Really? sat on this for 2 years? ;)
Given it's changing during this posting I'd at least include this
year in the range.

> +
> +#include <linux/arm_mpam.h>
> +#include <linux/cleanup.h>
> +#include <linux/device.h>
> +#include <linux/errno.h>
> +#include <linux/gfp.h>
> +#include <linux/list.h>
> +#include <linux/mailbox_client.h>
> +#include <linux/mutex.h>
> +#include <linux/of.h>
> +#include <linux/of_platform.h>

Scrub these for things used in this patch.
Maybe others will be needed after later patches.
Not seeing any of_ stuff in here for instance.

> +#include <linux/platform_device.h>
> +#include <linux/printk.h>
> +#include <linux/processor.h>
> +#include <linux/slab.h>
> +#include <linux/spinlock.h>
> +#include <linux/types.h>

> +struct mpam_fb_access_payload {
> + u32 msc_id;
> + u32 flags;
> + u32 reg_offset;
> + u32 value;
> +} __packed;
There are only a few of these in spec, and whilst they share the same layout
for fields they define (not all same length),

I'd define separate structures for each of the message types.
Added bonus being that...

> +
> +#define PCC_CHAN_FLAGS_IRQ BIT(0)
> +#define MPAM_VERSION_MSG_SIZE (PCC_TYPE3_MSG_PAYLOAD_OFS)
> +#define MPAM_READ_MSG_SIZE (PCC_TYPE3_MSG_PAYLOAD_OFS + 3 * sizeof(u32))

These would then become PCC_TYPE3_MSG_PAYLOAD_OFF + sizeof(mpam_fb_read_request_payload)
or something self describing along those lines.

> +#define MPAM_WRITE_MSG_SIZE (PCC_TYPE3_MSG_PAYLOAD_OFS + 4 * sizeof(u32))
> +
> +static atomic_t mpam_fb_token = ATOMIC_INIT(0);
> +
> +static int mpam_fb_build_version_message(unsigned int token,
> + void __iomem *msg_buf)
> +{
> + struct acpi_pcct_ext_pcc_shared_memory *pcc_shmem = msg_buf;
> +
> + writel_relaxed(0, &pcc_shmem->flags);
> + writel_relaxed(MPAM_VERSION_MSG_SIZE, &pcc_shmem->length);
> + writel_relaxed(MPAM_PROTOCOL_VERSION |
> + FIELD_PREP(MPAM_MSC_TOKEN_MASK, token) |
> + FIELD_PREP(MPAM_MSC_PROT_ID_MASK, MPAM_FB_PROTOCOL_ID),
> + &pcc_shmem->command);
> +
> + return MPAM_VERSION_MSG_SIZE;
> +}
> +
> +static int mpam_fb_build_read_message(int msc_id, int reg, unsigned int token,
> + void __iomem *msg_buf)
> +{
> + struct acpi_pcct_ext_pcc_shared_memory *pcc_shmem = msg_buf;
> + struct mpam_fb_access_payload *payload = msg_buf + sizeof(*pcc_shmem);
> +
> + writel_relaxed(0, &pcc_shmem->flags);
> + writel_relaxed(MPAM_READ_MSG_SIZE, &pcc_shmem->length);
> + writel_relaxed(MPAM_MSC_READ_CMD |
> + FIELD_PREP(MPAM_MSC_TOKEN_MASK, token) |
> + FIELD_PREP(MPAM_MSC_PROT_ID_MASK, MPAM_FB_PROTOCOL_ID),
> + &pcc_shmem->command);
> +
> + writel_relaxed(msc_id, &payload->msc_id);
> + writel_relaxed(0, &payload->flags);
> + writel_relaxed(reg, &payload->reg_offset);
> +
> + return MPAM_READ_MSG_SIZE;
> +}

> +
> +static int mpam_fb_send_request(struct mpam_pcc_chan *pcc_chan, u32 msc_id,
> + u16 reg, u32 *result, int mpam_fb_command)
> +{
> + unsigned int token = atomic_inc_return(&mpam_fb_token);
> + struct acpi_pcct_ext_pcc_shared_memory *pcc_shmem;
> + struct pcc_mbox_chan *chan;
> + void __iomem *payload_ofs;
> + u32 status;
> + int ret;
> +
> + if (!pcc_chan)

Is this defense needed? Feels like the sort of thing that is so fatal
if you get to call send_request() that you should really have failed a lot
earlier. If it's protecting against a tear down race or similar add a comment

> + return -ENODEV;