Skip to content

Commit 7745abd

Browse files
Hou Taochantra
Hou Tao
authored andcommitted
bpf: Use rcu_trace_implies_rcu_gp() for program array freeing
To support both sleepable and normal uprobe bpf program, the freeing of trace program array chains a RCU-tasks-trace grace period and a normal RCU grace period one after the other. With the introduction of rcu_trace_implies_rcu_gp(), __bpf_prog_array_free_sleepable_cb() can check whether or not a normal RCU grace period has also passed after a RCU-tasks-trace grace period has passed. If it is true, it is safe to invoke kfree() directly. Signed-off-by: Hou Tao <[email protected]>
1 parent f4c6c4b commit 7745abd

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

kernel/bpf/core.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -2251,8 +2251,14 @@ static void __bpf_prog_array_free_sleepable_cb(struct rcu_head *rcu)
22512251
{
22522252
struct bpf_prog_array *progs;
22532253

2254+
/* If RCU Tasks Trace grace period implies RCU grace period, there is
2255+
* no need to call kfree_rcu(), just call kfree() directly.
2256+
*/
22542257
progs = container_of(rcu, struct bpf_prog_array, rcu);
2255-
kfree_rcu(progs, rcu);
2258+
if (rcu_trace_implies_rcu_gp())
2259+
kfree(progs);
2260+
else
2261+
kfree_rcu(progs, rcu);
22562262
}
22572263

22582264
void bpf_prog_array_free_sleepable(struct bpf_prog_array *progs)

0 commit comments

Comments
 (0)