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: Drop always true do_idr_lock parameter to bpf_map_free_id

The do_idr_lock parameter to bpf_map_free_id was introduced by commit
bd5f5f4ecb78 ("bpf: Add BPF_MAP_GET_FD_BY_ID"). However, all callers set
do_idr_lock = true since commit 1e0bd5a091e5 ("bpf: Switch bpf_map ref
counter to atomic64_t so bpf_map_inc() never fails").

While at it also inline __bpf_map_put into its only caller bpf_map_put
now that do_idr_lock can be dropped from its signature.

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Link: https://lore.kernel.org/r/20230202141921.4424-1-tklauser@distanz.ch
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Tobias Klauser and committed by
Alexei Starovoitov
158e5e9e d9e44c32

+8 -19
+1 -1
include/linux/bpf.h
··· 1846 1846 void bpf_prog_put(struct bpf_prog *prog); 1847 1847 1848 1848 void bpf_prog_free_id(struct bpf_prog *prog); 1849 - void bpf_map_free_id(struct bpf_map *map, bool do_idr_lock); 1849 + void bpf_map_free_id(struct bpf_map *map); 1850 1850 1851 1851 struct btf_field *btf_record_find(const struct btf_record *rec, 1852 1852 u32 offset, enum btf_field_type type);
+1 -1
kernel/bpf/offload.c
··· 136 136 { 137 137 WARN_ON(bpf_map_offload_ndo(offmap, BPF_OFFLOAD_MAP_FREE)); 138 138 /* Make sure BPF_MAP_GET_NEXT_ID can't find this dead map */ 139 - bpf_map_free_id(&offmap->map, true); 139 + bpf_map_free_id(&offmap->map); 140 140 list_del_init(&offmap->offloads); 141 141 offmap->netdev = NULL; 142 142 }
+6 -17
kernel/bpf/syscall.c
··· 390 390 return id > 0 ? 0 : id; 391 391 } 392 392 393 - void bpf_map_free_id(struct bpf_map *map, bool do_idr_lock) 393 + void bpf_map_free_id(struct bpf_map *map) 394 394 { 395 395 unsigned long flags; 396 396 ··· 402 402 if (!map->id) 403 403 return; 404 404 405 - if (do_idr_lock) 406 - spin_lock_irqsave(&map_idr_lock, flags); 407 - else 408 - __acquire(&map_idr_lock); 405 + spin_lock_irqsave(&map_idr_lock, flags); 409 406 410 407 idr_remove(&map_idr, map->id); 411 408 map->id = 0; 412 409 413 - if (do_idr_lock) 414 - spin_unlock_irqrestore(&map_idr_lock, flags); 415 - else 416 - __release(&map_idr_lock); 410 + spin_unlock_irqrestore(&map_idr_lock, flags); 417 411 } 418 412 419 413 #ifdef CONFIG_MEMCG_KMEM ··· 700 706 } 701 707 702 708 /* decrement map refcnt and schedule it for freeing via workqueue 703 - * (unrelying map implementation ops->map_free() might sleep) 709 + * (underlying map implementation ops->map_free() might sleep) 704 710 */ 705 - static void __bpf_map_put(struct bpf_map *map, bool do_idr_lock) 711 + void bpf_map_put(struct bpf_map *map) 706 712 { 707 713 if (atomic64_dec_and_test(&map->refcnt)) { 708 714 /* bpf_map_free_id() must be called first */ 709 - bpf_map_free_id(map, do_idr_lock); 715 + bpf_map_free_id(map); 710 716 btf_put(map->btf); 711 717 INIT_WORK(&map->work, bpf_map_free_deferred); 712 718 /* Avoid spawning kworkers, since they all might contend ··· 714 720 */ 715 721 queue_work(system_unbound_wq, &map->work); 716 722 } 717 - } 718 - 719 - void bpf_map_put(struct bpf_map *map) 720 - { 721 - __bpf_map_put(map, true); 722 723 } 723 724 EXPORT_SYMBOL_GPL(bpf_map_put); 724 725