Commit d6ec084200c37683278c821338f74ddf21ab80f5
1 parent
18dabf473e
Exists in
master
and in
39 other branches
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
- include/asm-arm/scatterlist.h
- include/asm-avr32/scatterlist.h
- include/asm-blackfin/scatterlist.h
- include/asm-cris/scatterlist.h
- include/asm-frv/scatterlist.h
- include/asm-h8300/scatterlist.h
- include/asm-ia64/scatterlist.h
- include/asm-m32r/scatterlist.h
- include/asm-m68k/scatterlist.h
- include/asm-m68knommu/scatterlist.h
- include/asm-mips/scatterlist.h
- include/asm-parisc/scatterlist.h
- include/asm-powerpc/scatterlist.h
- include/asm-s390/scatterlist.h
- include/asm-sh/scatterlist.h
- include/asm-sh64/scatterlist.h
- include/asm-sparc/scatterlist.h
- include/asm-sparc64/scatterlist.h
- include/asm-v850/scatterlist.h
- include/asm-x86/scatterlist_32.h
- include/asm-x86/scatterlist_64.h
- include/asm-xtensa/scatterlist.h
- include/linux/scatterlist.h
- lib/Kconfig.debug
include/asm-alpha/scatterlist.h
include/asm-arm/scatterlist.h
include/asm-avr32/scatterlist.h
include/asm-blackfin/scatterlist.h
include/asm-cris/scatterlist.h
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
include/asm-ia64/scatterlist.h
include/asm-m32r/scatterlist.h
include/asm-m68k/scatterlist.h
include/asm-m68knommu/scatterlist.h
include/asm-mips/scatterlist.h
include/asm-parisc/scatterlist.h
include/asm-powerpc/scatterlist.h
include/asm-s390/scatterlist.h
include/asm-sh/scatterlist.h
include/asm-sh64/scatterlist.h
include/asm-sparc/scatterlist.h
include/asm-sparc64/scatterlist.h
include/asm-v850/scatterlist.h
include/asm-x86/scatterlist_32.h
include/asm-x86/scatterlist_64.h
include/asm-xtensa/scatterlist.h
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 | /** |
lib/Kconfig.debug
... | ... | @@ -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) |