Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

bpf: Always charge/uncharge memory when allocating/unlinking storage elements

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>

authored by

Amery Hung and committed by
Alexei Starovoitov
0e854e55 ec12ab2c

+12 -14
+1 -1
include/linux/bpf_local_storage.h
··· 184 184 185 185 struct bpf_local_storage_elem * 186 186 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); 188 188 189 189 void bpf_selem_free(struct bpf_local_storage_elem *selem, 190 190 struct bpf_local_storage_map *smap,
+10 -12
kernel/bpf/bpf_local_storage.c
··· 73 73 74 74 struct bpf_local_storage_elem * 75 75 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) 77 77 { 78 78 struct bpf_local_storage_elem *selem; 79 79 80 - if (charge_mem && mem_charge(smap, owner, smap->elem_size)) 80 + if (mem_charge(smap, owner, smap->elem_size)) 81 81 return NULL; 82 82 83 83 if (smap->bpf_ma) { ··· 106 106 return selem; 107 107 } 108 108 109 - if (charge_mem) 110 - mem_uncharge(smap, owner, smap->elem_size); 109 + mem_uncharge(smap, owner, smap->elem_size); 111 110 112 111 return NULL; 113 112 } ··· 283 284 */ 284 285 static bool bpf_selem_unlink_storage_nolock(struct bpf_local_storage *local_storage, 285 286 struct bpf_local_storage_elem *selem, 286 - bool uncharge_mem, struct hlist_head *free_selem_list) 287 + struct hlist_head *free_selem_list) 287 288 { 288 289 struct bpf_local_storage_map *smap; 289 290 bool free_local_storage; ··· 296 297 * The owner may be freed once the last selem is unlinked 297 298 * from local_storage. 298 299 */ 299 - if (uncharge_mem) 300 - mem_uncharge(smap, owner, smap->elem_size); 300 + mem_uncharge(smap, owner, smap->elem_size); 301 301 302 302 free_local_storage = hlist_is_singular_node(&selem->snode, 303 303 &local_storage->list); ··· 391 393 raw_spin_lock_irqsave(&local_storage->lock, flags); 392 394 if (likely(selem_linked_to_storage(selem))) 393 395 free_local_storage = bpf_selem_unlink_storage_nolock( 394 - local_storage, selem, true, &selem_free_list); 396 + local_storage, selem, &selem_free_list); 395 397 raw_spin_unlock_irqrestore(&local_storage->lock, flags); 396 398 397 399 bpf_selem_free_list(&selem_free_list, reuse_now); ··· 580 582 if (err) 581 583 return ERR_PTR(err); 582 584 583 - selem = bpf_selem_alloc(smap, owner, value, true, swap_uptrs, gfp_flags); 585 + selem = bpf_selem_alloc(smap, owner, value, swap_uptrs, gfp_flags); 584 586 if (!selem) 585 587 return ERR_PTR(-ENOMEM); 586 588 ··· 614 616 /* A lookup has just been done before and concluded a new selem is 615 617 * needed. The chance of an unnecessary alloc is unlikely. 616 618 */ 617 - alloc_selem = selem = bpf_selem_alloc(smap, owner, value, true, swap_uptrs, gfp_flags); 619 + alloc_selem = selem = bpf_selem_alloc(smap, owner, value, swap_uptrs, gfp_flags); 618 620 if (!alloc_selem) 619 621 return ERR_PTR(-ENOMEM); 620 622 ··· 654 656 if (old_sdata) { 655 657 bpf_selem_unlink_map(SELEM(old_sdata)); 656 658 bpf_selem_unlink_storage_nolock(local_storage, SELEM(old_sdata), 657 - true, &old_selem_free_list); 659 + &old_selem_free_list); 658 660 } 659 661 660 662 unlock: ··· 760 762 * of the loop will set the free_cgroup_storage to true. 761 763 */ 762 764 free_storage = bpf_selem_unlink_storage_nolock( 763 - local_storage, selem, true, &free_selem_list); 765 + local_storage, selem, &free_selem_list); 764 766 } 765 767 raw_spin_unlock_irqrestore(&local_storage->lock, flags); 766 768
+1 -1
net/core/bpf_sk_storage.c
··· 136 136 { 137 137 struct bpf_local_storage_elem *copy_selem; 138 138 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); 140 140 if (!copy_selem) 141 141 return NULL; 142 142