dma-debug: add a check dma memory leaks
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 18 lines · Linux Kernel Mailing List
Gitweb: http://git.kernel.org/linus/41531c8f5f05aba5ec645d9770557eedbf75b422 Commit: 41531c8f5f05aba5ec645d9770557eedbf75b422dma-debug: add a check dma memory leaks
Impact: allow architectures to monitor busses for dma mem leakage
This patch adds checking code to detect if a device has pending DMA operations when it is about to be unbound from its device driver.
Signed-off-by Joerg Roedel <[email protected]>(quoted diff) +5
-0+static int dma_debug_device_change(struct notifier_block *nb, + unsigned long action, void *data) +{ + struct device *dev = data; + int count;
Review
Quoted 10 lines
(quoted diff) +10
-0+ + + switch (action) { + case BUS_NOTIFY_UNBIND_DRIVER: + count = device_dma_allocations(dev); + if (count == 0) + break; + err_printk(dev, NULL, "DMA-API: device driver has pending " + "DMA allocations while released from device " + "[count=%d]\n", count);
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?
Signature · 2 lines
David Woodhouse Open Source Technology Centre [email protected] Intel Corporation
Quoted 35 lines · David Woodhouse
Quoted 18 lines · Linux Kernel Mailing List
Gitweb: http://git.kernel.org/linus/41531c8f5f05aba5ec645d9770557eedbf75b422 Commit: 41531c8f5f05aba5ec645d9770557eedbf75b422dma-debug: add a check dma memory leaks
Impact: allow architectures to monitor busses for dma mem leakage
This patch adds checking code to detect if a device has pending DMA operations when it is about to be unbound from its device driver.
Signed-off-by Joerg Roedel <[email protected]>(quoted diff) +5
-0+static int dma_debug_device_change(struct notifier_block *nb, + unsigned long action, void *data) +{ + struct device *dev = data; + int count;Review
Quoted 10 lines
(quoted diff) +10
-0+ + + switch (action) { + case BUS_NOTIFY_UNBIND_DRIVER: + count = device_dma_allocations(dev); + if (count == 0) + break; + err_printk(dev, NULL, "DMA-API: device driver has pending " + "DMA allocations while released from device " + "[count=%d]\n", count);Hm, cute... but not quite functioning as you intended. If you look at
__device_release_driver()indrivers/base/dd.cyou'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...
Quoted 4 lines
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?
Joerg
Signature · 6 lines
| Advanced Micro Devices GmbH
Operating | Karl-Hammerschmidt-Str. 34, 85609 Dornach bei München
System |
Research | Geschäftsführer: Jochen Polster, Thomas M. McCoy, Giuliano Meroni
Center | Sitz: Dornach, Gemeinde Aschheim, Landkreis München
| Registergericht München, HRB Nr. 43632Subject: 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.
---
Quoted 6 lines · Joerg Roedel
Quoted 5 lines · David Woodhouse
Hm, cute... but not quite functioning as you intended. If you look at
__device_release_driver()indrivers/base/dd.cyou'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...
Quoted 8 lines
Quoted 4 lines
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?
drivers/base/dd.c +4 -0
@@ -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); } }
include/linux/device.h +1 -0
@@ -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);
Signature · 2 lines
David Woodhouse Open Source Technology Centre [email protected] Intel Corporation
Quoted 7 lines · David Woodhouse
Subject: Add
BUS_NOTIFY_UNBOUND_DRIVERcallback after driver removalThis 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 <[email protected]>
I don't understand. Who wrote this patch, Joerg or you? I have this in my tree already as written by Joerg.
confused,
greg k-h
Quoted 11 lines · Greg KH
Quoted 7 lines · David Woodhouse
Subject: Add
BUS_NOTIFY_UNBOUND_DRIVERcallback after driver removalThis 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 <[email protected]>I don't understand. Who wrote this patch, Joerg or you? I have this in my tree already as written by Joerg.
In that case we probably both did it, independently. I did it last night after finally catching up with Ben and talking about the possibility of moving the existing notifiers. Jörg may have done it sooner.
You can drop my version, then.
Signature · 2 lines
David Woodhouse Open Source Technology Centre [email protected] Intel Corporation
Quoted 11 lines · David Woodhouse
Quoted 1 line
I don't understand. Who wrote this patch, Joerg or you? I have
this in
Quoted 1 line
my tree already as written by Joerg.
In that case we probably both did it, independently. I did it last night
after finally catching up with Ben and talking about the possibility of
moving the existing notifiers. Jörg may have done it sooner.You can drop my version, then.
As long as it's strictly identical :-) IE. I don't want to -move- the existing notifier, but adding a "BOUND" one is fine.
Cheers,
Ben.
Quoted 11 lines · Benjamin Herrenschmidt
Quoted 10 lines · David Woodhouse
Quoted 1 line
I don't understand. Who wrote this patch, Joerg or you? I have
this in
Quoted 1 line
my tree already as written by Joerg.
In that case we probably both did it, independently. I did it last night
after finally catching up with Ben and talking about the possibility of
moving the existing notifiers. Jörg may have done it sooner.
Quoted 4 lines
Quoted 1 line
You can drop my version, then.
As long as it's strictly identical :-) IE. I don't want to -move- the existing notifier, but adding a "BOUND" one is fine.
Look in the linux-next tree to verify that it is the same.
Or here's a direct link to the patch:
http://www.kernel.org/pub/linux/kernel/people/gregkh/gregkh-2.6/gregkh-03-driver-core/driver-core-add-bus_notify_unbound_driver-event.patch
thanks,
greg k-h
Benjamin Herrenschmidt
Acked-byQuoted 7 lines · David Woodhouse
Subject: Add
BUS_NOTIFY_UNBOUND_DRIVERcallback after driver removalThis 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 <[email protected]>
Quoted 53 lines
---
Quoted 6 lines · Joerg Roedel
Quoted 5 lines · David Woodhouse
Hm, cute... but not quite functioning as you intended. If you look at
__device_release_driver()indrivers/base/dd.cyou'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...Quoted 8 lines
Quoted 4 lines
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_iommunotifier callback too?drivers/base/dd.c +4
-0@@ -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); } }include/linux/device.h +1
-0@@ -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);