Skip to content

B4/lru map spin#12134

Draft
mykyta5 wants to merge 4 commits into
bpf-next_basefrom
b4/lru_map_spin
Draft

B4/lru map spin#12134
mykyta5 wants to merge 4 commits into
bpf-next_basefrom
b4/lru_map_spin

Conversation

@mykyta5
Copy link
Copy Markdown
Collaborator

@mykyta5 mykyta5 commented May 20, 2026

No description provided.

Kernel Patches Daemon and others added 4 commits May 18, 2026 19:04
# Describe the purpose of this series. The information you put here
# will be used by the project maintainer to make a decision whether
# your patches should be reviewed, and in what priority order. Please be
# very detailed and link to any relevant discussions or sites that the
# maintainer can review to better understand your proposed changes. If you
# only have a single patch in your series, the contents of the cover
# letter will be appended to the "under-the-cut" portion of the patch.

# Lines starting with # will be removed from the cover letter. You can
# use them to add notes or reminders to yourself. If you want to use
# markdown headers in your cover letter, start the line with ">#".

# You can add trailers to the cover letter. Any email addresses found in
# these trailers will be added to the addresses specified/generated
# during the b4 send stage. You can also run "b4 prep --auto-to-cc" to
# auto-populate the To: and Cc: trailers based on the code being
# modified.

Signed-off-by: Mykyta Yatsenko <yatsenko@meta.com>

--- b4-submit-tracking ---
# This section is used internally by b4 prep for tracking purposes.
{
  "series": {
    "revision": 1,
    "change-id": "20260519-lru_map_spin-8e20dabbf460",
    "prefixes": []
  }
}
Perf-event BPF programs running in NMI can re-enter the per-CPU
loc_l->lock (and the global lru_list lock) that bpf_lru_pop_free()
already holds in syscall context on the same CPU. Lockdep reports
"inconsistent {INITIAL USE} -> {IN-NMI} usage" at bpf_lru_pop_free,
and a real AA deadlock is possible.

Mirror hashtab's fix: switch both locks to rqspinlock_t so the NMI
acquirer sees -EDEADLK from the slow-path AA check and bails. Pop
paths return NULL (same as OOM); push paths skip the move (the node
stays in the preallocated pool until map destroy).

Signed-off-by: Mykyta Yatsenko <yatsenko@meta.com>
Reproduces the loc_l->lock NMI re-entry that lockdep flagged on the
LRU hash map. Pins to CPU 0, attaches a perf_event BPF prog that
updates an LRU map from NMI, and hammers the same map from
userspace. On an unpatched kernel with PROVE_LOCKING this fires the
"inconsistent {INITIAL USE} -> {IN-NMI}" splat within a second.

Marked serial_ because CPU pinning plus a high-rate HW perf event
would perturb parallel tests.

Signed-off-by: Mykyta Yatsenko <yatsenko@meta.com>
@kernel-patches-review-bot
Copy link
Copy Markdown

commit e15567f4acd127b3264864ba1f9a31f84b91d0b1
Author: Mykyta Yatsenko <yatsenko@meta.com>

bpf: convert bpf_lru locks to rqspinlock

This commit converts bpf_lru_list locks from raw_spinlock_t to
rqspinlock_t to prevent NMI deadlock issues. Perf-event BPF programs
running in NMI context can re-enter locks already held in syscall
context on the same CPU, causing AA deadlocks. The rqspinlock detects
these scenarios via -EDEADLK and allows NMI code to bail gracefully.

> Perf-event BPF programs running in NMI can re-enter the per-CPU
> loc_l->lock (and the global lru_list lock) that bpf_lru_pop_free()
> already holds in syscall context on the same CPU. Lockdep reports
> "inconsistent {INITIAL USE} -> {IN-NMI} usage" at bpf_lru_pop_free,
> and a real AA deadlock is possible.
>
> Mirror hashtab's fix: switch both locks to rqspinlock_t so the NMI
> acquirer sees -EDEADLK from the slow-path AA check and bails. Pop
> paths return NULL (same as OOM); push paths skip the move (the node
> stays in the preallocated pool until map destroy).
>
> Signed-off-by: Mykyta Yatsenko <yatsenko@meta.com>

This looks like a bug fix for the NMI deadlock issue introduced when
bpf_lru_list was originally implemented with raw_spinlock_t locks, which
are not NMI-safe. Should this include:

  Fixes: 3a08c2fd7634 ("bpf: LRU List")



AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

In-Reply-To-Subject: bpf: convert bpf_lru locks to rqspinlock
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/26133527427

@kernel-patches-daemon-bpf kernel-patches-daemon-bpf Bot force-pushed the bpf-next_base branch 2 times, most recently from ec31e3e to b3beebb Compare May 21, 2026 10:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant