alloc_skb cannot be called with GFP_DMA
[ok, I admit that this doesn't qualify as a timely reply]
Andrea wrote on Sun, 5 Aug 2001 17:53:34 +0200
Quoted 22 lines
I think it's good idea to apply this patch to mainline:
mm/slab.c Sun Aug 5 17:44:09 2001 renamed from mm/slab.c.~1~ Sun Aug 5 16:46:58 2001 +0
-2@@ -1172,7 +1172,6 @@ static inline void kmem_cache_alloc_head(kmem_cache_t *cachep, int flags) { -#if DEBUG if (flags & SLAB_DMA) { if (!(cachep->gfpflags & GFP_DMA)) BUG();@@ -1180,7 +1179,6 @@ if (cachep->gfpflags & GFP_DMA) BUG(); } -#endif } static inline void * kmem_cache_alloc_one_tail (kmem_cache_t *cachep,
Quoted 5 lines
This will trap anybody trying calling
alloc_skbusingGFP_DMA, that usage is illegal, it would work by luck only if _everybody_ callingalloc_skbwould be passingGFP_DMAtoo (because thegfp_maskis passed to the GFP in order to get right things likeGFP_WAIT) which is obviously not the case as the skb cache is shared by everybody.
If someone calls alloc_skb(GFP_DMA), then he wants the data buffer in DMA space, noone does DMA to/from the skb structure fields. The right approach is to mask the GFP_DMA bit before calling kmem_cache_alloc(skbuff_head_cache), and to forward the bit to the kmalloc of the skb data buffer. This is in 2.4.20-pre5, the right fix.
The check was indended to catch a feature that is present in the 2.2 slab allocator, but missing in 2.4: In 2.2, it was possible to create a custom cachep with kmem_cache_create(), and then allocate some objects with GFP_DMA set, some without GFP_DMA set. The allocator in 2.4/5 doesn't support that anymore.
But something else is wrong in kmem_cache_alloc_head - the common error, GFP_WAIT allocation from interrupt, is not checked - neither in DEBUG nor without DEBUG.
What about the attached patch?
- put the GFP_DMA test again under DEBUG: GFP_DMA errors are virtually impossible by design.
- add an in_interrupt() check into alloc_head()
I've put the in_interrupt() check under DEBUG, too: It's icache pollution, and the second test in kmem_cache_grow() will catch abusers sooner or later.
--
Manfred
mm/slab.c +8 -0
@@ -1259,6 +1259,13 @@static inline void kmem_cache_alloc_head (kmem_cache_t *cachep,int flags) { +#if DEBUG +/* check if someone calls us from interrupt with GFP_WAIT set +* With debug disabled, this only happens in kmem_cache_grow, +* to reduce the critical path length. +*/ +if (in_interrupt () && (flags & __GFP_WAIT)) +BUG ();if (flags &SLAB_DMA ) {if (!(cachep->gfpflags &GFP_DMA ))BUG ();
@@ -1266,6 +1273,7 @@if (cachep->gfpflags &GFP_DMA )BUG (); } +#endif } static inline void * kmem_cache_alloc_one_tail (kmem_cache_t *cachep,