| 0/0 |
2026/05/20 07:14 |
flow |
assessment-security |
1h08m
Results: map[DenialOfService:true Explanation:Based on the analysis of the bug report and the kernel source code, here is the
security assessment of the issue:
### Bug Mechanism
The bug is a recursive spinlock deadlock in the BPF LRU map implementation. The
sequence of events leading to the deadlock is as follows:
1. A kernel context (such as the `bpf(MAP_UPDATE_BATCH)` syscall) operates on an
LRU map and acquires the per-CPU `loc_l->lock`.
2. While holding `loc_l->lock`, it attempts to acquire the global LRU list lock
(`l->lock`).
3. If `l->lock` is contended by another CPU, the current CPU will spin in the
slowpath. Once it finally acquires the lock, the kernel's lock statistics
subsystem triggers the `contention_end` tracepoint (via
`trace_contention_end()`).
4. If a BPF tracing program (e.g., `BPF_PROG_TYPE_RAW_TRACEPOINT`) is attached
to the `contention_end` tracepoint, it will execute synchronously in this
context.
5. If the BPF program attempts to update or delete an element in the *same* LRU
map, it will call into the LRU map helpers (like `bpf_lru_push_free`) which try
to acquire the `loc_l->lock` again.
6. Because the lock is already held by the interrupted syscall context, the CPU
deadlocks.
### Security Impact
* **Exploitable:** **False**. This is a classic spinlock deadlock. It results in
a CPU hang (soft or hard lockup) but does not cause memory corruption,
out-of-bounds access, or allow for privilege escalation.
* **Denial Of Service:** **True**. Triggering the bug hangs the CPU, leading to
a system-wide denial of service (kernel panic via watchdog).
* **Accessible From Unprivileged Processes / User Namespaces:** **False**.
Attaching a BPF program to a raw tracepoint like `contention_end` strictly
requires `CAP_PERFMON` or `CAP_SYS_ADMIN` capabilities. Furthermore, with
`unprivileged_bpf_disabled=1` (as assumed), unprivileged users cannot create BPF
maps or load eBPF programs at all. Even if a privileged user (like an
administrator running a tracing tool) sets up the vulnerable BPF program, an
unprivileged user cannot trigger the deadlock because they do not have file
descriptor access to the privileged tracing tool's BPF map to cause the initial
lock contention.
* **Remote / Peripheral / Filesystem / VM Triggers:** **False**. The bug is
entirely contained within the BPF subsystem and requires local execution of BPF
syscalls to set up the tracepoint and map. It cannot be triggered remotely, via
malicious filesystems, or by external hardware.
In summary, this is a local Denial-of-Service bug that can only be triggered by
a highly privileged user (root or a user with `CAP_PERFMON`/`CAP_SYS_ADMIN`) who
is already capable of loading advanced BPF tracing programs. It does not cross
any security boundaries. Exploitable:false FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:false UserNamespace:false VMGuestTrigger:false VMHostTrigger:false]
|
| 1/1 |
2026/05/20 07:14 |
action |
syz-repro-to-c-repro |
0m
Results: map[SimplifiedCRepro:// autogenerated by syzkaller (https://github.com/google/syzkaller)
#define _GNU_SOURCE
#include <endian.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mount.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <unistd.h>
#ifndef __NR_bpf
#define __NR_bpf 321
#endif
#define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off))
#define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len))))
uint64_t r[2] = {0xffffffffffffffff, 0xffffffffffffffff};
int main(void)
{
syscall(__NR_mmap, /*addr=*/0x1ffffffff000ul, /*len=*/0x1000ul, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul);
syscall(__NR_mmap, /*addr=*/0x200000000000ul, /*len=*/0x1000000ul, /*prot=PROT_WRITE|PROT_READ|PROT_EXEC*/7ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul);
syscall(__NR_mmap, /*addr=*/0x200001000000ul, /*len=*/0x1000ul, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul);
const char* reason;
(void)reason;
intptr_t res = 0;
if (write(1, "executing program\n", sizeof("executing program\n") - 1)) {}
// bpf$MAP_CREATE arguments: [
// cmd: const = 0x0 (8 bytes)
// arg: ptr[inout, array[ANYUNION]] {
// array[ANYUNION] {
// union ANYUNION {
// ANYBLOB: buffer: {0a 00 00 00 01 00 00 00 0c 00 00 00 09} (length 0xd)
// }
// }
// }
// size: len = 0x50 (8 bytes)
// ]
// returns fd_bpf_map
memcpy((void*)0x2000000009c0, "\x0a\x00\x00\x00\x01\x00\x00\x00\x0c\x00\x00\x00\x09", 13);
res = syscall(__NR_bpf, /*cmd=*/0ul, /*arg=*/0x2000000009c0ul, /*size=*/0x50ul);
if (res != -1)
r[0] = res;
// bpf$PROG_LOAD arguments: [
// cmd: const = 0x5 (8 bytes)
// arg: ptr[in, bpf_prog_t[flags[bpf_prog_type, int32], bpf_prog_attach_types, bpf_btf_id[opt], fd_bpf_prog[opt]]] {
// bpf_prog_t[flags[bpf_prog_type, int32], bpf_prog_attach_types, bpf_btf_id[opt], fd_bpf_prog[opt]] {
// type: bpf_prog_type = 0x0 (4 bytes)
// ninsn: bytesize8 = 0xc (4 bytes)
// insns: ptr[in, bpf_instructions] {
// union bpf_instructions {
// framed: bpf_framed_program {
// initr0: bpf_insn_init_r0 {
// code: const = 0x18 (1 bytes)
// dst: const = 0x0 (0 bytes)
// src: const = 0x0 (1 bytes)
// off: const = 0x0 (2 bytes)
// imm: int32 = 0x0 (4 bytes)
// code2: const = 0x0 (1 bytes)
// regs2: const = 0x0 (1 bytes)
// off2: const = 0x0 (2 bytes)
// imm2: int32 = 0x0 (4 bytes)
// }
// body: array[bpf_insn] {
// union bpf_insn {
// ringbuf_output: bpf_insn_ringbuf_output {
// insn1: bpf_insn_map_fd_t[const[BPF_REG_1, int8:4], tail_call_map] {
// code: const = 0x18 (1 bytes)
// dst: const = 0x1 (0 bytes)
// src: const = 0x1 (1 bytes)
// off: const = 0x0 (2 bytes)
// imm: tail_call_map (resource)
// code2: const = 0x0 (1 bytes)
// regs2: const = 0x0 (1 bytes)
// off2: const = 0x0 (2 bytes)
// imm2: const = 0x0 (4 bytes)
// }
// insn2: bpf_insn_alu_t[BPF_ALU64, BPF_K0, BPF_MOV0, const[BPF_REG_8, int8:4], const[0, int8:4], const[0, int16], int32] {
// code_class: int8 = 0x7 (0 bytes)
// code_s: int8 = 0x0 (0 bytes)
// code_op: int8 = 0xb (1 bytes)
// dst: const = 0x8 (0 bytes)
// src: const = 0x0 (1 bytes)
// off: const = 0x0 (2 bytes)
// imm: int32 = 0x0 (4 bytes)
// }
// insn3: bpf_insn_ldst_t[BPF_STX, BPF_DW0, BPF_MEM0, const[BPF_REG_10, int8:4], const[BPF_REG_8, int8:4], const[-8, int16], const[0, int32]] {
// code_class: int8 = 0x3 (0 bytes)
// code_size: int8 = 0x3 (0 bytes)
// code_mode: int8 = 0x3 (1 bytes)
// dst: const = 0xa (0 bytes)
// src: const = 0x8 (1 bytes)
// off: const = 0xfff8 (2 bytes)
// imm: const = 0x0 (4 bytes)
// }
// insn4: bpf_insn_alu_t[BPF_ALU64, BPF_X0, BPF_MOV0, const[BPF_REG_2, int8:4], const[BPF_REG_10, int8:4], const[0, int16], const[0, int32]] {
// code_class: int8 = 0x7 (0 bytes)
// code_s: int8 = 0x1 (0 bytes)
// code_op: int8 = 0xb (1 bytes)
// dst: const = 0x2 (0 bytes)
// src: const = 0xa (1 bytes)
// off: const = 0x0 (2 bytes)
// imm: const = 0x0 (4 bytes)
// }
// insn5: bpf_insn_alu_t[BPF_ALU64, BPF_K0, BPF_ADD0, const[BPF_REG_2, int8:4], const[0, int8:4], const[0, int16], const[-8, int32]] {
// code_class: int8 = 0x7 (0 bytes)
// code_s: int8 = 0x0 (0 bytes)
// code_op: int8 = 0x0 (1 bytes)
// dst: const = 0x2 (0 bytes)
// src: const = 0x0 (1 bytes)
// off: const = 0x0 (2 bytes)
// imm: const = 0xfffffff8 (4 bytes)
// }
// insn6: bpf_insn_alu_t[BPF_ALU64, BPF_K0, BPF_MOV0, const[BPF_REG_3, int8:4], const[0, int8:4], const[0, int16], const[8, int32]] {
// code_class: int8 = 0x7 (0 bytes)
// code_s: int8 = 0x0 (0 bytes)
// code_op: int8 = 0xb (1 bytes)
// dst: const = 0x3 (0 bytes)
// src: const = 0x0 (1 bytes)
// off: const = 0x0 (2 bytes)
// imm: const = 0x8 (4 bytes)
// }
// insn7: bpf_insn_alu_t[BPF_ALU64, BPF_K0, BPF_MOV0, const[BPF_REG_4, int8:4], const[0, int8:4], const[0, int16], flags[bpf_ringbuf_wakeup_flags, int32]] {
// code_class: int8 = 0x7 (0 bytes)
// code_s: int8 = 0x0 (0 bytes)
// code_op: int8 = 0xb (1 bytes)
// dst: const = 0x4 (0 bytes)
// src: const = 0x0 (1 bytes)
// off: const = 0x0 (2 bytes)
// imm: bpf_ringbuf_wakeup_flags = 0x0 (4 bytes)
// }
// insn8: bpf_insn_call_helper_t[const[BPF_FUNC_ringbuf_output, int32]] {
// code: const = 0x85 (1 bytes)
// regs: const = 0x0 (1 bytes)
// off: const = 0x0 (2 bytes)
// func: const = 0x3 (4 bytes)
// }
// }
// }
// }
// exit: bpf_insn_exit {
// code: const = 0x95 (1 bytes)
// regs: const = 0x0 (1 bytes)
// off: const = 0x0 (2 bytes)
// imm: const = 0x0 (4 bytes)
// }
// }
// }
// }
// license: nil
// loglev: int32 = 0x0 (4 bytes)
// logsize: len = 0x6 (4 bytes)
// log: nil
// kern_version: bpf_kern_version = 0x0 (4 bytes)
// flags: bpf_prog_load_flags = 0x0 (4 bytes)
// prog_name: buffer: {00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00} (length 0x10)
// prog_ifindex: ifindex (resource)
// expected_attach_type: union bpf_prog_attach_types {
// fallback: bpf_attach_types = 0x0 (4 bytes)
// }
// btf_fd: fd_btf (resource)
// func_info_rec_size: const = 0x0 (4 bytes)
// func_info: nil
// func_info_cnt: len = 0x0 (4 bytes)
// line_info_rec_size: const = 0x0 (4 bytes)
// line_info: nil
// line_info_cnt: len = 0x0 (4 bytes)
// attach_btf_id: bpf_btf_id (resource)
// attach_prog_fd: fd_bpf_prog (resource)
// core_relo_cnt: len = 0x0 (4 bytes)
// fd_array: nil
// core_relos: nil
// core_relo_rec_size: const = 0x0 (4 bytes)
// log_true_size: int32 = 0x0 (4 bytes)
// prog_token_fd: union _bpf_prog_t[flags[bpf_prog_type, int32], bpf_prog_attach_types, bpf_btf_id[opt], fd_bpf_prog[opt]]_prog_token_fd_wrapper {
// void: buffer: {} (length 0x0)
// }
// pad: union _bpf_prog_t[flags[bpf_prog_type, int32], bpf_prog_attach_types, bpf_btf_id[opt], fd_bpf_prog[opt]]_pad_wrapper {
// value: const = 0x0 (4 bytes)
// }
// }
// }
// size: len = 0x90 (8 bytes)
// ]
// returns fd_bpf_prog
*(uint32_t*)0x2000000000c0 = 0;
*(uint32_t*)0x2000000000c4 = 0xc;
*(uint64_t*)0x2000000000c8 = 0x200000000440;
*(uint8_t*)0x200000000440 = 0x18;
STORE_BY_BITMASK(uint8_t, , 0x200000000441, 0, 0, 4);
STORE_BY_BITMASK(uint8_t, , 0x200000000441, 0, 4, 4);
*(uint16_t*)0x200000000442 = 0;
*(uint32_t*)0x200000000444 = 0;
*(uint8_t*)0x200000000448 = 0;
*(uint8_t*)0x200000000449 = 0;
*(uint16_t*)0x20000000044a = 0;
*(uint32_t*)0x20000000044c = 0;
*(uint8_t*)0x200000000450 = 0x18;
STORE_BY_BITMASK(uint8_t, , 0x200000000451, 1, 0, 4);
STORE_BY_BITMASK(uint8_t, , 0x200000000451, 1, 4, 4);
*(uint16_t*)0x200000000452 = 0;
*(uint32_t*)0x200000000454 = r[0];
*(uint8_t*)0x200000000458 = 0;
*(uint8_t*)0x200000000459 = 0;
*(uint16_t*)0x20000000045a = 0;
*(uint32_t*)0x20000000045c = 0;
STORE_BY_BITMASK(uint8_t, , 0x200000000460, 7, 0, 3);
STORE_BY_BITMASK(uint8_t, , 0x200000000460, 0, 3, 1);
STORE_BY_BITMASK(uint8_t, , 0x200000000460, 0xb, 4, 4);
STORE_BY_BITMASK(uint8_t, , 0x200000000461, 8, 0, 4);
STORE_BY_BITMASK(uint8_t, , 0x200000000461, 0, 4, 4);
*(uint16_t*)0x200000000462 = 0;
*(uint32_t*)0x200000000464 = 0;
STORE_BY_BITMASK(uint8_t, , 0x200000000468, 3, 0, 3);
STORE_BY_BITMASK(uint8_t, , 0x200000000468, 3, 3, 2);
STORE_BY_BITMASK(uint8_t, , 0x200000000468, 3, 5, 3);
STORE_BY_BITMASK(uint8_t, , 0x200000000469, 0xa, 0, 4);
STORE_BY_BITMASK(uint8_t, , 0x200000000469, 8, 4, 4);
*(uint16_t*)0x20000000046a = 0xfff8;
*(uint32_t*)0x20000000046c = 0;
STORE_BY_BITMASK(uint8_t, , 0x200000000470, 7, 0, 3);
STORE_BY_BITMASK(uint8_t, , 0x200000000470, 1, 3, 1);
STORE_BY_BITMASK(uint8_t, , 0x200000000470, 0xb, 4, 4);
STORE_BY_BITMASK(uint8_t, , 0x200000000471, 2, 0, 4);
STORE_BY_BITMASK(uint8_t, , 0x200000000471, 0xa, 4, 4);
*(uint16_t*)0x200000000472 = 0;
*(uint32_t*)0x200000000474 = 0;
STORE_BY_BITMASK(uint8_t, , 0x200000000478, 7, 0, 3);
STORE_BY_BITMASK(uint8_t, , 0x200000000478, 0, 3, 1);
STORE_BY_BITMASK(uint8_t, , 0x200000000478, 0, 4, 4);
STORE_BY_BITMASK(uint8_t, , 0x200000000479, 2, 0, 4);
STORE_BY_BITMASK(uint8_t, , 0x200000000479, 0, 4, 4);
*(uint16_t*)0x20000000047a = 0;
*(uint32_t*)0x20000000047c = 0xfffffff8;
STORE_BY_BITMASK(uint8_t, , 0x200000000480, 7, 0, 3);
STORE_BY_BITMASK(uint8_t, , 0x200000000480, 0, 3, 1);
STORE_BY_BITMASK(uint8_t, , 0x200000000480, 0xb, 4, 4);
STORE_BY_BITMASK(uint8_t, , 0x200000000481, 3, 0, 4);
STORE_BY_BITMASK(uint8_t, , 0x200000000481, 0, 4, 4);
*(uint16_t*)0x200000000482 = 0;
*(uint32_t*)0x200000000484 = 8;
STORE_BY_BITMASK(uint8_t, , 0x200000000488, 7, 0, 3);
STORE_BY_BITMASK(uint8_t, , 0x200000000488, 0, 3, 1);
STORE_BY_BITMASK(uint8_t, , 0x200000000488, 0xb, 4, 4);
STORE_BY_BITMASK(uint8_t, , 0x200000000489, 4, 0, 4);
STORE_BY_BITMASK(uint8_t, , 0x200000000489, 0, 4, 4);
*(uint16_t*)0x20000000048a = 0;
*(uint32_t*)0x20000000048c = 0;
*(uint8_t*)0x200000000490 = 0x85;
*(uint8_t*)0x200000000491 = 0;
*(uint16_t*)0x200000000492 = 0;
*(uint32_t*)0x200000000494 = 3;
*(uint8_t*)0x200000000498 = 0x95;
*(uint8_t*)0x200000000499 = 0;
*(uint16_t*)0x20000000049a = 0;
*(uint32_t*)0x20000000049c = 0;
*(uint64_t*)0x2000000000d0 = 0;
*(uint32_t*)0x2000000000d8 = 0;
*(uint32_t*)0x2000000000dc = 6;
*(uint64_t*)0x2000000000e0 = 0;
*(uint32_t*)0x2000000000e8 = 0;
*(uint32_t*)0x2000000000ec = 0;
memset((void*)0x2000000000f0, 0, 16);
*(uint32_t*)0x200000000100 = 0;
*(uint32_t*)0x200000000104 = 0;
*(uint32_t*)0x200000000108 = -1;
*(uint32_t*)0x20000000010c = 0;
*(uint64_t*)0x200000000110 = 0;
*(uint32_t*)0x200000000118 = 0;
*(uint32_t*)0x20000000011c = 0;
*(uint64_t*)0x200000000120 = 0;
*(uint32_t*)0x200000000128 = 0;
*(uint32_t*)0x20000000012c = 0;
*(uint32_t*)0x200000000130 = 0;
*(uint32_t*)0x200000000134 = 0;
*(uint64_t*)0x200000000138 = 0;
*(uint64_t*)0x200000000140 = 0;
*(uint32_t*)0x200000000148 = 0;
*(uint32_t*)0x20000000014c = 0;
*(uint32_t*)0x200000000150 = 0;
syscall(__NR_bpf, /*cmd=*/5ul, /*arg=*/0x2000000000c0ul, /*size=*/0x90ul);
// bpf$MAP_UPDATE_BATCH arguments: [
// cmd: const = 0x1a (8 bytes)
// arg: ptr[in, bpf_map_batch_arg] {
// bpf_map_batch_arg {
// in_batch: nil
// out_batch: nil
// key: ptr[in, buffer] {
// buffer: {} (length 0x0)
// }
// val: ptr[in, buffer] {
// buffer: {} (length 0x0)
// }
// count: int32 = 0xadc (4 bytes)
// map_fd: fd_bpf_map (resource)
// elem_flags: bpf_batch_flags = 0x0 (8 bytes)
// flags: const = 0x0 (8 bytes)
// }
// }
// size: len = 0x38 (8 bytes)
// ]
*(uint64_t*)0x200000000200 = 0;
*(uint64_t*)0x200000000208 = 0;
*(uint64_t*)0x200000000210 = 0x2000000001c0;
*(uint64_t*)0x200000000218 = 0x200000001040;
*(uint32_t*)0x200000000220 = 0xadc;
*(uint32_t*)0x200000000224 = r[0];
*(uint64_t*)0x200000000228 = 0;
*(uint64_t*)0x200000000230 = 0;
syscall(__NR_bpf, /*cmd=*/0x1aul, /*arg=*/0x200000000200ul, /*size=*/0x38ul);
// bpf$PROG_LOAD arguments: [
// cmd: const = 0x5 (8 bytes)
// arg: ptr[in, bpf_prog_t[flags[bpf_prog_type, int32], bpf_prog_attach_types, bpf_btf_id[opt], fd_bpf_prog[opt]]] {
// bpf_prog_t[flags[bpf_prog_type, int32], bpf_prog_attach_types, bpf_btf_id[opt], fd_bpf_prog[opt]] {
// type: bpf_prog_type = 0x11 (4 bytes)
// ninsn: bytesize8 = 0xc (4 bytes)
// insns: ptr[inout, array[ANYUNION]] {
// array[ANYUNION] {
// }
// }
// license: ptr[in, buffer] {
// buffer: {47 50 4c 00} (length 0x4)
// }
// loglev: int32 = 0x0 (4 bytes)
// logsize: len = 0x0 (4 bytes)
// log: nil
// kern_version: bpf_kern_version = 0x0 (4 bytes)
// flags: bpf_prog_load_flags = 0x0 (4 bytes)
// prog_name: buffer: {00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00} (length 0x10)
// prog_ifindex: ifindex (resource)
// expected_attach_type: union bpf_prog_attach_types {
// fallback: bpf_attach_types = 0x0 (4 bytes)
// }
// btf_fd: fd_btf (resource)
// func_info_rec_size: const = 0x0 (4 bytes)
// func_info: nil
// func_info_cnt: len = 0x0 (4 bytes)
// line_info_rec_size: const = 0x0 (4 bytes)
// line_info: nil
// line_info_cnt: len = 0x0 (4 bytes)
// attach_btf_id: bpf_btf_id (resource)
// attach_prog_fd: fd_bpf_prog (resource)
// core_relo_cnt: len = 0x0 (4 bytes)
// fd_array: nil
// core_relos: nil
// core_relo_rec_size: const = 0x0 (4 bytes)
// log_true_size: int32 = 0x0 (4 bytes)
// prog_token_fd: union _bpf_prog_t[flags[bpf_prog_type, int32], bpf_prog_attach_types, bpf_btf_id[opt], fd_bpf_prog[opt]]_prog_token_fd_wrapper {
// void: buffer: {} (length 0x0)
// }
// pad: union _bpf_prog_t[flags[bpf_prog_type, int32], bpf_prog_attach_types, bpf_btf_id[opt], fd_bpf_prog[opt]]_pad_wrapper {
// value: const = 0x0 (4 bytes)
// }
// }
// }
// size: len = 0x94 (8 bytes)
// ]
// returns fd_bpf_prog
*(uint32_t*)0x2000000000c0 = 0x11;
*(uint32_t*)0x2000000000c4 = 0xc;
*(uint64_t*)0x2000000000c8 = 0x200000000440;
*(uint64_t*)0x2000000000d0 = 0x200000000240;
memcpy((void*)0x200000000240, "GPL\000", 4);
*(uint32_t*)0x2000000000d8 = 0;
*(uint32_t*)0x2000000000dc = 0;
*(uint64_t*)0x2000000000e0 = 0;
*(uint32_t*)0x2000000000e8 = 0;
*(uint32_t*)0x2000000000ec = 0;
memset((void*)0x2000000000f0, 0, 16);
*(uint32_t*)0x200000000100 = 0;
*(uint32_t*)0x200000000104 = 0;
*(uint32_t*)0x200000000108 = -1;
*(uint32_t*)0x20000000010c = 0;
*(uint64_t*)0x200000000110 = 0;
*(uint32_t*)0x200000000118 = 0;
*(uint32_t*)0x20000000011c = 0;
*(uint64_t*)0x200000000120 = 0;
*(uint32_t*)0x200000000128 = 0;
*(uint32_t*)0x20000000012c = 0;
*(uint32_t*)0x200000000130 = 0;
*(uint32_t*)0x200000000134 = 0;
*(uint64_t*)0x200000000138 = 0;
*(uint64_t*)0x200000000140 = 0;
*(uint32_t*)0x200000000148 = 0;
*(uint32_t*)0x20000000014c = 0;
*(uint32_t*)0x200000000150 = 0;
res = syscall(__NR_bpf, /*cmd=*/5ul, /*arg=*/0x2000000000c0ul, /*size=*/0x94ul);
if (res != -1)
r[1] = res;
// bpf$BPF_RAW_TRACEPOINT_OPEN arguments: [
// cmd: const = 0x11 (8 bytes)
// arg: ptr[in, bpf_raw_tracepoint] {
// bpf_raw_tracepoint {
// name: ptr[in, buffer] {
// buffer: {63 6f 6e 74 65 6e 74 69 6f 6e 5f 65 6e 64 00} (length 0xf)
// }
// prog_fd: fd_bpf_prog_raw_tracepoint (resource)
// pad: const = 0x0 (4 bytes)
// cookie: int64 = 0x0 (8 bytes)
// }
// }
// size: len = 0x10 (8 bytes)
// ]
// returns fd_perf_base
*(uint64_t*)0x200000000180 = 0x200000000080;
memcpy((void*)0x200000000080, "contention_end\000", 15);
*(uint32_t*)0x200000000188 = r[1];
*(uint32_t*)0x20000000018c = 0;
*(uint64_t*)0x200000000190 = 0;
syscall(__NR_bpf, /*cmd=*/0x11ul, /*arg=*/0x200000000180ul, /*size=*/0x10ul);
return 0;
}
]
|
| 2/1 |
2026/05/20 07:14 |
action |
kernel-checkouter |
1m
Results: map[KernelSrc:/app/workdir/cache/src/2817224999bca682d784a45c41744f549291d336]
|
| 3/1 |
2026/05/20 07:16 |
action |
kernel-builder |
35m
Results: map[KernelObj:/app/workdir/cache/build/c1b7a26f509e3791349b0db2f0d09b54dedfc485]
|
| 4/1 |
2026/05/20 07:51 |
action |
codesearch-prepare |
23m
Results: map[Index:codesearch-index]
|
| 5/1 |
2026/05/20 08:15 |
agent |
expert |
7m
Model:
Results: map[DenialOfService:true Exploitable:false FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:false UserNamespace:false VMGuestTrigger:false VMHostTrigger:false]
Instruction:
You are an experienced Linux kernel security engineer. Your task is to analyze given kernel bug report
and determine its security impact based on the following dimensions.
Use the provided tools to examine the source code, check for capability checks (e.g., capable(), ns_capable()),
and understand the nature of the bug. Analyze the given kernel build and configuration.
You can check the kernel config by grepping ".config" file; you can check kernel cmdline by greeping
".config" file for "CONFIG_CMDLINE=". Assume sysctl parameters have default values.
But analyze for the corresponding production build w/o debugging tools enabled (like KASAN, KMSAN, UBSAN).
Don't make assumptions; verify them with source code access. Try different strategies when analyzing the bug:
- think of ways in which the vulnerable code is unreachable
- or the other way around: try to come up with different ideas of how an unprivileged user can reach the bug
If still unsure err on the side of the bug being non-exploitable/not-accessible.
In the final reply, provide a reasoning for your assessment.
Analysis dimensions:
* Exploitable:
Determine if the bug can result in memory corruption or elevated privileges.
Memory safety issues are almost always exploitable (KASAN or UBSAN reports for use-after-free, out-of-bounds;
refcounting issues, corrupted lists, etc). When kernel is crashing on a completly wild pointer access
(e.g. user-space address, or non-canonical address, but not on NULL or address corresponding to KASAN shadow
for NULL address), including both data accesses and control tranfers, that's also usually implies possibility
of exploitation. Such reports usually say "unable to handle kernel paging request".
Uses of uninitialized values detected by KMSAN may be exploitable b/c attacker frequently can affect uninit
values with spraying techniques. However, for these exploitabability depends on how exactly the uninit value
is used in the code, and what it affects.
Think of what happens after the bug is triggered. Some bugs cause kernel panic and halt execution,
they are harder to exploit. For example, BUG reports halts the kernel. However, WARNING reports don't halt
execution in production builds. Debug bug detection tools (like KASAN, KMSAN, KCSAN, UBSAN) are also not enabled
in production builds, so attacker can freely exploit these bugs w/o being detected by these tools.
If you see an integer overflow, think how the overflowed value used later (if it's used as allocation size,
or an array index). If you see an out-of-bounds read, think if it's followed by an out-of-bounds write as well.
Some KCSAN data-races may be exploitable by skilled attackers as well. Think what data structures got corrupted
as the result of data races and how. However, note that kernel has lots of "benign" data races that don't lead
to any runtime misbehavior at all.
* Denial Of Service:
Determine if the bug can result in denial-of-service. Most bugs can, since they cause system crash,
hangs, deadlocks, or resource leaks. This is mostly applicable to WARNING bugs that won't cause system crash
in production. For these think what will be consequences of the violation of the kernel assumptions flagged
by the WARNING. In some cases the unexpected condition is also properly handled by the normal control flow
(e.g. with "if (WARN_ON(...))"), these won't cause denial-of-service. If the condition is not handled,
then it may or may not cause denial-of-service.
* Accessible From Unprivileged Processes:
Determine if the bug can be reached from a typical (non-root) user process that does NOT have any special capabilities
(like CAP_SYS_ADMIN, CAP_NET_ADMIN, CAP_NET_RAW, CAP_PERFMON) or access to device nodes restricted to root.
Assume that unprivileged_bpf_disabled=1, that is eBPF loading is not accessible. However, cBPF (classical BPF)
is still accessible to non-root processes.
Assume that user namespaces are not accessible, that is, the process cannot get the mentioned capabilities even
within a new user namespace (checked by ns_capable() function in the kernel sources).
* Accessible From User Namespaces:
Determine if the bug can be reached within a user-namespace where the process has all capabilities
(including CAP_SYS_ADMIN, CAP_NET_ADMIN, CAP_NET_RAW, CAP_PERFMON). Such capabilities are checked with ns_capable()
function in the kernel sources.
* VM Guest Trigger:
Determine if the bug can be triggered from the context of a typical KVM guest (e.g., set up by a QEMU VMM).
Consider accesses to standard Linux host paravirtualized features (virtio-blk, virtio-net, etc.),
and handling of VM exits in the KVM code.
* VM Host Trigger in The Confidetial Computing Context:
Determine if the bug can be triggered in a confidential computing guest kernel from the context of a KVM host.
Consider access to standard Linux guest paravirtualized features (virtio-blk, virtio-net, etc.).
* Ethernet Network Trigger:
Determine if the bug can be triggered by processing ingress network Ethernet traffic, either directly (network stack)
or via drivers exposed to network data.
* Other Remote Trigger:
Determine if the bug can be triggered by processing remote traffic other than Ethernet (Wifi, Bluetooth, NFC, etc).
* Peripheral Trigger:
Determine if the bug can be triggered via an untrusted peripheral device that can be physically plugged
into a system, such as a USB device or a niche hardware driver handling external hardware inputs.
This is particularly important for mobile and desktop environments where users can plug in unknown devices.
* Malicious Filesystem Trigger:
Determine if the bug can be triggered by the kernel mounting and parsing a malicious filesystem image.
This is highly critical for Desktop and Mobile environments where external media or downloaded images
might be auto-mounted.
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt:
The kernel bug report is:
============================================
WARNING: possible recursive locking detected
syzkaller #0 Not tainted
--------------------------------------------
syz-executor149/10558 is trying to acquire lock:
ffffe8ffffc41588 (&loc_l->lock){....}-{2:2}, at: bpf_common_lru_push_free kernel/bpf/bpf_lru_list.c:514 [inline]
ffffe8ffffc41588 (&loc_l->lock){....}-{2:2}, at: bpf_lru_push_free+0x33b/0xbb0 kernel/bpf/bpf_lru_list.c:553
but task is already holding lock:
ffffe8ffffc41588 (&loc_l->lock){....}-{2:2}, at: bpf_common_lru_pop_free kernel/bpf/bpf_lru_list.c:440 [inline]
ffffe8ffffc41588 (&loc_l->lock){....}-{2:2}, at: bpf_lru_pop_free+0x1ab/0x19b0 kernel/bpf/bpf_lru_list.c:496
other info that might help us debug this:
Possible unsafe locking scenario:
CPU0
----
lock(&loc_l->lock);
lock(&loc_l->lock);
*** DEADLOCK ***
May be due to missing lock nesting notation
3 locks held by syz-executor149/10558:
#0: ffffffff8df3d620 (rcu_read_lock){....}-{1:3}, at: rcu_lock_acquire include/linux/rcupdate.h:331 [inline]
#0: ffffffff8df3d620 (rcu_read_lock){....}-{1:3}, at: rcu_read_lock include/linux/rcupdate.h:867 [inline]
#0: ffffffff8df3d620 (rcu_read_lock){....}-{1:3}, at: bpf_percpu_hash_update+0x2b/0x200 kernel/bpf/hashtab.c:2409
#1: ffffe8ffffc41588 (&loc_l->lock){....}-{2:2}, at: bpf_common_lru_pop_free kernel/bpf/bpf_lru_list.c:440 [inline]
#1: ffffe8ffffc41588 (&loc_l->lock){....}-{2:2}, at: bpf_lru_pop_free+0x1ab/0x19b0 kernel/bpf/bpf_lru_list.c:496
#2: ffffffff8df3d620 (rcu_read_lock){....}-{1:3}, at: rcu_lock_acquire include/linux/rcupdate.h:331 [inline]
#2: ffffffff8df3d620 (rcu_read_lock){....}-{1:3}, at: rcu_read_lock include/linux/rcupdate.h:867 [inline]
#2: ffffffff8df3d620 (rcu_read_lock){....}-{1:3}, at: __bpf_trace_run kernel/trace/bpf_trace.c:2074 [inline]
#2: ffffffff8df3d620 (rcu_read_lock){....}-{1:3}, at: bpf_trace_run2+0x186/0x4b0 kernel/trace/bpf_trace.c:2116
stack backtrace:
It is reproducible with the followint program.
Keep in mind that it may lack the precise threading, sandboxing, and some arguments of a working reproducer.
But it should give an idea of the involved syscalls.
// autogenerated by syzkaller (https://github.com/google/syzkaller)
#define _GNU_SOURCE
#include <endian.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mount.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <unistd.h>
#ifndef __NR_bpf
#define __NR_bpf 321
#endif
#define BITMASK(bf_off,bf_len) (((1ull << (bf_len)) - 1) << (bf_off))
#define STORE_BY_BITMASK(type,htobe,addr,val,bf_off,bf_len) *(type*)(addr) = htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len))))
uint64_t r[2] = {0xffffffffffffffff, 0xffffffffffffffff};
int main(void)
{
syscall(__NR_mmap, /*addr=*/0x1ffffffff000ul, /*len=*/0x1000ul, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul);
syscall(__NR_mmap, /*addr=*/0x200000000000ul, /*len=*/0x1000000ul, /*prot=PROT_WRITE|PROT_READ|PROT_EXEC*/7ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul);
syscall(__NR_mmap, /*addr=*/0x200001000000ul, /*len=*/0x1000ul, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul);
const char* reason;
(void)reason;
intptr_t res = 0;
if (write(1, "executing program\n", sizeof("executing program\n") - 1)) {}
// bpf$MAP_CREATE arguments: [
// cmd: const = 0x0 (8 bytes)
// arg: ptr[inout, array[ANYUNION]] {
// array[ANYUNION] {
// union ANYUNION {
// ANYBLOB: buffer: {0a 00 00 00 01 00 00 00 0c 00 00 00 09} (length 0xd)
// }
// }
// }
// size: len = 0x50 (8 bytes)
// ]
// returns fd_bpf_map
memcpy((void*)0x2000000009c0, "\x0a\x00\x00\x00\x01\x00\x00\x00\x0c\x00\x00\x00\x09", 13);
res = syscall(__NR_bpf, /*cmd=*/0ul, /*arg=*/0x2000000009c0ul, /*size=*/0x50ul);
if (res != -1)
r[0] = res;
// bpf$PROG_LOAD arguments: [
// cmd: const = 0x5 (8 bytes)
// arg: ptr[in, bpf_prog_t[flags[bpf_prog_type, int32], bpf_prog_attach_types, bpf_btf_id[opt], fd_bpf_prog[opt]]] {
// bpf_prog_t[flags[bpf_prog_type, int32], bpf_prog_attach_types, bpf_btf_id[opt], fd_bpf_prog[opt]] {
// type: bpf_prog_type = 0x0 (4 bytes)
// ninsn: bytesize8 = 0xc (4 bytes)
// insns: ptr[in, bpf_instructions] {
// union bpf_instructions {
// framed: bpf_framed_program {
// initr0: bpf_insn_init_r0 {
// code: const = 0x18 (1 bytes)
// dst: const = 0x0 (0 bytes)
// src: const = 0x0 (1 bytes)
// off: const = 0x0 (2 bytes)
// imm: int32 = 0x0 (4 bytes)
// code2: const = 0x0 (1 bytes)
// regs2: const = 0x0 (1 bytes)
// off2: const = 0x0 (2 bytes)
// imm2: int32 = 0x0 (4 bytes)
// }
// body: array[bpf_insn] {
// union bpf_insn {
// ringbuf_output: bpf_insn_ringbuf_output {
// insn1: bpf_insn_map_fd_t[const[BPF_REG_1, int8:4], tail_call_map] {
// code: const = 0x18 (1 bytes)
// dst: const = 0x1 (0 bytes)
// src: const = 0x1 (1 bytes)
// off: const = 0x0 (2 bytes)
// imm: tail_call_map (resource)
// code2: const = 0x0 (1 bytes)
// regs2: const = 0x0 (1 bytes)
// off2: const = 0x0 (2 bytes)
// imm2: const = 0x0 (4 bytes)
// }
// insn2: bpf_insn_alu_t[BPF_ALU64, BPF_K0, BPF_MOV0, const[BPF_REG_8, int8:4], const[0, int8:4], const[0, int16], int32] {
// code_class: int8 = 0x7 (0 bytes)
// code_s: int8 = 0x0 (0 bytes)
// code_op: int8 = 0xb (1 bytes)
// dst: const = 0x8 (0 bytes)
// src: const = 0x0 (1 bytes)
// off: const = 0x0 (2 bytes)
// imm: int32 = 0x0 (4 bytes)
// }
// insn3: bpf_insn_ldst_t[BPF_STX, BPF_DW0, BPF_MEM0, const[BPF_REG_10, int8:4], const[BPF_REG_8, int8:4], const[-8, int16], const[0, int32]] {
// code_class: int8 = 0x3 (0 bytes)
// code_size: int8 = 0x3 (0 bytes)
// code_mode: int8 = 0x3 (1 bytes)
// dst: const = 0xa (0 bytes)
// src: const = 0x8 (1 bytes)
// off: const = 0xfff8 (2 bytes)
// imm: const = 0x0 (4 bytes)
// }
// insn4: bpf_insn_alu_t[BPF_ALU64, BPF_X0, BPF_MOV0, const[BPF_REG_2, int8:4], const[BPF_REG_10, int8:4], const[0, int16], const[0, int32]] {
// code_class: int8 = 0x7 (0 bytes)
// code_s: int8 = 0x1 (0 bytes)
// code_op: int8 = 0xb (1 bytes)
// dst: const = 0x2 (0 bytes)
// src: const = 0xa (1 bytes)
// off: const = 0x0 (2 bytes)
// imm: const = 0x0 (4 bytes)
// }
// insn5: bpf_insn_alu_t[BPF_ALU64, BPF_K0, BPF_ADD0, const[BPF_REG_2, int8:4], const[0, int8:4], const[0, int16], const[-8, int32]] {
// code_class: int8 = 0x7 (0 bytes)
// code_s: int8 = 0x0 (0 bytes)
// code_op: int8 = 0x0 (1 bytes)
// dst: const = 0x2 (0 bytes)
// src: const = 0x0 (1 bytes)
// off: const = 0x0 (2 bytes)
// imm: const = 0xfffffff8 (4 bytes)
// }
// insn6: bpf_insn_alu_t[BPF_ALU64, BPF_K0, BPF_MOV0, const[BPF_REG_3, int8:4], const[0, int8:4], const[0, int16], const[8, int32]] {
// code_class: int8 = 0x7 (0 bytes)
// code_s: int8 = 0x0 (0 bytes)
// code_op: int8 = 0xb (1 bytes)
// dst: const = 0x3 (0 bytes)
// src: const = 0x0 (1 bytes)
// off: const = 0x0 (2 bytes)
// imm: const = 0x8 (4 bytes)
// }
// insn7: bpf_insn_alu_t[BPF_ALU64, BPF_K0, BPF_MOV0, const[BPF_REG_4, int8:4], const[0, int8:4], const[0, int16], flags[bpf_ringbuf_wakeup_flags, int32]] {
// code_class: int8 = 0x7 (0 bytes)
// code_s: int8 = 0x0 (0 bytes)
// code_op: int8 = 0xb (1 bytes)
// dst: const = 0x4 (0 bytes)
// src: const = 0x0 (1 bytes)
// off: const = 0x0 (2 bytes)
// imm: bpf_ringbuf_wakeup_flags = 0x0 (4 bytes)
// }
// insn8: bpf_insn_call_helper_t[const[BPF_FUNC_ringbuf_output, int32]] {
// code: const = 0x85 (1 bytes)
// regs: const = 0x0 (1 bytes)
// off: const = 0x0 (2 bytes)
// func: const = 0x3 (4 bytes)
// }
// }
// }
// }
// exit: bpf_insn_exit {
// code: const = 0x95 (1 bytes)
// regs: const = 0x0 (1 bytes)
// off: const = 0x0 (2 bytes)
// imm: const = 0x0 (4 bytes)
// }
// }
// }
// }
// license: nil
// loglev: int32 = 0x0 (4 bytes)
// logsize: len = 0x6 (4 bytes)
// log: nil
// kern_version: bpf_kern_version = 0x0 (4 bytes)
// flags: bpf_prog_load_flags = 0x0 (4 bytes)
// prog_name: buffer: {00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00} (length 0x10)
// prog_ifindex: ifindex (resource)
// expected_attach_type: union bpf_prog_attach_types {
// fallback: bpf_attach_types = 0x0 (4 bytes)
// }
// btf_fd: fd_btf (resource)
// func_info_rec_size: const = 0x0 (4 bytes)
// func_info: nil
// func_info_cnt: len = 0x0 (4 bytes)
// line_info_rec_size: const = 0x0 (4 bytes)
// line_info: nil
// line_info_cnt: len = 0x0 (4 bytes)
// attach_btf_id: bpf_btf_id (resource)
// attach_prog_fd: fd_bpf_prog (resource)
// core_relo_cnt: len = 0x0 (4 bytes)
// fd_array: nil
// core_relos: nil
// core_relo_rec_size: const = 0x0 (4 bytes)
// log_true_size: int32 = 0x0 (4 bytes)
// prog_token_fd: union _bpf_prog_t[flags[bpf_prog_type, int32], bpf_prog_attach_types, bpf_btf_id[opt], fd_bpf_prog[opt]]_prog_token_fd_wrapper {
// void: buffer: {} (length 0x0)
// }
// pad: union _bpf_prog_t[flags[bpf_prog_type, int32], bpf_prog_attach_types, bpf_btf_id[opt], fd_bpf_prog[opt]]_pad_wrapper {
// value: const = 0x0 (4 bytes)
// }
// }
// }
// size: len = 0x90 (8 bytes)
// ]
// returns fd_bpf_prog
*(uint32_t*)0x2000000000c0 = 0;
*(uint32_t*)0x2000000000c4 = 0xc;
*(uint64_t*)0x2000000000c8 = 0x200000000440;
*(uint8_t*)0x200000000440 = 0x18;
STORE_BY_BITMASK(uint8_t, , 0x200000000441, 0, 0, 4);
STORE_BY_BITMASK(uint8_t, , 0x200000000441, 0, 4, 4);
*(uint16_t*)0x200000000442 = 0;
*(uint32_t*)0x200000000444 = 0;
*(uint8_t*)0x200000000448 = 0;
*(uint8_t*)0x200000000449 = 0;
*(uint16_t*)0x20000000044a = 0;
*(uint32_t*)0x20000000044c = 0;
*(uint8_t*)0x200000000450 = 0x18;
STORE_BY_BITMASK(uint8_t, , 0x200000000451, 1, 0, 4);
STORE_BY_BITMASK(uint8_t, , 0x200000000451, 1, 4, 4);
*(uint16_t*)0x200000000452 = 0;
*(uint32_t*)0x200000000454 = r[0];
*(uint8_t*)0x200000000458 = 0;
*(uint8_t*)0x200000000459 = 0;
*(uint16_t*)0x20000000045a = 0;
*(uint32_t*)0x20000000045c = 0;
STORE_BY_BITMASK(uint8_t, , 0x200000000460, 7, 0, 3);
STORE_BY_BITMASK(uint8_t, , 0x200000000460, 0, 3, 1);
STORE_BY_BITMASK(uint8_t, , 0x200000000460, 0xb, 4, 4);
STORE_BY_BITMASK(uint8_t, , 0x200000000461, 8, 0, 4);
STORE_BY_BITMASK(uint8_t, , 0x200000000461, 0, 4, 4);
*(uint16_t*)0x200000000462 = 0;
*(uint32_t*)0x200000000464 = 0;
STORE_BY_BITMASK(uint8_t, , 0x200000000468, 3, 0, 3);
STORE_BY_BITMASK(uint8_t, , 0x200000000468, 3, 3, 2);
STORE_BY_BITMASK(uint8_t, , 0x200000000468, 3, 5, 3);
STORE_BY_BITMASK(uint8_t, , 0x200000000469, 0xa, 0, 4);
STORE_BY_BITMASK(uint8_t, , 0x200000000469, 8, 4, 4);
*(uint16_t*)0x20000000046a = 0xfff8;
*(uint32_t*)0x20000000046c = 0;
STORE_BY_BITMASK(uint8_t, , 0x200000000470, 7, 0, 3);
STORE_BY_BITMASK(uint8_t, , 0x200000000470, 1, 3, 1);
STORE_BY_BITMASK(uint8_t, , 0x200000000470, 0xb, 4, 4);
STORE_BY_BITMASK(uint8_t, , 0x200000000471, 2, 0, 4);
STORE_BY_BITMASK(uint8_t, , 0x200000000471, 0xa, 4, 4);
*(uint16_t*)0x200000000472 = 0;
*(uint32_t*)0x200000000474 = 0;
STORE_BY_BITMASK(uint8_t, , 0x200000000478, 7, 0, 3);
STORE_BY_BITMASK(uint8_t, , 0x200000000478, 0, 3, 1);
STORE_BY_BITMASK(uint8_t, , 0x200000000478, 0, 4, 4);
STORE_BY_BITMASK(uint8_t, , 0x200000000479, 2, 0, 4);
STORE_BY_BITMASK(uint8_t, , 0x200000000479, 0, 4, 4);
*(uint16_t*)0x20000000047a = 0;
*(uint32_t*)0x20000000047c = 0xfffffff8;
STORE_BY_BITMASK(uint8_t, , 0x200000000480, 7, 0, 3);
STORE_BY_BITMASK(uint8_t, , 0x200000000480, 0, 3, 1);
STORE_BY_BITMASK(uint8_t, , 0x200000000480, 0xb, 4, 4);
STORE_BY_BITMASK(uint8_t, , 0x200000000481, 3, 0, 4);
STORE_BY_BITMASK(uint8_t, , 0x200000000481, 0, 4, 4);
*(uint16_t*)0x200000000482 = 0;
*(uint32_t*)0x200000000484 = 8;
STORE_BY_BITMASK(uint8_t, , 0x200000000488, 7, 0, 3);
STORE_BY_BITMASK(uint8_t, , 0x200000000488, 0, 3, 1);
STORE_BY_BITMASK(uint8_t, , 0x200000000488, 0xb, 4, 4);
STORE_BY_BITMASK(uint8_t, , 0x200000000489, 4, 0, 4);
STORE_BY_BITMASK(uint8_t, , 0x200000000489, 0, 4, 4);
*(uint16_t*)0x20000000048a = 0;
*(uint32_t*)0x20000000048c = 0;
*(uint8_t*)0x200000000490 = 0x85;
*(uint8_t*)0x200000000491 = 0;
*(uint16_t*)0x200000000492 = 0;
*(uint32_t*)0x200000000494 = 3;
*(uint8_t*)0x200000000498 = 0x95;
*(uint8_t*)0x200000000499 = 0;
*(uint16_t*)0x20000000049a = 0;
*(uint32_t*)0x20000000049c = 0;
*(uint64_t*)0x2000000000d0 = 0;
*(uint32_t*)0x2000000000d8 = 0;
*(uint32_t*)0x2000000000dc = 6;
*(uint64_t*)0x2000000000e0 = 0;
*(uint32_t*)0x2000000000e8 = 0;
*(uint32_t*)0x2000000000ec = 0;
memset((void*)0x2000000000f0, 0, 16);
*(uint32_t*)0x200000000100 = 0;
*(uint32_t*)0x200000000104 = 0;
*(uint32_t*)0x200000000108 = -1;
*(uint32_t*)0x20000000010c = 0;
*(uint64_t*)0x200000000110 = 0;
*(uint32_t*)0x200000000118 = 0;
*(uint32_t*)0x20000000011c = 0;
*(uint64_t*)0x200000000120 = 0;
*(uint32_t*)0x200000000128 = 0;
*(uint32_t*)0x20000000012c = 0;
*(uint32_t*)0x200000000130 = 0;
*(uint32_t*)0x200000000134 = 0;
*(uint64_t*)0x200000000138 = 0;
*(uint64_t*)0x200000000140 = 0;
*(uint32_t*)0x200000000148 = 0;
*(uint32_t*)0x20000000014c = 0;
*(uint32_t*)0x200000000150 = 0;
syscall(__NR_bpf, /*cmd=*/5ul, /*arg=*/0x2000000000c0ul, /*size=*/0x90ul);
// bpf$MAP_UPDATE_BATCH arguments: [
// cmd: const = 0x1a (8 bytes)
// arg: ptr[in, bpf_map_batch_arg] {
// bpf_map_batch_arg {
// in_batch: nil
// out_batch: nil
// key: ptr[in, buffer] {
// buffer: {} (length 0x0)
// }
// val: ptr[in, buffer] {
// buffer: {} (length 0x0)
// }
// count: int32 = 0xadc (4 bytes)
// map_fd: fd_bpf_map (resource)
// elem_flags: bpf_batch_flags = 0x0 (8 bytes)
// flags: const = 0x0 (8 bytes)
// }
// }
// size: len = 0x38 (8 bytes)
// ]
*(uint64_t*)0x200000000200 = 0;
*(uint64_t*)0x200000000208 = 0;
*(uint64_t*)0x200000000210 = 0x2000000001c0;
*(uint64_t*)0x200000000218 = 0x200000001040;
*(uint32_t*)0x200000000220 = 0xadc;
*(uint32_t*)0x200000000224 = r[0];
*(uint64_t*)0x200000000228 = 0;
*(uint64_t*)0x200000000230 = 0;
syscall(__NR_bpf, /*cmd=*/0x1aul, /*arg=*/0x200000000200ul, /*size=*/0x38ul);
// bpf$PROG_LOAD arguments: [
// cmd: const = 0x5 (8 bytes)
// arg: ptr[in, bpf_prog_t[flags[bpf_prog_type, int32], bpf_prog_attach_types, bpf_btf_id[opt], fd_bpf_prog[opt]]] {
// bpf_prog_t[flags[bpf_prog_type, int32], bpf_prog_attach_types, bpf_btf_id[opt], fd_bpf_prog[opt]] {
// type: bpf_prog_type = 0x11 (4 bytes)
// ninsn: bytesize8 = 0xc (4 bytes)
// insns: ptr[inout, array[ANYUNION]] {
// array[ANYUNION] {
// }
// }
// license: ptr[in, buffer] {
// buffer: {47 50 4c 00} (length 0x4)
// }
// loglev: int32 = 0x0 (4 bytes)
// logsize: len = 0x0 (4 bytes)
// log: nil
// kern_version: bpf_kern_version = 0x0 (4 bytes)
// flags: bpf_prog_load_flags = 0x0 (4 bytes)
// prog_name: buffer: {00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00} (length 0x10)
// prog_ifindex: ifindex (resource)
// expected_attach_type: union bpf_prog_attach_types {
// fallback: bpf_attach_types = 0x0 (4 bytes)
// }
// btf_fd: fd_btf (resource)
// func_info_rec_size: const = 0x0 (4 bytes)
// func_info: nil
// func_info_cnt: len = 0x0 (4 bytes)
// line_info_rec_size: const = 0x0 (4 bytes)
// line_info: nil
// line_info_cnt: len = 0x0 (4 bytes)
// attach_btf_id: bpf_btf_id (resource)
// attach_prog_fd: fd_bpf_prog (resource)
// core_relo_cnt: len = 0x0 (4 bytes)
// fd_array: nil
// core_relos: nil
// core_relo_rec_size: const = 0x0 (4 bytes)
// log_true_size: int32 = 0x0 (4 bytes)
// prog_token_fd: union _bpf_prog_t[flags[bpf_prog_type, int32], bpf_prog_attach_types, bpf_btf_id[opt], fd_bpf_prog[opt]]_prog_token_fd_wrapper {
// void: buffer: {} (length 0x0)
// }
// pad: union _bpf_prog_t[flags[bpf_prog_type, int32], bpf_prog_attach_types, bpf_btf_id[opt], fd_bpf_prog[opt]]_pad_wrapper {
// value: const = 0x0 (4 bytes)
// }
// }
// }
// size: len = 0x94 (8 bytes)
// ]
// returns fd_bpf_prog
*(uint32_t*)0x2000000000c0 = 0x11;
*(uint32_t*)0x2000000000c4 = 0xc;
*(uint64_t*)0x2000000000c8 = 0x200000000440;
*(uint64_t*)0x2000000000d0 = 0x200000000240;
memcpy((void*)0x200000000240, "GPL\000", 4);
*(uint32_t*)0x2000000000d8 = 0;
*(uint32_t*)0x2000000000dc = 0;
*(uint64_t*)0x2000000000e0 = 0;
*(uint32_t*)0x2000000000e8 = 0;
*(uint32_t*)0x2000000000ec = 0;
memset((void*)0x2000000000f0, 0, 16);
*(uint32_t*)0x200000000100 = 0;
*(uint32_t*)0x200000000104 = 0;
*(uint32_t*)0x200000000108 = -1;
*(uint32_t*)0x20000000010c = 0;
*(uint64_t*)0x200000000110 = 0;
*(uint32_t*)0x200000000118 = 0;
*(uint32_t*)0x20000000011c = 0;
*(uint64_t*)0x200000000120 = 0;
*(uint32_t*)0x200000000128 = 0;
*(uint32_t*)0x20000000012c = 0;
*(uint32_t*)0x200000000130 = 0;
*(uint32_t*)0x200000000134 = 0;
*(uint64_t*)0x200000000138 = 0;
*(uint64_t*)0x200000000140 = 0;
*(uint32_t*)0x200000000148 = 0;
*(uint32_t*)0x20000000014c = 0;
*(uint32_t*)0x200000000150 = 0;
res = syscall(__NR_bpf, /*cmd=*/5ul, /*arg=*/0x2000000000c0ul, /*size=*/0x94ul);
if (res != -1)
r[1] = res;
// bpf$BPF_RAW_TRACEPOINT_OPEN arguments: [
// cmd: const = 0x11 (8 bytes)
// arg: ptr[in, bpf_raw_tracepoint] {
// bpf_raw_tracepoint {
// name: ptr[in, buffer] {
// buffer: {63 6f 6e 74 65 6e 74 69 6f 6e 5f 65 6e 64 00} (length 0xf)
// }
// prog_fd: fd_bpf_prog_raw_tracepoint (resource)
// pad: const = 0x0 (4 bytes)
// cookie: int64 = 0x0 (8 bytes)
// }
// }
// size: len = 0x10 (8 bytes)
// ]
// returns fd_perf_base
*(uint64_t*)0x200000000180 = 0x200000000080;
memcpy((void*)0x200000000080, "contention_end\000", 15);
*(uint32_t*)0x200000000188 = r[1];
*(uint32_t*)0x20000000018c = 0;
*(uint64_t*)0x200000000190 = 0;
syscall(__NR_bpf, /*cmd=*/0x11ul, /*arg=*/0x200000000180ul, /*size=*/0x10ul);
return 0;
}
Reply: Based on the analysis of the bug report and the kernel source code, here is the security assessment of the issue:
### Bug Mechanism
The bug is a recursive spinlock deadlock in the BPF LRU map implementation. The sequence of events leading to the deadlock is as follows:
1. A kernel context (such as the `bpf(MAP_UPDATE_BATCH)` syscall) operates on an LRU map and acquires the per-CPU `loc_l->lock`.
2. While holding `loc_l->lock`, it attempts to acquire the global LRU list lock (`l->lock`).
3. If `l->lock` is contended by another CPU, the current CPU will spin in the slowpath. Once it finally acquires the lock, the kernel's lock statistics subsystem triggers the `contention_end` tracepoint (via `trace_contention_end()`).
4. If a BPF tracing program (e.g., `BPF_PROG_TYPE_RAW_TRACEPOINT`) is attached to the `contention_end` tracepoint, it will execute synchronously in this context.
5. If the BPF program attempts to update or delete an element in the *same* LRU map, it will call into the LRU map helpers (like `bpf_lru_push_free`) which try to acquire the `loc_l->lock` again.
6. Because the lock is already held by the interrupted syscall context, the CPU deadlocks.
### Security Impact
* **Exploitable:** **False**. This is a classic spinlock deadlock. It results in a CPU hang (soft or hard lockup) but does not cause memory corruption, out-of-bounds access, or allow for privilege escalation.
* **Denial Of Service:** **True**. Triggering the bug hangs the CPU, leading to a system-wide denial of service (kernel panic via watchdog).
* **Accessible From Unprivileged Processes / User Namespaces:** **False**. Attaching a BPF program to a raw tracepoint like `contention_end` strictly requires `CAP_PERFMON` or `CAP_SYS_ADMIN` capabilities. Furthermore, with `unprivileged_bpf_disabled=1` (as assumed), unprivileged users cannot create BPF maps or load eBPF programs at all. Even if a privileged user (like an administrator running a tracing tool) sets up the vulnerable BPF program, an unprivileged user cannot trigger the deadlock because they do not have file descriptor access to the privileged tracing tool's BPF map to cause the initial lock contention.
* **Remote / Peripheral / Filesystem / VM Triggers:** **False**. The bug is entirely contained within the BPF subsystem and requires local execution of BPF syscalls to set up the tracepoint and map. It cannot be triggered remotely, via malicious filesystems, or by external hardware.
In summary, this is a local Denial-of-Service bug that can only be triggered by a highly privileged user (root or a user with `CAP_PERFMON`/`CAP_SYS_ADMIN`) who is already capable of loading advanced BPF tracing programs. It does not cross any security boundaries.
|
| 6/2 |
2026/05/20 08:15 |
llm |
expert |
0m
Model:
Tokens:
input: 14540
output: 52
thoughts: 810
Thoughts: **Recursive Locking in BPF LRU Implementation**
Okay, so I've got this syzkaller report flagging a "WARNING: possible recursive locking detected." The stack trace immediately caught my attention. It looks like the syz-executor is trying to acquire the `loc_l->lock` at `bpf_common_lru_push_free` (which calls `bpf_lru_push_free`), but it *already* holds the same lock, specifically at `bpf_common_lru_pop_free` (and therefore `bpf_lru_pop_free`). This screams potential deadlock, which is bad news.
Looking at the backtrace more closely, there's a wrinkle. It appears that the lock is held inside of `bpf_lru_pop_free` via rcu_read_lock, which is itself then reacquired at `__bpf_trace_run` -> `bpf_trace_run2` . The critical thing is the lock re-acquisition within `bpf_lru_push_free`. So, in the same thread, the sequence seems to be: `bpf_lru_pop_free` (holding the lock) -> `bpf_percpu_hash_update` and then calls `bpf_trace_run2` which tries to rcu lock again -> `bpf_lru_push_free` (trying to reacquire the same lock).
This `rcu_read_lock` being held while potentially trying to acquire another lock is the key. My immediate thought is, how is this even possible? We need to dive into the implementations of both `bpf_lru_pop_free` and `bpf_lru_push_free` to understand the flow and where this lock contention is happening. I need to trace the calling paths and understand which lock the `loc_l` variable refers to and, more importantly, *why* this recursion could happen. I'm going to dig into the code and start tracing the logic, looking for the shared data structures and control flow that leads to this. This could be tricky, but I think I have a path forward.
|
| 7/2 |
2026/05/20 08:15 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:kernel/bpf/bpf_lru_list.c IncludeLines:true Name:bpf_lru_pop_free]
Results: map[SourceCode: 491: struct bpf_lru_node *bpf_lru_pop_free(struct bpf_lru *lru, u32 hash)
492: {
493: if (lru->percpu)
494: return bpf_percpu_lru_pop_free(lru, hash);
495: else
496: return bpf_common_lru_pop_free(lru, hash);
497: }
SourceFile:kernel/bpf/bpf_lru_list.c]
|
| 8/2 |
2026/05/20 08:15 |
llm |
expert |
0m
Model:
Tokens:
input: 16036
output: 54
thoughts: 32
Thoughts: Okay, here's my interpretation of those thoughts, tailored for an expert audience, presented in the first person:
**Analyzing BPF LRU Management**
Alright, let's dive into the guts of this LRU management for BPF. My focus right now is definitely on `bpf_common_lru_pop_free` and `bpf_common_lru_push_free`. I need to understand exactly how the freelist is being manipulated here. I'm going to look closely at the atomic operations involved. What locks are being held, if any? Are we dealing with cache-line bounces, or are the memory accesses well-aligned for minimal contention? I'm particularly interested in the consistency guarantees. If we have multiple CPUs accessing these routines concurrently, are there any potential race conditions? I need to verify that we aren't introducing any deadlocks or starvation situations. The freelist's integrity is paramount. I'm thinking about the scenarios where we have many cores all trying to grab from or put into the freelist at the same time. Also, is this using per-cpu LRUs, or a global one? What are the tradeoffs? What's the impact of memory fragmentation on the freelist and its performance?
|
| 9/2 |
2026/05/20 08:15 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:kernel/bpf/bpf_lru_list.c IncludeLines:true Name:bpf_common_lru_pop_free]
Results: map[SourceCode: 428: static struct bpf_lru_node *bpf_common_lru_pop_free(struct bpf_lru *lru,
429: u32 hash)
430: {
431: struct bpf_lru_locallist *loc_l, *steal_loc_l;
432: struct bpf_common_lru *clru = &lru->common_lru;
433: struct bpf_lru_node *node;
434: int steal, first_steal;
435: unsigned long flags;
436: int cpu = raw_smp_processor_id();
437:
438: loc_l = per_cpu_ptr(clru->local_list, cpu);
439:
440: raw_spin_lock_irqsave(&loc_l->lock, flags);
441:
442: node = __local_list_pop_free(loc_l);
443: if (!node) {
444: bpf_lru_list_pop_free_to_local(lru, loc_l);
445: node = __local_list_pop_free(loc_l);
446: }
447:
448: if (node)
449: __local_list_add_pending(lru, loc_l, cpu, node, hash);
450:
451: raw_spin_unlock_irqrestore(&loc_l->lock, flags);
452:
453: if (node)
454: return node;
455:
456: /* No free nodes found from the local free list and
457: * the global LRU list.
458: *
459: * Steal from the local free/pending list of the
460: * current CPU and remote CPU in RR. It starts
461: * with the loc_l->next_steal CPU.
462: */
463:
464: first_steal = loc_l->next_steal;
465: steal = first_steal;
466: do {
467: steal_loc_l = per_cpu_ptr(clru->local_list, steal);
468:
469: raw_spin_lock_irqsave(&steal_loc_l->lock, flags);
470:
471: node = __local_list_pop_free(steal_loc_l);
472: if (!node)
473: node = __local_list_pop_pending(lru, steal_loc_l);
474:
475: raw_spin_unlock_irqrestore(&steal_loc_l->lock, flags);
476:
477: steal = cpumask_next_wrap(steal, cpu_possible_mask);
478: } while (!node && steal != first_steal);
479:
480: loc_l->next_steal = steal;
481:
482: if (node) {
483: raw_spin_lock_irqsave(&loc_l->lock, flags);
484: __local_list_add_pending(lru, loc_l, cpu, node, hash);
485: raw_spin_unlock_irqrestore(&loc_l->lock, flags);
486: }
487:
488: return node;
489: }
SourceFile:kernel/bpf/bpf_lru_list.c]
|
| 10/2 |
2026/05/20 08:15 |
llm |
expert |
0m
Model:
Tokens:
input: 17401
output: 58
thoughts: 447
Thoughts: **Analyzing a Potential BPF LRU Lock Contention**
Okay, let's break this down. My initial concern is that `bpf_common_lru_pop_free` *acquires* `loc_l->lock`. That's the starting point. I need to understand the control flow from there. It's looking like it then potentially calls `bpf_lru_list_pop_free_to_local(lru, loc_l)`. Crucially, my immediate thought is whether *that* function (or its callees) ever calls `bpf_lru_push_free`. It's the key to the problem, and I didn't see it immediately.
The stack trace is giving me more concrete information. It confirms my initial suspicion by showing a deadlock. The task (syz-executor149/10558) *attempts* to acquire the lock (`loc_l->lock`) at `bpf_common_lru_push_free` and then calls `bpf_lru_push_free`, but it *already holds* the same lock. It's held in `bpf_common_lru_pop_free` at line 440, and then is likely called from `bpf_lru_pop_free` at line 496.
This is a pretty clear lock ordering problem, a classic potential deadlock. The function `bpf_common_lru_pop_free` should be releasing the lock after it's done, which it doesn't seem to be. Now I need to focus on what happens within `bpf_common_lru_pop_free` *after* the lock is acquired. I've got to investigate what is being called from there, whether it's `bpf_lru_list_pop_free_to_local`, `__local_list_pop_free` or `__local_list_add_pending`. My hypothesis is that one of these functions or their children *are* attempting to call `bpf_lru_push_free` without releasing the lock, and that's the cause of the double lock acquisition.
|
| 11/2 |
2026/05/20 08:15 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:kernel/bpf/bpf_lru_list.c IncludeLines:true Name:bpf_lru_list_pop_free_to_local]
Results: map[SourceCode: 315: static void bpf_lru_list_pop_free_to_local(struct bpf_lru *lru,
316: struct bpf_lru_locallist *loc_l)
317: {
318: struct bpf_lru_list *l = &lru->common_lru.lru_list;
319: struct bpf_lru_node *node, *tmp_node;
320: unsigned int nfree = 0;
321:
322: raw_spin_lock(&l->lock);
323:
324: __local_list_flush(l, loc_l);
325:
326: __bpf_lru_list_rotate(lru, l);
327:
328: list_for_each_entry_safe(node, tmp_node, &l->lists[BPF_LRU_LIST_T_FREE],
329: list) {
330: __bpf_lru_node_move_to_free(l, node, local_free_list(loc_l),
331: BPF_LRU_LOCAL_LIST_T_FREE);
332: if (++nfree == lru->target_free)
333: break;
334: }
335:
336: if (nfree < lru->target_free)
337: __bpf_lru_list_shrink(lru, l, lru->target_free - nfree,
338: local_free_list(loc_l),
339: BPF_LRU_LOCAL_LIST_T_FREE);
340:
341: raw_spin_unlock(&l->lock);
342: }
SourceFile:kernel/bpf/bpf_lru_list.c]
|
| 12/2 |
2026/05/20 08:15 |
llm |
expert |
0m
Model:
Tokens:
input: 18912
output: 53
thoughts: 16
Thoughts: Okay, let's dive into this. Here's my thought process on what we're looking at, summarized from the prompt:
**Analyzing `__bpf_lru_list_shrink`**
Alright, my first instinct is to check out the function `__bpf_lru_list_shrink`. We know how important LRU lists are for efficient BPF program management, so seeing `shrink` in the name immediately triggers a mental checklist. I want to understand how this function operates on the LRU list. Is it about memory reclamation? Eviction? What criteria does it use to determine which entries need to go? What's the impact of this shrinking process on overall BPF performance and, more specifically, on the use of BPF maps? I'm anticipating this is a vital function for maintaining the BPF system's memory footprint and performance. This is where the core logic of memory management within the BPF system probably exists, especially regarding eviction. Time to dig in!
|
| 13/2 |
2026/05/20 08:16 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:kernel/bpf/bpf_lru_list.c IncludeLines:true Name:__bpf_lru_list_shrink]
Results: map[SourceCode: 242: /* Calls __bpf_lru_list_shrink_inactive() to shrink some
243: * ref-bit-cleared nodes and move them to the designated
244: * free list.
245: *
246: * If it cannot get a free node after calling
247: * __bpf_lru_list_shrink_inactive(). It will just remove
248: * one node from either inactive or active list without
249: * honoring the ref-bit. It prefers inactive list to active
250: * list in this situation.
251: */
252: static unsigned int __bpf_lru_list_shrink(struct bpf_lru *lru,
253: struct bpf_lru_list *l,
254: unsigned int tgt_nshrink,
255: struct list_head *free_list,
256: enum bpf_lru_list_type tgt_free_type)
257:
258: {
259: struct bpf_lru_node *node, *tmp_node;
260: struct list_head *force_shrink_list;
261: unsigned int nshrinked;
262:
263: nshrinked = __bpf_lru_list_shrink_inactive(lru, l, tgt_nshrink,
264: free_list, tgt_free_type);
265: if (nshrinked)
266: return nshrinked;
267:
268: /* Do a force shrink by ignoring the reference bit */
269: if (!list_empty(&l->lists[BPF_LRU_LIST_T_INACTIVE]))
270: force_shrink_list = &l->lists[BPF_LRU_LIST_T_INACTIVE];
271: else
272: force_shrink_list = &l->lists[BPF_LRU_LIST_T_ACTIVE];
273:
274: list_for_each_entry_safe_reverse(node, tmp_node, force_shrink_list,
275: list) {
276: if (lru->del_from_htab(lru->del_arg, node)) {
277: __bpf_lru_node_move_to_free(l, node, free_list,
278: tgt_free_type);
279: return 1;
280: }
281: }
282:
283: return 0;
284: }
SourceFile:kernel/bpf/bpf_lru_list.c]
|
| 14/2 |
2026/05/20 08:16 |
llm |
expert |
0m
Model:
Tokens:
input: 19951
output: 50
thoughts: 55
Thoughts: Here's my analysis of that code snippet:
**Concurrent Hash Table Deletion with Locks - Potential Deadlock?**
Okay, so I'm looking at this code and something immediately jumps out at me: `lru->del_from_htab(lru->del_arg, node)` is being called while *already* holding both `l->lock` and `loc_l->lock`. That's a red flag. Anytime you're dealing with multiple locks, you've got to be extremely careful about the order in which they're acquired, or you risk a classic deadlock scenario.
My first thought is, what exactly does `del_from_htab` *do*? I need to understand its behavior thoroughly to assess the potential concurrency issues. Does it also try to acquire locks? If so, what locks? And in what order? A quick look at its implementation is essential. We need to trace all the lock acquisitions within that function to determine if a lock ordering conflict exists. The current call stack might be:
1. `[Caller] acquires l->lock`
2. `[Caller] acquires loc_l->lock`
3. `[Caller] calls lru->del_from_htab(...)`
4. `[del_from_htab] acquires ...`
If `del_from_htab` tries to acquire `loc_l->lock` *before* `l->lock` (or attempts to acquire either lock, if it's held elsewhere), we've got a problem. This order might cause a cycle if another thread is holding the opposite. The potential for a deadlock situation demands a deep dive into the code.
|
| 15/2 |
2026/05/20 08:16 |
tool |
codesearch-find-references |
0m
Error:
Args: map[ContextFile:kernel/bpf/bpf_lru_list.c IncludeSnippetLines:0 Name:del_from_htab]
Results: map[References:<nil> TruncatedOutput:false]
|
| 16/2 |
2026/05/20 08:16 |
llm |
expert |
0m
Model:
Tokens:
input: 20438
output: 56
thoughts: 16
Thoughts: Okay, here's my interpretation of that thought process, tailored for an expert audience, and written in the first person:
**Decoding That `struct bpf_lru` Field**
Right, so I'm looking at something – a field within `struct bpf_lru`, specifically. My initial thought process is to immediately categorize and contextualize: "Okay, this is within a BPF LRU structure." That tells me quite a bit right off the bat. It implies we're dealing with a Least Recently Used cache implementation, likely in the context of BPF (Berkeley Packet Filter), meaning we're probably looking at a highly optimized data structure designed to manage resources efficiently within a kernel module or some other performance-critical application.
My mind then races through the implications: potential use cases immediately pop up. Caching BPF program descriptors? Tracking frequently accessed data within a BPF map? Managing memory allocations within the BPF VM? This struct is likely critical for managing access patterns efficiently.
I'm instantly considering things like cache eviction strategies, how contention is handled (if multiple BPF programs might interact with this LRU), and what underlying data structures are used for the actual LRU implementation. Is it a linked list, a hash table, or some hybrid approach? The specific field itself probably gives me a critical hint regarding the design goals – it's the specific field that tells us what is being cached using the LRU, so it is necessary to consider the type of the field to understand how its size, use and lifetime are managed. I'm keen to get the full struct definition to evaluate these points, because a lot is hanging off that one field. I'm already anticipating some interesting implementation details and probably some non-trivial performance optimizations.
|
| 17/2 |
2026/05/20 08:16 |
tool |
codesearch-find-references |
0m
Args: map[ContextFile:kernel/bpf/bpf_lru_list.c IncludeSnippetLines:0 Name:bpf_lru::del_from_htab]
Results: map[References:[map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:__bpf_lru_list_shrink SourceFile:kernel/bpf/bpf_lru_list.c SourceLine:276] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:__bpf_lru_list_shrink_inactive SourceFile:kernel/bpf/bpf_lru_list.c SourceLine:217] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:__local_list_pop_pending SourceFile:kernel/bpf/bpf_lru_list.c SourceLine:382] map[ReferenceKind:writes ReferencingEntityKind:function ReferencingEntityName:bpf_lru_init SourceFile:kernel/bpf/bpf_lru_list.c SourceLine:682]] TruncatedOutput:false]
|
| 18/2 |
2026/05/20 08:16 |
llm |
expert |
0m
Model:
Tokens:
input: 21136
output: 50
thoughts: 13
Thoughts: Okay, let's dive into this `bpf_lru_init` function. I need to understand how this crucial bit of code initializes the Least Recently Used (LRU) cache for BPF programs. I'm thinking about the implications for performance and how it interacts with the rest of the BPF infrastructure. I'm going to want to focus on the data structures. Is it a linked list, hash table, or something more specialized? How does it handle concurrency if multiple BPF programs are accessing the same LRU cache? I'll probably need to consider the eviction policy as well. Is it a simple LRU, or are there optimizations like a "frequency-based" approach, or maybe it combines LRU with other cache management techniques? I should look for details about memory allocation within the function. Does it use the standard kernel allocators, or does it have its own specialized mechanisms? And finally, of course, I have to consider the intended use-cases for this cache within the broader context of BPF. What kinds of data are we caching? What access patterns is the system designed for? This all is important as this `bpf_lru_init` likely sets the stage for everything else.
|
| 19/2 |
2026/05/20 08:16 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:kernel/bpf/bpf_lru_list.c IncludeLines:true Name:bpf_lru_init]
Results: map[SourceCode: 646: int bpf_lru_init(struct bpf_lru *lru, bool percpu, u32 hash_offset,
647: del_from_htab_func del_from_htab, void *del_arg)
648: {
649: int cpu;
650:
651: if (percpu) {
652: lru->percpu_lru = alloc_percpu(struct bpf_lru_list);
653: if (!lru->percpu_lru)
654: return -ENOMEM;
655:
656: for_each_possible_cpu(cpu) {
657: struct bpf_lru_list *l;
658:
659: l = per_cpu_ptr(lru->percpu_lru, cpu);
660: bpf_lru_list_init(l);
661: }
662: lru->nr_scans = PERCPU_NR_SCANS;
663: } else {
664: struct bpf_common_lru *clru = &lru->common_lru;
665:
666: clru->local_list = alloc_percpu(struct bpf_lru_locallist);
667: if (!clru->local_list)
668: return -ENOMEM;
669:
670: for_each_possible_cpu(cpu) {
671: struct bpf_lru_locallist *loc_l;
672:
673: loc_l = per_cpu_ptr(clru->local_list, cpu);
674: bpf_lru_locallist_init(loc_l, cpu);
675: }
676:
677: bpf_lru_list_init(&clru->lru_list);
678: lru->nr_scans = LOCAL_NR_SCANS;
679: }
680:
681: lru->percpu = percpu;
682: lru->del_from_htab = del_from_htab;
683: lru->del_arg = del_arg;
684: lru->hash_offset = hash_offset;
685:
686: return 0;
687: }
SourceFile:kernel/bpf/bpf_lru_list.c]
|
| 20/2 |
2026/05/20 08:16 |
llm |
expert |
0m
Model:
Tokens:
input: 22164
output: 51
thoughts: 15
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience:
**Tracing the Origins of `bpf_lru_init` Calls**
Alright, so the first question is, where are we seeing `bpf_lru_init` being invoked? I need to quickly identify the call sites. I'll need to use my tracing tools; `perf` or perhaps `bcc` with a simple tracepoint or uprobe to pinpoint the callers. Given the nature of a Least Recently Used (LRU) cache, this is likely linked to some memory management or object tracking within the BPF subsystem, which means that there are a finite number of locations in code that it would be called from.
I'm thinking about the various subsystems that could use this: network filter, security audit, or maybe even tracepoint-related BPF programs might use an LRU. I’ll need to figure out which area is relevant.
I need to quickly run a static analysis to locate those call sites. It's likely that it has something to do with initialization of BPF programs, or maybe the creation of some shared memory area. With a quick search through the code, I expect to see it coming from a variety of places, and I'll need to figure out which call sites are most relevant to what I'm looking for.
I'll be looking for any hints about the context in which `bpf_lru_init` is used. Knowing the callers will tell me a lot.
|
| 21/2 |
2026/05/20 08:16 |
tool |
codesearch-find-references |
0m
Args: map[ContextFile:kernel/bpf/bpf_lru_list.c IncludeSnippetLines:0 Name:bpf_lru_init]
Results: map[References:[map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:prealloc_init SourceFile:kernel/bpf/hashtab.c SourceLine:355]] TruncatedOutput:false]
|
| 22/2 |
2026/05/20 08:16 |
llm |
expert |
0m
Model:
Tokens:
input: 22617
output: 42
thoughts: 22
Thoughts: Here's my take on those thoughts, tailored for an expert audience:
**Diving into `prealloc_init` in `kernel/bpf/hashtab.c`**
Alright, let's pull up the source code for `prealloc_init` within `kernel/bpf/hashtab.c`. I need to refresh my understanding of how this pre-allocation mechanism works in the BPF hash table implementation. I'm particularly interested in how they're handling memory management here. What's the trade-off they're making between upfront allocation and potential fragmentation or overhead? I want to see how this function sets up the initial memory pool for the hash table entries. Specifically, I'm thinking about the implications for performance and concurrency – does this allocation strategy optimize lookups, updates, and deletions? Are they using any tricks like page alignment or slab allocation to minimize contention? I want to pay attention to details such as: the data structures being initialized, and any initial sizes or limits involved. I want to see if any specific memory barriers or locking primitives are used to ensure safe initialization in a concurrent environment. My main focus is efficiency and thread safety in preallocation. Let's see what gems we can find.
|
| 23/2 |
2026/05/20 08:16 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:kernel/bpf/hashtab.c IncludeLines:true Name:prealloc_init]
Results: map[SourceCode: 324: static int prealloc_init(struct bpf_htab *htab)
325: {
326: u32 num_entries = htab->map.max_entries;
327: int err = -ENOMEM, i;
328:
329: if (htab_has_extra_elems(htab))
330: num_entries += num_possible_cpus();
331:
332: htab->elems = bpf_map_area_alloc((u64)htab->elem_size * num_entries,
333: htab->map.numa_node);
334: if (!htab->elems)
335: return -ENOMEM;
336:
337: if (!htab_is_percpu(htab))
338: goto skip_percpu_elems;
339:
340: for (i = 0; i < num_entries; i++) {
341: u32 size = round_up(htab->map.value_size, 8);
342: void __percpu *pptr;
343:
344: pptr = bpf_map_alloc_percpu(&htab->map, size, 8,
345: GFP_USER | __GFP_NOWARN);
346: if (!pptr)
347: goto free_elems;
348: htab_elem_set_ptr(get_htab_elem(htab, i), htab->map.key_size,
349: pptr);
350: cond_resched();
351: }
352:
353: skip_percpu_elems:
354: if (htab_is_lru(htab))
355: err = bpf_lru_init(&htab->lru,
356: htab->map.map_flags & BPF_F_NO_COMMON_LRU,
357: offsetof(struct htab_elem, hash) -
358: offsetof(struct htab_elem, lru_node),
359: htab_lru_map_delete_node,
360: htab);
361: else
362: err = pcpu_freelist_init(&htab->freelist);
363:
364: if (err)
365: goto free_elems;
366:
367: if (htab_is_lru(htab))
368: bpf_lru_populate(&htab->lru, htab->elems,
369: offsetof(struct htab_elem, lru_node),
370: htab->elem_size, num_entries);
371: else
372: pcpu_freelist_populate(&htab->freelist,
373: htab->elems + offsetof(struct htab_elem, fnode),
374: htab->elem_size, num_entries);
375:
376: return 0;
377:
378: free_elems:
379: htab_free_elems(htab);
380: return err;
381: }
SourceFile:kernel/bpf/hashtab.c]
|
| 24/2 |
2026/05/20 08:16 |
llm |
expert |
0m
Model:
Tokens:
input: 23898
output: 49
thoughts: 23
Thoughts: Okay, here's my interpretation of that thought process, assuming I'm an expert in this field, presented as a first-person summary:
**Connecting the Dots: Function Aliases in HTAB Management**
Alright, let's see. "del_from_htab" – that's the function name I'm looking at. Hmm, based on the context, I immediately recognize that this likely means the deletion function. And yes, it's quickly confirmed that `del_from_htab` is just an alias or shorthand for `htab_lru_map_delete_node`. This is standard practice. We frequently use these more specific, descriptive names within the core implementation, but then provide the alias for simpler consumption by external code, or for backwards compatibility, or maybe just to make a higher-level view look cleaner. Nothing surprising here. This tells me I need to be aware that any internal discussion or analysis of `del_from_htab` also applies to `htab_lru_map_delete_node` and vice-versa.
|
| 25/2 |
2026/05/20 08:16 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:kernel/bpf/hashtab.c IncludeLines:true Name:htab_lru_map_delete_node]
Results: map[SourceCode: 790: /* It is called from the bpf_lru_list when the LRU needs to delete
791: * older elements from the htab.
792: */
793: static bool htab_lru_map_delete_node(void *arg, struct bpf_lru_node *node)
794: {
795: struct bpf_htab *htab = arg;
796: struct htab_elem *l = NULL, *tgt_l;
797: struct hlist_nulls_head *head;
798: struct hlist_nulls_node *n;
799: unsigned long flags;
800: struct bucket *b;
801: int ret;
802:
803: tgt_l = container_of(node, struct htab_elem, lru_node);
804: b = __select_bucket(htab, tgt_l->hash);
805: head = &b->head;
806:
807: ret = htab_lock_bucket(b, &flags);
808: if (ret)
809: return false;
810:
811: hlist_nulls_for_each_entry_rcu(l, n, head, hash_node)
812: if (l == tgt_l) {
813: hlist_nulls_del_rcu(&l->hash_node);
814: bpf_map_dec_elem_count(&htab->map);
815: break;
816: }
817:
818: htab_unlock_bucket(b, flags);
819:
820: if (l == tgt_l)
821: check_and_free_fields(htab, l);
822: return l == tgt_l;
823: }
SourceFile:kernel/bpf/hashtab.c]
|
| 26/2 |
2026/05/20 08:16 |
llm |
expert |
0m
Model:
Tokens:
input: 24762
output: 45
thoughts: 39
Thoughts: Here's my thought process, as if I were analyzing that code:
**Digging into Potential LRU Interactions**
Okay, so I'm suspecting a potential interaction here. I need to be absolutely sure: could `check_and_free_fields` actually be calling `bpf_lru_push_free`? That would be crucial to understanding the memory management flow. The dependency could introduce some subtle effects that I need to keep in mind, even if not immediately obvious. The possibility has triggered a chain reaction of queries I need to make in my mind. The implications could be profound, so I need to go look directly at the implementation of `check_and_free_fields` to verify the call path. Let's start with that function and trace the code...
|
| 27/2 |
2026/05/20 08:16 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:kernel/bpf/hashtab.c IncludeLines:true Name:check_and_free_fields]
Results: map[SourceCode: 771: static void check_and_free_fields(struct bpf_htab *htab,
772: struct htab_elem *elem)
773: {
774: if (IS_ERR_OR_NULL(htab->map.record))
775: return;
776:
777: if (htab_is_percpu(htab)) {
778: void __percpu *pptr = htab_elem_get_ptr(elem, htab->map.key_size);
779: int cpu;
780:
781: for_each_possible_cpu(cpu)
782: bpf_obj_free_fields(htab->map.record, per_cpu_ptr(pptr, cpu));
783: } else {
784: void *map_value = htab_elem_value(elem, htab->map.key_size);
785:
786: bpf_obj_free_fields(htab->map.record, map_value);
787: }
788: }
SourceFile:kernel/bpf/hashtab.c]
|
| 28/2 |
2026/05/20 08:16 |
llm |
expert |
0m
Model:
Tokens:
input: 25349
output: 45
thoughts: 14
Thoughts: Okay, let's dive into this. Here's my thought process on this:
**Analyzing `bpf_obj_free_fields`**
Right, `bpf_obj_free_fields`. My first thought is: I need to refresh my understanding of what that function *specifically* does within the BPF (Berkeley Packet Filter) context. I know it's about freeing resources associated with BPF objects, but the *details* are crucial. I need to ensure I'm clear on which fields it's responsible for freeing and under what circumstances. This function is a cornerstone, so understanding its impact is paramount to understanding BPF lifecycle management. Is it memory, file descriptors, structures, what exactly? I have to consider the implications of its execution. Where is it called from? Are there any potential race conditions I need to think about? Are there any obvious security implications, or potential vulnerabilities, associated with incorrect usage or timing of this function? This deeper dive will inform any further analysis and will ensure I don't miss anything critical.
|
| 29/2 |
2026/05/20 08:16 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:kernel/bpf/syscall.c IncludeLines:true Name:bpf_obj_free_fields]
Results: map[SourceCode: 812: void bpf_obj_free_fields(const struct btf_record *rec, void *obj)
813: {
814: const struct btf_field *fields;
815: int i;
816:
817: if (IS_ERR_OR_NULL(rec))
818: return;
819: fields = rec->fields;
820: for (i = 0; i < rec->cnt; i++) {
821: struct btf_struct_meta *pointee_struct_meta;
822: const struct btf_field *field = &fields[i];
823: void *field_ptr = obj + field->offset;
824: void *xchgd_field;
825:
826: switch (fields[i].type) {
827: case BPF_SPIN_LOCK:
828: case BPF_RES_SPIN_LOCK:
829: break;
830: case BPF_TIMER:
831: bpf_timer_cancel_and_free(field_ptr);
832: break;
833: case BPF_WORKQUEUE:
834: bpf_wq_cancel_and_free(field_ptr);
835: break;
836: case BPF_TASK_WORK:
837: bpf_task_work_cancel_and_free(field_ptr);
838: break;
839: case BPF_KPTR_UNREF:
840: WRITE_ONCE(*(u64 *)field_ptr, 0);
841: break;
842: case BPF_KPTR_REF:
843: case BPF_KPTR_PERCPU:
844: xchgd_field = (void *)xchg((unsigned long *)field_ptr, 0);
845: if (!xchgd_field)
846: break;
847:
848: if (!btf_is_kernel(field->kptr.btf)) {
849: pointee_struct_meta = btf_find_struct_meta(field->kptr.btf,
850: field->kptr.btf_id);
851: __bpf_obj_drop_impl(xchgd_field, pointee_struct_meta ?
852: pointee_struct_meta->record : NULL,
853: fields[i].type == BPF_KPTR_PERCPU);
854: } else {
855: field->kptr.dtor(xchgd_field);
856: }
857: break;
858: case BPF_UPTR:
859: /* The caller ensured that no one is using the uptr */
860: unpin_uptr_kaddr(*(void **)field_ptr);
861: break;
862: case BPF_LIST_HEAD:
863: if (WARN_ON_ONCE(rec->spin_lock_off < 0))
864: continue;
865: bpf_list_head_free(field, field_ptr, obj + rec->spin_lock_off);
866: break;
867: case BPF_RB_ROOT:
868: if (WARN_ON_ONCE(rec->spin_lock_off < 0))
869: continue;
870: bpf_rb_root_free(field, field_ptr, obj + rec->spin_lock_off);
871: break;
872: case BPF_LIST_NODE:
873: case BPF_RB_NODE:
874: case BPF_REFCOUNT:
875: break;
876: default:
877: WARN_ON_ONCE(1);
878: continue;
879: }
880: }
881: }
SourceFile:kernel/bpf/syscall.c]
|
| 30/2 |
2026/05/20 08:16 |
llm |
expert |
0m
Model:
Tokens:
input: 26766
output: 53
thoughts: 132
Thoughts: **Deconstructing the `field->kptr.dtor` Mystery**
Okay, so I'm trying to figure out what functions are potentially being invoked when `field->kptr.dtor` is called. My initial thought was that it could be something like `bpf_map_put`. However, that doesn't quite fit, because `bpf_map_put` doesn't directly call `bpf_lru_push_free`. Hmmm, need to rule out potential candidates.
Wait a minute, what about the possibility of `field->kptr.dtor` calling `bpf_timer_cancel_and_free`? That's a strong contender, since it certainly needs to handle freeing resources.
But... could it also be calling `bpf_map_put` directly? The puzzle pieces aren't quite clicking into place.
Right, then it hits me. Let me backtrack and refresh my understanding of how `bpf_lru_push_free` fits into this picture. Ah, yes! I remember now - `bpf_lru_push_free` *is* called from `htab_lru_push_free`. So, the relationship might be more indirect. I need to trace this back further. I need to understand what's calling *that*...
|
| 31/2 |
2026/05/20 08:16 |
tool |
codesearch-find-references |
0m
Args: map[ContextFile:kernel/bpf/bpf_lru_list.c IncludeSnippetLines:0 Name:bpf_lru_push_free]
Results: map[References:[map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:__htab_lru_percpu_map_update_elem SourceFile:kernel/bpf/hashtab.c SourceLine:1390] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:htab_lru_push_free SourceFile:kernel/bpf/hashtab.c SourceLine:1191]] TruncatedOutput:false]
|
| 32/2 |
2026/05/20 08:16 |
llm |
expert |
0m
Model:
Tokens:
input: 27372
output: 47
thoughts: 15
Thoughts: Okay, let's dive into this. Here's my take on `htab_lru_push_free`, framed from a technical perspective, assuming this code is something I'm very familiar with.
**Examining `htab_lru_push_free`**
Alright, so `htab_lru_push_free`. Immediately my mind jumps to the likely context: an LRU (Least Recently Used) cache implementation, specifically one built around a hash table (`htab`). The "push_free" part suggests that we're dealing with freeing up space in the cache, and the "push" probably relates to moving an entry to a free or discard list of some kind, as part of the LRU eviction process. I'm already anticipating questions about locking, atomicity, and potential race conditions in this function.
My initial thoughts are:
* **Structure:** What's the fundamental data structure used here? Is `htab` simply a pointer to a hash table, or is it a more complex struct holding table metadata and pointers to the LRU list? I'll need to know this to track the control flow here.
* **LRU Mechanism:** How does the LRU part fit in? Is it a doubly-linked list of entries in the hash table, where the "head" is the most recently used and the "tail" is the least? Or is some other mechanism employed, like timestamps, to determine least recently used entries? The 'push' verb used, suggests that the list is updated, possibly with a 'head' and 'tail' pointer.
* **Concurrency:** Given this is a cache, there is a very high probability that the method is thread-safe. If so, what synchronization primitives are being used? Mutexes, read-write locks, atomic operations? I'll need to scrutinize how these are used to prevent data corruption. How does the current thread interact with these primitives, and is there any chance for deadlock?
* **Memory Management:** 'Free' strongly suggests memory deallocation is happening. Where is the memory being freed from, and how is it linked into a free list to avoid fragmentation? Do we need to consider how this function interacts with any memory allocation routines? How do we handle potentially shared memory?
* **Error Handling:** What happens if the `htab` is NULL or corrupted? What about the specific entry that is being freed? Are there checks for null pointers and invalid states? Exception handling is critical to ensure resilience.
* **Context:** What is the full scope? Is this called from an eviction process, a cache replacement policy, or some other mechanism? Understanding the calling context is vital.
So, I'll be looking to understand the function's responsibility, control flow, and its potential impact on performance and correctness.
|
| 33/2 |
2026/05/20 08:17 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:kernel/bpf/hashtab.c IncludeLines:true Name:htab_lru_push_free]
Results: map[SourceCode:1187: static void htab_lru_push_free(struct bpf_htab *htab, struct htab_elem *elem)
1188: {
1189: check_and_free_fields(htab, elem);
1190: bpf_map_dec_elem_count(&htab->map);
1191: bpf_lru_push_free(&htab->lru, &elem->lru_node);
1192: }
SourceFile:kernel/bpf/hashtab.c]
|
| 34/2 |
2026/05/20 08:17 |
llm |
expert |
0m
Model:
Tokens:
input: 28188
output: 53
thoughts: 200
Thoughts: **Tracing the Execution Path**
Okay, so I'm looking at how these functions, specifically `htab_lru_push_free`, interact. The initial call flow is pretty clear: it calls `check_and_free_fields`, which then calls `bpf_lru_push_free`. So, `check_and_free_fields` precedes `bpf_lru_push_free`, which is what I initially thought.
But, a nagging question arose. What if something deeper inside `check_and_free_fields`, in a nested call, happens to call `bpf_lru_push_free`? That would change the sequence I'm currently understanding. I need to make sure I understand the full call graph.
Ah, and I think I see a potential issue... What if `check_and_free_fields` calls `bpf_timer_cancel_and_free`? Would *that* indirectly trigger a call to `bpf_lru_push_free`? No, wait a minute, I think `bpf_lru_push_free` can only be called from `htab_lru_push_free` and `__htab_lru_percpu_map_update_elem`. So that simplifies the analysis.
Alright, let's turn my attention to `__htab_lru_percpu_map_update_elem`. Time to understand its role in this system.
|
| 35/2 |
2026/05/20 08:17 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:kernel/bpf/hashtab.c IncludeLines:true Name:__htab_lru_percpu_map_update_elem]
Results: map[SourceCode:1325: static long __htab_lru_percpu_map_update_elem(struct bpf_map *map, void *key,
1326: void *value, u64 map_flags,
1327: bool onallcpus)
1328: {
1329: struct bpf_htab *htab = container_of(map, struct bpf_htab, map);
1330: struct htab_elem *l_new = NULL, *l_old;
1331: struct hlist_nulls_head *head;
1332: unsigned long flags;
1333: struct bucket *b;
1334: u32 key_size, hash;
1335: int ret;
1336:
1337: if (unlikely(map_flags > BPF_EXIST))
1338: /* unknown flags */
1339: return -EINVAL;
1340:
1341: WARN_ON_ONCE(!rcu_read_lock_held() && !rcu_read_lock_trace_held() &&
1342: !rcu_read_lock_bh_held());
1343:
1344: key_size = map->key_size;
1345:
1346: hash = htab_map_hash(key, key_size, htab->hashrnd);
1347:
1348: b = __select_bucket(htab, hash);
1349: head = &b->head;
1350:
1351: /* For LRU, we need to alloc before taking bucket's
1352: * spinlock because LRU's elem alloc may need
1353: * to remove older elem from htab and this removal
1354: * operation will need a bucket lock.
1355: */
1356: if (map_flags != BPF_EXIST) {
1357: l_new = prealloc_lru_pop(htab, key, hash);
1358: if (!l_new)
1359: return -ENOMEM;
1360: }
1361:
1362: ret = htab_lock_bucket(b, &flags);
1363: if (ret)
1364: goto err_lock_bucket;
1365:
1366: l_old = lookup_elem_raw(head, hash, key, key_size);
1367:
1368: ret = check_flags(htab, l_old, map_flags);
1369: if (ret)
1370: goto err;
1371:
1372: if (l_old) {
1373: bpf_lru_node_set_ref(&l_old->lru_node);
1374:
1375: /* per-cpu hash map can update value in-place */
1376: pcpu_copy_value(htab, htab_elem_get_ptr(l_old, key_size),
1377: value, onallcpus);
1378: } else {
1379: pcpu_init_value(htab, htab_elem_get_ptr(l_new, key_size),
1380: value, onallcpus);
1381: hlist_nulls_add_head_rcu(&l_new->hash_node, head);
1382: l_new = NULL;
1383: }
1384: ret = 0;
1385: err:
1386: htab_unlock_bucket(b, flags);
1387: err_lock_bucket:
1388: if (l_new) {
1389: bpf_map_dec_elem_count(&htab->map);
1390: bpf_lru_push_free(&htab->lru, &l_new->lru_node);
1391: }
1392: return ret;
1393: }
SourceFile:kernel/bpf/hashtab.c]
|
| 36/2 |
2026/05/20 08:17 |
llm |
expert |
0m
Model:
Tokens:
input: 29890
output: 45
thoughts: 23
Thoughts: Here's a summary of my immediate thought process:
**Diving into the Kernel LRU Logic**
Okay, let me break this down. I see `prealloc_lru_pop` and my brain immediately flags that it's interacting with the LRU (Least Recently Used) cache. The key detail here is that `prealloc_lru_pop` is *calling* `bpf_lru_pop_free`. That's the critical connection. This means that whatever `prealloc_lru_pop` is doing, it’s using `bpf_lru_pop_free` as part of the process, specifically as a way to free data that’s being removed from the BPF-specific LRU. It suggests some kind of garbage collection mechanism associated with the LRU for BPF, likely for the freeing of memory associated with entries being evicted. This is the core functionality that requires deeper understanding.
|
| 37/2 |
2026/05/20 08:17 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:kernel/bpf/hashtab.c IncludeLines:true Name:prealloc_lru_pop]
Results: map[SourceCode: 297: /* The LRU list has a lock (lru_lock). Each htab bucket has a lock
298: * (bucket_lock). If both locks need to be acquired together, the lock
299: * order is always lru_lock -> bucket_lock and this only happens in
300: * bpf_lru_list.c logic. For example, certain code path of
301: * bpf_lru_pop_free(), which is called by function prealloc_lru_pop(),
302: * will acquire lru_lock first followed by acquiring bucket_lock.
303: *
304: * In hashtab.c, to avoid deadlock, lock acquisition of
305: * bucket_lock followed by lru_lock is not allowed. In such cases,
306: * bucket_lock needs to be released first before acquiring lru_lock.
307: */
308: static struct htab_elem *prealloc_lru_pop(struct bpf_htab *htab, void *key,
309: u32 hash)
310: {
311: struct bpf_lru_node *node = bpf_lru_pop_free(&htab->lru, hash);
312: struct htab_elem *l;
313:
314: if (node) {
315: bpf_map_inc_elem_count(&htab->map);
316: l = container_of(node, struct htab_elem, lru_node);
317: memcpy(l->key, key, htab->map.key_size);
318: return l;
319: }
320:
321: return NULL;
322: }
SourceFile:kernel/bpf/hashtab.c]
|
| 38/2 |
2026/05/20 08:17 |
llm |
expert |
0m
Model:
Tokens:
input: 30671
output: 53
thoughts: 287
Thoughts: **Analyzing the BPF LRU Free Path**
Okay, so I'm tracing the execution path of `bpf_lru_pop_free`. Right, it calls `bpf_common_lru_pop_free`, which, as expected, grabs `loc_l->lock`. From there, it *might* dive into `bpf_lru_list_pop_free_to_local`, which then would grab `l->lock`. Now, it goes into `__bpf_lru_list_shrink`. Okay, *that* leads to `lru->del_from_htab`, which is just an alias to `htab_lru_map_delete_node`. And `htab_lru_map_delete_node`... yes, it acquires `bucket_lock`.
Hmm, now, the thing that's nagging me... within `htab_lru_map_delete_node`, it then calls `check_and_free_fields`. And I've seen that function call `bpf_timer_cancel_and_free` or similar things in the past. But, wait... I think I'm missing something here. Right, I see that `htab_lru_map_delete_node` *releases* `bucket_lock* before it calls `check_and_free_fields`.
Hang on a moment. I need to make sure I understand the locking order here. Does it release `loc_l->lock` and `l->lock`? It *can't* be doing that, surely! Aha! No, no, no, I see it now. `lru->del_from_htab` *is* called from `__bpf_lru_list_shrink` while *still* holding `l->lock` and `loc_l->lock`! That changes everything. Let's dig back into `__bpf_lru_list_shrink` and see what else it's doing, just to be sure...
|
| 39/2 |
2026/05/20 08:17 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:kernel/bpf/bpf_lru_list.c IncludeLines:true Name:__bpf_lru_list_shrink]
Results: map[SourceCode: 242: /* Calls __bpf_lru_list_shrink_inactive() to shrink some
243: * ref-bit-cleared nodes and move them to the designated
244: * free list.
245: *
246: * If it cannot get a free node after calling
247: * __bpf_lru_list_shrink_inactive(). It will just remove
248: * one node from either inactive or active list without
249: * honoring the ref-bit. It prefers inactive list to active
250: * list in this situation.
251: */
252: static unsigned int __bpf_lru_list_shrink(struct bpf_lru *lru,
253: struct bpf_lru_list *l,
254: unsigned int tgt_nshrink,
255: struct list_head *free_list,
256: enum bpf_lru_list_type tgt_free_type)
257:
258: {
259: struct bpf_lru_node *node, *tmp_node;
260: struct list_head *force_shrink_list;
261: unsigned int nshrinked;
262:
263: nshrinked = __bpf_lru_list_shrink_inactive(lru, l, tgt_nshrink,
264: free_list, tgt_free_type);
265: if (nshrinked)
266: return nshrinked;
267:
268: /* Do a force shrink by ignoring the reference bit */
269: if (!list_empty(&l->lists[BPF_LRU_LIST_T_INACTIVE]))
270: force_shrink_list = &l->lists[BPF_LRU_LIST_T_INACTIVE];
271: else
272: force_shrink_list = &l->lists[BPF_LRU_LIST_T_ACTIVE];
273:
274: list_for_each_entry_safe_reverse(node, tmp_node, force_shrink_list,
275: list) {
276: if (lru->del_from_htab(lru->del_arg, node)) {
277: __bpf_lru_node_move_to_free(l, node, free_list,
278: tgt_free_type);
279: return 1;
280: }
281: }
282:
283: return 0;
284: }
SourceFile:kernel/bpf/bpf_lru_list.c]
|
| 40/2 |
2026/05/20 08:17 |
llm |
expert |
0m
Model:
Tokens:
input: 32209
output: 54
thoughts: 147
Thoughts: **Analyzing the Lock Hierarchy in the BPF LRU Implementation**
Okay, so I'm tracing through this BPF LRU code. I've got `__bpf_lru_list_shrink` being called from `bpf_lru_list_pop_free_to_local`, and that one *definitely* holds `l->lock`, the list lock. Right, so far so good. Now, `bpf_lru_list_pop_free_to_local` gets called from `bpf_common_lru_pop_free`. And *that* one, if I'm remembering correctly, holds `loc_l->lock`, the local LRU lock. Hmm... wait a second. `bpf_common_lru_pop_free` calls `bpf_lru_list_pop_free_to_local` while already holding `loc_l->lock`? I need to verify this lock ordering. This could introduce a deadlock risk if we're not careful. I'm going to quickly check `bpf_common_lru_pop_free` to confirm. This is starting to look like a critical section that needs close attention to ensure it's not opening any race condition vulnerabilities.
|
| 41/2 |
2026/05/20 08:17 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:kernel/bpf/bpf_lru_list.c IncludeLines:true Name:bpf_common_lru_pop_free]
Results: map[SourceCode: 428: static struct bpf_lru_node *bpf_common_lru_pop_free(struct bpf_lru *lru,
429: u32 hash)
430: {
431: struct bpf_lru_locallist *loc_l, *steal_loc_l;
432: struct bpf_common_lru *clru = &lru->common_lru;
433: struct bpf_lru_node *node;
434: int steal, first_steal;
435: unsigned long flags;
436: int cpu = raw_smp_processor_id();
437:
438: loc_l = per_cpu_ptr(clru->local_list, cpu);
439:
440: raw_spin_lock_irqsave(&loc_l->lock, flags);
441:
442: node = __local_list_pop_free(loc_l);
443: if (!node) {
444: bpf_lru_list_pop_free_to_local(lru, loc_l);
445: node = __local_list_pop_free(loc_l);
446: }
447:
448: if (node)
449: __local_list_add_pending(lru, loc_l, cpu, node, hash);
450:
451: raw_spin_unlock_irqrestore(&loc_l->lock, flags);
452:
453: if (node)
454: return node;
455:
456: /* No free nodes found from the local free list and
457: * the global LRU list.
458: *
459: * Steal from the local free/pending list of the
460: * current CPU and remote CPU in RR. It starts
461: * with the loc_l->next_steal CPU.
462: */
463:
464: first_steal = loc_l->next_steal;
465: steal = first_steal;
466: do {
467: steal_loc_l = per_cpu_ptr(clru->local_list, steal);
468:
469: raw_spin_lock_irqsave(&steal_loc_l->lock, flags);
470:
471: node = __local_list_pop_free(steal_loc_l);
472: if (!node)
473: node = __local_list_pop_pending(lru, steal_loc_l);
474:
475: raw_spin_unlock_irqrestore(&steal_loc_l->lock, flags);
476:
477: steal = cpumask_next_wrap(steal, cpu_possible_mask);
478: } while (!node && steal != first_steal);
479:
480: loc_l->next_steal = steal;
481:
482: if (node) {
483: raw_spin_lock_irqsave(&loc_l->lock, flags);
484: __local_list_add_pending(lru, loc_l, cpu, node, hash);
485: raw_spin_unlock_irqrestore(&loc_l->lock, flags);
486: }
487:
488: return node;
489: }
SourceFile:kernel/bpf/bpf_lru_list.c]
|
| 42/2 |
2026/05/20 08:17 |
llm |
expert |
0m
Model:
Tokens:
input: 33697
output: 24
thoughts: 2241
Thoughts: **Analyzing a BPF Lock Contention Bug**
Okay, so I'm looking at this lock contention issue in the BPF LRU implementation. Line 444, `bpf_lru_list_pop_free_to_local`, is called under `loc_l->lock`. The lock order is: `loc_l->lock` -> `l->lock` -> `bucket_lock`. My initial thought was that `htab_lru_map_delete_node` calls `check_and_free_fields`, and `check_and_free_fields` then calls `bpf_obj_free_fields`. The problem here is that `bpf_obj_free_fields` could potentially trigger more calls that might be the source, such as `bpf_timer_cancel_and_free`, `bpf_wq_cancel_and_free`, `bpf_task_work_cancel_and_free`, or even `__bpf_obj_drop_impl` or `field->kptr.dtor`. The concern is that if a timer is freed within this function, the whole thing could call `bpf_lru_push_free`.
I'm trying to follow the execution flow, but the stack trace is truncated. It's missing `check_and_free_fields` and `bpf_obj_free_fields`, which is frustrating. The reproducer, however, is using `bpf$MAP_UPDATE_BATCH` and `bpf$BPF_RAW_TRACEPOINT_OPEN`. Looking at the map creation, it's a `BPF_MAP_TYPE_LRU_PERCPU_HASH` with key size 1, value size 12, and max entries 9. This gives me a direction to work with. The program being loaded next is a bit concerning, it starts with an `BPF_PROG_TYPE_UNSPEC` and then is a `BPF_PROG_TYPE_RAW_TRACEPOINT` attached to `contention_end`.
Aha! `contention_end` is the key. The tracepoint fires at lock contention. The BPF program attached to this tracepoint will get triggered when a lock contention *ends*. And that's happening with the `loc_l->lock` in `bpf_common_lru_pop_free`, because if contention occurs, or `l->lock` or `bucket_lock`, the tracepoint gets hit.
Okay, so what is the BPF program doing? It looks like it is calling `bpf_ringbuf_output`, but I immediately get confused. Wait... it seems that a map of type `BPF_MAP_TYPE_LRU_PERCPU_HASH` is passed in as an argument, which should be the wrong thing, right? No, the first program calls `bpf_ringbuf_output`, the second one is a tracepoint program. Wait, I see the program being loaded. The second program's instructions are identical to the first program! The second BPF program just reuses the same instructions as the first one, which is odd. Looking at the instructions, it's setting up arguments for a `bpf_insn_map_fd_t` type instruction, and then calling `BPF_FUNC_map_update_elem`. So this is not a `bpf_ringbuf_output` call, but a `BPF_FUNC_map_update_elem` call, that's it!
|
| 43/2 |
2026/05/20 08:17 |
tool |
grepper |
0m
Args: map[Expression:BPF_FUNC_map_update_elem]
Results: map[Output:drivers/media/rc/bpf-lirc.c=83=lirc_mode2_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
--
drivers/media/rc/bpf-lirc.c-93- return &bpf_map_lookup_elem_proto;
drivers/media/rc/bpf-lirc.c:94: case BPF_FUNC_map_update_elem:
drivers/media/rc/bpf-lirc.c-95- return &bpf_map_update_elem_proto;
--
drivers/net/ethernet/netronome/nfp/bpf/jit.c=1726=map_call_stack_common(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta)
--
drivers/net/ethernet/netronome/nfp/bpf/jit.c-1739- emit_csr_wr(nfp_prog, reg_b(2 * 2), NFP_CSR_ACT_LM_ADDR0);
drivers/net/ethernet/netronome/nfp/bpf/jit.c:1740: if (meta->func_id == BPF_FUNC_map_update_elem)
drivers/net/ethernet/netronome/nfp/bpf/jit.c-1741- emit_csr_wr(nfp_prog, reg_b(3 * 2), NFP_CSR_ACT_LM_ADDR2);
--
drivers/net/ethernet/netronome/nfp/bpf/jit.c=3347=static int helper_call(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta)
--
drivers/net/ethernet/netronome/nfp/bpf/jit.c-3354- case BPF_FUNC_map_lookup_elem:
drivers/net/ethernet/netronome/nfp/bpf/jit.c:3355: case BPF_FUNC_map_update_elem:
drivers/net/ethernet/netronome/nfp/bpf/jit.c-3356- case BPF_FUNC_map_delete_elem:
--
drivers/net/ethernet/netronome/nfp/bpf/jit.c=4534=void *nfp_bpf_relo_for_vnic(struct nfp_prog *nfp_prog, struct nfp_bpf_vnic *bv)
--
drivers/net/ethernet/netronome/nfp/bpf/jit.c-4592- break;
drivers/net/ethernet/netronome/nfp/bpf/jit.c:4593: case BPF_FUNC_map_update_elem:
drivers/net/ethernet/netronome/nfp/bpf/jit.c-4594- val = nfp_prog->bpf->helpers.map_update;
--
drivers/net/ethernet/netronome/nfp/bpf/main.c=238=nfp_bpf_parse_cap_func(struct nfp_app_bpf *bpf, void __iomem *value, u32 length)
--
drivers/net/ethernet/netronome/nfp/bpf/main.c-250- break;
drivers/net/ethernet/netronome/nfp/bpf/main.c:251: case BPF_FUNC_map_update_elem:
drivers/net/ethernet/netronome/nfp/bpf/main.c-252- bpf->helpers.map_update = readl(&cap->func_addr);
--
drivers/net/ethernet/netronome/nfp/bpf/verifier.c=170=nfp_bpf_check_helper_call(struct nfp_prog *nfp_prog,
--
drivers/net/ethernet/netronome/nfp/bpf/verifier.c-208-
drivers/net/ethernet/netronome/nfp/bpf/verifier.c:209: case BPF_FUNC_map_update_elem:
drivers/net/ethernet/netronome/nfp/bpf/verifier.c-210- if (!nfp_bpf_map_call_ok("map_update", env, meta,
--
kernel/bpf/helpers.c=1928=bpf_base_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
--
kernel/bpf/helpers.c-1932- return &bpf_map_lookup_elem_proto;
kernel/bpf/helpers.c:1933: case BPF_FUNC_map_update_elem:
kernel/bpf/helpers.c-1934- return &bpf_map_update_elem_proto;
--
kernel/bpf/verifier.c=9883=static bool may_update_sockmap(struct bpf_verifier_env *env, int func_id)
--
kernel/bpf/verifier.c-9887-
kernel/bpf/verifier.c:9888: if (func_id != BPF_FUNC_map_update_elem &&
kernel/bpf/verifier.c-9889- func_id != BPF_FUNC_map_delete_elem)
--
kernel/bpf/verifier.c=11098=record_func_map(struct bpf_verifier_env *env, struct bpf_call_arg_meta *meta,
--
kernel/bpf/verifier.c-11105- func_id != BPF_FUNC_map_lookup_elem &&
kernel/bpf/verifier.c:11106: func_id != BPF_FUNC_map_update_elem &&
kernel/bpf/verifier.c-11107- func_id != BPF_FUNC_map_delete_elem &&
--
kernel/bpf/verifier.c-11126- (func_id == BPF_FUNC_map_delete_elem ||
kernel/bpf/verifier.c:11127: func_id == BPF_FUNC_map_update_elem ||
kernel/bpf/verifier.c-11128- func_id == BPF_FUNC_map_push_elem ||
--
kernel/bpf/verifier.c=22005=static int do_misc_fixups(struct bpf_verifier_env *env)
--
kernel/bpf/verifier.c-22528- (insn->imm == BPF_FUNC_map_lookup_elem ||
kernel/bpf/verifier.c:22529: insn->imm == BPF_FUNC_map_update_elem ||
kernel/bpf/verifier.c-22530- insn->imm == BPF_FUNC_map_delete_elem ||
--
kernel/bpf/verifier.c-22592- goto next_insn;
kernel/bpf/verifier.c:22593: case BPF_FUNC_map_update_elem:
kernel/bpf/verifier.c-22594- insn->imm = BPF_CALL_IMM(ops->map_update_elem);
--
samples/bpf/cookie_uid_helper_example.c=76=static void prog_load(void)
--
samples/bpf/cookie_uid_helper_example.c-130- /*
samples/bpf/cookie_uid_helper_example.c:131: * add new map entry using BPF_FUNC_map_update_elem, it takes
samples/bpf/cookie_uid_helper_example.c-132- * 4 parameters (R1: map_fd, R2: &socket_cookie, R3: &stats,
--
samples/bpf/cookie_uid_helper_example.c-140- BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0,
samples/bpf/cookie_uid_helper_example.c:141: BPF_FUNC_map_update_elem),
samples/bpf/cookie_uid_helper_example.c-142- BPF_JMP_IMM(BPF_JA, 0, 0, 5),
--
samples/bpf/cookie_uid_helper_example.c-145- * be done by directly write to pointers instead of using
samples/bpf/cookie_uid_helper_example.c:146: * BPF_FUNC_map_update_elem helper function
samples/bpf/cookie_uid_helper_example.c-147- */
]
|
| 44/2 |
2026/05/20 08:17 |
llm |
expert |
0m
Model:
Tokens:
input: 38888
output: 25
thoughts: 81
Thoughts: Okay, here's my interpretation of those thoughts, considering my expertise:
**Checking the BPF Function ID Mapping**
Alright, *BPF_FUNC_map_update_elem* is definitely 2. Yes, I'm sure, it's 2. But, hold on a second… wait… `func: const = 0x3` is indicating it's *BPF_FUNC_map_delete_elem*? That doesn't seem right. I need to verify this and prevent an unexpected bug, and I need to be sure. I'll go directly to the source of truth, so I need to check `include/uapi/linux/bpf.h` to confirm the mapping between those function IDs and their corresponding BPF functions. I know that's where the definitive definitions are maintained. Better double-check it, to make sure there hasn't been a recent change that I am unaware of.
|
| 45/2 |
2026/05/20 08:17 |
tool |
grepper |
0m
Error:
Args: map[Expression:BPF_FUNC_map_update_elem =]
Results:
|
| 46/2 |
2026/05/20 08:17 |
llm |
expert |
0m
Model:
Tokens:
input: 39208
output: 24
thoughts: 30
Thoughts: Okay, here's my take on those thoughts, framed as an expert's internal monologue:
**Checking BPF Map Update**
Alright, time to dive into the core functionality. I need to refresh my memory on the specifics of `BPF_FUNC_map_update_elem`. Let's just double-check the definition, make sure I haven't missed any edge cases and confirm my understanding before I start. I know it's a fundamental BPF helper, but it's always good to be precise, especially when dealing with data structures in the kernel. `include/uapi/linux/bpf.h` is the definitive source for this, so that's where I need to look. It’s critical to get the signature and parameter details straight before I move forward, no point making assumptions or introducing a bug at this point, better to be thorough.
|
| 47/2 |
2026/05/20 08:18 |
tool |
grepper |
0m
Args: map[Expression:BPF_FUNC_map_update_elem]
Results: map[Output:drivers/media/rc/bpf-lirc.c=83=lirc_mode2_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
--
drivers/media/rc/bpf-lirc.c-93- return &bpf_map_lookup_elem_proto;
drivers/media/rc/bpf-lirc.c:94: case BPF_FUNC_map_update_elem:
drivers/media/rc/bpf-lirc.c-95- return &bpf_map_update_elem_proto;
--
drivers/net/ethernet/netronome/nfp/bpf/jit.c=1726=map_call_stack_common(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta)
--
drivers/net/ethernet/netronome/nfp/bpf/jit.c-1739- emit_csr_wr(nfp_prog, reg_b(2 * 2), NFP_CSR_ACT_LM_ADDR0);
drivers/net/ethernet/netronome/nfp/bpf/jit.c:1740: if (meta->func_id == BPF_FUNC_map_update_elem)
drivers/net/ethernet/netronome/nfp/bpf/jit.c-1741- emit_csr_wr(nfp_prog, reg_b(3 * 2), NFP_CSR_ACT_LM_ADDR2);
--
drivers/net/ethernet/netronome/nfp/bpf/jit.c=3347=static int helper_call(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta)
--
drivers/net/ethernet/netronome/nfp/bpf/jit.c-3354- case BPF_FUNC_map_lookup_elem:
drivers/net/ethernet/netronome/nfp/bpf/jit.c:3355: case BPF_FUNC_map_update_elem:
drivers/net/ethernet/netronome/nfp/bpf/jit.c-3356- case BPF_FUNC_map_delete_elem:
--
drivers/net/ethernet/netronome/nfp/bpf/jit.c=4534=void *nfp_bpf_relo_for_vnic(struct nfp_prog *nfp_prog, struct nfp_bpf_vnic *bv)
--
drivers/net/ethernet/netronome/nfp/bpf/jit.c-4592- break;
drivers/net/ethernet/netronome/nfp/bpf/jit.c:4593: case BPF_FUNC_map_update_elem:
drivers/net/ethernet/netronome/nfp/bpf/jit.c-4594- val = nfp_prog->bpf->helpers.map_update;
--
drivers/net/ethernet/netronome/nfp/bpf/main.c=238=nfp_bpf_parse_cap_func(struct nfp_app_bpf *bpf, void __iomem *value, u32 length)
--
drivers/net/ethernet/netronome/nfp/bpf/main.c-250- break;
drivers/net/ethernet/netronome/nfp/bpf/main.c:251: case BPF_FUNC_map_update_elem:
drivers/net/ethernet/netronome/nfp/bpf/main.c-252- bpf->helpers.map_update = readl(&cap->func_addr);
--
drivers/net/ethernet/netronome/nfp/bpf/verifier.c=170=nfp_bpf_check_helper_call(struct nfp_prog *nfp_prog,
--
drivers/net/ethernet/netronome/nfp/bpf/verifier.c-208-
drivers/net/ethernet/netronome/nfp/bpf/verifier.c:209: case BPF_FUNC_map_update_elem:
drivers/net/ethernet/netronome/nfp/bpf/verifier.c-210- if (!nfp_bpf_map_call_ok("map_update", env, meta,
--
kernel/bpf/helpers.c=1928=bpf_base_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
--
kernel/bpf/helpers.c-1932- return &bpf_map_lookup_elem_proto;
kernel/bpf/helpers.c:1933: case BPF_FUNC_map_update_elem:
kernel/bpf/helpers.c-1934- return &bpf_map_update_elem_proto;
--
kernel/bpf/verifier.c=9883=static bool may_update_sockmap(struct bpf_verifier_env *env, int func_id)
--
kernel/bpf/verifier.c-9887-
kernel/bpf/verifier.c:9888: if (func_id != BPF_FUNC_map_update_elem &&
kernel/bpf/verifier.c-9889- func_id != BPF_FUNC_map_delete_elem)
--
kernel/bpf/verifier.c=11098=record_func_map(struct bpf_verifier_env *env, struct bpf_call_arg_meta *meta,
--
kernel/bpf/verifier.c-11105- func_id != BPF_FUNC_map_lookup_elem &&
kernel/bpf/verifier.c:11106: func_id != BPF_FUNC_map_update_elem &&
kernel/bpf/verifier.c-11107- func_id != BPF_FUNC_map_delete_elem &&
--
kernel/bpf/verifier.c-11126- (func_id == BPF_FUNC_map_delete_elem ||
kernel/bpf/verifier.c:11127: func_id == BPF_FUNC_map_update_elem ||
kernel/bpf/verifier.c-11128- func_id == BPF_FUNC_map_push_elem ||
--
kernel/bpf/verifier.c=22005=static int do_misc_fixups(struct bpf_verifier_env *env)
--
kernel/bpf/verifier.c-22528- (insn->imm == BPF_FUNC_map_lookup_elem ||
kernel/bpf/verifier.c:22529: insn->imm == BPF_FUNC_map_update_elem ||
kernel/bpf/verifier.c-22530- insn->imm == BPF_FUNC_map_delete_elem ||
--
kernel/bpf/verifier.c-22592- goto next_insn;
kernel/bpf/verifier.c:22593: case BPF_FUNC_map_update_elem:
kernel/bpf/verifier.c-22594- insn->imm = BPF_CALL_IMM(ops->map_update_elem);
--
samples/bpf/cookie_uid_helper_example.c=76=static void prog_load(void)
--
samples/bpf/cookie_uid_helper_example.c-130- /*
samples/bpf/cookie_uid_helper_example.c:131: * add new map entry using BPF_FUNC_map_update_elem, it takes
samples/bpf/cookie_uid_helper_example.c-132- * 4 parameters (R1: map_fd, R2: &socket_cookie, R3: &stats,
--
samples/bpf/cookie_uid_helper_example.c-140- BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0,
samples/bpf/cookie_uid_helper_example.c:141: BPF_FUNC_map_update_elem),
samples/bpf/cookie_uid_helper_example.c-142- BPF_JMP_IMM(BPF_JA, 0, 0, 5),
--
samples/bpf/cookie_uid_helper_example.c-145- * be done by directly write to pointers instead of using
samples/bpf/cookie_uid_helper_example.c:146: * BPF_FUNC_map_update_elem helper function
samples/bpf/cookie_uid_helper_example.c-147- */
]
|
| 48/2 |
2026/05/20 08:18 |
llm |
expert |
0m
Model:
Tokens:
input: 41617
output: 46
thoughts: 52
Thoughts: Okay, let's see...
**Checking BPF Function Indices**
Hold on a second, am I remembering the BPF function indices correctly? I *thought* `BPF_FUNC_map_update_elem` was 2, and then `BPF_FUNC_map_delete_elem` was 3. But I should confirm this, just to be sure. I'm going to quickly check `include/uapi/linux/bpf.h` to make absolutely certain. It's always a good idea to double-check these details to prevent any silly mistakes in the code. Gotta be precise!
|
| 49/2 |
2026/05/20 08:18 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:include/uapi/linux/bpf.h IncludeLines:true Name:bpf_func_id]
Results: map[SourceCode:6098: enum bpf_func_id {
6099: ___BPF_FUNC_MAPPER(__BPF_ENUM_FN)
6100: __BPF_FUNC_MAX_ID,
6101: };
SourceFile:include/uapi/linux/bpf.h]
|
| 50/2 |
2026/05/20 08:18 |
llm |
expert |
0m
Model:
Tokens:
input: 41944
output: 49
thoughts: 207
Thoughts: **Deconstructing the BPF Function Call**
Okay, so I'm looking at this code and it's using a macro for this function call. Right, that's fairly standard. Now, I need to figure out what that macro expands to. Hmm, let me see... it looks like `func: const = 0x3` is indeed resolving to `BPF_FUNC_map_delete_elem`. Hold on, let me just confirm that I haven't mixed something up, `BPF_FUNC_unspec` is 0, `BPF_FUNC_map_lookup_elem` is 1, `BPF_FUNC_map_update_elem` is 2, and yup, `BPF_FUNC_map_delete_elem` is 3. Got it, so the BPF program is calling `bpf_map_delete_elem`.
Alright, my next question is, what does `bpf_map_delete_elem` actually *do*, especially for this `LRU_PERCPU_HASH` type? Let me trace that. Ah, it appears that `bpf_map_delete_elem` is calling `htab_lru_percpu_map_delete_elem`. Now, I'm thinking, wait, that function name doesn't *quite* ring a bell. Let me just double check my mental catalog... ah, I think it's more likely calling `htab_lru_map_delete_elem` instead. The percpu version is probably handled in the general function. I should verify that, but it's very likely a naming convention that I am familiar with.
|
| 51/2 |
2026/05/20 08:18 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:kernel/bpf/hashtab.c IncludeLines:true Name:htab_lru_map_delete_elem]
Results: map[SourceCode:1445: static long htab_lru_map_delete_elem(struct bpf_map *map, void *key)
1446: {
1447: struct bpf_htab *htab = container_of(map, struct bpf_htab, map);
1448: struct hlist_nulls_head *head;
1449: struct bucket *b;
1450: struct htab_elem *l;
1451: unsigned long flags;
1452: u32 hash, key_size;
1453: int ret;
1454:
1455: WARN_ON_ONCE(!rcu_read_lock_held() && !rcu_read_lock_trace_held() &&
1456: !rcu_read_lock_bh_held());
1457:
1458: key_size = map->key_size;
1459:
1460: hash = htab_map_hash(key, key_size, htab->hashrnd);
1461: b = __select_bucket(htab, hash);
1462: head = &b->head;
1463:
1464: ret = htab_lock_bucket(b, &flags);
1465: if (ret)
1466: return ret;
1467:
1468: l = lookup_elem_raw(head, hash, key, key_size);
1469:
1470: if (l)
1471: hlist_nulls_del_rcu(&l->hash_node);
1472: else
1473: ret = -ENOENT;
1474:
1475: htab_unlock_bucket(b, flags);
1476: if (l)
1477: htab_lru_push_free(htab, l);
1478: return ret;
1479: }
SourceFile:kernel/bpf/hashtab.c]
|
| 52/2 |
2026/05/20 08:18 |
llm |
expert |
0m
Model:
Tokens:
input: 43117
output: 46
thoughts: 639
Thoughts: **Analyzing a BPF Lock Contention Scenario**
Okay, so I'm tracing this issue and it looks like `htab_lru_map_delete_elem` is calling `htab_lru_push_free`, which then calls `bpf_lru_push_free`. The key here is that the BPF program attached to the `contention_end` tracepoint triggers through `bpf_map_delete_elem`, which in turn calls `bpf_lru_push_free`. And *that* function, `bpf_lru_push_free`, acquires `loc_l->lock`.
Now, here's where it gets interesting. The lock contention was supposedly on `loc_l->lock`. Does that mean the `contention_end` tracepoint fires when `loc_l->lock` is *released*? This doesn't quite seem right, but let's look at the stack trace they provided.
The stack trace shows a task attempting to acquire the lock (`&loc_l->lock`) at `bpf_lru_push_free`, as expected. However, it also shows that the task is *already* holding the lock at `bpf_common_lru_pop_free`. This is confusing. How can a contention *end* event fire if the task already *has* the lock? Line 440 of that code contains `raw_spin_lock_irqsave(&loc_l->lock, flags);`. It looks like it *shouldn't* be holding the lock here.
Wait a second... if there's contention, `_raw_spin_lock_irqsave` *spins*. When the task *finally* acquires the lock, *that's* when the `trace_contention_end` might be triggered! This makes a lot more sense now. I think it makes sense that `trace_contention_end` is called when lock acquisition is *successful* when it was contended. I need to verify that `trace_contention_end` is actually called with the lock being held. Time to dig deeper!
|
| 53/2 |
2026/05/20 08:18 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:kernel/locking/spinlock.c IncludeLines:true Name:_raw_spin_lock_irqsave]
Results: map[SourceCode: 160: noinline unsigned long __lockfunc _raw_spin_lock_irqsave(raw_spinlock_t *lock)
161: {
162: return __raw_spin_lock_irqsave(lock);
163: }
SourceFile:kernel/locking/spinlock.c]
|
| 54/2 |
2026/05/20 08:18 |
llm |
expert |
0m
Model:
Tokens:
input: 44360
output: 51
thoughts: 16
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience:
**Diving into `__raw_spin_lock_irqsave`**
Okay, time to dig into `__raw_spin_lock_irqsave`. I'm immediately interested in the core mechanics here. It's a low-level spinlock function, and the "irqsave" suffix implies it's intended to handle interrupt masking. That's the key: preventing race conditions with interrupt handlers when accessing shared resources. I need to understand how it's actually implemented to ensure atomicity, and understand the trade-offs of this approach. Are we saving the current interrupt state? Where is that stored? How does this interact with preemption? I want to see how this function guarantees that the critical section it protects is truly atomic, even in the face of potentially disruptive interrupts and context switches. Let's see how it achieves that.
|
| 55/2 |
2026/05/20 08:18 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:include/linux/spinlock_api_smp.h IncludeLines:true Name:__raw_spin_lock_irqsave]
Results: map[SourceCode: 104: static inline unsigned long __raw_spin_lock_irqsave(raw_spinlock_t *lock)
105: {
106: unsigned long flags;
107:
108: local_irq_save(flags);
109: preempt_disable();
110: spin_acquire(&lock->dep_map, 0, 0, _RET_IP_);
111: LOCK_CONTENDED(lock, do_raw_spin_trylock, do_raw_spin_lock);
112: return flags;
113: }
SourceFile:include/linux/spinlock_api_smp.h]
|
| 56/2 |
2026/05/20 08:18 |
llm |
expert |
0m
Model:
Tokens:
input: 44820
output: 45
thoughts: 13
Thoughts: Okay, here's my attempt at summarizing the thought process, as requested, aimed at an expert audience and in the first person:
**Diving into `do_raw_spin_lock`**
Alright, time to dig into this `do_raw_spin_lock` function. Where does this even live? I need to understand its role in this context, especially in light of the potential concurrency issues we're dealing with. Let's see how it's implemented. I'm assuming it's probably using atomic instructions, perhaps a test-and-set or compare-and-swap, but I need to confirm that. It's likely platform-specific, so I should see if there are any architecture macros involved – perhaps some assembly code being conditionally included. I have a hunch it's a very low-level mechanism, likely crucial for synchronization primitives. I need to understand the memory model implications here too – cache coherency, memory barriers… is it using any explicit memory fences? What's the potential for lock contention? And how is it dealing with interrupts? Does it disable them, or mask them, or... ? I need to check for any potential deadlock scenarios, or even livelock situations, and understand if it has any support for lock debugging. This is the critical piece that everything else might depend upon. Let's start with the definition.
|
| 57/2 |
2026/05/20 08:18 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:kernel/locking/spinlock_debug.c IncludeLines:true Name:do_raw_spin_lock]
Results: map[SourceCode: 109: /*
110: * We are now relying on the NMI watchdog to detect lockup instead of doing
111: * the detection here with an unfair lock which can cause problem of its own.
112: */
113: void do_raw_spin_lock(raw_spinlock_t *lock)
114: {
115: debug_spin_lock_before(lock);
116: arch_spin_lock(&lock->raw_lock);
117: mmiowb_spin_lock();
118: debug_spin_lock_after(lock);
119: }
SourceFile:kernel/locking/spinlock_debug.c]
|
| 58/2 |
2026/05/20 08:18 |
llm |
expert |
0m
Model:
Tokens:
input: 45368
output: 41
thoughts: 18
Thoughts: Here's a summary of my thought process:
**Diving into the Macro Maze**
Okay, hold on a second. I see this `LOCK_CONTENDED` thing and my brain immediately flags it as a macro. That's a classic sign, right? We're dealing with preprocessor magic. Before I jump to any conclusions about *what* it means in the grand scheme of things, my immediate instinct is to dissect that macro. I need to understand its expansion first. What's it doing behind the scenes? Is it a simple boolean check, or something more complex with side effects? Let's check the definition. Gotta unravel this macro.
|
| 59/2 |
2026/05/20 08:18 |
tool |
codesearch-definition-source |
0m
Error:
Args: map[ContextFile:include/linux/lockdep.h IncludeLines:true Name:LOCK_CONTENDED]
Results: map[SourceCode: SourceFile:]
|
| 60/2 |
2026/05/20 08:18 |
llm |
expert |
0m
Model:
Tokens:
input: 45586
output: 19
thoughts: 11
Thoughts: Okay, here's my interpretation of that thought process, from an expert's perspective:
**Diving into Contention**
Alright, I need to get to the bottom of some locking issues. My first instinct, given what I know about the system, is to immediately reach for the grep command. Specifically, I'm going to look for instances of `LOCK_CONTENDED`. This is a pretty clear indicator of a point in the code where there's significant wait time due to resource contention. It's a key starting point for debugging. It's almost always a good idea to start with this level of granularity before going deeper into more complex diagnostics. From here I can get a starting list of problem areas, and go deeper.
|
| 61/2 |
2026/05/20 08:18 |
tool |
grepper |
0m
Args: map[Expression:define LOCK_CONTENDED]
Results: map[Output:include/linux/lockdep.h=439=extern void lock_acquired(struct lockdep_map *lock, unsigned long ip);
include/linux/lockdep.h-440-
include/linux/lockdep.h:441:#define LOCK_CONTENDED(_lock, try, lock) \
include/linux/lockdep.h-442-do { \
--
include/linux/lockdep.h-449-
include/linux/lockdep.h:450:#define LOCK_CONTENDED_RETURN(_lock, try, lock) \
include/linux/lockdep.h-451-({ \
--
include/linux/lockdep.h-466-
include/linux/lockdep.h:467:#define LOCK_CONTENDED(_lock, try, lock) \
include/linux/lockdep.h-468- lock(_lock)
include/linux/lockdep.h-469-
include/linux/lockdep.h:470:#define LOCK_CONTENDED_RETURN(_lock, try, lock) \
include/linux/lockdep.h-471- lock(_lock)
]
|
| 62/2 |
2026/05/20 08:18 |
llm |
expert |
0m
Model:
Tokens:
input: 46061
output: 41
thoughts: 24
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience:
**Analyzing Lockdep.h: Unraveling the Line Numbers**
Okay, so I'm thinking about `include/linux/lockdep.h` again, specifically lines 441 to 448. Right, let me pull that section up in my head. I need to refresh my memory on the context of those lines. This is probably related to some lock debugging or analysis functionality in the kernel, likely dealing with how lock dependencies are tracked or how deadlocks might be detected. I bet that range is defining or describing a specific data structure or perhaps a macro related to lockdep's operations. Given the file and line range, I'm expecting to see details on lock dependency information, maybe a representation of lock classes, or perhaps code that traces lock acquisition sequences. It's likely something low-level that's crucial for understanding the intricacies of lockdep's operation. I need to understand what those specific lines are doing to understand the current context of my work.
|
| 63/2 |
2026/05/20 08:18 |
tool |
codesearch-definition-source |
0m
Error:
Args: map[ContextFile:include/linux/lockdep.h IncludeLines:true Name:LOCK_CONTENDED]
Results: map[SourceCode: SourceFile:]
|
| 64/2 |
2026/05/20 08:18 |
llm |
expert |
0m
Model:
Tokens:
input: 46370
output: 23
thoughts: 14
Thoughts: Here's my take on the thought process, as if I were the one thinking it:
**Diving into `lockdep.h`**
Alright, time to crack open `include/linux/lockdep.h`. It's been a while since I last really dove into the lockdep code. I need to refresh my understanding of how this lock dependency validator actually works. I know the basics, the idea of detecting circular locking dependencies at runtime, but I want to get a bit deeper. Specifically, I'm hoping to understand some recent optimizations I heard were discussed. Time to get my hands dirty. I'll need to pay close attention to the data structures used to represent locks and dependencies, and understand how the algorithm traverses the dependency graph. I'm especially interested in how it handles nested locks and the implications for performance overhead. Hopefully this deep dive can help me better understand those optimizations I read about and how I might contribute in the future.
|
| 65/2 |
2026/05/20 08:19 |
tool |
read-file |
0m
Args: map[File:include/linux/lockdep.h]
Results: map[Contents:/* SPDX-License-Identifier: GPL-2.0 */
/*
* Runtime locking correctness validator
*
* Copyright (C) 2006,2007 Red Hat, Inc., Ingo Molnar <mingo@redhat.com>
* Copyright (C) 2007 Red Hat, Inc., Peter Zijlstra
*
* see Documentation/locking/lockdep-design.rst for more details.
*/
#ifndef __LINUX_LOCKDEP_H
#define __LINUX_LOCKDEP_H
#include <linux/lockdep_types.h>
#include <linux/smp.h>
#include <asm/percpu.h>
struct task_struct;
#ifdef CONFIG_LOCKDEP
#include <linux/linkage.h>
#include <linux/list.h>
#include <linux/debug_locks.h>
#include <linux/stacktrace.h>
static inline void lockdep_copy_map(struct lockdep_map *to,
struct lockdep_map *from)
{
int i;
*to = *from;
/*
* Since the class cache can be modified concurrently we could observe
* half pointers (64bit arch using 32bit copy insns). Therefore clear
* the caches and take the performance hit.
*
* XXX it doesn't work well with lockdep_set_class_and_subclass(), since
* that relies on cache abuse.
*/
for (i = 0; i < NR_LOCKDEP_CACHING_CLASSES; i++)
to->class_cache[i] = NULL;
}
/*
* Every lock has a list of other locks that were taken after it.
* We only grow the list, never remove from it:
*/
struct lock_list {
struct list_head entry;
struct lock_class *class;
struct lock_class *links_to;
const struct lock_trace *trace;
u16 distance;
/* bitmap of different dependencies from head to this */
u8 dep;
/* used by BFS to record whether "prev -> this" only has -(*R)-> */
u8 only_xr;
/*
* The parent field is used to implement breadth-first search, and the
* bit 0 is reused to indicate if the lock has been accessed in BFS.
*/
struct lock_list *parent;
};
/**
* struct lock_chain - lock dependency chain record
*
* @irq_context: the same as irq_context in held_lock below
* @depth: the number of held locks in this chain
* @base: the index in chain_hlocks for this chain
* @entry: the collided lock chains in lock_chain hash list
* @chain_key: the hash key of this lock_chain
*/
struct lock_chain {
/* see BUILD_BUG_ON()s in add_chain_cache() */
unsigned int irq_context : 2,
depth : 6,
base : 24;
/* 4 byte hole */
struct hlist_node entry;
u64 chain_key;
};
/*
* Initialization, self-test and debugging-output methods:
*/
extern void lockdep_init(void);
extern void lockdep_reset(void);
extern void lockdep_reset_lock(struct lockdep_map *lock);
extern void lockdep_free_key_range(void *start, unsigned long size);
extern asmlinkage void lockdep_sys_exit(void);
extern void lockdep_set_selftest_task(struct task_struct *task);
extern void lockdep_init_task(struct task_struct *task);
/*
* Split the recursion counter in two to readily detect 'off' vs recursion.
*/
#define LOCKDEP_RECURSION_BITS 16
#define LOCKDEP_OFF (1U << LOCKDEP_RECURSION_BITS)
#define LOCKDEP_RECURSION_MASK (LOCKDEP_OFF - 1)
/*
* lockdep_{off,on}() are macros to avoid tracing and kprobes; not inlines due
* to header dependencies.
*/
#define lockdep_off() \
do { \
current->lockdep_recursion += LOCKDEP_OFF; \
} while (0)
#define lockdep_on() \
do { \
current->lockdep_recursion -= LOCKDEP_OFF; \
} while (0)
extern void lockdep_register_key(struct lock_class_key *key);
extern void lockdep_unregister_key(struct lock_class_key *key);
/*
* These methods are used by specific locking variants (spinlocks,
* rwlocks, mutexes and rwsems) to pass init/acquire/release events
* to lockdep:
*/
extern void lockdep_init_map_type(struct lockdep_map *lock, const char *name,
struct lock_class_key *key, int subclass, u8 inner, u8 outer, u8 lock_type);
static inline void
lockdep_init_map_waits(struct lockdep_map *lock, const char *name,
struct lock_class_key *key, int subclass, u8 inner, u8 outer)
{
lockdep_init_map_type(lock, name, key, subclass, inner, outer, LD_LOCK_NORMAL);
}
static inline void
lockdep_init_map_wait(struct lockdep_map *lock, const char *name,
struct lock_class_key *key, int subclass, u8 inner)
{
lockdep_init_map_waits(lock, name, key, subclass, inner, LD_WAIT_INV);
}
static inline void lockdep_init_map(struct lockdep_map *lock, const char *name,
struct lock_class_key *key, int subclass)
{
lockdep_init_map_wait(lock, name, key, subclass, LD_WAIT_INV);
}
/*
* Reinitialize a lock key - for cases where there is special locking or
* special initialization of locks so that the validator gets the scope
* of dependencies wrong: they are either too broad (they need a class-split)
* or they are too narrow (they suffer from a false class-split):
*/
#define lockdep_set_class(lock, key) \
lockdep_init_map_type(&(lock)->dep_map, #key, key, 0, \
(lock)->dep_map.wait_type_inner, \
(lock)->dep_map.wait_type_outer, \
(lock)->dep_map.lock_type)
#define lockdep_set_class_and_name(lock, key, name) \
lockdep_init_map_type(&(lock)->dep_map, name, key, 0, \
(lock)->dep_map.wait_type_inner, \
(lock)->dep_map.wait_type_outer, \
(lock)->dep_map.lock_type)
#define lockdep_set_class_and_subclass(lock, key, sub) \
lockdep_init_map_type(&(lock)->dep_map, #key, key, sub, \
(lock)->dep_map.wait_type_inner, \
(lock)->dep_map.wait_type_outer, \
(lock)->dep_map.lock_type)
#define lockdep_set_subclass(lock, sub) \
lockdep_init_map_type(&(lock)->dep_map, (lock)->dep_map.name, (lock)->dep_map.key, sub,\
(lock)->dep_map.wait_type_inner, \
(lock)->dep_map.wait_type_outer, \
(lock)->dep_map.lock_type)
/**
* lockdep_set_novalidate_class: disable checking of lock ordering on a given
* lock
* @lock: Lock to mark
*
* Lockdep will still record that this lock has been taken, and print held
* instances when dumping locks
*/
#define lockdep_set_novalidate_class(lock) \
lockdep_set_class_and_name(lock, &__lockdep_no_validate__, #lock)
/**
* lockdep_set_notrack_class: disable lockdep tracking of a given lock entirely
* @lock: Lock to mark
*
* Bigger hammer than lockdep_set_novalidate_class: so far just for bcachefs,
* which takes more locks than lockdep is able to track (48).
*/
#define lockdep_set_notrack_class(lock) \
lockdep_set_class_and_name(lock, &__lockdep_no_track__, #lock)
/*
* Compare locking classes
*/
#define lockdep_match_class(lock, key) lockdep_match_key(&(lock)->dep_map, key)
static inline int lockdep_match_key(struct lockdep_map *lock,
struct lock_class_key *key)
{
return lock->key == key;
}
/*
* Acquire a lock.
*
* Values for "read":
*
* 0: exclusive (write) acquire
* 1: read-acquire (no recursion allowed)
* 2: read-acquire with same-instance recursion allowed
*
* Values for check:
*
* 0: simple checks (freeing, held-at-exit-time, etc.)
* 1: full validation
*/
extern void lock_acquire(struct lockdep_map *lock, unsigned int subclass,
int trylock, int read, int check,
struct lockdep_map *nest_lock, unsigned long ip);
extern void lock_release(struct lockdep_map *lock, unsigned long ip);
extern void lock_sync(struct lockdep_map *lock, unsigned int subclass,
int read, int check, struct lockdep_map *nest_lock,
unsigned long ip);
/* lock_is_held_type() returns */
#define LOCK_STATE_UNKNOWN -1
#define LOCK_STATE_NOT_HELD 0
#define LOCK_STATE_HELD 1
/*
* Same "read" as for lock_acquire(), except -1 means any.
*/
extern int lock_is_held_type(const struct lockdep_map *lock, int read);
static inline int lock_is_held(const struct lockdep_map *lock)
{
return lock_is_held_type(lock, -1);
}
#define lockdep_is_held(lock) lock_is_held(&(lock)->dep_map)
#define lockdep_is_held_type(lock, r) lock_is_held_type(&(lock)->dep_map, (r))
extern void lock_set_class(struct lockdep_map *lock, const char *name,
struct lock_class_key *key, unsigned int subclass,
unsigned long ip);
#define lock_set_novalidate_class(l, n, i) \
lock_set_class(l, n, &__lockdep_no_validate__, 0, i)
static inline void lock_set_subclass(struct lockdep_map *lock,
unsigned int subclass, unsigned long ip)
{
lock_set_class(lock, lock->name, lock->key, subclass, ip);
}
extern void lock_downgrade(struct lockdep_map *lock, unsigned long ip);
#define NIL_COOKIE (struct pin_cookie){ .val = 0U, }
extern struct pin_cookie lock_pin_lock(struct lockdep_map *lock);
extern void lock_repin_lock(struct lockdep_map *lock, struct pin_cookie);
extern void lock_unpin_lock(struct lockdep_map *lock, struct pin_cookie);
#define lockdep_depth(tsk) (debug_locks ? (tsk)->lockdep_depth : 0)
#define lockdep_assert(cond) \
do { WARN_ON(debug_locks && !(cond)); } while (0)
#define lockdep_assert_once(cond) \
do { WARN_ON_ONCE(debug_locks && !(cond)); } while (0)
#define lockdep_assert_held(l) \
lockdep_assert(lockdep_is_held(l) != LOCK_STATE_NOT_HELD)
#define lockdep_assert_not_held(l) \
lockdep_assert(lockdep_is_held(l) != LOCK_STATE_HELD)
#define lockdep_assert_held_write(l) \
lockdep_assert(lockdep_is_held_type(l, 0))
#define lockdep_assert_held_read(l) \
lockdep_assert(lockdep_is_held_type(l, 1))
#define lockdep_assert_held_once(l) \
lockdep_assert_once(lockdep_is_held(l) != LOCK_STATE_NOT_HELD)
#define lockdep_assert_none_held_once() \
lockdep_assert_once(!current->lockdep_depth)
#define lockdep_recursing(tsk) ((tsk)->lockdep_recursion)
#define lockdep_pin_lock(l) lock_pin_lock(&(l)->dep_map)
#define lockdep_repin_lock(l,c) lock_repin_lock(&(l)->dep_map, (c))
#define lockdep_unpin_lock(l,c) lock_unpin_lock(&(l)->dep_map, (c))
/*
* Must use lock_map_aquire_try() with override maps to avoid
* lockdep thinking they participate in the block chain.
*/
#define DEFINE_WAIT_OVERRIDE_MAP(_name, _wait_type) \
struct lockdep_map _name = { \
.name = #_name "-wait-type-override", \
.wait_type_inner = _wait_type, \
.lock_type = LD_LOCK_WAIT_OVERRIDE, }
#else /* !CONFIG_LOCKDEP */
static inline void lockdep_init_task(struct task_struct *task)
{
}
static inline void lockdep_off(void)
{
}
static inline void lockdep_on(void)
{
}
static inline void lockdep_set_selftest_task(struct task_struct *task)
{
}
# define lock_acquire(l, s, t, r, c, n, i) do { } while (0)
# define lock_release(l, i) do { } while (0)
# define lock_downgrade(l, i) do { } while (0)
# define lock_set_class(l, n, key, s, i) do { (void)(key); } while (0)
# define lock_set_novalidate_class(l, n, i) do { } while (0)
# define lock_set_subclass(l, s, i) do { } while (0)
# define lockdep_init() do { } while (0)
# define lockdep_init_map_type(lock, name, key, sub, inner, outer, type) \
do { (void)(name); (void)(key); } while (0)
# define lockdep_init_map_waits(lock, name, key, sub, inner, outer) \
do { (void)(name); (void)(key); } while (0)
# define lockdep_init_map_wait(lock, name, key, sub, inner) \
do { (void)(name); (void)(key); } while (0)
# define lockdep_init_map(lock, name, key, sub) \
do { (void)(name); (void)(key); } while (0)
# define lockdep_set_class(lock, key) do { (void)(key); } while (0)
# define lockdep_set_class_and_name(lock, key, name) \
do { (void)(key); (void)(name); } while (0)
#define lockdep_set_class_and_subclass(lock, key, sub) \
do { (void)(key); } while (0)
#define lockdep_set_subclass(lock, sub) do { } while (0)
#define lockdep_set_novalidate_class(lock) do { } while (0)
#define lockdep_set_notrack_class(lock) do { } while (0)
/*
* We don't define lockdep_match_class() and lockdep_match_key() for !LOCKDEP
* case since the result is not well defined and the caller should rather
* #ifdef the call himself.
*/
# define lockdep_reset() do { debug_locks = 1; } while (0)
# define lockdep_free_key_range(start, size) do { } while (0)
# define lockdep_sys_exit() do { } while (0)
static inline void lockdep_register_key(struct lock_class_key *key)
{
}
static inline void lockdep_unregister_key(struct lock_class_key *key)
{
}
#define lockdep_depth(tsk) (0)
/*
* Dummy forward declarations, allow users to write less ifdef-y code
* and depend on dead code elimination.
*/
extern int lock_is_held(const void *);
extern int lockdep_is_held(const void *);
#define lockdep_is_held_type(l, r) (1)
#define lockdep_assert(c) do { } while (0)
#define lockdep_assert_once(c) do { } while (0)
#define lockdep_assert_held(l) do { (void)(l); } while (0)
#define lockdep_assert_not_held(l) do { (void)(l); } while (0)
#define lockdep_assert_held_write(l) do { (void)(l); } while (0)
#define lockdep_assert_held_read(l) do { (void)(l); } while (0)
#define lockdep_assert_held_once(l) do { (void)(l); } while (0)
#define lockdep_assert_none_held_once() do { } while (0)
#define lockdep_recursing(tsk) (0)
#define NIL_COOKIE (struct pin_cookie){ }
#define lockdep_pin_lock(l) ({ struct pin_cookie cookie = { }; cookie; })
#define lockdep_repin_lock(l, c) do { (void)(l); (void)(c); } while (0)
#define lockdep_unpin_lock(l, c) do { (void)(l); (void)(c); } while (0)
#define DEFINE_WAIT_OVERRIDE_MAP(_name, _wait_type) \
struct lockdep_map __maybe_unused _name = {}
#endif /* !LOCKDEP */
#ifdef CONFIG_PROVE_LOCKING
void lockdep_set_lock_cmp_fn(struct lockdep_map *, lock_cmp_fn, lock_print_fn);
#define lock_set_cmp_fn(lock, ...) lockdep_set_lock_cmp_fn(&(lock)->dep_map, __VA_ARGS__)
#else
#define lock_set_cmp_fn(lock, ...) do { } while (0)
#endif
enum xhlock_context_t {
XHLOCK_HARD,
XHLOCK_SOFT,
XHLOCK_CTX_NR,
};
/*
* To initialize a lockdep_map statically use this macro.
* Note that _name must not be NULL.
*/
#define STATIC_LOCKDEP_MAP_INIT(_name, _key) \
{ .name = (_name), .key = (void *)(_key), }
static inline void lockdep_invariant_state(bool force) {}
static inline void lockdep_free_task(struct task_struct *task) {}
#ifdef CONFIG_LOCK_STAT
extern void lock_contended(struct lockdep_map *lock, unsigned long ip);
extern void lock_acquired(struct lockdep_map *lock, unsigned long ip);
#define LOCK_CONTENDED(_lock, try, lock) \
do { \
if (!try(_lock)) { \
lock_contended(&(_lock)->dep_map, _RET_IP_); \
lock(_lock); \
} \
lock_acquired(&(_lock)->dep_map, _RET_IP_); \
} while (0)
#define LOCK_CONTENDED_RETURN(_lock, try, lock) \
({ \
int ____err = 0; \
if (!try(_lock)) { \
lock_contended(&(_lock)->dep_map, _RET_IP_); \
____err = lock(_lock); \
} \
if (!____err) \
lock_acquired(&(_lock)->dep_map, _RET_IP_); \
____err; \
})
#else /* CONFIG_LOCK_STAT */
#define lock_contended(lockdep_map, ip) do {} while (0)
#define lock_acquired(lockdep_map, ip) do {} while (0)
#define LOCK_CONTENDED(_lock, try, lock) \
lock(_lock)
#define LOCK_CONTENDED_RETURN(_lock, try, lock) \
lock(_lock)
#endif /* CONFIG_LOCK_STAT */
#ifdef CONFIG_PROVE_LOCKING
extern void print_irqtrace_events(struct task_struct *curr);
#else
static inline void print_irqtrace_events(struct task_struct *curr)
{
}
#endif
/* Variable used to make lockdep treat read_lock() as recursive in selftests */
#ifdef CONFIG_DEBUG_LOCKING_API_SELFTESTS
extern unsigned int force_read_lock_recursive;
#else /* CONFIG_DEBUG_LOCKING_API_SELFTESTS */
#define force_read_lock_recursive 0
#endif /* CONFIG_DEBUG_LOCKING_API_SELFTESTS */
#ifdef CONFIG_LOCKDEP
extern bool read_lock_is_recursive(void);
#else /* CONFIG_LOCKDEP */
/* If !LOCKDEP, the value is meaningless */
#define read_lock_is_recursive() 0
#endif
/*
* For trivial one-depth nesting of a lock-class, the following
* global define can be used. (Subsystems with multiple levels
* of nesting should define their own lock-nesting subclasses.)
*/
#define SINGLE_DEPTH_NESTING 1
/*
* Map the dependency ops to NOP or to real lockdep ops, depending
* on the per lock-class debug mode:
*/
#define lock_acquire_exclusive(l, s, t, n, i) lock_acquire(l, s, t, 0, 1, n, i)
#define lock_acquire_shared(l, s, t, n, i) lock_acquire(l, s, t, 1, 1, n, i)
#define lock_acquire_shared_recursive(l, s, t, n, i) lock_acquire(l, s, t, 2, 1, n, i)
#define spin_acquire(l, s, t, i) lock_acquire_exclusive(l, s, t, NULL, i)
#define spin_acquire_nest(l, s, t, n, i) lock_acquire_exclusive(l, s, t, n, i)
#define spin_release(l, i) lock_release(l, i)
#define rwlock_acquire(l, s, t, i) lock_acquire_exclusive(l, s, t, NULL, i)
#define rwlock_acquire_read(l, s, t, i) \
do { \
if (read_lock_is_recursive()) \
lock_acquire_shared_recursive(l, s, t, NULL, i); \
else \
lock_acquire_shared(l, s, t, NULL, i); \
} while (0)
#define rwlock_release(l, i) lock_release(l, i)
#define seqcount_acquire(l, s, t, i) lock_acquire_exclusive(l, s, t, NULL, i)
#define seqcount_acquire_read(l, s, t, i) lock_acquire_shared_recursive(l, s, t, NULL, i)
#define seqcount_release(l, i) lock_release(l, i)
#define mutex_acquire(l, s, t, i) lock_acquire_exclusive(l, s, t, NULL, i)
#define mutex_acquire_nest(l, s, t, n, i) lock_acquire_exclusive(l, s, t, n, i)
#define mutex_release(l, i) lock_release(l, i)
#define rwsem_acquire(l, s, t, i) lock_acquire_exclusive(l, s, t, NULL, i)
#define rwsem_acquire_nest(l, s, t, n, i) lock_acquire_exclusive(l, s, t, n, i)
#define rwsem_acquire_read(l, s, t, i) lock_acquire_shared(l, s, t, NULL, i)
#define rwsem_release(l, i) lock_release(l, i)
#define lock_map_acquire(l) lock_acquire_exclusive(l, 0, 0, NULL, _THIS_IP_)
#define lock_map_acquire_try(l) lock_acquire_exclusive(l, 0, 1, NULL, _THIS_IP_)
#define lock_map_acquire_read(l) lock_acquire_shared_recursive(l, 0, 0, NULL, _THIS_IP_)
#define lock_map_acquire_tryread(l) lock_acquire_shared_recursive(l, 0, 1, NULL, _THIS_IP_)
#define lock_map_release(l) lock_release(l, _THIS_IP_)
#define lock_map_sync(l) lock_sync(l, 0, 0, 1, NULL, _THIS_IP_)
#ifdef CONFIG_PROVE_LOCKING
# define might_lock(lock) \
do { \
typecheck(struct lockdep_map *, &(lock)->dep_map); \
lock_acquire(&(lock)->dep_map, 0, 0, 0, 1, NULL, _THIS_IP_); \
lock_release(&(lock)->dep_map, _THIS_IP_); \
} while (0)
# define might_lock_read(lock) \
do { \
typecheck(struct lockdep_map *, &(lock)->dep_map); \
lock_acquire(&(lock)->dep_map, 0, 0, 1, 1, NULL, _THIS_IP_); \
lock_release(&(lock)->dep_map, _THIS_IP_); \
} while (0)
# define might_lock_nested(lock, subclass) \
do { \
typecheck(struct lockdep_map *, &(lock)->dep_map); \
lock_acquire(&(lock)->dep_map, subclass, 0, 1, 1, NULL, \
_THIS_IP_); \
lock_release(&(lock)->dep_map, _THIS_IP_); \
} while (0)
DECLARE_PER_CPU(int, hardirqs_enabled);
DECLARE_PER_CPU(int, hardirq_context);
DECLARE_PER_CPU(unsigned int, lockdep_recursion);
#define __lockdep_enabled (debug_locks && !this_cpu_read(lockdep_recursion))
#define lockdep_assert_irqs_enabled() \
do { \
WARN_ON_ONCE(__lockdep_enabled && !this_cpu_read(hardirqs_enabled)); \
} while (0)
#define lockdep_assert_irqs_disabled() \
do { \
WARN_ON_ONCE(__lockdep_enabled && this_cpu_read(hardirqs_enabled)); \
} while (0)
#define lockdep_assert_in_irq() \
do { \
WARN_ON_ONCE(__lockdep_enabled && !this_cpu_read(hardirq_context)); \
} while (0)
#define lockdep_assert_no_hardirq() \
do { \
WARN_ON_ONCE(__lockdep_enabled && (this_cpu_read(hardirq_context) || \
!this_cpu_read(hardirqs_enabled))); \
} while (0)
#define lockdep_assert_preemption_enabled() \
do { \
WARN_ON_ONCE(IS_ENABLED(CONFIG_PREEMPT_COUNT) && \
__lockdep_enabled && \
(preempt_count() != 0 || \
!this_cpu_read(hardirqs_enabled))); \
} while (0)
#define lockdep_assert_preemption_disabled() \
do { \
WARN_ON_ONCE(IS_ENABLED(CONFIG_PREEMPT_COUNT) && \
__lockdep_enabled && \
(preempt_count() == 0 && \
this_cpu_read(hardirqs_enabled))); \
} while (0)
/*
* Acceptable for protecting per-CPU resources accessed from BH.
* Much like in_softirq() - semantics are ambiguous, use carefully.
*/
#define lockdep_assert_in_softirq() \
do { \
WARN_ON_ONCE(__lockdep_enabled && \
(!in_softirq() || in_irq() || in_nmi())); \
} while (0)
extern void lockdep_assert_in_softirq_func(void);
#else
# define might_lock(lock) do { } while (0)
# define might_lock_read(lock) do { } while (0)
# define might_lock_nested(lock, subclass) do { } while (0)
# define lockdep_assert_irqs_enabled() do { } while (0)
# define lockdep_assert_irqs_disabled() do { } while (0)
# define lockdep_assert_in_irq() do { } while (0)
# define lockdep_assert_no_hardirq() do { } while (0)
# define lockdep_assert_preemption_enabled() do { } while (0)
# define lockdep_assert_preemption_disabled() do { } while (0)
# define lockdep_assert_in_softirq() do { } while (0)
# define lockdep_assert_in_softirq_func() do { } while (0)
#endif
#ifdef CONFIG_PROVE_RAW_LOCK_NESTING
# define lockdep_assert_RT_in_threaded_ctx() do { \
WARN_ONCE(debug_locks && !current->lockdep_recursion && \
lockdep_hardirq_context() && \
!(current->hardirq_threaded || current->irq_config), \
"Not in threaded context on PREEMPT_RT as expected\n"); \
} while (0)
#else
# define lockdep_assert_RT_in_threaded_ctx() do { } while (0)
#endif
#ifdef CONFIG_LOCKDEP
void lockdep_rcu_suspicious(const char *file, const int line, const char *s);
#else
static inline void
lockdep_rcu_suspicious(const char *file, const int line, const char *s)
{
}
#endif
#endif /* __LINUX_LOCKDEP_H */
]
|
| 66/2 |
2026/05/20 08:19 |
llm |
expert |
0m
Model:
Tokens:
input: 54390
output: 20
thoughts: 171
Thoughts: **Analyzing the Lock Contention Macro**
Okay, so I'm looking at this `LOCK_CONTENDED` macro and immediately my brain starts dissecting it. Alright, so we've got the definition here:
```c
#define LOCK_CONTENDED(_lock, try, lock) \
do { \
if (!try(_lock)) { \
lock_contended(&(_lock)->dep_map, _RET_IP_); \
lock(_lock); \
} \
lock_acquired(&(_lock)->dep_map, _RET_IP_); \
} while (0)
```
Essentially, it's a wrapper for dealing with lock contention. It first *attempts* to acquire the lock using `try()`. If that fails, it calls `lock_contended()` which I know from experience, is in `kernel/locking/lockdep.c`. Then the code calls the `lock()` method. Right, so we're flagging the fact that contention existed to `lockdep`. Finally, we have `lock_acquired()` being called. I know that also is in `lockdep.c`. Interesting.
Now, my mind shifts to tracing and debugging. I wonder where the system is reporting the *end* of contention. Hmm, I know `lockdep` can be very useful. I need to find where the `contention_end` tracepoint is called. Let's fire up a `grep` and see if we can locate those calls.
|
| 67/2 |
2026/05/20 08:19 |
tool |
grepper |
0m
Args: map[Expression:trace_contention_end]
Results: map[Output:arch/powerpc/lib/qspinlock.c=712=void __lockfunc queued_spin_lock_slowpath(struct qspinlock *lock)
--
arch/powerpc/lib/qspinlock.c-730- }
arch/powerpc/lib/qspinlock.c:731: trace_contention_end(lock, 0);
arch/powerpc/lib/qspinlock.c-732-}
--
kernel/bpf/rqspinlock.c=348=int __lockfunc resilient_queued_spin_lock_slowpath(rqspinlock_t *lock, u32 val)
--
kernel/bpf/rqspinlock.c-648-release:
kernel/bpf/rqspinlock.c:649: trace_contention_end(lock, 0);
kernel/bpf/rqspinlock.c-650-
--
kernel/bpf/rqspinlock.c-656-err_release_node:
kernel/bpf/rqspinlock.c:657: trace_contention_end(lock, ret);
kernel/bpf/rqspinlock.c-658- __this_cpu_dec(rqnodes[0].mcs.count);
--
kernel/locking/mutex.c=562=__mutex_lock_common(struct mutex *lock, unsigned int state, unsigned int subclass,
--
kernel/locking/mutex.c-606- ww_mutex_set_context_fastpath(ww, ww_ctx);
kernel/locking/mutex.c:607: trace_contention_end(lock, 0);
kernel/locking/mutex.c-608- preempt_enable();
--
kernel/locking/mutex.c-732- lock_acquired(&lock->dep_map, ip);
kernel/locking/mutex.c:733: trace_contention_end(lock, 0);
kernel/locking/mutex.c-734-
--
kernel/locking/mutex.c-747- WARN_ON(__get_task_blocked_on(current));
kernel/locking/mutex.c:748: trace_contention_end(lock, ret);
kernel/locking/mutex.c-749- raw_spin_unlock_irqrestore_wake(&lock->wait_lock, flags, &wake_q);
--
kernel/locking/percpu-rwsem.c=169=bool __sched __percpu_down_read(struct percpu_rw_semaphore *sem, bool try,
--
kernel/locking/percpu-rwsem.c-181- preempt_disable();
kernel/locking/percpu-rwsem.c:182: trace_contention_end(sem, 0);
kernel/locking/percpu-rwsem.c-183-
--
kernel/locking/percpu-rwsem.c=227=void __sched percpu_down_write(struct percpu_rw_semaphore *sem)
--
kernel/locking/percpu-rwsem.c-257- if (contended)
kernel/locking/percpu-rwsem.c:258: trace_contention_end(sem, 0);
kernel/locking/percpu-rwsem.c-259-}
--
kernel/locking/qrwlock.c=21=void __lockfunc queued_read_lock_slowpath(struct qrwlock *lock)
--
kernel/locking/qrwlock.c-57-
kernel/locking/qrwlock.c:58: trace_contention_end(lock, 0);
kernel/locking/qrwlock.c-59-}
--
kernel/locking/qrwlock.c=66=void __lockfunc queued_write_lock_slowpath(struct qrwlock *lock)
--
kernel/locking/qrwlock.c-89-
kernel/locking/qrwlock.c:90: trace_contention_end(lock, 0);
kernel/locking/qrwlock.c-91-}
--
kernel/locking/qspinlock.c=130=void __lockfunc queued_spin_lock_slowpath(struct qspinlock *lock, u32 val)
--
kernel/locking/qspinlock.c-373-release:
kernel/locking/qspinlock.c:374: trace_contention_end(lock, 0);
kernel/locking/qspinlock.c-375-
--
kernel/locking/rtmutex.c=1691=static int __sched __rt_mutex_slowlock(struct rt_mutex_base *lock,
--
kernel/locking/rtmutex.c-1743-
kernel/locking/rtmutex.c:1744: trace_contention_end(lock, ret);
kernel/locking/rtmutex.c-1745-
--
kernel/locking/rtmutex.c=1829=static void __sched rtlock_slowlock_locked(struct rt_mutex_base *lock,
--
kernel/locking/rtmutex.c-1884-
kernel/locking/rtmutex.c:1885: trace_contention_end(lock, 0);
kernel/locking/rtmutex.c-1886- lockevent_cond_inc(rtlock_slow_wake, !wake_q_empty(wake_q));
--
kernel/locking/rwbase_rt.c=68=static int __sched __rwbase_read_lock(struct rwbase_rt *rwb,
--
kernel/locking/rwbase_rt.c-133-
kernel/locking/rwbase_rt.c:134: trace_contention_end(rwb, ret);
kernel/locking/rwbase_rt.c-135- rwbase_post_schedule();
--
kernel/locking/rwbase_rt.c=237=static int __sched rwbase_write_lock(struct rwbase_rt *rwb,
--
kernel/locking/rwbase_rt.c-263- rwbase_post_schedule();
kernel/locking/rwbase_rt.c:264: trace_contention_end(rwb, -EINTR);
kernel/locking/rwbase_rt.c-265- return -EINTR;
--
kernel/locking/rwbase_rt.c-277- rwbase_restore_current_state();
kernel/locking/rwbase_rt.c:278: trace_contention_end(rwb, 0);
kernel/locking/rwbase_rt.c-279-
--
kernel/locking/rwsem.c=993=rwsem_down_read_slowpath(struct rw_semaphore *sem, long count, unsigned int state)
--
kernel/locking/rwsem.c-1095- lockevent_inc(rwsem_rlock);
kernel/locking/rwsem.c:1096: trace_contention_end(sem, 0);
kernel/locking/rwsem.c-1097- return sem;
--
kernel/locking/rwsem.c-1102- lockevent_inc(rwsem_rlock_fail);
kernel/locking/rwsem.c:1103: trace_contention_end(sem, -EINTR);
kernel/locking/rwsem.c-1104- return ERR_PTR(-EINTR);
--
kernel/locking/rwsem.c=1111=rwsem_down_write_slowpath(struct rw_semaphore *sem, int state)
--
kernel/locking/rwsem.c-1197- lockevent_inc(rwsem_wlock);
kernel/locking/rwsem.c:1198: trace_contention_end(sem, 0);
kernel/locking/rwsem.c-1199- return sem;
--
kernel/locking/rwsem.c-1205- lockevent_inc(rwsem_wlock_fail);
kernel/locking/rwsem.c:1206: trace_contention_end(sem, -EINTR);
kernel/locking/rwsem.c-1207- return ERR_PTR(-EINTR);
--
kernel/locking/semaphore.c=285=static inline int __sched __down_common(struct semaphore *sem, long state,
--
kernel/locking/semaphore.c-293- ret = ___down_common(sem, state, timeout);
kernel/locking/semaphore.c:294: trace_contention_end(sem, ret);
kernel/locking/semaphore.c-295-
]
|
| 68/2 |
2026/05/20 08:19 |
llm |
expert |
0m
Model:
Tokens:
input: 57015
output: 45
thoughts: 178
Thoughts: **Tracing Contention in Queued Spinlocks**
Okay, so I see that `trace_contention_end` is called within `queued_spin_lock_slowpath`. Specifically, it looks like this is happening in `kernel/locking/qspinlock.c` right after the lock is released. So, if `raw_spin_lock_irqsave(&loc_l->lock, flags)` goes down the slowpath, then `trace_contention_end` is going to be invoked. I notice this happens *after* the lock acquisition which is crucial for understanding its purpose.
Right, so `queued_spin_lock_slowpath` is actually called from `queued_spin_lock`. I should take a closer look at the implementation of `queued_spin_lock_slowpath` itself in `kernel/locking/qspinlock.c`. This will give me the complete context.
|
| 69/2 |
2026/05/20 08:19 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:kernel/locking/qspinlock.c IncludeLines:true Name:queued_spin_lock_slowpath]
Results: map[SourceCode: 49: static inline void queued_spin_lock_slowpath(struct qspinlock *lock, u32 val)
50: {
51: pv_queued_spin_lock_slowpath(lock, val);
52: }
SourceFile:arch/x86/include/asm/qspinlock.h]
|
| 70/2 |
2026/05/20 08:19 |
llm |
expert |
0m
Model:
Tokens:
input: 57530
output: 45
thoughts: 32
Thoughts: Here's a summary of my thought process:
**Diving into the qspinlock.c Codebase**
Okay, so I need to find where this `queued_spin_lock_slowpath` function is actually defined. I know it's related to queued spinlocks, so logically, I'm thinking it's going to be in the `kernel/locking` directory, probably in a file related to spinlocks. Let me see... yes, `qspinlock.c` seems like the likely candidate. Now I just need to pinpoint the definition within that file, and I'm guessing it will be around line 130. I'll take a quick look to confirm.
|
| 71/2 |
2026/05/20 08:19 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:kernel/locking/qspinlock.c IncludeLines:true Name:queued_spin_lock_slowpath]
Results: map[SourceCode: 49: static inline void queued_spin_lock_slowpath(struct qspinlock *lock, u32 val)
50: {
51: pv_queued_spin_lock_slowpath(lock, val);
52: }
SourceFile:arch/x86/include/asm/qspinlock.h]
|
| 72/2 |
2026/05/20 08:19 |
llm |
expert |
0m
Model:
Tokens:
input: 57854
output: 16
thoughts: 21
Thoughts: Here's a summary of my thought process, as if I were the one thinking it:
**Diving into the QSpinlock Implementation**
Okay, time to get my hands dirty with `kernel/locking/qspinlock.c`. I'm going to jump straight to around line 370. I suspect this is where they're dealing with the core logic of... well, let's see. I'm going to look for any specific locking or unlocking functions and study the assembly. I'm especially keen to see how they handle contention and priority at this level. I want to see how that queuing works, since that's what makes the "q" in qspinlock so interesting. I'm looking for the nitty-gritty details of the memory barriers and atomic operations. I'll probably start by understanding the data structures involved, the layout of the lock, and then I'll trace through the critical path to figure out what's really happening during a lock acquisition under typical conditions, especially when there's contention.
|
| 73/2 |
2026/05/20 08:19 |
tool |
grepper |
0m
Args:
Results: map[Output:
Full output is too long, showing 500 out of 3688 lines.
Use more precise expression if possible.
[Documentation/ABI/testing/sysfs-devices-system-cpu=44=Description: Dynamic addition and removal of CPU's. This is not hotplug
--
Documentation/ABI/testing/sysfs-devices-system-cpu-51-
Documentation/ABI/testing/sysfs-devices-system-cpu:52: release: writes to this file dynamically remove a CPU from
Documentation/ABI/testing/sysfs-devices-system-cpu-53- the system. Information written to the file to remove CPU's
--
Documentation/atomic_t.txt=174=Except of course when a successful operation has an explicit ordering like:
--
Documentation/atomic_t.txt-177- {}_acquire: the R of the RMW (or atomic_read) is an ACQUIRE
Documentation/atomic_t.txt:178: {}_release: the W of the RMW (or atomic_set) is a RELEASE
Documentation/atomic_t.txt-179-
--
Documentation/conf.py=300=def get_cline_version():
--
Documentation/conf.py-313- if c_version:
Documentation/conf.py:314: if c_release:
Documentation/conf.py-315- return c_version + "-" + c_release
--
Documentation/driver-api/cxl/platform/bios-and-efi.rst=44=uefisettings examples
--
Documentation/driver-api/cxl/platform/bios-and-efi.rst-52- bios_version: xxx
Documentation/driver-api/cxl/platform/bios-and-efi.rst:53: bios_release: xxx
Documentation/driver-api/cxl/platform/bios-and-efi.rst-54- bios_date: xxx
--
Documentation/filesystems/locking.rst=47=d_init: no no yes no
Documentation/filesystems/locking.rst:48:d_release: no no yes no
Documentation/filesystems/locking.rst-49-d_prune: no yes no no
--
Documentation/filesystems/locking.rst=454=open: yes
Documentation/filesystems/locking.rst:455:release: yes
Documentation/filesystems/locking.rst-456-ioctl: no
--
Documentation/maintainer/modifying-patches.rst=31=message (just after the subject line) to facilitate tracking. For instance,
Documentation/maintainer/modifying-patches.rst:32:here's what we see in a 3.x-stable release::
Documentation/maintainer/modifying-patches.rst-33-
--
Documentation/misc-devices/xilinx_sdfec.rst=76=application interfaces:
--
Documentation/misc-devices/xilinx_sdfec.rst-78- - open: Implements restriction that only a single file descriptor can be open per SD-FEC instance at any time
Documentation/misc-devices/xilinx_sdfec.rst:79: - release: Allows another file descriptor to be open, that is after current file descriptor is closed
Documentation/misc-devices/xilinx_sdfec.rst-80- - poll: Provides a method to monitor for SD-FEC Error events
--
Documentation/networking/bonding.rst=7=Latest update: 27 April 2011
Documentation/networking/bonding.rst-8-
Documentation/networking/bonding.rst:9:Initial release: Thomas Davis <tadavis at lbl.gov>
Documentation/networking/bonding.rst-10-
--
Documentation/process/debugging/kgdb.rst=449=This is a quick example of how to use kdb with a keyboard.
--
Documentation/process/debugging/kgdb.rst-479-
Documentation/process/debugging/kgdb.rst:480: Press and release: `g`
Documentation/process/debugging/kgdb.rst-481-
--
Documentation/process/debugging/kgdb.rst-489-
Documentation/process/debugging/kgdb.rst:490: Press and release: `g`
Documentation/process/debugging/kgdb.rst-491-
--
Documentation/process/researcher-guidelines.rst=123=For example::
--
Documentation/process/researcher-guidelines.rst-135- developing, LeakMagic[1], which reported the following warning when
Documentation/process/researcher-guidelines.rst:136: analyzing the v5.15 kernel release:
Documentation/process/researcher-guidelines.rst-137-
--
Documentation/translations/sp_SP/process/researcher-guidelines.rst=103=Por ejemplo (en inglés, pues es en las listas)::
--
Documentation/translations/sp_SP/process/researcher-guidelines.rst-115- developing, LeakMagic[1], which reported the following warning when
Documentation/translations/sp_SP/process/researcher-guidelines.rst:116: analyzing the v5.15 kernel release:
Documentation/translations/sp_SP/process/researcher-guidelines.rst-117-
--
Documentation/translations/zh_CN/process/researcher-guidelines.rst=30=Linux 内核社区期望与项目互动的每个人都是真诚地为了使 Linux 变得更好。
--
Documentation/translations/zh_CN/process/researcher-guidelines.rst-101- developing, LeakMagic[1], which reported the following warning when
Documentation/translations/zh_CN/process/researcher-guidelines.rst:102: analyzing the v5.15 kernel release:
Documentation/translations/zh_CN/process/researcher-guidelines.rst-103-
--
Makefile=1252=endif
--
Makefile-1254-# Store (new) KERNELRELEASE string in include/config/kernel.release
Makefile:1255:include/config/kernel.release: FORCE
Makefile-1256- $(call filechk,kernel.release)
--
Makefile=2124=checkstack:
--
Makefile-2127-
Makefile:2128:kernelrelease:
Makefile-2129- @$(filechk_kernel.release)
--
arch/openrisc/kernel/head.S=728=secondary_wait:
--
arch/openrisc/kernel/head.S-760-
arch/openrisc/kernel/head.S:761:secondary_check_release:
arch/openrisc/kernel/head.S-762- /*
--
arch/powerpc/lib/qspinlock.c=527=static __always_inline void queued_spin_lock_mcs_queue(struct qspinlock *lock, bool paravirt)
--
arch/powerpc/lib/qspinlock.c-699-
arch/powerpc/lib/qspinlock.c:700:release:
arch/powerpc/lib/qspinlock.c-701- /*
--
arch/s390/include/asm/eadm.h=85=struct scm_device {
--
arch/s390/include/asm/eadm.h-94- unsigned int rank:4;
arch/s390/include/asm/eadm.h:95: unsigned int release:1;
arch/s390/include/asm/eadm.h-96- unsigned int res_id:8;
--
arch/sparc/kernel/vio.c=500=static int __init vio_init(void)
--
arch/sparc/kernel/vio.c-567-
arch/sparc/kernel/vio.c:568:out_release:
arch/sparc/kernel/vio.c-569- mdesc_release(hp);
--
arch/x86/kernel/cpu/microcode/amd.c=1205=static enum ucode_state request_microcode_amd(int cpu, struct device *device)
--
arch/x86/kernel/cpu/microcode/amd.c-1228-
arch/x86/kernel/cpu/microcode/amd.c:1229: fw_release:
arch/x86/kernel/cpu/microcode/amd.c-1230- release_firmware(fw);
--
block/blk-map.c=273=static int bio_map_user_iov(struct request *rq, struct iov_iter *iter,
--
block/blk-map.c-297-
block/blk-map.c:298:out_release:
block/blk-map.c-299- bio_release_pages(bio, false);
--
drivers/accel/habanalabs/common/habanalabs.h=917=struct hl_mem_mgr_fini_stats {
--
drivers/accel/habanalabs/common/habanalabs.h-930- * @mmap: callback executed on mmap, must map the buffer to vma
drivers/accel/habanalabs/common/habanalabs.h:931: * @release: callback executed on release, must free the resources used by the buffer
drivers/accel/habanalabs/common/habanalabs.h-932- */
--
drivers/accel/habanalabs/common/habanalabs.h=3249=struct eq_heartbeat_debug_info {
--
drivers/accel/habanalabs/common/habanalabs.h-3431- * @is_compute_ctx_active: Whether there is an active compute context executing.
drivers/accel/habanalabs/common/habanalabs.h:3432: * @compute_ctx_in_release: true if the current compute context is being released.
drivers/accel/habanalabs/common/habanalabs.h-3433- * @supports_mmu_prefetch: true if prefetch is supported, otherwise false.
drivers/accel/habanalabs/common/habanalabs.h:3434: * @reset_upon_device_release: reset the device when the user closes the file descriptor of the
drivers/accel/habanalabs/common/habanalabs.h-3435- * device.
--
drivers/accel/ivpu/ivpu_drv.c=97=static void file_priv_release(struct kref *ref)
--
drivers/accel/ivpu/ivpu_drv.c-101-
drivers/accel/ivpu/ivpu_drv.c:102: ivpu_dbg(vdev, FILE, "file_priv release: ctx %u bound %d\n",
drivers/accel/ivpu/ivpu_drv.c-103- file_priv->ctx.id, (bool)file_priv->bound);
--
drivers/accel/ivpu/ivpu_fw.c=396=int ivpu_fw_init(struct ivpu_device *vdev)
--
drivers/accel/ivpu/ivpu_fw.c-417-
drivers/accel/ivpu/ivpu_fw.c:418:err_fw_release:
drivers/accel/ivpu/ivpu_fw.c-419- ivpu_fw_release(vdev);
--
drivers/acpi/apei/einj-core.c=393=static int __einj_error_trigger(u64 trigger_paddr, u32 type,
--
drivers/acpi/apei/einj-core.c-499- apei_exec_post_unmap_gars(&trigger_ctx);
drivers/acpi/apei/einj-core.c:500:out_release:
drivers/acpi/apei/einj-core.c-501- apei_resources_release(&trigger_resources);
--
drivers/acpi/apei/einj-core.c=1027=static int __init einj_probe(struct faux_device *fdev)
--
drivers/acpi/apei/einj-core.c-1118-
drivers/acpi/apei/einj-core.c:1119:err_release:
drivers/acpi/apei/einj-core.c-1120- apei_resources_release(&einj_resources);
--
drivers/acpi/apei/erst.c=1187=static int __init erst_init(void)
--
drivers/acpi/apei/erst.c-1288- apei_exec_post_unmap_gars(&ctx);
drivers/acpi/apei/erst.c:1289:err_release:
drivers/acpi/apei/erst.c-1290- apei_resources_release(&erst_resources);
--
drivers/acpi/ioapic.c=97=static acpi_status handle_ioapic_add(acpi_handle handle, u32 lvl,
--
drivers/acpi/ioapic.c-184-
drivers/acpi/ioapic.c:185:exit_release:
drivers/acpi/ioapic.c-186- if (dev)
--
drivers/android/binder/rust_binder_main.rs=304=unsafe impl<T> Sync for AssertSync<T> {}
--
drivers/android/binder/rust_binder_main.rs-319- open: Some(rust_binder_open),
drivers/android/binder/rust_binder_main.rs:320: release: Some(rust_binder_release),
drivers/android/binder/rust_binder_main.rs-321- flush: Some(rust_binder_flush),
--
drivers/ata/pata_icside.c=480=static int pata_icside_probe(struct expansion_card *ec,
--
drivers/ata/pata_icside.c-548-
drivers/ata/pata_icside.c:549: release:
drivers/ata/pata_icside.c-550- ecard_release_resources(ec);
--
drivers/atm/eni.c=2215=static int eni_init_one(struct pci_dev *pci_dev,
--
drivers/atm/eni.c-2263-
drivers/atm/eni.c:2264:err_eni_release:
drivers/atm/eni.c-2265- dev->phy = NULL;
--
drivers/atm/fore200e.c=2387=static int fore200e_load_and_start_fw(struct fore200e *fore200e)
--
drivers/atm/fore200e.c-2438-
drivers/atm/fore200e.c:2439:release:
drivers/atm/fore200e.c-2440- release_firmware(firmware);
--
drivers/atm/fore200e.c=2696=fore200e_proc_read(struct atm_dev *dev, loff_t* pos, char* page)
--
drivers/atm/fore200e.c-2794- return sprintf(page,
drivers/atm/fore200e.c:2795: " firmware release:\t\t%d.%d.%d\n"
drivers/atm/fore200e.c:2796: " monitor release:\t\t%d.%d\n"
drivers/atm/fore200e.c-2797- " media type:\t\t\t%s\n"
--
drivers/base/attribute_container.c=141=attribute_container_add_device(struct device *dev,
--
drivers/base/attribute_container.c-199- * will not be freed until the classdev is released). If you want a
drivers/base/attribute_container.c:200: * two phase release: remove from visibility and then delete the
drivers/base/attribute_container.c-201- * device, then you should use this routine with a fn that calls
--
drivers/base/component.c=381=static void __component_match_add(struct device *parent,
--
drivers/base/component.c-428- * @matchptr: pointer to the list of component matches
drivers/base/component.c:429: * @release: release function for @compare_data
drivers/base/component.c-430- * @compare: compare function to match against all components
--
drivers/base/devres.c=139=static void replace_dr(struct device *dev,
--
drivers/base/devres.c-148- * __devres_alloc_node - Allocate device resource data
drivers/base/devres.c:149: * @release: Release function devres will be associated with
drivers/base/devres.c-150- * @size: Allocation size
--
drivers/base/devres.c=173=EXPORT_SYMBOL_GPL(__devres_alloc_node);
--
drivers/base/devres.c-177- * @dev: Device to iterate resource from
drivers/base/devres.c:178: * @release: Look for resources associated with this release function
drivers/base/devres.c-179- * @match: Match function (optional)
--
drivers/base/devres.c=254=static struct devres *find_dr(struct device *dev, dr_release_t release,
--
drivers/base/devres.c-274- * @dev: Device to lookup resource from
drivers/base/devres.c:275: * @release: Look for resources associated with this release function
drivers/base/devres.c-276- * @match: Match function (optional)
--
drivers/base/devres.c=335=EXPORT_SYMBOL_GPL(devres_get);
--
drivers/base/devres.c-339- * @dev: Device to find resource from
drivers/base/devres.c:340: * @release: Look for resources associated with this release function
drivers/base/devres.c-341- * @match: Match function (optional)
--
drivers/base/devres.c=370=EXPORT_SYMBOL_GPL(devres_remove);
--
drivers/base/devres.c-374- * @dev: Device to find resource from
drivers/base/devres.c:375: * @release: Look for resources associated with this release function
drivers/base/devres.c-376- * @match: Match function (optional)
--
drivers/base/devres.c=402=EXPORT_SYMBOL_GPL(devres_destroy);
--
drivers/base/devres.c-407- * @dev: Device to find resource from
drivers/base/devres.c:408: * @release: Look for resources associated with this release function
drivers/base/devres.c-409- * @match: Match function (optional)
--
drivers/block/swim3.c=1102=static int swim3_add_device(struct macio_dev *mdev, int index)
--
drivers/block/swim3.c-1182-
drivers/block/swim3.c:1183: out_release:
drivers/block/swim3.c-1184- macio_release_resource(mdev, 0);
--
drivers/bluetooth/bfusb.c=597=static int bfusb_probe(struct usb_interface *intf, const struct usb_device_id *id)
--
drivers/bluetooth/bfusb.c-684-
drivers/bluetooth/bfusb.c:685:release:
drivers/bluetooth/bfusb.c-686- release_firmware(firmware);
--
drivers/bluetooth/btsdio.c=183=static int btsdio_open(struct hci_dev *hdev)
--
drivers/bluetooth/btsdio.c-206-
drivers/bluetooth/btsdio.c:207:release:
drivers/bluetooth/btsdio.c-208- sdio_release_host(data->func);
--
drivers/cdrom/cdrom.c=1144=int cdrom_open(struct cdrom_device_info *cdi, blk_mode_t mode)
--
drivers/cdrom/cdrom.c-1178- return 0;
drivers/cdrom/cdrom.c:1179:err_release:
drivers/cdrom/cdrom.c-1180- if (CDROM_CAN(CDC_LOCK) && cdi->options & CDO_LOCK) {
--
drivers/char/hw_random/nomadik-rng.c=35=static int nmk_rng_probe(struct amba_device *dev, const struct amba_id *id)
--
drivers/char/hw_random/nomadik-rng.c-58-
drivers/char/hw_random/nomadik-rng.c:59:out_release:
drivers/char/hw_random/nomadik-rng.c-60- amba_release_regions(dev);
--
drivers/char/ipmi/ipmi_msghandler.c=1675=int ipmi_register_for_cmd(struct ipmi_user *user,
--
drivers/char/ipmi/ipmi_msghandler.c-1712- kfree(rcvr);
drivers/char/ipmi/ipmi_msghandler.c:1713:out_release:
drivers/char/ipmi/ipmi_msghandler.c-1714- release_ipmi_user(user);
--
drivers/char/tpm/tpm_i2c_infineon.c=613=static int tpm_tis_i2c_init(struct device *dev)
--
drivers/char/tpm/tpm_i2c_infineon.c-656- return tpm_chip_register(chip);
drivers/char/tpm/tpm_i2c_infineon.c:657:out_release:
drivers/char/tpm/tpm_i2c_infineon.c-658- release_locality(chip, tpm_dev.locality, 1);
--
drivers/clk/qcom/gcc-msm8909.c-6- * Copyright 2015 Linaro Limited
drivers/clk/qcom/gcc-msm8909.c:7: * adapted with data from clock-gcc-8909.c in Qualcomm's msm-3.18 release:
drivers/clk/qcom/gcc-msm8909.c-8- * Copyright (c) 2014-2016, The Linux Foundation. All rights reserved.
--
drivers/clk/qcom/gcc-msm8917.c-10- * Copyright 2020 Linaro Limited
drivers/clk/qcom/gcc-msm8917.c:11: * adapted with data from clock-gcc-8952.c in Qualcomm's msm-4.9 release:
drivers/clk/qcom/gcc-msm8917.c-12- * Copyright (c) 2014-2020, The Linux Foundation. All rights reserved.
--
drivers/clk/sophgo/clk-cv18xx-ip.c=739=static int mmux_set_parent(struct clk_hw *hw, u8 index)
--
drivers/clk/sophgo/clk-cv18xx-ip.c-768-
drivers/clk/sophgo/clk-cv18xx-ip.c:769:release:
drivers/clk/sophgo/clk-cv18xx-ip.c-770- return 0;
--
drivers/crypto/cavium/cpt/cptpf_main.c=251=static int cpt_ucode_load_fw(struct cpt_device *cpt, const u8 *fw, bool is_ae)
--
drivers/crypto/cavium/cpt/cptpf_main.c-314-
drivers/crypto/cavium/cpt/cptpf_main.c:315:fw_release:
drivers/crypto/cavium/cpt/cptpf_main.c-316- release_firmware(fw_entry);
--
drivers/crypto/intel/ixp4xx/ixp4xx_crypto.c=453=static int init_ixp_crypto(struct device *dev)
--
drivers/crypto/intel/ixp4xx/ixp4xx_crypto.c-570- dma_pool_destroy(buffer_pool);
drivers/crypto/intel/ixp4xx/ixp4xx_crypto.c:571:npe_release:
drivers/crypto/intel/ixp4xx/ixp4xx_crypto.c-572- npe_release(npe_c);
--
drivers/dma/bestcomm/bestcomm.c=365=static int mpc52xx_bcom_probe(struct platform_device *op)
--
drivers/dma/bestcomm/bestcomm.c-443- iounmap(bcom_eng->regs);
drivers/dma/bestcomm/bestcomm.c:444:error_release:
drivers/dma/bestcomm/bestcomm.c-445- release_mem_region(res_bcom.start, sizeof(struct mpc52xx_sdma));
--
drivers/dma/bestcomm/sram.c=37=int bcom_sram_init(struct device_node *sram_node, char *owner)
--
drivers/dma/bestcomm/sram.c-113-
drivers/dma/bestcomm/sram.c:114:error_release:
drivers/dma/bestcomm/sram.c-115- release_mem_region(res.start, resource_size(&res));
--
drivers/edac/altera_edac.c=249=static int a10_unmask_irq(struct platform_device *pdev, u32 mask)
--
drivers/edac/altera_edac.c-273-
drivers/edac/altera_edac.c:274:release:
drivers/edac/altera_edac.c-275- release_mem_region(A10_SYMAN_INTMASK_CLR, sizeof(u32));
--
drivers/firmware/qemu_fw_cfg.c=442=static const struct sysfs_ops fw_cfg_sysfs_attr_ops = {
--
drivers/firmware/qemu_fw_cfg.c-445-
drivers/firmware/qemu_fw_cfg.c:446:/* release: destructor, to be called via kobject_put() */
drivers/firmware/qemu_fw_cfg.c-447-static void fw_cfg_sysfs_release_entry(struct kobject *kobj)
--
drivers/fsi/fsi-master-aspeed.c=537=static int fsi_master_aspeed_probe(struct platform_device *pdev)
--
drivers/fsi/fsi-master-aspeed.c-641-
drivers/fsi/fsi-master-aspeed.c:642:err_release:
drivers/fsi/fsi-master-aspeed.c-643- clk_disable_unprepare(aspeed->clk);
--
drivers/fsi/fsi-master-hub.c=195=static int hub_master_probe(struct device *dev)
--
drivers/fsi/fsi-master-hub.c-255-
drivers/fsi/fsi-master-hub.c:256:err_release:
drivers/fsi/fsi-master-hub.c-257- fsi_slave_release_range(fsi_dev->slave, FSI_HUB_LINK_OFFSET,
--
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c=169=int amdgpu_amdkfd_reserve_mem_limit(struct amdgpu_device *adev,
--
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c-259-
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c:260:release:
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c-261- spin_unlock(&kfd_mem_limit.mem_limit_lock);
--
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c=265=void amdgpu_amdkfd_unreserve_mem_limit(struct amdgpu_device *adev,
--
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c-304-
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c:305:release:
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c-306- spin_unlock(&kfd_mem_limit.mem_limit_lock);
--
drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c=476=int amdgpu_mca_smu_log_ras_error(struct amdgpu_device *adev, enum amdgpu_ras_block blk, enum amdgpu_mca_error_type type,
--
drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c-505-
drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c:506:out_mca_release:
drivers/gpu/drm/amd/amdgpu/amdgpu_mca.c-507- amdgpu_mca_bank_set_release(&mca_set);
--
drivers/gpu/drm/amd/amdkfd/kfd_queue.c=233=int kfd_queue_acquire_buffers(struct kfd_process_device *pdd, struct queue_properties *properties)
--
drivers/gpu/drm/amd/amdkfd/kfd_queue.c-331- amdgpu_bo_unreserve(vm->root.bo);
drivers/gpu/drm/amd/amdkfd/kfd_queue.c:332:out_err_release:
drivers/gpu/drm/amd/amdkfd/kfd_queue.c-333- /* FIXME: make a _locked version of this that can be called before
--
drivers/gpu/drm/amd/display/dmub/inc/dmub_cmd.h=1352=union dmub_inbox0_cmd_lock_hw {
--
drivers/gpu/drm/amd/display/dmub/inc/dmub_cmd.h-1370- uint32_t lock: 1; /**< Lock */
drivers/gpu/drm/amd/display/dmub/inc/dmub_cmd.h:1371: uint32_t should_release: 1; /**< Release */
drivers/gpu/drm/amd/display/dmub/inc/dmub_cmd.h-1372- uint32_t reserved: 7; /**< Reserved for extending more clients, HW, etc. */
--
drivers/gpu/drm/amd/display/modules/color/color_gamma.c=397=static bool build_coefficients(struct gamma_coefficients *coefficients,
--
drivers/gpu/drm/amd/display/modules/color/color_gamma.c-433- } while (i != ARRAY_SIZE(coefficients->a0));
drivers/gpu/drm/amd/display/modules/color/color_gamma.c:434:release:
drivers/gpu/drm/amd/display/modules/color/color_gamma.c-435- return ret;
--
drivers/gpu/drm/amd/display/modules/color/color_gamma.c=923=static bool build_regamma(struct pwl_float_data_ex *rgb_regamma,
--
drivers/gpu/drm/amd/display/modules/color/color_gamma.c-958- ret = true;
drivers/gpu/drm/amd/display/modules/color/color_gamma.c:959:release:
drivers/gpu/drm/amd/display/modules/color/color_gamma.c-960- kvfree(coeff);
--
drivers/gpu/drm/amd/display/modules/color/color_gamma.c=1180=static bool build_degamma(struct pwl_float_data_ex *curve,
--
drivers/gpu/drm/amd/display/modules/color/color_gamma.c-1220- ret = true;
drivers/gpu/drm/amd/display/modules/color/color_gamma.c:1221:release:
drivers/gpu/drm/amd/display/modules/color/color_gamma.c-1222- return ret;
--
drivers/gpu/drm/armada/armada_gem.c=386=armada_gem_prime_map_dma_buf(struct dma_buf_attachment *attach,
--
drivers/gpu/drm/armada/armada_gem.c-440-
drivers/gpu/drm/armada/armada_gem.c:441: release:
drivers/gpu/drm/armada/armada_gem.c-442- for_each_sgtable_sg(sgt, sg, i)
--
drivers/gpu/drm/ci/build.yml=144=debian-arm64-build-test:
--
drivers/gpu/drm/ci/build.yml-147-
drivers/gpu/drm/ci/build.yml:148:debian-arm64-release:
drivers/gpu/drm/ci/build.yml-149- rules:
--
drivers/gpu/drm/ci/build.yml=160=debian-clang:
--
drivers/gpu/drm/ci/build.yml-163-
drivers/gpu/drm/ci/build.yml:164:debian-clang-release:
drivers/gpu/drm/ci/build.yml-165- rules:
--
drivers/gpu/drm/ci/build.yml=172=debian-ppc64el:
--
drivers/gpu/drm/ci/build.yml-175-
drivers/gpu/drm/ci/build.yml:176:debian-release:
drivers/gpu/drm/ci/build.yml-177- rules:
--
drivers/gpu/drm/ci/build.yml=204=debian-x86_32:
--
drivers/gpu/drm/ci/build.yml-207-
drivers/gpu/drm/ci/build.yml:208:fedora-release:
drivers/gpu/drm/ci/build.yml-209- rules:
--
drivers/gpu/drm/drm_fb_helper.c=507=struct fb_info *drm_fb_helper_alloc_info(struct drm_fb_helper *fb_helper)
--
drivers/gpu/drm/drm_fb_helper.c-529-
drivers/gpu/drm/drm_fb_helper.c:530:err_release:
drivers/gpu/drm/drm_fb_helper.c-531- framebuffer_release(info);
--
drivers/gpu/drm/drm_gem_shmem_helper.c=52=__drm_gem_shmem_create(struct drm_device *dev, size_t size, bool private,
--
drivers/gpu/drm/drm_gem_shmem_helper.c-106-
drivers/gpu/drm/drm_gem_shmem_helper.c:107:err_release:
drivers/gpu/drm/drm_gem_shmem_helper.c-108- drm_gem_object_release(obj);
--
drivers/gpu/drm/i915/gt/intel_context.c=219=int __intel_context_do_pin_ww(struct intel_context *ce,
--
drivers/gpu/drm/i915/gt/intel_context.c-292- mutex_unlock(&ce->pin_mutex);
drivers/gpu/drm/i915/gt/intel_context.c:293:err_release:
drivers/gpu/drm/i915/gt/intel_context.c-294- i915_active_release(&ce->active);
--
drivers/gpu/drm/i915/i915_scatterlist.h=168=struct i915_refct_sgt_ops {
drivers/gpu/drm/i915/i915_scatterlist.h-169- /**
drivers/gpu/drm/i915/i915_scatterlist.h:170: * @release: Free the memory of the struct i915_refct_sgt
drivers/gpu/drm/i915/i915_scatterlist.h-171- */
--
drivers/gpu/drm/i915/intel_memory_region.c=247=intel_memory_region_create(struct drm_i915_private *i915,
--
drivers/gpu/drm/i915/intel_memory_region.c-290-
drivers/gpu/drm/i915/intel_memory_region.c:291:err_release:
drivers/gpu/drm/i915/intel_memory_region.c-292- if (mem->ops->release)
--
drivers/gpu/drm/imagination/pvr_fw.c=939=pvr_fw_init(struct pvr_device *pvr_dev)
--
drivers/gpu/drm/imagination/pvr_fw.c-1015-
drivers/gpu/drm/imagination/pvr_fw.c:1016:err_kccb_rtn_release:
drivers/gpu/drm/imagination/pvr_fw.c-1017- pvr_fw_object_unmap_and_destroy(pvr_dev->kccb.rtn_obj);
--
drivers/gpu/drm/msm/disp/dpu1/dpu_core_perf.h=31=struct dpu_core_perf_tune {
--
drivers/gpu/drm/msm/disp/dpu1/dpu_core_perf.h-40- * @perf_tune: debug control for performance tuning
drivers/gpu/drm/msm/disp/dpu1/dpu_core_perf.h:41: * @enable_bw_release: debug control for bandwidth release
drivers/gpu/drm/msm/disp/dpu1/dpu_core_perf.h-42- * @fix_core_clk_rate: fixed core clock request in Hz used in mode 2
--
drivers/gpu/drm/nouveau/nouveau_dmem.c=228=nouveau_dmem_chunk_alloc(struct nouveau_drm *drm, struct page **ppage)
--
drivers/gpu/drm/nouveau/nouveau_dmem.c-291- nouveau_bo_unpin_del(&chunk->bo);
drivers/gpu/drm/nouveau/nouveau_dmem.c:292:out_release:
drivers/gpu/drm/nouveau/nouveau_dmem.c-293- release_mem_region(chunk->pagemap.range.start, range_len(&chunk->pagemap.range));
--
drivers/gpu/drm/nouveau/nvkm/subdev/pmu/fuc/i2c_.fuc=289=i2c_acquire:
--
drivers/gpu/drm/nouveau/nvkm/subdev/pmu/fuc/i2c_.fuc-295-
drivers/gpu/drm/nouveau/nvkm/subdev/pmu/fuc/i2c_.fuc:296:i2c_release:
drivers/gpu/drm/nouveau/nvkm/subdev/pmu/fuc/i2c_.fuc-297- call(i2c_acquire_addr)
--
drivers/gpu/drm/omapdrm/omap_gem.c=1281=struct drm_gem_object *omap_gem_new(struct drm_device *dev,
--
drivers/gpu/drm/omapdrm/omap_gem.c-1375-
drivers/gpu/drm/omapdrm/omap_gem.c:1376:err_release:
drivers/gpu/drm/omapdrm/omap_gem.c-1377- drm_gem_object_release(obj);
--
drivers/gpu/drm/qxl/qxl_display.c=488=static int qxl_primary_apply_cursor(struct qxl_device *qdev,
--
drivers/gpu/drm/qxl/qxl_display.c-527-
drivers/gpu/drm/qxl/qxl_display.c:528:out_free_release:
drivers/gpu/drm/qxl/qxl_display.c-529- qxl_release_free(qdev, release);
--
drivers/gpu/drm/qxl/qxl_ioctl.c=139=static int qxl_process_single_command(struct qxl_device *qdev,
]
]
|
| 74/2 |
2026/05/20 08:19 |
llm |
expert |
0m
Model:
Tokens:
input: 68517
output: 43
thoughts: 1001
Thoughts: **Recursive Locking Vulnerability in BPF Tracepoint Handling**
Okay, let's break this down. It seems `trace_contention_end` is getting called within `queued_spin_lock_slowpath`, which in turn is called from `queued_spin_lock` and eventually from `do_raw_spin_lock` when dealing with contended locks. The key here is that `trace_contention_end` is a tracepoint, and if `CONFIG_LOCK_STAT` isn't defined, which is often the default, `LOCK_CONTENDED` just ends up calling `do_raw_spin_lock` directly. This leads to `trace_contention_end` being called **while the lock is already held**.
Now, if a BPF program is attached to the `contention_end` tracepoint, and that BPF program calls `bpf_map_delete_elem`, we have a problem. `bpf_map_delete_elem` can call `bpf_lru_push_free`, which attempts to acquire the lock (`loc_l->lock`) *again*. The stack trace confirms this: the task already has the lock from `bpf_common_lru_pop_free`, it goes to the contended path, triggers the tracepoint, the BPF program gets executed, and within that execution, it tries to re-acquire the *same* lock in `bpf_lru_push_free`. Boom, recursive locking! It's a classic deadlock situation.
The system will hang.
So, this looks like a serious bug in the BPF handling around tracepoints.
My initial thought was that this could be a security vulnerability, thinking that a non-root user could attach a BPF program to a tracepoint. However, after further thought, attaching to a tracepoint *does* require privileges, specifically `CAP_PERFMON` or `CAP_SYS_ADMIN`. That said, if the BPF program exists, a deadlock can happen.
|
| 75/2 |
2026/05/20 08:19 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:kernel/bpf/syscall.c IncludeLines:true Name:bpf_prog_load]
Results: map[SourceCode:2859: static int bpf_prog_load(union bpf_attr *attr, bpfptr_t uattr, u32 uattr_size)
2860: {
2861: enum bpf_prog_type type = attr->prog_type;
2862: struct bpf_prog *prog, *dst_prog = NULL;
2863: struct btf *attach_btf = NULL;
2864: struct bpf_token *token = NULL;
2865: bool bpf_cap;
2866: int err;
2867: char license[128];
2868:
2869: if (CHECK_ATTR(BPF_PROG_LOAD))
2870: return -EINVAL;
2871:
2872: if (attr->prog_flags & ~(BPF_F_STRICT_ALIGNMENT |
2873: BPF_F_ANY_ALIGNMENT |
2874: BPF_F_TEST_STATE_FREQ |
2875: BPF_F_SLEEPABLE |
2876: BPF_F_TEST_RND_HI32 |
2877: BPF_F_XDP_HAS_FRAGS |
2878: BPF_F_XDP_DEV_BOUND_ONLY |
2879: BPF_F_TEST_REG_INVARIANTS |
2880: BPF_F_TOKEN_FD))
2881: return -EINVAL;
2882:
2883: bpf_prog_load_fixup_attach_type(attr);
2884:
2885: if (attr->prog_flags & BPF_F_TOKEN_FD) {
2886: token = bpf_token_get_from_fd(attr->prog_token_fd);
2887: if (IS_ERR(token))
2888: return PTR_ERR(token);
2889: /* if current token doesn't grant prog loading permissions,
2890: * then we can't use this token, so ignore it and rely on
2891: * system-wide capabilities checks
2892: */
2893: if (!bpf_token_allow_cmd(token, BPF_PROG_LOAD) ||
2894: !bpf_token_allow_prog_type(token, attr->prog_type,
2895: attr->expected_attach_type)) {
2896: bpf_token_put(token);
2897: token = NULL;
2898: }
2899: }
2900:
2901: bpf_cap = bpf_token_capable(token, CAP_BPF);
2902: err = -EPERM;
2903:
2904: if (!IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) &&
2905: (attr->prog_flags & BPF_F_ANY_ALIGNMENT) &&
2906: !bpf_cap)
2907: goto put_token;
2908:
2909: /* Intent here is for unprivileged_bpf_disabled to block BPF program
2910: * creation for unprivileged users; other actions depend
2911: * on fd availability and access to bpffs, so are dependent on
2912: * object creation success. Even with unprivileged BPF disabled,
2913: * capability checks are still carried out for these
2914: * and other operations.
2915: */
2916: if (sysctl_unprivileged_bpf_disabled && !bpf_cap)
2917: goto put_token;
2918:
2919: if (attr->insn_cnt == 0 ||
2920: attr->insn_cnt > (bpf_cap ? BPF_COMPLEXITY_LIMIT_INSNS : BPF_MAXINSNS)) {
2921: err = -E2BIG;
2922: goto put_token;
2923: }
2924: if (type != BPF_PROG_TYPE_SOCKET_FILTER &&
2925: type != BPF_PROG_TYPE_CGROUP_SKB &&
2926: !bpf_cap)
2927: goto put_token;
2928:
2929: if (is_net_admin_prog_type(type) && !bpf_token_capable(token, CAP_NET_ADMIN))
2930: goto put_token;
2931: if (is_perfmon_prog_type(type) && !bpf_token_capable(token, CAP_PERFMON))
2932: goto put_token;
2933:
2934: /* attach_prog_fd/attach_btf_obj_fd can specify fd of either bpf_prog
2935: * or btf, we need to check which one it is
2936: */
2937: if (attr->attach_prog_fd) {
2938: dst_prog = bpf_prog_get(attr->attach_prog_fd);
2939: if (IS_ERR(dst_prog)) {
2940: dst_prog = NULL;
2941: attach_btf = btf_get_by_fd(attr->attach_btf_obj_fd);
2942: if (IS_ERR(attach_btf)) {
2943: err = -EINVAL;
2944: goto put_token;
2945: }
2946: if (!btf_is_kernel(attach_btf)) {
2947: /* attaching through specifying bpf_prog's BTF
2948: * objects directly might be supported eventually
2949: */
2950: btf_put(attach_btf);
2951: err = -ENOTSUPP;
2952: goto put_token;
2953: }
2954: }
2955: } else if (attr->attach_btf_id) {
2956: /* fall back to vmlinux BTF, if BTF type ID is specified */
2957: attach_btf = bpf_get_btf_vmlinux();
2958: if (IS_ERR(attach_btf)) {
2959: err = PTR_ERR(attach_btf);
2960: goto put_token;
2961: }
2962: if (!attach_btf) {
2963: err = -EINVAL;
2964: goto put_token;
2965: }
2966: btf_get(attach_btf);
2967: }
2968:
2969: if (bpf_prog_load_check_attach(type, attr->expected_attach_type,
2970: attach_btf, attr->attach_btf_id,
2971: dst_prog)) {
2972: if (dst_prog)
2973: bpf_prog_put(dst_prog);
2974: if (attach_btf)
2975: btf_put(attach_btf);
2976: err = -EINVAL;
2977: goto put_token;
2978: }
2979:
2980: /* plain bpf_prog allocation */
2981: prog = bpf_prog_alloc(bpf_prog_size(attr->insn_cnt), GFP_USER);
2982: if (!prog) {
2983: if (dst_prog)
2984: bpf_prog_put(dst_prog);
2985: if (attach_btf)
2986: btf_put(attach_btf);
2987: err = -EINVAL;
2988: goto put_token;
2989: }
2990:
2991: prog->expected_attach_type = attr->expected_attach_type;
2992: prog->sleepable = !!(attr->prog_flags & BPF_F_SLEEPABLE);
2993: prog->aux->attach_btf = attach_btf;
2994: prog->aux->attach_btf_id = attr->attach_btf_id;
2995: prog->aux->dst_prog = dst_prog;
2996: prog->aux->dev_bound = !!attr->prog_ifindex;
2997: prog->aux->xdp_has_frags = attr->prog_flags & BPF_F_XDP_HAS_FRAGS;
2998:
2999: /* move token into prog->aux, reuse taken refcnt */
3000: prog->aux->token = token;
3001: token = NULL;
3002:
3003: prog->aux->user = get_current_user();
3004: prog->len = attr->insn_cnt;
3005:
3006: err = -EFAULT;
3007: if (copy_from_bpfptr(prog->insns,
3008: make_bpfptr(attr->insns, uattr.is_kernel),
3009: bpf_prog_insn_size(prog)) != 0)
3010: goto free_prog;
3011: /* copy eBPF program license from user space */
3012: if (strncpy_from_bpfptr(license,
3013: make_bpfptr(attr->license, uattr.is_kernel),
3014: sizeof(license) - 1) < 0)
3015: goto free_prog;
3016: license[sizeof(license) - 1] = 0;
3017:
3018: /* eBPF programs must be GPL compatible to use GPL-ed functions */
3019: prog->gpl_compatible = license_is_gpl_compatible(license) ? 1 : 0;
3020:
3021: if (attr->signature) {
3022: err = bpf_prog_verify_signature(prog, attr, uattr.is_kernel);
3023: if (err)
3024: goto free_prog;
3025: }
3026:
3027: prog->orig_prog = NULL;
3028: prog->jited = 0;
3029:
3030: atomic64_set(&prog->aux->refcnt, 1);
3031:
3032: if (bpf_prog_is_dev_bound(prog->aux)) {
3033: err = bpf_prog_dev_bound_init(prog, attr);
3034: if (err)
3035: goto free_prog;
3036: }
3037:
3038: if (type == BPF_PROG_TYPE_EXT && dst_prog &&
3039: bpf_prog_is_dev_bound(dst_prog->aux)) {
3040: err = bpf_prog_dev_bound_inherit(prog, dst_prog);
3041: if (err)
3042: goto free_prog;
3043: }
3044:
3045: /*
3046: * Bookkeeping for managing the program attachment chain.
3047: *
3048: * It might be tempting to set attach_tracing_prog flag at the attachment
3049: * time, but this will not prevent from loading bunch of tracing prog
3050: * first, then attach them one to another.
3051: *
3052: * The flag attach_tracing_prog is set for the whole program lifecycle, and
3053: * doesn't have to be cleared in bpf_tracing_link_release, since tracing
3054: * programs cannot change attachment target.
3055: */
3056: if (type == BPF_PROG_TYPE_TRACING && dst_prog &&
3057: dst_prog->type == BPF_PROG_TYPE_TRACING) {
3058: prog->aux->attach_tracing_prog = true;
3059: }
3060:
3061: /* find program type: socket_filter vs tracing_filter */
3062: err = find_prog_type(type, prog);
3063: if (err < 0)
3064: goto free_prog;
3065:
3066: prog->aux->load_time = ktime_get_boottime_ns();
3067: err = bpf_obj_name_cpy(prog->aux->name, attr->prog_name,
3068: sizeof(attr->prog_name));
3069: if (err < 0)
3070: goto free_prog;
3071:
3072: err = security_bpf_prog_load(prog, attr, token, uattr.is_kernel);
3073: if (err)
3074: goto free_prog_sec;
3075:
3076: /* run eBPF verifier */
3077: err = bpf_check(&prog, attr, uattr, uattr_size);
3078: if (err < 0)
3079: goto free_used_maps;
3080:
3081: prog = bpf_prog_select_runtime(prog, &err);
3082: if (err < 0)
3083: goto free_used_maps;
3084:
3085: err = bpf_prog_alloc_id(prog);
3086: if (err)
3087: goto free_used_maps;
3088:
3089: /* Upon success of bpf_prog_alloc_id(), the BPF prog is
3090: * effectively publicly exposed. However, retrieving via
3091: * bpf_prog_get_fd_by_id() will take another reference,
3092: * therefore it cannot be gone underneath us.
3093: *
3094: * Only for the time /after/ successful bpf_prog_new_fd()
3095: * and before returning to userspace, we might just hold
3096: * one reference and any parallel close on that fd could
3097: * rip everything out. Hence, below notifications must
3098: * happen before bpf_prog_new_fd().
3099: *
3100: * Also, any failure handling from this point onwards must
3101: * be using bpf_prog_put() given the program is exposed.
3102: */
3103: bpf_prog_kallsyms_add(prog);
3104: perf_event_bpf_event(prog, PERF_BPF_EVENT_PROG_LOAD, 0);
3105: bpf_audit_prog(prog, BPF_AUDIT_LOAD);
3106:
3107: err = bpf_prog_new_fd(prog);
3108: if (err < 0)
3109: bpf_prog_put(prog);
3110: return err;
3111:
3112: free_used_maps:
3113: /* In case we have subprogs, we need to wait for a grace
3114: * period before we can tear down JIT memory since symbols
3115: * are already exposed under kallsyms.
3116: */
3117: __bpf_prog_put_noref(prog, prog->aux->real_func_cnt);
3118: return err;
3119:
3120: free_prog_sec:
3121: security_bpf_prog_free(prog);
3122: free_prog:
3123: free_uid(prog->aux->user);
3124: if (prog->aux->attach_btf)
3125: btf_put(prog->aux->attach_btf);
3126: bpf_prog_free(prog);
3127: put_token:
3128: bpf_token_put(token);
3129: return err;
3130: }
SourceFile:kernel/bpf/syscall.c]
|
| 76/2 |
2026/05/20 08:19 |
llm |
expert |
0m
Model:
Tokens:
input: 74471
output: 45
thoughts: 27
Thoughts: Okay, here's my interpretation of that thought process, assuming I'm already deep in the weeds of performance monitoring and capability checks:
**Analyzing the `is_perfmon_prog_type(type)` Function Call**
Alright, let's break this down. So, `is_perfmon_prog_type(type)`... that's the key function here. I'm immediately thinking about how it's used and what it *means* within the larger context of program type handling. The name itself is fairly transparent – it's designed to determine if a given `type` of program is going to need performance monitoring capabilities. And by "performance monitoring capabilities" we're talking about the low-level stuff, the ability to tap into the system's performance counters.
So, the critical check is whether or not this `type` necessitates the `CAP_PERFMON` capability. That's it, that's the core question that this function needs to resolve. Everything hinges on whether the program will require that specific capability in order to do its job. It's essentially a gatekeeper function, deciding if a more privileged access is needed before the program can do its thing. My mind's now racing through the various program types and what they do. Which ones are going to involve reading performance data? Which ones are going to be safe to run without that capability? It's all about minimizing privilege and ensuring security.
|
| 77/2 |
2026/05/20 08:19 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:kernel/bpf/syscall.c IncludeLines:true Name:is_perfmon_prog_type]
Results: map[SourceCode:2802: static bool is_perfmon_prog_type(enum bpf_prog_type prog_type)
2803: {
2804: switch (prog_type) {
2805: case BPF_PROG_TYPE_KPROBE:
2806: case BPF_PROG_TYPE_TRACEPOINT:
2807: case BPF_PROG_TYPE_PERF_EVENT:
2808: case BPF_PROG_TYPE_RAW_TRACEPOINT:
2809: case BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE:
2810: case BPF_PROG_TYPE_TRACING:
2811: case BPF_PROG_TYPE_LSM:
2812: case BPF_PROG_TYPE_STRUCT_OPS: /* has access to struct sock */
2813: case BPF_PROG_TYPE_EXT: /* extends any prog */
2814: return true;
2815: default:
2816: return false;
2817: }
2818: }
SourceFile:kernel/bpf/syscall.c]
|
| 78/2 |
2026/05/20 08:19 |
llm |
expert |
0m
Model:
Tokens:
input: 75166
output: 51
thoughts: 703
Thoughts: **Analyzing the Vulnerability Scenario**
Okay, so the prompt is clear: a typical, unprivileged user process. That means no special capabilities like `CAP_PERFMON`, `CAP_SYS_ADMIN`, etc., and no access to restricted device nodes. Alright, let's start dissecting this. First, it's pretty obvious that loading a `BPF_PROG_TYPE_RAW_TRACEPOINT` program is out. That immediately requires `CAP_PERFMON`. I recall that `bpf_token_capable` does the check, looking at either `capable(CAP_PERFMON)` or `ns_capable(token->userns, CAP_PERFMON)`. But we are assuming user namespaces aren't accessible, so no dice.
The key question is, can a non-root user trigger this bug *some other way*? Let's consider `contention_end`, the likely tracepoint mentioned in the bug report. Tracepoints are just hooks; they don't *do* anything on their own. They need a BPF program or a perf event attached. Can a non-root user attach a perf event to `contention_end`? No, because perf events on tracepoints require `CAP_PERFMON` or `perf_event_paranoid <= -1`. That's blocked by default; `perf_event_paranoid` is usually 2, so that's a dead end. Furthermore, even *if* a perf event *could* attach, it would just record data, not call the vulnerable function. To execute the code we must have a BPF program. And loading a BPF program requires `CAP_PERFMON`.
Hold on... what if root loads the BPF program, and a non-root user triggers it? Okay, if root loads a BPF program that attaches to `contention_end` and calls `bpf_map_delete_elem`, *any* user that causes lock contention on `loc_l->lock` will trigger the deadlock! Is that a "vulnerability" in the traditional sense? Not really, because root is in control.
But here's a wrinkle... what if the BPF program *isn't* malicious? What if it's just a regular tracing program? Say, it's a BPF program that uses LRU maps and happens to call `bpf_map_update_elem` or `bpf_map_delete_elem` on the LRU map. If that innocent-looking program is attached to a tracepoint like `contention_end` – a tracepoint that is called while *holding* `loc_l->lock` – boom, deadlock! The problem isn't the malicious BPF program, the problem is that the program could perform those actions while the lock is already held. The real issue is that `bpf_common_lru_pop_free` *acquires* `loc_l->lock`, so we have a good clue. We need to confirm whether `loc_l->lock` is a raw spinlock or a normal spinlock. That will tell us where the kernel can and can't be pre-empted, and what the root cause of the deadlock might be. Time to look at the `struct bpf_lru_locallist` definition.
|
| 79/2 |
2026/05/20 08:20 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:kernel/bpf/bpf_lru_list.h IncludeLines:true Name:bpf_lru_locallist]
Results: map[SourceCode: 40: struct bpf_lru_locallist {
41: struct list_head lists[NR_BPF_LRU_LOCAL_LIST_T];
42: u16 next_steal;
43: raw_spinlock_t lock;
44: };
SourceFile:kernel/bpf/bpf_lru_list.h]
|
| 80/2 |
2026/05/20 08:20 |
llm |
expert |
0m
Model:
Tokens:
input: 76739
output: 50
thoughts: 963
Thoughts: **Deadlock Vulnerability in BPF Tracing with LRU Maps**
Okay, so I've been digging into a potential deadlock issue within the BPF (Berkeley Packet Filter) tracing framework. I'm focusing on how `raw_spinlock_t` and LRU (Least Recently Used) maps interact, specifically through the `contention_end` tracepoint.
Here's the scenario: a `raw_spinlock_t` experiences contention, triggering a chain of calls that eventually leads to the `trace_contention_end` tracepoint. Now, a BPF program can be attached to this tracepoint via `BPF_PROG_TYPE_RAW_TRACEPOINT` or `BPF_PROG_TYPE_TRACING`, assuming the user has `CAP_PERFMON` or `CAP_SYS_ADMIN` privileges.
The problem lies with using LRU maps within the BPF program. Specifically, if a BPF program attached to `contention_end` calls `bpf_map_delete_elem` on an LRU map, it can call `htab_lru_map_delete_elem`, which calls `bpf_lru_push_free`, which in turn, tries to acquire `loc_l->lock`. *This is where the trouble begins*.
The core issue is that `loc_l->lock` is a per-CPU lock. If the `raw_spinlock_t` that experienced contention *happens* to be the *same* lock as `loc_l->lock` for the *current CPU*, a deadlock *will* occur. Because the traced context already holds the same lock, and the BPF program, trying to release an element from the LRU map, tries to reacquire the same lock for the same CPU!
The implications are serious. Any privileged user running a tracing tool (e.g., `bpftrace`, `bcc`) that:
1. traces lock contention,
2. uses an LRU map to store data, and
3. updates *any* element in that LRU map
can trigger a system-wide deadlock. This effectively turns a legitimate tracing tool into a denial-of-service vulnerability.
This differs from typical BPF deadlock scenarios. Those usually involve recursive BPF program execution, which the kernel tries to prevent using mechanisms like `bpf_prog_active`. In this case, there's no recursion. It's the BPF program acquiring a lock that the tracing context *already* holds that causes the problem.
The verifier does a good job of checking which helpers are called, but it doesn't know about locks held when a tracepoint is triggered. BPF tracing programs are executed with `rcu_read_lock` and cannot sleep, but they can use maps. If an LRU map is used by a tracing program that's triggered when holding a `loc_l->lock`, boom, it deadlocks.
Is this limited to `loc_l->lock`? If a tracepoint is triggered while holding `htab->bucket_lock` (acquired by `htab_lock_bucket`), and the BPF program updates the *same* bucket, it deadlocks. However, `htab_lock_bucket` is a fine grained lock. Updating a *different* bucket is safe.
But, `loc_l->lock` is *per-CPU*, so *any* LRU map operation on the same CPU will try to acquire *the same* `loc_l->lock`! Because `loc_l` is shared across all LRU maps, if I'm understanding this correctly. I need to confirm if `loc_l` is indeed shared across all LRU maps...
|
| 81/2 |
2026/05/20 08:20 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:kernel/bpf/bpf_lru_list.c IncludeLines:true Name:bpf_lru_init]
Results: map[SourceCode: 646: int bpf_lru_init(struct bpf_lru *lru, bool percpu, u32 hash_offset,
647: del_from_htab_func del_from_htab, void *del_arg)
648: {
649: int cpu;
650:
651: if (percpu) {
652: lru->percpu_lru = alloc_percpu(struct bpf_lru_list);
653: if (!lru->percpu_lru)
654: return -ENOMEM;
655:
656: for_each_possible_cpu(cpu) {
657: struct bpf_lru_list *l;
658:
659: l = per_cpu_ptr(lru->percpu_lru, cpu);
660: bpf_lru_list_init(l);
661: }
662: lru->nr_scans = PERCPU_NR_SCANS;
663: } else {
664: struct bpf_common_lru *clru = &lru->common_lru;
665:
666: clru->local_list = alloc_percpu(struct bpf_lru_locallist);
667: if (!clru->local_list)
668: return -ENOMEM;
669:
670: for_each_possible_cpu(cpu) {
671: struct bpf_lru_locallist *loc_l;
672:
673: loc_l = per_cpu_ptr(clru->local_list, cpu);
674: bpf_lru_locallist_init(loc_l, cpu);
675: }
676:
677: bpf_lru_list_init(&clru->lru_list);
678: lru->nr_scans = LOCAL_NR_SCANS;
679: }
680:
681: lru->percpu = percpu;
682: lru->del_from_htab = del_from_htab;
683: lru->del_arg = del_arg;
684: lru->hash_offset = hash_offset;
685:
686: return 0;
687: }
SourceFile:kernel/bpf/bpf_lru_list.c]
|
| 82/2 |
2026/05/20 08:20 |
llm |
expert |
0m
Model:
Tokens:
input: 79255
output: 46
thoughts: 727
Thoughts: **Analyzing a Potential Kernel Deadlock**
Okay, let's break this down. My initial thought was about how `clru->local_list` is allocated. It's allocated per `struct bpf_lru`, meaning each LRU map has its *own* `local_list`. Ah, got it. `clru->local_list = alloc_percpu(struct bpf_lru_locallist);` So `loc_l` isn't shared *across* different LRU maps.
That immediately shifted my focus: if it's not shared, then the BPF program must be updating *the same* LRU map that triggered the tracepoint. Let's re-examine the reproducer. It creates *one* LRU map. Then loads a BPF program that updates that same LRU map. This program is attached to `contention_end`. And then `bpf$MAP_UPDATE_BATCH` is called on *that same* LRU map.
Looking at the `bpf$MAP_UPDATE_BATCH` arguments, specifically the `map_fd`, it confirms the target map. This means the reproducer is generating lock contention on the LRU map by calling `MAP_UPDATE_BATCH` with a significant count (0xadc). This will trigger multiple updates, each acquiring `loc_l->lock`. If there's contention – maybe due to background threads or the way `MAP_UPDATE_BATCH` operates – it triggers `contention_end`. And the BPF program attached to `contention_end` then calls `bpf_map_update_elem` on the *same* LRU map!
That's the crux of it. The program tries to acquire the *same* `loc_l->lock` – and that's the deadlock. This is a potential bug. A BPF program *can* deadlock the kernel if it updates the same map that triggered the tracepoint. Though, it's generally allowed from tracing programs, but specific lock contention leads to deadlock.
Now, is this exploitable by an unprivileged user? No, because attaching to `contention_end` requires `CAP_PERFMON` or `CAP_SYS_ADMIN`. However, what if root has already attached the tracing program? If root attaches a tracing program to `contention_end` that updates an LRU map, and an unprivileged user can cause lock contention on that LRU map, it *would* deadlock.
But that's a narrow window. The unprivileged user needs to know *which* LRU map the root program is using, AND be able to cause lock contention on it. Tracing programs usually use their own maps, which aren't accessible to unprivileged users. So an unprivileged user can't usually cause contention on the tracing program's map.
What if the tracing program updates a *shared* map? Unlikely. However, what if the tracing program is attached to `contention_end` and updates *its own* map? If its *own* map has lock contention, it will trigger `contention_end` recursively! I need to be careful.
Wait, if the tracing program updates its own map and causes contention, it will trigger the tracing program again! But BPF has recursion prevention, right? I need to double-check the recursion prevention mechanisms to be certain.
|
| 83/2 |
2026/05/20 08:20 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:kernel/trace/bpf_trace.c IncludeLines:true Name:__bpf_trace_run]
Results: map[SourceCode:2058: static __always_inline
2059: void __bpf_trace_run(struct bpf_raw_tp_link *link, u64 *args)
2060: {
2061: struct bpf_prog *prog = link->link.prog;
2062: struct bpf_run_ctx *old_run_ctx;
2063: struct bpf_trace_run_ctx run_ctx;
2064:
2065: cant_sleep();
2066: if (unlikely(this_cpu_inc_return(*(prog->active)) != 1)) {
2067: bpf_prog_inc_misses_counter(prog);
2068: goto out;
2069: }
2070:
2071: run_ctx.bpf_cookie = link->cookie;
2072: old_run_ctx = bpf_set_run_ctx(&run_ctx.run_ctx);
2073:
2074: rcu_read_lock();
2075: (void) bpf_prog_run(prog, args);
2076: rcu_read_unlock();
2077:
2078: bpf_reset_run_ctx(old_run_ctx);
2079: out:
2080: this_cpu_dec(*(prog->active));
2081: }
SourceFile:kernel/trace/bpf_trace.c]
|
| 84/2 |
2026/05/20 08:20 |
llm |
expert |
0m
Model:
Tokens:
input: 81155
output: 54
thoughts: 677
Thoughts: **Analyzing a BPF Deadlock in Depth**
Okay, so I see that `this_cpu_inc_return(*(prog->active)) != 1` is in place to prevent a program from running recursively on the same CPU, which is good. But this deadlock reported by syzkaller... it's *not* a recursive BPF execution, that's important. I need to understand this stack trace.
Right, the trace shows: `rcu_read_lock` at `bpf_percpu_hash_update`, then `&loc_l->lock` at `bpf_common_lru_pop_free`, and again `rcu_read_lock` at `__bpf_trace_run`. Now, `bpf_percpu_hash_update` is being called from the `bpf_map_update_elem` helper. And... is `bpf_common_lru_pop_free` *directly* called from `bpf_percpu_hash_update`? No. It's called from `bpf_lru_pop_free`, which is then called from `prealloc_lru_pop`, which is called from `__htab_lru_percpu_map_update_elem`. Okay, that makes more sense.
The key here is what the crash dump is telling me: syz-executor is trying to acquire the `loc_l->lock`, and it's already *holding* the same lock! The dump clearly states that the task has the lock at `bpf_common_lru_pop_free` and is *trying* to get it at `bpf_lru_push_free`.
So, let me break this down:
1. A task (likely through a `MAP_UPDATE_BATCH` syscall) is calling `bpf_lru_pop_free`.
2. `bpf_lru_pop_free` calls `bpf_common_lru_pop_free`, and that function *acquires* the `loc_l->lock`. Got it.
3. *While* holding `loc_l->lock`, something happened to trigger `contention_end`. Hmm.
The million-dollar question is: What is going on *while* holding that lock to trigger a contention? Did it try to acquire *another* lock? Let's go back and look at that code in `bpf_common_lru_pop_free`. I need to dig in to figure out what operation is occurring while this lock is held. That's where the problem lies.
|
| 85/2 |
2026/05/20 08:20 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:kernel/bpf/bpf_lru_list.c IncludeLines:true Name:bpf_common_lru_pop_free]
Results: map[SourceCode: 428: static struct bpf_lru_node *bpf_common_lru_pop_free(struct bpf_lru *lru,
429: u32 hash)
430: {
431: struct bpf_lru_locallist *loc_l, *steal_loc_l;
432: struct bpf_common_lru *clru = &lru->common_lru;
433: struct bpf_lru_node *node;
434: int steal, first_steal;
435: unsigned long flags;
436: int cpu = raw_smp_processor_id();
437:
438: loc_l = per_cpu_ptr(clru->local_list, cpu);
439:
440: raw_spin_lock_irqsave(&loc_l->lock, flags);
441:
442: node = __local_list_pop_free(loc_l);
443: if (!node) {
444: bpf_lru_list_pop_free_to_local(lru, loc_l);
445: node = __local_list_pop_free(loc_l);
446: }
447:
448: if (node)
449: __local_list_add_pending(lru, loc_l, cpu, node, hash);
450:
451: raw_spin_unlock_irqrestore(&loc_l->lock, flags);
452:
453: if (node)
454: return node;
455:
456: /* No free nodes found from the local free list and
457: * the global LRU list.
458: *
459: * Steal from the local free/pending list of the
460: * current CPU and remote CPU in RR. It starts
461: * with the loc_l->next_steal CPU.
462: */
463:
464: first_steal = loc_l->next_steal;
465: steal = first_steal;
466: do {
467: steal_loc_l = per_cpu_ptr(clru->local_list, steal);
468:
469: raw_spin_lock_irqsave(&steal_loc_l->lock, flags);
470:
471: node = __local_list_pop_free(steal_loc_l);
472: if (!node)
473: node = __local_list_pop_pending(lru, steal_loc_l);
474:
475: raw_spin_unlock_irqrestore(&steal_loc_l->lock, flags);
476:
477: steal = cpumask_next_wrap(steal, cpu_possible_mask);
478: } while (!node && steal != first_steal);
479:
480: loc_l->next_steal = steal;
481:
482: if (node) {
483: raw_spin_lock_irqsave(&loc_l->lock, flags);
484: __local_list_add_pending(lru, loc_l, cpu, node, hash);
485: raw_spin_unlock_irqrestore(&loc_l->lock, flags);
486: }
487:
488: return node;
489: }
SourceFile:kernel/bpf/bpf_lru_list.c]
|
| 86/2 |
2026/05/20 08:20 |
llm |
expert |
0m
Model:
Tokens:
input: 83470
output: 46
thoughts: 1002
Thoughts: **Deadlock Detected: LRU Map Contention and BPF Program Execution**
Okay, here's what I've figured out. `bpf_common_lru_pop_free` calls `bpf_lru_list_pop_free_to_local`, all while holding `loc_l->lock`. The problem is that `bpf_lru_list_pop_free_to_local` then *also* tries to grab `l->lock`. If there's contention on `l->lock`, it spins, and when it finally acquires the lock, it triggers `trace_contention_end`. `trace_contention_end` then executes a BPF program!
That BPF program, if it does things like `bpf_map_update_elem` or `bpf_map_delete_elem` on the *same* LRU map, we have a problem. `bpf_map_update_elem` calls `bpf_lru_push_free` (or `bpf_lru_pop_free` in the `LRU_PERCPU_HASH` case) which, under the hood, *also* tries to grab `loc_l->lock`. And this is where it hits: `loc_l->lock` is already held by the initial `bpf_common_lru_pop_free` call. Deadlock!
So, the sequence looks like this:
1. Thread A calls `bpf_common_lru_pop_free`, holds `loc_l->lock`.
2. Thread A calls `bpf_lru_list_pop_free_to_local`, tries to acquire `l->lock`.
3. `l->lock` is held by Thread B, so Thread A spins.
4. Thread B releases `l->lock`.
5. Thread A acquires `l->lock`, `trace_contention_end` runs.
6. The BPF program from `contention_end` runs.
7. The BPF program calls `bpf_map_update_elem` on the LRU map.
8. `bpf_map_update_elem` calls `bpf_lru_push_free` (or `bpf_lru_pop_free`), which tries to get `loc_l->lock`.
9. Deadlock! Thread A already holds `loc_l->lock`.
Is this a security hole? To trigger this, you need to attach a BPF program to `contention_end`. And, attaching to `contention_end` requires either `CAP_PERFMON` or `CAP_SYS_ADMIN`. So, a standard unprivileged user *shouldn't* be able to exploit this. Even with user namespaces, we're told `CAP_PERFMON` isn't accessible. So, no worry there.
But, are there any other loopholes? Can an unprivileged user load a `BPF_PROG_TYPE_SOCKET_FILTER` or `BPF_PROG_TYPE_CGROUP_SKB` program and somehow attach it to `contention_end`? No, `bpf_prog_load` does a check with `is_perfmon_prog_type(type)` and requires `CAP_PERFMON` for those cases. And raw tracepoints are perfmon program types. What about, say, a socket filter? Nope, `bpf_raw_tracepoint_open` ensures that the program is either a `BPF_PROG_TYPE_RAW_TRACEPOINT` or `BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE` which still requires elevated privileges. Looks like it is not.
|
| 87/2 |
2026/05/20 08:21 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:kernel/bpf/syscall.c IncludeLines:true Name:bpf_raw_tracepoint_open]
Results: map[SourceCode:4265: static int bpf_raw_tracepoint_open(const union bpf_attr *attr)
4266: {
4267: struct bpf_prog *prog;
4268: void __user *tp_name;
4269: __u64 cookie;
4270: int fd;
4271:
4272: if (CHECK_ATTR(BPF_RAW_TRACEPOINT_OPEN))
4273: return -EINVAL;
4274:
4275: prog = bpf_prog_get(attr->raw_tracepoint.prog_fd);
4276: if (IS_ERR(prog))
4277: return PTR_ERR(prog);
4278:
4279: tp_name = u64_to_user_ptr(attr->raw_tracepoint.name);
4280: cookie = attr->raw_tracepoint.cookie;
4281: fd = bpf_raw_tp_link_attach(prog, tp_name, cookie, prog->expected_attach_type);
4282: if (fd < 0)
4283: bpf_prog_put(prog);
4284: return fd;
4285: }
SourceFile:kernel/bpf/syscall.c]
|
| 88/2 |
2026/05/20 08:21 |
llm |
expert |
0m
Model:
Tokens:
input: 85706
output: 47
thoughts: 16
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience and written in the first person:
**BPF Raw Tracepoint Link Attachment Deep Dive**
Okay, time to dig into `bpf_raw_tp_link_attach`. I need to refresh my understanding of the raw tracepoint linking process. Let's see... what are the key aspects I need to consider? I'm immediately thinking about the interaction with the underlying tracepoint infrastructure. Is it using the standard kprobe/uprobe machinery, or is it doing something more directly at the kernel probe entry points? I know raw tracepoints have their own specific set of constraints, so I need to keep those in mind.
I'll be looking at how this function integrates with the existing BPF verifier and how it handles potential conflicts or overlaps with other tracepoint handlers. What kind of validation is performed on the BPF program being attached? Are there specific checks for raw tracepoints that differ from the regular `tracepoint_probe_attach` logic? The synchronization mechanisms are another important aspect. How is it ensuring that the BPF program doesn't interfere with other kernel activities, or create any race conditions during attach/detach?
I'm particularly interested in any potential performance implications. Are there any known overheads, compared to other BPF attach methods? Is there a difference in memory usage? Any potential issues with CPU cache coherency because of the raw tracepoint interactions? I also need to be vigilant for any edge cases, especially related to error handling and failure modes. What happens if the attach fails? How are resources cleaned up? I will pay special attention to the parameters the function accepts and the return values it can produce. Basically, I want to confirm that this is a robust and efficient way to interact with raw tracepoints. Let's see the code!
|
| 89/2 |
2026/05/20 08:21 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:kernel/bpf/syscall.c IncludeLines:true Name:bpf_raw_tp_link_attach]
Results: map[SourceCode:4192: static int bpf_raw_tp_link_attach(struct bpf_prog *prog,
4193: const char __user *user_tp_name, u64 cookie,
4194: enum bpf_attach_type attach_type)
4195: {
4196: struct bpf_link_primer link_primer;
4197: struct bpf_raw_tp_link *link;
4198: struct bpf_raw_event_map *btp;
4199: const char *tp_name;
4200: char buf[128];
4201: int err;
4202:
4203: switch (prog->type) {
4204: case BPF_PROG_TYPE_TRACING:
4205: case BPF_PROG_TYPE_EXT:
4206: case BPF_PROG_TYPE_LSM:
4207: if (user_tp_name)
4208: /* The attach point for this category of programs
4209: * should be specified via btf_id during program load.
4210: */
4211: return -EINVAL;
4212: if (prog->type == BPF_PROG_TYPE_TRACING &&
4213: prog->expected_attach_type == BPF_TRACE_RAW_TP) {
4214: tp_name = prog->aux->attach_func_name;
4215: break;
4216: }
4217: return bpf_tracing_prog_attach(prog, 0, 0, 0, attach_type);
4218: case BPF_PROG_TYPE_RAW_TRACEPOINT:
4219: case BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE:
4220: if (strncpy_from_user(buf, user_tp_name, sizeof(buf) - 1) < 0)
4221: return -EFAULT;
4222: buf[sizeof(buf) - 1] = 0;
4223: tp_name = buf;
4224: break;
4225: default:
4226: return -EINVAL;
4227: }
4228:
4229: btp = bpf_get_raw_tracepoint(tp_name);
4230: if (!btp)
4231: return -ENOENT;
4232:
4233: link = kzalloc(sizeof(*link), GFP_USER);
4234: if (!link) {
4235: err = -ENOMEM;
4236: goto out_put_btp;
4237: }
4238: bpf_link_init_sleepable(&link->link, BPF_LINK_TYPE_RAW_TRACEPOINT,
4239: &bpf_raw_tp_link_lops, prog, attach_type,
4240: tracepoint_is_faultable(btp->tp));
4241: link->btp = btp;
4242: link->cookie = cookie;
4243:
4244: err = bpf_link_prime(&link->link, &link_primer);
4245: if (err) {
4246: kfree(link);
4247: goto out_put_btp;
4248: }
4249:
4250: err = bpf_probe_register(link->btp, link);
4251: if (err) {
4252: bpf_link_cleanup(&link_primer);
4253: goto out_put_btp;
4254: }
4255:
4256: return bpf_link_settle(&link_primer);
4257:
4258: out_put_btp:
4259: bpf_put_raw_tracepoint(btp);
4260: return err;
4261: }
SourceFile:kernel/bpf/syscall.c]
|
| 90/2 |
2026/05/20 08:21 |
llm |
expert |
0m
Model:
Tokens:
input: 87276
output: 52
thoughts: 3797
Thoughts: **Analysis of a BPF Deadlock Vulnerability**
Okay, so the `bpf_raw_tp_link_attach` function restricts the programs it accepts, and loading these types requires elevated privileges, `CAP_PERFMON` or `CAP_SYS_ADMIN`. That means an unprivileged user can't load the BPF program directly. But, what if an unprivileged user can *trigger* a deadlock after a privileged user has set up the BPF program?
The core issue seems to be a BPF program attached to the `contention_end` tracepoint that updates an LRU map. A crash here would definitely be considered a denial-of-service, but is it a security vulnerability? Usually kernel crashes caused by root are not, unless a security boundary is crossed.
The key question is, can this be reached by a non-root user without special capabilities? The answer is generally no because setting up the BPF program requires privileges. But, what if the tracing tool, `bpftrace` or `bcc`, is already running and has loaded the BPF program? Even then, the LRU map the tracing tool is using is not accessible to unprivileged users, so an unprivileged user cannot trigger lock contention on the tracing tool's LRU map, and cause the deadlock. The relevant `loc_l->lock` is per-CPU AND per-LRU-map, so the unprivileged user must operate on the tracing tool's map.
The only way, then, would be if the tracing tool traces a kernel function an unprivileged user *can* trigger. For example, the tracing tool could be tracing `sys_read`. Then, if the unprivileged user makes many calls, it could trigger the contention end and cause the deadlock.
The deadlock only occurs if the BPF program is attached to the `contention_end` tracepoint, and that's the only way to trigger this bug! The BPF program, if attached to `contention_end`, could be used to trace lock contention with the LRU map. However, this raises the question as to *why* you would attach a BPF program to `contention_end` and then update the map in the first place? To trace *lock* contention.
Then, the tracing program could be triggered again and again, leading to recursive execution, but BPF prevents this by incrementing an 'active' counter. The deadlock is NOT recursive. The syscall (or kernel context) holds `loc_l->lock` and calls `bpf_lru_list_pop_free_to_local`, which tries to acquire another lock which is contended. Then, `trace_contention_end` is called. So, the deadlock happens in this scenario: 1) a syscall holds `loc_l->lock` 2) another lock is contended 3) contention_end fires 4) the BPF program tries to re-acquire `loc_l->lock`, causing a deadlock!
So, the issue is, the BPF programs attached to `contention_end` should not try to acquire locks that might already be held in that context. But, BPF programs have no way of knowing what locks the context which is calling the tracepoint is holding.
Can an unprivileged user trigger this? No. They do not have the access. So the deadlock is only possible if a privileged tracing tool has already set up the BPF program. Then, the tracing tool could deadlock itself, but unprivileged users are safe. The system itself is *not* at risk.
The syzkaller reproducer runs with root and creates its own LRU map, loads the BPF program, attaches it to `contention_end`, and then calls `MAP_UPDATE_BATCH`. That means it's a bug that's reachable by root. It's a denial of service (deadlock), it's not exploitable for privilege escalation, and it is inaccessible by unprivileged processes, user namespaces, and guests.
If an unprivileged user *could* set up a BPF map and program, and they trigger the contention, the tracing program could run, and repeatedly trigger lock contention on the LRU map. If `prog->active` prevents the program from executing again, it won't lead to a deadlock.
The bottom line is that an unprivileged user can't create or access the BPF maps to trigger the deadlock. `bpftrace` will not create a lock if you use an LRU map, because it reads the map using `bpf_map_get_next_key` and `bpf_map_lookup_elem`, or `MAP_LOOKUP_BATCH`.
The bug is in the kernel, because there's nothing the program can do, the deadlock only occurs from a privileged context!
|
| 91/2 |
2026/05/20 08:21 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:kernel/bpf/hashtab.c IncludeLines:true Name:htab_lru_percpu_map_lookup_batch]
Results: map[SourceCode:1944: static int
1945: htab_lru_percpu_map_lookup_batch(struct bpf_map *map,
1946: const union bpf_attr *attr,
1947: union bpf_attr __user *uattr)
1948: {
1949: return __htab_map_lookup_and_delete_batch(map, attr, uattr, false,
1950: true, true);
1951: }
SourceFile:kernel/bpf/hashtab.c]
|
| 92/2 |
2026/05/20 08:21 |
llm |
expert |
0m
Model:
Tokens:
input: 92304
output: 51
thoughts: 19
Thoughts: Okay, let's dive into this. Here's my thought process on what we're looking at, summarized in the first person, assuming I'm already pretty familiar with this code:
**Analyzing `__htab_map_lookup_and_delete_batch`**
Right, so we're looking at `__htab_map_lookup_and_delete_batch`. Okay, good. That immediately tells me this function is involved in some kind of batch operation related to a hash table, specifically a "htab" map. The name is pretty clear: we're doing a lookup and deletion, likely of multiple entries at once, which should offer some performance benefits compared to repeated single-element operations. The double underscore suggests this is probably a lower-level, internal function, not something directly exposed to the end user. This also implies it might be a performance-critical routine. I'll need to pay close attention to the details. I hope there's good comments. Let's see how this thing is structured. I need to understand the data structures it's working with and how it interacts with the underlying hash table implementation. Understanding the batching strategy is going to be key, and any concurrency considerations, because batch operations are often associated with parallelism. I'll need to figure out how it handles collisions, failure cases, and how the "batch" itself is defined (e.g., is it a pre-determined size, or based on some criteria). Let's dig in.
|
| 93/2 |
2026/05/20 08:21 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:kernel/bpf/hashtab.c IncludeLines:true Name:__htab_map_lookup_and_delete_batch]
Results: map[SourceCode:1679: static int
1680: __htab_map_lookup_and_delete_batch(struct bpf_map *map,
1681: const union bpf_attr *attr,
1682: union bpf_attr __user *uattr,
1683: bool do_delete, bool is_lru_map,
1684: bool is_percpu)
1685: {
1686: struct bpf_htab *htab = container_of(map, struct bpf_htab, map);
1687: void *keys = NULL, *values = NULL, *value, *dst_key, *dst_val;
1688: void __user *uvalues = u64_to_user_ptr(attr->batch.values);
1689: void __user *ukeys = u64_to_user_ptr(attr->batch.keys);
1690: void __user *ubatch = u64_to_user_ptr(attr->batch.in_batch);
1691: u32 batch, max_count, size, bucket_size, map_id;
1692: u32 bucket_cnt, total, key_size, value_size;
1693: struct htab_elem *node_to_free = NULL;
1694: u64 elem_map_flags, map_flags;
1695: struct hlist_nulls_head *head;
1696: struct hlist_nulls_node *n;
1697: unsigned long flags = 0;
1698: bool locked = false;
1699: struct htab_elem *l;
1700: struct bucket *b;
1701: int ret = 0;
1702:
1703: elem_map_flags = attr->batch.elem_flags;
1704: if ((elem_map_flags & ~BPF_F_LOCK) ||
1705: ((elem_map_flags & BPF_F_LOCK) && !btf_record_has_field(map->record, BPF_SPIN_LOCK)))
1706: return -EINVAL;
1707:
1708: map_flags = attr->batch.flags;
1709: if (map_flags)
1710: return -EINVAL;
1711:
1712: max_count = attr->batch.count;
1713: if (!max_count)
1714: return 0;
1715:
1716: if (put_user(0, &uattr->batch.count))
1717: return -EFAULT;
1718:
1719: batch = 0;
1720: if (ubatch && copy_from_user(&batch, ubatch, sizeof(batch)))
1721: return -EFAULT;
1722:
1723: if (batch >= htab->n_buckets)
1724: return -ENOENT;
1725:
1726: key_size = htab->map.key_size;
1727: value_size = htab->map.value_size;
1728: size = round_up(value_size, 8);
1729: if (is_percpu)
1730: value_size = size * num_possible_cpus();
1731: total = 0;
1732: /* while experimenting with hash tables with sizes ranging from 10 to
1733: * 1000, it was observed that a bucket can have up to 5 entries.
1734: */
1735: bucket_size = 5;
1736:
1737: alloc:
1738: /* We cannot do copy_from_user or copy_to_user inside
1739: * the rcu_read_lock. Allocate enough space here.
1740: */
1741: keys = kvmalloc_array(key_size, bucket_size, GFP_USER | __GFP_NOWARN);
1742: values = kvmalloc_array(value_size, bucket_size, GFP_USER | __GFP_NOWARN);
1743: if (!keys || !values) {
1744: ret = -ENOMEM;
1745: goto after_loop;
1746: }
1747:
1748: again:
1749: bpf_disable_instrumentation();
1750: rcu_read_lock();
1751: again_nocopy:
1752: dst_key = keys;
1753: dst_val = values;
1754: b = &htab->buckets[batch];
1755: head = &b->head;
1756: /* do not grab the lock unless need it (bucket_cnt > 0). */
1757: if (locked) {
1758: ret = htab_lock_bucket(b, &flags);
1759: if (ret) {
1760: rcu_read_unlock();
1761: bpf_enable_instrumentation();
1762: goto after_loop;
1763: }
1764: }
1765:
1766: bucket_cnt = 0;
1767: hlist_nulls_for_each_entry_rcu(l, n, head, hash_node)
1768: bucket_cnt++;
1769:
1770: if (bucket_cnt && !locked) {
1771: locked = true;
1772: goto again_nocopy;
1773: }
1774:
1775: if (bucket_cnt > (max_count - total)) {
1776: if (total == 0)
1777: ret = -ENOSPC;
1778: /* Note that since bucket_cnt > 0 here, it is implicit
1779: * that the locked was grabbed, so release it.
1780: */
1781: htab_unlock_bucket(b, flags);
1782: rcu_read_unlock();
1783: bpf_enable_instrumentation();
1784: goto after_loop;
1785: }
1786:
1787: if (bucket_cnt > bucket_size) {
1788: bucket_size = bucket_cnt;
1789: /* Note that since bucket_cnt > 0 here, it is implicit
1790: * that the locked was grabbed, so release it.
1791: */
1792: htab_unlock_bucket(b, flags);
1793: rcu_read_unlock();
1794: bpf_enable_instrumentation();
1795: kvfree(keys);
1796: kvfree(values);
1797: goto alloc;
1798: }
1799:
1800: /* Next block is only safe to run if you have grabbed the lock */
1801: if (!locked)
1802: goto next_batch;
1803:
1804: hlist_nulls_for_each_entry_safe(l, n, head, hash_node) {
1805: memcpy(dst_key, l->key, key_size);
1806:
1807: if (is_percpu) {
1808: int off = 0, cpu;
1809: void __percpu *pptr;
1810:
1811: pptr = htab_elem_get_ptr(l, map->key_size);
1812: for_each_possible_cpu(cpu) {
1813: copy_map_value_long(&htab->map, dst_val + off, per_cpu_ptr(pptr, cpu));
1814: check_and_init_map_value(&htab->map, dst_val + off);
1815: off += size;
1816: }
1817: } else {
1818: value = htab_elem_value(l, key_size);
1819: if (is_fd_htab(htab)) {
1820: struct bpf_map **inner_map = value;
1821:
1822: /* Actual value is the id of the inner map */
1823: map_id = map->ops->map_fd_sys_lookup_elem(*inner_map);
1824: value = &map_id;
1825: }
1826:
1827: if (elem_map_flags & BPF_F_LOCK)
1828: copy_map_value_locked(map, dst_val, value,
1829: true);
1830: else
1831: copy_map_value(map, dst_val, value);
1832: /* Zeroing special fields in the temp buffer */
1833: check_and_init_map_value(map, dst_val);
1834: }
1835: if (do_delete) {
1836: hlist_nulls_del_rcu(&l->hash_node);
1837:
1838: /* bpf_lru_push_free() will acquire lru_lock, which
1839: * may cause deadlock. See comments in function
1840: * prealloc_lru_pop(). Let us do bpf_lru_push_free()
1841: * after releasing the bucket lock.
1842: *
1843: * For htab of maps, htab_put_fd_value() in
1844: * free_htab_elem() may acquire a spinlock with bucket
1845: * lock being held and it violates the lock rule, so
1846: * invoke free_htab_elem() after unlock as well.
1847: */
1848: l->batch_flink = node_to_free;
1849: node_to_free = l;
1850: }
1851: dst_key += key_size;
1852: dst_val += value_size;
1853: }
1854:
1855: htab_unlock_bucket(b, flags);
1856: locked = false;
1857:
1858: while (node_to_free) {
1859: l = node_to_free;
1860: node_to_free = node_to_free->batch_flink;
1861: if (is_lru_map)
1862: htab_lru_push_free(htab, l);
1863: else
1864: free_htab_elem(htab, l);
1865: }
1866:
1867: next_batch:
1868: /* If we are not copying data, we can go to next bucket and avoid
1869: * unlocking the rcu.
1870: */
1871: if (!bucket_cnt && (batch + 1 < htab->n_buckets)) {
1872: batch++;
1873: goto again_nocopy;
1874: }
1875:
1876: rcu_read_unlock();
1877: bpf_enable_instrumentation();
1878: if (bucket_cnt && (copy_to_user(ukeys + total * key_size, keys,
1879: key_size * bucket_cnt) ||
1880: copy_to_user(uvalues + total * value_size, values,
1881: value_size * bucket_cnt))) {
1882: ret = -EFAULT;
1883: goto after_loop;
1884: }
1885:
1886: total += bucket_cnt;
1887: batch++;
1888: if (batch >= htab->n_buckets) {
1889: ret = -ENOENT;
1890: goto after_loop;
1891: }
1892: goto again;
1893:
1894: after_loop:
1895: if (ret == -EFAULT)
1896: goto out;
1897:
1898: /* copy # of entries and next batch */
1899: ubatch = u64_to_user_ptr(attr->batch.out_batch);
1900: if (copy_to_user(ubatch, &batch, sizeof(batch)) ||
1901: put_user(total, &uattr->batch.count))
1902: ret = -EFAULT;
1903:
1904: out:
1905: kvfree(keys);
1906: kvfree(values);
1907: return ret;
1908: }
SourceFile:kernel/bpf/hashtab.c]
|
| 94/2 |
2026/05/20 08:21 |
llm |
expert |
0m
Model:
Tokens:
input: 96253
output: 66
thoughts: 1893
Thoughts: **Analysis of a Potential BPF Deadlock**
Okay, let me break this down. It seems there's a potential deadlock scenario involving BPF programs, specifically with hash maps, particularly when it comes to the lock acquisition order. I'm seeing that `__htab_map_lookup_and_delete_batch` doesn't acquire locks the same way for all operations; in particular, `MAP_LOOKUP_BATCH` behaves differently. This is the crux.
My initial thought is that if `MAP_LOOKUP_BATCH` on an LRU map doesn't call `htab_lru_push_free` and subsequently `bpf_lru_pop_free`, it won't be using `loc_l->lock`. Instead, it looks like it's primarily grabbing `bucket_lock`. The potential for contention there is what caught my eye. If `bucket_lock` is contended, the BPF program attached to `contention_end` might trigger. That's where things get interesting.
If this BPF program then tries to update the *same* LRU map using `bpf_map_update_elem`, it could try to acquire `loc_l->lock` and then *again* acquire `bucket_lock`. This is where the deadlock arises – the BPF program, which is running *because* `bucket_lock` was contended in the first place, could be trying to reacquire the same lock it's waiting on, causing it to block indefinitely.
Crucially, this isn't just an LRU map issue; it looks like this is applicable to all hash maps due to the lock acquisition order within `htab_lock_bucket`. The probability of a collision, of course, depends on the number of buckets, and potential attacker-controlled keys.
My immediate question was about unprivileged users. Could an unprivileged user trigger this? My thinking is that no, because the typical user wouldn't have access to the tracing tool's maps to cause any lock contention, so in the typical scenario, there shouldn't be anything to worry about.
However, I started thinking more specifically. What if there was lock contention while the BPF program was already running? This is when I started thinking about the recursion prevention mechanism. If contention happens *inside* the BPF program, `prog->active` becomes non-zero, and `__bpf_trace_run` will see the `prog->active` as already active. So, this BPF program would *not* be run again, and the deadlock is avoided.
The *only* way the deadlock could be triggered is if the lock contention happens *outside* the BPF program. That means a syscall or some other kernel context, which would have to be operating on a tracing tool's hash map. I've concluded again that unprivileged users can't touch that map.
Then I considered the scenario where an unprivileged user might be able to update a global map, so if root creates a shared map, gives unprivileged access, and that is used by `contention_end`. I realized this is a *very* contrived, user misconfiguration.
So, is it exploitable? No. Denial of Service? Yes, but only in this limited scenario. Is it accessible to unprivileged users or within user namespaces? No.
The only way it can occur is in this *extremely* niche case where an administrator specifically sets up a misconfigured map that leads to a collision, which is not really a kernel bug.
Finally, I checked my assumptions on BPF access. Using `unprivileged_bpf_disabled=1` means unprivileged users cannot even create BPF programs or maps.
Given all of this, the stack trace, and the logical progression, this is absolutely a BPF bug. My final conclusion is as above and will be confirmed.
|
| 95/2 |
2026/05/20 08:22 |
tool |
set-results |
0m
Args: map[DenialOfService:true Exploitable:false FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:false UserNamespace:false VMGuestTrigger:false VMHostTrigger:false]
Results: map[DenialOfService:true Exploitable:false FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:false UserNamespace:false VMGuestTrigger:false VMHostTrigger:false]
|
| 96/2 |
2026/05/20 08:22 |
llm |
expert |
0m
Model:
Tokens:
input: 99092
output: 671
thoughts: 532
Thoughts: **Finalizing the Analysis: A BPF LRU Map Deadlock**
Alright, the results are in, and now it's time to craft the explanation. This bug boils down to a classic spinlock deadlock within the BPF LRU map implementation. The core issue revolves around recursive locking, specifically involving `loc_l->lock`.
Here's the sequence: a kernel context, let's say a syscall like `bpf(MAP_UPDATE_BATCH)`, grabs that `loc_l->lock` for an LRU map. While holding *that* lock, the context then tries to acquire another one, perhaps the global `l->lock` of the LRU list. If that second lock is busy, the CPU starts spinning, as expected. Then, *finally* getting it, the kernel's lockdep or lockstat subsystems trigger the `contention_end` tracepoint, and that's where the trouble begins.
If a BPF tracing program, like a `BPF_PROG_TYPE_RAW_TRACEPOINT`, is hooked to that `contention_end` tracepoint, it's going to run. And if that BPF program decides to mess with *the same* LRU map, maybe by calling `bpf_map_delete_elem`, it's going to attempt to grab `loc_l->lock` again. And that's it - because the original context is *still* holding that lock, a deadlock occurs. Boom, CPU hang.
Now, as far as security goes: Exploitable? Nope, it's a deadlock, resulting in a CPU hang, which is not fun but doesn't lead to memory corruption or any privilege escalation. Denial of Service? Absolutely, triggering this is going to hang the CPU and bring down the system. Unprivileged? Unlikely, especially given the prompt states `unprivileged_bpf_disabled=1` and no user namespaces. Even if those restrictions were lifted, a user needs `CAP_PERFMON` or `CAP_SYS_ADMIN` to attach a tracing program to something like `contention_end`. A regular user can't load such a program, nor would they be able to trigger the deadlock even if a privileged user had already loaded the tracing program, as the unprivileged user can't cause lock contention on the tracing program's private BPF map, which is inaccessible to them. No network, filesystem, VM, or peripheral involvement either, as the bug is purely in BPF, and local BPF syscalls are needed for setup.
|
| 97/1 |
2026/05/20 08:22 |
action |
format-explanation |
0m
Results: map[Explanation:Based on the analysis of the bug report and the kernel source code, here is the
security assessment of the issue:
### Bug Mechanism
The bug is a recursive spinlock deadlock in the BPF LRU map implementation. The
sequence of events leading to the deadlock is as follows:
1. A kernel context (such as the `bpf(MAP_UPDATE_BATCH)` syscall) operates on an
LRU map and acquires the per-CPU `loc_l->lock`.
2. While holding `loc_l->lock`, it attempts to acquire the global LRU list lock
(`l->lock`).
3. If `l->lock` is contended by another CPU, the current CPU will spin in the
slowpath. Once it finally acquires the lock, the kernel's lock statistics
subsystem triggers the `contention_end` tracepoint (via
`trace_contention_end()`).
4. If a BPF tracing program (e.g., `BPF_PROG_TYPE_RAW_TRACEPOINT`) is attached
to the `contention_end` tracepoint, it will execute synchronously in this
context.
5. If the BPF program attempts to update or delete an element in the *same* LRU
map, it will call into the LRU map helpers (like `bpf_lru_push_free`) which try
to acquire the `loc_l->lock` again.
6. Because the lock is already held by the interrupted syscall context, the CPU
deadlocks.
### Security Impact
* **Exploitable:** **False**. This is a classic spinlock deadlock. It results in
a CPU hang (soft or hard lockup) but does not cause memory corruption,
out-of-bounds access, or allow for privilege escalation.
* **Denial Of Service:** **True**. Triggering the bug hangs the CPU, leading to
a system-wide denial of service (kernel panic via watchdog).
* **Accessible From Unprivileged Processes / User Namespaces:** **False**.
Attaching a BPF program to a raw tracepoint like `contention_end` strictly
requires `CAP_PERFMON` or `CAP_SYS_ADMIN` capabilities. Furthermore, with
`unprivileged_bpf_disabled=1` (as assumed), unprivileged users cannot create BPF
maps or load eBPF programs at all. Even if a privileged user (like an
administrator running a tracing tool) sets up the vulnerable BPF program, an
unprivileged user cannot trigger the deadlock because they do not have file
descriptor access to the privileged tracing tool's BPF map to cause the initial
lock contention.
* **Remote / Peripheral / Filesystem / VM Triggers:** **False**. The bug is
entirely contained within the BPF subsystem and requires local execution of BPF
syscalls to set up the tracepoint and map. It cannot be triggered remotely, via
malicious filesystems, or by external hardware.
In summary, this is a local Denial-of-Service bug that can only be triggered by
a highly privileged user (root or a user with `CAP_PERFMON`/`CAP_SYS_ADMIN`) who
is already capable of loading advanced BPF tracing programs. It does not cross
any security boundaries.]
|