Skip to content

Commit 2d49421

Browse files
Hou Taochantra
authored andcommitted
bpf: Use rcu_trace_implies_rcu_gp() in local storage map
Local storage map is accessible for both sleepable and non-sleepable bpf program, and its memory is freed by using both call_rcu_tasks_trace() and kfree_rcu() to wait for both RCU-tasks-trace grace period and RCU grace period to pass. With the introduction of rcu_trace_implies_rcu_gp(), both bpf_selem_free_rcu() and bpf_local_storage_free_rcu() 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 call kfree() directly. Signed-off-by: Hou Tao <[email protected]>
1 parent 6f10a26 commit 2d49421

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

kernel/bpf/bpf_local_storage.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,25 @@ void bpf_local_storage_free_rcu(struct rcu_head *rcu)
8888
{
8989
struct bpf_local_storage *local_storage;
9090

91+
/* If RCU Tasks Trace grace period implies RCU grace period, do
92+
* kfree(), else do kfree_rcu().
93+
*/
9194
local_storage = container_of(rcu, struct bpf_local_storage, rcu);
92-
kfree_rcu(local_storage, rcu);
95+
if (rcu_trace_implies_rcu_gp())
96+
kfree(local_storage);
97+
else
98+
kfree_rcu(local_storage, rcu);
9399
}
94100

95101
static void bpf_selem_free_rcu(struct rcu_head *rcu)
96102
{
97103
struct bpf_local_storage_elem *selem;
98104

99105
selem = container_of(rcu, struct bpf_local_storage_elem, rcu);
100-
kfree_rcu(selem, rcu);
106+
if (rcu_trace_implies_rcu_gp())
107+
kfree(selem);
108+
else
109+
kfree_rcu(selem, rcu);
101110
}
102111

103112
/* local_storage->lock must be held and selem->local_storage == local_storage.

0 commit comments

Comments
 (0)