All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] dma-debug: fix to not have dependency on get_dma_ops() interface
@ 2012-11-03 23:00 Shuah Khan
  2012-11-05 13:59 ` Konrad Rzeszutek Wilk
  2012-11-17 12:07 ` Joerg Roedel
  0 siblings, 2 replies; 4+ messages in thread
From: Shuah Khan @ 2012-11-03 23:00 UTC (permalink / raw)
  To: Joerg Roedel, Andrew Morton, kubakici, stern, Greg KH,
	Konrad Rzeszutek Wilk, Mark Salter
  Cc: LKML, shuahkhan

dma-debug depends on get_dma_ops() interface. Several architectures
do not define dma_ops and get_dma_ops(). When dma debug interfaces are
used on an architecture (e.g: c6x) that doesn't define get_dmap_ops(),
compilation fails. Changing dma-debug to call dma_mapping_error() instead
of defining its own that calls get_dma_ops(), such that the internal use of
dma_mapping_error() doesn't interfere with the debug_dma_mapping_error()
interface's mapping error checks. Moving dma_mapping_error() checks in
check_unmap() under the dma debug entry not found is sufficient to fix the
problem.

Reference: https://lkml.org/lkml/2012/10/26/367

Signed-off-by: Shuah Khan <shuah.khan@hp.com>
Reported-by: Mark Salter <msalter@redhat.com>
---
 lib/dma-debug.c |   29 +++++++----------------------
 1 file changed, 7 insertions(+), 22 deletions(-)

diff --git a/lib/dma-debug.c b/lib/dma-debug.c
index 59f4a1a..5e396ac 100644
--- a/lib/dma-debug.c
+++ b/lib/dma-debug.c
@@ -852,37 +852,22 @@ static __init int dma_debug_entries_cmdline(char *str)
 __setup("dma_debug=", dma_debug_cmdline);
 __setup("dma_debug_entries=", dma_debug_entries_cmdline);
 
-/* Calling dma_mapping_error() from dma-debug api will result in calling
-   debug_dma_mapping_error() - need internal mapping error routine to
-   avoid debug checks */
-#ifndef DMA_ERROR_CODE
-#define DMA_ERROR_CODE 0
-#endif
-static inline int has_mapping_error(struct device *dev, dma_addr_t dma_addr)
-{
-	const struct dma_map_ops *ops = get_dma_ops(dev);
-	if (ops->mapping_error)
-		return ops->mapping_error(dev, dma_addr);
-
-	return (dma_addr == DMA_ERROR_CODE);
-}
-
 static void check_unmap(struct dma_debug_entry *ref)
 {
 	struct dma_debug_entry *entry;
 	struct hash_bucket *bucket;
 	unsigned long flags;
 
-	if (unlikely(has_mapping_error(ref->dev, ref->dev_addr))) {
-		err_printk(ref->dev, NULL, "DMA-API: device driver tries "
-			   "to free an invalid DMA memory address\n");
-		return;
-	}
-
 	bucket = get_hash_bucket(ref, &flags);
 	entry = bucket_find_exact(bucket, ref);
 
 	if (!entry) {
+		if (dma_mapping_error(ref->dev, ref->dev_addr)) {
+			err_printk(ref->dev, NULL,
+				   "DMA-API: device driver tries "
+				   "to free an invalid DMA memory address\n");
+			return;
+		}
 		err_printk(ref->dev, NULL, "DMA-API: device driver tries "
 			   "to free DMA memory it has not allocated "
 			   "[device address=0x%016llx] [size=%llu bytes]\n",
@@ -1055,7 +1040,7 @@ void debug_dma_map_page(struct device *dev, struct page *page, size_t offset,
 	if (unlikely(global_disable))
 		return;
 
-	if (unlikely(has_mapping_error(dev, dma_addr)))
+	if (dma_mapping_error(dev, dma_addr))
 		return;
 
 	entry = dma_entry_alloc();
-- 
1.7.9.5




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

* Re: [PATCH] dma-debug: fix to not have dependency on get_dma_ops() interface
  2012-11-03 23:00 [PATCH] dma-debug: fix to not have dependency on get_dma_ops() interface Shuah Khan
@ 2012-11-05 13:59 ` Konrad Rzeszutek Wilk
  2012-11-15 17:04   ` Shuah Khan
  2012-11-17 12:07 ` Joerg Roedel
  1 sibling, 1 reply; 4+ messages in thread
From: Konrad Rzeszutek Wilk @ 2012-11-05 13:59 UTC (permalink / raw)
  To: Shuah Khan
  Cc: Joerg Roedel, Andrew Morton, kubakici, stern, Greg KH,
	Mark Salter, LKML, shuahkhan

On Sat, Nov 03, 2012 at 05:00:07PM -0600, Shuah Khan wrote:
> dma-debug depends on get_dma_ops() interface. Several architectures
> do not define dma_ops and get_dma_ops(). When dma debug interfaces are
> used on an architecture (e.g: c6x) that doesn't define get_dmap_ops(),
> compilation fails. Changing dma-debug to call dma_mapping_error() instead
> of defining its own that calls get_dma_ops(), such that the internal use of
> dma_mapping_error() doesn't interfere with the debug_dma_mapping_error()
> interface's mapping error checks. Moving dma_mapping_error() checks in
> check_unmap() under the dma debug entry not found is sufficient to fix the
> problem.

OK.

It looks ok to me.

> -   debug_dma_mapping_error() - need internal mapping error routine to
> -   avoid debug checks */
> -#ifndef DMA_ERROR_CODE
> -#define DMA_ERROR_CODE 0
> -#endif
> -static inline int has_mapping_error(struct device *dev, dma_addr_t dma_addr)
> -{
> -	const struct dma_map_ops *ops = get_dma_ops(dev);
> -	if (ops->mapping_error)
> -		return ops->mapping_error(dev, dma_addr);
> -
> -	return (dma_addr == DMA_ERROR_CODE);
> -}
> -
>  static void check_unmap(struct dma_debug_entry *ref)
>  {
>  	struct dma_debug_entry *entry;
>  	struct hash_bucket *bucket;
>  	unsigned long flags;
>  
> -	if (unlikely(has_mapping_error(ref->dev, ref->dev_addr))) {
> -		err_printk(ref->dev, NULL, "DMA-API: device driver tries "
> -			   "to free an invalid DMA memory address\n");
> -		return;
> -	}
> -
>  	bucket = get_hash_bucket(ref, &flags);
>  	entry = bucket_find_exact(bucket, ref);
>  
>  	if (!entry) {
> +		if (dma_mapping_error(ref->dev, ref->dev_addr)) {
> +			err_printk(ref->dev, NULL,
> +				   "DMA-API: device driver tries "
> +				   "to free an invalid DMA memory address\n");
> +			return;
> +		}
>  		err_printk(ref->dev, NULL, "DMA-API: device driver tries "
>  			   "to free DMA memory it has not allocated "
>  			   "[device address=0x%016llx] [size=%llu bytes]\n",
> @@ -1055,7 +1040,7 @@ void debug_dma_map_page(struct device *dev, struct page *page, size_t offset,
>  	if (unlikely(global_disable))
>  		return;
>  
> -	if (unlikely(has_mapping_error(dev, dma_addr)))
> +	if (dma_mapping_error(dev, dma_addr))
>  		return;
>  
>  	entry = dma_entry_alloc();
> -- 
> 1.7.9.5
> 
> 

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

* Re: [PATCH] dma-debug: fix to not have dependency on get_dma_ops() interface
  2012-11-05 13:59 ` Konrad Rzeszutek Wilk
@ 2012-11-15 17:04   ` Shuah Khan
  0 siblings, 0 replies; 4+ messages in thread
From: Shuah Khan @ 2012-11-15 17:04 UTC (permalink / raw)
  To: Marek Szyprowski
  Cc: Joerg Roedel, Andrew Morton, kubakici, stern, Greg KH,
	Mark Salter, LKML, konrad.wilk, shuahkhan

On Mon, 2012-11-05 at 08:59 -0500, Konrad Rzeszutek Wilk wrote:
> On Sat, Nov 03, 2012 at 05:00:07PM -0600, Shuah Khan wrote:
> > dma-debug depends on get_dma_ops() interface. Several architectures
> > do not define dma_ops and get_dma_ops(). When dma debug interfaces are
> > used on an architecture (e.g: c6x) that doesn't define get_dmap_ops(),
> > compilation fails. Changing dma-debug to call dma_mapping_error() instead
> > of defining its own that calls get_dma_ops(), such that the internal use of
> > dma_mapping_error() doesn't interfere with the debug_dma_mapping_error()
> > interface's mapping error checks. Moving dma_mapping_error() checks in
> > check_unmap() under the dma debug entry not found is sufficient to fix the
> > problem.
> 
> OK.
> 
> It looks ok to me.

Marek,

Following up on our off-line discussion about your offer to pull
dma-debug patch and the arch patches that call debug_dma_mapping_error()
interface in to your tree. Thanks again for offering to do that. This
patch is depends on the first debug_dma_mapping_error() patch that is in
linux-next and in the dma-debug tree.

Reference - https://lkml.org/lkml/2012/10/8/296

linux-next commit-id is commit 6c9c6d6301287e369a754d628230fa6e50cdb74b

You will need to pull these two first into your tree and then the arch
patches - I will include you on my responses to those patches shortly.

-- Shuah

> 
> > -   debug_dma_mapping_error() - need internal mapping error routine to
> > -   avoid debug checks */
> > -#ifndef DMA_ERROR_CODE
> > -#define DMA_ERROR_CODE 0
> > -#endif
> > -static inline int has_mapping_error(struct device *dev, dma_addr_t dma_addr)
> > -{
> > -	const struct dma_map_ops *ops = get_dma_ops(dev);
> > -	if (ops->mapping_error)
> > -		return ops->mapping_error(dev, dma_addr);
> > -
> > -	return (dma_addr == DMA_ERROR_CODE);
> > -}
> > -
> >  static void check_unmap(struct dma_debug_entry *ref)
> >  {
> >  	struct dma_debug_entry *entry;
> >  	struct hash_bucket *bucket;
> >  	unsigned long flags;
> >  
> > -	if (unlikely(has_mapping_error(ref->dev, ref->dev_addr))) {
> > -		err_printk(ref->dev, NULL, "DMA-API: device driver tries "
> > -			   "to free an invalid DMA memory address\n");
> > -		return;
> > -	}
> > -
> >  	bucket = get_hash_bucket(ref, &flags);
> >  	entry = bucket_find_exact(bucket, ref);
> >  
> >  	if (!entry) {
> > +		if (dma_mapping_error(ref->dev, ref->dev_addr)) {
> > +			err_printk(ref->dev, NULL,
> > +				   "DMA-API: device driver tries "
> > +				   "to free an invalid DMA memory address\n");
> > +			return;
> > +		}
> >  		err_printk(ref->dev, NULL, "DMA-API: device driver tries "
> >  			   "to free DMA memory it has not allocated "
> >  			   "[device address=0x%016llx] [size=%llu bytes]\n",
> > @@ -1055,7 +1040,7 @@ void debug_dma_map_page(struct device *dev, struct page *page, size_t offset,
> >  	if (unlikely(global_disable))
> >  		return;
> >  
> > -	if (unlikely(has_mapping_error(dev, dma_addr)))
> > +	if (dma_mapping_error(dev, dma_addr))
> >  		return;
> >  
> >  	entry = dma_entry_alloc();
> > -- 
> > 1.7.9.5
> > 
> > 



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

* Re: [PATCH] dma-debug: fix to not have dependency on get_dma_ops() interface
  2012-11-03 23:00 [PATCH] dma-debug: fix to not have dependency on get_dma_ops() interface Shuah Khan
  2012-11-05 13:59 ` Konrad Rzeszutek Wilk
@ 2012-11-17 12:07 ` Joerg Roedel
  1 sibling, 0 replies; 4+ messages in thread
From: Joerg Roedel @ 2012-11-17 12:07 UTC (permalink / raw)
  To: Shuah Khan
  Cc: Andrew Morton, kubakici, stern, Greg KH, Konrad Rzeszutek Wilk,
	Mark Salter, LKML, shuahkhan

On Sat, Nov 03, 2012 at 05:00:07PM -0600, Shuah Khan wrote:
> dma-debug depends on get_dma_ops() interface. Several architectures
> do not define dma_ops and get_dma_ops(). When dma debug interfaces are
> used on an architecture (e.g: c6x) that doesn't define get_dmap_ops(),
> compilation fails. Changing dma-debug to call dma_mapping_error() instead
> of defining its own that calls get_dma_ops(), such that the internal use of
> dma_mapping_error() doesn't interfere with the debug_dma_mapping_error()
> interface's mapping error checks. Moving dma_mapping_error() checks in
> check_unmap() under the dma debug entry not found is sufficient to fix the
> problem.
> 
> Reference: https://lkml.org/lkml/2012/10/26/367
> 
> Signed-off-by: Shuah Khan <shuah.khan@hp.com>
> Reported-by: Mark Salter <msalter@redhat.com>

Sorry for the delay. I applied the patch to the dma-debug branch.


	Joerg



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

end of thread, other threads:[~2012-11-17 12:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-03 23:00 [PATCH] dma-debug: fix to not have dependency on get_dma_ops() interface Shuah Khan
2012-11-05 13:59 ` Konrad Rzeszutek Wilk
2012-11-15 17:04   ` Shuah Khan
2012-11-17 12:07 ` Joerg Roedel

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.