bpf: fix a rcu usage warning in bpf_prog_array_copy_core()
Subsystems (4)
PATCH 1/1 bpf: fix a rcu usage warning in bpf_prog_array_copy_core()
Commit 394e40a29788 ("bpf: extend bpf_prog_array to store pointers to the cgroup storage") refactored the bpf_prog_array_copy_core() to accommodate new structure bpf_prog_array_item which contains bpf_prog array itself.
In the old code, we had
perf_event_query_prog_array():
mutex_lock(...)
bpf_prog_array_copy_call():
prog = rcu_dereference_check(array, 1)->progs
bpf_prog_array_copy_core(prog, ...)
mutex_unlock(...)With the above commit, we had
perf_event_query_prog_array():
mutex_lock(...)
bpf_prog_array_copy_call():
bpf_prog_array_copy_core(array, ...):
item = rcu_dereference(array)->items;
...
mutex_unlock(...)The new code will trigger a lockdep rcu checking warning. The fix is to change rcu_dereference() to rcu_dereference_check() to prevent such a warning.
--- kernel/bpf/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/bpf/core.c +1 -1
@@ -1579,7 +1579,7 @@ static bool bpf_prog_array_copy_core(struct bpf_prog_array __rcu *array,struct bpf_prog_array_item *item;int i =0 ; - item =rcu_dereference (array)->items; + item =rcu_dereference_check (array,1 )->items;for (; item->prog; item++) {if (item->prog == &dummy_bpf_prog.prog)continue ;
Signature · 1 line
2.17.1
Quoted 22 lines · Yonghong Song
Commit
394e40a29788("bpf: extendbpf_prog_arrayto store pointers to the cgroup storage") refactored thebpf_prog_array_copy_core()to accommodate new structurebpf_prog_array_itemwhich containsbpf_progarray itself.In the old code, we had
perf_event_query_prog_array():mutex_lock(...) bpf_prog_array_copy_call(): prog = rcu_dereference_check(array, 1)->progs bpf_prog_array_copy_core(prog, ...) mutex_unlock(...)With the above commit, we had
perf_event_query_prog_array():mutex_lock(...) bpf_prog_array_copy_call(): bpf_prog_array_copy_core(array, ...): item = rcu_dereference(array)->items; ... mutex_unlock(...)
Quoted 8 lines
The new code will trigger a lockdep rcu checking warning. The fix is to change
rcu_dereference()torcu_dereference_check()to prevent such a warning.Reported-by [email protected]Fixes 394e40a29788 ("bpf: extend bpf_prog_array to store pointers to the cgroup storage")Cc Roman Gushchin <[email protected]>Signed-off-by Yonghong Song <[email protected]>
makes sense to me
Roman, would you agree?
Quoted 32 lines · Alexei Starovoitov
Quoted 22 lines · Yonghong Song
Commit
394e40a29788("bpf: extendbpf_prog_arrayto store pointers to the cgroup storage") refactored thebpf_prog_array_copy_core()to accommodate new structurebpf_prog_array_itemwhich containsbpf_progarray itself.In the old code, we had
perf_event_query_prog_array():mutex_lock(...) bpf_prog_array_copy_call(): prog = rcu_dereference_check(array, 1)->progs bpf_prog_array_copy_core(prog, ...) mutex_unlock(...)With the above commit, we had
perf_event_query_prog_array():mutex_lock(...) bpf_prog_array_copy_call(): bpf_prog_array_copy_core(array, ...): item = rcu_dereference(array)->items; ... mutex_unlock(...)Quoted 8 lines
The new code will trigger a lockdep rcu checking warning. The fix is to change
rcu_dereference()torcu_dereference_check()to prevent such a warning.Reported-by [email protected]Fixes 394e40a29788 ("bpf: extend bpf_prog_array to store pointers to the cgroup storage")Cc Roman Gushchin <[email protected]>Signed-off-by Yonghong Song <[email protected]>
Quoted 5 lines
makes sense to me
Roman, would you agree?
rcu_dereference_check(<>, 1) always looks a bit strange to me, but if it's the only reasonable way to silence the warning, of course I'm fine with it.
Thanks!
Quoted 36 lines · Roman Gushchin
Quoted 35 lines · Alexei Starovoitov
Quoted 22 lines · Yonghong Song
Commit
394e40a29788("bpf: extendbpf_prog_arrayto store pointers to the cgroup storage") refactored thebpf_prog_array_copy_core()to accommodate new structurebpf_prog_array_itemwhich containsbpf_progarray itself.In the old code, we had
perf_event_query_prog_array():mutex_lock(...) bpf_prog_array_copy_call(): prog = rcu_dereference_check(array, 1)->progs bpf_prog_array_copy_core(prog, ...) mutex_unlock(...)With the above commit, we had
perf_event_query_prog_array():mutex_lock(...) bpf_prog_array_copy_call(): bpf_prog_array_copy_core(array, ...): item = rcu_dereference(array)->items; ... mutex_unlock(...)Quoted 8 lines
The new code will trigger a lockdep rcu checking warning. The fix is to change
rcu_dereference()torcu_dereference_check()to prevent such a warning.Reported-by [email protected]Fixes 394e40a29788 ("bpf: extend bpf_prog_array to store pointers to the cgroup storage")Cc Roman Gushchin <[email protected]>Signed-off-by Yonghong Song <[email protected]>makes sense to me
Quoted 6 lines
Quoted 2 lines
Roman, would you agree?
rcu_dereference_check(<>, 1)always looks a bit strange to me, but if it's the only reasonable way to silence the warning, of course I'm fine with it.
do you have better suggestion?
This patch is a fix for the regression introduced in your earlier patch, so I think the only fair path forward is either to Ack it or to send an alternative patch asap.
Roman Gushchin
Acked-byQuoted 40 lines · Alexei Starovoitov
Quoted 39 lines · Roman Gushchin
Quoted 37 lines · Alexei Starovoitov
Quoted 22 lines · Yonghong Song
Commit
394e40a29788("bpf: extendbpf_prog_arrayto store pointers to the cgroup storage") refactored thebpf_prog_array_copy_core()to accommodate new structurebpf_prog_array_itemwhich containsbpf_progarray itself.In the old code, we had
perf_event_query_prog_array():mutex_lock(...) bpf_prog_array_copy_call(): prog = rcu_dereference_check(array, 1)->progs bpf_prog_array_copy_core(prog, ...) mutex_unlock(...)With the above commit, we had
perf_event_query_prog_array():mutex_lock(...) bpf_prog_array_copy_call(): bpf_prog_array_copy_core(array, ...): item = rcu_dereference(array)->items; ... mutex_unlock(...)Quoted 8 lines
The new code will trigger a lockdep rcu checking warning. The fix is to change
rcu_dereference()torcu_dereference_check()to prevent such a warning.Reported-by [email protected]Fixes 394e40a29788 ("bpf: extend bpf_prog_array to store pointers to the cgroup storage")Cc Roman Gushchin <[email protected]>Signed-off-by Yonghong Song <[email protected]>makes sense to me
Roman, would you agree?
Quoted 9 lines
Quoted 3 lines
rcu_dereference_check(<>, 1)always looks a bit strange to me, but if it's the only reasonable way to silence the warning, of course I'm fine with it.do you have better suggestion?
This patch is a fix for the regression introduced in your earlier patch, so I think the only fair path forward is either to Ack it or to send an alternative patch asap.
As I said, I've nothing against.
Thanks!
Quoted 24 lines · Roman Gushchin
Quoted 23 lines · Alexei Starovoitov
Quoted 22 lines · Yonghong Song
Commit
394e40a29788("bpf: extendbpf_prog_arrayto store pointers to the cgroup storage") refactored thebpf_prog_array_copy_core()to accommodate new structurebpf_prog_array_itemwhich containsbpf_progarray itself.In the old code, we had
perf_event_query_prog_array():mutex_lock(...) bpf_prog_array_copy_call(): prog = rcu_dereference_check(array, 1)->progs bpf_prog_array_copy_core(prog, ...) mutex_unlock(...)With the above commit, we had
perf_event_query_prog_array():mutex_lock(...) bpf_prog_array_copy_call(): bpf_prog_array_copy_core(array, ...): item = rcu_dereference(array)->items; ... mutex_unlock(...)
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
The new code will trigger a lockdep rcu checking warning. The fix is to change
rcu_dereference()torcu_dereference_check()to prevent such a warning.Reported-by [email protected]Fixes 394e40a29788 ("bpf: extend bpf_prog_array to store pointers to the cgroup storage")Cc Roman Gushchin <[email protected]>Signed-off-by Yonghong Song <[email protected]>
Applied to bpf, thanks Yonghong!