Skip to contentSkip to conversation

bpf: fix a rcu usage warning in bpf_prog_array_copy_core()

PATCH Applied Yonghong Song 4 participants 6 messages Aug 14, 2018 – Aug 16, 2018

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

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.

Reported-by [email protected]
Fixes 394e40a29788 ("bpf: extend bpf_prog_array to store pointers to the cgroup storage")
Cc Roman Gushchin <[email protected]>
---
 kernel/bpf/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/bpf/core.c +1 -1
index 4d09e610777f..3f5bf1af0826 100644
@@ -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
Acked-by on v1 1/1
#1 lore raw
Quoted 22 lines · Yonghong Song

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(...)
Quoted 8 lines

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.

Reported-by [email protected]
Fixes 394e40a29788 ("bpf: extend bpf_prog_array to store pointers to the cgroup storage")
Cc Roman Gushchin <[email protected]>

makes sense to me

Roman, would you agree?

#2 lore raw
Quoted 32 lines · Alexei Starovoitov
Quoted 22 lines · Yonghong Song

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(...)
Quoted 8 lines

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.

Reported-by [email protected]
Fixes 394e40a29788 ("bpf: extend bpf_prog_array to store pointers to the cgroup storage")
Cc Roman Gushchin <[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!

#3 lore raw
Quoted 36 lines · Roman Gushchin
Quoted 35 lines · Alexei Starovoitov
Quoted 22 lines · Yonghong Song

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(...)
Quoted 8 lines

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.

Reported-by [email protected]
Fixes 394e40a29788 ("bpf: extend bpf_prog_array to store pointers to the cgroup storage")
Cc Roman Gushchin <[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.

#4 lore raw
Quoted 40 lines · Alexei Starovoitov
Quoted 39 lines · Roman Gushchin
Quoted 37 lines · Alexei Starovoitov
Quoted 22 lines · Yonghong Song

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(...)
Quoted 8 lines

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.

Reported-by [email protected]
Fixes 394e40a29788 ("bpf: extend bpf_prog_array to store pointers to the cgroup storage")
Cc Roman Gushchin <[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!

maintainer Applied
#5 lore raw
In reply to Roman Gushchin
Quoted 24 lines · Roman Gushchin
Quoted 23 lines · Alexei Starovoitov
Quoted 22 lines · Yonghong Song

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(...)
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() to rcu_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]>

Applied to bpf, thanks Yonghong!