Re: [PATCH v2 1/2] iommu/arm-smmu-v3: Manage teardown with devm

From: Nicolin Chen

Date: Thu Jun 11 2026 - 21:16:22 EST


On Thu, Jun 11, 2026 at 09:42:04AM +0100, Shameer Kolothum wrote:
> arm_smmu_device_remove() manually frees the IOPF queue, destroys the
> vmid_map and disables the device, while the IRQs and queues are devm
> managed. devm unwinds only after remove() returns, so the cleanup runs
> in the wrong order. The IOPF queue is freed before the event-queue IRQ
> whose handler uses it.
>
> Manage all of it with devm so the unwind order is correct. Free the IOPF
> queue and vmid_map via devm actions, and disable the device from one
> registered after arm_smmu_device_reset().
>
> This is also a prerequisite for fixing a Tegra241 CMDQV CMD_SYNC
> use-after-free in the subsequent patch.
>
> Suggested-by: Jason Gunthorpe <jgg@xxxxxxxx>
> Signed-off-by: Shameer Kolothum <skolothumtho@xxxxxxxxxx>

Given that the PATCH-2 adds new code to arm_smmu_disable_action()
which is introduced here, should this patch also cc stable tree?

> +static void arm_smmu_free_iopf_action(void *data)
> +{
> + iopf_queue_free(data);
> +}
> +
> +static void arm_smmu_destroy_vmid_map(void *data)
> +{
> + ida_destroy(data);
> +}
[...]
> +static void arm_smmu_disable_action(void *data)
> +{
> + arm_smmu_device_disable(data);
> +}

Jason prefers casting.

Otherwise,

Reviewed-by: Nicolin Chen <nicolinc@xxxxxxxxxx>