diff mbox

[10/16] dma-debug: add add checking for map/unmap_sg

Message ID 1231517970-20288-11-git-send-email-joerg.roedel@amd.com
State Not Applicable, archived
Delegated to: David Miller
Headers show

Commit Message

Joerg Roedel Jan. 9, 2009, 4:19 p.m. UTC
Impact: add debug callbacks for dma_{un}map_sg

Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
---
 include/linux/dma-debug.h |   15 ++++++++++++
 lib/dma-debug.c           |   53 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 68 insertions(+), 0 deletions(-)

Comments

Evgeniy Polyakov Jan. 9, 2009, 6:08 p.m. UTC | #1
On Fri, Jan 09, 2009 at 05:19:24PM +0100, Joerg Roedel (joerg.roedel@amd.com) wrote:
> +void debug_map_sg(struct device *dev, struct scatterlist *sg,
> +		  int nents, int direction)
> +{
> +	struct dma_debug_entry *entry;
> +	struct scatterlist *s;
> +	int i;
> +
> +	if (global_disable)
> +		return;
> +
> +	for_each_sg(sg, s, nents, i) {
> +		entry = dma_entry_alloc();
> +		if (!entry)
> +			return;
> +
> +		entry->type      = dma_debug_sg;
> +		entry->dev       = dev;
> +		entry->cpu_addr  = sg_virt(s);
> +		entry->size      = s->length;
> +		entry->dev_addr  = s->dma_address;
> +		entry->direction = direction;
> +
> +		add_dma_entry(entry);
> +	}
> +}
> +EXPORT_SYMBOL(debug_map_sg);
> +
> +void debug_unmap_sg(struct device *dev, struct scatterlist *sglist,
> +		    int nelems, int dir)
> +{
> +	struct scatterlist *s;
> +	int i;
> +
> +	if (global_disable)
> +		return;
> +
> +	for_each_sg(sglist, s, nelems, i) {
> +
> +		struct dma_debug_entry ref = {
> +			.type           = dma_debug_sg,
> +			.dev            = dev,
> +			.cpu_addr       = sg_virt(s),
> +			.dev_addr       = s->dma_address,
> +			.size           = s->length,
> +			.direction      = dir,
> +		};
> +
> +		check_unmap(&ref);

Will this print false errors if above map debug failed to add an entry
into the list?
Joerg Roedel Jan. 9, 2009, 6:11 p.m. UTC | #2
On Fri, Jan 09, 2009 at 09:08:36PM +0300, Evgeniy Polyakov wrote:
> On Fri, Jan 09, 2009 at 05:19:24PM +0100, Joerg Roedel (joerg.roedel@amd.com) wrote:
> > +void debug_map_sg(struct device *dev, struct scatterlist *sg,
> > +		  int nents, int direction)
> > +{
> > +	struct dma_debug_entry *entry;
> > +	struct scatterlist *s;
> > +	int i;
> > +
> > +	if (global_disable)
> > +		return;
> > +
> > +	for_each_sg(sg, s, nents, i) {
> > +		entry = dma_entry_alloc();
> > +		if (!entry)
> > +			return;
> > +
> > +		entry->type      = dma_debug_sg;
> > +		entry->dev       = dev;
> > +		entry->cpu_addr  = sg_virt(s);
> > +		entry->size      = s->length;
> > +		entry->dev_addr  = s->dma_address;
> > +		entry->direction = direction;
> > +
> > +		add_dma_entry(entry);
> > +	}
> > +}
> > +EXPORT_SYMBOL(debug_map_sg);
> > +
> > +void debug_unmap_sg(struct device *dev, struct scatterlist *sglist,
> > +		    int nelems, int dir)
> > +{
> > +	struct scatterlist *s;
> > +	int i;
> > +
> > +	if (global_disable)
> > +		return;
> > +
> > +	for_each_sg(sglist, s, nelems, i) {
> > +
> > +		struct dma_debug_entry ref = {
> > +			.type           = dma_debug_sg,
> > +			.dev            = dev,
> > +			.cpu_addr       = sg_virt(s),
> > +			.dev_addr       = s->dma_address,
> > +			.size           = s->length,
> > +			.direction      = dir,
> > +		};
> > +
> > +		check_unmap(&ref);
> 
> Will this print false errors if above map debug failed to add an entry
> into the list?

No. The code disables itself if adding an entry fails. This can only
happen when we run out of preallocated dma_debug_entries.

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
diff mbox

Patch

diff --git a/include/linux/dma-debug.h b/include/linux/dma-debug.h
index 82ae9ca..b2131f4 100644
--- a/include/linux/dma-debug.h
+++ b/include/linux/dma-debug.h
@@ -34,6 +34,11 @@  extern void debug_map_single(struct device *dev, void *ptr, size_t size,
 extern void debug_unmap_single(struct device *dev, dma_addr_t addr,
 			       size_t size, int direction);
 
+extern void debug_map_sg(struct device *dev, struct scatterlist *sg,
+			 int nents, int direction);
+
+extern void debug_unmap_sg(struct device *dev, struct scatterlist *sglist,
+			   int nelems, int dir);
 
 #else /* CONFIG_DMA_API_DEBUG */
 
@@ -52,6 +57,16 @@  static inline void debug_unmap_single(struct device *dev, dma_addr_t addr,
 {
 }
 
+static inline void debug_map_sg(struct device *dev, struct scatterlist *sg,
+				int nents, int direction)
+{
+}
+
+static inline void debug_unmap_sg(struct device *dev,
+				  struct scatterlist *sglist,
+				  int nelems, int dir)
+{
+}
 
 #endif /* CONFIG_DMA_API_DEBUG */
 
diff --git a/lib/dma-debug.c b/lib/dma-debug.c
index d4d14e5..e6d45f9 100644
--- a/lib/dma-debug.c
+++ b/lib/dma-debug.c
@@ -17,6 +17,7 @@ 
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  */
 
+#include <linux/scatterlist.h>
 #include <linux/dma-mapping.h>
 #include <linux/dma-debug.h>
 #include <linux/spinlock.h>
@@ -551,3 +552,55 @@  void debug_unmap_single(struct device *dev, dma_addr_t addr,
 }
 EXPORT_SYMBOL(debug_unmap_single);
 
+void debug_map_sg(struct device *dev, struct scatterlist *sg,
+		  int nents, int direction)
+{
+	struct dma_debug_entry *entry;
+	struct scatterlist *s;
+	int i;
+
+	if (global_disable)
+		return;
+
+	for_each_sg(sg, s, nents, i) {
+		entry = dma_entry_alloc();
+		if (!entry)
+			return;
+
+		entry->type      = dma_debug_sg;
+		entry->dev       = dev;
+		entry->cpu_addr  = sg_virt(s);
+		entry->size      = s->length;
+		entry->dev_addr  = s->dma_address;
+		entry->direction = direction;
+
+		add_dma_entry(entry);
+	}
+}
+EXPORT_SYMBOL(debug_map_sg);
+
+void debug_unmap_sg(struct device *dev, struct scatterlist *sglist,
+		    int nelems, int dir)
+{
+	struct scatterlist *s;
+	int i;
+
+	if (global_disable)
+		return;
+
+	for_each_sg(sglist, s, nelems, i) {
+
+		struct dma_debug_entry ref = {
+			.type           = dma_debug_sg,
+			.dev            = dev,
+			.cpu_addr       = sg_virt(s),
+			.dev_addr       = s->dma_address,
+			.size           = s->length,
+			.direction      = dir,
+		};
+
+		check_unmap(&ref);
+	}
+}
+EXPORT_SYMBOL(debug_unmap_sg);
+