mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] vfio: fix noiommu vfio_iommu_group_get reference count
@ 2017-08-11 13:16 Eric Auger
  2017-08-30 21:23 ` Alex Williamson
  0 siblings, 1 reply; 2+ messages in thread
From: Eric Auger @ 2017-08-11 13:16 UTC (permalink / raw)
  To: eric.auger.pro, eric.auger, linux-kernel, alex.williamson

In vfio_iommu_group_get() we want to increase the reference
count of the iommu group.

In noiommu case, the group does not exist and is allocated.
iommu_group_add_device() increases the group ref count. However we
then call iommu_group_put() which decrements it.

This leads to a "refcount_t: underflow WARN_ON".

Only decrement the ref count in case of iommu_group_add_device
failure.

Signed-off-by: Eric Auger <eric.auger@redhat.com>

---

v1 -> v2:
put the group in case iommu_group_add_device failed
---
 drivers/vfio/vfio.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
index 330d505..4ee4f36 100644
--- a/drivers/vfio/vfio.c
+++ b/drivers/vfio/vfio.c
@@ -138,9 +138,10 @@ struct iommu_group *vfio_iommu_group_get(struct device *dev)
 	iommu_group_set_name(group, "vfio-noiommu");
 	iommu_group_set_iommudata(group, &noiommu, NULL);
 	ret = iommu_group_add_device(group, dev);
-	iommu_group_put(group);
-	if (ret)
+	if (ret) {
+		iommu_group_put(group);
 		return NULL;
+	}
 
 	/*
 	 * Where to taint?  At this point we've added an IOMMU group for a
-- 
2.5.5

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

* Re: [PATCH v2] vfio: fix noiommu vfio_iommu_group_get reference count
  2017-08-11 13:16 [PATCH v2] vfio: fix noiommu vfio_iommu_group_get reference count Eric Auger
@ 2017-08-30 21:23 ` Alex Williamson
  0 siblings, 0 replies; 2+ messages in thread
From: Alex Williamson @ 2017-08-30 21:23 UTC (permalink / raw)
  To: Eric Auger; +Cc: eric.auger.pro, linux-kernel

On Fri, 11 Aug 2017 15:16:06 +0200
Eric Auger <eric.auger@redhat.com> wrote:

> In vfio_iommu_group_get() we want to increase the reference
> count of the iommu group.
> 
> In noiommu case, the group does not exist and is allocated.
> iommu_group_add_device() increases the group ref count. However we
> then call iommu_group_put() which decrements it.
> 
> This leads to a "refcount_t: underflow WARN_ON".
> 
> Only decrement the ref count in case of iommu_group_add_device
> failure.
> 
> Signed-off-by: Eric Auger <eric.auger@redhat.com>
> 
> ---
> 
> v1 -> v2:
> put the group in case iommu_group_add_device failed
> ---
>  drivers/vfio/vfio.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)

Applied to next branch for v4.14.  Thanks,

Alex
 
> diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
> index 330d505..4ee4f36 100644
> --- a/drivers/vfio/vfio.c
> +++ b/drivers/vfio/vfio.c
> @@ -138,9 +138,10 @@ struct iommu_group *vfio_iommu_group_get(struct device *dev)
>  	iommu_group_set_name(group, "vfio-noiommu");
>  	iommu_group_set_iommudata(group, &noiommu, NULL);
>  	ret = iommu_group_add_device(group, dev);
> -	iommu_group_put(group);
> -	if (ret)
> +	if (ret) {
> +		iommu_group_put(group);
>  		return NULL;
> +	}
>  
>  	/*
>  	 * Where to taint?  At this point we've added an IOMMU group for a

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

end of thread, other threads:[~2017-08-30 21:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-11 13:16 [PATCH v2] vfio: fix noiommu vfio_iommu_group_get reference count Eric Auger
2017-08-30 21:23 ` Alex Williamson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®