Message ID | 20210803002409.19406-2-sstabellini@kernel.org (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Generic SMMU Bindings | expand |
Hi Stefano, On 03/08/2021 01:24, Stefano Stabellini wrote: > iommu_add_dt_device() returns -EEXIST if the device was already > registered. At the moment, this can only happen if the device was > already assigned to a domain (either dom0 at boot or via > XEN_DOMCTL_assign_device). > > In a follow-up patch, we will convert the SMMU driver to use the FW > spec. When the legacy bindings are used, all the devices will be > registered at probe. Therefore, iommu_add_dt_device() will always > returns -EEXIST. So this patch needs to be first in the series to avoid breaking bisection. I will re-order the patches on commit. > > Currently, one caller (XEN_DOMCTL_assign_device) will check the return > and ignore -EEXIST. All the other will fail because it was technically a > programming error. > > However, there is no harm to call iommu_add_dt_device() twice, so we can > simply return 0. > > With that in place the caller doesn't need to check -EEXIST anymore, so > remove the check. > > Signed-off-by: Stefano Stabellini <stefano.stabellini@xilinx.com> Acked-by: Julien Grall <jgrall@amazon.com> Cheers,
diff --git a/xen/drivers/passthrough/device_tree.c b/xen/drivers/passthrough/device_tree.c index 999b831d90..9249f21c01 100644 --- a/xen/drivers/passthrough/device_tree.c +++ b/xen/drivers/passthrough/device_tree.c @@ -140,8 +140,12 @@ int iommu_add_dt_device(struct dt_device_node *np) if ( !ops ) return -EINVAL; + /* + * The device may already have been registered. As there is no harm in + * it just return success early. + */ if ( dev_iommu_fwspec_get(dev) ) - return -EEXIST; + return 0; /* * According to the Documentation/devicetree/bindings/iommu/iommu.txt @@ -249,12 +253,7 @@ int iommu_do_dt_domctl(struct xen_domctl *domctl, struct domain *d, return -EINVAL; ret = iommu_add_dt_device(dev); - /* - * Ignore "-EEXIST" error code as it would mean that the device is - * already added to the IOMMU (positive result). Such happens after - * re-creating guest domain. - */ - if ( ret < 0 && ret != -EEXIST ) + if ( ret < 0 ) { printk(XENLOG_G_ERR "Failed to add %s to the IOMMU\n", dt_node_full_name(dev));
iommu_add_dt_device() returns -EEXIST if the device was already registered. At the moment, this can only happen if the device was already assigned to a domain (either dom0 at boot or via XEN_DOMCTL_assign_device). In a follow-up patch, we will convert the SMMU driver to use the FW spec. When the legacy bindings are used, all the devices will be registered at probe. Therefore, iommu_add_dt_device() will always returns -EEXIST. Currently, one caller (XEN_DOMCTL_assign_device) will check the return and ignore -EEXIST. All the other will fail because it was technically a programming error. However, there is no harm to call iommu_add_dt_device() twice, so we can simply return 0. With that in place the caller doesn't need to check -EEXIST anymore, so remove the check. Signed-off-by: Stefano Stabellini <stefano.stabellini@xilinx.com> --- Changes in v6: - improve in-code comment - improve commit message - remove stale in-code comment Changes in v5: - new patch --- xen/drivers/passthrough/device_tree.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)