Commit d6ec084200c37683278c821338f74ddf21ab80f5

Authored by Jens Axboe
1 parent 18dabf473e

Add CONFIG_DEBUG_SG sg validation

Add a Kconfig entry which will toggle some sanity checks on the sg
entry and tables.

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>

Showing 25 changed files with 101 additions and 0 deletions Side-by-side Diff

include/asm-alpha/scatterlist.h
... ... @@ -5,6 +5,9 @@
5 5 #include <asm/types.h>
6 6  
7 7 struct scatterlist {
  8 +#ifdef CONFIG_DEBUG_SG
  9 + unsigned long sg_magic;
  10 +#endif
8 11 unsigned long page_link;
9 12 unsigned int offset;
10 13  
include/asm-arm/scatterlist.h
... ... @@ -5,6 +5,9 @@
5 5 #include <asm/types.h>
6 6  
7 7 struct scatterlist {
  8 +#ifdef CONFIG_DEBUG_SG
  9 + unsigned long sg_magic;
  10 +#endif
8 11 unsigned long page_link;
9 12 unsigned int offset; /* buffer offset */
10 13 dma_addr_t dma_address; /* dma address */
include/asm-avr32/scatterlist.h
... ... @@ -4,6 +4,9 @@
4 4 #include <asm/types.h>
5 5  
6 6 struct scatterlist {
  7 +#ifdef CONFIG_DEBUG_SG
  8 + unsigned long sg_magic;
  9 +#endif
7 10 unsigned long page_link;
8 11 unsigned int offset;
9 12 dma_addr_t dma_address;
include/asm-blackfin/scatterlist.h
... ... @@ -4,6 +4,9 @@
4 4 #include <linux/mm.h>
5 5  
6 6 struct scatterlist {
  7 +#ifdef CONFIG_DEBUG_SG
  8 + unsigned long sg_magic;
  9 +#endif
7 10 unsigned long page_link;
8 11 unsigned int offset;
9 12 dma_addr_t dma_address;
include/asm-cris/scatterlist.h
... ... @@ -2,6 +2,9 @@
2 2 #define __ASM_CRIS_SCATTERLIST_H
3 3  
4 4 struct scatterlist {
  5 +#ifdef CONFIG_DEBUG_SG
  6 + unsigned long sg_magic;
  7 +#endif
5 8 char * address; /* Location data is to be transferred to */
6 9 unsigned int length;
7 10  
include/asm-frv/scatterlist.h
... ... @@ -22,6 +22,9 @@
22 22 * and that's it. There's no excuse for not highmem enabling YOUR driver. /jens
23 23 */
24 24 struct scatterlist {
  25 +#ifdef CONFIG_DEBUG_SG
  26 + unsigned long sg_magic;
  27 +#endif
25 28 unsigned long page_link;
26 29 unsigned int offset; /* for highmem, page offset */
27 30  
include/asm-h8300/scatterlist.h
... ... @@ -4,6 +4,9 @@
4 4 #include <asm/types.h>
5 5  
6 6 struct scatterlist {
  7 +#ifdef CONFIG_DEBUG_SG
  8 + unsigned long sg_magic;
  9 +#endif
7 10 unsigned long page_link;
8 11 unsigned int offset;
9 12 dma_addr_t dma_address;
include/asm-ia64/scatterlist.h
... ... @@ -9,6 +9,9 @@
9 9 #include <asm/types.h>
10 10  
11 11 struct scatterlist {
  12 +#ifdef CONFIG_DEBUG_SG
  13 + unsigned long sg_magic;
  14 +#endif
12 15 unsigned long page_link;
13 16 unsigned int offset;
14 17 unsigned int length; /* buffer length */
include/asm-m32r/scatterlist.h
... ... @@ -4,6 +4,9 @@
4 4 #include <asm/types.h>
5 5  
6 6 struct scatterlist {
  7 +#ifdef CONFIG_DEBUG_SG
  8 + unsigned long sg_magic;
  9 +#endif
7 10 char * address; /* Location data is to be transferred to, NULL for
8 11 * highmem page */
9 12 unsigned long page_link;
include/asm-m68k/scatterlist.h
... ... @@ -4,6 +4,9 @@
4 4 #include <linux/types.h>
5 5  
6 6 struct scatterlist {
  7 +#ifdef CONFIG_DEBUG_SG
  8 + unsigned long sg_magic;
  9 +#endif
7 10 unsigned long page_link;
8 11 unsigned int offset;
9 12 unsigned int length;
include/asm-m68knommu/scatterlist.h
... ... @@ -5,6 +5,9 @@
5 5 #include <asm/types.h>
6 6  
7 7 struct scatterlist {
  8 +#ifdef CONFIG_DEBUG_SG
  9 + unsigned long sg_magic;
  10 +#endif
8 11 unsigned long page_link;
9 12 unsigned int offset;
10 13 dma_addr_t dma_address;
include/asm-mips/scatterlist.h
... ... @@ -4,6 +4,9 @@
4 4 #include <asm/types.h>
5 5  
6 6 struct scatterlist {
  7 +#ifdef CONFIG_DEBUG_SG
  8 + unsigned long sg_magic;
  9 +#endif
7 10 unsigned long page_link;
8 11 unsigned int offset;
9 12 dma_addr_t dma_address;
include/asm-parisc/scatterlist.h
... ... @@ -5,6 +5,9 @@
5 5 #include <asm/types.h>
6 6  
7 7 struct scatterlist {
  8 +#ifdef CONFIG_DEBUG_SG
  9 + unsigned long sg_magic;
  10 +#endif
8 11 unsigned long page_link;
9 12 unsigned int offset;
10 13  
include/asm-powerpc/scatterlist.h
... ... @@ -14,6 +14,9 @@
14 14 #include <asm/dma.h>
15 15  
16 16 struct scatterlist {
  17 +#ifdef CONFIG_DEBUG_SG
  18 + unsigned long sg_magic;
  19 +#endif
17 20 unsigned long page_link;
18 21 unsigned int offset;
19 22 unsigned int length;
include/asm-s390/scatterlist.h
... ... @@ -2,6 +2,9 @@
2 2 #define _ASMS390_SCATTERLIST_H
3 3  
4 4 struct scatterlist {
  5 +#ifdef CONFIG_DEBUG_SG
  6 + unsigned long sg_magic;
  7 +#endif
5 8 unsigned long page_link;
6 9 unsigned int offset;
7 10 unsigned int length;
include/asm-sh/scatterlist.h
... ... @@ -4,6 +4,9 @@
4 4 #include <asm/types.h>
5 5  
6 6 struct scatterlist {
  7 +#ifdef CONFIG_DEBUG_SG
  8 + unsigned long sg_magic;
  9 +#endif
7 10 unsigned long page_link;
8 11 unsigned int offset;/* for highmem, page offset */
9 12 dma_addr_t dma_address;
include/asm-sh64/scatterlist.h
... ... @@ -14,6 +14,9 @@
14 14 #include <asm/types.h>
15 15  
16 16 struct scatterlist {
  17 +#ifdef CONFIG_DEBUG_SG
  18 + unsigned long sg_magic;
  19 +#endif
17 20 unsigned long page_link;
18 21 unsigned int offset;/* for highmem, page offset */
19 22 dma_addr_t dma_address;
include/asm-sparc/scatterlist.h
... ... @@ -5,6 +5,9 @@
5 5 #include <linux/types.h>
6 6  
7 7 struct scatterlist {
  8 +#ifdef CONFIG_DEBUG_SG
  9 + unsigned long sg_magic;
  10 +#endif
8 11 unsigned long page_link;
9 12 unsigned int offset;
10 13  
include/asm-sparc64/scatterlist.h
... ... @@ -6,6 +6,9 @@
6 6 #include <asm/types.h>
7 7  
8 8 struct scatterlist {
  9 +#ifdef CONFIG_DEBUG_SG
  10 + unsigned long sg_magic;
  11 +#endif
9 12 unsigned long page_link;
10 13 unsigned int offset;
11 14  
include/asm-v850/scatterlist.h
... ... @@ -17,6 +17,9 @@
17 17 #include <asm/types.h>
18 18  
19 19 struct scatterlist {
  20 +#ifdef CONFIG_DEBUG_SG
  21 + unsigned long sg_magic;
  22 +#endif
20 23 unsigned long page_link;
21 24 unsigned offset;
22 25 dma_addr_t dma_address;
include/asm-x86/scatterlist_32.h
... ... @@ -4,6 +4,9 @@
4 4 #include <asm/types.h>
5 5  
6 6 struct scatterlist {
  7 +#ifdef CONFIG_DEBUG_SG
  8 + unsigned long sg_magic;
  9 +#endif
7 10 unsigned long page_link;
8 11 unsigned int offset;
9 12 dma_addr_t dma_address;
include/asm-x86/scatterlist_64.h
... ... @@ -4,6 +4,9 @@
4 4 #include <asm/types.h>
5 5  
6 6 struct scatterlist {
  7 +#ifdef CONFIG_DEBUG_SG
  8 + unsigned long sg_magic;
  9 +#endif
7 10 unsigned long page_link;
8 11 unsigned int offset;
9 12 unsigned int length;
include/asm-xtensa/scatterlist.h
... ... @@ -14,6 +14,9 @@
14 14 #include <asm/types.h>
15 15  
16 16 struct scatterlist {
  17 +#ifdef CONFIG_DEBUG_SG
  18 + unsigned long sg_magic;
  19 +#endif
17 20 unsigned long page_link;
18 21 unsigned int offset;
19 22 dma_addr_t dma_address;
include/linux/scatterlist.h
... ... @@ -23,6 +23,8 @@
23 23 *
24 24 */
25 25  
  26 +#define SG_MAGIC 0x87654321
  27 +
26 28 /**
27 29 * sg_set_page - Set sg entry to point at given page
28 30 * @sg: SG entry
... ... @@ -39,6 +41,9 @@
39 41 {
40 42 unsigned long page_link = sg->page_link & 0x3;
41 43  
  44 +#ifdef CONFIG_DEBUG_SG
  45 + BUG_ON(sg->sg_magic != SG_MAGIC);
  46 +#endif
42 47 sg->page_link = page_link | (unsigned long) page;
43 48 }
44 49  
... ... @@ -81,6 +86,9 @@
81 86 **/
82 87 static inline struct scatterlist *sg_next(struct scatterlist *sg)
83 88 {
  89 +#ifdef CONFIG_DEBUG_SG
  90 + BUG_ON(sg->sg_magic != SG_MAGIC);
  91 +#endif
84 92 if (sg_is_last(sg))
85 93 return NULL;
86 94  
... ... @@ -124,6 +132,10 @@
124 132 ret = sg;
125 133  
126 134 #endif
  135 +#ifdef CONFIG_DEBUG_SG
  136 + BUG_ON(sgl[0].sg_magic != SG_MAGIC);
  137 + BUG_ON(!sg_is_last(ret));
  138 +#endif
127 139 return ret;
128 140 }
129 141  
... ... @@ -180,6 +192,9 @@
180 192 unsigned int buflen)
181 193 {
182 194 memset(sg, 0, sizeof(*sg));
  195 +#ifdef CONFIG_DEBUG_SG
  196 + sg->sg_magic = SG_MAGIC;
  197 +#endif
183 198 sg_mark_end(sg, 1);
184 199 sg_set_buf(sg, buf, buflen);
185 200 }
... ... @@ -198,6 +213,13 @@
198 213 {
199 214 memset(sgl, 0, sizeof(*sgl) * nents);
200 215 sg_mark_end(sgl, nents);
  216 +#ifdef CONFIG_DEBUG_SG
  217 + {
  218 + int i;
  219 + for (i = 0; i < nents; i++)
  220 + sgl[i].sg_magic = SG_MAGIC;
  221 + }
  222 +#endif
201 223 }
202 224  
203 225 /**
... ... @@ -389,6 +389,16 @@
389 389  
390 390 If unsure, say N.
391 391  
  392 +config DEBUG_SG
  393 + bool "Debug SG table operations"
  394 + depends on DEBUG_KERNEL
  395 + help
  396 + Enable this to turn on checks on scatter-gather tables. This can
  397 + help find problems with drivers that do not properly initialize
  398 + their sg tables.
  399 +
  400 + If unsure, say N.
  401 +
392 402 config FRAME_POINTER
393 403 bool "Compile the kernel with frame pointers"
394 404 depends on DEBUG_KERNEL && (X86 || CRIS || M68K || M68KNOMMU || FRV || UML || S390 || AVR32 || SUPERH || BFIN)