Commit f8ccf30c authored by Martin KaFai Lau's avatar Martin KaFai Lau Committed by Alexei Starovoitov

bpf: Add bpf_selem_free_rcu callback

Add bpf_selem_free_rcu() callback to do the kfree() instead
of using kfree_rcu. It is a preparation work for using
bpf_mem_cache_alloc/free in a later patch.
Signed-off-by: default avatarMartin KaFai Lau <martin.lau@kernel.org>
Link: https://lore.kernel.org/r/20230308065936.1550103-9-martin.lau@linux.devSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parent c6099813
...@@ -109,15 +109,20 @@ static void bpf_local_storage_free_rcu(struct rcu_head *rcu) ...@@ -109,15 +109,20 @@ static void bpf_local_storage_free_rcu(struct rcu_head *rcu)
kfree_rcu(local_storage, rcu); kfree_rcu(local_storage, rcu);
} }
static void bpf_selem_free_trace_rcu(struct rcu_head *rcu) 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); kfree(selem);
}
static void bpf_selem_free_trace_rcu(struct rcu_head *rcu)
{
if (rcu_trace_implies_rcu_gp())
bpf_selem_free_rcu(rcu);
else else
kfree_rcu(selem, rcu); call_rcu(rcu, bpf_selem_free_rcu);
} }
/* local_storage->lock must be held and selem->local_storage == local_storage. /* local_storage->lock must be held and selem->local_storage == local_storage.
...@@ -174,7 +179,7 @@ static bool bpf_selem_unlink_storage_nolock(struct bpf_local_storage *local_stor ...@@ -174,7 +179,7 @@ static bool bpf_selem_unlink_storage_nolock(struct bpf_local_storage *local_stor
if (!reuse_now) if (!reuse_now)
call_rcu_tasks_trace(&selem->rcu, bpf_selem_free_trace_rcu); call_rcu_tasks_trace(&selem->rcu, bpf_selem_free_trace_rcu);
else else
kfree_rcu(selem, rcu); call_rcu(&selem->rcu, bpf_selem_free_rcu);
if (rcu_access_pointer(local_storage->smap) == smap) if (rcu_access_pointer(local_storage->smap) == smap)
RCU_INIT_POINTER(local_storage->smap, NULL); RCU_INIT_POINTER(local_storage->smap, NULL);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment