Skip to content

Commit e0cb26c

Browse files
committed
bpf: Always charge/uncharge memory when allocating/unlinking storage elements
Since commit a96a44a ("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 <[email protected]>
1 parent f8c67d8 commit e0cb26c

File tree

3 files changed

+12
-14
lines changed

3 files changed

+12
-14
lines changed

include/linux/bpf_local_storage.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ void bpf_selem_link_map(struct bpf_local_storage_map *smap,
184184

185185
struct bpf_local_storage_elem *
186186
bpf_selem_alloc(struct bpf_local_storage_map *smap, void *owner, void *value,
187-
bool charge_mem, bool swap_uptrs, gfp_t gfp_flags);
187+
bool swap_uptrs, gfp_t gfp_flags);
188188

189189
void bpf_selem_free(struct bpf_local_storage_elem *selem,
190190
struct bpf_local_storage_map *smap,

kernel/bpf/bpf_local_storage.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ static bool selem_linked_to_map(const struct bpf_local_storage_elem *selem)
7373

7474
struct bpf_local_storage_elem *
7575
bpf_selem_alloc(struct bpf_local_storage_map *smap, void *owner,
76-
void *value, bool charge_mem, bool swap_uptrs, gfp_t gfp_flags)
76+
void *value, bool swap_uptrs, gfp_t gfp_flags)
7777
{
7878
struct bpf_local_storage_elem *selem;
7979

80-
if (charge_mem && mem_charge(smap, owner, smap->elem_size))
80+
if (mem_charge(smap, owner, smap->elem_size))
8181
return NULL;
8282

8383
if (smap->bpf_ma) {
@@ -106,8 +106,7 @@ bpf_selem_alloc(struct bpf_local_storage_map *smap, void *owner,
106106
return selem;
107107
}
108108

109-
if (charge_mem)
110-
mem_uncharge(smap, owner, smap->elem_size);
109+
mem_uncharge(smap, owner, smap->elem_size);
111110

112111
return NULL;
113112
}
@@ -284,7 +283,7 @@ static void bpf_selem_free_list(struct hlist_head *list, bool reuse_now)
284283
*/
285284
static bool bpf_selem_unlink_storage_nolock(struct bpf_local_storage *local_storage,
286285
struct bpf_local_storage_elem *selem,
287-
bool uncharge_mem, struct hlist_head *free_selem_list)
286+
struct hlist_head *free_selem_list)
288287
{
289288
struct bpf_local_storage_map *smap;
290289
bool free_local_storage;
@@ -297,8 +296,7 @@ static bool bpf_selem_unlink_storage_nolock(struct bpf_local_storage *local_stor
297296
* The owner may be freed once the last selem is unlinked
298297
* from local_storage.
299298
*/
300-
if (uncharge_mem)
301-
mem_uncharge(smap, owner, smap->elem_size);
299+
mem_uncharge(smap, owner, smap->elem_size);
302300

303301
free_local_storage = hlist_is_singular_node(&selem->snode,
304302
&local_storage->list);
@@ -393,7 +391,7 @@ static void bpf_selem_unlink_storage(struct bpf_local_storage_elem *selem,
393391
raw_spin_lock_irqsave(&local_storage->lock, flags);
394392
if (likely(selem_linked_to_storage(selem)))
395393
free_local_storage = bpf_selem_unlink_storage_nolock(
396-
local_storage, selem, true, &selem_free_list);
394+
local_storage, selem, &selem_free_list);
397395
raw_spin_unlock_irqrestore(&local_storage->lock, flags);
398396

399397
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,
582580
if (err)
583581
return ERR_PTR(err);
584582

585-
selem = bpf_selem_alloc(smap, owner, value, true, swap_uptrs, gfp_flags);
583+
selem = bpf_selem_alloc(smap, owner, value, swap_uptrs, gfp_flags);
586584
if (!selem)
587585
return ERR_PTR(-ENOMEM);
588586

@@ -616,7 +614,7 @@ bpf_local_storage_update(void *owner, struct bpf_local_storage_map *smap,
616614
/* A lookup has just been done before and concluded a new selem is
617615
* needed. The chance of an unnecessary alloc is unlikely.
618616
*/
619-
alloc_selem = selem = bpf_selem_alloc(smap, owner, value, true, swap_uptrs, gfp_flags);
617+
alloc_selem = selem = bpf_selem_alloc(smap, owner, value, swap_uptrs, gfp_flags);
620618
if (!alloc_selem)
621619
return ERR_PTR(-ENOMEM);
622620

@@ -656,7 +654,7 @@ bpf_local_storage_update(void *owner, struct bpf_local_storage_map *smap,
656654
if (old_sdata) {
657655
bpf_selem_unlink_map(SELEM(old_sdata));
658656
bpf_selem_unlink_storage_nolock(local_storage, SELEM(old_sdata),
659-
true, &old_selem_free_list);
657+
&old_selem_free_list);
660658
}
661659

662660
unlock:
@@ -762,7 +760,7 @@ void bpf_local_storage_destroy(struct bpf_local_storage *local_storage)
762760
* of the loop will set the free_cgroup_storage to true.
763761
*/
764762
free_storage = bpf_selem_unlink_storage_nolock(
765-
local_storage, selem, true, &free_selem_list);
763+
local_storage, selem, &free_selem_list);
766764
}
767765
raw_spin_unlock_irqrestore(&local_storage->lock, flags);
768766

net/core/bpf_sk_storage.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ bpf_sk_storage_clone_elem(struct sock *newsk,
136136
{
137137
struct bpf_local_storage_elem *copy_selem;
138138

139-
copy_selem = bpf_selem_alloc(smap, newsk, NULL, true, false, GFP_ATOMIC);
139+
copy_selem = bpf_selem_alloc(smap, newsk, NULL, false, GFP_ATOMIC);
140140
if (!copy_selem)
141141
return NULL;
142142

0 commit comments

Comments
 (0)