]> git.baikalelectronics.ru Git - kernel.git/commit
bpf: Only allow sleepable program for resched-able iterator
authorHou Tao <houtao1@huawei.com>
Wed, 10 Aug 2022 08:05:35 +0000 (16:05 +0800)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 10 Aug 2022 17:12:48 +0000 (10:12 -0700)
commitb4f1d8e27da50b6f521ea8e54ed75bab83d85026
tree206244e8fd1c6487d541dea2c9405580de17c60e
parent33bdc33aa80f9657ac0af8e11d6171fcc96e92de
bpf: Only allow sleepable program for resched-able iterator

When a sleepable program is attached to a hash map iterator, might_fault()
will report "BUG: sleeping function called from invalid context..." if
CONFIG_DEBUG_ATOMIC_SLEEP is enabled. The reason is that rcu_read_lock()
is held in bpf_hash_map_seq_next() and won't be released until all elements
are traversed or bpf_hash_map_seq_stop() is called.

Fixing it by reusing BPF_ITER_RESCHED to indicate that only non-sleepable
program is allowed for iterator without BPF_ITER_RESCHED. We can revise
bpf_iter_link_attach() later if there are other conditions which may
cause rcu_read_lock() or spin_lock() issues.

Signed-off-by: Hou Tao <houtao1@huawei.com>
Acked-by: Yonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/r/20220810080538.1845898-7-houtao@huaweicloud.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/bpf/bpf_iter.c