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: Use refcount_t instead of atomic_t for mmap_count

Use an API that resembles more the actual use of mmap_count.

Found by cocci:
kernel/bpf/arena.c:245:6-25: WARNING: atomic_dec_and_test variation before object free at line 249.

Fixes: b90d77e5fd78 ("bpf: Fix remap of arena.")
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202412292037.LXlYSHKl-lkp@intel.com/
Signed-off-by: Pei Xiao <xiaopei01@kylinos.cn>
Link: https://lore.kernel.org/r/6ecce439a6bc81adb85d5080908ea8959b792a50.1735542814.git.xiaopei01@kylinos.cn
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Pei Xiao and committed by
Alexei Starovoitov
dfa94ce5 654a3381

+4 -4
+4 -4
kernel/bpf/arena.c
··· 218 218 struct vma_list { 219 219 struct vm_area_struct *vma; 220 220 struct list_head head; 221 - atomic_t mmap_count; 221 + refcount_t mmap_count; 222 222 }; 223 223 224 224 static int remember_vma(struct bpf_arena *arena, struct vm_area_struct *vma) ··· 228 228 vml = kmalloc(sizeof(*vml), GFP_KERNEL); 229 229 if (!vml) 230 230 return -ENOMEM; 231 - atomic_set(&vml->mmap_count, 1); 231 + refcount_set(&vml->mmap_count, 1); 232 232 vma->vm_private_data = vml; 233 233 vml->vma = vma; 234 234 list_add(&vml->head, &arena->vma_list); ··· 239 239 { 240 240 struct vma_list *vml = vma->vm_private_data; 241 241 242 - atomic_inc(&vml->mmap_count); 242 + refcount_inc(&vml->mmap_count); 243 243 } 244 244 245 245 static void arena_vm_close(struct vm_area_struct *vma) ··· 248 248 struct bpf_arena *arena = container_of(map, struct bpf_arena, map); 249 249 struct vma_list *vml = vma->vm_private_data; 250 250 251 - if (!atomic_dec_and_test(&vml->mmap_count)) 251 + if (!refcount_dec_and_test(&vml->mmap_count)) 252 252 return; 253 253 guard(mutex)(&arena->lock); 254 254 /* update link list under lock */