Skip to content

Conversation

@puranjaymohan
Copy link
Contributor

BPF VMA iterators and bpf_find_vma() hold mmap_lock, which deadlocks when BPF programs call bpf_copy_from_user_task() on the same task (recursive lock acquisition).

Holding per-VMA locks during BPF execution also deadlocks due to circular locking: kernel has mmap_lock → vm_lock dependency (vma_expand), our code creates vm_lock → mmap_lock (callback → bpf_copy_from_user_task).

Solution: Use per-VMA locks to validate VMAs are stable, then release vm_lock BEFORE returning to BPF or calling callbacks. VMA structures remain RCU-protected during BPF execution.

Trade-off: VMA fields may be stale between lock release and BPF access. This is acceptable for tracing/profiling use cases.

BPF VMA iterators and bpf_find_vma() hold mmap_lock, which deadlocks
when BPF programs call bpf_copy_from_user_task() on the same task
(recursive lock acquisition).

Holding per-VMA locks during BPF execution also deadlocks due to
circular locking: kernel has mmap_lock → vm_lock dependency (vma_expand),
our code creates vm_lock → mmap_lock (callback → bpf_copy_from_user_task).

Solution: Use per-VMA locks to validate VMAs are stable, then release
vm_lock BEFORE returning to BPF or calling callbacks. VMA structures
remain RCU-protected during BPF execution.

Trade-off: VMA fields may be stale between lock release and BPF access.
This is acceptable for tracing/profiling use cases.

Signed-off-by: Paul Jia <pjy@meta.com>
@kernel-patches-daemon-bpf kernel-patches-daemon-bpf bot force-pushed the bpf-next_base branch 3 times, most recently from e7b5368 to 1e194b1 Compare January 7, 2026 05:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant