提交 b620e67e 编写于 作者: E Eric Dumazet 提交者: Zheng Zengkai

bpf: Add schedule points in batch ops

stable inclusion
from stable-v5.10.103
commit 7ef94bfb08fb9e73defafbd5ddef6b5a0e2ee12b
bugzilla: https://gitee.com/openeuler/kernel/issues/I56NE7

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=7ef94bfb08fb9e73defafbd5ddef6b5a0e2ee12b

--------------------------------

commit 75134f16 upstream.

syzbot reported various soft lockups caused by bpf batch operations.

 INFO: task kworker/1:1:27 blocked for more than 140 seconds.
 INFO: task hung in rcu_barrier

Nothing prevents batch ops to process huge amount of data,
we need to add schedule points in them.

Note that maybe_wait_bpf_programs(map) calls from
generic_map_delete_batch() can be factorized by moving
the call after the loop.

This will be done later in -next tree once we get this fix merged,
unless there is strong opinion doing this optimization sooner.

Fixes: aa2e93b8 ("bpf: Add generic support for update and delete batch ops")
Fixes: cb4d03ab ("bpf: Add generic support for lookup batch op")
Reported-by: Nsyzbot <syzkaller@googlegroups.com>
Signed-off-by: NEric Dumazet <edumazet@google.com>
Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
Reviewed-by: NStanislav Fomichev <sdf@google.com>
Acked-by: NBrian Vazquez <brianvv@google.com>
Link: https://lore.kernel.org/bpf/20220217181902.808742-1-eric.dumazet@gmail.comSigned-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: NYu Liao <liaoyu15@huawei.com>
Reviewed-by: NWei Li <liwei391@huawei.com>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
上级 472f8501
...@@ -1308,6 +1308,7 @@ int generic_map_delete_batch(struct bpf_map *map, ...@@ -1308,6 +1308,7 @@ int generic_map_delete_batch(struct bpf_map *map,
maybe_wait_bpf_programs(map); maybe_wait_bpf_programs(map);
if (err) if (err)
break; break;
cond_resched();
} }
if (copy_to_user(&uattr->batch.count, &cp, sizeof(cp))) if (copy_to_user(&uattr->batch.count, &cp, sizeof(cp)))
err = -EFAULT; err = -EFAULT;
...@@ -1365,6 +1366,7 @@ int generic_map_update_batch(struct bpf_map *map, ...@@ -1365,6 +1366,7 @@ int generic_map_update_batch(struct bpf_map *map,
if (err) if (err)
break; break;
cond_resched();
} }
if (copy_to_user(&uattr->batch.count, &cp, sizeof(cp))) if (copy_to_user(&uattr->batch.count, &cp, sizeof(cp)))
...@@ -1462,6 +1464,7 @@ int generic_map_lookup_batch(struct bpf_map *map, ...@@ -1462,6 +1464,7 @@ int generic_map_lookup_batch(struct bpf_map *map,
swap(prev_key, key); swap(prev_key, key);
retry = MAP_LOOKUP_RETRIES; retry = MAP_LOOKUP_RETRIES;
cp++; cp++;
cond_resched();
} }
if (err == -EFAULT) if (err == -EFAULT)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册