Patchwork [11/16] dma-debug: add checking for [alloc|free]_coherent

login
register
mail settings
Submitter Joerg Roedel
Date Jan. 9, 2009, 4:19 p.m.
Message ID <1231517970-20288-12-git-send-email-joerg.roedel@amd.com>
Download mbox | patch
Permalink /patch/17538/
State Not Applicable
Delegated to: David Miller
Headers show

Comments

Joerg Roedel - Jan. 9, 2009, 4:19 p.m.
Impact: add debug callbacks for dma_[alloc|free]_coherent

Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
---
 include/linux/dma-debug.h |   16 ++++++++++++++++
 lib/dma-debug.c           |   45 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 61 insertions(+), 0 deletions(-)
FUJITA Tomonori - Jan. 11, 2009, 6:25 a.m.
On Fri, 9 Jan 2009 17:19:25 +0100
Joerg Roedel <joerg.roedel@amd.com> wrote:

> Impact: add debug callbacks for dma_[alloc|free]_coherent
> 
> Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
> ---
>  include/linux/dma-debug.h |   16 ++++++++++++++++
>  lib/dma-debug.c           |   45 +++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 61 insertions(+), 0 deletions(-)
> 
> diff --git a/include/linux/dma-debug.h b/include/linux/dma-debug.h
> index b2131f4..a28a701 100644
> --- a/include/linux/dma-debug.h
> +++ b/include/linux/dma-debug.h
> @@ -40,6 +40,12 @@ extern void debug_map_sg(struct device *dev, struct scatterlist *sg,
>  extern void debug_unmap_sg(struct device *dev, struct scatterlist *sglist,
>  			   int nelems, int dir);
>  
> +extern void debug_alloc_coherent(struct device *dev, size_t size,
> +				 dma_addr_t dma_addr, void *virt);
> +
> +extern void debug_free_coherent(struct device *dev, size_t size,
> +				void *virt, dma_addr_t addr);
> +
>  #else /* CONFIG_DMA_API_DEBUG */
>  
>  static inline void dma_debug_init(u32 num_entries)
> @@ -68,6 +74,16 @@ static inline void debug_unmap_sg(struct device *dev,
>  {
>  }
>  
> +static inline void debug_alloc_coherent(struct device *dev, size_t size,
> +					dma_addr_t dma_addr, void *virt)
> +{
> +}
> +
> +static inline void debug_free_coherent(struct device *dev, size_t size,
> +				       void *virt, dma_addr_t addr)
> +{
> +}
> +
>  #endif /* CONFIG_DMA_API_DEBUG */
>  
>  #endif /* __DMA_DEBUG_H */
> diff --git a/lib/dma-debug.c b/lib/dma-debug.c
> index e6d45f9..a4a5b0f 100644
> --- a/lib/dma-debug.c
> +++ b/lib/dma-debug.c
> @@ -604,3 +604,48 @@ void debug_unmap_sg(struct device *dev, struct scatterlist *sglist,
>  }
>  EXPORT_SYMBOL(debug_unmap_sg);
>  
> +void debug_alloc_coherent(struct device *dev, size_t size,
> +			  dma_addr_t dma_addr, void *virt)
> +{
> +	struct dma_debug_entry *entry;
> +
> +	if (global_disable)
> +		return;
> +
> +	if (dma_addr == bad_dma_address)
> +		return;

Only X86 has 'bad_dma_address' (IA64 also has with some configurations
though). You need to use dma_mapping_error, as I pointed out in the
previous submission.

I recommend you to try this on one non-x86 box (at least). Even if you
don't have non x86, you can use cross compiler.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
FUJITA Tomonori - Jan. 11, 2009, 6:30 a.m.
On Sun, 11 Jan 2009 15:25:42 +0900
FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> wrote:

> On Fri, 9 Jan 2009 17:19:25 +0100
> Joerg Roedel <joerg.roedel@amd.com> wrote:
> 
> > Impact: add debug callbacks for dma_[alloc|free]_coherent
> > 
> > Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
> > ---
> >  include/linux/dma-debug.h |   16 ++++++++++++++++
> >  lib/dma-debug.c           |   45 +++++++++++++++++++++++++++++++++++++++++++++
> >  2 files changed, 61 insertions(+), 0 deletions(-)
> > 
> > diff --git a/include/linux/dma-debug.h b/include/linux/dma-debug.h
> > index b2131f4..a28a701 100644
> > --- a/include/linux/dma-debug.h
> > +++ b/include/linux/dma-debug.h
> > @@ -40,6 +40,12 @@ extern void debug_map_sg(struct device *dev, struct scatterlist *sg,
> >  extern void debug_unmap_sg(struct device *dev, struct scatterlist *sglist,
> >  			   int nelems, int dir);
> >  
> > +extern void debug_alloc_coherent(struct device *dev, size_t size,
> > +				 dma_addr_t dma_addr, void *virt);
> > +
> > +extern void debug_free_coherent(struct device *dev, size_t size,
> > +				void *virt, dma_addr_t addr);
> > +
> >  #else /* CONFIG_DMA_API_DEBUG */
> >  
> >  static inline void dma_debug_init(u32 num_entries)
> > @@ -68,6 +74,16 @@ static inline void debug_unmap_sg(struct device *dev,
> >  {
> >  }
> >  
> > +static inline void debug_alloc_coherent(struct device *dev, size_t size,
> > +					dma_addr_t dma_addr, void *virt)
> > +{
> > +}
> > +
> > +static inline void debug_free_coherent(struct device *dev, size_t size,
> > +				       void *virt, dma_addr_t addr)
> > +{
> > +}
> > +
> >  #endif /* CONFIG_DMA_API_DEBUG */
> >  
> >  #endif /* __DMA_DEBUG_H */
> > diff --git a/lib/dma-debug.c b/lib/dma-debug.c
> > index e6d45f9..a4a5b0f 100644
> > --- a/lib/dma-debug.c
> > +++ b/lib/dma-debug.c
> > @@ -604,3 +604,48 @@ void debug_unmap_sg(struct device *dev, struct scatterlist *sglist,
> >  }
> >  EXPORT_SYMBOL(debug_unmap_sg);
> >  
> > +void debug_alloc_coherent(struct device *dev, size_t size,
> > +			  dma_addr_t dma_addr, void *virt)
> > +{
> > +	struct dma_debug_entry *entry;
> > +
> > +	if (global_disable)
> > +		return;
> > +
> > +	if (dma_addr == bad_dma_address)
> > +		return;
> 
> Only X86 has 'bad_dma_address' (IA64 also has with some configurations
> though). You need to use dma_mapping_error, as I pointed out in the
> previous submission.

Oops, this is for dma_alloc_coherent so you need to check 'virt'
instead of dma_mapping_error().
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Joerg Roedel - Jan. 11, 2009, 7:59 a.m.
On Sun, Jan 11, 2009 at 03:30:14PM +0900, FUJITA Tomonori wrote:
> On Sun, 11 Jan 2009 15:25:42 +0900
> FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> wrote:
> 
> > On Fri, 9 Jan 2009 17:19:25 +0100
> > Joerg Roedel <joerg.roedel@amd.com> wrote:
> > 
> > > Impact: add debug callbacks for dma_[alloc|free]_coherent
> > > 
> > > Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
> > > ---
> > >  include/linux/dma-debug.h |   16 ++++++++++++++++
> > >  lib/dma-debug.c           |   45 +++++++++++++++++++++++++++++++++++++++++++++
> > >  2 files changed, 61 insertions(+), 0 deletions(-)
> > > 
> > > diff --git a/include/linux/dma-debug.h b/include/linux/dma-debug.h
> > > index b2131f4..a28a701 100644
> > > --- a/include/linux/dma-debug.h
> > > +++ b/include/linux/dma-debug.h
> > > @@ -40,6 +40,12 @@ extern void debug_map_sg(struct device *dev, struct scatterlist *sg,
> > >  extern void debug_unmap_sg(struct device *dev, struct scatterlist *sglist,
> > >  			   int nelems, int dir);
> > >  
> > > +extern void debug_alloc_coherent(struct device *dev, size_t size,
> > > +				 dma_addr_t dma_addr, void *virt);
> > > +
> > > +extern void debug_free_coherent(struct device *dev, size_t size,
> > > +				void *virt, dma_addr_t addr);
> > > +
> > >  #else /* CONFIG_DMA_API_DEBUG */
> > >  
> > >  static inline void dma_debug_init(u32 num_entries)
> > > @@ -68,6 +74,16 @@ static inline void debug_unmap_sg(struct device *dev,
> > >  {
> > >  }
> > >  
> > > +static inline void debug_alloc_coherent(struct device *dev, size_t size,
> > > +					dma_addr_t dma_addr, void *virt)
> > > +{
> > > +}
> > > +
> > > +static inline void debug_free_coherent(struct device *dev, size_t size,
> > > +				       void *virt, dma_addr_t addr)
> > > +{
> > > +}
> > > +
> > >  #endif /* CONFIG_DMA_API_DEBUG */
> > >  
> > >  #endif /* __DMA_DEBUG_H */
> > > diff --git a/lib/dma-debug.c b/lib/dma-debug.c
> > > index e6d45f9..a4a5b0f 100644
> > > --- a/lib/dma-debug.c
> > > +++ b/lib/dma-debug.c
> > > @@ -604,3 +604,48 @@ void debug_unmap_sg(struct device *dev, struct scatterlist *sglist,
> > >  }
> > >  EXPORT_SYMBOL(debug_unmap_sg);
> > >  
> > > +void debug_alloc_coherent(struct device *dev, size_t size,
> > > +			  dma_addr_t dma_addr, void *virt)
> > > +{
> > > +	struct dma_debug_entry *entry;
> > > +
> > > +	if (global_disable)
> > > +		return;
> > > +
> > > +	if (dma_addr == bad_dma_address)
> > > +		return;
> > 
> > Only X86 has 'bad_dma_address' (IA64 also has with some configurations
> > though). You need to use dma_mapping_error, as I pointed out in the
> > previous submission.
> 
> Oops, this is for dma_alloc_coherent so you need to check 'virt'
> instead of dma_mapping_error().

Ah, true. Thanks. I will fix that.

Joerg
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/include/linux/dma-debug.h b/include/linux/dma-debug.h
index b2131f4..a28a701 100644
--- a/include/linux/dma-debug.h
+++ b/include/linux/dma-debug.h
@@ -40,6 +40,12 @@  extern void debug_map_sg(struct device *dev, struct scatterlist *sg,
 extern void debug_unmap_sg(struct device *dev, struct scatterlist *sglist,
 			   int nelems, int dir);
 
+extern void debug_alloc_coherent(struct device *dev, size_t size,
+				 dma_addr_t dma_addr, void *virt);
+
+extern void debug_free_coherent(struct device *dev, size_t size,
+				void *virt, dma_addr_t addr);
+
 #else /* CONFIG_DMA_API_DEBUG */
 
 static inline void dma_debug_init(u32 num_entries)
@@ -68,6 +74,16 @@  static inline void debug_unmap_sg(struct device *dev,
 {
 }
 
+static inline void debug_alloc_coherent(struct device *dev, size_t size,
+					dma_addr_t dma_addr, void *virt)
+{
+}
+
+static inline void debug_free_coherent(struct device *dev, size_t size,
+				       void *virt, dma_addr_t addr)
+{
+}
+
 #endif /* CONFIG_DMA_API_DEBUG */
 
 #endif /* __DMA_DEBUG_H */
diff --git a/lib/dma-debug.c b/lib/dma-debug.c
index e6d45f9..a4a5b0f 100644
--- a/lib/dma-debug.c
+++ b/lib/dma-debug.c
@@ -604,3 +604,48 @@  void debug_unmap_sg(struct device *dev, struct scatterlist *sglist,
 }
 EXPORT_SYMBOL(debug_unmap_sg);
 
+void debug_alloc_coherent(struct device *dev, size_t size,
+			  dma_addr_t dma_addr, void *virt)
+{
+	struct dma_debug_entry *entry;
+
+	if (global_disable)
+		return;
+
+	if (dma_addr == bad_dma_address)
+		return;
+
+	entry = dma_entry_alloc();
+	if (!entry)
+		return;
+
+	entry->type      = dma_debug_coherent;
+	entry->dev       = dev;
+	entry->cpu_addr  = virt;
+	entry->size      = size;
+	entry->dev_addr  = dma_addr;
+	entry->direction = DMA_BIDIRECTIONAL;
+
+	add_dma_entry(entry);
+}
+EXPORT_SYMBOL(debug_alloc_coherent);
+
+void debug_free_coherent(struct device *dev, size_t size,
+			 void *virt, dma_addr_t addr)
+{
+	struct dma_debug_entry ref = {
+		.type           = dma_debug_coherent,
+		.dev            = dev,
+		.cpu_addr       = virt,
+		.dev_addr       = addr,
+		.size           = size,
+		.direction      = DMA_BIDIRECTIONAL,
+	};
+
+	if (global_disable)
+		return;
+
+	check_unmap(&ref);
+}
+EXPORT_SYMBOL(debug_free_coherent);
+