Skip to contentSkip to conversation

dma_zalloc_coherent broken with 57bf5a8963f80fb3828c46c3e3a5b2dd790e09a7

DISCUSSION Sebastian Ott 3 participants 9 messages Mar 27, 2018 – Mar 28, 2018

lore
Share & tools
lore
#0 lore raw

Hi,

commit 57bf5a8963f80fb3828c46c3e3a5b2dd790e09a7 broke usage of dma allocations specifying __GFP_ZERO by silently removing that flag.

Why should "the memory returned [] always be zeroed."?

Regards,
Sebastian

#1 lore raw

Hi Sebastian,

Quoted 2 lines · Sebastian Ott

commit 57bf5a8963f80fb3828c46c3e3a5b2dd790e09a7 broke usage of dma allocations specifying __GFP_ZERO by silently removing that flag.

How did it break? The flag is now always added.

Quoted 1 line

Why should "the memory returned [] always be zeroed."?

To avoid leaking information.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#2 lore raw

Hello Geert,

Quoted 6 lines · Geert Uytterhoeven
Quoted 2 lines · Sebastian Ott

commit 57bf5a8963f80fb3828c46c3e3a5b2dd790e09a7 broke usage of dma allocations specifying __GFP_ZERO by silently removing that flag.

How did it break? The flag is now always added.

+ flag &= ~(__GFP_DMA | __GFP_DMA32 | __GFP_HIGHMEM | __GFP_ZERO);

I read that as a removal. But maybe I need more coffee..

Sebastian

#3 lore raw

Hi Sebastian,

Quoted 11 lines · Sebastian Ott
Quoted 6 lines · Geert Uytterhoeven
Quoted 2 lines · Sebastian Ott

commit 57bf5a8963f80fb3828c46c3e3a5b2dd790e09a7 broke usage of dma allocations specifying __GFP_ZERO by silently removing that flag.

How did it break? The flag is now always added.

+ flag &= ~(__GFP_DMA | __GFP_DMA32 | __GFP_HIGHMEM | __GFP_ZERO);

I read that as a removal. But maybe I need more coffee..

Sorry, you're right.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#4 lore raw
In reply to Sebastian Ott
Quoted 6 lines · Sebastian Ott

Hi,

commit 57bf5a8963f80fb3828c46c3e3a5b2dd790e09a7 broke usage of dma allocations specifying __GFP_ZERO by silently removing that flag.

Why should "the memory returned [] always be zeroed."?

Because that is what the current implementations do - we always zero the memory returned from dma_map_ops.alloc().

#5 lore raw
Quoted 10 lines · Christoph Hellwig
Quoted 6 lines · Sebastian Ott

Hi,

commit 57bf5a8963f80fb3828c46c3e3a5b2dd790e09a7 broke usage of dma allocations specifying __GFP_ZERO by silently removing that flag.

Why should "the memory returned [] always be zeroed."?

Because that is what the current implementations do - we always zero the memory returned from dma_map_ops.alloc().

What do you mean by current implementations? Arch specific code? At least on s390 we don't do that. dma-mapping.h doesn't do it either.

Sebastian

#6 lore raw
Quoted 2 lines · Sebastian Ott

What do you mean by current implementations? Arch specific code? At least on s390 we don't do that. dma-mapping.h doesn't do it either.

The arch implementations should do it. Seems like s390 and potentially a few others don't. I'm a little slow due to a cast on one arm, but I'll do an audit and will fix up anything I'll find.

#7 lore raw
Quoted 7 lines · Christoph Hellwig
Quoted 2 lines · Sebastian Ott

What do you mean by current implementations? Arch specific code? At least on s390 we don't do that. dma-mapping.h doesn't do it either.

The arch implementations should do it. Seems like s390 and potentially a few others don't. I'm a little slow due to a cast on one arm, but I'll do an audit and will fix up anything I'll find.

What was wrong with the old behavior (let the caller decide - the same as with memory allocations)? We have interfaces like dma_zalloc_coherent, which explicitely set __GFP_ZERO. We have callers of dma_alloc followed by a manually memset..

Sebastian

#8 lore raw
Quoted 2 lines · Sebastian Ott

What was wrong with the old behavior (let the caller decide - the same as with memory allocations)?

The old behavior on most (all?) mainstream architectures is that we always zero the return value. On x86/i386 this goes back to at least Linux 2.4. So common drivers simply expect this to happen.