bpf: Add bpf_local_storage_rcu callback
authorMartin KaFai Lau <martin.lau@kernel.org>
Wed, 8 Mar 2023 06:59:29 +0000 (22:59 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 10 Mar 2023 19:05:29 +0000 (11:05 -0800)
The existing bpf_local_storage_free_rcu is renamed to
bpf_local_storage_free_trace_rcu. A new bpf_local_storage_rcu
callback is added to do the kfree instead of using kfree_rcu.
It is a preparation work for a later patch using
bpf_mem_cache_alloc/free.

Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Link: https://lore.kernel.org/r/20230308065936.1550103-11-martin.lau@linux.dev
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/bpf/bpf_local_storage.c

index 512943a..0fbc477 100644 (file)
@@ -99,14 +99,19 @@ static void bpf_local_storage_free_rcu(struct rcu_head *rcu)
 {
        struct bpf_local_storage *local_storage;
 
+       local_storage = container_of(rcu, struct bpf_local_storage, rcu);
+       kfree(local_storage);
+}
+
+static void bpf_local_storage_free_trace_rcu(struct rcu_head *rcu)
+{
        /* 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);
        if (rcu_trace_implies_rcu_gp())
-               kfree(local_storage);
+               bpf_local_storage_free_rcu(rcu);
        else
-               kfree_rcu(local_storage, rcu);
+               call_rcu(rcu, bpf_local_storage_free_rcu);
 }
 
 static void bpf_selem_free_rcu(struct rcu_head *rcu)
@@ -216,9 +221,9 @@ static void bpf_selem_unlink_storage(struct bpf_local_storage_elem *selem,
        if (free_local_storage) {
                if (!reuse_now)
                        call_rcu_tasks_trace(&local_storage->rcu,
-                                    bpf_local_storage_free_rcu);
+                                    bpf_local_storage_free_trace_rcu);
                else
-                       kfree_rcu(local_storage, rcu);
+                       call_rcu(&local_storage->rcu, bpf_local_storage_free_rcu);
        }
 }
 
@@ -631,7 +636,7 @@ void bpf_local_storage_destroy(struct bpf_local_storage *local_storage)
        raw_spin_unlock_irqrestore(&local_storage->lock, flags);
 
        if (free_storage)
-               kfree_rcu(local_storage, rcu);
+               call_rcu(&local_storage->rcu, bpf_local_storage_free_rcu);
 }
 
 u64 bpf_local_storage_map_mem_usage(const struct bpf_map *map)