Skip to content

Commit 9544bc5

Browse files
committed
sg: remove ->sg_magic member
This was introduced more than a decade ago when sg chaining was added, but we never really caught anything with it. The scatterlist entry size can be critical, since drivers allocate it, so remove the magic member. Recently it's been triggering allocation stalls and failures in NVMe. Tested-by: Jordan Glover <[email protected]> Acked-by: Christoph Hellwig <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 49f1c61 commit 9544bc5

File tree

4 files changed

+0
-45
lines changed

4 files changed

+0
-45
lines changed

drivers/gpu/drm/i915/i915_drv.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2238,9 +2238,6 @@ static inline struct scatterlist *____sg_next(struct scatterlist *sg)
22382238
**/
22392239
static inline struct scatterlist *__sg_next(struct scatterlist *sg)
22402240
{
2241-
#ifdef CONFIG_DEBUG_SG
2242-
BUG_ON(sg->sg_magic != SG_MAGIC);
2243-
#endif
22442241
return sg_is_last(sg) ? NULL : ____sg_next(sg);
22452242
}
22462243

include/linux/scatterlist.h

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
#include <asm/io.h>
1010

1111
struct scatterlist {
12-
#ifdef CONFIG_DEBUG_SG
13-
unsigned long sg_magic;
14-
#endif
1512
unsigned long page_link;
1613
unsigned int offset;
1714
unsigned int length;
@@ -64,7 +61,6 @@ struct sg_table {
6461
*
6562
*/
6663

67-
#define SG_MAGIC 0x87654321
6864
#define SG_CHAIN 0x01UL
6965
#define SG_END 0x02UL
7066

@@ -98,7 +94,6 @@ static inline void sg_assign_page(struct scatterlist *sg, struct page *page)
9894
*/
9995
BUG_ON((unsigned long) page & (SG_CHAIN | SG_END));
10096
#ifdef CONFIG_DEBUG_SG
101-
BUG_ON(sg->sg_magic != SG_MAGIC);
10297
BUG_ON(sg_is_chain(sg));
10398
#endif
10499
sg->page_link = page_link | (unsigned long) page;
@@ -129,7 +124,6 @@ static inline void sg_set_page(struct scatterlist *sg, struct page *page,
129124
static inline struct page *sg_page(struct scatterlist *sg)
130125
{
131126
#ifdef CONFIG_DEBUG_SG
132-
BUG_ON(sg->sg_magic != SG_MAGIC);
133127
BUG_ON(sg_is_chain(sg));
134128
#endif
135129
return (struct page *)((sg)->page_link & ~(SG_CHAIN | SG_END));
@@ -195,9 +189,6 @@ static inline void sg_chain(struct scatterlist *prv, unsigned int prv_nents,
195189
**/
196190
static inline void sg_mark_end(struct scatterlist *sg)
197191
{
198-
#ifdef CONFIG_DEBUG_SG
199-
BUG_ON(sg->sg_magic != SG_MAGIC);
200-
#endif
201192
/*
202193
* Set termination bit, clear potential chain bit
203194
*/
@@ -215,9 +206,6 @@ static inline void sg_mark_end(struct scatterlist *sg)
215206
**/
216207
static inline void sg_unmark_end(struct scatterlist *sg)
217208
{
218-
#ifdef CONFIG_DEBUG_SG
219-
BUG_ON(sg->sg_magic != SG_MAGIC);
220-
#endif
221209
sg->page_link &= ~SG_END;
222210
}
223211

@@ -260,12 +248,6 @@ static inline void *sg_virt(struct scatterlist *sg)
260248
static inline void sg_init_marker(struct scatterlist *sgl,
261249
unsigned int nents)
262250
{
263-
#ifdef CONFIG_DEBUG_SG
264-
unsigned int i;
265-
266-
for (i = 0; i < nents; i++)
267-
sgl[i].sg_magic = SG_MAGIC;
268-
#endif
269251
sg_mark_end(&sgl[nents - 1]);
270252
}
271253

lib/scatterlist.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@
2424
**/
2525
struct scatterlist *sg_next(struct scatterlist *sg)
2626
{
27-
#ifdef CONFIG_DEBUG_SG
28-
BUG_ON(sg->sg_magic != SG_MAGIC);
29-
#endif
3027
if (sg_is_last(sg))
3128
return NULL;
3229

@@ -111,10 +108,7 @@ struct scatterlist *sg_last(struct scatterlist *sgl, unsigned int nents)
111108
for_each_sg(sgl, sg, nents, i)
112109
ret = sg;
113110

114-
#ifdef CONFIG_DEBUG_SG
115-
BUG_ON(sgl[0].sg_magic != SG_MAGIC);
116111
BUG_ON(!sg_is_last(ret));
117-
#endif
118112
return ret;
119113
}
120114
EXPORT_SYMBOL(sg_last);

tools/virtio/linux/scatterlist.h

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ static inline void sg_assign_page(struct scatterlist *sg, struct page *page)
3636
*/
3737
BUG_ON((unsigned long) page & 0x03);
3838
#ifdef CONFIG_DEBUG_SG
39-
BUG_ON(sg->sg_magic != SG_MAGIC);
4039
BUG_ON(sg_is_chain(sg));
4140
#endif
4241
sg->page_link = page_link | (unsigned long) page;
@@ -67,7 +66,6 @@ static inline void sg_set_page(struct scatterlist *sg, struct page *page,
6766
static inline struct page *sg_page(struct scatterlist *sg)
6867
{
6968
#ifdef CONFIG_DEBUG_SG
70-
BUG_ON(sg->sg_magic != SG_MAGIC);
7169
BUG_ON(sg_is_chain(sg));
7270
#endif
7371
return (struct page *)((sg)->page_link & ~0x3);
@@ -116,9 +114,6 @@ static inline void sg_chain(struct scatterlist *prv, unsigned int prv_nents,
116114
**/
117115
static inline void sg_mark_end(struct scatterlist *sg)
118116
{
119-
#ifdef CONFIG_DEBUG_SG
120-
BUG_ON(sg->sg_magic != SG_MAGIC);
121-
#endif
122117
/*
123118
* Set termination bit, clear potential chain bit
124119
*/
@@ -136,17 +131,11 @@ static inline void sg_mark_end(struct scatterlist *sg)
136131
**/
137132
static inline void sg_unmark_end(struct scatterlist *sg)
138133
{
139-
#ifdef CONFIG_DEBUG_SG
140-
BUG_ON(sg->sg_magic != SG_MAGIC);
141-
#endif
142134
sg->page_link &= ~0x02;
143135
}
144136

145137
static inline struct scatterlist *sg_next(struct scatterlist *sg)
146138
{
147-
#ifdef CONFIG_DEBUG_SG
148-
BUG_ON(sg->sg_magic != SG_MAGIC);
149-
#endif
150139
if (sg_is_last(sg))
151140
return NULL;
152141

@@ -160,13 +149,6 @@ static inline struct scatterlist *sg_next(struct scatterlist *sg)
160149
static inline void sg_init_table(struct scatterlist *sgl, unsigned int nents)
161150
{
162151
memset(sgl, 0, sizeof(*sgl) * nents);
163-
#ifdef CONFIG_DEBUG_SG
164-
{
165-
unsigned int i;
166-
for (i = 0; i < nents; i++)
167-
sgl[i].sg_magic = SG_MAGIC;
168-
}
169-
#endif
170152
sg_mark_end(&sgl[nents - 1]);
171153
}
172154

0 commit comments

Comments
 (0)