提交 d39d1445 编写于 作者: H Hou Tao 提交者: Alexei Starovoitov

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: NHou Tao <houtao1@huawei.com>
Link: https://lore.kernel.org/r/20221014113946.965131-4-houtao@huaweicloud.comSigned-off-by: NAlexei Starovoitov <ast@kernel.org>
上级 59be91e5
...@@ -88,7 +88,13 @@ void bpf_local_storage_free_rcu(struct rcu_head *rcu) ...@@ -88,7 +88,13 @@ void bpf_local_storage_free_rcu(struct rcu_head *rcu)
{ {
struct bpf_local_storage *local_storage; struct bpf_local_storage *local_storage;
/* If RCU Tasks Trace grace period implies RCU grace period, do
* kfree(), else do kfree_rcu().
*/
local_storage = container_of(rcu, struct bpf_local_storage, rcu); local_storage = container_of(rcu, struct bpf_local_storage, rcu);
if (rcu_trace_implies_rcu_gp())
kfree(local_storage);
else
kfree_rcu(local_storage, rcu); kfree_rcu(local_storage, rcu);
} }
...@@ -97,6 +103,9 @@ static void bpf_selem_free_rcu(struct rcu_head *rcu) ...@@ -97,6 +103,9 @@ static void bpf_selem_free_rcu(struct rcu_head *rcu)
struct bpf_local_storage_elem *selem; struct bpf_local_storage_elem *selem;
selem = container_of(rcu, struct bpf_local_storage_elem, rcu); selem = container_of(rcu, struct bpf_local_storage_elem, rcu);
if (rcu_trace_implies_rcu_gp())
kfree(selem);
else
kfree_rcu(selem, rcu); kfree_rcu(selem, rcu);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册