]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
bpf: Always charge/uncharge memory when allocating/unlinking storage elements
authorAmery Hung <ameryhung@gmail.com>
Fri, 14 Nov 2025 20:13:23 +0000 (12:13 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 19 Nov 2025 00:20:25 +0000 (16:20 -0800)
Since commit a96a44aba556 ("bpf: bpf_sk_storage: Fix invalid wait
context lockdep report"), {charge,uncharge}_mem are always true when
allocating a bpf_local_storage_elem or unlinking a bpf_local_storage_elem
from local storage, so drop these arguments. No functional change.

Signed-off-by: Amery Hung <ameryhung@gmail.com>
Reviewed-by: Martin KaFai Lau <martin.lau@kernel.org>
Link: https://lore.kernel.org/r/20251114201329.3275875-2-ameryhung@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
include/linux/bpf_local_storage.h
kernel/bpf/bpf_local_storage.c
net/core/bpf_sk_storage.c

index 782f58feea356514a8420070cabf3d213a19a3c1..3663eabcc3ffff213162ede90cd7fb6fd61d855f 100644 (file)
@@ -184,7 +184,7 @@ void bpf_selem_link_map(struct bpf_local_storage_map *smap,
 
 struct bpf_local_storage_elem *
 bpf_selem_alloc(struct bpf_local_storage_map *smap, void *owner, void *value,
-               bool charge_mem, bool swap_uptrs, gfp_t gfp_flags);
+               bool swap_uptrs, gfp_t gfp_flags);
 
 void bpf_selem_free(struct bpf_local_storage_elem *selem,
                    struct bpf_local_storage_map *smap,
index b931fbceb54da00f182d15ab343d7a47cb3b162f..400bdf8a3eb216af461c7892cb3b2b22faa0cb5f 100644 (file)
@@ -73,11 +73,11 @@ static bool selem_linked_to_map(const struct bpf_local_storage_elem *selem)
 
 struct bpf_local_storage_elem *
 bpf_selem_alloc(struct bpf_local_storage_map *smap, void *owner,
-               void *value, bool charge_mem, bool swap_uptrs, gfp_t gfp_flags)
+               void *value, bool swap_uptrs, gfp_t gfp_flags)
 {
        struct bpf_local_storage_elem *selem;
 
-       if (charge_mem && mem_charge(smap, owner, smap->elem_size))
+       if (mem_charge(smap, owner, smap->elem_size))
                return NULL;
 
        if (smap->bpf_ma) {
@@ -106,8 +106,7 @@ bpf_selem_alloc(struct bpf_local_storage_map *smap, void *owner,
                return selem;
        }
 
-       if (charge_mem)
-               mem_uncharge(smap, owner, smap->elem_size);
+       mem_uncharge(smap, owner, smap->elem_size);
 
        return NULL;
 }
@@ -284,7 +283,7 @@ static void bpf_selem_free_list(struct hlist_head *list, bool reuse_now)
  */
 static bool bpf_selem_unlink_storage_nolock(struct bpf_local_storage *local_storage,
                                            struct bpf_local_storage_elem *selem,
-                                           bool uncharge_mem, struct hlist_head *free_selem_list)
+                                           struct hlist_head *free_selem_list)
 {
        struct bpf_local_storage_map *smap;
        bool free_local_storage;
@@ -297,8 +296,7 @@ static bool bpf_selem_unlink_storage_nolock(struct bpf_local_storage *local_stor
         * The owner may be freed once the last selem is unlinked
         * from local_storage.
         */
-       if (uncharge_mem)
-               mem_uncharge(smap, owner, smap->elem_size);
+       mem_uncharge(smap, owner, smap->elem_size);
 
        free_local_storage = hlist_is_singular_node(&selem->snode,
                                                    &local_storage->list);
@@ -393,7 +391,7 @@ static void bpf_selem_unlink_storage(struct bpf_local_storage_elem *selem,
        raw_spin_lock_irqsave(&local_storage->lock, flags);
        if (likely(selem_linked_to_storage(selem)))
                free_local_storage = bpf_selem_unlink_storage_nolock(
-                       local_storage, selem, true, &selem_free_list);
+                       local_storage, selem, &selem_free_list);
        raw_spin_unlock_irqrestore(&local_storage->lock, flags);
 
        bpf_selem_free_list(&selem_free_list, reuse_now);
@@ -582,7 +580,7 @@ bpf_local_storage_update(void *owner, struct bpf_local_storage_map *smap,
                if (err)
                        return ERR_PTR(err);
 
-               selem = bpf_selem_alloc(smap, owner, value, true, swap_uptrs, gfp_flags);
+               selem = bpf_selem_alloc(smap, owner, value, swap_uptrs, gfp_flags);
                if (!selem)
                        return ERR_PTR(-ENOMEM);
 
@@ -616,7 +614,7 @@ bpf_local_storage_update(void *owner, struct bpf_local_storage_map *smap,
        /* A lookup has just been done before and concluded a new selem is
         * needed. The chance of an unnecessary alloc is unlikely.
         */
-       alloc_selem = selem = bpf_selem_alloc(smap, owner, value, true, swap_uptrs, gfp_flags);
+       alloc_selem = selem = bpf_selem_alloc(smap, owner, value, swap_uptrs, gfp_flags);
        if (!alloc_selem)
                return ERR_PTR(-ENOMEM);
 
@@ -656,7 +654,7 @@ bpf_local_storage_update(void *owner, struct bpf_local_storage_map *smap,
        if (old_sdata) {
                bpf_selem_unlink_map(SELEM(old_sdata));
                bpf_selem_unlink_storage_nolock(local_storage, SELEM(old_sdata),
-                                               true, &old_selem_free_list);
+                                               &old_selem_free_list);
        }
 
 unlock:
@@ -762,7 +760,7 @@ void bpf_local_storage_destroy(struct bpf_local_storage *local_storage)
                 * of the loop will set the free_cgroup_storage to true.
                 */
                free_storage = bpf_selem_unlink_storage_nolock(
-                       local_storage, selem, true, &free_selem_list);
+                       local_storage, selem, &free_selem_list);
        }
        raw_spin_unlock_irqrestore(&local_storage->lock, flags);
 
index d3fbaf89a698da1e3ed593ff82bb6ec4414bbd39..bd3c686edc0b43ea52701bfed192630cd04c9f57 100644 (file)
@@ -136,7 +136,7 @@ bpf_sk_storage_clone_elem(struct sock *newsk,
 {
        struct bpf_local_storage_elem *copy_selem;
 
-       copy_selem = bpf_selem_alloc(smap, newsk, NULL, true, false, GFP_ATOMIC);
+       copy_selem = bpf_selem_alloc(smap, newsk, NULL, false, GFP_ATOMIC);
        if (!copy_selem)
                return NULL;