All of lore.kernel.org
 help / color / mirror / Atom feed
From: Borislav Petkov <bp-Gina5bIWoIWzQB+pC5nmwQ@public.gmane.org>
To: Joerg Roedel <joro-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
Cc: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org,
	Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>,
	David Woodhouse <dwmw2-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Jiang Liu <jiang.liu-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
Subject: Re: [PATCH] iommu/vt-d: Do not BUG_ON in intel_unmap if no domain
Date: Mon, 4 Aug 2014 13:42:05 +0200	[thread overview]
Message-ID: <20140804114205.GA5545@pd.tnic> (raw)
In-Reply-To: <1407151386-16467-1-git-send-email-joro-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>

On Mon, Aug 04, 2014 at 01:23:06PM +0200, Joerg Roedel wrote:
> From: Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>
> 
> This BUG_ON is easy to trigger with device-hotplug (e.g.
> SR-IOV). The device_notifier function in the Intel IOMMU
> driver listens to the BUS_NOTIFY_DEL_DEVICE event and frees
> the domain for the device if it is reveived.
> 
> But this event is triggered before the device driver is
> unbound from the device. When the driver core actually
> removes the device the driver may release pending DMA
> resources, which ends up in intel_unmap and triggers the
> BUG_ON.
> 
> Not listening to BUS_NOTIFY_DEL_DEVICE would cause resource
> leakage with devices that have never been assigned to any
> driver, so fix this issue by just making unmap a nop when
> the domain is already released.
> 
> Cc: Jiang Liu <jiang.liu-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
> Cc: David Woodhouse <dwmw2-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
> Signed-off-by: Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>
> ---
>  drivers/iommu/intel-iommu.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
> index d1f5caa..7d689d7 100644
> --- a/drivers/iommu/intel-iommu.c
> +++ b/drivers/iommu/intel-iommu.c
> @@ -3196,7 +3196,8 @@ static void intel_unmap(struct device *dev, dma_addr_t dev_addr)
>  		return;
>  
>  	domain = find_domain(dev);
> -	BUG_ON(!domain);
> +	if (!domain)
> +		return;

It is always questionable when people remove BUG_ONs because relaxing
assertions sound like a temporary fix more often than not. Sounds to me
that the original commit which deals with BUS_NOTIFY_DEL_DEVICE needs to
try again with the fix. :-)

-- 
Regards/Gruss,
    Boris.

Sent from a fat crate under my desk. Formatting is fine.
--

WARNING: multiple messages have this Message-ID (diff)
From: Borislav Petkov <bp@alien8.de>
To: Joerg Roedel <joro@8bytes.org>
Cc: iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org,
	Joerg Roedel <jroedel@suse.de>,
	Jiang Liu <jiang.liu@linux.intel.com>,
	David Woodhouse <dwmw2@infradead.org>
Subject: Re: [PATCH] iommu/vt-d: Do not BUG_ON in intel_unmap if no domain
Date: Mon, 4 Aug 2014 13:42:05 +0200	[thread overview]
Message-ID: <20140804114205.GA5545@pd.tnic> (raw)
In-Reply-To: <1407151386-16467-1-git-send-email-joro@8bytes.org>

On Mon, Aug 04, 2014 at 01:23:06PM +0200, Joerg Roedel wrote:
> From: Joerg Roedel <jroedel@suse.de>
> 
> This BUG_ON is easy to trigger with device-hotplug (e.g.
> SR-IOV). The device_notifier function in the Intel IOMMU
> driver listens to the BUS_NOTIFY_DEL_DEVICE event and frees
> the domain for the device if it is reveived.
> 
> But this event is triggered before the device driver is
> unbound from the device. When the driver core actually
> removes the device the driver may release pending DMA
> resources, which ends up in intel_unmap and triggers the
> BUG_ON.
> 
> Not listening to BUS_NOTIFY_DEL_DEVICE would cause resource
> leakage with devices that have never been assigned to any
> driver, so fix this issue by just making unmap a nop when
> the domain is already released.
> 
> Cc: Jiang Liu <jiang.liu@linux.intel.com>
> Cc: David Woodhouse <dwmw2@infradead.org>
> Signed-off-by: Joerg Roedel <jroedel@suse.de>
> ---
>  drivers/iommu/intel-iommu.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
> index d1f5caa..7d689d7 100644
> --- a/drivers/iommu/intel-iommu.c
> +++ b/drivers/iommu/intel-iommu.c
> @@ -3196,7 +3196,8 @@ static void intel_unmap(struct device *dev, dma_addr_t dev_addr)
>  		return;
>  
>  	domain = find_domain(dev);
> -	BUG_ON(!domain);
> +	if (!domain)
> +		return;

It is always questionable when people remove BUG_ONs because relaxing
assertions sound like a temporary fix more often than not. Sounds to me
that the original commit which deals with BUS_NOTIFY_DEL_DEVICE needs to
try again with the fix. :-)

-- 
Regards/Gruss,
    Boris.

Sent from a fat crate under my desk. Formatting is fine.
--

  parent reply	other threads:[~2014-08-04 11:42 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-04 11:23 [PATCH] iommu/vt-d: Do not BUG_ON in intel_unmap if no domain Joerg Roedel
2014-08-04 11:23 ` Joerg Roedel
     [not found] ` <1407151386-16467-1-git-send-email-joro-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
2014-08-04 11:42   ` Borislav Petkov [this message]
2014-08-04 11:42     ` Borislav Petkov
2014-08-04 11:49     ` Joerg Roedel
2014-08-05 11:05     ` [PATCH] iommu/vt-d: Defer domain removal if device is assigned to a driver Joerg Roedel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140804114205.GA5545@pd.tnic \
    --to=bp-gina5biwoiwzqb+pc5nmwq@public.gmane.org \
    --cc=dwmw2-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org \
    --cc=iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
    --cc=jiang.liu-VuQAYsv1563Yd54FQh9/CA@public.gmane.org \
    --cc=joro-zLv9SwRftAIdnm+yROfE0A@public.gmane.org \
    --cc=jroedel-l3A5Bk7waGM@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.