linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] ARM: SMMU: add devices attached to the SMMU to an IOMMU group
@ 2013-10-18 15:08 Antonios Motakis
  2013-10-28 16:44 ` Alex Williamson
  0 siblings, 1 reply; 3+ messages in thread
From: Antonios Motakis @ 2013-10-18 15:08 UTC (permalink / raw)
  To: Will Deacon, Joerg Roedel, moderated list:ARM SMMU DRIVER,
	open list:IOMMU DRIVERS, open list
  Cc: kvmarm, iommu, tech, Antonios Motakis

IOMMU groups are expected by certain users of the IOMMU API,
e.g. VFIO. Add new devices found by the SMMU driver to an IOMMU
group to satisfy those users.

Changes from v1:
 * Added check that dev->archdata.iommu has not been set already by an IOMMU
   driver. This way we can also skip checking for an existing IOMMU group.

Signed-off-by: Antonios Motakis <a.motakis@virtualopensystems.com>
---
 drivers/iommu/arm-smmu.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c
index 0f45a48..6762885 100644
--- a/drivers/iommu/arm-smmu.c
+++ b/drivers/iommu/arm-smmu.c
@@ -1502,6 +1502,13 @@ static int arm_smmu_add_device(struct device *dev)
 {
 	struct arm_smmu_device *child, *parent, *smmu;
 	struct arm_smmu_master *master = NULL;
+	struct iommu_group *group;
+	int ret;
+
+	if (dev->archdata.iommu) {
+		dev_warn(dev, "IOMMU driver already assigned to device\n");
+		return -EINVAL;
+	}
 
 	spin_lock(&arm_smmu_devices_lock);
 	list_for_each_entry(parent, &arm_smmu_devices, list) {
@@ -1534,13 +1541,23 @@ static int arm_smmu_add_device(struct device *dev)
 	if (!master)
 		return -ENODEV;
 
+	group = iommu_group_alloc();
+	if (IS_ERR(group)) {
+		dev_err(dev, "Failed to allocate IOMMU group\n");
+		return PTR_ERR(group);
+	}
+
+	ret = iommu_group_add_device(group, dev);
+	iommu_group_put(group);
 	dev->archdata.iommu = smmu;
-	return 0;
+
+	return ret;
 }
 
 static void arm_smmu_remove_device(struct device *dev)
 {
 	dev->archdata.iommu = NULL;
+	iommu_group_remove_device(dev);
 }
 
 static struct iommu_ops arm_smmu_ops = {
-- 
1.8.1.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] ARM: SMMU: add devices attached to the SMMU to an IOMMU group
  2013-10-18 15:08 [PATCH v2] ARM: SMMU: add devices attached to the SMMU to an IOMMU group Antonios Motakis
@ 2013-10-28 16:44 ` Alex Williamson
  2013-10-29  4:32   ` Will Deacon
  0 siblings, 1 reply; 3+ messages in thread
From: Alex Williamson @ 2013-10-28 16:44 UTC (permalink / raw)
  To: Antonios Motakis
  Cc: Will Deacon, Joerg Roedel, moderated list:ARM SMMU DRIVER,
	open list:IOMMU DRIVERS, open list, kvmarm, tech

On Fri, 2013-10-18 at 17:08 +0200, Antonios Motakis wrote:
> IOMMU groups are expected by certain users of the IOMMU API,
> e.g. VFIO. Add new devices found by the SMMU driver to an IOMMU
> group to satisfy those users.
> 
> Changes from v1:
>  * Added check that dev->archdata.iommu has not been set already by an IOMMU
>    driver. This way we can also skip checking for an existing IOMMU group.
> 
> Signed-off-by: Antonios Motakis <a.motakis@virtualopensystems.com>


Looks ok to me.

Acked-by: Alex Williamson <alex.williamson@redhat.com>

> ---
>  drivers/iommu/arm-smmu.c | 19 ++++++++++++++++++-
>  1 file changed, 18 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c
> index 0f45a48..6762885 100644
> --- a/drivers/iommu/arm-smmu.c
> +++ b/drivers/iommu/arm-smmu.c
> @@ -1502,6 +1502,13 @@ static int arm_smmu_add_device(struct device *dev)
>  {
>  	struct arm_smmu_device *child, *parent, *smmu;
>  	struct arm_smmu_master *master = NULL;
> +	struct iommu_group *group;
> +	int ret;
> +
> +	if (dev->archdata.iommu) {
> +		dev_warn(dev, "IOMMU driver already assigned to device\n");
> +		return -EINVAL;
> +	}
>  
>  	spin_lock(&arm_smmu_devices_lock);
>  	list_for_each_entry(parent, &arm_smmu_devices, list) {
> @@ -1534,13 +1541,23 @@ static int arm_smmu_add_device(struct device *dev)
>  	if (!master)
>  		return -ENODEV;
>  
> +	group = iommu_group_alloc();
> +	if (IS_ERR(group)) {
> +		dev_err(dev, "Failed to allocate IOMMU group\n");
> +		return PTR_ERR(group);
> +	}
> +
> +	ret = iommu_group_add_device(group, dev);
> +	iommu_group_put(group);
>  	dev->archdata.iommu = smmu;
> -	return 0;
> +
> +	return ret;
>  }
>  
>  static void arm_smmu_remove_device(struct device *dev)
>  {
>  	dev->archdata.iommu = NULL;
> +	iommu_group_remove_device(dev);
>  }
>  
>  static struct iommu_ops arm_smmu_ops = {



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] ARM: SMMU: add devices attached to the SMMU to an IOMMU group
  2013-10-28 16:44 ` Alex Williamson
@ 2013-10-29  4:32   ` Will Deacon
  0 siblings, 0 replies; 3+ messages in thread
From: Will Deacon @ 2013-10-29  4:32 UTC (permalink / raw)
  To: Alex Williamson
  Cc: Antonios Motakis, Joerg Roedel, open list,
	open list:IOMMU DRIVERS, tech, kvmarm,
	moderated list:ARM SMMU DRIVER

On Mon, Oct 28, 2013 at 04:44:22PM +0000, Alex Williamson wrote:
> On Fri, 2013-10-18 at 17:08 +0200, Antonios Motakis wrote:
> > IOMMU groups are expected by certain users of the IOMMU API,
> > e.g. VFIO. Add new devices found by the SMMU driver to an IOMMU
> > group to satisfy those users.
> > 
> > Changes from v1:
> >  * Added check that dev->archdata.iommu has not been set already by an IOMMU
> >    driver. This way we can also skip checking for an existing IOMMU group.
> > 
> > Signed-off-by: Antonios Motakis <a.motakis@virtualopensystems.com>
> 
> 
> Looks ok to me.
> 
> Acked-by: Alex Williamson <alex.williamson@redhat.com>

Yup, looks fine to me too. I'm travelling until next week, so I'll start
picking things up then.

Cheers,

Will

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-10-29  4:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-18 15:08 [PATCH v2] ARM: SMMU: add devices attached to the SMMU to an IOMMU group Antonios Motakis
2013-10-28 16:44 ` Alex Williamson
2013-10-29  4:32   ` Will Deacon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).