On Fri, Aug 25, 2023 at 01:02:12AM -0700, Vikram Garhwal wrote:
> Protect iommu_add_dt_device() with dtdevs_lock to prevent concurrent access
> to add/remove/assign/deassign.
> With addition of dynamic programming feature(follow-up patches in this
> series),
> this function can be concurrently accessed by while making a device
> assign/deassign for passthrough and by dynamic node add/remove using device
> tree
> overlays.
There was a comment from Julien on v9 on commit message. In v11, I Will remove
references to PCI because this is misleading.
>
> Signed-off-by: Vikram Garhwal <vikram.garh...@amd.com>
> Reviewed-by: Luca Fancellu <luca.fance...@arm.com>
> Reviewed-by: Michal Orzel <michal.or...@amd.com>
>
> ---
> Changes from v7:
> Update commit message and fix indent.
> ---
> ---
> xen/drivers/passthrough/device_tree.c | 9 ++++++++-
> 1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/xen/drivers/passthrough/device_tree.c
> b/xen/drivers/passthrough/device_tree.c
> index 5d84c07b50..1202eac625 100644
> --- a/xen/drivers/passthrough/device_tree.c
> +++ b/xen/drivers/passthrough/device_tree.c
> @@ -148,6 +148,8 @@ int iommu_add_dt_device(struct dt_device_node *np)
> if ( dev_iommu_fwspec_get(dev) )
> return 0;
>
> + spin_lock(&dtdevs_lock);
> +
> /*
> * According to the Documentation/devicetree/bindings/iommu/iommu.txt
> * from Linux.
> @@ -160,7 +162,10 @@ int iommu_add_dt_device(struct dt_device_node *np)
> * these callback implemented.
> */
> if ( !ops->add_device || !ops->dt_xlate )
> - return -EINVAL;
> + {
> + rc = -EINVAL;
> + goto fail;
> + }
>
> if ( !dt_device_is_available(iommu_spec.np) )
> break;
> @@ -191,6 +196,8 @@ int iommu_add_dt_device(struct dt_device_node *np)
> if ( rc < 0 )
> iommu_fwspec_free(dev);
>
> + fail:
> + spin_unlock(&dtdevs_lock);
> return rc;
> }
>
> --
> 2.17.1
>
>