Re: [PATCH v2 1/6] iommu/ipmmu-vmsa: Link IOMMUs and devices in sysfs
Hi Simon, On Thu, Apr 11, 2019 at 10:12 AM Simon Horman wrote: > On Thu, Apr 11, 2019 at 10:10:28AM +0200, Simon Horman wrote: > > On Wed, Apr 03, 2019 at 08:21:43PM +0200, Geert Uytterhoeven wrote: > > > As of commit 7af9a5fdb9e0ca33 ("iommu/ipmmu-vmsa: Use > > > iommu_device_sysfs_add()/remove()"), IOMMU devices show up under > > > /sys/class/iommus/, but their "devices" subdirectories are empty. > > > > Should the path be /sys/class/iommu/ (no trailing 's') ? Yes it does, thanks. Will fix. > > > Likewise, devices tied to an IOMMU do not have an "iommu" backlink. > > > > > > Make sure all links are created, on both arm32 and arm64. > > > > > > Signed-off-by: Geert Uytterhoeven > > > Reviewed-by: Laurent Pinchart > > > --- > > > v2: > > > - Add Reviewed-by. > > > --- > > > drivers/iommu/ipmmu-vmsa.c | 24 +--- > > > 1 file changed, 17 insertions(+), 7 deletions(-) > > > > > > diff --git a/drivers/iommu/ipmmu-vmsa.c b/drivers/iommu/ipmmu-vmsa.c > > > index 9a380c10655e182d..9f2b781e20a0eba6 100644 > > > --- a/drivers/iommu/ipmmu-vmsa.c > > > +++ b/drivers/iommu/ipmmu-vmsa.c > > > @@ -885,27 +885,37 @@ static int ipmmu_init_arm_mapping(struct device > > > *dev) > > > > > > static int ipmmu_add_device(struct device *dev) > > > { > > > + struct ipmmu_vmsa_device *mmu = to_ipmmu(dev); > > > struct iommu_group *group; > > > + int ret; > > > > > > /* > > > * Only let through devices that have been verified in xlate() > > > */ > > > - if (!to_ipmmu(dev)) > > > + if (!mmu) > > > return -ENODEV; > > > > > > - if (IS_ENABLED(CONFIG_ARM) && !IS_ENABLED(CONFIG_IOMMU_DMA)) > > > - return ipmmu_init_arm_mapping(dev); > > > + if (IS_ENABLED(CONFIG_ARM) && !IS_ENABLED(CONFIG_IOMMU_DMA)) { > > > + ret = ipmmu_init_arm_mapping(dev); > > > + if (ret) > > > + return ret; > > > + } else { > > > + group = iommu_group_get_for_dev(dev); > > > + if (IS_ERR(group)) > > > + return PTR_ERR(group); > > > > > > - group = iommu_group_get_for_dev(dev); > > > - if (IS_ERR(group)) > > > - return PTR_ERR(group); > > > + iommu_group_put(group); > > > + } > > > > > > - iommu_group_put(group); > > > + iommu_device_link(>iommu, dev); > > Also, is there any value in propagating the return value > of iommu_device_link() ? I don't think so. Sysfs information is not super-critical, and most drivers just ignore such return values. Also, the sysfs cleanup code handles cleanup after failed setup fine. Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- ge...@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
Re: [PATCH v2 1/6] iommu/ipmmu-vmsa: Link IOMMUs and devices in sysfs
On Wed, Apr 03, 2019 at 08:21:43PM +0200, Geert Uytterhoeven wrote: > As of commit 7af9a5fdb9e0ca33 ("iommu/ipmmu-vmsa: Use > iommu_device_sysfs_add()/remove()"), IOMMU devices show up under > /sys/class/iommus/, but their "devices" subdirectories are empty. Hi Geert, Should the path be /sys/class/iommu/ (no trailing 's') ? > Likewise, devices tied to an IOMMU do not have an "iommu" backlink. > > Make sure all links are created, on both arm32 and arm64. > > Signed-off-by: Geert Uytterhoeven > Reviewed-by: Laurent Pinchart > --- > v2: > - Add Reviewed-by. > --- > drivers/iommu/ipmmu-vmsa.c | 24 +--- > 1 file changed, 17 insertions(+), 7 deletions(-) > > diff --git a/drivers/iommu/ipmmu-vmsa.c b/drivers/iommu/ipmmu-vmsa.c > index 9a380c10655e182d..9f2b781e20a0eba6 100644 > --- a/drivers/iommu/ipmmu-vmsa.c > +++ b/drivers/iommu/ipmmu-vmsa.c > @@ -885,27 +885,37 @@ static int ipmmu_init_arm_mapping(struct device *dev) > > static int ipmmu_add_device(struct device *dev) > { > + struct ipmmu_vmsa_device *mmu = to_ipmmu(dev); > struct iommu_group *group; > + int ret; > > /* >* Only let through devices that have been verified in xlate() >*/ > - if (!to_ipmmu(dev)) > + if (!mmu) > return -ENODEV; > > - if (IS_ENABLED(CONFIG_ARM) && !IS_ENABLED(CONFIG_IOMMU_DMA)) > - return ipmmu_init_arm_mapping(dev); > + if (IS_ENABLED(CONFIG_ARM) && !IS_ENABLED(CONFIG_IOMMU_DMA)) { > + ret = ipmmu_init_arm_mapping(dev); > + if (ret) > + return ret; > + } else { > + group = iommu_group_get_for_dev(dev); > + if (IS_ERR(group)) > + return PTR_ERR(group); > > - group = iommu_group_get_for_dev(dev); > - if (IS_ERR(group)) > - return PTR_ERR(group); > + iommu_group_put(group); > + } > > - iommu_group_put(group); > + iommu_device_link(>iommu, dev); > return 0; > } > > static void ipmmu_remove_device(struct device *dev) > { > + struct ipmmu_vmsa_device *mmu = to_ipmmu(dev); > + > + iommu_device_unlink(>iommu, dev); > arm_iommu_detach_device(dev); > iommu_group_remove_device(dev); > } > -- > 2.17.1 > ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
Re: [PATCH v2 1/6] iommu/ipmmu-vmsa: Link IOMMUs and devices in sysfs
On Thu, Apr 11, 2019 at 10:10:28AM +0200, Simon Horman wrote: > On Wed, Apr 03, 2019 at 08:21:43PM +0200, Geert Uytterhoeven wrote: > > As of commit 7af9a5fdb9e0ca33 ("iommu/ipmmu-vmsa: Use > > iommu_device_sysfs_add()/remove()"), IOMMU devices show up under > > /sys/class/iommus/, but their "devices" subdirectories are empty. > > Hi Geert, > > Should the path be /sys/class/iommu/ (no trailing 's') ? > > > Likewise, devices tied to an IOMMU do not have an "iommu" backlink. > > > > Make sure all links are created, on both arm32 and arm64. > > > > Signed-off-by: Geert Uytterhoeven > > Reviewed-by: Laurent Pinchart > > --- > > v2: > > - Add Reviewed-by. > > --- > > drivers/iommu/ipmmu-vmsa.c | 24 +--- > > 1 file changed, 17 insertions(+), 7 deletions(-) > > > > diff --git a/drivers/iommu/ipmmu-vmsa.c b/drivers/iommu/ipmmu-vmsa.c > > index 9a380c10655e182d..9f2b781e20a0eba6 100644 > > --- a/drivers/iommu/ipmmu-vmsa.c > > +++ b/drivers/iommu/ipmmu-vmsa.c > > @@ -885,27 +885,37 @@ static int ipmmu_init_arm_mapping(struct device *dev) > > > > static int ipmmu_add_device(struct device *dev) > > { > > + struct ipmmu_vmsa_device *mmu = to_ipmmu(dev); > > struct iommu_group *group; > > + int ret; > > > > /* > > * Only let through devices that have been verified in xlate() > > */ > > - if (!to_ipmmu(dev)) > > + if (!mmu) > > return -ENODEV; > > > > - if (IS_ENABLED(CONFIG_ARM) && !IS_ENABLED(CONFIG_IOMMU_DMA)) > > - return ipmmu_init_arm_mapping(dev); > > + if (IS_ENABLED(CONFIG_ARM) && !IS_ENABLED(CONFIG_IOMMU_DMA)) { > > + ret = ipmmu_init_arm_mapping(dev); > > + if (ret) > > + return ret; > > + } else { > > + group = iommu_group_get_for_dev(dev); > > + if (IS_ERR(group)) > > + return PTR_ERR(group); > > > > - group = iommu_group_get_for_dev(dev); > > - if (IS_ERR(group)) > > - return PTR_ERR(group); > > + iommu_group_put(group); > > + } > > > > - iommu_group_put(group); > > + iommu_device_link(>iommu, dev); Also, is there any value in propagating the return value of iommu_device_link() ? > > return 0; > > } > > > > static void ipmmu_remove_device(struct device *dev) > > { > > + struct ipmmu_vmsa_device *mmu = to_ipmmu(dev); > > + > > + iommu_device_unlink(>iommu, dev); > > arm_iommu_detach_device(dev); > > iommu_group_remove_device(dev); > > } > > -- > > 2.17.1 > > ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
[PATCH v2 1/6] iommu/ipmmu-vmsa: Link IOMMUs and devices in sysfs
As of commit 7af9a5fdb9e0ca33 ("iommu/ipmmu-vmsa: Use iommu_device_sysfs_add()/remove()"), IOMMU devices show up under /sys/class/iommus/, but their "devices" subdirectories are empty. Likewise, devices tied to an IOMMU do not have an "iommu" backlink. Make sure all links are created, on both arm32 and arm64. Signed-off-by: Geert Uytterhoeven Reviewed-by: Laurent Pinchart --- v2: - Add Reviewed-by. --- drivers/iommu/ipmmu-vmsa.c | 24 +--- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/drivers/iommu/ipmmu-vmsa.c b/drivers/iommu/ipmmu-vmsa.c index 9a380c10655e182d..9f2b781e20a0eba6 100644 --- a/drivers/iommu/ipmmu-vmsa.c +++ b/drivers/iommu/ipmmu-vmsa.c @@ -885,27 +885,37 @@ static int ipmmu_init_arm_mapping(struct device *dev) static int ipmmu_add_device(struct device *dev) { + struct ipmmu_vmsa_device *mmu = to_ipmmu(dev); struct iommu_group *group; + int ret; /* * Only let through devices that have been verified in xlate() */ - if (!to_ipmmu(dev)) + if (!mmu) return -ENODEV; - if (IS_ENABLED(CONFIG_ARM) && !IS_ENABLED(CONFIG_IOMMU_DMA)) - return ipmmu_init_arm_mapping(dev); + if (IS_ENABLED(CONFIG_ARM) && !IS_ENABLED(CONFIG_IOMMU_DMA)) { + ret = ipmmu_init_arm_mapping(dev); + if (ret) + return ret; + } else { + group = iommu_group_get_for_dev(dev); + if (IS_ERR(group)) + return PTR_ERR(group); - group = iommu_group_get_for_dev(dev); - if (IS_ERR(group)) - return PTR_ERR(group); + iommu_group_put(group); + } - iommu_group_put(group); + iommu_device_link(>iommu, dev); return 0; } static void ipmmu_remove_device(struct device *dev) { + struct ipmmu_vmsa_device *mmu = to_ipmmu(dev); + + iommu_device_unlink(>iommu, dev); arm_iommu_detach_device(dev); iommu_group_remove_device(dev); } -- 2.17.1 ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu