Re: WARNING in kvmalloc_node

From: Jason Wang
Date: Wed Feb 14 2018 - 07:48:16 EST




On 2018å02æ14æ 20:29, Jesper Dangaard Brouer wrote:
On Wed, 14 Feb 2018 13:17:18 +0100
Daniel Borkmann <daniel@xxxxxxxxxxxxx> wrote:

On 02/14/2018 01:02 PM, Jason Wang wrote:
On 2018å02æ14æ 19:51, Michal Hocko wrote:
On Wed 14-02-18 19:47:30, Jason Wang wrote:
On 2018å02æ14æ 17:28, Daniel Borkmann wrote:
[ +Jason, +Jesper ]

On 02/14/2018 09:43 AM, Michal Hocko wrote:
On Tue 13-02-18 18:55:33, Matthew Wilcox wrote:
On Tue, Feb 13, 2018 at 03:59:01PM -0800, syzbot wrote:
[...]
ÂÂ kvmalloc include/linux/mm.h:541 [inline]
ÂÂ kvmalloc_array include/linux/mm.h:557 [inline]
ÂÂ __ptr_ring_init_queue_alloc include/linux/ptr_ring.h:474 [inline]
ÂÂ ptr_ring_init include/linux/ptr_ring.h:492 [inline]
ÂÂ __cpu_map_entry_alloc kernel/bpf/cpumap.c:359 [inline]
ÂÂ cpu_map_update_elem+0x3c3/0x8e0 kernel/bpf/cpumap.c:490
ÂÂ map_update_elem kernel/bpf/syscall.c:698 [inline]
Blame the BPF people, not the MM people ;-)
Heh, not really. ;-)
Yes. kvmalloc (the vmalloc part) doesn't support GFP_ATOMIC semantic.
Agree, that doesn't work.

Bug was added in commit 0bf7800f1799 ("ptr_ring: try vmalloc() when kmalloc() fails").

Jason, please take a look at fixing this, thanks!
It looks to me the only solution is to revert that commit.
Do you really need this to be GFP_ATOMIC? I can see some callers are
under RCU read lock but can we perhaps do the allocation outside of this
section?
If I understand the code correctly, the code would be called by XDP program (usually run inside a bh) which makes it hard to do this.

Rethink of this, we can probably test gfp and not call kvmalloc if GFP_ATOMIC is set in __ptr_ring_init_queue_alloc().
That would be one option indeed (probably useful in any case to make the API
more robust). Another one is to just not use GFP_ATOMIC in cpumap. Looking at
it, update can neither be called out of a BPF prog since prevented by verifier
nor under RCU reader side when updating this type of map from syscall path.
Jesper, any concrete reason we still need GFP_ATOMIC here?
Allocations in cpumap (related to ptr_ring) should only be possible to
be initiated through userspace via bpf-syscall.

I see verifier guarantees this.

Thus, there isn't any
reason for GFP_ATOMIC here.


Want me to send a patch to remove GFP_ATOMIC here?

Thanks