On Fri, 16 Oct 2026 18:10:40 +0800
Jinjie Ruan <[email protected]> wrote:

> From: Jinjie Ruan <[email protected]>
> 
> With mpam=on, create one mpam-msc-mem per NUMA node with memory
> (256 request PARTIDs narrowed to 32 internal PARTIDs), or with
> mpam-min-msc=on a single shared MSC with one RIS per memory node
> and extreme narrowing (2 internal PARTIDs).  MSC creation requires
> NUMA nodes to be specified.  Cache MSC creation arrives with the
> next patch.
> 
> Based on an RFC series by Jonathan Cameron, adapted to the current
> cache topology API (machine_get_cache_topo_level).
> 
> Signed-off-by: Jinjie Ruan <[email protected]>

A couple of formatting suggestions.  Otherwise LGTM
Reviewed-by: Jonathan Cameron <[email protected]>

> ---
>  hw/arm/virt.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 61 insertions(+)
> 
> diff --git a/hw/arm/virt.c b/hw/arm/virt.c
> index 3ad7de8..77942e7 100644
> --- a/hw/arm/virt.c
> +++ b/hw/arm/virt.c
> @@ -2144,6 +2144,63 @@ static void 
> create_virtio_iommu_dt_bindings(VirtMachineState *vms)
>  #define MPAM_VIRT_NUM_PARTID     256
>  #define MPAM_VIRT_NUM_INTPARTID  32
>  
> +static void create_mpam_msc(VirtMachineState *vms, Error **errp)
> +{
> +    MachineState *ms = MACHINE(vms);
> +    DeviceState *dev;
> +    int i, count = 0;
> +    hwaddr base = vms->memmap[VIRT_MPAM_MSC].base;
> +
> +    if (ms->numa_state->num_nodes == 0) {
> +        error_setg(errp,
> +                   "MPAM support requires NUMA nodes to be specified");
> +        return;
> +    }
> +    if (!vms->mpam_min_msc) {
> +        for (i = 0; i < ms->numa_state->num_nodes; i++) {

Perhaps pull the declaration of i into each loop just to be
clear that it is locally scoped.

> +            /* at most 16 mem MSCs (4-bit selector space, SPI budget) */
> +            if (ms->numa_state->nodes[i].node_mem > 0 && count < 16) {
Maybe flip logic to reduce indent.
            if (count >= 16)
                break;

            if (ms->numa_state->nodes[i].node_mem <= 0)
                continue;

            dev = ...

> +                dev = qdev_new(TYPE_MPAM_MSC_MEM);
> +
> +                object_property_set_uint(OBJECT(dev), "node", i,
> +                                         &error_fatal);

Perhaps with slightly lower indent and going a touch over 80 these might fit
on fewer lines.

> +                object_property_set_uint(OBJECT(dev), "num-ris", 1,
> +                                         &error_fatal);
> +                object_property_set_uint(OBJECT(dev), "num-partid",
> +                                         MPAM_VIRT_NUM_PARTID,
> +                                         &error_fatal);
> +                object_property_set_uint(OBJECT(dev), "num-int-partid",
> +                                         MPAM_VIRT_NUM_INTPARTID,
> +                                         &error_fatal);
> +                sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
> +                sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base);
> +                base += MPAM_SIZE;
> +                count++;
> +            }
> +        }
> +    } else {
> +        int count_with_mem = 0;
> +
> +        for (i = 0; i < ms->numa_state->num_nodes; i++) {
> +            if (ms->numa_state->nodes[i].node_mem) {
> +                count_with_mem++;
> +            }
> +        }
> +        dev = qdev_new(TYPE_MPAM_MSC_MEM);
> +        object_property_set_uint(OBJECT(dev), "num-ris", count_with_mem,
> +                                 &error_fatal);
> +        object_property_set_uint(OBJECT(dev), "num-partid",
> +                                 MPAM_VIRT_NUM_PARTID, &error_fatal);
> +        object_property_set_uint(OBJECT(dev), "num-int-partid",
> +                                 2, /* extreme narrowing */
> +                                 &error_fatal);
> +
> +        sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
> +        sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base);
> +        base += MPAM_SIZE;
> +    }
> +}



Reply via email to