linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Benjamin Herrenschmidt <benh@kernel.crashing.org>
To: David Woodhouse <dwmw2@infradead.org>
Cc: Joerg Roedel <joerg.roedel@amd.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	reinette.chatre@intel.com, greg@kroah.com
Subject: Re: dma-debug: add a check dma memory leaks
Date: Sun, 10 May 2009 11:46:24 +1000	[thread overview]
Message-ID: <1241919984.19955.9.camel@pasglop> (raw)
In-Reply-To: <1241913552.24436.113.camel@macbook.infradead.org>

On Sun, 2009-05-10 at 00:59 +0100, David Woodhouse wrote:
> Subject: Add BUS_NOTIFY_UNBOUND_DRIVER callback after driver removal
> 
> This adds a notifier callback which happens _after_ the driver has been
> unbound from the device, needed for things like the DMA debugging API
> which want to check that all DMA mappings have been correctly torn down.
> 
> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>

Acked-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>

> ---
> On Tue, 2009-04-21 at 11:20 +0200, Joerg Roedel wrote:
> > On Fri, Apr 17, 2009 at 10:51:05PM +0100, David Woodhouse wrote:
> > > Hm, cute... but not quite functioning as you intended. If you look at
> > > __device_release_driver() in drivers/base/dd.c you'll see it actually
> > > calls the notifier _before_ calling into the driver's ->remove() method.
> > > So it's hardly surprising that not everything has been freed yet...
> > > 
> > > Reported by Reinette when it bit iwlwifi.
> > > 
> > > Ben, can we get away with changing the order so that the ->remove() is
> > > called before the notifier, in this case?
> > 
> > Ben? I would like to keep this check. If its not possible to move this
> > one behind the drivers ->remove function it may be an option to add
> > another notifier?
> 
> It doesn't look like it's possible to move the UNBIND callback. Let's
> add an UNBOUND callback instead... I've tested this and it fixes the
> false positives.
> 
> Jörg, should you be using UNBOUND instead of UNBIND in the amd_iommu
> notifier callback too?
> 
> diff --git a/drivers/base/dd.c b/drivers/base/dd.c
> index 742cbe6..efd00de 100644
> --- a/drivers/base/dd.c
> +++ b/drivers/base/dd.c
> @@ -320,6 +320,10 @@ static void __device_release_driver(struct device *dev)
>  		devres_release_all(dev);
>  		dev->driver = NULL;
>  		klist_remove(&dev->p->knode_driver);
> +		if (dev->bus)
> +			blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
> +						     BUS_NOTIFY_UNBOUND_DRIVER,
> +						     dev);
>  	}
>  }
>  
> diff --git a/include/linux/device.h b/include/linux/device.h
> index 6a69caa..4ded2ae 100644
> --- a/include/linux/device.h
> +++ b/include/linux/device.h
> @@ -116,6 +116,7 @@ extern int bus_unregister_notifier(struct bus_type *bus,
>  #define BUS_NOTIFY_BOUND_DRIVER		0x00000003 /* driver bound to device */
>  #define BUS_NOTIFY_UNBIND_DRIVER	0x00000004 /* driver about to be
>  						      unbound */
> +#define BUS_NOTIFY_UNBOUND_DRIVER	0x00000005 /* driver has been unbound */
>  
>  extern struct kset *bus_get_kset(struct bus_type *bus);
>  extern struct klist *bus_get_device_klist(struct bus_type *bus);
> 
> 


  reply	other threads:[~2009-05-10  2:51 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <200903302101.n2UL1O1n011970@hera.kernel.org>
2009-04-17 21:51 ` dma-debug: add a check dma memory leaks David Woodhouse
2009-04-21  9:20   ` Joerg Roedel
2009-05-09 23:59     ` David Woodhouse
2009-05-10  1:46       ` Benjamin Herrenschmidt [this message]
2009-05-10  2:09       ` Greg KH
2009-05-10  8:49         ` David Woodhouse
2009-05-10  9:32           ` Benjamin Herrenschmidt
2009-05-11 17:43             ` Greg KH

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=1241919984.19955.9.camel@pasglop \
    --to=benh@kernel.crashing.org \
    --cc=dwmw2@infradead.org \
    --cc=greg@kroah.com \
    --cc=joerg.roedel@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=reinette.chatre@intel.com \
    /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 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).