| Seq | Timestamp | Type | Name | Duration |
|---|---|---|---|---|
| 0/0 | 2026/10/24 20:46 | flow | patch-triage |
2mArgs:null Results: {
"EnableConfigs": [
"SLUB",
"SLUB_DEBUG",
"SLUB_TINY"
],
"FocusSymbols": [
"alloc_single_from_partial",
"alloc_single_from_new_slab",
"free_to_partial_list",
"kmem_cache_flags",
"calculate_sheaf_capacity",
"do_kmem_cache_create",
"__kmem_cache_alloc_bulk"
],
"KMSANReasoning": "The patch series refactors the SLUB allocator to replace compile-time CONFIG_SLUB_TINY with a runtime boot parameter (slab_tiny) and introduces the SLAB_DEBUG_NOOP flag to route allocations through debug slowpaths to minimize memory footprint. It also allows KASAN, SLUB_DEBUG, and other features previously disallowed under CONFIG_SLUB_TINY to be enabled.\n\nThese modifications only affect SLUB internal management, cache merging, order calculations, and slowpath routing. They do not alter object initialization or zeroing logic (kmsan_slab_alloc hooks and GFP_ZERO paths remain unchanged), do not introduce uninitialized stack or heap variables, and do not expose any kernel data or padding to userspace. Potential regressions or errors in these changes (such as freelist corruption, incorrect slab ordering, or memory corruption) are covered by KASAN, SLUB consistency checks, and standard debugging tools. Therefore, dedicated KMSAN fuzzing is not required.",
"NeedsKMSAN": false,
"Reasoning": "The patch converts CONFIG_SLUB_TINY from compile-time conditional compilation to a runtime boot-time configuration (slab_tiny), introduces a new no-op debug mode (SLAB_DEBUG_NOOP / slab_debug=N), and refactors the SLUB memory allocator's allocation, freeing, and cache creation paths. This modifies reachable core memory management logic in mm/slub.c and mm/slab_common.c, altering freelist handling, sheaf capacity computation, and single-object allocation/free slowpaths. Fuzzing is warranted to ensure the refactored slowpaths and invariant assertions do not introduce regressions or memory corruption.",
"WorthFuzzing": true
} |
| 1/1 | 2026/10/24 20:46 | action | read-patch-diff |
0mArgs:null Results: {
"PatchDiff": "commit 140335c47acb03e30728e609e79ac4636d89dd6b\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate: Sat Oct 24 20:46:31 2026 +0000\n\n syz-cluster: applied patch under review\n\ndiff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt\nindex 03636d7998374..29dc1c8124733 100644\n--- a/Documentation/admin-guide/kernel-parameters.txt\n+++ b/Documentation/admin-guide/kernel-parameters.txt\n@@ -7043,6 +7043,10 @@ Kernel parameters\n \t\t\tNUMA kernel object placement which helps with slow\n \t\t\tinterconnects in NUMA systems.\n \n+\tslab_tiny=\t[MM, EARLY]\n+\t\t\tMinimize the slab allocator memory footprint at the\n+\t\t\texpense of SMP scalability.\n+\n \tslram=\t\t[HW,MTD]\n \n \tsmart2=\t\t[HW]\ndiff --git a/Documentation/admin-guide/mm/slab.rst b/Documentation/admin-guide/mm/slab.rst\nindex 14429ab90611b..350384908631b 100644\n--- a/Documentation/admin-guide/mm/slab.rst\n+++ b/Documentation/admin-guide/mm/slab.rst\n@@ -45,12 +45,12 @@ of the first \"select slabs\" blocks that matches the slab's name are applied.\n \n Possible debug options are::\n \n-\tF\t\tSanity checks on (enables SLAB_DEBUG_CONSISTENCY_CHECKS\n-\t\t\tSorry SLAB legacy issues)\n+\tF\t\tSanity (slab consistency) checks on alloc and free\n \tZ\t\tRed zoning\n \tP\t\tPoisoning (object and padding)\n \tU\t\tUser tracking (free and alloc)\n \tT\t\tTrace (please only use on single slabs)\n+\tN\t\tNo-op (force debugging slowpaths without any checks)\n \tA\t\tEnable failslab filter mark for the cache\n \tO\t\tSwitch debugging off for caches that would have\n \t\t\tcaused higher minimum slab orders\n@@ -85,6 +85,20 @@ switch off debugging for such caches by default, use::\n \n \tslab_debug=O\n \n+The No-op option can be useful to minimize slab memory overhead by forcing slab\n+debugging slowpaths, which disables percpu object caching. This reduces SMP\n+scalability significantly, but does not impose the extra cpu or memory overhead\n+of debugging options that actually perform checks. This can be useful for e.g.\n+kdump kernels where scalability is not a concern, but memory has to be\n+pre-reserved from the production kernel. So for a kdump kernel you can use::\n+\n+\tslab_debug=N\n+\n+Note that for this purpose you can instead use an option that can achieve\n+slightly better memory savings (by not creating separate kmalloc-rcl caches)::\n+\n+\tslab_tiny=1\n+\n You can apply different options to different list of slab names, using blocks\n of options. This will enable red zoning for dentry and user tracking for\n kmalloc. All other slabs will not get any debugging enabled::\ndiff --git a/include/linux/slab.h b/include/linux/slab.h\nindex cda126def67af..ad645967a3eea 100644\n--- a/include/linux/slab.h\n+++ b/include/linux/slab.h\n@@ -35,6 +35,7 @@ enum _slab_flag_bits {\n \t_SLAB_PANIC,\n \t_SLAB_TYPESAFE_BY_RCU,\n \t_SLAB_TRACE,\n+\t_SLAB_DEBUG_NOOP,\n #ifdef CONFIG_DEBUG_OBJECTS\n \t_SLAB_DEBUG_OBJECTS,\n #endif\n@@ -54,9 +55,7 @@ enum _slab_flag_bits {\n #ifdef CONFIG_KFENCE\n \t_SLAB_SKIP_KFENCE,\n #endif\n-#ifndef CONFIG_SLUB_TINY\n \t_SLAB_RECLAIM_ACCOUNT,\n-#endif\n \t_SLAB_OBJECT_POISON,\n \t_SLAB_CMPXCHG_DOUBLE,\n #ifdef CONFIG_SLAB_OBJ_EXT\n@@ -166,8 +165,10 @@ enum _slab_flag_bits {\n * Note that SLAB_TYPESAFE_BY_RCU was originally named SLAB_DESTROY_BY_RCU.\n */\n #define SLAB_TYPESAFE_BY_RCU\t__SLAB_FLAG_BIT(_SLAB_TYPESAFE_BY_RCU)\n-/* Trace allocations and frees */\n+/* DEBUG: Trace allocations and frees */\n #define SLAB_TRACE\t\t__SLAB_FLAG_BIT(_SLAB_TRACE)\n+/* DEBUG: Force the debug slowpaths without actually doing anything */\n+#define SLAB_DEBUG_NOOP\t\t__SLAB_FLAG_BIT(_SLAB_DEBUG_NOOP)\n \n /* Flag to prevent checks on free */\n #ifdef CONFIG_DEBUG_OBJECTS\n@@ -187,7 +188,7 @@ enum _slab_flag_bits {\n * - general caches created and used by a subsystem, only when a\n * (subsystem-specific) debug option is enabled\n * - performance critical caches, should be very rare and consulted with slab\n- * maintainers, and not used together with CONFIG_SLUB_TINY\n+ * maintainers\n */\n #define SLAB_NO_MERGE\t\t__SLAB_FLAG_BIT(_SLAB_NO_MERGE)\n \n@@ -238,11 +239,7 @@ enum _slab_flag_bits {\n * pages are allocated with __GFP_RECLAIMABLE, which affects grouping pages by\n * mobility, and are accounted in SReclaimable counter in /proc/meminfo\n */\n-#ifndef CONFIG_SLUB_TINY\n #define SLAB_RECLAIM_ACCOUNT\t__SLAB_FLAG_BIT(_SLAB_RECLAIM_ACCOUNT)\n-#else\n-#define SLAB_RECLAIM_ACCOUNT\t__SLAB_FLAG_UNUSED\n-#endif\n #define SLAB_TEMPORARY\t\tSLAB_RECLAIM_ACCOUNT\t/* Objects are short-lived */\n \n /* Slab caches without obj_exts array */\n@@ -721,11 +718,7 @@ enum kmalloc_cache_type {\n #endif\n \tKMALLOC_PARTITION_START = KMALLOC_NORMAL,\n \tKMALLOC_PARTITION_END = KMALLOC_PARTITION_START + KMALLOC_PARTITION_CACHES_NR,\n-#ifdef CONFIG_SLUB_TINY\n-\tKMALLOC_RECLAIM = KMALLOC_NORMAL,\n-#else\n \tKMALLOC_RECLAIM,\n-#endif\n #ifdef CONFIG_ZONE_DMA\n \tKMALLOC_DMA,\n #endif\ndiff --git a/lib/Kconfig.kasan b/lib/Kconfig.kasan\nindex a4bb610a7a6fa..f20b574f6653a 100644\n--- a/lib/Kconfig.kasan\n+++ b/lib/Kconfig.kasan\n@@ -49,7 +49,7 @@ menuconfig KASAN\n \t\t (HAVE_ARCH_KASAN_SW_TAGS \u0026\u0026 CC_HAS_KASAN_SW_TAGS)) \u0026\u0026 \\\n \t\t CC_HAS_WORKING_NOSANITIZE_ADDRESS) || \\\n \t\t HAVE_ARCH_KASAN_HW_TAGS\n-\tdepends on SYSFS \u0026\u0026 !SLUB_TINY\n+\tdepends on SYSFS\n \tselect STACKDEPOT_ALWAYS_INIT\n \thelp\n \t Enables KASAN (Kernel Address Sanitizer) - a dynamic memory safety\ndiff --git a/mm/Kconfig b/mm/Kconfig\nindex edb4a6c0a8702..2286073ea9065 100644\n--- a/mm/Kconfig\n+++ b/mm/Kconfig\n@@ -167,16 +167,18 @@ config SLUB\n \n config KVFREE_RCU_BATCHED\n \tdef_bool y\n-\tdepends on !SLUB_TINY \u0026\u0026 !TINY_RCU\n+\tdepends on !TINY_RCU\n \tdepends on !RCU_STRICT_GRACE_PERIOD\n \n config SLUB_TINY\n-\tbool \"Configure for minimal memory footprint\"\n+\tbool \"Enable slab_tiny by default\"\n \tdepends on EXPERT \u0026\u0026 !COMPILE_TEST\n-\tselect SLAB_MERGE_DEFAULT\n \thelp\n+\t Deprecated option that enables the slab_tiny boot parameter by\n+\t default, and can be overridden by booting with slab_tiny=0.\n+\n \t Configures the slab allocator in a way to achieve minimal memory\n-\t footprint, sacrificing scalability, debugging and other features.\n+\t footprint, sacrificing scalability.\n \t This is intended only for the smallest system that had used the\n \t SLOB allocator and is not recommended for systems with more than\n \t 16MB RAM.\n@@ -199,7 +201,6 @@ config SLAB_MERGE_DEFAULT\n \n config SLAB_FREELIST_RANDOM\n \tbool \"Randomize slab freelist\"\n-\tdepends on !SLUB_TINY\n \thelp\n \t Randomizes the freelist order used on creating new pages. This\n \t security feature reduces the predictability of the kernel slab\n@@ -207,7 +208,6 @@ config SLAB_FREELIST_RANDOM\n \n config SLAB_FREELIST_HARDENED\n \tbool \"Harden slab freelist metadata\"\n-\tdepends on !SLUB_TINY\n \thelp\n \t Many kernel heap attacks try to target slab cache metadata and\n \t other infrastructure. This options makes minor performance\n@@ -216,7 +216,6 @@ config SLAB_FREELIST_HARDENED\n \n config SLAB_BUCKETS\n \tbool \"Support allocation from separate kmalloc buckets\"\n-\tdepends on !SLUB_TINY\n \tdefault SLAB_FREELIST_HARDENED\n \thelp\n \t Kernel heap attacks frequently depend on being able to create\n@@ -234,7 +233,7 @@ config SLAB_BUCKETS\n config SLUB_STATS\n \tdefault n\n \tbool \"Enable performance statistics\"\n-\tdepends on SYSFS \u0026\u0026 !SLUB_TINY\n+\tdepends on SYSFS\n \thelp\n \t The statistics are useful to debug slab allocation behavior in\n \t order find ways to optimize the allocator. This should never be\n@@ -245,7 +244,6 @@ config SLUB_STATS\n \t Try running: slabinfo -DA\n \n config KMALLOC_PARTITION_CACHES\n-\tdepends on !SLUB_TINY\n \tbool \"Partitioned slab caches for normal kmalloc\"\n \tdefault RANDOM_KMALLOC_CACHES\n \thelp\ndiff --git a/mm/Kconfig.debug b/mm/Kconfig.debug\nindex 9eaa25d1cf234..4e36c7c63ef78 100644\n--- a/mm/Kconfig.debug\n+++ b/mm/Kconfig.debug\n@@ -48,7 +48,7 @@ config DEBUG_PAGEALLOC_ENABLE_DEFAULT\n config SLUB_DEBUG\n \tdefault y\n \tbool \"Enable SLUB debugging support\" if EXPERT\n-\tdepends on SYSFS \u0026\u0026 !SLUB_TINY\n+\tdepends on SYSFS\n \tselect STACKDEPOT if STACKTRACE_SUPPORT\n \thelp\n \t SLUB has extensive debug support features. Disabling these can\ndiff --git a/mm/slab.h b/mm/slab.h\nindex e94ac63d10dc0..d39ea67d44f4e 100644\n--- a/mm/slab.h\n+++ b/mm/slab.h\n@@ -282,16 +282,15 @@ struct kmem_cache {\n /*\n * Every cache has !NULL s-\u003ecpu_sheaves but they may point to the\n * bootstrap_sheaf temporarily during init, or permanently for the boot caches\n- * and caches with debugging enabled, or all caches with CONFIG_SLUB_TINY. This\n+ * and caches with debugging enabled (or all caches with slab_tiny). This\n * helper distinguishes whether cache has real non-bootstrap sheaves.\n */\n static inline bool cache_has_sheaves(struct kmem_cache *s)\n {\n-\t/* Test CONFIG_SLUB_TINY for code elimination purposes */\n-\treturn !IS_ENABLED(CONFIG_SLUB_TINY) \u0026\u0026 s-\u003esheaf_capacity;\n+\treturn s-\u003esheaf_capacity;\n }\n \n-#if defined(CONFIG_SYSFS) \u0026\u0026 !defined(CONFIG_SLUB_TINY)\n+#ifdef CONFIG_SYSFS\n #define SLAB_SUPPORTS_SYSFS 1\n void sysfs_slab_unlink(struct kmem_cache *s);\n void sysfs_slab_release(struct kmem_cache *s);\n@@ -396,6 +395,8 @@ extern const struct kmalloc_info_struct {\n \tunsigned int size;\n } kmalloc_info[];\n \n+extern bool slab_tiny_enabled;\n+\n /* Kmalloc array related functions */\n void setup_kmalloc_cache_index_table(void);\n void create_kmalloc_caches(void);\n@@ -476,7 +477,7 @@ void flush_rcu_sheaves_on_cache(struct kmem_cache *s);\n \t\t\t SLAB_NO_USER_FLAGS | SLAB_KMALLOC | SLAB_NO_MERGE)\n \n #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER | \\\n-\t\t\t SLAB_TRACE | SLAB_CONSISTENCY_CHECKS)\n+\t\t\t SLAB_TRACE | SLAB_DEBUG_NOOP | SLAB_CONSISTENCY_CHECKS)\n \n #define SLAB_FLAGS_PERMITTED (SLAB_CORE_FLAGS | SLAB_DEBUG_FLAGS)\n \n@@ -504,26 +505,20 @@ struct slabinfo {\n \n void get_slabinfo(struct kmem_cache *s, struct slabinfo *sinfo);\n \n-#ifdef CONFIG_SLUB_DEBUG\n-#ifdef CONFIG_SLUB_DEBUG_ON\n-DECLARE_STATIC_KEY_TRUE(slub_debug_enabled);\n-#else\n-DECLARE_STATIC_KEY_FALSE(slub_debug_enabled);\n-#endif\n-extern void print_tracking(struct kmem_cache *s, void *object);\n-long validate_slab_cache(struct kmem_cache *s);\n+DECLARE_STATIC_KEY_MAYBE(CONFIG_SLUB_DEBUG_ON, slub_debug_enabled);\n+\n static inline bool __slub_debug_enabled(void)\n {\n \treturn static_branch_unlikely(\u0026slub_debug_enabled);\n }\n+\n+#ifdef CONFIG_SLUB_DEBUG\n+extern void print_tracking(struct kmem_cache *s, void *object);\n+long validate_slab_cache(struct kmem_cache *s);\n #else\n static inline void print_tracking(struct kmem_cache *s, void *object)\n {\n }\n-static inline bool __slub_debug_enabled(void)\n-{\n-\treturn false;\n-}\n #endif\n \n /*\n@@ -576,8 +571,7 @@ static inline bool need_kmalloc_no_objext(void)\n \tif (!mem_alloc_profiling_permanently_disabled())\n \t\treturn true;\n \n-\tif (!mem_cgroup_kmem_disabled() \u0026\u0026\n-\t\t\t(KMALLOC_NORMAL == KMALLOC_RECLAIM))\n+\tif (!mem_cgroup_kmem_disabled() \u0026\u0026 slab_tiny_enabled)\n \t\treturn true;\n \n \treturn false;\ndiff --git a/mm/slab_common.c b/mm/slab_common.c\nindex 01c64ef661e7f..33e76a0c30844 100644\n--- a/mm/slab_common.c\n+++ b/mm/slab_common.c\n@@ -47,9 +47,9 @@ struct kmem_cache *kmem_cache;\n * Any flag that adds per-object metadata should be included,\n * since slab merging can update s-\u003einuse that affects the metadata layout.\n */\n-#define SLAB_NEVER_MERGE (SLAB_DEBUG_FLAGS | SLAB_TYPESAFE_BY_RCU | \\\n-\t\tSLAB_NOLEAKTRACE | SLAB_FAILSLAB | SLAB_NO_MERGE | \\\n-\t\tSLAB_OBJ_EXT_IN_OBJ)\n+#define SLAB_NEVER_MERGE ((SLAB_DEBUG_FLAGS \u0026 ~SLAB_DEBUG_NOOP) | \\\n+\t\tSLAB_TYPESAFE_BY_RCU | SLAB_NOLEAKTRACE | SLAB_FAILSLAB | \\\n+\t\tSLAB_NO_MERGE | SLAB_OBJ_EXT_IN_OBJ)\n \n #define SLAB_MERGE_SAME (SLAB_RECLAIM_ACCOUNT | SLAB_CACHE_DMA | \\\n \t\t\t SLAB_CACHE_DMA32 | SLAB_ACCOUNT | SLAB_MAY_ACCOUNT)\n@@ -835,11 +835,7 @@ EXPORT_SYMBOL(kmalloc_size_roundup);\n #define KMALLOC_CGROUP_NAME(sz)\n #endif\n \n-#ifndef CONFIG_SLUB_TINY\n #define KMALLOC_RCL_NAME(sz)\t.name[KMALLOC_RECLAIM] = \"kmalloc-rcl-\" #sz,\n-#else\n-#define KMALLOC_RCL_NAME(sz)\n-#endif\n \n #ifdef CONFIG_KMALLOC_PARTITION_CACHES\n #define __KMALLOC_PARTITION_CONCAT(a, b) a ## b\n@@ -976,7 +972,11 @@ new_kmalloc_cache(int idx, enum kmalloc_cache_type type)\n \tunsigned int aligned_size = kmalloc_info[idx].size;\n \tint aligned_idx = idx;\n \n-\tif ((KMALLOC_RECLAIM != KMALLOC_NORMAL) \u0026\u0026 (type == KMALLOC_RECLAIM)) {\n+\tif (type == KMALLOC_RECLAIM) {\n+\t\tif (slab_tiny_enabled) {\n+\t\t\tkmalloc_caches[type][idx] = kmalloc_caches[KMALLOC_NORMAL][idx];\n+\t\t\treturn;\n+\t\t}\n \t\tflags |= SLAB_RECLAIM_ACCOUNT;\n \t} else if (IS_ENABLED(CONFIG_MEMCG) \u0026\u0026 (type == KMALLOC_CGROUP)) {\n \t\tif (mem_cgroup_kmem_disabled()) {\n@@ -1009,7 +1009,7 @@ new_kmalloc_cache(int idx, enum kmalloc_cache_type type)\n \t * KMALLOC_NO_OBJ_EXT cache.\n \t */\n \tif (!mem_cgroup_kmem_disabled()) {\n-\t\tif (type == KMALLOC_NORMAL \u0026\u0026 KMALLOC_RECLAIM != KMALLOC_NORMAL)\n+\t\tif (type == KMALLOC_NORMAL \u0026\u0026 !slab_tiny_enabled)\n \t\t\tflags |= SLAB_NO_MERGE;\n \t\telse if (!(flags \u0026 SLAB_NO_OBJ_EXT))\n \t\t\tflags |= SLAB_MAY_ACCOUNT;\ndiff --git a/mm/slub.c b/mm/slub.c\nindex 45e077c7526c2..3b7ba4fdeada4 100644\n--- a/mm/slub.c\n+++ b/mm/slub.c\n@@ -196,19 +196,9 @@ enum slab_flags {\n \tSL_pfmemalloc = PG_active,\t/* Historical reasons for this bit */\n };\n \n-#ifndef CONFIG_SLUB_TINY\n #define __fastpath_inline __always_inline\n-#else\n-#define __fastpath_inline\n-#endif\n \n-#ifdef CONFIG_SLUB_DEBUG\n-#ifdef CONFIG_SLUB_DEBUG_ON\n-DEFINE_STATIC_KEY_TRUE(slub_debug_enabled);\n-#else\n-DEFINE_STATIC_KEY_FALSE(slub_debug_enabled);\n-#endif\n-#endif\t\t/* CONFIG_SLUB_DEBUG */\n+DEFINE_STATIC_KEY_MAYBE(CONFIG_SLUB_DEBUG_ON, slub_debug_enabled);\n \n #ifdef CONFIG_NUMA\n static DEFINE_STATIC_KEY_FALSE(strict_numa);\n@@ -219,6 +209,8 @@ DEFINE_STATIC_KEY_MAYBE(CONFIG_MEM_ALLOC_PROFILING_ENABLED_BY_DEFAULT,\n \t\t\tslab_obj_ext_has_codetag_key);\n #endif\n \n+bool slab_tiny_enabled __read_mostly = IS_ENABLED(CONFIG_SLUB_TINY);\n+\n /* Structure holding extra parameters for slab allocations */\n struct slab_alloc_context {\n \tunsigned long caller_addr;\n@@ -270,7 +262,6 @@ void *fixup_red_left(struct kmem_cache *s, void *p)\n /* Enable to log cmpxchg failures */\n #undef SLUB_DEBUG_CMPXCHG\n \n-#ifndef CONFIG_SLUB_TINY\n /*\n * Minimum number of partial slabs. These will be left on the partial\n * lists even if they are empty. kmem_cache_shrink may reclaim them.\n@@ -283,10 +274,6 @@ void *fixup_red_left(struct kmem_cache *s, void *p)\n * sort the partial list by the number of objects in use.\n */\n #define MAX_PARTIAL 10\n-#else\n-#define MIN_PARTIAL 0\n-#define MAX_PARTIAL 0\n-#endif\n \n #define DEBUG_DEFAULT_FLAGS (SLAB_CONSISTENCY_CHECKS | SLAB_RED_ZONE | \\\n \t\t\t\tSLAB_POISON | SLAB_STORE_USER)\n@@ -1044,15 +1031,24 @@ static inline void *restore_red_left(struct kmem_cache *s, void *p)\n /*\n * Debug settings:\n */\n-#if defined(CONFIG_SLUB_DEBUG_ON)\n-static slab_flags_t slub_debug = DEBUG_DEFAULT_FLAGS;\n-#else\n-static slab_flags_t slub_debug;\n-#endif\n+static slab_flags_t slub_debug = IS_ENABLED(CONFIG_SLUB_DEBUG_ON) ? DEBUG_DEFAULT_FLAGS : 0;\n \n static const char *slub_debug_string __ro_after_init;\n static int disable_higher_order_debug;\n \n+/* Union of all slab debug flags enabled for specific caches only */\n+static slab_flags_t slab_debug_per_cache_union __initdata;\n+\n+static inline bool __init slab_want_nohash_pointers(void)\n+{\n+\t/*\n+\t * If any debugging is enabled globally or per-cache, we would like\n+\t * nohash pointers. The exception is no-op debugging that only forces\n+\t * the slowpaths.\n+\t */\n+\treturn (slub_debug | slab_debug_per_cache_union) \u0026 ~SLAB_DEBUG_NOOP;\n+}\n+\n /*\n * Object debugging\n */\n@@ -1898,6 +1894,9 @@ parse_slub_debug_flags(const char *str, slab_flags_t *flags, const char **slabs,\n \t\tcase 't':\n \t\t\t*flags |= SLAB_TRACE;\n \t\t\tbreak;\n+\t\tcase 'n':\n+\t\t\t*flags |= SLAB_DEBUG_NOOP;\n+\t\t\tbreak;\n \t\tcase 'a':\n \t\t\t*flags |= SLAB_FAILSLAB;\n \t\t\tbreak;\n@@ -1961,6 +1960,7 @@ static int __init setup_slub_debug(const char *str, const struct kernel_param *k\n \t\t\tglobal_slub_debug_changed = true;\n \t\t} else {\n \t\t\tslab_list_specified = true;\n+\t\t\tslab_debug_per_cache_union |= flags;\n \t\t\tif (flags \u0026 SLAB_STORE_USER)\n \t\t\t\tstack_depot_request_early_init();\n \t\t}\n@@ -2018,6 +2018,9 @@ slab_flags_t kmem_cache_flags(slab_flags_t flags, const char *name)\n \tslab_flags_t block_flags;\n \tslab_flags_t slub_debug_local = slub_debug;\n \n+\tif (slab_tiny_enabled)\n+\t\tflags |= SLAB_DEBUG_NOOP;\n+\n \tif (flags \u0026 SLAB_NO_USER_FLAGS)\n \t\treturn flags;\n \n@@ -2069,6 +2072,8 @@ static inline void setup_object_debug(struct kmem_cache *s, void *object) {}\n static inline\n void setup_slab_debug(struct kmem_cache *s, struct slab *slab, void *addr) {}\n \n+static inline bool __init slab_want_nohash_pointers(void) { return false; }\n+\n static inline bool alloc_debug_processing(struct kmem_cache *s,\n \tstruct slab *slab, void *object, int orig_size) { return true; }\n \n@@ -2088,6 +2093,9 @@ static inline void remove_full(struct kmem_cache *s, struct kmem_cache_node *n,\n \t\t\t\t\tstruct slab *slab) {}\n slab_flags_t kmem_cache_flags(slab_flags_t flags, const char *name)\n {\n+\tif (slab_tiny_enabled)\n+\t\tflags |= SLAB_DEBUG_NOOP;\n+\n \treturn flags;\n }\n #define slub_debug 0\n@@ -3948,7 +3956,7 @@ static void *get_from_partial_node(struct kmem_cache *s,\n \t\tif (!pfmemalloc_match(slab, gfp_flags))\n \t\t\tcontinue;\n \n-\t\tif (IS_ENABLED(CONFIG_SLUB_TINY) || kmem_cache_debug(s)) {\n+\t\tif (kmem_cache_debug(s)) {\n \t\t\tobject = alloc_single_from_partial(s, n, slab,\n \t\t\t\t\t\t\tac-\u003eorig_size);\n \t\t\tif (object)\n@@ -4562,7 +4570,7 @@ static unsigned int alloc_from_new_slab(struct kmem_cache *s, struct slab *slab,\n \n /*\n * Slow path. We failed to allocate via percpu sheaves or they are not available\n- * due to bootstrap or debugging enabled or SLUB_TINY.\n+ * due to bootstrap or debugging enabled.\n *\n * We try to allocate from partial slab lists and fall back to allocating a new\n * slab.\n@@ -4616,7 +4624,7 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node,\n \n \tstat(s, ALLOC_SLAB);\n \n-\tif (IS_ENABLED(CONFIG_SLUB_TINY) || kmem_cache_debug(s)) {\n+\tif (kmem_cache_debug(s)) {\n \t\tobject = alloc_single_from_new_slab(s, slab, ac);\n \n \t\tif (likely(object))\n@@ -5845,7 +5853,7 @@ static void __slab_free(struct kmem_cache *s, struct slab *slab,\n \tunsigned long flags;\n \tbool on_node_partial;\n \n-\tif (IS_ENABLED(CONFIG_SLUB_TINY) || kmem_cache_debug(s)) {\n+\tif (kmem_cache_debug(s)) {\n \t\tfree_to_partial_list(s, slab, head, tail, cnt, addr);\n \t\treturn;\n \t}\n@@ -7557,7 +7565,7 @@ static bool __kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags,\n {\n \tint i;\n \n-\tif (IS_ENABLED(CONFIG_SLUB_TINY) || kmem_cache_debug(s)) {\n+\tif (kmem_cache_debug(s)) {\n \t\tconst struct slab_alloc_context ac = {\n \t\t\t.caller_addr = _RET_IP_,\n \t\t\t.orig_size = s-\u003eobject_size,\n@@ -7684,10 +7692,16 @@ EXPORT_SYMBOL(kmem_cache_alloc_bulk_noprof);\n * and increases the number of allocations possible without having to\n * take the list_lock.\n */\n-static unsigned int slub_min_order;\n-static unsigned int slub_max_order =\n-\tIS_ENABLED(CONFIG_SLUB_TINY) ? 1 : PAGE_ALLOC_COSTLY_ORDER;\n-static unsigned int slub_min_objects;\n+static unsigned int slab_min_order;\n+static unsigned int slab_max_order = PAGE_ALLOC_COSTLY_ORDER;\n+static unsigned int slab_min_objects;\n+\n+/*\n+ * Store values set by boot-time parameters, to be evaluated in\n+ * kmem_cache_init(). UINT_MAX means they were not set, as 0 is a valid value.\n+ */\n+static unsigned int slab_min_order_param __initdata = UINT_MAX;\n+static unsigned int slab_max_order_param __initdata = UINT_MAX;\n \n /*\n * Calculate the order of allocation given an slab object size.\n@@ -7741,7 +7755,7 @@ static inline int calculate_order(unsigned int size)\n \tunsigned int max_objects;\n \tunsigned int min_order;\n \n-\tmin_objects = slub_min_objects;\n+\tmin_objects = slab_min_objects;\n \tif (!min_objects) {\n \t\t/*\n \t\t * Some architectures will only update present cpus when\n@@ -7758,10 +7772,10 @@ static inline int calculate_order(unsigned int size)\n \t\tmin_objects = 4 * (fls(nr_cpus) + 1);\n \t}\n \t/* min_objects can't be 0 because get_order(0) is undefined */\n-\tmax_objects = max(order_objects(slub_max_order, size), 1U);\n+\tmax_objects = max(order_objects(slab_max_order, size), 1U);\n \tmin_objects = min(min_objects, max_objects);\n \n-\tmin_order = max_t(unsigned int, slub_min_order,\n+\tmin_order = max_t(unsigned int, slab_min_order,\n \t\t\t get_order(min_objects * size));\n \tif (order_objects(min_order, size) \u003e MAX_OBJS_PER_PAGE)\n \t\treturn get_order(size * MAX_OBJS_PER_PAGE) - 1;\n@@ -7782,9 +7796,9 @@ static inline int calculate_order(unsigned int size)\n \t * long as at least single object fits within slab_max_order.\n \t */\n \tfor (unsigned int fraction = 16; fraction \u003e 1; fraction /= 2) {\n-\t\torder = calc_slab_order(size, min_order, slub_max_order,\n+\t\torder = calc_slab_order(size, min_order, slab_max_order,\n \t\t\t\t\tfraction);\n-\t\tif (order \u003c= slub_max_order)\n+\t\tif (order \u003c= slab_max_order)\n \t\t\treturn order;\n \t}\n \n@@ -7852,7 +7866,7 @@ static int init_percpu_sheaves(struct kmem_cache *s)\n \t\t * cache.\n \t\t *\n \t\t * We keep bootstrap_sheaf for kmem_cache and kmem_cache_node,\n-\t\t * caches with debug enabled, and all caches with SLUB_TINY.\n+\t\t * and caches with debugging enabled.\n \t\t * For kmalloc caches it's used temporarily during the initial\n \t\t * bootstrap.\n \t\t */\n@@ -7999,7 +8013,7 @@ static unsigned int calculate_sheaf_capacity(struct kmem_cache *s,\n \tsize_t size;\n \n \n-\tif (IS_ENABLED(CONFIG_SLUB_TINY) || s-\u003eflags \u0026 SLAB_DEBUG_FLAGS)\n+\tif (slab_tiny_enabled || s-\u003eflags \u0026 SLAB_DEBUG_FLAGS)\n \t\treturn 0;\n \n \t/*\n@@ -8355,50 +8369,14 @@ void __kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct slab *slab)\n *\t\tKmalloc subsystem\n *******************************************************************/\n \n-static int __init setup_slub_min_order(const char *str, const struct kernel_param *kp)\n-{\n-\tint ret;\n-\n-\tret = kstrtouint(str, 0, \u0026slub_min_order);\n-\tif (ret)\n-\t\treturn ret;\n-\n-\tif (slub_min_order \u003e slub_max_order)\n-\t\tslub_max_order = slub_min_order;\n-\n-\treturn 0;\n-}\n-\n-static const struct kernel_param_ops param_ops_slab_min_order __initconst = {\n-\t.set = setup_slub_min_order,\n-};\n-__core_param_cb(slab_min_order, \u0026param_ops_slab_min_order, \u0026slub_min_order, 0);\n-__core_param_cb(slub_min_order, \u0026param_ops_slab_min_order, \u0026slub_min_order, 0);\n-\n-static int __init setup_slub_max_order(const char *str, const struct kernel_param *kp)\n-{\n-\tint ret;\n-\n-\tret = kstrtouint(str, 0, \u0026slub_max_order);\n-\tif (ret)\n-\t\treturn ret;\n-\n-\tslub_max_order = min_t(unsigned int, slub_max_order, MAX_PAGE_ORDER);\n-\n-\tif (slub_min_order \u003e slub_max_order)\n-\t\tslub_min_order = slub_max_order;\n+core_param(slab_min_order, slab_min_order_param, uint, 0);\n+core_param(slub_min_order, slab_min_order_param, uint, 0);\n \n-\treturn 0;\n-}\n-\n-static const struct kernel_param_ops param_ops_slab_max_order __initconst = {\n-\t.set = setup_slub_max_order,\n-};\n-__core_param_cb(slab_max_order, \u0026param_ops_slab_max_order, \u0026slub_max_order, 0);\n-__core_param_cb(slub_max_order, \u0026param_ops_slab_max_order, \u0026slub_max_order, 0);\n+core_param(slab_max_order, slab_max_order_param, uint, 0);\n+core_param(slub_max_order, slab_max_order_param, uint, 0);\n \n-core_param(slab_min_objects, slub_min_objects, uint, 0);\n-core_param(slub_min_objects, slub_min_objects, uint, 0);\n+core_param(slab_min_objects, slab_min_objects, uint, 0);\n+core_param(slub_min_objects, slab_min_objects, uint, 0);\n \n #ifdef CONFIG_NUMA\n static int __init setup_slab_strict_numa(const char *str, const struct kernel_param *kp)\n@@ -8705,7 +8683,7 @@ static void __init bootstrap_cache_sheaves(struct kmem_cache *s)\n \n \tcapacity = calculate_sheaf_capacity(s, \u0026empty_args);\n \n-\t/* capacity can be 0 due to debugging or SLUB_TINY */\n+\t/* capacity can be 0 due to debugging */\n \tif (!capacity)\n \t\treturn;\n \n@@ -8771,11 +8749,25 @@ void __init kmem_cache_init(void)\n \n \tslab_obj_ext_has_codetag_init();\n \n+\tif (slab_tiny_enabled) {\n+\t\tslab_max_order = 1;\n+\t\tstatic_branch_enable(\u0026slub_debug_enabled);\n+\t}\n+\n+\tif (slab_max_order_param \u003c= MAX_PAGE_ORDER)\n+\t\tslab_max_order = slab_max_order_param;\n+\n+\tif (slab_min_order_param \u003c= MAX_PAGE_ORDER)\n+\t\tslab_min_order = slab_min_order_param;\n+\n \tif (debug_guardpage_minorder())\n-\t\tslub_max_order = 0;\n+\t\tslab_max_order = 0;\n+\n+\tif (slab_min_order \u003e slab_max_order)\n+\t\tslab_min_order = slab_max_order;\n \n \t/* Inform pointer hashing choice about slub debugging state. */\n-\thash_pointers_finalize(__slub_debug_enabled());\n+\thash_pointers_finalize(slab_want_nohash_pointers());\n \n \tkmem_cache_node = \u0026boot_kmem_cache_node;\n \tkmem_cache = \u0026boot_kmem_cache;\n@@ -8823,7 +8815,7 @@ void __init kmem_cache_init(void)\n \n \tpr_info(\"SLUB: HWalign=%d, Order=%u-%u, MinObjects=%u, CPUs=%u, Nodes=%u\\n\",\n \t\tcache_line_size(),\n-\t\tslub_min_order, slub_max_order, slub_min_objects,\n+\t\tslab_min_order, slab_max_order, slab_min_objects,\n \t\tnr_cpu_ids, nr_node_ids);\n }\n \n@@ -8837,6 +8829,13 @@ void __init kmem_cache_init_late(void)\n #endif\n }\n \n+static int __init early_slab_tiny(char *buf)\n+{\n+\treturn kstrtobool(buf, \u0026slab_tiny_enabled);\n+}\n+\n+early_param(\"slab_tiny\", early_slab_tiny);\n+\n int do_kmem_cache_create(struct kmem_cache *s, const char *name,\n \t\t\t unsigned int size, struct kmem_cache_args *args,\n \t\t\t slab_flags_t flags)\n@@ -8885,6 +8884,8 @@ int do_kmem_cache_create(struct kmem_cache *s, const char *name,\n \t */\n \ts-\u003emin_partial = min_t(unsigned long, MAX_PARTIAL, ilog2(s-\u003esize) / 2);\n \ts-\u003emin_partial = max_t(unsigned long, MIN_PARTIAL, s-\u003emin_partial);\n+\tif (slab_tiny_enabled)\n+\t\ts-\u003emin_partial = 0;\n \n \ts-\u003ecpu_sheaves = alloc_percpu(struct slub_percpu_sheaves);\n \tif (!s-\u003ecpu_sheaves) {\n"
} |
| 2/1 | 2026/10/24 20:46 | agent | patch-evaluator |
1mModel:core Args: null Results: {
"EnableConfigs": [
"SLUB",
"SLUB_DEBUG",
"SLUB_TINY"
],
"FocusSymbols": [
"alloc_single_from_partial",
"alloc_single_from_new_slab",
"free_to_partial_list",
"kmem_cache_flags",
"calculate_sheaf_capacity",
"do_kmem_cache_create",
"__kmem_cache_alloc_bulk"
],
"Reasoning": "The patch converts CONFIG_SLUB_TINY from compile-time conditional compilation to a runtime boot-time configuration (slab_tiny), introduces a new no-op debug mode (SLAB_DEBUG_NOOP / slab_debug=N), and refactors the SLUB memory allocator's allocation, freeing, and cache creation paths. This modifies reachable core memory management logic in mm/slub.c and mm/slab_common.c, altering freelist handling, sheaf capacity computation, and single-object allocation/free slowpaths. Fuzzing is warranted to ensure the refactored slowpaths and invariant assertions do not introduce regressions or memory corruption.",
"WorthFuzzing": true
}Instruction: You are an expert Linux kernel maintainer and security engineer.
Your job is to review a provided patch series and evaluate whether it warrants fuzzing with syzkaller.
IMPORTANT: The changes have ALREADY been applied and committed as the HEAD commit in
your workspace. Do NOT rely on internal assumptions. You must actively use your code access
tools to inspect the actual source code, callers, and surrounding context.
================================================================================
1. CORE TRIAGE PHILOSOPHY
================================================================================
The goal of patch fuzzing is to discover crashes, regressions, exposed latent bugs,
and newly triggered assertions introduced by the patch series.
- REACHABILITY IS THE PRIMARY GATE:
Fuzzing can only discover bugs in code that can actually execute in standard virtualized
environments (GCE or QEMU, utilizing software-emulated devices like USB gadgets, netdev, tun/tap).
If the modified code is structurally unreachable (see Section 2), it MUST NOT be fuzzed,
regardless of whether it adds assertions or complex logic.
- DO NOT BLINDLY TRUST "NO FUNCTIONAL CHANGE" (NFCI) OR "REFACTORING" CLAIMS:
Patch authors routinely label changes as "cleanups", "refactorings", or state
"No functional change intended". Do NOT take these claims at face value.
Code refactorings that rearrange logic, introduce helper functions, or alter state management
in core subsystems frequently introduce subtle semantic shifts or uncover latent kernel bugs.
If reachable executable code is modified or refactored, it MUST be fuzzed.
- NEW OR MODIFIED ASSERTIONS IN REACHABLE CODE MUST BE FUZZED:
When a patch introduces or modifies runtime checks or assertions (e.g., WARN_ON*, VM_WARN_ON*,
BUG_ON*, lockdep_assert*) in reachable code paths, it enforces new or stricter invariants.
Even if the author believes the invariant always holds, fuzzing is essential to verify whether
an unusual sequence of operations can violate it.
================================================================================
2. WHEN TO RETURN WorthFuzzing=false (NEGATIVE CRITERIA)
================================================================================
Return WorthFuzzing=false ONLY IF all modified code falls strictly into one or more of these categories:
- Non-kernel and non-executable changes:
* Modifications to Documentation/, comments, or spelling fixes.
* User-space directories, self-tests, samples, or scripts (e.g., tools/, samples/, scripts/, usr/)
that do not affect the compiled kernel image (vmlinux) or kernel modules.
* Purely decorative logging (e.g., message strings in pr_err, printk, dev_info) or tracepoints
that do not alter control flow or data structures.
* Build system or Kconfig changes that do not alter compiled C logic.
- Structurally unreachable hardware:
* Vendor-specific PCIe switches, SmartNICs, or GPU drivers (e.g., mlxsw, pds_core, qed,
ionic, amdgpu) requiring physical ASIC/PCIe cards not emulated in standard QEMU.
- Unreachable execution paths:
* Driver teardown callbacks (.remove, .shutdown, pci_unregister_driver) executed only during
physical PCI hot-unplug or manual sysfs driver unbinding.
* Code paths exclusive to architectures other than the target architecture.
================================================================================
3. WHEN TO RETURN WorthFuzzing=true (POSITIVE CRITERIA)
================================================================================
Return WorthFuzzing=true whenever the patch touches reachable executable code, including:
- Core Subsystems:
* Any logic modifications in memory management (mm/), synchronization/locking (kernel/locking/),
BPF, scheduler, core networking, VFS, or syscall handling.
- Refactorings and Code Cleanups:
* Any restructuring of reachable data structures, helper abstractions, or algorithm flows.
- Runtime Assertions and Defensive Checks:
* Any introduction or alteration of assertions (WARN_ON*, VM_WARN_ON*, BUG_ON*, etc.) in reachable paths.
- Reachable Drivers and Protocols:
* Drivers accessible via virtual buses (virtio, USB gadget, loopback, netlink, binder, sockets, etc.).
================================================================================
4. EXTRACTING FocusSymbols (PREVENTING DILUTION)
================================================================================
When WorthFuzzing=true, you must extract specific kernel functions into FocusSymbols to guide the fuzzer:
- AVOID UBIQUITOUS LIFECYCLE HOT-PATHS:
Do NOT list generic, ubiquitous functions called by almost every program in the corpus
(including, but not limited to: general memory allocators and deallocators, page fault
and trap handlers, or core synchronization primitives; this is not an exhaustive list).
Listing ubiquitous functions causes the fuzzer to classify thousands of unrelated tests as "focused",
which severely dilutes fuzzing effort away from the actual changes.
- TARGET SPECIFIC FEATURE LOGIC AND ENTRYPOINTS:
List functions that specifically implement the logic being added or altered, or direct API entrypoints
for the subsystem feature under review.
- HANDLING STATIC INLINE FUNCTIONS IN HEADERS (.h):
Compiler-inlined static functions (such as static inlines in mm/*.h or include/linux/*.h) lack
distinct symbol addresses in vmlinux and cannot be targeted directly by symbol coverage filters.
If the changes are primarily in static inline helpers, identify non-static, feature-specific caller
functions in .c files that exercise them (avoiding ubiquitous lifecycle wrappers).
================================================================================
5. IDENTIFYING EnableConfigs
================================================================================
Identify any specific CONFIG_ options required to properly compile and reach the modified code:
- Inspect Kconfig files and #ifdef guards; do not make assumptions.
- Check "depends on" lines in Kconfig to include any non-standard parent subsystem configs needed.
- Strip any 'CONFIG_' prefix (e.g., return "NET_IPV4" instead of "CONFIG_NET_IPV4").
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt: Target architecture: amd64
For your convenience, here is the diff of the changes:
commit 140335c47acb03e30728e609e79ac4636d89dd6b
Author: syz-cluster <triage@syzkaller.com>
Date: Sat Oct 24 20:46:31 2026 +0000
syz-cluster: applied patch under review
diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index 03636d7998374..29dc1c8124733 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -7043,6 +7043,10 @@ Kernel parameters
NUMA kernel object placement which helps with slow
interconnects in NUMA systems.
+ slab_tiny= [MM, EARLY]
+ Minimize the slab allocator memory footprint at the
+ expense of SMP scalability.
+
slram= [HW,MTD]
smart2= [HW]
diff --git a/Documentation/admin-guide/mm/slab.rst b/Documentation/admin-guide/mm/slab.rst
index 14429ab90611b..350384908631b 100644
--- a/Documentation/admin-guide/mm/slab.rst
+++ b/Documentation/admin-guide/mm/slab.rst
@@ -45,12 +45,12 @@ of the first "select slabs" blocks that matches the slab's name are applied.
Possible debug options are::
- F Sanity checks on (enables SLAB_DEBUG_CONSISTENCY_CHECKS
- Sorry SLAB legacy issues)
+ F Sanity (slab consistency) checks on alloc and free
Z Red zoning
P Poisoning (object and padding)
U User tracking (free and alloc)
T Trace (please only use on single slabs)
+ N No-op (force debugging slowpaths without any checks)
A Enable failslab filter mark for the cache
O Switch debugging off for caches that would have
caused higher minimum slab orders
@@ -85,6 +85,20 @@ switch off debugging for such caches by default, use::
slab_debug=O
+The No-op option can be useful to minimize slab memory overhead by forcing slab
+debugging slowpaths, which disables percpu object caching. This reduces SMP
+scalability significantly, but does not impose the extra cpu or memory overhead
+of debugging options that actually perform checks. This can be useful for e.g.
+kdump kernels where scalability is not a concern, but memory has to be
+pre-reserved from the production kernel. So for a kdump kernel you can use::
+
+ slab_debug=N
+
+Note that for this purpose you can instead use an option that can achieve
+slightly better memory savings (by not creating separate kmalloc-rcl caches)::
+
+ slab_tiny=1
+
You can apply different options to different list of slab names, using blocks
of options. This will enable red zoning for dentry and user tracking for
kmalloc. All other slabs will not get any debugging enabled::
diff --git a/include/linux/slab.h b/include/linux/slab.h
index cda126def67af..ad645967a3eea 100644
--- a/include/linux/slab.h
+++ b/include/linux/slab.h
@@ -35,6 +35,7 @@ enum _slab_flag_bits {
_SLAB_PANIC,
_SLAB_TYPESAFE_BY_RCU,
_SLAB_TRACE,
+ _SLAB_DEBUG_NOOP,
#ifdef CONFIG_DEBUG_OBJECTS
_SLAB_DEBUG_OBJECTS,
#endif
@@ -54,9 +55,7 @@ enum _slab_flag_bits {
#ifdef CONFIG_KFENCE
_SLAB_SKIP_KFENCE,
#endif
-#ifndef CONFIG_SLUB_TINY
_SLAB_RECLAIM_ACCOUNT,
-#endif
_SLAB_OBJECT_POISON,
_SLAB_CMPXCHG_DOUBLE,
#ifdef CONFIG_SLAB_OBJ_EXT
@@ -166,8 +165,10 @@ enum _slab_flag_bits {
* Note that SLAB_TYPESAFE_BY_RCU was originally named SLAB_DESTROY_BY_RCU.
*/
#define SLAB_TYPESAFE_BY_RCU __SLAB_FLAG_BIT(_SLAB_TYPESAFE_BY_RCU)
-/* Trace allocations and frees */
+/* DEBUG: Trace allocations and frees */
#define SLAB_TRACE __SLAB_FLAG_BIT(_SLAB_TRACE)
+/* DEBUG: Force the debug slowpaths without actually doing anything */
+#define SLAB_DEBUG_NOOP __SLAB_FLAG_BIT(_SLAB_DEBUG_NOOP)
/* Flag to prevent checks on free */
#ifdef CONFIG_DEBUG_OBJECTS
@@ -187,7 +188,7 @@ enum _slab_flag_bits {
* - general caches created and used by a subsystem, only when a
* (subsystem-specific) debug option is enabled
* - performance critical caches, should be very rare and consulted with slab
- * maintainers, and not used together with CONFIG_SLUB_TINY
+ * maintainers
*/
#define SLAB_NO_MERGE __SLAB_FLAG_BIT(_SLAB_NO_MERGE)
@@ -238,11 +239,7 @@ enum _slab_flag_bits {
* pages are allocated with __GFP_RECLAIMABLE, which affects grouping pages by
* mobility, and are accounted in SReclaimable counter in /proc/meminfo
*/
-#ifndef CONFIG_SLUB_TINY
#define SLAB_RECLAIM_ACCOUNT __SLAB_FLAG_BIT(_SLAB_RECLAIM_ACCOUNT)
-#else
-#define SLAB_RECLAIM_ACCOUNT __SLAB_FLAG_UNUSED
-#endif
#define SLAB_TEMPORARY SLAB_RECLAIM_ACCOUNT /* Objects are short-lived */
/* Slab caches without obj_exts array */
@@ -721,11 +718,7 @@ enum kmalloc_cache_type {
#endif
KMALLOC_PARTITION_START = KMALLOC_NORMAL,
KMALLOC_PARTITION_END = KMALLOC_PARTITION_START + KMALLOC_PARTITION_CACHES_NR,
-#ifdef CONFIG_SLUB_TINY
- KMALLOC_RECLAIM = KMALLOC_NORMAL,
-#else
KMALLOC_RECLAIM,
-#endif
#ifdef CONFIG_ZONE_DMA
KMALLOC_DMA,
#endif
diff --git a/lib/Kconfig.kasan b/lib/Kconfig.kasan
index a4bb610a7a6fa..f20b574f6653a 100644
--- a/lib/Kconfig.kasan
+++ b/lib/Kconfig.kasan
@@ -49,7 +49,7 @@ menuconfig KASAN
(HAVE_ARCH_KASAN_SW_TAGS && CC_HAS_KASAN_SW_TAGS)) && \
CC_HAS_WORKING_NOSANITIZE_ADDRESS) || \
HAVE_ARCH_KASAN_HW_TAGS
- depends on SYSFS && !SLUB_TINY
+ depends on SYSFS
select STACKDEPOT_ALWAYS_INIT
help
Enables KASAN (Kernel Address Sanitizer) - a dynamic memory safety
diff --git a/mm/Kconfig b/mm/Kconfig
index edb4a6c0a8702..2286073ea9065 100644
--- a/mm/Kconfig
+++ b/mm/Kconfig
@@ -167,16 +167,18 @@ config SLUB
config KVFREE_RCU_BATCHED
def_bool y
- depends on !SLUB_TINY && !TINY_RCU
+ depends on !TINY_RCU
depends on !RCU_STRICT_GRACE_PERIOD
config SLUB_TINY
- bool "Configure for minimal memory footprint"
+ bool "Enable slab_tiny by default"
depends on EXPERT && !COMPILE_TEST
- select SLAB_MERGE_DEFAULT
help
+ Deprecated option that enables the slab_tiny boot parameter by
+ default, and can be overridden by booting with slab_tiny=0.
+
Configures the slab allocator in a way to achieve minimal memory
- footprint, sacrificing scalability, debugging and other features.
+ footprint, sacrificing scalability.
This is intended only for the smallest system that had used the
SLOB allocator and is not recommended for systems with more than
16MB RAM.
@@ -199,7 +201,6 @@ config SLAB_MERGE_DEFAULT
config SLAB_FREELIST_RANDOM
bool "Randomize slab freelist"
- depends on !SLUB_TINY
help
Randomizes the freelist order used on creating new pages. This
security feature reduces the predictability of the kernel slab
@@ -207,7 +208,6 @@ config SLAB_FREELIST_RANDOM
config SLAB_FREELIST_HARDENED
bool "Harden slab freelist metadata"
- depends on !SLUB_TINY
help
Many kernel heap attacks try to target slab cache metadata and
other infrastructure. This options makes minor performance
@@ -216,7 +216,6 @@ config SLAB_FREELIST_HARDENED
config SLAB_BUCKETS
bool "Support allocation from separate kmalloc buckets"
- depends on !SLUB_TINY
default SLAB_FREELIST_HARDENED
help
Kernel heap attacks frequently depend on being able to create
@@ -234,7 +233,7 @@ config SLAB_BUCKETS
config SLUB_STATS
default n
bool "Enable performance statistics"
- depends on SYSFS && !SLUB_TINY
+ depends on SYSFS
help
The statistics are useful to debug slab allocation behavior in
order find ways to optimize the allocator. This should never be
@@ -245,7 +244,6 @@ config SLUB_STATS
Try running: slabinfo -DA
config KMALLOC_PARTITION_CACHES
- depends on !SLUB_TINY
bool "Partitioned slab caches for normal kmalloc"
default RANDOM_KMALLOC_CACHES
help
diff --git a/mm/Kconfig.debug b/mm/Kconfig.debug
index 9eaa25d1cf234..4e36c7c63ef78 100644
--- a/mm/Kconfig.debug
+++ b/mm/Kconfig.debug
@@ -48,7 +48,7 @@ config DEBUG_PAGEALLOC_ENABLE_DEFAULT
config SLUB_DEBUG
default y
bool "Enable SLUB debugging support" if EXPERT
- depends on SYSFS && !SLUB_TINY
+ depends on SYSFS
select STACKDEPOT if STACKTRACE_SUPPORT
help
SLUB has extensive debug support features. Disabling these can
diff --git a/mm/slab.h b/mm/slab.h
index e94ac63d10dc0..d39ea67d44f4e 100644
--- a/mm/slab.h
+++ b/mm/slab.h
@@ -282,16 +282,15 @@ struct kmem_cache {
/*
* Every cache has !NULL s->cpu_sheaves but they may point to the
* bootstrap_sheaf temporarily during init, or permanently for the boot caches
- * and caches with debugging enabled, or all caches with CONFIG_SLUB_TINY. This
+ * and caches with debugging enabled (or all caches with slab_tiny). This
* helper distinguishes whether cache has real non-bootstrap sheaves.
*/
static inline bool cache_has_sheaves(struct kmem_cache *s)
{
- /* Test CONFIG_SLUB_TINY for code elimination purposes */
- return !IS_ENABLED(CONFIG_SLUB_TINY) && s->sheaf_capacity;
+ return s->sheaf_capacity;
}
-#if defined(CONFIG_SYSFS) && !defined(CONFIG_SLUB_TINY)
+#ifdef CONFIG_SYSFS
#define SLAB_SUPPORTS_SYSFS 1
void sysfs_slab_unlink(struct kmem_cache *s);
void sysfs_slab_release(struct kmem_cache *s);
@@ -396,6 +395,8 @@ extern const struct kmalloc_info_struct {
unsigned int size;
} kmalloc_info[];
+extern bool slab_tiny_enabled;
+
/* Kmalloc array related functions */
void setup_kmalloc_cache_index_table(void);
void create_kmalloc_caches(void);
@@ -476,7 +477,7 @@ void flush_rcu_sheaves_on_cache(struct kmem_cache *s);
SLAB_NO_USER_FLAGS | SLAB_KMALLOC | SLAB_NO_MERGE)
#define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER | \
- SLAB_TRACE | SLAB_CONSISTENCY_CHECKS)
+ SLAB_TRACE | SLAB_DEBUG_NOOP | SLAB_CONSISTENCY_CHECKS)
#define SLAB_FLAGS_PERMITTED (SLAB_CORE_FLAGS | SLAB_DEBUG_FLAGS)
@@ -504,26 +505,20 @@ struct slabinfo {
void get_slabinfo(struct kmem_cache *s, struct slabinfo *sinfo);
-#ifdef CONFIG_SLUB_DEBUG
-#ifdef CONFIG_SLUB_DEBUG_ON
-DECLARE_STATIC_KEY_TRUE(slub_debug_enabled);
-#else
-DECLARE_STATIC_KEY_FALSE(slub_debug_enabled);
-#endif
-extern void print_tracking(struct kmem_cache *s, void *object);
-long validate_slab_cache(struct kmem_cache *s);
+DECLARE_STATIC_KEY_MAYBE(CONFIG_SLUB_DEBUG_ON, slub_debug_enabled);
+
static inline bool __slub_debug_enabled(void)
{
return static_branch_unlikely(&slub_debug_enabled);
}
+
+#ifdef CONFIG_SLUB_DEBUG
+extern void print_tracking(struct kmem_cache *s, void *object);
+long validate_slab_cache(struct kmem_cache *s);
#else
static inline void print_tracking(struct kmem_cache *s, void *object)
{
}
-static inline bool __slub_debug_enabled(void)
-{
- return false;
-}
#endif
/*
@@ -576,8 +571,7 @@ static inline bool need_kmalloc_no_objext(void)
if (!mem_alloc_profiling_permanently_disabled())
return true;
- if (!mem_cgroup_kmem_disabled() &&
- (KMALLOC_NORMAL == KMALLOC_RECLAIM))
+ if (!mem_cgroup_kmem_disabled() && slab_tiny_enabled)
return true;
return false;
diff --git a/mm/slab_common.c b/mm/slab_common.c
index 01c64ef661e7f..33e76a0c30844 100644
--- a/mm/slab_common.c
+++ b/mm/slab_common.c
@@ -47,9 +47,9 @@ struct kmem_cache *kmem_cache;
* Any flag that adds per-object metadata should be included,
* since slab merging can update s->inuse that affects the metadata layout.
*/
-#define SLAB_NEVER_MERGE (SLAB_DEBUG_FLAGS | SLAB_TYPESAFE_BY_RCU | \
- SLAB_NOLEAKTRACE | SLAB_FAILSLAB | SLAB_NO_MERGE | \
- SLAB_OBJ_EXT_IN_OBJ)
+#define SLAB_NEVER_MERGE ((SLAB_DEBUG_FLAGS & ~SLAB_DEBUG_NOOP) | \
+ SLAB_TYPESAFE_BY_RCU | SLAB_NOLEAKTRACE | SLAB_FAILSLAB | \
+ SLAB_NO_MERGE | SLAB_OBJ_EXT_IN_OBJ)
#define SLAB_MERGE_SAME (SLAB_RECLAIM_ACCOUNT | SLAB_CACHE_DMA | \
SLAB_CACHE_DMA32 | SLAB_ACCOUNT | SLAB_MAY_ACCOUNT)
@@ -835,11 +835,7 @@ EXPORT_SYMBOL(kmalloc_size_roundup);
#define KMALLOC_CGROUP_NAME(sz)
#endif
-#ifndef CONFIG_SLUB_TINY
#define KMALLOC_RCL_NAME(sz) .name[KMALLOC_RECLAIM] = "kmalloc-rcl-" #sz,
-#else
-#define KMALLOC_RCL_NAME(sz)
-#endif
#ifdef CONFIG_KMALLOC_PARTITION_CACHES
#define __KMALLOC_PARTITION_CONCAT(a, b) a ## b
@@ -976,7 +972,11 @@ new_kmalloc_cache(int idx, enum kmalloc_cache_type type)
unsigned int aligned_size = kmalloc_info[idx].size;
int aligned_idx = idx;
- if ((KMALLOC_RECLAIM != KMALLOC_NORMAL) && (type == KMALLOC_RECLAIM)) {
+ if (type == KMALLOC_RECLAIM) {
+ if (slab_tiny_enabled) {
+ kmalloc_caches[type][idx] = kmalloc_caches[KMALLOC_NORMAL][idx];
+ return;
+ }
flags |= SLAB_RECLAIM_ACCOUNT;
} else if (IS_ENABLED(CONFIG_MEMCG) && (type == KMALLOC_CGROUP)) {
if (mem_cgroup_kmem_disabled()) {
@@ -1009,7 +1009,7 @@ new_kmalloc_cache(int idx, enum kmalloc_cache_type type)
* KMALLOC_NO_OBJ_EXT cache.
*/
if (!mem_cgroup_kmem_disabled()) {
- if (type == KMALLOC_NORMAL && KMALLOC_RECLAIM != KMALLOC_NORMAL)
+ if (type == KMALLOC_NORMAL && !slab_tiny_enabled)
flags |= SLAB_NO_MERGE;
else if (!(flags & SLAB_NO_OBJ_EXT))
flags |= SLAB_MAY_ACCOUNT;
diff --git a/mm/slub.c b/mm/slub.c
index 45e077c7526c2..3b7ba4fdeada4 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -196,19 +196,9 @@ enum slab_flags {
SL_pfmemalloc = PG_active, /* Historical reasons for this bit */
};
-#ifndef CONFIG_SLUB_TINY
#define __fastpath_inline __always_inline
-#else
-#define __fastpath_inline
-#endif
-#ifdef CONFIG_SLUB_DEBUG
-#ifdef CONFIG_SLUB_DEBUG_ON
-DEFINE_STATIC_KEY_TRUE(slub_debug_enabled);
-#else
-DEFINE_STATIC_KEY_FALSE(slub_debug_enabled);
-#endif
-#endif /* CONFIG_SLUB_DEBUG */
+DEFINE_STATIC_KEY_MAYBE(CONFIG_SLUB_DEBUG_ON, slub_debug_enabled);
#ifdef CONFIG_NUMA
static DEFINE_STATIC_KEY_FALSE(strict_numa);
@@ -219,6 +209,8 @@ DEFINE_STATIC_KEY_MAYBE(CONFIG_MEM_ALLOC_PROFILING_ENABLED_BY_DEFAULT,
slab_obj_ext_has_codetag_key);
#endif
+bool slab_tiny_enabled __read_mostly = IS_ENABLED(CONFIG_SLUB_TINY);
+
/* Structure holding extra parameters for slab allocations */
struct slab_alloc_context {
unsigned long caller_addr;
@@ -270,7 +262,6 @@ void *fixup_red_left(struct kmem_cache *s, void *p)
/* Enable to log cmpxchg failures */
#undef SLUB_DEBUG_CMPXCHG
-#ifndef CONFIG_SLUB_TINY
/*
* Minimum number of partial slabs. These will be left on the partial
* lists even if they are empty. kmem_cache_shrink may reclaim them.
@@ -283,10 +274,6 @@ void *fixup_red_left(struct kmem_cache *s, void *p)
* sort the partial list by the number of objects in use.
*/
#define MAX_PARTIAL 10
-#else
-#define MIN_PARTIAL 0
-#define MAX_PARTIAL 0
-#endif
#define DEBUG_DEFAULT_FLAGS (SLAB_CONSISTENCY_CHECKS | SLAB_RED_ZONE | \
SLAB_POISON | SLAB_STORE_USER)
@@ -1044,15 +1031,24 @@ static inline void *restore_red_left(struct kmem_cache *s, void *p)
/*
* Debug settings:
*/
-#if defined(CONFIG_SLUB_DEBUG_ON)
-static slab_flags_t slub_debug = DEBUG_DEFAULT_FLAGS;
-#else
-static slab_flags_t slub_debug;
-#endif
+static slab_flags_t slub_debug = IS_ENABLED(CONFIG_SLUB_DEBUG_ON) ? DEBUG_DEFAULT_FLAGS : 0;
static const char *slub_debug_string __ro_after_init;
static int disable_higher_order_debug;
+/* Union of all slab debug flags enabled for specific caches only */
+static slab_flags_t slab_debug_per_cache_union __initdata;
+
+static inline bool __init slab_want_nohash_pointers(void)
+{
+ /*
+ * If any debugging is enabled globally or per-cache, we would like
+ * nohash pointers. The exception is no-op debugging that only forces
+ * the slowpaths.
+ */
+ return (slub_debug | slab_debug_per_cache_union) & ~SLAB_DEBUG_NOOP;
+}
+
/*
* Object debugging
*/
@@ -1898,6 +1894,9 @@ parse_slub_debug_flags(const char *str, slab_flags_t *flags, const char **slabs,
case 't':
*flags |= SLAB_TRACE;
break;
+ case 'n':
+ *flags |= SLAB_DEBUG_NOOP;
+ break;
case 'a':
*flags |= SLAB_FAILSLAB;
break;
@@ -1961,6 +1960,7 @@ static int __init setup_slub_debug(const char *str, const struct kernel_param *k
global_slub_debug_changed = true;
} else {
slab_list_specified = true;
+ slab_debug_per_cache_union |= flags;
if (flags & SLAB_STORE_USER)
stack_depot_request_early_init();
}
@@ -2018,6 +2018,9 @@ slab_flags_t kmem_cache_flags(slab_flags_t flags, const char *name)
slab_flags_t block_flags;
slab_flags_t slub_debug_local = slub_debug;
+ if (slab_tiny_enabled)
+ flags |= SLAB_DEBUG_NOOP;
+
if (flags & SLAB_NO_USER_FLAGS)
return flags;
@@ -2069,6 +2072,8 @@ static inline void setup_object_debug(struct kmem_cache *s, void *object) {}
static inline
void setup_slab_debug(struct kmem_cache *s, struct slab *slab, void *addr) {}
+static inline bool __init slab_want_nohash_pointers(void) { return false; }
+
static inline bool alloc_debug_processing(struct kmem_cache *s,
struct slab *slab, void *object, int orig_size) { return true; }
@@ -2088,6 +2093,9 @@ static inline void remove_full(struct kmem_cache *s, struct kmem_cache_node *n,
struct slab *slab) {}
slab_flags_t kmem_cache_flags(slab_flags_t flags, const char *name)
{
+ if (slab_tiny_enabled)
+ flags |= SLAB_DEBUG_NOOP;
+
return flags;
}
#define slub_debug 0
@@ -3948,7 +3956,7 @@ static void *get_from_partial_node(struct kmem_cache *s,
if (!pfmemalloc_match(slab, gfp_flags))
continue;
- if (IS_ENABLED(CONFIG_SLUB_TINY) || kmem_cache_debug(s)) {
+ if (kmem_cache_debug(s)) {
object = alloc_single_from_partial(s, n, slab,
ac->orig_size);
if (object)
@@ -4562,7 +4570,7 @@ static unsigned int alloc_from_new_slab(struct kmem_cache *s, struct slab *slab,
/*
* Slow path. We failed to allocate via percpu sheaves or they are not available
- * due to bootstrap or debugging enabled or SLUB_TINY.
+ * due to bootstrap or debugging enabled.
*
* We try to allocate from partial slab lists and fall back to allocating a new
* slab.
@@ -4616,7 +4624,7 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node,
stat(s, ALLOC_SLAB);
- if (IS_ENABLED(CONFIG_SLUB_TINY) || kmem_cache_debug(s)) {
+ if (kmem_cache_debug(s)) {
object = alloc_single_from_new_slab(s, slab, ac);
if (likely(object))
@@ -5845,7 +5853,7 @@ static void __slab_free(struct kmem_cache *s, struct slab *slab,
unsigned long flags;
bool on_node_partial;
- if (IS_ENABLED(CONFIG_SLUB_TINY) || kmem_cache_debug(s)) {
+ if (kmem_cache_debug(s)) {
free_to_partial_list(s, slab, head, tail, cnt, addr);
return;
}
@@ -7557,7 +7565,7 @@ static bool __kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags,
{
int i;
- if (IS_ENABLED(CONFIG_SLUB_TINY) || kmem_cache_debug(s)) {
+ if (kmem_cache_debug(s)) {
const struct slab_alloc_context ac = {
.caller_addr = _RET_IP_,
.orig_size = s->object_size,
@@ -7684,10 +7692,16 @@ EXPORT_SYMBOL(kmem_cache_alloc_bulk_noprof);
* and increases the number of allocations possible without having to
* take the list_lock.
*/
-static unsigned int slub_min_order;
-static unsigned int slub_max_order =
- IS_ENABLED(CONFIG_SLUB_TINY) ? 1 : PAGE_ALLOC_COSTLY_ORDER;
-static unsigned int slub_min_objects;
+static unsigned int slab_min_order;
+static unsigned int slab_max_order = PAGE_ALLOC_COSTLY_ORDER;
+static unsigned int slab_min_objects;
+
+/*
+ * Store values set by boot-time parameters, to be evaluated in
+ * kmem_cache_init(). UINT_MAX means they were not set, as 0 is a valid value.
+ */
+static unsigned int slab_min_order_param __initdata = UINT_MAX;
+static unsigned int slab_max_order_param __initdata = UINT_MAX;
/*
* Calculate the order of allocation given an slab object size.
@@ -7741,7 +7755,7 @@ static inline int calculate_order(unsigned int size)
unsigned int max_objects;
unsigned int min_order;
- min_objects = slub_min_objects;
+ min_objects = slab_min_objects;
if (!min_objects) {
/*
* Some architectures will only update present cpus when
@@ -7758,10 +7772,10 @@ static inline int calculate_order(unsigned int size)
min_objects = 4 * (fls(nr_cpus) + 1);
}
/* min_objects can't be 0 because get_order(0) is undefined */
- max_objects = max(order_objects(slub_max_order, size), 1U);
+ max_objects = max(order_objects(slab_max_order, size), 1U);
min_objects = min(min_objects, max_objects);
- min_order = max_t(unsigned int, slub_min_order,
+ min_order = max_t(unsigned int, slab_min_order,
get_order(min_objects * size));
if (order_objects(min_order, size) > MAX_OBJS_PER_PAGE)
return get_order(size * MAX_OBJS_PER_PAGE) - 1;
@@ -7782,9 +7796,9 @@ static inline int calculate_order(unsigned int size)
* long as at least single object fits within slab_max_order.
*/
for (unsigned int fraction = 16; fraction > 1; fraction /= 2) {
- order = calc_slab_order(size, min_order, slub_max_order,
+ order = calc_slab_order(size, min_order, slab_max_order,
fraction);
- if (order <= slub_max_order)
+ if (order <= slab_max_order)
return order;
}
@@ -7852,7 +7866,7 @@ static int init_percpu_sheaves(struct kmem_cache *s)
* cache.
*
* We keep bootstrap_sheaf for kmem_cache and kmem_cache_node,
- * caches with debug enabled, and all caches with SLUB_TINY.
+ * and caches with debugging enabled.
* For kmalloc caches it's used temporarily during the initial
* bootstrap.
*/
@@ -7999,7 +8013,7 @@ static unsigned int calculate_sheaf_capacity(struct kmem_cache *s,
size_t size;
- if (IS_ENABLED(CONFIG_SLUB_TINY) || s->flags & SLAB_DEBUG_FLAGS)
+ if (slab_tiny_enabled || s->flags & SLAB_DEBUG_FLAGS)
return 0;
/*
@@ -8355,50 +8369,14 @@ void __kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct slab *slab)
* Kmalloc subsystem
*******************************************************************/
-static int __init setup_slub_min_order(const char *str, const struct kernel_param *kp)
-{
- int ret;
-
- ret = kstrtouint(str, 0, &slub_min_order);
- if (ret)
- return ret;
-
- if (slub_min_order > slub_max_order)
- slub_max_order = slub_min_order;
-
- return 0;
-}
-
-static const struct kernel_param_ops param_ops_slab_min_order __initconst = {
- .set = setup_slub_min_order,
-};
-__core_param_cb(slab_min_order, ¶m_ops_slab_min_order, &slub_min_order, 0);
-__core_param_cb(slub_min_order, ¶m_ops_slab_min_order, &slub_min_order, 0);
-
-static int __init setup_slub_max_order(const char *str, const struct kernel_param *kp)
-{
- int ret;
-
- ret = kstrtouint(str, 0, &slub_max_order);
- if (ret)
- return ret;
-
- slub_max_order = min_t(unsigned int, slub_max_order, MAX_PAGE_ORDER);
-
- if (slub_min_order > slub_max_order)
- slub_min_order = slub_max_order;
+core_param(slab_min_order, slab_min_order_param, uint, 0);
+core_param(slub_min_order, slab_min_order_param, uint, 0);
- return 0;
-}
-
-static const struct kernel_param_ops param_ops_slab_max_order __initconst = {
- .set = setup_slub_max_order,
-};
-__core_param_cb(slab_max_order, ¶m_ops_slab_max_order, &slub_max_order, 0);
-__core_param_cb(slub_max_order, ¶m_ops_slab_max_order, &slub_max_order, 0);
+core_param(slab_max_order, slab_max_order_param, uint, 0);
+core_param(slub_max_order, slab_max_order_param, uint, 0);
-core_param(slab_min_objects, slub_min_objects, uint, 0);
-core_param(slub_min_objects, slub_min_objects, uint, 0);
+core_param(slab_min_objects, slab_min_objects, uint, 0);
+core_param(slub_min_objects, slab_min_objects, uint, 0);
#ifdef CONFIG_NUMA
static int __init setup_slab_strict_numa(const char *str, const struct kernel_param *kp)
@@ -8705,7 +8683,7 @@ static void __init bootstrap_cache_sheaves(struct kmem_cache *s)
capacity = calculate_sheaf_capacity(s, &empty_args);
- /* capacity can be 0 due to debugging or SLUB_TINY */
+ /* capacity can be 0 due to debugging */
if (!capacity)
return;
@@ -8771,11 +8749,25 @@ void __init kmem_cache_init(void)
slab_obj_ext_has_codetag_init();
+ if (slab_tiny_enabled) {
+ slab_max_order = 1;
+ static_branch_enable(&slub_debug_enabled);
+ }
+
+ if (slab_max_order_param <= MAX_PAGE_ORDER)
+ slab_max_order = slab_max_order_param;
+
+ if (slab_min_order_param <= MAX_PAGE_ORDER)
+ slab_min_order = slab_min_order_param;
+
if (debug_guardpage_minorder())
- slub_max_order = 0;
+ slab_max_order = 0;
+
+ if (slab_min_order > slab_max_order)
+ slab_min_order = slab_max_order;
/* Inform pointer hashing choice about slub debugging state. */
- hash_pointers_finalize(__slub_debug_enabled());
+ hash_pointers_finalize(slab_want_nohash_pointers());
kmem_cache_node = &boot_kmem_cache_node;
kmem_cache = &boot_kmem_cache;
@@ -8823,7 +8815,7 @@ void __init kmem_cache_init(void)
pr_info("SLUB: HWalign=%d, Order=%u-%u, MinObjects=%u, CPUs=%u, Nodes=%u\n",
cache_line_size(),
- slub_min_order, slub_max_order, slub_min_objects,
+ slab_min_order, slab_max_order, slab_min_objects,
nr_cpu_ids, nr_node_ids);
}
@@ -8837,6 +8829,13 @@ void __init kmem_cache_init_late(void)
#endif
}
+static int __init early_slab_tiny(char *buf)
+{
+ return kstrtobool(buf, &slab_tiny_enabled);
+}
+
+early_param("slab_tiny", early_slab_tiny);
+
int do_kmem_cache_create(struct kmem_cache *s, const char *name,
unsigned int size, struct kmem_cache_args *args,
slab_flags_t flags)
@@ -8885,6 +8884,8 @@ int do_kmem_cache_create(struct kmem_cache *s, const char *name,
*/
s->min_partial = min_t(unsigned long, MAX_PARTIAL, ilog2(s->size) / 2);
s->min_partial = max_t(unsigned long, MIN_PARTIAL, s->min_partial);
+ if (slab_tiny_enabled)
+ s->min_partial = 0;
s->cpu_sheaves = alloc_percpu(struct slub_percpu_sheaves);
if (!s->cpu_sheaves) {
|
| 3/2 | 2026/10/24 20:46 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 12467 output: 29 thoughts: 760 Thoughts: **My Assessment of the Proposed Patch** Okay, so this patch is digging deep into the slab allocator, specifically the SLUB implementation, which is a key part of memory management within the kernel. It seems to be focused on a new debug feature or configuration option, dubbed `SLAB_DEBUG_NOOP`, and tied to the `CONFIG_SLUB_TINY` configuration. Previously, `CONFIG_SLUB_TINY` was a compile-time directive, effectively creating different code paths via preprocessor directives. Now, the patch introduces runtime control via the `slab_tiny=` boot parameter, and also the `slab_debug=N` option, which sets `slab_tiny_enabled` at runtime. My initial impression is that this is more than just a minor refactoring. The patch's modifications are pretty extensive, touching core functions like `calculate_order`, `kmem_cache_flags`, `new_kmalloc_cache`, and `kmem_cache_init` across several crucial files: `mm/slub.c`, `mm/slab_common.c`, `mm/slab.h`, `include/linux/slab.h`, `mm/Kconfig`, and even `lib/Kconfig.kasan`. The fact that it's altering the conditions under which `kmem_cache_debug(s)` is called, replacing some `IS_ENABLED(CONFIG_SLUB_TINY)` checks with runtime checks against `slab_tiny_enabled`, is a significant shift. This new `SLAB_DEBUG_NOOP` flag is now included in `SLAB_DEBUG_FLAGS` and it is added to `kmem_cache_flags` when `slab_tiny_enabled` is set. I need to understand exactly what `kmem_cache_debug` is doing now in this context. Given the scope of the changes, this patch definitely falls under "Code refactorings that rearrange logic, introduce helper functions, or alter state management in core subsystems." which, as we know, means it's prime for fuzzing. Also, the patch targets "Memory Management (mm/)" which, again, is explicitly called out as worth fuzzing due to the potential for subtle semantic shifts and latent kernel bugs. The impact on slab caching, kmalloc, slow paths, order calculations, and sheaves is a red flag, because it touches fundamental memory allocation paths. Thankfully, SLUB is the default slab allocator on amd64 systems, so this code *is* reachable in standard virtualized environments. The introduction of the `slab_tiny` boot parameter and `slab_debug` parameter, combined with changes to how `CONFIG_SLUB_TINY` impacts code execution even when disabled, means we need to carefully test the different execution paths. It's not just the compile-time configuration anymore; runtime configuration via parameters and flags is critical. I'm going to double check all configs, symbols and details with a quick `grep` or reading the file, to verify all the new and the modified behaviors and parameters. This warrants a thorough investigation with fuzzing. |
| 4/2 | 2026/10/24 20:46 | tool | grepper |
0mArgs:{
"Expression": "kmem_cache_debug",
"PathPrefixes": [
"mm/"
]
}Results: {
"Output": "mm/slab.h=519=static inline void print_tracking(struct kmem_cache *s, void *object)\n--\nmm/slab.h-528- */\nmm/slab.h:529:static inline bool kmem_cache_debug_flags(struct kmem_cache *s, slab_flags_t flags)\nmm/slab.h-530-{\n--\nmm/slab.h=932=static inline bool slub_debug_orig_size(struct kmem_cache *s)\nmm/slab.h-933-{\nmm/slab.h:934:\treturn (kmem_cache_debug_flags(s, SLAB_STORE_USER) \u0026\u0026\nmm/slab.h-935-\t\t\t(s-\u003eflags \u0026 SLAB_KMALLOC));\n--\nmm/slub.c=231=struct slab_obj_iter {\n--\nmm/slub.c-240-\nmm/slub.c:241:static inline bool kmem_cache_debug(struct kmem_cache *s)\nmm/slub.c-242-{\nmm/slub.c:243:\treturn kmem_cache_debug_flags(s, SLAB_DEBUG_FLAGS);\nmm/slub.c-244-}\n--\nmm/slub.c=246=void *fixup_red_left(struct kmem_cache *s, void *p)\nmm/slub.c-247-{\nmm/slub.c:248:\tif (kmem_cache_debug_flags(s, SLAB_RED_ZONE))\nmm/slub.c-249-\t\tp += s-\u003ered_left_pad;\n--\nmm/slub.c=906=static unsigned int obj_exts_offset_in_object(struct kmem_cache *s)\n--\nmm/slub.c-909-\nmm/slub.c:910:\tif (kmem_cache_debug_flags(s, SLAB_STORE_USER))\nmm/slub.c-911-\t\toffset += sizeof(struct track) * 2;\n--\nmm/slub.c=1754=static void setup_object_debug(struct kmem_cache *s, void *object)\nmm/slub.c-1755-{\nmm/slub.c:1756:\tif (!kmem_cache_debug_flags(s, SLAB_STORE_USER|SLAB_RED_ZONE|__OBJECT_POISON))\nmm/slub.c-1757-\t\treturn;\n--\nmm/slub.c=1764=void setup_slab_debug(struct kmem_cache *s, struct slab *slab, void *addr)\nmm/slub.c-1765-{\nmm/slub.c:1766:\tif (!kmem_cache_debug_flags(s, SLAB_POISON))\nmm/slub.c-1767-\t\treturn;\n--\nmm/slub.c=3594=static void free_slab(struct kmem_cache *s, struct slab *slab)\nmm/slub.c-3595-{\nmm/slub.c:3596:\tif (kmem_cache_debug_flags(s, SLAB_CONSISTENCY_CHECKS)) {\nmm/slub.c-3597-\t\tvoid *p;\n--\nmm/slub.c=3665=static inline void remove_partial(struct kmem_cache_node *n,\n--\nmm/slub.c-3673-/*\nmm/slub.c:3674: * Called only for kmem_cache_debug() caches instead of remove_partial(), with a\nmm/slub.c-3675- * slab from the n-\u003epartial list. Remove only a single object from the slab, do\n--\nmm/slub.c=3763=static inline void init_slab_obj_iter(struct kmem_cache *s, struct slab *slab,\n--\nmm/slub.c-3794-/*\nmm/slub.c:3795: * Called only for kmem_cache_debug() caches to allocate from a freshly\nmm/slub.c-3796- * allocated slab. Allocate a single object instead of whole freelist\n--\nmm/slub.c=3930=static void *get_from_partial_node(struct kmem_cache *s,\n--\nmm/slub.c-3958-\nmm/slub.c:3959:\t\tif (kmem_cache_debug(s)) {\nmm/slub.c-3960-\t\t\tobject = alloc_single_from_partial(s, n, slab,\n--\nmm/slub.c=4578=static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node,\n--\nmm/slub.c-4626-\nmm/slub.c:4627:\tif (kmem_cache_debug(s)) {\nmm/slub.c-4628-\t\tobject = alloc_single_from_new_slab(s, slab, ac);\n--\nmm/slub.c-4644-success:\nmm/slub.c:4645:\tif (kmem_cache_debug_flags(s, SLAB_STORE_USER))\nmm/slub.c-4646-\t\tset_track(s, object, TRACK_ALLOC, ac-\u003ecaller_addr, gfpflags);\n--\nmm/slub.c=5569=static void *__kmalloc_nolock_noprof(DECL_TOKEN_PARAMS(size, token), gfp_t gfp_flags,\n--\nmm/slub.c-5596-\nmm/slub.c:5597:\tif (!(s-\u003eflags \u0026 __CMPXCHG_DOUBLE) \u0026\u0026 !kmem_cache_debug(s))\nmm/slub.c-5598-\t\t/*\n--\nmm/slub.c=5845=static void __slab_free(struct kmem_cache *s, struct slab *slab,\n--\nmm/slub.c-5855-\nmm/slub.c:5856:\tif (kmem_cache_debug(s)) {\nmm/slub.c-5857-\t\tfree_to_partial_list(s, slab, head, tail, cnt, addr);\n--\nmm/slub.c=6745=void kmem_cache_free(struct kmem_cache *s, void *x)\n--\nmm/slub.c-6751-\tif (IS_ENABLED(CONFIG_SLAB_FREELIST_HARDENED) ||\nmm/slub.c:6752:\t kmem_cache_debug_flags(s, SLAB_CONSISTENCY_CHECKS)) {\nmm/slub.c-6753-\n--\nmm/slub.c=7563=static bool __kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags,\n--\nmm/slub.c-7567-\nmm/slub.c:7568:\tif (kmem_cache_debug(s)) {\nmm/slub.c-7569-\t\tconst struct slab_alloc_context ac = {\n--\nmm/slub.c=8411=void __check_heap_object(const void *ptr, unsigned long n,\n--\nmm/slub.c-8434-\t/* Adjust for redzone and reject if within the redzone. */\nmm/slub.c:8435:\tif (!is_kfence \u0026\u0026 kmem_cache_debug_flags(s, SLAB_RED_ZONE)) {\nmm/slub.c-8436-\t\tif (offset \u003c s-\u003ered_left_pad)\n--\nmm/slub.c=9508=static ssize_t validate_store(struct kmem_cache *s,\n--\nmm/slub.c-9512-\nmm/slub.c:9513:\tif (buf[0] == '1' \u0026\u0026 kmem_cache_debug(s)) {\nmm/slub.c-9514-\t\tret = validate_slab_cache(s);\n"
} |
| 5/2 | 2026/10/24 20:46 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 15972 output: 33 thoughts: 19 Thoughts: Here's a summary of my thought process, as requested: **Diving into `mm/slab.h`** Okay, let's zero in on `mm/slab.h` around line 529. My initial thought is that this area likely deals with a crucial aspect of the slab allocator. Considering the location, it's probably related to some fundamental slab management function, perhaps memory allocation, deallocation, or object tracking within the slabs themselves. I need to refresh my memory, this is a part of the kernel memory management that is of great interest. |
| 6/2 | 2026/10/24 20:46 | tool | read-file |
0mArgs:{
"File": "mm/slab.h",
"FirstLine": 520,
"LineCount": 35
}Results: {
"Contents": " 520:\t{\n 521:\t}\n 522:\t#endif\n 523:\t\n 524:\t/*\n 525:\t * Returns true if any of the specified slab_debug flags is enabled for the\n 526:\t * cache. Use only for flags parsed by setup_slub_debug() as it also enables\n 527:\t * the static key.\n 528:\t */\n 529:\tstatic inline bool kmem_cache_debug_flags(struct kmem_cache *s, slab_flags_t flags)\n 530:\t{\n 531:\t\tif (IS_ENABLED(CONFIG_SLUB_DEBUG))\n 532:\t\t\tVM_WARN_ON_ONCE(!(flags \u0026 SLAB_DEBUG_FLAGS));\n 533:\t\tif (__slub_debug_enabled())\n 534:\t\t\treturn s-\u003eflags \u0026 flags;\n 535:\t\treturn false;\n 536:\t}\n 537:\t\n 538:\t#if IS_ENABLED(CONFIG_SLUB_DEBUG) \u0026\u0026 IS_ENABLED(CONFIG_KUNIT)\n 539:\tbool slab_in_kunit_test(void);\n 540:\t#else\n 541:\tstatic inline bool slab_in_kunit_test(void) { return false; }\n 542:\t#endif\n 543:\t\n 544:\t/*\n 545:\t * slub is about to manipulate internal object metadata. This memory lies\n 546:\t * outside the range of the allocated object, so accessing it would normally\n 547:\t * be reported by kasan as a bounds error. metadata_access_enable() is used\n 548:\t * to tell kasan that these accesses are OK.\n 549:\t */\n 550:\tstatic inline void metadata_access_enable(void)\n 551:\t{\n 552:\t\tkasan_disable_current();\n 553:\t\tkmsan_disable_current();\n 554:\t}\n"
} |
| 7/2 | 2026/10/24 20:46 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 16676 output: 35 thoughts: 1267 Thoughts: **Analyzing the SLUB Patch: A Deep Dive** Okay, let's break this patch down from a memory management perspective. My initial thought is this looks interesting and definitely warrants a closer look. It seems like the core changes revolve around enabling a "tiny" SLUB variant via the runtime boot parameter `slab_tiny`, effectively transitioning `SLUB_TINY` from a compile-time only option. This also introduces `SLAB_DEBUG_NOOP`, controlled by `slab_debug=N` or `slab_tiny=1`. The impact is significant. Enabling `slab_tiny` or `SLAB_DEBUG_NOOP` triggers a cascade of effects: debug slowpaths for allocation and deallocation are enabled. This means we'll be hitting `alloc_single_from_partial`, `alloc_single_from_new_slab`, `free_to_partial_list`, and single allocation in `__kmem_cache_alloc_bulk()`. Sheaf calculation is disabled, `min_partial` is set to zero, kmalloc reclaim caches are merged, and `slab_max_order` is restricted to 1. This is essentially going to change the entire SLUB allocation pathway, making this absolutely an area worth fuzzing. The patch also modifies the order parameters, replacing callbacks with parameters. It also unlocks a variety of Kconfig options that were previously dependent on `!SLUB_TINY`. This opens up even more attack surface. My primary concern, however, is reachability and exploitability. This change directly touches the core memory management subsystem (mm/slub.c, mm/slab_common.c, mm/slab.h), which is critical. Considering that the change affects allocation paths, and state management, this is definitely reachable in standard virtualized environments. Next, I need to pinpoint the relevant configurations and symbols carefully. `CONFIG_SLUB` seems standard, but `CONFIG_SLUB_DEBUG` is the key. I see a reference to `kmem_cache_debug_flags` and `__slub_debug_enabled()`. My initial thought is: * If `CONFIG_SLUB_DEBUG` is not enabled, the code path is different. Checking the Kconfig entry reveals that `CONFIG_SLUB_DEBUG` defaults to `y`, but the check on `__slub_debug_enabled()` happens, regardless. * This means the kernel can have a default of `CONFIG_SLUB_DEBUG`, but debug can still be toggled off at run time. It's clear that `mm/slab.h` and `mm/slub.c` are where the action is. I need to now examine those files for how `CONFIG_SLUB_DEBUG` is used (or not) to see how it might impact the patch's changes when it's disabled. |
| 8/2 | 2026/10/24 20:47 | tool | grepper |
0mArgs:{
"Expression": "#ifdef CONFIG_SLUB_DEBUG",
"PathPrefixes": [
"mm/slub.c"
]
}Results: {
"Output": "mm/slub.c=476=struct kmem_cache_node {\n--\nmm/slub.c-479-\tstruct list_head partial;\nmm/slub.c:480:#ifdef CONFIG_SLUB_DEBUG\nmm/slub.c-481-\tatomic_long_t nr_slabs;\n--\nmm/slub.c=946=static inline void slab_attach_kprobe_locked(void) { }\n--\nmm/slub.c-953-\nmm/slub.c:954:#ifdef CONFIG_SLUB_DEBUG\nmm/slub.c-955-\n--\nmm/slub.c=3679=static void *alloc_single_from_partial(struct kmem_cache *s,\n--\nmm/slub.c-3685-\nmm/slub.c:3686:#ifdef CONFIG_SLUB_DEBUG\nmm/slub.c-3687-\tif (s-\u003eflags \u0026 SLAB_CONSISTENCY_CHECKS) {\n--\nmm/slub.c=4294=static int slub_cpu_dead(unsigned int cpu)\n--\nmm/slub.c-4306-\nmm/slub.c:4307:#ifdef CONFIG_SLUB_DEBUG\nmm/slub.c-4308-static int count_free(struct slab *slab)\n--\nmm/slub.c=4378=static unsigned long count_partial(struct kmem_cache_node *n,\n--\nmm/slub.c-4392-\nmm/slub.c:4393:#ifdef CONFIG_SLUB_DEBUG\nmm/slub.c-4394-#define MAX_PARTIAL_TO_SCAN 10000\n--\nmm/slub.c=6769=static inline size_t slab_ksize(struct slab *slab)\n--\nmm/slub.c-6772-\nmm/slub.c:6773:#ifdef CONFIG_SLUB_DEBUG\nmm/slub.c-6774-\t/*\n--\nmm/slub.c=6798=static size_t __ksize(const void *object)\n--\nmm/slub.c-6815-\nmm/slub.c:6816:#ifdef CONFIG_SLUB_DEBUG\nmm/slub.c-6817-\tskip_orig_size_check(slab-\u003eslab_cache, object);\n--\nmm/slub.c=7815=init_kmem_cache_node(struct kmem_cache_node *n)\n--\nmm/slub.c-7819-\tINIT_LIST_HEAD(\u0026n-\u003epartial);\nmm/slub.c:7820:#ifdef CONFIG_SLUB_DEBUG\nmm/slub.c-7821-\tatomic_long_set(\u0026n-\u003enr_slabs, 0);\n--\nmm/slub.c=7896=static void early_kmem_cache_node_alloc(int node)\n--\nmm/slub.c-7920-\nmm/slub.c:7921:#ifdef CONFIG_SLUB_DEBUG\nmm/slub.c-7922-\tinit_object(kmem_cache_node, n, SLUB_RED_ACTIVE);\n--\nmm/slub.c=8059=static int calculate_sizes(struct kmem_cache_args *args, struct kmem_cache *s)\n--\nmm/slub.c-8072-\nmm/slub.c:8073:#ifdef CONFIG_SLUB_DEBUG\nmm/slub.c-8074-\t/*\n--\nmm/slub.c-8135-\nmm/slub.c:8136:#ifdef CONFIG_SLUB_DEBUG\nmm/slub.c-8137-\tif (flags \u0026 SLAB_STORE_USER) {\n--\nmm/slub.c-8150-\tkasan_cache_create(s, \u0026size, \u0026s-\u003eflags);\nmm/slub.c:8151:#ifdef CONFIG_SLUB_DEBUG\nmm/slub.c-8152-\tif (flags \u0026 SLAB_RED_ZONE) {\n--\nmm/slub.c=8215=static void list_slab_objects(struct kmem_cache *s, struct slab *slab)\nmm/slub.c-8216-{\nmm/slub.c:8217:#ifdef CONFIG_SLUB_DEBUG\nmm/slub.c-8218-\tvoid *addr = slab_address(slab);\n--\nmm/slub.c=8310=void __kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct slab *slab)\n--\nmm/slub.c-8324-\tobjp0 = kasan_reset_tag(object);\nmm/slub.c:8325:#ifdef CONFIG_SLUB_DEBUG\nmm/slub.c-8326-\tobjp = restore_red_left(s, objp0);\n--\nmm/slub.c-8337-\t\treturn;\nmm/slub.c:8338:#ifdef CONFIG_SLUB_DEBUG\nmm/slub.c-8339-\tobjp = fixup_red_left(s, objp);\n--\nmm/slub.c=8647=static struct kmem_cache * __init bootstrap(struct kmem_cache *static_cache)\n--\nmm/slub.c-8660-\nmm/slub.c:8661:#ifdef CONFIG_SLUB_DEBUG\nmm/slub.c-8662-\t\tlist_for_each_entry(p, \u0026n-\u003efull, slab_list)\n--\nmm/slub.c=8946=static int count_total(struct slab *slab)\n--\nmm/slub.c-8951-\nmm/slub.c:8952:#ifdef CONFIG_SLUB_DEBUG\nmm/slub.c-8953-static void validate_slab(struct kmem_cache *s, struct slab *slab,\n--\nmm/slub.c=9216=static ssize_t show_slab_objects(struct kmem_cache *s,\n--\nmm/slub.c-9239-\nmm/slub.c:9240:#ifdef CONFIG_SLUB_DEBUG\nmm/slub.c-9241-\tif (flags \u0026 SO_ALL) {\n--\nmm/slub.c=9449=SLAB_ATTR_RO(destroy_by_rcu);\nmm/slub.c-9450-\nmm/slub.c:9451:#ifdef CONFIG_SLUB_DEBUG\nmm/slub.c-9452-static ssize_t slabs_show(struct kmem_cache *s, char *buf)\n--\nmm/slub.c=9672=static const struct attribute *const slab_attrs[] = {\n--\nmm/slub.c-9690-\t\u0026slabs_cpu_partial_attr.attr,\nmm/slub.c:9691:#ifdef CONFIG_SLUB_DEBUG\nmm/slub.c-9692-\t\u0026total_objects_attr.attr,\n--\nmm/slub.c=10185=static void __init slab_debugfs_root_init(void)\n--\nmm/slub.c-10192- */\nmm/slub.c:10193:#ifdef CONFIG_SLUB_DEBUG\nmm/slub.c-10194-void get_slabinfo(struct kmem_cache *s, struct slabinfo *sinfo)\n"
} |
| 9/2 | 2026/10/24 20:47 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 20512 output: 35 thoughts: 29 Thoughts: Okay, let's dive into this. Here's my take on those thoughts: **Dissecting `mm/slub.c` at the `#else` Point** Alright, so I'm thinking about line 2065 in `mm/slub.c`. I need to pinpoint the section where the `#else` block resides. Itβs always a good starting point to revisit these conditional branches when you're tracking down tricky memory allocation behavior. I'm focusing on that `#else` specifically because it likely represents the alternative code path, often a critical point for understanding how the system handles scenarios outside the typical allocation flow, or where error handling or fallback mechanisms kick in. Knowing *why* that `#else` exists, and what the code does within it, gives me a stronger grasp on the broader allocation design. Iβm expecting that's where something interesting is, and I want to refresh my memory on the implementation details around that. I am anticipating I can quickly identify the code segment to analyze further. |
| 10/2 | 2026/10/24 20:47 | tool | read-file |
0mArgs:{
"File": "mm/slub.c",
"FirstLine": 2065,
"LineCount": 40
}Results: {
"Contents": "2065:\t\t\t}\n2066:\t\t}\n2067:\t\n2068:\t\treturn flags | slub_debug_local;\n2069:\t}\n2070:\t#else /* !CONFIG_SLUB_DEBUG */\n2071:\tstatic inline void setup_object_debug(struct kmem_cache *s, void *object) {}\n2072:\tstatic inline\n2073:\tvoid setup_slab_debug(struct kmem_cache *s, struct slab *slab, void *addr) {}\n2074:\t\n2075:\tstatic inline bool __init slab_want_nohash_pointers(void) { return false; }\n2076:\t\n2077:\tstatic inline bool alloc_debug_processing(struct kmem_cache *s,\n2078:\t\tstruct slab *slab, void *object, int orig_size) { return true; }\n2079:\t\n2080:\tstatic inline bool free_debug_processing(struct kmem_cache *s,\n2081:\t\tstruct slab *slab, void *head, void *tail, int *bulk_cnt,\n2082:\t\tunsigned long addr, depot_stack_handle_t handle) { return true; }\n2083:\t\n2084:\tstatic inline void slab_pad_check(struct kmem_cache *s, struct slab *slab) {}\n2085:\tstatic inline int check_object(struct kmem_cache *s, struct slab *slab,\n2086:\t\t\t\tvoid *object, u8 val) { return 1; }\n2087:\tstatic inline depot_stack_handle_t set_track_prepare(gfp_t gfp_flags) { return 0; }\n2088:\tstatic inline void set_track(struct kmem_cache *s, void *object,\n2089:\t\t\t\t enum track_item alloc, unsigned long addr, gfp_t gfp_flags) {}\n2090:\tstatic inline void add_full(struct kmem_cache *s, struct kmem_cache_node *n,\n2091:\t\t\t\t\t\tstruct slab *slab) {}\n2092:\tstatic inline void remove_full(struct kmem_cache *s, struct kmem_cache_node *n,\n2093:\t\t\t\t\t\tstruct slab *slab) {}\n2094:\tslab_flags_t kmem_cache_flags(slab_flags_t flags, const char *name)\n2095:\t{\n2096:\t\tif (slab_tiny_enabled)\n2097:\t\t\tflags |= SLAB_DEBUG_NOOP;\n2098:\t\n2099:\t\treturn flags;\n2100:\t}\n2101:\t#define slub_debug 0\n2102:\t\n2103:\t#define disable_higher_order_debug 0\n2104:\t\n"
} |
| 11/2 | 2026/10/24 20:47 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 21524 output: 54 thoughts: 1978 Thoughts: **SLUB Refactoring and Feature Enhancement Analysis** Alright, let's break this down. It seems we have a significant refactoring and enhancement of the SLUB memory allocator on our hands. The code touches core memory management code, specifically `mm/slub.c` and `mm/slab_common.c`. The initial observation is that the code surrounding `kmem_cache_flags()` has been restructured, placing the `SLAB_DEBUG_NOOP` flag setting within both the `#ifdef CONFIG_SLUB_DEBUG` and `#else` blocks. This ensures the debug no-op behavior is applied consistently. Furthermore, `DEFINE_STATIC_KEY_MAYBE(CONFIG_SLUB_DEBUG_ON, slub_debug_enabled);` is now outside the conditional, which makes sense for the overall design. `kmem_cache_init()` now enables `slub_debug_enabled` if `slab_tiny_enabled`, solidifying the dependency. This also changes behavior of `calculate_sheaf_capacity` and `do_kmem_cache_create` based on `slab_tiny_enabled`. It also affects how `new_kmalloc_cache` handles `KMALLOC_RECLAIM` and `KMALLOC_NORMAL` caches, and introduces new `SLAB_NO_MERGE` and `SLAB_MAY_ACCOUNT` flags in certain scenarios. There's also a new `early_slab_tiny` function using `early_param` to control `slab_tiny_enabled` via a boot parameter. The `parse_slub_debug_flags` function supports the 'n' flag, and `setup_slub_debug` is now used to set up debugging behavior and applies flags. `slab_want_nohash_pointers` is now also updated to properly take into account debug flags. So, this is a clear refactoring and feature enhancement. The `WorthFuzzing` flag is set to true, as it should be. Now, let's think about the fuzzing setup. First, the relevant kernel config flags: we need `CONFIG_SLUB` (or `SLUB`) for the SLUB allocator, naturally. Then, we have `CONFIG_SLUB_DEBUG` for debug options (e.g., `SLAB_DEBUG_NOOP`) and finally `CONFIG_SLUB_TINY`. Importantly, `SLUB_TINY` is enabled by default in the kernel config! We should test this configuration. We know `SLUB_DEBUG` depends on `SYSFS`, so make sure we include this. Next, the critical part: focusing our fuzzing effort. We need to identify relevant symbols to include. We need to avoid ubiquitous functions, which are the allocators themselves. We can see the function `new_kmalloc_cache` has been modified, which is a good candidate for focusing the fuzzing. The other key functions, I think, are: `alloc_single_from_partial`, `alloc_single_from_new_slab`, `free_to_partial_list`, `kmem_cache_flags`, `calculate_sheaf_capacity`, `parse_slub_debug_flags`, `setup_slub_debug`, `do_kmem_cache_create`, and `__kmem_cache_alloc_bulk`. They all seem specific to this refactoring or related functionality, making them better targets for fuzzing. It would also be a good idea to ensure we target both the `early_slab_tiny` and the `kmem_cache_init`. |
| 12/2 | 2026/10/24 20:47 | tool | grepper |
0mArgs:{
"Expression": "(alloc_single_from_partial|alloc_single_from_new_slab|free_to_partial_list)",
"PathPrefixes": [
"mm/slub.c"
]
}Results: {
"Output": "mm/slub.c=3665=static inline void remove_partial(struct kmem_cache_node *n,\n--\nmm/slub.c-3678- */\nmm/slub.c:3679:static void *alloc_single_from_partial(struct kmem_cache *s,\nmm/slub.c-3680-\t\tstruct kmem_cache_node *n, struct slab *slab, int orig_size)\n--\nmm/slub.c=3763=static inline void init_slab_obj_iter(struct kmem_cache *s, struct slab *slab,\n--\nmm/slub.c-3798- */\nmm/slub.c:3799:static void *alloc_single_from_new_slab(struct kmem_cache *s, struct slab *slab,\nmm/slub.c-3800-\t\t\t\t\tconst struct slab_alloc_context *ac)\n--\nmm/slub.c=3930=static void *get_from_partial_node(struct kmem_cache *s,\n--\nmm/slub.c-3959-\t\tif (kmem_cache_debug(s)) {\nmm/slub.c:3960:\t\t\tobject = alloc_single_from_partial(s, n, slab,\nmm/slub.c-3961-\t\t\t\t\t\t\tac-\u003eorig_size);\n--\nmm/slub.c=4578=static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node,\n--\nmm/slub.c-4627-\tif (kmem_cache_debug(s)) {\nmm/slub.c:4628:\t\tobject = alloc_single_from_new_slab(s, slab, ac);\nmm/slub.c-4629-\n--\nmm/slub.c=5717=void *__kmalloc_flags_noprof(DECL_TOKEN_PARAMS(size, token), gfp_t flags,\n--\nmm/slub.c-5735-\nmm/slub.c:5736:static noinline void free_to_partial_list(\nmm/slub.c-5737-\tstruct kmem_cache *s, struct slab *slab,\n--\nmm/slub.c=5845=static void __slab_free(struct kmem_cache *s, struct slab *slab,\n--\nmm/slub.c-5856-\tif (kmem_cache_debug(s)) {\nmm/slub.c:5857:\t\tfree_to_partial_list(s, slab, head, tail, cnt, addr);\nmm/slub.c-5858-\t\treturn;\n"
} |
| 13/2 | 2026/10/24 20:47 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 25007 output: 35 thoughts: 52 Thoughts: Here's my take on this β a distilled thought process as if I'm the one thinking it: **Digging into Memory Allocation** Okay, so `free_to_partial_list` is definitely defined as a `static noinline void` function. That's a good starting point. Now, to understand how this function fits into the bigger picture, I need to see how it's actually used. My next thought is to jump directly to the implementations of `alloc_single_from_partial` and `alloc_single_from_new_slab` functions. I want to see where they're being called and how. That will likely illuminate the flow of memory allocation and deallocation within this section of code. Getting a solid grasp of those interactions will definitely provide insights into the overall memory management strategy here. Let's see what those functions reveal! |
| 14/2 | 2026/10/24 20:47 | tool | read-file |
0mArgs:{
"File": "mm/slub.c",
"FirstLine": 3675,
"LineCount": 25
}Results: {
"Contents": "3675:\t * slab from the n-\u003epartial list. Remove only a single object from the slab, do\n3676:\t * the alloc_debug_processing() checks and leave the slab on the list, or move\n3677:\t * it to full list if it was the last free object.\n3678:\t */\n3679:\tstatic void *alloc_single_from_partial(struct kmem_cache *s,\n3680:\t\t\tstruct kmem_cache_node *n, struct slab *slab, int orig_size)\n3681:\t{\n3682:\t\tvoid *object;\n3683:\t\n3684:\t\tslab_lockdep_assert_held(\u0026n-\u003elist_lock);\n3685:\t\n3686:\t#ifdef CONFIG_SLUB_DEBUG\n3687:\t\tif (s-\u003eflags \u0026 SLAB_CONSISTENCY_CHECKS) {\n3688:\t\t\tif (!validate_slab_ptr(slab)) {\n3689:\t\t\t\tslab_err(s, slab, \"Not a valid slab page\");\n3690:\t\t\t\treturn NULL;\n3691:\t\t\t}\n3692:\t\t}\n3693:\t#endif\n3694:\t\n3695:\t\tobject = slab-\u003efreelist;\n3696:\t\tslab-\u003efreelist = get_freepointer(s, object);\n3697:\t\tslab-\u003einuse++;\n3698:\t\n3699:\t\tif (!alloc_debug_processing(s, slab, object, orig_size)) {\n"
} |
| 15/2 | 2026/10/24 20:47 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 25678 output: 35 thoughts: 15 Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience, and delivered as a first-person summary: **Diving into `alloc_single_from_new_slab`** Alright, let's dissect this. My primary focus right now is on the `alloc_single_from_new_slab` function. I need to understand its role within the broader allocation strategy, particularly in the context of our slab allocator. I'm immediately thinking about the implications of allocating from a *new* slab. This inherently suggests there wasn't a pre-existing free block available. So, what triggers this path? Is it due to slab exhaustion in the relevant cache? Or perhaps an initial allocation call? I'm already envisioning the potential overhead here β the cost of creating a new slab, initializing it, and then pulling a single object. How well does it handle concurrent access? And what's the typical size distribution we're dealing with that dictates when this becomes the favored approach? I'm also curious to see how the function integrates with our metadata structures β how do we track the slab's state, the newly allocated object's location within it, and any necessary cache updates? Let me see how it does things. It's the allocation part that I will focus on. |
| 16/2 | 2026/10/24 20:47 | tool | read-file |
0mArgs:{
"File": "mm/slub.c",
"FirstLine": 3795,
"LineCount": 25
}Results: {
"Contents": "3795:\t * Called only for kmem_cache_debug() caches to allocate from a freshly\n3796:\t * allocated slab. Allocate a single object instead of whole freelist\n3797:\t * and put the slab to the partial (or full) list.\n3798:\t */\n3799:\tstatic void *alloc_single_from_new_slab(struct kmem_cache *s, struct slab *slab,\n3800:\t\t\t\t\t\tconst struct slab_alloc_context *ac)\n3801:\t{\n3802:\t\tbool allow_spin = alloc_flags_allow_spinning(ac-\u003ealloc_flags);\n3803:\t\tstruct kmem_cache_node *n;\n3804:\t\tstruct slab_obj_iter iter;\n3805:\t\tbool needs_add_partial;\n3806:\t\tunsigned long flags;\n3807:\t\tvoid *object;\n3808:\t\n3809:\t\tinit_slab_obj_iter(s, slab, \u0026iter, allow_spin);\n3810:\t\tobject = next_slab_obj(s, \u0026iter);\n3811:\t\tslab-\u003einuse = 1;\n3812:\t\n3813:\t\tneeds_add_partial = (slab-\u003eobjects \u003e 1);\n3814:\t\tbuild_slab_freelist(s, slab, \u0026iter);\n3815:\t\n3816:\t\t/* alloc_debug_processing() always expects a valid freepointer */\n3817:\t\tset_freepointer(s, object, slab-\u003efreelist);\n3818:\t\n3819:\t\tif (!alloc_debug_processing(s, slab, object, ac-\u003eorig_size)) {\n"
} |
| 17/2 | 2026/10/24 20:47 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 26442 output: 34 thoughts: 446 Thoughts: **Analyzing Allocation and Freeing Paths in the Kernel's SLUB Subsystem** Okay, so I'm looking at these functions: `alloc_single_from_partial`, `alloc_single_from_new_slab`, and `free_to_partial_list`. These are clearly crucial. They're explicitly the single-object allocation and freeing routines, specifically for debug caches and tiny caches, which is interesting. But wait, if `slab_tiny_enabled` is true, *every* cache effectively becomes a debug noop cache (`SLAB_DEBUG_NOOP`). This means *all* allocations and frees now funnel through those three functions. That's a huge shift in the allocation path. So, if `slab_tiny_enabled` is on, would highlighting these functions actually dilute the core issue? Thinking about how syzkaller operates, it usually runs with a standard kernel configuration or potentially modified ones. Under a standard syzkaller setup, unless `slab_tiny` is explicitly enabled through boot parameters or config options, these functions are *only* exercised by debug caches or if someone has manually enabled `slab_debug=N` or `slab_tiny`. However, what about `SLUB_TINY`? But regardless, these functions are the ones that were changed to handle `kmem_cache_debug(s)` where `IS_ENABLED(CONFIG_SLUB_TINY)` was removed and unified into `kmem_cache_debug(s)`! Let me broaden the scope. I should also check these other functions that were modified in this diff: `kmem_cache_flags`, `new_kmalloc_cache`, `calculate_sheaf_capacity`, `do_kmem_cache_create`, `setup_slub_debug`, `parse_slub_debug_flags`, and `__kmem_cache_alloc_bulk`. They are all related to cache creation, debugging, or allocation, so they are all relevant to this investigation. Let me take a closer look at `kmem_cache_flags`. I need to figure out if it's a critical symbol in the vmlinux and see where it's declared and defined. |
| 18/2 | 2026/10/24 20:47 | tool | grepper |
0mArgs:{
"Expression": "kmem_cache_flags",
"PathPrefixes": [
"mm/",
"include/"
]
}Results: {
"Output": "mm/slab.h=451=bool slab_args_unmergeable(struct kmem_cache_args *args, slab_flags_t flags);\nmm/slab.h-452-\nmm/slab.h:453:slab_flags_t kmem_cache_flags(slab_flags_t flags, const char *name);\nmm/slab.h-454-\n--\nmm/slab_common.c=194=static struct kmem_cache *find_mergeable(unsigned int size, slab_flags_t flags,\n--\nmm/slab_common.c-199-\nmm/slab_common.c:200:\tflags = kmem_cache_flags(flags, name);\nmm/slab_common.c-201-\tif (slab_args_unmergeable(args, flags))\n--\nmm/slub.c=2001=__core_param_cb(slub_debug, \u0026param_ops_slab_debug, NULL, 0);\n--\nmm/slub.c-2003-/*\nmm/slub.c:2004: * kmem_cache_flags - apply debugging options to the cache\nmm/slub.c-2005- * @flags:\t\tflags to set\n--\nmm/slub.c-2012- */\nmm/slub.c:2013:slab_flags_t kmem_cache_flags(slab_flags_t flags, const char *name)\nmm/slub.c-2014-{\n--\nmm/slub.c=2092=static inline void remove_full(struct kmem_cache *s, struct kmem_cache_node *n,\nmm/slub.c-2093-\t\t\t\t\tstruct slab *slab) {}\nmm/slub.c:2094:slab_flags_t kmem_cache_flags(slab_flags_t flags, const char *name)\nmm/slub.c-2095-{\n--\nmm/slub.c=8839=int do_kmem_cache_create(struct kmem_cache *s, const char *name,\n--\nmm/slub.c-8847-\nmm/slub.c:8848:\ts-\u003eflags = kmem_cache_flags(flags, s-\u003ename);\nmm/slub.c-8849-#ifdef CONFIG_SLAB_FREELIST_HARDENED\n"
} |
| 19/2 | 2026/10/24 20:47 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 27990 output: 31 thoughts: 59 Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience: **Internal Symbol Insights** Alright, let's break this down. My initial thought process revolves around the relationship between the `mm` subsystem and its allocation mechanisms. I've noted that `kmem_cache_flags` is an exported *internal* symbol. The fact that it's declared in `mm/slab.h`, but defined in `mm/slub.c`, is key. This strongly suggests it's a critical flag or set of flags, specifically related to the SLUB allocator. Exporting it, even as internal, means it's likely used by other parts of the memory management system, maybe even kernel modules, for configuration, introspection, or manipulation of `kmem_cache` objects. Simultaneously seeing that `do_kmem_cache_create` also resides within `mm/slub.c` reinforces the importance of SLUB. This function is the workhorse for creating new `kmem_cache` instances, so the connection is highly significant. If I needed to understand the setup or initialization of the SLUB allocator, or if I was debugging memory allocation issues, this is the prime area I would investigate. The linkage between the flags and creation function implies a level of control over the allocated memory blocks at creation time. I immediately start thinking about the implications for memory alignment, page coloring, object attributes, etc. within the SLUB allocator based on those flags! This is a pivotal point to study. |
| 20/2 | 2026/10/24 20:47 | tool | grepper |
0mArgs:{
"Expression": "do_kmem_cache_create",
"PathPrefixes": [
"mm/"
]
}Results: {
"Output": "mm/slab.h=438=gfp_t kmalloc_fix_flags(gfp_t flags);\n--\nmm/slab.h-440-/* Functions provided by the slab allocators */\nmm/slab.h:441:int do_kmem_cache_create(struct kmem_cache *s, const char *name,\nmm/slab.h-442-\t\t\t unsigned int size, struct kmem_cache_args *args,\n--\nmm/slab_common.c=232=static struct kmem_cache *create_cache(const char *name,\n--\nmm/slab_common.c-251-\t\tgoto out;\nmm/slab_common.c:252:\terr = do_kmem_cache_create(s, name, object_size, args, flags);\nmm/slab_common.c-253-\tif (err)\n--\nmm/slab_common.c=711=void __init create_boot_cache(struct kmem_cache *s, const char *name,\n--\nmm/slab_common.c-732-\nmm/slab_common.c:733:\terr = do_kmem_cache_create(s, name, size, \u0026kmem_args, flags);\nmm/slab_common.c-734-\n--\nmm/slub.c=8837=early_param(\"slab_tiny\", early_slab_tiny);\nmm/slub.c-8838-\nmm/slub.c:8839:int do_kmem_cache_create(struct kmem_cache *s, const char *name,\nmm/slub.c-8840-\t\t\t unsigned int size, struct kmem_cache_args *args,\n"
} |
| 21/2 | 2026/10/24 20:47 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 28836 output: 29 thoughts: 12 Thoughts: Okay, here's my interpretation of that thought process, tailored for an expert audience, and rendered in the first person: **Analyzing `calculate_sheaf_capacity`** Alright, let's dive into this `calculate_sheaf_capacity` function, shall we? My immediate thought is, "Okay, what's the context here? What kind of sheaf are we talking about? Is it a locally free sheaf, a torsion sheaf, something more general?" Without that context, a function name like that is...well, it could mean anything. My mind's already racing through the possible algorithms. Are we dealing with a discrete sheaf on a finite set, or something more complex like a coherent sheaf on a scheme? The computational approach will vary dramatically depending on the input. I need to quickly assess the method. The name itself suggests we're computing some kind of "capacity," which, for a sheaf, often relates to its sections, or perhaps its rank at various points, or even the growth rate of its cohomology. We might be looking at a global section bound, a local rank estimate, or something else entirely. I need to quickly remember the assumptions and definitions involved. Does this function have a dependency on a particular structure? Is it using some kind of grid? Perhaps a cohomology calculator? Or is it calculating capacities based on sections that must be found first? What is being assumed as input? More specifically, is this relating to a projective module, or something else? Is there a need to apply Grothendieck's theorem to this? Alright, let's dig into the details. I need to understand the underlying computational structure. Is it efficient? Is it using optimal algorithms, or is it a naive approach? Are there potential bottlenecks, and if so, where? Are we going to need to look at approximations, or are we hoping for exact results? |
| 22/2 | 2026/10/24 20:47 | tool | grepper |
0mArgs:{
"Expression": "calculate_sheaf_capacity",
"PathPrefixes": [
"mm/"
]
}Results: {
"Output": "mm/slub.c=7969=static int init_kmem_cache_nodes(struct kmem_cache *s)\n--\nmm/slub.c-8007-\nmm/slub.c:8008:static unsigned int calculate_sheaf_capacity(struct kmem_cache *s,\nmm/slub.c-8009-\t\t\t\t\t struct kmem_cache_args *args)\n--\nmm/slub.c=8059=static int calculate_sizes(struct kmem_cache_args *args, struct kmem_cache *s)\n--\nmm/slub.c-8203-\tif (!is_kmalloc_cache(s))\nmm/slub.c:8204:\t\ts-\u003esheaf_capacity = calculate_sheaf_capacity(s, args);\nmm/slub.c-8205-\n--\nmm/slub.c=8675=static void __init bootstrap_cache_sheaves(struct kmem_cache *s)\n--\nmm/slub.c-8683-\nmm/slub.c:8684:\tcapacity = calculate_sheaf_capacity(s, \u0026empty_args);\nmm/slub.c-8685-\n"
} |
| 23/2 | 2026/10/24 20:47 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 29585 output: 32 thoughts: 15 Thoughts: Okay, let's dive into this. Here's my thought process on checking `__kmem_cache_alloc_bulk`: **Checking `__kmem_cache_alloc_bulk`** Right, `__kmem_cache_alloc_bulk`. That's the function we need to examine. The sheer name tells me we're dealing with bulk allocation, which instantly flags a certain set of potential issues β contention, fragmentation, memory pressure, cache misses, all the usual suspects related to the underlying slab allocator. I need to understand its behavior thoroughly to get a handle on performance bottlenecks or memory-related bugs. Specifically, the bulk aspect is key: How many objects are we talking about per allocation? What's the typical size of these objects? Does the system allocate in powers of two? And most importantly, what are the use cases for bulk allocation? Is it a common operation and does it occur in latency critical sections? I should also check its place in the call graph and surrounding functions, that can offer good insight into its purpose. Let's see how it behaves, because if that's the point, that is what is happening here! |
| 24/2 | 2026/10/24 20:47 | tool | grepper |
0mArgs:{
"Expression": "__kmem_cache_alloc_bulk",
"PathPrefixes": [
"mm/"
]
}Results: {
"Output": "mm/slub.c=5193=static int __prefill_sheaf_pfmemalloc(struct kmem_cache *s,\n--\nmm/slub.c-5220-\nmm/slub.c:5221:static bool __kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags,\nmm/slub.c-5222-\t\tsize_t size, void **p);\n--\nmm/slub.c=5231=kmem_cache_prefill_sheaf(struct kmem_cache *s, gfp_t gfp, unsigned int size)\n--\nmm/slub.c-5252-\t\t */\nmm/slub.c:5253:\t\tif (!__kmem_cache_alloc_bulk(s, gfp, size,\nmm/slub.c-5254-\t\t\t\t\t \u0026sheaf-\u003eobjects[0])) {\n--\nmm/slub.c=5372=int kmem_cache_refill_sheaf(struct kmem_cache *s, gfp_t gfp,\n--\nmm/slub.c-5391-\nmm/slub.c:5392:\t\tif (!__kmem_cache_alloc_bulk(s, gfp, sheaf-\u003ecapacity - sheaf-\u003esize,\nmm/slub.c-5393-\t\t\t\t\t \u0026sheaf-\u003eobjects[sheaf-\u003esize]))\n--\nmm/slub.c=7527=refill_objects(struct kmem_cache *s, void **p, gfp_t gfp, unsigned int min,\n--\nmm/slub.c-7562-\nmm/slub.c:7563:static bool __kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags,\nmm/slub.c-7564-\t\tsize_t size, void **p)\n--\nmm/slub.c=7613=bool kmem_cache_alloc_bulk_noprof(struct kmem_cache *s, gfp_t flags,\n--\nmm/slub.c-7649-\t\t */\nmm/slub.c:7650:\t\tif (unlikely(!__kmem_cache_alloc_bulk(s, flags, size - i,\nmm/slub.c-7651-\t\t\t\tp + i))) {\n"
} |
| 25/2 | 2026/10/24 20:47 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 30474 output: 258 thoughts: 1067 Thoughts: **Fuzzing Justification: SLUB Refactoring** Alright, let's break this down. My initial assessment centers on these key functions: `kmem_cache_alloc_bulk_noprof`, `__kmem_cache_alloc_bulk`, `free_to_partial_list`, `alloc_single_from_partial`, and `alloc_single_from_new_slab`. I need to understand how this patch affects their execution paths, especially in relation to the `SLUB_TINY` configuration. First, I need to check if these functions are ubiquitous or not. It looks like `free_to_partial_list`, in a standard kernel build *without* debug or tiny slabs, is *never* called. It's only invoked when `kmem_cache_debug(s)` is true. The same pattern holds true for `alloc_single_from_partial` and `alloc_single_from_new_slab`. Essentially, these functions are the slow paths, the ones that handle allocations and frees *only* when debugging is enabled or when `slab_tiny` is in use. This implies a significant refactoring of the debug and tiny paths. This means that this patch is definitely modifying slow paths, which are critical to fuzz. Looking at the code, it's clear the patch is moving `CONFIG_SLUB_TINY` from compile-time to a runtime boot parameter (`slab_tiny`), introducing `SLAB_DEBUG_NOOP` (controlled by `slab_debug=N` or `slab_tiny=1`), and, crucially, routing allocation/deallocation slow paths through `kmem_cache_debug()`. It looks like it's touching critical code in `mm/slub.c` and `mm/slab_common.c`, and potentially affecting the slab order calculations, cache merging, per-CPU sheaves and the slow allocation/free paths. This strongly indicates the need for fuzzing to catch regressions, race conditions, or, ideally, invariant violations. Therefore, fuzzing is warranted. My reasoning is that this patch refactors the SLUB memory allocator, specifically handling `CONFIG_SLUB_TINY`, introduces new slab debug flags, and directs slow path allocation and deallocation to the debug path. The modification of core memory management code makes fuzzing crucial. The necessary configurations are `SLUB`, `SLUB_DEBUG`, and `SLUB_TINY`. The focus symbols are: `alloc_single_from_partial`, `alloc_single_from_new_slab`, `free_to_partial_list`, `kmem_cache_flags`, `calculate_sheaf_capacity`, `do_kmem_cache_create`, and `__kmem_cache_alloc_bulk`. Now, let's verify that the configs are correctly named and the focus symbols are relevant. They are and do. - `alloc_single_from_partial` has a modified condition (`IS_ENABLED(CONFIG_SLUB_TINY) || kmem_cache_debug(s)` -> `kmem_cache_debug(s)`). - `alloc_single_from_new_slab` also has a modified condition. - `free_to_partial_list` has a modified condition. - `kmem_cache_flags` is modified. - `calculate_sheaf_capacity` has modified code. - `do_kmem_cache_create` is modified. - `__kmem_cache_alloc_bulk` has a modified condition. Everything checks out. I'm confident in this assessment. Let's call `set-results`. |
| 26/2 | 2026/10/24 20:47 | tool | set-results |
0mArgs:{
"EnableConfigs": [
"SLUB",
"SLUB_DEBUG",
"SLUB_TINY"
],
"FocusSymbols": [
"alloc_single_from_partial",
"alloc_single_from_new_slab",
"free_to_partial_list",
"kmem_cache_flags",
"calculate_sheaf_capacity",
"do_kmem_cache_create",
"__kmem_cache_alloc_bulk"
],
"Reasoning": "The patch converts CONFIG_SLUB_TINY from compile-time conditional compilation to a runtime boot-time configuration (slab_tiny), introduces a new no-op debug mode (SLAB_DEBUG_NOOP / slab_debug=N), and refactors the SLUB memory allocator's allocation, freeing, and cache creation paths. This modifies reachable core memory management logic in mm/slub.c and mm/slab_common.c, altering freelist handling, sheaf capacity computation, and single-object allocation/free slowpaths. Fuzzing is warranted to ensure the refactored slowpaths and invariant assertions do not introduce regressions or memory corruption.",
"WorthFuzzing": true
}Results: {
"EnableConfigs": [
"SLUB",
"SLUB_DEBUG",
"SLUB_TINY"
],
"FocusSymbols": [
"alloc_single_from_partial",
"alloc_single_from_new_slab",
"free_to_partial_list",
"kmem_cache_flags",
"calculate_sheaf_capacity",
"do_kmem_cache_create",
"__kmem_cache_alloc_bulk"
],
"Reasoning": "The patch converts CONFIG_SLUB_TINY from compile-time conditional compilation to a runtime boot-time configuration (slab_tiny), introduces a new no-op debug mode (SLAB_DEBUG_NOOP / slab_debug=N), and refactors the SLUB memory allocator's allocation, freeing, and cache creation paths. This modifies reachable core memory management logic in mm/slub.c and mm/slab_common.c, altering freelist handling, sheaf capacity computation, and single-object allocation/free slowpaths. Fuzzing is warranted to ensure the refactored slowpaths and invariant assertions do not introduce regressions or memory corruption.",
"WorthFuzzing": true
} |
| 27/1 | 2026/10/24 20:47 | action | If |
0mArgs:{
"WorthFuzzing": true
}Results: null |
| 28/2 | 2026/10/24 20:47 | agent | kmsan-evaluator |
0mModel:core Args: null Results: {
"KMSANReasoning": "The patch series refactors the SLUB allocator to replace compile-time CONFIG_SLUB_TINY with a runtime boot parameter (slab_tiny) and introduces the SLAB_DEBUG_NOOP flag to route allocations through debug slowpaths to minimize memory footprint. It also allows KASAN, SLUB_DEBUG, and other features previously disallowed under CONFIG_SLUB_TINY to be enabled.\n\nThese modifications only affect SLUB internal management, cache merging, order calculations, and slowpath routing. They do not alter object initialization or zeroing logic (kmsan_slab_alloc hooks and GFP_ZERO paths remain unchanged), do not introduce uninitialized stack or heap variables, and do not expose any kernel data or padding to userspace. Potential regressions or errors in these changes (such as freelist corruption, incorrect slab ordering, or memory corruption) are covered by KASAN, SLUB consistency checks, and standard debugging tools. Therefore, dedicated KMSAN fuzzing is not required.",
"NeedsKMSAN": false
}Instruction: You are an expert Linux kernel security engineer specializing in kernel memory
error detectors (KASAN and KMSAN). Your job is to review the provided patch series and
determine if the code changes justify spawning a dedicated KMSAN (KernelMemorySanitizer)
fuzzing session in addition to standard KASAN fuzzing.
CRITICAL DISTINCTION BETWEEN KASAN AND KMSAN:
- Standard KASAN kernel builds (upstream-apparmor-kasan.config) already enable
a comprehensive suite of debugging tools and sanitizers, including KASAN
(out-of-bounds accesses, use-after-free, double free, invalid free), LOCKDEP
(locking bugs and deadlocks), UB-sanitizers, and memory corruption checks.
- KMSAN (KernelMemorySanitizer) detects reads of UNINITIALIZED memory (stack, heap,
or page allocations) and kernel-to-user memory info-leaks.
Rule: THERE IS NO SENSE IN RUNNING A KMSAN SESSION IF A BUG CAN BE CAUGHT BY KASAN,
LOCKDEP, OR OTHER STANDARD BUG DETECTORS.
A dedicated KMSAN fuzzing session incurs significant resource costs. You must ONLY
set NeedsKMSAN=true if the code changes introduce or expose UNINITIALIZED MEMORY risks
that are detected ONLY by KMSAN.
Look holistically at the patch series and surrounding code. Even if no direct
uninitialized field accesses or new buffer allocations are added in the diff itself,
a patch may alter control flow, bounds checking, or data length calculations in ways
that change how the rest of the code operates on existing buffers (e.g. allowing
uninitialized stack/heap memory to be read, copied to user space, or used in control
flow). Do not hesitate to use your code access tools to inspect the surrounding code,
called functions, and callers.
Set NeedsKMSAN=true ONLY IF the patch introduces or modifies:
1. Kernel structures sent to user space (via copy_to_user, put_user, netlink skb
attributes, ioctl output arguments, socket options, or BPF buffers) where fields
or structure padding might not be fully initialized/zeroed.
2. Conditional logic or branching that depends on potentially uninitialized variables
or struct fields.
3. Allocation or initialization of complex data structures where uninitialized fields
could be read later in reachable code paths.
4. Bounds checks, lengths, or logic in a way that allows surrounding code to access
uninitialized bytes of existing buffers.
Set NeedsKMSAN=false IF:
- The code changes primarily risk out-of-bounds access, array overflows, NULL pointer
dereferences, locking deadlocks, or use-after-free bugs (these are already caught
by KASAN, LOCKDEP, or standard bug detectors).
- All stack/heap structures touched or introduced by the patch are fully zeroed
or initialized (e.g. using = {0}, memset, kzalloc) before being read or copied.
- The patch does not introduce any risk of uninitialized memory usage or info-leaks.
Use your code access tools to inspect the surrounding code if necessary, then provide
detailed KMSANReasoning contrasting KASAN vs KMSAN applicability for this patch.
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt: Target architecture: amd64
For your convenience, here is the diff of the changes:
commit 140335c47acb03e30728e609e79ac4636d89dd6b
Author: syz-cluster <triage@syzkaller.com>
Date: Sat Oct 24 20:46:31 2026 +0000
syz-cluster: applied patch under review
diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index 03636d7998374..29dc1c8124733 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -7043,6 +7043,10 @@ Kernel parameters
NUMA kernel object placement which helps with slow
interconnects in NUMA systems.
+ slab_tiny= [MM, EARLY]
+ Minimize the slab allocator memory footprint at the
+ expense of SMP scalability.
+
slram= [HW,MTD]
smart2= [HW]
diff --git a/Documentation/admin-guide/mm/slab.rst b/Documentation/admin-guide/mm/slab.rst
index 14429ab90611b..350384908631b 100644
--- a/Documentation/admin-guide/mm/slab.rst
+++ b/Documentation/admin-guide/mm/slab.rst
@@ -45,12 +45,12 @@ of the first "select slabs" blocks that matches the slab's name are applied.
Possible debug options are::
- F Sanity checks on (enables SLAB_DEBUG_CONSISTENCY_CHECKS
- Sorry SLAB legacy issues)
+ F Sanity (slab consistency) checks on alloc and free
Z Red zoning
P Poisoning (object and padding)
U User tracking (free and alloc)
T Trace (please only use on single slabs)
+ N No-op (force debugging slowpaths without any checks)
A Enable failslab filter mark for the cache
O Switch debugging off for caches that would have
caused higher minimum slab orders
@@ -85,6 +85,20 @@ switch off debugging for such caches by default, use::
slab_debug=O
+The No-op option can be useful to minimize slab memory overhead by forcing slab
+debugging slowpaths, which disables percpu object caching. This reduces SMP
+scalability significantly, but does not impose the extra cpu or memory overhead
+of debugging options that actually perform checks. This can be useful for e.g.
+kdump kernels where scalability is not a concern, but memory has to be
+pre-reserved from the production kernel. So for a kdump kernel you can use::
+
+ slab_debug=N
+
+Note that for this purpose you can instead use an option that can achieve
+slightly better memory savings (by not creating separate kmalloc-rcl caches)::
+
+ slab_tiny=1
+
You can apply different options to different list of slab names, using blocks
of options. This will enable red zoning for dentry and user tracking for
kmalloc. All other slabs will not get any debugging enabled::
diff --git a/include/linux/slab.h b/include/linux/slab.h
index cda126def67af..ad645967a3eea 100644
--- a/include/linux/slab.h
+++ b/include/linux/slab.h
@@ -35,6 +35,7 @@ enum _slab_flag_bits {
_SLAB_PANIC,
_SLAB_TYPESAFE_BY_RCU,
_SLAB_TRACE,
+ _SLAB_DEBUG_NOOP,
#ifdef CONFIG_DEBUG_OBJECTS
_SLAB_DEBUG_OBJECTS,
#endif
@@ -54,9 +55,7 @@ enum _slab_flag_bits {
#ifdef CONFIG_KFENCE
_SLAB_SKIP_KFENCE,
#endif
-#ifndef CONFIG_SLUB_TINY
_SLAB_RECLAIM_ACCOUNT,
-#endif
_SLAB_OBJECT_POISON,
_SLAB_CMPXCHG_DOUBLE,
#ifdef CONFIG_SLAB_OBJ_EXT
@@ -166,8 +165,10 @@ enum _slab_flag_bits {
* Note that SLAB_TYPESAFE_BY_RCU was originally named SLAB_DESTROY_BY_RCU.
*/
#define SLAB_TYPESAFE_BY_RCU __SLAB_FLAG_BIT(_SLAB_TYPESAFE_BY_RCU)
-/* Trace allocations and frees */
+/* DEBUG: Trace allocations and frees */
#define SLAB_TRACE __SLAB_FLAG_BIT(_SLAB_TRACE)
+/* DEBUG: Force the debug slowpaths without actually doing anything */
+#define SLAB_DEBUG_NOOP __SLAB_FLAG_BIT(_SLAB_DEBUG_NOOP)
/* Flag to prevent checks on free */
#ifdef CONFIG_DEBUG_OBJECTS
@@ -187,7 +188,7 @@ enum _slab_flag_bits {
* - general caches created and used by a subsystem, only when a
* (subsystem-specific) debug option is enabled
* - performance critical caches, should be very rare and consulted with slab
- * maintainers, and not used together with CONFIG_SLUB_TINY
+ * maintainers
*/
#define SLAB_NO_MERGE __SLAB_FLAG_BIT(_SLAB_NO_MERGE)
@@ -238,11 +239,7 @@ enum _slab_flag_bits {
* pages are allocated with __GFP_RECLAIMABLE, which affects grouping pages by
* mobility, and are accounted in SReclaimable counter in /proc/meminfo
*/
-#ifndef CONFIG_SLUB_TINY
#define SLAB_RECLAIM_ACCOUNT __SLAB_FLAG_BIT(_SLAB_RECLAIM_ACCOUNT)
-#else
-#define SLAB_RECLAIM_ACCOUNT __SLAB_FLAG_UNUSED
-#endif
#define SLAB_TEMPORARY SLAB_RECLAIM_ACCOUNT /* Objects are short-lived */
/* Slab caches without obj_exts array */
@@ -721,11 +718,7 @@ enum kmalloc_cache_type {
#endif
KMALLOC_PARTITION_START = KMALLOC_NORMAL,
KMALLOC_PARTITION_END = KMALLOC_PARTITION_START + KMALLOC_PARTITION_CACHES_NR,
-#ifdef CONFIG_SLUB_TINY
- KMALLOC_RECLAIM = KMALLOC_NORMAL,
-#else
KMALLOC_RECLAIM,
-#endif
#ifdef CONFIG_ZONE_DMA
KMALLOC_DMA,
#endif
diff --git a/lib/Kconfig.kasan b/lib/Kconfig.kasan
index a4bb610a7a6fa..f20b574f6653a 100644
--- a/lib/Kconfig.kasan
+++ b/lib/Kconfig.kasan
@@ -49,7 +49,7 @@ menuconfig KASAN
(HAVE_ARCH_KASAN_SW_TAGS && CC_HAS_KASAN_SW_TAGS)) && \
CC_HAS_WORKING_NOSANITIZE_ADDRESS) || \
HAVE_ARCH_KASAN_HW_TAGS
- depends on SYSFS && !SLUB_TINY
+ depends on SYSFS
select STACKDEPOT_ALWAYS_INIT
help
Enables KASAN (Kernel Address Sanitizer) - a dynamic memory safety
diff --git a/mm/Kconfig b/mm/Kconfig
index edb4a6c0a8702..2286073ea9065 100644
--- a/mm/Kconfig
+++ b/mm/Kconfig
@@ -167,16 +167,18 @@ config SLUB
config KVFREE_RCU_BATCHED
def_bool y
- depends on !SLUB_TINY && !TINY_RCU
+ depends on !TINY_RCU
depends on !RCU_STRICT_GRACE_PERIOD
config SLUB_TINY
- bool "Configure for minimal memory footprint"
+ bool "Enable slab_tiny by default"
depends on EXPERT && !COMPILE_TEST
- select SLAB_MERGE_DEFAULT
help
+ Deprecated option that enables the slab_tiny boot parameter by
+ default, and can be overridden by booting with slab_tiny=0.
+
Configures the slab allocator in a way to achieve minimal memory
- footprint, sacrificing scalability, debugging and other features.
+ footprint, sacrificing scalability.
This is intended only for the smallest system that had used the
SLOB allocator and is not recommended for systems with more than
16MB RAM.
@@ -199,7 +201,6 @@ config SLAB_MERGE_DEFAULT
config SLAB_FREELIST_RANDOM
bool "Randomize slab freelist"
- depends on !SLUB_TINY
help
Randomizes the freelist order used on creating new pages. This
security feature reduces the predictability of the kernel slab
@@ -207,7 +208,6 @@ config SLAB_FREELIST_RANDOM
config SLAB_FREELIST_HARDENED
bool "Harden slab freelist metadata"
- depends on !SLUB_TINY
help
Many kernel heap attacks try to target slab cache metadata and
other infrastructure. This options makes minor performance
@@ -216,7 +216,6 @@ config SLAB_FREELIST_HARDENED
config SLAB_BUCKETS
bool "Support allocation from separate kmalloc buckets"
- depends on !SLUB_TINY
default SLAB_FREELIST_HARDENED
help
Kernel heap attacks frequently depend on being able to create
@@ -234,7 +233,7 @@ config SLAB_BUCKETS
config SLUB_STATS
default n
bool "Enable performance statistics"
- depends on SYSFS && !SLUB_TINY
+ depends on SYSFS
help
The statistics are useful to debug slab allocation behavior in
order find ways to optimize the allocator. This should never be
@@ -245,7 +244,6 @@ config SLUB_STATS
Try running: slabinfo -DA
config KMALLOC_PARTITION_CACHES
- depends on !SLUB_TINY
bool "Partitioned slab caches for normal kmalloc"
default RANDOM_KMALLOC_CACHES
help
diff --git a/mm/Kconfig.debug b/mm/Kconfig.debug
index 9eaa25d1cf234..4e36c7c63ef78 100644
--- a/mm/Kconfig.debug
+++ b/mm/Kconfig.debug
@@ -48,7 +48,7 @@ config DEBUG_PAGEALLOC_ENABLE_DEFAULT
config SLUB_DEBUG
default y
bool "Enable SLUB debugging support" if EXPERT
- depends on SYSFS && !SLUB_TINY
+ depends on SYSFS
select STACKDEPOT if STACKTRACE_SUPPORT
help
SLUB has extensive debug support features. Disabling these can
diff --git a/mm/slab.h b/mm/slab.h
index e94ac63d10dc0..d39ea67d44f4e 100644
--- a/mm/slab.h
+++ b/mm/slab.h
@@ -282,16 +282,15 @@ struct kmem_cache {
/*
* Every cache has !NULL s->cpu_sheaves but they may point to the
* bootstrap_sheaf temporarily during init, or permanently for the boot caches
- * and caches with debugging enabled, or all caches with CONFIG_SLUB_TINY. This
+ * and caches with debugging enabled (or all caches with slab_tiny). This
* helper distinguishes whether cache has real non-bootstrap sheaves.
*/
static inline bool cache_has_sheaves(struct kmem_cache *s)
{
- /* Test CONFIG_SLUB_TINY for code elimination purposes */
- return !IS_ENABLED(CONFIG_SLUB_TINY) && s->sheaf_capacity;
+ return s->sheaf_capacity;
}
-#if defined(CONFIG_SYSFS) && !defined(CONFIG_SLUB_TINY)
+#ifdef CONFIG_SYSFS
#define SLAB_SUPPORTS_SYSFS 1
void sysfs_slab_unlink(struct kmem_cache *s);
void sysfs_slab_release(struct kmem_cache *s);
@@ -396,6 +395,8 @@ extern const struct kmalloc_info_struct {
unsigned int size;
} kmalloc_info[];
+extern bool slab_tiny_enabled;
+
/* Kmalloc array related functions */
void setup_kmalloc_cache_index_table(void);
void create_kmalloc_caches(void);
@@ -476,7 +477,7 @@ void flush_rcu_sheaves_on_cache(struct kmem_cache *s);
SLAB_NO_USER_FLAGS | SLAB_KMALLOC | SLAB_NO_MERGE)
#define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER | \
- SLAB_TRACE | SLAB_CONSISTENCY_CHECKS)
+ SLAB_TRACE | SLAB_DEBUG_NOOP | SLAB_CONSISTENCY_CHECKS)
#define SLAB_FLAGS_PERMITTED (SLAB_CORE_FLAGS | SLAB_DEBUG_FLAGS)
@@ -504,26 +505,20 @@ struct slabinfo {
void get_slabinfo(struct kmem_cache *s, struct slabinfo *sinfo);
-#ifdef CONFIG_SLUB_DEBUG
-#ifdef CONFIG_SLUB_DEBUG_ON
-DECLARE_STATIC_KEY_TRUE(slub_debug_enabled);
-#else
-DECLARE_STATIC_KEY_FALSE(slub_debug_enabled);
-#endif
-extern void print_tracking(struct kmem_cache *s, void *object);
-long validate_slab_cache(struct kmem_cache *s);
+DECLARE_STATIC_KEY_MAYBE(CONFIG_SLUB_DEBUG_ON, slub_debug_enabled);
+
static inline bool __slub_debug_enabled(void)
{
return static_branch_unlikely(&slub_debug_enabled);
}
+
+#ifdef CONFIG_SLUB_DEBUG
+extern void print_tracking(struct kmem_cache *s, void *object);
+long validate_slab_cache(struct kmem_cache *s);
#else
static inline void print_tracking(struct kmem_cache *s, void *object)
{
}
-static inline bool __slub_debug_enabled(void)
-{
- return false;
-}
#endif
/*
@@ -576,8 +571,7 @@ static inline bool need_kmalloc_no_objext(void)
if (!mem_alloc_profiling_permanently_disabled())
return true;
- if (!mem_cgroup_kmem_disabled() &&
- (KMALLOC_NORMAL == KMALLOC_RECLAIM))
+ if (!mem_cgroup_kmem_disabled() && slab_tiny_enabled)
return true;
return false;
diff --git a/mm/slab_common.c b/mm/slab_common.c
index 01c64ef661e7f..33e76a0c30844 100644
--- a/mm/slab_common.c
+++ b/mm/slab_common.c
@@ -47,9 +47,9 @@ struct kmem_cache *kmem_cache;
* Any flag that adds per-object metadata should be included,
* since slab merging can update s->inuse that affects the metadata layout.
*/
-#define SLAB_NEVER_MERGE (SLAB_DEBUG_FLAGS | SLAB_TYPESAFE_BY_RCU | \
- SLAB_NOLEAKTRACE | SLAB_FAILSLAB | SLAB_NO_MERGE | \
- SLAB_OBJ_EXT_IN_OBJ)
+#define SLAB_NEVER_MERGE ((SLAB_DEBUG_FLAGS & ~SLAB_DEBUG_NOOP) | \
+ SLAB_TYPESAFE_BY_RCU | SLAB_NOLEAKTRACE | SLAB_FAILSLAB | \
+ SLAB_NO_MERGE | SLAB_OBJ_EXT_IN_OBJ)
#define SLAB_MERGE_SAME (SLAB_RECLAIM_ACCOUNT | SLAB_CACHE_DMA | \
SLAB_CACHE_DMA32 | SLAB_ACCOUNT | SLAB_MAY_ACCOUNT)
@@ -835,11 +835,7 @@ EXPORT_SYMBOL(kmalloc_size_roundup);
#define KMALLOC_CGROUP_NAME(sz)
#endif
-#ifndef CONFIG_SLUB_TINY
#define KMALLOC_RCL_NAME(sz) .name[KMALLOC_RECLAIM] = "kmalloc-rcl-" #sz,
-#else
-#define KMALLOC_RCL_NAME(sz)
-#endif
#ifdef CONFIG_KMALLOC_PARTITION_CACHES
#define __KMALLOC_PARTITION_CONCAT(a, b) a ## b
@@ -976,7 +972,11 @@ new_kmalloc_cache(int idx, enum kmalloc_cache_type type)
unsigned int aligned_size = kmalloc_info[idx].size;
int aligned_idx = idx;
- if ((KMALLOC_RECLAIM != KMALLOC_NORMAL) && (type == KMALLOC_RECLAIM)) {
+ if (type == KMALLOC_RECLAIM) {
+ if (slab_tiny_enabled) {
+ kmalloc_caches[type][idx] = kmalloc_caches[KMALLOC_NORMAL][idx];
+ return;
+ }
flags |= SLAB_RECLAIM_ACCOUNT;
} else if (IS_ENABLED(CONFIG_MEMCG) && (type == KMALLOC_CGROUP)) {
if (mem_cgroup_kmem_disabled()) {
@@ -1009,7 +1009,7 @@ new_kmalloc_cache(int idx, enum kmalloc_cache_type type)
* KMALLOC_NO_OBJ_EXT cache.
*/
if (!mem_cgroup_kmem_disabled()) {
- if (type == KMALLOC_NORMAL && KMALLOC_RECLAIM != KMALLOC_NORMAL)
+ if (type == KMALLOC_NORMAL && !slab_tiny_enabled)
flags |= SLAB_NO_MERGE;
else if (!(flags & SLAB_NO_OBJ_EXT))
flags |= SLAB_MAY_ACCOUNT;
diff --git a/mm/slub.c b/mm/slub.c
index 45e077c7526c2..3b7ba4fdeada4 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -196,19 +196,9 @@ enum slab_flags {
SL_pfmemalloc = PG_active, /* Historical reasons for this bit */
};
-#ifndef CONFIG_SLUB_TINY
#define __fastpath_inline __always_inline
-#else
-#define __fastpath_inline
-#endif
-#ifdef CONFIG_SLUB_DEBUG
-#ifdef CONFIG_SLUB_DEBUG_ON
-DEFINE_STATIC_KEY_TRUE(slub_debug_enabled);
-#else
-DEFINE_STATIC_KEY_FALSE(slub_debug_enabled);
-#endif
-#endif /* CONFIG_SLUB_DEBUG */
+DEFINE_STATIC_KEY_MAYBE(CONFIG_SLUB_DEBUG_ON, slub_debug_enabled);
#ifdef CONFIG_NUMA
static DEFINE_STATIC_KEY_FALSE(strict_numa);
@@ -219,6 +209,8 @@ DEFINE_STATIC_KEY_MAYBE(CONFIG_MEM_ALLOC_PROFILING_ENABLED_BY_DEFAULT,
slab_obj_ext_has_codetag_key);
#endif
+bool slab_tiny_enabled __read_mostly = IS_ENABLED(CONFIG_SLUB_TINY);
+
/* Structure holding extra parameters for slab allocations */
struct slab_alloc_context {
unsigned long caller_addr;
@@ -270,7 +262,6 @@ void *fixup_red_left(struct kmem_cache *s, void *p)
/* Enable to log cmpxchg failures */
#undef SLUB_DEBUG_CMPXCHG
-#ifndef CONFIG_SLUB_TINY
/*
* Minimum number of partial slabs. These will be left on the partial
* lists even if they are empty. kmem_cache_shrink may reclaim them.
@@ -283,10 +274,6 @@ void *fixup_red_left(struct kmem_cache *s, void *p)
* sort the partial list by the number of objects in use.
*/
#define MAX_PARTIAL 10
-#else
-#define MIN_PARTIAL 0
-#define MAX_PARTIAL 0
-#endif
#define DEBUG_DEFAULT_FLAGS (SLAB_CONSISTENCY_CHECKS | SLAB_RED_ZONE | \
SLAB_POISON | SLAB_STORE_USER)
@@ -1044,15 +1031,24 @@ static inline void *restore_red_left(struct kmem_cache *s, void *p)
/*
* Debug settings:
*/
-#if defined(CONFIG_SLUB_DEBUG_ON)
-static slab_flags_t slub_debug = DEBUG_DEFAULT_FLAGS;
-#else
-static slab_flags_t slub_debug;
-#endif
+static slab_flags_t slub_debug = IS_ENABLED(CONFIG_SLUB_DEBUG_ON) ? DEBUG_DEFAULT_FLAGS : 0;
static const char *slub_debug_string __ro_after_init;
static int disable_higher_order_debug;
+/* Union of all slab debug flags enabled for specific caches only */
+static slab_flags_t slab_debug_per_cache_union __initdata;
+
+static inline bool __init slab_want_nohash_pointers(void)
+{
+ /*
+ * If any debugging is enabled globally or per-cache, we would like
+ * nohash pointers. The exception is no-op debugging that only forces
+ * the slowpaths.
+ */
+ return (slub_debug | slab_debug_per_cache_union) & ~SLAB_DEBUG_NOOP;
+}
+
/*
* Object debugging
*/
@@ -1898,6 +1894,9 @@ parse_slub_debug_flags(const char *str, slab_flags_t *flags, const char **slabs,
case 't':
*flags |= SLAB_TRACE;
break;
+ case 'n':
+ *flags |= SLAB_DEBUG_NOOP;
+ break;
case 'a':
*flags |= SLAB_FAILSLAB;
break;
@@ -1961,6 +1960,7 @@ static int __init setup_slub_debug(const char *str, const struct kernel_param *k
global_slub_debug_changed = true;
} else {
slab_list_specified = true;
+ slab_debug_per_cache_union |= flags;
if (flags & SLAB_STORE_USER)
stack_depot_request_early_init();
}
@@ -2018,6 +2018,9 @@ slab_flags_t kmem_cache_flags(slab_flags_t flags, const char *name)
slab_flags_t block_flags;
slab_flags_t slub_debug_local = slub_debug;
+ if (slab_tiny_enabled)
+ flags |= SLAB_DEBUG_NOOP;
+
if (flags & SLAB_NO_USER_FLAGS)
return flags;
@@ -2069,6 +2072,8 @@ static inline void setup_object_debug(struct kmem_cache *s, void *object) {}
static inline
void setup_slab_debug(struct kmem_cache *s, struct slab *slab, void *addr) {}
+static inline bool __init slab_want_nohash_pointers(void) { return false; }
+
static inline bool alloc_debug_processing(struct kmem_cache *s,
struct slab *slab, void *object, int orig_size) { return true; }
@@ -2088,6 +2093,9 @@ static inline void remove_full(struct kmem_cache *s, struct kmem_cache_node *n,
struct slab *slab) {}
slab_flags_t kmem_cache_flags(slab_flags_t flags, const char *name)
{
+ if (slab_tiny_enabled)
+ flags |= SLAB_DEBUG_NOOP;
+
return flags;
}
#define slub_debug 0
@@ -3948,7 +3956,7 @@ static void *get_from_partial_node(struct kmem_cache *s,
if (!pfmemalloc_match(slab, gfp_flags))
continue;
- if (IS_ENABLED(CONFIG_SLUB_TINY) || kmem_cache_debug(s)) {
+ if (kmem_cache_debug(s)) {
object = alloc_single_from_partial(s, n, slab,
ac->orig_size);
if (object)
@@ -4562,7 +4570,7 @@ static unsigned int alloc_from_new_slab(struct kmem_cache *s, struct slab *slab,
/*
* Slow path. We failed to allocate via percpu sheaves or they are not available
- * due to bootstrap or debugging enabled or SLUB_TINY.
+ * due to bootstrap or debugging enabled.
*
* We try to allocate from partial slab lists and fall back to allocating a new
* slab.
@@ -4616,7 +4624,7 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node,
stat(s, ALLOC_SLAB);
- if (IS_ENABLED(CONFIG_SLUB_TINY) || kmem_cache_debug(s)) {
+ if (kmem_cache_debug(s)) {
object = alloc_single_from_new_slab(s, slab, ac);
if (likely(object))
@@ -5845,7 +5853,7 @@ static void __slab_free(struct kmem_cache *s, struct slab *slab,
unsigned long flags;
bool on_node_partial;
- if (IS_ENABLED(CONFIG_SLUB_TINY) || kmem_cache_debug(s)) {
+ if (kmem_cache_debug(s)) {
free_to_partial_list(s, slab, head, tail, cnt, addr);
return;
}
@@ -7557,7 +7565,7 @@ static bool __kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags,
{
int i;
- if (IS_ENABLED(CONFIG_SLUB_TINY) || kmem_cache_debug(s)) {
+ if (kmem_cache_debug(s)) {
const struct slab_alloc_context ac = {
.caller_addr = _RET_IP_,
.orig_size = s->object_size,
@@ -7684,10 +7692,16 @@ EXPORT_SYMBOL(kmem_cache_alloc_bulk_noprof);
* and increases the number of allocations possible without having to
* take the list_lock.
*/
-static unsigned int slub_min_order;
-static unsigned int slub_max_order =
- IS_ENABLED(CONFIG_SLUB_TINY) ? 1 : PAGE_ALLOC_COSTLY_ORDER;
-static unsigned int slub_min_objects;
+static unsigned int slab_min_order;
+static unsigned int slab_max_order = PAGE_ALLOC_COSTLY_ORDER;
+static unsigned int slab_min_objects;
+
+/*
+ * Store values set by boot-time parameters, to be evaluated in
+ * kmem_cache_init(). UINT_MAX means they were not set, as 0 is a valid value.
+ */
+static unsigned int slab_min_order_param __initdata = UINT_MAX;
+static unsigned int slab_max_order_param __initdata = UINT_MAX;
/*
* Calculate the order of allocation given an slab object size.
@@ -7741,7 +7755,7 @@ static inline int calculate_order(unsigned int size)
unsigned int max_objects;
unsigned int min_order;
- min_objects = slub_min_objects;
+ min_objects = slab_min_objects;
if (!min_objects) {
/*
* Some architectures will only update present cpus when
@@ -7758,10 +7772,10 @@ static inline int calculate_order(unsigned int size)
min_objects = 4 * (fls(nr_cpus) + 1);
}
/* min_objects can't be 0 because get_order(0) is undefined */
- max_objects = max(order_objects(slub_max_order, size), 1U);
+ max_objects = max(order_objects(slab_max_order, size), 1U);
min_objects = min(min_objects, max_objects);
- min_order = max_t(unsigned int, slub_min_order,
+ min_order = max_t(unsigned int, slab_min_order,
get_order(min_objects * size));
if (order_objects(min_order, size) > MAX_OBJS_PER_PAGE)
return get_order(size * MAX_OBJS_PER_PAGE) - 1;
@@ -7782,9 +7796,9 @@ static inline int calculate_order(unsigned int size)
* long as at least single object fits within slab_max_order.
*/
for (unsigned int fraction = 16; fraction > 1; fraction /= 2) {
- order = calc_slab_order(size, min_order, slub_max_order,
+ order = calc_slab_order(size, min_order, slab_max_order,
fraction);
- if (order <= slub_max_order)
+ if (order <= slab_max_order)
return order;
}
@@ -7852,7 +7866,7 @@ static int init_percpu_sheaves(struct kmem_cache *s)
* cache.
*
* We keep bootstrap_sheaf for kmem_cache and kmem_cache_node,
- * caches with debug enabled, and all caches with SLUB_TINY.
+ * and caches with debugging enabled.
* For kmalloc caches it's used temporarily during the initial
* bootstrap.
*/
@@ -7999,7 +8013,7 @@ static unsigned int calculate_sheaf_capacity(struct kmem_cache *s,
size_t size;
- if (IS_ENABLED(CONFIG_SLUB_TINY) || s->flags & SLAB_DEBUG_FLAGS)
+ if (slab_tiny_enabled || s->flags & SLAB_DEBUG_FLAGS)
return 0;
/*
@@ -8355,50 +8369,14 @@ void __kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct slab *slab)
* Kmalloc subsystem
*******************************************************************/
-static int __init setup_slub_min_order(const char *str, const struct kernel_param *kp)
-{
- int ret;
-
- ret = kstrtouint(str, 0, &slub_min_order);
- if (ret)
- return ret;
-
- if (slub_min_order > slub_max_order)
- slub_max_order = slub_min_order;
-
- return 0;
-}
-
-static const struct kernel_param_ops param_ops_slab_min_order __initconst = {
- .set = setup_slub_min_order,
-};
-__core_param_cb(slab_min_order, ¶m_ops_slab_min_order, &slub_min_order, 0);
-__core_param_cb(slub_min_order, ¶m_ops_slab_min_order, &slub_min_order, 0);
-
-static int __init setup_slub_max_order(const char *str, const struct kernel_param *kp)
-{
- int ret;
-
- ret = kstrtouint(str, 0, &slub_max_order);
- if (ret)
- return ret;
-
- slub_max_order = min_t(unsigned int, slub_max_order, MAX_PAGE_ORDER);
-
- if (slub_min_order > slub_max_order)
- slub_min_order = slub_max_order;
+core_param(slab_min_order, slab_min_order_param, uint, 0);
+core_param(slub_min_order, slab_min_order_param, uint, 0);
- return 0;
-}
-
-static const struct kernel_param_ops param_ops_slab_max_order __initconst = {
- .set = setup_slub_max_order,
-};
-__core_param_cb(slab_max_order, ¶m_ops_slab_max_order, &slub_max_order, 0);
-__core_param_cb(slub_max_order, ¶m_ops_slab_max_order, &slub_max_order, 0);
+core_param(slab_max_order, slab_max_order_param, uint, 0);
+core_param(slub_max_order, slab_max_order_param, uint, 0);
-core_param(slab_min_objects, slub_min_objects, uint, 0);
-core_param(slub_min_objects, slub_min_objects, uint, 0);
+core_param(slab_min_objects, slab_min_objects, uint, 0);
+core_param(slub_min_objects, slab_min_objects, uint, 0);
#ifdef CONFIG_NUMA
static int __init setup_slab_strict_numa(const char *str, const struct kernel_param *kp)
@@ -8705,7 +8683,7 @@ static void __init bootstrap_cache_sheaves(struct kmem_cache *s)
capacity = calculate_sheaf_capacity(s, &empty_args);
- /* capacity can be 0 due to debugging or SLUB_TINY */
+ /* capacity can be 0 due to debugging */
if (!capacity)
return;
@@ -8771,11 +8749,25 @@ void __init kmem_cache_init(void)
slab_obj_ext_has_codetag_init();
+ if (slab_tiny_enabled) {
+ slab_max_order = 1;
+ static_branch_enable(&slub_debug_enabled);
+ }
+
+ if (slab_max_order_param <= MAX_PAGE_ORDER)
+ slab_max_order = slab_max_order_param;
+
+ if (slab_min_order_param <= MAX_PAGE_ORDER)
+ slab_min_order = slab_min_order_param;
+
if (debug_guardpage_minorder())
- slub_max_order = 0;
+ slab_max_order = 0;
+
+ if (slab_min_order > slab_max_order)
+ slab_min_order = slab_max_order;
/* Inform pointer hashing choice about slub debugging state. */
- hash_pointers_finalize(__slub_debug_enabled());
+ hash_pointers_finalize(slab_want_nohash_pointers());
kmem_cache_node = &boot_kmem_cache_node;
kmem_cache = &boot_kmem_cache;
@@ -8823,7 +8815,7 @@ void __init kmem_cache_init(void)
pr_info("SLUB: HWalign=%d, Order=%u-%u, MinObjects=%u, CPUs=%u, Nodes=%u\n",
cache_line_size(),
- slub_min_order, slub_max_order, slub_min_objects,
+ slab_min_order, slab_max_order, slab_min_objects,
nr_cpu_ids, nr_node_ids);
}
@@ -8837,6 +8829,13 @@ void __init kmem_cache_init_late(void)
#endif
}
+static int __init early_slab_tiny(char *buf)
+{
+ return kstrtobool(buf, &slab_tiny_enabled);
+}
+
+early_param("slab_tiny", early_slab_tiny);
+
int do_kmem_cache_create(struct kmem_cache *s, const char *name,
unsigned int size, struct kmem_cache_args *args,
slab_flags_t flags)
@@ -8885,6 +8884,8 @@ int do_kmem_cache_create(struct kmem_cache *s, const char *name,
*/
s->min_partial = min_t(unsigned long, MAX_PARTIAL, ilog2(s->size) / 2);
s->min_partial = max_t(unsigned long, MIN_PARTIAL, s->min_partial);
+ if (slab_tiny_enabled)
+ s->min_partial = 0;
s->cpu_sheaves = alloc_percpu(struct slub_percpu_sheaves);
if (!s->cpu_sheaves) {
|
| 29/3 | 2026/10/24 20:47 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 11679 output: 29 thoughts: 1797 Thoughts: **SLUB Allocator Changes: KMSAN Considerations** Okay, so this patch series fundamentally alters the SLUB allocator in the Linux kernel, specifically focusing on the `slab_tiny` feature. It's essentially transitioning `slab_tiny` from a compile-time construct to a runtime-configurable option, controlled by the `slab_tiny` boot parameter and `CONFIG_SLUB_TINY`. My primary concern is whether these changes introduce any new avenues for uninitialized memory reads, particularly those that KMSAN would catch. I need to determine if `NeedsKMSAN=true` is warranted here. The core changes involve: * Introducing `slab_tiny_enabled` and using it to enable or disable features which previously depended on the compile-time `CONFIG_SLUB_TINY`. * Replacing compile-time checks with runtime ones, using `slab_tiny_enabled`. * Re-enabling debug features that were previously excluded with `!SLUB_TINY`, such as KASAN, SLUB_DEBUG, etc. * Modifying `kmalloc` cache setup, specifically aliasing `KMALLOC_RECLAIM` to `KMALLOC_NORMAL` when `slab_tiny_enabled` is true. * Updating parameter parsing for SLUB debug options. I'm focusing on whether these changes introduce uninitialized memory risks, particularly in the context of structures being passed to user space, conditional logic involving potentially uninitialized variables, the allocation and initialization of data structures, or potential bounds check issues. Given the documentation on KMSAN, any of these, *especially* data copied to userspace, could be very serious. I've reviewed the diffs, which mainly involve: * Documentation updates, to reflect the new functionality. * Header file changes, with the introduction of `SLAB_DEBUG_NOOP` and modifications to `KMALLOC_RECLAIM`. * Kconfig changes, removing dependencies on `!SLUB_TINY` for various debug and hardening features, and updated help text for `CONFIG_SLUB_TINY`. * `slab.h` changes include: The addition of `slab_tiny_enabled`, `SLAB_DEBUG_NOOP` and `kmem_cache_flags`. * `slab_common.c` modifications: Aliasing `KMALLOC_RECLAIM` when `slab_tiny_enabled` is true. * `slub.c` modifications: Initialization of `slab_tiny_enabled`, `slub_debug` and modifications to allocation/free paths. The key areas I'm looking at are: 1. How the new `slab_tiny_enabled` variable influences kmalloc cache setup, specifically the aliasing of `KMALLOC_RECLAIM` to `KMALLOC_NORMAL`. Is this potentially leading to uninitialized memory being used? I'll need to check the kmalloc paths. 2. The re-enabling of various debug features. While this is generally positive for finding bugs, it also increases the possibility of triggering previously masked memory errors, if not handled carefully. The impact depends on how these features are used. 3. The use of `kmem_cache_debug(s)` replacing the older `IS_ENABLED(CONFIG_SLUB_TINY) || kmem_cache_debug(s)` calls. I need to be sure that `SLAB_DEBUG_NOOP` (enabled by `slab_tiny_enabled`) does not silently enable any new uninitialized memory issues. A `grep` check is needed on this. I will need to carefully check `kmem_cache_debug()` definition to be sure that this does not introduce any risks, or cause issues with other debug features. I'll need to double check the allocation and free paths and that data is zero initialized as required. This is key to deciding whether `NeedsKMSAN=true` is appropriate. Based on this, I'll assess whether the changes fall under any of the KMSAN criteria, specifically those related to uninitialized memory reads or leaks. |
| 30/3 | 2026/10/24 20:48 | tool | grepper |
0mArgs:{
"Expression": "kmem_cache_debug",
"PathPrefixes": [
"mm/"
]
}Results: {
"Output": "mm/slab.h=519=static inline void print_tracking(struct kmem_cache *s, void *object)\n--\nmm/slab.h-528- */\nmm/slab.h:529:static inline bool kmem_cache_debug_flags(struct kmem_cache *s, slab_flags_t flags)\nmm/slab.h-530-{\n--\nmm/slab.h=932=static inline bool slub_debug_orig_size(struct kmem_cache *s)\nmm/slab.h-933-{\nmm/slab.h:934:\treturn (kmem_cache_debug_flags(s, SLAB_STORE_USER) \u0026\u0026\nmm/slab.h-935-\t\t\t(s-\u003eflags \u0026 SLAB_KMALLOC));\n--\nmm/slub.c=231=struct slab_obj_iter {\n--\nmm/slub.c-240-\nmm/slub.c:241:static inline bool kmem_cache_debug(struct kmem_cache *s)\nmm/slub.c-242-{\nmm/slub.c:243:\treturn kmem_cache_debug_flags(s, SLAB_DEBUG_FLAGS);\nmm/slub.c-244-}\n--\nmm/slub.c=246=void *fixup_red_left(struct kmem_cache *s, void *p)\nmm/slub.c-247-{\nmm/slub.c:248:\tif (kmem_cache_debug_flags(s, SLAB_RED_ZONE))\nmm/slub.c-249-\t\tp += s-\u003ered_left_pad;\n--\nmm/slub.c=906=static unsigned int obj_exts_offset_in_object(struct kmem_cache *s)\n--\nmm/slub.c-909-\nmm/slub.c:910:\tif (kmem_cache_debug_flags(s, SLAB_STORE_USER))\nmm/slub.c-911-\t\toffset += sizeof(struct track) * 2;\n--\nmm/slub.c=1754=static void setup_object_debug(struct kmem_cache *s, void *object)\nmm/slub.c-1755-{\nmm/slub.c:1756:\tif (!kmem_cache_debug_flags(s, SLAB_STORE_USER|SLAB_RED_ZONE|__OBJECT_POISON))\nmm/slub.c-1757-\t\treturn;\n--\nmm/slub.c=1764=void setup_slab_debug(struct kmem_cache *s, struct slab *slab, void *addr)\nmm/slub.c-1765-{\nmm/slub.c:1766:\tif (!kmem_cache_debug_flags(s, SLAB_POISON))\nmm/slub.c-1767-\t\treturn;\n--\nmm/slub.c=3594=static void free_slab(struct kmem_cache *s, struct slab *slab)\nmm/slub.c-3595-{\nmm/slub.c:3596:\tif (kmem_cache_debug_flags(s, SLAB_CONSISTENCY_CHECKS)) {\nmm/slub.c-3597-\t\tvoid *p;\n--\nmm/slub.c=3665=static inline void remove_partial(struct kmem_cache_node *n,\n--\nmm/slub.c-3673-/*\nmm/slub.c:3674: * Called only for kmem_cache_debug() caches instead of remove_partial(), with a\nmm/slub.c-3675- * slab from the n-\u003epartial list. Remove only a single object from the slab, do\n--\nmm/slub.c=3763=static inline void init_slab_obj_iter(struct kmem_cache *s, struct slab *slab,\n--\nmm/slub.c-3794-/*\nmm/slub.c:3795: * Called only for kmem_cache_debug() caches to allocate from a freshly\nmm/slub.c-3796- * allocated slab. Allocate a single object instead of whole freelist\n--\nmm/slub.c=3930=static void *get_from_partial_node(struct kmem_cache *s,\n--\nmm/slub.c-3958-\nmm/slub.c:3959:\t\tif (kmem_cache_debug(s)) {\nmm/slub.c-3960-\t\t\tobject = alloc_single_from_partial(s, n, slab,\n--\nmm/slub.c=4578=static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node,\n--\nmm/slub.c-4626-\nmm/slub.c:4627:\tif (kmem_cache_debug(s)) {\nmm/slub.c-4628-\t\tobject = alloc_single_from_new_slab(s, slab, ac);\n--\nmm/slub.c-4644-success:\nmm/slub.c:4645:\tif (kmem_cache_debug_flags(s, SLAB_STORE_USER))\nmm/slub.c-4646-\t\tset_track(s, object, TRACK_ALLOC, ac-\u003ecaller_addr, gfpflags);\n--\nmm/slub.c=5569=static void *__kmalloc_nolock_noprof(DECL_TOKEN_PARAMS(size, token), gfp_t gfp_flags,\n--\nmm/slub.c-5596-\nmm/slub.c:5597:\tif (!(s-\u003eflags \u0026 __CMPXCHG_DOUBLE) \u0026\u0026 !kmem_cache_debug(s))\nmm/slub.c-5598-\t\t/*\n--\nmm/slub.c=5845=static void __slab_free(struct kmem_cache *s, struct slab *slab,\n--\nmm/slub.c-5855-\nmm/slub.c:5856:\tif (kmem_cache_debug(s)) {\nmm/slub.c-5857-\t\tfree_to_partial_list(s, slab, head, tail, cnt, addr);\n--\nmm/slub.c=6745=void kmem_cache_free(struct kmem_cache *s, void *x)\n--\nmm/slub.c-6751-\tif (IS_ENABLED(CONFIG_SLAB_FREELIST_HARDENED) ||\nmm/slub.c:6752:\t kmem_cache_debug_flags(s, SLAB_CONSISTENCY_CHECKS)) {\nmm/slub.c-6753-\n--\nmm/slub.c=7563=static bool __kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags,\n--\nmm/slub.c-7567-\nmm/slub.c:7568:\tif (kmem_cache_debug(s)) {\nmm/slub.c-7569-\t\tconst struct slab_alloc_context ac = {\n--\nmm/slub.c=8411=void __check_heap_object(const void *ptr, unsigned long n,\n--\nmm/slub.c-8434-\t/* Adjust for redzone and reject if within the redzone. */\nmm/slub.c:8435:\tif (!is_kfence \u0026\u0026 kmem_cache_debug_flags(s, SLAB_RED_ZONE)) {\nmm/slub.c-8436-\t\tif (offset \u003c s-\u003ered_left_pad)\n--\nmm/slub.c=9508=static ssize_t validate_store(struct kmem_cache *s,\n--\nmm/slub.c-9512-\nmm/slub.c:9513:\tif (buf[0] == '1' \u0026\u0026 kmem_cache_debug(s)) {\nmm/slub.c-9514-\t\tret = validate_slab_cache(s);\n"
} |
| 31/3 | 2026/10/24 20:48 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 16437 output: 39 thoughts: 808 Thoughts: **Analyzing the `kmem_cache_debug` and `slab_tiny_enabled` Impact** Okay, let's break this down. My initial thought is to understand the implications of `kmem_cache_debug` and how it's now intertwined with `slab_tiny_enabled`. It seems `kmem_cache_debug` is effectively being set to true for all caches when `slab_tiny_enabled` is active, because of that `SLAB_DEBUG_NOOP` flag. This mimics the old SLUB_TINY behavior, which is intriguing. It's essentially forcing all caches down the debug slowpaths, bypassing CPU sheaves and opting for single object allocations, and so on. That sounds like a significant change in performance characteristics, something to be aware of. Now, my primary concern with any patch is security, so let's dig into potential risks. Specifically, I need to evaluate the chance that this could introduce uninitialized memory vulnerabilities. First, are there any kernel structures exposed to user space? No, this patch is firmly within the slab allocator, focused on internal management, parameters, and configuration options. Good. Next, I need to check for conditional logic or branching that might rely on uninitialized variables. Let's see... looking at the code... * `slab_min_order_param`, `slab_max_order_param` are initialized properly to `UINT_MAX`. * `slab_tiny_enabled` is initialized to `IS_ENABLED(CONFIG_SLUB_TINY)`. * `slab_debug_per_cache_union` is `static slab_flags_t slab_debug_per_cache_union __initdata;` (in BSS, so 0). In `calculate_sheaf_capacity`: * `if (slab_tiny_enabled || s->flags & SLAB_DEBUG_FLAGS)` In `kmem_cache_init`: * `if (slab_tiny_enabled)`: Sets `slab_max_order = 1` and enables `slub_debug_enabled`. * It looks like the `slab_max_order_param` and `slab_min_order_param` are initialized to `UINT_MAX` and then assigned to `slab_max_order` and `slab_min_order` if they are less than `MAX_PAGE_ORDER`. The variables look safe. Does it change how slabs are initialized or zeroed? No, from what I can see, object allocation still respects GFP_ZERO, constructors, poisoned objects, etc. So the standard memory safety mechanisms are still in place. What about other bug possibilities? The usual suspects: merging issues, locking issues, slab order calculation errors, potential memory corruption in the freelist or metadata if the order or freelists are misconfigured. These types of bugs *could* be introduced, but KASAN and SLUB_DEBUG should catch them. But none of these are related to kernel-to-user info leaks that might be missed by KASAN. Finally, just to be thorough, I have to consider KMSAN. I need to make sure this patch hasn't inadvertently bypassed any KMSAN hooks in the SLUB layer. I should probably grep for `kmsan` in `mm/slub.c` and make sure. Okay, I have confirmed this patch did not touch any `kmsan` hooks. All things considered, this patch seems like a relatively safe change in terms of uninitialized memory issues and kernel-to-user information leaks. It's more about performance and configuration changes than outright vulnerabilities. Still, I'd want to run this through thorough testing, particularly with the debug features enabled, to ensure there are no regressions. |
| 32/3 | 2026/10/24 20:48 | tool | grepper |
0mArgs:{
"Expression": "kmsan",
"PathPrefixes": [
"mm/slub.c",
"mm/slab_common.c"
]
}Results: {
"Output": "mm/slub.c-28-#include \u003clinux/node.h\u003e\nmm/slub.c:29:#include \u003clinux/kmsan.h\u003e\nmm/slub.c-30-#include \u003clinux/cpu.h\u003e\n--\nmm/slub.c=1348=static void restore_bytes(struct kmem_cache *s, const char *message, u8 data,\n--\nmm/slub.c-1355-#ifdef CONFIG_KMSAN\nmm/slub.c:1356:#define pad_check_attributes noinline __no_kmsan_checks\nmm/slub.c-1357-#else\n--\nmm/slub.c=2674=struct rcu_delayed_free {\n--\nmm/slub.c-2691- * Alloc hooks called for kmalloc_nolock():\nmm/slub.c:2692: * - kmsan_slab_alloc()\nmm/slub.c-2693- * - kasan_slab_alloc()\n--\nmm/slub.c=2707=bool slab_free_hook(struct kmem_cache *s, void *x, bool init,\n--\nmm/slub.c-2713-\tkmemleak_free_recursive(x, s-\u003eflags);\nmm/slub.c:2714:\tkmsan_slab_free(s, x);\nmm/slub.c-2715-\n--\nmm/slub.c=4690=bool slab_post_alloc_hook(struct kmem_cache *s, gfp_t flags, size_t size,\n--\nmm/slub.c-4742-\t\t\t\t\t\t s-\u003eflags, init_flags);\nmm/slub.c:4743:\t\tkmsan_slab_alloc(s, p[i], init_flags);\nmm/slub.c-4744-\t\talloc_tagging_slab_alloc_hook(s, p[i], flags, ac-\u003ealloc_flags);\n--\nmm/slub.c=5461=static void *___kmalloc_large_node(size_t size, gfp_t flags, int node)\n--\nmm/slub.c-5492-\tkmemleak_alloc(ptr, size, 1, flags);\nmm/slub.c:5493:\tkmsan_kmalloc_large(ptr, size, flags);\nmm/slub.c-5494-\n--\nmm/slub.c=6859=static void free_large_kmalloc(struct page *page, void *object)\n--\nmm/slub.c-6872-\tkasan_kfree_large(object);\nmm/slub.c:6873:\tkmsan_kfree_large(object);\nmm/slub.c-6874-\n--\nmm/slub.c=6944=void kfree_nolock(const void *object)\n--\nmm/slub.c-6971-\t */\nmm/slub.c:6972:\tkmsan_slab_free(s, x);\nmm/slub.c-6973-\t/*\n--\nmm/slub.c=9789=static char *create_unique_id(struct kmem_cache *s)\n--\nmm/slub.c-9822-\t}\nmm/slub.c:9823:\tkmsan_unpoison_memory(name, p - name);\nmm/slub.c-9824-\treturn name;\n--\nmm/slub.c=9899=int sysfs_slab_alias(struct kmem_cache *s, const char *name)\n--\nmm/slub.c-9923-\talias_list = al;\nmm/slub.c:9924:\tkmsan_unpoison_memory(al, sizeof(*al));\nmm/slub.c-9925-\treturn 0;\n"
} |
| 33/3 | 2026/10/24 20:48 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 19079 output: 229 thoughts: 556 Thoughts: **KMSAN Assessment of SLUB Refactoring** Alright, let's break this down. From what I'm seeing, this patch is primarily focused on refactoring the SLUB allocator. Itβs making `SLUB_TINY` a runtime option instead of a compile-time one, introducing `SLAB_DEBUG_NOOP`, and generally untangling the Kconfig options, so debug options like KASAN and SLUB_DEBUG can play nicely, regardless of whether `SLUB_TINY` is enabled. My key focus is always on KMSAN, so let's get specific. KMSAN is my radar for detecting those nasties: uninitialized memory reads, especially the ones that can leak info from kernel space to user space. It focuses on memory initialization, as it does with `kmsan_slab_alloc()`. Now, reviewing these changes, it's pretty clear that the underlying allocation and free paths are untouched from a KMSAN perspective. We are *still* calling `slab_post_alloc_hook` and `slab_free_hook`. KMSAN is still tracking initialization during allocation. The core allocation and free mechanisms haven't been altered to circumvent KMSAN's checks. The patch's changes revolve around things like how the allocator selects slow paths, how it calculates order, how it handles parameters at boot, and the logic around cache merging and partitioning. The kicker is, *none* of these changes introduce or modify any data passed to user space. Importantly, it doesn't touch the initialization or zeroing semantics of memory (using things like `kzalloc` or `GFP_ZERO` or the hooks already mentioned). It doesn't introduce any new uninitialized variable reads that would trigger a KMSAN alert. Any potential bugs *this* patch might introduce (think problems with order calculations, slow-path lockups, invalid slab state, and so forth) are all things that KASAN, SLUB consistency checks, and other standard debugging tools like SLUB_DEBUG are perfectly capable of catching. We have that safety net in place, making sure that there are no gaps. Therefore, because this patch doesn't introduce any new KMSAN-relevant issues β meaning no info leaks, no uninitialized reads, and no alterations to memory initialization or data passed to user space β `NeedsKMSAN` is definitively `false`. Time to move on. I'll invoke `set-results`. |
| 34/3 | 2026/10/24 20:48 | tool | set-results |
0mArgs:{
"KMSANReasoning": "The patch series refactors the SLUB allocator to replace compile-time CONFIG_SLUB_TINY with a runtime boot parameter (slab_tiny) and introduces the SLAB_DEBUG_NOOP flag to route allocations through debug slowpaths to minimize memory footprint. It also allows KASAN, SLUB_DEBUG, and other features previously disallowed under CONFIG_SLUB_TINY to be enabled.\n\nThese modifications only affect SLUB internal management, cache merging, order calculations, and slowpath routing. They do not alter object initialization or zeroing logic (kmsan_slab_alloc hooks and GFP_ZERO paths remain unchanged), do not introduce uninitialized stack or heap variables, and do not expose any kernel data or padding to userspace. Potential regressions or errors in these changes (such as freelist corruption, incorrect slab ordering, or memory corruption) are covered by KASAN, SLUB consistency checks, and standard debugging tools. Therefore, dedicated KMSAN fuzzing is not required.",
"NeedsKMSAN": false
}Results: {
"KMSANReasoning": "The patch series refactors the SLUB allocator to replace compile-time CONFIG_SLUB_TINY with a runtime boot parameter (slab_tiny) and introduces the SLAB_DEBUG_NOOP flag to route allocations through debug slowpaths to minimize memory footprint. It also allows KASAN, SLUB_DEBUG, and other features previously disallowed under CONFIG_SLUB_TINY to be enabled.\n\nThese modifications only affect SLUB internal management, cache merging, order calculations, and slowpath routing. They do not alter object initialization or zeroing logic (kmsan_slab_alloc hooks and GFP_ZERO paths remain unchanged), do not introduce uninitialized stack or heap variables, and do not expose any kernel data or padding to userspace. Potential regressions or errors in these changes (such as freelist corruption, incorrect slab ordering, or memory corruption) are covered by KASAN, SLUB consistency checks, and standard debugging tools. Therefore, dedicated KMSAN fuzzing is not required.",
"NeedsKMSAN": false
} |
| Total Calls | Total Tokens | Avg Tokens | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|
| Total Calls | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|