Re: [PATCH v3 2/2] iommu/riscv: create a auxiliary device for HPM

From: Guo Ren

Date: Tue Jun 30 2026 - 21:43:37 EST


On Tue, Jun 30, 2026 at 4:38 PM Zong Li <zong.li@xxxxxxxxxx> wrote:
>
> Create an auxiliary device for HPM when the IOMMU supports a
> hardware performance monitor.
>
> Suggested-by: Samuel Holland <samuel.holland@xxxxxxxxxx>
> Signed-off-by: Zong Li <zong.li@xxxxxxxxxx>
> ---
> drivers/iommu/riscv/iommu.c | 19 +++++++++++++++++++
> 1 file changed, 19 insertions(+)
>
> diff --git a/drivers/iommu/riscv/iommu.c b/drivers/iommu/riscv/iommu.c
> index cec3ddd7ab10..36ad4aa81465 100644
> --- a/drivers/iommu/riscv/iommu.c
> +++ b/drivers/iommu/riscv/iommu.c
> @@ -14,6 +14,7 @@
>
> #include <linux/acpi.h>
> #include <linux/acpi_rimt.h>
> +#include <linux/auxiliary_bus.h>
> #include <linux/compiler.h>
> #include <linux/crash_dump.h>
> #include <linux/init.h>
> @@ -565,6 +566,21 @@ static irqreturn_t riscv_iommu_fltq_process(int irq, void *data)
> return IRQ_HANDLED;
> }
>
> +/*
> + * IOMMU Hardware performance monitor
> + */
> +static int riscv_iommu_hpm_enable(struct riscv_iommu_device *iommu)
> +{
> + struct auxiliary_device *auxdev;
> +
> + auxdev = __devm_auxiliary_device_create(iommu->dev, KBUILD_MODNAME,
> + "pmu", iommu, 0);

Using an auxiliary device makes sense here — it keeps perf PMU logic
out of the IOMMU driver and lets a dedicated driver handle
perf_pmu_register() independently. The devm-managed creation also ties
the auxiliary device lifetime to the parent IOMMU device, so no
explicit teardown is needed.

Reviewed-by: Guo Ren <guoren@xxxxxxxxxx>


> + if (!auxdev)
> + return -ENODEV;
> +
> + return 0;
> +}
> +
> /* Lookup and initialize device context info structure. */
> static struct riscv_iommu_dc *riscv_iommu_get_dc(struct riscv_iommu_device *iommu,
> unsigned int devid)
> @@ -1613,6 +1629,9 @@ int riscv_iommu_init(struct riscv_iommu_device *iommu)
> goto err_remove_sysfs;
> }
>
> + if (iommu->caps & RISCV_IOMMU_CAPABILITIES_HPM)
> + riscv_iommu_hpm_enable(iommu);
> +
> return 0;
>
> err_remove_sysfs:
> --
> 2.43.7
>


--
Best Regards
Guo Ren