AI Trajectory


Trajectory: (Expand/Collapse All)
Seq Timestamp Type Name Duration
0/0 2026/09/23 19:45 flow patch-triage
5m Args:
null

Results:
{
  "EnableConfigs": [
    "BPF_SYSCALL",
    "DEBUG_INFO_BTF"
  ],
  "FocusSymbols": [
    "bpf_call_rcu",
    "bpf_call_rcu_tasks_trace",
    "bpf_rcu_run_callback",
    "__bpf_call_rcu",
    "set_rcu_callback_state"
  ],
  "KMSANReasoning": "The patch introduces the `bpf_call_rcu` and `bpf_call_rcu_tasks_trace` kfuncs along with the `bpf_rcu_head` BTF field type (restricted to array maps). \n\nAn analysis of uninitialized memory risks shows:\n1. All fields of `struct bpf_rcu_head_kern` (`callback_fn`, `map`, `prog`, `armed`) are explicitly set prior to arming via `call_rcu()` / `call_rcu_tasks_trace()`, and `call_rcu` initializes the embedded `struct rcu_head`.\n2. Array map elements are zero-allocated upon creation. If userspace reads the map value via `bpf_map_lookup_elem`, `check_and_init_map_value()` invokes `bpf_obj_init_field()`, which explicitly zeroes the `bpf_rcu_head` struct with `memset()`, preventing info-leaks to userspace.\n3. BPF programs are prohibited from directly reading or writing the `bpf_rcu_head` field by verifier rules in `check_map_access()`.\n4. In `bpf_rcu_run_callback()`, the key passed to the callback points to `idx`, which is directly initialized by `map_key_from_value()`.\n\nThe primary risks for this feature pertain to object lifetimes (BPF program and map lifetime vs pending RCU callbacks), race conditions / concurrency bugs around callback rearming, or RCU context/locking misuse. These risks are effectively covered by KASAN (use-after-free, double free) and LOCKDEP (RCU / lock validation), and do not involve uninitialized memory access. Therefore, a dedicated KMSAN session is not warranted.",
  "NeedsKMSAN": false,
  "Reasoning": "The patch series introduces BPF support for asynchronous RCU callbacks via `struct bpf_rcu_head` and kfuncs `bpf_call_rcu` and `bpf_call_rcu_tasks_trace`. This touches the BPF verifier, core BPF helpers, BTF parsing, and map subsystem. It executes in standard virtualized environments and handles asynchronous execution, reference counting, and RCU callbacks, making it well-suited for fuzzing.",
  "WorthFuzzing": true
}

1/1 2026/09/23 19:45 action read-patch-diff
0m Args:
null

Results:
{
  "PatchDiff": "commit 53dabebe1086ff9808c18c85bd1d583e876072cc\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate:   Wed Sep 23 19:45:15 2026 +0000\n\n    syz-cluster: applied patch under review\n\ndiff --git a/include/linux/bpf.h b/include/linux/bpf.h\nindex fd22db8bc6c50..e7c5e203edddb 100644\n--- a/include/linux/bpf.h\n+++ b/include/linux/bpf.h\n@@ -215,6 +215,7 @@ enum btf_field_type {\n \tBPF_UPTR       = (1 \u003c\u003c 11),\n \tBPF_RES_SPIN_LOCK = (1 \u003c\u003c 12),\n \tBPF_TASK_WORK  = (1 \u003c\u003c 13),\n+\tBPF_RCU_HEAD   = (1 \u003c\u003c 14),\n };\n \n enum bpf_cgroup_storage_type {\n@@ -269,6 +270,7 @@ struct btf_record {\n \tint wq_off;\n \tint refcount_off;\n \tint task_work_off;\n+\tint rcu_head_off;\n \tstruct btf_field fields[];\n };\n \n@@ -374,6 +376,8 @@ static inline const char *btf_field_type_name(enum btf_field_type type)\n \t\treturn \"bpf_refcount\";\n \tcase BPF_TASK_WORK:\n \t\treturn \"bpf_task_work\";\n+\tcase BPF_RCU_HEAD:\n+\t\treturn \"bpf_rcu_head\";\n \tdefault:\n \t\tWARN_ON_ONCE(1);\n \t\treturn \"unknown\";\n@@ -414,6 +418,8 @@ static inline u32 btf_field_type_size(enum btf_field_type type)\n \t\treturn sizeof(struct bpf_refcount);\n \tcase BPF_TASK_WORK:\n \t\treturn sizeof(struct bpf_task_work);\n+\tcase BPF_RCU_HEAD:\n+\t\treturn sizeof(struct bpf_rcu_head);\n \tdefault:\n \t\tWARN_ON_ONCE(1);\n \t\treturn 0;\n@@ -448,6 +454,8 @@ static inline u32 btf_field_type_align(enum btf_field_type type)\n \t\treturn __alignof__(struct bpf_refcount);\n \tcase BPF_TASK_WORK:\n \t\treturn __alignof__(struct bpf_task_work);\n+\tcase BPF_RCU_HEAD:\n+\t\treturn __alignof__(struct bpf_rcu_head);\n \tdefault:\n \t\tWARN_ON_ONCE(1);\n \t\treturn 0;\n@@ -480,6 +488,7 @@ static inline void bpf_obj_init_field(const struct btf_field *field, void *addr)\n \tcase BPF_KPTR_PERCPU:\n \tcase BPF_UPTR:\n \tcase BPF_TASK_WORK:\n+\tcase BPF_RCU_HEAD:\n \t\tbreak;\n \tdefault:\n \t\tWARN_ON_ONCE(1);\n@@ -925,6 +934,7 @@ enum bpf_arg_type {\n \tARG_PTR_TO_RB_NODE,\t/* pointer to bpf_rb_node */\n \tARG_PTR_TO_WORKQUEUE,\t/* pointer to bpf_wq */\n \tARG_PTR_TO_TASK_WORK,\t/* pointer to bpf_task_work */\n+\tARG_PTR_TO_RCU_HEAD,\t/* pointer to bpf_rcu_head */\n \tARG_PTR_TO_IRQ_FLAG,\t/* pointer to saved IRQ flags on the stack */\n \tARG_PTR_TO_RES_SPIN_LOCK,\t/* pointer to bpf_res_spin_lock */\n \tARG_PTR_TO_CTX_OUT,\t/* hook output argument passed through from ctx */\ndiff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h\nindex 6330b7d745c57..eafeba23f5da7 100644\n--- a/include/uapi/linux/bpf.h\n+++ b/include/uapi/linux/bpf.h\n@@ -7611,6 +7611,10 @@ struct bpf_task_work {\n \t__u64 __opaque;\n } __attribute__((aligned(8)));\n \n+struct bpf_rcu_head {\n+\t__u64 __opaque[8];\n+} __attribute__((aligned(8)));\n+\n struct bpf_wq {\n \t__u64 __opaque[2];\n } __attribute__((aligned(8)));\ndiff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c\nindex 314ecb0e593b0..4a1fa4fbdf4e8 100644\n--- a/kernel/bpf/btf.c\n+++ b/kernel/bpf/btf.c\n@@ -3696,6 +3696,7 @@ static int btf_get_field_type(const struct btf *btf, const struct btf_type *var_\n \t\t{ BPF_TIMER, \"bpf_timer\", true },\n \t\t{ BPF_WORKQUEUE, \"bpf_wq\", true },\n \t\t{ BPF_TASK_WORK, \"bpf_task_work\", true },\n+\t\t{ BPF_RCU_HEAD, \"bpf_rcu_head\", true },\n \t\t{ BPF_LIST_HEAD, \"bpf_list_head\", false },\n \t\t{ BPF_LIST_NODE, \"bpf_list_node\", false },\n \t\t{ BPF_RB_ROOT, \"bpf_rb_root\", false },\n@@ -3881,6 +3882,7 @@ static int btf_find_field_one(const struct btf *btf,\n \tcase BPF_RB_NODE:\n \tcase BPF_REFCOUNT:\n \tcase BPF_TASK_WORK:\n+\tcase BPF_RCU_HEAD:\n \t\tret = btf_find_struct(btf, var_type, off, sz, field_type,\n \t\t\t\t      info_cnt ? \u0026info[0] : \u0026tmp);\n \t\tif (ret \u003c 0)\n@@ -4176,6 +4178,7 @@ struct btf_record *btf_parse_fields(const struct btf *btf, const struct btf_type\n \trec-\u003ewq_off = -EINVAL;\n \trec-\u003erefcount_off = -EINVAL;\n \trec-\u003etask_work_off = -EINVAL;\n+\trec-\u003ercu_head_off = -EINVAL;\n \tfor (i = 0; i \u003c cnt; i++) {\n \t\tfield_type_size = btf_field_type_size(info_arr[i].type);\n \t\tif (info_arr[i].off + field_type_size \u003e value_size) {\n@@ -4219,6 +4222,10 @@ struct btf_record *btf_parse_fields(const struct btf *btf, const struct btf_type\n \t\t\tWARN_ON_ONCE(rec-\u003etask_work_off \u003e= 0);\n \t\t\trec-\u003etask_work_off = rec-\u003efields[i].offset;\n \t\t\tbreak;\n+\t\tcase BPF_RCU_HEAD:\n+\t\t\tWARN_ON_ONCE(rec-\u003ercu_head_off \u003e= 0);\n+\t\t\trec-\u003ercu_head_off = rec-\u003efields[i].offset;\n+\t\t\tbreak;\n \t\tcase BPF_REFCOUNT:\n \t\t\tWARN_ON_ONCE(rec-\u003erefcount_off \u003e= 0);\n \t\t\t/* Cache offset for faster lookup at runtime */\ndiff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c\nindex 501c7ce35cba9..301b35bd85c8a 100644\n--- a/kernel/bpf/helpers.c\n+++ b/kernel/bpf/helpers.c\n@@ -4805,6 +4805,106 @@ __bpf_kfunc int bpf_task_work_schedule_resume(struct task_struct *task, struct b\n \treturn bpf_task_work_schedule(task, tw, map__const_map, callback, aux, TWA_RESUME);\n }\n \n+typedef int (*bpf_rcu_callback_t)(struct bpf_map *map, void *key, void *value);\n+\n+/* Actual type for struct bpf_rcu_head */\n+struct bpf_rcu_head_kern {\n+\tstruct rcu_head rcu;\n+\tbpf_callback_t callback_fn;\n+\tstruct bpf_map *map;\n+\tstruct bpf_prog *prog;\n+\tu32 armed;\n+} __aligned(8);\n+\n+static void bpf_rcu_run_callback(struct rcu_head *rcu)\n+{\n+\tstruct bpf_rcu_head_kern *rh = container_of(rcu, struct bpf_rcu_head_kern, rcu);\n+\tbpf_callback_t callback_fn = rh-\u003ecallback_fn;\n+\tstruct bpf_prog *prog = rh-\u003eprog;\n+\tstruct bpf_map *map = rh-\u003emap;\n+\tvoid *value, *key;\n+\tu32 idx;\n+\n+\tvalue = (void *)rh - map-\u003erecord-\u003ercu_head_off;\n+\tkey = map_key_from_value(map, value, \u0026idx);\n+\n+\t/* Pairs with the arming cmpxchg(): rh may be re-armed as soon as this store lands. */\n+\tsmp_store_release(\u0026rh-\u003earmed, 0);\n+\n+\trcu_read_lock_dont_migrate();\n+\tcallback_fn((u64)(long)map, (u64)(long)key, (u64)(long)value, 0, 0);\n+\trcu_read_unlock_migrate();\n+\n+\tbpf_prog_put(prog);\n+}\n+\n+static int __bpf_call_rcu(struct bpf_rcu_head *rh, struct bpf_map *map, void *callback,\n+\t\t\t  struct bpf_prog_aux *aux, bool trace)\n+{\n+\tstruct bpf_rcu_head_kern *rhk = (void *)rh;\n+\tstruct bpf_prog *prog;\n+\n+\tBUILD_BUG_ON(sizeof(struct bpf_rcu_head_kern) \u003e sizeof(struct bpf_rcu_head));\n+\tBUILD_BUG_ON(__alignof__(struct bpf_rcu_head_kern) != __alignof__(struct bpf_rcu_head));\n+\tBTF_TYPE_EMIT(struct bpf_rcu_head);\n+\n+\t/* A queued callback cannot be cancelled, so a self-rearming one would pin prog and map. */\n+\tif (!atomic64_read(\u0026map-\u003eusercnt))\n+\t\treturn -EPERM;\n+\n+\tif (cmpxchg(\u0026rhk-\u003earmed, 0, 1))\n+\t\treturn -EBUSY;\n+\n+\tprog = bpf_prog_inc_not_zero(aux-\u003eprog);\n+\tif (IS_ERR(prog)) {\n+\t\tWRITE_ONCE(rhk-\u003earmed, 0);\n+\t\treturn -EBADF;\n+\t}\n+\n+\trhk-\u003ecallback_fn = (bpf_callback_t)callback;\n+\trhk-\u003emap = map;\n+\trhk-\u003eprog = prog;\n+\tif (trace)\n+\t\tcall_rcu_tasks_trace(\u0026rhk-\u003ercu, bpf_rcu_run_callback);\n+\telse\n+\t\tcall_rcu(\u0026rhk-\u003ercu, bpf_rcu_run_callback);\n+\treturn 0;\n+}\n+\n+/**\n+ * bpf_call_rcu - Invoke a BPF callback after an RCU grace period\n+ * @rh: struct bpf_rcu_head in a BPF map value\n+ * @map__const_map: bpf_map that embeds struct bpf_rcu_head in the values\n+ * @callback: BPF subprogram, invoked as callback(map, key, value) for the value holding @rh\n+ * @aux: bpf_prog_aux of the caller, implicitly set by the verifier\n+ *\n+ * Return: 0, -EBUSY if @rh is already queued, -EPERM if @map is held by neither a process\n+ * nor bpffs, or -EBADF if the calling program is going away.\n+ */\n+__bpf_kfunc int bpf_call_rcu(struct bpf_rcu_head *rh, void *map__const_map,\n+\t\t\t     bpf_rcu_callback_t callback, struct bpf_prog_aux *aux)\n+{\n+\treturn __bpf_call_rcu(rh, map__const_map, callback, aux, false);\n+}\n+\n+/**\n+ * bpf_call_rcu_tasks_trace - Invoke a BPF callback after an RCU tasks trace grace period\n+ * @rh: struct bpf_rcu_head in a BPF map value\n+ * @map__const_map: bpf_map that embeds struct bpf_rcu_head in the values\n+ * @callback: BPF subprogram, invoked as callback(map, key, value) for the value holding @rh\n+ * @aux: bpf_prog_aux of the caller, implicitly set by the verifier\n+ *\n+ * Waits for sleepable BPF programs too.  The callback itself is not sleepable either way.\n+ *\n+ * Return: 0, -EBUSY if @rh is already queued, -EPERM if @map is held by neither a process\n+ * nor bpffs, or -EBADF if the calling program is going away.\n+ */\n+__bpf_kfunc int bpf_call_rcu_tasks_trace(struct bpf_rcu_head *rh, void *map__const_map,\n+\t\t\t\t\t bpf_rcu_callback_t callback, struct bpf_prog_aux *aux)\n+{\n+\treturn __bpf_call_rcu(rh, map__const_map, callback, aux, true);\n+}\n+\n static int make_file_dynptr(struct file *file, u32 flags, bool may_sleep,\n \t\t\t    struct bpf_dynptr_kern *ptr)\n {\n@@ -5100,6 +5200,8 @@ BTF_ID_FLAGS(func, bpf_stream_vprintk, KF_IMPLICIT_ARGS | KF_SPINLOCK_SAFE)\n BTF_ID_FLAGS(func, bpf_stream_print_stack, KF_IMPLICIT_ARGS | KF_SPINLOCK_SAFE)\n BTF_ID_FLAGS(func, bpf_task_work_schedule_signal, KF_IMPLICIT_ARGS)\n BTF_ID_FLAGS(func, bpf_task_work_schedule_resume, KF_IMPLICIT_ARGS)\n+BTF_ID_FLAGS(func, bpf_call_rcu, KF_IMPLICIT_ARGS)\n+BTF_ID_FLAGS(func, bpf_call_rcu_tasks_trace, KF_IMPLICIT_ARGS)\n BTF_ID_FLAGS(func, bpf_dynptr_from_file)\n BTF_ID_FLAGS(func, bpf_dynptr_file_discard, KF_RELEASE)\n BTF_ID_FLAGS(func, bpf_timer_cancel_async)\ndiff --git a/kernel/bpf/map_in_map.c b/kernel/bpf/map_in_map.c\nindex d2cbab4bdf644..5ee8aae7435ba 100644\n--- a/kernel/bpf/map_in_map.c\n+++ b/kernel/bpf/map_in_map.c\n@@ -25,6 +25,10 @@ struct bpf_map *bpf_map_meta_alloc(int inner_map_ufd)\n \tif (!inner_map-\u003eops-\u003emap_meta_equal)\n \t\treturn ERR_PTR(-ENOTSUPP);\n \n+\t/* An inner map has no used_maps reference to hold it under a queued callback. */\n+\tif (btf_record_has_field(inner_map-\u003erecord, BPF_RCU_HEAD))\n+\t\treturn ERR_PTR(-EOPNOTSUPP);\n+\n \tinner_map_meta_size = sizeof(*inner_map_meta);\n \t/* In some cases verifier needs to access beyond just base map. */\n \tif (inner_map-\u003eops == \u0026array_map_ops || inner_map-\u003eops == \u0026percpu_array_map_ops)\ndiff --git a/kernel/bpf/map_iter.c b/kernel/bpf/map_iter.c\nindex c19b360bad9ea..2077d46d167c7 100644\n--- a/kernel/bpf/map_iter.c\n+++ b/kernel/bpf/map_iter.c\n@@ -117,6 +117,12 @@ static int bpf_iter_attach_map(struct bpf_prog *prog,\n \t\tgoto put_map;\n \t}\n \n+\t/* The value ctx arg is writable and aliases the live element. */\n+\tif (btf_record_has_field(map-\u003erecord, BPF_RCU_HEAD)) {\n+\t\terr = -EOPNOTSUPP;\n+\t\tgoto put_map;\n+\t}\n+\n \tif (map-\u003emap_type == BPF_MAP_TYPE_PERCPU_HASH ||\n \t    map-\u003emap_type == BPF_MAP_TYPE_LRU_PERCPU_HASH ||\n \t    map-\u003emap_type == BPF_MAP_TYPE_PERCPU_ARRAY)\ndiff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c\nindex 113486b15d29f..74496fd716d3b 100644\n--- a/kernel/bpf/syscall.c\n+++ b/kernel/bpf/syscall.c\n@@ -687,6 +687,7 @@ void btf_record_free(struct btf_record *rec)\n \t\tcase BPF_REFCOUNT:\n \t\tcase BPF_WORKQUEUE:\n \t\tcase BPF_TASK_WORK:\n+\t\tcase BPF_RCU_HEAD:\n \t\t\t/* Nothing to release */\n \t\t\tbreak;\n \t\tdefault:\n@@ -741,6 +742,7 @@ struct btf_record *btf_record_dup(const struct btf_record *rec)\n \t\tcase BPF_REFCOUNT:\n \t\tcase BPF_WORKQUEUE:\n \t\tcase BPF_TASK_WORK:\n+\t\tcase BPF_RCU_HEAD:\n \t\t\t/* Nothing to acquire */\n \t\t\tbreak;\n \t\tdefault:\n@@ -874,6 +876,7 @@ void bpf_obj_free_fields(const struct btf_record *rec, void *obj)\n \t\tcase BPF_LIST_NODE:\n \t\tcase BPF_RB_NODE:\n \t\tcase BPF_REFCOUNT:\n+\t\tcase BPF_RCU_HEAD:\n \t\t\tbreak;\n \t\tdefault:\n \t\t\tWARN_ON_ONCE(1);\n@@ -1280,7 +1283,7 @@ static int map_check_btf(struct bpf_map *map, struct bpf_token *token,\n \tmap-\u003erecord = btf_parse_fields(btf, value_type,\n \t\t\t\t       BPF_SPIN_LOCK | BPF_RES_SPIN_LOCK | BPF_TIMER | BPF_KPTR | BPF_LIST_HEAD |\n \t\t\t\t       BPF_RB_ROOT | BPF_REFCOUNT | BPF_WORKQUEUE | BPF_UPTR |\n-\t\t\t\t       BPF_TASK_WORK,\n+\t\t\t\t       BPF_TASK_WORK | BPF_RCU_HEAD,\n \t\t\t\t       map-\u003evalue_size);\n \tif (!IS_ERR_OR_NULL(map-\u003erecord)) {\n \t\tint i;\n@@ -1322,6 +1325,12 @@ static int map_check_btf(struct bpf_map *map, struct bpf_token *token,\n \t\t\t\t\tgoto free_map_tab;\n \t\t\t\t}\n \t\t\t\tbreak;\n+\t\t\tcase BPF_RCU_HEAD:\n+\t\t\t\tif (map-\u003emap_type != BPF_MAP_TYPE_ARRAY) {\n+\t\t\t\t\tret = -EOPNOTSUPP;\n+\t\t\t\t\tgoto free_map_tab;\n+\t\t\t\t}\n+\t\t\t\tbreak;\n \t\t\tcase BPF_KPTR_UNREF:\n \t\t\tcase BPF_KPTR_REF:\n \t\t\tcase BPF_KPTR_PERCPU:\ndiff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c\nindex d62c0f74cff5e..a7c9e2d8965d5 100644\n--- a/kernel/bpf/verifier.c\n+++ b/kernel/bpf/verifier.c\n@@ -535,6 +535,7 @@ static bool is_ptr_cast_function(enum bpf_func_id func_id)\n \n static bool is_sync_callback_calling_kfunc(u32 btf_id);\n static bool is_async_callback_calling_kfunc(u32 btf_id);\n+static bool is_call_rcu_kfunc(u32 btf_id);\n static bool is_callback_calling_kfunc(u32 btf_id);\n \n static bool is_bpf_wq_set_callback_kfunc(u32 btf_id);\n@@ -577,6 +578,10 @@ static bool is_async_cb_sleepable(struct bpf_verifier_env *env, struct bpf_insn\n \tif (bpf_helper_call(insn) \u0026\u0026 insn-\u003eimm == BPF_FUNC_timer_set_callback)\n \t\treturn false;\n \n+\t/* bpf_call_rcu and bpf_call_rcu_tasks_trace callbacks are never sleepable. */\n+\tif (bpf_pseudo_kfunc_call(insn) \u0026\u0026 insn-\u003eoff == 0 \u0026\u0026 is_call_rcu_kfunc(insn-\u003eimm))\n+\t\treturn false;\n+\n \t/* bpf_wq and bpf_task_work callbacks are always sleepable. */\n \tif (bpf_pseudo_kfunc_call(insn) \u0026\u0026 insn-\u003eoff == 0 \u0026\u0026\n \t    (is_bpf_wq_set_callback_kfunc(insn-\u003eimm) || is_task_work_add_kfunc(insn-\u003eimm)))\n@@ -7590,6 +7595,9 @@ static int check_map_field_pointer(struct bpf_verifier_env *env, struct bpf_reg_\n \tcase BPF_TASK_WORK:\n \t\tfield_off = map-\u003erecord-\u003etask_work_off;\n \t\tbreak;\n+\tcase BPF_RCU_HEAD:\n+\t\tfield_off = map-\u003erecord-\u003ercu_head_off;\n+\t\tbreak;\n \tcase BPF_WORKQUEUE:\n \t\tfield_off = map-\u003erecord-\u003ewq_off;\n \t\tbreak;\n@@ -8448,6 +8456,7 @@ static const struct bpf_reg_types *compatible_reg_types[__BPF_ARG_TYPE_MAX] = {\n \t[ARG_PTR_TO_RES_SPIN_LOCK]\t= \u0026map_value_or_alloc_obj_types,\n \t[ARG_PTR_TO_WORKQUEUE]\t\t= \u0026map_value_types,\n \t[ARG_PTR_TO_TASK_WORK]\t\t= \u0026map_value_types,\n+\t[ARG_PTR_TO_RCU_HEAD]\t\t= \u0026map_value_types,\n \t[ARG_PTR_TO_IRQ_FLAG]\t\t= \u0026stack_ptr_types,\n \t[ARG_PTR_TO_ARENA]\t\t= \u0026arena_types,\n \t[ARG_PTR_TO_CTX_OUT]\t\t= \u0026ctx_out_types,\n@@ -8894,6 +8903,8 @@ static int process_map_ptr_arg(struct bpf_verifier_env *env, struct bpf_reg_stat\n \t\t\tobj_name = \"timer\";\n \t\telse if (rec-\u003etask_work_off \u003e= 0)\n \t\t\tobj_name = \"bpf_task_work\";\n+\t\telse if (rec-\u003ercu_head_off \u003e= 0)\n+\t\t\tobj_name = \"bpf_rcu_head\";\n \n \t\tverbose(env, \"%s pointer in %s map_uid=%d \",\n \t\t\tobj_name, reg_arg_name(env, obj_argno), meta-\u003emap.uid);\n@@ -9442,6 +9453,11 @@ static int check_func_arg(struct bpf_verifier_env *env, u32 arg, u32 slot, u32 p\n \t\tif (err \u003c 0)\n \t\t\treturn err;\n \t\tbreak;\n+\tcase ARG_PTR_TO_RCU_HEAD:\n+\t\terr = check_map_field_pointer(env, reg, argno, BPF_RCU_HEAD, \u0026meta-\u003emap);\n+\t\tif (err \u003c 0)\n+\t\t\treturn err;\n+\t\tbreak;\n \tcase ARG_PTR_TO_IRQ_FLAG:\n \t\terr = process_irq_flag(env, reg, argno, meta);\n \t\tif (err \u003c 0)\n@@ -10955,6 +10971,40 @@ static int set_task_work_schedule_callback_state(struct bpf_verifier_env *env,\n \treturn 0;\n }\n \n+static int set_rcu_callback_state(struct bpf_verifier_env *env,\n+\t\t\t\t  struct bpf_func_state *caller,\n+\t\t\t\t  struct bpf_func_state *callee,\n+\t\t\t\t  int insn_idx)\n+{\n+\tstruct bpf_map *map_ptr = caller-\u003eregs[BPF_REG_2].map_ptr;\n+\tu32 map_uid = caller-\u003eregs[BPF_REG_2].map_uid;\n+\n+\t/*\n+\t * callback_fn(struct bpf_map *map, void *key, void *value);\n+\t */\n+\tcallee-\u003eregs[BPF_REG_1].type = CONST_PTR_TO_MAP;\n+\t__mark_reg_known_zero(\u0026callee-\u003eregs[BPF_REG_1]);\n+\tcallee-\u003eregs[BPF_REG_1].map_ptr = map_ptr;\n+\tcallee-\u003eregs[BPF_REG_1].map_uid = map_uid;\n+\n+\tcallee-\u003eregs[BPF_REG_2].type = PTR_TO_MAP_KEY;\n+\t__mark_reg_known_zero(\u0026callee-\u003eregs[BPF_REG_2]);\n+\tcallee-\u003eregs[BPF_REG_2].map_ptr = map_ptr;\n+\tcallee-\u003eregs[BPF_REG_2].map_uid = map_uid;\n+\n+\tcallee-\u003eregs[BPF_REG_3].type = PTR_TO_MAP_VALUE;\n+\t__mark_reg_known_zero(\u0026callee-\u003eregs[BPF_REG_3]);\n+\tcallee-\u003eregs[BPF_REG_3].map_ptr = map_ptr;\n+\tcallee-\u003eregs[BPF_REG_3].map_uid = map_uid;\n+\n+\t/* unused */\n+\tbpf_mark_reg_not_init(env, \u0026callee-\u003eregs[BPF_REG_4]);\n+\tbpf_mark_reg_not_init(env, \u0026callee-\u003eregs[BPF_REG_5]);\n+\tcallee-\u003ein_async_callback_fn = true;\n+\tcallee-\u003ecallback_ret_range = retval_range(S32_MIN, S32_MAX);\n+\treturn 0;\n+}\n+\n static bool is_rbtree_lock_required_kfunc(u32 btf_id);\n \n static void account_processed_insn(struct bpf_verifier_env *env)\n@@ -12216,7 +12266,8 @@ enum {\n \tKF_ARG_RES_SPIN_LOCK_ID,\n \tKF_ARG_TASK_WORK_ID,\n \tKF_ARG_PROG_AUX_ID,\n-\tKF_ARG_TIMER_ID\n+\tKF_ARG_TIMER_ID,\n+\tKF_ARG_RCU_HEAD_ID\n };\n \n BTF_ID_LIST(kf_arg_btf_ids)\n@@ -12230,6 +12281,7 @@ BTF_ID(struct, bpf_res_spin_lock)\n BTF_ID(struct, bpf_task_work)\n BTF_ID(struct, bpf_prog_aux)\n BTF_ID(struct, bpf_timer)\n+BTF_ID(struct, bpf_rcu_head)\n \n static bool __is_kfunc_ptr_arg_type(const struct btf *btf,\n \t\t\t\t    const struct btf_param *arg, int type)\n@@ -12288,6 +12340,11 @@ static bool is_kfunc_arg_task_work(const struct btf *btf, const struct btf_param\n \treturn __is_kfunc_ptr_arg_type(btf, arg, KF_ARG_TASK_WORK_ID);\n }\n \n+static bool is_kfunc_arg_rcu_head(const struct btf *btf, const struct btf_param *arg)\n+{\n+\treturn __is_kfunc_ptr_arg_type(btf, arg, KF_ARG_RCU_HEAD_ID);\n+}\n+\n static bool is_kfunc_arg_res_spin_lock(const struct btf *btf, const struct btf_param *arg)\n {\n \treturn __is_kfunc_ptr_arg_type(btf, arg, KF_ARG_RES_SPIN_LOCK_ID);\n@@ -12571,6 +12628,8 @@ enum special_kfunc_type {\n \tKF___bpf_trap,\n \tKF_bpf_task_work_schedule_signal,\n \tKF_bpf_task_work_schedule_resume,\n+\tKF_bpf_call_rcu,\n+\tKF_bpf_call_rcu_tasks_trace,\n \tKF_bpf_arena_alloc_pages,\n \tKF_bpf_arena_free_pages,\n \tKF_bpf_arena_reserve_pages,\n@@ -12664,6 +12723,8 @@ BTF_ID(func, bpf_dynptr_file_discard)\n BTF_ID(func, __bpf_trap)\n BTF_ID(func, bpf_task_work_schedule_signal)\n BTF_ID(func, bpf_task_work_schedule_resume)\n+BTF_ID(func, bpf_call_rcu)\n+BTF_ID(func, bpf_call_rcu_tasks_trace)\n BTF_ID(func, bpf_arena_alloc_pages)\n BTF_ID(func, bpf_arena_free_pages)\n BTF_ID(func, bpf_arena_reserve_pages)\n@@ -12735,6 +12796,12 @@ static bool is_bpf_rbtree_add_kfunc(u32 func_id)\n \t       func_id == special_kfunc_list[KF_bpf_rbtree_add_impl];\n }\n \n+static bool is_call_rcu_kfunc(u32 func_id)\n+{\n+\treturn func_id == special_kfunc_list[KF_bpf_call_rcu] ||\n+\t       func_id == special_kfunc_list[KF_bpf_call_rcu_tasks_trace];\n+}\n+\n static bool is_task_work_add_kfunc(u32 func_id)\n {\n \treturn func_id == special_kfunc_list[KF_bpf_task_work_schedule_signal] ||\n@@ -12941,6 +13008,8 @@ get_kfunc_arg_type(struct bpf_verifier_env *env, struct bpf_call_arg_meta *meta,\n \t\targ_type = ARG_PTR_TO_TIMER;\n \telse if (is_kfunc_arg_task_work(meta-\u003ebtf, \u0026args[arg]))\n \t\targ_type = ARG_PTR_TO_TASK_WORK;\n+\telse if (is_kfunc_arg_rcu_head(meta-\u003ebtf, \u0026args[arg]))\n+\t\targ_type = ARG_PTR_TO_RCU_HEAD;\n \telse if (is_kfunc_arg_irq_flag(meta-\u003ebtf, \u0026args[arg]))\n \t\targ_type = ARG_PTR_TO_IRQ_FLAG;\n \telse if (is_kfunc_arg_res_spin_lock(meta-\u003ebtf, \u0026args[arg]))\n@@ -13442,7 +13511,8 @@ static bool is_sync_callback_calling_kfunc(u32 btf_id)\n static bool is_async_callback_calling_kfunc(u32 btf_id)\n {\n \treturn is_bpf_wq_set_callback_kfunc(btf_id) ||\n-\t       is_task_work_add_kfunc(btf_id);\n+\t       is_task_work_add_kfunc(btf_id) ||\n+\t       is_call_rcu_kfunc(btf_id);\n }\n \n bool bpf_is_throw_kfunc(struct bpf_insn *insn)\n@@ -14259,6 +14329,16 @@ static int check_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn,\n \t\t}\n \t}\n \n+\tif (is_call_rcu_kfunc(meta.func_id)) {\n+\t\terr = push_callback_call(env, insn, insn_idx, meta.subprogno,\n+\t\t\t\t\t set_rcu_callback_state);\n+\t\tif (err) {\n+\t\t\tverbose(env, \"kfunc %s#%d failed callback verification\\n\",\n+\t\t\t\tfunc_name, meta.func_id);\n+\t\t\treturn err;\n+\t\t}\n+\t}\n+\n \trcu_lock = is_kfunc_bpf_rcu_read_lock(\u0026meta);\n \trcu_unlock = is_kfunc_bpf_rcu_read_unlock(\u0026meta);\n \ndiff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h\nindex 6330b7d745c57..eafeba23f5da7 100644\n--- a/tools/include/uapi/linux/bpf.h\n+++ b/tools/include/uapi/linux/bpf.h\n@@ -7611,6 +7611,10 @@ struct bpf_task_work {\n \t__u64 __opaque;\n } __attribute__((aligned(8)));\n \n+struct bpf_rcu_head {\n+\t__u64 __opaque[8];\n+} __attribute__((aligned(8)));\n+\n struct bpf_wq {\n \t__u64 __opaque[2];\n } __attribute__((aligned(8)));\ndiff --git a/tools/testing/selftests/bpf/prog_tests/call_rcu.c b/tools/testing/selftests/bpf/prog_tests/call_rcu.c\nnew file mode 100644\nindex 0000000000000..e4d271d43d878\n--- /dev/null\n+++ b/tools/testing/selftests/bpf/prog_tests/call_rcu.c\n@@ -0,0 +1,275 @@\n+// SPDX-License-Identifier: GPL-2.0\n+/* Copyright (c) 2026 Meta Platforms, Inc. and affiliates. */\n+#include \u003ctest_progs.h\u003e\n+#include \"call_rcu.skel.h\"\n+#include \"call_rcu_fail.skel.h\"\n+\n+struct elem {\n+\t__u64 pad;\n+\tstruct bpf_rcu_head rh;\n+\t__u64 val;\n+};\n+\n+/*\n+ * Force the grace period, then poll: the callback still has to be invoked\n+ * afterwards, and call_rcu() is lazy on a CONFIG_RCU_LAZY kernel.\n+ */\n+static bool wait_for_callbacks(struct call_rcu *skel, int expected)\n+{\n+\tint i, got = 0;\n+\n+\tkern_sync_rcu();\n+\tfor (i = 0; i \u003c 3000; i++) {\n+\t\tgot = __atomic_load_n(\u0026skel-\u003ebss-\u003ecallbacks, __ATOMIC_ACQUIRE);\n+\t\tif (got \u003e= expected)\n+\t\t\treturn true;\n+\t\tusleep(10000);\n+\t}\n+\treturn ASSERT_GE(got, expected, \"callbacks\");\n+}\n+\n+static void test_call_rcu_run(bool trace)\n+{\n+\tLIBBPF_OPTS(bpf_test_run_opts, opts);\n+\tstruct bpf_program *prog;\n+\tstruct call_rcu *skel;\n+\tstruct elem elem;\n+\t__u32 key = 1;\n+\tint err;\n+\n+\tskel = call_rcu__open_and_load();\n+\tif (!ASSERT_OK_PTR(skel, \"skel_open_and_load\"))\n+\t\treturn;\n+\n+\tprog = trace ? skel-\u003eprogs.arm_trace : skel-\u003eprogs.arm;\n+\terr = bpf_prog_test_run_opts(bpf_program__fd(prog), \u0026opts);\n+\tif (!ASSERT_OK(err, \"test_run\") || !ASSERT_EQ(opts.retval, 0, \"retval\"))\n+\t\tgoto out;\n+\n+\tASSERT_EQ(skel-\u003ebss-\u003earm_err, 0, \"arm_err\");\n+\tASSERT_EQ(skel-\u003ebss-\u003ebusy_err, -EBUSY, \"busy_err\");\n+\n+\tif (!wait_for_callbacks(skel, 1))\n+\t\tgoto out;\n+\n+\tASSERT_EQ(skel-\u003ebss-\u003ecb_key, key, \"cb_key\");\n+\tASSERT_EQ(skel-\u003ebss-\u003ecb_val, 0xdeadbeef, \"cb_val\");\n+\tASSERT_EQ(skel-\u003ebss-\u003ecb_max_entries, bpf_map__max_entries(skel-\u003emaps.arr), \"cb_map\");\n+\n+\terr = bpf_map__lookup_elem(skel-\u003emaps.arr, \u0026key, sizeof(key), \u0026elem, sizeof(elem), 0);\n+\tif (ASSERT_OK(err, \"lookup\"))\n+\t\tASSERT_EQ(elem.val, 0, \"value_cleared\");\n+\n+\t/* The head is disarmed before the callback runs, so it can be reused. */\n+\terr = bpf_prog_test_run_opts(bpf_program__fd(prog), \u0026opts);\n+\tif (!ASSERT_OK(err, \"test_run_again\"))\n+\t\tgoto out;\n+\tASSERT_EQ(skel-\u003ebss-\u003earm_err, 0, \"rearm_err\");\n+\twait_for_callbacks(skel, 2);\n+out:\n+\tcall_rcu__destroy(skel);\n+}\n+\n+static void test_call_rcu_chain(void)\n+{\n+\tLIBBPF_OPTS(bpf_test_run_opts, opts);\n+\tstruct call_rcu *skel;\n+\n+\tskel = call_rcu__open_and_load();\n+\tif (!ASSERT_OK_PTR(skel, \"skel_open_and_load\"))\n+\t\treturn;\n+\n+\tskel-\u003ebss-\u003echain = 1;\n+\tif (!ASSERT_OK(bpf_prog_test_run_opts(bpf_program__fd(skel-\u003eprogs.arm), \u0026opts), \"test_run\"))\n+\t\tgoto out;\n+\n+\tif (!wait_for_callbacks(skel, 1))\n+\t\tgoto out;\n+\tASSERT_EQ(skel-\u003ebss-\u003echain_err, 0, \"chain_err\");\n+\twait_for_callbacks(skel, 2);\n+out:\n+\tcall_rcu__destroy(skel);\n+}\n+\n+/*\n+ * A callback that keeps re-arming must stop once the map loses its last user\n+ * reference, or it pins the program for good.  Hold an independent fd on .bss\n+ * so the refusal is still readable after the skeleton is gone.\n+ */\n+static void test_call_rcu_teardown(void)\n+{\n+\tLIBBPF_OPTS(bpf_test_run_opts, opts);\n+\tint i, err, fd = 0, bss_fd = -1;\n+\tstruct bpf_prog_info pinfo = {};\n+\tstruct bpf_map_info minfo = {};\n+\t__u32 len, prog_id, zero = 0;\n+\tstruct call_rcu *skel;\n+\tchar *buf = NULL;\n+\tsize_t off, vsz;\n+\n+\tskel = call_rcu__open_and_load();\n+\tif (!ASSERT_OK_PTR(skel, \"skel_open_and_load\"))\n+\t\treturn;\n+\n+\tlen = sizeof(pinfo);\n+\tif (!ASSERT_OK(bpf_prog_get_info_by_fd(bpf_program__fd(skel-\u003eprogs.arm), \u0026pinfo, \u0026len),\n+\t\t       \"prog_info\"))\n+\t\tgoto out;\n+\tprog_id = pinfo.id;\n+\n+\tlen = sizeof(minfo);\n+\tif (!ASSERT_OK(bpf_map_get_info_by_fd(bpf_map__fd(skel-\u003emaps.bss), \u0026minfo, \u0026len),\n+\t\t       \"bss_info\"))\n+\t\tgoto out;\n+\tbss_fd = bpf_map_get_fd_by_id(minfo.id);\n+\tif (!ASSERT_GE(bss_fd, 0, \"bss_fd\"))\n+\t\tgoto out;\n+\n+\tvsz = bpf_map__value_size(skel-\u003emaps.bss);\n+\toff = (char *)\u0026skel-\u003ebss-\u003echain_err - (char *)skel-\u003ebss;\n+\tbuf = malloc(vsz);\n+\tif (!ASSERT_OK_PTR(buf, \"buf\"))\n+\t\tgoto out;\n+\n+\tskel-\u003ebss-\u003echain = INT_MAX;\n+\terr = bpf_prog_test_run_opts(bpf_program__fd(skel-\u003eprogs.arm), \u0026opts);\n+\tif (!ASSERT_OK(err, \"test_run\") || !ASSERT_EQ(opts.retval, 0, \"retval\"))\n+\t\tgoto out;\n+\tif (!ASSERT_EQ(skel-\u003ebss-\u003earm_err, 0, \"arm_err\"))\n+\t\tgoto out;\n+\t/* The chain has to be running before the map reference goes away. */\n+\tif (!wait_for_callbacks(skel, 2))\n+\t\tgoto out;\n+\n+\tcall_rcu__destroy(skel);\n+\tskel = NULL;\n+\n+\tfor (i = 0; i \u003c 3000; i++) {\n+\t\tfd = bpf_prog_get_fd_by_id(prog_id);\n+\t\tif (fd \u003c 0)\n+\t\t\tbreak;\n+\t\tclose(fd);\n+\t\tusleep(10000);\n+\t}\n+\tif (!ASSERT_EQ(fd, -ENOENT, \"prog_freed\"))\n+\t\tgoto out;\n+\n+\tif (ASSERT_OK(bpf_map_lookup_elem(bss_fd, \u0026zero, buf), \"bss_lookup\"))\n+\t\tASSERT_EQ(*(int *)(buf + off), -EPERM, \"chain_refused\");\n+out:\n+\tfree(buf);\n+\tif (bss_fd \u003e= 0)\n+\t\tclose(bss_fd);\n+\tcall_rcu__destroy(skel);\n+}\n+\n+static void test_call_rcu_bad_map(void)\n+{\n+\tLIBBPF_OPTS(bpf_map_create_opts, opts);\n+\tstruct call_rcu *skel;\n+\tint fd;\n+\n+\tskel = call_rcu__open_and_load();\n+\tif (!ASSERT_OK_PTR(skel, \"skel_open_and_load\"))\n+\t\treturn;\n+\n+\topts.btf_fd = bpf_object__btf_fd(skel-\u003eobj);\n+\topts.btf_key_type_id = bpf_map__btf_key_type_id(skel-\u003emaps.arr);\n+\topts.btf_value_type_id = bpf_map__btf_value_type_id(skel-\u003emaps.arr);\n+\n+\tfd = bpf_map_create(BPF_MAP_TYPE_HASH, \"rcu_hash\", sizeof(__u32),\n+\t\t\t    bpf_map__value_size(skel-\u003emaps.arr), 1, \u0026opts);\n+\tASSERT_EQ(fd, -EOPNOTSUPP, \"hash_rejected\");\n+\tif (fd \u003e= 0)\n+\t\tclose(fd);\n+\n+\tcall_rcu__destroy(skel);\n+}\n+\n+/* Iterating would hand the program a writable pointer to the head. */\n+static void test_call_rcu_iter(void)\n+{\n+\tLIBBPF_OPTS(bpf_iter_attach_opts, opts);\n+\tunion bpf_iter_link_info linfo = {};\n+\tstruct bpf_link *link;\n+\tstruct call_rcu *skel;\n+\n+\tskel = call_rcu__open_and_load();\n+\tif (!ASSERT_OK_PTR(skel, \"skel_open_and_load\"))\n+\t\treturn;\n+\n+\tlinfo.map.map_fd = bpf_map__fd(skel-\u003emaps.arr);\n+\topts.link_info = \u0026linfo;\n+\topts.link_info_len = sizeof(linfo);\n+\n+\tlink = bpf_program__attach_iter(skel-\u003eprogs.dump, \u0026opts);\n+\tif (!ASSERT_ERR_PTR(link, \"iter_rejected\"))\n+\t\tbpf_link__destroy(link);\n+\telse\n+\t\tASSERT_EQ(libbpf_get_error(link), -EOPNOTSUPP, \"iter_errno\");\n+\n+\tcall_rcu__destroy(skel);\n+}\n+\n+static void test_call_rcu_inner_map(void)\n+{\n+\tLIBBPF_OPTS(bpf_map_create_opts, opts);\n+\tstruct call_rcu *skel;\n+\tint fd;\n+\n+\tskel = call_rcu__open_and_load();\n+\tif (!ASSERT_OK_PTR(skel, \"skel_open_and_load\"))\n+\t\treturn;\n+\n+\topts.inner_map_fd = bpf_map__fd(skel-\u003emaps.arr);\n+\tfd = bpf_map_create(BPF_MAP_TYPE_ARRAY_OF_MAPS, \"rcu_outer\",\n+\t\t\t    sizeof(__u32), sizeof(__u32), 1, \u0026opts);\n+\tASSERT_EQ(fd, -EOPNOTSUPP, \"inner_map_rejected\");\n+\tif (fd \u003e= 0)\n+\t\tclose(fd);\n+\n+\tcall_rcu__destroy(skel);\n+}\n+\n+/* Two heads in the same map must be independent. */\n+static void test_call_rcu_two_heads(void)\n+{\n+\tLIBBPF_OPTS(bpf_test_run_opts, opts);\n+\tstruct call_rcu *skel;\n+\n+\tskel = call_rcu__open_and_load();\n+\tif (!ASSERT_OK_PTR(skel, \"skel_open_and_load\"))\n+\t\treturn;\n+\n+\tif (!ASSERT_OK(bpf_prog_test_run_opts(bpf_program__fd(skel-\u003eprogs.arm_both), \u0026opts),\n+\t\t       \"test_run\"))\n+\t\tgoto out;\n+\tif (!ASSERT_EQ(skel-\u003ebss-\u003earm_err, 0, \"arm_err\"))\n+\t\tgoto out;\n+\tif (!wait_for_callbacks(skel, 2))\n+\t\tgoto out;\n+\tASSERT_EQ(skel-\u003ebss-\u003ecb_keys, 0x3, \"both_keys\");\n+out:\n+\tcall_rcu__destroy(skel);\n+}\n+\n+void test_call_rcu(void)\n+{\n+\tif (test__start_subtest(\"run\"))\n+\t\ttest_call_rcu_run(false);\n+\tif (test__start_subtest(\"run_tasks_trace\"))\n+\t\ttest_call_rcu_run(true);\n+\tif (test__start_subtest(\"chain\"))\n+\t\ttest_call_rcu_chain();\n+\tif (test__start_subtest(\"two_heads\"))\n+\t\ttest_call_rcu_two_heads();\n+\tif (test__start_subtest(\"teardown\"))\n+\t\ttest_call_rcu_teardown();\n+\tif (test__start_subtest(\"bad_map\"))\n+\t\ttest_call_rcu_bad_map();\n+\tif (test__start_subtest(\"iter\"))\n+\t\ttest_call_rcu_iter();\n+\tif (test__start_subtest(\"inner_map\"))\n+\t\ttest_call_rcu_inner_map();\n+\tRUN_TESTS(call_rcu_fail);\n+}\ndiff --git a/tools/testing/selftests/bpf/progs/call_rcu.c b/tools/testing/selftests/bpf/progs/call_rcu.c\nnew file mode 100644\nindex 0000000000000..505008647fd6f\n--- /dev/null\n+++ b/tools/testing/selftests/bpf/progs/call_rcu.c\n@@ -0,0 +1,110 @@\n+// SPDX-License-Identifier: GPL-2.0\n+/* Copyright (c) 2026 Meta Platforms, Inc. and affiliates. */\n+\n+#include \u003cvmlinux.h\u003e\n+#include \u003cbpf/bpf_helpers.h\u003e\n+\n+char _license[] SEC(\"license\") = \"GPL\";\n+\n+/* rh is not at offset 0, so the callback's value recovery is exercised. */\n+struct elem {\n+\t__u64 pad;\n+\tstruct bpf_rcu_head rh;\n+\t__u64 val;\n+};\n+\n+struct {\n+\t__uint(type, BPF_MAP_TYPE_ARRAY);\n+\t__uint(max_entries, 2);\n+\t__type(key, __u32);\n+\t__type(value, struct elem);\n+} arr SEC(\".maps\");\n+\n+__u32 cb_key;\n+__u64 cb_keys;\n+__u64 cb_val;\n+__u32 cb_max_entries;\n+int callbacks;\n+int arm_err;\n+int busy_err;\n+int chain;\t\t/* set by userspace: number of times to re-arm from the callback */\n+int chain_err;\n+\n+static int reclaim(struct bpf_map *map, void *key, void *value)\n+{\n+\tstruct elem *e = value;\n+\n+\tcb_key = *(__u32 *)key;\n+\t__sync_fetch_and_or(\u0026cb_keys, 1ULL \u003c\u003c cb_key);\n+\tcb_val = e-\u003eval;\n+\tcb_max_entries = map-\u003emax_entries;\n+\te-\u003eval = 0;\n+\n+\tif (chain \u003e 0) {\n+\t\tchain--;\n+\t\tchain_err = bpf_call_rcu(\u0026e-\u003erh, \u0026arr, reclaim);\n+\t}\n+\n+\t__sync_fetch_and_add(\u0026callbacks, 1);\n+\treturn 0;\n+}\n+\n+SEC(\"syscall\")\n+int arm(void *ctx)\n+{\n+\t__u32 key = 1;\n+\tstruct elem *e;\n+\n+\te = bpf_map_lookup_elem(\u0026arr, \u0026key);\n+\tif (!e)\n+\t\treturn 1;\n+\n+\te-\u003eval = 0xdeadbeef;\n+\t/* Keep a grace period from elapsing between the two arms. */\n+\tbpf_rcu_read_lock();\n+\tarm_err = bpf_call_rcu(\u0026e-\u003erh, \u0026arr, reclaim);\n+\tbusy_err = bpf_call_rcu(\u0026e-\u003erh, \u0026arr, reclaim);\n+\tbpf_rcu_read_unlock();\n+\treturn 0;\n+}\n+\n+SEC(\"syscall\")\n+int arm_both(void *ctx)\n+{\n+\t__u32 key0 = 0, key1 = 1;\n+\tstruct elem *e0, *e1;\n+\n+\te0 = bpf_map_lookup_elem(\u0026arr, \u0026key0);\n+\te1 = bpf_map_lookup_elem(\u0026arr, \u0026key1);\n+\tif (!e0 || !e1)\n+\t\treturn 1;\n+\n+\te0-\u003eval = 0xdeadbeef;\n+\te1-\u003eval = 0xdeadbeef;\n+\tarm_err = bpf_call_rcu(\u0026e0-\u003erh, \u0026arr, reclaim);\n+\tarm_err |= bpf_call_rcu(\u0026e1-\u003erh, \u0026arr, reclaim);\n+\treturn 0;\n+}\n+\n+SEC(\"syscall\")\n+int arm_trace(void *ctx)\n+{\n+\t__u32 key = 1;\n+\tstruct elem *e;\n+\n+\te = bpf_map_lookup_elem(\u0026arr, \u0026key);\n+\tif (!e)\n+\t\treturn 1;\n+\n+\te-\u003eval = 0xdeadbeef;\n+\t/* No lock needed: the enclosing rcu_read_lock_trace() already blocks the grace period. */\n+\tarm_err = bpf_call_rcu_tasks_trace(\u0026e-\u003erh, \u0026arr, reclaim);\n+\tbusy_err = bpf_call_rcu_tasks_trace(\u0026e-\u003erh, \u0026arr, reclaim);\n+\treturn 0;\n+}\n+\n+SEC(\"iter/bpf_map_elem\")\n+int dump(struct bpf_iter__bpf_map_elem *ctx)\n+{\n+\treturn 0;\n+}\ndiff --git a/tools/testing/selftests/bpf/progs/call_rcu_fail.c b/tools/testing/selftests/bpf/progs/call_rcu_fail.c\nnew file mode 100644\nindex 0000000000000..bf60a27731fb3\n--- /dev/null\n+++ b/tools/testing/selftests/bpf/progs/call_rcu_fail.c\n@@ -0,0 +1,114 @@\n+// SPDX-License-Identifier: GPL-2.0\n+/* Copyright (c) 2026 Meta Platforms, Inc. and affiliates. */\n+\n+#include \u003cvmlinux.h\u003e\n+#include \u003cbpf/bpf_helpers.h\u003e\n+#include \"bpf_misc.h\"\n+\n+char _license[] SEC(\"license\") = \"GPL\";\n+\n+const void *user_ptr = NULL;\n+\n+struct elem {\n+\t__u64 pad;\n+\tstruct bpf_rcu_head rh;\n+\t__u64 val;\n+};\n+\n+struct {\n+\t__uint(type, BPF_MAP_TYPE_ARRAY);\n+\t__uint(max_entries, 1);\n+\t__type(key, __u32);\n+\t__type(value, struct elem);\n+} arr SEC(\".maps\");\n+\n+struct {\n+\t__uint(type, BPF_MAP_TYPE_ARRAY);\n+\t__uint(max_entries, 1);\n+\t__type(key, __u32);\n+\t__type(value, struct elem);\n+} arr2 SEC(\".maps\");\n+\n+struct {\n+\t__uint(type, BPF_MAP_TYPE_ARRAY);\n+\t__uint(max_entries, 1);\n+\t__type(key, __u32);\n+\t__type(value, __u64);\n+} plain SEC(\".maps\");\n+\n+__u32 key = 0;\n+\n+static int reclaim(struct bpf_map *map, void *key, void *value)\n+{\n+\treturn 0;\n+}\n+\n+static int sleepable_reclaim(struct bpf_map *map, void *key, void *value)\n+{\n+\tstruct elem *e = value;\n+\n+\tbpf_copy_from_user(\u0026e-\u003eval, sizeof(e-\u003eval), user_ptr);\n+\treturn 0;\n+}\n+\n+SEC(\"syscall\")\n+__failure __msg(\"bpf_rcu_head pointer in R1\") __msg(\"doesn't match map pointer in R2\")\n+int mismatch_map(void *ctx)\n+{\n+\tstruct elem *e;\n+\n+\te = bpf_map_lookup_elem(\u0026arr, \u0026key);\n+\tif (!e)\n+\t\treturn 0;\n+\tbpf_call_rcu(\u0026e-\u003erh, \u0026arr2, reclaim);\n+\treturn 0;\n+}\n+\n+SEC(\"syscall\")\n+__failure __msg(\"map 'plain' has no valid bpf_rcu_head\")\n+int no_rcu_head(void *ctx)\n+{\n+\t__u64 *val;\n+\n+\tval = bpf_map_lookup_elem(\u0026plain, \u0026key);\n+\tif (!val)\n+\t\treturn 0;\n+\tbpf_call_rcu((struct bpf_rcu_head *)val, \u0026plain, reclaim);\n+\treturn 0;\n+}\n+\n+SEC(\"syscall\")\n+__failure __msg(\"doesn't point to 'struct bpf_rcu_head' that is at 8\")\n+int wrong_offset(void *ctx)\n+{\n+\tstruct elem *e;\n+\n+\te = bpf_map_lookup_elem(\u0026arr, \u0026key);\n+\tif (!e)\n+\t\treturn 0;\n+\tbpf_call_rcu((struct bpf_rcu_head *)\u0026e-\u003epad, \u0026arr, reclaim);\n+\treturn 0;\n+}\n+\n+SEC(\"syscall\")\n+__failure __msg(\"R1 type=fp expected=map_value\")\n+int rcu_head_on_stack(void *ctx)\n+{\n+\tstruct bpf_rcu_head rh;\n+\n+\tbpf_call_rcu(\u0026rh, \u0026arr, reclaim);\n+\treturn 0;\n+}\n+\n+SEC(\"syscall\")\n+__failure __msg(\"sleepable helper bpf_copy_from_user\") __msg(\"in non-sleepable prog\")\n+int sleepable_callback(void *ctx)\n+{\n+\tstruct elem *e;\n+\n+\te = bpf_map_lookup_elem(\u0026arr, \u0026key);\n+\tif (!e)\n+\t\treturn 0;\n+\tbpf_call_rcu(\u0026e-\u003erh, \u0026arr, sleepable_reclaim);\n+\treturn 0;\n+}\n"
}

2/1 2026/09/23 19:45 agent patch-evaluator
1m Model:
core

Args:
null

Results:
{
  "EnableConfigs": [
    "BPF_SYSCALL",
    "DEBUG_INFO_BTF"
  ],
  "FocusSymbols": [
    "bpf_call_rcu",
    "bpf_call_rcu_tasks_trace",
    "bpf_rcu_run_callback",
    "__bpf_call_rcu",
    "set_rcu_callback_state"
  ],
  "Reasoning": "The patch series introduces BPF support for asynchronous RCU callbacks via `struct bpf_rcu_head` and kfuncs `bpf_call_rcu` and `bpf_call_rcu_tasks_trace`. This touches the BPF verifier, core BPF helpers, BTF parsing, and map subsystem. It executes in standard virtualized environments and handles asynchronous execution, reference counting, and RCU callbacks, making it well-suited for fuzzing.",
  "WorthFuzzing": true
}

Instruction:
You are an expert Linux kernel maintainer and security engineer.
Your job is to review a provided patch series and evaluate whether it warrants fuzzing with syzkaller.

IMPORTANT: The changes have ALREADY been applied and committed as the HEAD commit in
your workspace. Do NOT rely on internal assumptions. You must actively use your code access
tools to inspect the actual source code, callers, and surrounding context.

================================================================================
1. CORE TRIAGE PHILOSOPHY
================================================================================
The goal of patch fuzzing is to discover crashes, regressions, exposed latent bugs,
and newly triggered assertions introduced by the patch series.

- REACHABILITY IS THE PRIMARY GATE:
  Fuzzing can only discover bugs in code that can actually execute in standard virtualized
  environments (GCE or QEMU, utilizing software-emulated devices like USB gadgets, netdev, tun/tap).
  If the modified code is structurally unreachable (see Section 2), it MUST NOT be fuzzed,
  regardless of whether it adds assertions or complex logic.

- DO NOT BLINDLY TRUST "NO FUNCTIONAL CHANGE" (NFCI) OR "REFACTORING" CLAIMS:
  Patch authors routinely label changes as "cleanups", "refactorings", or state
  "No functional change intended". Do NOT take these claims at face value.
  Code refactorings that rearrange logic, introduce helper functions, or alter state management
  in core subsystems frequently introduce subtle semantic shifts or uncover latent kernel bugs.
  If reachable executable code is modified or refactored, it MUST be fuzzed.

- NEW OR MODIFIED ASSERTIONS IN REACHABLE CODE MUST BE FUZZED:
  When a patch introduces or modifies runtime checks or assertions (e.g., WARN_ON*, VM_WARN_ON*,
  BUG_ON*, lockdep_assert*) in reachable code paths, it enforces new or stricter invariants.
  Even if the author believes the invariant always holds, fuzzing is essential to verify whether
  an unusual sequence of operations can violate it.

================================================================================
2. WHEN TO RETURN WorthFuzzing=false (NEGATIVE CRITERIA)
================================================================================
Return WorthFuzzing=false ONLY IF all modified code falls strictly into one or more of these categories:

- Non-kernel and non-executable changes:
  * Modifications to Documentation/, comments, or spelling fixes.
  * User-space directories, self-tests, samples, or scripts (e.g., tools/, samples/, scripts/, usr/)
    that do not affect the compiled kernel image (vmlinux) or kernel modules.
  * Purely decorative logging (e.g., message strings in pr_err, printk, dev_info) or tracepoints
    that do not alter control flow or data structures.
  * Build system or Kconfig changes that do not alter compiled C logic.
- Structurally unreachable hardware:
  * Vendor-specific PCIe switches, SmartNICs, or GPU drivers (e.g., mlxsw, pds_core, qed,
    ionic, amdgpu) requiring physical ASIC/PCIe cards not emulated in standard QEMU.
- Unreachable execution paths:
  * Driver teardown callbacks (.remove, .shutdown, pci_unregister_driver) executed only during
    physical PCI hot-unplug or manual sysfs driver unbinding.
  * Code paths exclusive to architectures other than the target architecture.

================================================================================
3. WHEN TO RETURN WorthFuzzing=true (POSITIVE CRITERIA)
================================================================================
Return WorthFuzzing=true whenever the patch touches reachable executable code, including:
- Core Subsystems:
  * Any logic modifications in memory management (mm/), synchronization/locking (kernel/locking/),
    BPF, scheduler, core networking, VFS, or syscall handling.
- Refactorings and Code Cleanups:
  * Any restructuring of reachable data structures, helper abstractions, or algorithm flows.
- Runtime Assertions and Defensive Checks:
  * Any introduction or alteration of assertions (WARN_ON*, VM_WARN_ON*, BUG_ON*, etc.) in reachable paths.
- Reachable Drivers and Protocols:
  * Drivers accessible via virtual buses (virtio, USB gadget, loopback, netlink, binder, sockets, etc.).

================================================================================
4. EXTRACTING FocusSymbols (PREVENTING DILUTION)
================================================================================
When WorthFuzzing=true, you must extract specific kernel functions into FocusSymbols to guide the fuzzer:

- AVOID UBIQUITOUS LIFECYCLE HOT-PATHS:
  Do NOT list generic, ubiquitous functions called by almost every program in the corpus
  (including, but not limited to: general memory allocators and deallocators, page fault
  and trap handlers, or core synchronization primitives; this is not an exhaustive list).
  Listing ubiquitous functions causes the fuzzer to classify thousands of unrelated tests as "focused",
  which severely dilutes fuzzing effort away from the actual changes.

- TARGET SPECIFIC FEATURE LOGIC AND ENTRYPOINTS:
  List functions that specifically implement the logic being added or altered, or direct API entrypoints
  for the subsystem feature under review.

- HANDLING STATIC INLINE FUNCTIONS IN HEADERS (.h):
  Compiler-inlined static functions (such as static inlines in mm/*.h or include/linux/*.h) lack
  distinct symbol addresses in vmlinux and cannot be targeted directly by symbol coverage filters.
  If the changes are primarily in static inline helpers, identify non-static, feature-specific caller
  functions in .c files that exercise them (avoiding ubiquitous lifecycle wrappers).

================================================================================
5. IDENTIFYING EnableConfigs
================================================================================
Identify any specific CONFIG_ options required to properly compile and reach the modified code:
- Inspect Kconfig files and #ifdef guards; do not make assumptions.
- Check "depends on" lines in Kconfig to include any non-standard parent subsystem configs needed.
- Strip any 'CONFIG_' prefix (e.g., return "NET_IPV4" instead of "CONFIG_NET_IPV4").
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:
Target architecture: amd64

For your convenience, here is the diff of the changes:
commit 53dabebe1086ff9808c18c85bd1d583e876072cc
Author: syz-cluster <triage@syzkaller.com>
Date:   Wed Sep 23 19:45:15 2026 +0000

    syz-cluster: applied patch under review

diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index fd22db8bc6c50..e7c5e203edddb 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -215,6 +215,7 @@ enum btf_field_type {
 	BPF_UPTR       = (1 << 11),
 	BPF_RES_SPIN_LOCK = (1 << 12),
 	BPF_TASK_WORK  = (1 << 13),
+	BPF_RCU_HEAD   = (1 << 14),
 };
 
 enum bpf_cgroup_storage_type {
@@ -269,6 +270,7 @@ struct btf_record {
 	int wq_off;
 	int refcount_off;
 	int task_work_off;
+	int rcu_head_off;
 	struct btf_field fields[];
 };
 
@@ -374,6 +376,8 @@ static inline const char *btf_field_type_name(enum btf_field_type type)
 		return "bpf_refcount";
 	case BPF_TASK_WORK:
 		return "bpf_task_work";
+	case BPF_RCU_HEAD:
+		return "bpf_rcu_head";
 	default:
 		WARN_ON_ONCE(1);
 		return "unknown";
@@ -414,6 +418,8 @@ static inline u32 btf_field_type_size(enum btf_field_type type)
 		return sizeof(struct bpf_refcount);
 	case BPF_TASK_WORK:
 		return sizeof(struct bpf_task_work);
+	case BPF_RCU_HEAD:
+		return sizeof(struct bpf_rcu_head);
 	default:
 		WARN_ON_ONCE(1);
 		return 0;
@@ -448,6 +454,8 @@ static inline u32 btf_field_type_align(enum btf_field_type type)
 		return __alignof__(struct bpf_refcount);
 	case BPF_TASK_WORK:
 		return __alignof__(struct bpf_task_work);
+	case BPF_RCU_HEAD:
+		return __alignof__(struct bpf_rcu_head);
 	default:
 		WARN_ON_ONCE(1);
 		return 0;
@@ -480,6 +488,7 @@ static inline void bpf_obj_init_field(const struct btf_field *field, void *addr)
 	case BPF_KPTR_PERCPU:
 	case BPF_UPTR:
 	case BPF_TASK_WORK:
+	case BPF_RCU_HEAD:
 		break;
 	default:
 		WARN_ON_ONCE(1);
@@ -925,6 +934,7 @@ enum bpf_arg_type {
 	ARG_PTR_TO_RB_NODE,	/* pointer to bpf_rb_node */
 	ARG_PTR_TO_WORKQUEUE,	/* pointer to bpf_wq */
 	ARG_PTR_TO_TASK_WORK,	/* pointer to bpf_task_work */
+	ARG_PTR_TO_RCU_HEAD,	/* pointer to bpf_rcu_head */
 	ARG_PTR_TO_IRQ_FLAG,	/* pointer to saved IRQ flags on the stack */
 	ARG_PTR_TO_RES_SPIN_LOCK,	/* pointer to bpf_res_spin_lock */
 	ARG_PTR_TO_CTX_OUT,	/* hook output argument passed through from ctx */
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index 6330b7d745c57..eafeba23f5da7 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -7611,6 +7611,10 @@ struct bpf_task_work {
 	__u64 __opaque;
 } __attribute__((aligned(8)));
 
+struct bpf_rcu_head {
+	__u64 __opaque[8];
+} __attribute__((aligned(8)));
+
 struct bpf_wq {
 	__u64 __opaque[2];
 } __attribute__((aligned(8)));
diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
index 314ecb0e593b0..4a1fa4fbdf4e8 100644
--- a/kernel/bpf/btf.c
+++ b/kernel/bpf/btf.c
@@ -3696,6 +3696,7 @@ static int btf_get_field_type(const struct btf *btf, const struct btf_type *var_
 		{ BPF_TIMER, "bpf_timer", true },
 		{ BPF_WORKQUEUE, "bpf_wq", true },
 		{ BPF_TASK_WORK, "bpf_task_work", true },
+		{ BPF_RCU_HEAD, "bpf_rcu_head", true },
 		{ BPF_LIST_HEAD, "bpf_list_head", false },
 		{ BPF_LIST_NODE, "bpf_list_node", false },
 		{ BPF_RB_ROOT, "bpf_rb_root", false },
@@ -3881,6 +3882,7 @@ static int btf_find_field_one(const struct btf *btf,
 	case BPF_RB_NODE:
 	case BPF_REFCOUNT:
 	case BPF_TASK_WORK:
+	case BPF_RCU_HEAD:
 		ret = btf_find_struct(btf, var_type, off, sz, field_type,
 				      info_cnt ? &info[0] : &tmp);
 		if (ret < 0)
@@ -4176,6 +4178,7 @@ struct btf_record *btf_parse_fields(const struct btf *btf, const struct btf_type
 	rec->wq_off = -EINVAL;
 	rec->refcount_off = -EINVAL;
 	rec->task_work_off = -EINVAL;
+	rec->rcu_head_off = -EINVAL;
 	for (i = 0; i < cnt; i++) {
 		field_type_size = btf_field_type_size(info_arr[i].type);
 		if (info_arr[i].off + field_type_size > value_size) {
@@ -4219,6 +4222,10 @@ struct btf_record *btf_parse_fields(const struct btf *btf, const struct btf_type
 			WARN_ON_ONCE(rec->task_work_off >= 0);
 			rec->task_work_off = rec->fields[i].offset;
 			break;
+		case BPF_RCU_HEAD:
+			WARN_ON_ONCE(rec->rcu_head_off >= 0);
+			rec->rcu_head_off = rec->fields[i].offset;
+			break;
 		case BPF_REFCOUNT:
 			WARN_ON_ONCE(rec->refcount_off >= 0);
 			/* Cache offset for faster lookup at runtime */
diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c
index 501c7ce35cba9..301b35bd85c8a 100644
--- a/kernel/bpf/helpers.c
+++ b/kernel/bpf/helpers.c
@@ -4805,6 +4805,106 @@ __bpf_kfunc int bpf_task_work_schedule_resume(struct task_struct *task, struct b
 	return bpf_task_work_schedule(task, tw, map__const_map, callback, aux, TWA_RESUME);
 }
 
+typedef int (*bpf_rcu_callback_t)(struct bpf_map *map, void *key, void *value);
+
+/* Actual type for struct bpf_rcu_head */
+struct bpf_rcu_head_kern {
+	struct rcu_head rcu;
+	bpf_callback_t callback_fn;
+	struct bpf_map *map;
+	struct bpf_prog *prog;
+	u32 armed;
+} __aligned(8);
+
+static void bpf_rcu_run_callback(struct rcu_head *rcu)
+{
+	struct bpf_rcu_head_kern *rh = container_of(rcu, struct bpf_rcu_head_kern, rcu);
+	bpf_callback_t callback_fn = rh->callback_fn;
+	struct bpf_prog *prog = rh->prog;
+	struct bpf_map *map = rh->map;
+	void *value, *key;
+	u32 idx;
+
+	value = (void *)rh - map->record->rcu_head_off;
+	key = map_key_from_value(map, value, &idx);
+
+	/* Pairs with the arming cmpxchg(): rh may be re-armed as soon as this store lands. */
+	smp_store_release(&rh->armed, 0);
+
+	rcu_read_lock_dont_migrate();
+	callback_fn((u64)(long)map, (u64)(long)key, (u64)(long)value, 0, 0);
+	rcu_read_unlock_migrate();
+
+	bpf_prog_put(prog);
+}
+
+static int __bpf_call_rcu(struct bpf_rcu_head *rh, struct bpf_map *map, void *callback,
+			  struct bpf_prog_aux *aux, bool trace)
+{
+	struct bpf_rcu_head_kern *rhk = (void *)rh;
+	struct bpf_prog *prog;
+
+	BUILD_BUG_ON(sizeof(struct bpf_rcu_head_kern) > sizeof(struct bpf_rcu_head));
+	BUILD_BUG_ON(__alignof__(struct bpf_rcu_head_kern) != __alignof__(struct bpf_rcu_head));
+	BTF_TYPE_EMIT(struct bpf_rcu_head);
+
+	/* A queued callback cannot be cancelled, so a self-rearming one would pin prog and map. */
+	if (!atomic64_read(&map->usercnt))
+		return -EPERM;
+
+	if (cmpxchg(&rhk->armed, 0, 1))
+		return -EBUSY;
+
+	prog = bpf_prog_inc_not_zero(aux->prog);
+	if (IS_ERR(prog)) {
+		WRITE_ONCE(rhk->armed, 0);
+		return -EBADF;
+	}
+
+	rhk->callback_fn = (bpf_callback_t)callback;
+	rhk->map = map;
+	rhk->prog = prog;
+	if (trace)
+		call_rcu_tasks_trace(&rhk->rcu, bpf_rcu_run_callback);
+	else
+		call_rcu(&rhk->rcu, bpf_rcu_run_callback);
+	return 0;
+}
+
+/**
+ * bpf_call_rcu - Invoke a BPF callback after an RCU grace period
+ * @rh: struct bpf_rcu_head in a BPF map value
+ * @map__const_map: bpf_map that embeds struct bpf_rcu_head in the values
+ * @callback: BPF subprogram, invoked as callback(map, key, value) for the value holding @rh
+ * @aux: bpf_prog_aux of the caller, implicitly set by the verifier
+ *
+ * Return: 0, -EBUSY if @rh is already queued, -EPERM if @map is held by neither a process
+ * nor bpffs, or -EBADF if the calling program is going away.
+ */
+__bpf_kfunc int bpf_call_rcu(struct bpf_rcu_head *rh, void *map__const_map,
+			     bpf_rcu_callback_t callback, struct bpf_prog_aux *aux)
+{
+	return __bpf_call_rcu(rh, map__const_map, callback, aux, false);
+}
+
+/**
+ * bpf_call_rcu_tasks_trace - Invoke a BPF callback after an RCU tasks trace grace period
+ * @rh: struct bpf_rcu_head in a BPF map value
+ * @map__const_map: bpf_map that embeds struct bpf_rcu_head in the values
+ * @callback: BPF subprogram, invoked as callback(map, key, value) for the value holding @rh
+ * @aux: bpf_prog_aux of the caller, implicitly set by the verifier
+ *
+ * Waits for sleepable BPF programs too.  The callback itself is not sleepable either way.
+ *
+ * Return: 0, -EBUSY if @rh is already queued, -EPERM if @map is held by neither a process
+ * nor bpffs, or -EBADF if the calling program is going away.
+ */
+__bpf_kfunc int bpf_call_rcu_tasks_trace(struct bpf_rcu_head *rh, void *map__const_map,
+					 bpf_rcu_callback_t callback, struct bpf_prog_aux *aux)
+{
+	return __bpf_call_rcu(rh, map__const_map, callback, aux, true);
+}
+
 static int make_file_dynptr(struct file *file, u32 flags, bool may_sleep,
 			    struct bpf_dynptr_kern *ptr)
 {
@@ -5100,6 +5200,8 @@ BTF_ID_FLAGS(func, bpf_stream_vprintk, KF_IMPLICIT_ARGS | KF_SPINLOCK_SAFE)
 BTF_ID_FLAGS(func, bpf_stream_print_stack, KF_IMPLICIT_ARGS | KF_SPINLOCK_SAFE)
 BTF_ID_FLAGS(func, bpf_task_work_schedule_signal, KF_IMPLICIT_ARGS)
 BTF_ID_FLAGS(func, bpf_task_work_schedule_resume, KF_IMPLICIT_ARGS)
+BTF_ID_FLAGS(func, bpf_call_rcu, KF_IMPLICIT_ARGS)
+BTF_ID_FLAGS(func, bpf_call_rcu_tasks_trace, KF_IMPLICIT_ARGS)
 BTF_ID_FLAGS(func, bpf_dynptr_from_file)
 BTF_ID_FLAGS(func, bpf_dynptr_file_discard, KF_RELEASE)
 BTF_ID_FLAGS(func, bpf_timer_cancel_async)
diff --git a/kernel/bpf/map_in_map.c b/kernel/bpf/map_in_map.c
index d2cbab4bdf644..5ee8aae7435ba 100644
--- a/kernel/bpf/map_in_map.c
+++ b/kernel/bpf/map_in_map.c
@@ -25,6 +25,10 @@ struct bpf_map *bpf_map_meta_alloc(int inner_map_ufd)
 	if (!inner_map->ops->map_meta_equal)
 		return ERR_PTR(-ENOTSUPP);
 
+	/* An inner map has no used_maps reference to hold it under a queued callback. */
+	if (btf_record_has_field(inner_map->record, BPF_RCU_HEAD))
+		return ERR_PTR(-EOPNOTSUPP);
+
 	inner_map_meta_size = sizeof(*inner_map_meta);
 	/* In some cases verifier needs to access beyond just base map. */
 	if (inner_map->ops == &array_map_ops || inner_map->ops == &percpu_array_map_ops)
diff --git a/kernel/bpf/map_iter.c b/kernel/bpf/map_iter.c
index c19b360bad9ea..2077d46d167c7 100644
--- a/kernel/bpf/map_iter.c
+++ b/kernel/bpf/map_iter.c
@@ -117,6 +117,12 @@ static int bpf_iter_attach_map(struct bpf_prog *prog,
 		goto put_map;
 	}
 
+	/* The value ctx arg is writable and aliases the live element. */
+	if (btf_record_has_field(map->record, BPF_RCU_HEAD)) {
+		err = -EOPNOTSUPP;
+		goto put_map;
+	}
+
 	if (map->map_type == BPF_MAP_TYPE_PERCPU_HASH ||
 	    map->map_type == BPF_MAP_TYPE_LRU_PERCPU_HASH ||
 	    map->map_type == BPF_MAP_TYPE_PERCPU_ARRAY)
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 113486b15d29f..74496fd716d3b 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -687,6 +687,7 @@ void btf_record_free(struct btf_record *rec)
 		case BPF_REFCOUNT:
 		case BPF_WORKQUEUE:
 		case BPF_TASK_WORK:
+		case BPF_RCU_HEAD:
 			/* Nothing to release */
 			break;
 		default:
@@ -741,6 +742,7 @@ struct btf_record *btf_record_dup(const struct btf_record *rec)
 		case BPF_REFCOUNT:
 		case BPF_WORKQUEUE:
 		case BPF_TASK_WORK:
+		case BPF_RCU_HEAD:
 			/* Nothing to acquire */
 			break;
 		default:
@@ -874,6 +876,7 @@ void bpf_obj_free_fields(const struct btf_record *rec, void *obj)
 		case BPF_LIST_NODE:
 		case BPF_RB_NODE:
 		case BPF_REFCOUNT:
+		case BPF_RCU_HEAD:
 			break;
 		default:
 			WARN_ON_ONCE(1);
@@ -1280,7 +1283,7 @@ static int map_check_btf(struct bpf_map *map, struct bpf_token *token,
 	map->record = btf_parse_fields(btf, value_type,
 				       BPF_SPIN_LOCK | BPF_RES_SPIN_LOCK | BPF_TIMER | BPF_KPTR | BPF_LIST_HEAD |
 				       BPF_RB_ROOT | BPF_REFCOUNT | BPF_WORKQUEUE | BPF_UPTR |
-				       BPF_TASK_WORK,
+				       BPF_TASK_WORK | BPF_RCU_HEAD,
 				       map->value_size);
 	if (!IS_ERR_OR_NULL(map->record)) {
 		int i;
@@ -1322,6 +1325,12 @@ static int map_check_btf(struct bpf_map *map, struct bpf_token *token,
 					goto free_map_tab;
 				}
 				break;
+			case BPF_RCU_HEAD:
+				if (map->map_type != BPF_MAP_TYPE_ARRAY) {
+					ret = -EOPNOTSUPP;
+					goto free_map_tab;
+				}
+				break;
 			case BPF_KPTR_UNREF:
 			case BPF_KPTR_REF:
 			case BPF_KPTR_PERCPU:
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index d62c0f74cff5e..a7c9e2d8965d5 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -535,6 +535,7 @@ static bool is_ptr_cast_function(enum bpf_func_id func_id)
 
 static bool is_sync_callback_calling_kfunc(u32 btf_id);
 static bool is_async_callback_calling_kfunc(u32 btf_id);
+static bool is_call_rcu_kfunc(u32 btf_id);
 static bool is_callback_calling_kfunc(u32 btf_id);
 
 static bool is_bpf_wq_set_callback_kfunc(u32 btf_id);
@@ -577,6 +578,10 @@ static bool is_async_cb_sleepable(struct bpf_verifier_env *env, struct bpf_insn
 	if (bpf_helper_call(insn) && insn->imm == BPF_FUNC_timer_set_callback)
 		return false;
 
+	/* bpf_call_rcu and bpf_call_rcu_tasks_trace callbacks are never sleepable. */
+	if (bpf_pseudo_kfunc_call(insn) && insn->off == 0 && is_call_rcu_kfunc(insn->imm))
+		return false;
+
 	/* bpf_wq and bpf_task_work callbacks are always sleepable. */
 	if (bpf_pseudo_kfunc_call(insn) && insn->off == 0 &&
 	    (is_bpf_wq_set_callback_kfunc(insn->imm) || is_task_work_add_kfunc(insn->imm)))
@@ -7590,6 +7595,9 @@ static int check_map_field_pointer(struct bpf_verifier_env *env, struct bpf_reg_
 	case BPF_TASK_WORK:
 		field_off = map->record->task_work_off;
 		break;
+	case BPF_RCU_HEAD:
+		field_off = map->record->rcu_head_off;
+		break;
 	case BPF_WORKQUEUE:
 		field_off = map->record->wq_off;
 		break;
@@ -8448,6 +8456,7 @@ static const struct bpf_reg_types *compatible_reg_types[__BPF_ARG_TYPE_MAX] = {
 	[ARG_PTR_TO_RES_SPIN_LOCK]	= &map_value_or_alloc_obj_types,
 	[ARG_PTR_TO_WORKQUEUE]		= &map_value_types,
 	[ARG_PTR_TO_TASK_WORK]		= &map_value_types,
+	[ARG_PTR_TO_RCU_HEAD]		= &map_value_types,
 	[ARG_PTR_TO_IRQ_FLAG]		= &stack_ptr_types,
 	[ARG_PTR_TO_ARENA]		= &arena_types,
 	[ARG_PTR_TO_CTX_OUT]		= &ctx_out_types,
@@ -8894,6 +8903,8 @@ static int process_map_ptr_arg(struct bpf_verifier_env *env, struct bpf_reg_stat
 			obj_name = "timer";
 		else if (rec->task_work_off >= 0)
 			obj_name = "bpf_task_work";
+		else if (rec->rcu_head_off >= 0)
+			obj_name = "bpf_rcu_head";
 
 		verbose(env, "%s pointer in %s map_uid=%d ",
 			obj_name, reg_arg_name(env, obj_argno), meta->map.uid);
@@ -9442,6 +9453,11 @@ static int check_func_arg(struct bpf_verifier_env *env, u32 arg, u32 slot, u32 p
 		if (err < 0)
 			return err;
 		break;
+	case ARG_PTR_TO_RCU_HEAD:
+		err = check_map_field_pointer(env, reg, argno, BPF_RCU_HEAD, &meta->map);
+		if (err < 0)
+			return err;
+		break;
 	case ARG_PTR_TO_IRQ_FLAG:
 		err = process_irq_flag(env, reg, argno, meta);
 		if (err < 0)
@@ -10955,6 +10971,40 @@ static int set_task_work_schedule_callback_state(struct bpf_verifier_env *env,
 	return 0;
 }
 
+static int set_rcu_callback_state(struct bpf_verifier_env *env,
+				  struct bpf_func_state *caller,
+				  struct bpf_func_state *callee,
+				  int insn_idx)
+{
+	struct bpf_map *map_ptr = caller->regs[BPF_REG_2].map_ptr;
+	u32 map_uid = caller->regs[BPF_REG_2].map_uid;
+
+	/*
+	 * callback_fn(struct bpf_map *map, void *key, void *value);
+	 */
+	callee->regs[BPF_REG_1].type = CONST_PTR_TO_MAP;
+	__mark_reg_known_zero(&callee->regs[BPF_REG_1]);
+	callee->regs[BPF_REG_1].map_ptr = map_ptr;
+	callee->regs[BPF_REG_1].map_uid = map_uid;
+
+	callee->regs[BPF_REG_2].type = PTR_TO_MAP_KEY;
+	__mark_reg_known_zero(&callee->regs[BPF_REG_2]);
+	callee->regs[BPF_REG_2].map_ptr = map_ptr;
+	callee->regs[BPF_REG_2].map_uid = map_uid;
+
+	callee->regs[BPF_REG_3].type = PTR_TO_MAP_VALUE;
+	__mark_reg_known_zero(&callee->regs[BPF_REG_3]);
+	callee->regs[BPF_REG_3].map_ptr = map_ptr;
+	callee->regs[BPF_REG_3].map_uid = map_uid;
+
+	/* unused */
+	bpf_mark_reg_not_init(env, &callee->regs[BPF_REG_4]);
+	bpf_mark_reg_not_init(env, &callee->regs[BPF_REG_5]);
+	callee->in_async_callback_fn = true;
+	callee->callback_ret_range = retval_range(S32_MIN, S32_MAX);
+	return 0;
+}
+
 static bool is_rbtree_lock_required_kfunc(u32 btf_id);
 
 static void account_processed_insn(struct bpf_verifier_env *env)
@@ -12216,7 +12266,8 @@ enum {
 	KF_ARG_RES_SPIN_LOCK_ID,
 	KF_ARG_TASK_WORK_ID,
 	KF_ARG_PROG_AUX_ID,
-	KF_ARG_TIMER_ID
+	KF_ARG_TIMER_ID,
+	KF_ARG_RCU_HEAD_ID
 };
 
 BTF_ID_LIST(kf_arg_btf_ids)
@@ -12230,6 +12281,7 @@ BTF_ID(struct, bpf_res_spin_lock)
 BTF_ID(struct, bpf_task_work)
 BTF_ID(struct, bpf_prog_aux)
 BTF_ID(struct, bpf_timer)
+BTF_ID(struct, bpf_rcu_head)
 
 static bool __is_kfunc_ptr_arg_type(const struct btf *btf,
 				    const struct btf_param *arg, int type)
@@ -12288,6 +12340,11 @@ static bool is_kfunc_arg_task_work(const struct btf *btf, const struct btf_param
 	return __is_kfunc_ptr_arg_type(btf, arg, KF_ARG_TASK_WORK_ID);
 }
 
+static bool is_kfunc_arg_rcu_head(const struct btf *btf, const struct btf_param *arg)
+{
+	return __is_kfunc_ptr_arg_type(btf, arg, KF_ARG_RCU_HEAD_ID);
+}
+
 static bool is_kfunc_arg_res_spin_lock(const struct btf *btf, const struct btf_param *arg)
 {
 	return __is_kfunc_ptr_arg_type(btf, arg, KF_ARG_RES_SPIN_LOCK_ID);
@@ -12571,6 +12628,8 @@ enum special_kfunc_type {
 	KF___bpf_trap,
 	KF_bpf_task_work_schedule_signal,
 	KF_bpf_task_work_schedule_resume,
+	KF_bpf_call_rcu,
+	KF_bpf_call_rcu_tasks_trace,
 	KF_bpf_arena_alloc_pages,
 	KF_bpf_arena_free_pages,
 	KF_bpf_arena_reserve_pages,
@@ -12664,6 +12723,8 @@ BTF_ID(func, bpf_dynptr_file_discard)
 BTF_ID(func, __bpf_trap)
 BTF_ID(func, bpf_task_work_schedule_signal)
 BTF_ID(func, bpf_task_work_schedule_resume)
+BTF_ID(func, bpf_call_rcu)
+BTF_ID(func, bpf_call_rcu_tasks_trace)
 BTF_ID(func, bpf_arena_alloc_pages)
 BTF_ID(func, bpf_arena_free_pages)
 BTF_ID(func, bpf_arena_reserve_pages)
@@ -12735,6 +12796,12 @@ static bool is_bpf_rbtree_add_kfunc(u32 func_id)
 	       func_id == special_kfunc_list[KF_bpf_rbtree_add_impl];
 }
 
+static bool is_call_rcu_kfunc(u32 func_id)
+{
+	return func_id == special_kfunc_list[KF_bpf_call_rcu] ||
+	       func_id == special_kfunc_list[KF_bpf_call_rcu_tasks_trace];
+}
+
 static bool is_task_work_add_kfunc(u32 func_id)
 {
 	return func_id == special_kfunc_list[KF_bpf_task_work_schedule_signal] ||
@@ -12941,6 +13008,8 @@ get_kfunc_arg_type(struct bpf_verifier_env *env, struct bpf_call_arg_meta *meta,
 		arg_type = ARG_PTR_TO_TIMER;
 	else if (is_kfunc_arg_task_work(meta->btf, &args[arg]))
 		arg_type = ARG_PTR_TO_TASK_WORK;
+	else if (is_kfunc_arg_rcu_head(meta->btf, &args[arg]))
+		arg_type = ARG_PTR_TO_RCU_HEAD;
 	else if (is_kfunc_arg_irq_flag(meta->btf, &args[arg]))
 		arg_type = ARG_PTR_TO_IRQ_FLAG;
 	else if (is_kfunc_arg_res_spin_lock(meta->btf, &args[arg]))
@@ -13442,7 +13511,8 @@ static bool is_sync_callback_calling_kfunc(u32 btf_id)
 static bool is_async_callback_calling_kfunc(u32 btf_id)
 {
 	return is_bpf_wq_set_callback_kfunc(btf_id) ||
-	       is_task_work_add_kfunc(btf_id);
+	       is_task_work_add_kfunc(btf_id) ||
+	       is_call_rcu_kfunc(btf_id);
 }
 
 bool bpf_is_throw_kfunc(struct bpf_insn *insn)
@@ -14259,6 +14329,16 @@ static int check_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn,
 		}
 	}
 
+	if (is_call_rcu_kfunc(meta.func_id)) {
+		err = push_callback_call(env, insn, insn_idx, meta.subprogno,
+					 set_rcu_callback_state);
+		if (err) {
+			verbose(env, "kfunc %s#%d failed callback verification\n",
+				func_name, meta.func_id);
+			return err;
+		}
+	}
+
 	rcu_lock = is_kfunc_bpf_rcu_read_lock(&meta);
 	rcu_unlock = is_kfunc_bpf_rcu_read_unlock(&meta);
 
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index 6330b7d745c57..eafeba23f5da7 100644
--- a/tools/include/uapi/linux/bpf.h
+++ b/tools/include/uapi/linux/bpf.h
@@ -7611,6 +7611,10 @@ struct bpf_task_work {
 	__u64 __opaque;
 } __attribute__((aligned(8)));
 
+struct bpf_rcu_head {
+	__u64 __opaque[8];
+} __attribute__((aligned(8)));
+
 struct bpf_wq {
 	__u64 __opaque[2];
 } __attribute__((aligned(8)));
diff --git a/tools/testing/selftests/bpf/prog_tests/call_rcu.c b/tools/testing/selftests/bpf/prog_tests/call_rcu.c
new file mode 100644
index 0000000000000..e4d271d43d878
--- /dev/null
+++ b/tools/testing/selftests/bpf/prog_tests/call_rcu.c
@@ -0,0 +1,275 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (c) 2026 Meta Platforms, Inc. and affiliates. */
+#include <test_progs.h>
+#include "call_rcu.skel.h"
+#include "call_rcu_fail.skel.h"
+
+struct elem {
+	__u64 pad;
+	struct bpf_rcu_head rh;
+	__u64 val;
+};
+
+/*
+ * Force the grace period, then poll: the callback still has to be invoked
+ * afterwards, and call_rcu() is lazy on a CONFIG_RCU_LAZY kernel.
+ */
+static bool wait_for_callbacks(struct call_rcu *skel, int expected)
+{
+	int i, got = 0;
+
+	kern_sync_rcu();
+	for (i = 0; i < 3000; i++) {
+		got = __atomic_load_n(&skel->bss->callbacks, __ATOMIC_ACQUIRE);
+		if (got >= expected)
+			return true;
+		usleep(10000);
+	}
+	return ASSERT_GE(got, expected, "callbacks");
+}
+
+static void test_call_rcu_run(bool trace)
+{
+	LIBBPF_OPTS(bpf_test_run_opts, opts);
+	struct bpf_program *prog;
+	struct call_rcu *skel;
+	struct elem elem;
+	__u32 key = 1;
+	int err;
+
+	skel = call_rcu__open_and_load();
+	if (!ASSERT_OK_PTR(skel, "skel_open_and_load"))
+		return;
+
+	prog = trace ? skel->progs.arm_trace : skel->progs.arm;
+	err = bpf_prog_test_run_opts(bpf_program__fd(prog), &opts);
+	if (!ASSERT_OK(err, "test_run") || !ASSERT_EQ(opts.retval, 0, "retval"))
+		goto out;
+
+	ASSERT_EQ(skel->bss->arm_err, 0, "arm_err");
+	ASSERT_EQ(skel->bss->busy_err, -EBUSY, "busy_err");
+
+	if (!wait_for_callbacks(skel, 1))
+		goto out;
+
+	ASSERT_EQ(skel->bss->cb_key, key, "cb_key");
+	ASSERT_EQ(skel->bss->cb_val, 0xdeadbeef, "cb_val");
+	ASSERT_EQ(skel->bss->cb_max_entries, bpf_map__max_entries(skel->maps.arr), "cb_map");
+
+	err = bpf_map__lookup_elem(skel->maps.arr, &key, sizeof(key), &elem, sizeof(elem), 0);
+	if (ASSERT_OK(err, "lookup"))
+		ASSERT_EQ(elem.val, 0, "value_cleared");
+
+	/* The head is disarmed before the callback runs, so it can be reused. */
+	err = bpf_prog_test_run_opts(bpf_program__fd(prog), &opts);
+	if (!ASSERT_OK(err, "test_run_again"))
+		goto out;
+	ASSERT_EQ(skel->bss->arm_err, 0, "rearm_err");
+	wait_for_callbacks(skel, 2);
+out:
+	call_rcu__destroy(skel);
+}
+
+static void test_call_rcu_chain(void)
+{
+	LIBBPF_OPTS(bpf_test_run_opts, opts);
+	struct call_rcu *skel;
+
+	skel = call_rcu__open_and_load();
+	if (!ASSERT_OK_PTR(skel, "skel_open_and_load"))
+		return;
+
+	skel->bss->chain = 1;
+	if (!ASSERT_OK(bpf_prog_test_run_opts(bpf_program__fd(skel->progs.arm), &opts), "test_run"))
+		goto out;
+
+	if (!wait_for_callbacks(skel, 1))
+		goto out;
+	ASSERT_EQ(skel->bss->chain_err, 0, "chain_err");
+	wait_for_callbacks(skel, 2);
+out:
+	call_rcu__destroy(skel);
+}
+
+/*
+ * A callback that keeps re-arming must stop once the map loses its last user
+ * reference, or it pins the program for good.  Hold an independent fd on .bss
+ * so the refusal is still readable after the skeleton is gone.
+ */
+static void test_call_rcu_teardown(void)
+{
+	LIBBPF_OPTS(bpf_test_run_opts, opts);
+	int i, err, fd = 0, bss_fd = -1;
+	struct bpf_prog_info pinfo = {};
+	struct bpf_map_info minfo = {};
+	__u32 len, prog_id, zero = 0;
+	struct call_rcu *skel;
+	char *buf = NULL;
+	size_t off, vsz;
+
+	skel = call_rcu__open_and_load();
+	if (!ASSERT_OK_PTR(skel, "skel_open_and_load"))
+		return;
+
+	len = sizeof(pinfo);
+	if (!ASSERT_OK(bpf_prog_get_info_by_fd(bpf_program__fd(skel->progs.arm), &pinfo, &len),
+		       "prog_info"))
+		goto out;
+	prog_id = pinfo.id;
+
+	len = sizeof(minfo);
+	if (!ASSERT_OK(bpf_map_get_info_by_fd(bpf_map__fd(skel->maps.bss), &minfo, &len),
+		       "bss_info"))
+		goto out;
+	bss_fd = bpf_map_get_fd_by_id(minfo.id);
+	if (!ASSERT_GE(bss_fd, 0, "bss_fd"))
+		goto out;
+
+	vsz = bpf_map__value_size(skel->maps.bss);
+	off = (char *)&skel->bss->chain_err - (char *)skel->bss;
+	buf = malloc(vsz);
+	if (!ASSERT_OK_PTR(buf, "buf"))
+		goto out;
+
+	skel->bss->chain = INT_MAX;
+	err = bpf_prog_test_run_opts(bpf_program__fd(skel->progs.arm), &opts);
+	if (!ASSERT_OK(err, "test_run") || !ASSERT_EQ(opts.retval, 0, "retval"))
+		goto out;
+	if (!ASSERT_EQ(skel->bss->arm_err, 0, "arm_err"))
+		goto out;
+	/* The chain has to be running before the map reference goes away. */
+	if (!wait_for_callbacks(skel, 2))
+		goto out;
+
+	call_rcu__destroy(skel);
+	skel = NULL;
+
+	for (i = 0; i < 3000; i++) {
+		fd = bpf_prog_get_fd_by_id(prog_id);
+		if (fd < 0)
+			break;
+		close(fd);
+		usleep(10000);
+	}
+	if (!ASSERT_EQ(fd, -ENOENT, "prog_freed"))
+		goto out;
+
+	if (ASSERT_OK(bpf_map_lookup_elem(bss_fd, &zero, buf), "bss_lookup"))
+		ASSERT_EQ(*(int *)(buf + off), -EPERM, "chain_refused");
+out:
+	free(buf);
+	if (bss_fd >= 0)
+		close(bss_fd);
+	call_rcu__destroy(skel);
+}
+
+static void test_call_rcu_bad_map(void)
+{
+	LIBBPF_OPTS(bpf_map_create_opts, opts);
+	struct call_rcu *skel;
+	int fd;
+
+	skel = call_rcu__open_and_load();
+	if (!ASSERT_OK_PTR(skel, "skel_open_and_load"))
+		return;
+
+	opts.btf_fd = bpf_object__btf_fd(skel->obj);
+	opts.btf_key_type_id = bpf_map__btf_key_type_id(skel->maps.arr);
+	opts.btf_value_type_id = bpf_map__btf_value_type_id(skel->maps.arr);
+
+	fd = bpf_map_create(BPF_MAP_TYPE_HASH, "rcu_hash", sizeof(__u32),
+			    bpf_map__value_size(skel->maps.arr), 1, &opts);
+	ASSERT_EQ(fd, -EOPNOTSUPP, "hash_rejected");
+	if (fd >= 0)
+		close(fd);
+
+	call_rcu__destroy(skel);
+}
+
+/* Iterating would hand the program a writable pointer to the head. */
+static void test_call_rcu_iter(void)
+{
+	LIBBPF_OPTS(bpf_iter_attach_opts, opts);
+	union bpf_iter_link_info linfo = {};
+	struct bpf_link *link;
+	struct call_rcu *skel;
+
+	skel = call_rcu__open_and_load();
+	if (!ASSERT_OK_PTR(skel, "skel_open_and_load"))
+		return;
+
+	linfo.map.map_fd = bpf_map__fd(skel->maps.arr);
+	opts.link_info = &linfo;
+	opts.link_info_len = sizeof(linfo);
+
+	link = bpf_program__attach_iter(skel->progs.dump, &opts);
+	if (!ASSERT_ERR_PTR(link, "iter_rejected"))
+		bpf_link__destroy(link);
+	else
+		ASSERT_EQ(libbpf_get_error(link), -EOPNOTSUPP, "iter_errno");
+
+	call_rcu__destroy(skel);
+}
+
+static void test_call_rcu_inner_map(void)
+{
+	LIBBPF_OPTS(bpf_map_create_opts, opts);
+	struct call_rcu *skel;
+	int fd;
+
+	skel = call_rcu__open_and_load();
+	if (!ASSERT_OK_PTR(skel, "skel_open_and_load"))
+		return;
+
+	opts.inner_map_fd = bpf_map__fd(skel->maps.arr);
+	fd = bpf_map_create(BPF_MAP_TYPE_ARRAY_OF_MAPS, "rcu_outer",
+			    sizeof(__u32), sizeof(__u32), 1, &opts);
+	ASSERT_EQ(fd, -EOPNOTSUPP, "inner_map_rejected");
+	if (fd >= 0)
+		close(fd);
+
+	call_rcu__destroy(skel);
+}
+
+/* Two heads in the same map must be independent. */
+static void test_call_rcu_two_heads(void)
+{
+	LIBBPF_OPTS(bpf_test_run_opts, opts);
+	struct call_rcu *skel;
+
+	skel = call_rcu__open_and_load();
+	if (!ASSERT_OK_PTR(skel, "skel_open_and_load"))
+		return;
+
+	if (!ASSERT_OK(bpf_prog_test_run_opts(bpf_program__fd(skel->progs.arm_both), &opts),
+		       "test_run"))
+		goto out;
+	if (!ASSERT_EQ(skel->bss->arm_err, 0, "arm_err"))
+		goto out;
+	if (!wait_for_callbacks(skel, 2))
+		goto out;
+	ASSERT_EQ(skel->bss->cb_keys, 0x3, "both_keys");
+out:
+	call_rcu__destroy(skel);
+}
+
+void test_call_rcu(void)
+{
+	if (test__start_subtest("run"))
+		test_call_rcu_run(false);
+	if (test__start_subtest("run_tasks_trace"))
+		test_call_rcu_run(true);
+	if (test__start_subtest("chain"))
+		test_call_rcu_chain();
+	if (test__start_subtest("two_heads"))
+		test_call_rcu_two_heads();
+	if (test__start_subtest("teardown"))
+		test_call_rcu_teardown();
+	if (test__start_subtest("bad_map"))
+		test_call_rcu_bad_map();
+	if (test__start_subtest("iter"))
+		test_call_rcu_iter();
+	if (test__start_subtest("inner_map"))
+		test_call_rcu_inner_map();
+	RUN_TESTS(call_rcu_fail);
+}
diff --git a/tools/testing/selftests/bpf/progs/call_rcu.c b/tools/testing/selftests/bpf/progs/call_rcu.c
new file mode 100644
index 0000000000000..505008647fd6f
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/call_rcu.c
@@ -0,0 +1,110 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (c) 2026 Meta Platforms, Inc. and affiliates. */
+
+#include <vmlinux.h>
+#include <bpf/bpf_helpers.h>
+
+char _license[] SEC("license") = "GPL";
+
+/* rh is not at offset 0, so the callback's value recovery is exercised. */
+struct elem {
+	__u64 pad;
+	struct bpf_rcu_head rh;
+	__u64 val;
+};
+
+struct {
+	__uint(type, BPF_MAP_TYPE_ARRAY);
+	__uint(max_entries, 2);
+	__type(key, __u32);
+	__type(value, struct elem);
+} arr SEC(".maps");
+
+__u32 cb_key;
+__u64 cb_keys;
+__u64 cb_val;
+__u32 cb_max_entries;
+int callbacks;
+int arm_err;
+int busy_err;
+int chain;		/* set by userspace: number of times to re-arm from the callback */
+int chain_err;
+
+static int reclaim(struct bpf_map *map, void *key, void *value)
+{
+	struct elem *e = value;
+
+	cb_key = *(__u32 *)key;
+	__sync_fetch_and_or(&cb_keys, 1ULL << cb_key);
+	cb_val = e->val;
+	cb_max_entries = map->max_entries;
+	e->val = 0;
+
+	if (chain > 0) {
+		chain--;
+		chain_err = bpf_call_rcu(&e->rh, &arr, reclaim);
+	}
+
+	__sync_fetch_and_add(&callbacks, 1);
+	return 0;
+}
+
+SEC("syscall")
+int arm(void *ctx)
+{
+	__u32 key = 1;
+	struct elem *e;
+
+	e = bpf_map_lookup_elem(&arr, &key);
+	if (!e)
+		return 1;
+
+	e->val = 0xdeadbeef;
+	/* Keep a grace period from elapsing between the two arms. */
+	bpf_rcu_read_lock();
+	arm_err = bpf_call_rcu(&e->rh, &arr, reclaim);
+	busy_err = bpf_call_rcu(&e->rh, &arr, reclaim);
+	bpf_rcu_read_unlock();
+	return 0;
+}
+
+SEC("syscall")
+int arm_both(void *ctx)
+{
+	__u32 key0 = 0, key1 = 1;
+	struct elem *e0, *e1;
+
+	e0 = bpf_map_lookup_elem(&arr, &key0);
+	e1 = bpf_map_lookup_elem(&arr, &key1);
+	if (!e0 || !e1)
+		return 1;
+
+	e0->val = 0xdeadbeef;
+	e1->val = 0xdeadbeef;
+	arm_err = bpf_call_rcu(&e0->rh, &arr, reclaim);
+	arm_err |= bpf_call_rcu(&e1->rh, &arr, reclaim);
+	return 0;
+}
+
+SEC("syscall")
+int arm_trace(void *ctx)
+{
+	__u32 key = 1;
+	struct elem *e;
+
+	e = bpf_map_lookup_elem(&arr, &key);
+	if (!e)
+		return 1;
+
+	e->val = 0xdeadbeef;
+	/* No lock needed: the enclosing rcu_read_lock_trace() already blocks the grace period. */
+	arm_err = bpf_call_rcu_tasks_trace(&e->rh, &arr, reclaim);
+	busy_err = bpf_call_rcu_tasks_trace(&e->rh, &arr, reclaim);
+	return 0;
+}
+
+SEC("iter/bpf_map_elem")
+int dump(struct bpf_iter__bpf_map_elem *ctx)
+{
+	return 0;
+}
diff --git a/tools/testing/selftests/bpf/progs/call_rcu_fail.c b/tools/testing/selftests/bpf/progs/call_rcu_fail.c
new file mode 100644
index 0000000000000..bf60a27731fb3
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/call_rcu_fail.c
@@ -0,0 +1,114 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (c) 2026 Meta Platforms, Inc. and affiliates. */
+
+#include <vmlinux.h>
+#include <bpf/bpf_helpers.h>
+#include "bpf_misc.h"
+
+char _license[] SEC("license") = "GPL";
+
+const void *user_ptr = NULL;
+
+struct elem {
+	__u64 pad;
+	struct bpf_rcu_head rh;
+	__u64 val;
+};
+
+struct {
+	__uint(type, BPF_MAP_TYPE_ARRAY);
+	__uint(max_entries, 1);
+	__type(key, __u32);
+	__type(value, struct elem);
+} arr SEC(".maps");
+
+struct {
+	__uint(type, BPF_MAP_TYPE_ARRAY);
+	__uint(max_entries, 1);
+	__type(key, __u32);
+	__type(value, struct elem);
+} arr2 SEC(".maps");
+
+struct {
+	__uint(type, BPF_MAP_TYPE_ARRAY);
+	__uint(max_entries, 1);
+	__type(key, __u32);
+	__type(value, __u64);
+} plain SEC(".maps");
+
+__u32 key = 0;
+
+static int reclaim(struct bpf_map *map, void *key, void *value)
+{
+	return 0;
+}
+
+static int sleepable_reclaim(struct bpf_map *map, void *key, void *value)
+{
+	struct elem *e = value;
+
+	bpf_copy_from_user(&e->val, sizeof(e->val), user_ptr);
+	return 0;
+}
+
+SEC("syscall")
+__failure __msg("bpf_rcu_head pointer in R1") __msg("doesn't match map pointer in R2")
+int mismatch_map(void *ctx)
+{
+	struct elem *e;
+
+	e = bpf_map_lookup_elem(&arr, &key);
+	if (!e)
+		return 0;
+	bpf_call_rcu(&e->rh, &arr2, reclaim);
+	return 0;
+}
+
+SEC("syscall")
+__failure __msg("map 'plain' has no valid bpf_rcu_head")
+int no_rcu_head(void *ctx)
+{
+	__u64 *val;
+
+	val = bpf_map_lookup_elem(&plain, &key);
+	if (!val)
+		return 0;
+	bpf_call_rcu((struct bpf_rcu_head *)val, &plain, reclaim);
+	return 0;
+}
+
+SEC("syscall")
+__failure __msg("doesn't point to 'struct bpf_rcu_head' that is at 8")
+int wrong_offset(void *ctx)
+{
+	struct elem *e;
+
+	e = bpf_map_lookup_elem(&arr, &key);
+	if (!e)
+		return 0;
+	bpf_call_rcu((struct bpf_rcu_head *)&e->pad, &arr, reclaim);
+	return 0;
+}
+
+SEC("syscall")
+__failure __msg("R1 type=fp expected=map_value")
+int rcu_head_on_stack(void *ctx)
+{
+	struct bpf_rcu_head rh;
+
+	bpf_call_rcu(&rh, &arr, reclaim);
+	return 0;
+}
+
+SEC("syscall")
+__failure __msg("sleepable helper bpf_copy_from_user") __msg("in non-sleepable prog")
+int sleepable_callback(void *ctx)
+{
+	struct elem *e;
+
+	e = bpf_map_lookup_elem(&arr, &key);
+	if (!e)
+		return 0;
+	bpf_call_rcu(&e->rh, &arr, sleepable_reclaim);
+	return 0;
+}

3/2 2026/09/23 19:45 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 17612
							output: 34
							thoughts: 761
						

Thoughts:
**My Initial Assessment of the BPF RCU Head Patch**

Okay, let's dive into this patch. My expert eye immediately picks up on the addition of `bpf_rcu_head` support within the BPF framework. That's a significant development, opening up a new avenue for integrating RCU callbacks within BPF programs. I need to understand the implications of this thoroughly.

First, I need to understand what's been added in the relevant header files (`bpf.h`, `uapi/linux/bpf.h`). New enumerations like `BPF_RCU_HEAD` in `btf_field_type`, `rcu_head_off` in `btf_record` and `struct bpf_rcu_head` need to be accounted for. It's clear that the infrastructure for representing and managing RCU heads within the BTF data has been put in place, alongside `ARG_PTR_TO_RCU_HEAD`.

I notice parsing of `struct bpf_rcu_head` is now a part of map value types in `btf.c`. That's important. This means RCU head structures can be used as values within BPF maps, a fundamental data structure in the BPF world.

The inclusion of new kfuncs like `bpf_rcu_run_callback`, `__bpf_call_rcu`, and `bpf_call_rcu`, and `bpf_call_rcu_tasks_trace` in `helpers.c` is the key. These are the building blocks that BPF programs will use to schedule and execute RCU callbacks. This is a game-changer!

The prohibitions in `map_in_map.c` and `map_iter.c` against inner maps and iterators using `BPF_RCU_HEAD` require careful consideration to ensure correctness and prevent potential issues. The restrictions in `syscall.c` about the supported map types for `BPF_RCU_HEAD` (currently limited to `BPF_MAP_TYPE_ARRAY`) are also important. I need to follow how the lifecycle of these objects is handled with `btf_record_free`, `btf_record_dup`, and `bpf_obj_free_fields`.

The verifier changes in `verifier.c` are where the real complexity lies, with the introduction of  `is_call_rcu_kfunc`,  `set_rcu_callback_state`, and the very detailed callback checking during the verification process (`push_callback_call`, `check_kfunc_call`, `get_kfunc_arg_type`, `compatible_reg_types`, `is_async_cb_sleepable`). This part is critical for ensuring the safety and correctness of BPF programs that use RCU callbacks. The ability to verify the callback's non-sleepable nature is particularly important.

The presence of selftests for this new functionality is fantastic, and I'll make sure to thoroughly review those test cases to understand how this is expected to be used.

Given that BPF is explicitly listed under critical core subsystems, I know it is a highly reachable codebase and is therefore likely "WorthFuzzing" due to the possibility of calling RCU callbacks from BPF programs that have been loaded, verified, maps created with BTF and `bpf_call_rcu` kfunc called. The interactions with concurrency, re-arming, and lifetime management will make this very interesting to test, given the asynchronous nature of RCU callbacks.

Finally, I need to check the Kconfig options required for this functionality. I'll need to run a search for BPF kfuncs, BTF, and the BPF syscall itself, probably using `grepper` or by inspecting `kernel/bpf/Kconfig`. I need to ensure that the necessary configuration options are enabled for this functionality to be available.



4/2 2026/09/23 19:45 tool grepper
0m Args:
{
  "Expression": "config BPF_SYSCALL",
  "PathPrefix": "kernel/bpf/Kconfig"
}

Results:
{
  "Output": "kernel/bpf/Kconfig=29=menu \"BPF subsystem\"\nkernel/bpf/Kconfig-30-\nkernel/bpf/Kconfig:31:config BPF_SYSCALL\nkernel/bpf/Kconfig-32-\tbool \"Enable bpf() system call\"\n"
}

5/2 2026/09/23 19:45 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 19323
							output: 28
							thoughts: 36
						

Thoughts:
Here's my attempt at summarizing the thought process, tailored for an expert audience:

**Investigating the BPF Object Compilation Process**

Okay, so I need to understand the build process for those core BPF object files – `helpers.o`, `btf.o`, `verifier.o`, and the like. My first port of call will be the `kernel/bpf/Makefile`. That's where I expect the build rules and dependencies for these components to be defined. I'm especially interested in how the compiler flags, linker options, and any specific target rules are set for these critical BPF infrastructure elements. This will likely give me insight into the build environment, optimization levels, and any specific considerations for BPF code generation and linking within the kernel. I'll be looking for things like whether they're using specific clang or gcc versions, any custom macros or include paths, and if there are any special considerations for BTF generation, which is crucial. It's time to dig in.



6/2 2026/09/23 19:45 tool grepper
0m Args:
{
  "Expression": "helpers\\.o",
  "PathPrefix": "kernel/bpf/"
}

Results:
{
  "Output": "kernel/bpf/Makefile=7=CFLAGS_core.o += -Wno-override-init $(cflags-nogcse-yy)\nkernel/bpf/Makefile-8-\nkernel/bpf/Makefile:9:obj-$(CONFIG_BPF_SYSCALL) += syscall.o verifier.o inode.o helpers.o tnum.o cnum.o log.o token.o liveness.o const_fold.o diagnostics.o\nkernel/bpf/Makefile-10-obj-$(CONFIG_BPF_SYSCALL) += bpf_iter.o map_iter.o task_iter.o prog_iter.o link_iter.o\n"
}

7/2 2026/09/23 19:45 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 19763
							output: 29
							thoughts: 20
						

Thoughts:
Here's my take on those thoughts:

**Checking the BPF Makefile**

Okay, so I'm digging into this BPF situation, and I need to make absolutely sure I've got all the bases covered. That means, beyond the obvious, I should probably take a look at `btf.o` in the `kernel/bpf/Makefile` as well. It's easy to overlook things when you're focusing on a particular area, so a quick cross-reference there will help me make sure there are no dependencies or unexpected interactions I'm missing. Given my experience, I'm confident I'll spot anything relevant quickly, but it's always best to be thorough, especially when dealing with something as crucial as the BPF infrastructure. Gotta stay sharp!



8/2 2026/09/23 19:45 tool grepper
0m Args:
{
  "Expression": "btf\\.o",
  "PathPrefix": "kernel/bpf/"
}

Results:
{
  "Output": "kernel/bpf/Makefile=13=obj-$(CONFIG_BPF_SYSCALL) += bpf_local_storage.o bpf_task_storage.o\nkernel/bpf/Makefile:14:obj-$(CONFIG_BPF_SYSCALL) += fixups.o cfg.o states.o backtrack.o check_btf.o\nkernel/bpf/Makefile-15-obj-${CONFIG_BPF_LSM}\t  += bpf_inode_storage.o\n--\nkernel/bpf/Makefile=17=obj-$(CONFIG_BPF_JIT) += trampoline.o\nkernel/bpf/Makefile:18:obj-$(CONFIG_BPF_SYSCALL) += btf.o memalloc.o rqspinlock.o stream.o\nkernel/bpf/Makefile-19-ifeq ($(CONFIG_MMU)$(CONFIG_64BIT),yy)\n--\nkernel/bpf/Makefile=43=ifeq ($(CONFIG_SYSFS),y)\nkernel/bpf/Makefile:44:obj-$(CONFIG_DEBUG_INFO_BTF) += sysfs_btf.o\nkernel/bpf/Makefile-45-endif\n"
}

9/2 2026/09/23 19:45 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 20265
							output: 31
							thoughts: 77
						

Thoughts:
Here's my take on those thoughts:

**Analyzing BPF Compilation Dependencies**

Okay, so `CONFIG_BPF_SYSCALL` is set, which means the BPF system call stuff is being compiled. That should include `syscall.o`, `verifier.o`, `helpers.o`, `btf.o`, and `map_iter.o`. But hold on... isn't BTF dependent on debug information? I need to quickly confirm whether the `CONFIG_DEBUG_INFO_BTF` option is also required for BTF functionality. To do that, I'll need to check the source code. Specifically, either `kernel/bpf/btf.c` or, better yet, the `kernel/bpf/Kconfig` file, which should explicitly define the dependencies for that particular feature.



10/2 2026/09/23 19:45 tool grepper
0m Args:
{
  "Expression": "DEBUG_INFO_BTF",
  "PathPrefix": "kernel/bpf/"
}

Results:
{
  "Output": "kernel/bpf/Makefile=43=ifeq ($(CONFIG_SYSFS),y)\nkernel/bpf/Makefile:44:obj-$(CONFIG_DEBUG_INFO_BTF) += sysfs_btf.o\nkernel/bpf/Makefile-45-endif\n--\nkernel/bpf/btf.c=6424=static struct btf *btf_parse_base(struct btf_verifier_env *env, const char *name,\n--\nkernel/bpf/btf.c-6429-\nkernel/bpf/btf.c:6430:\tif (!IS_ENABLED(CONFIG_DEBUG_INFO_BTF))\nkernel/bpf/btf.c-6431-\t\treturn ERR_PTR(-ENOENT);\n--\nkernel/bpf/btf.c=6510=__u32 btf_relocate_id(const struct btf *btf, __u32 id)\n--\nkernel/bpf/btf.c-6516-\nkernel/bpf/btf.c:6517:#ifdef CONFIG_DEBUG_INFO_BTF_MODULES\nkernel/bpf/btf.c-6518-\nkernel/bpf/btf.c=6519=static struct btf *btf_parse_module(const char *module_name, const void *data,\n--\nkernel/bpf/btf.c-6614-\nkernel/bpf/btf.c:6615:#endif /* CONFIG_DEBUG_INFO_BTF_MODULES */\nkernel/bpf/btf.c-6616-\n--\nkernel/bpf/btf.c=8595=enum {\n--\nkernel/bpf/btf.c-8598-\nkernel/bpf/btf.c:8599:#ifdef CONFIG_DEBUG_INFO_BTF_MODULES\nkernel/bpf/btf.c-8600-struct btf_module {\n--\nkernel/bpf/btf.c=8737=fs_initcall(btf_module_init);\nkernel/bpf/btf.c:8738:#endif /* CONFIG_DEBUG_INFO_BTF_MODULES */\nkernel/bpf/btf.c-8739-\nkernel/bpf/btf.c=8740=struct module *btf_try_get_module(const struct btf *btf)\n--\nkernel/bpf/btf.c-8742-\tstruct module *res = NULL;\nkernel/bpf/btf.c:8743:#ifdef CONFIG_DEBUG_INFO_BTF_MODULES\nkernel/bpf/btf.c-8744-\tstruct btf_module *btf_mod, *tmp;\n--\nkernel/bpf/btf.c=8770=struct btf *btf_get_module_btf(const struct module *module)\nkernel/bpf/btf.c-8771-{\nkernel/bpf/btf.c:8772:#ifdef CONFIG_DEBUG_INFO_BTF_MODULES\nkernel/bpf/btf.c-8773-\tstruct btf_module *btf_mod, *tmp;\n--\nkernel/bpf/btf.c-8783-\nkernel/bpf/btf.c:8784:#ifdef CONFIG_DEBUG_INFO_BTF_MODULES\nkernel/bpf/btf.c-8785-\tmutex_lock(\u0026btf_module_mutex);\n--\nkernel/bpf/btf.c=8800=static int check_btf_kconfigs(const struct module *module, const char *feature)\nkernel/bpf/btf.c-8801-{\nkernel/bpf/btf.c:8802:\tif (!module \u0026\u0026 IS_ENABLED(CONFIG_DEBUG_INFO_BTF)) {\nkernel/bpf/btf.c-8803-\t\tpr_err(\"missing vmlinux BTF, cannot register %s\\n\", feature);\n--\nkernel/bpf/btf.c-8805-\t}\nkernel/bpf/btf.c:8806:\tif (module \u0026\u0026 IS_ENABLED(CONFIG_DEBUG_INFO_BTF_MODULES))\nkernel/bpf/btf.c-8807-\t\tpr_warn(\"missing module BTF, cannot register %s\\n\", feature);\n--\nkernel/bpf/btf.c=8948=static int btf_check_kfunc_name(struct btf *btf, const char *func_name, u32 kind)\nkernel/bpf/btf.c-8949-{\nkernel/bpf/btf.c:8950:#ifdef CONFIG_DEBUG_INFO_BTF_MODULES\nkernel/bpf/btf.c-8951-\tstruct btf_module *btf_mod, *tmp;\n--\nkernel/bpf/btf.c-8964-\nkernel/bpf/btf.c:8965:#ifdef CONFIG_DEBUG_INFO_BTF_MODULES\nkernel/bpf/btf.c-8966-\tguard(mutex)(\u0026btf_module_mutex);\n--\nkernel/bpf/btf.c=9613=static struct bpf_cand_cache *populate_cand_cache(struct bpf_cand_cache *cands,\n--\nkernel/bpf/btf.c-9640-\nkernel/bpf/btf.c:9641:#ifdef CONFIG_DEBUG_INFO_BTF_MODULES\nkernel/bpf/btf.c-9642-static void __purge_cand_cache(struct btf *btf, struct bpf_cand_cache **cache,\n--\nkernel/bpf/verifier.c=2860=int bpf_add_kfunc_call(struct bpf_verifier_env *env, u32 func_id, u16 offset)\n--\nkernel/bpf/verifier.c-2876-\t\tif (!btf_vmlinux) {\nkernel/bpf/verifier.c:2877:\t\t\tverbose(env, \"calling kernel function is not supported without CONFIG_DEBUG_INFO_BTF\\n\");\nkernel/bpf/verifier.c-2878-\t\t\treturn -ENOTSUPP;\n--\nkernel/bpf/verifier.c=6246=static int check_ptr_to_map_access(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-6260-\tif (!btf_vmlinux) {\nkernel/bpf/verifier.c:6261:\t\tverbose(env, \"map_ptr access not supported without CONFIG_DEBUG_INFO_BTF\\n\");\nkernel/bpf/verifier.c-6262-\t\treturn -ENOTSUPP;\n--\nkernel/bpf/verifier.c=19222=static int check_pseudo_btf_id(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-19238-\t\tif (!btf_vmlinux) {\nkernel/bpf/verifier.c:19239:\t\t\tverbose(env, \"kernel is missing BTF, make sure CONFIG_DEBUG_INFO_BTF=y is specified in Kconfig.\\n\");\nkernel/bpf/verifier.c-19240-\t\t\treturn -EINVAL;\n--\nkernel/bpf/verifier.c=21133=struct btf *bpf_get_btf_vmlinux(void)\n--\nkernel/bpf/verifier.c-21137-\nkernel/bpf/verifier.c:21138:\tif (!btf \u0026\u0026 IS_ENABLED(CONFIG_DEBUG_INFO_BTF)) {\nkernel/bpf/verifier.c-21139-\t\tmutex_lock(\u0026btf_vmlinux_lock);\n"
}

11/2 2026/09/23 19:45 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 22503
							output: 33
							thoughts: 113
						

Thoughts:
**My Assessment of the BPF Kernel Configuration**

Okay, so I see this error message: "calling kernel function is not supported without CONFIG_DEBUG_INFO_BTF." Hmm, that's interesting. And *aha!* `bpf_call_rcu` and `bpf_call_rcu_tasks_trace` are kfuncs, and from that message, it looks like **`CONFIG_BPF_SYSCALL` and `CONFIG_DEBUG_INFO_BTF` are both critical prerequisites for using kernel functions and BTF within BPF programs.** That's a good find!

Now, let's dig a bit deeper. I need to refresh my understanding of the dependencies. I should check the `CONFIG_DEBUG_INFO_BTF` option in the Kconfig files. This will clarify its relationships with other configurations and the overall implications for my BPF development. I need to be sure I have all the prerequisites met to take advantage of kfuncs.



12/2 2026/09/23 19:45 tool grepper
0m Error:
no matches

Args:
{
  "Expression": "config DEBUG_INFO_BTF\\b",
  "PathPrefix": "init/Kconfig"
}

Results:
{
  "error": "no matches"
}

13/2 2026/09/23 19:45 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 22871
							output: 23
							thoughts: 17
						

Thoughts:
Okay, here's my attempt at summarizing the thought process, tailored for an expert audience:

**Investigating DEBUG_INFO_BTF Definition**

Right, let's track down the definition of `config DEBUG_INFO_BTF`. I need to figure out where this is declared within the kernel build system. It’s likely in one of the `Kconfig` files, but which one? The goal is to determine the context around it. I'll need to use my usual methods, probably starting with `grep` across the source tree, perhaps with some clever exclusions to narrow the search. I'm thinking I might look for the surrounding context to see if I can get some relevant metadata about this configuration variable. The resulting file should provide relevant information, such as dependencies, defaults, and the overall purpose of this setting, so I can better understand its impact on the build. Once I find it, I can then understand its effect.



14/2 2026/09/23 19:45 tool grepper
0m Args:
{
  "Expression": "config DEBUG_INFO_BTF\\b"
}

Results:
{
  "Output": "lib/Kconfig.debug=378=config DEBUG_INFO_SPLIT\n--\nlib/Kconfig.debug-397-\nlib/Kconfig.debug:398:config DEBUG_INFO_BTF\nlib/Kconfig.debug-399-\tbool \"Generate BTF type information\"\n"
}

15/2 2026/09/23 19:45 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 23192
							output: 34
							thoughts: 19
						

Thoughts:
Here's my analysis of the provided text, rendered as a first-person expert summary:

**Digging into the Kconfig.debug file**

Okay, so we're looking at `lib/Kconfig.debug`. I know this file intimately – it's where we manage a lot of the low-level debug and instrumentation options for the kernel and related libraries. Now, the context here is critical. Where should I be focusing? Ah, they're suggesting line 398. That usually means something pretty specific. I'll need to remember to check for any relevant dependencies or conditional statements around that line, too. Let's get to it. Time to dive in.



16/2 2026/09/23 19:45 tool read-file
0m Args:
{
  "File": "lib/Kconfig.debug",
  "FirstLine": 395,
  "LineCount": 30
}

Results:
{
  "Contents": " 395:\t\t  to know about the .dwo files and include them.\n 396:\t\t  Incompatible with older versions of ccache.\n 397:\t\n 398:\tconfig DEBUG_INFO_BTF\n 399:\t\tbool \"Generate BTF type information\"\n 400:\t\tdepends on !DEBUG_INFO_SPLIT \u0026\u0026 !DEBUG_INFO_REDUCED\n 401:\t\tdepends on !GCC_PLUGIN_RANDSTRUCT || COMPILE_TEST\n 402:\t\tdepends on BPF_SYSCALL\n 403:\t\tdepends on PAHOLE_VERSION \u003e= 122\n 404:\t\t# pahole uses elfutils, which does not have support for Hexagon relocations\n 405:\t\tdepends on !HEXAGON\n 406:\t\thelp\n 407:\t\t  Generate deduplicated BTF type information from DWARF debug info.\n 408:\t\t  Turning this on requires pahole v1.22 or later, which will convert\n 409:\t\t  DWARF type info into equivalent deduplicated BTF type info.\n 410:\t\n 411:\tconfig PAHOLE_HAS_BTF_TAG\n 412:\t\tdef_bool PAHOLE_VERSION \u003e= 123\n 413:\t\tdepends on CC_IS_CLANG\n 414:\t\thelp\n 415:\t\t  Decide whether pahole emits btf_tag attributes (btf_type_tag and\n 416:\t\t  btf_decl_tag) or not. Currently only clang compiler implements\n 417:\t\t  these attributes, so make the config depend on CC_IS_CLANG.\n 418:\t\n 419:\tconfig PAHOLE_HAS_LANG_EXCLUDE\n 420:\t\tdef_bool PAHOLE_VERSION \u003e= 124\n 421:\t\thelp\n 422:\t\t  Support for the --lang_exclude flag which makes pahole exclude\n 423:\t\t  compilation units from the supplied language. Used in Kbuild to\n 424:\t\t  omit Rust CUs which are not supported in version 1.24 of pahole,\n"
}

17/2 2026/09/23 19:45 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 23929
							output: 38
							thoughts: 908
						

Thoughts:
**Analyzing BPF Feature Dependencies and Identifying Key Symbols**

Okay, so `DEBUG_INFO_BTF` is dependent on `BPF_SYSCALL`, that's the starting point. I need to figure out what functions have been introduced or modified and then choose the correct `FocusSymbols` for this. Let's dig into this diff.

First pass: It looks like `bpf_call_rcu` and `bpf_call_rcu_tasks_trace` in `kernel/bpf/helpers.c` are significant, along with `__bpf_call_rcu` and `bpf_rcu_run_callback`. Also, `btf_parse_fields` in `kernel/bpf/btf.c`, `set_rcu_callback_state` and `is_call_rcu_kfunc` in the verifier, `bpf_map_meta_alloc` in `kernel/bpf/map_in_map.c`, `bpf_iter_attach_map` in `kernel/bpf/map_iter.c`, and finally `map_check_btf` in `kernel/bpf/syscall.c`.

Hold on, I need to check the symbol visibility here. Are these static or non-static? Are they symbols that will appear in `vmlinux`?

So, in `kernel/bpf/helpers.c`, `bpf_call_rcu` and `bpf_call_rcu_tasks_trace` are non-static `__bpf_kfunc`, that's good. `bpf_rcu_run_callback` is static, but crucially it's passed as a function pointer to `call_rcu` or `call_rcu_tasks_trace`, so it's not inlined! And `__bpf_call_rcu` is a static helper.

In `kernel/bpf/verifier.c`, `set_rcu_callback_state` is also static, but it gets passed as a function pointer to `push_callback_call`. So, it's a function pointer/not inlined. Wait, is `check_kfunc_call` in the verifier? Yes, but that's generic, so not what I'm after. Ah, but `bpf_call_rcu` and `bpf_call_rcu_tasks_trace` are exactly the kfuncs *being* introduced, that's important. And `bpf_rcu_run_callback` is the RCU callback that runs after grace period. And `map_check_btf` is static, called from `map_create`. `btf_parse_fields` is non-static.

Now, let's think about the `FocusSymbols`. Are `bpf_rcu_run_callback`, `bpf_call_rcu`, `bpf_call_rcu_tasks_trace`, and `set_rcu_callback_state` good candidates? I need to consult section 4 of the instructions. Let's see... it says to list functions that specifically implement the new logic or are API entrypoints. Also to avoid ubiquitous hot-paths, and the note about static inline functions is relevant.

Alright, based on the instructions, it sounds like `bpf_call_rcu`, `bpf_call_rcu_tasks_trace`, `bpf_rcu_run_callback`, and `set_rcu_callback_state` are good, especially because they are not inlined.

Let's do a final check. I need to confirm whether those four are symbols in the object files. Just to make sure, let's look at `kernel/bpf/helpers.c` lines 4800-4920 to see how `bpf_call_rcu`, `bpf_call_rcu_tasks_trace`, and `bpf_rcu_run_callback` are defined to be sure.



18/2 2026/09/23 19:45 tool read-file
0m Args:
{
  "File": "kernel/bpf/helpers.c",
  "FirstLine": 4805,
  "LineCount": 100
}

Results:
{
  "Contents": "4805:\t\treturn bpf_task_work_schedule(task, tw, map__const_map, callback, aux, TWA_RESUME);\n4806:\t}\n4807:\t\n4808:\ttypedef int (*bpf_rcu_callback_t)(struct bpf_map *map, void *key, void *value);\n4809:\t\n4810:\t/* Actual type for struct bpf_rcu_head */\n4811:\tstruct bpf_rcu_head_kern {\n4812:\t\tstruct rcu_head rcu;\n4813:\t\tbpf_callback_t callback_fn;\n4814:\t\tstruct bpf_map *map;\n4815:\t\tstruct bpf_prog *prog;\n4816:\t\tu32 armed;\n4817:\t} __aligned(8);\n4818:\t\n4819:\tstatic void bpf_rcu_run_callback(struct rcu_head *rcu)\n4820:\t{\n4821:\t\tstruct bpf_rcu_head_kern *rh = container_of(rcu, struct bpf_rcu_head_kern, rcu);\n4822:\t\tbpf_callback_t callback_fn = rh-\u003ecallback_fn;\n4823:\t\tstruct bpf_prog *prog = rh-\u003eprog;\n4824:\t\tstruct bpf_map *map = rh-\u003emap;\n4825:\t\tvoid *value, *key;\n4826:\t\tu32 idx;\n4827:\t\n4828:\t\tvalue = (void *)rh - map-\u003erecord-\u003ercu_head_off;\n4829:\t\tkey = map_key_from_value(map, value, \u0026idx);\n4830:\t\n4831:\t\t/* Pairs with the arming cmpxchg(): rh may be re-armed as soon as this store lands. */\n4832:\t\tsmp_store_release(\u0026rh-\u003earmed, 0);\n4833:\t\n4834:\t\trcu_read_lock_dont_migrate();\n4835:\t\tcallback_fn((u64)(long)map, (u64)(long)key, (u64)(long)value, 0, 0);\n4836:\t\trcu_read_unlock_migrate();\n4837:\t\n4838:\t\tbpf_prog_put(prog);\n4839:\t}\n4840:\t\n4841:\tstatic int __bpf_call_rcu(struct bpf_rcu_head *rh, struct bpf_map *map, void *callback,\n4842:\t\t\t\t  struct bpf_prog_aux *aux, bool trace)\n4843:\t{\n4844:\t\tstruct bpf_rcu_head_kern *rhk = (void *)rh;\n4845:\t\tstruct bpf_prog *prog;\n4846:\t\n4847:\t\tBUILD_BUG_ON(sizeof(struct bpf_rcu_head_kern) \u003e sizeof(struct bpf_rcu_head));\n4848:\t\tBUILD_BUG_ON(__alignof__(struct bpf_rcu_head_kern) != __alignof__(struct bpf_rcu_head));\n4849:\t\tBTF_TYPE_EMIT(struct bpf_rcu_head);\n4850:\t\n4851:\t\t/* A queued callback cannot be cancelled, so a self-rearming one would pin prog and map. */\n4852:\t\tif (!atomic64_read(\u0026map-\u003eusercnt))\n4853:\t\t\treturn -EPERM;\n4854:\t\n4855:\t\tif (cmpxchg(\u0026rhk-\u003earmed, 0, 1))\n4856:\t\t\treturn -EBUSY;\n4857:\t\n4858:\t\tprog = bpf_prog_inc_not_zero(aux-\u003eprog);\n4859:\t\tif (IS_ERR(prog)) {\n4860:\t\t\tWRITE_ONCE(rhk-\u003earmed, 0);\n4861:\t\t\treturn -EBADF;\n4862:\t\t}\n4863:\t\n4864:\t\trhk-\u003ecallback_fn = (bpf_callback_t)callback;\n4865:\t\trhk-\u003emap = map;\n4866:\t\trhk-\u003eprog = prog;\n4867:\t\tif (trace)\n4868:\t\t\tcall_rcu_tasks_trace(\u0026rhk-\u003ercu, bpf_rcu_run_callback);\n4869:\t\telse\n4870:\t\t\tcall_rcu(\u0026rhk-\u003ercu, bpf_rcu_run_callback);\n4871:\t\treturn 0;\n4872:\t}\n4873:\t\n4874:\t/**\n4875:\t * bpf_call_rcu - Invoke a BPF callback after an RCU grace period\n4876:\t * @rh: struct bpf_rcu_head in a BPF map value\n4877:\t * @map__const_map: bpf_map that embeds struct bpf_rcu_head in the values\n4878:\t * @callback: BPF subprogram, invoked as callback(map, key, value) for the value holding @rh\n4879:\t * @aux: bpf_prog_aux of the caller, implicitly set by the verifier\n4880:\t *\n4881:\t * Return: 0, -EBUSY if @rh is already queued, -EPERM if @map is held by neither a process\n4882:\t * nor bpffs, or -EBADF if the calling program is going away.\n4883:\t */\n4884:\t__bpf_kfunc int bpf_call_rcu(struct bpf_rcu_head *rh, void *map__const_map,\n4885:\t\t\t\t     bpf_rcu_callback_t callback, struct bpf_prog_aux *aux)\n4886:\t{\n4887:\t\treturn __bpf_call_rcu(rh, map__const_map, callback, aux, false);\n4888:\t}\n4889:\t\n4890:\t/**\n4891:\t * bpf_call_rcu_tasks_trace - Invoke a BPF callback after an RCU tasks trace grace period\n4892:\t * @rh: struct bpf_rcu_head in a BPF map value\n4893:\t * @map__const_map: bpf_map that embeds struct bpf_rcu_head in the values\n4894:\t * @callback: BPF subprogram, invoked as callback(map, key, value) for the value holding @rh\n4895:\t * @aux: bpf_prog_aux of the caller, implicitly set by the verifier\n4896:\t *\n4897:\t * Waits for sleepable BPF programs too.  The callback itself is not sleepable either way.\n4898:\t *\n4899:\t * Return: 0, -EBUSY if @rh is already queued, -EPERM if @map is held by neither a process\n4900:\t * nor bpffs, or -EBADF if the calling program is going away.\n4901:\t */\n4902:\t__bpf_kfunc int bpf_call_rcu_tasks_trace(struct bpf_rcu_head *rh, void *map__const_map,\n4903:\t\t\t\t\t\t bpf_rcu_callback_t callback, struct bpf_prog_aux *aux)\n4904:\t{\n"
}

19/2 2026/09/23 19:45 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 27683
							output: 32
							thoughts: 373
						

Thoughts:
**My Initial BPF-RCU Exploration**

Alright, let's dive into this `bpf_rcu_head` situation. My first instinct is to zero in on the core RCU functions involved. I'm looking at `bpf_call_rcu`, `bpf_call_rcu_tasks_trace`, `bpf_rcu_run_callback`, and `__bpf_call_rcu`. Then, I'll check what's happening within the verifier, particularly `set_rcu_callback_state` in `kernel/bpf/verifier.c`. Are there any other critical functions here?

I need to see how these RCU heads are handled, so `btf_parse_fields` in `kernel/bpf/btf.c`, which specifically deals with `BPF_RCU_HEAD`, is important. I'll also glance at `kernel/bpf/syscall.c`, focusing on `map_check_btf` which validates the use of `BPF_RCU_HEAD`, specifically to see if the restriction to only using it with `BPF_MAP_TYPE_ARRAY` is enforced.

Now, let's take a closer look at these symbols: `bpf_call_rcu`, `bpf_call_rcu_tasks_trace`, `bpf_rcu_run_callback`, `__bpf_call_rcu`, and `set_rcu_callback_state`. I need to assess their scope. Are these functions widely used across the kernel, or are they specific to this new functionality?

The good news is that they seem quite specific to this RCU-BPF feature. This suggests a clean separation, which is always nice to see.

Now, let's consider the configuration options. The obvious ones are `BPF_SYSCALL` (since it's a BPF system call), `DEBUG_INFO_BTF` for kfuncs and BTF validation, and whatever else might be relevant. My concern is whether `CONFIG_RCU_TASKS_TRACE` is a separate config, or selected by default or BPF. I'm going to do a quick `grep` for `CONFIG_RCU_TASKS_TRACE` and `call_rcu_tasks_trace` to ascertain that.



20/2 2026/09/23 19:45 tool grepper
0m Error:
no matches

Args:
{
  "Expression": "RCU_TASKS_TRACE",
  "PathPrefix": "kernel/rcu/"
}

Results:
{
  "error": "no matches"
}

21/2 2026/09/23 19:45 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 28604
							output: 33
							thoughts: 26
						

Thoughts:
Okay, here's my take on those thoughts, tailored for an expert audience:

**Investigating `call_rcu_tasks_trace` in the Kernel**

Alright, let's dive into this. My initial thought process is to quickly understand the landscape surrounding `call_rcu_tasks_trace`. The most direct and efficient method here is, of course, a quick `grep` within the kernel source. I'm aiming for a comprehensive view, so I'll be targeting the entire tree. I want to see the declaration, the call sites, and any other relevant usage patterns. Essentially, I'm trying to map out the call graph and identify any direct dependencies or significant interactions that this tracepoint has. This is where I can start building an understanding of how it's used and how it interacts with the RCU implementation. This will help inform any potential modifications or analysis that I need to perform. I'm expecting this `grep` to quickly give me enough context to proceed with any deeper analysis.



22/2 2026/09/23 19:45 tool grepper
0m Args:
{
  "Expression": "call_rcu_tasks_trace",
  "PathPrefix": "kernel/rcu/"
}

Results:
{
  "Output": "kernel/rcu/rcuscale.c=399=static struct rcu_scale_ops tasks_tracing_ops = {\n--\nkernel/rcu/rcuscale.c-405-\t.gp_diff\t= rcu_seq_diff,\nkernel/rcu/rcuscale.c:406:\t.async\t\t= call_rcu_tasks_trace,\nkernel/rcu/rcuscale.c-407-\t.gp_barrier\t= rcu_barrier_tasks_trace,\n--\nkernel/rcu/rcutorture.c=1249=static void rcu_tasks_tracing_torture_deferred_free(struct rcu_torture *p)\nkernel/rcu/rcutorture.c-1250-{\nkernel/rcu/rcutorture.c:1251:\tcall_rcu_tasks_trace(\u0026p-\u003ertort_rcu, rcu_torture_cb);\nkernel/rcu/rcutorture.c-1252-}\n--\nkernel/rcu/rcutorture.c=1254=static struct rcu_torture_ops tasks_tracing_ops = {\n--\nkernel/rcu/rcutorture.c-1266-\t.exp_current\t= rcu_tasks_trace_expedite_current,\nkernel/rcu/rcutorture.c:1267:\t.call\t\t= call_rcu_tasks_trace,\nkernel/rcu/rcutorture.c-1268-\t.cb_barrier\t= rcu_barrier_tasks_trace,\n--\nkernel/rcu/tasks.h=1466=static struct rcu_tasks_test_desc tests[] = {\n--\nkernel/rcu/tasks.h-1474-\t{\nkernel/rcu/tasks.h:1475:\t\t.name = \"call_rcu_tasks_trace()\",\nkernel/rcu/tasks.h-1476-\t\t/* If not defined, the test is skipped. */\n--\nkernel/rcu/tasks.h=1493=static void rcu_tasks_initiate_self_tests(void)\n--\nkernel/rcu/tasks.h-1510-\tsynchronize_rcu_tasks_trace();\nkernel/rcu/tasks.h:1511:\tcall_rcu_tasks_trace(\u0026tests[1].rh, test_rcu_tasks_callback);\nkernel/rcu/tasks.h-1512-#endif\n"
}

23/2 2026/09/23 19:45 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 29504
							output: 23
							thoughts: 20
						

Thoughts:
Here's a first-person summary, tailored for an expert audience, as requested:

**Tracing the Call to `call_rcu_tasks_trace`**

Okay, so I need to understand the lifecycle and usage of this `call_rcu_tasks_trace` function. My first instinct is to immediately locate the declaration and definition. No hand-waving here; I'm going to jump straight into the kernel source and use my usual tools – likely `grep` and a decent IDE with symbol lookup – to pinpoint its exact location. I need the declaration to understand its signature, any arguments passed, and its return type. The definition, obviously, contains the actual implementation, which will be crucial for understanding its behavior within the RCU (Read-Copy-Update) context. I'm assuming it's part of the RCU tracing subsystem, but I need to confirm that suspicion through the code itself. Understanding where it's *declared* will also give me important information, namely where to look for documentation.



24/2 2026/09/23 19:45 tool grepper
0m Args:
{
  "Expression": "void call_rcu_tasks_trace"
}

Results:
{
  "Output": "include/linux/rcupdate_trace.h=123=static inline void rcu_read_unlock_trace(void)\n--\ninclude/linux/rcupdate_trace.h-156- */\ninclude/linux/rcupdate_trace.h:157:static inline void call_rcu_tasks_trace(struct rcu_head *rhp, rcu_callback_t func)\ninclude/linux/rcupdate_trace.h-158-{\n--\ninclude/linux/rcupdate_trace.h=215=static inline unsigned long rcu_tasks_trace_batches_completed(void) { return 0; }\n--\ninclude/linux/rcupdate_trace.h-219- */\ninclude/linux/rcupdate_trace.h:220:static inline void call_rcu_tasks_trace(struct rcu_head *rhp, rcu_callback_t func) { BUG(); }\ninclude/linux/rcupdate_trace.h-221-static inline void rcu_read_lock_trace(void) { BUG(); }\n"
}

25/2 2026/09/23 19:46 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 30026
							output: 38
							thoughts: 16
						

Thoughts:
Here's a summary of my thought process, as requested:

**Diving into `rcupdate_trace.h`**

Okay, time to get started. My initial thought is to dive into `include/linux/rcupdate_trace.h`. I'm specifically interested in the tracing aspects, given the file name. I need to understand how the read-copy-update mechanisms are being instrumented for debugging and performance analysis. I'm going to look for the tracepoints, probe points, and any supporting macros or structures that facilitate capturing data related to RCU operations. I'm expecting to find details on events like grace periods, quiescent states, and potentially even data related to specific update side operations that are of interest. I also need to see how this traces is structured, what kernel subsystems it interfaces with, and how verbose and effective this tracing is. Let's see what we can dig up here.



26/2 2026/09/23 19:46 tool read-file
0m Args:
{
  "File": "include/linux/rcupdate_trace.h",
  "FirstLine": 145,
  "LineCount": 40
}

Results:
{
  "Contents": " 145:\t * @rhp: structure to be used for queueing the RCU updates.\n 146:\t * @func: actual callback function to be invoked after the grace period\n 147:\t *\n 148:\t * The callback function will be invoked some time after a trace rcu-tasks\n 149:\t * grace period elapses, in other words after all currently executing\n 150:\t * trace rcu-tasks read-side critical sections have completed. These\n 151:\t * read-side critical sections are delimited by calls to rcu_read_lock_trace()\n 152:\t * and rcu_read_unlock_trace().\n 153:\t *\n 154:\t * See the description of call_rcu() for more detailed information on\n 155:\t * memory ordering guarantees.\n 156:\t */\n 157:\tstatic inline void call_rcu_tasks_trace(struct rcu_head *rhp, rcu_callback_t func)\n 158:\t{\n 159:\t\tcall_srcu(\u0026rcu_tasks_trace_srcu_struct, rhp, func);\n 160:\t}\n 161:\t\n 162:\t/**\n 163:\t * synchronize_rcu_tasks_trace - wait for a trace rcu-tasks grace period\n 164:\t *\n 165:\t * Control will return to the caller some time after a trace rcu-tasks\n 166:\t * grace period has elapsed, in other words after all currently executing\n 167:\t * trace rcu-tasks read-side critical sections have elapsed. These read-side\n 168:\t * critical sections are delimited by calls to rcu_read_lock_trace()\n 169:\t * and rcu_read_unlock_trace().\n 170:\t *\n 171:\t * This is a very specialized primitive, intended only for a few uses in\n 172:\t * tracing and other situations requiring manipulation of function preambles\n 173:\t * and profiling hooks.  The synchronize_rcu_tasks_trace() function is not\n 174:\t * (yet) intended for heavy use from multiple CPUs.\n 175:\t *\n 176:\t * See the description of synchronize_rcu() for more detailed information\n 177:\t * on memory ordering guarantees.\n 178:\t */\n 179:\tstatic inline void synchronize_rcu_tasks_trace(void)\n 180:\t{\n 181:\t\tsynchronize_srcu(\u0026rcu_tasks_trace_srcu_struct);\n 182:\t}\n 183:\t\n 184:\t/**\n"
}

27/2 2026/09/23 19:46 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 30959
							output: 36
							thoughts: 33
						

Thoughts:
Here's my analysis of the provided task, assuming I'm an experienced kernel developer:

**Investigating the `rcupdate_trace.h` Header**

Okay, so the goal is to figure out the conditional compilation (#ifdef) that controls the inclusion of lines 1-140 of `include/linux/rcupdate_trace.h`. This is a standard investigation process; knowing under what configurations a piece of code is compiled is crucial for understanding its purpose and potential impact, especially in a complex area like RCU (Read-Copy-Update). I'll need to open that header file directly and examine the code. I'll mentally parse the preprocessor directives: looking for `#ifdef`, `#ifndef`, `#if`, `#else`, and `#endif` blocks. I'll need to pay close attention to the conditions; often there are multiple layers, and the conditions themselves may involve macros or other definitions that I'll need to track. Ultimately, the goal is to identify the specific configuration options (like kernel features enabled, architecture-specific defines, or build-time settings) that determine whether those lines are actually compiled into the kernel. This is a vital first step to properly contextualize that section of code.



28/2 2026/09/23 19:46 tool read-file
0m Args:
{
  "File": "include/linux/rcupdate_trace.h",
  "FirstLine": 1,
  "LineCount": 50
}

Results:
{
  "Contents": "   1:\t/* SPDX-License-Identifier: GPL-2.0+ */\n   2:\t/*\n   3:\t * Read-Copy Update mechanism for mutual exclusion, adapted for tracing.\n   4:\t *\n   5:\t * Copyright (C) 2020 Paul E. McKenney.\n   6:\t */\n   7:\t\n   8:\t#ifndef __LINUX_RCUPDATE_TRACE_H\n   9:\t#define __LINUX_RCUPDATE_TRACE_H\n  10:\t\n  11:\t#include \u003clinux/sched.h\u003e\n  12:\t#include \u003clinux/rcupdate.h\u003e\n  13:\t#include \u003clinux/cleanup.h\u003e\n  14:\t\n  15:\t#ifdef CONFIG_TASKS_TRACE_RCU\n  16:\textern struct srcu_struct rcu_tasks_trace_srcu_struct;\n  17:\t#endif // #ifdef CONFIG_TASKS_TRACE_RCU\n  18:\t\n  19:\t#if defined(CONFIG_DEBUG_LOCK_ALLOC) \u0026\u0026 defined(CONFIG_TASKS_TRACE_RCU)\n  20:\t\n  21:\tstatic inline int rcu_read_lock_trace_held(void)\n  22:\t{\n  23:\t\treturn srcu_read_lock_held(\u0026rcu_tasks_trace_srcu_struct);\n  24:\t}\n  25:\t\n  26:\t#else // #if defined(CONFIG_DEBUG_LOCK_ALLOC) \u0026\u0026 defined(CONFIG_TASKS_TRACE_RCU)\n  27:\t\n  28:\tstatic inline int rcu_read_lock_trace_held(void)\n  29:\t{\n  30:\t\treturn 1;\n  31:\t}\n  32:\t\n  33:\t#endif // #else // #if defined(CONFIG_DEBUG_LOCK_ALLOC) \u0026\u0026 defined(CONFIG_TASKS_TRACE_RCU)\n  34:\t\n  35:\t#ifdef CONFIG_TASKS_TRACE_RCU\n  36:\t\n  37:\t/**\n  38:\t * rcu_read_lock_tasks_trace - mark beginning of RCU-trace read-side critical section\n  39:\t *\n  40:\t * When synchronize_rcu_tasks_trace() is invoked by one task, then that\n  41:\t * task is guaranteed to block until all other tasks exit their read-side\n  42:\t * critical sections.  Similarly, if call_rcu_trace() is invoked on one\n  43:\t * task while other tasks are within RCU read-side critical sections,\n  44:\t * invocation of the corresponding RCU callback is deferred until after\n  45:\t * the all the other tasks exit their critical sections.\n  46:\t *\n  47:\t * For more details, please see the documentation for\n  48:\t * srcu_read_lock_fast().  For a description of how implicit RCU\n  49:\t * readers provide the needed ordering for architectures defining the\n  50:\t * ARCH_WANTS_NO_INSTR Kconfig option (and thus promising never to trace\n"
}

29/2 2026/09/23 19:46 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 32062
							output: 21
							thoughts: 29
						

Thoughts:
Here's a summary of my thought process, as requested:

**Investigating the Dependencies of `CONFIG_TASKS_TRACE_RCU`**

Okay, so `CONFIG_TASKS_TRACE_RCU` has popped up. My immediate instinct is to understand its dependencies. It's crucial, as always, to grasp the implications of enabling this. I need to figure out what other configurations or features trigger its inclusion. What other code paths might rely on it, and what are the functional consequences of its existence or absence? I'll need to trace through the Kconfig files now, see who's selecting it. Time to dive into the kernel configuration hierarchy...



30/2 2026/09/23 19:46 tool grepper
0m Args:
{
  "Expression": "TASKS_TRACE_RCU"
}

Results:
{
  "Output": "Documentation/RCU/Design/Requirements/Requirements.rst=2787=that apply noinstr to kernel entry/exit code (or that build with\nDocumentation/RCU/Design/Requirements/Requirements.rst:2788:``CONFIG_TASKS_TRACE_RCU_NO_MB=y``).\nDocumentation/RCU/Design/Requirements/Requirements.rst-2789-\n--\narch/Kconfig=196=config UPROBES\n--\narch/Kconfig-198-\tdepends on ARCH_SUPPORTS_UPROBES\narch/Kconfig:199:\tselect TASKS_TRACE_RCU\narch/Kconfig-200-\thelp\n--\ninclude/linux/rcupdate_trace.h-14-\ninclude/linux/rcupdate_trace.h:15:#ifdef CONFIG_TASKS_TRACE_RCU\ninclude/linux/rcupdate_trace.h-16-extern struct srcu_struct rcu_tasks_trace_srcu_struct;\ninclude/linux/rcupdate_trace.h:17:#endif // #ifdef CONFIG_TASKS_TRACE_RCU\ninclude/linux/rcupdate_trace.h-18-\ninclude/linux/rcupdate_trace.h:19:#if defined(CONFIG_DEBUG_LOCK_ALLOC) \u0026\u0026 defined(CONFIG_TASKS_TRACE_RCU)\ninclude/linux/rcupdate_trace.h-20-\ninclude/linux/rcupdate_trace.h=21=static inline int rcu_read_lock_trace_held(void)\n--\ninclude/linux/rcupdate_trace.h-25-\ninclude/linux/rcupdate_trace.h:26:#else // #if defined(CONFIG_DEBUG_LOCK_ALLOC) \u0026\u0026 defined(CONFIG_TASKS_TRACE_RCU)\ninclude/linux/rcupdate_trace.h-27-\ninclude/linux/rcupdate_trace.h=28=static inline int rcu_read_lock_trace_held(void)\n--\ninclude/linux/rcupdate_trace.h-32-\ninclude/linux/rcupdate_trace.h:33:#endif // #else // #if defined(CONFIG_DEBUG_LOCK_ALLOC) \u0026\u0026 defined(CONFIG_TASKS_TRACE_RCU)\ninclude/linux/rcupdate_trace.h-34-\ninclude/linux/rcupdate_trace.h:35:#ifdef CONFIG_TASKS_TRACE_RCU\ninclude/linux/rcupdate_trace.h-36-\n--\ninclude/linux/rcupdate_trace.h=55=static inline struct srcu_ctr __percpu *rcu_read_lock_tasks_trace(void)\n--\ninclude/linux/rcupdate_trace.h-59-\trcu_try_lock_acquire(\u0026rcu_tasks_trace_srcu_struct.dep_map);\ninclude/linux/rcupdate_trace.h:60:\tif (!IS_ENABLED(CONFIG_TASKS_TRACE_RCU_NO_MB))\ninclude/linux/rcupdate_trace.h-61-\t\tsmp_mb(); // Provide ordering on noinstr-incomplete architectures.\n--\ninclude/linux/rcupdate_trace.h=76=static inline void rcu_read_unlock_tasks_trace(struct srcu_ctr __percpu *scp)\ninclude/linux/rcupdate_trace.h-77-{\ninclude/linux/rcupdate_trace.h:78:\tif (!IS_ENABLED(CONFIG_TASKS_TRACE_RCU_NO_MB))\ninclude/linux/rcupdate_trace.h-79-\t\tsmp_mb(); // Provide ordering on noinstr-incomplete architectures.\n--\ninclude/linux/rcupdate_trace.h=96=static inline void rcu_read_lock_trace(void)\n--\ninclude/linux/rcupdate_trace.h-109-\tt-\u003etrc_reader_scp = __srcu_read_lock_fast(\u0026rcu_tasks_trace_srcu_struct);\ninclude/linux/rcupdate_trace.h:110:\tif (!IS_ENABLED(CONFIG_TASKS_TRACE_RCU_NO_MB))\ninclude/linux/rcupdate_trace.h-111-\t\tsmp_mb(); // Placeholder for more selective ordering\n--\ninclude/linux/rcupdate_trace.h=123=static inline void rcu_read_unlock_trace(void)\n--\ninclude/linux/rcupdate_trace.h-135-\t\tWRITE_ONCE(t-\u003etrc_reader_nesting, n);\ninclude/linux/rcupdate_trace.h:136:\t\tif (!IS_ENABLED(CONFIG_TASKS_TRACE_RCU_NO_MB))\ninclude/linux/rcupdate_trace.h-137-\t\t\tsmp_mb(); // Placeholder for more selective ordering\n--\ninclude/linux/rcupdate_trace.h=222=static inline void rcu_read_unlock_trace(void) { BUG(); }\ninclude/linux/rcupdate_trace.h:223:#endif /* #ifdef CONFIG_TASKS_TRACE_RCU */\ninclude/linux/rcupdate_trace.h-224-\n--\ninclude/linux/sched.h=835=struct task_struct {\n--\ninclude/linux/sched.h-964-\ninclude/linux/sched.h:965:#ifdef CONFIG_TASKS_TRACE_RCU\ninclude/linux/sched.h-966-\tint\t\t\t\ttrc_reader_nesting;\ninclude/linux/sched.h-967-\tstruct srcu_ctr __percpu\t*trc_reader_scp;\ninclude/linux/sched.h:968:#endif /* #ifdef CONFIG_TASKS_TRACE_RCU */\ninclude/linux/sched.h-969-\n--\ninit/Kconfig=2296=config TRACEPOINTS\ninit/Kconfig-2297-\tbool\ninit/Kconfig:2298:\tselect TASKS_TRACE_RCU\ninit/Kconfig-2299-\n--\ninit/init_task.c=105=struct task_struct init_task __aligned(L1_CACHE_BYTES) = {\n--\ninit/init_task.c-207-#endif\ninit/init_task.c:208:#ifdef CONFIG_TASKS_TRACE_RCU\ninit/init_task.c-209-\t.trc_reader_nesting = 0,\n--\nkernel/bpf/Kconfig=31=config BPF_SYSCALL\n--\nkernel/bpf/Kconfig-35-\tselect NEED_TASKS_RCU\nkernel/bpf/Kconfig:36:\tselect TASKS_TRACE_RCU\nkernel/bpf/Kconfig-37-\tselect BINARY_PRINTF\n--\nkernel/fork.c=1862=static inline void rcu_copy_process(struct task_struct *p)\n--\nkernel/fork.c-1875-#endif /* #ifdef CONFIG_TASKS_RCU */\nkernel/fork.c:1876:#ifdef CONFIG_TASKS_TRACE_RCU\nkernel/fork.c-1877-\tp-\u003etrc_reader_nesting = 0;\nkernel/fork.c:1878:#endif /* #ifdef CONFIG_TASKS_TRACE_RCU */\nkernel/fork.c-1879-}\n--\nkernel/rcu/Kconfig=122=config TASKS_RUDE_RCU\n--\nkernel/rcu/Kconfig-126-\nkernel/rcu/Kconfig:127:config FORCE_TASKS_TRACE_RCU\nkernel/rcu/Kconfig-128-\tbool \"Force selection of Tasks Trace RCU\"\nkernel/rcu/Kconfig-129-\tdepends on RCU_EXPERT\nkernel/rcu/Kconfig:130:\tselect TASKS_TRACE_RCU\nkernel/rcu/Kconfig-131-\tdefault n\n--\nkernel/rcu/Kconfig-139-\nkernel/rcu/Kconfig:140:config TASKS_TRACE_RCU\nkernel/rcu/Kconfig-141-\tbool\n--\nkernel/rcu/Kconfig-143-\nkernel/rcu/Kconfig:144:config TASKS_TRACE_RCU_NO_MB\nkernel/rcu/Kconfig-145-\tbool \"Override RCU Tasks Trace inclusion of read-side memory barriers\"\nkernel/rcu/Kconfig:146:\tdepends on RCU_EXPERT \u0026\u0026 TASKS_TRACE_RCU\nkernel/rcu/Kconfig-147-\tdefault ARCH_WANTS_NO_INSTR\n--\nkernel/rcu/rcuscale.c=360=static struct rcu_scale_ops tasks_rude_ops = {\n--\nkernel/rcu/rcuscale.c-381-\nkernel/rcu/rcuscale.c:382:#ifdef CONFIG_TASKS_TRACE_RCU\nkernel/rcu/rcuscale.c-383-\n--\nkernel/rcu/rcuscale.c=399=static struct rcu_scale_ops tasks_tracing_ops = {\n--\nkernel/rcu/rcuscale.c-414-\nkernel/rcu/rcuscale.c:415:#else // #ifdef CONFIG_TASKS_TRACE_RCU\nkernel/rcu/rcuscale.c-416-\n--\nkernel/rcu/rcuscale.c-418-\nkernel/rcu/rcuscale.c:419:#endif // #else // #ifdef CONFIG_TASKS_TRACE_RCU\nkernel/rcu/rcuscale.c-420-\n--\nkernel/rcu/rcutorture.c=1198=static struct rcu_torture_ops tasks_rude_ops = {\n--\nkernel/rcu/rcutorture.c-1222-\nkernel/rcu/rcutorture.c:1223:#ifdef CONFIG_TASKS_TRACE_RCU\nkernel/rcu/rcutorture.c-1224-\n--\nkernel/rcu/rcutorture.c=1254=static struct rcu_torture_ops tasks_tracing_ops = {\n--\nkernel/rcu/rcutorture.c-1276-\nkernel/rcu/rcutorture.c:1277:#else // #ifdef CONFIG_TASKS_TRACE_RCU\nkernel/rcu/rcutorture.c-1278-\n--\nkernel/rcu/rcutorture.c-1280-\nkernel/rcu/rcutorture.c:1281:#endif // #else #ifdef CONFIG_TASKS_TRACE_RCU\nkernel/rcu/rcutorture.c-1282-\n--\nkernel/rcu/rcutorture.c=4506=static void rcu_torture_init_srcu_lockdep(void)\n--\nkernel/rcu/rcutorture.c-4597-\nkernel/rcu/rcutorture.c:4598:#ifdef CONFIG_TASKS_TRACE_RCU\nkernel/rcu/rcutorture.c-4599-\tif (testtype == 3) {\n--\nkernel/rcu/rcutorture.c-4627-\t}\nkernel/rcu/rcutorture.c:4628:#endif // #ifdef CONFIG_TASKS_TRACE_RCU\nkernel/rcu/rcutorture.c-4629-\n--\nkernel/rcu/rcutorture.c-4635-\tpr_info(\"%s: L: Cycle length.\\n\", __func__);\nkernel/rcu/rcutorture.c:4636:\tif (!IS_ENABLED(CONFIG_TASKS_TRACE_RCU))\nkernel/rcu/rcutorture.c:4637:\t\tpr_info(\"%s: NN=3 disallowed because kernel is built with CONFIG_TASKS_TRACE_RCU=n\\n\", __func__);\nkernel/rcu/rcutorture.c-4638-}\n--\nkernel/rcu/refscale.c=304=static const struct ref_scale_ops rcu_tasks_ops = {\n--\nkernel/rcu/refscale.c-318-\nkernel/rcu/refscale.c:319:#ifdef CONFIG_TASKS_TRACE_RCU\nkernel/rcu/refscale.c-320-\n--\nkernel/rcu/refscale.c=343=static const struct ref_scale_ops rcu_trace_ops = {\n--\nkernel/rcu/refscale.c-351-\nkernel/rcu/refscale.c:352:#else // #ifdef CONFIG_TASKS_TRACE_RCU\nkernel/rcu/refscale.c-353-\n--\nkernel/rcu/refscale.c-355-\nkernel/rcu/refscale.c:356:#endif // #else // #ifdef CONFIG_TASKS_TRACE_RCU\nkernel/rcu/refscale.c-357-\n--\nkernel/rcu/tasks.h=695=static void __init rcu_tasks_bootup_oddness(void)\nkernel/rcu/tasks.h-696-{\nkernel/rcu/tasks.h:697:#if defined(CONFIG_TASKS_RCU) || defined(CONFIG_TASKS_TRACE_RCU)\nkernel/rcu/tasks.h-698-\tint rtsimc;\n--\nkernel/rcu/tasks.h-713-#endif /* #ifdef CONFIG_TASKS_RUDE_RCU */\nkernel/rcu/tasks.h:714:#ifdef CONFIG_TASKS_TRACE_RCU\nkernel/rcu/tasks.h-715-\tpr_info(\"\\tTracing variant of Tasks RCU enabled.\\n\");\nkernel/rcu/tasks.h:716:#endif /* #ifdef CONFIG_TASKS_TRACE_RCU */\nkernel/rcu/tasks.h-717-}\n--\nkernel/rcu/tasks.h=1466=static struct rcu_tasks_test_desc tests[] = {\n--\nkernel/rcu/tasks.h-1476-\t\t/* If not defined, the test is skipped. */\nkernel/rcu/tasks.h:1477:\t\t.notrun = IS_ENABLED(CONFIG_TASKS_TRACE_RCU)\nkernel/rcu/tasks.h-1478-\t}\n--\nkernel/rcu/tasks.h-1480-\nkernel/rcu/tasks.h:1481:#if defined(CONFIG_TASKS_RCU) || defined(CONFIG_TASKS_TRACE_RCU)\nkernel/rcu/tasks.h-1482-static void test_rcu_tasks_callback(struct rcu_head *rhp)\n--\nkernel/rcu/tasks.h-1490-}\nkernel/rcu/tasks.h:1491:#endif // #if defined(CONFIG_TASKS_RCU) || defined(CONFIG_TASKS_TRACE_RCU)\nkernel/rcu/tasks.h-1492-\nkernel/rcu/tasks.h=1493=static void rcu_tasks_initiate_self_tests(void)\n--\nkernel/rcu/tasks.h-1506-\nkernel/rcu/tasks.h:1507:#ifdef CONFIG_TASKS_TRACE_RCU\nkernel/rcu/tasks.h-1508-\tpr_info(\"Running RCU Tasks Trace wait API self tests\\n\");\n--\nkernel/rcu/tasks.h=1605=static inline void rcu_tasks_bootup_oddness(void) {}\n--\nkernel/rcu/tasks.h-1607-\nkernel/rcu/tasks.h:1608:#ifdef CONFIG_TASKS_TRACE_RCU\nkernel/rcu/tasks.h-1609-\n--\nkernel/rcu/tasks.h=1623=EXPORT_SYMBOL_GPL(rcu_tasks_trace_batches_completed);\nkernel/rcu/tasks.h-1624-\nkernel/rcu/tasks.h:1625:#endif /* #else #ifdef CONFIG_TASKS_TRACE_RCU */\n--\ntools/testing/selftests/rcutorture/bin/torture.sh=461=then\n--\ntools/testing/selftests/rcutorture/bin/torture.sh-467-#CHECK#CONFIG_TASKS_RUDE_RCU=n\ntools/testing/selftests/rcutorture/bin/torture.sh:468:#CHECK#CONFIG_TASKS_TRACE_RCU=n\ntools/testing/selftests/rcutorture/bin/torture.sh-469-__EOF__\ntools/testing/selftests/rcutorture/bin/torture.sh:470:\tfor flavor in CONFIG_TASKS_RCU CONFIG_TASKS_RUDE_RCU CONFIG_TASKS_TRACE_RCU\ntools/testing/selftests/rcutorture/bin/torture.sh-471-\tdo\n--\ntools/testing/selftests/rcutorture/bin/torture.sh=597=do\n--\ntools/testing/selftests/rcutorture/bin/torture.sh-600-\t\ttorture_bootargs=\"refscale.scale_type=\"$prim\" refscale.nreaders=$SCALE_ALLOTED_CPUS refscale.loops=10000 refscale.holdoff=20 torture.disable_ono...\ntools/testing/selftests/rcutorture/bin/torture.sh:601:\t\ttorture_set \"refscale-$prim\" tools/testing/selftests/rcutorture/bin/kvm.sh --torture refscale --allcpus --duration 5 --kconfig \"CONFIG_TASKS_TRA...\ntools/testing/selftests/rcutorture/bin/torture.sh-602-\t\tmv $T/last-resdir-nodebug $T/first-resdir-nodebug || :\n--\ntools/testing/selftests/rcutorture/bin/torture.sh=646=do\n--\ntools/testing/selftests/rcutorture/bin/torture.sh-649-\t\ttorture_bootargs=\"rcuscale.scale_type=\"$prim\" rcuscale.nwriters=$SCALE_ALLOTED_CPUS rcuscale.holdoff=20 torture.disable_onoff_at_boot\"\ntools/testing/selftests/rcutorture/bin/torture.sh:650:\t\ttorture_set \"rcuscale-$prim\" tools/testing/selftests/rcutorture/bin/kvm.sh --torture rcuscale --allcpus --duration 5 --kconfig \"CONFIG_TASKS_TRA...\ntools/testing/selftests/rcutorture/bin/torture.sh-651-\t\tmv $T/last-resdir-nodebug $T/first-resdir-nodebug || :\n--\ntools/testing/selftests/rcutorture/configs/rcu/TRACE01=10=CONFIG_PROVE_LOCKING=n\ntools/testing/selftests/rcutorture/configs/rcu/TRACE01-11-#CHECK#CONFIG_PROVE_RCU=n\ntools/testing/selftests/rcutorture/configs/rcu/TRACE01:12:CONFIG_FORCE_TASKS_TRACE_RCU=y\ntools/testing/selftests/rcutorture/configs/rcu/TRACE01:13:#CHECK#CONFIG_TASKS_TRACE_RCU=y\ntools/testing/selftests/rcutorture/configs/rcu/TRACE01-14-CONFIG_RCU_EXPERT=y\n--\ntools/testing/selftests/rcutorture/configs/rcu/TRACE02=8=CONFIG_PROVE_LOCKING=y\ntools/testing/selftests/rcutorture/configs/rcu/TRACE02-9-#CHECK#CONFIG_PROVE_RCU=y\ntools/testing/selftests/rcutorture/configs/rcu/TRACE02:10:CONFIG_FORCE_TASKS_TRACE_RCU=y\ntools/testing/selftests/rcutorture/configs/rcu/TRACE02:11:#CHECK#CONFIG_TASKS_TRACE_RCU=y\ntools/testing/selftests/rcutorture/configs/rcu/TRACE02-12-CONFIG_RCU_EXPERT=y\n--\ntools/testing/selftests/rcutorture/configs/rcuscale/CFcommon=5=CONFIG_FORCE_TASKS_RUDE_RCU=y\ntools/testing/selftests/rcutorture/configs/rcuscale/CFcommon-6-#CHECK#CONFIG_TASKS_RUDE_RCU=y\ntools/testing/selftests/rcutorture/configs/rcuscale/CFcommon:7:CONFIG_FORCE_TASKS_TRACE_RCU=y\ntools/testing/selftests/rcutorture/configs/rcuscale/CFcommon:8:#CHECK#CONFIG_TASKS_TRACE_RCU=y\n--\ntools/testing/selftests/rcutorture/configs/refscale/CFcommon=3=CONFIG_FORCE_TASKS_RCU=y\ntools/testing/selftests/rcutorture/configs/refscale/CFcommon-4-#CHECK#CONFIG_TASKS_RCU=y\ntools/testing/selftests/rcutorture/configs/refscale/CFcommon:5:CONFIG_FORCE_TASKS_TRACE_RCU=y\ntools/testing/selftests/rcutorture/configs/refscale/CFcommon:6:#CHECK#CONFIG_TASKS_TRACE_RCU=y\n"
}

31/2 2026/09/23 19:46 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 37597
							output: 204
							thoughts: 1185
						

Thoughts:
**Analysis of BPF RCU Implementation for Fuzzing and Configuration**

Okay, so looking at this patch, the `BPF_SYSCALL` config automatically selects `TASKS_TRACE_RCU`, which is good to know. And the `DEBUG_INFO_BTF` option depends on `BPF_SYSCALL`, that's another important dependency. No other obvious config dependencies stand out.

I need to nail down the focus functions for fuzzing. Let's see... the patch adds, or significantly alters: `bpf_call_rcu`, `bpf_call_rcu_tasks_trace`, `bpf_rcu_run_callback`, `__bpf_call_rcu`, and `set_rcu_callback_state`. I need to confirm those aren't static inline functions. Okay, `bpf_rcu_run_callback` is static but not inlined, since its address is passed to `call_rcu` and `call_rcu_tasks_trace`, so that's a key symbol. `__bpf_call_rcu` is a static helper function, so its inlining is a compiler concern. `bpf_call_rcu` and `bpf_call_rcu_tasks_trace` are exported kfuncs, definitely non-inlined symbols. `set_rcu_callback_state` is static and passed as a function pointer; it *cannot* be inlined. Got it.

Double-checking, any other symbols that are relevant? Well, `map_check_btf` now has a `BPF_RCU_HEAD` case, and it's called on every map creation with BTF, so it's a focus symbol. The same with `bpf_map_meta_alloc` and `bpf_iter_attach_map`.

So, the critical functions implementing this RCU feature: `bpf_call_rcu`, `bpf_call_rcu_tasks_trace`, `bpf_rcu_run_callback`, `__bpf_call_rcu`, and `set_rcu_callback_state` -- definitely those.

Now, let's make sure I'm following the instructions. For "WorthFuzzing", this *absolutely* applies. We're modifying the BPF core subsystem by adding `bpf_rcu_head` support, registration of callbacks, verification, deferred execution, and map lifetime refcounting - all of this reachable via the `bpf()` syscall.

For "FocusSymbols", the list I identified above - `bpf_call_rcu`, `bpf_call_rcu_tasks_trace`, `bpf_rcu_run_callback`, `__bpf_call_rcu`, `set_rcu_callback_state` - are precisely the functions *implementing* the new RCU logic and API entrypoints, avoiding ubiquitous functions.

And for "EnableConfigs", the required configs are `BPF_SYSCALL` and `DEBUG_INFO_BTF`, from the Kconfig analysis. No other specific configurations jump out as strictly required. `BPF_JIT` could matter but it's not strictly required, and PAHOLE_VERSION is a build-time dependency related to BTF.

Alright, seems I've thoroughly analyzed this. Time to call `set-results`.



32/2 2026/09/23 19:46 tool set-results
0m Args:
{
  "EnableConfigs": [
    "BPF_SYSCALL",
    "DEBUG_INFO_BTF"
  ],
  "FocusSymbols": [
    "bpf_call_rcu",
    "bpf_call_rcu_tasks_trace",
    "bpf_rcu_run_callback",
    "__bpf_call_rcu",
    "set_rcu_callback_state"
  ],
  "Reasoning": "The patch series introduces BPF support for asynchronous RCU callbacks via `struct bpf_rcu_head` and kfuncs `bpf_call_rcu` and `bpf_call_rcu_tasks_trace`. This touches the BPF verifier, core BPF helpers, BTF parsing, and map subsystem. It executes in standard virtualized environments and handles asynchronous execution, reference counting, and RCU callbacks, making it well-suited for fuzzing.",
  "WorthFuzzing": true
}

Results:
{
  "EnableConfigs": [
    "BPF_SYSCALL",
    "DEBUG_INFO_BTF"
  ],
  "FocusSymbols": [
    "bpf_call_rcu",
    "bpf_call_rcu_tasks_trace",
    "bpf_rcu_run_callback",
    "__bpf_call_rcu",
    "set_rcu_callback_state"
  ],
  "Reasoning": "The patch series introduces BPF support for asynchronous RCU callbacks via `struct bpf_rcu_head` and kfuncs `bpf_call_rcu` and `bpf_call_rcu_tasks_trace`. This touches the BPF verifier, core BPF helpers, BTF parsing, and map subsystem. It executes in standard virtualized environments and handles asynchronous execution, reference counting, and RCU callbacks, making it well-suited for fuzzing.",
  "WorthFuzzing": true
}

33/1 2026/09/23 19:46 action If
4m Args:
{
  "WorthFuzzing": true
}

Results:
null

34/2 2026/09/23 19:46 agent kmsan-evaluator
4m Model:
core

Args:
null

Results:
{
  "KMSANReasoning": "The patch introduces the `bpf_call_rcu` and `bpf_call_rcu_tasks_trace` kfuncs along with the `bpf_rcu_head` BTF field type (restricted to array maps). \n\nAn analysis of uninitialized memory risks shows:\n1. All fields of `struct bpf_rcu_head_kern` (`callback_fn`, `map`, `prog`, `armed`) are explicitly set prior to arming via `call_rcu()` / `call_rcu_tasks_trace()`, and `call_rcu` initializes the embedded `struct rcu_head`.\n2. Array map elements are zero-allocated upon creation. If userspace reads the map value via `bpf_map_lookup_elem`, `check_and_init_map_value()` invokes `bpf_obj_init_field()`, which explicitly zeroes the `bpf_rcu_head` struct with `memset()`, preventing info-leaks to userspace.\n3. BPF programs are prohibited from directly reading or writing the `bpf_rcu_head` field by verifier rules in `check_map_access()`.\n4. In `bpf_rcu_run_callback()`, the key passed to the callback points to `idx`, which is directly initialized by `map_key_from_value()`.\n\nThe primary risks for this feature pertain to object lifetimes (BPF program and map lifetime vs pending RCU callbacks), race conditions / concurrency bugs around callback rearming, or RCU context/locking misuse. These risks are effectively covered by KASAN (use-after-free, double free) and LOCKDEP (RCU / lock validation), and do not involve uninitialized memory access. Therefore, a dedicated KMSAN session is not warranted.",
  "NeedsKMSAN": false
}

Instruction:
You are an expert Linux kernel security engineer specializing in kernel memory
error detectors (KASAN and KMSAN). Your job is to review the provided patch series and
determine if the code changes justify spawning a dedicated KMSAN (KernelMemorySanitizer)
fuzzing session in addition to standard KASAN fuzzing.

CRITICAL DISTINCTION BETWEEN KASAN AND KMSAN:
- Standard KASAN kernel builds (upstream-apparmor-kasan.config) already enable
  a comprehensive suite of debugging tools and sanitizers, including KASAN
  (out-of-bounds accesses, use-after-free, double free, invalid free), LOCKDEP
  (locking bugs and deadlocks), UB-sanitizers, and memory corruption checks.
- KMSAN (KernelMemorySanitizer) detects reads of UNINITIALIZED memory (stack, heap,
  or page allocations) and kernel-to-user memory info-leaks.

Rule: THERE IS NO SENSE IN RUNNING A KMSAN SESSION IF A BUG CAN BE CAUGHT BY KASAN,
LOCKDEP, OR OTHER STANDARD BUG DETECTORS.
A dedicated KMSAN fuzzing session incurs significant resource costs. You must ONLY
set NeedsKMSAN=true if the code changes introduce or expose UNINITIALIZED MEMORY risks
that are detected ONLY by KMSAN.

Look holistically at the patch series and surrounding code. Even if no direct
uninitialized field accesses or new buffer allocations are added in the diff itself,
a patch may alter control flow, bounds checking, or data length calculations in ways
that change how the rest of the code operates on existing buffers (e.g. allowing
uninitialized stack/heap memory to be read, copied to user space, or used in control
flow). Do not hesitate to use your code access tools to inspect the surrounding code,
called functions, and callers.

Set NeedsKMSAN=true ONLY IF the patch introduces or modifies:
1. Kernel structures sent to user space (via copy_to_user, put_user, netlink skb
   attributes, ioctl output arguments, socket options, or BPF buffers) where fields
   or structure padding might not be fully initialized/zeroed.
2. Conditional logic or branching that depends on potentially uninitialized variables
   or struct fields.
3. Allocation or initialization of complex data structures where uninitialized fields
   could be read later in reachable code paths.
4. Bounds checks, lengths, or logic in a way that allows surrounding code to access
   uninitialized bytes of existing buffers.

Set NeedsKMSAN=false IF:
- The code changes primarily risk out-of-bounds access, array overflows, NULL pointer
  dereferences, locking deadlocks, or use-after-free bugs (these are already caught
  by KASAN, LOCKDEP, or standard bug detectors).
- All stack/heap structures touched or introduced by the patch are fully zeroed
  or initialized (e.g. using = {0}, memset, kzalloc) before being read or copied.
- The patch does not introduce any risk of uninitialized memory usage or info-leaks.

Use your code access tools to inspect the surrounding code if necessary, then provide
detailed KMSANReasoning contrasting KASAN vs KMSAN applicability for this patch.
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:
Target architecture: amd64

For your convenience, here is the diff of the changes:
commit 53dabebe1086ff9808c18c85bd1d583e876072cc
Author: syz-cluster <triage@syzkaller.com>
Date:   Wed Sep 23 19:45:15 2026 +0000

    syz-cluster: applied patch under review

diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index fd22db8bc6c50..e7c5e203edddb 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -215,6 +215,7 @@ enum btf_field_type {
 	BPF_UPTR       = (1 << 11),
 	BPF_RES_SPIN_LOCK = (1 << 12),
 	BPF_TASK_WORK  = (1 << 13),
+	BPF_RCU_HEAD   = (1 << 14),
 };
 
 enum bpf_cgroup_storage_type {
@@ -269,6 +270,7 @@ struct btf_record {
 	int wq_off;
 	int refcount_off;
 	int task_work_off;
+	int rcu_head_off;
 	struct btf_field fields[];
 };
 
@@ -374,6 +376,8 @@ static inline const char *btf_field_type_name(enum btf_field_type type)
 		return "bpf_refcount";
 	case BPF_TASK_WORK:
 		return "bpf_task_work";
+	case BPF_RCU_HEAD:
+		return "bpf_rcu_head";
 	default:
 		WARN_ON_ONCE(1);
 		return "unknown";
@@ -414,6 +418,8 @@ static inline u32 btf_field_type_size(enum btf_field_type type)
 		return sizeof(struct bpf_refcount);
 	case BPF_TASK_WORK:
 		return sizeof(struct bpf_task_work);
+	case BPF_RCU_HEAD:
+		return sizeof(struct bpf_rcu_head);
 	default:
 		WARN_ON_ONCE(1);
 		return 0;
@@ -448,6 +454,8 @@ static inline u32 btf_field_type_align(enum btf_field_type type)
 		return __alignof__(struct bpf_refcount);
 	case BPF_TASK_WORK:
 		return __alignof__(struct bpf_task_work);
+	case BPF_RCU_HEAD:
+		return __alignof__(struct bpf_rcu_head);
 	default:
 		WARN_ON_ONCE(1);
 		return 0;
@@ -480,6 +488,7 @@ static inline void bpf_obj_init_field(const struct btf_field *field, void *addr)
 	case BPF_KPTR_PERCPU:
 	case BPF_UPTR:
 	case BPF_TASK_WORK:
+	case BPF_RCU_HEAD:
 		break;
 	default:
 		WARN_ON_ONCE(1);
@@ -925,6 +934,7 @@ enum bpf_arg_type {
 	ARG_PTR_TO_RB_NODE,	/* pointer to bpf_rb_node */
 	ARG_PTR_TO_WORKQUEUE,	/* pointer to bpf_wq */
 	ARG_PTR_TO_TASK_WORK,	/* pointer to bpf_task_work */
+	ARG_PTR_TO_RCU_HEAD,	/* pointer to bpf_rcu_head */
 	ARG_PTR_TO_IRQ_FLAG,	/* pointer to saved IRQ flags on the stack */
 	ARG_PTR_TO_RES_SPIN_LOCK,	/* pointer to bpf_res_spin_lock */
 	ARG_PTR_TO_CTX_OUT,	/* hook output argument passed through from ctx */
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index 6330b7d745c57..eafeba23f5da7 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -7611,6 +7611,10 @@ struct bpf_task_work {
 	__u64 __opaque;
 } __attribute__((aligned(8)));
 
+struct bpf_rcu_head {
+	__u64 __opaque[8];
+} __attribute__((aligned(8)));
+
 struct bpf_wq {
 	__u64 __opaque[2];
 } __attribute__((aligned(8)));
diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
index 314ecb0e593b0..4a1fa4fbdf4e8 100644
--- a/kernel/bpf/btf.c
+++ b/kernel/bpf/btf.c
@@ -3696,6 +3696,7 @@ static int btf_get_field_type(const struct btf *btf, const struct btf_type *var_
 		{ BPF_TIMER, "bpf_timer", true },
 		{ BPF_WORKQUEUE, "bpf_wq", true },
 		{ BPF_TASK_WORK, "bpf_task_work", true },
+		{ BPF_RCU_HEAD, "bpf_rcu_head", true },
 		{ BPF_LIST_HEAD, "bpf_list_head", false },
 		{ BPF_LIST_NODE, "bpf_list_node", false },
 		{ BPF_RB_ROOT, "bpf_rb_root", false },
@@ -3881,6 +3882,7 @@ static int btf_find_field_one(const struct btf *btf,
 	case BPF_RB_NODE:
 	case BPF_REFCOUNT:
 	case BPF_TASK_WORK:
+	case BPF_RCU_HEAD:
 		ret = btf_find_struct(btf, var_type, off, sz, field_type,
 				      info_cnt ? &info[0] : &tmp);
 		if (ret < 0)
@@ -4176,6 +4178,7 @@ struct btf_record *btf_parse_fields(const struct btf *btf, const struct btf_type
 	rec->wq_off = -EINVAL;
 	rec->refcount_off = -EINVAL;
 	rec->task_work_off = -EINVAL;
+	rec->rcu_head_off = -EINVAL;
 	for (i = 0; i < cnt; i++) {
 		field_type_size = btf_field_type_size(info_arr[i].type);
 		if (info_arr[i].off + field_type_size > value_size) {
@@ -4219,6 +4222,10 @@ struct btf_record *btf_parse_fields(const struct btf *btf, const struct btf_type
 			WARN_ON_ONCE(rec->task_work_off >= 0);
 			rec->task_work_off = rec->fields[i].offset;
 			break;
+		case BPF_RCU_HEAD:
+			WARN_ON_ONCE(rec->rcu_head_off >= 0);
+			rec->rcu_head_off = rec->fields[i].offset;
+			break;
 		case BPF_REFCOUNT:
 			WARN_ON_ONCE(rec->refcount_off >= 0);
 			/* Cache offset for faster lookup at runtime */
diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c
index 501c7ce35cba9..301b35bd85c8a 100644
--- a/kernel/bpf/helpers.c
+++ b/kernel/bpf/helpers.c
@@ -4805,6 +4805,106 @@ __bpf_kfunc int bpf_task_work_schedule_resume(struct task_struct *task, struct b
 	return bpf_task_work_schedule(task, tw, map__const_map, callback, aux, TWA_RESUME);
 }
 
+typedef int (*bpf_rcu_callback_t)(struct bpf_map *map, void *key, void *value);
+
+/* Actual type for struct bpf_rcu_head */
+struct bpf_rcu_head_kern {
+	struct rcu_head rcu;
+	bpf_callback_t callback_fn;
+	struct bpf_map *map;
+	struct bpf_prog *prog;
+	u32 armed;
+} __aligned(8);
+
+static void bpf_rcu_run_callback(struct rcu_head *rcu)
+{
+	struct bpf_rcu_head_kern *rh = container_of(rcu, struct bpf_rcu_head_kern, rcu);
+	bpf_callback_t callback_fn = rh->callback_fn;
+	struct bpf_prog *prog = rh->prog;
+	struct bpf_map *map = rh->map;
+	void *value, *key;
+	u32 idx;
+
+	value = (void *)rh - map->record->rcu_head_off;
+	key = map_key_from_value(map, value, &idx);
+
+	/* Pairs with the arming cmpxchg(): rh may be re-armed as soon as this store lands. */
+	smp_store_release(&rh->armed, 0);
+
+	rcu_read_lock_dont_migrate();
+	callback_fn((u64)(long)map, (u64)(long)key, (u64)(long)value, 0, 0);
+	rcu_read_unlock_migrate();
+
+	bpf_prog_put(prog);
+}
+
+static int __bpf_call_rcu(struct bpf_rcu_head *rh, struct bpf_map *map, void *callback,
+			  struct bpf_prog_aux *aux, bool trace)
+{
+	struct bpf_rcu_head_kern *rhk = (void *)rh;
+	struct bpf_prog *prog;
+
+	BUILD_BUG_ON(sizeof(struct bpf_rcu_head_kern) > sizeof(struct bpf_rcu_head));
+	BUILD_BUG_ON(__alignof__(struct bpf_rcu_head_kern) != __alignof__(struct bpf_rcu_head));
+	BTF_TYPE_EMIT(struct bpf_rcu_head);
+
+	/* A queued callback cannot be cancelled, so a self-rearming one would pin prog and map. */
+	if (!atomic64_read(&map->usercnt))
+		return -EPERM;
+
+	if (cmpxchg(&rhk->armed, 0, 1))
+		return -EBUSY;
+
+	prog = bpf_prog_inc_not_zero(aux->prog);
+	if (IS_ERR(prog)) {
+		WRITE_ONCE(rhk->armed, 0);
+		return -EBADF;
+	}
+
+	rhk->callback_fn = (bpf_callback_t)callback;
+	rhk->map = map;
+	rhk->prog = prog;
+	if (trace)
+		call_rcu_tasks_trace(&rhk->rcu, bpf_rcu_run_callback);
+	else
+		call_rcu(&rhk->rcu, bpf_rcu_run_callback);
+	return 0;
+}
+
+/**
+ * bpf_call_rcu - Invoke a BPF callback after an RCU grace period
+ * @rh: struct bpf_rcu_head in a BPF map value
+ * @map__const_map: bpf_map that embeds struct bpf_rcu_head in the values
+ * @callback: BPF subprogram, invoked as callback(map, key, value) for the value holding @rh
+ * @aux: bpf_prog_aux of the caller, implicitly set by the verifier
+ *
+ * Return: 0, -EBUSY if @rh is already queued, -EPERM if @map is held by neither a process
+ * nor bpffs, or -EBADF if the calling program is going away.
+ */
+__bpf_kfunc int bpf_call_rcu(struct bpf_rcu_head *rh, void *map__const_map,
+			     bpf_rcu_callback_t callback, struct bpf_prog_aux *aux)
+{
+	return __bpf_call_rcu(rh, map__const_map, callback, aux, false);
+}
+
+/**
+ * bpf_call_rcu_tasks_trace - Invoke a BPF callback after an RCU tasks trace grace period
+ * @rh: struct bpf_rcu_head in a BPF map value
+ * @map__const_map: bpf_map that embeds struct bpf_rcu_head in the values
+ * @callback: BPF subprogram, invoked as callback(map, key, value) for the value holding @rh
+ * @aux: bpf_prog_aux of the caller, implicitly set by the verifier
+ *
+ * Waits for sleepable BPF programs too.  The callback itself is not sleepable either way.
+ *
+ * Return: 0, -EBUSY if @rh is already queued, -EPERM if @map is held by neither a process
+ * nor bpffs, or -EBADF if the calling program is going away.
+ */
+__bpf_kfunc int bpf_call_rcu_tasks_trace(struct bpf_rcu_head *rh, void *map__const_map,
+					 bpf_rcu_callback_t callback, struct bpf_prog_aux *aux)
+{
+	return __bpf_call_rcu(rh, map__const_map, callback, aux, true);
+}
+
 static int make_file_dynptr(struct file *file, u32 flags, bool may_sleep,
 			    struct bpf_dynptr_kern *ptr)
 {
@@ -5100,6 +5200,8 @@ BTF_ID_FLAGS(func, bpf_stream_vprintk, KF_IMPLICIT_ARGS | KF_SPINLOCK_SAFE)
 BTF_ID_FLAGS(func, bpf_stream_print_stack, KF_IMPLICIT_ARGS | KF_SPINLOCK_SAFE)
 BTF_ID_FLAGS(func, bpf_task_work_schedule_signal, KF_IMPLICIT_ARGS)
 BTF_ID_FLAGS(func, bpf_task_work_schedule_resume, KF_IMPLICIT_ARGS)
+BTF_ID_FLAGS(func, bpf_call_rcu, KF_IMPLICIT_ARGS)
+BTF_ID_FLAGS(func, bpf_call_rcu_tasks_trace, KF_IMPLICIT_ARGS)
 BTF_ID_FLAGS(func, bpf_dynptr_from_file)
 BTF_ID_FLAGS(func, bpf_dynptr_file_discard, KF_RELEASE)
 BTF_ID_FLAGS(func, bpf_timer_cancel_async)
diff --git a/kernel/bpf/map_in_map.c b/kernel/bpf/map_in_map.c
index d2cbab4bdf644..5ee8aae7435ba 100644
--- a/kernel/bpf/map_in_map.c
+++ b/kernel/bpf/map_in_map.c
@@ -25,6 +25,10 @@ struct bpf_map *bpf_map_meta_alloc(int inner_map_ufd)
 	if (!inner_map->ops->map_meta_equal)
 		return ERR_PTR(-ENOTSUPP);
 
+	/* An inner map has no used_maps reference to hold it under a queued callback. */
+	if (btf_record_has_field(inner_map->record, BPF_RCU_HEAD))
+		return ERR_PTR(-EOPNOTSUPP);
+
 	inner_map_meta_size = sizeof(*inner_map_meta);
 	/* In some cases verifier needs to access beyond just base map. */
 	if (inner_map->ops == &array_map_ops || inner_map->ops == &percpu_array_map_ops)
diff --git a/kernel/bpf/map_iter.c b/kernel/bpf/map_iter.c
index c19b360bad9ea..2077d46d167c7 100644
--- a/kernel/bpf/map_iter.c
+++ b/kernel/bpf/map_iter.c
@@ -117,6 +117,12 @@ static int bpf_iter_attach_map(struct bpf_prog *prog,
 		goto put_map;
 	}
 
+	/* The value ctx arg is writable and aliases the live element. */
+	if (btf_record_has_field(map->record, BPF_RCU_HEAD)) {
+		err = -EOPNOTSUPP;
+		goto put_map;
+	}
+
 	if (map->map_type == BPF_MAP_TYPE_PERCPU_HASH ||
 	    map->map_type == BPF_MAP_TYPE_LRU_PERCPU_HASH ||
 	    map->map_type == BPF_MAP_TYPE_PERCPU_ARRAY)
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 113486b15d29f..74496fd716d3b 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -687,6 +687,7 @@ void btf_record_free(struct btf_record *rec)
 		case BPF_REFCOUNT:
 		case BPF_WORKQUEUE:
 		case BPF_TASK_WORK:
+		case BPF_RCU_HEAD:
 			/* Nothing to release */
 			break;
 		default:
@@ -741,6 +742,7 @@ struct btf_record *btf_record_dup(const struct btf_record *rec)
 		case BPF_REFCOUNT:
 		case BPF_WORKQUEUE:
 		case BPF_TASK_WORK:
+		case BPF_RCU_HEAD:
 			/* Nothing to acquire */
 			break;
 		default:
@@ -874,6 +876,7 @@ void bpf_obj_free_fields(const struct btf_record *rec, void *obj)
 		case BPF_LIST_NODE:
 		case BPF_RB_NODE:
 		case BPF_REFCOUNT:
+		case BPF_RCU_HEAD:
 			break;
 		default:
 			WARN_ON_ONCE(1);
@@ -1280,7 +1283,7 @@ static int map_check_btf(struct bpf_map *map, struct bpf_token *token,
 	map->record = btf_parse_fields(btf, value_type,
 				       BPF_SPIN_LOCK | BPF_RES_SPIN_LOCK | BPF_TIMER | BPF_KPTR | BPF_LIST_HEAD |
 				       BPF_RB_ROOT | BPF_REFCOUNT | BPF_WORKQUEUE | BPF_UPTR |
-				       BPF_TASK_WORK,
+				       BPF_TASK_WORK | BPF_RCU_HEAD,
 				       map->value_size);
 	if (!IS_ERR_OR_NULL(map->record)) {
 		int i;
@@ -1322,6 +1325,12 @@ static int map_check_btf(struct bpf_map *map, struct bpf_token *token,
 					goto free_map_tab;
 				}
 				break;
+			case BPF_RCU_HEAD:
+				if (map->map_type != BPF_MAP_TYPE_ARRAY) {
+					ret = -EOPNOTSUPP;
+					goto free_map_tab;
+				}
+				break;
 			case BPF_KPTR_UNREF:
 			case BPF_KPTR_REF:
 			case BPF_KPTR_PERCPU:
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index d62c0f74cff5e..a7c9e2d8965d5 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -535,6 +535,7 @@ static bool is_ptr_cast_function(enum bpf_func_id func_id)
 
 static bool is_sync_callback_calling_kfunc(u32 btf_id);
 static bool is_async_callback_calling_kfunc(u32 btf_id);
+static bool is_call_rcu_kfunc(u32 btf_id);
 static bool is_callback_calling_kfunc(u32 btf_id);
 
 static bool is_bpf_wq_set_callback_kfunc(u32 btf_id);
@@ -577,6 +578,10 @@ static bool is_async_cb_sleepable(struct bpf_verifier_env *env, struct bpf_insn
 	if (bpf_helper_call(insn) && insn->imm == BPF_FUNC_timer_set_callback)
 		return false;
 
+	/* bpf_call_rcu and bpf_call_rcu_tasks_trace callbacks are never sleepable. */
+	if (bpf_pseudo_kfunc_call(insn) && insn->off == 0 && is_call_rcu_kfunc(insn->imm))
+		return false;
+
 	/* bpf_wq and bpf_task_work callbacks are always sleepable. */
 	if (bpf_pseudo_kfunc_call(insn) && insn->off == 0 &&
 	    (is_bpf_wq_set_callback_kfunc(insn->imm) || is_task_work_add_kfunc(insn->imm)))
@@ -7590,6 +7595,9 @@ static int check_map_field_pointer(struct bpf_verifier_env *env, struct bpf_reg_
 	case BPF_TASK_WORK:
 		field_off = map->record->task_work_off;
 		break;
+	case BPF_RCU_HEAD:
+		field_off = map->record->rcu_head_off;
+		break;
 	case BPF_WORKQUEUE:
 		field_off = map->record->wq_off;
 		break;
@@ -8448,6 +8456,7 @@ static const struct bpf_reg_types *compatible_reg_types[__BPF_ARG_TYPE_MAX] = {
 	[ARG_PTR_TO_RES_SPIN_LOCK]	= &map_value_or_alloc_obj_types,
 	[ARG_PTR_TO_WORKQUEUE]		= &map_value_types,
 	[ARG_PTR_TO_TASK_WORK]		= &map_value_types,
+	[ARG_PTR_TO_RCU_HEAD]		= &map_value_types,
 	[ARG_PTR_TO_IRQ_FLAG]		= &stack_ptr_types,
 	[ARG_PTR_TO_ARENA]		= &arena_types,
 	[ARG_PTR_TO_CTX_OUT]		= &ctx_out_types,
@@ -8894,6 +8903,8 @@ static int process_map_ptr_arg(struct bpf_verifier_env *env, struct bpf_reg_stat
 			obj_name = "timer";
 		else if (rec->task_work_off >= 0)
 			obj_name = "bpf_task_work";
+		else if (rec->rcu_head_off >= 0)
+			obj_name = "bpf_rcu_head";
 
 		verbose(env, "%s pointer in %s map_uid=%d ",
 			obj_name, reg_arg_name(env, obj_argno), meta->map.uid);
@@ -9442,6 +9453,11 @@ static int check_func_arg(struct bpf_verifier_env *env, u32 arg, u32 slot, u32 p
 		if (err < 0)
 			return err;
 		break;
+	case ARG_PTR_TO_RCU_HEAD:
+		err = check_map_field_pointer(env, reg, argno, BPF_RCU_HEAD, &meta->map);
+		if (err < 0)
+			return err;
+		break;
 	case ARG_PTR_TO_IRQ_FLAG:
 		err = process_irq_flag(env, reg, argno, meta);
 		if (err < 0)
@@ -10955,6 +10971,40 @@ static int set_task_work_schedule_callback_state(struct bpf_verifier_env *env,
 	return 0;
 }
 
+static int set_rcu_callback_state(struct bpf_verifier_env *env,
+				  struct bpf_func_state *caller,
+				  struct bpf_func_state *callee,
+				  int insn_idx)
+{
+	struct bpf_map *map_ptr = caller->regs[BPF_REG_2].map_ptr;
+	u32 map_uid = caller->regs[BPF_REG_2].map_uid;
+
+	/*
+	 * callback_fn(struct bpf_map *map, void *key, void *value);
+	 */
+	callee->regs[BPF_REG_1].type = CONST_PTR_TO_MAP;
+	__mark_reg_known_zero(&callee->regs[BPF_REG_1]);
+	callee->regs[BPF_REG_1].map_ptr = map_ptr;
+	callee->regs[BPF_REG_1].map_uid = map_uid;
+
+	callee->regs[BPF_REG_2].type = PTR_TO_MAP_KEY;
+	__mark_reg_known_zero(&callee->regs[BPF_REG_2]);
+	callee->regs[BPF_REG_2].map_ptr = map_ptr;
+	callee->regs[BPF_REG_2].map_uid = map_uid;
+
+	callee->regs[BPF_REG_3].type = PTR_TO_MAP_VALUE;
+	__mark_reg_known_zero(&callee->regs[BPF_REG_3]);
+	callee->regs[BPF_REG_3].map_ptr = map_ptr;
+	callee->regs[BPF_REG_3].map_uid = map_uid;
+
+	/* unused */
+	bpf_mark_reg_not_init(env, &callee->regs[BPF_REG_4]);
+	bpf_mark_reg_not_init(env, &callee->regs[BPF_REG_5]);
+	callee->in_async_callback_fn = true;
+	callee->callback_ret_range = retval_range(S32_MIN, S32_MAX);
+	return 0;
+}
+
 static bool is_rbtree_lock_required_kfunc(u32 btf_id);
 
 static void account_processed_insn(struct bpf_verifier_env *env)
@@ -12216,7 +12266,8 @@ enum {
 	KF_ARG_RES_SPIN_LOCK_ID,
 	KF_ARG_TASK_WORK_ID,
 	KF_ARG_PROG_AUX_ID,
-	KF_ARG_TIMER_ID
+	KF_ARG_TIMER_ID,
+	KF_ARG_RCU_HEAD_ID
 };
 
 BTF_ID_LIST(kf_arg_btf_ids)
@@ -12230,6 +12281,7 @@ BTF_ID(struct, bpf_res_spin_lock)
 BTF_ID(struct, bpf_task_work)
 BTF_ID(struct, bpf_prog_aux)
 BTF_ID(struct, bpf_timer)
+BTF_ID(struct, bpf_rcu_head)
 
 static bool __is_kfunc_ptr_arg_type(const struct btf *btf,
 				    const struct btf_param *arg, int type)
@@ -12288,6 +12340,11 @@ static bool is_kfunc_arg_task_work(const struct btf *btf, const struct btf_param
 	return __is_kfunc_ptr_arg_type(btf, arg, KF_ARG_TASK_WORK_ID);
 }
 
+static bool is_kfunc_arg_rcu_head(const struct btf *btf, const struct btf_param *arg)
+{
+	return __is_kfunc_ptr_arg_type(btf, arg, KF_ARG_RCU_HEAD_ID);
+}
+
 static bool is_kfunc_arg_res_spin_lock(const struct btf *btf, const struct btf_param *arg)
 {
 	return __is_kfunc_ptr_arg_type(btf, arg, KF_ARG_RES_SPIN_LOCK_ID);
@@ -12571,6 +12628,8 @@ enum special_kfunc_type {
 	KF___bpf_trap,
 	KF_bpf_task_work_schedule_signal,
 	KF_bpf_task_work_schedule_resume,
+	KF_bpf_call_rcu,
+	KF_bpf_call_rcu_tasks_trace,
 	KF_bpf_arena_alloc_pages,
 	KF_bpf_arena_free_pages,
 	KF_bpf_arena_reserve_pages,
@@ -12664,6 +12723,8 @@ BTF_ID(func, bpf_dynptr_file_discard)
 BTF_ID(func, __bpf_trap)
 BTF_ID(func, bpf_task_work_schedule_signal)
 BTF_ID(func, bpf_task_work_schedule_resume)
+BTF_ID(func, bpf_call_rcu)
+BTF_ID(func, bpf_call_rcu_tasks_trace)
 BTF_ID(func, bpf_arena_alloc_pages)
 BTF_ID(func, bpf_arena_free_pages)
 BTF_ID(func, bpf_arena_reserve_pages)
@@ -12735,6 +12796,12 @@ static bool is_bpf_rbtree_add_kfunc(u32 func_id)
 	       func_id == special_kfunc_list[KF_bpf_rbtree_add_impl];
 }
 
+static bool is_call_rcu_kfunc(u32 func_id)
+{
+	return func_id == special_kfunc_list[KF_bpf_call_rcu] ||
+	       func_id == special_kfunc_list[KF_bpf_call_rcu_tasks_trace];
+}
+
 static bool is_task_work_add_kfunc(u32 func_id)
 {
 	return func_id == special_kfunc_list[KF_bpf_task_work_schedule_signal] ||
@@ -12941,6 +13008,8 @@ get_kfunc_arg_type(struct bpf_verifier_env *env, struct bpf_call_arg_meta *meta,
 		arg_type = ARG_PTR_TO_TIMER;
 	else if (is_kfunc_arg_task_work(meta->btf, &args[arg]))
 		arg_type = ARG_PTR_TO_TASK_WORK;
+	else if (is_kfunc_arg_rcu_head(meta->btf, &args[arg]))
+		arg_type = ARG_PTR_TO_RCU_HEAD;
 	else if (is_kfunc_arg_irq_flag(meta->btf, &args[arg]))
 		arg_type = ARG_PTR_TO_IRQ_FLAG;
 	else if (is_kfunc_arg_res_spin_lock(meta->btf, &args[arg]))
@@ -13442,7 +13511,8 @@ static bool is_sync_callback_calling_kfunc(u32 btf_id)
 static bool is_async_callback_calling_kfunc(u32 btf_id)
 {
 	return is_bpf_wq_set_callback_kfunc(btf_id) ||
-	       is_task_work_add_kfunc(btf_id);
+	       is_task_work_add_kfunc(btf_id) ||
+	       is_call_rcu_kfunc(btf_id);
 }
 
 bool bpf_is_throw_kfunc(struct bpf_insn *insn)
@@ -14259,6 +14329,16 @@ static int check_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn,
 		}
 	}
 
+	if (is_call_rcu_kfunc(meta.func_id)) {
+		err = push_callback_call(env, insn, insn_idx, meta.subprogno,
+					 set_rcu_callback_state);
+		if (err) {
+			verbose(env, "kfunc %s#%d failed callback verification\n",
+				func_name, meta.func_id);
+			return err;
+		}
+	}
+
 	rcu_lock = is_kfunc_bpf_rcu_read_lock(&meta);
 	rcu_unlock = is_kfunc_bpf_rcu_read_unlock(&meta);
 
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index 6330b7d745c57..eafeba23f5da7 100644
--- a/tools/include/uapi/linux/bpf.h
+++ b/tools/include/uapi/linux/bpf.h
@@ -7611,6 +7611,10 @@ struct bpf_task_work {
 	__u64 __opaque;
 } __attribute__((aligned(8)));
 
+struct bpf_rcu_head {
+	__u64 __opaque[8];
+} __attribute__((aligned(8)));
+
 struct bpf_wq {
 	__u64 __opaque[2];
 } __attribute__((aligned(8)));
diff --git a/tools/testing/selftests/bpf/prog_tests/call_rcu.c b/tools/testing/selftests/bpf/prog_tests/call_rcu.c
new file mode 100644
index 0000000000000..e4d271d43d878
--- /dev/null
+++ b/tools/testing/selftests/bpf/prog_tests/call_rcu.c
@@ -0,0 +1,275 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (c) 2026 Meta Platforms, Inc. and affiliates. */
+#include <test_progs.h>
+#include "call_rcu.skel.h"
+#include "call_rcu_fail.skel.h"
+
+struct elem {
+	__u64 pad;
+	struct bpf_rcu_head rh;
+	__u64 val;
+};
+
+/*
+ * Force the grace period, then poll: the callback still has to be invoked
+ * afterwards, and call_rcu() is lazy on a CONFIG_RCU_LAZY kernel.
+ */
+static bool wait_for_callbacks(struct call_rcu *skel, int expected)
+{
+	int i, got = 0;
+
+	kern_sync_rcu();
+	for (i = 0; i < 3000; i++) {
+		got = __atomic_load_n(&skel->bss->callbacks, __ATOMIC_ACQUIRE);
+		if (got >= expected)
+			return true;
+		usleep(10000);
+	}
+	return ASSERT_GE(got, expected, "callbacks");
+}
+
+static void test_call_rcu_run(bool trace)
+{
+	LIBBPF_OPTS(bpf_test_run_opts, opts);
+	struct bpf_program *prog;
+	struct call_rcu *skel;
+	struct elem elem;
+	__u32 key = 1;
+	int err;
+
+	skel = call_rcu__open_and_load();
+	if (!ASSERT_OK_PTR(skel, "skel_open_and_load"))
+		return;
+
+	prog = trace ? skel->progs.arm_trace : skel->progs.arm;
+	err = bpf_prog_test_run_opts(bpf_program__fd(prog), &opts);
+	if (!ASSERT_OK(err, "test_run") || !ASSERT_EQ(opts.retval, 0, "retval"))
+		goto out;
+
+	ASSERT_EQ(skel->bss->arm_err, 0, "arm_err");
+	ASSERT_EQ(skel->bss->busy_err, -EBUSY, "busy_err");
+
+	if (!wait_for_callbacks(skel, 1))
+		goto out;
+
+	ASSERT_EQ(skel->bss->cb_key, key, "cb_key");
+	ASSERT_EQ(skel->bss->cb_val, 0xdeadbeef, "cb_val");
+	ASSERT_EQ(skel->bss->cb_max_entries, bpf_map__max_entries(skel->maps.arr), "cb_map");
+
+	err = bpf_map__lookup_elem(skel->maps.arr, &key, sizeof(key), &elem, sizeof(elem), 0);
+	if (ASSERT_OK(err, "lookup"))
+		ASSERT_EQ(elem.val, 0, "value_cleared");
+
+	/* The head is disarmed before the callback runs, so it can be reused. */
+	err = bpf_prog_test_run_opts(bpf_program__fd(prog), &opts);
+	if (!ASSERT_OK(err, "test_run_again"))
+		goto out;
+	ASSERT_EQ(skel->bss->arm_err, 0, "rearm_err");
+	wait_for_callbacks(skel, 2);
+out:
+	call_rcu__destroy(skel);
+}
+
+static void test_call_rcu_chain(void)
+{
+	LIBBPF_OPTS(bpf_test_run_opts, opts);
+	struct call_rcu *skel;
+
+	skel = call_rcu__open_and_load();
+	if (!ASSERT_OK_PTR(skel, "skel_open_and_load"))
+		return;
+
+	skel->bss->chain = 1;
+	if (!ASSERT_OK(bpf_prog_test_run_opts(bpf_program__fd(skel->progs.arm), &opts), "test_run"))
+		goto out;
+
+	if (!wait_for_callbacks(skel, 1))
+		goto out;
+	ASSERT_EQ(skel->bss->chain_err, 0, "chain_err");
+	wait_for_callbacks(skel, 2);
+out:
+	call_rcu__destroy(skel);
+}
+
+/*
+ * A callback that keeps re-arming must stop once the map loses its last user
+ * reference, or it pins the program for good.  Hold an independent fd on .bss
+ * so the refusal is still readable after the skeleton is gone.
+ */
+static void test_call_rcu_teardown(void)
+{
+	LIBBPF_OPTS(bpf_test_run_opts, opts);
+	int i, err, fd = 0, bss_fd = -1;
+	struct bpf_prog_info pinfo = {};
+	struct bpf_map_info minfo = {};
+	__u32 len, prog_id, zero = 0;
+	struct call_rcu *skel;
+	char *buf = NULL;
+	size_t off, vsz;
+
+	skel = call_rcu__open_and_load();
+	if (!ASSERT_OK_PTR(skel, "skel_open_and_load"))
+		return;
+
+	len = sizeof(pinfo);
+	if (!ASSERT_OK(bpf_prog_get_info_by_fd(bpf_program__fd(skel->progs.arm), &pinfo, &len),
+		       "prog_info"))
+		goto out;
+	prog_id = pinfo.id;
+
+	len = sizeof(minfo);
+	if (!ASSERT_OK(bpf_map_get_info_by_fd(bpf_map__fd(skel->maps.bss), &minfo, &len),
+		       "bss_info"))
+		goto out;
+	bss_fd = bpf_map_get_fd_by_id(minfo.id);
+	if (!ASSERT_GE(bss_fd, 0, "bss_fd"))
+		goto out;
+
+	vsz = bpf_map__value_size(skel->maps.bss);
+	off = (char *)&skel->bss->chain_err - (char *)skel->bss;
+	buf = malloc(vsz);
+	if (!ASSERT_OK_PTR(buf, "buf"))
+		goto out;
+
+	skel->bss->chain = INT_MAX;
+	err = bpf_prog_test_run_opts(bpf_program__fd(skel->progs.arm), &opts);
+	if (!ASSERT_OK(err, "test_run") || !ASSERT_EQ(opts.retval, 0, "retval"))
+		goto out;
+	if (!ASSERT_EQ(skel->bss->arm_err, 0, "arm_err"))
+		goto out;
+	/* The chain has to be running before the map reference goes away. */
+	if (!wait_for_callbacks(skel, 2))
+		goto out;
+
+	call_rcu__destroy(skel);
+	skel = NULL;
+
+	for (i = 0; i < 3000; i++) {
+		fd = bpf_prog_get_fd_by_id(prog_id);
+		if (fd < 0)
+			break;
+		close(fd);
+		usleep(10000);
+	}
+	if (!ASSERT_EQ(fd, -ENOENT, "prog_freed"))
+		goto out;
+
+	if (ASSERT_OK(bpf_map_lookup_elem(bss_fd, &zero, buf), "bss_lookup"))
+		ASSERT_EQ(*(int *)(buf + off), -EPERM, "chain_refused");
+out:
+	free(buf);
+	if (bss_fd >= 0)
+		close(bss_fd);
+	call_rcu__destroy(skel);
+}
+
+static void test_call_rcu_bad_map(void)
+{
+	LIBBPF_OPTS(bpf_map_create_opts, opts);
+	struct call_rcu *skel;
+	int fd;
+
+	skel = call_rcu__open_and_load();
+	if (!ASSERT_OK_PTR(skel, "skel_open_and_load"))
+		return;
+
+	opts.btf_fd = bpf_object__btf_fd(skel->obj);
+	opts.btf_key_type_id = bpf_map__btf_key_type_id(skel->maps.arr);
+	opts.btf_value_type_id = bpf_map__btf_value_type_id(skel->maps.arr);
+
+	fd = bpf_map_create(BPF_MAP_TYPE_HASH, "rcu_hash", sizeof(__u32),
+			    bpf_map__value_size(skel->maps.arr), 1, &opts);
+	ASSERT_EQ(fd, -EOPNOTSUPP, "hash_rejected");
+	if (fd >= 0)
+		close(fd);
+
+	call_rcu__destroy(skel);
+}
+
+/* Iterating would hand the program a writable pointer to the head. */
+static void test_call_rcu_iter(void)
+{
+	LIBBPF_OPTS(bpf_iter_attach_opts, opts);
+	union bpf_iter_link_info linfo = {};
+	struct bpf_link *link;
+	struct call_rcu *skel;
+
+	skel = call_rcu__open_and_load();
+	if (!ASSERT_OK_PTR(skel, "skel_open_and_load"))
+		return;
+
+	linfo.map.map_fd = bpf_map__fd(skel->maps.arr);
+	opts.link_info = &linfo;
+	opts.link_info_len = sizeof(linfo);
+
+	link = bpf_program__attach_iter(skel->progs.dump, &opts);
+	if (!ASSERT_ERR_PTR(link, "iter_rejected"))
+		bpf_link__destroy(link);
+	else
+		ASSERT_EQ(libbpf_get_error(link), -EOPNOTSUPP, "iter_errno");
+
+	call_rcu__destroy(skel);
+}
+
+static void test_call_rcu_inner_map(void)
+{
+	LIBBPF_OPTS(bpf_map_create_opts, opts);
+	struct call_rcu *skel;
+	int fd;
+
+	skel = call_rcu__open_and_load();
+	if (!ASSERT_OK_PTR(skel, "skel_open_and_load"))
+		return;
+
+	opts.inner_map_fd = bpf_map__fd(skel->maps.arr);
+	fd = bpf_map_create(BPF_MAP_TYPE_ARRAY_OF_MAPS, "rcu_outer",
+			    sizeof(__u32), sizeof(__u32), 1, &opts);
+	ASSERT_EQ(fd, -EOPNOTSUPP, "inner_map_rejected");
+	if (fd >= 0)
+		close(fd);
+
+	call_rcu__destroy(skel);
+}
+
+/* Two heads in the same map must be independent. */
+static void test_call_rcu_two_heads(void)
+{
+	LIBBPF_OPTS(bpf_test_run_opts, opts);
+	struct call_rcu *skel;
+
+	skel = call_rcu__open_and_load();
+	if (!ASSERT_OK_PTR(skel, "skel_open_and_load"))
+		return;
+
+	if (!ASSERT_OK(bpf_prog_test_run_opts(bpf_program__fd(skel->progs.arm_both), &opts),
+		       "test_run"))
+		goto out;
+	if (!ASSERT_EQ(skel->bss->arm_err, 0, "arm_err"))
+		goto out;
+	if (!wait_for_callbacks(skel, 2))
+		goto out;
+	ASSERT_EQ(skel->bss->cb_keys, 0x3, "both_keys");
+out:
+	call_rcu__destroy(skel);
+}
+
+void test_call_rcu(void)
+{
+	if (test__start_subtest("run"))
+		test_call_rcu_run(false);
+	if (test__start_subtest("run_tasks_trace"))
+		test_call_rcu_run(true);
+	if (test__start_subtest("chain"))
+		test_call_rcu_chain();
+	if (test__start_subtest("two_heads"))
+		test_call_rcu_two_heads();
+	if (test__start_subtest("teardown"))
+		test_call_rcu_teardown();
+	if (test__start_subtest("bad_map"))
+		test_call_rcu_bad_map();
+	if (test__start_subtest("iter"))
+		test_call_rcu_iter();
+	if (test__start_subtest("inner_map"))
+		test_call_rcu_inner_map();
+	RUN_TESTS(call_rcu_fail);
+}
diff --git a/tools/testing/selftests/bpf/progs/call_rcu.c b/tools/testing/selftests/bpf/progs/call_rcu.c
new file mode 100644
index 0000000000000..505008647fd6f
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/call_rcu.c
@@ -0,0 +1,110 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (c) 2026 Meta Platforms, Inc. and affiliates. */
+
+#include <vmlinux.h>
+#include <bpf/bpf_helpers.h>
+
+char _license[] SEC("license") = "GPL";
+
+/* rh is not at offset 0, so the callback's value recovery is exercised. */
+struct elem {
+	__u64 pad;
+	struct bpf_rcu_head rh;
+	__u64 val;
+};
+
+struct {
+	__uint(type, BPF_MAP_TYPE_ARRAY);
+	__uint(max_entries, 2);
+	__type(key, __u32);
+	__type(value, struct elem);
+} arr SEC(".maps");
+
+__u32 cb_key;
+__u64 cb_keys;
+__u64 cb_val;
+__u32 cb_max_entries;
+int callbacks;
+int arm_err;
+int busy_err;
+int chain;		/* set by userspace: number of times to re-arm from the callback */
+int chain_err;
+
+static int reclaim(struct bpf_map *map, void *key, void *value)
+{
+	struct elem *e = value;
+
+	cb_key = *(__u32 *)key;
+	__sync_fetch_and_or(&cb_keys, 1ULL << cb_key);
+	cb_val = e->val;
+	cb_max_entries = map->max_entries;
+	e->val = 0;
+
+	if (chain > 0) {
+		chain--;
+		chain_err = bpf_call_rcu(&e->rh, &arr, reclaim);
+	}
+
+	__sync_fetch_and_add(&callbacks, 1);
+	return 0;
+}
+
+SEC("syscall")
+int arm(void *ctx)
+{
+	__u32 key = 1;
+	struct elem *e;
+
+	e = bpf_map_lookup_elem(&arr, &key);
+	if (!e)
+		return 1;
+
+	e->val = 0xdeadbeef;
+	/* Keep a grace period from elapsing between the two arms. */
+	bpf_rcu_read_lock();
+	arm_err = bpf_call_rcu(&e->rh, &arr, reclaim);
+	busy_err = bpf_call_rcu(&e->rh, &arr, reclaim);
+	bpf_rcu_read_unlock();
+	return 0;
+}
+
+SEC("syscall")
+int arm_both(void *ctx)
+{
+	__u32 key0 = 0, key1 = 1;
+	struct elem *e0, *e1;
+
+	e0 = bpf_map_lookup_elem(&arr, &key0);
+	e1 = bpf_map_lookup_elem(&arr, &key1);
+	if (!e0 || !e1)
+		return 1;
+
+	e0->val = 0xdeadbeef;
+	e1->val = 0xdeadbeef;
+	arm_err = bpf_call_rcu(&e0->rh, &arr, reclaim);
+	arm_err |= bpf_call_rcu(&e1->rh, &arr, reclaim);
+	return 0;
+}
+
+SEC("syscall")
+int arm_trace(void *ctx)
+{
+	__u32 key = 1;
+	struct elem *e;
+
+	e = bpf_map_lookup_elem(&arr, &key);
+	if (!e)
+		return 1;
+
+	e->val = 0xdeadbeef;
+	/* No lock needed: the enclosing rcu_read_lock_trace() already blocks the grace period. */
+	arm_err = bpf_call_rcu_tasks_trace(&e->rh, &arr, reclaim);
+	busy_err = bpf_call_rcu_tasks_trace(&e->rh, &arr, reclaim);
+	return 0;
+}
+
+SEC("iter/bpf_map_elem")
+int dump(struct bpf_iter__bpf_map_elem *ctx)
+{
+	return 0;
+}
diff --git a/tools/testing/selftests/bpf/progs/call_rcu_fail.c b/tools/testing/selftests/bpf/progs/call_rcu_fail.c
new file mode 100644
index 0000000000000..bf60a27731fb3
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/call_rcu_fail.c
@@ -0,0 +1,114 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (c) 2026 Meta Platforms, Inc. and affiliates. */
+
+#include <vmlinux.h>
+#include <bpf/bpf_helpers.h>
+#include "bpf_misc.h"
+
+char _license[] SEC("license") = "GPL";
+
+const void *user_ptr = NULL;
+
+struct elem {
+	__u64 pad;
+	struct bpf_rcu_head rh;
+	__u64 val;
+};
+
+struct {
+	__uint(type, BPF_MAP_TYPE_ARRAY);
+	__uint(max_entries, 1);
+	__type(key, __u32);
+	__type(value, struct elem);
+} arr SEC(".maps");
+
+struct {
+	__uint(type, BPF_MAP_TYPE_ARRAY);
+	__uint(max_entries, 1);
+	__type(key, __u32);
+	__type(value, struct elem);
+} arr2 SEC(".maps");
+
+struct {
+	__uint(type, BPF_MAP_TYPE_ARRAY);
+	__uint(max_entries, 1);
+	__type(key, __u32);
+	__type(value, __u64);
+} plain SEC(".maps");
+
+__u32 key = 0;
+
+static int reclaim(struct bpf_map *map, void *key, void *value)
+{
+	return 0;
+}
+
+static int sleepable_reclaim(struct bpf_map *map, void *key, void *value)
+{
+	struct elem *e = value;
+
+	bpf_copy_from_user(&e->val, sizeof(e->val), user_ptr);
+	return 0;
+}
+
+SEC("syscall")
+__failure __msg("bpf_rcu_head pointer in R1") __msg("doesn't match map pointer in R2")
+int mismatch_map(void *ctx)
+{
+	struct elem *e;
+
+	e = bpf_map_lookup_elem(&arr, &key);
+	if (!e)
+		return 0;
+	bpf_call_rcu(&e->rh, &arr2, reclaim);
+	return 0;
+}
+
+SEC("syscall")
+__failure __msg("map 'plain' has no valid bpf_rcu_head")
+int no_rcu_head(void *ctx)
+{
+	__u64 *val;
+
+	val = bpf_map_lookup_elem(&plain, &key);
+	if (!val)
+		return 0;
+	bpf_call_rcu((struct bpf_rcu_head *)val, &plain, reclaim);
+	return 0;
+}
+
+SEC("syscall")
+__failure __msg("doesn't point to 'struct bpf_rcu_head' that is at 8")
+int wrong_offset(void *ctx)
+{
+	struct elem *e;
+
+	e = bpf_map_lookup_elem(&arr, &key);
+	if (!e)
+		return 0;
+	bpf_call_rcu((struct bpf_rcu_head *)&e->pad, &arr, reclaim);
+	return 0;
+}
+
+SEC("syscall")
+__failure __msg("R1 type=fp expected=map_value")
+int rcu_head_on_stack(void *ctx)
+{
+	struct bpf_rcu_head rh;
+
+	bpf_call_rcu(&rh, &arr, reclaim);
+	return 0;
+}
+
+SEC("syscall")
+__failure __msg("sleepable helper bpf_copy_from_user") __msg("in non-sleepable prog")
+int sleepable_callback(void *ctx)
+{
+	struct elem *e;
+
+	e = bpf_map_lookup_elem(&arr, &key);
+	if (!e)
+		return 0;
+	bpf_call_rcu(&e->rh, &arr, sleepable_reclaim);
+	return 0;
+}

35/3 2026/09/23 19:46 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 16824
							output: 22
							thoughts: 311
						

Thoughts:
**Analyzing the Potential for Uninitialized Memory Risks in the New BPF RCU Implementation**

Okay, so this patch is adding `bpf_call_rcu`, `bpf_call_rcu_tasks_trace` kfuncs, and `struct bpf_rcu_head`, alongside the `BPF_RCU_HEAD` BTF field type. My initial thought is to meticulously dissect this patch for any potential uninitialized memory vulnerabilities. I need to be thorough.

Let's start by methodically reading through the changes.

First, `include/linux/bpf.h`. Aha! It's adding `BPF_RCU_HEAD = (1 << 14)`. It’s also including `int rcu_head_off;` to `struct btf_record`, and the functions `btf_field_type_name`, `btf_field_type_size`, `btf_field_type_align`, and `bpf_obj_init_field`. Interesting. Now, that `bpf_obj_init_field` function... it seems crucial for object initialization. Let me see... in this section it's got:

```c
 	case BPF_KPTR_PERCPU:
 	case BPF_UPTR:
 	case BPF_TASK_WORK:
+	case BPF_RCU_HEAD:
 		break;
```

Hold on... the `BPF_RCU_HEAD` case simply `break`s. That raises a red flag. How are these fields, specifically `BPF_RCU_HEAD`, initialized within BPF objects? I'm not seeing any explicit initialization logic here. This definitely needs more investigation. Let's see if this `bpf_obj_init_field` function is defined anywhere else. I'll need to use grep to find its definition.



36/3 2026/09/23 19:46 tool grepper
0m Args:
{
  "Expression": "bpf_obj_init_field"
}

Results:
{
  "Output": "include/linux/bpf.h=429=static inline u32 btf_field_type_align(enum btf_field_type type)\n--\ninclude/linux/bpf.h-464-\ninclude/linux/bpf.h:465:static inline void bpf_obj_init_field(const struct btf_field *field, void *addr)\ninclude/linux/bpf.h-466-{\n--\ninclude/linux/bpf.h=535=static inline void bpf_obj_init(const struct btf_record *rec, void *obj)\n--\ninclude/linux/bpf.h-541-\tfor (i = 0; i \u003c rec-\u003ecnt; i++)\ninclude/linux/bpf.h:542:\t\tbpf_obj_init_field(\u0026rec-\u003efields[i], obj + rec-\u003efields[i].offset);\ninclude/linux/bpf.h-543-}\n--\nkernel/bpf/helpers.c=2525=static int __bpf_list_add(struct bpf_list_node_kern *node,\n--\nkernel/bpf/helpers.c-2532-\nkernel/bpf/helpers.c:2533:\t/* If list_head was 0-initialized by map, bpf_obj_init_field wasn't\nkernel/bpf/helpers.c-2534-\t * called on its fields, so init here\n--\nkernel/bpf/helpers.c=2636=static struct bpf_list_node *__bpf_list_del(struct bpf_list_head *head,\n--\nkernel/bpf/helpers.c-2641-\nkernel/bpf/helpers.c:2642:\t/* If list_head was 0-initialized by map, bpf_obj_init_field wasn't\nkernel/bpf/helpers.c-2643-\t * called on its fields, so init here\n--\nkernel/bpf/helpers.c=2729=__bpf_kfunc bool bpf_list_empty(struct bpf_list_head *head)\n--\nkernel/bpf/helpers.c-2732-\nkernel/bpf/helpers.c:2733:\t/* If list_head was 0-initialized by map, bpf_obj_init_field wasn't\nkernel/bpf/helpers.c-2734-\t * called on its fields, so init here\n"
}

37/3 2026/09/23 19:46 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 18179
							output: 36
							thoughts: 42
						

Thoughts:
Okay, let's dive into this. I need to understand how `bpf_obj_init_field` functions. My first step is to check the source. I'll head straight to `include/linux/bpf.h` and focus on lines 465 to 500. That should give me a solid view of its core functionality, how it's defined, and what it's intended to do within the BPF framework. Understanding this specific function will likely unlock insights into the larger object initialization processes. I'm expecting this section to provide the fundamental mechanics of field initialization within a BPF context.



38/3 2026/09/23 19:46 tool read-file
0m Args:
{
  "File": "include/linux/bpf.h",
  "FirstLine": 465,
  "LineCount": 45
}

Results:
{
  "Contents": " 465:\tstatic inline void bpf_obj_init_field(const struct btf_field *field, void *addr)\n 466:\t{\n 467:\t\tmemset(addr, 0, field-\u003esize);\n 468:\t\n 469:\t\tswitch (field-\u003etype) {\n 470:\t\tcase BPF_REFCOUNT:\n 471:\t\t\trefcount_set((refcount_t *)addr, 1);\n 472:\t\t\tbreak;\n 473:\t\tcase BPF_RB_NODE:\n 474:\t\t\tRB_CLEAR_NODE((struct rb_node *)addr);\n 475:\t\t\tbreak;\n 476:\t\tcase BPF_LIST_HEAD:\n 477:\t\tcase BPF_LIST_NODE:\n 478:\t\t\tINIT_LIST_HEAD((struct list_head *)addr);\n 479:\t\t\tbreak;\n 480:\t\tcase BPF_RB_ROOT:\n 481:\t\t\t/* RB_ROOT_CACHED 0-inits, no need to do anything after memset */\n 482:\t\tcase BPF_SPIN_LOCK:\n 483:\t\tcase BPF_RES_SPIN_LOCK:\n 484:\t\tcase BPF_TIMER:\n 485:\t\tcase BPF_WORKQUEUE:\n 486:\t\tcase BPF_KPTR_UNREF:\n 487:\t\tcase BPF_KPTR_REF:\n 488:\t\tcase BPF_KPTR_PERCPU:\n 489:\t\tcase BPF_UPTR:\n 490:\t\tcase BPF_TASK_WORK:\n 491:\t\tcase BPF_RCU_HEAD:\n 492:\t\t\tbreak;\n 493:\t\tdefault:\n 494:\t\t\tWARN_ON_ONCE(1);\n 495:\t\t\treturn;\n 496:\t\t}\n 497:\t}\n 498:\t\n 499:\tstatic inline bool btf_record_has_field(const struct btf_record *rec, enum btf_field_type type)\n 500:\t{\n 501:\t\tif (IS_ERR_OR_NULL(rec))\n 502:\t\t\treturn false;\n 503:\t\treturn rec-\u003efield_mask \u0026 type;\n 504:\t}\n 505:\t\n 506:\tstatic inline bool btf_field_is_nmi_safe(enum btf_field_type type)\n 507:\t{\n 508:\t\tswitch (type) {\n 509:\t\tcase BPF_SPIN_LOCK:\n"
}

39/3 2026/09/23 19:46 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 19068
							output: 21
							thoughts: 972
						

Thoughts:
**Analyzing BPF RCU Head Initialization and Usage**

Okay, so I'm looking into how `bpf_rcu_head` is handled, specifically within the context of array maps. The code starts by zeroing out the memory (`memset(addr, 0, field->size)`) during the initialization of a BPF object field, which seems standard. Plus, maps are kzalloc'ed, which implies initial zeroing as well. However, the use of `BPF_RCU_HEAD` is restricted to array maps only, which triggers my curiosity. I need to understand why and whether array maps have some specific allocation or initialization patterns that warrant this restriction.

To get a complete picture, I'm now diving deeper into how array maps allocate and initialize `bpf_rcu_head` elements. I also need to understand how the kernel defines and uses the `struct bpf_rcu_head_kern`, since it appears to be the internal representation.

I see the definition of `struct bpf_rcu_head_kern` in `kernel/bpf/helpers.c`. It contains an `rcu_head`, a callback function pointer, pointers to the map and program, and an `armed` flag. There are some alignment checks and debug information emitted using BTF. Looking at `bpf_rcu_run_callback` and `__bpf_call_rcu`, it looks like the kernel is using the `container_of` macro to get a pointer to the kernel struct and call the callback with information about the map entry. It also looks like there is a check to make sure the callback can't be rearmed before it completes, and a corresponding arming check with an atomic compare-and-swap (cmpxchg) operation.

Then I noticed that `map_key_from_value` is used in the `bpf_rcu_run_callback`. I need to understand how the key is obtained from the value because the kernel is essentially getting the key from the value in the map.



40/3 2026/09/23 19:46 tool grepper
0m Args:
{
  "Expression": "map_key_from_value"
}

Results:
{
  "Output": "kernel/bpf/helpers.c=1129=const struct bpf_func_proto bpf_snprintf_proto = {\n--\nkernel/bpf/helpers.c-1139-\nkernel/bpf/helpers.c:1140:static void *map_key_from_value(struct bpf_map *map, void *value, u32 *arr_idx)\nkernel/bpf/helpers.c-1141-{\n--\nkernel/bpf/helpers.c=1221=static enum hrtimer_restart bpf_timer_cb(struct hrtimer *hrtimer)\n--\nkernel/bpf/helpers.c-1242-\nkernel/bpf/helpers.c:1243:\tkey = map_key_from_value(map, value, \u0026idx);\nkernel/bpf/helpers.c-1244-\n--\nkernel/bpf/helpers.c=1253=static void bpf_wq_work(struct work_struct *work)\n--\nkernel/bpf/helpers.c-1268-\nkernel/bpf/helpers.c:1269:\tkey = map_key_from_value(map, value, \u0026idx);\nkernel/bpf/helpers.c-1270-\n--\nkernel/bpf/helpers.c=4581=static void bpf_task_work_callback(struct callback_head *cb)\n--\nkernel/bpf/helpers.c-4601-\nkernel/bpf/helpers.c:4602:\tkey = (void *)map_key_from_value(ctx-\u003emap, ctx-\u003emap_val, \u0026idx);\nkernel/bpf/helpers.c-4603-\n--\nkernel/bpf/helpers.c=4819=static void bpf_rcu_run_callback(struct rcu_head *rcu)\n--\nkernel/bpf/helpers.c-4828-\tvalue = (void *)rh - map-\u003erecord-\u003ercu_head_off;\nkernel/bpf/helpers.c:4829:\tkey = map_key_from_value(map, value, \u0026idx);\nkernel/bpf/helpers.c-4830-\n"
}

41/3 2026/09/23 19:46 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 21050
							output: 37
							thoughts: 24
						

Thoughts:
Okay, let's dive into this. Here's how I'd approach this task, as if I were thinking it through:

**Inspecting the `map_key_from_value` Helper**

Alright, I need to get a handle on `map_key_from_value`. Let's start with `kernel/bpf/helpers.c`. I already know the usual suspects in this area, but a good quick look is always prudent. I need to understand exactly what this helper is doing and, crucially, how it interacts with the BPF map infrastructure. I'll be particularly interested in its arguments, their types, and what data structures it manipulates. Are there any potential gotchas with memory management or concurrency? What are the implications for performance in the common use-cases? Is it in-lined, and if so, how does that affect optimization? I'll probably be able to glean this just by reading the code. I will pay close attention to the error handling within the function. Are the error codes well-defined and propagated correctly? Are there any potential race conditions I need to think through? Alright, let's see what's in there...



42/3 2026/09/23 19:46 tool read-file
0m Args:
{
  "File": "kernel/bpf/helpers.c",
  "FirstLine": 1140,
  "LineCount": 25
}

Results:
{
  "Contents": "1140:\tstatic void *map_key_from_value(struct bpf_map *map, void *value, u32 *arr_idx)\n1141:\t{\n1142:\t\tif (map-\u003emap_type == BPF_MAP_TYPE_ARRAY) {\n1143:\t\t\tstruct bpf_array *array = container_of(map, struct bpf_array, map);\n1144:\t\n1145:\t\t\t*arr_idx = ((char *)value - array-\u003evalue) / array-\u003eelem_size;\n1146:\t\t\treturn arr_idx;\n1147:\t\t}\n1148:\t\treturn (void *)value - round_up(map-\u003ekey_size, 8);\n1149:\t}\n1150:\t\n1151:\tenum bpf_async_type {\n1152:\t\tBPF_ASYNC_TYPE_TIMER = 0,\n1153:\t\tBPF_ASYNC_TYPE_WQ,\n1154:\t};\n1155:\t\n1156:\tenum bpf_async_op {\n1157:\t\tBPF_ASYNC_START,\n1158:\t\tBPF_ASYNC_CANCEL\n1159:\t};\n1160:\t\n1161:\tstruct bpf_async_cmd {\n1162:\t\tstruct llist_node node;\n1163:\t\tu64 nsec;\n1164:\t\tu32 mode;\n"
}

43/3 2026/09/23 19:46 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 21748
							output: 21
							thoughts: 1104
						

Thoughts:
**Analyzing the BPF RCU Callback Mechanism**

Okay, let me break this down. My initial thought is about how `map_key_from_value` works within the `bpf_rcu_run_callback` function. Specifically, it initializes `*arr_idx` which is located on the stack within `bpf_rcu_run_callback` (it's a `u32 idx`), and returns the address of that `idx` variable (`&idx`). I need to make sure I grasp the context here.

Inside `bpf_rcu_run_callback`, I'm seeing that the `idx` variable is declared locally. Then, `map_key_from_value` is called. It's crucial to recall that this function is part of the RCU mechanism and deals with memory releases. In particular, it's about getting the key for an array-type map.

Let's look more closely at the code. `key = map_key_from_value(map, value, &idx);`. Then, if the `map->map_type` is indeed `BPF_MAP_TYPE_ARRAY` (and this is enforced by `map_check_btf`), then `map_key_from_value` will execute the following: `*arr_idx = ((char *)value - array->value) / array->elem_size;` and finally `return arr_idx;`.

So, `idx` is initialized within `map_key_from_value` and gets a value based on the offset of `value` within the array map. Moreover, `key` is effectively a pointer to the address of `idx`. So, `key` is a pointer to a `u32` which represents the index of an element within the array.

This is important because `bpf_rcu_run_callback` then calls the actual callback function: `callback_fn((u64)(long)map, (u64)(long)key, (u64)(long)value, 0, 0);`. This raises the question of the signature of `bpf_rcu_callback_t`. I need to confirm that this works.

The signature of the BPF callback is `typedef int (*bpf_rcu_callback_t)(struct bpf_map *map, void *key, void *value);`. This confirms it.

Now, let's turn to how the BPF verifier handles this. I need to understand how the verifier interprets `PTR_TO_MAP_KEY` in the context of this callback. The verifier uses `set_rcu_callback_state` when it encounters a callback function, with the signature `callback_fn(struct bpf_map *map, void *key, void *value);`. Crucially, the verifier sets the register types in `callee` accordingly:

*   `callee->regs[BPF_REG_1].type = CONST_PTR_TO_MAP;` This is expected.
*   `callee->regs[BPF_REG_2].type = PTR_TO_MAP_KEY;` Ah, this is where it is important. It marks `key` as a pointer to the map key.
*   `callee->regs[BPF_REG_3].type = PTR_TO_MAP_VALUE;` Also expected for the value.

So, the verifier understands that the `key` argument is a pointer to the map's key. Now, I have to ensure the verifier correctly handles this pointer. Specifically, I'm thinking about the implications of the stack-allocated `idx`. Is the verifier tracking it correctly? How is it validated? I need to dig deeper into the verifier's logic regarding `PTR_TO_MAP_KEY`. What constraints are placed on how the key pointer can be used and what are the implications for the `idx`?



44/3 2026/09/23 19:46 tool grepper
0m Args:
{
  "Expression": "PTR_TO_MAP_KEY"
}

Results:
{
  "Output": "include/linux/bpf.h=889=enum bpf_arg_type {\n--\ninclude/linux/bpf.h-895-\tARG_CONST_MAP_PTR,\t/* const argument used as pointer to bpf_map */\ninclude/linux/bpf.h:896:\tARG_PTR_TO_MAP_KEY,\t/* pointer to stack used as map key */\ninclude/linux/bpf.h-897-\tARG_PTR_TO_MAP_VALUE,\t/* pointer to stack used as map value */\n--\ninclude/linux/bpf.h=1087=enum bpf_reg_type {\n--\ninclude/linux/bpf.h-1092-\tPTR_TO_MAP_VALUE,\t /* reg points to map element value */\ninclude/linux/bpf.h:1093:\tPTR_TO_MAP_KEY,\t\t /* reg points to a map element key */\ninclude/linux/bpf.h-1094-\tPTR_TO_STACK,\t\t /* reg == frame_pointer + offset */\n--\ninclude/linux/bpf_verifier.h=1402=static inline bool type_is_map_ptr(enum bpf_reg_type type)\n--\ninclude/linux/bpf_verifier.h-1405-\tcase CONST_PTR_TO_MAP:\ninclude/linux/bpf_verifier.h:1406:\tcase PTR_TO_MAP_KEY:\ninclude/linux/bpf_verifier.h-1407-\tcase PTR_TO_MAP_VALUE:\n--\nkernel/bpf/helpers.c=50=const struct bpf_func_proto bpf_map_lookup_elem_proto = {\n--\nkernel/bpf/helpers.c-55-\t.arg1_type\t= ARG_CONST_MAP_PTR,\nkernel/bpf/helpers.c:56:\t.arg2_type\t= ARG_PTR_TO_MAP_KEY,\nkernel/bpf/helpers.c-57-};\n--\nkernel/bpf/helpers.c=66=const struct bpf_func_proto bpf_map_update_elem_proto = {\n--\nkernel/bpf/helpers.c-71-\t.arg1_type\t= ARG_CONST_MAP_PTR,\nkernel/bpf/helpers.c:72:\t.arg2_type\t= ARG_PTR_TO_MAP_KEY,\nkernel/bpf/helpers.c-73-\t.arg3_type\t= ARG_PTR_TO_MAP_VALUE,\n--\nkernel/bpf/helpers.c=83=const struct bpf_func_proto bpf_map_delete_elem_proto = {\n--\nkernel/bpf/helpers.c-88-\t.arg1_type\t= ARG_CONST_MAP_PTR,\nkernel/bpf/helpers.c:89:\t.arg2_type\t= ARG_PTR_TO_MAP_KEY,\nkernel/bpf/helpers.c-90-};\n--\nkernel/bpf/helpers.c=139=const struct bpf_func_proto bpf_map_lookup_percpu_elem_proto = {\n--\nkernel/bpf/helpers.c-144-\t.arg1_type\t= ARG_CONST_MAP_PTR,\nkernel/bpf/helpers.c:145:\t.arg2_type\t= ARG_PTR_TO_MAP_KEY,\nkernel/bpf/helpers.c-146-\t.arg3_type\t= ARG_ANYTHING,\n--\nkernel/bpf/log.c=399=const char *reg_type_str(struct bpf_verifier_env *env, enum bpf_reg_type type)\n--\nkernel/bpf/log.c-423-\t\t[PTR_TO_INSN]\t\t= \"insn\",\nkernel/bpf/log.c:424:\t\t[PTR_TO_MAP_KEY]\t= \"map_key\",\nkernel/bpf/log.c-425-\t\t[CONST_PTR_TO_DYNPTR]\t= \"dynptr_ptr\",\n--\nkernel/bpf/states.c=504=static bool regsafe(struct bpf_verifier_env *env, struct bpf_reg_state *rold,\n--\nkernel/bpf/states.c-606-\t\treturn range_within(rold, rcur) \u0026\u0026 tnum_in(rold-\u003evar_off, rcur-\u003evar_off);\nkernel/bpf/states.c:607:\tcase PTR_TO_MAP_KEY:\nkernel/bpf/states.c-608-\tcase PTR_TO_MAP_VALUE:\n--\nkernel/bpf/verifier.c=59=static bool bpf_global_percpu_ma_set;\n--\nkernel/bpf/verifier.c-114- *\nkernel/bpf/verifier.c:115: * ARG_PTR_TO_MAP_KEY is one of such argument constraints.\nkernel/bpf/verifier.c-116- * It means that the register type passed to this function must be\n--\nkernel/bpf/verifier.c-122- *   .arg1_type = ARG_CONST_MAP_PTR,\nkernel/bpf/verifier.c:123: *   .arg2_type = ARG_PTR_TO_MAP_KEY,\nkernel/bpf/verifier.c-124- *\n--\nkernel/bpf/verifier.c-150- *\nkernel/bpf/verifier.c:151: * Then .arg2_type == ARG_PTR_TO_MAP_KEY and R2-\u003etype == PTR_TO_STACK, ok so far,\nkernel/bpf/verifier.c-152- * Now verifier checks that [R2, R2 + map's key_size) are within stack limits\n--\nkernel/bpf/verifier.c=354=static bool reg_not_null(struct bpf_verifier_env *env, const struct bpf_reg_state *reg)\n--\nkernel/bpf/verifier.c-374-\t\ttype == PTR_TO_MAP_VALUE ||\nkernel/bpf/verifier.c:375:\t\ttype == PTR_TO_MAP_KEY ||\nkernel/bpf/verifier.c-376-\t\ttype == PTR_TO_SOCK_COMMON ||\n--\nkernel/bpf/verifier.c=4389=static int __check_mem_access(struct bpf_verifier_env *env, struct bpf_reg_state *reg, argno_t argno,\n--\nkernel/bpf/verifier.c-4398-\tswitch (reg-\u003etype) {\nkernel/bpf/verifier.c:4399:\tcase PTR_TO_MAP_KEY:\nkernel/bpf/verifier.c-4400-\t\tverbose(env, \"invalid access to map key, key_size=%d off=%d size=%d\\n\",\n--\nkernel/bpf/verifier.c=5274=static int check_ptr_alignment(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-5290-\t\tbreak;\nkernel/bpf/verifier.c:5291:\tcase PTR_TO_MAP_KEY:\nkernel/bpf/verifier.c-5292-\t\tpointer_desc = \"key \";\n--\nkernel/bpf/verifier.c=6476=static int check_mem_access(struct bpf_verifier_env *env, int insn_idx, struct bpf_reg_state *reg, argno_t argno,\n--\nkernel/bpf/verifier.c-6491-\nkernel/bpf/verifier.c:6492:\tif (reg-\u003etype == PTR_TO_MAP_KEY) {\nkernel/bpf/verifier.c-6493-\t\tif (t == BPF_WRITE) {\n--\nkernel/bpf/verifier.c=7108=static int check_helper_mem_access(struct bpf_verifier_env *env, struct bpf_reg_state *reg,\n--\nkernel/bpf/verifier.c-7127-\t\t\t\t\t   zero_size_allowed);\nkernel/bpf/verifier.c:7128:\tcase PTR_TO_MAP_KEY:\nkernel/bpf/verifier.c-7129-\t\tif (access_type == BPF_WRITE) {\n--\nkernel/bpf/verifier.c=8336=static const struct bpf_reg_types mem_types = {\n--\nkernel/bpf/verifier.c-8340-\t\tPTR_TO_PACKET_META,\nkernel/bpf/verifier.c:8341:\t\tPTR_TO_MAP_KEY,\nkernel/bpf/verifier.c-8342-\t\tPTR_TO_MAP_VALUE,\n--\nkernel/bpf/verifier.c=8422=static const struct bpf_reg_types *compatible_reg_types[__BPF_ARG_TYPE_MAX] = {\nkernel/bpf/verifier.c:8423:\t[ARG_PTR_TO_MAP_KEY]\t\t= \u0026mem_types,\nkernel/bpf/verifier.c-8424-\t[ARG_PTR_TO_MAP_VALUE]\t\t= \u0026mem_types,\n--\nkernel/bpf/verifier.c=8676=static int check_func_arg_reg_off(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-8713-\tcase PTR_TO_PACKET_META:\nkernel/bpf/verifier.c:8714:\tcase PTR_TO_MAP_KEY:\nkernel/bpf/verifier.c-8715-\tcase PTR_TO_MAP_VALUE:\n--\nkernel/bpf/verifier.c=8934=static int check_func_arg(struct bpf_verifier_env *env, u32 arg, u32 slot, u32 prev_slot,\n--\nkernel/bpf/verifier.c-9026-\t\tbreak;\nkernel/bpf/verifier.c:9027:\tcase ARG_PTR_TO_MAP_KEY:\nkernel/bpf/verifier.c-9028-\t\t/* bpf_map_xxx(..., map_ptr, ..., key) call:\n--\nkernel/bpf/verifier.c=10731=int map_set_for_each_callback_args(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-10741-\nkernel/bpf/verifier.c:10742:\tcallee-\u003eregs[BPF_REG_2].type = PTR_TO_MAP_KEY;\nkernel/bpf/verifier.c-10743-\t__mark_reg_known_zero(\u0026callee-\u003eregs[BPF_REG_2]);\n--\nkernel/bpf/verifier.c=10822=static int set_timer_callback_state(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-10837-\nkernel/bpf/verifier.c:10838:\tcallee-\u003eregs[BPF_REG_2].type = PTR_TO_MAP_KEY;\nkernel/bpf/verifier.c-10839-\t__mark_reg_known_zero(\u0026callee-\u003eregs[BPF_REG_2]);\n--\nkernel/bpf/verifier.c=10940=static int set_task_work_schedule_callback_state(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-10955-\nkernel/bpf/verifier.c:10956:\tcallee-\u003eregs[BPF_REG_2].type = PTR_TO_MAP_KEY;\nkernel/bpf/verifier.c-10957-\t__mark_reg_known_zero(\u0026callee-\u003eregs[BPF_REG_2]);\n--\nkernel/bpf/verifier.c=10974=static int set_rcu_callback_state(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-10989-\nkernel/bpf/verifier.c:10990:\tcallee-\u003eregs[BPF_REG_2].type = PTR_TO_MAP_KEY;\nkernel/bpf/verifier.c-10991-\t__mark_reg_known_zero(\u0026callee-\u003eregs[BPF_REG_2]);\n--\nkernel/bpf/verifier.c=13810=s64 bpf_helper_stack_access_bytes(struct bpf_verifier_env *env, struct bpf_insn *insn,\n--\nkernel/bpf/verifier.c-13831-\tswitch (base_type(at)) {\nkernel/bpf/verifier.c:13832:\tcase ARG_PTR_TO_MAP_KEY:\nkernel/bpf/verifier.c-13833-\tcase ARG_PTR_TO_MAP_VALUE: {\nkernel/bpf/verifier.c:13834:\t\tbool is_key = base_type(at) == ARG_PTR_TO_MAP_KEY;\nkernel/bpf/verifier.c-13835-\t\tu64 val;\n--\nkernel/bpf/verifier.c=15036=static int adjust_ptr_min_max_vals(struct bpf_verifier_env *env, struct bpf_insn *insn,\n--\nkernel/bpf/verifier.c-15096-\tcase PTR_TO_MAP_VALUE:\nkernel/bpf/verifier.c:15097:\tcase PTR_TO_MAP_KEY:\nkernel/bpf/verifier.c-15098-\tcase PTR_TO_STACK:\n--\nnet/core/filter.c=11795=static const struct bpf_func_proto sk_select_reuseport_proto = {\n--\nnet/core/filter.c-11800-\t.arg2_type      = ARG_CONST_MAP_PTR,\nnet/core/filter.c:11801:\t.arg3_type      = ARG_PTR_TO_MAP_KEY,\nnet/core/filter.c-11802-\t.arg4_type\t= ARG_ANYTHING,\n--\nnet/core/sock_map.c=636=const struct bpf_func_proto bpf_sock_map_update_proto = {\n--\nnet/core/sock_map.c-642-\t.arg2_type\t= ARG_CONST_MAP_PTR,\nnet/core/sock_map.c:643:\t.arg3_type\t= ARG_PTR_TO_MAP_KEY,\nnet/core/sock_map.c-644-\t.arg4_type\t= ARG_ANYTHING,\n--\nnet/core/sock_map.c=1242=const struct bpf_func_proto bpf_sock_hash_update_proto = {\n--\nnet/core/sock_map.c-1248-\t.arg2_type\t= ARG_CONST_MAP_PTR,\nnet/core/sock_map.c:1249:\t.arg3_type\t= ARG_PTR_TO_MAP_KEY,\nnet/core/sock_map.c-1250-\t.arg4_type\t= ARG_ANYTHING,\n--\nnet/core/sock_map.c=1271=const struct bpf_func_proto bpf_sk_redirect_hash_proto = {\n--\nnet/core/sock_map.c-1276-\t.arg2_type      = ARG_CONST_MAP_PTR,\nnet/core/sock_map.c:1277:\t.arg3_type      = ARG_PTR_TO_MAP_KEY,\nnet/core/sock_map.c-1278-\t.arg4_type      = ARG_ANYTHING,\n--\nnet/core/sock_map.c=1302=const struct bpf_func_proto bpf_msg_redirect_hash_proto = {\n--\nnet/core/sock_map.c-1307-\t.arg2_type      = ARG_CONST_MAP_PTR,\nnet/core/sock_map.c:1308:\t.arg3_type      = ARG_PTR_TO_MAP_KEY,\nnet/core/sock_map.c-1309-\t.arg4_type      = ARG_ANYTHING,\n"
}

45/3 2026/09/23 19:46 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 27781
							output: 38
							thoughts: 97
						

Thoughts:
Here's my analysis of the provided code snippet:

**Analyzing `set_rcu_callback_state` and Its Relatives**

Okay, first things first, it immediately jumps out at me that `set_rcu_callback_state` seems to be structured similarly to `set_timer_callback_state` and `set_task_work_schedule_callback_state`. That's a strong indicator we might be dealing with a common pattern or design choice in the verifier. Given that similarity, it makes sense to drill down into how `set_timer_callback_state` works. I know that's where I can start to build an understanding of the verification strategy here.

Let's dive right into `verifier.c`. I need to understand the logic. I recall the approximate line number, around 10822 is a reasonable place to start, as I recall that's where the function definition starts. Let's see what we can find. I'm going to look for the function signature and the surrounding code for context. I'll need to understand the verifier's purpose here, which almost certainly is to ensure that the callback state is properly managed with respect to memory safety and program correctness. This should be an interesting line of inquiry.



46/3 2026/09/23 19:46 tool read-file
0m Args:
{
  "File": "kernel/bpf/verifier.c",
  "FirstLine": 10820,
  "LineCount": 40
}

Results:
{
  "Contents": "10820:\t}\n10821:\t\n10822:\tstatic int set_timer_callback_state(struct bpf_verifier_env *env,\n10823:\t\t\t\t\t    struct bpf_func_state *caller,\n10824:\t\t\t\t\t    struct bpf_func_state *callee,\n10825:\t\t\t\t\t    int insn_idx)\n10826:\t{\n10827:\t\tstruct bpf_map *map_ptr = caller-\u003eregs[BPF_REG_1].map_ptr;\n10828:\t\tu32 map_uid = caller-\u003eregs[BPF_REG_1].map_uid;\n10829:\t\n10830:\t\t/* bpf_timer_set_callback(struct bpf_timer *timer, void *callback_fn);\n10831:\t\t * callback_fn(struct bpf_map *map, void *key, void *value);\n10832:\t\t */\n10833:\t\tcallee-\u003eregs[BPF_REG_1].type = CONST_PTR_TO_MAP;\n10834:\t\t__mark_reg_known_zero(\u0026callee-\u003eregs[BPF_REG_1]);\n10835:\t\tcallee-\u003eregs[BPF_REG_1].map_ptr = map_ptr;\n10836:\t\tcallee-\u003eregs[BPF_REG_1].map_uid = map_uid;\n10837:\t\n10838:\t\tcallee-\u003eregs[BPF_REG_2].type = PTR_TO_MAP_KEY;\n10839:\t\t__mark_reg_known_zero(\u0026callee-\u003eregs[BPF_REG_2]);\n10840:\t\tcallee-\u003eregs[BPF_REG_2].map_ptr = map_ptr;\n10841:\t\tcallee-\u003eregs[BPF_REG_2].map_uid = map_uid;\n10842:\t\n10843:\t\tcallee-\u003eregs[BPF_REG_3].type = PTR_TO_MAP_VALUE;\n10844:\t\t__mark_reg_known_zero(\u0026callee-\u003eregs[BPF_REG_3]);\n10845:\t\tcallee-\u003eregs[BPF_REG_3].map_ptr = map_ptr;\n10846:\t\tcallee-\u003eregs[BPF_REG_3].map_uid = map_uid;\n10847:\t\n10848:\t\t/* unused */\n10849:\t\tbpf_mark_reg_not_init(env, \u0026callee-\u003eregs[BPF_REG_4]);\n10850:\t\tbpf_mark_reg_not_init(env, \u0026callee-\u003eregs[BPF_REG_5]);\n10851:\t\tcallee-\u003ein_async_callback_fn = true;\n10852:\t\tcallee-\u003ecallback_ret_range = retval_range(0, 0);\n10853:\t\treturn 0;\n10854:\t}\n10855:\t\n10856:\tstatic int set_find_vma_callback_state(struct bpf_verifier_env *env,\n10857:\t\t\t\t\t       struct bpf_func_state *caller,\n10858:\t\t\t\t\t       struct bpf_func_state *callee,\n10859:\t\t\t\t\t       int insn_idx)\n"
}

47/3 2026/09/23 19:46 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 29057
							output: 20
							thoughts: 638
						

Thoughts:
**Analyzing the BPF RCU Head Structure and Its Lifecycle**

Okay, so I'm looking at `set_rcu_callback_state` and it's strikingly similar to `set_timer_callback_state`. The key difference I'm seeing is that `caller->regs[BPF_REG_2]` points to `map_ptr` in the context of `bpf_call_rcu`, where `REG_1` is the `bpf_rcu_head`, `REG_2` is the map, and `REG_3` is the callback. And that `callback_ret_range = retval_range(S32_MIN, S32_MAX)`.

Let's dive into `bpf_call_rcu` itself, looking at the struct definition:
```c
struct bpf_rcu_head_kern {
	struct rcu_head rcu;
	bpf_callback_t callback_fn;
	struct bpf_map *map;
	struct bpf_prog *prog;
	u32 armed;
} __aligned(8);
```
Wait, wait, I need to check the UAPI side of the `bpf_rcu_head`.
```c
struct bpf_rcu_head {
	__u64 __opaque[8];
} __attribute__((aligned(8)));
```
Okay, so the UAPI version is 64 bytes due to that opaque array. Now, what's the size of the kernel version, `struct bpf_rcu_head_kern`?
`rcu_head` is 16 bytes on 64-bit. Then we have a callback function pointer (8 bytes), the map pointer (8 bytes), the program pointer (8 bytes), and a `u32 armed` (4 bytes).
That's 16 + 8 + 8 + 8 + 4 = 44 bytes, and it's probably padded to 48 bytes due to the alignment of 8.
And there are `BUILD_BUG_ON` checks: `sizeof(struct bpf_rcu_head_kern) > sizeof(struct bpf_rcu_head)` which makes sense, and the alignment check too `__alignof__(struct bpf_rcu_head_kern) != __alignof__(struct bpf_rcu_head)`.

Now, I really need to examine the lifetime of `struct bpf_rcu_head` and how it's accessed! Can a BPF program or user space read or write directly to this structure? I need to understand how the verifier handles access to these special fields within map values.

Let's start by digging into `kernel/bpf/verifier.c`. I'll search for `check_map_field_pointer` or any direct references to `BPF_RCU_HEAD` itself. I should also check how the verifier handles `BPF_TASK_WORK`, `BPF_WORKQUEUE`, or `BPF_TIMER` to see if there are similar patterns or checks for these types of BPF-specific structures.



48/3 2026/09/23 19:47 tool grepper
0m Args:
{
  "Expression": "BPF_TASK_WORK"
}

Results:
{
  "Output": "include/linux/bpf.h=200=enum btf_field_type {\n--\ninclude/linux/bpf.h-216-\tBPF_RES_SPIN_LOCK = (1 \u003c\u003c 12),\ninclude/linux/bpf.h:217:\tBPF_TASK_WORK  = (1 \u003c\u003c 13),\ninclude/linux/bpf.h-218-\tBPF_RCU_HEAD   = (1 \u003c\u003c 14),\n--\ninclude/linux/bpf.h=349=static inline const char *btf_field_type_name(enum btf_field_type type)\n--\ninclude/linux/bpf.h-376-\t\treturn \"bpf_refcount\";\ninclude/linux/bpf.h:377:\tcase BPF_TASK_WORK:\ninclude/linux/bpf.h-378-\t\treturn \"bpf_task_work\";\n--\ninclude/linux/bpf.h=393=static inline u32 btf_field_type_size(enum btf_field_type type)\n--\ninclude/linux/bpf.h-418-\t\treturn sizeof(struct bpf_refcount);\ninclude/linux/bpf.h:419:\tcase BPF_TASK_WORK:\ninclude/linux/bpf.h-420-\t\treturn sizeof(struct bpf_task_work);\n--\ninclude/linux/bpf.h=429=static inline u32 btf_field_type_align(enum btf_field_type type)\n--\ninclude/linux/bpf.h-454-\t\treturn __alignof__(struct bpf_refcount);\ninclude/linux/bpf.h:455:\tcase BPF_TASK_WORK:\ninclude/linux/bpf.h-456-\t\treturn __alignof__(struct bpf_task_work);\n--\ninclude/linux/bpf.h=465=static inline void bpf_obj_init_field(const struct btf_field *field, void *addr)\n--\ninclude/linux/bpf.h-489-\tcase BPF_UPTR:\ninclude/linux/bpf.h:490:\tcase BPF_TASK_WORK:\ninclude/linux/bpf.h-491-\tcase BPF_RCU_HEAD:\n--\ninclude/linux/bpf.h=506=static inline bool btf_field_is_nmi_safe(enum btf_field_type type)\n--\ninclude/linux/bpf.h-512-\tcase BPF_WORKQUEUE:\ninclude/linux/bpf.h:513:\tcase BPF_TASK_WORK:\ninclude/linux/bpf.h-514-\tcase BPF_KPTR_UNREF:\n--\ninclude/linux/bpf.h=713=static inline bool bpf_map_has_internal_structs(struct bpf_map *map)\ninclude/linux/bpf.h-714-{\ninclude/linux/bpf.h:715:\treturn btf_record_has_field(map-\u003erecord, BPF_TIMER | BPF_WORKQUEUE | BPF_TASK_WORK);\ninclude/linux/bpf.h-716-}\n--\nkernel/bpf/btf.c=3686=static int btf_get_field_type(const struct btf *btf, const struct btf_type *var_type,\n--\nkernel/bpf/btf.c-3697-\t\t{ BPF_WORKQUEUE, \"bpf_wq\", true },\nkernel/bpf/btf.c:3698:\t\t{ BPF_TASK_WORK, \"bpf_task_work\", true },\nkernel/bpf/btf.c-3699-\t\t{ BPF_RCU_HEAD, \"bpf_rcu_head\", true },\n--\nkernel/bpf/btf.c=3827=static int btf_find_field_one(const struct btf *btf,\n--\nkernel/bpf/btf.c-3883-\tcase BPF_REFCOUNT:\nkernel/bpf/btf.c:3884:\tcase BPF_TASK_WORK:\nkernel/bpf/btf.c-3885-\tcase BPF_RCU_HEAD:\n--\nkernel/bpf/btf.c=4153=struct btf_record *btf_parse_fields(const struct btf *btf, const struct btf_type *t,\n--\nkernel/bpf/btf.c-4220-\t\t\tbreak;\nkernel/bpf/btf.c:4221:\t\tcase BPF_TASK_WORK:\nkernel/bpf/btf.c-4222-\t\t\tWARN_ON_ONCE(rec-\u003etask_work_off \u003e= 0);\n--\nkernel/bpf/helpers.c=5266=void bpf_map_free_internal_structs(struct bpf_map *map, void *val)\n--\nkernel/bpf/helpers.c-5271-\t\tbpf_obj_free_workqueue(map-\u003erecord, val);\nkernel/bpf/helpers.c:5272:\tif (btf_record_has_field(map-\u003erecord, BPF_TASK_WORK))\nkernel/bpf/helpers.c-5273-\t\tbpf_obj_free_task_work(map-\u003erecord, val);\n--\nkernel/bpf/syscall.c=663=void btf_record_free(struct btf_record *rec)\n--\nkernel/bpf/syscall.c-688-\t\tcase BPF_WORKQUEUE:\nkernel/bpf/syscall.c:689:\t\tcase BPF_TASK_WORK:\nkernel/bpf/syscall.c-690-\t\tcase BPF_RCU_HEAD:\n--\nkernel/bpf/syscall.c=707=struct btf_record *btf_record_dup(const struct btf_record *rec)\n--\nkernel/bpf/syscall.c-743-\t\tcase BPF_WORKQUEUE:\nkernel/bpf/syscall.c:744:\t\tcase BPF_TASK_WORK:\nkernel/bpf/syscall.c-745-\t\tcase BPF_RCU_HEAD:\n--\nkernel/bpf/syscall.c=804=void bpf_obj_free_task_work(const struct btf_record *rec, void *obj)\nkernel/bpf/syscall.c-805-{\nkernel/bpf/syscall.c:806:\tif (WARN_ON_ONCE(!btf_record_has_field(rec, BPF_TASK_WORK)))\nkernel/bpf/syscall.c-807-\t\treturn;\n--\nkernel/bpf/syscall.c=816=void bpf_obj_free_fields(const struct btf_record *rec, void *obj)\n--\nkernel/bpf/syscall.c-839-\t\t\tbreak;\nkernel/bpf/syscall.c:840:\t\tcase BPF_TASK_WORK:\nkernel/bpf/syscall.c-841-\t\t\tbpf_task_work_cancel_and_free(field_ptr);\n--\nkernel/bpf/syscall.c=1261=static int map_check_btf(struct bpf_map *map, struct bpf_token *token,\n--\nkernel/bpf/syscall.c-1285-\t\t\t\t       BPF_RB_ROOT | BPF_REFCOUNT | BPF_WORKQUEUE | BPF_UPTR |\nkernel/bpf/syscall.c:1286:\t\t\t\t       BPF_TASK_WORK | BPF_RCU_HEAD,\nkernel/bpf/syscall.c-1287-\t\t\t\t       map-\u003evalue_size);\n--\nkernel/bpf/syscall.c-1318-\t\t\tcase BPF_WORKQUEUE:\nkernel/bpf/syscall.c:1319:\t\t\tcase BPF_TASK_WORK:\nkernel/bpf/syscall.c-1320-\t\t\t\tif (map-\u003emap_type != BPF_MAP_TYPE_HASH \u0026\u0026\n--\nkernel/bpf/verifier.c=1978=static void refine_map_lookup_value(struct bpf_reg_state *reg)\n--\nkernel/bpf/verifier.c-1989-\t\tif (btf_record_has_field(map-\u003einner_map_meta-\u003erecord,\nkernel/bpf/verifier.c:1990:\t\t\t\t\t BPF_TIMER | BPF_WORKQUEUE | BPF_TASK_WORK))\nkernel/bpf/verifier.c-1991-\t\t\treg-\u003emap_uid = reg-\u003eid;\n--\nkernel/bpf/verifier.c=7566=static int check_map_field_pointer(struct bpf_verifier_env *env, struct bpf_reg_state *reg, argno_t argno,\n--\nkernel/bpf/verifier.c-7594-\t\tbreak;\nkernel/bpf/verifier.c:7595:\tcase BPF_TASK_WORK:\nkernel/bpf/verifier.c-7596-\t\tfield_off = map-\u003erecord-\u003etask_work_off;\n--\nkernel/bpf/verifier.c=8934=static int check_func_arg(struct bpf_verifier_env *env, u32 arg, u32 slot, u32 prev_slot,\n--\nkernel/bpf/verifier.c-9451-\tcase ARG_PTR_TO_TASK_WORK:\nkernel/bpf/verifier.c:9452:\t\terr = check_map_field_pointer(env, reg, argno, BPF_TASK_WORK, \u0026meta-\u003emap);\nkernel/bpf/verifier.c-9453-\t\tif (err \u003c 0)\n--\ntools/testing/selftests/bpf/prog_tests/task_work_stress.c=46=static void task_work_run(bool enable_delete)\n--\ntools/testing/selftests/bpf/prog_tests/task_work_stress.c-50-\tint nthreads = 16;\ntools/testing/selftests/bpf/prog_tests/task_work_stress.c:51:\tint test_time_s = get_env_int(\"BPF_TASK_WORK_TEST_TIME\", 1);\ntools/testing/selftests/bpf/prog_tests/task_work_stress.c-52-\tpthread_t tid[nthreads], tid_del;\n"
}

49/3 2026/09/23 19:47 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 33012
							output: 25
							thoughts: 116
						

Thoughts:
Okay, let's see what we have here.

**Deconstructing bpf_map_has_internal_structs**

My initial thought is to examine this `bpf_map_has_internal_structs` function. The code is straightforward: it's an inline function that checks if a `bpf_map` contains any internal structures, specifically ones related to timers, workqueues, or task work. It leverages `btf_record_has_field` to achieve this, which suggests a reliance on BTF (BPF Type Format) for its type introspection.

But the real question now is: Where is this actually *used*? Understanding its call sites is critical. Knowing how and why this function is called will give me insight into its significance in the bigger picture of the BPF ecosystem. Time to trace its usage!



50/3 2026/09/23 19:47 tool grepper
0m Args:
{
  "Expression": "bpf_map_has_internal_structs"
}

Results:
{
  "Output": "include/linux/bpf.h=710=bool bpf_map_meta_equal(const struct bpf_map *meta0,\n--\ninclude/linux/bpf.h-712-\ninclude/linux/bpf.h:713:static inline bool bpf_map_has_internal_structs(struct bpf_map *map)\ninclude/linux/bpf.h-714-{\n--\nkernel/bpf/arraymap.c=492=static void array_map_free_internal_structs(struct bpf_map *map)\n--\nkernel/bpf/arraymap.c-497-\t/* We only free internal structs on uref dropping to zero */\nkernel/bpf/arraymap.c:498:\tif (!bpf_map_has_internal_structs(map))\nkernel/bpf/arraymap.c-499-\t\treturn;\n--\nkernel/bpf/hashtab.c=1615=static void htab_map_free_internal_structs(struct bpf_map *map)\n--\nkernel/bpf/hashtab.c-1619-\t/* We only free internal structs on uref dropping to zero */\nkernel/bpf/hashtab.c:1620:\tif (!bpf_map_has_internal_structs(map))\nkernel/bpf/hashtab.c-1621-\t\treturn;\n--\nkernel/bpf/hashtab.c=3111=static void rhtab_map_free_internal_structs(struct bpf_map *map)\n--\nkernel/bpf/hashtab.c-3116-\nkernel/bpf/hashtab.c:3117:\tif (!bpf_map_has_internal_structs(map))\nkernel/bpf/hashtab.c-3118-\t\treturn;\n"
}

51/3 2026/09/23 19:47 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 33799
							output: 37
							thoughts: 41
						

Thoughts:
Here's my summary, as if I were thinking these thoughts:

**Analyzing the Array Map Implementation**

Okay, let's dive into the BPF array map implementation. I need to understand how this is working under the hood, so I'm focusing on a specific area. I'm taking a look at the code, and my attention is immediately drawn to `kernel/bpf/arraymap.c` around line 492. I'm going to zoom in and examine lines 480 through 520 very closely. Understanding this section of code will give me some insight into what's happening.



52/3 2026/09/23 19:47 tool read-file
0m Args:
{
  "File": "kernel/bpf/arraymap.c",
  "FirstLine": 480,
  "LineCount": 40
}

Results:
{
  "Contents": " 480:\t\n 481:\t/* Called from syscall or from eBPF program */\n 482:\tstatic long array_map_delete_elem(struct bpf_map *map, void *key)\n 483:\t{\n 484:\t\treturn -EINVAL;\n 485:\t}\n 486:\t\n 487:\tstatic void *array_map_vmalloc_addr(struct bpf_array *array)\n 488:\t{\n 489:\t\treturn (void *)round_down((unsigned long)array, PAGE_SIZE);\n 490:\t}\n 491:\t\n 492:\tstatic void array_map_free_internal_structs(struct bpf_map *map)\n 493:\t{\n 494:\t\tstruct bpf_array *array = container_of(map, struct bpf_array, map);\n 495:\t\tint i;\n 496:\t\n 497:\t\t/* We only free internal structs on uref dropping to zero */\n 498:\t\tif (!bpf_map_has_internal_structs(map))\n 499:\t\t\treturn;\n 500:\t\n 501:\t\tfor (i = 0; i \u003c array-\u003emap.max_entries; i++)\n 502:\t\t\tbpf_map_free_internal_structs(map, array_map_elem_ptr(array, i));\n 503:\t}\n 504:\t\n 505:\t/* Called when map-\u003erefcnt goes to zero, either from workqueue or from syscall */\n 506:\tstatic void array_map_free(struct bpf_map *map)\n 507:\t{\n 508:\t\tstruct bpf_array *array = container_of(map, struct bpf_array, map);\n 509:\t\tint i;\n 510:\t\n 511:\t\tif (!IS_ERR_OR_NULL(map-\u003erecord)) {\n 512:\t\t\tif (array-\u003emap.map_type == BPF_MAP_TYPE_PERCPU_ARRAY) {\n 513:\t\t\t\tfor (i = 0; i \u003c array-\u003emap.max_entries; i++) {\n 514:\t\t\t\t\tvoid __percpu *pptr = array-\u003epptrs[i \u0026 array-\u003eindex_mask];\n 515:\t\t\t\t\tint cpu;\n 516:\t\n 517:\t\t\t\t\tfor_each_possible_cpu(cpu) {\n 518:\t\t\t\t\t\tbpf_obj_free_fields(map-\u003erecord, per_cpu_ptr(pptr, cpu));\n 519:\t\t\t\t\t\tcond_resched();\n"
}

53/3 2026/09/23 19:47 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 34689
							output: 19
							thoughts: 999
						

Thoughts:
**BPF RCU Head Considerations**

Okay, let's break this down. I was looking into `bpf_call_rcu` and how it handles map teardown.  My initial observation was about this check in `kernel/bpf/helpers.c`:

```c
	/* A queued callback cannot be cancelled, so a self-rearming one would pin prog and map. */
	if (!atomic64_read(&map->usercnt))
		return -EPERM;
```

This seemed important, and I noted the lack of explicit release/cancelation for `BPF_RCU_HEAD` in `syscall.c` and `bpf_obj_free_fields`.  This raised a question: Why isn't `BPF_RCU_HEAD` explicitly freed like other objects?

My suspicion was that `bpf_call_rcu` doesn't take a reference on the map itself, but then I needed to confirm whether `bpf_rcu_run_callback` actually accesses the map.

Sure enough, the code within `bpf_rcu_run_callback` does access the map via `rh->map`:

```c
static void bpf_rcu_run_callback(struct rcu_head *rcu)
{
	struct bpf_rcu_head_kern *rh = container_of(rcu, struct bpf_rcu_head_kern, rcu);
	bpf_callback_t callback_fn = rh->callback_fn;
	struct bpf_prog *prog = rh->prog;
	struct bpf_map *map = rh->map;
	void *value, *key;
	u32 idx;

	value = (void *)rh - map->record->rcu_head_off;
	key = map_key_from_value(map, value, &idx);

	/* Pairs with the arming cmpxchg(): rh may be re-armed as soon as this store lands. */
	smp_store_release(&rh->armed, 0);

	rcu_read_lock_dont_migrate();
	callback_fn((u64)(long)map, (u64)(long)key, (u64)(long)value, 0, 0);
	rcu_read_unlock_migrate();

	bpf_prog_put(prog);
}
```

Now, the critical question: How is the lifetime of `map` guaranteed? The answer lies in the program reference. It's kept alive through the program itself: `prog = bpf_prog_inc_not_zero(aux->prog);` which means that the loaded program holds references to its used maps (`aux->used_maps`)!  When the `prog` is alive, all `prog->aux->used_maps` are alive.  `prog` is then kept alive until `bpf_prog_put(prog)` in `bpf_rcu_run_callback`.

This makes sense.  However, this led to another question: what about inner maps?

There are restrictions on inner maps as I found out, these were enforced by the check:

```c
	/* An inner map has no used_maps reference to hold it under a queued callback. */
	if (btf_record_has_field(inner_map->record, BPF_RCU_HEAD))
		return ERR_PTR(-EOPNOTSUPP);
```

Thus, inner maps aren't allowed. And I found another restriction:

```c
	/* The value ctx arg is writable and aliases the live element. */
	if (btf_record_has_field(map->record, BPF_RCU_HEAD)) {
		err = -EOPNOTSUPP;
		goto put_map;
	}
```

This leads me to think, the system prevents RCU head on the elements of the map, and now I'm thinking about user-space interactions.

Now I am considering what happens if userspace interacts with a map that *does* contain an `bpf_rcu_head` via `bpf_map_lookup_elem` or `bpf_map_update_elem`.  I need to understand how these other types like `BPF_TASK_WORK`, `BPF_TIMER`, `BPF_SPIN_LOCK` are handled during syscall lookups/updates or copy operations.  I should search `kernel/bpf/` for instances of these and calls to `copy_map_value` or similar functionality.



54/3 2026/09/23 19:47 tool grepper
0m Args:
{
  "Expression": "copy_map_value"
}

Results:
{
  "Output": "include/linux/bpf.h=574=static inline void bpf_obj_memcpy(struct btf_record *rec,\n--\ninclude/linux/bpf.h-598-\ninclude/linux/bpf.h:599:static inline void copy_map_value(struct bpf_map *map, void *dst, void *src)\ninclude/linux/bpf.h-600-{\n--\ninclude/linux/bpf.h-603-\ninclude/linux/bpf.h:604:static inline void copy_map_value_long(struct bpf_map *map, void *dst, void *src)\ninclude/linux/bpf.h-605-{\n--\ninclude/linux/bpf.h=648=static inline void zero_map_value(struct bpf_map *map, void *dst)\n--\ninclude/linux/bpf.h-652-\ninclude/linux/bpf.h:653:void copy_map_value_locked(struct bpf_map *map, void *dst, void *src,\ninclude/linux/bpf.h-654-\t\t\t   bool lock_src);\n--\nkernel/bpf/arraymap.c=339=int bpf_percpu_array_copy(struct bpf_map *map, void *key, void *value, u64 map_flags)\n--\nkernel/bpf/arraymap.c-358-\t\tcpu = map_flags \u003e\u003e 32;\nkernel/bpf/arraymap.c:359:\t\tcopy_map_value(map, value, per_cpu_ptr(pptr, cpu));\nkernel/bpf/arraymap.c-360-\t\tcheck_and_init_map_value(map, value);\n--\nkernel/bpf/arraymap.c-363-\tfor_each_possible_cpu(cpu) {\nkernel/bpf/arraymap.c:364:\t\tcopy_map_value_long(map, value + off, per_cpu_ptr(pptr, cpu));\nkernel/bpf/arraymap.c-365-\t\tcheck_and_init_map_value(map, value + off);\n--\nkernel/bpf/arraymap.c=392=static long array_map_update_elem(struct bpf_map *map, void *key, void *value,\n--\nkernel/bpf/arraymap.c-416-\t\tval = this_cpu_ptr(array-\u003epptrs[index \u0026 array-\u003eindex_mask]);\nkernel/bpf/arraymap.c:417:\t\tcopy_map_value(map, val, value);\nkernel/bpf/arraymap.c-418-\t\tbpf_obj_cancel_fields(map, val);\n--\nkernel/bpf/arraymap.c-422-\t\tif (map_flags \u0026 BPF_F_LOCK)\nkernel/bpf/arraymap.c:423:\t\t\tcopy_map_value_locked(map, val, value, false);\nkernel/bpf/arraymap.c-424-\t\telse\nkernel/bpf/arraymap.c:425:\t\t\tcopy_map_value(map, val, value);\nkernel/bpf/arraymap.c-426-\t\tbpf_obj_cancel_fields(map, val);\n--\nkernel/bpf/arraymap.c=431=int bpf_percpu_array_update(struct bpf_map *map, void *key, void *value,\n--\nkernel/bpf/arraymap.c-464-\t\tptr = per_cpu_ptr(pptr, cpu);\nkernel/bpf/arraymap.c:465:\t\tcopy_map_value(map, ptr, value);\nkernel/bpf/arraymap.c-466-\t\tbpf_obj_cancel_fields(map, ptr);\n--\nkernel/bpf/arraymap.c-471-\t\tval = (map_flags \u0026 BPF_F_ALL_CPUS) ? value : value + off;\nkernel/bpf/arraymap.c:472:\t\tcopy_map_value(map, ptr, val);\nkernel/bpf/arraymap.c-473-\t\tbpf_obj_cancel_fields(map, ptr);\n--\nkernel/bpf/arraymap.c=703=static int __bpf_array_map_seq_show(struct seq_file *seq, void *v)\n--\nkernel/bpf/arraymap.c-730-\t\t\tfor_each_possible_cpu(cpu) {\nkernel/bpf/arraymap.c:731:\t\t\t\tcopy_map_value_long(map, info-\u003epercpu_value_buf + off,\nkernel/bpf/arraymap.c-732-\t\t\t\t\t\t    per_cpu_ptr(pptr, cpu));\n--\nkernel/bpf/bpf_insn_array.c=75=static long insn_array_update_elem(struct bpf_map *map, void *key, void *value, u64 map_flags)\n--\nkernel/bpf/bpf_insn_array.c-86-\nkernel/bpf/bpf_insn_array.c:87:\tcopy_map_value(map, \u0026val, value);\nkernel/bpf/bpf_insn_array.c-88-\tif (val.jitted_off || val.xlated_off)\n--\nkernel/bpf/bpf_local_storage.c=70=bpf_selem_alloc(struct bpf_local_storage_map *smap, void *owner,\n--\nkernel/bpf/bpf_local_storage.c-86-\t\t\t/* No need to call check_and_init_map_value as memory is zero init */\nkernel/bpf/bpf_local_storage.c:87:\t\t\tcopy_map_value(\u0026smap-\u003emap, SDATA(selem)-\u003edata, value);\nkernel/bpf/bpf_local_storage.c-88-\t\t\tif (swap_uptrs)\n--\nkernel/bpf/bpf_local_storage.c=549=bpf_local_storage_update(void *owner, struct bpf_local_storage_map *smap,\n--\nkernel/bpf/bpf_local_storage.c-599-\t\tif (old_sdata \u0026\u0026 selem_linked_to_storage_lockless(SELEM(old_sdata))) {\nkernel/bpf/bpf_local_storage.c:600:\t\t\tcopy_map_value_locked(\u0026smap-\u003emap, old_sdata-\u003edata,\nkernel/bpf/bpf_local_storage.c-601-\t\t\t\t\t      value, false);\n--\nkernel/bpf/bpf_local_storage.c-633-\tif (old_sdata \u0026\u0026 (map_flags \u0026 BPF_F_LOCK)) {\nkernel/bpf/bpf_local_storage.c:634:\t\tcopy_map_value_locked(\u0026smap-\u003emap, old_sdata-\u003edata, value,\nkernel/bpf/bpf_local_storage.c-635-\t\t\t\t      false);\n--\nkernel/bpf/hashtab.c=1018=static void pcpu_copy_value(struct bpf_htab *htab, void __percpu *pptr,\n--\nkernel/bpf/hashtab.c-1025-\t\tptr = this_cpu_ptr(pptr);\nkernel/bpf/hashtab.c:1026:\t\tcopy_map_value(\u0026htab-\u003emap, ptr, value);\nkernel/bpf/hashtab.c-1027-\t\tbpf_obj_cancel_fields(\u0026htab-\u003emap, ptr);\n--\nkernel/bpf/hashtab.c-1035-\t\t\tptr = per_cpu_ptr(pptr, cpu);\nkernel/bpf/hashtab.c:1036:\t\t\tcopy_map_value(\u0026htab-\u003emap, ptr, value);\nkernel/bpf/hashtab.c-1037-\t\t\tbpf_obj_cancel_fields(\u0026htab-\u003emap, ptr);\n--\nkernel/bpf/hashtab.c-1043-\t\t\tval = (map_flags \u0026 BPF_F_ALL_CPUS) ? value : value + off;\nkernel/bpf/hashtab.c:1044:\t\t\tcopy_map_value(\u0026htab-\u003emap, ptr, val);\nkernel/bpf/hashtab.c-1045-\t\t\tbpf_obj_cancel_fields(\u0026htab-\u003emap, ptr);\n--\nkernel/bpf/hashtab.c=1051=static void pcpu_init_value(struct bpf_htab *htab, void __percpu *pptr,\n--\nkernel/bpf/hashtab.c-1064-\t\t\tif (cpu == current_cpu)\nkernel/bpf/hashtab.c:1065:\t\t\t\tcopy_map_value(\u0026htab-\u003emap, per_cpu_ptr(pptr, cpu), value);\nkernel/bpf/hashtab.c-1066-\t\t\telse /* Since elem is preallocated, we cannot touch special fields */\n--\nkernel/bpf/hashtab.c=1079=static struct htab_elem *alloc_htab_elem(struct bpf_htab *htab, void *key,\n--\nkernel/bpf/hashtab.c-1147-\t} else if (map_flags \u0026 BPF_F_LOCK) {\nkernel/bpf/hashtab.c:1148:\t\tcopy_map_value_locked(\u0026htab-\u003emap,\nkernel/bpf/hashtab.c-1149-\t\t\t\t      htab_elem_value(l_new, key_size),\n--\nkernel/bpf/hashtab.c-1151-\t} else {\nkernel/bpf/hashtab.c:1152:\t\tcopy_map_value(\u0026htab-\u003emap, htab_elem_value(l_new, key_size), value);\nkernel/bpf/hashtab.c-1153-\t}\n--\nkernel/bpf/hashtab.c=1177=static long htab_map_update_elem(struct bpf_map *map, void *key, void *value,\n--\nkernel/bpf/hashtab.c-1211-\t\t\t/* grab the element lock and update value in place */\nkernel/bpf/hashtab.c:1212:\t\t\tcopy_map_value_locked(map,\nkernel/bpf/hashtab.c-1213-\t\t\t\t\t      htab_elem_value(l_old, key_size),\n--\nkernel/bpf/hashtab.c-1239-\t\t */\nkernel/bpf/hashtab.c:1240:\t\tcopy_map_value_locked(map,\nkernel/bpf/hashtab.c-1241-\t\t\t\t      htab_elem_value(l_old, key_size),\n--\nkernel/bpf/hashtab.c=1284=static long htab_lru_map_update_elem(struct bpf_map *map, void *key, void *value,\n--\nkernel/bpf/hashtab.c-1315-\t\treturn -ENOMEM;\nkernel/bpf/hashtab.c:1316:\tcopy_map_value(\u0026htab-\u003emap, htab_elem_value(l_new, map-\u003ekey_size), value);\nkernel/bpf/hashtab.c-1317-\n--\nkernel/bpf/hashtab.c=1681=static int __htab_map_lookup_and_delete_elem(struct bpf_map *map, void *key,\n--\nkernel/bpf/hashtab.c-1715-\t\tfor_each_possible_cpu(cpu) {\nkernel/bpf/hashtab.c:1716:\t\t\tcopy_map_value_long(\u0026htab-\u003emap, value + off, per_cpu_ptr(pptr, cpu));\nkernel/bpf/hashtab.c-1717-\t\t\tcheck_and_init_map_value(\u0026htab-\u003emap, value + off);\n--\nkernel/bpf/hashtab.c-1723-\t\tif (flags \u0026 BPF_F_LOCK)\nkernel/bpf/hashtab.c:1724:\t\t\tcopy_map_value_locked(map, value, src, true);\nkernel/bpf/hashtab.c-1725-\t\telse\nkernel/bpf/hashtab.c:1726:\t\t\tcopy_map_value(map, value, src);\nkernel/bpf/hashtab.c-1727-\t\t/* Zeroing special fields in the temp buffer */\n--\nkernel/bpf/hashtab.c=1776=__htab_map_lookup_and_delete_batch(struct bpf_map *map,\n--\nkernel/bpf/hashtab.c-1912-\t\t\t\tcpu = elem_map_flags \u003e\u003e 32;\nkernel/bpf/hashtab.c:1913:\t\t\t\tcopy_map_value(\u0026htab-\u003emap, dst_val, per_cpu_ptr(pptr, cpu));\nkernel/bpf/hashtab.c-1914-\t\t\t\tcheck_and_init_map_value(\u0026htab-\u003emap, dst_val);\n--\nkernel/bpf/hashtab.c-1916-\t\t\t\tfor_each_possible_cpu(cpu) {\nkernel/bpf/hashtab.c:1917:\t\t\t\t\tcopy_map_value_long(\u0026htab-\u003emap, dst_val + off,\nkernel/bpf/hashtab.c-1918-\t\t\t\t\t\t\t    per_cpu_ptr(pptr, cpu));\n--\nkernel/bpf/hashtab.c-1933-\t\t\tif (elem_map_flags \u0026 BPF_F_LOCK)\nkernel/bpf/hashtab.c:1934:\t\t\t\tcopy_map_value_locked(map, dst_val, value,\nkernel/bpf/hashtab.c-1935-\t\t\t\t\t\t      true);\nkernel/bpf/hashtab.c-1936-\t\t\telse\nkernel/bpf/hashtab.c:1937:\t\t\t\tcopy_map_value(map, dst_val, value);\nkernel/bpf/hashtab.c-1938-\t\t\t/* Zeroing special fields in the temp buffer */\n--\nkernel/bpf/hashtab.c=2172=static int __bpf_hash_map_seq_show(struct seq_file *seq, struct htab_elem *elem)\n--\nkernel/bpf/hashtab.c-2195-\t\t\t\tfor_each_possible_cpu(cpu) {\nkernel/bpf/hashtab.c:2196:\t\t\t\t\tcopy_map_value_long(map, info-\u003epercpu_value_buf + off,\nkernel/bpf/hashtab.c-2197-\t\t\t\t\t\t\t    per_cpu_ptr(pptr, cpu));\n--\nkernel/bpf/hashtab.c=2479=int bpf_percpu_hash_copy(struct bpf_map *map, void *key, void *value, u64 map_flags)\n--\nkernel/bpf/hashtab.c-2502-\t\tcpu = map_flags \u003e\u003e 32;\nkernel/bpf/hashtab.c:2503:\t\tcopy_map_value(map, value, per_cpu_ptr(pptr, cpu));\nkernel/bpf/hashtab.c-2504-\t\tcheck_and_init_map_value(map, value);\n--\nkernel/bpf/hashtab.c-2507-\tfor_each_possible_cpu(cpu) {\nkernel/bpf/hashtab.c:2508:\t\tcopy_map_value_long(map, value + off, per_cpu_ptr(pptr, cpu));\nkernel/bpf/hashtab.c-2509-\t\tcheck_and_init_map_value(map, value + off);\n--\nkernel/bpf/hashtab.c=2922=static void rhtab_read_elem_value(struct bpf_map *map, void *dst, struct rhtab_elem *elem,\n--\nkernel/bpf/hashtab.c-2927-\tif (flags \u0026 BPF_F_LOCK)\nkernel/bpf/hashtab.c:2928:\t\tcopy_map_value_locked(map, dst, src, true);\nkernel/bpf/hashtab.c-2929-\telse\nkernel/bpf/hashtab.c:2930:\t\tcopy_map_value(map, dst, src);\nkernel/bpf/hashtab.c-2931-}\n--\nkernel/bpf/hashtab.c=2999=static long rhtab_map_update_existing(struct bpf_map *map, struct rhtab_elem *elem, void *value,\n--\nkernel/bpf/hashtab.c-3007-\tif (map_flags \u0026 BPF_F_LOCK)\nkernel/bpf/hashtab.c:3008:\t\tcopy_map_value_locked(map, old_val, value, false);\nkernel/bpf/hashtab.c-3009-\telse\nkernel/bpf/hashtab.c:3010:\t\tcopy_map_value(map, old_val, value);\nkernel/bpf/hashtab.c-3011-\n--\nkernel/bpf/hashtab.c-3016-\t *\nkernel/bpf/hashtab.c:3017:\t * copy_map_value() skips special-field offsets, so old timers/\nkernel/bpf/hashtab.c-3018-\t * kptrs/etc. still sit in the slot. Cancel them after the copy\n--\nkernel/bpf/hashtab.c=3025=static long rhtab_map_update_elem(struct bpf_map *map, void *key, void *value, u64 map_flags)\n--\nkernel/bpf/hashtab.c-3060-\tmemcpy(elem-\u003edata, key, map-\u003ekey_size);\nkernel/bpf/hashtab.c:3061:\tcopy_map_value(map, rhtab_elem_value(elem, map-\u003ekey_size), value);\nkernel/bpf/hashtab.c-3062-\n--\nkernel/bpf/helpers.c=370=const struct bpf_func_proto bpf_spin_unlock_proto = {\n--\nkernel/bpf/helpers.c-377-\nkernel/bpf/helpers.c:378:void copy_map_value_locked(struct bpf_map *map, void *dst, void *src,\nkernel/bpf/helpers.c-379-\t\t\t   bool lock_src)\n--\nkernel/bpf/helpers.c-388-\t__bpf_spin_lock_irqsave(lock);\nkernel/bpf/helpers.c:389:\tcopy_map_value(map, dst, src);\nkernel/bpf/helpers.c-390-\t__bpf_spin_unlock_irqrestore(lock);\n--\nkernel/bpf/local_storage.c=144=static long cgroup_storage_update_elem(struct bpf_map *map, void *key,\n--\nkernel/bpf/local_storage.c-162-\tif (flags \u0026 BPF_F_LOCK) {\nkernel/bpf/local_storage.c:163:\t\tcopy_map_value_locked(map, storage-\u003ebuf-\u003edata, value, false);\nkernel/bpf/local_storage.c-164-\t\treturn 0;\n--\nkernel/bpf/local_storage.c=182=int bpf_percpu_cgroup_storage_copy(struct bpf_map *_map, void *key,\n--\nkernel/bpf/local_storage.c-202-\t\tcpu = map_flags \u003e\u003e 32;\nkernel/bpf/local_storage.c:203:\t\tcopy_map_value(_map, value, per_cpu_ptr(storage-\u003epercpu_buf, cpu));\nkernel/bpf/local_storage.c-204-\t\tgoto unlock;\n--\nkernel/bpf/local_storage.c-207-\tfor_each_possible_cpu(cpu) {\nkernel/bpf/local_storage.c:208:\t\tcopy_map_value_long(_map, value + off, per_cpu_ptr(storage-\u003epercpu_buf, cpu));\nkernel/bpf/local_storage.c-209-\t\toff += size;\n--\nkernel/bpf/local_storage.c=216=int bpf_percpu_cgroup_storage_update(struct bpf_map *_map, void *key,\n--\nkernel/bpf/local_storage.c-242-\t\tcpu = map_flags \u003e\u003e 32;\nkernel/bpf/local_storage.c:243:\t\tcopy_map_value(_map, per_cpu_ptr(storage-\u003epercpu_buf, cpu), value);\nkernel/bpf/local_storage.c-244-\t\tgoto unlock;\n--\nkernel/bpf/local_storage.c-248-\t\tval = (map_flags \u0026 BPF_F_ALL_CPUS) ? value : value + off;\nkernel/bpf/local_storage.c:249:\t\tcopy_map_value(_map, per_cpu_ptr(storage-\u003epercpu_buf, cpu), val);\nkernel/bpf/local_storage.c-250-\t\toff += size;\n--\nkernel/bpf/syscall.c=308=static int bpf_map_copy_value(struct bpf_map *map, void *key, void *value,\n--\nkernel/bpf/syscall.c-353-\t\t\t\t/* lock 'ptr' and copy everything but lock */\nkernel/bpf/syscall.c:354:\t\t\t\tcopy_map_value_locked(map, value, ptr, true);\nkernel/bpf/syscall.c-355-\t\t\telse\nkernel/bpf/syscall.c:356:\t\t\t\tcopy_map_value(map, value, ptr);\nkernel/bpf/syscall.c-357-\t\t\t/* mask lock and timer, since value wasn't zero inited */\n--\nnet/core/bpf_sk_storage.c=134=bpf_sk_storage_clone_elem(struct sock *newsk,\n--\nnet/core/bpf_sk_storage.c-144-\tif (btf_record_has_field(smap-\u003emap.record, BPF_SPIN_LOCK))\nnet/core/bpf_sk_storage.c:145:\t\tcopy_map_value_locked(\u0026smap-\u003emap, SDATA(copy_selem)-\u003edata,\nnet/core/bpf_sk_storage.c-146-\t\t\t\t      SDATA(selem)-\u003edata, true);\nnet/core/bpf_sk_storage.c-147-\telse\nnet/core/bpf_sk_storage.c:148:\t\tcopy_map_value(\u0026smap-\u003emap, SDATA(copy_selem)-\u003edata,\nnet/core/bpf_sk_storage.c-149-\t\t\t       SDATA(selem)-\u003edata);\n--\nnet/core/bpf_sk_storage.c=532=static int diag_get(struct bpf_local_storage_map *smap,\n--\nnet/core/bpf_sk_storage.c-553-\tif (btf_record_has_field(smap-\u003emap.record, BPF_SPIN_LOCK))\nnet/core/bpf_sk_storage.c:554:\t\tcopy_map_value_locked(\u0026smap-\u003emap, nla_data(nla_value),\nnet/core/bpf_sk_storage.c-555-\t\t\t\t      sdata-\u003edata, true);\nnet/core/bpf_sk_storage.c-556-\telse\nnet/core/bpf_sk_storage.c:557:\t\tcopy_map_value(\u0026smap-\u003emap, nla_data(nla_value), sdata-\u003edata);\nnet/core/bpf_sk_storage.c-558-\tcheck_and_init_map_value(\u0026smap-\u003emap, nla_data(nla_value));\n--\ntools/testing/selftests/bpf/progs/cgroup_storage.c=39=int trigger_oob(struct bpf_sock *sk)\n--\ntools/testing/selftests/bpf/progs/cgroup_storage.c-54-\t * bpf_map_update_elem() -\u003e htab_map_update_elem() -\u003e\ntools/testing/selftests/bpf/progs/cgroup_storage.c:55:\t * pcpu_init_value() -\u003e copy_map_value_long() -\u003e\ntools/testing/selftests/bpf/progs/cgroup_storage.c-56-\t * bpf_obj_memcpy(..., long_memcpy=true) -\u003e\n"
}

55/3 2026/09/23 19:47 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 42895
							output: 36
							thoughts: 51
						

Thoughts:
Here's my analysis of the provided text, rendered in the first person, assuming an expert user:

**Diving into `bpf_obj_memcpy`**

Alright, let's take a look at `bpf_obj_memcpy`, shall we? Seems like a good starting point to understand data manipulation within BPF programs. I'm going to head straight into `include/linux/bpf.h` and target lines 560 through 650. Knowing this area well, I'm expecting this section will likely define or detail the implementation of `bpf_obj_memcpy`, which would be critical for inspecting memory within BPF maps or BPF program context from user space. Let's see what interesting tidbits and gotchas are in there. I'm hoping to quickly identify any potential performance implications and security considerations directly in this section.



56/3 2026/09/23 19:47 tool read-file
0m Args:
{
  "File": "include/linux/bpf.h",
  "FirstLine": 560,
  "LineCount": 90
}

Results:
{
  "Contents": " 560:\t * updates from BPF programs. Called from bpf syscall and mostly used with\n 561:\t * size 8 or 16 bytes, so ask compiler to inline it.\n 562:\t */\n 563:\tstatic inline void bpf_long_memcpy(void *dst, const void *src, u32 size)\n 564:\t{\n 565:\t\tconst long *lsrc = src;\n 566:\t\tlong *ldst = dst;\n 567:\t\n 568:\t\tsize /= sizeof(long);\n 569:\t\twhile (size--)\n 570:\t\t\tdata_race(*ldst++ = *lsrc++);\n 571:\t}\n 572:\t\n 573:\t/* copy everything but bpf_spin_lock, bpf_timer, and kptrs. There could be one of each. */\n 574:\tstatic inline void bpf_obj_memcpy(struct btf_record *rec,\n 575:\t\t\t\t\t  void *dst, void *src, u32 size,\n 576:\t\t\t\t\t  bool long_memcpy)\n 577:\t{\n 578:\t\tu32 curr_off = 0;\n 579:\t\tint i;\n 580:\t\n 581:\t\tif (IS_ERR_OR_NULL(rec)) {\n 582:\t\t\tif (long_memcpy)\n 583:\t\t\t\tbpf_long_memcpy(dst, src, size);\n 584:\t\t\telse\n 585:\t\t\t\tdata_race(memcpy(dst, src, size));\n 586:\t\t\treturn;\n 587:\t\t}\n 588:\t\n 589:\t\tfor (i = 0; i \u003c rec-\u003ecnt; i++) {\n 590:\t\t\tu32 next_off = rec-\u003efields[i].offset;\n 591:\t\t\tu32 sz = next_off - curr_off;\n 592:\t\n 593:\t\t\tdata_race(memcpy(dst + curr_off, src + curr_off, sz));\n 594:\t\t\tcurr_off += rec-\u003efields[i].size + sz;\n 595:\t\t}\n 596:\t\tdata_race(memcpy(dst + curr_off, src + curr_off, size - curr_off));\n 597:\t}\n 598:\t\n 599:\tstatic inline void copy_map_value(struct bpf_map *map, void *dst, void *src)\n 600:\t{\n 601:\t\tbpf_obj_memcpy(map-\u003erecord, dst, src, map-\u003evalue_size, false);\n 602:\t}\n 603:\t\n 604:\tstatic inline void copy_map_value_long(struct bpf_map *map, void *dst, void *src)\n 605:\t{\n 606:\t\tbpf_obj_memcpy(map-\u003erecord, dst, src, round_up(map-\u003evalue_size, 8), true);\n 607:\t}\n 608:\t\n 609:\tstatic inline void bpf_obj_swap_uptrs(const struct btf_record *rec, void *dst, void *src)\n 610:\t{\n 611:\t\tunsigned long *src_uptr, *dst_uptr;\n 612:\t\tconst struct btf_field *field;\n 613:\t\tint i;\n 614:\t\n 615:\t\tif (!btf_record_has_field(rec, BPF_UPTR))\n 616:\t\t\treturn;\n 617:\t\n 618:\t\tfor (i = 0, field = rec-\u003efields; i \u003c rec-\u003ecnt; i++, field++) {\n 619:\t\t\tif (field-\u003etype != BPF_UPTR)\n 620:\t\t\t\tcontinue;\n 621:\t\n 622:\t\t\tsrc_uptr = src + field-\u003eoffset;\n 623:\t\t\tdst_uptr = dst + field-\u003eoffset;\n 624:\t\t\tswap(*src_uptr, *dst_uptr);\n 625:\t\t}\n 626:\t}\n 627:\t\n 628:\tstatic inline void bpf_obj_memzero(struct btf_record *rec, void *dst, u32 size)\n 629:\t{\n 630:\t\tu32 curr_off = 0;\n 631:\t\tint i;\n 632:\t\n 633:\t\tif (IS_ERR_OR_NULL(rec)) {\n 634:\t\t\tmemset(dst, 0, size);\n 635:\t\t\treturn;\n 636:\t\t}\n 637:\t\n 638:\t\tfor (i = 0; i \u003c rec-\u003ecnt; i++) {\n 639:\t\t\tu32 next_off = rec-\u003efields[i].offset;\n 640:\t\t\tu32 sz = next_off - curr_off;\n 641:\t\n 642:\t\t\tmemset(dst + curr_off, 0, sz);\n 643:\t\t\tcurr_off += rec-\u003efields[i].size + sz;\n 644:\t\t}\n 645:\t\tmemset(dst + curr_off, 0, size - curr_off);\n 646:\t}\n 647:\t\n 648:\tstatic inline void zero_map_value(struct bpf_map *map, void *dst)\n 649:\t{\n"
}

57/3 2026/09/23 19:47 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 44580
							output: 36
							thoughts: 396
						

Thoughts:
**Analyzing the Data Copying Logic in BPF Maps**

Okay, let's break this down. I'm looking at `bpf_obj_memcpy` and how it handles copying data within a BPF map. Here's what jumps out:

```c
		for (i = 0; i < rec->cnt; i++) {
			u32 next_off = rec->fields[i].offset;
			u32 sz = next_off - curr_off;
	
			data_race(memcpy(dst + curr_off, src + curr_off, sz));
			curr_off += rec->fields[i].size + sz;
		}
		data_race(memcpy(dst + curr_off, src + curr_off, size - curr_off));
```

The loop iterates through `rec->cnt` and copies chunks of data. The interesting part is the use of `rec->fields[i]`. Now, I recall that `rec->fields` gets populated somehow during BTF parsing, specifically during the `btf_parse_fields` step. I need to refresh my memory, let's see how that looks.

I know the `BPF_RCU_HEAD` type is parsed by `btf_parse_fields` and added as a field. Let's see specifically where that happens... ah yes, in `btf_find_field_one`:

```c
	case BPF_RB_NODE:
	case BPF_REFCOUNT:
	case BPF_TASK_WORK:
	case BPF_RCU_HEAD:
		ret = btf_find_struct(btf, var_type, off, sz, field_type,
				      info_cnt ? &info[0] : &tmp);
```

So, `rec->fields` *does* contain this `BPF_RCU_HEAD` field. Back to `bpf_obj_memcpy`, it seems like it's *skipping* the content of this `BPF_RCU_HEAD` struct when copying.

But wait a minute... What happens when we *read* the map value? Specifically, what happens when it's copied to userspace using something like `bpf_map_copy_value`? That's the critical question! I need to check the code in `kernel/bpf/syscall.c` to understand how `bpf_map_copy_value` works. It's time to dig into the details of the copy operation from the kernel to userspace.



58/3 2026/09/23 19:47 tool read-file
0m Args:
{
  "File": "kernel/bpf/syscall.c",
  "FirstLine": 308,
  "LineCount": 60
}

Results:
{
  "Contents": " 308:\tstatic int bpf_map_copy_value(struct bpf_map *map, void *key, void *value,\n 309:\t\t\t\t      __u64 flags)\n 310:\t{\n 311:\t\tvoid *ptr;\n 312:\t\tint err;\n 313:\t\n 314:\t\tif (bpf_map_is_offloaded(map))\n 315:\t\t\treturn bpf_map_offload_lookup_elem(map, key, value);\n 316:\t\n 317:\t\tbpf_disable_instrumentation();\n 318:\t\tif (map-\u003emap_type == BPF_MAP_TYPE_PERCPU_HASH ||\n 319:\t\t    map-\u003emap_type == BPF_MAP_TYPE_LRU_PERCPU_HASH) {\n 320:\t\t\terr = bpf_percpu_hash_copy(map, key, value, flags);\n 321:\t\t} else if (map-\u003emap_type == BPF_MAP_TYPE_PERCPU_ARRAY) {\n 322:\t\t\terr = bpf_percpu_array_copy(map, key, value, flags);\n 323:\t\t} else if (map-\u003emap_type == BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE) {\n 324:\t\t\terr = bpf_percpu_cgroup_storage_copy(map, key, value, flags);\n 325:\t\t} else if (map-\u003emap_type == BPF_MAP_TYPE_STACK_TRACE) {\n 326:\t\t\terr = bpf_stackmap_extract(map, key, value, false);\n 327:\t\t} else if (IS_FD_ARRAY(map) || IS_FD_PROG_ARRAY(map)) {\n 328:\t\t\terr = bpf_fd_array_map_lookup_elem(map, key, value);\n 329:\t\t} else if (IS_FD_HASH(map)) {\n 330:\t\t\terr = bpf_fd_htab_map_lookup_elem(map, key, value);\n 331:\t\t} else if (map-\u003emap_type == BPF_MAP_TYPE_REUSEPORT_SOCKARRAY) {\n 332:\t\t\terr = bpf_fd_reuseport_array_lookup_elem(map, key, value);\n 333:\t\t} else if (map-\u003emap_type == BPF_MAP_TYPE_QUEUE ||\n 334:\t\t\t   map-\u003emap_type == BPF_MAP_TYPE_STACK ||\n 335:\t\t\t   map-\u003emap_type == BPF_MAP_TYPE_BLOOM_FILTER) {\n 336:\t\t\terr = map-\u003eops-\u003emap_peek_elem(map, value);\n 337:\t\t} else if (map-\u003emap_type == BPF_MAP_TYPE_STRUCT_OPS) {\n 338:\t\t\t/* struct_ops map requires directly updating \"value\" */\n 339:\t\t\terr = bpf_struct_ops_map_sys_lookup_elem(map, key, value);\n 340:\t\t} else {\n 341:\t\t\trcu_read_lock();\n 342:\t\t\tif (map-\u003eops-\u003emap_lookup_elem_sys_only)\n 343:\t\t\t\tptr = map-\u003eops-\u003emap_lookup_elem_sys_only(map, key);\n 344:\t\t\telse\n 345:\t\t\t\tptr = map-\u003eops-\u003emap_lookup_elem(map, key);\n 346:\t\t\tif (IS_ERR(ptr)) {\n 347:\t\t\t\terr = PTR_ERR(ptr);\n 348:\t\t\t} else if (!ptr) {\n 349:\t\t\t\terr = -ENOENT;\n 350:\t\t\t} else {\n 351:\t\t\t\terr = 0;\n 352:\t\t\t\tif (flags \u0026 BPF_F_LOCK)\n 353:\t\t\t\t\t/* lock 'ptr' and copy everything but lock */\n 354:\t\t\t\t\tcopy_map_value_locked(map, value, ptr, true);\n 355:\t\t\t\telse\n 356:\t\t\t\t\tcopy_map_value(map, value, ptr);\n 357:\t\t\t\t/* mask lock and timer, since value wasn't zero inited */\n 358:\t\t\t\tcheck_and_init_map_value(map, value);\n 359:\t\t\t}\n 360:\t\t\trcu_read_unlock();\n 361:\t\t}\n 362:\t\n 363:\t\tbpf_enable_instrumentation();\n 364:\t\n 365:\t\treturn err;\n 366:\t}\n 367:\t\n"
}

59/3 2026/09/23 19:47 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 46742
							output: 23
							thoughts: 44
						

Thoughts:
Okay, let's dive into this code.

**Diving Deep into `check_and_init_map_value`**

Alright, my expert eye landed on line 358: `check_and_init_map_value(map, value);`. Now *that* looks interesting. Whenever I see a function name like that, my mental gears start turning. I need to understand what that function, `check_and_init_map_value`, is *really* doing. It's almost certainly handling some crucial aspect of managing this `map` data structure, probably related to either pre-existing or to-be-inserted `value`. Given the name, my initial assumption is that it's either: 1) Checking if a value needs to be initialized within the map before use, or 2) It ensures the map is properly populated with the correct key-value pairs. Likely, it's a combination of both. I bet it's something foundational to how this map operates and, ultimately, how the system as a whole behaves. Time to dig in and unravel the magic!



60/3 2026/09/23 19:47 tool grepper
0m Args:
{
  "Expression": "check_and_init_map_value"
}

Results:
{
  "Output": "include/linux/bpf.h=535=static inline void bpf_obj_init(const struct btf_record *rec, void *obj)\n--\ninclude/linux/bpf.h-551- */\ninclude/linux/bpf.h:552:static inline void check_and_init_map_value(struct bpf_map *map, void *dst)\ninclude/linux/bpf.h-553-{\n--\nkernel/bpf/arraymap.c=339=int bpf_percpu_array_copy(struct bpf_map *map, void *key, void *value, u64 map_flags)\n--\nkernel/bpf/arraymap.c-359-\t\tcopy_map_value(map, value, per_cpu_ptr(pptr, cpu));\nkernel/bpf/arraymap.c:360:\t\tcheck_and_init_map_value(map, value);\nkernel/bpf/arraymap.c-361-\t\tgoto unlock;\n--\nkernel/bpf/arraymap.c-364-\t\tcopy_map_value_long(map, value + off, per_cpu_ptr(pptr, cpu));\nkernel/bpf/arraymap.c:365:\t\tcheck_and_init_map_value(map, value + off);\nkernel/bpf/arraymap.c-366-\t\toff += size;\n--\nkernel/bpf/arraymap.c=703=static int __bpf_array_map_seq_show(struct seq_file *seq, void *v)\n--\nkernel/bpf/arraymap.c-732-\t\t\t\t\t\t    per_cpu_ptr(pptr, cpu));\nkernel/bpf/arraymap.c:733:\t\t\t\tcheck_and_init_map_value(map, info-\u003epercpu_value_buf + off);\nkernel/bpf/arraymap.c-734-\t\t\t\toff += size;\n--\nkernel/bpf/bpf_local_storage.c=70=bpf_selem_alloc(struct bpf_local_storage_map *smap, void *owner,\n--\nkernel/bpf/bpf_local_storage.c-85-\t\tif (value) {\nkernel/bpf/bpf_local_storage.c:86:\t\t\t/* No need to call check_and_init_map_value as memory is zero init */\nkernel/bpf/bpf_local_storage.c-87-\t\t\tcopy_map_value(\u0026smap-\u003emap, SDATA(selem)-\u003edata, value);\n--\nkernel/bpf/hashtab.c=1681=static int __htab_map_lookup_and_delete_elem(struct bpf_map *map, void *key,\n--\nkernel/bpf/hashtab.c-1716-\t\t\tcopy_map_value_long(\u0026htab-\u003emap, value + off, per_cpu_ptr(pptr, cpu));\nkernel/bpf/hashtab.c:1717:\t\t\tcheck_and_init_map_value(\u0026htab-\u003emap, value + off);\nkernel/bpf/hashtab.c-1718-\t\t\toff += roundup_value_size;\n--\nkernel/bpf/hashtab.c-1727-\t\t/* Zeroing special fields in the temp buffer */\nkernel/bpf/hashtab.c:1728:\t\tcheck_and_init_map_value(map, value);\nkernel/bpf/hashtab.c-1729-\t}\n--\nkernel/bpf/hashtab.c=1776=__htab_map_lookup_and_delete_batch(struct bpf_map *map,\n--\nkernel/bpf/hashtab.c-1913-\t\t\t\tcopy_map_value(\u0026htab-\u003emap, dst_val, per_cpu_ptr(pptr, cpu));\nkernel/bpf/hashtab.c:1914:\t\t\t\tcheck_and_init_map_value(\u0026htab-\u003emap, dst_val);\nkernel/bpf/hashtab.c-1915-\t\t\t} else {\n--\nkernel/bpf/hashtab.c-1918-\t\t\t\t\t\t\t    per_cpu_ptr(pptr, cpu));\nkernel/bpf/hashtab.c:1919:\t\t\t\t\tcheck_and_init_map_value(\u0026htab-\u003emap, dst_val + off);\nkernel/bpf/hashtab.c-1920-\t\t\t\t\toff += size;\n--\nkernel/bpf/hashtab.c-1938-\t\t\t/* Zeroing special fields in the temp buffer */\nkernel/bpf/hashtab.c:1939:\t\t\tcheck_and_init_map_value(map, dst_val);\nkernel/bpf/hashtab.c-1940-\t\t}\n--\nkernel/bpf/hashtab.c=2172=static int __bpf_hash_map_seq_show(struct seq_file *seq, struct htab_elem *elem)\n--\nkernel/bpf/hashtab.c-2197-\t\t\t\t\t\t\t    per_cpu_ptr(pptr, cpu));\nkernel/bpf/hashtab.c:2198:\t\t\t\t\tcheck_and_init_map_value(map, info-\u003epercpu_value_buf + off);\nkernel/bpf/hashtab.c-2199-\t\t\t\t\toff += roundup_value_size;\n--\nkernel/bpf/hashtab.c=2479=int bpf_percpu_hash_copy(struct bpf_map *map, void *key, void *value, u64 map_flags)\n--\nkernel/bpf/hashtab.c-2503-\t\tcopy_map_value(map, value, per_cpu_ptr(pptr, cpu));\nkernel/bpf/hashtab.c:2504:\t\tcheck_and_init_map_value(map, value);\nkernel/bpf/hashtab.c-2505-\t\tgoto out;\n--\nkernel/bpf/hashtab.c-2508-\t\tcopy_map_value_long(map, value + off, per_cpu_ptr(pptr, cpu));\nkernel/bpf/hashtab.c:2509:\t\tcheck_and_init_map_value(map, value + off);\nkernel/bpf/hashtab.c-2510-\t\toff += size;\n--\nkernel/bpf/hashtab.c=2933=static int rhtab_delete_elem(struct bpf_rhtab *rhtab, struct rhtab_elem *elem, void *copy,\n--\nkernel/bpf/hashtab.c-2957-\t\trhtab_read_elem_value(\u0026rhtab-\u003emap, copy, elem, flags);\nkernel/bpf/hashtab.c:2958:\t\tcheck_and_init_map_value(\u0026rhtab-\u003emap, copy);\nkernel/bpf/hashtab.c-2959-\t}\n--\nkernel/bpf/hashtab.c=3238=static int __rhtab_map_lookup_and_delete_batch(struct bpf_map *map,\n--\nkernel/bpf/hashtab.c-3318-\t\trhtab_read_elem_value(map, dst_val, elem, elem_map_flags);\nkernel/bpf/hashtab.c:3319:\t\tcheck_and_init_map_value(map, dst_val);\nkernel/bpf/hashtab.c-3320-\n--\nkernel/bpf/local_storage.c=144=static long cgroup_storage_update_elem(struct bpf_map *map, void *key,\n--\nkernel/bpf/local_storage.c-173-\tmemcpy(\u0026new-\u003edata[0], value, map-\u003evalue_size);\nkernel/bpf/local_storage.c:174:\tcheck_and_init_map_value(map, new-\u003edata);\nkernel/bpf/local_storage.c-175-\n--\nkernel/bpf/local_storage.c=504=struct bpf_cgroup_storage *bpf_cgroup_storage_alloc(struct bpf_prog *prog,\n--\nkernel/bpf/local_storage.c-528-\t\t\tgoto enomem;\nkernel/bpf/local_storage.c:529:\t\tcheck_and_init_map_value(map, storage-\u003ebuf-\u003edata);\nkernel/bpf/local_storage.c-530-\t} else {\n--\nkernel/bpf/syscall.c=308=static int bpf_map_copy_value(struct bpf_map *map, void *key, void *value,\n--\nkernel/bpf/syscall.c-357-\t\t\t/* mask lock and timer, since value wasn't zero inited */\nkernel/bpf/syscall.c:358:\t\t\tcheck_and_init_map_value(map, value);\nkernel/bpf/syscall.c-359-\t\t}\n--\nnet/core/bpf_sk_storage.c=532=static int diag_get(struct bpf_local_storage_map *smap,\n--\nnet/core/bpf_sk_storage.c-557-\t\tcopy_map_value(\u0026smap-\u003emap, nla_data(nla_value), sdata-\u003edata);\nnet/core/bpf_sk_storage.c:558:\tcheck_and_init_map_value(\u0026smap-\u003emap, nla_data(nla_value));\nnet/core/bpf_sk_storage.c-559-\n--\ntools/testing/selftests/bpf/prog_tests/lru_bug.c=6=void test_lru_bug(void)\n--\ntools/testing/selftests/bpf/prog_tests/lru_bug.c-17-\tusleep(1);\ntools/testing/selftests/bpf/prog_tests/lru_bug.c:18:\tASSERT_OK(skel-\u003edata-\u003eresult, \"prealloc_lru_pop doesn't call check_and_init_map_value\");\ntools/testing/selftests/bpf/prog_tests/lru_bug.c-19-end:\n"
}

61/3 2026/09/23 19:47 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 49561
							output: 36
							thoughts: 63
						

Thoughts:
Here's my analysis of the provided code snippet:

**Diving into BPF Initialization**

Okay, so I'm focusing on the initialization procedures within the BPF framework. My interest is piqued by `check_and_init_map_value` and `bpf_obj_init`, both defined in `include/linux/bpf.h`. I'm starting by zeroing in on lines 530 through 560 of that header file. My goal is to grasp how BPF map values are validated and initialized, and also how BPF objects in general are set up. I need to understand the fundamental mechanics, so I'm looking for the core logic surrounding these critical initialization routines. This is likely where the foundation of any subsequent BPF operations is laid, so this area is clearly worth dissecting.



62/3 2026/09/23 19:47 tool read-file
0m Args:
{
  "File": "include/linux/bpf.h",
  "FirstLine": 530,
  "LineCount": 30
}

Results:
{
  "Contents": " 530:\t\t\t\treturn true;\n 531:\t\t}\n 532:\t\treturn false;\n 533:\t}\n 534:\t\n 535:\tstatic inline void bpf_obj_init(const struct btf_record *rec, void *obj)\n 536:\t{\n 537:\t\tint i;\n 538:\t\n 539:\t\tif (IS_ERR_OR_NULL(rec))\n 540:\t\t\treturn;\n 541:\t\tfor (i = 0; i \u003c rec-\u003ecnt; i++)\n 542:\t\t\tbpf_obj_init_field(\u0026rec-\u003efields[i], obj + rec-\u003efields[i].offset);\n 543:\t}\n 544:\t\n 545:\t/* 'dst' must be a temporary buffer and should not point to memory that is being\n 546:\t * used in parallel by a bpf program or bpf syscall, otherwise the access from\n 547:\t * the bpf program or bpf syscall may be corrupted by the reinitialization,\n 548:\t * leading to weird problems. Even 'dst' is newly-allocated from bpf memory\n 549:\t * allocator, it is still possible for 'dst' to be used in parallel by a bpf\n 550:\t * program or bpf syscall.\n 551:\t */\n 552:\tstatic inline void check_and_init_map_value(struct bpf_map *map, void *dst)\n 553:\t{\n 554:\t\tbpf_obj_init(map-\u003erecord, dst);\n 555:\t}\n 556:\t\n 557:\t/* memcpy that is used with 8-byte aligned pointers, power-of-8 size and\n 558:\t * forced to use 'long' read/writes to try to atomically copy long counters.\n 559:\t * Best-effort only.  No barriers here, since it _will_ race with concurrent\n"
}

63/3 2026/09/23 19:47 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 50346
							output: 34
							thoughts: 292
						

Thoughts:
**My Analysis of the `bpf_rcu_head` Zeroing Issue**

Okay, so I'm digging into this BPF code, specifically the map handling. `check_and_init_map_value` is the culprit here, calling `bpf_obj_init`. Within that function, we get to the core problem: `bpf_obj_init_field` is called and, critically, uses `memset` to zero out the field's memory. This seems fine *until* you consider the `bpf_rcu_head` struct. The code path includes a `memset(addr, 0, field->size);` which, in the case of `bpf_rcu_head`, zeroes out the entire 64-byte structure.

Now, the issue is becoming clear. When `map_lookup_elem` is called (specifically for the temp buffer `value`), `check_and_init_map_value` is called. This initialization is happening BEFORE data is copied to userspace, which means that `bpf_rcu_head` is getting zeroed before a program can even read it!

I need to confirm this assumption. To do that, I'll need to go to `kernel/bpf/syscall.c` and verify how `map_lookup_elem` copies values to userspace.



64/3 2026/09/23 19:47 tool grepper
0m Args:
{
  "Expression": "map_lookup_elem\\(",
  "PathPrefix": "kernel/bpf/syscall.c"
}

Results:
{
  "Output": "kernel/bpf/syscall.c=308=static int bpf_map_copy_value(struct bpf_map *map, void *key, void *value,\n--\nkernel/bpf/syscall.c-327-\t} else if (IS_FD_ARRAY(map) || IS_FD_PROG_ARRAY(map)) {\nkernel/bpf/syscall.c:328:\t\terr = bpf_fd_array_map_lookup_elem(map, key, value);\nkernel/bpf/syscall.c-329-\t} else if (IS_FD_HASH(map)) {\nkernel/bpf/syscall.c:330:\t\terr = bpf_fd_htab_map_lookup_elem(map, key, value);\nkernel/bpf/syscall.c-331-\t} else if (map-\u003emap_type == BPF_MAP_TYPE_REUSEPORT_SOCKARRAY) {\n--\nkernel/bpf/syscall.c-344-\t\telse\nkernel/bpf/syscall.c:345:\t\t\tptr = map-\u003eops-\u003emap_lookup_elem(map, key);\nkernel/bpf/syscall.c-346-\t\tif (IS_ERR(ptr)) {\n--\nkernel/bpf/syscall.c=1784=static void *___bpf_copy_key(bpfptr_t ukey, u64 key_size)\n--\nkernel/bpf/syscall.c-1797-\nkernel/bpf/syscall.c:1798:static int map_lookup_elem(union bpf_attr *attr)\nkernel/bpf/syscall.c-1799-{\n--\nkernel/bpf/syscall.c=6316=static int __sys_bpf(enum bpf_cmd cmd, bpfptr_t uattr, unsigned int size,\n--\nkernel/bpf/syscall.c-6359-\tcase BPF_MAP_LOOKUP_ELEM:\nkernel/bpf/syscall.c:6360:\t\terr = map_lookup_elem(\u0026attr);\nkernel/bpf/syscall.c-6361-\t\tbreak;\n"
}

65/3 2026/09/23 19:47 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 51495
							output: 37
							thoughts: 29
						

Thoughts:
Okay, let's dive into this. Here's my thought process as I approach this code:

**Diving into `map_lookup_elem` in `kernel/bpf/syscall.c`**

Alright, I'm going to navigate to `kernel/bpf/syscall.c` and specifically look at the vicinity of line 1798. That's where `map_lookup_elem` is defined. I know this function is crucial for BPF map lookups within the kernel, so understanding its implementation is essential for diagnosing potential issues or comprehending kernel behavior related to BPF programs. I expect it to handle the core logic of retrieving an element from a specified BPF map based on a provided key. I'll be looking for things like argument validation, map access, potential error handling, any locking mechanisms used to ensure thread safety, and how it interacts with the underlying map data structures. I'll pay attention to the return values and any implications they might have on the calling BPF program or system calls. I am ready to deep dive.



66/3 2026/09/23 19:47 tool read-file
0m Args:
{
  "File": "kernel/bpf/syscall.c",
  "FirstLine": 1798,
  "LineCount": 40
}

Results:
{
  "Contents": "1798:\tstatic int map_lookup_elem(union bpf_attr *attr)\n1799:\t{\n1800:\t\tvoid __user *ukey = u64_to_user_ptr(attr-\u003ekey);\n1801:\t\tvoid __user *uvalue = u64_to_user_ptr(attr-\u003evalue);\n1802:\t\tstruct bpf_map *map;\n1803:\t\tvoid *key, *value;\n1804:\t\tu32 value_size;\n1805:\t\tint err;\n1806:\t\n1807:\t\tif (CHECK_ATTR(BPF_MAP_LOOKUP_ELEM))\n1808:\t\t\treturn -EINVAL;\n1809:\t\n1810:\t\tCLASS(fd, f)(attr-\u003emap_fd);\n1811:\t\tmap = __bpf_map_get(f);\n1812:\t\tif (IS_ERR(map))\n1813:\t\t\treturn PTR_ERR(map);\n1814:\t\tif (!(map_get_sys_perms(map, f) \u0026 FMODE_CAN_READ))\n1815:\t\t\treturn -EPERM;\n1816:\t\n1817:\t\terr = bpf_map_check_op_flags(map, attr-\u003eflags, BPF_F_LOCK | BPF_F_CPU);\n1818:\t\tif (err)\n1819:\t\t\treturn err;\n1820:\t\n1821:\t\tkey = __bpf_copy_key(ukey, map-\u003ekey_size);\n1822:\t\tif (IS_ERR(key))\n1823:\t\t\treturn PTR_ERR(key);\n1824:\t\n1825:\t\tvalue_size = bpf_map_value_size(map, attr-\u003eflags);\n1826:\t\n1827:\t\terr = -ENOMEM;\n1828:\t\tvalue = kvmalloc(value_size, GFP_USER | __GFP_NOWARN);\n1829:\t\tif (!value)\n1830:\t\t\tgoto free_key;\n1831:\t\n1832:\t\tif (map-\u003emap_type == BPF_MAP_TYPE_BLOOM_FILTER) {\n1833:\t\t\tif (copy_from_user(value, uvalue, value_size))\n1834:\t\t\t\terr = -EFAULT;\n1835:\t\t\telse\n1836:\t\t\t\terr = bpf_map_copy_value(map, key, value, attr-\u003eflags);\n1837:\t\t\tgoto free_value;\n"
}

67/3 2026/09/23 19:47 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 52451
							output: 37
							thoughts: 14
						

Thoughts:
Okay, here's my attempt at summarizing the thought process, tailored for an expert audience, and written in the first person:

**Diving into `map_lookup_elem`**

Alright, let's get into the nitty-gritty. I've been focusing on this particular function, `map_lookup_elem`, and I want to really understand its full operation. The context is important here; I need to see the rest of the code that defines its behavior. I know what the surface level looks like, but I need the broader picture. My mind is already running through possible edge cases and performance implications based on the data structures it uses, so knowing the specifics of the surrounding code is key to a complete understanding. I'm especially interested in how it handles missing keys, and what optimizations might be in place for common access patterns. Let's dig in and see what we can find.



68/3 2026/09/23 19:47 tool read-file
0m Args:
{
  "File": "kernel/bpf/syscall.c",
  "FirstLine": 1838,
  "LineCount": 25
}

Results:
{
  "Contents": "1838:\t\t}\n1839:\t\n1840:\t\terr = bpf_map_copy_value(map, key, value, attr-\u003eflags);\n1841:\t\tif (err)\n1842:\t\t\tgoto free_value;\n1843:\t\n1844:\t\terr = -EFAULT;\n1845:\t\tif (copy_to_user(uvalue, value, value_size) != 0)\n1846:\t\t\tgoto free_value;\n1847:\t\n1848:\t\terr = 0;\n1849:\t\n1850:\tfree_value:\n1851:\t\tkvfree(value);\n1852:\tfree_key:\n1853:\t\tkvfree(key);\n1854:\t\treturn err;\n1855:\t}\n1856:\t\n1857:\t#define BPF_MAP_UPDATE_ELEM_LAST_FIELD flags\n1858:\t\n1859:\tstatic int map_update_elem(union bpf_attr *attr, bpfptr_t uattr)\n1860:\t{\n1861:\t\tbpfptr_t ukey = make_bpfptr(attr-\u003ekey, uattr.is_kernel);\n1862:\t\tbpfptr_t uvalue = make_bpfptr(attr-\u003evalue, uattr.is_kernel);\n"
}

69/3 2026/09/23 19:47 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 53060
							output: 37
							thoughts: 2278
						

Thoughts:
**Deep Dive into Potential Uninitialized Memory Exposure in BPF Maps**

Okay, let's break this down. My initial thought process focused on the memory initialization within `map_lookup_elem`. I immediately honed in on the allocation with `kvmalloc`, noting that it *doesn't* zero initialize the memory, unlike `kvzalloc`. This triggered an alarm because the subsequent `bpf_map_copy_value` function seemed like a potential weak spot. Specifically, `copy_map_value` calls `bpf_obj_memcpy`, which, at first glance, *appeared* to copy *everything* from the source (`ptr`) to the destination (`value`), which is what I thought, before going further in the code. I followed the flow further, and found that that was NOT the case, and there was also the potential that some bytes could be left uninitialized.

However, after a bit more digging, I found `bpf_obj_memcpy` doesn't do a full copy! It seems to skip over the offsets defined by `rec->fields[i]`. But THEN, it calls `check_and_init_map_value`, which *should* solve the problem, by calling `bpf_obj_init`.

`bpf_obj_init` iterates through fields and calls `bpf_obj_init_field` which then uses `memset` to zero out each individual field of `dst`.
Great, so that zeroes the field, which takes care of potentially uninitialized memory within the map *value* structure itself. However, I need to verify that this logic holds up in all places where it is called!

So, the next step is to ensure that `check_and_init_map_value` is ALWAYS called after any potential memory copies. So, I ran through the patch files. In `kernel/bpf/helpers.c`, there's a callback within the rcu functionality, which requires review.

The `bpf_rcu_run_callback` function passes `map`, `key`, and `value` to the callback function.
Then I focused on the verifier output for this:
In `set_rcu_callback_state`, I see that the verifier marks registers R1, R2, and R3 as `CONST_PTR_TO_MAP`, `PTR_TO_MAP_KEY`, and `PTR_TO_MAP_VALUE` respectively, which means that the verifier is aware of what's passed.
`PTR_TO_MAP_KEY` should be safe!

The next question: Let's check how big is the key in an array map.

In BPF, array maps always have `key_size == 4` (u32)! This looks good.



70/3 2026/09/23 19:47 tool grepper
0m Error:
no matches

Args:
{
  "Expression": "map-\u003ekey_size != 4",
  "PathPrefix": "kernel/bpf/arraymap.c"
}

Results:
{
  "error": "no matches"
}

71/3 2026/09/23 19:47 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 55977
							output: 32
							thoughts: 23
						

Thoughts:
Okay, here's my take on those thoughts, tailored for an expert audience:

**Diving into `array_map_alloc`**

Alright, let's get down to brass tacks. I need to get a handle on what's happening with array maps from the kernel's perspective, so I'm heading directly into `kernel/bpf/arraymap.c` to examine `array_map_alloc`. I need to review the allocation logic. I need to look closely at memory management, error handling, and of course, the general design and behavior. I'm hoping I can trace any performance bottlenecks. It will be useful to understand its interactions with the BPF subsystem, especially since any issues there can be tricky to debug.



72/3 2026/09/23 19:48 tool grepper
0m Args:
{
  "Expression": "key_size",
  "PathPrefix": "kernel/bpf/arraymap.c"
}

Results:
{
  "Output": "kernel/bpf/arraymap.c=53=int array_map_alloc_check(union bpf_attr *attr)\n--\nkernel/bpf/arraymap.c-58-\t/* check sanity of attributes */\nkernel/bpf/arraymap.c:59:\tif (attr-\u003emax_entries == 0 || attr-\u003ekey_size != 4 ||\nkernel/bpf/arraymap.c-60-\t    attr-\u003evalue_size == 0 ||\n"
}

73/3 2026/09/23 19:48 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 56316
							output: 37
							thoughts: 177
						

Thoughts:
Okay, let's see. My initial thought is a definitive "Yes!" That check, `attr->key_size != 4`, is precisely what I expect to be in place to reject array maps in this context! The reason is straightforward: I see `idx` is declared as `u32 idx;`, which is 4 bytes. And, crucially, `*arr_idx` is what `map_key_from_value` writes to memory.

Therefore, when the BPF program attempts to read from register R2 which contains the key, it's effectively reading that initialized `idx` value, which is exactly 4 bytes.

But then a new thought surfaces: hold on... what if the program tries to sneak in a read of *more* than 4 bytes from R2? That's the question I have to ask myself. 

The good news is, I'm pretty sure the verifier has a check for precisely this scenario. It should verify any memory accesses to `PTR_TO_MAP_KEY` against `map->key_size`, which, in this case, we know is *guaranteed* to be 4!

Time to confirm my suspicions. I'll need to go directly to the source. Specifically, I should be looking at `kernel/bpf/verifier.c` in the kernel source code, around line 4399 where memory access checks happen.

Let's read the code and get to the bottom of this.



74/3 2026/09/23 19:48 tool read-file
0m Args:
{
  "File": "kernel/bpf/verifier.c",
  "FirstLine": 4395,
  "LineCount": 20
}

Results:
{
  "Contents": "4395:\t\tif (off \u003e= 0 \u0026\u0026 size_ok \u0026\u0026 (u64)off + size \u003c= mem_size)\n4396:\t\t\treturn 0;\n4397:\t\n4398:\t\tswitch (reg-\u003etype) {\n4399:\t\tcase PTR_TO_MAP_KEY:\n4400:\t\t\tverbose(env, \"invalid access to map key, key_size=%d off=%d size=%d\\n\",\n4401:\t\t\t\tmem_size, off, size);\n4402:\t\t\tbreak;\n4403:\t\tcase PTR_TO_MAP_VALUE:\n4404:\t\t\tverbose(env, \"invalid access to map value, value_size=%d off=%d size=%d\\n\",\n4405:\t\t\t\tmem_size, off, size);\n4406:\t\t\tbreak;\n4407:\t\tcase PTR_TO_PACKET:\n4408:\t\tcase PTR_TO_PACKET_META:\n4409:\t\tcase PTR_TO_PACKET_END:\n4410:\t\t\tverbose(env, \"invalid access to packet, off=%d size=%d, %s(id=%d,off=%d,r=%d)\\n\",\n4411:\t\t\t\toff, size, reg_arg_name(env, argno), reg-\u003eid, off, mem_size);\n4412:\t\t\tbreak;\n4413:\t\tcase PTR_TO_CTX:\n4414:\t\t\tverbose(env, \"invalid access to context, ctx_size=%d off=%d size=%d\\n\",\n"
}

75/3 2026/09/23 19:48 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 57241
							output: 32
							thoughts: 308
						

Thoughts:
**Analyzing BPF Map Value Access**

Okay, let's break down how we're handling memory access within this BPF environment. My immediate concern centers around how the verifier ensures safe access to map values, specifically considering the `bpf_rcu_head` struct and other special fields, especially given `PTR_TO_MAP_VALUE`. I see that `check_mem_access` is performing the core bounds checking, making sure that `off` (offset) and `size` are within the valid memory region, which, in this case, appears to be determined by `reg->map_ptr->key_size` (4 bytes). Good, that's the basic sanity check.

Now, the code explicitly rejects writes to `PTR_TO_MAP_KEY`. That makes sense; we don't want programs mucking with the map's keys directly. That's a solid security measure, but what about the value side? My thought process goes directly to asking what's the deal with `PTR_TO_MAP_VALUE` and if we can modify the contents of the `bpf_rcu_head` struct, or indeed, any other struct fields in the map value. Given that `value` seems to point to the array element value and those elements are `kzalloc`'d, it's a good starting point, but I need to dig deeper.

Specifically, I'm thinking about the implications for concurrent access and data races. Are there any restrictions on what a BPF program can *do* with the `bpf_rcu_head` field itself? Can it read, write, or modify it? Are there other special fields, like `BPF_TIMER`, `BPF_TASK_WORK`, or `BPF_WORKQUEUE` that might also be present in map values?

To answer this, my next step is clear. I need to dive into `kernel/bpf/verifier.c`. I'll search for how the verifier handles accesses to those special fields. Finding how the verifier specifically handles these types of fields, whether they're disallowed, restricted, or allowed under specific constraints, will give me a better understanding of the overall memory safety guarantees. This will be the key to understanding if we have any vulnerabilities here.



76/3 2026/09/23 19:48 tool grepper
0m Args:
{
  "Expression": "BPF_TIMER",
  "PathPrefix": "kernel/bpf/verifier.c"
}

Results:
{
  "Output": "kernel/bpf/verifier.c=1978=static void refine_map_lookup_value(struct bpf_reg_state *reg)\n--\nkernel/bpf/verifier.c-1989-\t\tif (btf_record_has_field(map-\u003einner_map_meta-\u003erecord,\nkernel/bpf/verifier.c:1990:\t\t\t\t\t BPF_TIMER | BPF_WORKQUEUE | BPF_TASK_WORK))\nkernel/bpf/verifier.c-1991-\t\t\treg-\u003emap_uid = reg-\u003eid;\n--\nkernel/bpf/verifier.c=7566=static int check_map_field_pointer(struct bpf_verifier_env *env, struct bpf_reg_state *reg, argno_t argno,\n--\nkernel/bpf/verifier.c-7591-\tswitch (field_type) {\nkernel/bpf/verifier.c:7592:\tcase BPF_TIMER:\nkernel/bpf/verifier.c-7593-\t\tfield_off = map-\u003erecord-\u003etimer_off;\n--\nkernel/bpf/verifier.c=7622=static int process_timer_func(struct bpf_verifier_env *env, struct bpf_reg_state *reg, argno_t argno,\n--\nkernel/bpf/verifier.c-7628-\t}\nkernel/bpf/verifier.c:7629:\treturn check_map_field_pointer(env, reg, argno, BPF_TIMER, map);\nkernel/bpf/verifier.c-7630-}\n"
}

77/3 2026/09/23 19:48 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 58463
							output: 33
							thoughts: 37
						

Thoughts:
Okay, here's my take on those thoughts, tailored for an expert audience:

**Investigating Map Value Field Access in the BPF Verifier**

Alright, let's dive into the BPF verifier. I need to understand how the kernel handles access checks for specific fields within a map's value. The logical place to start is `kernel/bpf/verifier.c`. I'm going to search directly for the string `check_map_access`. That identifier is the most likely candidate for the function or functions that perform those checks. Hopefully, a direct search will quickly lead me to the relevant code paths, and I can then analyze the surrounding logic to understand the specific rules and how they're enforced. I'm especially interested in the nuances of access restrictions based on map type, the context of the BPF program, and any potential security implications.



78/3 2026/09/23 19:48 tool grepper
0m Args:
{
  "Expression": "check_map_access",
  "PathPrefix": "kernel/bpf/verifier.c"
}

Results:
{
  "Output": "kernel/bpf/verifier.c=4358=static struct bpf_reg_state *get_func_arg_reg(struct bpf_func_state *caller,\n--\nkernel/bpf/verifier.c-4366-\nkernel/bpf/verifier.c:4367:static int check_map_access_type(struct bpf_verifier_env *env, struct bpf_reg_state *reg,\nkernel/bpf/verifier.c-4368-\t\t\t\t int off, int size, enum bpf_access_type type)\n--\nkernel/bpf/verifier.c=4747=static int check_map_kptr_access(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-4755-\nkernel/bpf/verifier.c:4756:\t/* Things we already checked for in check_map_access and caller:\nkernel/bpf/verifier.c-4757-\t *  - Reject cases where variable offset may touch kptr\n--\nkernel/bpf/verifier.c=4822=static u32 map_mem_size(const struct bpf_map *map)\n--\nkernel/bpf/verifier.c-4830-/* check read/write into a map element with possible variable offset */\nkernel/bpf/verifier.c:4831:static int check_map_access(struct bpf_verifier_env *env, struct bpf_reg_state *reg, argno_t argno,\nkernel/bpf/verifier.c-4832-\t\t\t    int off, int size, bool zero_size_allowed,\n--\nkernel/bpf/verifier.c=6476=static int check_mem_access(struct bpf_verifier_env *env, int insn_idx, struct bpf_reg_state *reg, argno_t argno,\n--\nkernel/bpf/verifier.c-6512-\t\t}\nkernel/bpf/verifier.c:6513:\t\terr = check_map_access_type(env, reg, off, size, t);\nkernel/bpf/verifier.c-6514-\t\tif (err)\nkernel/bpf/verifier.c-6515-\t\t\treturn err;\nkernel/bpf/verifier.c:6516:\t\terr = check_map_access(env, reg, argno, off, size, false, ACCESS_DIRECT);\nkernel/bpf/verifier.c-6517-\t\tif (err)\n--\nkernel/bpf/verifier.c=7108=static int check_helper_mem_access(struct bpf_verifier_env *env, struct bpf_reg_state *reg,\n--\nkernel/bpf/verifier.c-7136-\tcase PTR_TO_MAP_VALUE:\nkernel/bpf/verifier.c:7137:\t\tif (check_map_access_type(env, reg, 0, access_size, access_type))\nkernel/bpf/verifier.c-7138-\t\t\treturn -EACCES;\nkernel/bpf/verifier.c:7139:\t\treturn check_map_access(env, reg, argno, 0, access_size,\nkernel/bpf/verifier.c-7140-\t\t\t\t\tzero_size_allowed, ACCESS_HELPER);\n--\nkernel/bpf/verifier.c=8758=static int check_arg_const_str(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-8796-\nkernel/bpf/verifier.c:8797:\terr = check_map_access(env, reg, argno, 0,\nkernel/bpf/verifier.c-8798-\t\t\t       map-\u003evalue_size - reg-\u003evar_off.value, false,\n--\nkernel/bpf/verifier.c=11571=static int check_helper_call(struct bpf_verifier_env *env, struct bpf_insn *insn,\n--\nkernel/bpf/verifier.c-11852-\t\tmark_reg_known_zero(env, regs, BPF_REG_0);\nkernel/bpf/verifier.c:11853:\t\t/* remember map_ptr, so that check_map_access()\nkernel/bpf/verifier.c-11854-\t\t * can check 'value_size' boundary of memory access\n--\nkernel/bpf/verifier.c=14999=static int sanitize_check_bounds(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-15017-\tcase PTR_TO_MAP_VALUE:\nkernel/bpf/verifier.c:15018:\t\tif (check_map_access(env, dst_reg, argno_from_reg(dst), 0, 1, false, ACCESS_HELPER)) {\nkernel/bpf/verifier.c-15019-\t\t\tverbose(env, \"R%d pointer arithmetic of map value goes out of range, \"\n"
}

79/3 2026/09/23 19:48 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 59956
							output: 37
							thoughts: 24
						

Thoughts:
Okay, let's dive into this. Here's how I'd approach this task, as if these were my internal thoughts:

**Analyzing `check_map_access_type` in `kernel/bpf/verifier.c`**

Alright, time to get my hands dirty. I need to take a look at the `check_map_access_type` function, and it lives in `kernel/bpf/verifier.c`. This suggests we're dealing with the BPF verifier, and specifically, how it's validating map accesses. This is a critical area, as improper map access is a common source of security vulnerabilities and runtime errors in BPF programs. My immediate assumption is that this function's purpose is to ensure that a BPF program is using a map in a safe and authorized way. This could involve checking for things like:

*   **Valid Map Types**: Does the program try to use the map in a manner consistent with its defined type (e.g., trying to do a `BPF_MAP_TYPE_HASH` operation on a `BPF_MAP_TYPE_ARRAY`)?
*   **Permitted Access Types**: Does the program attempt operations which are invalid for the map? For instance, writing to a read-only map, or attempting to read beyond the map bounds.
*   **Key and Value Size Consistency**: This is important. Do the size of the keys and values being used in the access operation match what the map was initialized with? Incorrect sizes can lead to memory corruption.
*   **Contextual Validation**: Is the map access occurring in a valid context for the type of program? For example, is it a valid operation to make in the current BPF program type?
*   **Pointer Validation**: If pointers are involved (as they often are in map value manipulation), are the pointers valid? This can involve ensuring they are within bounds.

I'll be looking for how the function enforces these checks and what kinds of errors it might report. The specifics of the implementation should reveal which aspects of map access this function prioritizes. Time to jump into the code and see what's actually going on in there.



80/3 2026/09/23 19:48 tool read-file
0m Args:
{
  "File": "kernel/bpf/verifier.c",
  "FirstLine": 4367,
  "LineCount": 40
}

Results:
{
  "Contents": "4367:\tstatic int check_map_access_type(struct bpf_verifier_env *env, struct bpf_reg_state *reg,\n4368:\t\t\t\t\t int off, int size, enum bpf_access_type type)\n4369:\t{\n4370:\t\tstruct bpf_map *map = reg-\u003emap_ptr;\n4371:\t\tu32 cap = bpf_map_flags_to_cap(map);\n4372:\t\n4373:\t\tif (type == BPF_WRITE \u0026\u0026 !(cap \u0026 BPF_MAP_CAN_WRITE)) {\n4374:\t\t\tverbose(env, \"write into map forbidden, value_size=%d off=%lld size=%d\\n\",\n4375:\t\t\t\tmap-\u003evalue_size, reg_smin(reg) + off, size);\n4376:\t\t\treturn -EACCES;\n4377:\t\t}\n4378:\t\n4379:\t\tif (type == BPF_READ \u0026\u0026 !(cap \u0026 BPF_MAP_CAN_READ)) {\n4380:\t\t\tverbose(env, \"read from map forbidden, value_size=%d off=%lld size=%d\\n\",\n4381:\t\t\t\tmap-\u003evalue_size, reg_smin(reg) + off, size);\n4382:\t\t\treturn -EACCES;\n4383:\t\t}\n4384:\t\n4385:\t\treturn 0;\n4386:\t}\n4387:\t\n4388:\t/* check read/write into memory region (e.g., map value, ringbuf sample, etc) */\n4389:\tstatic int __check_mem_access(struct bpf_verifier_env *env, struct bpf_reg_state *reg, argno_t argno,\n4390:\t\t\t\t      int off, int size, u32 mem_size,\n4391:\t\t\t\t      bool zero_size_allowed)\n4392:\t{\n4393:\t\tbool size_ok = size \u003e 0 || (size == 0 \u0026\u0026 zero_size_allowed);\n4394:\t\n4395:\t\tif (off \u003e= 0 \u0026\u0026 size_ok \u0026\u0026 (u64)off + size \u003c= mem_size)\n4396:\t\t\treturn 0;\n4397:\t\n4398:\t\tswitch (reg-\u003etype) {\n4399:\t\tcase PTR_TO_MAP_KEY:\n4400:\t\t\tverbose(env, \"invalid access to map key, key_size=%d off=%d size=%d\\n\",\n4401:\t\t\t\tmem_size, off, size);\n4402:\t\t\tbreak;\n4403:\t\tcase PTR_TO_MAP_VALUE:\n4404:\t\t\tverbose(env, \"invalid access to map value, value_size=%d off=%d size=%d\\n\",\n4405:\t\t\t\tmem_size, off, size);\n4406:\t\t\tbreak;\n"
}

81/3 2026/09/23 19:48 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 61218
							output: 37
							thoughts: 22
						

Thoughts:
Here's my summary, as though I'm reading and thinking about the code:

**Diving into `check_map_access`**

Alright, let's get down to it. Time to dissect `check_map_access` in `kernel/bpf/verifier.c`. This is where the magic happens, or at least, the essential validation that prevents BPF programs from going rogue when interacting with maps. I want to understand how it ensures safe access. I need to figure out the checks for a given map access. What is the scope of the checks? What map types are being considered? How does it interact with the rest of the verifier to ensure that the memory access is safe? Specifically, what are the restrictions that are imposed on BPF programs when accessing maps? I need to understand it at the function level. Let's see how it handles the different types of map access, like reads, writes, and updates. I'm looking for the core logic, the crucial conditions, the potential pitfalls and how they're addressed. I expect this is where the map access permissions and safety are really fleshed out, and I'm eager to get a clearer picture of how the verifier guards against potential exploitation through map interaction.



82/3 2026/09/23 19:48 tool read-file
0m Args:
{
  "File": "kernel/bpf/verifier.c",
  "FirstLine": 4831,
  "LineCount": 70
}

Results:
{
  "Contents": "4831:\tstatic int check_map_access(struct bpf_verifier_env *env, struct bpf_reg_state *reg, argno_t argno,\n4832:\t\t\t\t    int off, int size, bool zero_size_allowed,\n4833:\t\t\t\t    enum bpf_access_src src)\n4834:\t{\n4835:\t\tstruct bpf_map *map = reg-\u003emap_ptr;\n4836:\t\tu32 mem_size = map_mem_size(map);\n4837:\t\tstruct btf_record *rec;\n4838:\t\tint err, i;\n4839:\t\n4840:\t\terr = check_mem_region_access(env, reg, argno, off, size, mem_size, zero_size_allowed);\n4841:\t\tif (err)\n4842:\t\t\treturn err;\n4843:\t\n4844:\t\tif (IS_ERR_OR_NULL(map-\u003erecord))\n4845:\t\t\treturn 0;\n4846:\t\trec = map-\u003erecord;\n4847:\t\tfor (i = 0; i \u003c rec-\u003ecnt; i++) {\n4848:\t\t\tstruct btf_field *field = \u0026rec-\u003efields[i];\n4849:\t\t\tu32 p = field-\u003eoffset;\n4850:\t\n4851:\t\t\t/* If any part of a field  can be touched by load/store, reject\n4852:\t\t\t * this program. To check that [x1, x2) overlaps with [y1, y2),\n4853:\t\t\t * it is sufficient to check x1 \u003c y2 \u0026\u0026 y1 \u003c x2.\n4854:\t\t\t */\n4855:\t\t\tif (reg_smin(reg) + off \u003c p + field-\u003esize \u0026\u0026\n4856:\t\t\t    p \u003c reg_umax(reg) + off + size) {\n4857:\t\t\t\tswitch (field-\u003etype) {\n4858:\t\t\t\tcase BPF_KPTR_UNREF:\n4859:\t\t\t\tcase BPF_KPTR_REF:\n4860:\t\t\t\tcase BPF_KPTR_PERCPU:\n4861:\t\t\t\tcase BPF_UPTR:\n4862:\t\t\t\t\tif (src != ACCESS_DIRECT) {\n4863:\t\t\t\t\t\tverbose(env, \"%s cannot be accessed indirectly by helper\\n\",\n4864:\t\t\t\t\t\t\tbtf_field_type_name(field-\u003etype));\n4865:\t\t\t\t\t\treturn -EACCES;\n4866:\t\t\t\t\t}\n4867:\t\t\t\t\tif (!tnum_is_const(reg-\u003evar_off)) {\n4868:\t\t\t\t\t\tverbose(env, \"%s access cannot have variable offset\\n\",\n4869:\t\t\t\t\t\t\tbtf_field_type_name(field-\u003etype));\n4870:\t\t\t\t\t\treturn -EACCES;\n4871:\t\t\t\t\t}\n4872:\t\t\t\t\tif (p != off + reg-\u003evar_off.value) {\n4873:\t\t\t\t\t\tverbose(env, \"%s access misaligned expected=%u off=%llu\\n\",\n4874:\t\t\t\t\t\t\tbtf_field_type_name(field-\u003etype),\n4875:\t\t\t\t\t\t\tp, off + reg-\u003evar_off.value);\n4876:\t\t\t\t\t\treturn -EACCES;\n4877:\t\t\t\t\t}\n4878:\t\t\t\t\tif (size != bpf_size_to_bytes(BPF_DW)) {\n4879:\t\t\t\t\t\tverbose(env, \"%s access size must be BPF_DW\\n\",\n4880:\t\t\t\t\t\t\tbtf_field_type_name(field-\u003etype));\n4881:\t\t\t\t\t\treturn -EACCES;\n4882:\t\t\t\t\t}\n4883:\t\t\t\t\tbreak;\n4884:\t\t\t\tdefault:\n4885:\t\t\t\t\tverbose(env, \"%s cannot be accessed directly by load/store\\n\",\n4886:\t\t\t\t\t\tbtf_field_type_name(field-\u003etype));\n4887:\t\t\t\t\treturn -EACCES;\n4888:\t\t\t\t}\n4889:\t\t\t}\n4890:\t\t}\n4891:\t\treturn 0;\n4892:\t}\n4893:\t\n4894:\tstatic bool may_access_direct_pkt_data(struct bpf_verifier_env *env,\n4895:\t\t\t\t       const struct bpf_call_arg_meta *meta,\n4896:\t\t\t\t       enum bpf_access_type t)\n4897:\t{\n4898:\t\tenum bpf_prog_type prog_type = resolve_prog_type(env-\u003eprog);\n4899:\t\n4900:\t\tswitch (prog_type) {\n"
}

83/3 2026/09/23 19:48 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 62720
							output: 37
							thoughts: 855
						

Thoughts:
**Analyzing `bpf_rcu_head` Accessibility in BPF Maps**

Okay, let's break down how a `bpf_rcu_head` field in a BPF map value is handled. First, I'm checking the `check_map_access` function. Looks like direct load/store operations on map values are restricted based on field type. Specifically, if a field is *not* a KPTR or UPTR (like our `BPF_RCU_HEAD`), the code hits the `default:` case, which spits out an error using `verbose()` and returns `-EACCES`. So, no direct access to `bpf_rcu_head` via BPF load/store is allowed.

Furthermore, `check_helper_mem_access` calls `check_map_access` with `ACCESS_HELPER`. Because the source is not `ACCESS_DIRECT`, the map access also returns `-EACCES`.  Therefore, neither direct load/store nor helper read/write are permitted for accessing the `bpf_rcu_head` field in the map value.

Alright, what about userspace access via `bpf_map_lookup_elem`? Tracing back through `syscall.c`, I see that `bpf_map_copy_value` utilizes `copy_map_value`. This function cleverly skips the `rec->fields` with `bpf_obj_memcpy` and *then* invokes `check_and_init_map_value`. This function ensures all `rec->fields` are zeroed out with `memset(addr, 0, field->size)`. This means that userspace will only ever read zeroes when reading a `struct bpf_rcu_head` field!

Now, the crucial question: what about `bpf_rcu_run_callback`? Let's refresh my understanding of how it works.  I'm rereading the function code. I'm noting that the callback function accesses the `bpf_rcu_head_kern` structure, which contains the callback function itself and the BPF program. I need to compare this with how related helper functions, like `bpf_task_work_callback`, `bpf_timer_cb` or `bpf_wq_work`, interact with the system. I'll read around line 4581 in `kernel/bpf/helpers.c` to see how the callback function actually works with the `bpf_rcu_head` data!



84/3 2026/09/23 19:48 tool read-file
0m Args:
{
  "File": "kernel/bpf/helpers.c",
  "FirstLine": 4580,
  "LineCount": 40
}

Results:
{
  "Contents": "4580:\t\n4581:\tstatic void bpf_task_work_callback(struct callback_head *cb)\n4582:\t{\n4583:\t\tstruct bpf_task_work_ctx *ctx = container_of(cb, struct bpf_task_work_ctx, work);\n4584:\t\tenum bpf_task_work_state state;\n4585:\t\tu32 idx;\n4586:\t\tvoid *key;\n4587:\t\n4588:\t\t/* Read lock is needed to protect ctx and map key/value access */\n4589:\t\tguard(rcu_tasks_trace)();\n4590:\t\t/*\n4591:\t\t * This callback may start running before bpf_task_work_irq() switched to\n4592:\t\t * SCHEDULED state, so handle both transition variants SCHEDULING|SCHEDULED -\u003e RUNNING.\n4593:\t\t */\n4594:\t\tstate = cmpxchg(\u0026ctx-\u003estate, BPF_TW_SCHEDULING, BPF_TW_RUNNING);\n4595:\t\tif (state == BPF_TW_SCHEDULED)\n4596:\t\t\tstate = cmpxchg(\u0026ctx-\u003estate, BPF_TW_SCHEDULED, BPF_TW_RUNNING);\n4597:\t\tif (state == BPF_TW_FREED) {\n4598:\t\t\tbpf_task_work_ctx_put(ctx);\n4599:\t\t\treturn;\n4600:\t\t}\n4601:\t\n4602:\t\tkey = (void *)map_key_from_value(ctx-\u003emap, ctx-\u003emap_val, \u0026idx);\n4603:\t\n4604:\t\tmigrate_disable();\n4605:\t\tctx-\u003ecallback_fn((u64)(long)ctx-\u003emap, (u64)(long)key,\n4606:\t\t\t\t (u64)(long)ctx-\u003emap_val, 0, 0);\n4607:\t\tmigrate_enable();\n4608:\t\n4609:\t\tbpf_task_work_ctx_reset(ctx);\n4610:\t\t(void)cmpxchg(\u0026ctx-\u003estate, BPF_TW_RUNNING, BPF_TW_STANDBY);\n4611:\t\n4612:\t\tbpf_task_work_ctx_put(ctx);\n4613:\t}\n4614:\t\n4615:\tstatic void bpf_task_work_irq(struct irq_work *irq_work)\n4616:\t{\n4617:\t\tstruct bpf_task_work_ctx *ctx = container_of(irq_work, struct bpf_task_work_ctx, irq_work);\n4618:\t\tenum bpf_task_work_state state;\n4619:\t\tint err;\n"
}

85/3 2026/09/23 19:48 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 64882
							output: 37
							thoughts: 24
						

Thoughts:
Okay, let's dive into this. Here's my summary, presented as my own thought process, aimed at an expert audience:

**Examining `bpf_timer_cb` in `kernel/bpf/helpers.c`**

Alright, given the context, I need to drill down into the internals of the BPF timer callback mechanism. It's imperative that I thoroughly examine the implementation of `bpf_timer_cb` within `kernel/bpf/helpers.c`. I need to understand exactly how the kernel handles the execution of BPF timers. I will need to understand its relationship to the underlying timer infrastructure and how it interacts with BPF programs. I need to dissect the context in which it's invoked, the arguments passed, and the actions it performs within the BPF framework. Understanding this is key to grasping the overall behavior and potential issues around BPF timer functionality.



86/3 2026/09/23 19:48 tool read-file
0m Args:
{
  "File": "kernel/bpf/helpers.c",
  "FirstLine": 1235,
  "LineCount": 25
}

Results:
{
  "Contents": "1235:\t\t/* bpf_timer_cb() runs in hrtimer_run_softirq. It doesn't migrate and\n1236:\t\t * cannot be preempted by another bpf_timer_cb() on the same cpu.\n1237:\t\t * Remember the timer this callback is servicing to prevent\n1238:\t\t * deadlock if callback_fn() calls bpf_timer_cancel() or\n1239:\t\t * bpf_map_delete_elem() on the same timer.\n1240:\t\t */\n1241:\t\tthis_cpu_write(hrtimer_running, t);\n1242:\t\n1243:\t\tkey = map_key_from_value(map, value, \u0026idx);\n1244:\t\n1245:\t\tcallback_fn((u64)(long)map, (u64)(long)key, (u64)(long)value, 0, 0);\n1246:\t\t/* The verifier checked that return value is zero. */\n1247:\t\n1248:\t\tthis_cpu_write(hrtimer_running, NULL);\n1249:\tout:\n1250:\t\treturn HRTIMER_NORESTART;\n1251:\t}\n1252:\t\n1253:\tstatic void bpf_wq_work(struct work_struct *work)\n1254:\t{\n1255:\t\tstruct bpf_work *w = container_of(work, struct bpf_work, work);\n1256:\t\tstruct bpf_async_cb *cb = \u0026w-\u003ecb;\n1257:\t\tstruct bpf_map *map = cb-\u003emap;\n1258:\t\tbpf_callback_t callback_fn;\n1259:\t\tvoid *value = cb-\u003evalue;\n"
}

87/3 2026/09/23 19:48 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 65592
							output: 22
							thoughts: 830
						

Thoughts:
**Analyzing BPF RCU Callback Execution and State Preservation**

Okay, let's break this down. My initial focus was on comparing `bpf_rcu_run_callback` and `bpf_timer_cb`. In both cases, I see the common pattern: `key = map_key_from_value(map, value, &idx);` followed by a call to `callback_fn`. The interesting part is that `idx` is initialized by `map_key_from_value`.

However, I need to consider other execution paths – particularly, what about situations beyond these explicit callback invocations, like those in `bpf_prog_test_run_opts`? Time to dig into `__bpf_call_rcu`. The code reveals that before a callback can even be scheduled, several checks occur. Specifically, a callback can't be canceled after being queued, thus preventing a self-rearming one from pinning program and map. Also, the map has to have a `usercnt` greater than zero, and the callback has to be armed before it is enqueued. The crucial bit here is how `rhk->armed` is initialized.

Looking at the code, it seems the value is initialized with the kzalloc call to allocate the array. This is good because it means `armed` starts at zero for array map values. That also brings to mind the next question, which is what happens if an array map element is updated through `map_update_elem`? Does this create an issue? Let's trace it out. The update path calls `array_map_update_elem`.

In that function, there's `copy_map_value` and its variants. Aha! `copy_map_value` in turn uses `bpf_obj_memcpy`, which carefully *skips* `BPF_RCU_HEAD` as a field (because it's handled by `rec->fields`). That implies `rhk` is preserved across updates. Okay, that's crucial. I am seeing that, at least in the array map case, the `bpf_rcu_head` state is likely maintained during element updates.

But what does `bpf_obj_cancel_fields` do? I'm going to have to look at that function next because it’s called in `array_map_update_elem` too. Let's see if that interferes with the arm state.



88/3 2026/09/23 19:48 tool grepper
0m Args:
{
  "Expression": "bpf_obj_cancel_fields"
}

Results:
{
  "Output": "include/linux/bpf.h=2829=void bpf_obj_free_task_work(const struct btf_record *rec, void *obj);\ninclude/linux/bpf.h:2830:void bpf_obj_cancel_fields(struct bpf_map *map, void *obj);\ninclude/linux/bpf.h-2831-void bpf_obj_free_fields(const struct btf_record *rec, void *obj);\n--\nkernel/bpf/arraymap.c=392=static long array_map_update_elem(struct bpf_map *map, void *key, void *value,\n--\nkernel/bpf/arraymap.c-417-\t\tcopy_map_value(map, val, value);\nkernel/bpf/arraymap.c:418:\t\tbpf_obj_cancel_fields(map, val);\nkernel/bpf/arraymap.c-419-\t} else {\n--\nkernel/bpf/arraymap.c-425-\t\t\tcopy_map_value(map, val, value);\nkernel/bpf/arraymap.c:426:\t\tbpf_obj_cancel_fields(map, val);\nkernel/bpf/arraymap.c-427-\t}\n--\nkernel/bpf/arraymap.c=431=int bpf_percpu_array_update(struct bpf_map *map, void *key, void *value,\n--\nkernel/bpf/arraymap.c-465-\t\tcopy_map_value(map, ptr, value);\nkernel/bpf/arraymap.c:466:\t\tbpf_obj_cancel_fields(map, ptr);\nkernel/bpf/arraymap.c-467-\t\tgoto unlock;\n--\nkernel/bpf/arraymap.c-472-\t\tcopy_map_value(map, ptr, val);\nkernel/bpf/arraymap.c:473:\t\tbpf_obj_cancel_fields(map, ptr);\nkernel/bpf/arraymap.c-474-\t\toff += size;\n--\nkernel/bpf/hashtab.c=843=static void check_and_cancel_fields(struct bpf_htab *htab,\n--\nkernel/bpf/hashtab.c-853-\t\tfor_each_possible_cpu(cpu)\nkernel/bpf/hashtab.c:854:\t\t\tbpf_obj_cancel_fields(\u0026htab-\u003emap, per_cpu_ptr(pptr, cpu));\nkernel/bpf/hashtab.c-855-\t} else {\n--\nkernel/bpf/hashtab.c-857-\nkernel/bpf/hashtab.c:858:\t\tbpf_obj_cancel_fields(\u0026htab-\u003emap, map_value);\nkernel/bpf/hashtab.c-859-\t}\n--\nkernel/bpf/hashtab.c=1018=static void pcpu_copy_value(struct bpf_htab *htab, void __percpu *pptr,\n--\nkernel/bpf/hashtab.c-1026-\t\tcopy_map_value(\u0026htab-\u003emap, ptr, value);\nkernel/bpf/hashtab.c:1027:\t\tbpf_obj_cancel_fields(\u0026htab-\u003emap, ptr);\nkernel/bpf/hashtab.c-1028-\t} else {\n--\nkernel/bpf/hashtab.c-1036-\t\t\tcopy_map_value(\u0026htab-\u003emap, ptr, value);\nkernel/bpf/hashtab.c:1037:\t\t\tbpf_obj_cancel_fields(\u0026htab-\u003emap, ptr);\nkernel/bpf/hashtab.c-1038-\t\t\treturn;\n--\nkernel/bpf/hashtab.c-1044-\t\t\tcopy_map_value(\u0026htab-\u003emap, ptr, val);\nkernel/bpf/hashtab.c:1045:\t\t\tbpf_obj_cancel_fields(\u0026htab-\u003emap, ptr);\nkernel/bpf/hashtab.c-1046-\t\t\toff += size;\n--\nkernel/bpf/hashtab.c=2933=static int rhtab_delete_elem(struct bpf_rhtab *rhtab, struct rhtab_elem *elem, void *copy,\n--\nkernel/bpf/hashtab.c-2959-\t}\nkernel/bpf/hashtab.c:2960:\tbpf_obj_cancel_fields(\u0026rhtab-\u003emap,\nkernel/bpf/hashtab.c-2961-\t\t\t      rhtab_elem_value(elem, rhtab-\u003emap.key_size));\n--\nkernel/bpf/hashtab.c=2999=static long rhtab_map_update_existing(struct bpf_map *map, struct rhtab_elem *elem, void *value,\n--\nkernel/bpf/hashtab.c-3020-\t */\nkernel/bpf/hashtab.c:3021:\tbpf_obj_cancel_fields(map, old_val);\nkernel/bpf/hashtab.c-3022-\treturn 0;\n--\nkernel/bpf/syscall.c=804=void bpf_obj_free_task_work(const struct btf_record *rec, void *obj)\n--\nkernel/bpf/syscall.c-810-\nkernel/bpf/syscall.c:811:void bpf_obj_cancel_fields(struct bpf_map *map, void *obj)\nkernel/bpf/syscall.c-812-{\n--\ntools/testing/selftests/bpf/prog_tests/htab_update.c=15=static void test_reenter_update(void)\n--\ntools/testing/selftests/bpf/prog_tests/htab_update.c-25-\ntools/testing/selftests/bpf/prog_tests/htab_update.c:26:\tbpf_program__set_autoload(skel-\u003eprogs.bpf_obj_cancel_fields, true);\ntools/testing/selftests/bpf/prog_tests/htab_update.c-27-\terr = htab_update__load(skel);\n--\ntools/testing/selftests/bpf/prog_tests/htab_update.c-52-\t * the reentrancy of bpf_map_update_elem().\ntools/testing/selftests/bpf/prog_tests/htab_update.c:53:\t * check_and_cancel_fields() calls bpf_obj_cancel_fields() on the old\ntools/testing/selftests/bpf/prog_tests/htab_update.c-54-\t * value, which is where fentry program runs and performs a nested\n--\ntools/testing/selftests/bpf/progs/htab_update.c=23=int update_err = 0;\ntools/testing/selftests/bpf/progs/htab_update.c-24-\ntools/testing/selftests/bpf/progs/htab_update.c:25:SEC(\"?fentry/bpf_obj_cancel_fields\")\ntools/testing/selftests/bpf/progs/htab_update.c:26:int bpf_obj_cancel_fields(void *ctx)\ntools/testing/selftests/bpf/progs/htab_update.c-27-{\n"
}

89/3 2026/09/23 19:48 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 68816
							output: 36
							thoughts: 31
						

Thoughts:
Here's my summary, as though I'm thinking through it:

**Examining bpf_obj_cancel_fields**

Okay, let's dive into this. I'm focusing on `bpf_obj_cancel_fields` – it's crucial for understanding the lifecycle of BPF objects, especially in cleanup scenarios. Right now, I need to see exactly where it's being used. Specifically, I'm checking line 811 in `kernel/bpf/syscall.c`. That file's a major player in how BPF interacts with user space. Knowing *how* and *when* this function gets called is key to debugging potential memory leaks, resource exhaustion, or unexpected behavior when BPF programs are involved. This is probably a good place to start my investigation.



90/3 2026/09/23 19:49 tool read-file
0m Args:
{
  "File": "kernel/bpf/syscall.c",
  "FirstLine": 810,
  "LineCount": 30
}

Results:
{
  "Contents": " 810:\t\n 811:\tvoid bpf_obj_cancel_fields(struct bpf_map *map, void *obj)\n 812:\t{\n 813:\t\tbpf_map_free_internal_structs(map, obj);\n 814:\t}\n 815:\t\n 816:\tvoid bpf_obj_free_fields(const struct btf_record *rec, void *obj)\n 817:\t{\n 818:\t\tconst struct btf_field *fields;\n 819:\t\tint i;\n 820:\t\n 821:\t\tif (IS_ERR_OR_NULL(rec))\n 822:\t\t\treturn;\n 823:\t\tfields = rec-\u003efields;\n 824:\t\tfor (i = 0; i \u003c rec-\u003ecnt; i++) {\n 825:\t\t\tstruct btf_struct_meta *pointee_struct_meta;\n 826:\t\t\tconst struct btf_field *field = \u0026fields[i];\n 827:\t\t\tvoid *field_ptr = obj + field-\u003eoffset;\n 828:\t\t\tvoid *xchgd_field;\n 829:\t\n 830:\t\t\tswitch (fields[i].type) {\n 831:\t\t\tcase BPF_SPIN_LOCK:\n 832:\t\t\tcase BPF_RES_SPIN_LOCK:\n 833:\t\t\t\tbreak;\n 834:\t\t\tcase BPF_TIMER:\n 835:\t\t\t\tbpf_timer_cancel_and_free(field_ptr);\n 836:\t\t\t\tbreak;\n 837:\t\t\tcase BPF_WORKQUEUE:\n 838:\t\t\t\tbpf_wq_cancel_and_free(field_ptr);\n 839:\t\t\t\tbreak;\n"
}

91/3 2026/09/23 19:49 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 69514
							output: 36
							thoughts: 25
						

Thoughts:
Okay, let's dive into this. I'm focusing on lines 840-885 of `kernel/bpf/syscall.c`. My immediate thought is, "What's the context here? This section must be handling a specific BPF-related syscall, or a key part of the broader BPF execution framework." I need to understand the function this code is part of, the arguments it receives, and the potential return values.

**Analyzing Lines 840-885 in `kernel/bpf/syscall.c`**

I'll be looking for clues:

*   **Function Signature:** The function definition itself will tell me the name and what parameters it takes. Understanding these parameters is crucial. Are we dealing with program loading, map creation, instruction execution, or something else entirely?
*   **Error Handling:** The presence and nature of any error checks are important. Are we seeing checks for invalid BPF programs, out-of-bounds map accesses, permission issues, or resource limitations? This will highlight potential vulnerabilities or performance bottlenecks.
*   **Data Structures:** What BPF-related data structures are being manipulated within this section? Are we seeing interactions with `bpf_prog`, `bpf_map`, `bpf_insn` or others? Understanding the relationship between these structures helps me understand the overall data flow.
*   **Core Logic:** The core of the code, obviously, what is the code *doing*? Is there instruction interpretation? Map access and modification? Context switching? Memory allocation? I'll need to look at any loops, conditional statements and function calls to determine what tasks are being performed.
*   **Interaction with Hardware:** Any interaction with hardware accelerators, such as XDP hardware or eBPF verifiers. This is an area of significant complexity, and it will be interesting to see if any code here interacts with that complexity.
*   **Security Concerns:** This is the kernel, so security is paramount. I'll need to identify any potential security implications of the logic, focusing on program verification, sandbox escapes, and potential denial-of-service vectors.

I anticipate this section being a critical piece in the overall BPF puzzle. Now, let's get to the code and see what secrets it holds!



92/3 2026/09/23 19:49 tool read-file
0m Args:
{
  "File": "kernel/bpf/syscall.c",
  "FirstLine": 840,
  "LineCount": 45
}

Results:
{
  "Contents": " 840:\t\t\tcase BPF_TASK_WORK:\n 841:\t\t\t\tbpf_task_work_cancel_and_free(field_ptr);\n 842:\t\t\t\tbreak;\n 843:\t\t\tcase BPF_KPTR_UNREF:\n 844:\t\t\t\tWRITE_ONCE(*(u64 *)field_ptr, 0);\n 845:\t\t\t\tbreak;\n 846:\t\t\tcase BPF_KPTR_REF:\n 847:\t\t\tcase BPF_KPTR_PERCPU:\n 848:\t\t\t\txchgd_field = (void *)xchg((unsigned long *)field_ptr, 0);\n 849:\t\t\t\tif (!xchgd_field)\n 850:\t\t\t\t\tbreak;\n 851:\t\n 852:\t\t\t\tif (!btf_is_kernel(field-\u003ekptr.btf)) {\n 853:\t\t\t\t\tpointee_struct_meta = btf_find_struct_meta(field-\u003ekptr.btf,\n 854:\t\t\t\t\t\t\t\t\t\t   field-\u003ekptr.btf_id);\n 855:\t\t\t\t\t__bpf_obj_drop_impl(xchgd_field, pointee_struct_meta ?\n 856:\t\t\t\t\t\t\t\t\t pointee_struct_meta-\u003erecord : NULL,\n 857:\t\t\t\t\t\t\t\t\t fields[i].type == BPF_KPTR_PERCPU);\n 858:\t\t\t\t} else {\n 859:\t\t\t\t\tfield-\u003ekptr.dtor(xchgd_field);\n 860:\t\t\t\t}\n 861:\t\t\t\tbreak;\n 862:\t\t\tcase BPF_UPTR:\n 863:\t\t\t\t/* The caller ensured that no one is using the uptr */\n 864:\t\t\t\tunpin_uptr_kaddr(*(void **)field_ptr);\n 865:\t\t\t\tbreak;\n 866:\t\t\tcase BPF_LIST_HEAD:\n 867:\t\t\t\tif (WARN_ON_ONCE(rec-\u003espin_lock_off \u003c 0))\n 868:\t\t\t\t\tcontinue;\n 869:\t\t\t\tbpf_list_head_free(field, field_ptr, obj + rec-\u003espin_lock_off);\n 870:\t\t\t\tbreak;\n 871:\t\t\tcase BPF_RB_ROOT:\n 872:\t\t\t\tif (WARN_ON_ONCE(rec-\u003espin_lock_off \u003c 0))\n 873:\t\t\t\t\tcontinue;\n 874:\t\t\t\tbpf_rb_root_free(field, field_ptr, obj + rec-\u003espin_lock_off);\n 875:\t\t\t\tbreak;\n 876:\t\t\tcase BPF_LIST_NODE:\n 877:\t\t\tcase BPF_RB_NODE:\n 878:\t\t\tcase BPF_REFCOUNT:\n 879:\t\t\tcase BPF_RCU_HEAD:\n 880:\t\t\t\tbreak;\n 881:\t\t\tdefault:\n 882:\t\t\t\tWARN_ON_ONCE(1);\n 883:\t\t\t\tcontinue;\n 884:\t\t\t}\n"
}

93/3 2026/09/23 19:49 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 70811
							output: 37
							thoughts: 53
						

Thoughts:
Here's my summary, as though I'm thinking through this process:

**Diving into bpf_map_free_internal_structs**

Alright, let's take a closer look at `bpf_map_free_internal_structs`. I'm specifically targeting the implementation in `kernel/bpf/helpers.c`. I need to understand how the internal structures associated with BPF maps are being freed, and any potential implications. I'm going to jump straight to the code, and I'm particularly interested in lines 5265 through 5280. I expect this section contains the core logic for the process. My goal is to grasp the mechanics of this function and identify any key details of its operation.



94/3 2026/09/23 19:50 tool read-file
0m Args:
{
  "File": "kernel/bpf/helpers.c",
  "FirstLine": 5265,
  "LineCount": 20
}

Results:
{
  "Contents": "5265:\t\n5266:\tvoid bpf_map_free_internal_structs(struct bpf_map *map, void *val)\n5267:\t{\n5268:\t\tif (btf_record_has_field(map-\u003erecord, BPF_TIMER))\n5269:\t\t\tbpf_obj_free_timer(map-\u003erecord, val);\n5270:\t\tif (btf_record_has_field(map-\u003erecord, BPF_WORKQUEUE))\n5271:\t\t\tbpf_obj_free_workqueue(map-\u003erecord, val);\n5272:\t\tif (btf_record_has_field(map-\u003erecord, BPF_TASK_WORK))\n5273:\t\t\tbpf_obj_free_task_work(map-\u003erecord, val);\n5274:\t}\n"
}

95/3 2026/09/23 19:50 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 71282
							output: 415
							thoughts: 2363
						

Thoughts:
**My Analysis of KMSAN Applicability**

Okay, so I've got this patch here introducing `bpf_call_rcu` and its related infrastructure, and I need to assess whether it introduces any uninitialized memory vulnerabilities that KMSAN should be concerned about.  My initial assessment is that it looks unlikely, but I need to be thorough.

First, I've confirmed that the `BPF_RCU_HEAD` doesn't do anything prematurely. The `bpf_call_rcu` function contains logic to check if a callback can even be run. Importantly, the `bpf_prog_inc_not_zero(aux->prog)` ensures that the program, and by extension the map, stays alive for the duration of the callback. This is critical for preventing use-after-free scenarios.

Now, let's go through the KMSAN criteria.

1.  **Kernel structures to userspace:**  The patch *does* introduce `struct bpf_rcu_head` to the UAPI.  However, upon closer inspection, when a user-space program retrieves the map element, `check_and_init_map_value` is called. This function, in turn, calls `bpf_obj_init` and `bpf_obj_init_field` which explicitly `memset`s `bpf_rcu_head` to zero *before* any copy to user space.  So, even if a user program doesn't specifically use `map_lookup_elem`, no other codepath sends `struct bpf_rcu_head` to user space, eliminating the risk of information leakage.

2.  **Conditional logic and branching:** There isn't any conditional logic that relies on potentially uninitialized variables.

3.  **Allocation of complex data structures:** The kernel representation, `bpf_rcu_head_kern`, is thoroughly initialized before being passed to `call_rcu` (or `call_rcu_tasks_trace`). All its members (callback function, map, program, armed state) are populated. The `rcu_head` member, used internally by the RCU mechanism, is properly initialized by `call_rcu`.

4.  **Bounds checks:** The code explicitly enforces the `BPF_RCU_HEAD` can only be used with array maps and prevents map-in-map scenarios, iterators, and direct load/store accesses to `bpf_rcu_head` through the verifier, effectively eliminating any risk of accessing uninitialized bytes around existing buffers or overflowing bounds checks.

I've also carefully examined all the local variables within the new functions. The index variable `idx`, written to in `bpf_rcu_run_callback`, is initialized by `map_key_from_value`.  The callback function, key, and value are passed as arguments to `callback_fn` within this function.  The verifier guarantees that the arguments are valid and properly initialized prior to the callback being called. All values passed to the callback function are explicitly initialized.  The `armed` flag in `bpf_rcu_head_kern` is properly initialized via `cmpxchg`.

Now, considering potential bugs, I need to check for concurrency issues, lifetime problems, or sleep vs. non-sleepable contexts, and so on. But none of them are directly caused by uninitialized memory. Refcounting, use-after-free, concurrency issues, and similar problems are best detected by KASAN and LOCKDEP.  Since all the introduced structures are fully initialized before being read or copied and I do not see an uninitialized memory usage, this patch is safe from KMSAN.

Therefore, `NeedsKMSAN` is `false`. I'll document my reasoning clearly in the tool call.



96/3 2026/09/23 19:50 tool set-results
0m Args:
{
  "KMSANReasoning": "The patch introduces the `bpf_call_rcu` and `bpf_call_rcu_tasks_trace` kfuncs along with the `bpf_rcu_head` BTF field type (restricted to array maps). \n\nAn analysis of uninitialized memory risks shows:\n1. All fields of `struct bpf_rcu_head_kern` (`callback_fn`, `map`, `prog`, `armed`) are explicitly set prior to arming via `call_rcu()` / `call_rcu_tasks_trace()`, and `call_rcu` initializes the embedded `struct rcu_head`.\n2. Array map elements are zero-allocated upon creation. If userspace reads the map value via `bpf_map_lookup_elem`, `check_and_init_map_value()` invokes `bpf_obj_init_field()`, which explicitly zeroes the `bpf_rcu_head` struct with `memset()`, preventing info-leaks to userspace.\n3. BPF programs are prohibited from directly reading or writing the `bpf_rcu_head` field by verifier rules in `check_map_access()`.\n4. In `bpf_rcu_run_callback()`, the key passed to the callback points to `idx`, which is directly initialized by `map_key_from_value()`.\n\nThe primary risks for this feature pertain to object lifetimes (BPF program and map lifetime vs pending RCU callbacks), race conditions / concurrency bugs around callback rearming, or RCU context/locking misuse. These risks are effectively covered by KASAN (use-after-free, double free) and LOCKDEP (RCU / lock validation), and do not involve uninitialized memory access. Therefore, a dedicated KMSAN session is not warranted.",
  "NeedsKMSAN": false
}

Results:
{
  "KMSANReasoning": "The patch introduces the `bpf_call_rcu` and `bpf_call_rcu_tasks_trace` kfuncs along with the `bpf_rcu_head` BTF field type (restricted to array maps). \n\nAn analysis of uninitialized memory risks shows:\n1. All fields of `struct bpf_rcu_head_kern` (`callback_fn`, `map`, `prog`, `armed`) are explicitly set prior to arming via `call_rcu()` / `call_rcu_tasks_trace()`, and `call_rcu` initializes the embedded `struct rcu_head`.\n2. Array map elements are zero-allocated upon creation. If userspace reads the map value via `bpf_map_lookup_elem`, `check_and_init_map_value()` invokes `bpf_obj_init_field()`, which explicitly zeroes the `bpf_rcu_head` struct with `memset()`, preventing info-leaks to userspace.\n3. BPF programs are prohibited from directly reading or writing the `bpf_rcu_head` field by verifier rules in `check_map_access()`.\n4. In `bpf_rcu_run_callback()`, the key passed to the callback points to `idx`, which is directly initialized by `map_key_from_value()`.\n\nThe primary risks for this feature pertain to object lifetimes (BPF program and map lifetime vs pending RCU callbacks), race conditions / concurrency bugs around callback rearming, or RCU context/locking misuse. These risks are effectively covered by KASAN (use-after-free, double free) and LOCKDEP (RCU / lock validation), and do not involve uninitialized memory access. Therefore, a dedicated KMSAN session is not warranted.",
  "NeedsKMSAN": false
}

LLM Calls Summary:
Total Calls Total Tokens Avg Tokens Total Duration (Seconds) Avg Duration (Seconds)
Tool Calls Summary:
Total Calls Total Duration (Seconds) Avg Duration (Seconds)