| Seq | Timestamp | Type | Name | Duration |
|---|---|---|---|---|
| 0/0 | 2026/07/30 14:43 | flow | patch-triage |
1mArgs:null Results: {
"EnableConfigs": [
"SLUB_KUNIT_TEST",
"KUNIT",
"PERF_EVENTS",
"KPROBES",
"SMP",
"SLUB_DEBUG",
"KVFREE_RCU_BATCHED"
],
"FocusSymbols": [
"kfree_call_rcu_nolock",
"kvfree_call_rcu",
"__kfree_rcu_sheaf",
"defer_kfree_rcu",
"deferred_work_barrier",
"kvfree_rcu_barrier",
"kvfree_rcu_barrier_on_cache"
],
"Reasoning": "The patch introduces `kfree_rcu_nolock()` API which allows deferring freeing of objects in any context without locks. It modifies `kvfree_call_rcu()` to use `struct kvfree_rcu_head` and implements `kfree_call_rcu_nolock()` which relies on `__kfree_rcu_sheaf()` and `defer_kfree_rcu()`. It also adds KUnit tests for these new APIs using perf events and kprobes. This is a core memory management and RCU change that is highly functional and reachable.",
"WorthFuzzing": true
} |
| 1/1 | 2026/07/30 14:43 | action | read-patch-diff |
0mArgs:null Results: {
"PatchDiff": "commit 56bb7565a8ecf47c9f52258f16c540812b33833e\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate: Thu Jul 30 14:43:13 2026 +0000\n\n syz-cluster: applied patch under review\n\ndiff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h\nindex 5e95acc33989b..aede77bd03873 100644\n--- a/include/linux/rcupdate.h\n+++ b/include/linux/rcupdate.h\n@@ -1098,19 +1098,22 @@ static inline void rcu_read_unlock_migrate(void)\n /*\n * In mm/slab_common.c, no suitable header to include here.\n */\n-void kvfree_call_rcu(struct rcu_head *head, void *ptr);\n+void kvfree_call_rcu(struct kvfree_rcu_head *head, void *ptr);\n+void kfree_call_rcu_nolock(struct kvfree_rcu_head *head, void *ptr);\n \n /*\n * The BUILD_BUG_ON() makes sure the rcu_head offset can be handled. See the\n * comment of kfree_rcu() for details.\n */\n-#define kvfree_rcu_arg_2(ptr, rhf)\t\t\t\t\t\\\n+#define kvfree_rcu_arg_2(ptr, kvrhf)\t\t\t\t\t\\\n do {\t\t\t\t\t\t\t\t\t\\\n \ttypeof (ptr) ___p = (ptr);\t\t\t\t\t\\\n+\tstruct kvfree_rcu_head *___head;\t\t\t\t\\\n \t\t\t\t\t\t\t\t\t\\\n \tif (___p) {\t\t\t\t\t\t\t\\\n-\t\tBUILD_BUG_ON(offsetof(typeof(*(ptr)), rhf) \u003e= 4096);\t\\\n-\t\tkvfree_call_rcu(\u0026((___p)-\u003erhf), (void *) (___p));\t\\\n+\t\tBUILD_BUG_ON(offsetof(typeof(*(ptr)), kvrhf) \u003e= 4096);\t\\\n+\t\t___head = (struct kvfree_rcu_head *) \u0026(___p)-\u003ekvrhf;\t\\\n+\t\tkvfree_call_rcu(___head, (void *) (___p));\t\t\\\n \t}\t\t\t\t\t\t\t\t\\\n } while (0)\n \n@@ -1122,6 +1125,27 @@ do {\t\t\t\t\t\t\t\t\\\n \t\tkvfree_call_rcu(NULL, (void *) (___p));\t\t\\\n } while (0)\n \n+/**\n+ * kfree_rcu_nolock() - a version of kfree_rcu() that can be called in any context.\n+ * @ptr: pointer to kfree for double-argument invocations.\n+ * @kvrhf: the name of the struct kvfree_rcu_head within the type of @ptr.\n+ *\n+ * With KVFREE_RCU_BATCHED, kfree_rcu_nolock() tries hard to free objects\n+ * without any deferred processing, but may still defer freeing.\n+ * Large kmalloc and vmalloc objects are always deferred.\n+ *\n+ * kfree_rcu_nolock() supports 2-arg variant only.\n+ */\n+#define kfree_rcu_nolock(ptr, kvrhf)\t\t\t\t\t\t\\\n+do {\t\t\t\t\t\t\t\t\t\t\\\n+\ttypeof (ptr) ___p = (ptr);\t\t\t\t\t\t\\\n+\t\t\t\t\t\t\t\t\t\t\\\n+\tif (___p) {\t\t\t\t\t\t\t\t\\\n+\t\tBUILD_BUG_ON(offsetof(typeof(*(ptr)), kvrhf) \u003e= 4096);\t\t\\\n+\t\tkfree_call_rcu_nolock(\u0026((___p)-\u003ekvrhf), (void *) (___p));\t\\\n+\t}\t\t\t\t\t\t\t\t\t\\\n+} while (0)\n+\n /*\n * Place this after a lock-acquisition primitive to guarantee that\n * an UNLOCK+LOCK pair acts as a full barrier. This guarantee applies\ndiff --git a/include/linux/slab.h b/include/linux/slab.h\nindex e1915026e0304..cda126def67af 100644\n--- a/include/linux/slab.h\n+++ b/include/linux/slab.h\n@@ -1430,25 +1430,15 @@ extern void kvfree_sensitive(const void *addr, size_t len);\n unsigned int kmem_cache_size(struct kmem_cache *s);\n \n #ifndef CONFIG_KVFREE_RCU_BATCHED\n-static inline void kvfree_rcu_barrier(void)\n-{\n-\trcu_barrier();\n-}\n-\n-static inline void kvfree_rcu_barrier_on_cache(struct kmem_cache *s)\n-{\n-\trcu_barrier();\n-}\n-\n static inline void kfree_rcu_scheduler_running(void) { }\n #else\n+void kfree_rcu_scheduler_running(void);\n+#endif\n+\n void kvfree_rcu_barrier(void);\n \n void kvfree_rcu_barrier_on_cache(struct kmem_cache *s);\n \n-void kfree_rcu_scheduler_running(void);\n-#endif\n-\n /**\n * kmalloc_size_roundup - Report allocation bucket size for the given size\n *\ndiff --git a/include/linux/types.h b/include/linux/types.h\nindex bc5dda2a3d861..79bf419c69e47 100644\n--- a/include/linux/types.h\n+++ b/include/linux/types.h\n@@ -257,6 +257,14 @@ struct callback_head {\n } __attribute__((aligned(sizeof(void *))));\n #define rcu_head callback_head\n \n+#ifdef CONFIG_KVFREE_RCU_BATCHED\n+struct kvfree_rcu_head {\n+\tstruct kvfree_rcu_head *next;\n+};\n+#else\n+#define kvfree_rcu_head rcu_head\n+#endif\n+\n typedef void (*rcu_callback_t)(struct rcu_head *head);\n typedef void (*call_rcu_func_t)(struct rcu_head *head, rcu_callback_t func);\n \ndiff --git a/include/trace/events/rcu.h b/include/trace/events/rcu.h\nindex 5fbdabe3faead..a74027126a2fd 100644\n--- a/include/trace/events/rcu.h\n+++ b/include/trace/events/rcu.h\n@@ -625,7 +625,7 @@ TRACE_EVENT_RCU(rcu_invoke_callback,\n */\n TRACE_EVENT_RCU(rcu_invoke_kvfree_callback,\n \n-\tTP_PROTO(const char *rcuname, struct rcu_head *rhp, unsigned long offset),\n+\tTP_PROTO(const char *rcuname, struct kvfree_rcu_head *rhp, unsigned long offset),\n \n \tTP_ARGS(rcuname, rhp, offset),\n \ndiff --git a/lib/tests/slub_kunit.c b/lib/tests/slub_kunit.c\nindex fa6d31dbca166..e3b63f0338d5f 100644\n--- a/lib/tests/slub_kunit.c\n+++ b/lib/tests/slub_kunit.c\n@@ -8,6 +8,7 @@\n #include \u003clinux/rcupdate.h\u003e\n #include \u003clinux/delay.h\u003e\n #include \u003clinux/perf_event.h\u003e\n+#include \u003clinux/kprobes.h\u003e\n #include \"../mm/slab.h\"\n \n static struct kunit_resource resource;\n@@ -161,7 +162,10 @@ static void test_kmalloc_redzone_access(struct kunit *test)\n }\n \n struct test_kfree_rcu_struct {\n-\tstruct rcu_head rcu;\n+\tunion {\n+\t\tstruct rcu_head rcu;\n+\t\tstruct kvfree_rcu_head kvrcu;\n+\t};\n };\n \n static void test_kfree_rcu(struct kunit *test)\n@@ -292,19 +296,76 @@ static void test_krealloc_redzone_zeroing(struct kunit *test)\n \tkmem_cache_destroy(s);\n }\n \n-#ifdef CONFIG_PERF_EVENTS\n+#if defined(CONFIG_PERF_EVENTS) || (defined(CONFIG_KPROBES) \u0026\u0026 defined(CONFIG_SMP))\n #define NR_ITERATIONS 1000\n #define NR_OBJECTS 1000\n-static void *objects[NR_OBJECTS];\n+static struct test_kfree_rcu_struct *objects[NR_OBJECTS];\n \n struct test_nolock_context {\n \tstruct kunit *test;\n \tint callback_count;\n \tint alloc_ok;\n \tint alloc_fail;\n+#ifdef CONFIG_PERF_EVENTS\n \tstruct perf_event *event;\n+#endif\n+#if defined(CONFIG_KPROBES) \u0026\u0026 defined(CONFIG_SMP)\n+\tstruct kprobe kprobe;\n+#endif\n };\n \n+static void test_kmalloc_and_friends(void)\n+{\n+\tint i, j;\n+\tbool can_use_kfree_rcu = !IS_BUILTIN(CONFIG_SLUB_KUNIT_TEST);\n+\n+\tfor (i = 0; i \u003c NR_ITERATIONS; i++) {\n+\t\tfor (j = 0; j \u003c NR_OBJECTS; j++) {\n+\t\t\tgfp_t gfp = (i \u0026 1) ? GFP_KERNEL : GFP_KERNEL_ACCOUNT;\n+\n+\t\t\tobjects[j] = kmalloc_obj(*objects[j], gfp);\n+\t\t\tif (!objects[j]) {\n+\t\t\t\tj--;\n+\t\t\t\twhile (j \u003e= 0)\n+\t\t\t\t\tkfree(objects[j--]);\n+\t\t\t\treturn;\n+\t\t\t}\n+\t\t}\n+\n+\t\tfor (j = 0; j \u003c NR_OBJECTS; j++) {\n+\t\t\tif (can_use_kfree_rcu \u0026\u0026 (i \u0026 2))\n+\t\t\t\tkfree_rcu(objects[j], rcu);\n+\t\t\telse\n+\t\t\t\tkfree(objects[j]);\n+\t\t}\n+\t}\n+}\n+\n+static void test_nolock(struct test_nolock_context *ctx)\n+{\n+\tstruct test_kfree_rcu_struct *objp;\n+\tgfp_t gfp;\n+\tbool can_use_kfree_rcu = !IS_BUILTIN(CONFIG_SLUB_KUNIT_TEST);\n+\n+\t/* __GFP_ACCOUNT to test kmalloc_nolock() in alloc_slab_obj_exts() */\n+\tgfp = (ctx-\u003ecallback_count \u0026 1) ? 0 : __GFP_ACCOUNT;\n+\tobjp = kmalloc_nolock(sizeof(*objp), gfp, NUMA_NO_NODE);\n+\n+\tif (objp)\n+\t\tctx-\u003ealloc_ok++;\n+\telse\n+\t\tctx-\u003ealloc_fail++;\n+\n+\tif (can_use_kfree_rcu \u0026\u0026 (ctx-\u003ecallback_count \u0026 2))\n+\t\tkfree_rcu_nolock(objp, kvrcu);\n+\telse\n+\t\tkfree_nolock(objp);\n+\n+\tctx-\u003ecallback_count++;\n+}\n+#endif\n+\n+#ifdef CONFIG_PERF_EVENTS\n static struct perf_event_attr hw_attr = {\n \t.type = PERF_TYPE_HARDWARE,\n \t.config = PERF_COUNT_HW_CPU_CYCLES,\n@@ -315,67 +376,91 @@ static struct perf_event_attr hw_attr = {\n \t.sample_freq = 100000,\n };\n \n-static void overflow_handler_test_kmalloc_kfree_nolock(struct perf_event *event,\n-\t\t\t\t\t\t struct perf_sample_data *data,\n-\t\t\t\t\t\t struct pt_regs *regs)\n+static void overflow_handler_test_nolock(struct perf_event *event,\n+\t\t\t\t\t struct perf_sample_data *data,\n+\t\t\t\t\t struct pt_regs *regs)\n {\n-\tvoid *objp;\n-\tgfp_t gfp;\n \tstruct test_nolock_context *ctx = event-\u003eoverflow_handler_context;\n \n-\t/* __GFP_ACCOUNT to test kmalloc_nolock() in alloc_slab_obj_exts() */\n-\tgfp = (ctx-\u003ecallback_count % 2) ? 0 : __GFP_ACCOUNT;\n-\tobjp = kmalloc_nolock(64, gfp, NUMA_NO_NODE);\n-\n-\tif (objp)\n-\t\tctx-\u003ealloc_ok++;\n-\telse\n-\t\tctx-\u003ealloc_fail++;\n-\n-\tkfree_nolock(objp);\n-\tctx-\u003ecallback_count++;\n+\ttest_nolock(ctx);\n }\n \n-static void test_kmalloc_kfree_nolock(struct kunit *test)\n+static bool enable_perf_events(struct test_nolock_context *ctx)\n {\n-\tint i, j;\n-\tstruct test_nolock_context ctx = { .test = test };\n \tstruct perf_event *event;\n-\tbool alloc_fail = false;\n \n \tevent = perf_event_create_kernel_counter(\u0026hw_attr, -1, current,\n-\t\t\t\t\t\t overflow_handler_test_kmalloc_kfree_nolock,\n-\t\t\t\t\t\t \u0026ctx);\n+\t\t\t\t\t\t overflow_handler_test_nolock,\n+\t\t\t\t\t\t ctx);\n+\n \tif (IS_ERR(event))\n-\t\tkunit_skip(test, \"Failed to create perf event\");\n-\tctx.event = event;\n-\tperf_event_enable(ctx.event);\n-\tfor (i = 0; i \u003c NR_ITERATIONS; i++) {\n-\t\tfor (j = 0; j \u003c NR_OBJECTS; j++) {\n-\t\t\tgfp_t gfp = (i % 2) ? GFP_KERNEL : GFP_KERNEL_ACCOUNT;\n+\t\treturn false;\n \n-\t\t\tobjects[j] = kmalloc(64, gfp);\n-\t\t\tif (!objects[j]) {\n-\t\t\t\tj--;\n-\t\t\t\twhile (j \u003e= 0)\n-\t\t\t\t\tkfree(objects[j--]);\n-\t\t\t\talloc_fail = true;\n-\t\t\t\tgoto cleanup;\n-\t\t\t}\n-\t\t}\n-\t\tfor (j = 0; j \u003c NR_OBJECTS; j++)\n-\t\t\tkfree(objects[j]);\n-\t}\n+\tctx-\u003eevent = event;\n+\tperf_event_enable(ctx-\u003eevent);\n+\treturn true;\n+}\n+\n+static void disable_perf_events(struct test_nolock_context *ctx)\n+{\n+\tkunit_info(ctx-\u003etest, \"HW perf events: callback_count: %d, alloc_ok: %d, alloc_fail: %d\\n\",\n+\t\t ctx-\u003ecallback_count, ctx-\u003ealloc_ok, ctx-\u003ealloc_fail);\n+\n+\tperf_event_disable(ctx-\u003eevent);\n+\tperf_event_release_kernel(ctx-\u003eevent);\n+}\n+\n+static void test_kmalloc_nolock_and_friends_perf(struct kunit *test)\n+{\n+\tstruct test_nolock_context ctx = { .test = test };\n \n-cleanup:\n-\tperf_event_disable(ctx.event);\n-\tperf_event_release_kernel(ctx.event);\n+\tif (!enable_perf_events(\u0026ctx))\n+\t\tkunit_skip(test, \"Failed to enable perf event, skipping\");\n \n-\tkunit_info(test, \"callback_count: %d, alloc_ok: %d, alloc_fail: %d\\n\",\n-\t\t ctx.callback_count, ctx.alloc_ok, ctx.alloc_fail);\n+\ttest_kmalloc_and_friends();\n \n-\tif (alloc_fail)\n-\t\tkunit_skip(test, \"Allocation failed\");\n+\tdisable_perf_events(\u0026ctx);\n+\tKUNIT_EXPECT_EQ(test, 0, slab_errors);\n+}\n+#endif\n+\n+#if defined(CONFIG_KPROBES) \u0026\u0026 defined(CONFIG_SMP)\n+static int slab_kprobe_pre_handler(struct kprobe *p, struct pt_regs *regs)\n+{\n+\tstruct test_nolock_context *ctx;\n+\n+\tctx = container_of(p, struct test_nolock_context, kprobe);\n+\ttest_nolock(ctx);\n+\treturn 0;\n+}\n+\n+static bool register_slab_kprobes(struct test_nolock_context *ctx)\n+{\n+\tctx-\u003ekprobe.symbol_name = \"slab_attach_kprobe_locked\";\n+\tctx-\u003ekprobe.pre_handler = slab_kprobe_pre_handler;\n+\n+\tif (register_kprobe(\u0026ctx-\u003ekprobe))\n+\t\treturn false;\n+\treturn true;\n+}\n+\n+static void unregister_slab_kprobes(struct test_nolock_context *ctx)\n+{\n+\tkunit_info(ctx-\u003etest, \"kprobes: callback_count: %d, alloc_ok: %d, alloc_fail: %d\\n\",\n+\t\t ctx-\u003ecallback_count, ctx-\u003ealloc_ok, ctx-\u003ealloc_fail);\n+\tunregister_kprobe(\u0026ctx-\u003ekprobe);\n+}\n+\n+static void test_kmalloc_nolock_and_friends_kprobe(struct kunit *test)\n+{\n+\tstruct test_nolock_context ctx = { .test = test };\n+\n+\tif (!register_slab_kprobes(\u0026ctx))\n+\t\tkunit_skip(test, \"Failed to register kprobe, skipping\");\n+\n+\ttest_kmalloc_and_friends();\n+\n+\tunregister_slab_kprobes(\u0026ctx);\n \tKUNIT_EXPECT_EQ(test, 0, slab_errors);\n }\n #endif\n@@ -405,7 +490,10 @@ static struct kunit_case test_cases[] = {\n \tKUNIT_CASE(test_leak_destroy),\n \tKUNIT_CASE(test_krealloc_redzone_zeroing),\n #ifdef CONFIG_PERF_EVENTS\n-\tKUNIT_CASE_SLOW(test_kmalloc_kfree_nolock),\n+\tKUNIT_CASE_SLOW(test_kmalloc_nolock_and_friends_perf),\n+#endif\n+#if defined(CONFIG_KPROBES) \u0026\u0026 defined(CONFIG_SMP)\n+\tKUNIT_CASE_SLOW(test_kmalloc_nolock_and_friends_kprobe),\n #endif\n \t{}\n };\ndiff --git a/mm/slab.h b/mm/slab.h\nindex e01c1015b8c8d..8fd6835e42352 100644\n--- a/mm/slab.h\n+++ b/mm/slab.h\n@@ -24,11 +24,27 @@\n #define SLAB_ALLOC_NO_RECURSE\t0x04 /* prevent kmalloc() recursion */\n #define SLAB_ALLOC_NO_OBJ_EXT\t0x08 /* prevent obj_exts array allocation */\n \n+#define SLAB_FREE_DEFAULT\t0x00 /* no flags */\n+#define SLAB_FREE_NOLOCK\t0x01 /* spinning not allowed */\n+\n+static inline unsigned int to_alloc_flags(unsigned int free_flags)\n+{\n+\tif (free_flags \u0026 SLAB_FREE_NOLOCK)\n+\t\treturn SLAB_ALLOC_NOLOCK;\n+\telse\n+\t\treturn SLAB_ALLOC_DEFAULT;\n+}\n+\n static inline bool alloc_flags_allow_spinning(const unsigned int alloc_flags)\n {\n \treturn !(alloc_flags \u0026 SLAB_ALLOC_NOLOCK);\n }\n \n+static inline bool free_flags_allow_spinning(const unsigned int free_flags)\n+{\n+\treturn !(free_flags \u0026 SLAB_FREE_NOLOCK);\n+}\n+\n void *__kmalloc_flags_noprof(DECL_TOKEN_PARAMS(size, token), gfp_t flags,\n \t\t\t\t unsigned int alloc_flags, int node)\n \t\t\t\t __assume_kmalloc_alignment __alloc_size(1);\n@@ -331,6 +347,37 @@ static inline unsigned int obj_to_index(const struct kmem_cache *cache,\n \treturn __obj_to_index(cache, slab_address(slab), obj);\n }\n \n+/*\n+ * kvfree_rcu_head offset can be only less than page size.\n+ * Calculate the start address while preserving the KASAN tag.\n+ */\n+static inline void *kvmalloc_obj_start_addr(void *head)\n+{\n+\tunsigned long offset;\n+\n+\tif (unlikely(is_vmalloc_addr(head))) {\n+\t\toffset = offset_in_page(head);\n+\t} else {\n+\t\tstruct slab *slab = virt_to_slab(head);\n+\n+\t\tif (!slab) {\n+\t\t\toffset = offset_in_page(head);\n+\t\t} else if (is_kfence_address(head)) {\n+\t\t\toffset = head - kfence_object_start(head);\n+\t\t} else {\n+\t\t\tstruct kmem_cache *s = slab-\u003eslab_cache;\n+\t\t\tunsigned int idx = __obj_to_index(s, slab_address(slab), head);\n+\t\t\tvoid *obj = slab_address(slab) + s-\u003esize * idx;\n+\n+\t\t\tobj = fixup_red_left(s, obj);\n+\t\t\tobj = kasan_reset_tag(obj);\n+\t\t\toffset = kasan_reset_tag(head) - obj;\n+\t\t}\n+\t}\n+\n+\treturn head - offset;\n+}\n+\n /*\n * State of the slab allocator.\n *\n@@ -431,7 +478,7 @@ static inline bool is_kmalloc_normal(struct kmem_cache *s)\n \treturn !(s-\u003eflags \u0026 (SLAB_CACHE_DMA|SLAB_ACCOUNT|SLAB_RECLAIM_ACCOUNT|SLAB_NO_OBJ_EXT));\n }\n \n-bool __kfree_rcu_sheaf(struct kmem_cache *s, void *obj);\n+bool __kfree_rcu_sheaf(struct kmem_cache *s, void *obj, unsigned int free_flags);\n void flush_all_rcu_sheaves(void);\n void flush_rcu_sheaves_on_cache(struct kmem_cache *s);\n \n@@ -899,7 +946,8 @@ void __kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct slab *slab)\n void __check_heap_object(const void *ptr, unsigned long n,\n \t\t\t const struct slab *slab, bool to_user);\n \n-void defer_free_barrier(void);\n+void deferred_work_barrier(void);\n+void defer_kfree_rcu(struct kvfree_rcu_head *head);\n \n static inline bool slub_debug_orig_size(struct kmem_cache *s)\n {\ndiff --git a/mm/slab_common.c b/mm/slab_common.c\nindex 1e1d3feec3535..b8f21eabcccc2 100644\n--- a/mm/slab_common.c\n+++ b/mm/slab_common.c\n@@ -558,7 +558,7 @@ void kmem_cache_destroy(struct kmem_cache *s)\n \t}\n \n \t/* Wait for deferred work from kmalloc/kfree_nolock() */\n-\tdefer_free_barrier();\n+\tdeferred_work_barrier();\n \n \tcpus_read_lock();\n \tmutex_lock(\u0026slab_mutex);\n@@ -1296,6 +1296,33 @@ EXPORT_TRACEPOINT_SYMBOL(kmem_cache_alloc);\n EXPORT_TRACEPOINT_SYMBOL(kfree);\n EXPORT_TRACEPOINT_SYMBOL(kmem_cache_free);\n \n+void kfree_call_rcu_nolock(struct kvfree_rcu_head *head, void *ptr)\n+{\n+\tstruct slab *slab;\n+\n+\tif (!IS_ENABLED(CONFIG_KVFREE_RCU_BATCHED))\n+\t\tgoto fallback;\n+\n+\tif (unlikely(is_vmalloc_addr(ptr)))\n+\t\tgoto fallback;\n+\n+\tslab = virt_to_slab(ptr);\n+\tif (unlikely(!slab))\n+\t\tgoto fallback;\n+\n+\tif (unlikely(IS_ENABLED(CONFIG_NUMA) \u0026\u0026 slab_nid(slab) != numa_mem_id()))\n+\t\tgoto fallback;\n+\n+\tif (unlikely(!__kfree_rcu_sheaf(slab-\u003eslab_cache, ptr, SLAB_FREE_NOLOCK)))\n+\t\tgoto fallback;\n+\n+\treturn;\n+\n+fallback:\n+\tdefer_kfree_rcu(head);\n+}\n+EXPORT_SYMBOL_GPL(kfree_call_rcu_nolock);\n+\n #ifndef CONFIG_KVFREE_RCU_BATCHED\n \n void kvfree_call_rcu(struct rcu_head *head, void *ptr)\n@@ -1313,6 +1340,20 @@ void kvfree_call_rcu(struct rcu_head *head, void *ptr)\n }\n EXPORT_SYMBOL_GPL(kvfree_call_rcu);\n \n+void kvfree_rcu_barrier(void)\n+{\n+\tdeferred_work_barrier();\n+\trcu_barrier();\n+}\n+EXPORT_SYMBOL_GPL(kvfree_rcu_barrier);\n+\n+void kvfree_rcu_barrier_on_cache(struct kmem_cache *s)\n+{\n+\tdeferred_work_barrier();\n+\trcu_barrier();\n+}\n+EXPORT_SYMBOL_GPL(kvfree_rcu_barrier_on_cache);\n+\n void __init kvfree_rcu_init(void)\n {\n }\n@@ -1379,7 +1420,7 @@ struct kvfree_rcu_bulk_data {\n \n struct kfree_rcu_cpu_work {\n \tstruct rcu_work rcu_work;\n-\tstruct rcu_head *head_free;\n+\tstruct kvfree_rcu_head *head_free;\n \tstruct rcu_gp_oldstate head_free_gp_snap;\n \tstruct list_head bulk_head_free[FREE_N_CHANNELS];\n \tstruct kfree_rcu_cpu *krcp;\n@@ -1415,7 +1456,7 @@ struct kfree_rcu_cpu_work {\n struct kfree_rcu_cpu {\n \t// Objects queued on a linked list\n \t// through their rcu_head structures.\n-\tstruct rcu_head *head;\n+\tstruct kvfree_rcu_head *head;\n \tunsigned long head_gp_snap;\n \tatomic_t head_count;\n \n@@ -1556,12 +1597,12 @@ kvfree_rcu_bulk(struct kfree_rcu_cpu *krcp,\n }\n \n static void\n-kvfree_rcu_list(struct rcu_head *head)\n+kvfree_rcu_list(struct kvfree_rcu_head *head)\n {\n-\tstruct rcu_head *next;\n+\tstruct kvfree_rcu_head *next;\n \n \tfor (; head; head = next) {\n-\t\tvoid *ptr = (void *) head-\u003efunc;\n+\t\tvoid *ptr = kvmalloc_obj_start_addr(head);\n \t\tunsigned long offset = (void *) head - ptr;\n \n \t\tnext = head-\u003enext;\n@@ -1585,7 +1626,7 @@ static void kfree_rcu_work(struct work_struct *work)\n \tunsigned long flags;\n \tstruct kvfree_rcu_bulk_data *bnode, *n;\n \tstruct list_head bulk_head[FREE_N_CHANNELS];\n-\tstruct rcu_head *head;\n+\tstruct kvfree_rcu_head *head;\n \tstruct kfree_rcu_cpu *krcp;\n \tstruct kfree_rcu_cpu_work *krwp;\n \tstruct rcu_gp_oldstate head_gp_snap;\n@@ -1628,6 +1669,14 @@ static bool kfree_rcu_sheaf(void *obj)\n {\n \tstruct kmem_cache *s;\n \tstruct slab *slab;\n+\tunsigned int free_flags = SLAB_FREE_DEFAULT;\n+\n+\t/*\n+\t * It is not safe to spin on PREEMPT_RT because the kernel might be\n+\t * holding a raw spinlock and slab acquires sleeping locks.\n+\t */\n+\tif (IS_ENABLED(CONFIG_PREEMPT_RT))\n+\t\tfree_flags = SLAB_FREE_NOLOCK;\n \n \tif (is_vmalloc_addr(obj))\n \t\treturn false;\n@@ -1638,7 +1687,7 @@ static bool kfree_rcu_sheaf(void *obj)\n \n \ts = slab-\u003eslab_cache;\n \tif (likely(!IS_ENABLED(CONFIG_NUMA) || slab_nid(slab) == numa_mem_id()))\n-\t\treturn __kfree_rcu_sheaf(s, obj);\n+\t\treturn __kfree_rcu_sheaf(s, obj, free_flags);\n \n \treturn false;\n }\n@@ -1708,7 +1757,7 @@ kvfree_rcu_drain_ready(struct kfree_rcu_cpu *krcp)\n {\n \tstruct list_head bulk_ready[FREE_N_CHANNELS];\n \tstruct kvfree_rcu_bulk_data *bnode, *n;\n-\tstruct rcu_head *head_ready = NULL;\n+\tstruct kvfree_rcu_head *head_ready = NULL;\n \tunsigned long flags;\n \tint i;\n \n@@ -1971,7 +2020,7 @@ void __init kfree_rcu_scheduler_running(void)\n * be free'd in workqueue context. This allows us to: batch requests together to\n * reduce the number of grace periods during heavy kfree_rcu()/kvfree_rcu() load.\n */\n-void kvfree_call_rcu(struct rcu_head *head, void *ptr)\n+void kvfree_call_rcu(struct kvfree_rcu_head *head, void *ptr)\n {\n \tunsigned long flags;\n \tstruct kfree_rcu_cpu *krcp;\n@@ -1987,7 +2036,7 @@ void kvfree_call_rcu(struct rcu_head *head, void *ptr)\n \tif (!head)\n \t\tmight_sleep();\n \n-\tif (!IS_ENABLED(CONFIG_PREEMPT_RT) \u0026\u0026 kfree_rcu_sheaf(ptr))\n+\tif (kfree_rcu_sheaf(ptr))\n \t\treturn;\n \n \t// Queue the object but don't yet schedule the batch.\n@@ -2009,7 +2058,6 @@ void kvfree_call_rcu(struct rcu_head *head, void *ptr)\n \t\t\t// Inline if kvfree_rcu(one_arg) call.\n \t\t\tgoto unlock_return;\n \n-\t\thead-\u003efunc = ptr;\n \t\thead-\u003enext = krcp-\u003ehead;\n \t\tWRITE_ONCE(krcp-\u003ehead, head);\n \t\tatomic_inc(\u0026krcp-\u003ehead_count);\n@@ -2142,17 +2190,16 @@ EXPORT_SYMBOL_GPL(kvfree_rcu_barrier);\n */\n void kvfree_rcu_barrier_on_cache(struct kmem_cache *s)\n {\n+\t/* kfree_rcu_nolock() might have deferred frees even without sheaves */\n+\tdeferred_work_barrier();\n+\n \tif (cache_has_sheaves(s)) {\n \t\tcpus_read_lock();\n \t\tflush_rcu_sheaves_on_cache(s);\n \t\tcpus_read_unlock();\n-\t\trcu_barrier();\n \t}\n \n-\t/*\n-\t * TODO: Introduce a version of __kvfree_rcu_barrier() that works\n-\t * on a specific slab cache.\n-\t */\n+\trcu_barrier();\n \t__kvfree_rcu_barrier();\n }\n EXPORT_SYMBOL_GPL(kvfree_rcu_barrier_on_cache);\ndiff --git a/mm/slub.c b/mm/slub.c\nindex ade17f84e5832..ba2f208262bf6 100644\n--- a/mm/slub.c\n+++ b/mm/slub.c\n@@ -424,6 +424,8 @@ struct slab_sheaf {\n \tunion {\n \t\tstruct rcu_head rcu_head;\n \t\tstruct list_head barn_list;\n+\t\t/* only used to defer call_rcu() in unknown context */\n+\t\tstruct llist_node llnode;\n \t\t/* only used for prefilled sheafs */\n \t\tstruct {\n \t\t\tunsigned int capacity;\n@@ -906,6 +908,24 @@ static inline void slab_set_obj_exts_in_object(struct slab *slab)\n }\n #endif\n \n+/*\n+ * A no-op function used to attach kprobe handlers in slub_kunit tests.\n+ * The barrier is needed to prevent the compiler from optimizing out callsites.\n+ */\n+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PROVE_LOCKING)\n+static noinline void slab_attach_kprobe_locked(void)\n+{\n+\tbarrier();\n+}\n+#else\n+static inline void slab_attach_kprobe_locked(void) { }\n+#endif\n+\n+#define slab_lockdep_assert_held(lock) do {\t\\\n+\tlockdep_assert_held(lock);\t\t\\\n+\tslab_attach_kprobe_locked();\t\\\n+} while (0)\n+\n #ifdef CONFIG_SLUB_DEBUG\n \n /*\n@@ -1663,7 +1683,7 @@ static void add_full(struct kmem_cache *s,\n \tif (!(s-\u003eflags \u0026 SLAB_STORE_USER))\n \t\treturn;\n \n-\tlockdep_assert_held(\u0026n-\u003elist_lock);\n+\tslab_lockdep_assert_held(\u0026n-\u003elist_lock);\n \tlist_add(\u0026slab-\u003eslab_list, \u0026n-\u003efull);\n }\n \n@@ -1672,7 +1692,7 @@ static void remove_full(struct kmem_cache *s, struct kmem_cache_node *n, struct\n \tif (!(s-\u003eflags \u0026 SLAB_STORE_USER))\n \t\treturn;\n \n-\tlockdep_assert_held(\u0026n-\u003elist_lock);\n+\tslab_lockdep_assert_held(\u0026n-\u003elist_lock);\n \tlist_del(\u0026slab-\u003eslab_list);\n }\n \n@@ -2816,7 +2836,8 @@ static inline struct slab_sheaf *alloc_empty_sheaf(struct kmem_cache *s,\n \treturn __alloc_empty_sheaf(s, gfp, alloc_flags, s-\u003esheaf_capacity);\n }\n \n-static void free_empty_sheaf(struct kmem_cache *s, struct slab_sheaf *sheaf)\n+static void __free_empty_sheaf(struct kmem_cache *s, struct slab_sheaf *sheaf,\n+\t\t\t unsigned int free_flags)\n {\n \t/*\n \t * If the sheaf was created with SLAB_ALLOC_NO_RECURSE flag then its\n@@ -2828,11 +2849,20 @@ static void free_empty_sheaf(struct kmem_cache *s, struct slab_sheaf *sheaf)\n \t\tmark_obj_codetag_empty(sheaf);\n \n \tVM_WARN_ON_ONCE(sheaf-\u003esize \u003e 0);\n-\tkfree(sheaf);\n+\n+\tif (unlikely(free_flags \u0026 SLAB_FREE_NOLOCK))\n+\t\tkfree_nolock(sheaf);\n+\telse\n+\t\tkfree(sheaf);\n \n \tstat(s, SHEAF_FREE);\n }\n \n+static void free_empty_sheaf(struct kmem_cache *s, struct slab_sheaf *sheaf)\n+{\n+\t__free_empty_sheaf(s, sheaf, SLAB_FREE_DEFAULT);\n+}\n+\n static unsigned int\n refill_objects(struct kmem_cache *s, void **p, gfp_t gfp, unsigned int min,\n \t unsigned int max);\n@@ -2885,7 +2915,7 @@ static unsigned int __sheaf_flush_main_batch(struct kmem_cache *s)\n \tvoid *objects[PCS_BATCH_MAX];\n \tstruct slab_sheaf *sheaf;\n \n-\tlockdep_assert_held(this_cpu_ptr(\u0026s-\u003ecpu_sheaves-\u003elock));\n+\tslab_lockdep_assert_held(this_cpu_ptr(\u0026s-\u003ecpu_sheaves-\u003elock));\n \n \tpcs = this_cpu_ptr(s-\u003ecpu_sheaves);\n \tsheaf = pcs-\u003emain;\n@@ -3570,7 +3600,7 @@ __add_partial(struct kmem_cache_node *n, struct slab *slab, enum add_mode mode)\n static inline void add_partial(struct kmem_cache_node *n,\n \t\t\t\tstruct slab *slab, enum add_mode mode)\n {\n-\tlockdep_assert_held(\u0026n-\u003elist_lock);\n+\tslab_lockdep_assert_held(\u0026n-\u003elist_lock);\n \t__add_partial(n, slab, mode);\n }\n \n@@ -3584,7 +3614,7 @@ static inline void clear_node_partial_state(struct kmem_cache_node *n,\n static inline void remove_partial(struct kmem_cache_node *n,\n \t\t\t\t\tstruct slab *slab)\n {\n-\tlockdep_assert_held(\u0026n-\u003elist_lock);\n+\tslab_lockdep_assert_held(\u0026n-\u003elist_lock);\n \tlist_del(\u0026slab-\u003eslab_list);\n \tclear_node_partial_state(n, slab);\n }\n@@ -3600,7 +3630,7 @@ static void *alloc_single_from_partial(struct kmem_cache *s,\n {\n \tvoid *object;\n \n-\tlockdep_assert_held(\u0026n-\u003elist_lock);\n+\tslab_lockdep_assert_held(\u0026n-\u003elist_lock);\n \n #ifdef CONFIG_SLUB_DEBUG\n \tif (s-\u003eflags \u0026 SLAB_CONSISTENCY_CHECKS) {\n@@ -4069,6 +4099,22 @@ static void flush_all(struct kmem_cache *s)\n \tcpus_read_unlock();\n }\n \n+struct deferred_percpu_work {\n+\tstruct llist_head objects;\n+\tstruct llist_head objects_by_rcu;\n+\tstruct llist_head rcu_sheaves;\n+\tstruct irq_work work;\n+};\n+\n+static void deferred_percpu_work_fn(struct irq_work *work);\n+\n+static DEFINE_PER_CPU(struct deferred_percpu_work, deferred_percpu_work) = {\n+\t.objects = LLIST_HEAD_INIT(objects),\n+\t.objects_by_rcu = LLIST_HEAD_INIT(objects_by_rcu),\n+\t.rcu_sheaves = LLIST_HEAD_INIT(rcu_sheaves),\n+\t.work = IRQ_WORK_INIT(deferred_percpu_work_fn),\n+};\n+\n static void flush_rcu_sheaf(struct work_struct *w)\n {\n \tstruct slub_percpu_sheaves *pcs;\n@@ -4128,6 +4174,8 @@ void flush_all_rcu_sheaves(void)\n {\n \tstruct kmem_cache *s;\n \n+\tdeferred_work_barrier();\n+\n \tcpus_read_lock();\n \tmutex_lock(\u0026slab_mutex);\n \n@@ -4665,7 +4713,7 @@ __pcs_replace_empty_main(struct kmem_cache *s, struct slub_percpu_sheaves *pcs,\n \tstruct node_barn *barn;\n \tbool allow_spin;\n \n-\tlockdep_assert_held(this_cpu_ptr(\u0026s-\u003ecpu_sheaves-\u003elock));\n+\tslab_lockdep_assert_held(this_cpu_ptr(\u0026s-\u003ecpu_sheaves-\u003elock));\n \n \t/* Bootstrap or debug cache, back off */\n \tif (unlikely(!cache_has_sheaves(s))) {\n@@ -5783,7 +5831,7 @@ static void __pcs_install_empty_sheaf(struct kmem_cache *s,\n \t\tstruct slub_percpu_sheaves *pcs, struct slab_sheaf *empty,\n \t\tstruct node_barn *barn)\n {\n-\tlockdep_assert_held(this_cpu_ptr(\u0026s-\u003ecpu_sheaves-\u003elock));\n+\tslab_lockdep_assert_held(this_cpu_ptr(\u0026s-\u003ecpu_sheaves-\u003elock));\n \n \t/* This is what we expect to find if nobody interrupted us. */\n \tif (likely(!pcs-\u003espare)) {\n@@ -5834,7 +5882,7 @@ __pcs_replace_full_main(struct kmem_cache *s, struct slub_percpu_sheaves *pcs,\n \tbool put_fail;\n \n restart:\n-\tlockdep_assert_held(this_cpu_ptr(\u0026s-\u003ecpu_sheaves-\u003elock));\n+\tslab_lockdep_assert_held(this_cpu_ptr(\u0026s-\u003ecpu_sheaves-\u003elock));\n \n \t/* Bootstrap or debug cache, back off */\n \tif (unlikely(!cache_has_sheaves(s))) {\n@@ -6035,24 +6083,26 @@ static void rcu_free_sheaf(struct rcu_head *head)\n * kvfree_call_rcu() can be called while holding a raw_spinlock_t. Since\n * __kfree_rcu_sheaf() may acquire a spinlock_t (sleeping lock on PREEMPT_RT),\n * this would violate lock nesting rules. Therefore, kvfree_call_rcu() avoids\n- * this problem by bypassing the sheaves layer entirely on PREEMPT_RT.\n+ * this problem by passing SLAB_FREE_NOLOCK on PREEMPT_RT.\n *\n * However, lockdep still complains that it is invalid to acquire spinlock_t\n * while holding raw_spinlock_t, even on !PREEMPT_RT where spinlock_t is a\n * spinning lock. Tell lockdep that acquiring spinlock_t is valid here\n- * by temporarily raising the wait-type to LD_WAIT_CONFIG.\n+ * by temporarily raising the wait-type to LD_WAIT_CONFIG. Skip the lockdep map\n+ * on PREEMPT_RT to avoid suppressing valid lockdep warnings.\n */\n static DEFINE_WAIT_OVERRIDE_MAP(kfree_rcu_sheaf_map, LD_WAIT_CONFIG);\n \n-bool __kfree_rcu_sheaf(struct kmem_cache *s, void *obj)\n+bool __kfree_rcu_sheaf(struct kmem_cache *s, void *obj, unsigned int free_flags)\n {\n \tstruct slub_percpu_sheaves *pcs;\n \tstruct slab_sheaf *rcu_sheaf;\n+\tbool allow_spin = free_flags_allow_spinning(free_flags);\n \n-\tif (WARN_ON_ONCE(IS_ENABLED(CONFIG_PREEMPT_RT)))\n-\t\treturn false;\n+\tVM_WARN_ON_ONCE(IS_ENABLED(CONFIG_PREEMPT_RT) \u0026\u0026 allow_spin);\n \n-\tlock_map_acquire_try(\u0026kfree_rcu_sheaf_map);\n+\tif (!IS_ENABLED(CONFIG_PREEMPT_RT))\n+\t\tlock_map_acquire_try(\u0026kfree_rcu_sheaf_map);\n \n \tif (!local_trylock(\u0026s-\u003ecpu_sheaves-\u003elock))\n \t\tgoto fail;\n@@ -6060,9 +6110,10 @@ bool __kfree_rcu_sheaf(struct kmem_cache *s, void *obj)\n \tpcs = this_cpu_ptr(s-\u003ecpu_sheaves);\n \n \tif (unlikely(!pcs-\u003ercu_free)) {\n-\n \t\tstruct slab_sheaf *empty;\n \t\tstruct node_barn *barn;\n+\t\tunsigned int alloc_flags = to_alloc_flags(free_flags);\n+\t\tgfp_t gfp = allow_spin ? GFP_NOWAIT : __GFP_NOWARN;\n \n \t\t/* Bootstrap or debug cache, fall back */\n \t\tif (unlikely(!cache_has_sheaves(s))) {\n@@ -6082,7 +6133,7 @@ bool __kfree_rcu_sheaf(struct kmem_cache *s, void *obj)\n \t\t\tgoto fail;\n \t\t}\n \n-\t\tempty = barn_get_empty_sheaf(barn, true);\n+\t\tempty = barn_get_empty_sheaf(barn, allow_spin);\n \n \t\tif (empty) {\n \t\t\tpcs-\u003ercu_free = empty;\n@@ -6091,20 +6142,20 @@ bool __kfree_rcu_sheaf(struct kmem_cache *s, void *obj)\n \n \t\tlocal_unlock(\u0026s-\u003ecpu_sheaves-\u003elock);\n \n-\t\tempty = alloc_empty_sheaf(s, GFP_NOWAIT, SLAB_ALLOC_DEFAULT);\n+\t\tempty = alloc_empty_sheaf(s, gfp, alloc_flags);\n \n \t\tif (!empty)\n \t\t\tgoto fail;\n \n \t\tif (!local_trylock(\u0026s-\u003ecpu_sheaves-\u003elock)) {\n-\t\t\tbarn_put_empty_sheaf(barn, empty);\n+\t\t\t__free_empty_sheaf(s, empty, free_flags);\n \t\t\tgoto fail;\n \t\t}\n \n \t\tpcs = this_cpu_ptr(s-\u003ecpu_sheaves);\n \n \t\tif (unlikely(pcs-\u003ercu_free))\n-\t\t\tbarn_put_empty_sheaf(barn, empty);\n+\t\t\t__free_empty_sheaf(s, empty, free_flags);\n \t\telse\n \t\t\tpcs-\u003ercu_free = empty;\n \t}\n@@ -6130,18 +6181,34 @@ bool __kfree_rcu_sheaf(struct kmem_cache *s, void *obj)\n \t * we flush before local_unlock to make sure a racing\n \t * flush_all_rcu_sheaves() doesn't miss this sheaf\n \t */\n-\tif (rcu_sheaf)\n-\t\tcall_rcu(\u0026rcu_sheaf-\u003ercu_head, rcu_free_sheaf);\n+\tif (rcu_sheaf) {\n+\t\t/*\n+\t\t * With !allow_spin, we might have interrupted call_rcu()'s\n+\t\t * IRQ-disabled critical section. If IRQs are not disabled,\n+\t\t * we know that's not the case.\n+\t\t */\n+\t\tif (unlikely(!allow_spin \u0026\u0026 irqs_disabled())) {\n+\t\t\tstruct deferred_percpu_work *dpw;\n+\n+\t\t\tdpw = this_cpu_ptr(\u0026deferred_percpu_work);\n+\t\t\tif (llist_add(\u0026rcu_sheaf-\u003ellnode, \u0026dpw-\u003ercu_sheaves))\n+\t\t\t\tirq_work_queue(\u0026dpw-\u003ework);\n+\t\t} else {\n+\t\t\tcall_rcu(\u0026rcu_sheaf-\u003ercu_head, rcu_free_sheaf);\n+\t\t}\n+\t}\n \n \tlocal_unlock(\u0026s-\u003ecpu_sheaves-\u003elock);\n \n \tstat(s, FREE_RCU_SHEAF);\n-\tlock_map_release(\u0026kfree_rcu_sheaf_map);\n+\tif (!IS_ENABLED(CONFIG_PREEMPT_RT))\n+\t\tlock_map_release(\u0026kfree_rcu_sheaf_map);\n \treturn true;\n \n fail:\n \tstat(s, FREE_RCU_SHEAF_FAIL);\n-\tlock_map_release(\u0026kfree_rcu_sheaf_map);\n+\tif (!IS_ENABLED(CONFIG_PREEMPT_RT))\n+\t\tlock_map_release(\u0026kfree_rcu_sheaf_map);\n \treturn false;\n }\n \n@@ -6330,31 +6397,22 @@ static void free_to_pcs_bulk(struct kmem_cache *s, size_t size, void **p)\n \t}\n }\n \n-struct defer_free {\n-\tstruct llist_head objects;\n-\tstruct irq_work work;\n-};\n-\n-static void free_deferred_objects(struct irq_work *work);\n-\n-static DEFINE_PER_CPU(struct defer_free, defer_free_objects) = {\n-\t.objects = LLIST_HEAD_INIT(objects),\n-\t.work = IRQ_WORK_INIT(free_deferred_objects),\n-};\n-\n /*\n * In PREEMPT_RT irq_work runs in per-cpu kthread, so it's safe\n * to take sleeping spin_locks from __slab_free().\n * In !PREEMPT_RT irq_work will run after local_unlock_irqrestore().\n */\n-static void free_deferred_objects(struct irq_work *work)\n+static void deferred_percpu_work_fn(struct irq_work *work)\n {\n-\tstruct defer_free *df = container_of(work, struct defer_free, work);\n-\tstruct llist_head *objs = \u0026df-\u003eobjects;\n+\tstruct deferred_percpu_work *dpw;\n+\tstruct llist_head *objs, *objs_by_rcu, *rcu_sheaves;\n \tstruct llist_node *llnode, *pos, *t;\n+\tstruct slab_sheaf *sheaf, *next;\n \n-\tif (llist_empty(objs))\n-\t\treturn;\n+\tdpw = container_of(work, struct deferred_percpu_work, work);\n+\trcu_sheaves = \u0026dpw-\u003ercu_sheaves;\n+\tobjs = \u0026dpw-\u003eobjects;\n+\tobjs_by_rcu = \u0026dpw-\u003eobjects_by_rcu;\n \n \tllnode = llist_del_all(objs);\n \tllist_for_each_safe(pos, t, llnode) {\n@@ -6378,27 +6436,51 @@ static void free_deferred_objects(struct irq_work *work)\n \t\t__slab_free(s, slab, x, x, 1, _THIS_IP_);\n \t\tstat(s, FREE_SLOWPATH);\n \t}\n+\n+\tllnode = llist_del_all(objs_by_rcu);\n+\tllist_for_each_safe(pos, t, llnode) {\n+\t\tvoid *head = pos;\n+\t\tvoid *objp = kvmalloc_obj_start_addr(head);\n+\n+\t\tkvfree_call_rcu(head, objp);\n+\t}\n+\n+\tllnode = llist_del_all(rcu_sheaves);\n+\tllist_for_each_entry_safe(sheaf, next, llnode, llnode)\n+\t\tcall_rcu(\u0026sheaf-\u003ercu_head, rcu_free_sheaf);\n }\n \n static void defer_free(struct kmem_cache *s, void *head)\n {\n-\tstruct defer_free *df;\n+\tstruct deferred_percpu_work *dpw;\n \n \tguard(preempt)();\n \n \thead = kasan_reset_tag(head);\n \n-\tdf = this_cpu_ptr(\u0026defer_free_objects);\n-\tif (llist_add(head + s-\u003eoffset, \u0026df-\u003eobjects))\n-\t\tirq_work_queue(\u0026df-\u003ework);\n+\tdpw = this_cpu_ptr(\u0026deferred_percpu_work);\n+\tif (llist_add(head + s-\u003eoffset, \u0026dpw-\u003eobjects))\n+\t\tirq_work_queue(\u0026dpw-\u003ework);\n+}\n+\n+void defer_kfree_rcu(struct kvfree_rcu_head *head)\n+{\n+\tstruct deferred_percpu_work *dpw;\n+\n+\tguard(preempt)();\n+\n+\tdpw = this_cpu_ptr(\u0026deferred_percpu_work);\n+\tif (llist_add((struct llist_node *)head, \u0026dpw-\u003eobjects_by_rcu))\n+\t\tirq_work_queue(\u0026dpw-\u003ework);\n }\n \n-void defer_free_barrier(void)\n+/* Must be called before flush_rcu_sheaves_on_cache() */\n+void deferred_work_barrier(void)\n {\n \tint cpu;\n \n \tfor_each_possible_cpu(cpu)\n-\t\tirq_work_sync(\u0026per_cpu_ptr(\u0026defer_free_objects, cpu)-\u003ework);\n+\t\tirq_work_sync(\u0026per_cpu_ptr(\u0026deferred_percpu_work, cpu)-\u003ework);\n }\n \n static __fastpath_inline\n@@ -6657,43 +6739,21 @@ static void free_large_kmalloc(struct page *page, void *object)\n */\n void kvfree_rcu_cb(struct rcu_head *head)\n {\n-\tvoid *obj = head;\n-\tstruct page *page;\n-\tstruct slab *slab;\n-\tstruct kmem_cache *s;\n-\tvoid *slab_addr;\n+\tvoid *obj;\n+\n+\tobj = kvmalloc_obj_start_addr(head);\n \n \tif (is_vmalloc_addr(obj)) {\n-\t\tobj = (void *) PAGE_ALIGN_DOWN((unsigned long)obj);\n \t\tvfree(obj);\n-\t\treturn;\n-\t}\n-\n-\tpage = virt_to_page(obj);\n-\tslab = page_slab(page);\n-\tif (!slab) {\n-\t\t/*\n-\t\t * rcu_head offset can be only less than page size so no need to\n-\t\t * consider allocation order\n-\t\t */\n-\t\tobj = (void *) PAGE_ALIGN_DOWN((unsigned long)obj);\n-\t\tfree_large_kmalloc(page, obj);\n-\t\treturn;\n-\t}\n-\n-\ts = slab-\u003eslab_cache;\n-\tslab_addr = slab_address(slab);\n-\n-\tif (is_kfence_address(obj)) {\n-\t\tobj = kfence_object_start(obj);\n \t} else {\n-\t\tunsigned int idx = __obj_to_index(s, slab_addr, obj);\n+\t\tstruct page *page = virt_to_page(obj);\n+\t\tstruct slab *slab = page_slab(page);\n \n-\t\tobj = slab_addr + s-\u003esize * idx;\n-\t\tobj = fixup_red_left(s, obj);\n+\t\tif (slab)\n+\t\t\tslab_free(slab-\u003eslab_cache, slab, obj, _RET_IP_);\n+\t\telse\n+\t\t\tfree_large_kmalloc(page, obj);\n \t}\n-\n-\tslab_free(s, slab, obj, _RET_IP_);\n }\n \n /**\n"
} |
| 2/1 | 2026/07/30 14:43 | agent | patch-evaluator |
1mModel:best-expensive Args: null Results: {
"EnableConfigs": [
"SLUB_KUNIT_TEST",
"KUNIT",
"PERF_EVENTS",
"KPROBES",
"SMP",
"SLUB_DEBUG",
"KVFREE_RCU_BATCHED"
],
"FocusSymbols": [
"kfree_call_rcu_nolock",
"kvfree_call_rcu",
"__kfree_rcu_sheaf",
"defer_kfree_rcu",
"deferred_work_barrier",
"kvfree_rcu_barrier",
"kvfree_rcu_barrier_on_cache"
],
"Reasoning": "The patch introduces `kfree_rcu_nolock()` API which allows deferring freeing of objects in any context without locks. It modifies `kvfree_call_rcu()` to use `struct kvfree_rcu_head` and implements `kfree_call_rcu_nolock()` which relies on `__kfree_rcu_sheaf()` and `defer_kfree_rcu()`. It also adds KUnit tests for these new APIs using perf events and kprobes. This is a core memory management and RCU change that is highly functional and reachable.",
"WorthFuzzing": true
}Instruction: You are an expert Linux kernel maintainer. Your job is to review a provided patch series and determine if it makes functional changes to the kernel that should be fuzzed. IMPORTANT: The changes have ALREADY been applied and committed as the HEAD commit in your workspace. Do NOT rely on your internal knowledge of the kernel. You must actively use your code access tools to examine the actual source code and confirm any assumptions. Return WorthFuzzing=false if the patch only contains: - Modifications to Documentation/, Kconfig files, or code comments. - Purely decorative changes, such as logging (e.g., pr_err, printk) or tracepoints. - Changes to numeric constants or macros that do not functionally alter execution flow. - Code paths that are impossible to reach in virtualized environments like GCE or QEMU, even when utilizing software-emulated hardware (e.g., usb gadget, mac80211_hwsim). - Code in vendor-specific PCIe switch, SmartNIC, or GPU drivers (e.g., mlxsw, pds_core, qed, ionic, amdgpu) that require physical PCIe hardware cards not emulated in standard QEMU. - Driver .remove, .shutdown, or pci_unregister_driver teardown callbacks (e.g., igb_remove) that are executed only during PCI hot-unplug or sysfs driver unbind operations. If it modifies reachable core kernel logic, drivers, or architectures, use your code search tools to verify the code can be executed, then return WorthFuzzing=true. When returning WorthFuzzing=true, you MUST ALSO: 1. Extract any specific kernel functions that should be heavily fuzzed into FocusSymbols. Avoid listing generic hot-path functions to prevent skewed test distributions. Prefer non-static, non-inlined API entrypoint functions over internal static helper functions (which are inlined by the compiler and do not have distinct symbol addresses). 2. Identify any specific CONFIG_ options required to properly test this new/modified feature. Go and look into the Kconfig files and check for ifdefs around the code, do not make assumptions. Also check "depends on" lines in Kconfig to include any non-standard parent subsystem configs needed for Kbuild to compile the code statically into vmlinux. List them in the EnableConfigs output array, and DO NOT add a '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: For your convenience, here is the diff of the changes:
commit 56bb7565a8ecf47c9f52258f16c540812b33833e
Author: syz-cluster <triage@syzkaller.com>
Date: Thu Jul 30 14:43:13 2026 +0000
syz-cluster: applied patch under review
diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
index 5e95acc33989b..aede77bd03873 100644
--- a/include/linux/rcupdate.h
+++ b/include/linux/rcupdate.h
@@ -1098,19 +1098,22 @@ static inline void rcu_read_unlock_migrate(void)
/*
* In mm/slab_common.c, no suitable header to include here.
*/
-void kvfree_call_rcu(struct rcu_head *head, void *ptr);
+void kvfree_call_rcu(struct kvfree_rcu_head *head, void *ptr);
+void kfree_call_rcu_nolock(struct kvfree_rcu_head *head, void *ptr);
/*
* The BUILD_BUG_ON() makes sure the rcu_head offset can be handled. See the
* comment of kfree_rcu() for details.
*/
-#define kvfree_rcu_arg_2(ptr, rhf) \
+#define kvfree_rcu_arg_2(ptr, kvrhf) \
do { \
typeof (ptr) ___p = (ptr); \
+ struct kvfree_rcu_head *___head; \
\
if (___p) { \
- BUILD_BUG_ON(offsetof(typeof(*(ptr)), rhf) >= 4096); \
- kvfree_call_rcu(&((___p)->rhf), (void *) (___p)); \
+ BUILD_BUG_ON(offsetof(typeof(*(ptr)), kvrhf) >= 4096); \
+ ___head = (struct kvfree_rcu_head *) &(___p)->kvrhf; \
+ kvfree_call_rcu(___head, (void *) (___p)); \
} \
} while (0)
@@ -1122,6 +1125,27 @@ do { \
kvfree_call_rcu(NULL, (void *) (___p)); \
} while (0)
+/**
+ * kfree_rcu_nolock() - a version of kfree_rcu() that can be called in any context.
+ * @ptr: pointer to kfree for double-argument invocations.
+ * @kvrhf: the name of the struct kvfree_rcu_head within the type of @ptr.
+ *
+ * With KVFREE_RCU_BATCHED, kfree_rcu_nolock() tries hard to free objects
+ * without any deferred processing, but may still defer freeing.
+ * Large kmalloc and vmalloc objects are always deferred.
+ *
+ * kfree_rcu_nolock() supports 2-arg variant only.
+ */
+#define kfree_rcu_nolock(ptr, kvrhf) \
+do { \
+ typeof (ptr) ___p = (ptr); \
+ \
+ if (___p) { \
+ BUILD_BUG_ON(offsetof(typeof(*(ptr)), kvrhf) >= 4096); \
+ kfree_call_rcu_nolock(&((___p)->kvrhf), (void *) (___p)); \
+ } \
+} while (0)
+
/*
* Place this after a lock-acquisition primitive to guarantee that
* an UNLOCK+LOCK pair acts as a full barrier. This guarantee applies
diff --git a/include/linux/slab.h b/include/linux/slab.h
index e1915026e0304..cda126def67af 100644
--- a/include/linux/slab.h
+++ b/include/linux/slab.h
@@ -1430,25 +1430,15 @@ extern void kvfree_sensitive(const void *addr, size_t len);
unsigned int kmem_cache_size(struct kmem_cache *s);
#ifndef CONFIG_KVFREE_RCU_BATCHED
-static inline void kvfree_rcu_barrier(void)
-{
- rcu_barrier();
-}
-
-static inline void kvfree_rcu_barrier_on_cache(struct kmem_cache *s)
-{
- rcu_barrier();
-}
-
static inline void kfree_rcu_scheduler_running(void) { }
#else
+void kfree_rcu_scheduler_running(void);
+#endif
+
void kvfree_rcu_barrier(void);
void kvfree_rcu_barrier_on_cache(struct kmem_cache *s);
-void kfree_rcu_scheduler_running(void);
-#endif
-
/**
* kmalloc_size_roundup - Report allocation bucket size for the given size
*
diff --git a/include/linux/types.h b/include/linux/types.h
index bc5dda2a3d861..79bf419c69e47 100644
--- a/include/linux/types.h
+++ b/include/linux/types.h
@@ -257,6 +257,14 @@ struct callback_head {
} __attribute__((aligned(sizeof(void *))));
#define rcu_head callback_head
+#ifdef CONFIG_KVFREE_RCU_BATCHED
+struct kvfree_rcu_head {
+ struct kvfree_rcu_head *next;
+};
+#else
+#define kvfree_rcu_head rcu_head
+#endif
+
typedef void (*rcu_callback_t)(struct rcu_head *head);
typedef void (*call_rcu_func_t)(struct rcu_head *head, rcu_callback_t func);
diff --git a/include/trace/events/rcu.h b/include/trace/events/rcu.h
index 5fbdabe3faead..a74027126a2fd 100644
--- a/include/trace/events/rcu.h
+++ b/include/trace/events/rcu.h
@@ -625,7 +625,7 @@ TRACE_EVENT_RCU(rcu_invoke_callback,
*/
TRACE_EVENT_RCU(rcu_invoke_kvfree_callback,
- TP_PROTO(const char *rcuname, struct rcu_head *rhp, unsigned long offset),
+ TP_PROTO(const char *rcuname, struct kvfree_rcu_head *rhp, unsigned long offset),
TP_ARGS(rcuname, rhp, offset),
diff --git a/lib/tests/slub_kunit.c b/lib/tests/slub_kunit.c
index fa6d31dbca166..e3b63f0338d5f 100644
--- a/lib/tests/slub_kunit.c
+++ b/lib/tests/slub_kunit.c
@@ -8,6 +8,7 @@
#include <linux/rcupdate.h>
#include <linux/delay.h>
#include <linux/perf_event.h>
+#include <linux/kprobes.h>
#include "../mm/slab.h"
static struct kunit_resource resource;
@@ -161,7 +162,10 @@ static void test_kmalloc_redzone_access(struct kunit *test)
}
struct test_kfree_rcu_struct {
- struct rcu_head rcu;
+ union {
+ struct rcu_head rcu;
+ struct kvfree_rcu_head kvrcu;
+ };
};
static void test_kfree_rcu(struct kunit *test)
@@ -292,19 +296,76 @@ static void test_krealloc_redzone_zeroing(struct kunit *test)
kmem_cache_destroy(s);
}
-#ifdef CONFIG_PERF_EVENTS
+#if defined(CONFIG_PERF_EVENTS) || (defined(CONFIG_KPROBES) && defined(CONFIG_SMP))
#define NR_ITERATIONS 1000
#define NR_OBJECTS 1000
-static void *objects[NR_OBJECTS];
+static struct test_kfree_rcu_struct *objects[NR_OBJECTS];
struct test_nolock_context {
struct kunit *test;
int callback_count;
int alloc_ok;
int alloc_fail;
+#ifdef CONFIG_PERF_EVENTS
struct perf_event *event;
+#endif
+#if defined(CONFIG_KPROBES) && defined(CONFIG_SMP)
+ struct kprobe kprobe;
+#endif
};
+static void test_kmalloc_and_friends(void)
+{
+ int i, j;
+ bool can_use_kfree_rcu = !IS_BUILTIN(CONFIG_SLUB_KUNIT_TEST);
+
+ for (i = 0; i < NR_ITERATIONS; i++) {
+ for (j = 0; j < NR_OBJECTS; j++) {
+ gfp_t gfp = (i & 1) ? GFP_KERNEL : GFP_KERNEL_ACCOUNT;
+
+ objects[j] = kmalloc_obj(*objects[j], gfp);
+ if (!objects[j]) {
+ j--;
+ while (j >= 0)
+ kfree(objects[j--]);
+ return;
+ }
+ }
+
+ for (j = 0; j < NR_OBJECTS; j++) {
+ if (can_use_kfree_rcu && (i & 2))
+ kfree_rcu(objects[j], rcu);
+ else
+ kfree(objects[j]);
+ }
+ }
+}
+
+static void test_nolock(struct test_nolock_context *ctx)
+{
+ struct test_kfree_rcu_struct *objp;
+ gfp_t gfp;
+ bool can_use_kfree_rcu = !IS_BUILTIN(CONFIG_SLUB_KUNIT_TEST);
+
+ /* __GFP_ACCOUNT to test kmalloc_nolock() in alloc_slab_obj_exts() */
+ gfp = (ctx->callback_count & 1) ? 0 : __GFP_ACCOUNT;
+ objp = kmalloc_nolock(sizeof(*objp), gfp, NUMA_NO_NODE);
+
+ if (objp)
+ ctx->alloc_ok++;
+ else
+ ctx->alloc_fail++;
+
+ if (can_use_kfree_rcu && (ctx->callback_count & 2))
+ kfree_rcu_nolock(objp, kvrcu);
+ else
+ kfree_nolock(objp);
+
+ ctx->callback_count++;
+}
+#endif
+
+#ifdef CONFIG_PERF_EVENTS
static struct perf_event_attr hw_attr = {
.type = PERF_TYPE_HARDWARE,
.config = PERF_COUNT_HW_CPU_CYCLES,
@@ -315,67 +376,91 @@ static struct perf_event_attr hw_attr = {
.sample_freq = 100000,
};
-static void overflow_handler_test_kmalloc_kfree_nolock(struct perf_event *event,
- struct perf_sample_data *data,
- struct pt_regs *regs)
+static void overflow_handler_test_nolock(struct perf_event *event,
+ struct perf_sample_data *data,
+ struct pt_regs *regs)
{
- void *objp;
- gfp_t gfp;
struct test_nolock_context *ctx = event->overflow_handler_context;
- /* __GFP_ACCOUNT to test kmalloc_nolock() in alloc_slab_obj_exts() */
- gfp = (ctx->callback_count % 2) ? 0 : __GFP_ACCOUNT;
- objp = kmalloc_nolock(64, gfp, NUMA_NO_NODE);
-
- if (objp)
- ctx->alloc_ok++;
- else
- ctx->alloc_fail++;
-
- kfree_nolock(objp);
- ctx->callback_count++;
+ test_nolock(ctx);
}
-static void test_kmalloc_kfree_nolock(struct kunit *test)
+static bool enable_perf_events(struct test_nolock_context *ctx)
{
- int i, j;
- struct test_nolock_context ctx = { .test = test };
struct perf_event *event;
- bool alloc_fail = false;
event = perf_event_create_kernel_counter(&hw_attr, -1, current,
- overflow_handler_test_kmalloc_kfree_nolock,
- &ctx);
+ overflow_handler_test_nolock,
+ ctx);
+
if (IS_ERR(event))
- kunit_skip(test, "Failed to create perf event");
- ctx.event = event;
- perf_event_enable(ctx.event);
- for (i = 0; i < NR_ITERATIONS; i++) {
- for (j = 0; j < NR_OBJECTS; j++) {
- gfp_t gfp = (i % 2) ? GFP_KERNEL : GFP_KERNEL_ACCOUNT;
+ return false;
- objects[j] = kmalloc(64, gfp);
- if (!objects[j]) {
- j--;
- while (j >= 0)
- kfree(objects[j--]);
- alloc_fail = true;
- goto cleanup;
- }
- }
- for (j = 0; j < NR_OBJECTS; j++)
- kfree(objects[j]);
- }
+ ctx->event = event;
+ perf_event_enable(ctx->event);
+ return true;
+}
+
+static void disable_perf_events(struct test_nolock_context *ctx)
+{
+ kunit_info(ctx->test, "HW perf events: callback_count: %d, alloc_ok: %d, alloc_fail: %d\n",
+ ctx->callback_count, ctx->alloc_ok, ctx->alloc_fail);
+
+ perf_event_disable(ctx->event);
+ perf_event_release_kernel(ctx->event);
+}
+
+static void test_kmalloc_nolock_and_friends_perf(struct kunit *test)
+{
+ struct test_nolock_context ctx = { .test = test };
-cleanup:
- perf_event_disable(ctx.event);
- perf_event_release_kernel(ctx.event);
+ if (!enable_perf_events(&ctx))
+ kunit_skip(test, "Failed to enable perf event, skipping");
- kunit_info(test, "callback_count: %d, alloc_ok: %d, alloc_fail: %d\n",
- ctx.callback_count, ctx.alloc_ok, ctx.alloc_fail);
+ test_kmalloc_and_friends();
- if (alloc_fail)
- kunit_skip(test, "Allocation failed");
+ disable_perf_events(&ctx);
+ KUNIT_EXPECT_EQ(test, 0, slab_errors);
+}
+#endif
+
+#if defined(CONFIG_KPROBES) && defined(CONFIG_SMP)
+static int slab_kprobe_pre_handler(struct kprobe *p, struct pt_regs *regs)
+{
+ struct test_nolock_context *ctx;
+
+ ctx = container_of(p, struct test_nolock_context, kprobe);
+ test_nolock(ctx);
+ return 0;
+}
+
+static bool register_slab_kprobes(struct test_nolock_context *ctx)
+{
+ ctx->kprobe.symbol_name = "slab_attach_kprobe_locked";
+ ctx->kprobe.pre_handler = slab_kprobe_pre_handler;
+
+ if (register_kprobe(&ctx->kprobe))
+ return false;
+ return true;
+}
+
+static void unregister_slab_kprobes(struct test_nolock_context *ctx)
+{
+ kunit_info(ctx->test, "kprobes: callback_count: %d, alloc_ok: %d, alloc_fail: %d\n",
+ ctx->callback_count, ctx->alloc_ok, ctx->alloc_fail);
+ unregister_kprobe(&ctx->kprobe);
+}
+
+static void test_kmalloc_nolock_and_friends_kprobe(struct kunit *test)
+{
+ struct test_nolock_context ctx = { .test = test };
+
+ if (!register_slab_kprobes(&ctx))
+ kunit_skip(test, "Failed to register kprobe, skipping");
+
+ test_kmalloc_and_friends();
+
+ unregister_slab_kprobes(&ctx);
KUNIT_EXPECT_EQ(test, 0, slab_errors);
}
#endif
@@ -405,7 +490,10 @@ static struct kunit_case test_cases[] = {
KUNIT_CASE(test_leak_destroy),
KUNIT_CASE(test_krealloc_redzone_zeroing),
#ifdef CONFIG_PERF_EVENTS
- KUNIT_CASE_SLOW(test_kmalloc_kfree_nolock),
+ KUNIT_CASE_SLOW(test_kmalloc_nolock_and_friends_perf),
+#endif
+#if defined(CONFIG_KPROBES) && defined(CONFIG_SMP)
+ KUNIT_CASE_SLOW(test_kmalloc_nolock_and_friends_kprobe),
#endif
{}
};
diff --git a/mm/slab.h b/mm/slab.h
index e01c1015b8c8d..8fd6835e42352 100644
--- a/mm/slab.h
+++ b/mm/slab.h
@@ -24,11 +24,27 @@
#define SLAB_ALLOC_NO_RECURSE 0x04 /* prevent kmalloc() recursion */
#define SLAB_ALLOC_NO_OBJ_EXT 0x08 /* prevent obj_exts array allocation */
+#define SLAB_FREE_DEFAULT 0x00 /* no flags */
+#define SLAB_FREE_NOLOCK 0x01 /* spinning not allowed */
+
+static inline unsigned int to_alloc_flags(unsigned int free_flags)
+{
+ if (free_flags & SLAB_FREE_NOLOCK)
+ return SLAB_ALLOC_NOLOCK;
+ else
+ return SLAB_ALLOC_DEFAULT;
+}
+
static inline bool alloc_flags_allow_spinning(const unsigned int alloc_flags)
{
return !(alloc_flags & SLAB_ALLOC_NOLOCK);
}
+static inline bool free_flags_allow_spinning(const unsigned int free_flags)
+{
+ return !(free_flags & SLAB_FREE_NOLOCK);
+}
+
void *__kmalloc_flags_noprof(DECL_TOKEN_PARAMS(size, token), gfp_t flags,
unsigned int alloc_flags, int node)
__assume_kmalloc_alignment __alloc_size(1);
@@ -331,6 +347,37 @@ static inline unsigned int obj_to_index(const struct kmem_cache *cache,
return __obj_to_index(cache, slab_address(slab), obj);
}
+/*
+ * kvfree_rcu_head offset can be only less than page size.
+ * Calculate the start address while preserving the KASAN tag.
+ */
+static inline void *kvmalloc_obj_start_addr(void *head)
+{
+ unsigned long offset;
+
+ if (unlikely(is_vmalloc_addr(head))) {
+ offset = offset_in_page(head);
+ } else {
+ struct slab *slab = virt_to_slab(head);
+
+ if (!slab) {
+ offset = offset_in_page(head);
+ } else if (is_kfence_address(head)) {
+ offset = head - kfence_object_start(head);
+ } else {
+ struct kmem_cache *s = slab->slab_cache;
+ unsigned int idx = __obj_to_index(s, slab_address(slab), head);
+ void *obj = slab_address(slab) + s->size * idx;
+
+ obj = fixup_red_left(s, obj);
+ obj = kasan_reset_tag(obj);
+ offset = kasan_reset_tag(head) - obj;
+ }
+ }
+
+ return head - offset;
+}
+
/*
* State of the slab allocator.
*
@@ -431,7 +478,7 @@ static inline bool is_kmalloc_normal(struct kmem_cache *s)
return !(s->flags & (SLAB_CACHE_DMA|SLAB_ACCOUNT|SLAB_RECLAIM_ACCOUNT|SLAB_NO_OBJ_EXT));
}
-bool __kfree_rcu_sheaf(struct kmem_cache *s, void *obj);
+bool __kfree_rcu_sheaf(struct kmem_cache *s, void *obj, unsigned int free_flags);
void flush_all_rcu_sheaves(void);
void flush_rcu_sheaves_on_cache(struct kmem_cache *s);
@@ -899,7 +946,8 @@ void __kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct slab *slab)
void __check_heap_object(const void *ptr, unsigned long n,
const struct slab *slab, bool to_user);
-void defer_free_barrier(void);
+void deferred_work_barrier(void);
+void defer_kfree_rcu(struct kvfree_rcu_head *head);
static inline bool slub_debug_orig_size(struct kmem_cache *s)
{
diff --git a/mm/slab_common.c b/mm/slab_common.c
index 1e1d3feec3535..b8f21eabcccc2 100644
--- a/mm/slab_common.c
+++ b/mm/slab_common.c
@@ -558,7 +558,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
}
/* Wait for deferred work from kmalloc/kfree_nolock() */
- defer_free_barrier();
+ deferred_work_barrier();
cpus_read_lock();
mutex_lock(&slab_mutex);
@@ -1296,6 +1296,33 @@ EXPORT_TRACEPOINT_SYMBOL(kmem_cache_alloc);
EXPORT_TRACEPOINT_SYMBOL(kfree);
EXPORT_TRACEPOINT_SYMBOL(kmem_cache_free);
+void kfree_call_rcu_nolock(struct kvfree_rcu_head *head, void *ptr)
+{
+ struct slab *slab;
+
+ if (!IS_ENABLED(CONFIG_KVFREE_RCU_BATCHED))
+ goto fallback;
+
+ if (unlikely(is_vmalloc_addr(ptr)))
+ goto fallback;
+
+ slab = virt_to_slab(ptr);
+ if (unlikely(!slab))
+ goto fallback;
+
+ if (unlikely(IS_ENABLED(CONFIG_NUMA) && slab_nid(slab) != numa_mem_id()))
+ goto fallback;
+
+ if (unlikely(!__kfree_rcu_sheaf(slab->slab_cache, ptr, SLAB_FREE_NOLOCK)))
+ goto fallback;
+
+ return;
+
+fallback:
+ defer_kfree_rcu(head);
+}
+EXPORT_SYMBOL_GPL(kfree_call_rcu_nolock);
+
#ifndef CONFIG_KVFREE_RCU_BATCHED
void kvfree_call_rcu(struct rcu_head *head, void *ptr)
@@ -1313,6 +1340,20 @@ void kvfree_call_rcu(struct rcu_head *head, void *ptr)
}
EXPORT_SYMBOL_GPL(kvfree_call_rcu);
+void kvfree_rcu_barrier(void)
+{
+ deferred_work_barrier();
+ rcu_barrier();
+}
+EXPORT_SYMBOL_GPL(kvfree_rcu_barrier);
+
+void kvfree_rcu_barrier_on_cache(struct kmem_cache *s)
+{
+ deferred_work_barrier();
+ rcu_barrier();
+}
+EXPORT_SYMBOL_GPL(kvfree_rcu_barrier_on_cache);
+
void __init kvfree_rcu_init(void)
{
}
@@ -1379,7 +1420,7 @@ struct kvfree_rcu_bulk_data {
struct kfree_rcu_cpu_work {
struct rcu_work rcu_work;
- struct rcu_head *head_free;
+ struct kvfree_rcu_head *head_free;
struct rcu_gp_oldstate head_free_gp_snap;
struct list_head bulk_head_free[FREE_N_CHANNELS];
struct kfree_rcu_cpu *krcp;
@@ -1415,7 +1456,7 @@ struct kfree_rcu_cpu_work {
struct kfree_rcu_cpu {
// Objects queued on a linked list
// through their rcu_head structures.
- struct rcu_head *head;
+ struct kvfree_rcu_head *head;
unsigned long head_gp_snap;
atomic_t head_count;
@@ -1556,12 +1597,12 @@ kvfree_rcu_bulk(struct kfree_rcu_cpu *krcp,
}
static void
-kvfree_rcu_list(struct rcu_head *head)
+kvfree_rcu_list(struct kvfree_rcu_head *head)
{
- struct rcu_head *next;
+ struct kvfree_rcu_head *next;
for (; head; head = next) {
- void *ptr = (void *) head->func;
+ void *ptr = kvmalloc_obj_start_addr(head);
unsigned long offset = (void *) head - ptr;
next = head->next;
@@ -1585,7 +1626,7 @@ static void kfree_rcu_work(struct work_struct *work)
unsigned long flags;
struct kvfree_rcu_bulk_data *bnode, *n;
struct list_head bulk_head[FREE_N_CHANNELS];
- struct rcu_head *head;
+ struct kvfree_rcu_head *head;
struct kfree_rcu_cpu *krcp;
struct kfree_rcu_cpu_work *krwp;
struct rcu_gp_oldstate head_gp_snap;
@@ -1628,6 +1669,14 @@ static bool kfree_rcu_sheaf(void *obj)
{
struct kmem_cache *s;
struct slab *slab;
+ unsigned int free_flags = SLAB_FREE_DEFAULT;
+
+ /*
+ * It is not safe to spin on PREEMPT_RT because the kernel might be
+ * holding a raw spinlock and slab acquires sleeping locks.
+ */
+ if (IS_ENABLED(CONFIG_PREEMPT_RT))
+ free_flags = SLAB_FREE_NOLOCK;
if (is_vmalloc_addr(obj))
return false;
@@ -1638,7 +1687,7 @@ static bool kfree_rcu_sheaf(void *obj)
s = slab->slab_cache;
if (likely(!IS_ENABLED(CONFIG_NUMA) || slab_nid(slab) == numa_mem_id()))
- return __kfree_rcu_sheaf(s, obj);
+ return __kfree_rcu_sheaf(s, obj, free_flags);
return false;
}
@@ -1708,7 +1757,7 @@ kvfree_rcu_drain_ready(struct kfree_rcu_cpu *krcp)
{
struct list_head bulk_ready[FREE_N_CHANNELS];
struct kvfree_rcu_bulk_data *bnode, *n;
- struct rcu_head *head_ready = NULL;
+ struct kvfree_rcu_head *head_ready = NULL;
unsigned long flags;
int i;
@@ -1971,7 +2020,7 @@ void __init kfree_rcu_scheduler_running(void)
* be free'd in workqueue context. This allows us to: batch requests together to
* reduce the number of grace periods during heavy kfree_rcu()/kvfree_rcu() load.
*/
-void kvfree_call_rcu(struct rcu_head *head, void *ptr)
+void kvfree_call_rcu(struct kvfree_rcu_head *head, void *ptr)
{
unsigned long flags;
struct kfree_rcu_cpu *krcp;
@@ -1987,7 +2036,7 @@ void kvfree_call_rcu(struct rcu_head *head, void *ptr)
if (!head)
might_sleep();
- if (!IS_ENABLED(CONFIG_PREEMPT_RT) && kfree_rcu_sheaf(ptr))
+ if (kfree_rcu_sheaf(ptr))
return;
// Queue the object but don't yet schedule the batch.
@@ -2009,7 +2058,6 @@ void kvfree_call_rcu(struct rcu_head *head, void *ptr)
// Inline if kvfree_rcu(one_arg) call.
goto unlock_return;
- head->func = ptr;
head->next = krcp->head;
WRITE_ONCE(krcp->head, head);
atomic_inc(&krcp->head_count);
@@ -2142,17 +2190,16 @@ EXPORT_SYMBOL_GPL(kvfree_rcu_barrier);
*/
void kvfree_rcu_barrier_on_cache(struct kmem_cache *s)
{
+ /* kfree_rcu_nolock() might have deferred frees even without sheaves */
+ deferred_work_barrier();
+
if (cache_has_sheaves(s)) {
cpus_read_lock();
flush_rcu_sheaves_on_cache(s);
cpus_read_unlock();
- rcu_barrier();
}
- /*
- * TODO: Introduce a version of __kvfree_rcu_barrier() that works
- * on a specific slab cache.
- */
+ rcu_barrier();
__kvfree_rcu_barrier();
}
EXPORT_SYMBOL_GPL(kvfree_rcu_barrier_on_cache);
diff --git a/mm/slub.c b/mm/slub.c
index ade17f84e5832..ba2f208262bf6 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -424,6 +424,8 @@ struct slab_sheaf {
union {
struct rcu_head rcu_head;
struct list_head barn_list;
+ /* only used to defer call_rcu() in unknown context */
+ struct llist_node llnode;
/* only used for prefilled sheafs */
struct {
unsigned int capacity;
@@ -906,6 +908,24 @@ static inline void slab_set_obj_exts_in_object(struct slab *slab)
}
#endif
+/*
+ * A no-op function used to attach kprobe handlers in slub_kunit tests.
+ * The barrier is needed to prevent the compiler from optimizing out callsites.
+ */
+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PROVE_LOCKING)
+static noinline void slab_attach_kprobe_locked(void)
+{
+ barrier();
+}
+#else
+static inline void slab_attach_kprobe_locked(void) { }
+#endif
+
+#define slab_lockdep_assert_held(lock) do { \
+ lockdep_assert_held(lock); \
+ slab_attach_kprobe_locked(); \
+} while (0)
+
#ifdef CONFIG_SLUB_DEBUG
/*
@@ -1663,7 +1683,7 @@ static void add_full(struct kmem_cache *s,
if (!(s->flags & SLAB_STORE_USER))
return;
- lockdep_assert_held(&n->list_lock);
+ slab_lockdep_assert_held(&n->list_lock);
list_add(&slab->slab_list, &n->full);
}
@@ -1672,7 +1692,7 @@ static void remove_full(struct kmem_cache *s, struct kmem_cache_node *n, struct
if (!(s->flags & SLAB_STORE_USER))
return;
- lockdep_assert_held(&n->list_lock);
+ slab_lockdep_assert_held(&n->list_lock);
list_del(&slab->slab_list);
}
@@ -2816,7 +2836,8 @@ static inline struct slab_sheaf *alloc_empty_sheaf(struct kmem_cache *s,
return __alloc_empty_sheaf(s, gfp, alloc_flags, s->sheaf_capacity);
}
-static void free_empty_sheaf(struct kmem_cache *s, struct slab_sheaf *sheaf)
+static void __free_empty_sheaf(struct kmem_cache *s, struct slab_sheaf *sheaf,
+ unsigned int free_flags)
{
/*
* If the sheaf was created with SLAB_ALLOC_NO_RECURSE flag then its
@@ -2828,11 +2849,20 @@ static void free_empty_sheaf(struct kmem_cache *s, struct slab_sheaf *sheaf)
mark_obj_codetag_empty(sheaf);
VM_WARN_ON_ONCE(sheaf->size > 0);
- kfree(sheaf);
+
+ if (unlikely(free_flags & SLAB_FREE_NOLOCK))
+ kfree_nolock(sheaf);
+ else
+ kfree(sheaf);
stat(s, SHEAF_FREE);
}
+static void free_empty_sheaf(struct kmem_cache *s, struct slab_sheaf *sheaf)
+{
+ __free_empty_sheaf(s, sheaf, SLAB_FREE_DEFAULT);
+}
+
static unsigned int
refill_objects(struct kmem_cache *s, void **p, gfp_t gfp, unsigned int min,
unsigned int max);
@@ -2885,7 +2915,7 @@ static unsigned int __sheaf_flush_main_batch(struct kmem_cache *s)
void *objects[PCS_BATCH_MAX];
struct slab_sheaf *sheaf;
- lockdep_assert_held(this_cpu_ptr(&s->cpu_sheaves->lock));
+ slab_lockdep_assert_held(this_cpu_ptr(&s->cpu_sheaves->lock));
pcs = this_cpu_ptr(s->cpu_sheaves);
sheaf = pcs->main;
@@ -3570,7 +3600,7 @@ __add_partial(struct kmem_cache_node *n, struct slab *slab, enum add_mode mode)
static inline void add_partial(struct kmem_cache_node *n,
struct slab *slab, enum add_mode mode)
{
- lockdep_assert_held(&n->list_lock);
+ slab_lockdep_assert_held(&n->list_lock);
__add_partial(n, slab, mode);
}
@@ -3584,7 +3614,7 @@ static inline void clear_node_partial_state(struct kmem_cache_node *n,
static inline void remove_partial(struct kmem_cache_node *n,
struct slab *slab)
{
- lockdep_assert_held(&n->list_lock);
+ slab_lockdep_assert_held(&n->list_lock);
list_del(&slab->slab_list);
clear_node_partial_state(n, slab);
}
@@ -3600,7 +3630,7 @@ static void *alloc_single_from_partial(struct kmem_cache *s,
{
void *object;
- lockdep_assert_held(&n->list_lock);
+ slab_lockdep_assert_held(&n->list_lock);
#ifdef CONFIG_SLUB_DEBUG
if (s->flags & SLAB_CONSISTENCY_CHECKS) {
@@ -4069,6 +4099,22 @@ static void flush_all(struct kmem_cache *s)
cpus_read_unlock();
}
+struct deferred_percpu_work {
+ struct llist_head objects;
+ struct llist_head objects_by_rcu;
+ struct llist_head rcu_sheaves;
+ struct irq_work work;
+};
+
+static void deferred_percpu_work_fn(struct irq_work *work);
+
+static DEFINE_PER_CPU(struct deferred_percpu_work, deferred_percpu_work) = {
+ .objects = LLIST_HEAD_INIT(objects),
+ .objects_by_rcu = LLIST_HEAD_INIT(objects_by_rcu),
+ .rcu_sheaves = LLIST_HEAD_INIT(rcu_sheaves),
+ .work = IRQ_WORK_INIT(deferred_percpu_work_fn),
+};
+
static void flush_rcu_sheaf(struct work_struct *w)
{
struct slub_percpu_sheaves *pcs;
@@ -4128,6 +4174,8 @@ void flush_all_rcu_sheaves(void)
{
struct kmem_cache *s;
+ deferred_work_barrier();
+
cpus_read_lock();
mutex_lock(&slab_mutex);
@@ -4665,7 +4713,7 @@ __pcs_replace_empty_main(struct kmem_cache *s, struct slub_percpu_sheaves *pcs,
struct node_barn *barn;
bool allow_spin;
- lockdep_assert_held(this_cpu_ptr(&s->cpu_sheaves->lock));
+ slab_lockdep_assert_held(this_cpu_ptr(&s->cpu_sheaves->lock));
/* Bootstrap or debug cache, back off */
if (unlikely(!cache_has_sheaves(s))) {
@@ -5783,7 +5831,7 @@ static void __pcs_install_empty_sheaf(struct kmem_cache *s,
struct slub_percpu_sheaves *pcs, struct slab_sheaf *empty,
struct node_barn *barn)
{
- lockdep_assert_held(this_cpu_ptr(&s->cpu_sheaves->lock));
+ slab_lockdep_assert_held(this_cpu_ptr(&s->cpu_sheaves->lock));
/* This is what we expect to find if nobody interrupted us. */
if (likely(!pcs->spare)) {
@@ -5834,7 +5882,7 @@ __pcs_replace_full_main(struct kmem_cache *s, struct slub_percpu_sheaves *pcs,
bool put_fail;
restart:
- lockdep_assert_held(this_cpu_ptr(&s->cpu_sheaves->lock));
+ slab_lockdep_assert_held(this_cpu_ptr(&s->cpu_sheaves->lock));
/* Bootstrap or debug cache, back off */
if (unlikely(!cache_has_sheaves(s))) {
@@ -6035,24 +6083,26 @@ static void rcu_free_sheaf(struct rcu_head *head)
* kvfree_call_rcu() can be called while holding a raw_spinlock_t. Since
* __kfree_rcu_sheaf() may acquire a spinlock_t (sleeping lock on PREEMPT_RT),
* this would violate lock nesting rules. Therefore, kvfree_call_rcu() avoids
- * this problem by bypassing the sheaves layer entirely on PREEMPT_RT.
+ * this problem by passing SLAB_FREE_NOLOCK on PREEMPT_RT.
*
* However, lockdep still complains that it is invalid to acquire spinlock_t
* while holding raw_spinlock_t, even on !PREEMPT_RT where spinlock_t is a
* spinning lock. Tell lockdep that acquiring spinlock_t is valid here
- * by temporarily raising the wait-type to LD_WAIT_CONFIG.
+ * by temporarily raising the wait-type to LD_WAIT_CONFIG. Skip the lockdep map
+ * on PREEMPT_RT to avoid suppressing valid lockdep warnings.
*/
static DEFINE_WAIT_OVERRIDE_MAP(kfree_rcu_sheaf_map, LD_WAIT_CONFIG);
-bool __kfree_rcu_sheaf(struct kmem_cache *s, void *obj)
+bool __kfree_rcu_sheaf(struct kmem_cache *s, void *obj, unsigned int free_flags)
{
struct slub_percpu_sheaves *pcs;
struct slab_sheaf *rcu_sheaf;
+ bool allow_spin = free_flags_allow_spinning(free_flags);
- if (WARN_ON_ONCE(IS_ENABLED(CONFIG_PREEMPT_RT)))
- return false;
+ VM_WARN_ON_ONCE(IS_ENABLED(CONFIG_PREEMPT_RT) && allow_spin);
- lock_map_acquire_try(&kfree_rcu_sheaf_map);
+ if (!IS_ENABLED(CONFIG_PREEMPT_RT))
+ lock_map_acquire_try(&kfree_rcu_sheaf_map);
if (!local_trylock(&s->cpu_sheaves->lock))
goto fail;
@@ -6060,9 +6110,10 @@ bool __kfree_rcu_sheaf(struct kmem_cache *s, void *obj)
pcs = this_cpu_ptr(s->cpu_sheaves);
if (unlikely(!pcs->rcu_free)) {
-
struct slab_sheaf *empty;
struct node_barn *barn;
+ unsigned int alloc_flags = to_alloc_flags(free_flags);
+ gfp_t gfp = allow_spin ? GFP_NOWAIT : __GFP_NOWARN;
/* Bootstrap or debug cache, fall back */
if (unlikely(!cache_has_sheaves(s))) {
@@ -6082,7 +6133,7 @@ bool __kfree_rcu_sheaf(struct kmem_cache *s, void *obj)
goto fail;
}
- empty = barn_get_empty_sheaf(barn, true);
+ empty = barn_get_empty_sheaf(barn, allow_spin);
if (empty) {
pcs->rcu_free = empty;
@@ -6091,20 +6142,20 @@ bool __kfree_rcu_sheaf(struct kmem_cache *s, void *obj)
local_unlock(&s->cpu_sheaves->lock);
- empty = alloc_empty_sheaf(s, GFP_NOWAIT, SLAB_ALLOC_DEFAULT);
+ empty = alloc_empty_sheaf(s, gfp, alloc_flags);
if (!empty)
goto fail;
if (!local_trylock(&s->cpu_sheaves->lock)) {
- barn_put_empty_sheaf(barn, empty);
+ __free_empty_sheaf(s, empty, free_flags);
goto fail;
}
pcs = this_cpu_ptr(s->cpu_sheaves);
if (unlikely(pcs->rcu_free))
- barn_put_empty_sheaf(barn, empty);
+ __free_empty_sheaf(s, empty, free_flags);
else
pcs->rcu_free = empty;
}
@@ -6130,18 +6181,34 @@ bool __kfree_rcu_sheaf(struct kmem_cache *s, void *obj)
* we flush before local_unlock to make sure a racing
* flush_all_rcu_sheaves() doesn't miss this sheaf
*/
- if (rcu_sheaf)
- call_rcu(&rcu_sheaf->rcu_head, rcu_free_sheaf);
+ if (rcu_sheaf) {
+ /*
+ * With !allow_spin, we might have interrupted call_rcu()'s
+ * IRQ-disabled critical section. If IRQs are not disabled,
+ * we know that's not the case.
+ */
+ if (unlikely(!allow_spin && irqs_disabled())) {
+ struct deferred_percpu_work *dpw;
+
+ dpw = this_cpu_ptr(&deferred_percpu_work);
+ if (llist_add(&rcu_sheaf->llnode, &dpw->rcu_sheaves))
+ irq_work_queue(&dpw->work);
+ } else {
+ call_rcu(&rcu_sheaf->rcu_head, rcu_free_sheaf);
+ }
+ }
local_unlock(&s->cpu_sheaves->lock);
stat(s, FREE_RCU_SHEAF);
- lock_map_release(&kfree_rcu_sheaf_map);
+ if (!IS_ENABLED(CONFIG_PREEMPT_RT))
+ lock_map_release(&kfree_rcu_sheaf_map);
return true;
fail:
stat(s, FREE_RCU_SHEAF_FAIL);
- lock_map_release(&kfree_rcu_sheaf_map);
+ if (!IS_ENABLED(CONFIG_PREEMPT_RT))
+ lock_map_release(&kfree_rcu_sheaf_map);
return false;
}
@@ -6330,31 +6397,22 @@ static void free_to_pcs_bulk(struct kmem_cache *s, size_t size, void **p)
}
}
-struct defer_free {
- struct llist_head objects;
- struct irq_work work;
-};
-
-static void free_deferred_objects(struct irq_work *work);
-
-static DEFINE_PER_CPU(struct defer_free, defer_free_objects) = {
- .objects = LLIST_HEAD_INIT(objects),
- .work = IRQ_WORK_INIT(free_deferred_objects),
-};
-
/*
* In PREEMPT_RT irq_work runs in per-cpu kthread, so it's safe
* to take sleeping spin_locks from __slab_free().
* In !PREEMPT_RT irq_work will run after local_unlock_irqrestore().
*/
-static void free_deferred_objects(struct irq_work *work)
+static void deferred_percpu_work_fn(struct irq_work *work)
{
- struct defer_free *df = container_of(work, struct defer_free, work);
- struct llist_head *objs = &df->objects;
+ struct deferred_percpu_work *dpw;
+ struct llist_head *objs, *objs_by_rcu, *rcu_sheaves;
struct llist_node *llnode, *pos, *t;
+ struct slab_sheaf *sheaf, *next;
- if (llist_empty(objs))
- return;
+ dpw = container_of(work, struct deferred_percpu_work, work);
+ rcu_sheaves = &dpw->rcu_sheaves;
+ objs = &dpw->objects;
+ objs_by_rcu = &dpw->objects_by_rcu;
llnode = llist_del_all(objs);
llist_for_each_safe(pos, t, llnode) {
@@ -6378,27 +6436,51 @@ static void free_deferred_objects(struct irq_work *work)
__slab_free(s, slab, x, x, 1, _THIS_IP_);
stat(s, FREE_SLOWPATH);
}
+
+ llnode = llist_del_all(objs_by_rcu);
+ llist_for_each_safe(pos, t, llnode) {
+ void *head = pos;
+ void *objp = kvmalloc_obj_start_addr(head);
+
+ kvfree_call_rcu(head, objp);
+ }
+
+ llnode = llist_del_all(rcu_sheaves);
+ llist_for_each_entry_safe(sheaf, next, llnode, llnode)
+ call_rcu(&sheaf->rcu_head, rcu_free_sheaf);
}
static void defer_free(struct kmem_cache *s, void *head)
{
- struct defer_free *df;
+ struct deferred_percpu_work *dpw;
guard(preempt)();
head = kasan_reset_tag(head);
- df = this_cpu_ptr(&defer_free_objects);
- if (llist_add(head + s->offset, &df->objects))
- irq_work_queue(&df->work);
+ dpw = this_cpu_ptr(&deferred_percpu_work);
+ if (llist_add(head + s->offset, &dpw->objects))
+ irq_work_queue(&dpw->work);
+}
+
+void defer_kfree_rcu(struct kvfree_rcu_head *head)
+{
+ struct deferred_percpu_work *dpw;
+
+ guard(preempt)();
+
+ dpw = this_cpu_ptr(&deferred_percpu_work);
+ if (llist_add((struct llist_node *)head, &dpw->objects_by_rcu))
+ irq_work_queue(&dpw->work);
}
-void defer_free_barrier(void)
+/* Must be called before flush_rcu_sheaves_on_cache() */
+void deferred_work_barrier(void)
{
int cpu;
for_each_possible_cpu(cpu)
- irq_work_sync(&per_cpu_ptr(&defer_free_objects, cpu)->work);
+ irq_work_sync(&per_cpu_ptr(&deferred_percpu_work, cpu)->work);
}
static __fastpath_inline
@@ -6657,43 +6739,21 @@ static void free_large_kmalloc(struct page *page, void *object)
*/
void kvfree_rcu_cb(struct rcu_head *head)
{
- void *obj = head;
- struct page *page;
- struct slab *slab;
- struct kmem_cache *s;
- void *slab_addr;
+ void *obj;
+
+ obj = kvmalloc_obj_start_addr(head);
if (is_vmalloc_addr(obj)) {
- obj = (void *) PAGE_ALIGN_DOWN((unsigned long)obj);
vfree(obj);
- return;
- }
-
- page = virt_to_page(obj);
- slab = page_slab(page);
- if (!slab) {
- /*
- * rcu_head offset can be only less than page size so no need to
- * consider allocation order
- */
- obj = (void *) PAGE_ALIGN_DOWN((unsigned long)obj);
- free_large_kmalloc(page, obj);
- return;
- }
-
- s = slab->slab_cache;
- slab_addr = slab_address(slab);
-
- if (is_kfence_address(obj)) {
- obj = kfence_object_start(obj);
} else {
- unsigned int idx = __obj_to_index(s, slab_addr, obj);
+ struct page *page = virt_to_page(obj);
+ struct slab *slab = page_slab(page);
- obj = slab_addr + s->size * idx;
- obj = fixup_red_left(s, obj);
+ if (slab)
+ slab_free(slab->slab_cache, slab, obj, _RET_IP_);
+ else
+ free_large_kmalloc(page, obj);
}
-
- slab_free(s, slab, obj, _RET_IP_);
}
/**
|
| 3/2 | 2026/07/30 14:43 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 15591 output: 22 thoughts: 287 Thoughts: **Analyzing the RCU/SLUB Patch** Okay, so I'm looking at this patch and my initial impression is that it's a pretty significant change, especially given that it touches core kernel components like `mm/slab`, `mm/slab_common.c`, `mm/slub.c`, and the RCU code. The introduction of `kfree_rcu_nolock` and the tweaks to `kvfree_call_rcu` are the focal points. It looks like `kvfree_call_rcu` is now accepting a `struct kvfree_rcu_head *` rather than the more generic `struct rcu_head *`. And we've got a `kfree_call_rcu_nolock` being added, which uses either `defer_kfree_rcu` or `__kfree_rcu_sheaf` with that `SLAB_FREE_NOLOCK` flag. Good to see there are perf and kprobe tests in `lib/tests/slub_kunit.c` too; always crucial. My first thought is always to confirm that this is genuinely functional, and that it isn't an unreachable dead end of a patch. Given the areas it touches, I'm going to assume it's both functional and that some code paths are definitely going to be using it. Now, let's dive deeper and make sure the configuration requirements are clear. Specifically, I see `CONFIG_KVFREE_RCU_BATCHED` being used in `mm/slab_common.c` in relation to `kfree_call_rcu_nolock`. That raises the immediate question of how that config is defined and enabled. I need to track down where `CONFIG_KVFREE_RCU_BATCHED` is defined. I'll need to check the Kconfig files, probably in `init/Kconfig`, `mm/Kconfig`, or perhaps even `kernel/rcu/Kconfig`. I'll search for "KVFREE_RCU_BATCHED" within the kernel source to get a complete view. |
| 4/2 | 2026/07/30 14:43 | tool | grepper |
0mArgs:{
"Expression": "KVFREE_RCU_BATCHED"
}Results: {
"Output": "include/linux/rcupdate.h=1121=do {\t\t\t\t\t\t\t\t\\\n--\ninclude/linux/rcupdate.h-1132- *\ninclude/linux/rcupdate.h:1133: * With KVFREE_RCU_BATCHED, kfree_rcu_nolock() tries hard to free objects\ninclude/linux/rcupdate.h-1134- * without any deferred processing, but may still defer freeing.\n--\ninclude/linux/slab.h=1430=unsigned int kmem_cache_size(struct kmem_cache *s);\ninclude/linux/slab.h-1431-\ninclude/linux/slab.h:1432:#ifndef CONFIG_KVFREE_RCU_BATCHED\ninclude/linux/slab.h-1433-static inline void kfree_rcu_scheduler_running(void) { }\n--\ninclude/linux/types.h=254=struct callback_head {\n--\ninclude/linux/types.h-259-\ninclude/linux/types.h:260:#ifdef CONFIG_KVFREE_RCU_BATCHED\ninclude/linux/types.h-261-struct kvfree_rcu_head {\n--\nmm/Kconfig=164=config SLUB\n--\nmm/Kconfig-167-\nmm/Kconfig:168:config KVFREE_RCU_BATCHED\nmm/Kconfig-169-\tdef_bool y\n--\nmm/slab_common.c=1299=void kfree_call_rcu_nolock(struct kvfree_rcu_head *head, void *ptr)\n--\nmm/slab_common.c-1302-\nmm/slab_common.c:1303:\tif (!IS_ENABLED(CONFIG_KVFREE_RCU_BATCHED))\nmm/slab_common.c-1304-\t\tgoto fallback;\n--\nmm/slab_common.c=1324=EXPORT_SYMBOL_GPL(kfree_call_rcu_nolock);\nmm/slab_common.c-1325-\nmm/slab_common.c:1326:#ifndef CONFIG_KVFREE_RCU_BATCHED\nmm/slab_common.c-1327-\n--\nmm/slab_common.c=1357=void __init kvfree_rcu_init(void)\n--\nmm/slab_common.c-1360-\nmm/slab_common.c:1361:#else /* CONFIG_KVFREE_RCU_BATCHED */\nmm/slab_common.c-1362-\n--\nmm/slab_common.c=2248=void __init kvfree_rcu_init(void)\n--\nmm/slab_common.c-2300-\nmm/slab_common.c:2301:#endif /* CONFIG_KVFREE_RCU_BATCHED */\n"
} |
| 5/2 | 2026/07/30 14:43 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 17062 output: 23 thoughts: 41 Thoughts: Okay, here's my interpretation of that thought process, from an expert's perspective: **Investigating RCU Batched Freed with SLUB Dependency** Alright, so `KVFREE_RCU_BATCHED` is flagged as a default boolean 'yes' – that's good, likely indicating it's enabled by default under the right circumstances. The clue here is `SLUB`. My gut feeling is telling me that this option is dependent on the `SLUB` allocator. Now, my immediate thought is to confirm this dependency. I need to dive into the `mm/Kconfig` file. I'll need to check the conditions surrounding the definition of `KVFREE_RCU_BATCHED` to nail down the precise dependency on `SLUB`, and any other conditions. This is the first step toward confirming how this option impacts RCU and the SLUB allocator. |
| 6/2 | 2026/07/30 14:43 | tool | grepper |
0mArgs:{
"Expression": "config KVFREE_RCU_BATCHED"
}Results: {
"Output": "mm/Kconfig=164=config SLUB\n--\nmm/Kconfig-167-\nmm/Kconfig:168:config KVFREE_RCU_BATCHED\nmm/Kconfig-169-\tdef_bool y\n"
} |
| 7/2 | 2026/07/30 14:43 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 17382 output: 32 thoughts: 27 Thoughts: Here's a summary of my thought process, as requested: **Navigating Kernel Configuration Dependencies** Okay, so the current question hinges on whether or not we're using `SLUB`. Right, I need to check how that's configured. My instinct is telling me to look at `mm/Kconfig`, but I need to be sure. Alright, let's open that file and head down to line 168. Hopefully, it'll be a straightforward dependency or configuration option. Time to dig in and see what `mm/Kconfig` tells me about `SLUB`. |
| 8/2 | 2026/07/30 14:43 | tool | read-file |
0mArgs:{
"File": "mm/Kconfig",
"FirstLine": 160,
"LineCount": 20
}Results: {
"Contents": " 160:\tendmenu\n 161:\t\n 162:\tmenu \"Slab allocator options\"\n 163:\t\n 164:\tconfig SLUB\n 165:\t\tdef_bool y\n 166:\t\tselect IRQ_WORK\n 167:\t\n 168:\tconfig KVFREE_RCU_BATCHED\n 169:\t\tdef_bool y\n 170:\t\tdepends on !SLUB_TINY \u0026\u0026 !TINY_RCU\n 171:\t\tdepends on !RCU_STRICT_GRACE_PERIOD\n 172:\t\n 173:\tconfig SLUB_TINY\n 174:\t\tbool \"Configure for minimal memory footprint\"\n 175:\t\tdepends on EXPERT \u0026\u0026 !COMPILE_TEST\n 176:\t\tselect SLAB_MERGE_DEFAULT\n 177:\t\thelp\n 178:\t\t Configures the slab allocator in a way to achieve minimal memory\n 179:\t\t footprint, sacrificing scalability, debugging and other features.\n"
} |
| 9/2 | 2026/07/30 14:43 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 17839 output: 22 thoughts: 128 Thoughts: **Examining the KVFREE_RCU_BATCHED Configuration** Okay, so I'm just quickly reviewing how `KVFREE_RCU_BATCHED` is handled in this kernel configuration. It looks like the default is to have it enabled unless we're dealing with `SLUB_TINY`, `TINY_RCU`, or if `RCU_STRICT_GRACE_PERIOD` is also turned on. That makes sense, no need to overcomplicate things. So, I could just rely on the defaults and not explicitly enable `KVFREE_RCU_BATCHED`, but I could also add it in there, just for clarity's sake, or maybe not. Doesn't seem strictly necessary. Hang on a second… I'm remembering that `SLUB_KUNIT_TEST` is touched in `lib/tests/slub_kunit.c`. I should probably double-check the configuration options around that. Need to see if there's any linkage or dependencies. I'll take a quick look into `lib/Kconfig.debug` or maybe `lib/tests/Kconfig` to figure out where that's controlled. |
| 10/2 | 2026/07/30 14:43 | tool | grepper |
0mArgs:{
"Expression": "config SLUB_KUNIT_TEST"
}Results: {
"Output": "lib/Kconfig.debug=2965=config SHDI3_KUNIT_TEST\n--\nlib/Kconfig.debug-2974-\nlib/Kconfig.debug:2975:config SLUB_KUNIT_TEST\nlib/Kconfig.debug-2976-\ttristate \"KUnit test for SLUB cache error detection\" if !KUNIT_ALL_TESTS\n"
} |
| 11/2 | 2026/07/30 14:43 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 18346 output: 35 thoughts: 20 Thoughts: Here's my summary, as the expert: **Investigating a Kconfig Debugging Configuration** Alright, let's dive into this. Based on what I'm looking at, I need to understand something better about the build configuration and how it affects debugging. My immediate thought is to zero in on a specific area, probably related to debugging options directly within the `Kconfig` files. I'm going to jump into `lib/Kconfig.debug`, specifically around line 2975. That should be the right place to find some useful clues. I'm expecting to find some configuration symbols or dependencies there. |
| 12/2 | 2026/07/30 14:43 | tool | read-file |
0mArgs:{
"File": "lib/Kconfig.debug",
"FirstLine": 2970,
"LineCount": 20
}Results: {
"Contents": "2970:\t\t This builds the unit test for __ashldi3(), __ashrdi3(), and\n2971:\t\t __lshrdi3() helper functions used to implement 64-bit arithmetic\n2972:\t\t shift left, arithmetic shift right and logical shift right,\n2973:\t\t respectively, on a 32-bit CPUs.\n2974:\t\n2975:\tconfig SLUB_KUNIT_TEST\n2976:\t\ttristate \"KUnit test for SLUB cache error detection\" if !KUNIT_ALL_TESTS\n2977:\t\tdepends on SLUB_DEBUG \u0026\u0026 KUNIT\n2978:\t\tdefault KUNIT_ALL_TESTS\n2979:\t\thelp\n2980:\t\t This builds SLUB allocator unit test.\n2981:\t\t Tests SLUB cache debugging functionality.\n2982:\t\t For more information on KUnit and unit tests in general please refer\n2983:\t\t to the KUnit documentation in Documentation/dev-tools/kunit/.\n2984:\t\n2985:\t\t If unsure, say N.\n2986:\t\n2987:\tconfig RATIONAL_KUNIT_TEST\n2988:\t\ttristate \"KUnit test for rational.c\" if !KUNIT_ALL_TESTS\n2989:\t\tdepends on KUNIT \u0026\u0026 RATIONAL\n"
} |
| 13/2 | 2026/07/30 14:43 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 18886 output: 22 thoughts: 874 Thoughts: **Analyzing the SLUB RCU Patch**
Alright, let's break this down. First, enabling `SLUB_KUNIT_TEST` seems like the right move for testing, especially since it's a dedicated test configuration. The patch touches `mm/slab_common.c` and `mm/slub.c`, adding `kfree_call_rcu_nolock` and `defer_kfree_rcu`. My focus here is on understanding how these changes integrate with the existing RCU machinery and any potential performance or correctness implications.
So the main symbols involved are `kfree_call_rcu_nolock`, `kvfree_call_rcu`, `__kfree_rcu_sheaf`, and `defer_kfree_rcu`. I know `__kfree_rcu_sheaf` is a core function, so I need to pay particularly close attention to how this is modified. I quickly confirmed `kfree_call_rcu_nolock` is exported with `EXPORT_SYMBOL_GPL`, which is good. That makes it more readily usable. However, `defer_kfree_rcu` is internal to the SLUB code, only declared in `mm/slab.h`. Same story with `__kfree_rcu_sheaf`. `kvfree_call_rcu` is exported.
Looking at the code for `kfree_call_rcu_nolock`, specifically:
```c
void kfree_call_rcu_nolock(struct kvfree_rcu_head *head, void *ptr)
{
struct slab *slab;
if (!IS_ENABLED(CONFIG_KVFREE_RCU_BATCHED))
goto fallback;
if (unlikely(is_vmalloc_addr(ptr)))
goto fallback;
slab = virt_to_slab(ptr);
if (unlikely(!slab))
goto fallback;
if (unlikely(IS_ENABLED(CONFIG_NUMA) && slab_nid(slab) != numa_mem_id()))
goto fallback;
if (unlikely(!__kfree_rcu_sheaf(slab->slab_cache, ptr, SLAB_FREE_NOLOCK)))
goto fallback;
return;
fallback:
defer_kfree_rcu(head);
}
EXPORT_SYMBOL_GPL(kfree_call_rcu_nolock);
```
My initial thought is that this function seems relatively straightforward, but I have to really think about the `fallback` path. I need to understand what this means for performance. The `fallback` means it goes to `defer_kfree_rcu`. So, if `CONFIG_KVFREE_RCU_BATCHED` is not enabled, or if it is a `vmalloc` address, or if `virt_to_slab` fails, if NUMA is enabled and the slab isn't local, or if `__kfree_rcu_sheaf` returns false, it falls back to the RCU deferral. I'll need to dig into the RCU batching mechanics later. I need to determine if these are likely scenarios and what the impact of the fallback is in terms of latency and RCU usage.
I note the additional focus symbols: `deferred_work_barrier` and `deferred_percpu_work_fn`. `deferred_percpu_work_fn` is static which is what I expect.
Then, I check the new tests. I see `test_kmalloc_nolock_and_friends_perf` and `test_kmalloc_nolock_and_friends_kprobe` in `lib/tests/slub_kunit.c`, KUnit tests, so enabling `SLUB_KUNIT_TEST` is definitely the right choice. However, these tests depend on `CONFIG_PERF_EVENTS` and `CONFIG_KPROBES` to run.
```c
#if defined(CONFIG_PERF_EVENTS) || (defined(CONFIG_KPROBES) && defined(CONFIG_SMP))
```
Looks like I can enable `PERF_EVENTS` and `KPROBES`, or just `KPROBES` if `CONFIG_SMP` is also enabled, to run these tests. I'll need to check the dependencies and determine the impact of enabling these options on the build and runtime. I'll also double-check whether `kfree_rcu_nolock` (typo!) is used anywhere else in the code base, as a sanity check.
|
| 14/2 | 2026/07/30 14:44 | tool | grepper |
0mArgs:{
"Expression": "kfree_rcu_nolock"
}Results: {
"Output": "include/linux/rcupdate.h=1121=do {\t\t\t\t\t\t\t\t\\\n--\ninclude/linux/rcupdate.h-1128-/**\ninclude/linux/rcupdate.h:1129: * kfree_rcu_nolock() - a version of kfree_rcu() that can be called in any context.\ninclude/linux/rcupdate.h-1130- * @ptr: pointer to kfree for double-argument invocations.\n--\ninclude/linux/rcupdate.h-1132- *\ninclude/linux/rcupdate.h:1133: * With KVFREE_RCU_BATCHED, kfree_rcu_nolock() tries hard to free objects\ninclude/linux/rcupdate.h-1134- * without any deferred processing, but may still defer freeing.\n--\ninclude/linux/rcupdate.h-1136- *\ninclude/linux/rcupdate.h:1137: * kfree_rcu_nolock() supports 2-arg variant only.\ninclude/linux/rcupdate.h-1138- */\ninclude/linux/rcupdate.h:1139:#define kfree_rcu_nolock(ptr, kvrhf)\t\t\t\t\t\t\\\ninclude/linux/rcupdate.h-1140-do {\t\t\t\t\t\t\t\t\t\t\\\n--\nlib/tests/slub_kunit.c=344=static void test_nolock(struct test_nolock_context *ctx)\n--\nlib/tests/slub_kunit.c-359-\tif (can_use_kfree_rcu \u0026\u0026 (ctx-\u003ecallback_count \u0026 2))\nlib/tests/slub_kunit.c:360:\t\tkfree_rcu_nolock(objp, kvrcu);\nlib/tests/slub_kunit.c-361-\telse\n--\nmm/slab_common.c=2191=void kvfree_rcu_barrier_on_cache(struct kmem_cache *s)\nmm/slab_common.c-2192-{\nmm/slab_common.c:2193:\t/* kfree_rcu_nolock() might have deferred frees even without sheaves */\nmm/slab_common.c-2194-\tdeferred_work_barrier();\n"
} |
| 15/2 | 2026/07/30 14:44 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 21334 output: 24 thoughts: 64 Thoughts: Okay, here's my take on those thoughts, framed from my own perspective: **Fuzzing That New API: Absolutely Worth the Effort** Alright, even though this function, whatever it's doing, is only specifically called in the test code *right now*, the fact that a new API has been introduced, and this test actually *uses* it, makes it a prime candidate for fuzzing. New APIs always carry a higher risk profile for unforeseen issues. It's a key exercise of the new functionality, so getting a fuzzing test in place early will be a proactive move. No brainer, really. I suppose I should check out `kfree_call_rcu_nolock` in `mm/slab_common.c` to see how it operates. The test is invoking that function, it's worth seeing what it does under the hood. Understanding the internals will allow us to devise effective fuzzing strategies. |
| 16/2 | 2026/07/30 14:44 | tool | grepper |
0mArgs:{
"Expression": "kfree_call_rcu_nolock"
}Results: {
"Output": "include/linux/rcupdate.h=1101=void kvfree_call_rcu(struct kvfree_rcu_head *head, void *ptr);\ninclude/linux/rcupdate.h:1102:void kfree_call_rcu_nolock(struct kvfree_rcu_head *head, void *ptr);\ninclude/linux/rcupdate.h-1103-\n--\ninclude/linux/rcupdate.h=1140=do {\t\t\t\t\t\t\t\t\t\t\\\n--\ninclude/linux/rcupdate.h-1144-\t\tBUILD_BUG_ON(offsetof(typeof(*(ptr)), kvrhf) \u003e= 4096);\t\t\\\ninclude/linux/rcupdate.h:1145:\t\tkfree_call_rcu_nolock(\u0026((___p)-\u003ekvrhf), (void *) (___p));\t\\\ninclude/linux/rcupdate.h-1146-\t}\t\t\t\t\t\t\t\t\t\\\n--\nmm/slab_common.c=1297=EXPORT_TRACEPOINT_SYMBOL(kmem_cache_free);\nmm/slab_common.c-1298-\nmm/slab_common.c:1299:void kfree_call_rcu_nolock(struct kvfree_rcu_head *head, void *ptr)\nmm/slab_common.c-1300-{\n--\nmm/slab_common.c-1323-}\nmm/slab_common.c:1324:EXPORT_SYMBOL_GPL(kfree_call_rcu_nolock);\nmm/slab_common.c-1325-\n"
} |
| 17/2 | 2026/07/30 14:44 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 22015 output: 23 thoughts: 47 Thoughts: Okay, here's my take on those thoughts, framed as my own mental processing as an expert: **Diving into the `kfree_call_rcu_nolock` Mystery** Alright, so the macro expands out to `kfree_call_rcu_nolock`, good. That's the actual workhorse function. Now I need to see what's actually happening under the hood. My next logical step is to dive into `__kfree_rcu_sheaf` in `mm/slub.c`. I expect this is where the core RCU operations are being initiated, probably dealing with the slub allocator's internal structures. Time to dig in and see how this all connects. |
| 18/2 | 2026/07/30 14:44 | tool | grepper |
0mArgs:{
"Expression": "__kfree_rcu_sheaf"
}Results: {
"Output": "mm/slab.h=473=static inline bool is_kmalloc_normal(struct kmem_cache *s)\n--\nmm/slab.h-480-\nmm/slab.h:481:bool __kfree_rcu_sheaf(struct kmem_cache *s, void *obj, unsigned int free_flags);\nmm/slab.h-482-void flush_all_rcu_sheaves(void);\n--\nmm/slab_common.c=1299=void kfree_call_rcu_nolock(struct kvfree_rcu_head *head, void *ptr)\n--\nmm/slab_common.c-1315-\nmm/slab_common.c:1316:\tif (unlikely(!__kfree_rcu_sheaf(slab-\u003eslab_cache, ptr, SLAB_FREE_NOLOCK)))\nmm/slab_common.c-1317-\t\tgoto fallback;\n--\nmm/slab_common.c=1668=static bool kfree_rcu_sheaf(void *obj)\n--\nmm/slab_common.c-1689-\tif (likely(!IS_ENABLED(CONFIG_NUMA) || slab_nid(slab) == numa_mem_id()))\nmm/slab_common.c:1690:\t\treturn __kfree_rcu_sheaf(s, obj, free_flags);\nmm/slab_common.c-1691-\n--\nmm/slub.c=4142=void flush_rcu_sheaves_on_cache(struct kmem_cache *s)\n--\nmm/slub.c-4154-\t\t * we don't check if rcu_free sheaf exists - racing\nmm/slub.c:4155:\t\t * __kfree_rcu_sheaf() might have just removed it.\nmm/slub.c-4156-\t\t * by executing flush_rcu_sheaf() on the cpu we make\nmm/slub.c:4157:\t\t * sure the __kfree_rcu_sheaf() finished its call_rcu()\nmm/slub.c-4158-\t\t */\n--\nmm/slub.c=6025=static void rcu_free_sheaf(struct rcu_head *head)\n--\nmm/slub.c-6083- * kvfree_call_rcu() can be called while holding a raw_spinlock_t. Since\nmm/slub.c:6084: * __kfree_rcu_sheaf() may acquire a spinlock_t (sleeping lock on PREEMPT_RT),\nmm/slub.c-6085- * this would violate lock nesting rules. Therefore, kvfree_call_rcu() avoids\n--\nmm/slub.c=6094=static DEFINE_WAIT_OVERRIDE_MAP(kfree_rcu_sheaf_map, LD_WAIT_CONFIG);\nmm/slub.c-6095-\nmm/slub.c:6096:bool __kfree_rcu_sheaf(struct kmem_cache *s, void *obj, unsigned int free_flags)\nmm/slub.c-6097-{\n"
} |
| 19/2 | 2026/07/30 14:44 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 23034 output: 21 thoughts: 40 Thoughts: Okay, here's my interpretation of those thoughts, presented as a personal thought process, as requested: **Delving into the `__kfree_rcu_sheaf` Function** Alright, so `__kfree_rcu_sheaf`... that's a key function, isn't it? It's right in the heart of things, suggesting its involvement in critical memory management operations. I should really understand its place in the grand scheme. My next immediate thought is to trace its usage. `defer_kfree_rcu` in `mm/slub.c` is the obvious starting point. I can quickly review its implementation there to figure out how `__kfree_rcu_sheaf` is being called and get a sense of its behavior. |
| 20/2 | 2026/07/30 14:44 | tool | grepper |
0mArgs:{
"Expression": "defer_kfree_rcu"
}Results: {
"Output": "mm/slab.h=949=void deferred_work_barrier(void);\nmm/slab.h:950:void defer_kfree_rcu(struct kvfree_rcu_head *head);\nmm/slab.h-951-\n--\nmm/slab_common.c=1299=void kfree_call_rcu_nolock(struct kvfree_rcu_head *head, void *ptr)\n--\nmm/slab_common.c-1321-fallback:\nmm/slab_common.c:1322:\tdefer_kfree_rcu(head);\nmm/slab_common.c-1323-}\n--\nmm/slub.c=6453=static void defer_free(struct kmem_cache *s, void *head)\n--\nmm/slub.c-6465-\nmm/slub.c:6466:void defer_kfree_rcu(struct kvfree_rcu_head *head)\nmm/slub.c-6467-{\n"
} |
| 21/2 | 2026/07/30 14:44 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 23530 output: 21 thoughts: 39 Thoughts: Okay, here's my understanding, written as if I'm the one thinking it: **Digging into Memory Management** Alright, I'm looking at `defer_kfree_rcu`. Seems like it's a pretty fundamental function, probably crucial for deferring memory deallocation, specifically with RCU. Now, where is this used? Let's check where it's called, starting with `kvfree_call_rcu` in `mm/slab_common.c`. I expect to find its implementation and how it interacts with the rest of the slab allocator. This should give me some solid context. |
| 22/2 | 2026/07/30 14:44 | tool | grepper |
0mArgs:{
"Expression": "kvfree_call_rcu"
}Results: {
"Output": "include/linux/rcupdate.h=985=static inline void rcu_read_unlock_migrate(void)\n--\ninclude/linux/rcupdate.h-1100- */\ninclude/linux/rcupdate.h:1101:void kvfree_call_rcu(struct kvfree_rcu_head *head, void *ptr);\ninclude/linux/rcupdate.h-1102-void kfree_call_rcu_nolock(struct kvfree_rcu_head *head, void *ptr);\n--\ninclude/linux/rcupdate.h=1109=do {\t\t\t\t\t\t\t\t\t\\\n--\ninclude/linux/rcupdate.h-1115-\t\t___head = (struct kvfree_rcu_head *) \u0026(___p)-\u003ekvrhf;\t\\\ninclude/linux/rcupdate.h:1116:\t\tkvfree_call_rcu(___head, (void *) (___p));\t\t\\\ninclude/linux/rcupdate.h-1117-\t}\t\t\t\t\t\t\t\t\\\n--\ninclude/linux/rcupdate.h=1121=do {\t\t\t\t\t\t\t\t\\\n--\ninclude/linux/rcupdate.h-1124-\tif (___p)\t\t\t\t\t\t\\\ninclude/linux/rcupdate.h:1125:\t\tkvfree_call_rcu(NULL, (void *) (___p));\t\t\\\ninclude/linux/rcupdate.h-1126-} while (0)\n--\nmm/slab_common.c=1324=EXPORT_SYMBOL_GPL(kfree_call_rcu_nolock);\n--\nmm/slab_common.c-1327-\nmm/slab_common.c:1328:void kvfree_call_rcu(struct rcu_head *head, void *ptr)\nmm/slab_common.c-1329-{\n--\nmm/slab_common.c-1340-}\nmm/slab_common.c:1341:EXPORT_SYMBOL_GPL(kvfree_call_rcu);\nmm/slab_common.c-1342-\n--\nmm/slab_common.c=1999=void __init kfree_rcu_scheduler_running(void)\n--\nmm/slab_common.c-2017- *\nmm/slab_common.c:2018: * Each kvfree_call_rcu() request is added to a batch. The batch will be drained\nmm/slab_common.c-2019- * every KFREE_DRAIN_JIFFIES number of jiffies. All the objects in the batch will\n--\nmm/slab_common.c-2022- */\nmm/slab_common.c:2023:void kvfree_call_rcu(struct kvfree_rcu_head *head, void *ptr)\nmm/slab_common.c-2024-{\n--\nmm/slab_common.c-2095-}\nmm/slab_common.c:2096:EXPORT_SYMBOL_GPL(kvfree_call_rcu);\nmm/slab_common.c-2097-\n--\nmm/slub.c=6025=static void rcu_free_sheaf(struct rcu_head *head)\n--\nmm/slub.c-6082-/*\nmm/slub.c:6083: * kvfree_call_rcu() can be called while holding a raw_spinlock_t. Since\nmm/slub.c-6084- * __kfree_rcu_sheaf() may acquire a spinlock_t (sleeping lock on PREEMPT_RT),\nmm/slub.c:6085: * this would violate lock nesting rules. Therefore, kvfree_call_rcu() avoids\nmm/slub.c-6086- * this problem by passing SLAB_FREE_NOLOCK on PREEMPT_RT.\n--\nmm/slub.c=6405=static void deferred_percpu_work_fn(struct irq_work *work)\n--\nmm/slub.c-6444-\nmm/slub.c:6445:\t\tkvfree_call_rcu(head, objp);\nmm/slub.c-6446-\t}\n--\nrust/kernel/sync/poll.rs=162= fn drop(\u0026mut self) {\n--\nrust/kernel/sync/poll.rs-174- // SAFETY: This was allocated using `KBox::pin_init`, so it can be freed with `kvfree`.\nrust/kernel/sync/poll.rs:175: unsafe { bindings::kvfree_call_rcu((*ptr).rcu.get(), ptr.cast::\u003cffi::c_void\u003e()) };\nrust/kernel/sync/poll.rs-176- }\n--\ntools/rcu/rcu-updaters.sh=20=fi\ntools/rcu/rcu-updaters.sh:21:bpftrace -e 'kprobe:kvfree_call_rcu,\ntools/rcu/rcu-updaters.sh-22-\t kprobe:call_rcu,\n"
} |
| 23/2 | 2026/07/30 14:44 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 24983 output: 280 thoughts: 1740 Thoughts: **My Analysis of the RCU and SLUB Changes** Alright, let's break this down. It seems we have a patch that's introducing changes related to `kvfree_call_rcu` and adding `kfree_rcu_nolock`, essentially allowing for lockless object freeing within the kernel. The core of this is the introduction of `struct kvfree_rcu_head` and adjustments to `kfree_call_rcu_nolock` and the slab freeing path. Looking into it, the `kfree_rcu_nolock` macro leverages `kfree_call_rcu_nolock`, which then probably works with `__kfree_rcu_sheaf`, and the patching introduces a `free_flags` parameter to it. This suggests a more flexible mechanism, potentially for different contexts, like `SLAB_FREE_NOLOCK` in the `PREEMPT_RT` case. The use of `deferred_percpu_work` and the checks with `irqs_disabled()` indicate that this is cleverly designed to handle different scenarios where the immediate freeing of the object might be problematic. Now, focusing on the symbols, I've identified the following as the primary API entry points: * `kfree_call_rcu_nolock` (This is exported) * `kvfree_call_rcu` * `__kfree_rcu_sheaf` * `defer_kfree_rcu` * `deferred_work_barrier` * `kvfree_rcu_barrier` * `kvfree_rcu_barrier_on_cache` It's clear that the test suite, `SLUB_KUNIT_TEST`, uses `PERF_EVENTS` and `KPROBES` in addition to `SMP` to cover the new lockless freeing behavior. The fact that the tests use perf events and kprobes indicates that we need to enable those configs. And, since it's an RCU-related change, we should be using RCU in an SMP environment. So, for full coverage, I will include these configs: * `SLUB_KUNIT_TEST` * `KUNIT` * `SLUB_DEBUG` * `PERF_EVENTS` * `KPROBES` * `SMP` * `KVFREE_RCU_BATCHED` (Even though it's the default, let's be explicit) Given that this affects core memory management and RCU mechanisms, it is important to include this set of configs to thoroughly test the change. |
| 24/2 | 2026/07/30 14:44 | tool | set-results |
0mArgs:{
"EnableConfigs": [
"SLUB_KUNIT_TEST",
"KUNIT",
"PERF_EVENTS",
"KPROBES",
"SMP",
"SLUB_DEBUG",
"KVFREE_RCU_BATCHED"
],
"FocusSymbols": [
"kfree_call_rcu_nolock",
"kvfree_call_rcu",
"__kfree_rcu_sheaf",
"defer_kfree_rcu",
"deferred_work_barrier",
"kvfree_rcu_barrier",
"kvfree_rcu_barrier_on_cache"
],
"Reasoning": "The patch introduces `kfree_rcu_nolock()` API which allows deferring freeing of objects in any context without locks. It modifies `kvfree_call_rcu()` to use `struct kvfree_rcu_head` and implements `kfree_call_rcu_nolock()` which relies on `__kfree_rcu_sheaf()` and `defer_kfree_rcu()`. It also adds KUnit tests for these new APIs using perf events and kprobes. This is a core memory management and RCU change that is highly functional and reachable.",
"WorthFuzzing": true
}Results: {
"EnableConfigs": [
"SLUB_KUNIT_TEST",
"KUNIT",
"PERF_EVENTS",
"KPROBES",
"SMP",
"SLUB_DEBUG",
"KVFREE_RCU_BATCHED"
],
"FocusSymbols": [
"kfree_call_rcu_nolock",
"kvfree_call_rcu",
"__kfree_rcu_sheaf",
"defer_kfree_rcu",
"deferred_work_barrier",
"kvfree_rcu_barrier",
"kvfree_rcu_barrier_on_cache"
],
"Reasoning": "The patch introduces `kfree_rcu_nolock()` API which allows deferring freeing of objects in any context without locks. It modifies `kvfree_call_rcu()` to use `struct kvfree_rcu_head` and implements `kfree_call_rcu_nolock()` which relies on `__kfree_rcu_sheaf()` and `defer_kfree_rcu()`. It also adds KUnit tests for these new APIs using perf events and kprobes. This is a core memory management and RCU change that is highly functional and reachable.",
"WorthFuzzing": true
} |
| Total Calls | Total Tokens | Avg Tokens | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|
| Total Calls | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|