Re: [RFC PATCH v2 2/4] iommu/riscv: Register independently tagged devices with resctrl
From: Drew Fustini
Date: Mon Nov 23 2026 - 02:48:46 EST
On Mon, Nov 16, 2026 at 03:13:41PM +0800, Zhanpeng Zhang wrote:
> Register independently tagged devices after default-domain setup and
> retain their IDs in driver-private state across domain changes. Program
> all firmware IDs under the context-update lock and report command
> completion failures to resctrl.
>
> The DC.ta field size does not describe the implemented QoS ID widths.
> Probe the low bits of the global write-any, read-legal fields with DDTP
> OFF and all queues disabled and idle. Preserve and verify restoration of
> the original register. If the widths cannot be obtained safely, do not
> register devices with resctrl. Reject IDs outside the probed range before
> changing any device context.
>
> Track exclusive device-context ownership without changing IOMMU core.
> Discovering an alias resets and unregisters any previous QoS owner before
> marking the context shared. Shared contexts are excluded from independent
> QoS assignment until IOMMU reprobe, without failing ordinary DMA probing.
> Serialize registration, alias discovery and release so an old owner
> cannot become independently assignable again after its context is shared.
>
> Signed-off-by: Zhanpeng Zhang <zhangzhanpeng.jasper@xxxxxxxxxxxxx>
[..]
> diff --git a/drivers/iommu/riscv/iommu.c b/drivers/iommu/riscv/iommu.c
> index fbdca69c436e..dd2ebb25312d 100644
> --- a/drivers/iommu/riscv/iommu.c
> +++ b/drivers/iommu/riscv/iommu.c
[..]
> +static void riscv_iommu_probe_qosid_limits(struct riscv_iommu_device *iommu)
[..]
> + iommu->qos_rcid_max = rcid;
> + iommu->qos_mcid_max = mcid;
> + iommu->qos_ids_valid = true;
The iommu spec requires rcid and mcid to be at least as wide as on any
hart, and resctrl only hands out IDs that the harts already use in
srmcfg. Maybe the limit probe could be dropped?
[..]
> diff --git a/drivers/iommu/riscv/iommu.h b/drivers/iommu/riscv/iommu.h
> index 5676001548cc..72bb536190d1 100644
> --- a/drivers/iommu/riscv/iommu.h
> +++ b/drivers/iommu/riscv/iommu.h
> @@ -15,6 +15,9 @@
> #include <linux/spinlock.h>
> #include <linux/types.h>
> #include <linux/iopoll.h>
> +#include <linux/mutex.h>
> +#include <linux/spinlock.h>
> +#include <linux/xarray.h>
spinlock.h is already included above.
Thanks,
Drew