public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] dma-debug: enhance dma_debug_device_change() to check for mapping errors
@ 2013-11-12 20:51 Shuah Khan
  2013-11-12 22:12 ` Alexander Duyck
  0 siblings, 1 reply; 4+ messages in thread
From: Shuah Khan @ 2013-11-12 20:51 UTC (permalink / raw)
  To: akpm, alexander.h.duyck, joro; +Cc: Shuah Khan, linux-kernel, shuahkhan

dma-debug checks to verify if driver validated the address returned by
dma mapping routines when driver does unmap. If a driver doesn't call
unmap, failure to check mapping errors isn't detected and reported.

Enhancing existing bus notifier_call dma_debug_device_change() to check
for mapping errors at the same time it detects leaked dma buffers for
BUS_NOTIFY_UNBOUND_DRIVER event.

Signed-off-by: Shuah Khan <shuah.kh@samsung.com>
---
 lib/dma-debug.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/lib/dma-debug.c b/lib/dma-debug.c
index d87a17a..6c17b90 100644
--- a/lib/dma-debug.c
+++ b/lib/dma-debug.c
@@ -712,6 +712,19 @@ out_err:
 	return -ENOMEM;
 }
 
+static void check_dma_mapping_error(struct dma_debug_entry *ref,
+				    struct dma_debug_entry *entry)
+{
+	if (entry->map_err_type == MAP_ERR_NOT_CHECKED) {
+		err_printk(ref->dev, entry,
+			   "DMA-API: device driver failed to check map error"
+			   "[device address=0x%016llx] [size=%llu bytes] "
+			   "[mapped as %s]",
+			   ref->dev_addr, ref->size,
+			   type2name[entry->type]);
+	}
+}
+
 static int device_dma_allocations(struct device *dev, struct dma_debug_entry **out_entry)
 {
 	struct dma_debug_entry *entry;
@@ -724,6 +737,7 @@ static int device_dma_allocations(struct device *dev, struct dma_debug_entry **o
 		spin_lock(&dma_entry_hash[i].lock);
 		list_for_each_entry(entry, &dma_entry_hash[i].list, list) {
 			if (entry->dev == dev) {
+				check_dma_mapping_error(entry, entry);
 				count += 1;
 				*out_entry = entry;
 			}
@@ -928,14 +942,7 @@ static void check_unmap(struct dma_debug_entry *ref)
 			   dir2name[ref->direction]);
 	}
 
-	if (entry->map_err_type == MAP_ERR_NOT_CHECKED) {
-		err_printk(ref->dev, entry,
-			   "DMA-API: device driver failed to check map error"
-			   "[device address=0x%016llx] [size=%llu bytes] "
-			   "[mapped as %s]",
-			   ref->dev_addr, ref->size,
-			   type2name[entry->type]);
-	}
+	check_dma_mapping_error(ref, entry);
 
 	hash_bucket_del(entry);
 	dma_entry_free(entry);
-- 
1.8.3.2


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

* Re: [PATCH] dma-debug: enhance dma_debug_device_change() to check for mapping errors
  2013-11-12 20:51 [PATCH] dma-debug: enhance dma_debug_device_change() to check for mapping errors Shuah Khan
@ 2013-11-12 22:12 ` Alexander Duyck
  2013-11-12 22:20   ` Shuah Khan
  0 siblings, 1 reply; 4+ messages in thread
From: Alexander Duyck @ 2013-11-12 22:12 UTC (permalink / raw)
  To: Shuah Khan; +Cc: akpm, joro, linux-kernel, shuahkhan

I think this might be overdoing the error checking by a bit.  I would
much rather have the DMA leaked error be visible than have it buried
under messages about the failure to check for DMA errors.  In my mind
the DMA buffer leak is much more serious than the failure to check for
mapping errors.

Thanks,

Alex


On 11/12/2013 12:51 PM, Shuah Khan wrote:
> dma-debug checks to verify if driver validated the address returned by
> dma mapping routines when driver does unmap. If a driver doesn't call
> unmap, failure to check mapping errors isn't detected and reported.
>
> Enhancing existing bus notifier_call dma_debug_device_change() to check
> for mapping errors at the same time it detects leaked dma buffers for
> BUS_NOTIFY_UNBOUND_DRIVER event.
>
> Signed-off-by: Shuah Khan <shuah.kh@samsung.com>
> ---
>  lib/dma-debug.c | 23 +++++++++++++++--------
>  1 file changed, 15 insertions(+), 8 deletions(-)
>
> diff --git a/lib/dma-debug.c b/lib/dma-debug.c
> index d87a17a..6c17b90 100644
> --- a/lib/dma-debug.c
> +++ b/lib/dma-debug.c
> @@ -712,6 +712,19 @@ out_err:
>  	return -ENOMEM;
>  }
>  
> +static void check_dma_mapping_error(struct dma_debug_entry *ref,
> +				    struct dma_debug_entry *entry)
> +{
> +	if (entry->map_err_type == MAP_ERR_NOT_CHECKED) {
> +		err_printk(ref->dev, entry,
> +			   "DMA-API: device driver failed to check map error"
> +			   "[device address=0x%016llx] [size=%llu bytes] "
> +			   "[mapped as %s]",
> +			   ref->dev_addr, ref->size,
> +			   type2name[entry->type]);
> +	}
> +}
> +
>  static int device_dma_allocations(struct device *dev, struct dma_debug_entry **out_entry)
>  {
>  	struct dma_debug_entry *entry;
> @@ -724,6 +737,7 @@ static int device_dma_allocations(struct device *dev, struct dma_debug_entry **o
>  		spin_lock(&dma_entry_hash[i].lock);
>  		list_for_each_entry(entry, &dma_entry_hash[i].list, list) {
>  			if (entry->dev == dev) {
> +				check_dma_mapping_error(entry, entry);
>  				count += 1;
>  				*out_entry = entry;
>  			}
> @@ -928,14 +942,7 @@ static void check_unmap(struct dma_debug_entry *ref)
>  			   dir2name[ref->direction]);
>  	}
>  
> -	if (entry->map_err_type == MAP_ERR_NOT_CHECKED) {
> -		err_printk(ref->dev, entry,
> -			   "DMA-API: device driver failed to check map error"
> -			   "[device address=0x%016llx] [size=%llu bytes] "
> -			   "[mapped as %s]",
> -			   ref->dev_addr, ref->size,
> -			   type2name[entry->type]);
> -	}
> +	check_dma_mapping_error(ref, entry);
>  
>  	hash_bucket_del(entry);
>  	dma_entry_free(entry);


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

* Re: [PATCH] dma-debug: enhance dma_debug_device_change() to check for mapping errors
  2013-11-12 22:12 ` Alexander Duyck
@ 2013-11-12 22:20   ` Shuah Khan
  2013-11-13  0:22     ` Alexander Duyck
  0 siblings, 1 reply; 4+ messages in thread
From: Shuah Khan @ 2013-11-12 22:20 UTC (permalink / raw)
  To: Alexander Duyck; +Cc: akpm, joro, linux-kernel, shuahkhan, Shuah Khan

On 11/12/2013 03:12 PM, Alexander Duyck wrote:
> I think this might be overdoing the error checking by a bit.  I would
> much rather have the DMA leaked error be visible than have it buried
> under messages about the failure to check for DMA errors.  In my mind
> the DMA buffer leak is much more serious than the failure to check for
> mapping errors.
>

I agree DMA leak message is more important. Would you like to see just 
one message if mapping errors are found? Instead of printing the entire 
stacktrace like it does now, it could just do warn.

-- Shuah


-- 
Shuah Khan
Senior Linux Kernel Developer - Open Source Group
Samsung Research America(Silicon Valley)
shuah.kh@samsung.com | (970) 672-0658

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

* Re: [PATCH] dma-debug: enhance dma_debug_device_change() to check for mapping errors
  2013-11-12 22:20   ` Shuah Khan
@ 2013-11-13  0:22     ` Alexander Duyck
  0 siblings, 0 replies; 4+ messages in thread
From: Alexander Duyck @ 2013-11-13  0:22 UTC (permalink / raw)
  To: shuah.kh; +Cc: akpm, joro, linux-kernel, shuahkhan

On 11/12/2013 02:20 PM, Shuah Khan wrote:
> On 11/12/2013 03:12 PM, Alexander Duyck wrote:
>> I think this might be overdoing the error checking by a bit.  I would
>> much rather have the DMA leaked error be visible than have it buried
>> under messages about the failure to check for DMA errors.  In my mind
>> the DMA buffer leak is much more serious than the failure to check for
>> mapping errors.
>>
>
> I agree DMA leak message is more important. Would you like to see just
> one message if mapping errors are found? Instead of printing the
> entire stacktrace like it does now, it could just do warn.
>
> -- Shuah
>
>

I think only one message would be preferred.  If nothing else you might
update the function so that it only dumps the DMA mapping error check on
the first one found and then goes quiet after that.  There is no point
in displaying the same error message multiple times since that is likely
what we would see.

Thanks,

Alex

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

end of thread, other threads:[~2013-11-13  0:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-11-12 20:51 [PATCH] dma-debug: enhance dma_debug_device_change() to check for mapping errors Shuah Khan
2013-11-12 22:12 ` Alexander Duyck
2013-11-12 22:20   ` Shuah Khan
2013-11-13  0:22     ` Alexander Duyck

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