AI Trajectory


Trajectory: (Expand/Collapse All)
Seq Timestamp Type Name Duration
0/0 2026/11/13 02:22 flow patch-triage
7m Args:
null

Results:
{
  "EnableConfigs": [
    "BPF_NUMAB",
    "NUMA_BALANCING",
    "MEMCG",
    "BPF_SYSCALL",
    "DEBUG_INFO_BTF",
    "NUMA"
  ],
  "FocusSymbols": [
    "bpf_numab_set_mode",
    "bpf_numab_get_mode",
    "task_numab_mode",
    "folio_numab_mode",
    "numab_memcg_reset",
    "task_numa_fault",
    "should_numa_migrate_memory",
    "migrate_misplaced_folio",
    "folio_can_map_prot_numa"
  ],
  "KMSANReasoning": "The patch series introduces per-cgroup NUMA balancing mode selection via BPF kfuncs (CONFIG_BPF_NUMAB). It adds an integer field `numab_mode` to `struct mem_cgroup`, initializes it in `mem_cgroup_alloc` (which allocates via kmem_cache_zalloc), and updates scheduler and memory tiering logic to consult the effective NUMA balancing mode.\n\n1. No kernel structures or data buffers are copied to user space (no copy_to_user, netlink skb, ioctl output, or info-leak vectors).\n2. All newly introduced and modified variables (such as `numab_enabled` and `numab_tiering` via `task_numab_get_modes`) are deterministically initialized before any read or branch.\n3. The newly added struct field `memcg-\u003enumab_mode` is initialized upon allocation and reset during css offline/reset.\n4. The potential risks introduced by this change are related to concurrency, RCU dereferencing of cgroups/memcgs, cgroup reference counting, and lock handling (mutex vs static keys), all of which are covered by standard bug detectors, KASAN, and LOCKDEP.\n\nBecause there are no uninitialized memory access risks or info-leaks, a dedicated KMSAN fuzzing session is not warranted.",
  "NeedsKMSAN": false,
  "Reasoning": "The patch introduces per-cgroup NUMA balancing mode selection via BPF kfuncs (bpf_numab_set_mode, bpf_numab_get_mode) and modifies NUMA balancing scan, fault handling, and folio migration logic across the scheduler and memory management subsystems (fair.c, mempolicy.c, migrate.c, memory-tiers.c). These changes are in core, reachable code paths in virtualized environments with NUMA and cgroups enabled.",
  "WorthFuzzing": true
}

1/1 2026/11/13 02:22 action read-patch-diff
0m Args:
null

Results:
{
  "PatchDiff": "commit 1c523a70068adf269503582cd4945bd6c12b20f8\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate:   Fri Nov 13 02:22:16 2026 +0000\n\n    syz-cluster: applied patch under review\n\ndiff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h\nindex 69e1bcc67c588d..78ea21bfab95e0 100644\n--- a/include/linux/memcontrol.h\n+++ b/include/linux/memcontrol.h\n@@ -342,6 +342,12 @@ struct mem_cgroup {\n \t */\n \tbool zswap_writeback;\n #endif\n+\n+#ifdef CONFIG_BPF_NUMAB\n+\t/* per-cgroup NUMA balancing mode request; -1 follows the global state. */\n+\tint numab_mode;\n+#endif\n+\n \t/* Not padded: nodeinfo[] is read-mostly too, let it share the line. */\n \t__cacheline_group_end(memcg_read_mostly);\n \ndiff --git a/include/linux/sched/numa_balancing.h b/include/linux/sched/numa_balancing.h\nindex 52b22c5c396db0..e10093386cf739 100644\n--- a/include/linux/sched/numa_balancing.h\n+++ b/include/linux/sched/numa_balancing.h\n@@ -8,6 +8,7 @@\n  */\n \n #include \u003clinux/sched.h\u003e\n+#include \u003clinux/sched/sysctl.h\u003e\n \n #define TNF_MIGRATED\t0x01\n #define TNF_NO_GROUP\t0x02\n@@ -32,6 +33,122 @@ extern void set_numabalancing_state(bool enabled);\n extern void task_numa_free(struct task_struct *p, bool final);\n bool should_numa_migrate_memory(struct task_struct *p, struct folio *folio,\n \t\t\t\tint src_nid, int dst_cpu);\n+\n+extern struct static_key_false sched_numa_balancing;\n+\n+/*\n+ * Mode values used by the NUMA balancing helpers.\n+ */\n+enum numab_mode {\n+\tNUMAB_FOLLOW_SYSTEM\t= -1,\n+\tNUMAB_DISABLED\t\t= NUMA_BALANCING_DISABLED,\n+\tNUMAB_NORMAL\t\t= NUMA_BALANCING_NORMAL,\n+\tNUMAB_TIERING\t\t= NUMA_BALANCING_MEMORY_TIERING,\n+\tNUMAB_NORMAL_TIERING\t= NUMA_BALANCING_NORMAL |\n+\t\t\t\t  NUMA_BALANCING_MEMORY_TIERING,\n+};\n+\n+#ifdef CONFIG_BPF_NUMAB\n+extern struct static_key_false numab_cgroup_mode_set;\n+\n+int task_numab_mode(struct task_struct *p);\n+int folio_numab_mode(struct folio *folio);\n+void numab_memcg_reset(struct mem_cgroup *memcg);\n+#endif\n+\n+/*\n+ * Whether any task might need the NUMA scanner on this tick.  This is\n+ * only the cheap global gate; the per-task request is checked after the\n+ * scan period in task_tick_numa().\n+ */\n+static inline bool task_numab_tick_possible(void)\n+{\n+#ifdef CONFIG_BPF_NUMAB\n+\tif (static_branch_likely(\u0026numab_cgroup_mode_set))\n+\t\treturn true;\n+#endif\n+\treturn static_branch_unlikely(\u0026sched_numa_balancing);\n+}\n+\n+/*\n+ * Whether NUMA balancing applies to @p: the global sysctl state, possibly\n+ * overridden by the requests of @p's memcg and of every ancestor.\n+ * A memcg's request always takes priority over the system setting.\n+ */\n+static inline bool task_numab_enabled(struct task_struct *p)\n+{\n+#ifdef CONFIG_BPF_NUMAB\n+\tif (static_branch_unlikely(\u0026numab_cgroup_mode_set)) {\n+\t\tint mode = task_numab_mode(p);\n+\n+\t\tif (mode != NUMAB_FOLLOW_SYSTEM)\n+\t\t\treturn mode != NUMAB_DISABLED;\n+\t}\n+#endif\n+\treturn static_branch_likely(\u0026sched_numa_balancing);\n+}\n+\n+/* Whether NUMA balancing is in memory tiering mode. */\n+static inline bool numab_in_tiering_mode(void)\n+{\n+\treturn sysctl_numa_balancing_mode \u0026 NUMA_BALANCING_MEMORY_TIERING;\n+}\n+\n+/*\n+ * Return both task-side decisions from one request lookup.  This is used\n+ * by paths that need to know both whether to account the fault and\n+ * whether slow-tier faults should be skipped.\n+ */\n+static inline void task_numab_get_modes(struct task_struct *p, bool *enabled,\n+\t\t\t\t\tbool *tiering)\n+{\n+#ifdef CONFIG_BPF_NUMAB\n+\tif (static_branch_unlikely(\u0026numab_cgroup_mode_set)) {\n+\t\tint mode = task_numab_mode(p);\n+\n+\t\tif (mode != NUMAB_FOLLOW_SYSTEM) {\n+\t\t\t*enabled = mode != NUMAB_DISABLED;\n+\t\t\t*tiering = mode \u0026 NUMAB_TIERING;\n+\t\t\treturn;\n+\t\t}\n+\t}\n+#endif\n+\t*enabled = static_branch_likely(\u0026sched_numa_balancing);\n+\t*tiering = numab_in_tiering_mode();\n+}\n+\n+/*\n+ * The combined folio-side request, with the global sysctl state used when\n+ * no memcg requests a mode.  DISABLED never speaks for memory, so only\n+ * NORMAL and TIERING are present here.  Callers that need more than one\n+ * bit should use this helper once rather than querying each bit\n+ * separately.\n+ */\n+static inline int folio_numab_effective_mode(struct folio *folio)\n+{\n+#ifdef CONFIG_BPF_NUMAB\n+\tif (static_branch_unlikely(\u0026numab_cgroup_mode_set)) {\n+\t\tint mode = folio_numab_mode(folio);\n+\n+\t\tif (mode != NUMAB_FOLLOW_SYSTEM)\n+\t\t\treturn mode;\n+\t}\n+#endif\n+\treturn sysctl_numa_balancing_mode;\n+}\n+\n+/*\n+ * Whether @folio's memory participates in tiering, i.e. whether its\n+ * _last_cpupid carries an access time instead of a cpupid. The\n+ * requests of the owner memcg and of every ancestor are combined.\n+ * DISABLED never speaks for memory (it is a task-side request), so only\n+ * NORMAL and TIERING are consulted here; without either, the global\n+ * sysctl decides.\n+ */\n+static inline bool folio_numab_in_tiering_mode(struct folio *folio)\n+{\n+\treturn folio_numab_effective_mode(folio) \u0026 NUMAB_TIERING;\n+}\n #else\n static inline void task_numa_fault(int last_node, int node, int pages,\n \t\t\t\t   int flags)\n@@ -52,6 +169,33 @@ static inline bool should_numa_migrate_memory(struct task_struct *p,\n {\n \treturn true;\n }\n+\n+static inline bool task_numab_enabled(struct task_struct *p)\n+{\n+\treturn false;\n+}\n+\n+static inline bool numab_in_tiering_mode(void)\n+{\n+\treturn false;\n+}\n+\n+static inline bool folio_numab_in_tiering_mode(struct folio *folio)\n+{\n+\treturn false;\n+}\n+\n+static inline void task_numab_get_modes(struct task_struct *p, bool *enabled,\n+\t\t\t\t\tbool *tiering)\n+{\n+\t*enabled = false;\n+\t*tiering = false;\n+}\n+\n+static inline bool task_numab_tick_possible(void)\n+{\n+\treturn false;\n+}\n #endif\n \n #endif /* _LINUX_SCHED_NUMA_BALANCING_H */\ndiff --git a/init/Kconfig b/init/Kconfig\nindex 4013781e0a0292..3f38cf8077a3ca 100644\n--- a/init/Kconfig\n+++ b/init/Kconfig\n@@ -827,6 +827,29 @@ config NUMA_BALANCING\n \n \t  This system will be inactive on UMA systems.\n \n+config BPF_NUMAB\n+\tbool \"Per-cgroup NUMA balancing mode selection\"\n+\tdefault n\n+\tdepends on NUMA_BALANCING \u0026\u0026 MEMCG \u0026\u0026 BPF_SYSCALL \u0026\u0026 DEBUG_INFO_BTF\n+\thelp\n+\t  Allow BPF programs to select the NUMA balancing mode (disabled,\n+\t  normal, memory tiering, or both) on a per-cgroup basis, overriding the\n+\t  global NUMA balancing sysctl. A latency-sensitive service can\n+\t  opt its tasks out of balancing, or a batch service can have its\n+\t  PMEM-resident memory promoted when hot, without changing the\n+\t  mode for the rest of the system.\n+\n+\t  The request is written and read back through the\n+\t  bpf_numab_set_mode() and bpf_numab_get_mode() kfuncs, callable\n+\t  from BPF_PROG_TYPE_SYSCALL programs. The mode is stored in the\n+\t  target cgroup's memcg; setting it on a cgroup without the memory\n+\t  controller enabled is rejected.  This interface only applies to\n+\t  cgroups on the default hierarchy (cgroup v2).  While no memcg\n+\t  makes a request, the NUMA balancing hot paths pay a single\n+\t  patched-out branch and nothing else.\n+\n+\t  If unsure, say N.\n+\n config SCHED_CACHE\n \tbool \"Cache aware load balance\"\n \tdefault y\ndiff --git a/kernel/sched/bpf_numab.c b/kernel/sched/bpf_numab.c\nnew file mode 100644\nindex 00000000000000..c7f44bf383f61d\n--- /dev/null\n+++ b/kernel/sched/bpf_numab.c\n@@ -0,0 +1,261 @@\n+// SPDX-License-Identifier: GPL-2.0-or-later\n+/*\n+ * Per-cgroup NUMA balancing mode\n+ *\n+ * A cgroup overrides the global state through its memcg. Task and folio\n+ * lookups walk the memcg chain; an opt-out binds the subtree, while the\n+ * remaining bits OR together.\n+ *\n+ * Author: Yafang Shao \u003claoar.shao@gmail.com\u003e\n+ */\n+#include \u003clinux/bpf.h\u003e\n+#include \u003clinux/btf.h\u003e\n+#include \u003clinux/cgroup.h\u003e\n+#include \u003clinux/memcontrol.h\u003e\n+#include \u003clinux/module.h\u003e\n+#include \u003clinux/mutex.h\u003e\n+#include \u003clinux/sched.h\u003e\n+#include \u003clinux/sched/numa_balancing.h\u003e\n+\n+DEFINE_STATIC_KEY_FALSE(numab_cgroup_mode_set);\n+\n+/* Whether this memcg may still own a NUMA balancing request. */\n+static bool numab_memcg_active(struct mem_cgroup *memcg)\n+{\n+\tunsigned int flags;\n+\n+\tif (mem_cgroup_is_root(memcg))\n+\t\treturn true;\n+\n+\t/* Take one snapshot so all three state bits describe the same moment. */\n+\tflags = READ_ONCE(memcg-\u003ecss.flags);\n+\n+\treturn (flags \u0026 CSS_ONLINE) \u0026\u0026\n+\t       !(flags \u0026 CSS_DYING) \u0026\u0026\n+\t       (flags \u0026 CSS_VISIBLE);\n+}\n+\n+/*\n+ * Combine the requests of @memcg and of every ancestor. A task chain\n+ * stops at an explicit opt-out: a task can never be forced into\n+ * balancing. A folio chain skips opt-outs instead (a memcg's DISABLED\n+ * request only speaks for its tasks, never for its memory) and keeps\n+ * collecting the remaining requests.\n+ */\n+static int numab_memcg_mode(struct mem_cgroup *memcg, bool folio_side)\n+{\n+\tint req = 0;\n+\n+\tfor (; memcg; memcg = parent_mem_cgroup(memcg)) {\n+\t\tint mode;\n+\n+\t\tif (!numab_memcg_active(memcg))\n+\t\t\tcontinue;\n+\n+\t\t/* Paired with WRITE_ONCE() under numab_mode_mutex. */\n+\t\tmode = data_race(READ_ONCE(memcg-\u003enumab_mode));\n+\t\tif (mode == NUMAB_FOLLOW_SYSTEM)\n+\t\t\tcontinue;\n+\t\tif (mode == NUMAB_DISABLED) {\n+\t\t\tif (!folio_side)\n+\t\t\t\treturn NUMAB_DISABLED;\n+\t\t\tcontinue;\n+\t\t}\n+\t\treq |= mode;\n+\t}\n+\treturn req ?: NUMAB_FOLLOW_SYSTEM;\n+}\n+\n+/*\n+ * The combined request for @p. Kernel threads have no user memory to\n+ * balance, so they make no request.  The walk needs no reference: the\n+ * memcg chain is RCU-protected, so rcu_read_lock() keeps it alive for\n+ * the whole walk.\n+ */\n+int task_numab_mode(struct task_struct *p)\n+{\n+\tstruct mem_cgroup *memcg;\n+\tint mode;\n+\n+\tif (mem_cgroup_disabled() || !p-\u003emm)\n+\t\treturn NUMAB_FOLLOW_SYSTEM;\n+\n+\trcu_read_lock();\n+\tmemcg = mem_cgroup_from_task(p);\n+\tmode = memcg ? numab_memcg_mode(memcg, false) : NUMAB_FOLLOW_SYSTEM;\n+\trcu_read_unlock();\n+\treturn mode;\n+}\n+\n+/*\n+ * The combined request for @folio's owner. An uncharged folio makes no\n+ * request. A folio charged to a memcg whose cgroup the kfunc cannot\n+ * reach carries no request and follows the global state.\n+ */\n+int folio_numab_mode(struct folio *folio)\n+{\n+\tstruct mem_cgroup *memcg;\n+\tint mode;\n+\n+\tif (mem_cgroup_disabled())\n+\t\treturn NUMAB_FOLLOW_SYSTEM;\n+\n+\trcu_read_lock();\n+\tmemcg = folio_memcg(folio);\n+\tmode = memcg ? numab_memcg_mode(memcg, true) : NUMAB_FOLLOW_SYSTEM;\n+\trcu_read_unlock();\n+\treturn mode;\n+}\n+\n+static DEFINE_MUTEX(numab_mode_mutex);\n+\n+/*\n+ * Reset the request when the memory controller is disabled, the memcg is\n+ * offlined or the memcg is pinned.  A memcg may be made visible again, so\n+ * it must start transparent.\n+ */\n+void numab_memcg_reset(struct mem_cgroup *memcg)\n+{\n+\tmutex_lock(\u0026numab_mode_mutex);\n+\tif (memcg-\u003enumab_mode != NUMAB_FOLLOW_SYSTEM) {\n+\t\tWRITE_ONCE(memcg-\u003enumab_mode, NUMAB_FOLLOW_SYSTEM);\n+\t\tstatic_branch_dec(\u0026numab_cgroup_mode_set);\n+\t}\n+\tmutex_unlock(\u0026numab_mode_mutex);\n+}\n+\n+__bpf_kfunc_start_defs();\n+\n+/**\n+ * bpf_numab_set_mode() - Set the NUMA balancing mode of a cgroup's memcg.\n+ * @cgid: kernfs id of the cgroup whose memcg is updated\n+ * @mode: NUMAB_FOLLOW_SYSTEM to defer to the global sysctl state, or a\n+ *        NUMAB_* mode. The kernel reads the bits independently, the way\n+ *        kernel.numa_balancing reads them, so\n+ *        NUMAB_NORMAL|NUMAB_TIERING engages both modes. A\n+ *        NUMAB_DISABLED request only speaks for the memcg's tasks, never\n+ *        for its memory, which follows the remaining requests of its\n+ *        ancestors.\n+ *\n+ * The cgroup must have a visible, online memory cgroup; otherwise the\n+ * update is rejected.\n+ *\n+ * Return: 0 on success; %-EINVAL for a mode outside the domain;\n+ *         %-ENOENT for an id that resolves to no cgroup; %-EOPNOTSUPP\n+ *         for a cgroup without a visible, online memcg.\n+ */\n+__bpf_kfunc int bpf_numab_set_mode(u64 cgid, enum numab_mode mode)\n+{\n+\tstruct cgroup_subsys_state *css;\n+\tstruct mem_cgroup *memcg;\n+\tstruct cgroup *cgrp;\n+\tint old;\n+\n+\tif (mode != NUMAB_FOLLOW_SYSTEM \u0026\u0026\n+\t    (mode \u003c 0 || mode \u003e NUMAB_NORMAL_TIERING))\n+\t\treturn -EINVAL;\n+\n+\tcgrp = __cgroup_get_from_id(cgid);\n+\tif (IS_ERR(cgrp))\n+\t\treturn PTR_ERR(cgrp);\n+\n+\tif (mem_cgroup_disabled()) {\n+\t\tcgroup_put(cgrp);\n+\t\treturn -EOPNOTSUPP;\n+\t}\n+\n+\trcu_read_lock();\n+\tcss = cgroup_css(cgrp, \u0026memory_cgrp_subsys);\n+\tmemcg = mem_cgroup_from_css(css);\n+\tif (memcg \u0026\u0026 !mem_cgroup_tryget_online(memcg))\n+\t\tmemcg = NULL;\n+\trcu_read_unlock();\n+\n+\tif (!memcg) {\n+\t\tcgroup_put(cgrp);\n+\t\treturn -EOPNOTSUPP;\n+\t}\n+\n+\tmutex_lock(\u0026numab_mode_mutex);\n+\tif (!numab_memcg_active(memcg)) {\n+\t\tmutex_unlock(\u0026numab_mode_mutex);\n+\t\tmem_cgroup_put(memcg);\n+\t\tcgroup_put(cgrp);\n+\t\treturn -EOPNOTSUPP;\n+\t}\n+\n+\told = READ_ONCE(memcg-\u003enumab_mode);\n+\tif (old == NUMAB_FOLLOW_SYSTEM \u0026\u0026 mode != NUMAB_FOLLOW_SYSTEM)\n+\t\tstatic_branch_inc(\u0026numab_cgroup_mode_set);\n+\telse if (old != NUMAB_FOLLOW_SYSTEM \u0026\u0026 mode == NUMAB_FOLLOW_SYSTEM)\n+\t\tstatic_branch_dec(\u0026numab_cgroup_mode_set);\n+\tWRITE_ONCE(memcg-\u003enumab_mode, (int)mode);\n+\tmutex_unlock(\u0026numab_mode_mutex);\n+\n+\tmem_cgroup_put(memcg);\n+\tcgroup_put(cgrp);\n+\treturn 0;\n+}\n+\n+/**\n+ * bpf_numab_get_mode() - Read the NUMA balancing mode that applies to a cgroup.\n+ * @cgid: kernfs id of the cgroup\n+ *\n+ * The combined task-side request of the cgroup's effective memcg and of\n+ * every ancestor: an opt-out wins, otherwise the requested bits OR\n+ * together, and the kernel reads them independently, as\n+ * kernel.numa_balancing does, so a combined\n+ * NUMAB_NORMAL|NUMAB_TIERING engages both modes. NUMAB_FOLLOW_SYSTEM\n+ * when nobody makes a request. If the cgroup\n+ * has no memcg, the nearest ancestor memcg is used. The folio-side view\n+ * stays internal to the kernel.\n+ *\n+ * Return: the combined mode, NUMAB_FOLLOW_SYSTEM (-1) included, or\n+ *         %-ENOENT for an id that resolves to no cgroup.\n+ */\n+__bpf_kfunc s64 bpf_numab_get_mode(u64 cgid)\n+{\n+\tstruct mem_cgroup *memcg;\n+\tstruct cgroup *cgrp;\n+\ts64 mode;\n+\n+\tcgrp = __cgroup_get_from_id(cgid);\n+\tif (IS_ERR(cgrp))\n+\t\treturn PTR_ERR(cgrp);\n+\n+\tif (mem_cgroup_disabled()) {\n+\t\tcgroup_put(cgrp);\n+\t\treturn NUMAB_FOLLOW_SYSTEM;\n+\t}\n+\n+\trcu_read_lock();\n+\tmemcg = mem_cgroup_from_css(cgroup_e_css(cgrp, \u0026memory_cgrp_subsys));\n+\tmode = memcg ? numab_memcg_mode(memcg, false) : NUMAB_FOLLOW_SYSTEM;\n+\trcu_read_unlock();\n+\n+\tcgroup_put(cgrp);\n+\treturn mode;\n+}\n+\n+__bpf_kfunc_end_defs();\n+\n+BTF_KFUNCS_START(numab_kfunc_ids)\n+BTF_ID_FLAGS(func, bpf_numab_set_mode, KF_SLEEPABLE)\n+BTF_ID_FLAGS(func, bpf_numab_get_mode)\n+BTF_KFUNCS_END(numab_kfunc_ids)\n+\n+static const struct btf_kfunc_id_set numab_kfunc_set = {\n+\t.owner = THIS_MODULE,\n+\t.set   = \u0026numab_kfunc_ids,\n+};\n+\n+static int __init numab_kfunc_init(void)\n+{\n+\tint ret;\n+\n+\tret = register_btf_kfunc_id_set(BPF_PROG_TYPE_SYSCALL, \u0026numab_kfunc_set);\n+\tif (ret)\n+\t\tpr_warn(\"numab: failed to register kfuncs: %d\\n\", ret);\n+\treturn ret;\n+}\n+late_initcall(numab_kfunc_init);\ndiff --git a/kernel/sched/build_policy.c b/kernel/sched/build_policy.c\nindex 2a828725a7f965..3746c6675ff325 100644\n--- a/kernel/sched/build_policy.c\n+++ b/kernel/sched/build_policy.c\n@@ -75,4 +75,8 @@\n # include \"ext/sub.c\"\n #endif\n \n+#ifdef CONFIG_BPF_NUMAB\n+#include \"bpf_numab.c\"\n+#endif\n+\n #include \"syscalls.c\"\ndiff --git a/kernel/sched/fair.c b/kernel/sched/fair.c\nindex cfc982205b98c6..6c2a7550eef522 100644\n--- a/kernel/sched/fair.c\n+++ b/kernel/sched/fair.c\n@@ -39,6 +39,7 @@\n #include \u003clinux/sched/cputime.h\u003e\n #include \u003clinux/sched/isolation.h\u003e\n #include \u003clinux/sched/nohz.h\u003e\n+#include \u003clinux/sched/numa_balancing.h\u003e\n #include \u003clinux/sched/prio.h\u003e\n #include \u003clinux/static_call.h\u003e\n \n@@ -1421,7 +1422,8 @@ static inline int get_sched_cache_scale(int mul)\n \treturn (1 + (tol - 1) * mul);\n }\n \n-static bool exceed_llc_capacity(struct sched_cache_group *grp, int cpu)\n+static bool exceed_llc_capacity(struct sched_cache_group *grp, int cpu,\n+\t\t\t\tbool numab_enabled)\n {\n #ifdef CONFIG_NUMA_BALANCING\n \tunsigned long llc, footprint;\n@@ -1434,7 +1436,7 @@ static bool exceed_llc_capacity(struct sched_cache_group *grp, int cpu)\n \tif (!sd)\n \t\treturn true;\n \n-\tif (static_branch_likely(\u0026sched_numa_balancing)) {\n+\tif (numab_enabled) {\n \t\t/*\n \t\t * TBD: RDT exclusive LLC ways reserved should be\n \t\t * excluded.\n@@ -1800,7 +1802,8 @@ static unsigned long fraction_mm_sched(struct rq *rq,\n \treturn div64_u64(NICE_0_LOAD * pcpu_sched-\u003eruntime, rq-\u003ecpu_runtime + 1);\n }\n \n-static int get_pref_llc(struct task_struct *p, struct sched_cache_group *grp)\n+static int get_pref_llc(struct task_struct *p, struct sched_cache_group *grp,\n+\t\t\tbool numab_enabled)\n {\n \tint mm_sched_llc = -1, mm_sched_cpu;\n \n@@ -1822,7 +1825,7 @@ static int get_pref_llc(struct task_struct *p, struct sched_cache_group *grp)\n \t\t * than sched_setnuma() at least -- and thus the\n \t\t * conflict only exists for a short period of time.\n \t\t */\n-\t\tif (static_branch_likely(\u0026sched_numa_balancing) \u0026\u0026\n+\t\tif (numab_enabled \u0026\u0026\n \t\t    p-\u003enuma_preferred_nid \u003e= 0 \u0026\u0026\n \t\t    cpu_to_node(mm_sched_cpu) != p-\u003enuma_preferred_nid)\n \t\t\tmm_sched_llc = -1;\n@@ -1841,6 +1844,7 @@ void account_mm_sched(struct rq *rq, struct task_struct *p, s64 delta_exec)\n \tstruct sched_cache_time *pcpu_sched;\n \tint mm_sched_llc = -1;\n \tunsigned long epoch;\n+\tbool numab_enabled;\n \n \tif (!sched_cache_enabled())\n \t\treturn;\n@@ -1874,14 +1878,19 @@ void account_mm_sched(struct rq *rq, struct task_struct *p, s64 delta_exec)\n \t * its preferred state.\n \t */\n \tif ((long)(epoch - READ_ONCE(grp-\u003eepoch)) \u003e llc_epoch_affinity_timeout ||\n-\t    invalid_llc_nr(grp, p, cpu_of(rq)) ||\n-\t    exceed_llc_capacity(grp, cpu_of(rq))) {\n+\t    invalid_llc_nr(grp, p, cpu_of(rq))) {\n \t\tif (READ_ONCE(grp-\u003ecpu) != -1)\n \t\t\tWRITE_ONCE(grp-\u003ecpu, -1);\n+\t} else {\n+\t\tnumab_enabled = task_numab_enabled(p);\n+\t\tif (exceed_llc_capacity(grp, cpu_of(rq), numab_enabled)) {\n+\t\t\tif (READ_ONCE(grp-\u003ecpu) != -1)\n+\t\t\t\tWRITE_ONCE(grp-\u003ecpu, -1);\n+\t\t} else {\n+\t\t\tmm_sched_llc = get_pref_llc(p, grp, numab_enabled);\n+\t\t}\n \t}\n \n-\tmm_sched_llc = get_pref_llc(p, grp);\n-\n \t/* task not on rq accounted later in account_entity_enqueue() */\n \tif (task_running_on_cpu(rq-\u003ecpu, p) \u0026\u0026\n \t    READ_ONCE(p-\u003epreferred_llc) != mm_sched_llc) {\n@@ -1918,12 +1927,12 @@ static void task_tick_cache(struct rq *rq, struct task_struct *p)\n }\n \n static void get_scan_cpumasks(cpumask_var_t cpus, struct task_struct *p,\n-\t\t\t      struct sched_cache_group *grp)\n+\t\t\t      struct sched_cache_group *grp, bool numab_enabled)\n {\n #ifdef CONFIG_NUMA_BALANCING\n \tint cpu, curr_cpu, nid, pref_nid;\n \n-\tif (!static_branch_likely(\u0026sched_numa_balancing))\n+\tif (!numab_enabled)\n \t\tgoto out;\n \n \tcpu = READ_ONCE(grp-\u003ecpu);\n@@ -1990,6 +1999,7 @@ static void task_cache_work(struct callback_head *work)\n \tstruct task_struct *p = current, *cur;\n \tunsigned long curr_m_a_occ = 0;\n \tunsigned long m_a_occ = 0;\n+\tbool numab_enabled;\n \n \tWARN_ON_ONCE(work != \u0026p-\u003ecache_work);\n \n@@ -2018,11 +2028,16 @@ static void task_cache_work(struct callback_head *work)\n \t\treturn;\n \n \tcurr_cpu = task_cpu(p);\n-\tif (invalid_llc_nr(grp, p, curr_cpu) ||\n-\t    exceed_llc_capacity(grp, curr_cpu)) {\n+\tif (invalid_llc_nr(grp, p, curr_cpu)) {\n \t\tif (READ_ONCE(grp-\u003ecpu) != -1)\n \t\t\tWRITE_ONCE(grp-\u003ecpu, -1);\n+\t\treturn;\n+\t}\n \n+\tnumab_enabled = task_numab_enabled(p);\n+\tif (exceed_llc_capacity(grp, curr_cpu, numab_enabled)) {\n+\t\tif (READ_ONCE(grp-\u003ecpu) != -1)\n+\t\t\tWRITE_ONCE(grp-\u003ecpu, -1);\n \t\treturn;\n \t}\n \n@@ -2032,7 +2047,7 @@ static void task_cache_work(struct callback_head *work)\n \tscoped_guard (cpus_read_lock) {\n \t\tguard(rcu)();\n \n-\t\tget_scan_cpumasks(cpus, p, grp);\n+\t\tget_scan_cpumasks(cpus, p, grp, numab_enabled);\n \n \t\tfor_each_cpu(cpu, cpus) {\n \t\t\t/* XXX sched_cluster_active */\n@@ -2137,7 +2152,8 @@ void init_sched_mm(struct task_struct *p) { }\n static void task_tick_cache(struct rq *rq, struct task_struct *p) { }\n \n static inline int get_pref_llc(struct task_struct *p,\n-\t\t\t       struct sched_cache_group *grp)\n+\t\t\t       struct sched_cache_group *grp,\n+\t\t\t       bool numab_enabled)\n {\n \treturn -1;\n }\n@@ -2866,6 +2882,9 @@ bool should_numa_migrate_memory(struct task_struct *p, struct folio *folio,\n \tstruct numa_group *ng = deref_curr_numa_group(p);\n \tint dst_nid = cpu_to_node(dst_cpu);\n \tint last_cpupid, this_cpupid;\n+\tbool tiering;\n+\n+\ttiering = folio_numab_in_tiering_mode(folio);\n \n \t/*\n \t * Cannot migrate to memoryless nodes.\n@@ -2877,7 +2896,7 @@ bool should_numa_migrate_memory(struct task_struct *p, struct folio *folio,\n \t * The pages in slow memory node should be migrated according\n \t * to hot/cold instead of private/shared.\n \t */\n-\tif (folio_use_access_time(folio)) {\n+\tif (tiering \u0026\u0026 !node_is_toptier(folio_nid(folio))) {\n \t\tstruct pglist_data *pgdat;\n \t\tunsigned long rate_limit;\n \t\tunsigned int latency, th, def_th;\n@@ -2906,8 +2925,8 @@ bool should_numa_migrate_memory(struct task_struct *p, struct folio *folio,\n \tthis_cpupid = cpu_pid_to_cpupid(dst_cpu, current-\u003epid);\n \tlast_cpupid = folio_xchg_last_cpupid(folio, this_cpupid);\n \n-\tif (!(sysctl_numa_balancing_mode \u0026 NUMA_BALANCING_MEMORY_TIERING) \u0026\u0026\n-\t    !node_is_toptier(src_nid) \u0026\u0026 !cpupid_valid(last_cpupid))\n+\tif (!tiering \u0026\u0026 !node_is_toptier(src_nid) \u0026\u0026\n+\t    !cpupid_valid(last_cpupid))\n \t\treturn false;\n \n \t/*\n@@ -4135,12 +4154,14 @@ void task_numa_fault(int last_cpupid, int mem_node, int pages, int flags)\n {\n \tstruct task_struct *p = current;\n \tbool migrated = flags \u0026 TNF_MIGRATED;\n+\tbool numab_enabled, numab_tiering;\n \tint cpu_node = task_node(current);\n \tint local = !!(flags \u0026 TNF_FAULT_LOCAL);\n \tstruct numa_group *ng;\n \tint priv;\n \n-\tif (!static_branch_likely(\u0026sched_numa_balancing))\n+\ttask_numab_get_modes(p, \u0026numab_enabled, \u0026numab_tiering);\n+\tif (!numab_enabled)\n \t\treturn;\n \n \t/* for example, ksmd faulting in a user's mm */\n@@ -4152,8 +4173,7 @@ void task_numa_fault(int last_cpupid, int mem_node, int pages, int flags)\n \t * node for memory tiering mode.\n \t */\n \tif (!node_is_toptier(mem_node) \u0026\u0026\n-\t    (sysctl_numa_balancing_mode \u0026 NUMA_BALANCING_MEMORY_TIERING ||\n-\t     !cpupid_valid(last_cpupid)))\n+\t    (numab_tiering || !cpupid_valid(last_cpupid)))\n \t\treturn;\n \n \t/* Allocate buffer to track faults on a per-node basis */\n@@ -4297,6 +4317,9 @@ static void task_numa_work(struct callback_head *work)\n \tif (p-\u003eflags \u0026 PF_EXITING)\n \t\treturn;\n \n+\tif (!task_numab_enabled(p))\n+\t\treturn;\n+\n \t/*\n \t * Memory is pinned to only one NUMA node via cpuset.mems, naturally\n \t * no page can be migrated.\n@@ -4601,6 +4624,11 @@ static void task_tick_numa(struct rq *rq, struct task_struct *curr)\n \t\t\tcurr-\u003enuma_scan_period = task_scan_start(curr);\n \t\tcurr-\u003enode_stamp += period;\n \n+\t\tif (!task_numab_enabled(curr)) {\n+\t\t\tcurr-\u003enode_stamp = now;\n+\t\t\treturn;\n+\t\t}\n+\n \t\tif (!time_before(jiffies, curr-\u003emm-\u003enuma_next_scan))\n \t\t\ttask_work_add(curr, work, TWA_RESUME);\n \t}\n@@ -4611,7 +4639,7 @@ static void update_scan_period(struct task_struct *p, int new_cpu)\n \tint src_nid = cpu_to_node(task_cpu(p));\n \tint dst_nid = cpu_to_node(new_cpu);\n \n-\tif (!static_branch_likely(\u0026sched_numa_balancing))\n+\tif (!task_numab_enabled(p))\n \t\treturn;\n \n \tif (!p-\u003emm || !p-\u003enuma_faults || (p-\u003eflags \u0026 PF_EXITING))\n@@ -10696,13 +10724,14 @@ static int task_hot(struct task_struct *p, struct lb_env *env)\n  * Returns 0, if task migration is not affected by locality.\n  * Returns a negative value, if task migration improves locality i.e migration preferred.\n  */\n-static long migrate_degrades_locality(struct task_struct *p, struct lb_env *env)\n+static long migrate_degrades_locality(struct task_struct *p, struct lb_env *env,\n+\t\t\t\t      bool numab_enabled)\n {\n \tstruct numa_group *numa_group = rcu_dereference_all(p-\u003enuma_group);\n \tunsigned long src_weight, dst_weight;\n \tint src_nid, dst_nid, dist;\n \n-\tif (!static_branch_likely(\u0026sched_numa_balancing))\n+\tif (!numab_enabled)\n \t\treturn 0;\n \n \tif (!p-\u003enuma_faults || !(env-\u003esd-\u003eflags \u0026 SD_NUMA))\n@@ -10744,7 +10773,8 @@ static long migrate_degrades_locality(struct task_struct *p, struct lb_env *env)\n \n #else /* !CONFIG_NUMA_BALANCING: */\n static inline long migrate_degrades_locality(struct task_struct *p,\n-\t\t\t\t\t     struct lb_env *env)\n+\t\t\t\t\t     struct lb_env *env,\n+\t\t\t\t\t     bool numab_enabled)\n {\n \treturn 0;\n }\n@@ -10946,7 +10976,8 @@ static inline bool sched_asym(struct sched_domain *sd, int dst_cpu, int src_cpu)\n  * destination LLC in terms of cache aware load balance.\n  */\n static enum llc_mig can_migrate_llc_task(struct lb_env *env,\n-\t\t\t\t\t struct task_struct *p)\n+\t\t\t\t\t struct task_struct *p,\n+\t\t\t\t\t bool numab_enabled)\n {\n \tstruct sched_cache_group *grp;\n \tbool to_pref;\n@@ -10971,7 +11002,7 @@ static enum llc_mig can_migrate_llc_task(struct lb_env *env,\n \n \t/* skip cache aware load balance for too many threads */\n \tif (invalid_llc_nr(grp, p, dst_cpu) ||\n-\t    exceed_llc_capacity(grp, dst_cpu)) {\n+\t    exceed_llc_capacity(grp, dst_cpu, numab_enabled)) {\n \t\tif (READ_ONCE(grp-\u003ecpu) != -1)\n \t\t\tWRITE_ONCE(grp-\u003ecpu, -1);\n \t\treturn mig_unrestricted;\n@@ -11060,7 +11091,8 @@ migrate_llc_task_wrong_dst(struct task_struct *p, struct lb_env *env)\n  * Check if migrating task p from env-\u003esrc_cpu to\n  * env-\u003edst_cpu breaks LLC localiy.\n  */\n-static bool migrate_degrades_llc(struct task_struct *p, struct lb_env *env)\n+static bool migrate_degrades_llc(struct task_struct *p, struct lb_env *env,\n+\t\t\t\t bool numab_enabled)\n {\n \tif (!sched_cache_enabled())\n \t\treturn false;\n@@ -11087,7 +11119,7 @@ static bool migrate_degrades_llc(struct task_struct *p, struct lb_env *env)\n \tif (migrate_llc_task_wrong_dst(p, env))\n \t\treturn true;\n \n-\tif (can_migrate_llc_task(env, p) != mig_forbid)\n+\tif (can_migrate_llc_task(env, p, numab_enabled) != mig_forbid)\n \t\treturn false;\n \n \treturn true;\n@@ -11113,7 +11145,8 @@ migrate_llc_task_wrong_dst(struct task_struct *p, struct lb_env *env)\n }\n \n static inline bool\n-migrate_degrades_llc(struct task_struct *p, struct lb_env *env)\n+migrate_degrades_llc(struct task_struct *p, struct lb_env *env,\n+\t\t     bool numab_enabled)\n {\n \treturn false;\n }\n@@ -11125,6 +11158,7 @@ static\n int can_migrate_task(struct task_struct *p, struct lb_env *env)\n {\n \tlong degrades, hot;\n+\tbool numab_enabled;\n \n \tlockdep_assert_rq_held(env-\u003esrc_rq);\n \tif (p-\u003esched_task_hot)\n@@ -11213,14 +11247,15 @@ int can_migrate_task(struct task_struct *p, struct lb_env *env)\n \tif (env-\u003eflags \u0026 LBF_ACTIVE_LB)\n \t\treturn !migrate_llc_task_wrong_dst(p, env);\n \n-\tdegrades = migrate_degrades_locality(p, env);\n+\tnumab_enabled = task_numab_enabled(p);\n+\tdegrades = migrate_degrades_locality(p, env, numab_enabled);\n \tif (!degrades) {\n \t\t/*\n \t\t * If the NUMA locality is not broken,\n \t\t * further check if migration would hurt\n \t\t * LLC locality.\n \t\t */\n-\t\tif (migrate_degrades_llc(p, env)) {\n+\t\tif (migrate_degrades_llc(p, env, numab_enabled)) {\n \t\t\t/*\n \t\t\t * If regular load balancing fails to pull a task\n \t\t\t * due to LLC locality, this is expected behavior\n@@ -15362,7 +15397,7 @@ static void task_tick_fair(struct rq *rq, struct task_struct *curr, int queued)\n \tif (queued)\n \t\treturn;\n \n-\tif (static_branch_unlikely(\u0026sched_numa_balancing))\n+\tif (task_numab_tick_possible())\n \t\ttask_tick_numa(rq, curr);\n \n \ttask_tick_cache(rq, curr);\ndiff --git a/kernel/sched/sched.h b/kernel/sched/sched.h\nindex 6c7c5633524a3b..9b616abf5c9c31 100644\n--- a/kernel/sched/sched.h\n+++ b/kernel/sched/sched.h\n@@ -2496,7 +2496,6 @@ extern union sched_feat_key sched_feat_keys[__SCHED_FEAT_NR];\n \n #endif /* !CONFIG_JUMP_LABEL */\n \n-extern struct static_key_false sched_numa_balancing;\n extern struct static_key_false sched_schedstats;\n \n static inline u64 global_rt_period(void)\ndiff --git a/mm/memcontrol.c b/mm/memcontrol.c\nindex a05d9a8baa1b6b..3971b5b3360bac 100644\n--- a/mm/memcontrol.c\n+++ b/mm/memcontrol.c\n@@ -31,6 +31,7 @@\n #include \u003clinux/cgroup.h\u003e\n #include \u003clinux/cpuset.h\u003e\n #include \u003clinux/sched/mm.h\u003e\n+#include \u003clinux/sched/numa_balancing.h\u003e\n #include \u003clinux/shmem_fs.h\u003e\n #include \u003clinux/hugetlb.h\u003e\n #include \u003clinux/pagemap.h\u003e\n@@ -4266,6 +4267,9 @@ static struct mem_cgroup *mem_cgroup_alloc(struct mem_cgroup *parent)\n \tif (!memcg)\n \t\treturn ERR_PTR(-ENOMEM);\n \n+#ifdef CONFIG_BPF_NUMAB\n+\tmemcg-\u003enumab_mode = NUMAB_FOLLOW_SYSTEM;\n+#endif\n \terror = xa_alloc(\u0026mem_cgroup_private_ids, \u0026memcg-\u003eprivate_id, NULL,\n \t\t\t XA_LIMIT(1, MEM_CGROUP_ID_MAX), GFP_KERNEL);\n \tif (error)\n@@ -4459,6 +4463,9 @@ static void mem_cgroup_css_offline(struct cgroup_subsys_state *css)\n {\n \tstruct mem_cgroup *memcg = mem_cgroup_from_css(css);\n \n+#ifdef CONFIG_BPF_NUMAB\n+\tnumab_memcg_reset(memcg);\n+#endif\n \tmemcg1_css_offline(memcg);\n \n \tpage_counter_set_min(\u0026memcg-\u003ememory, 0);\n@@ -4532,6 +4539,9 @@ static void mem_cgroup_css_reset(struct cgroup_subsys_state *css)\n {\n \tstruct mem_cgroup *memcg = mem_cgroup_from_css(css);\n \n+#ifdef CONFIG_BPF_NUMAB\n+\tnumab_memcg_reset(memcg);\n+#endif\n \tpage_counter_set_max(\u0026memcg-\u003ememory, PAGE_COUNTER_MAX);\n \tpage_counter_set_max(\u0026memcg-\u003eswap, PAGE_COUNTER_MAX);\n \tWRITE_ONCE(memcg-\u003eoom_group, false);\n@@ -5917,6 +5927,10 @@ static void __init memcg_struct_check(void)\n \t\t\t\t      kmemcg_id);\n \tCACHELINE_ASSERT_GROUP_MEMBER(struct mem_cgroup, memcg_read_mostly,\n \t\t\t\t      oom_group);\n+#ifdef CONFIG_BPF_NUMAB\n+\tCACHELINE_ASSERT_GROUP_MEMBER(struct mem_cgroup, memcg_read_mostly,\n+\t\t\t\t      numab_mode);\n+#endif\n \n \tCACHELINE_ASSERT_GROUP_MEMBER(struct mem_cgroup_per_node,\n \t\t\t\t      memcg_pn_read_mostly, memcg);\ndiff --git a/mm/memory-tiers.c b/mm/memory-tiers.c\nindex 25e121851b5862..7bfb92657e24ca 100644\n--- a/mm/memory-tiers.c\n+++ b/mm/memory-tiers.c\n@@ -6,6 +6,7 @@\n #include \u003clinux/memory.h\u003e\n #include \u003clinux/memory-tiers.h\u003e\n #include \u003clinux/notifier.h\u003e\n+#include \u003clinux/sched/numa_balancing.h\u003e\n #include \u003clinux/sched/sysctl.h\u003e\n \n #include \"internal.h\"\n@@ -56,15 +57,15 @@ static const struct bus_type memory_tier_subsys = {\n  * folio_use_access_time - check if a folio reuses cpupid for page access time\n  * @folio: folio to check\n  *\n- * folio's _last_cpupid field is repurposed by memory tiering. In memory\n- * tiering mode, cpupid of slow memory folio (not toptier memory) is used to\n- * record page access time.\n+ * folio's _last_cpupid field is repurposed by memory tiering. When the\n+ * owner of @folio participates in tiering, cpupid of slow memory folio\n+ * (not toptier memory) is used to record page access time.\n  *\n  * Return: the folio _last_cpupid is used to record page access time\n  */\n bool folio_use_access_time(struct folio *folio)\n {\n-\treturn (sysctl_numa_balancing_mode \u0026 NUMA_BALANCING_MEMORY_TIERING) \u0026\u0026\n+\treturn folio_numab_in_tiering_mode(folio) \u0026\u0026\n \t       !node_is_toptier(folio_nid(folio));\n }\n #endif\ndiff --git a/mm/mempolicy.c b/mm/mempolicy.c\nindex 0884c629670dd6..3534dc63b5a9c3 100644\n--- a/mm/mempolicy.c\n+++ b/mm/mempolicy.c\n@@ -854,7 +854,7 @@ static int queue_folios_hugetlb(pte_t *pte, unsigned long hmask,\n bool folio_can_map_prot_numa(struct folio *folio, struct vm_area_struct *vma,\n \t\tbool is_private_single_threaded)\n {\n-\tint nid;\n+\tint nid, mode;\n \n \tif (!folio || folio_is_zone_device(folio) || folio_test_ksm(folio))\n \t\treturn false;\n@@ -883,15 +883,16 @@ bool folio_can_map_prot_numa(struct folio *folio, struct vm_area_struct *vma,\n \tif (is_private_single_threaded \u0026\u0026 (nid == numa_node_id()))\n \t\treturn false;\n \n+\tmode = folio_numab_effective_mode(folio);\n+\n \t/*\n \t * Skip scanning top tier node if normal numa\n \t * balancing is disabled\n \t */\n-\tif (!(sysctl_numa_balancing_mode \u0026 NUMA_BALANCING_NORMAL) \u0026\u0026\n-\t    node_is_toptier(nid))\n+\tif (!(mode \u0026 NUMAB_NORMAL) \u0026\u0026 node_is_toptier(nid))\n \t\treturn false;\n \n-\tif (folio_use_access_time(folio))\n+\tif ((mode \u0026 NUMAB_TIERING) \u0026\u0026 !node_is_toptier(nid))\n \t\tfolio_xchg_access_time(folio, jiffies_to_msecs(jiffies));\n \n \treturn true;\ndiff --git a/mm/migrate.c b/mm/migrate.c\nindex 7bdcdb57652f8f..f3a84a5903aa0c 100644\n--- a/mm/migrate.c\n+++ b/mm/migrate.c\n@@ -41,6 +41,7 @@\n #include \u003clinux/ptrace.h\u003e\n #include \u003clinux/memory.h\u003e\n #include \u003clinux/sched/sysctl.h\u003e\n+#include \u003clinux/sched/numa_balancing.h\u003e\n #include \u003clinux/memory-tiers.h\u003e\n #include \u003clinux/pagewalk.h\u003e\n \n@@ -818,7 +819,7 @@ void folio_migrate_flags(struct folio *newfolio, struct folio *folio)\n \t * memory node, reset cpupid, because that is used to record\n \t * page access time in slow memory node.\n \t */\n-\tif (sysctl_numa_balancing_mode \u0026 NUMA_BALANCING_MEMORY_TIERING) {\n+\tif (folio_numab_in_tiering_mode(folio)) {\n \t\tbool f_toptier = node_is_toptier(folio_nid(folio));\n \t\tbool t_toptier = node_is_toptier(folio_nid(newfolio));\n \n@@ -2717,7 +2718,7 @@ int migrate_misplaced_folio_prepare(struct folio *folio,\n \tif (!migrate_balanced_pgdat(pgdat, nr_pages)) {\n \t\tint z;\n \n-\t\tif (!(sysctl_numa_balancing_mode \u0026 NUMA_BALANCING_MEMORY_TIERING))\n+\t\tif (!folio_numab_in_tiering_mode(folio))\n \t\t\treturn -EAGAIN;\n \t\tfor (z = pgdat-\u003enr_zones - 1; z \u003e= 0; z--) {\n \t\t\tif (managed_zone(pgdat-\u003enode_zones + z))\n@@ -2759,6 +2760,7 @@ int migrate_misplaced_folio(struct folio *folio, int node)\n \tLIST_HEAD(migratepages);\n \tstruct mem_cgroup *memcg = get_mem_cgroup_from_folio(folio);\n \tstruct lruvec *lruvec = mem_cgroup_lruvec(memcg, pgdat);\n+\tbool folio_tiering = folio_numab_in_tiering_mode(folio);\n \n \tlist_add(\u0026folio-\u003elru, \u0026migratepages);\n \tnr_remaining = migrate_pages(\u0026migratepages, alloc_misplaced_dst_folio,\n@@ -2769,8 +2771,7 @@ int migrate_misplaced_folio(struct folio *folio, int node)\n \tif (nr_succeeded) {\n \t\tcount_vm_numa_events(NUMA_PAGE_MIGRATE, nr_succeeded);\n \t\tcount_memcg_events(memcg, NUMA_PAGE_MIGRATE, nr_succeeded);\n-\t\tif ((sysctl_numa_balancing_mode \u0026 NUMA_BALANCING_MEMORY_TIERING)\n-\t\t    \u0026\u0026 !node_is_toptier(folio_nid(folio))\n+\t\tif (folio_tiering \u0026\u0026 !node_is_toptier(folio_nid(folio))\n \t\t    \u0026\u0026 node_is_toptier(node))\n \t\t\tmod_lruvec_state(lruvec, PGPROMOTE_SUCCESS, nr_succeeded);\n \t}\ndiff --git a/mm/vmscan.c b/mm/vmscan.c\nindex 9959ca158ce835..7ef4205b6a4e77 100644\n--- a/mm/vmscan.c\n+++ b/mm/vmscan.c\n@@ -65,6 +65,7 @@\n \n #include \u003clinux/swapops.h\u003e\n #include \u003clinux/sched/sysctl.h\u003e\n+#include \u003clinux/sched/numa_balancing.h\u003e\n \n #include \"internal.h\"\n #include \"page_alloc.h\"\n@@ -5224,8 +5225,7 @@ static bool should_abort_scan(struct lruvec *lruvec, struct scan_control *sc)\n \tif (!current_is_kswapd() || sc-\u003eorder)\n \t\treturn false;\n \n-\tmark = sysctl_numa_balancing_mode \u0026 NUMA_BALANCING_MEMORY_TIERING ?\n-\t       WMARK_PROMO : WMARK_HIGH;\n+\tmark = numab_in_tiering_mode() ? WMARK_PROMO : WMARK_HIGH;\n \n \tfor (i = 0; i \u003c= sc-\u003ereclaim_idx; i++) {\n \t\tstruct zone *zone = lruvec_pgdat(lruvec)-\u003enode_zones + i;\n@@ -7131,7 +7131,7 @@ static bool pgdat_balanced(pg_data_t *pgdat, int order, int highest_zoneidx)\n \t\tenum zone_stat_item item;\n \t\tunsigned long free_pages;\n \n-\t\tif (sysctl_numa_balancing_mode \u0026 NUMA_BALANCING_MEMORY_TIERING)\n+\t\tif (numab_in_tiering_mode())\n \t\t\tmark = promo_wmark_pages(zone);\n \t\telse\n \t\t\tmark = high_wmark_pages(zone);\ndiff --git a/tools/testing/selftests/bpf/config b/tools/testing/selftests/bpf/config\nindex 49dfe939467cc8..e56c8872e51a04 100644\n--- a/tools/testing/selftests/bpf/config\n+++ b/tools/testing/selftests/bpf/config\n@@ -7,6 +7,7 @@ CONFIG_BPF_JIT=y\n CONFIG_BPF_KPROBE_OVERRIDE=y\n CONFIG_BPF_LIRC_MODE2=y\n CONFIG_BPF_LSM=y\n+CONFIG_BPF_NUMAB=y\n CONFIG_BPF_STREAM_PARSER=y\n CONFIG_BPF_SYSCALL=y\n # CONFIG_BPF_UNPRIV_DEFAULT_OFF is not set\n@@ -78,6 +79,7 @@ CONFIG_NET_CLS_FLOWER=y\n CONFIG_NET_CLS_MATCHALL=y\n CONFIG_NET_FOU=y\n CONFIG_NET_FOU_IP_TUNNELS=y\n+CONFIG_NUMA_BALANCING=y\n CONFIG_NET_IPGRE=y\n CONFIG_NET_IPGRE_DEMUX=y\n CONFIG_NET_IPIP=y\ndiff --git a/tools/testing/selftests/bpf/prog_tests/bpf_numab.c b/tools/testing/selftests/bpf/prog_tests/bpf_numab.c\nnew file mode 100644\nindex 00000000000000..6fb6a4d9f29194\n--- /dev/null\n+++ b/tools/testing/selftests/bpf/prog_tests/bpf_numab.c\n@@ -0,0 +1,273 @@\n+// SPDX-License-Identifier: GPL-2.0\n+\n+#include \u003ctest_progs.h\u003e\n+#include \"cgroup_helpers.h\"\n+#include \"bpf_numab.skel.h\"\n+\n+#define CGROUP_PATH\t\"/bpf_numab\"\n+#define CHILD_PATH\tCGROUP_PATH \"/child\"\n+#define HIER_PATH\t\"/bpf_numab_hier\"\n+#define HIER_CHILD_PATH\tHIER_PATH \"/child\"\n+#define NOMEM_PATH\t\"/bpf_numab_nomem\"\n+#define NOMEM_CHILD_PATH NOMEM_PATH \"/child\"\n+\n+/* The per-cgroup request domain, mirroring the kernel constants. */\n+#define NUMAB_FOLLOW_SYSTEM\t(-1)\n+#define NUMAB_DISABLED\t\t0\n+#define NUMAB_NORMAL\t\t1\n+#define NUMAB_TIERING\t\t2\n+#define NUMAB_NORMAL_TIERING\t3\n+\n+static int numab_set(struct bpf_numab *skel, u64 cgid,\n+\t\t     long mode)\n+{\n+\tLIBBPF_OPTS(bpf_test_run_opts, opts);\n+\tint ret;\n+\n+\tskel-\u003ebss-\u003eset_cgid = cgid;\n+\tskel-\u003ebss-\u003eset_mode = mode;\n+\tret = bpf_prog_test_run_opts(bpf_program__fd(skel-\u003eprogs.numab_set),\n+\t\t\t\t     \u0026opts);\n+\tif (!ASSERT_OK(ret, \"set run\"))\n+\t\treturn -1;\n+\treturn skel-\u003ebss-\u003eset_ret;\n+}\n+\n+static long numab_get(struct bpf_numab *skel, u64 cgid)\n+{\n+\tLIBBPF_OPTS(bpf_test_run_opts, opts);\n+\tint ret;\n+\n+\tskel-\u003ebss-\u003eget_cgid = cgid;\n+\tret = bpf_prog_test_run_opts(bpf_program__fd(skel-\u003eprogs.numab_get),\n+\t\t\t\t     \u0026opts);\n+\tif (!ASSERT_OK(ret, \"get run\"))\n+\t\treturn -EIO;\n+\treturn skel-\u003ebss-\u003eget_mode;\n+}\n+\n+static void test_set_get(void)\n+{\n+\tstruct bpf_numab *skel;\n+\tint cgroup_fd;\n+\tu64 cgid;\n+\n+\tcgroup_fd = test__join_cgroup(CGROUP_PATH);\n+\tif (!ASSERT_GE(cgroup_fd, 0, \"join_cgroup\"))\n+\t\treturn;\n+\n+\tskel = bpf_numab__open_and_load();\n+\tif (!ASSERT_OK_PTR(skel, \"open_and_load\"))\n+\t\tgoto cleanup;\n+\n+\tcgid = get_cgroup_id(CGROUP_PATH);\n+\tif (!ASSERT_GT(cgid, 0, \"get_cgroup_id\"))\n+\t\tgoto cleanup;\n+\n+\tASSERT_EQ(numab_set(skel, cgid, NUMAB_NORMAL), 0, \"set normal\");\n+\tASSERT_EQ(numab_get(skel, cgid), NUMAB_NORMAL, \"get normal\");\n+\n+\tASSERT_EQ(numab_set(skel, cgid, NUMAB_TIERING), 0, \"set tiering\");\n+\tASSERT_EQ(numab_get(skel, cgid), NUMAB_TIERING, \"get tiering\");\n+\n+\tASSERT_EQ(numab_set(skel, cgid, NUMAB_NORMAL_TIERING), 0, \"set both\");\n+\tASSERT_EQ(numab_get(skel, cgid), NUMAB_NORMAL_TIERING, \"get both\");\n+\n+\tASSERT_EQ(numab_set(skel, cgid, NUMAB_DISABLED), 0, \"set disabled\");\n+\tASSERT_EQ(numab_get(skel, cgid), NUMAB_DISABLED, \"get disabled\");\n+\n+\t/* Back to the system setting. */\n+\tASSERT_EQ(numab_set(skel, cgid, NUMAB_FOLLOW_SYSTEM), 0, \"unset\");\n+\tASSERT_EQ(numab_get(skel, cgid), NUMAB_FOLLOW_SYSTEM, \"get unset\");\n+\n+cleanup:\n+\tbpf_numab__destroy(skel);\n+\tclose(cgroup_fd);\n+}\n+\n+static void test_invalid_mode(void)\n+{\n+\tstruct bpf_numab *skel;\n+\tint cgroup_fd;\n+\tu64 cgid;\n+\n+\tcgroup_fd = test__join_cgroup(CGROUP_PATH);\n+\tif (!ASSERT_GE(cgroup_fd, 0, \"join_cgroup\"))\n+\t\treturn;\n+\n+\tskel = bpf_numab__open_and_load();\n+\tif (!ASSERT_OK_PTR(skel, \"open_and_load\"))\n+\t\tgoto cleanup;\n+\n+\tcgid = get_cgroup_id(CGROUP_PATH);\n+\tif (!ASSERT_GT(cgid, 0, \"get_cgroup_id\"))\n+\t\tgoto cleanup;\n+\n+\tASSERT_EQ(numab_set(skel, cgid, -2), -EINVAL, \"set below domain\");\n+\tASSERT_EQ(numab_set(skel, cgid, 4), -EINVAL, \"set above domain\");\n+\tASSERT_EQ(numab_set(skel, cgid, 0x1000), -EINVAL, \"set far above\");\n+\n+\t/* The rejected requests must not have stuck. */\n+\tASSERT_EQ(numab_get(skel, cgid), NUMAB_FOLLOW_SYSTEM, \"get unchanged\");\n+\n+cleanup:\n+\tbpf_numab__destroy(skel);\n+\tclose(cgroup_fd);\n+}\n+\n+static void test_bad_cgid(void)\n+{\n+\tstruct bpf_numab *skel;\n+\n+\tskel = bpf_numab__open_and_load();\n+\tif (!ASSERT_OK_PTR(skel, \"open_and_load\"))\n+\t\treturn;\n+\n+\tASSERT_EQ(numab_set(skel, 0, NUMAB_NORMAL), -ENOENT, \"set cgid 0\");\n+\tASSERT_EQ(numab_get(skel, 0), -ENOENT, \"get cgid 0\");\n+\tASSERT_EQ(numab_set(skel, 0xdeadbeef, NUMAB_NORMAL), -ENOENT,\n+\t\t  \"set bad cgid\");\n+\tASSERT_EQ(numab_get(skel, 0xdeadbeef), -ENOENT, \"get bad cgid\");\n+\n+\tbpf_numab__destroy(skel);\n+}\n+\n+static void test_hierarchy(void)\n+{\n+\tu64 parent_cgid, child_cgid;\n+\tint runner_fd, parent_fd, child_fd;\n+\tstruct bpf_numab *skel;\n+\n+\trunner_fd = test__join_cgroup(\"/bpf_numab_runner\");\n+\tif (!ASSERT_GE(runner_fd, 0, \"join_runner_cgroup\"))\n+\t\treturn;\n+\n+\tparent_fd = create_and_get_cgroup(HIER_PATH);\n+\tif (!ASSERT_GE(parent_fd, 0, \"create_parent_cgroup\"))\n+\t\tgoto cleanup_runner;\n+\n+\tif (!ASSERT_OK(enable_controllers(HIER_PATH, \"memory\"),\n+\t\t       \"enable_memory_controller\"))\n+\t\tgoto cleanup_parent;\n+\n+\tchild_fd = create_and_get_cgroup(HIER_CHILD_PATH);\n+\tif (!ASSERT_GE(child_fd, 0, \"create_child_cgroup\"))\n+\t\tgoto cleanup_parent;\n+\n+\tskel = bpf_numab__open_and_load();\n+\tif (!ASSERT_OK_PTR(skel, \"open_and_load\"))\n+\t\tgoto cleanup;\n+\n+\tparent_cgid = get_cgroup_id(HIER_PATH);\n+\tchild_cgid = get_cgroup_id(HIER_CHILD_PATH);\n+\tif (!ASSERT_GT(parent_cgid, 0, \"get_parent_cgid\") ||\n+\t    !ASSERT_GT(child_cgid, 0, \"get_child_cgid\"))\n+\t\tgoto cleanup;\n+\n+\t/* The child inherits an ancestor's request untouched. */\n+\tASSERT_EQ(numab_set(skel, parent_cgid, NUMAB_TIERING), 0,\n+\t\t  \"set parent tiering\");\n+\tASSERT_EQ(numab_get(skel, child_cgid), NUMAB_TIERING,\n+\t\t  \"child inherits\");\n+\n+\t/* A request ORs with the ancestor's; NORMAL does not undo TIERING. */\n+\tASSERT_EQ(numab_set(skel, child_cgid, NUMAB_NORMAL), 0,\n+\t\t  \"set child normal\");\n+\tASSERT_EQ(numab_get(skel, child_cgid), NUMAB_NORMAL_TIERING,\n+\t\t  \"or both\");\n+\n+\t/* The child's own opt-out wins. */\n+\tASSERT_EQ(numab_set(skel, child_cgid, NUMAB_DISABLED), 0,\n+\t\t  \"set child disabled\");\n+\tASSERT_EQ(numab_get(skel, child_cgid), NUMAB_DISABLED,\n+\t\t  \"own opt-out wins\");\n+\n+\t/* So does an ancestor's: a task is never forced into balancing. */\n+\tASSERT_EQ(numab_set(skel, child_cgid, NUMAB_TIERING), 0,\n+\t\t  \"set child tiering\");\n+\tASSERT_EQ(numab_set(skel, parent_cgid, NUMAB_DISABLED), 0,\n+\t\t  \"set parent disabled\");\n+\tASSERT_EQ(numab_get(skel, child_cgid), NUMAB_DISABLED,\n+\t\t  \"ancestor opt-out wins\");\n+\n+\t/* Unsetting the parent re-exposes the child's own request. */\n+\tASSERT_EQ(numab_set(skel, parent_cgid, NUMAB_FOLLOW_SYSTEM), 0,\n+\t\t  \"unset parent\");\n+\tASSERT_EQ(numab_get(skel, child_cgid), NUMAB_TIERING,\n+\t\t  \"child request again\");\n+\n+\t/* Unsetting the child leaves the chain with no request. */\n+\tASSERT_EQ(numab_set(skel, child_cgid, NUMAB_FOLLOW_SYSTEM), 0,\n+\t\t  \"unset child\");\n+\tASSERT_EQ(numab_get(skel, child_cgid), NUMAB_FOLLOW_SYSTEM,\n+\t\t  \"no request\");\n+\n+cleanup:\n+\tbpf_numab__destroy(skel);\n+\tclose(child_fd);\n+\tremove_cgroup(HIER_CHILD_PATH);\n+cleanup_parent:\n+\tclose(parent_fd);\n+\tremove_cgroup(HIER_PATH);\n+cleanup_runner:\n+\tclose(runner_fd);\n+}\n+\n+static void test_no_memcg(void)\n+{\n+\tstruct bpf_numab *skel;\n+\tint parent_fd, child_fd;\n+\tu64 parent_cgid, child_cgid;\n+\n+\tparent_fd = test__join_cgroup(NOMEM_PATH);\n+\tif (!ASSERT_GE(parent_fd, 0, \"join_nomem_parent\"))\n+\t\treturn;\n+\n+\tchild_fd = create_and_get_cgroup(NOMEM_CHILD_PATH);\n+\tif (!ASSERT_GE(child_fd, 0, \"create_nomem_child\"))\n+\t\tgoto cleanup_parent;\n+\n+\tskel = bpf_numab__open_and_load();\n+\tif (!ASSERT_OK_PTR(skel, \"open_and_load\"))\n+\t\tgoto cleanup;\n+\n+\tparent_cgid = get_cgroup_id(NOMEM_PATH);\n+\tchild_cgid = get_cgroup_id(NOMEM_CHILD_PATH);\n+\tif (!ASSERT_GT(parent_cgid, 0, \"get_nomem_parent_cgid\") ||\n+\t    !ASSERT_GT(child_cgid, 0, \"get_nomem_child_cgid\"))\n+\t\tgoto cleanup;\n+\n+\t/*\n+\t * The parent has a memcg; the child was created without enabling\n+\t * the memory controller in the parent's subtree, so it has none.\n+\t */\n+\tASSERT_EQ(numab_set(skel, parent_cgid, NUMAB_NORMAL), 0,\n+\t\t  \"set parent normal\");\n+\tASSERT_EQ(numab_get(skel, child_cgid), NUMAB_NORMAL,\n+\t\t  \"child resolves to parent memcg\");\n+\tASSERT_EQ(numab_set(skel, child_cgid, NUMAB_TIERING), -EOPNOTSUPP,\n+\t\t  \"child set rejected\");\n+\tASSERT_EQ(numab_get(skel, child_cgid), NUMAB_NORMAL,\n+\t\t  \"child get unchanged\");\n+\n+cleanup:\n+\tbpf_numab__destroy(skel);\n+\tclose(child_fd);\n+\tremove_cgroup(NOMEM_CHILD_PATH);\n+cleanup_parent:\n+\tclose(parent_fd);\n+}\n+\n+void test_bpf_numab(void)\n+{\n+\tif (test__start_subtest(\"set_get\"))\n+\t\ttest_set_get();\n+\tif (test__start_subtest(\"invalid_mode\"))\n+\t\ttest_invalid_mode();\n+\tif (test__start_subtest(\"bad_cgid\"))\n+\t\ttest_bad_cgid();\n+\tif (test__start_subtest(\"hierarchy\"))\n+\t\ttest_hierarchy();\n+\tif (test__start_subtest(\"no_memcg\"))\n+\t\ttest_no_memcg();\n+}\ndiff --git a/tools/testing/selftests/bpf/progs/bpf_numab.c b/tools/testing/selftests/bpf/progs/bpf_numab.c\nnew file mode 100644\nindex 00000000000000..25da97bce82ff2\n--- /dev/null\n+++ b/tools/testing/selftests/bpf/progs/bpf_numab.c\n@@ -0,0 +1,32 @@\n+// SPDX-License-Identifier: GPL-2.0\n+\n+#include \u003cvmlinux.h\u003e\n+#include \u003cbpf/bpf_helpers.h\u003e\n+\n+/* Inputs, set from userspace before each run. */\n+u64 set_cgid;\n+long set_mode;\n+u64 get_cgid;\n+\n+/* Results, read back after each run. */\n+long set_ret;\n+long get_mode;\n+\n+extern int bpf_numab_set_mode(u64 cgid, enum numab_mode mode) __ksym;\n+extern s64 bpf_numab_get_mode(u64 cgid) __ksym;\n+\n+SEC(\"syscall\")\n+int numab_set(void *ctx)\n+{\n+\tset_ret = bpf_numab_set_mode(set_cgid, (enum numab_mode)set_mode);\n+\treturn 0;\n+}\n+\n+SEC(\"syscall\")\n+int numab_get(void *ctx)\n+{\n+\tget_mode = bpf_numab_get_mode(get_cgid);\n+\treturn 0;\n+}\n+\n+char _license[] SEC(\"license\") = \"GPL\";\n"
}

2/1 2026/11/13 02:22 agent patch-evaluator
6m Model:
core

Args:
null

Results:
{
  "EnableConfigs": [
    "BPF_NUMAB",
    "NUMA_BALANCING",
    "MEMCG",
    "BPF_SYSCALL",
    "DEBUG_INFO_BTF",
    "NUMA"
  ],
  "FocusSymbols": [
    "bpf_numab_set_mode",
    "bpf_numab_get_mode",
    "task_numab_mode",
    "folio_numab_mode",
    "numab_memcg_reset",
    "task_numa_fault",
    "should_numa_migrate_memory",
    "migrate_misplaced_folio",
    "folio_can_map_prot_numa"
  ],
  "Reasoning": "The patch introduces per-cgroup NUMA balancing mode selection via BPF kfuncs (bpf_numab_set_mode, bpf_numab_get_mode) and modifies NUMA balancing scan, fault handling, and folio migration logic across the scheduler and memory management subsystems (fair.c, mempolicy.c, migrate.c, memory-tiers.c). These changes are in core, reachable code paths in virtualized environments with NUMA and cgroups enabled.",
  "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 1c523a70068adf269503582cd4945bd6c12b20f8
Author: syz-cluster <triage@syzkaller.com>
Date:   Fri Nov 13 02:22:16 2026 +0000

    syz-cluster: applied patch under review

diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index 69e1bcc67c588d..78ea21bfab95e0 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -342,6 +342,12 @@ struct mem_cgroup {
 	 */
 	bool zswap_writeback;
 #endif
+
+#ifdef CONFIG_BPF_NUMAB
+	/* per-cgroup NUMA balancing mode request; -1 follows the global state. */
+	int numab_mode;
+#endif
+
 	/* Not padded: nodeinfo[] is read-mostly too, let it share the line. */
 	__cacheline_group_end(memcg_read_mostly);
 
diff --git a/include/linux/sched/numa_balancing.h b/include/linux/sched/numa_balancing.h
index 52b22c5c396db0..e10093386cf739 100644
--- a/include/linux/sched/numa_balancing.h
+++ b/include/linux/sched/numa_balancing.h
@@ -8,6 +8,7 @@
  */
 
 #include <linux/sched.h>
+#include <linux/sched/sysctl.h>
 
 #define TNF_MIGRATED	0x01
 #define TNF_NO_GROUP	0x02
@@ -32,6 +33,122 @@ extern void set_numabalancing_state(bool enabled);
 extern void task_numa_free(struct task_struct *p, bool final);
 bool should_numa_migrate_memory(struct task_struct *p, struct folio *folio,
 				int src_nid, int dst_cpu);
+
+extern struct static_key_false sched_numa_balancing;
+
+/*
+ * Mode values used by the NUMA balancing helpers.
+ */
+enum numab_mode {
+	NUMAB_FOLLOW_SYSTEM	= -1,
+	NUMAB_DISABLED		= NUMA_BALANCING_DISABLED,
+	NUMAB_NORMAL		= NUMA_BALANCING_NORMAL,
+	NUMAB_TIERING		= NUMA_BALANCING_MEMORY_TIERING,
+	NUMAB_NORMAL_TIERING	= NUMA_BALANCING_NORMAL |
+				  NUMA_BALANCING_MEMORY_TIERING,
+};
+
+#ifdef CONFIG_BPF_NUMAB
+extern struct static_key_false numab_cgroup_mode_set;
+
+int task_numab_mode(struct task_struct *p);
+int folio_numab_mode(struct folio *folio);
+void numab_memcg_reset(struct mem_cgroup *memcg);
+#endif
+
+/*
+ * Whether any task might need the NUMA scanner on this tick.  This is
+ * only the cheap global gate; the per-task request is checked after the
+ * scan period in task_tick_numa().
+ */
+static inline bool task_numab_tick_possible(void)
+{
+#ifdef CONFIG_BPF_NUMAB
+	if (static_branch_likely(&numab_cgroup_mode_set))
+		return true;
+#endif
+	return static_branch_unlikely(&sched_numa_balancing);
+}
+
+/*
+ * Whether NUMA balancing applies to @p: the global sysctl state, possibly
+ * overridden by the requests of @p's memcg and of every ancestor.
+ * A memcg's request always takes priority over the system setting.
+ */
+static inline bool task_numab_enabled(struct task_struct *p)
+{
+#ifdef CONFIG_BPF_NUMAB
+	if (static_branch_unlikely(&numab_cgroup_mode_set)) {
+		int mode = task_numab_mode(p);
+
+		if (mode != NUMAB_FOLLOW_SYSTEM)
+			return mode != NUMAB_DISABLED;
+	}
+#endif
+	return static_branch_likely(&sched_numa_balancing);
+}
+
+/* Whether NUMA balancing is in memory tiering mode. */
+static inline bool numab_in_tiering_mode(void)
+{
+	return sysctl_numa_balancing_mode & NUMA_BALANCING_MEMORY_TIERING;
+}
+
+/*
+ * Return both task-side decisions from one request lookup.  This is used
+ * by paths that need to know both whether to account the fault and
+ * whether slow-tier faults should be skipped.
+ */
+static inline void task_numab_get_modes(struct task_struct *p, bool *enabled,
+					bool *tiering)
+{
+#ifdef CONFIG_BPF_NUMAB
+	if (static_branch_unlikely(&numab_cgroup_mode_set)) {
+		int mode = task_numab_mode(p);
+
+		if (mode != NUMAB_FOLLOW_SYSTEM) {
+			*enabled = mode != NUMAB_DISABLED;
+			*tiering = mode & NUMAB_TIERING;
+			return;
+		}
+	}
+#endif
+	*enabled = static_branch_likely(&sched_numa_balancing);
+	*tiering = numab_in_tiering_mode();
+}
+
+/*
+ * The combined folio-side request, with the global sysctl state used when
+ * no memcg requests a mode.  DISABLED never speaks for memory, so only
+ * NORMAL and TIERING are present here.  Callers that need more than one
+ * bit should use this helper once rather than querying each bit
+ * separately.
+ */
+static inline int folio_numab_effective_mode(struct folio *folio)
+{
+#ifdef CONFIG_BPF_NUMAB
+	if (static_branch_unlikely(&numab_cgroup_mode_set)) {
+		int mode = folio_numab_mode(folio);
+
+		if (mode != NUMAB_FOLLOW_SYSTEM)
+			return mode;
+	}
+#endif
+	return sysctl_numa_balancing_mode;
+}
+
+/*
+ * Whether @folio's memory participates in tiering, i.e. whether its
+ * _last_cpupid carries an access time instead of a cpupid. The
+ * requests of the owner memcg and of every ancestor are combined.
+ * DISABLED never speaks for memory (it is a task-side request), so only
+ * NORMAL and TIERING are consulted here; without either, the global
+ * sysctl decides.
+ */
+static inline bool folio_numab_in_tiering_mode(struct folio *folio)
+{
+	return folio_numab_effective_mode(folio) & NUMAB_TIERING;
+}
 #else
 static inline void task_numa_fault(int last_node, int node, int pages,
 				   int flags)
@@ -52,6 +169,33 @@ static inline bool should_numa_migrate_memory(struct task_struct *p,
 {
 	return true;
 }
+
+static inline bool task_numab_enabled(struct task_struct *p)
+{
+	return false;
+}
+
+static inline bool numab_in_tiering_mode(void)
+{
+	return false;
+}
+
+static inline bool folio_numab_in_tiering_mode(struct folio *folio)
+{
+	return false;
+}
+
+static inline void task_numab_get_modes(struct task_struct *p, bool *enabled,
+					bool *tiering)
+{
+	*enabled = false;
+	*tiering = false;
+}
+
+static inline bool task_numab_tick_possible(void)
+{
+	return false;
+}
 #endif
 
 #endif /* _LINUX_SCHED_NUMA_BALANCING_H */
diff --git a/init/Kconfig b/init/Kconfig
index 4013781e0a0292..3f38cf8077a3ca 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -827,6 +827,29 @@ config NUMA_BALANCING
 
 	  This system will be inactive on UMA systems.
 
+config BPF_NUMAB
+	bool "Per-cgroup NUMA balancing mode selection"
+	default n
+	depends on NUMA_BALANCING && MEMCG && BPF_SYSCALL && DEBUG_INFO_BTF
+	help
+	  Allow BPF programs to select the NUMA balancing mode (disabled,
+	  normal, memory tiering, or both) on a per-cgroup basis, overriding the
+	  global NUMA balancing sysctl. A latency-sensitive service can
+	  opt its tasks out of balancing, or a batch service can have its
+	  PMEM-resident memory promoted when hot, without changing the
+	  mode for the rest of the system.
+
+	  The request is written and read back through the
+	  bpf_numab_set_mode() and bpf_numab_get_mode() kfuncs, callable
+	  from BPF_PROG_TYPE_SYSCALL programs. The mode is stored in the
+	  target cgroup's memcg; setting it on a cgroup without the memory
+	  controller enabled is rejected.  This interface only applies to
+	  cgroups on the default hierarchy (cgroup v2).  While no memcg
+	  makes a request, the NUMA balancing hot paths pay a single
+	  patched-out branch and nothing else.
+
+	  If unsure, say N.
+
 config SCHED_CACHE
 	bool "Cache aware load balance"
 	default y
diff --git a/kernel/sched/bpf_numab.c b/kernel/sched/bpf_numab.c
new file mode 100644
index 00000000000000..c7f44bf383f61d
--- /dev/null
+++ b/kernel/sched/bpf_numab.c
@@ -0,0 +1,261 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Per-cgroup NUMA balancing mode
+ *
+ * A cgroup overrides the global state through its memcg. Task and folio
+ * lookups walk the memcg chain; an opt-out binds the subtree, while the
+ * remaining bits OR together.
+ *
+ * Author: Yafang Shao <laoar.shao@gmail.com>
+ */
+#include <linux/bpf.h>
+#include <linux/btf.h>
+#include <linux/cgroup.h>
+#include <linux/memcontrol.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/sched.h>
+#include <linux/sched/numa_balancing.h>
+
+DEFINE_STATIC_KEY_FALSE(numab_cgroup_mode_set);
+
+/* Whether this memcg may still own a NUMA balancing request. */
+static bool numab_memcg_active(struct mem_cgroup *memcg)
+{
+	unsigned int flags;
+
+	if (mem_cgroup_is_root(memcg))
+		return true;
+
+	/* Take one snapshot so all three state bits describe the same moment. */
+	flags = READ_ONCE(memcg->css.flags);
+
+	return (flags & CSS_ONLINE) &&
+	       !(flags & CSS_DYING) &&
+	       (flags & CSS_VISIBLE);
+}
+
+/*
+ * Combine the requests of @memcg and of every ancestor. A task chain
+ * stops at an explicit opt-out: a task can never be forced into
+ * balancing. A folio chain skips opt-outs instead (a memcg's DISABLED
+ * request only speaks for its tasks, never for its memory) and keeps
+ * collecting the remaining requests.
+ */
+static int numab_memcg_mode(struct mem_cgroup *memcg, bool folio_side)
+{
+	int req = 0;
+
+	for (; memcg; memcg = parent_mem_cgroup(memcg)) {
+		int mode;
+
+		if (!numab_memcg_active(memcg))
+			continue;
+
+		/* Paired with WRITE_ONCE() under numab_mode_mutex. */
+		mode = data_race(READ_ONCE(memcg->numab_mode));
+		if (mode == NUMAB_FOLLOW_SYSTEM)
+			continue;
+		if (mode == NUMAB_DISABLED) {
+			if (!folio_side)
+				return NUMAB_DISABLED;
+			continue;
+		}
+		req |= mode;
+	}
+	return req ?: NUMAB_FOLLOW_SYSTEM;
+}
+
+/*
+ * The combined request for @p. Kernel threads have no user memory to
+ * balance, so they make no request.  The walk needs no reference: the
+ * memcg chain is RCU-protected, so rcu_read_lock() keeps it alive for
+ * the whole walk.
+ */
+int task_numab_mode(struct task_struct *p)
+{
+	struct mem_cgroup *memcg;
+	int mode;
+
+	if (mem_cgroup_disabled() || !p->mm)
+		return NUMAB_FOLLOW_SYSTEM;
+
+	rcu_read_lock();
+	memcg = mem_cgroup_from_task(p);
+	mode = memcg ? numab_memcg_mode(memcg, false) : NUMAB_FOLLOW_SYSTEM;
+	rcu_read_unlock();
+	return mode;
+}
+
+/*
+ * The combined request for @folio's owner. An uncharged folio makes no
+ * request. A folio charged to a memcg whose cgroup the kfunc cannot
+ * reach carries no request and follows the global state.
+ */
+int folio_numab_mode(struct folio *folio)
+{
+	struct mem_cgroup *memcg;
+	int mode;
+
+	if (mem_cgroup_disabled())
+		return NUMAB_FOLLOW_SYSTEM;
+
+	rcu_read_lock();
+	memcg = folio_memcg(folio);
+	mode = memcg ? numab_memcg_mode(memcg, true) : NUMAB_FOLLOW_SYSTEM;
+	rcu_read_unlock();
+	return mode;
+}
+
+static DEFINE_MUTEX(numab_mode_mutex);
+
+/*
+ * Reset the request when the memory controller is disabled, the memcg is
+ * offlined or the memcg is pinned.  A memcg may be made visible again, so
+ * it must start transparent.
+ */
+void numab_memcg_reset(struct mem_cgroup *memcg)
+{
+	mutex_lock(&numab_mode_mutex);
+	if (memcg->numab_mode != NUMAB_FOLLOW_SYSTEM) {
+		WRITE_ONCE(memcg->numab_mode, NUMAB_FOLLOW_SYSTEM);
+		static_branch_dec(&numab_cgroup_mode_set);
+	}
+	mutex_unlock(&numab_mode_mutex);
+}
+
+__bpf_kfunc_start_defs();
+
+/**
+ * bpf_numab_set_mode() - Set the NUMA balancing mode of a cgroup's memcg.
+ * @cgid: kernfs id of the cgroup whose memcg is updated
+ * @mode: NUMAB_FOLLOW_SYSTEM to defer to the global sysctl state, or a
+ *        NUMAB_* mode. The kernel reads the bits independently, the way
+ *        kernel.numa_balancing reads them, so
+ *        NUMAB_NORMAL|NUMAB_TIERING engages both modes. A
+ *        NUMAB_DISABLED request only speaks for the memcg's tasks, never
+ *        for its memory, which follows the remaining requests of its
+ *        ancestors.
+ *
+ * The cgroup must have a visible, online memory cgroup; otherwise the
+ * update is rejected.
+ *
+ * Return: 0 on success; %-EINVAL for a mode outside the domain;
+ *         %-ENOENT for an id that resolves to no cgroup; %-EOPNOTSUPP
+ *         for a cgroup without a visible, online memcg.
+ */
+__bpf_kfunc int bpf_numab_set_mode(u64 cgid, enum numab_mode mode)
+{
+	struct cgroup_subsys_state *css;
+	struct mem_cgroup *memcg;
+	struct cgroup *cgrp;
+	int old;
+
+	if (mode != NUMAB_FOLLOW_SYSTEM &&
+	    (mode < 0 || mode > NUMAB_NORMAL_TIERING))
+		return -EINVAL;
+
+	cgrp = __cgroup_get_from_id(cgid);
+	if (IS_ERR(cgrp))
+		return PTR_ERR(cgrp);
+
+	if (mem_cgroup_disabled()) {
+		cgroup_put(cgrp);
+		return -EOPNOTSUPP;
+	}
+
+	rcu_read_lock();
+	css = cgroup_css(cgrp, &memory_cgrp_subsys);
+	memcg = mem_cgroup_from_css(css);
+	if (memcg && !mem_cgroup_tryget_online(memcg))
+		memcg = NULL;
+	rcu_read_unlock();
+
+	if (!memcg) {
+		cgroup_put(cgrp);
+		return -EOPNOTSUPP;
+	}
+
+	mutex_lock(&numab_mode_mutex);
+	if (!numab_memcg_active(memcg)) {
+		mutex_unlock(&numab_mode_mutex);
+		mem_cgroup_put(memcg);
+		cgroup_put(cgrp);
+		return -EOPNOTSUPP;
+	}
+
+	old = READ_ONCE(memcg->numab_mode);
+	if (old == NUMAB_FOLLOW_SYSTEM && mode != NUMAB_FOLLOW_SYSTEM)
+		static_branch_inc(&numab_cgroup_mode_set);
+	else if (old != NUMAB_FOLLOW_SYSTEM && mode == NUMAB_FOLLOW_SYSTEM)
+		static_branch_dec(&numab_cgroup_mode_set);
+	WRITE_ONCE(memcg->numab_mode, (int)mode);
+	mutex_unlock(&numab_mode_mutex);
+
+	mem_cgroup_put(memcg);
+	cgroup_put(cgrp);
+	return 0;
+}
+
+/**
+ * bpf_numab_get_mode() - Read the NUMA balancing mode that applies to a cgroup.
+ * @cgid: kernfs id of the cgroup
+ *
+ * The combined task-side request of the cgroup's effective memcg and of
+ * every ancestor: an opt-out wins, otherwise the requested bits OR
+ * together, and the kernel reads them independently, as
+ * kernel.numa_balancing does, so a combined
+ * NUMAB_NORMAL|NUMAB_TIERING engages both modes. NUMAB_FOLLOW_SYSTEM
+ * when nobody makes a request. If the cgroup
+ * has no memcg, the nearest ancestor memcg is used. The folio-side view
+ * stays internal to the kernel.
+ *
+ * Return: the combined mode, NUMAB_FOLLOW_SYSTEM (-1) included, or
+ *         %-ENOENT for an id that resolves to no cgroup.
+ */
+__bpf_kfunc s64 bpf_numab_get_mode(u64 cgid)
+{
+	struct mem_cgroup *memcg;
+	struct cgroup *cgrp;
+	s64 mode;
+
+	cgrp = __cgroup_get_from_id(cgid);
+	if (IS_ERR(cgrp))
+		return PTR_ERR(cgrp);
+
+	if (mem_cgroup_disabled()) {
+		cgroup_put(cgrp);
+		return NUMAB_FOLLOW_SYSTEM;
+	}
+
+	rcu_read_lock();
+	memcg = mem_cgroup_from_css(cgroup_e_css(cgrp, &memory_cgrp_subsys));
+	mode = memcg ? numab_memcg_mode(memcg, false) : NUMAB_FOLLOW_SYSTEM;
+	rcu_read_unlock();
+
+	cgroup_put(cgrp);
+	return mode;
+}
+
+__bpf_kfunc_end_defs();
+
+BTF_KFUNCS_START(numab_kfunc_ids)
+BTF_ID_FLAGS(func, bpf_numab_set_mode, KF_SLEEPABLE)
+BTF_ID_FLAGS(func, bpf_numab_get_mode)
+BTF_KFUNCS_END(numab_kfunc_ids)
+
+static const struct btf_kfunc_id_set numab_kfunc_set = {
+	.owner = THIS_MODULE,
+	.set   = &numab_kfunc_ids,
+};
+
+static int __init numab_kfunc_init(void)
+{
+	int ret;
+
+	ret = register_btf_kfunc_id_set(BPF_PROG_TYPE_SYSCALL, &numab_kfunc_set);
+	if (ret)
+		pr_warn("numab: failed to register kfuncs: %d\n", ret);
+	return ret;
+}
+late_initcall(numab_kfunc_init);
diff --git a/kernel/sched/build_policy.c b/kernel/sched/build_policy.c
index 2a828725a7f965..3746c6675ff325 100644
--- a/kernel/sched/build_policy.c
+++ b/kernel/sched/build_policy.c
@@ -75,4 +75,8 @@
 # include "ext/sub.c"
 #endif
 
+#ifdef CONFIG_BPF_NUMAB
+#include "bpf_numab.c"
+#endif
+
 #include "syscalls.c"
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index cfc982205b98c6..6c2a7550eef522 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -39,6 +39,7 @@
 #include <linux/sched/cputime.h>
 #include <linux/sched/isolation.h>
 #include <linux/sched/nohz.h>
+#include <linux/sched/numa_balancing.h>
 #include <linux/sched/prio.h>
 #include <linux/static_call.h>
 
@@ -1421,7 +1422,8 @@ static inline int get_sched_cache_scale(int mul)
 	return (1 + (tol - 1) * mul);
 }
 
-static bool exceed_llc_capacity(struct sched_cache_group *grp, int cpu)
+static bool exceed_llc_capacity(struct sched_cache_group *grp, int cpu,
+				bool numab_enabled)
 {
 #ifdef CONFIG_NUMA_BALANCING
 	unsigned long llc, footprint;
@@ -1434,7 +1436,7 @@ static bool exceed_llc_capacity(struct sched_cache_group *grp, int cpu)
 	if (!sd)
 		return true;
 
-	if (static_branch_likely(&sched_numa_balancing)) {
+	if (numab_enabled) {
 		/*
 		 * TBD: RDT exclusive LLC ways reserved should be
 		 * excluded.
@@ -1800,7 +1802,8 @@ static unsigned long fraction_mm_sched(struct rq *rq,
 	return div64_u64(NICE_0_LOAD * pcpu_sched->runtime, rq->cpu_runtime + 1);
 }
 
-static int get_pref_llc(struct task_struct *p, struct sched_cache_group *grp)
+static int get_pref_llc(struct task_struct *p, struct sched_cache_group *grp,
+			bool numab_enabled)
 {
 	int mm_sched_llc = -1, mm_sched_cpu;
 
@@ -1822,7 +1825,7 @@ static int get_pref_llc(struct task_struct *p, struct sched_cache_group *grp)
 		 * than sched_setnuma() at least -- and thus the
 		 * conflict only exists for a short period of time.
 		 */
-		if (static_branch_likely(&sched_numa_balancing) &&
+		if (numab_enabled &&
 		    p->numa_preferred_nid >= 0 &&
 		    cpu_to_node(mm_sched_cpu) != p->numa_preferred_nid)
 			mm_sched_llc = -1;
@@ -1841,6 +1844,7 @@ void account_mm_sched(struct rq *rq, struct task_struct *p, s64 delta_exec)
 	struct sched_cache_time *pcpu_sched;
 	int mm_sched_llc = -1;
 	unsigned long epoch;
+	bool numab_enabled;
 
 	if (!sched_cache_enabled())
 		return;
@@ -1874,14 +1878,19 @@ void account_mm_sched(struct rq *rq, struct task_struct *p, s64 delta_exec)
 	 * its preferred state.
 	 */
 	if ((long)(epoch - READ_ONCE(grp->epoch)) > llc_epoch_affinity_timeout ||
-	    invalid_llc_nr(grp, p, cpu_of(rq)) ||
-	    exceed_llc_capacity(grp, cpu_of(rq))) {
+	    invalid_llc_nr(grp, p, cpu_of(rq))) {
 		if (READ_ONCE(grp->cpu) != -1)
 			WRITE_ONCE(grp->cpu, -1);
+	} else {
+		numab_enabled = task_numab_enabled(p);
+		if (exceed_llc_capacity(grp, cpu_of(rq), numab_enabled)) {
+			if (READ_ONCE(grp->cpu) != -1)
+				WRITE_ONCE(grp->cpu, -1);
+		} else {
+			mm_sched_llc = get_pref_llc(p, grp, numab_enabled);
+		}
 	}
 
-	mm_sched_llc = get_pref_llc(p, grp);
-
 	/* task not on rq accounted later in account_entity_enqueue() */
 	if (task_running_on_cpu(rq->cpu, p) &&
 	    READ_ONCE(p->preferred_llc) != mm_sched_llc) {
@@ -1918,12 +1927,12 @@ static void task_tick_cache(struct rq *rq, struct task_struct *p)
 }
 
 static void get_scan_cpumasks(cpumask_var_t cpus, struct task_struct *p,
-			      struct sched_cache_group *grp)
+			      struct sched_cache_group *grp, bool numab_enabled)
 {
 #ifdef CONFIG_NUMA_BALANCING
 	int cpu, curr_cpu, nid, pref_nid;
 
-	if (!static_branch_likely(&sched_numa_balancing))
+	if (!numab_enabled)
 		goto out;
 
 	cpu = READ_ONCE(grp->cpu);
@@ -1990,6 +1999,7 @@ static void task_cache_work(struct callback_head *work)
 	struct task_struct *p = current, *cur;
 	unsigned long curr_m_a_occ = 0;
 	unsigned long m_a_occ = 0;
+	bool numab_enabled;
 
 	WARN_ON_ONCE(work != &p->cache_work);
 
@@ -2018,11 +2028,16 @@ static void task_cache_work(struct callback_head *work)
 		return;
 
 	curr_cpu = task_cpu(p);
-	if (invalid_llc_nr(grp, p, curr_cpu) ||
-	    exceed_llc_capacity(grp, curr_cpu)) {
+	if (invalid_llc_nr(grp, p, curr_cpu)) {
 		if (READ_ONCE(grp->cpu) != -1)
 			WRITE_ONCE(grp->cpu, -1);
+		return;
+	}
 
+	numab_enabled = task_numab_enabled(p);
+	if (exceed_llc_capacity(grp, curr_cpu, numab_enabled)) {
+		if (READ_ONCE(grp->cpu) != -1)
+			WRITE_ONCE(grp->cpu, -1);
 		return;
 	}
 
@@ -2032,7 +2047,7 @@ static void task_cache_work(struct callback_head *work)
 	scoped_guard (cpus_read_lock) {
 		guard(rcu)();
 
-		get_scan_cpumasks(cpus, p, grp);
+		get_scan_cpumasks(cpus, p, grp, numab_enabled);
 
 		for_each_cpu(cpu, cpus) {
 			/* XXX sched_cluster_active */
@@ -2137,7 +2152,8 @@ void init_sched_mm(struct task_struct *p) { }
 static void task_tick_cache(struct rq *rq, struct task_struct *p) { }
 
 static inline int get_pref_llc(struct task_struct *p,
-			       struct sched_cache_group *grp)
+			       struct sched_cache_group *grp,
+			       bool numab_enabled)
 {
 	return -1;
 }
@@ -2866,6 +2882,9 @@ bool should_numa_migrate_memory(struct task_struct *p, struct folio *folio,
 	struct numa_group *ng = deref_curr_numa_group(p);
 	int dst_nid = cpu_to_node(dst_cpu);
 	int last_cpupid, this_cpupid;
+	bool tiering;
+
+	tiering = folio_numab_in_tiering_mode(folio);
 
 	/*
 	 * Cannot migrate to memoryless nodes.
@@ -2877,7 +2896,7 @@ bool should_numa_migrate_memory(struct task_struct *p, struct folio *folio,
 	 * The pages in slow memory node should be migrated according
 	 * to hot/cold instead of private/shared.
 	 */
-	if (folio_use_access_time(folio)) {
+	if (tiering && !node_is_toptier(folio_nid(folio))) {
 		struct pglist_data *pgdat;
 		unsigned long rate_limit;
 		unsigned int latency, th, def_th;
@@ -2906,8 +2925,8 @@ bool should_numa_migrate_memory(struct task_struct *p, struct folio *folio,
 	this_cpupid = cpu_pid_to_cpupid(dst_cpu, current->pid);
 	last_cpupid = folio_xchg_last_cpupid(folio, this_cpupid);
 
-	if (!(sysctl_numa_balancing_mode & NUMA_BALANCING_MEMORY_TIERING) &&
-	    !node_is_toptier(src_nid) && !cpupid_valid(last_cpupid))
+	if (!tiering && !node_is_toptier(src_nid) &&
+	    !cpupid_valid(last_cpupid))
 		return false;
 
 	/*
@@ -4135,12 +4154,14 @@ void task_numa_fault(int last_cpupid, int mem_node, int pages, int flags)
 {
 	struct task_struct *p = current;
 	bool migrated = flags & TNF_MIGRATED;
+	bool numab_enabled, numab_tiering;
 	int cpu_node = task_node(current);
 	int local = !!(flags & TNF_FAULT_LOCAL);
 	struct numa_group *ng;
 	int priv;
 
-	if (!static_branch_likely(&sched_numa_balancing))
+	task_numab_get_modes(p, &numab_enabled, &numab_tiering);
+	if (!numab_enabled)
 		return;
 
 	/* for example, ksmd faulting in a user's mm */
@@ -4152,8 +4173,7 @@ void task_numa_fault(int last_cpupid, int mem_node, int pages, int flags)
 	 * node for memory tiering mode.
 	 */
 	if (!node_is_toptier(mem_node) &&
-	    (sysctl_numa_balancing_mode & NUMA_BALANCING_MEMORY_TIERING ||
-	     !cpupid_valid(last_cpupid)))
+	    (numab_tiering || !cpupid_valid(last_cpupid)))
 		return;
 
 	/* Allocate buffer to track faults on a per-node basis */
@@ -4297,6 +4317,9 @@ static void task_numa_work(struct callback_head *work)
 	if (p->flags & PF_EXITING)
 		return;
 
+	if (!task_numab_enabled(p))
+		return;
+
 	/*
 	 * Memory is pinned to only one NUMA node via cpuset.mems, naturally
 	 * no page can be migrated.
@@ -4601,6 +4624,11 @@ static void task_tick_numa(struct rq *rq, struct task_struct *curr)
 			curr->numa_scan_period = task_scan_start(curr);
 		curr->node_stamp += period;
 
+		if (!task_numab_enabled(curr)) {
+			curr->node_stamp = now;
+			return;
+		}
+
 		if (!time_before(jiffies, curr->mm->numa_next_scan))
 			task_work_add(curr, work, TWA_RESUME);
 	}
@@ -4611,7 +4639,7 @@ static void update_scan_period(struct task_struct *p, int new_cpu)
 	int src_nid = cpu_to_node(task_cpu(p));
 	int dst_nid = cpu_to_node(new_cpu);
 
-	if (!static_branch_likely(&sched_numa_balancing))
+	if (!task_numab_enabled(p))
 		return;
 
 	if (!p->mm || !p->numa_faults || (p->flags & PF_EXITING))
@@ -10696,13 +10724,14 @@ static int task_hot(struct task_struct *p, struct lb_env *env)
  * Returns 0, if task migration is not affected by locality.
  * Returns a negative value, if task migration improves locality i.e migration preferred.
  */
-static long migrate_degrades_locality(struct task_struct *p, struct lb_env *env)
+static long migrate_degrades_locality(struct task_struct *p, struct lb_env *env,
+				      bool numab_enabled)
 {
 	struct numa_group *numa_group = rcu_dereference_all(p->numa_group);
 	unsigned long src_weight, dst_weight;
 	int src_nid, dst_nid, dist;
 
-	if (!static_branch_likely(&sched_numa_balancing))
+	if (!numab_enabled)
 		return 0;
 
 	if (!p->numa_faults || !(env->sd->flags & SD_NUMA))
@@ -10744,7 +10773,8 @@ static long migrate_degrades_locality(struct task_struct *p, struct lb_env *env)
 
 #else /* !CONFIG_NUMA_BALANCING: */
 static inline long migrate_degrades_locality(struct task_struct *p,
-					     struct lb_env *env)
+					     struct lb_env *env,
+					     bool numab_enabled)
 {
 	return 0;
 }
@@ -10946,7 +10976,8 @@ static inline bool sched_asym(struct sched_domain *sd, int dst_cpu, int src_cpu)
  * destination LLC in terms of cache aware load balance.
  */
 static enum llc_mig can_migrate_llc_task(struct lb_env *env,
-					 struct task_struct *p)
+					 struct task_struct *p,
+					 bool numab_enabled)
 {
 	struct sched_cache_group *grp;
 	bool to_pref;
@@ -10971,7 +11002,7 @@ static enum llc_mig can_migrate_llc_task(struct lb_env *env,
 
 	/* skip cache aware load balance for too many threads */
 	if (invalid_llc_nr(grp, p, dst_cpu) ||
-	    exceed_llc_capacity(grp, dst_cpu)) {
+	    exceed_llc_capacity(grp, dst_cpu, numab_enabled)) {
 		if (READ_ONCE(grp->cpu) != -1)
 			WRITE_ONCE(grp->cpu, -1);
 		return mig_unrestricted;
@@ -11060,7 +11091,8 @@ migrate_llc_task_wrong_dst(struct task_struct *p, struct lb_env *env)
  * Check if migrating task p from env->src_cpu to
  * env->dst_cpu breaks LLC localiy.
  */
-static bool migrate_degrades_llc(struct task_struct *p, struct lb_env *env)
+static bool migrate_degrades_llc(struct task_struct *p, struct lb_env *env,
+				 bool numab_enabled)
 {
 	if (!sched_cache_enabled())
 		return false;
@@ -11087,7 +11119,7 @@ static bool migrate_degrades_llc(struct task_struct *p, struct lb_env *env)
 	if (migrate_llc_task_wrong_dst(p, env))
 		return true;
 
-	if (can_migrate_llc_task(env, p) != mig_forbid)
+	if (can_migrate_llc_task(env, p, numab_enabled) != mig_forbid)
 		return false;
 
 	return true;
@@ -11113,7 +11145,8 @@ migrate_llc_task_wrong_dst(struct task_struct *p, struct lb_env *env)
 }
 
 static inline bool
-migrate_degrades_llc(struct task_struct *p, struct lb_env *env)
+migrate_degrades_llc(struct task_struct *p, struct lb_env *env,
+		     bool numab_enabled)
 {
 	return false;
 }
@@ -11125,6 +11158,7 @@ static
 int can_migrate_task(struct task_struct *p, struct lb_env *env)
 {
 	long degrades, hot;
+	bool numab_enabled;
 
 	lockdep_assert_rq_held(env->src_rq);
 	if (p->sched_task_hot)
@@ -11213,14 +11247,15 @@ int can_migrate_task(struct task_struct *p, struct lb_env *env)
 	if (env->flags & LBF_ACTIVE_LB)
 		return !migrate_llc_task_wrong_dst(p, env);
 
-	degrades = migrate_degrades_locality(p, env);
+	numab_enabled = task_numab_enabled(p);
+	degrades = migrate_degrades_locality(p, env, numab_enabled);
 	if (!degrades) {
 		/*
 		 * If the NUMA locality is not broken,
 		 * further check if migration would hurt
 		 * LLC locality.
 		 */
-		if (migrate_degrades_llc(p, env)) {
+		if (migrate_degrades_llc(p, env, numab_enabled)) {
 			/*
 			 * If regular load balancing fails to pull a task
 			 * due to LLC locality, this is expected behavior
@@ -15362,7 +15397,7 @@ static void task_tick_fair(struct rq *rq, struct task_struct *curr, int queued)
 	if (queued)
 		return;
 
-	if (static_branch_unlikely(&sched_numa_balancing))
+	if (task_numab_tick_possible())
 		task_tick_numa(rq, curr);
 
 	task_tick_cache(rq, curr);
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index 6c7c5633524a3b..9b616abf5c9c31 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -2496,7 +2496,6 @@ extern union sched_feat_key sched_feat_keys[__SCHED_FEAT_NR];
 
 #endif /* !CONFIG_JUMP_LABEL */
 
-extern struct static_key_false sched_numa_balancing;
 extern struct static_key_false sched_schedstats;
 
 static inline u64 global_rt_period(void)
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index a05d9a8baa1b6b..3971b5b3360bac 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -31,6 +31,7 @@
 #include <linux/cgroup.h>
 #include <linux/cpuset.h>
 #include <linux/sched/mm.h>
+#include <linux/sched/numa_balancing.h>
 #include <linux/shmem_fs.h>
 #include <linux/hugetlb.h>
 #include <linux/pagemap.h>
@@ -4266,6 +4267,9 @@ static struct mem_cgroup *mem_cgroup_alloc(struct mem_cgroup *parent)
 	if (!memcg)
 		return ERR_PTR(-ENOMEM);
 
+#ifdef CONFIG_BPF_NUMAB
+	memcg->numab_mode = NUMAB_FOLLOW_SYSTEM;
+#endif
 	error = xa_alloc(&mem_cgroup_private_ids, &memcg->private_id, NULL,
 			 XA_LIMIT(1, MEM_CGROUP_ID_MAX), GFP_KERNEL);
 	if (error)
@@ -4459,6 +4463,9 @@ static void mem_cgroup_css_offline(struct cgroup_subsys_state *css)
 {
 	struct mem_cgroup *memcg = mem_cgroup_from_css(css);
 
+#ifdef CONFIG_BPF_NUMAB
+	numab_memcg_reset(memcg);
+#endif
 	memcg1_css_offline(memcg);
 
 	page_counter_set_min(&memcg->memory, 0);
@@ -4532,6 +4539,9 @@ static void mem_cgroup_css_reset(struct cgroup_subsys_state *css)
 {
 	struct mem_cgroup *memcg = mem_cgroup_from_css(css);
 
+#ifdef CONFIG_BPF_NUMAB
+	numab_memcg_reset(memcg);
+#endif
 	page_counter_set_max(&memcg->memory, PAGE_COUNTER_MAX);
 	page_counter_set_max(&memcg->swap, PAGE_COUNTER_MAX);
 	WRITE_ONCE(memcg->oom_group, false);
@@ -5917,6 +5927,10 @@ static void __init memcg_struct_check(void)
 				      kmemcg_id);
 	CACHELINE_ASSERT_GROUP_MEMBER(struct mem_cgroup, memcg_read_mostly,
 				      oom_group);
+#ifdef CONFIG_BPF_NUMAB
+	CACHELINE_ASSERT_GROUP_MEMBER(struct mem_cgroup, memcg_read_mostly,
+				      numab_mode);
+#endif
 
 	CACHELINE_ASSERT_GROUP_MEMBER(struct mem_cgroup_per_node,
 				      memcg_pn_read_mostly, memcg);
diff --git a/mm/memory-tiers.c b/mm/memory-tiers.c
index 25e121851b5862..7bfb92657e24ca 100644
--- a/mm/memory-tiers.c
+++ b/mm/memory-tiers.c
@@ -6,6 +6,7 @@
 #include <linux/memory.h>
 #include <linux/memory-tiers.h>
 #include <linux/notifier.h>
+#include <linux/sched/numa_balancing.h>
 #include <linux/sched/sysctl.h>
 
 #include "internal.h"
@@ -56,15 +57,15 @@ static const struct bus_type memory_tier_subsys = {
  * folio_use_access_time - check if a folio reuses cpupid for page access time
  * @folio: folio to check
  *
- * folio's _last_cpupid field is repurposed by memory tiering. In memory
- * tiering mode, cpupid of slow memory folio (not toptier memory) is used to
- * record page access time.
+ * folio's _last_cpupid field is repurposed by memory tiering. When the
+ * owner of @folio participates in tiering, cpupid of slow memory folio
+ * (not toptier memory) is used to record page access time.
  *
  * Return: the folio _last_cpupid is used to record page access time
  */
 bool folio_use_access_time(struct folio *folio)
 {
-	return (sysctl_numa_balancing_mode & NUMA_BALANCING_MEMORY_TIERING) &&
+	return folio_numab_in_tiering_mode(folio) &&
 	       !node_is_toptier(folio_nid(folio));
 }
 #endif
diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index 0884c629670dd6..3534dc63b5a9c3 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -854,7 +854,7 @@ static int queue_folios_hugetlb(pte_t *pte, unsigned long hmask,
 bool folio_can_map_prot_numa(struct folio *folio, struct vm_area_struct *vma,
 		bool is_private_single_threaded)
 {
-	int nid;
+	int nid, mode;
 
 	if (!folio || folio_is_zone_device(folio) || folio_test_ksm(folio))
 		return false;
@@ -883,15 +883,16 @@ bool folio_can_map_prot_numa(struct folio *folio, struct vm_area_struct *vma,
 	if (is_private_single_threaded && (nid == numa_node_id()))
 		return false;
 
+	mode = folio_numab_effective_mode(folio);
+
 	/*
 	 * Skip scanning top tier node if normal numa
 	 * balancing is disabled
 	 */
-	if (!(sysctl_numa_balancing_mode & NUMA_BALANCING_NORMAL) &&
-	    node_is_toptier(nid))
+	if (!(mode & NUMAB_NORMAL) && node_is_toptier(nid))
 		return false;
 
-	if (folio_use_access_time(folio))
+	if ((mode & NUMAB_TIERING) && !node_is_toptier(nid))
 		folio_xchg_access_time(folio, jiffies_to_msecs(jiffies));
 
 	return true;
diff --git a/mm/migrate.c b/mm/migrate.c
index 7bdcdb57652f8f..f3a84a5903aa0c 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -41,6 +41,7 @@
 #include <linux/ptrace.h>
 #include <linux/memory.h>
 #include <linux/sched/sysctl.h>
+#include <linux/sched/numa_balancing.h>
 #include <linux/memory-tiers.h>
 #include <linux/pagewalk.h>
 
@@ -818,7 +819,7 @@ void folio_migrate_flags(struct folio *newfolio, struct folio *folio)
 	 * memory node, reset cpupid, because that is used to record
 	 * page access time in slow memory node.
 	 */
-	if (sysctl_numa_balancing_mode & NUMA_BALANCING_MEMORY_TIERING) {
+	if (folio_numab_in_tiering_mode(folio)) {
 		bool f_toptier = node_is_toptier(folio_nid(folio));
 		bool t_toptier = node_is_toptier(folio_nid(newfolio));
 
@@ -2717,7 +2718,7 @@ int migrate_misplaced_folio_prepare(struct folio *folio,
 	if (!migrate_balanced_pgdat(pgdat, nr_pages)) {
 		int z;
 
-		if (!(sysctl_numa_balancing_mode & NUMA_BALANCING_MEMORY_TIERING))
+		if (!folio_numab_in_tiering_mode(folio))
 			return -EAGAIN;
 		for (z = pgdat->nr_zones - 1; z >= 0; z--) {
 			if (managed_zone(pgdat->node_zones + z))
@@ -2759,6 +2760,7 @@ int migrate_misplaced_folio(struct folio *folio, int node)
 	LIST_HEAD(migratepages);
 	struct mem_cgroup *memcg = get_mem_cgroup_from_folio(folio);
 	struct lruvec *lruvec = mem_cgroup_lruvec(memcg, pgdat);
+	bool folio_tiering = folio_numab_in_tiering_mode(folio);
 
 	list_add(&folio->lru, &migratepages);
 	nr_remaining = migrate_pages(&migratepages, alloc_misplaced_dst_folio,
@@ -2769,8 +2771,7 @@ int migrate_misplaced_folio(struct folio *folio, int node)
 	if (nr_succeeded) {
 		count_vm_numa_events(NUMA_PAGE_MIGRATE, nr_succeeded);
 		count_memcg_events(memcg, NUMA_PAGE_MIGRATE, nr_succeeded);
-		if ((sysctl_numa_balancing_mode & NUMA_BALANCING_MEMORY_TIERING)
-		    && !node_is_toptier(folio_nid(folio))
+		if (folio_tiering && !node_is_toptier(folio_nid(folio))
 		    && node_is_toptier(node))
 			mod_lruvec_state(lruvec, PGPROMOTE_SUCCESS, nr_succeeded);
 	}
diff --git a/mm/vmscan.c b/mm/vmscan.c
index 9959ca158ce835..7ef4205b6a4e77 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -65,6 +65,7 @@
 
 #include <linux/swapops.h>
 #include <linux/sched/sysctl.h>
+#include <linux/sched/numa_balancing.h>
 
 #include "internal.h"
 #include "page_alloc.h"
@@ -5224,8 +5225,7 @@ static bool should_abort_scan(struct lruvec *lruvec, struct scan_control *sc)
 	if (!current_is_kswapd() || sc->order)
 		return false;
 
-	mark = sysctl_numa_balancing_mode & NUMA_BALANCING_MEMORY_TIERING ?
-	       WMARK_PROMO : WMARK_HIGH;
+	mark = numab_in_tiering_mode() ? WMARK_PROMO : WMARK_HIGH;
 
 	for (i = 0; i <= sc->reclaim_idx; i++) {
 		struct zone *zone = lruvec_pgdat(lruvec)->node_zones + i;
@@ -7131,7 +7131,7 @@ static bool pgdat_balanced(pg_data_t *pgdat, int order, int highest_zoneidx)
 		enum zone_stat_item item;
 		unsigned long free_pages;
 
-		if (sysctl_numa_balancing_mode & NUMA_BALANCING_MEMORY_TIERING)
+		if (numab_in_tiering_mode())
 			mark = promo_wmark_pages(zone);
 		else
 			mark = high_wmark_pages(zone);
diff --git a/tools/testing/selftests/bpf/config b/tools/testing/selftests/bpf/config
index 49dfe939467cc8..e56c8872e51a04 100644
--- a/tools/testing/selftests/bpf/config
+++ b/tools/testing/selftests/bpf/config
@@ -7,6 +7,7 @@ CONFIG_BPF_JIT=y
 CONFIG_BPF_KPROBE_OVERRIDE=y
 CONFIG_BPF_LIRC_MODE2=y
 CONFIG_BPF_LSM=y
+CONFIG_BPF_NUMAB=y
 CONFIG_BPF_STREAM_PARSER=y
 CONFIG_BPF_SYSCALL=y
 # CONFIG_BPF_UNPRIV_DEFAULT_OFF is not set
@@ -78,6 +79,7 @@ CONFIG_NET_CLS_FLOWER=y
 CONFIG_NET_CLS_MATCHALL=y
 CONFIG_NET_FOU=y
 CONFIG_NET_FOU_IP_TUNNELS=y
+CONFIG_NUMA_BALANCING=y
 CONFIG_NET_IPGRE=y
 CONFIG_NET_IPGRE_DEMUX=y
 CONFIG_NET_IPIP=y
diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_numab.c b/tools/testing/selftests/bpf/prog_tests/bpf_numab.c
new file mode 100644
index 00000000000000..6fb6a4d9f29194
--- /dev/null
+++ b/tools/testing/selftests/bpf/prog_tests/bpf_numab.c
@@ -0,0 +1,273 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <test_progs.h>
+#include "cgroup_helpers.h"
+#include "bpf_numab.skel.h"
+
+#define CGROUP_PATH	"/bpf_numab"
+#define CHILD_PATH	CGROUP_PATH "/child"
+#define HIER_PATH	"/bpf_numab_hier"
+#define HIER_CHILD_PATH	HIER_PATH "/child"
+#define NOMEM_PATH	"/bpf_numab_nomem"
+#define NOMEM_CHILD_PATH NOMEM_PATH "/child"
+
+/* The per-cgroup request domain, mirroring the kernel constants. */
+#define NUMAB_FOLLOW_SYSTEM	(-1)
+#define NUMAB_DISABLED		0
+#define NUMAB_NORMAL		1
+#define NUMAB_TIERING		2
+#define NUMAB_NORMAL_TIERING	3
+
+static int numab_set(struct bpf_numab *skel, u64 cgid,
+		     long mode)
+{
+	LIBBPF_OPTS(bpf_test_run_opts, opts);
+	int ret;
+
+	skel->bss->set_cgid = cgid;
+	skel->bss->set_mode = mode;
+	ret = bpf_prog_test_run_opts(bpf_program__fd(skel->progs.numab_set),
+				     &opts);
+	if (!ASSERT_OK(ret, "set run"))
+		return -1;
+	return skel->bss->set_ret;
+}
+
+static long numab_get(struct bpf_numab *skel, u64 cgid)
+{
+	LIBBPF_OPTS(bpf_test_run_opts, opts);
+	int ret;
+
+	skel->bss->get_cgid = cgid;
+	ret = bpf_prog_test_run_opts(bpf_program__fd(skel->progs.numab_get),
+				     &opts);
+	if (!ASSERT_OK(ret, "get run"))
+		return -EIO;
+	return skel->bss->get_mode;
+}
+
+static void test_set_get(void)
+{
+	struct bpf_numab *skel;
+	int cgroup_fd;
+	u64 cgid;
+
+	cgroup_fd = test__join_cgroup(CGROUP_PATH);
+	if (!ASSERT_GE(cgroup_fd, 0, "join_cgroup"))
+		return;
+
+	skel = bpf_numab__open_and_load();
+	if (!ASSERT_OK_PTR(skel, "open_and_load"))
+		goto cleanup;
+
+	cgid = get_cgroup_id(CGROUP_PATH);
+	if (!ASSERT_GT(cgid, 0, "get_cgroup_id"))
+		goto cleanup;
+
+	ASSERT_EQ(numab_set(skel, cgid, NUMAB_NORMAL), 0, "set normal");
+	ASSERT_EQ(numab_get(skel, cgid), NUMAB_NORMAL, "get normal");
+
+	ASSERT_EQ(numab_set(skel, cgid, NUMAB_TIERING), 0, "set tiering");
+	ASSERT_EQ(numab_get(skel, cgid), NUMAB_TIERING, "get tiering");
+
+	ASSERT_EQ(numab_set(skel, cgid, NUMAB_NORMAL_TIERING), 0, "set both");
+	ASSERT_EQ(numab_get(skel, cgid), NUMAB_NORMAL_TIERING, "get both");
+
+	ASSERT_EQ(numab_set(skel, cgid, NUMAB_DISABLED), 0, "set disabled");
+	ASSERT_EQ(numab_get(skel, cgid), NUMAB_DISABLED, "get disabled");
+
+	/* Back to the system setting. */
+	ASSERT_EQ(numab_set(skel, cgid, NUMAB_FOLLOW_SYSTEM), 0, "unset");
+	ASSERT_EQ(numab_get(skel, cgid), NUMAB_FOLLOW_SYSTEM, "get unset");
+
+cleanup:
+	bpf_numab__destroy(skel);
+	close(cgroup_fd);
+}
+
+static void test_invalid_mode(void)
+{
+	struct bpf_numab *skel;
+	int cgroup_fd;
+	u64 cgid;
+
+	cgroup_fd = test__join_cgroup(CGROUP_PATH);
+	if (!ASSERT_GE(cgroup_fd, 0, "join_cgroup"))
+		return;
+
+	skel = bpf_numab__open_and_load();
+	if (!ASSERT_OK_PTR(skel, "open_and_load"))
+		goto cleanup;
+
+	cgid = get_cgroup_id(CGROUP_PATH);
+	if (!ASSERT_GT(cgid, 0, "get_cgroup_id"))
+		goto cleanup;
+
+	ASSERT_EQ(numab_set(skel, cgid, -2), -EINVAL, "set below domain");
+	ASSERT_EQ(numab_set(skel, cgid, 4), -EINVAL, "set above domain");
+	ASSERT_EQ(numab_set(skel, cgid, 0x1000), -EINVAL, "set far above");
+
+	/* The rejected requests must not have stuck. */
+	ASSERT_EQ(numab_get(skel, cgid), NUMAB_FOLLOW_SYSTEM, "get unchanged");
+
+cleanup:
+	bpf_numab__destroy(skel);
+	close(cgroup_fd);
+}
+
+static void test_bad_cgid(void)
+{
+	struct bpf_numab *skel;
+
+	skel = bpf_numab__open_and_load();
+	if (!ASSERT_OK_PTR(skel, "open_and_load"))
+		return;
+
+	ASSERT_EQ(numab_set(skel, 0, NUMAB_NORMAL), -ENOENT, "set cgid 0");
+	ASSERT_EQ(numab_get(skel, 0), -ENOENT, "get cgid 0");
+	ASSERT_EQ(numab_set(skel, 0xdeadbeef, NUMAB_NORMAL), -ENOENT,
+		  "set bad cgid");
+	ASSERT_EQ(numab_get(skel, 0xdeadbeef), -ENOENT, "get bad cgid");
+
+	bpf_numab__destroy(skel);
+}
+
+static void test_hierarchy(void)
+{
+	u64 parent_cgid, child_cgid;
+	int runner_fd, parent_fd, child_fd;
+	struct bpf_numab *skel;
+
+	runner_fd = test__join_cgroup("/bpf_numab_runner");
+	if (!ASSERT_GE(runner_fd, 0, "join_runner_cgroup"))
+		return;
+
+	parent_fd = create_and_get_cgroup(HIER_PATH);
+	if (!ASSERT_GE(parent_fd, 0, "create_parent_cgroup"))
+		goto cleanup_runner;
+
+	if (!ASSERT_OK(enable_controllers(HIER_PATH, "memory"),
+		       "enable_memory_controller"))
+		goto cleanup_parent;
+
+	child_fd = create_and_get_cgroup(HIER_CHILD_PATH);
+	if (!ASSERT_GE(child_fd, 0, "create_child_cgroup"))
+		goto cleanup_parent;
+
+	skel = bpf_numab__open_and_load();
+	if (!ASSERT_OK_PTR(skel, "open_and_load"))
+		goto cleanup;
+
+	parent_cgid = get_cgroup_id(HIER_PATH);
+	child_cgid = get_cgroup_id(HIER_CHILD_PATH);
+	if (!ASSERT_GT(parent_cgid, 0, "get_parent_cgid") ||
+	    !ASSERT_GT(child_cgid, 0, "get_child_cgid"))
+		goto cleanup;
+
+	/* The child inherits an ancestor's request untouched. */
+	ASSERT_EQ(numab_set(skel, parent_cgid, NUMAB_TIERING), 0,
+		  "set parent tiering");
+	ASSERT_EQ(numab_get(skel, child_cgid), NUMAB_TIERING,
+		  "child inherits");
+
+	/* A request ORs with the ancestor's; NORMAL does not undo TIERING. */
+	ASSERT_EQ(numab_set(skel, child_cgid, NUMAB_NORMAL), 0,
+		  "set child normal");
+	ASSERT_EQ(numab_get(skel, child_cgid), NUMAB_NORMAL_TIERING,
+		  "or both");
+
+	/* The child's own opt-out wins. */
+	ASSERT_EQ(numab_set(skel, child_cgid, NUMAB_DISABLED), 0,
+		  "set child disabled");
+	ASSERT_EQ(numab_get(skel, child_cgid), NUMAB_DISABLED,
+		  "own opt-out wins");
+
+	/* So does an ancestor's: a task is never forced into balancing. */
+	ASSERT_EQ(numab_set(skel, child_cgid, NUMAB_TIERING), 0,
+		  "set child tiering");
+	ASSERT_EQ(numab_set(skel, parent_cgid, NUMAB_DISABLED), 0,
+		  "set parent disabled");
+	ASSERT_EQ(numab_get(skel, child_cgid), NUMAB_DISABLED,
+		  "ancestor opt-out wins");
+
+	/* Unsetting the parent re-exposes the child's own request. */
+	ASSERT_EQ(numab_set(skel, parent_cgid, NUMAB_FOLLOW_SYSTEM), 0,
+		  "unset parent");
+	ASSERT_EQ(numab_get(skel, child_cgid), NUMAB_TIERING,
+		  "child request again");
+
+	/* Unsetting the child leaves the chain with no request. */
+	ASSERT_EQ(numab_set(skel, child_cgid, NUMAB_FOLLOW_SYSTEM), 0,
+		  "unset child");
+	ASSERT_EQ(numab_get(skel, child_cgid), NUMAB_FOLLOW_SYSTEM,
+		  "no request");
+
+cleanup:
+	bpf_numab__destroy(skel);
+	close(child_fd);
+	remove_cgroup(HIER_CHILD_PATH);
+cleanup_parent:
+	close(parent_fd);
+	remove_cgroup(HIER_PATH);
+cleanup_runner:
+	close(runner_fd);
+}
+
+static void test_no_memcg(void)
+{
+	struct bpf_numab *skel;
+	int parent_fd, child_fd;
+	u64 parent_cgid, child_cgid;
+
+	parent_fd = test__join_cgroup(NOMEM_PATH);
+	if (!ASSERT_GE(parent_fd, 0, "join_nomem_parent"))
+		return;
+
+	child_fd = create_and_get_cgroup(NOMEM_CHILD_PATH);
+	if (!ASSERT_GE(child_fd, 0, "create_nomem_child"))
+		goto cleanup_parent;
+
+	skel = bpf_numab__open_and_load();
+	if (!ASSERT_OK_PTR(skel, "open_and_load"))
+		goto cleanup;
+
+	parent_cgid = get_cgroup_id(NOMEM_PATH);
+	child_cgid = get_cgroup_id(NOMEM_CHILD_PATH);
+	if (!ASSERT_GT(parent_cgid, 0, "get_nomem_parent_cgid") ||
+	    !ASSERT_GT(child_cgid, 0, "get_nomem_child_cgid"))
+		goto cleanup;
+
+	/*
+	 * The parent has a memcg; the child was created without enabling
+	 * the memory controller in the parent's subtree, so it has none.
+	 */
+	ASSERT_EQ(numab_set(skel, parent_cgid, NUMAB_NORMAL), 0,
+		  "set parent normal");
+	ASSERT_EQ(numab_get(skel, child_cgid), NUMAB_NORMAL,
+		  "child resolves to parent memcg");
+	ASSERT_EQ(numab_set(skel, child_cgid, NUMAB_TIERING), -EOPNOTSUPP,
+		  "child set rejected");
+	ASSERT_EQ(numab_get(skel, child_cgid), NUMAB_NORMAL,
+		  "child get unchanged");
+
+cleanup:
+	bpf_numab__destroy(skel);
+	close(child_fd);
+	remove_cgroup(NOMEM_CHILD_PATH);
+cleanup_parent:
+	close(parent_fd);
+}
+
+void test_bpf_numab(void)
+{
+	if (test__start_subtest("set_get"))
+		test_set_get();
+	if (test__start_subtest("invalid_mode"))
+		test_invalid_mode();
+	if (test__start_subtest("bad_cgid"))
+		test_bad_cgid();
+	if (test__start_subtest("hierarchy"))
+		test_hierarchy();
+	if (test__start_subtest("no_memcg"))
+		test_no_memcg();
+}
diff --git a/tools/testing/selftests/bpf/progs/bpf_numab.c b/tools/testing/selftests/bpf/progs/bpf_numab.c
new file mode 100644
index 00000000000000..25da97bce82ff2
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/bpf_numab.c
@@ -0,0 +1,32 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <vmlinux.h>
+#include <bpf/bpf_helpers.h>
+
+/* Inputs, set from userspace before each run. */
+u64 set_cgid;
+long set_mode;
+u64 get_cgid;
+
+/* Results, read back after each run. */
+long set_ret;
+long get_mode;
+
+extern int bpf_numab_set_mode(u64 cgid, enum numab_mode mode) __ksym;
+extern s64 bpf_numab_get_mode(u64 cgid) __ksym;
+
+SEC("syscall")
+int numab_set(void *ctx)
+{
+	set_ret = bpf_numab_set_mode(set_cgid, (enum numab_mode)set_mode);
+	return 0;
+}
+
+SEC("syscall")
+int numab_get(void *ctx)
+{
+	get_mode = bpf_numab_get_mode(get_cgid);
+	return 0;
+}
+
+char _license[] SEC("license") = "GPL";

3/2 2026/11/13 02:22 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 20833
							output: 31
							thoughts: 1803
						

Thoughts:
**Evaluation of Potential Syzkaller Fuzzing for the NUMA Balancing Patch Series**

Okay, let's break this down. My initial assessment is that this patch series *strongly* warrants fuzzing with syzkaller.  Let's walk through my reasoning. First, I'm seeing changes across several crucial areas: the scheduler, memory management, and it introduces new BPF kfuncs. This is a big red flag in a good way, as it targets fundamental kernel subsystems.  The fact that `kernel/sched/fair.c` and multiple files under `mm/` are being modified raises my eyebrows. These are core components that are inherently complex and potential sources of subtle, hard-to-find bugs.  And the introduction of *new* BPF kfuncs ( `bpf_numab_set_mode` and `bpf_numab_get_mode`) callable through the syscall interface is *definitely* a prime target. BPF syscall programs are already a well-established attack surface for syzkaller.

Next, I need to confirm if these changes are actually reachable.  NUMA balancing, cgroups (memcg), and BPF syscall programs are all easily accessible in standard QEMU/KVM virtualized environments. No exotic hardware or setup is required. The patch leverages NUMA balancing, cgroups, and BPF capabilities that syzkaller already has a good track record with.  Even without BPF kfunc calls enabled, just the modifications to `kernel/sched/fair.c` and the `mm/*` code would make this a good candidate.

I'm digging into `task_numab_enabled()`, `task_numa_fault()`, `task_tick_numa()`, `account_mm_sched()`, `can_migrate_task()`, `folio_can_map_prot_numa()` - these routines are *always* executed! Even if `CONFIG_BPF_NUMAB` isn't set, these are being modified.  But, when `CONFIG_BPF_NUMAB` is active, the `bpf_numab_set_mode` functions provide the ability to change the `static_branch_inc(&numab_cgroup_mode_set)` setting. This is critical. The moment that's set, `task_numab_mode()` and `folio_numab_mode()` start getting invoked on every tick, page fault, and migration. This creates the possibility for interesting race conditions and logic bugs.

Now, let's go back to the defined criteria.  This patch series hits all the main points: it modifies core subsystems (scheduler, mm, BPF), it refactors logic by implementing new helper abstractions, and this includes new and reachable kfuncs.

In conclusion, I'm confident that this is *WorthFuzzing = true*. I'll now dig into the configs and focus my analysis on critical symbols.



4/2 2026/11/13 02:22 tool grepper
0m Args:
{
  "Expression": "config BPF_NUMAB",
  "PathPrefixes": [
    "init/Kconfig"
  ]
}

Results:
{
  "Output": "init/Kconfig=818=config NUMA_BALANCING\n--\ninit/Kconfig-829-\ninit/Kconfig:830:config BPF_NUMAB\ninit/Kconfig-831-\tbool \"Per-cgroup NUMA balancing mode selection\"\n"
}

5/2 2026/11/13 02:22 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 23369
							output: 32
							thoughts: 22
						

Thoughts:
Here's my thought process, as requested:

**Navigating the Kconfig Labyrinth**

Okay, let's dive in. I need to investigate something specific, and my first instinct is to poke around in the `init/Kconfig` file. I'm thinking specifically around line 830. Given the complexities of the Kconfig system, and remembering the last time I had to debug a similar situation, I'll use the `read-file` tool to quickly grab the relevant section. This will allow me to check the specific configuration options and dependencies in the vicinity of that line, without having to visually hunt for it in the full file. This initial investigation will likely set the course for the rest of my exploration. It’s a good starting point for understanding how this particular element is configured.



6/2 2026/11/13 02:23 tool read-file
0m Args:
{
  "File": "init/Kconfig",
  "FirstLine": 825,
  "LineCount": 35
}

Results:
{
  "Contents": " 825:\t\t  The mechanism is quite primitive and is based on migrating memory when\n 826:\t\t  it has references to the node the task is running on.\n 827:\t\n 828:\t\t  This system will be inactive on UMA systems.\n 829:\t\n 830:\tconfig BPF_NUMAB\n 831:\t\tbool \"Per-cgroup NUMA balancing mode selection\"\n 832:\t\tdefault n\n 833:\t\tdepends on NUMA_BALANCING \u0026\u0026 MEMCG \u0026\u0026 BPF_SYSCALL \u0026\u0026 DEBUG_INFO_BTF\n 834:\t\thelp\n 835:\t\t  Allow BPF programs to select the NUMA balancing mode (disabled,\n 836:\t\t  normal, memory tiering, or both) on a per-cgroup basis, overriding the\n 837:\t\t  global NUMA balancing sysctl. A latency-sensitive service can\n 838:\t\t  opt its tasks out of balancing, or a batch service can have its\n 839:\t\t  PMEM-resident memory promoted when hot, without changing the\n 840:\t\t  mode for the rest of the system.\n 841:\t\n 842:\t\t  The request is written and read back through the\n 843:\t\t  bpf_numab_set_mode() and bpf_numab_get_mode() kfuncs, callable\n 844:\t\t  from BPF_PROG_TYPE_SYSCALL programs. The mode is stored in the\n 845:\t\t  target cgroup's memcg; setting it on a cgroup without the memory\n 846:\t\t  controller enabled is rejected.  This interface only applies to\n 847:\t\t  cgroups on the default hierarchy (cgroup v2).  While no memcg\n 848:\t\t  makes a request, the NUMA balancing hot paths pay a single\n 849:\t\t  patched-out branch and nothing else.\n 850:\t\n 851:\t\t  If unsure, say N.\n 852:\t\n 853:\tconfig SCHED_CACHE\n 854:\t\tbool \"Cache aware load balance\"\n 855:\t\tdefault y\n 856:\t\tdepends on SMP\n 857:\t\thelp\n 858:\t\t  When enabled, the scheduler will attempt to aggregate tasks from\n 859:\t\t  the same process onto a single Last Level Cache (LLC) domain when\n"
}

7/2 2026/11/13 02:23 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 24200
							output: 32
							thoughts: 77
						

Thoughts:
Okay, let's break this down.

**Investigating the Dependencies of `BPF_NUMA_BALANCING`**

Alright, so I need to understand the preconditions for `BPF_NUMA_BALANCING`. First, let's get the lay of the land, what does that depend on? The code says it needs `NUMA_BALANCING`, `MEMCG`, `BPF_SYSCALL`, and `DEBUG_INFO_BTF`. Seems pretty standard for things interacting with memory and BPF. Now, hold on, let's not jump to conclusions. It’s always good to be thorough. I should double-check that `NUMA_BALANCING` itself doesn't have any further dependencies. It’s easy to get lost in these dependency chains, so let's make sure that `NUMA_BALANCING` is solid and that the dependencies given are all there are. Let me go check the config for `NUMA_BALANCING`. This will keep me from missing anything.



8/2 2026/11/13 02:23 tool grepper
0m Args:
{
  "Expression": "config NUMA_BALANCING",
  "PathPrefixes": [
    "init/Kconfig"
  ]
}

Results:
{
  "Output": "init/Kconfig=815=config ARCH_SUPPORTS_INT128\n--\ninit/Kconfig-817-\ninit/Kconfig:818:config NUMA_BALANCING\ninit/Kconfig-819-\tbool \"Memory placement aware NUMA scheduler\"\n--\ninit/Kconfig=853=config SCHED_CACHE\n--\ninit/Kconfig-863-\ninit/Kconfig:864:config NUMA_BALANCING_DEFAULT_ENABLED\ninit/Kconfig-865-\tbool \"Automatically enable NUMA aware memory/task placement\"\n"
}

9/2 2026/11/13 02:23 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 24685
							output: 32
							thoughts: 17
						

Thoughts:
Okay, here's my interpretation of that thought process, assuming I'm an expert in this field and speaking in the first person:

**Diving into the Configuration Options**

Alright, I'm thinking we need to check the `init/Kconfig` file, specifically around line 815. That area likely holds some crucial configuration options related to whatever we're currently working on. Based on my experience, that's a common location for core initialization settings or perhaps related to early boot processes. Time to get my eyes on those options and see what's being defined there. This should give us a clearer picture of how a particular feature is enabled or disabled and what dependencies might be at play. Let's see what's what.



10/2 2026/11/13 02:23 tool read-file
0m Args:
{
  "File": "init/Kconfig",
  "FirstLine": 810,
  "LineCount": 20
}

Results:
{
  "Contents": " 810:\t\tdefault y if CC_IS_GCC \u0026\u0026 !CC_NO_STRINGOP_OVERFLOW\n 811:\t\n 812:\t#\n 813:\t# For architectures that know their GCC __int128 support is sound\n 814:\t#\n 815:\tconfig ARCH_SUPPORTS_INT128\n 816:\t\tbool\n 817:\t\n 818:\tconfig NUMA_BALANCING\n 819:\t\tbool \"Memory placement aware NUMA scheduler\"\n 820:\t\tdepends on ARCH_SUPPORTS_NUMA_BALANCING\n 821:\t\tdepends on ARCH_HAS_PTE_PROTNONE\n 822:\t\tdepends on SMP \u0026\u0026 NUMA_MIGRATION \u0026\u0026 !PREEMPT_RT\n 823:\t\thelp\n 824:\t\t  This option adds support for automatic NUMA aware memory/task placement.\n 825:\t\t  The mechanism is quite primitive and is based on migrating memory when\n 826:\t\t  it has references to the node the task is running on.\n 827:\t\n 828:\t\t  This system will be inactive on UMA systems.\n 829:\t\n"
}

11/2 2026/11/13 02:23 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 25201
							output: 30
							thoughts: 195
						

Thoughts:
**My Analysis of NUMA and BPF Configuration Dependencies**

Okay, let's break down these kernel configuration dependencies. My initial thought is that `NUMA_BALANCING` is fundamental, and it's contingent on several other factors: `ARCH_SUPPORTS_NUMA_BALANCING`, `ARCH_HAS_PTE_PROTNONE`, and crucially, the combination of `SMP`, `NUMA_MIGRATION`, and the *absence* of `PREEMPT_RT`. Clearly, real-time preemption throws a wrench into NUMA balancing. This makes perfect sense; real-time systems often have stricter and more predictable memory access requirements.

Now, `NUMA_MIGRATION` itself relies on both `MIGRATION` and `NUMA` being enabled. So, the dependency tree starts to branch, as you'd expect.

The real key point here is that `BPF_NUMAB` is specifically pegged to:

*   `BPF_NUMAB` (circular dependency which is probably just used to make it easier to find in the menuconfig)
*   `NUMA_BALANCING`
*   `MEMCG` (Memory Control Groups)
*   `BPF_SYSCALL`
*   `DEBUG_INFO_BTF`

That connection between `BPF_NUMAB` and `NUMA_BALANCING` is the one I need to be careful with. BPF integration with NUMA balancing is interesting. Given that BPF can be used for performance monitoring and memory access analysis, this linkage makes good sense. `MEMCG` suggests that the BPF-NUMA integration is likely used for per-cgroup memory management decisions.

The connection to `DEBUG_INFO_BTF` is also important. I suspect BTF (BPF Type Format) is used to map memory locations.

Let me see if there are related configurations or, if `MEMORY_TIERING` is relevant. In `mm/memory-tiers.c`, I see `folio_use_access_time()`. This looks like memory access tracking and tiering could be playing a part as well. Time to dive into the code for a closer look.



12/2 2026/11/13 02:23 tool grepper
0m Args:
{
  "Expression": "folio_use_access_time",
  "PathPrefixes": [
    "mm/"
  ]
}

Results:
{
  "Output": "mm/memory-tiers.c=50=static const struct bus_type memory_tier_subsys = {\n--\nmm/memory-tiers.c-56-/**\nmm/memory-tiers.c:57: * folio_use_access_time - check if a folio reuses cpupid for page access time\nmm/memory-tiers.c-58- * @folio: folio to check\n--\nmm/memory-tiers.c-65- */\nmm/memory-tiers.c:66:bool folio_use_access_time(struct folio *folio)\nmm/memory-tiers.c-67-{\n--\nmm/memory.c=6217=int numa_migrate_check(struct folio *folio, struct vm_fault *vmf,\n--\nmm/memory.c-6243-\t */\nmm/memory.c:6244:\tif (folio_use_access_time(folio))\nmm/memory.c-6245-\t\t*last_cpupid = (-1 \u0026 LAST_CPUPID_MASK);\n"
}

13/2 2026/11/13 02:23 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 26156
							output: 27
							thoughts: 24
						

Thoughts:
Here's my summary, as I see it:

**Digging into Memory Tier Compilation**

Okay, let's get down to brass tacks. I need to understand precisely how `mm/memory-tiers.c` is being compiled. This isn't just a casual glance; I want the specifics. The next logical step is to dive right into the `mm/Makefile`. That's where all the build magic happens. I'm expecting to find the relevant compilation flags, dependencies, and rules that govern the creation of the object files and ultimately, how this memory-tier functionality integrates into the larger kernel. This is where the core of my investigation will lie.



14/2 2026/11/13 02:24 tool grepper
0m Args:
{
  "Expression": "memory-tiers",
  "PathPrefixes": [
    "mm/Makefile"
  ]
}

Results:
{
  "Output": "mm/Makefile=99=obj-$(CONFIG_MIGRATION) += migrate.o\nmm/Makefile:100:obj-$(CONFIG_NUMA) += memory-tiers.o\nmm/Makefile-101-obj-$(CONFIG_DEVICE_MIGRATION) += migrate_device.o\n"
}

15/2 2026/11/13 02:24 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 26430
							output: 30
							thoughts: 961
						

Thoughts:
**Focusing on NUMA Balancing and BPF Integration**

Okay, so I'm looking at this `memory-tiers.o` and trying to figure out the best way to fuzz this.  My initial thought is that the build system is using the `CONFIG_NUMA` option.  Now, I see `CONFIG_BPF_NUMAB` is used in a few places, namely `kernel/sched/build_policy.c` and potentially others. I'll need to double check the Makefile to confirm.  

I'm zeroing in on this BPF integration with NUMA balancing, so I've identified the key functions in `kernel/sched/bpf_numab.c` and related headers.

Specifically, I need to choose my `FocusSymbols` carefully to avoid the trap of including ubiquitous functions that dilute the fuzzing effort. General memory allocators, deallocators, or core synchronization primitives are a no-go. I'm aiming for the feature-specific logic, the entrypoints, and functions that exercise the static inline helpers I see.

From `kernel/sched/bpf_numab.c`, I've got:

*   `bpf_numab_set_mode` - Perfect, a non-static BPF kfunc. This is a good entrypoint.
*   `bpf_numab_get_mode` - Another solid non-static BPF kfunc. Excellent!
*   `task_numab_mode` - Non-static, worth investigating.
*   `folio_numab_mode` - Also non-static.
*   `numab_memcg_reset` - Non-static, potentially relevant.

I also know there are static helper functions like `numab_memcg_mode` and `numab_memcg_active`.  I'll need to identify non-static callers that exercise these.

I've also got `include/linux/sched/numa_balancing.h` containing functions, such as `task_numab_tick_possible()`, `task_numab_enabled()`, `numab_in_tiering_mode()`, `task_numab_get_modes()`, `folio_numab_effective_mode()` and `folio_numab_in_tiering_mode()`. These are most likely helpers that are not called directly by the fuzzer.

Now, I'm thinking about related NUMA balancing functions in `kernel/sched/fair.c`. Ah, `task_numa_fault` looks promising.  I need to verify if this is an ubiquitous lifecycle hot-path or is specific enough. After a bit of examination, `task_numa_fault` appears to be specific to NUMA balancing faults, triggered by PTE\_PROTNONE. This is good; it is not a general page fault handler. It is called from `do_numa_page()`, so that may be another option for my `FocusSymbols`. Then, `should_numa_migrate_memory` might be used for `numamigrate_isolate_page()` or during the fault.

Let me check the `update_scan_period` function. I think it may be static. Let's see... I'll need to grep.



16/2 2026/11/13 02:24 tool grepper
0m Args:
{
  "Expression": "update_scan_period",
  "PathPrefixes": [
    "kernel/sched/"
  ]
}

Results:
{
  "Output": "kernel/sched/fair.c=4602=static void task_tick_numa(struct rq *rq, struct task_struct *curr)\n--\nkernel/sched/fair.c-4636-\nkernel/sched/fair.c:4637:static void update_scan_period(struct task_struct *p, int new_cpu)\nkernel/sched/fair.c-4638-{\n--\nkernel/sched/fair.c=4681=static inline void account_numa_dequeue(struct rq *rq, struct task_struct *p)\n--\nkernel/sched/fair.c-4684-\nkernel/sched/fair.c:4685:static inline void update_scan_period(struct task_struct *p, int new_cpu)\nkernel/sched/fair.c-4686-{\n--\nkernel/sched/fair.c=10016=static void migrate_task_rq_fair(struct task_struct *p, int new_cpu)\n--\nkernel/sched/fair.c-10038-\nkernel/sched/fair.c:10039:\tupdate_scan_period(p, new_cpu);\nkernel/sched/fair.c-10040-}\n"
}

17/2 2026/11/13 02:24 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 28440
							output: 33
							thoughts: 83
						

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

**NUMA Policy Inquiry**

Okay, so I'm looking at these functions, `task_tick_numa` and `update_scan_period`. Pretty sure those are static, but I need to be absolutely certain before I move forward. Wait a second, wasn't there something about NUMA policy in `mm/mempolicy.c`? Gotta double-check that location – it's a critical area for this line of thinking.

Now, let's see. There's this function, `folio_can_map_prot_numa(struct folio *folio, struct vm_area_struct *vma, bool is_private_single_threaded)`. I need to figure out if *that* one's static or if it's exported. The static/exported nature of this, or similar, functions will influence my next analysis. I'm going to run a quick search.



18/2 2026/11/13 02:24 tool grepper
0m Args:
{
  "Expression": "folio_can_map_prot_numa",
  "PathPrefixes": [
    "mm/"
  ]
}

Results:
{
  "Output": "mm/huge_memory.c=2726=int change_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma,\n--\nmm/huge_memory.c-2769-\nmm/huge_memory.c:2770:\t\tif (!folio_can_map_prot_numa(pmd_folio(*pmd), vma,\nmm/huge_memory.c-2771-\t\t\t\t\t     vma_is_single_threaded_private(vma)))\n--\nmm/internal.h=1248=static inline bool vma_is_single_threaded_private(struct vm_area_struct *vma)\n--\nmm/internal.h-1256-#ifdef CONFIG_NUMA_BALANCING\nmm/internal.h:1257:bool folio_can_map_prot_numa(struct folio *folio, struct vm_area_struct *vma,\nmm/internal.h-1258-\t\tbool is_private_single_threaded);\n--\nmm/internal.h-1260-#else\nmm/internal.h:1261:static inline bool folio_can_map_prot_numa(struct folio *folio,\nmm/internal.h-1262-\t\tstruct vm_area_struct *vma, bool is_private_single_threaded)\n--\nmm/mempolicy.c=790=static int queue_folios_hugetlb(pte_t *pte, unsigned long hmask,\n--\nmm/mempolicy.c-841-/**\nmm/mempolicy.c:842: * folio_can_map_prot_numa() - check whether the folio can map prot numa\nmm/mempolicy.c-843- * @folio: The folio whose mapping considered for being made NUMA hintable\n--\nmm/mempolicy.c-853- */\nmm/mempolicy.c:854:bool folio_can_map_prot_numa(struct folio *folio, struct vm_area_struct *vma,\nmm/mempolicy.c-855-\t\tbool is_private_single_threaded)\n--\nmm/mprotect.c=331=static long change_pte_range(struct mmu_gather *tlb,\n--\nmm/mprotect.c-385-\t\t\tif (prot_numa \u0026\u0026\nmm/mprotect.c:386:\t\t\t    !folio_can_map_prot_numa(folio, vma,\nmm/mprotect.c-387-\t\t\t\t\t\tis_private_single_threaded)) {\n"
}

19/2 2026/11/13 02:24 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 29398
							output: 29
							thoughts: 143
						

Thoughts:
**My Initial Thoughts on Folio Migration**

Okay, so I'm digging into memory migration, specifically around folios. My first thought is about this `folio_can_map_prot_numa` function – I see it's non-static and in `mm/mempolicy.c`. Interesting. I know that's related to memory policies, but where else might this be relevant?

My mind immediately jumps to `mm/migrate.c`. That's the obvious place to look for folio migration routines. Let's see... within `migrate.c`, I spot `folio_migrate_flags(struct folio *newfolio, struct folio *folio)`, `migrate_misplaced_folio_prepare(struct folio *folio, struct vm_area_struct *vma, int node)`, and `migrate_misplaced_folio(struct folio *folio, int node)`. I need to determine the scope of each.

I'm getting a hunch. I'll need to check if either `migrate_misplaced_folio_prepare` or `migrate_misplaced_folio` are declared as non-static. Those would be interesting candidates to explore further. This seems like a promising path.



20/2 2026/11/13 02:25 tool grepper
0m Args:
{
  "Expression": "migrate_misplaced_folio",
  "PathPrefixes": [
    "mm/"
  ]
}

Results:
{
  "Output": "mm/huge_memory.c=2319=vm_fault_t do_huge_pmd_numa_page(struct vm_fault *vmf)\n--\nmm/huge_memory.c-2358-\t\tgoto out_map;\nmm/huge_memory.c:2359:\tif (migrate_misplaced_folio_prepare(folio, vma, target_nid)) {\nmm/huge_memory.c-2360-\t\tflags |= TNF_MIGRATE_FAIL;\n--\nmm/huge_memory.c-2366-\nmm/huge_memory.c:2367:\tif (!migrate_misplaced_folio(folio, target_nid)) {\nmm/huge_memory.c-2368-\t\tflags |= TNF_MIGRATED;\n--\nmm/memory.c=6357=static vm_fault_t do_numa_page(struct vm_fault *vmf)\n--\nmm/memory.c-6403-\t\tgoto out_map;\nmm/memory.c:6404:\tif (migrate_misplaced_folio_prepare(folio, vma, target_nid)) {\nmm/memory.c-6405-\t\tflags |= TNF_MIGRATE_FAIL;\n--\nmm/memory.c-6413-\t/* Migrate to the requested node */\nmm/memory.c:6414:\tif (!migrate_misplaced_folio(folio, target_nid)) {\nmm/memory.c-6415-\t\tnid = target_nid;\n--\nmm/migrate.c=2669=static struct folio *alloc_misplaced_dst_folio(struct folio *src,\n--\nmm/migrate.c-2686-/*\nmm/migrate.c:2687: * Prepare for calling migrate_misplaced_folio() by isolating the folio if\nmm/migrate.c-2688- * permitted. Must be called with the PTL still held.\nmm/migrate.c-2689- */\nmm/migrate.c:2690:int migrate_misplaced_folio_prepare(struct folio *folio,\nmm/migrate.c-2691-\t\tstruct vm_area_struct *vma, int node)\n--\nmm/migrate.c-2750- * node. Caller is expected to have isolated the folio by calling\nmm/migrate.c:2751: * migrate_misplaced_folio_prepare(), which will result in an\nmm/migrate.c-2752- * elevated reference count on the folio. This function will un-isolate the\n--\nmm/migrate.c-2754- */\nmm/migrate.c:2755:int migrate_misplaced_folio(struct folio *folio, int node)\nmm/migrate.c-2756-{\n"
}

21/2 2026/11/13 02:25 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 30513
							output: 31
							thoughts: 680
						

Thoughts:
**Analyzing Potential Call Sites for Modified Folio Logic**

Okay, let's dive into this code. First thing I'm noticing is that `migrate_misplaced_folio_prepare` and `migrate_misplaced_folio` are *not* static, meaning they're directly implementing and exercising the misplaced folio logic that this patch is touching. Excellent, that's what I expected to see.

Now, what about `folio_use_access_time` in `mm/memory-tiers.c`? Checking... yup, it's also a non-static, exposed function: `bool folio_use_access_time(struct folio *folio)`. Good to know.

I'm also seeing some intriguing functions in `kernel/sched/fair.c`:
*   `task_numa_fault`
*   `should_numa_migrate_memory`
*   `account_mm_sched`
*   `can_migrate_task`

Hold on, `can_migrate_task` and `account_mm_sched`... those are likely called *very* frequently within the scheduler, potentially creating contention. We'll need to keep an eye on those! Let's check `task_numa_fault` and `should_numa_migrate_memory` more closely. It looks like `task_numa_fault` is only triggered on NUMA faults, specifically via `do_numa_page` and `do_huge_pmd_numa_page`, which is probably less frequent than the scheduler calls. `should_numa_migrate_memory` is called from `numamigrate_isolate_page` during NUMA migration.

Next, I see a set of functions introduced in `kernel/sched/bpf_numab.c`, including:
*   `bpf_numab_set_mode`
*   `bpf_numab_get_mode`
*   `task_numab_mode`
*   `folio_numab_mode`
*   `numab_memcg_reset`

Quick check to see if `task_numab_mode` and `folio_numab_mode` are non-static... and yes, they are: `int task_numab_mode(struct task_struct *p)`, `int folio_numab_mode(struct folio *folio)`. `void numab_memcg_reset(struct mem_cgroup *memcg)`, `int bpf_numab_set_mode(u64 cgid, enum numab_mode mode)`, and `s64 bpf_numab_get_mode(u64 cgid)` are also visible.

Wait, is `bpf_numab_set_mode` a symbol in vmlinux? Yes! And it seems that kfuncs, defined with `__bpf_kfunc int bpf_numab_set_mode(...)`, are normal C functions within the kernel. Let me just confirm that the kfunc compiler generates standard symbols. Yes, `__bpf_kfunc` is just an attribute/empty macro, used for BTF ID markings. Perfect. That helps verify their visibility.



22/2 2026/11/13 02:25 tool grepper
0m Args:
{
  "Expression": "#define __bpf_kfunc",
  "PathPrefixes": [
    "include/"
  ]
}

Results:
{
  "Output": "include/linux/btf.h-92- */\ninclude/linux/btf.h:93:#define __bpf_kfunc __used __retain __noclone noinline\ninclude/linux/btf.h-94-\ninclude/linux/btf.h:95:#define __bpf_kfunc_start_defs()\t\t\t\t\t       \\\ninclude/linux/btf.h-96-\t__diag_push();\t\t\t\t\t\t\t       \\\n--\ninclude/linux/btf.h-101-\ninclude/linux/btf.h:102:#define __bpf_kfunc_end_defs() __diag_pop()\ninclude/linux/btf.h-103-#define __bpf_hook_start() __bpf_kfunc_start_defs()\n"
}

23/2 2026/11/13 02:25 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 32116
							output: 28
							thoughts: 222
						

Thoughts:
**Investigating BPF and NUMA Integration in the Kernel**

Okay, so I'm looking at how BPF interacts with NUMA memory allocation, specifically concerning `bpf_numab_set_mode` and `bpf_numab_get_mode`. I see that these are defined as `noinline` symbols within `vmlinux`, thanks to the `#define __bpf_kfunc __used __retain __noclone noinline` macro. And it looks like `task_numab_mode`, `folio_numab_mode`, and `numab_memcg_reset` are exported symbols that are shared between `fair.c` and `memcontrol.c`.

Now, I'm thinking about how this ties into the broader scheduling policy framework. Let's check `build_policy.c`! Aha! I see `#ifdef CONFIG_BPF_NUMAB`, which then `#include "bpf_numab.c"`. That's interesting, `bpf_numab.c` is *directly* included within `build_policy.c`.

Now I need to understand the relationship between `fair.c` and `build_policy.c`. Is `fair.c` also included in `build_policy.c`? Or is it compiled separately and linked in? Let's take a look at `kernel/sched/build_policy.c` to clarify things.



24/2 2026/11/13 02:26 tool grepper
0m Args:
{
  "Expression": "fair\\.c",
  "PathPrefixes": [
    "kernel/sched/"
  ]
}

Results:
{
  "Output": "kernel/sched/build_policy.c-6- * ( Incidentally, the size of the compilation unit is roughly\nkernel/sched/build_policy.c:7: *   comparable to core.c and fair.c, the other two big\nkernel/sched/build_policy.c-8- *   compilation units. This helps balance build time, while\n--\nkernel/sched/build_policy.c-11- *\nkernel/sched/build_policy.c:12: * core.c and fair.c are built separately.\nkernel/sched/build_policy.c-13- */\n--\nkernel/sched/build_utility.c-6- * ( Incidentally, the size of the compilation unit is roughly\nkernel/sched/build_utility.c:7: *   comparable to core.c, fair.c, smp.c and policy.c, the other\nkernel/sched/build_utility.c-8- *   big compilation units. This helps balance build time, while\n--\nkernel/sched/ext/internal.h=132=enum scx_ops_flags {\n--\nkernel/sched/ext/internal.h-219-\t * If set, tasks default to requesting lazy rescheduling when their\nkernel/sched/ext/internal.h:220:\t * slice runs out at the tick, the way fair.c expires a slice from\nkernel/sched/ext/internal.h-221-\t * update_curr(). The default is copied to p-\u003escx.lazy_resched\n--\nkernel/sched/idle.c-6- * (NOTE: these are not related to SCHED_IDLE batch scheduled\nkernel/sched/idle.c:7: *        tasks which are handled in sched/fair.c )\nkernel/sched/idle.c-8- */\n--\nkernel/sched/pelt.c-22- *\nkernel/sched/pelt.c:23: *  Move PELT related code from fair.c into this pelt.c file\nkernel/sched/pelt.c-24- *  Author: Vincent Guittot \u003cvincent.guittot@linaro.org\u003e\n--\nkernel/sched/topology.c=1334=build_overlap_sched_groups(struct sched_domain *sd, int cpu)\n--\nkernel/sched/topology.c-1428-/*\nkernel/sched/topology.c:1429: * Package topology (also see the load-balance blurb in fair.c)\nkernel/sched/topology.c-1430- *\n--\nkernel/sched/topology.c-1479- *  - The first is the balance_cpu (see should_we_balance() and the\nkernel/sched/topology.c:1480: *    load-balance blurb in fair.c); for each group we only want 1 CPU to\nkernel/sched/topology.c-1481- *    continue balancing at a higher domain.\n"
}

25/2 2026/11/13 02:26 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 33371
							output: 31
							thoughts: 631
						

Thoughts:
**Analyzing the NUMAB Patch's Dependencies and Interactions**

Okay, so I'm diving into this NUMAB patch and need to understand how everything's wired together. First, I'm noting that `core.c` and `fair.c` are built as separate units, while `bpf_numab.c` gets included in `build_policy.c`. This means that functions like `task_numab_mode`, `folio_numab_mode`, and `numab_memcg_reset` in `bpf_numab.c` have to have external linkage because they're being called from `fair.c` and `memcontrol.c`. That's important for the build process.

Now, let's look at `memcontrol.c`. I see `mem_cgroup_css_offline()` and `mem_cgroup_css_reset()` both call `numab_memcg_reset(memcg)`, which confirms the interaction I expect. Also, `mem_cgroup_alloc()` initializes `memcg->numab_mode` to `NUMAB_FOLLOW_SYSTEM`. This is the starting point for memory control.

I need to make sure I've got a complete list of the modified or added functions. So, in `kernel/sched/bpf_numab.c`, I've got `bpf_numab_set_mode`, `bpf_numab_get_mode`, `task_numab_mode`, `folio_numab_mode`, and `numab_memcg_reset`. In `kernel/sched/fair.c`, I'm looking at `task_numa_fault` and `should_numa_migrate_memory`. Then there's `folio_can_map_prot_numa` in `mm/mempolicy.c`, `folio_use_access_time` in `mm/memory-tiers.c`, and finally, `migrate_misplaced_folio` and `migrate_misplaced_folio_prepare` from `mm/migrate.c`.

Okay, next up, the configurations. I see `BPF_NUMAB`, naturally, but also `NUMA_BALANCING`, `MEMCG`, `BPF_SYSCALL`, and `DEBUG_INFO_BTF`. Now, I want to make sure I've got all the dependencies right, especially because `BPF_NUMAB` looks like a key enabler. Checking the Kconfig, it looks like it depends on `NUMA_BALANCING && MEMCG && BPF_SYSCALL && DEBUG_INFO_BTF`.

So let me follow the rabbit hole. What does `NUMA_BALANCING` depend on? It needs `ARCH_SUPPORTS_NUMA_BALANCING && ARCH_HAS_PTE_PROTNONE && SMP && NUMA_MIGRATION && !PREEMPT_RT`. On x86, which is what I'm primarily focused on, `ARCH_SUPPORTS_NUMA_BALANCING` and `ARCH_HAS_PTE_PROTNONE` are both basically always 'y' because they are selected by the architecture. Then, `NUMA_MIGRATION` needs `MIGRATION && NUMA`. So, `NUMA` itself is a crucial, underlying requirement. What about `MEMORY_TIERING`? I should probably check that too.



26/2 2026/11/13 02:27 tool grepper
0m Args:
{
  "Expression": "config MEMORY_TIERING",
  "PathPrefixes": [
    "mm/Kconfig"
  ]
}

Results:
{
  "Output": "no matches"
}

27/2 2026/11/13 02:27 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 34781
							output: 27
							thoughts: 14
						

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

**Investigating `MEMORY_TIERING`**

Alright, let's get down to brass tacks. My initial thought is to dive right into the code and pinpoint precisely where `MEMORY_TIERING` is defined. This isn't just a casual stroll through the codebase; I need to know the origin, the scope, the intended behavior. This macro, constant, or whatever it is, is clearly central to memory management or some architectural principle regarding memory usage, given the name. I can't build any understanding of the system without starting there. Locating its definition will immediately contextualize the surrounding code and uncover the designers' intentions behind using a tiered approach. So, let's fire up the IDE/grep/whatever tool is at hand and start tracking it down. We are going to find its declaration, and its implementation.



28/2 2026/11/13 02:27 tool grepper
0m Args:
{
  "Expression": "MEMORY_TIERING",
  "PathPrefixes": [
    "mm/"
  ]
}

Results:
{
  "Output": "no matches"
}

29/2 2026/11/13 02:27 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 35027
							output: 20
							thoughts: 16
						

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

**Kernel Memory Tiering Investigation**

Okay, so I'm thinking, "Where the heck is this `MEMORY_TIERING` thing showing up in the kernel source?" Clearly, I need to get a handle on how this feature, or macro, is being used. First instinct, like always, is to go wide with a grep. I need to cast a broad net. I'll launch a `grep` across the *entire* kernel source tree. This is the starting point, the baseline. From there, I can narrow down my search based on the context of the results. I'm anticipating a lot of hits initially, but that's fine. It's about getting the full picture, identifying the different areas that interact with it, and understanding the scope of its impact. This is the quickest way to get a bird's eye view before I drill down. Now, let's see what the grep pulls up...



30/2 2026/11/13 02:28 tool grepper
0m Args:
{
  "Expression": "config MEMORY_TIERING"
}

Results:
{
  "Output": "no matches"
}

31/2 2026/11/13 02:28 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 35289
							output: 25
							thoughts: 21
						

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

**Investigating NUMA Balancing and Memory Tiering**

Alright, let's dive in. My immediate thought is to pinpoint the exact definition of `NUMA_BALANCING_MEMORY_TIERING`. This isn't just a generic concept; I need to know the specific implementation, the flags used, the data structures involved, the whole nine yards. Where *exactly* is this key variable or macro defined? I need to understand its scope within the system. Is it a kernel-level flag, a userspace option, something in a configuration file? The source code is calling my name. This is where the real nuance lies. Only then can I start to understand the implications of it for a specific platform.



32/2 2026/11/13 02:28 tool grepper
0m Args:
{
  "Expression": "NUMA_BALANCING_MEMORY_TIERING"
}

Results:
{
  "Output": "Documentation/admin-guide/sysctl/kernel.rst=732=The value to set can be the result of ORing the following:\n--\nDocumentation/admin-guide/sysctl/kernel.rst-736-1 NUMA_BALANCING_NORMAL\nDocumentation/admin-guide/sysctl/kernel.rst:737:2 NUMA_BALANCING_MEMORY_TIERING\nDocumentation/admin-guide/sysctl/kernel.rst-738-= =================================\n--\nDocumentation/admin-guide/sysctl/kernel.rst=751=feature should be disabled.\nDocumentation/admin-guide/sysctl/kernel.rst-752-\nDocumentation/admin-guide/sysctl/kernel.rst:753:Or NUMA_BALANCING_MEMORY_TIERING to optimize page placement among\nDocumentation/admin-guide/sysctl/kernel.rst-754-different types of memory (represented as different NUMA nodes) to\n--\nDocumentation/mm/physical_memory.rst=374=General\n--\nDocumentation/mm/physical_memory.rst-383-  kswapd stops reclaiming (a zone is balanced) when the\nDocumentation/mm/physical_memory.rst:384:  ``NUMA_BALANCING_MEMORY_TIERING`` bit of ``sysctl_numa_balancing_mode`` is not\nDocumentation/mm/physical_memory.rst-385-  set. The promo watermark is used for memory tiering and NUMA balancing. When\nDocumentation/mm/physical_memory.rst-386-  the amount of free pages in a zone is above the promo watermark, kswapd stops\nDocumentation/mm/physical_memory.rst:387:  reclaiming when the ``NUMA_BALANCING_MEMORY_TIERING`` bit of\nDocumentation/mm/physical_memory.rst-388-  ``sysctl_numa_balancing_mode`` is set. The watermarks are set by\n--\ninclude/linux/sched/numa_balancing.h=42=enum numab_mode {\n--\ninclude/linux/sched/numa_balancing.h-45-\tNUMAB_NORMAL\t\t= NUMA_BALANCING_NORMAL,\ninclude/linux/sched/numa_balancing.h:46:\tNUMAB_TIERING\t\t= NUMA_BALANCING_MEMORY_TIERING,\ninclude/linux/sched/numa_balancing.h-47-\tNUMAB_NORMAL_TIERING\t= NUMA_BALANCING_NORMAL |\ninclude/linux/sched/numa_balancing.h:48:\t\t\t\t  NUMA_BALANCING_MEMORY_TIERING,\ninclude/linux/sched/numa_balancing.h-49-};\n--\ninclude/linux/sched/numa_balancing.h=92=static inline bool numab_in_tiering_mode(void)\ninclude/linux/sched/numa_balancing.h-93-{\ninclude/linux/sched/numa_balancing.h:94:\treturn sysctl_numa_balancing_mode \u0026 NUMA_BALANCING_MEMORY_TIERING;\ninclude/linux/sched/numa_balancing.h-95-}\n--\ninclude/linux/sched/sysctl.h=15=enum sched_tunable_scaling {\n--\ninclude/linux/sched/sysctl.h-23-#define NUMA_BALANCING_NORMAL\t\t0x1\ninclude/linux/sched/sysctl.h:24:#define NUMA_BALANCING_MEMORY_TIERING\t0x2\ninclude/linux/sched/sysctl.h-25-\n--\nkernel/sched/core.c=4726=static int sysctl_numa_balancing(const struct ctl_table *table, int write,\n--\nkernel/sched/core.c-4741-\tif (write) {\nkernel/sched/core.c:4742:\t\tif (!(sysctl_numa_balancing_mode \u0026 NUMA_BALANCING_MEMORY_TIERING) \u0026\u0026\nkernel/sched/core.c:4743:\t\t    (state \u0026 NUMA_BALANCING_MEMORY_TIERING))\nkernel/sched/core.c-4744-\t\t\treset_memory_tiering();\n"
}

33/2 2026/11/13 02:28 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 36510
							output: 268
							thoughts: 1140
						

Thoughts:
**Analysis of NUMA Balancing for Fuzzing Focus**

Okay, let's break this down for a fuzzing strategy. The core area of interest revolves around `NUMA_BALANCING_MEMORY_TIERING`, which is controlled by `sysctl_numa_balancing_mode`. I need to identify specific, non-ubiquitous kernel functions related to this feature that would be good targets for fuzzing.

First, I need to make sure all of the right config options are set.  The patch includes `CONFIG_BPF_NUMAB` and `CONFIG_NUMA_BALANCING`, which I'll remember. From the Kconfig files, I see that this all depends on `NUMA_BALANCING`, `MEMCG`, `BPF_SYSCALL`, `DEBUG_INFO_BTF`, and `NUMA` (because of the dependency chain to `NUMA_MIGRATION`). I'll need to enable these. Specifically, `BPF_NUMAB` enables the "Per-cgroup NUMA balancing mode selection". I'll also double check the includes and usage of this functionality in relation to `SCHED_CACHE` in `fair.c`.

Based on this, my required EnableConfigs are: `BPF_NUMAB`, `NUMA_BALANCING`, `MEMCG`, `BPF_SYSCALL`, `DEBUG_INFO_BTF`, and `NUMA`.

Now, the crucial part: identifying the *right* FocusSymbols. I need functions that are *directly* involved in the NUMA balancing logic, and crucially, they need to *not* be used everywhere. Let's look at the candidates:

1.  `bpf_numab_set_mode`: Looks good as an entry point, used via BPF.
2.  `bpf_numab_get_mode`: Another good BPF entry point.
3.  `task_numab_mode`: This is used to query the task memcg mode, but only when `numab_cgroup_mode_set` is true. Not ubiquitous.
4.  `folio_numab_mode`: Similar to `task_numab_mode`, also only called when `numab_cgroup_mode_set` is true.
5.  `numab_memcg_reset`: Called on memcg offline/reset. Seems specific enough.
6.  `task_numa_fault`: Modified to check `task_numab_get_modes`.  This is only triggered on NUMA hint faults (`PROT_NONE` induced by numa scan). Definitely not ubiquitous.
7.  `should_numa_migrate_memory`:  NUMA migration decision. Modified to check `folio_numab_in_tiering_mode`. Called during NUMA fault migration handling.
8.  `migrate_misplaced_folio`:  Migrates based on NUMA balancing.  Also triggered during NUMA fault handling.
9.  `migrate_misplaced_folio_prepare`:  Prepares migration. Still part of fault handling.
10. `folio_can_map_prot_numa`: Page protection check, using `folio_numab_effective_mode`, called during task numa scan (`change_pte_range` / `change_huge_pmd`).

I need to confirm that these aren't called constantly in the kernel. `task_numa_fault` looks promising as it is only triggered when there is a NUMA hint fault. The BPF kfuncs (`bpf_numab_set/get_mode`) are also specific because they are only called via BPF programs. `task_numab_mode` and `folio_numab_mode` are tied to the cgroup mode being active and load-balancing paths.  `numab_memcg_reset` is only called on memcg changes. `should_numa_migrate_memory`, `migrate_misplaced_folio`, and `folio_can_map_prot_numa` all are specific to migration handling and numa scans.

So, I think I've got a good list of non-ubiquitous FocusSymbols:

*   `bpf_numab_set_mode`
*   `bpf_numab_get_mode`
*   `task_numab_mode`
*   `folio_numab_mode`
*   `numab_memcg_reset`
*   `task_numa_fault`
*   `should_numa_migrate_memory`
*   `migrate_misplaced_folio`
*   `folio_can_map_prot_numa`

I've verified that all the requirements are met, and I


34/2 2026/11/13 02:28 tool set-results
0m Args:
{
  "EnableConfigs": [
    "BPF_NUMAB",
    "NUMA_BALANCING",
    "MEMCG",
    "BPF_SYSCALL",
    "DEBUG_INFO_BTF",
    "NUMA"
  ],
  "FocusSymbols": [
    "bpf_numab_set_mode",
    "bpf_numab_get_mode",
    "task_numab_mode",
    "folio_numab_mode",
    "numab_memcg_reset",
    "task_numa_fault",
    "should_numa_migrate_memory",
    "migrate_misplaced_folio",
    "folio_can_map_prot_numa"
  ],
  "Reasoning": "The patch introduces per-cgroup NUMA balancing mode selection via BPF kfuncs (bpf_numab_set_mode, bpf_numab_get_mode) and modifies NUMA balancing scan, fault handling, and folio migration logic across the scheduler and memory management subsystems (fair.c, mempolicy.c, migrate.c, memory-tiers.c). These changes are in core, reachable code paths in virtualized environments with NUMA and cgroups enabled.",
  "WorthFuzzing": true
}

Results:
{
  "EnableConfigs": [
    "BPF_NUMAB",
    "NUMA_BALANCING",
    "MEMCG",
    "BPF_SYSCALL",
    "DEBUG_INFO_BTF",
    "NUMA"
  ],
  "FocusSymbols": [
    "bpf_numab_set_mode",
    "bpf_numab_get_mode",
    "task_numab_mode",
    "folio_numab_mode",
    "numab_memcg_reset",
    "task_numa_fault",
    "should_numa_migrate_memory",
    "migrate_misplaced_folio",
    "folio_can_map_prot_numa"
  ],
  "Reasoning": "The patch introduces per-cgroup NUMA balancing mode selection via BPF kfuncs (bpf_numab_set_mode, bpf_numab_get_mode) and modifies NUMA balancing scan, fault handling, and folio migration logic across the scheduler and memory management subsystems (fair.c, mempolicy.c, migrate.c, memory-tiers.c). These changes are in core, reachable code paths in virtualized environments with NUMA and cgroups enabled.",
  "WorthFuzzing": true
}

35/1 2026/11/13 02:28 action If
1m Args:
{
  "WorthFuzzing": true
}

Results:
null

36/2 2026/11/13 02:28 agent kmsan-evaluator
1m Model:
core

Args:
null

Results:
{
  "KMSANReasoning": "The patch series introduces per-cgroup NUMA balancing mode selection via BPF kfuncs (CONFIG_BPF_NUMAB). It adds an integer field `numab_mode` to `struct mem_cgroup`, initializes it in `mem_cgroup_alloc` (which allocates via kmem_cache_zalloc), and updates scheduler and memory tiering logic to consult the effective NUMA balancing mode.\n\n1. No kernel structures or data buffers are copied to user space (no copy_to_user, netlink skb, ioctl output, or info-leak vectors).\n2. All newly introduced and modified variables (such as `numab_enabled` and `numab_tiering` via `task_numab_get_modes`) are deterministically initialized before any read or branch.\n3. The newly added struct field `memcg-\u003enumab_mode` is initialized upon allocation and reset during css offline/reset.\n4. The potential risks introduced by this change are related to concurrency, RCU dereferencing of cgroups/memcgs, cgroup reference counting, and lock handling (mutex vs static keys), all of which are covered by standard bug detectors, KASAN, and LOCKDEP.\n\nBecause there are no uninitialized memory access risks or info-leaks, a dedicated KMSAN fuzzing session is not warranted.",
  "NeedsKMSAN": false
}

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

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

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

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

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

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

Use your code access tools to inspect the surrounding code if necessary, then provide
detailed KMSANReasoning contrasting KASAN vs KMSAN applicability for this patch.
Prefer calling several tools at the same time to save round-trips.


Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.

Prompt:
Target architecture: amd64

For your convenience, here is the diff of the changes:
commit 1c523a70068adf269503582cd4945bd6c12b20f8
Author: syz-cluster <triage@syzkaller.com>
Date:   Fri Nov 13 02:22:16 2026 +0000

    syz-cluster: applied patch under review

diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index 69e1bcc67c588d..78ea21bfab95e0 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -342,6 +342,12 @@ struct mem_cgroup {
 	 */
 	bool zswap_writeback;
 #endif
+
+#ifdef CONFIG_BPF_NUMAB
+	/* per-cgroup NUMA balancing mode request; -1 follows the global state. */
+	int numab_mode;
+#endif
+
 	/* Not padded: nodeinfo[] is read-mostly too, let it share the line. */
 	__cacheline_group_end(memcg_read_mostly);
 
diff --git a/include/linux/sched/numa_balancing.h b/include/linux/sched/numa_balancing.h
index 52b22c5c396db0..e10093386cf739 100644
--- a/include/linux/sched/numa_balancing.h
+++ b/include/linux/sched/numa_balancing.h
@@ -8,6 +8,7 @@
  */
 
 #include <linux/sched.h>
+#include <linux/sched/sysctl.h>
 
 #define TNF_MIGRATED	0x01
 #define TNF_NO_GROUP	0x02
@@ -32,6 +33,122 @@ extern void set_numabalancing_state(bool enabled);
 extern void task_numa_free(struct task_struct *p, bool final);
 bool should_numa_migrate_memory(struct task_struct *p, struct folio *folio,
 				int src_nid, int dst_cpu);
+
+extern struct static_key_false sched_numa_balancing;
+
+/*
+ * Mode values used by the NUMA balancing helpers.
+ */
+enum numab_mode {
+	NUMAB_FOLLOW_SYSTEM	= -1,
+	NUMAB_DISABLED		= NUMA_BALANCING_DISABLED,
+	NUMAB_NORMAL		= NUMA_BALANCING_NORMAL,
+	NUMAB_TIERING		= NUMA_BALANCING_MEMORY_TIERING,
+	NUMAB_NORMAL_TIERING	= NUMA_BALANCING_NORMAL |
+				  NUMA_BALANCING_MEMORY_TIERING,
+};
+
+#ifdef CONFIG_BPF_NUMAB
+extern struct static_key_false numab_cgroup_mode_set;
+
+int task_numab_mode(struct task_struct *p);
+int folio_numab_mode(struct folio *folio);
+void numab_memcg_reset(struct mem_cgroup *memcg);
+#endif
+
+/*
+ * Whether any task might need the NUMA scanner on this tick.  This is
+ * only the cheap global gate; the per-task request is checked after the
+ * scan period in task_tick_numa().
+ */
+static inline bool task_numab_tick_possible(void)
+{
+#ifdef CONFIG_BPF_NUMAB
+	if (static_branch_likely(&numab_cgroup_mode_set))
+		return true;
+#endif
+	return static_branch_unlikely(&sched_numa_balancing);
+}
+
+/*
+ * Whether NUMA balancing applies to @p: the global sysctl state, possibly
+ * overridden by the requests of @p's memcg and of every ancestor.
+ * A memcg's request always takes priority over the system setting.
+ */
+static inline bool task_numab_enabled(struct task_struct *p)
+{
+#ifdef CONFIG_BPF_NUMAB
+	if (static_branch_unlikely(&numab_cgroup_mode_set)) {
+		int mode = task_numab_mode(p);
+
+		if (mode != NUMAB_FOLLOW_SYSTEM)
+			return mode != NUMAB_DISABLED;
+	}
+#endif
+	return static_branch_likely(&sched_numa_balancing);
+}
+
+/* Whether NUMA balancing is in memory tiering mode. */
+static inline bool numab_in_tiering_mode(void)
+{
+	return sysctl_numa_balancing_mode & NUMA_BALANCING_MEMORY_TIERING;
+}
+
+/*
+ * Return both task-side decisions from one request lookup.  This is used
+ * by paths that need to know both whether to account the fault and
+ * whether slow-tier faults should be skipped.
+ */
+static inline void task_numab_get_modes(struct task_struct *p, bool *enabled,
+					bool *tiering)
+{
+#ifdef CONFIG_BPF_NUMAB
+	if (static_branch_unlikely(&numab_cgroup_mode_set)) {
+		int mode = task_numab_mode(p);
+
+		if (mode != NUMAB_FOLLOW_SYSTEM) {
+			*enabled = mode != NUMAB_DISABLED;
+			*tiering = mode & NUMAB_TIERING;
+			return;
+		}
+	}
+#endif
+	*enabled = static_branch_likely(&sched_numa_balancing);
+	*tiering = numab_in_tiering_mode();
+}
+
+/*
+ * The combined folio-side request, with the global sysctl state used when
+ * no memcg requests a mode.  DISABLED never speaks for memory, so only
+ * NORMAL and TIERING are present here.  Callers that need more than one
+ * bit should use this helper once rather than querying each bit
+ * separately.
+ */
+static inline int folio_numab_effective_mode(struct folio *folio)
+{
+#ifdef CONFIG_BPF_NUMAB
+	if (static_branch_unlikely(&numab_cgroup_mode_set)) {
+		int mode = folio_numab_mode(folio);
+
+		if (mode != NUMAB_FOLLOW_SYSTEM)
+			return mode;
+	}
+#endif
+	return sysctl_numa_balancing_mode;
+}
+
+/*
+ * Whether @folio's memory participates in tiering, i.e. whether its
+ * _last_cpupid carries an access time instead of a cpupid. The
+ * requests of the owner memcg and of every ancestor are combined.
+ * DISABLED never speaks for memory (it is a task-side request), so only
+ * NORMAL and TIERING are consulted here; without either, the global
+ * sysctl decides.
+ */
+static inline bool folio_numab_in_tiering_mode(struct folio *folio)
+{
+	return folio_numab_effective_mode(folio) & NUMAB_TIERING;
+}
 #else
 static inline void task_numa_fault(int last_node, int node, int pages,
 				   int flags)
@@ -52,6 +169,33 @@ static inline bool should_numa_migrate_memory(struct task_struct *p,
 {
 	return true;
 }
+
+static inline bool task_numab_enabled(struct task_struct *p)
+{
+	return false;
+}
+
+static inline bool numab_in_tiering_mode(void)
+{
+	return false;
+}
+
+static inline bool folio_numab_in_tiering_mode(struct folio *folio)
+{
+	return false;
+}
+
+static inline void task_numab_get_modes(struct task_struct *p, bool *enabled,
+					bool *tiering)
+{
+	*enabled = false;
+	*tiering = false;
+}
+
+static inline bool task_numab_tick_possible(void)
+{
+	return false;
+}
 #endif
 
 #endif /* _LINUX_SCHED_NUMA_BALANCING_H */
diff --git a/init/Kconfig b/init/Kconfig
index 4013781e0a0292..3f38cf8077a3ca 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -827,6 +827,29 @@ config NUMA_BALANCING
 
 	  This system will be inactive on UMA systems.
 
+config BPF_NUMAB
+	bool "Per-cgroup NUMA balancing mode selection"
+	default n
+	depends on NUMA_BALANCING && MEMCG && BPF_SYSCALL && DEBUG_INFO_BTF
+	help
+	  Allow BPF programs to select the NUMA balancing mode (disabled,
+	  normal, memory tiering, or both) on a per-cgroup basis, overriding the
+	  global NUMA balancing sysctl. A latency-sensitive service can
+	  opt its tasks out of balancing, or a batch service can have its
+	  PMEM-resident memory promoted when hot, without changing the
+	  mode for the rest of the system.
+
+	  The request is written and read back through the
+	  bpf_numab_set_mode() and bpf_numab_get_mode() kfuncs, callable
+	  from BPF_PROG_TYPE_SYSCALL programs. The mode is stored in the
+	  target cgroup's memcg; setting it on a cgroup without the memory
+	  controller enabled is rejected.  This interface only applies to
+	  cgroups on the default hierarchy (cgroup v2).  While no memcg
+	  makes a request, the NUMA balancing hot paths pay a single
+	  patched-out branch and nothing else.
+
+	  If unsure, say N.
+
 config SCHED_CACHE
 	bool "Cache aware load balance"
 	default y
diff --git a/kernel/sched/bpf_numab.c b/kernel/sched/bpf_numab.c
new file mode 100644
index 00000000000000..c7f44bf383f61d
--- /dev/null
+++ b/kernel/sched/bpf_numab.c
@@ -0,0 +1,261 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Per-cgroup NUMA balancing mode
+ *
+ * A cgroup overrides the global state through its memcg. Task and folio
+ * lookups walk the memcg chain; an opt-out binds the subtree, while the
+ * remaining bits OR together.
+ *
+ * Author: Yafang Shao <laoar.shao@gmail.com>
+ */
+#include <linux/bpf.h>
+#include <linux/btf.h>
+#include <linux/cgroup.h>
+#include <linux/memcontrol.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/sched.h>
+#include <linux/sched/numa_balancing.h>
+
+DEFINE_STATIC_KEY_FALSE(numab_cgroup_mode_set);
+
+/* Whether this memcg may still own a NUMA balancing request. */
+static bool numab_memcg_active(struct mem_cgroup *memcg)
+{
+	unsigned int flags;
+
+	if (mem_cgroup_is_root(memcg))
+		return true;
+
+	/* Take one snapshot so all three state bits describe the same moment. */
+	flags = READ_ONCE(memcg->css.flags);
+
+	return (flags & CSS_ONLINE) &&
+	       !(flags & CSS_DYING) &&
+	       (flags & CSS_VISIBLE);
+}
+
+/*
+ * Combine the requests of @memcg and of every ancestor. A task chain
+ * stops at an explicit opt-out: a task can never be forced into
+ * balancing. A folio chain skips opt-outs instead (a memcg's DISABLED
+ * request only speaks for its tasks, never for its memory) and keeps
+ * collecting the remaining requests.
+ */
+static int numab_memcg_mode(struct mem_cgroup *memcg, bool folio_side)
+{
+	int req = 0;
+
+	for (; memcg; memcg = parent_mem_cgroup(memcg)) {
+		int mode;
+
+		if (!numab_memcg_active(memcg))
+			continue;
+
+		/* Paired with WRITE_ONCE() under numab_mode_mutex. */
+		mode = data_race(READ_ONCE(memcg->numab_mode));
+		if (mode == NUMAB_FOLLOW_SYSTEM)
+			continue;
+		if (mode == NUMAB_DISABLED) {
+			if (!folio_side)
+				return NUMAB_DISABLED;
+			continue;
+		}
+		req |= mode;
+	}
+	return req ?: NUMAB_FOLLOW_SYSTEM;
+}
+
+/*
+ * The combined request for @p. Kernel threads have no user memory to
+ * balance, so they make no request.  The walk needs no reference: the
+ * memcg chain is RCU-protected, so rcu_read_lock() keeps it alive for
+ * the whole walk.
+ */
+int task_numab_mode(struct task_struct *p)
+{
+	struct mem_cgroup *memcg;
+	int mode;
+
+	if (mem_cgroup_disabled() || !p->mm)
+		return NUMAB_FOLLOW_SYSTEM;
+
+	rcu_read_lock();
+	memcg = mem_cgroup_from_task(p);
+	mode = memcg ? numab_memcg_mode(memcg, false) : NUMAB_FOLLOW_SYSTEM;
+	rcu_read_unlock();
+	return mode;
+}
+
+/*
+ * The combined request for @folio's owner. An uncharged folio makes no
+ * request. A folio charged to a memcg whose cgroup the kfunc cannot
+ * reach carries no request and follows the global state.
+ */
+int folio_numab_mode(struct folio *folio)
+{
+	struct mem_cgroup *memcg;
+	int mode;
+
+	if (mem_cgroup_disabled())
+		return NUMAB_FOLLOW_SYSTEM;
+
+	rcu_read_lock();
+	memcg = folio_memcg(folio);
+	mode = memcg ? numab_memcg_mode(memcg, true) : NUMAB_FOLLOW_SYSTEM;
+	rcu_read_unlock();
+	return mode;
+}
+
+static DEFINE_MUTEX(numab_mode_mutex);
+
+/*
+ * Reset the request when the memory controller is disabled, the memcg is
+ * offlined or the memcg is pinned.  A memcg may be made visible again, so
+ * it must start transparent.
+ */
+void numab_memcg_reset(struct mem_cgroup *memcg)
+{
+	mutex_lock(&numab_mode_mutex);
+	if (memcg->numab_mode != NUMAB_FOLLOW_SYSTEM) {
+		WRITE_ONCE(memcg->numab_mode, NUMAB_FOLLOW_SYSTEM);
+		static_branch_dec(&numab_cgroup_mode_set);
+	}
+	mutex_unlock(&numab_mode_mutex);
+}
+
+__bpf_kfunc_start_defs();
+
+/**
+ * bpf_numab_set_mode() - Set the NUMA balancing mode of a cgroup's memcg.
+ * @cgid: kernfs id of the cgroup whose memcg is updated
+ * @mode: NUMAB_FOLLOW_SYSTEM to defer to the global sysctl state, or a
+ *        NUMAB_* mode. The kernel reads the bits independently, the way
+ *        kernel.numa_balancing reads them, so
+ *        NUMAB_NORMAL|NUMAB_TIERING engages both modes. A
+ *        NUMAB_DISABLED request only speaks for the memcg's tasks, never
+ *        for its memory, which follows the remaining requests of its
+ *        ancestors.
+ *
+ * The cgroup must have a visible, online memory cgroup; otherwise the
+ * update is rejected.
+ *
+ * Return: 0 on success; %-EINVAL for a mode outside the domain;
+ *         %-ENOENT for an id that resolves to no cgroup; %-EOPNOTSUPP
+ *         for a cgroup without a visible, online memcg.
+ */
+__bpf_kfunc int bpf_numab_set_mode(u64 cgid, enum numab_mode mode)
+{
+	struct cgroup_subsys_state *css;
+	struct mem_cgroup *memcg;
+	struct cgroup *cgrp;
+	int old;
+
+	if (mode != NUMAB_FOLLOW_SYSTEM &&
+	    (mode < 0 || mode > NUMAB_NORMAL_TIERING))
+		return -EINVAL;
+
+	cgrp = __cgroup_get_from_id(cgid);
+	if (IS_ERR(cgrp))
+		return PTR_ERR(cgrp);
+
+	if (mem_cgroup_disabled()) {
+		cgroup_put(cgrp);
+		return -EOPNOTSUPP;
+	}
+
+	rcu_read_lock();
+	css = cgroup_css(cgrp, &memory_cgrp_subsys);
+	memcg = mem_cgroup_from_css(css);
+	if (memcg && !mem_cgroup_tryget_online(memcg))
+		memcg = NULL;
+	rcu_read_unlock();
+
+	if (!memcg) {
+		cgroup_put(cgrp);
+		return -EOPNOTSUPP;
+	}
+
+	mutex_lock(&numab_mode_mutex);
+	if (!numab_memcg_active(memcg)) {
+		mutex_unlock(&numab_mode_mutex);
+		mem_cgroup_put(memcg);
+		cgroup_put(cgrp);
+		return -EOPNOTSUPP;
+	}
+
+	old = READ_ONCE(memcg->numab_mode);
+	if (old == NUMAB_FOLLOW_SYSTEM && mode != NUMAB_FOLLOW_SYSTEM)
+		static_branch_inc(&numab_cgroup_mode_set);
+	else if (old != NUMAB_FOLLOW_SYSTEM && mode == NUMAB_FOLLOW_SYSTEM)
+		static_branch_dec(&numab_cgroup_mode_set);
+	WRITE_ONCE(memcg->numab_mode, (int)mode);
+	mutex_unlock(&numab_mode_mutex);
+
+	mem_cgroup_put(memcg);
+	cgroup_put(cgrp);
+	return 0;
+}
+
+/**
+ * bpf_numab_get_mode() - Read the NUMA balancing mode that applies to a cgroup.
+ * @cgid: kernfs id of the cgroup
+ *
+ * The combined task-side request of the cgroup's effective memcg and of
+ * every ancestor: an opt-out wins, otherwise the requested bits OR
+ * together, and the kernel reads them independently, as
+ * kernel.numa_balancing does, so a combined
+ * NUMAB_NORMAL|NUMAB_TIERING engages both modes. NUMAB_FOLLOW_SYSTEM
+ * when nobody makes a request. If the cgroup
+ * has no memcg, the nearest ancestor memcg is used. The folio-side view
+ * stays internal to the kernel.
+ *
+ * Return: the combined mode, NUMAB_FOLLOW_SYSTEM (-1) included, or
+ *         %-ENOENT for an id that resolves to no cgroup.
+ */
+__bpf_kfunc s64 bpf_numab_get_mode(u64 cgid)
+{
+	struct mem_cgroup *memcg;
+	struct cgroup *cgrp;
+	s64 mode;
+
+	cgrp = __cgroup_get_from_id(cgid);
+	if (IS_ERR(cgrp))
+		return PTR_ERR(cgrp);
+
+	if (mem_cgroup_disabled()) {
+		cgroup_put(cgrp);
+		return NUMAB_FOLLOW_SYSTEM;
+	}
+
+	rcu_read_lock();
+	memcg = mem_cgroup_from_css(cgroup_e_css(cgrp, &memory_cgrp_subsys));
+	mode = memcg ? numab_memcg_mode(memcg, false) : NUMAB_FOLLOW_SYSTEM;
+	rcu_read_unlock();
+
+	cgroup_put(cgrp);
+	return mode;
+}
+
+__bpf_kfunc_end_defs();
+
+BTF_KFUNCS_START(numab_kfunc_ids)
+BTF_ID_FLAGS(func, bpf_numab_set_mode, KF_SLEEPABLE)
+BTF_ID_FLAGS(func, bpf_numab_get_mode)
+BTF_KFUNCS_END(numab_kfunc_ids)
+
+static const struct btf_kfunc_id_set numab_kfunc_set = {
+	.owner = THIS_MODULE,
+	.set   = &numab_kfunc_ids,
+};
+
+static int __init numab_kfunc_init(void)
+{
+	int ret;
+
+	ret = register_btf_kfunc_id_set(BPF_PROG_TYPE_SYSCALL, &numab_kfunc_set);
+	if (ret)
+		pr_warn("numab: failed to register kfuncs: %d\n", ret);
+	return ret;
+}
+late_initcall(numab_kfunc_init);
diff --git a/kernel/sched/build_policy.c b/kernel/sched/build_policy.c
index 2a828725a7f965..3746c6675ff325 100644
--- a/kernel/sched/build_policy.c
+++ b/kernel/sched/build_policy.c
@@ -75,4 +75,8 @@
 # include "ext/sub.c"
 #endif
 
+#ifdef CONFIG_BPF_NUMAB
+#include "bpf_numab.c"
+#endif
+
 #include "syscalls.c"
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index cfc982205b98c6..6c2a7550eef522 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -39,6 +39,7 @@
 #include <linux/sched/cputime.h>
 #include <linux/sched/isolation.h>
 #include <linux/sched/nohz.h>
+#include <linux/sched/numa_balancing.h>
 #include <linux/sched/prio.h>
 #include <linux/static_call.h>
 
@@ -1421,7 +1422,8 @@ static inline int get_sched_cache_scale(int mul)
 	return (1 + (tol - 1) * mul);
 }
 
-static bool exceed_llc_capacity(struct sched_cache_group *grp, int cpu)
+static bool exceed_llc_capacity(struct sched_cache_group *grp, int cpu,
+				bool numab_enabled)
 {
 #ifdef CONFIG_NUMA_BALANCING
 	unsigned long llc, footprint;
@@ -1434,7 +1436,7 @@ static bool exceed_llc_capacity(struct sched_cache_group *grp, int cpu)
 	if (!sd)
 		return true;
 
-	if (static_branch_likely(&sched_numa_balancing)) {
+	if (numab_enabled) {
 		/*
 		 * TBD: RDT exclusive LLC ways reserved should be
 		 * excluded.
@@ -1800,7 +1802,8 @@ static unsigned long fraction_mm_sched(struct rq *rq,
 	return div64_u64(NICE_0_LOAD * pcpu_sched->runtime, rq->cpu_runtime + 1);
 }
 
-static int get_pref_llc(struct task_struct *p, struct sched_cache_group *grp)
+static int get_pref_llc(struct task_struct *p, struct sched_cache_group *grp,
+			bool numab_enabled)
 {
 	int mm_sched_llc = -1, mm_sched_cpu;
 
@@ -1822,7 +1825,7 @@ static int get_pref_llc(struct task_struct *p, struct sched_cache_group *grp)
 		 * than sched_setnuma() at least -- and thus the
 		 * conflict only exists for a short period of time.
 		 */
-		if (static_branch_likely(&sched_numa_balancing) &&
+		if (numab_enabled &&
 		    p->numa_preferred_nid >= 0 &&
 		    cpu_to_node(mm_sched_cpu) != p->numa_preferred_nid)
 			mm_sched_llc = -1;
@@ -1841,6 +1844,7 @@ void account_mm_sched(struct rq *rq, struct task_struct *p, s64 delta_exec)
 	struct sched_cache_time *pcpu_sched;
 	int mm_sched_llc = -1;
 	unsigned long epoch;
+	bool numab_enabled;
 
 	if (!sched_cache_enabled())
 		return;
@@ -1874,14 +1878,19 @@ void account_mm_sched(struct rq *rq, struct task_struct *p, s64 delta_exec)
 	 * its preferred state.
 	 */
 	if ((long)(epoch - READ_ONCE(grp->epoch)) > llc_epoch_affinity_timeout ||
-	    invalid_llc_nr(grp, p, cpu_of(rq)) ||
-	    exceed_llc_capacity(grp, cpu_of(rq))) {
+	    invalid_llc_nr(grp, p, cpu_of(rq))) {
 		if (READ_ONCE(grp->cpu) != -1)
 			WRITE_ONCE(grp->cpu, -1);
+	} else {
+		numab_enabled = task_numab_enabled(p);
+		if (exceed_llc_capacity(grp, cpu_of(rq), numab_enabled)) {
+			if (READ_ONCE(grp->cpu) != -1)
+				WRITE_ONCE(grp->cpu, -1);
+		} else {
+			mm_sched_llc = get_pref_llc(p, grp, numab_enabled);
+		}
 	}
 
-	mm_sched_llc = get_pref_llc(p, grp);
-
 	/* task not on rq accounted later in account_entity_enqueue() */
 	if (task_running_on_cpu(rq->cpu, p) &&
 	    READ_ONCE(p->preferred_llc) != mm_sched_llc) {
@@ -1918,12 +1927,12 @@ static void task_tick_cache(struct rq *rq, struct task_struct *p)
 }
 
 static void get_scan_cpumasks(cpumask_var_t cpus, struct task_struct *p,
-			      struct sched_cache_group *grp)
+			      struct sched_cache_group *grp, bool numab_enabled)
 {
 #ifdef CONFIG_NUMA_BALANCING
 	int cpu, curr_cpu, nid, pref_nid;
 
-	if (!static_branch_likely(&sched_numa_balancing))
+	if (!numab_enabled)
 		goto out;
 
 	cpu = READ_ONCE(grp->cpu);
@@ -1990,6 +1999,7 @@ static void task_cache_work(struct callback_head *work)
 	struct task_struct *p = current, *cur;
 	unsigned long curr_m_a_occ = 0;
 	unsigned long m_a_occ = 0;
+	bool numab_enabled;
 
 	WARN_ON_ONCE(work != &p->cache_work);
 
@@ -2018,11 +2028,16 @@ static void task_cache_work(struct callback_head *work)
 		return;
 
 	curr_cpu = task_cpu(p);
-	if (invalid_llc_nr(grp, p, curr_cpu) ||
-	    exceed_llc_capacity(grp, curr_cpu)) {
+	if (invalid_llc_nr(grp, p, curr_cpu)) {
 		if (READ_ONCE(grp->cpu) != -1)
 			WRITE_ONCE(grp->cpu, -1);
+		return;
+	}
 
+	numab_enabled = task_numab_enabled(p);
+	if (exceed_llc_capacity(grp, curr_cpu, numab_enabled)) {
+		if (READ_ONCE(grp->cpu) != -1)
+			WRITE_ONCE(grp->cpu, -1);
 		return;
 	}
 
@@ -2032,7 +2047,7 @@ static void task_cache_work(struct callback_head *work)
 	scoped_guard (cpus_read_lock) {
 		guard(rcu)();
 
-		get_scan_cpumasks(cpus, p, grp);
+		get_scan_cpumasks(cpus, p, grp, numab_enabled);
 
 		for_each_cpu(cpu, cpus) {
 			/* XXX sched_cluster_active */
@@ -2137,7 +2152,8 @@ void init_sched_mm(struct task_struct *p) { }
 static void task_tick_cache(struct rq *rq, struct task_struct *p) { }
 
 static inline int get_pref_llc(struct task_struct *p,
-			       struct sched_cache_group *grp)
+			       struct sched_cache_group *grp,
+			       bool numab_enabled)
 {
 	return -1;
 }
@@ -2866,6 +2882,9 @@ bool should_numa_migrate_memory(struct task_struct *p, struct folio *folio,
 	struct numa_group *ng = deref_curr_numa_group(p);
 	int dst_nid = cpu_to_node(dst_cpu);
 	int last_cpupid, this_cpupid;
+	bool tiering;
+
+	tiering = folio_numab_in_tiering_mode(folio);
 
 	/*
 	 * Cannot migrate to memoryless nodes.
@@ -2877,7 +2896,7 @@ bool should_numa_migrate_memory(struct task_struct *p, struct folio *folio,
 	 * The pages in slow memory node should be migrated according
 	 * to hot/cold instead of private/shared.
 	 */
-	if (folio_use_access_time(folio)) {
+	if (tiering && !node_is_toptier(folio_nid(folio))) {
 		struct pglist_data *pgdat;
 		unsigned long rate_limit;
 		unsigned int latency, th, def_th;
@@ -2906,8 +2925,8 @@ bool should_numa_migrate_memory(struct task_struct *p, struct folio *folio,
 	this_cpupid = cpu_pid_to_cpupid(dst_cpu, current->pid);
 	last_cpupid = folio_xchg_last_cpupid(folio, this_cpupid);
 
-	if (!(sysctl_numa_balancing_mode & NUMA_BALANCING_MEMORY_TIERING) &&
-	    !node_is_toptier(src_nid) && !cpupid_valid(last_cpupid))
+	if (!tiering && !node_is_toptier(src_nid) &&
+	    !cpupid_valid(last_cpupid))
 		return false;
 
 	/*
@@ -4135,12 +4154,14 @@ void task_numa_fault(int last_cpupid, int mem_node, int pages, int flags)
 {
 	struct task_struct *p = current;
 	bool migrated = flags & TNF_MIGRATED;
+	bool numab_enabled, numab_tiering;
 	int cpu_node = task_node(current);
 	int local = !!(flags & TNF_FAULT_LOCAL);
 	struct numa_group *ng;
 	int priv;
 
-	if (!static_branch_likely(&sched_numa_balancing))
+	task_numab_get_modes(p, &numab_enabled, &numab_tiering);
+	if (!numab_enabled)
 		return;
 
 	/* for example, ksmd faulting in a user's mm */
@@ -4152,8 +4173,7 @@ void task_numa_fault(int last_cpupid, int mem_node, int pages, int flags)
 	 * node for memory tiering mode.
 	 */
 	if (!node_is_toptier(mem_node) &&
-	    (sysctl_numa_balancing_mode & NUMA_BALANCING_MEMORY_TIERING ||
-	     !cpupid_valid(last_cpupid)))
+	    (numab_tiering || !cpupid_valid(last_cpupid)))
 		return;
 
 	/* Allocate buffer to track faults on a per-node basis */
@@ -4297,6 +4317,9 @@ static void task_numa_work(struct callback_head *work)
 	if (p->flags & PF_EXITING)
 		return;
 
+	if (!task_numab_enabled(p))
+		return;
+
 	/*
 	 * Memory is pinned to only one NUMA node via cpuset.mems, naturally
 	 * no page can be migrated.
@@ -4601,6 +4624,11 @@ static void task_tick_numa(struct rq *rq, struct task_struct *curr)
 			curr->numa_scan_period = task_scan_start(curr);
 		curr->node_stamp += period;
 
+		if (!task_numab_enabled(curr)) {
+			curr->node_stamp = now;
+			return;
+		}
+
 		if (!time_before(jiffies, curr->mm->numa_next_scan))
 			task_work_add(curr, work, TWA_RESUME);
 	}
@@ -4611,7 +4639,7 @@ static void update_scan_period(struct task_struct *p, int new_cpu)
 	int src_nid = cpu_to_node(task_cpu(p));
 	int dst_nid = cpu_to_node(new_cpu);
 
-	if (!static_branch_likely(&sched_numa_balancing))
+	if (!task_numab_enabled(p))
 		return;
 
 	if (!p->mm || !p->numa_faults || (p->flags & PF_EXITING))
@@ -10696,13 +10724,14 @@ static int task_hot(struct task_struct *p, struct lb_env *env)
  * Returns 0, if task migration is not affected by locality.
  * Returns a negative value, if task migration improves locality i.e migration preferred.
  */
-static long migrate_degrades_locality(struct task_struct *p, struct lb_env *env)
+static long migrate_degrades_locality(struct task_struct *p, struct lb_env *env,
+				      bool numab_enabled)
 {
 	struct numa_group *numa_group = rcu_dereference_all(p->numa_group);
 	unsigned long src_weight, dst_weight;
 	int src_nid, dst_nid, dist;
 
-	if (!static_branch_likely(&sched_numa_balancing))
+	if (!numab_enabled)
 		return 0;
 
 	if (!p->numa_faults || !(env->sd->flags & SD_NUMA))
@@ -10744,7 +10773,8 @@ static long migrate_degrades_locality(struct task_struct *p, struct lb_env *env)
 
 #else /* !CONFIG_NUMA_BALANCING: */
 static inline long migrate_degrades_locality(struct task_struct *p,
-					     struct lb_env *env)
+					     struct lb_env *env,
+					     bool numab_enabled)
 {
 	return 0;
 }
@@ -10946,7 +10976,8 @@ static inline bool sched_asym(struct sched_domain *sd, int dst_cpu, int src_cpu)
  * destination LLC in terms of cache aware load balance.
  */
 static enum llc_mig can_migrate_llc_task(struct lb_env *env,
-					 struct task_struct *p)
+					 struct task_struct *p,
+					 bool numab_enabled)
 {
 	struct sched_cache_group *grp;
 	bool to_pref;
@@ -10971,7 +11002,7 @@ static enum llc_mig can_migrate_llc_task(struct lb_env *env,
 
 	/* skip cache aware load balance for too many threads */
 	if (invalid_llc_nr(grp, p, dst_cpu) ||
-	    exceed_llc_capacity(grp, dst_cpu)) {
+	    exceed_llc_capacity(grp, dst_cpu, numab_enabled)) {
 		if (READ_ONCE(grp->cpu) != -1)
 			WRITE_ONCE(grp->cpu, -1);
 		return mig_unrestricted;
@@ -11060,7 +11091,8 @@ migrate_llc_task_wrong_dst(struct task_struct *p, struct lb_env *env)
  * Check if migrating task p from env->src_cpu to
  * env->dst_cpu breaks LLC localiy.
  */
-static bool migrate_degrades_llc(struct task_struct *p, struct lb_env *env)
+static bool migrate_degrades_llc(struct task_struct *p, struct lb_env *env,
+				 bool numab_enabled)
 {
 	if (!sched_cache_enabled())
 		return false;
@@ -11087,7 +11119,7 @@ static bool migrate_degrades_llc(struct task_struct *p, struct lb_env *env)
 	if (migrate_llc_task_wrong_dst(p, env))
 		return true;
 
-	if (can_migrate_llc_task(env, p) != mig_forbid)
+	if (can_migrate_llc_task(env, p, numab_enabled) != mig_forbid)
 		return false;
 
 	return true;
@@ -11113,7 +11145,8 @@ migrate_llc_task_wrong_dst(struct task_struct *p, struct lb_env *env)
 }
 
 static inline bool
-migrate_degrades_llc(struct task_struct *p, struct lb_env *env)
+migrate_degrades_llc(struct task_struct *p, struct lb_env *env,
+		     bool numab_enabled)
 {
 	return false;
 }
@@ -11125,6 +11158,7 @@ static
 int can_migrate_task(struct task_struct *p, struct lb_env *env)
 {
 	long degrades, hot;
+	bool numab_enabled;
 
 	lockdep_assert_rq_held(env->src_rq);
 	if (p->sched_task_hot)
@@ -11213,14 +11247,15 @@ int can_migrate_task(struct task_struct *p, struct lb_env *env)
 	if (env->flags & LBF_ACTIVE_LB)
 		return !migrate_llc_task_wrong_dst(p, env);
 
-	degrades = migrate_degrades_locality(p, env);
+	numab_enabled = task_numab_enabled(p);
+	degrades = migrate_degrades_locality(p, env, numab_enabled);
 	if (!degrades) {
 		/*
 		 * If the NUMA locality is not broken,
 		 * further check if migration would hurt
 		 * LLC locality.
 		 */
-		if (migrate_degrades_llc(p, env)) {
+		if (migrate_degrades_llc(p, env, numab_enabled)) {
 			/*
 			 * If regular load balancing fails to pull a task
 			 * due to LLC locality, this is expected behavior
@@ -15362,7 +15397,7 @@ static void task_tick_fair(struct rq *rq, struct task_struct *curr, int queued)
 	if (queued)
 		return;
 
-	if (static_branch_unlikely(&sched_numa_balancing))
+	if (task_numab_tick_possible())
 		task_tick_numa(rq, curr);
 
 	task_tick_cache(rq, curr);
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index 6c7c5633524a3b..9b616abf5c9c31 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -2496,7 +2496,6 @@ extern union sched_feat_key sched_feat_keys[__SCHED_FEAT_NR];
 
 #endif /* !CONFIG_JUMP_LABEL */
 
-extern struct static_key_false sched_numa_balancing;
 extern struct static_key_false sched_schedstats;
 
 static inline u64 global_rt_period(void)
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index a05d9a8baa1b6b..3971b5b3360bac 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -31,6 +31,7 @@
 #include <linux/cgroup.h>
 #include <linux/cpuset.h>
 #include <linux/sched/mm.h>
+#include <linux/sched/numa_balancing.h>
 #include <linux/shmem_fs.h>
 #include <linux/hugetlb.h>
 #include <linux/pagemap.h>
@@ -4266,6 +4267,9 @@ static struct mem_cgroup *mem_cgroup_alloc(struct mem_cgroup *parent)
 	if (!memcg)
 		return ERR_PTR(-ENOMEM);
 
+#ifdef CONFIG_BPF_NUMAB
+	memcg->numab_mode = NUMAB_FOLLOW_SYSTEM;
+#endif
 	error = xa_alloc(&mem_cgroup_private_ids, &memcg->private_id, NULL,
 			 XA_LIMIT(1, MEM_CGROUP_ID_MAX), GFP_KERNEL);
 	if (error)
@@ -4459,6 +4463,9 @@ static void mem_cgroup_css_offline(struct cgroup_subsys_state *css)
 {
 	struct mem_cgroup *memcg = mem_cgroup_from_css(css);
 
+#ifdef CONFIG_BPF_NUMAB
+	numab_memcg_reset(memcg);
+#endif
 	memcg1_css_offline(memcg);
 
 	page_counter_set_min(&memcg->memory, 0);
@@ -4532,6 +4539,9 @@ static void mem_cgroup_css_reset(struct cgroup_subsys_state *css)
 {
 	struct mem_cgroup *memcg = mem_cgroup_from_css(css);
 
+#ifdef CONFIG_BPF_NUMAB
+	numab_memcg_reset(memcg);
+#endif
 	page_counter_set_max(&memcg->memory, PAGE_COUNTER_MAX);
 	page_counter_set_max(&memcg->swap, PAGE_COUNTER_MAX);
 	WRITE_ONCE(memcg->oom_group, false);
@@ -5917,6 +5927,10 @@ static void __init memcg_struct_check(void)
 				      kmemcg_id);
 	CACHELINE_ASSERT_GROUP_MEMBER(struct mem_cgroup, memcg_read_mostly,
 				      oom_group);
+#ifdef CONFIG_BPF_NUMAB
+	CACHELINE_ASSERT_GROUP_MEMBER(struct mem_cgroup, memcg_read_mostly,
+				      numab_mode);
+#endif
 
 	CACHELINE_ASSERT_GROUP_MEMBER(struct mem_cgroup_per_node,
 				      memcg_pn_read_mostly, memcg);
diff --git a/mm/memory-tiers.c b/mm/memory-tiers.c
index 25e121851b5862..7bfb92657e24ca 100644
--- a/mm/memory-tiers.c
+++ b/mm/memory-tiers.c
@@ -6,6 +6,7 @@
 #include <linux/memory.h>
 #include <linux/memory-tiers.h>
 #include <linux/notifier.h>
+#include <linux/sched/numa_balancing.h>
 #include <linux/sched/sysctl.h>
 
 #include "internal.h"
@@ -56,15 +57,15 @@ static const struct bus_type memory_tier_subsys = {
  * folio_use_access_time - check if a folio reuses cpupid for page access time
  * @folio: folio to check
  *
- * folio's _last_cpupid field is repurposed by memory tiering. In memory
- * tiering mode, cpupid of slow memory folio (not toptier memory) is used to
- * record page access time.
+ * folio's _last_cpupid field is repurposed by memory tiering. When the
+ * owner of @folio participates in tiering, cpupid of slow memory folio
+ * (not toptier memory) is used to record page access time.
  *
  * Return: the folio _last_cpupid is used to record page access time
  */
 bool folio_use_access_time(struct folio *folio)
 {
-	return (sysctl_numa_balancing_mode & NUMA_BALANCING_MEMORY_TIERING) &&
+	return folio_numab_in_tiering_mode(folio) &&
 	       !node_is_toptier(folio_nid(folio));
 }
 #endif
diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index 0884c629670dd6..3534dc63b5a9c3 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -854,7 +854,7 @@ static int queue_folios_hugetlb(pte_t *pte, unsigned long hmask,
 bool folio_can_map_prot_numa(struct folio *folio, struct vm_area_struct *vma,
 		bool is_private_single_threaded)
 {
-	int nid;
+	int nid, mode;
 
 	if (!folio || folio_is_zone_device(folio) || folio_test_ksm(folio))
 		return false;
@@ -883,15 +883,16 @@ bool folio_can_map_prot_numa(struct folio *folio, struct vm_area_struct *vma,
 	if (is_private_single_threaded && (nid == numa_node_id()))
 		return false;
 
+	mode = folio_numab_effective_mode(folio);
+
 	/*
 	 * Skip scanning top tier node if normal numa
 	 * balancing is disabled
 	 */
-	if (!(sysctl_numa_balancing_mode & NUMA_BALANCING_NORMAL) &&
-	    node_is_toptier(nid))
+	if (!(mode & NUMAB_NORMAL) && node_is_toptier(nid))
 		return false;
 
-	if (folio_use_access_time(folio))
+	if ((mode & NUMAB_TIERING) && !node_is_toptier(nid))
 		folio_xchg_access_time(folio, jiffies_to_msecs(jiffies));
 
 	return true;
diff --git a/mm/migrate.c b/mm/migrate.c
index 7bdcdb57652f8f..f3a84a5903aa0c 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -41,6 +41,7 @@
 #include <linux/ptrace.h>
 #include <linux/memory.h>
 #include <linux/sched/sysctl.h>
+#include <linux/sched/numa_balancing.h>
 #include <linux/memory-tiers.h>
 #include <linux/pagewalk.h>
 
@@ -818,7 +819,7 @@ void folio_migrate_flags(struct folio *newfolio, struct folio *folio)
 	 * memory node, reset cpupid, because that is used to record
 	 * page access time in slow memory node.
 	 */
-	if (sysctl_numa_balancing_mode & NUMA_BALANCING_MEMORY_TIERING) {
+	if (folio_numab_in_tiering_mode(folio)) {
 		bool f_toptier = node_is_toptier(folio_nid(folio));
 		bool t_toptier = node_is_toptier(folio_nid(newfolio));
 
@@ -2717,7 +2718,7 @@ int migrate_misplaced_folio_prepare(struct folio *folio,
 	if (!migrate_balanced_pgdat(pgdat, nr_pages)) {
 		int z;
 
-		if (!(sysctl_numa_balancing_mode & NUMA_BALANCING_MEMORY_TIERING))
+		if (!folio_numab_in_tiering_mode(folio))
 			return -EAGAIN;
 		for (z = pgdat->nr_zones - 1; z >= 0; z--) {
 			if (managed_zone(pgdat->node_zones + z))
@@ -2759,6 +2760,7 @@ int migrate_misplaced_folio(struct folio *folio, int node)
 	LIST_HEAD(migratepages);
 	struct mem_cgroup *memcg = get_mem_cgroup_from_folio(folio);
 	struct lruvec *lruvec = mem_cgroup_lruvec(memcg, pgdat);
+	bool folio_tiering = folio_numab_in_tiering_mode(folio);
 
 	list_add(&folio->lru, &migratepages);
 	nr_remaining = migrate_pages(&migratepages, alloc_misplaced_dst_folio,
@@ -2769,8 +2771,7 @@ int migrate_misplaced_folio(struct folio *folio, int node)
 	if (nr_succeeded) {
 		count_vm_numa_events(NUMA_PAGE_MIGRATE, nr_succeeded);
 		count_memcg_events(memcg, NUMA_PAGE_MIGRATE, nr_succeeded);
-		if ((sysctl_numa_balancing_mode & NUMA_BALANCING_MEMORY_TIERING)
-		    && !node_is_toptier(folio_nid(folio))
+		if (folio_tiering && !node_is_toptier(folio_nid(folio))
 		    && node_is_toptier(node))
 			mod_lruvec_state(lruvec, PGPROMOTE_SUCCESS, nr_succeeded);
 	}
diff --git a/mm/vmscan.c b/mm/vmscan.c
index 9959ca158ce835..7ef4205b6a4e77 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -65,6 +65,7 @@
 
 #include <linux/swapops.h>
 #include <linux/sched/sysctl.h>
+#include <linux/sched/numa_balancing.h>
 
 #include "internal.h"
 #include "page_alloc.h"
@@ -5224,8 +5225,7 @@ static bool should_abort_scan(struct lruvec *lruvec, struct scan_control *sc)
 	if (!current_is_kswapd() || sc->order)
 		return false;
 
-	mark = sysctl_numa_balancing_mode & NUMA_BALANCING_MEMORY_TIERING ?
-	       WMARK_PROMO : WMARK_HIGH;
+	mark = numab_in_tiering_mode() ? WMARK_PROMO : WMARK_HIGH;
 
 	for (i = 0; i <= sc->reclaim_idx; i++) {
 		struct zone *zone = lruvec_pgdat(lruvec)->node_zones + i;
@@ -7131,7 +7131,7 @@ static bool pgdat_balanced(pg_data_t *pgdat, int order, int highest_zoneidx)
 		enum zone_stat_item item;
 		unsigned long free_pages;
 
-		if (sysctl_numa_balancing_mode & NUMA_BALANCING_MEMORY_TIERING)
+		if (numab_in_tiering_mode())
 			mark = promo_wmark_pages(zone);
 		else
 			mark = high_wmark_pages(zone);
diff --git a/tools/testing/selftests/bpf/config b/tools/testing/selftests/bpf/config
index 49dfe939467cc8..e56c8872e51a04 100644
--- a/tools/testing/selftests/bpf/config
+++ b/tools/testing/selftests/bpf/config
@@ -7,6 +7,7 @@ CONFIG_BPF_JIT=y
 CONFIG_BPF_KPROBE_OVERRIDE=y
 CONFIG_BPF_LIRC_MODE2=y
 CONFIG_BPF_LSM=y
+CONFIG_BPF_NUMAB=y
 CONFIG_BPF_STREAM_PARSER=y
 CONFIG_BPF_SYSCALL=y
 # CONFIG_BPF_UNPRIV_DEFAULT_OFF is not set
@@ -78,6 +79,7 @@ CONFIG_NET_CLS_FLOWER=y
 CONFIG_NET_CLS_MATCHALL=y
 CONFIG_NET_FOU=y
 CONFIG_NET_FOU_IP_TUNNELS=y
+CONFIG_NUMA_BALANCING=y
 CONFIG_NET_IPGRE=y
 CONFIG_NET_IPGRE_DEMUX=y
 CONFIG_NET_IPIP=y
diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_numab.c b/tools/testing/selftests/bpf/prog_tests/bpf_numab.c
new file mode 100644
index 00000000000000..6fb6a4d9f29194
--- /dev/null
+++ b/tools/testing/selftests/bpf/prog_tests/bpf_numab.c
@@ -0,0 +1,273 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <test_progs.h>
+#include "cgroup_helpers.h"
+#include "bpf_numab.skel.h"
+
+#define CGROUP_PATH	"/bpf_numab"
+#define CHILD_PATH	CGROUP_PATH "/child"
+#define HIER_PATH	"/bpf_numab_hier"
+#define HIER_CHILD_PATH	HIER_PATH "/child"
+#define NOMEM_PATH	"/bpf_numab_nomem"
+#define NOMEM_CHILD_PATH NOMEM_PATH "/child"
+
+/* The per-cgroup request domain, mirroring the kernel constants. */
+#define NUMAB_FOLLOW_SYSTEM	(-1)
+#define NUMAB_DISABLED		0
+#define NUMAB_NORMAL		1
+#define NUMAB_TIERING		2
+#define NUMAB_NORMAL_TIERING	3
+
+static int numab_set(struct bpf_numab *skel, u64 cgid,
+		     long mode)
+{
+	LIBBPF_OPTS(bpf_test_run_opts, opts);
+	int ret;
+
+	skel->bss->set_cgid = cgid;
+	skel->bss->set_mode = mode;
+	ret = bpf_prog_test_run_opts(bpf_program__fd(skel->progs.numab_set),
+				     &opts);
+	if (!ASSERT_OK(ret, "set run"))
+		return -1;
+	return skel->bss->set_ret;
+}
+
+static long numab_get(struct bpf_numab *skel, u64 cgid)
+{
+	LIBBPF_OPTS(bpf_test_run_opts, opts);
+	int ret;
+
+	skel->bss->get_cgid = cgid;
+	ret = bpf_prog_test_run_opts(bpf_program__fd(skel->progs.numab_get),
+				     &opts);
+	if (!ASSERT_OK(ret, "get run"))
+		return -EIO;
+	return skel->bss->get_mode;
+}
+
+static void test_set_get(void)
+{
+	struct bpf_numab *skel;
+	int cgroup_fd;
+	u64 cgid;
+
+	cgroup_fd = test__join_cgroup(CGROUP_PATH);
+	if (!ASSERT_GE(cgroup_fd, 0, "join_cgroup"))
+		return;
+
+	skel = bpf_numab__open_and_load();
+	if (!ASSERT_OK_PTR(skel, "open_and_load"))
+		goto cleanup;
+
+	cgid = get_cgroup_id(CGROUP_PATH);
+	if (!ASSERT_GT(cgid, 0, "get_cgroup_id"))
+		goto cleanup;
+
+	ASSERT_EQ(numab_set(skel, cgid, NUMAB_NORMAL), 0, "set normal");
+	ASSERT_EQ(numab_get(skel, cgid), NUMAB_NORMAL, "get normal");
+
+	ASSERT_EQ(numab_set(skel, cgid, NUMAB_TIERING), 0, "set tiering");
+	ASSERT_EQ(numab_get(skel, cgid), NUMAB_TIERING, "get tiering");
+
+	ASSERT_EQ(numab_set(skel, cgid, NUMAB_NORMAL_TIERING), 0, "set both");
+	ASSERT_EQ(numab_get(skel, cgid), NUMAB_NORMAL_TIERING, "get both");
+
+	ASSERT_EQ(numab_set(skel, cgid, NUMAB_DISABLED), 0, "set disabled");
+	ASSERT_EQ(numab_get(skel, cgid), NUMAB_DISABLED, "get disabled");
+
+	/* Back to the system setting. */
+	ASSERT_EQ(numab_set(skel, cgid, NUMAB_FOLLOW_SYSTEM), 0, "unset");
+	ASSERT_EQ(numab_get(skel, cgid), NUMAB_FOLLOW_SYSTEM, "get unset");
+
+cleanup:
+	bpf_numab__destroy(skel);
+	close(cgroup_fd);
+}
+
+static void test_invalid_mode(void)
+{
+	struct bpf_numab *skel;
+	int cgroup_fd;
+	u64 cgid;
+
+	cgroup_fd = test__join_cgroup(CGROUP_PATH);
+	if (!ASSERT_GE(cgroup_fd, 0, "join_cgroup"))
+		return;
+
+	skel = bpf_numab__open_and_load();
+	if (!ASSERT_OK_PTR(skel, "open_and_load"))
+		goto cleanup;
+
+	cgid = get_cgroup_id(CGROUP_PATH);
+	if (!ASSERT_GT(cgid, 0, "get_cgroup_id"))
+		goto cleanup;
+
+	ASSERT_EQ(numab_set(skel, cgid, -2), -EINVAL, "set below domain");
+	ASSERT_EQ(numab_set(skel, cgid, 4), -EINVAL, "set above domain");
+	ASSERT_EQ(numab_set(skel, cgid, 0x1000), -EINVAL, "set far above");
+
+	/* The rejected requests must not have stuck. */
+	ASSERT_EQ(numab_get(skel, cgid), NUMAB_FOLLOW_SYSTEM, "get unchanged");
+
+cleanup:
+	bpf_numab__destroy(skel);
+	close(cgroup_fd);
+}
+
+static void test_bad_cgid(void)
+{
+	struct bpf_numab *skel;
+
+	skel = bpf_numab__open_and_load();
+	if (!ASSERT_OK_PTR(skel, "open_and_load"))
+		return;
+
+	ASSERT_EQ(numab_set(skel, 0, NUMAB_NORMAL), -ENOENT, "set cgid 0");
+	ASSERT_EQ(numab_get(skel, 0), -ENOENT, "get cgid 0");
+	ASSERT_EQ(numab_set(skel, 0xdeadbeef, NUMAB_NORMAL), -ENOENT,
+		  "set bad cgid");
+	ASSERT_EQ(numab_get(skel, 0xdeadbeef), -ENOENT, "get bad cgid");
+
+	bpf_numab__destroy(skel);
+}
+
+static void test_hierarchy(void)
+{
+	u64 parent_cgid, child_cgid;
+	int runner_fd, parent_fd, child_fd;
+	struct bpf_numab *skel;
+
+	runner_fd = test__join_cgroup("/bpf_numab_runner");
+	if (!ASSERT_GE(runner_fd, 0, "join_runner_cgroup"))
+		return;
+
+	parent_fd = create_and_get_cgroup(HIER_PATH);
+	if (!ASSERT_GE(parent_fd, 0, "create_parent_cgroup"))
+		goto cleanup_runner;
+
+	if (!ASSERT_OK(enable_controllers(HIER_PATH, "memory"),
+		       "enable_memory_controller"))
+		goto cleanup_parent;
+
+	child_fd = create_and_get_cgroup(HIER_CHILD_PATH);
+	if (!ASSERT_GE(child_fd, 0, "create_child_cgroup"))
+		goto cleanup_parent;
+
+	skel = bpf_numab__open_and_load();
+	if (!ASSERT_OK_PTR(skel, "open_and_load"))
+		goto cleanup;
+
+	parent_cgid = get_cgroup_id(HIER_PATH);
+	child_cgid = get_cgroup_id(HIER_CHILD_PATH);
+	if (!ASSERT_GT(parent_cgid, 0, "get_parent_cgid") ||
+	    !ASSERT_GT(child_cgid, 0, "get_child_cgid"))
+		goto cleanup;
+
+	/* The child inherits an ancestor's request untouched. */
+	ASSERT_EQ(numab_set(skel, parent_cgid, NUMAB_TIERING), 0,
+		  "set parent tiering");
+	ASSERT_EQ(numab_get(skel, child_cgid), NUMAB_TIERING,
+		  "child inherits");
+
+	/* A request ORs with the ancestor's; NORMAL does not undo TIERING. */
+	ASSERT_EQ(numab_set(skel, child_cgid, NUMAB_NORMAL), 0,
+		  "set child normal");
+	ASSERT_EQ(numab_get(skel, child_cgid), NUMAB_NORMAL_TIERING,
+		  "or both");
+
+	/* The child's own opt-out wins. */
+	ASSERT_EQ(numab_set(skel, child_cgid, NUMAB_DISABLED), 0,
+		  "set child disabled");
+	ASSERT_EQ(numab_get(skel, child_cgid), NUMAB_DISABLED,
+		  "own opt-out wins");
+
+	/* So does an ancestor's: a task is never forced into balancing. */
+	ASSERT_EQ(numab_set(skel, child_cgid, NUMAB_TIERING), 0,
+		  "set child tiering");
+	ASSERT_EQ(numab_set(skel, parent_cgid, NUMAB_DISABLED), 0,
+		  "set parent disabled");
+	ASSERT_EQ(numab_get(skel, child_cgid), NUMAB_DISABLED,
+		  "ancestor opt-out wins");
+
+	/* Unsetting the parent re-exposes the child's own request. */
+	ASSERT_EQ(numab_set(skel, parent_cgid, NUMAB_FOLLOW_SYSTEM), 0,
+		  "unset parent");
+	ASSERT_EQ(numab_get(skel, child_cgid), NUMAB_TIERING,
+		  "child request again");
+
+	/* Unsetting the child leaves the chain with no request. */
+	ASSERT_EQ(numab_set(skel, child_cgid, NUMAB_FOLLOW_SYSTEM), 0,
+		  "unset child");
+	ASSERT_EQ(numab_get(skel, child_cgid), NUMAB_FOLLOW_SYSTEM,
+		  "no request");
+
+cleanup:
+	bpf_numab__destroy(skel);
+	close(child_fd);
+	remove_cgroup(HIER_CHILD_PATH);
+cleanup_parent:
+	close(parent_fd);
+	remove_cgroup(HIER_PATH);
+cleanup_runner:
+	close(runner_fd);
+}
+
+static void test_no_memcg(void)
+{
+	struct bpf_numab *skel;
+	int parent_fd, child_fd;
+	u64 parent_cgid, child_cgid;
+
+	parent_fd = test__join_cgroup(NOMEM_PATH);
+	if (!ASSERT_GE(parent_fd, 0, "join_nomem_parent"))
+		return;
+
+	child_fd = create_and_get_cgroup(NOMEM_CHILD_PATH);
+	if (!ASSERT_GE(child_fd, 0, "create_nomem_child"))
+		goto cleanup_parent;
+
+	skel = bpf_numab__open_and_load();
+	if (!ASSERT_OK_PTR(skel, "open_and_load"))
+		goto cleanup;
+
+	parent_cgid = get_cgroup_id(NOMEM_PATH);
+	child_cgid = get_cgroup_id(NOMEM_CHILD_PATH);
+	if (!ASSERT_GT(parent_cgid, 0, "get_nomem_parent_cgid") ||
+	    !ASSERT_GT(child_cgid, 0, "get_nomem_child_cgid"))
+		goto cleanup;
+
+	/*
+	 * The parent has a memcg; the child was created without enabling
+	 * the memory controller in the parent's subtree, so it has none.
+	 */
+	ASSERT_EQ(numab_set(skel, parent_cgid, NUMAB_NORMAL), 0,
+		  "set parent normal");
+	ASSERT_EQ(numab_get(skel, child_cgid), NUMAB_NORMAL,
+		  "child resolves to parent memcg");
+	ASSERT_EQ(numab_set(skel, child_cgid, NUMAB_TIERING), -EOPNOTSUPP,
+		  "child set rejected");
+	ASSERT_EQ(numab_get(skel, child_cgid), NUMAB_NORMAL,
+		  "child get unchanged");
+
+cleanup:
+	bpf_numab__destroy(skel);
+	close(child_fd);
+	remove_cgroup(NOMEM_CHILD_PATH);
+cleanup_parent:
+	close(parent_fd);
+}
+
+void test_bpf_numab(void)
+{
+	if (test__start_subtest("set_get"))
+		test_set_get();
+	if (test__start_subtest("invalid_mode"))
+		test_invalid_mode();
+	if (test__start_subtest("bad_cgid"))
+		test_bad_cgid();
+	if (test__start_subtest("hierarchy"))
+		test_hierarchy();
+	if (test__start_subtest("no_memcg"))
+		test_no_memcg();
+}
diff --git a/tools/testing/selftests/bpf/progs/bpf_numab.c b/tools/testing/selftests/bpf/progs/bpf_numab.c
new file mode 100644
index 00000000000000..25da97bce82ff2
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/bpf_numab.c
@@ -0,0 +1,32 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <vmlinux.h>
+#include <bpf/bpf_helpers.h>
+
+/* Inputs, set from userspace before each run. */
+u64 set_cgid;
+long set_mode;
+u64 get_cgid;
+
+/* Results, read back after each run. */
+long set_ret;
+long get_mode;
+
+extern int bpf_numab_set_mode(u64 cgid, enum numab_mode mode) __ksym;
+extern s64 bpf_numab_get_mode(u64 cgid) __ksym;
+
+SEC("syscall")
+int numab_set(void *ctx)
+{
+	set_ret = bpf_numab_set_mode(set_cgid, (enum numab_mode)set_mode);
+	return 0;
+}
+
+SEC("syscall")
+int numab_get(void *ctx)
+{
+	get_mode = bpf_numab_get_mode(get_cgid);
+	return 0;
+}
+
+char _license[] SEC("license") = "GPL";

37/3 2026/11/13 02:28 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 20045
							output: 40
							thoughts: 809
						

Thoughts:
**Evaluating the KMSAN Fuzzing Justification**

Okay, let's see if this patch series warrants spinning up a dedicated KMSAN fuzzing session. My initial impression is that it's introducing quite a bit of new functionality that could be interesting to explore.

I'm reviewing this patch series – "Per-cgroup NUMA balancing mode selection via BPF kfuncs (`CONFIG_BPF_NUMAB`)". I'll be looking at the potential attack surface.

Here's my breakdown:

*   **Changes to Data Structures:** It looks like it's added `int numab_mode` to `struct mem_cgroup` under `CONFIG_BPF_NUMAB` in `include/linux/memcontrol.h`. That's a new field in a core data structure, that alone could be interesting.
*   **NUMA Balancing Helpers:** There are also new enums and static inlines related to NUMA balancing mode in `include/linux/sched/numa_balancing.h`. These are the sort of things that should be carefully checked, especially in memory management code. There is a `numab_mode` enum, which warrants examination.
*   **Configuration Option:** `config BPF_NUMAB` is added in `init/Kconfig` which is a new config option. Good.
*   **New BPF Implementation:** The introduction of `kernel/sched/bpf_numab.c` with functions like `task_numab_mode`, `folio_numab_mode`, `numab_memcg_reset`, and the BPF kfuncs `bpf_numab_set_mode` and `bpf_numab_get_mode` is definitely a red flag, and is the core of this patch series. KFuncs are definitely something to watch. They provide an API for in-kernel BPF programs to interact with kernel data structures. That's a potential area for fuzzing.
*   **Integration with Existing Code:** It seems to replace existing NUMA balancing mechanisms within `kernel/sched/fair.c` with the new helpers. Now it uses things like `exceed_llc_capacity`, `get_pref_llc`, `task_numab_fault`, `folio_numab_in_tiering_mode` in various scheduler functions like `task_numa_work`, `task_tick_numa` and `update_scan_period`. This could introduce subtle differences and race conditions. I see the use of `numab_enabled` and `numab_tiering` within those functions, so they should be checked.
*   **Memory Control Group Integration:** In `mm/memcontrol.c`, `mem_cgroup_alloc` initializes `memcg->numab_mode`. I need to double-check how memory control groups are allocated. It looks like `kzalloc` or `struct_size` / `kzalloc` is used. This area could have subtle memory corruption vulnerabilities. `numab_memcg_reset` is called within `mem_cgroup_css_offline` and `mem_cgroup_css_reset`. Memory management is definitely the area to look at.
*   **Broader Impact:** The patch touches `mm/memory-tiers.c`, `mm/mempolicy.c`, `mm/migrate.c`, and `mm/vmscan.c`. Functions like `folio_numab_in_tiering_mode` are used, as is `numab_in_tiering_mode()`. That's a wide reach, so the overall effect should be checked.
*   **Selftests:** Includes BPF selftests in `tools/testing/selftests/...`. That’s good, but selftests can be limited.

So, the introduction of a new configuration option, the addition of a BPF-based mode selection mechanism, the changes to memory management code, and the integration across multiple subsystems make me think this is indeed worth a dedicated KMSAN fuzzing campaign. The use of KFuncs and the changes in memory management are particularly interesting. I will now examine `mem_cgroup_alloc` in mm/memcontrol.c to verify how memcg is allocated. I think KMSAN could definitely find bugs here.



38/3 2026/11/13 02:29 tool grepper
0m Args:
{
  "Expression": "static struct mem_cgroup \\*mem_cgroup_alloc",
  "PathPrefixes": [
    "mm/memcontrol.c"
  ]
}

Results:
{
  "Output": "mm/memcontrol.c=4250=static void mem_cgroup_free(struct mem_cgroup *memcg)\n--\nmm/memcontrol.c-4256-\nmm/memcontrol.c:4257:static struct mem_cgroup *mem_cgroup_alloc(struct mem_cgroup *parent)\nmm/memcontrol.c-4258-{\n"
}

39/3 2026/11/13 02:29 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 21916
							output: 35
							thoughts: 31
						

Thoughts:
Okay, let's dive into this. I'm going to focus on `mem_cgroup_alloc`, specifically lines 4256 through 4280 in `mm/memcontrol.c`. I need to get a clear picture of what's happening within that section of the memory cgroup allocation code. I'm expecting this to be a critical point, likely dealing with how memory is actually granted or rejected based on the cgroup's limits. I'll be looking for how it handles different allocation scenarios, potential locking mechanisms involved, any error handling, and, of course, the actual memory reservation or assignment logic. Given the line range, I'm anticipating this section is likely responsible for either allocating and/or rejecting a requested memory allocation based on the cgroup's defined constraints. It could be interacting with the kernel's slab allocators or page frame management. It could also involve accounting updates to track the cgroup's memory usage in real-time. Let's see what the code reveals.



40/3 2026/11/13 02:29 tool read-file
0m Args:
{
  "File": "mm/memcontrol.c",
  "FirstLine": 4256,
  "LineCount": 35
}

Results:
{
  "Contents": "4256:\t\n4257:\tstatic struct mem_cgroup *mem_cgroup_alloc(struct mem_cgroup *parent)\n4258:\t{\n4259:\t\tstruct memcg_vmstats_percpu *statc;\n4260:\t\tstruct memcg_vmstats_percpu __percpu *pstatc_pcpu;\n4261:\t\tstruct mem_cgroup *memcg;\n4262:\t\tint node, cpu;\n4263:\t\tint __maybe_unused i;\n4264:\t\tlong error;\n4265:\t\n4266:\t\tmemcg = kmem_cache_zalloc(memcg_cachep, GFP_KERNEL);\n4267:\t\tif (!memcg)\n4268:\t\t\treturn ERR_PTR(-ENOMEM);\n4269:\t\n4270:\t#ifdef CONFIG_BPF_NUMAB\n4271:\t\tmemcg-\u003enumab_mode = NUMAB_FOLLOW_SYSTEM;\n4272:\t#endif\n4273:\t\terror = xa_alloc(\u0026mem_cgroup_private_ids, \u0026memcg-\u003eprivate_id, NULL,\n4274:\t\t\t\t XA_LIMIT(1, MEM_CGROUP_ID_MAX), GFP_KERNEL);\n4275:\t\tif (error)\n4276:\t\t\tgoto fail;\n4277:\t\terror = -ENOMEM;\n4278:\t\n4279:\t\tmemcg-\u003evmstats = kzalloc_obj(struct memcg_vmstats, GFP_KERNEL_ACCOUNT);\n4280:\t\tif (!memcg-\u003evmstats)\n4281:\t\t\tgoto fail;\n4282:\t\n4283:\t\tmemcg-\u003evmstats_percpu = alloc_percpu_gfp(struct memcg_vmstats_percpu,\n4284:\t\t\t\t\t\t\t GFP_KERNEL_ACCOUNT);\n4285:\t\tif (!memcg-\u003evmstats_percpu)\n4286:\t\t\tgoto fail;\n4287:\t\n4288:\t\tif (!memcg1_alloc_events(memcg))\n4289:\t\t\tgoto fail;\n4290:\t\n"
}

41/3 2026/11/13 02:29 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 22755
							output: 33
							thoughts: 57
						

Thoughts:
Okay, here's my take on those thoughts, framed as an expert's internal monologue:

**Investigating `memcg` Initialization and NUMA Affinity**

Right, so `kmem_cache_zalloc` is being used to allocate the `memcg` structure. And, specifically, it's setting `memcg->numab_mode` to `NUMAB_FOLLOW_SYSTEM`. That's interesting, but expected. The system-wide default is generally the starting point for a reason.

Now, what about the *root* memcg? How is *it* initialized, and does it follow this same pattern? I need to verify whether the root memcg also defaults to `NUMAB_FOLLOW_SYSTEM`. That's the baseline, the foundation. Understanding the root's setup is critical for reasoning about the behaviour of child memcgs. I'll need to check the initialization sequence to confirm. Time to dig in and find out.



42/3 2026/11/13 02:29 tool grepper
0m Args:
{
  "Expression": "root_mem_cgroup",
  "PathPrefixes": [
    "mm/memcontrol.c"
  ]
}

Results:
{
  "Output": "mm/memcontrol.c=84=EXPORT_SYMBOL(memory_cgrp_subsys);\nmm/memcontrol.c-85-\nmm/memcontrol.c:86:struct mem_cgroup *root_mem_cgroup __read_mostly;\nmm/memcontrol.c:87:EXPORT_SYMBOL(root_mem_cgroup);\nmm/memcontrol.c-88-\n--\nmm/memcontrol.c=118=struct vmpressure *memcg_to_vmpressure(struct mem_cgroup *memcg)\n--\nmm/memcontrol.c-120-\tif (!memcg)\nmm/memcontrol.c:121:\t\tmemcg = root_mem_cgroup;\nmm/memcontrol.c-122-\treturn \u0026memcg-\u003evmpressure;\n--\nmm/memcontrol.c=339=EXPORT_SYMBOL(memcg_bpf_enabled_key);\n--\nmm/memcontrol.c-348- *\nmm/memcontrol.c:349: * If memcg is bound to a traditional hierarchy, the css of root_mem_cgroup\nmm/memcontrol.c-350- * is returned.\n--\nmm/memcontrol.c=352=struct cgroup_subsys_state *get_mem_cgroup_css_from_folio(const struct folio *folio)\n--\nmm/memcontrol.c-356-\tif (!cgroup_subsys_on_dfl(memory_cgrp_subsys))\nmm/memcontrol.c:357:\t\treturn \u0026root_mem_cgroup-\u003ecss;\nmm/memcontrol.c-358-\n--\nmm/memcontrol.c-360-\nmm/memcontrol.c:361:\treturn memcg ? \u0026memcg-\u003ecss : \u0026root_mem_cgroup-\u003ecss;\nmm/memcontrol.c-362-}\n--\nmm/memcontrol.c=817=void mem_cgroup_flush_stats(struct mem_cgroup *memcg)\n--\nmm/memcontrol.c-822-\tif (!memcg)\nmm/memcontrol.c:823:\t\tmemcg = root_mem_cgroup;\nmm/memcontrol.c-824-\n--\nmm/memcontrol.c=835=static void flush_memcg_stats_dwork(struct work_struct *w)\n--\nmm/memcontrol.c-840-\t */\nmm/memcontrol.c:841:\t__mem_cgroup_flush_stats(root_mem_cgroup, true);\nmm/memcontrol.c-842-\tqueue_delayed_work(system_dfl_wq, \u0026stats_flush_dwork, FLUSH_TIME);\n--\nmm/memcontrol.c=1193=struct mem_cgroup *get_mem_cgroup_from_mm(struct mm_struct *mm)\n--\nmm/memcontrol.c-1217-\t\tif (unlikely(!mm))\nmm/memcontrol.c:1218:\t\t\treturn root_mem_cgroup;\nmm/memcontrol.c-1219-\t}\n--\nmm/memcontrol.c-1224-\t\tif (unlikely(!memcg))\nmm/memcontrol.c:1225:\t\t\tmemcg = root_mem_cgroup;\nmm/memcontrol.c-1226-\t} while (!css_tryget(\u0026memcg-\u003ecss));\n--\nmm/memcontrol.c=1259=struct mem_cgroup *get_mem_cgroup_from_folio(const struct folio *folio)\n--\nmm/memcontrol.c-1266-\tif (!folio_memcg_charged(folio))\nmm/memcontrol.c:1267:\t\treturn root_mem_cgroup;\nmm/memcontrol.c-1268-\n--\nmm/memcontrol.c=1294=struct mem_cgroup *mem_cgroup_iter(struct mem_cgroup *root,\n--\nmm/memcontrol.c-1306-\tif (!root)\nmm/memcontrol.c:1307:\t\troot = root_mem_cgroup;\nmm/memcontrol.c-1308-\n--\nmm/memcontrol.c=1386=void mem_cgroup_iter_break(struct mem_cgroup *root,\n--\nmm/memcontrol.c-1389-\tif (!root)\nmm/memcontrol.c:1390:\t\troot = root_mem_cgroup;\nmm/memcontrol.c-1391-\tif (prev \u0026\u0026 prev != root)\n--\nmm/memcontrol.c=1409=static void invalidate_reclaim_iterators(struct mem_cgroup *dead_memcg)\n--\nmm/memcontrol.c-1421-\t * parent_mem_cgroup() does not walk all the way up to the\nmm/memcontrol.c:1422:\t * cgroup root (root_mem_cgroup). So we have to handle\nmm/memcontrol.c-1423-\t * dead_memcg from cgroup root separately.\n--\nmm/memcontrol.c-1425-\tif (!mem_cgroup_is_root(last))\nmm/memcontrol.c:1426:\t\t__invalidate_reclaim_iterators(root_mem_cgroup,\nmm/memcontrol.c-1427-\t\t\t\t\t\tdead_memcg);\n--\nmm/memcontrol.c=2013=struct mem_cgroup *mem_cgroup_get_oom_group(struct task_struct *victim,\n--\nmm/memcontrol.c-2022-\tif (!oom_domain)\nmm/memcontrol.c:2023:\t\toom_domain = root_mem_cgroup;\nmm/memcontrol.c-2024-\n--\nmm/memcontrol.c=3112=__always_inline struct obj_cgroup *current_obj_cgroup(void)\n--\nmm/memcontrol.c-3132-\t\t */\nmm/memcontrol.c:3133:\t\treturn objcg ? : rcu_dereference_check(root_mem_cgroup-\u003enodeinfo[nid]-\u003eobjcg, 1);\nmm/memcontrol.c-3134-\t}\n--\nmm/memcontrol.c-3139-\nmm/memcontrol.c:3140:\treturn rcu_dereference_check(root_mem_cgroup-\u003enodeinfo[nid]-\u003eobjcg, 1);\nmm/memcontrol.c-3141-\n--\nmm/memcontrol.c-3154-\nmm/memcontrol.c:3155:\treturn rcu_dereference_check(root_mem_cgroup-\u003enodeinfo[nid]-\u003eobjcg, 1);\nmm/memcontrol.c-3156-}\n--\nmm/memcontrol.c=4332=mem_cgroup_css_alloc(struct cgroup_subsys_state *parent_css)\n--\nmm/memcontrol.c-4370-#endif\nmm/memcontrol.c:4371:\t\troot_mem_cgroup = memcg;\nmm/memcontrol.c-4372-\t\treturn \u0026memcg-\u003ecss;\n--\nmm/memcontrol.c=5314=void mem_cgroup_calculate_protection(struct mem_cgroup *root,\n--\nmm/memcontrol.c-5323-\tif (!root)\nmm/memcontrol.c:5324:\t\troot = root_mem_cgroup;\nmm/memcontrol.c-5325-\n--\nmm/memcontrol.c-5331- * mem_cgroup_calculate_protection_path - compute protection along a path\nmm/memcontrol.c:5332: * @root: the top ancestor of the sub-tree being checked (NULL for root_mem_cgroup)\nmm/memcontrol.c-5333- * @memcg: the target memory cgroup\n--\nmm/memcontrol.c=5339=void mem_cgroup_calculate_protection_path(struct mem_cgroup *root,\n--\nmm/memcontrol.c-5350-\tif (!root)\nmm/memcontrol.c:5351:\t\troot = root_mem_cgroup;\nmm/memcontrol.c-5352-\n--\nmm/memcontrol.c=5850=__setup(\"cgroup.memory=\", cgroup_memory);\n--\nmm/memcontrol.c-5852-/*\nmm/memcontrol.c:5853: * Memory controller init before cgroup_init() initialize root_mem_cgroup.\nmm/memcontrol.c-5854- *\n--\nmm/memcontrol.c=6511=void mem_cgroup_show_protected_memory(struct mem_cgroup *memcg)\n--\nmm/memcontrol.c-6516-\tif (!memcg)\nmm/memcontrol.c:6517:\t\tmemcg = root_mem_cgroup;\nmm/memcontrol.c-6518-\n"
}

43/3 2026/11/13 02:29 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 25300
							output: 35
							thoughts: 21
						

Thoughts:
Okay, let's dive in.

**Analyzing `mem_cgroup_css_alloc` - Deep Dive**

Alright, time to get my hands dirty. I need to take a look at the `mem_cgroup_css_alloc` function. Seems like a good starting point for understanding memory cgroup allocation. Let's head straight to line 4332. That's usually a good indicator of where the meat of the function begins. I'm expecting to see the core logic of the allocation process right there. Time to see what we're working with.



44/3 2026/11/13 02:29 tool read-file
0m Args:
{
  "File": "mm/memcontrol.c",
  "FirstLine": 4332,
  "LineCount": 45
}

Results:
{
  "Contents": "4332:\tmem_cgroup_css_alloc(struct cgroup_subsys_state *parent_css)\n4333:\t{\n4334:\t\tstruct mem_cgroup *parent = mem_cgroup_from_css(parent_css);\n4335:\t\tstruct mem_cgroup *memcg, *old_memcg;\n4336:\t\tbool memcg_on_dfl = cgroup_subsys_on_dfl(memory_cgrp_subsys);\n4337:\t\n4338:\t\told_memcg = set_active_memcg(parent);\n4339:\t\tmemcg = mem_cgroup_alloc(parent);\n4340:\t\tset_active_memcg(old_memcg);\n4341:\t\tif (IS_ERR(memcg))\n4342:\t\t\treturn ERR_CAST(memcg);\n4343:\t\n4344:\t\tpage_counter_set_high(\u0026memcg-\u003ememory, PAGE_COUNTER_MAX);\n4345:\t#ifdef CONFIG_ZSWAP\n4346:\t\tmemcg-\u003ezswap_max = PAGE_COUNTER_MAX;\n4347:\t\tWRITE_ONCE(memcg-\u003ezswap_writeback, true);\n4348:\t#endif\n4349:\t\tpage_counter_set_high(\u0026memcg-\u003eswap, PAGE_COUNTER_MAX);\n4350:\t\tif (parent) {\n4351:\t\t\tpage_counter_init(\u0026memcg-\u003ememory, \u0026parent-\u003ememory, memcg_on_dfl);\n4352:\t\t\tpage_counter_init(\u0026memcg-\u003eswap, \u0026parent-\u003eswap, false);\n4353:\t#ifdef CONFIG_MEMCG_V1\n4354:\t\t\tWRITE_ONCE(memcg-\u003eswappiness, mem_cgroup_swappiness(parent));\n4355:\t\t\tmemcg-\u003ememory.track_failcnt = !memcg_on_dfl;\n4356:\t\t\tmemcg-\u003ememsw.track_failcnt = !memcg_on_dfl;\n4357:\t\t\tWRITE_ONCE(memcg-\u003eoom_kill_disable, READ_ONCE(parent-\u003eoom_kill_disable));\n4358:\t\t\tpage_counter_init(\u0026memcg-\u003ekmem, \u0026parent-\u003ekmem, false);\n4359:\t\t\tpage_counter_init(\u0026memcg-\u003etcpmem, \u0026parent-\u003etcpmem, false);\n4360:\t\t\tmemcg-\u003etcpmem.track_failcnt = !memcg_on_dfl;\n4361:\t#endif\n4362:\t\t} else {\n4363:\t\t\tinit_memcg_stats();\n4364:\t\t\tinit_memcg_events();\n4365:\t\t\tpage_counter_init(\u0026memcg-\u003ememory, NULL, true);\n4366:\t\t\tpage_counter_init(\u0026memcg-\u003eswap, NULL, false);\n4367:\t#ifdef CONFIG_MEMCG_V1\n4368:\t\t\tpage_counter_init(\u0026memcg-\u003ekmem, NULL, false);\n4369:\t\t\tpage_counter_init(\u0026memcg-\u003etcpmem, NULL, false);\n4370:\t#endif\n4371:\t\t\troot_mem_cgroup = memcg;\n4372:\t\t\treturn \u0026memcg-\u003ecss;\n4373:\t\t}\n4374:\t\n4375:\t\tif (memcg_on_dfl \u0026\u0026 !cgroup_memory_nosocket)\n4376:\t\t\tstatic_branch_inc(\u0026memcg_sockets_enabled_key);\n"
}

45/3 2026/11/13 02:29 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 26380
							output: 312
							thoughts: 3815
						

Thoughts:
**Analysis of NUMA Balancing Mode Patch for KMSAN Readiness**

Alright, let's break this down. First, the core of the patch seems to revolve around NUMA balancing mode, which is managed at the memcg level. I see that `mem_cgroup_css_alloc` is allocating both root and child memcgs. Good, `mem_cgroup_alloc` is using `kmem_cache_zalloc`, meaning the new `memcg->numab_mode` is zeroed initially, and then explicitly set. This looks safe right off the bat. The BPF kfuncs `bpf_numab_set_mode` and `bpf_numab_get_mode` are added, dealing with scalar integers. Crucially, they aren't copying structs or pointers to userspace which would make me very nervous. They are simply kfuncs called from within BPF programs, fine.

Now, let's dig deeper, especially around data flow. In `task_numab_get_modes`, the code *always* initializes `*enabled` and `*tiering`. This function is pivotal and looks okay. And it's used in `task_numa_fault`, the `*enabled` and `*tiering` flags are both used, which is good.  I need to check that no uninitialized variables sneak through, so I am going to check this closely. I see that `task_numab_mode` retrieves the mode from the memcg, with appropriate checks for `mem_cgroup_disabled()` and `p->mm`. The use of RCU locks here is standard, so I have to check this, in terms of safety. In `folio_numab_mode` is similar. Then, there's `numab_memcg_mode` which iterates up the memcg hierarchy. I can't find anything to flag, in terms of safety, here. I need to make sure that folios and memcgs are handled properly if they are uncharged or not initialized. Here, the code handles the case of a NULL `folio_memcg` gracefully, returning `NUMAB_FOLLOW_SYSTEM`.

Now, the potential for uninitialized memory usage is what I need to watch out for. I see that the patch touches the code around `folio_migrate_flags`, and the effective mode calculations. Looks like there is nothing strange here. The `folio_numab_effective_mode` looks ok.  Also, I need to verify what is being updated with the code changes. I am checking `folio_xchg_access_time` or `cpupid`. The code change is replacing code that used `sysctl_numa_balancing_mode` with equivalent code. The addition of tiering is not a new concept, it is an extension of an existing one. `folio->_last_cpupid` is part of `folio` and is properly initialized. I see no issues here.

The key test is to see whether any information is being leaked to userspace. I don't see any explicit `copy_to_user`, netlink, ioctl calls, or BPF buffer interactions introduced by the patch. All it adds are the BPF kfuncs and the memcg tracking. No new user-facing data is being exposed.

Now, let's analyze for potential KMSAN risks, as the guidelines lay out. The patch could expose uninitialized memory if it involves kernel structures passed to userspace, conditional logic on uninitialized vars, complex data structure allocation with later uninitialized reads, or bounds check abuse that accesses uninitialized bytes. But, based on the analysis:

1.  No structures are copied to userspace.
2.  `memcg->numab_mode` is *explicitly* zeroed and initialized.
3.  All local variables are initialized before use.
4.  All output pointers are unconditionally written.
5.  No new memory buffers or copy routines are added.
6.  The usual concurrency bugs (RCU, mutex, refcounting, etc.) are handled by KASAN and LOCKDEP.

Given that, I'm confident that this patch does *not* introduce KMSAN-specific risks. Therefore, `NeedsKMSAN` should be `false`. Now, let's run `set-results`.



46/3 2026/11/13 02:30 tool set-results
0m Args:
{
  "KMSANReasoning": "The patch series introduces per-cgroup NUMA balancing mode selection via BPF kfuncs (CONFIG_BPF_NUMAB). It adds an integer field `numab_mode` to `struct mem_cgroup`, initializes it in `mem_cgroup_alloc` (which allocates via kmem_cache_zalloc), and updates scheduler and memory tiering logic to consult the effective NUMA balancing mode.\n\n1. No kernel structures or data buffers are copied to user space (no copy_to_user, netlink skb, ioctl output, or info-leak vectors).\n2. All newly introduced and modified variables (such as `numab_enabled` and `numab_tiering` via `task_numab_get_modes`) are deterministically initialized before any read or branch.\n3. The newly added struct field `memcg-\u003enumab_mode` is initialized upon allocation and reset during css offline/reset.\n4. The potential risks introduced by this change are related to concurrency, RCU dereferencing of cgroups/memcgs, cgroup reference counting, and lock handling (mutex vs static keys), all of which are covered by standard bug detectors, KASAN, and LOCKDEP.\n\nBecause there are no uninitialized memory access risks or info-leaks, a dedicated KMSAN fuzzing session is not warranted.",
  "NeedsKMSAN": false
}

Results:
{
  "KMSANReasoning": "The patch series introduces per-cgroup NUMA balancing mode selection via BPF kfuncs (CONFIG_BPF_NUMAB). It adds an integer field `numab_mode` to `struct mem_cgroup`, initializes it in `mem_cgroup_alloc` (which allocates via kmem_cache_zalloc), and updates scheduler and memory tiering logic to consult the effective NUMA balancing mode.\n\n1. No kernel structures or data buffers are copied to user space (no copy_to_user, netlink skb, ioctl output, or info-leak vectors).\n2. All newly introduced and modified variables (such as `numab_enabled` and `numab_tiering` via `task_numab_get_modes`) are deterministically initialized before any read or branch.\n3. The newly added struct field `memcg-\u003enumab_mode` is initialized upon allocation and reset during css offline/reset.\n4. The potential risks introduced by this change are related to concurrency, RCU dereferencing of cgroups/memcgs, cgroup reference counting, and lock handling (mutex vs static keys), all of which are covered by standard bug detectors, KASAN, and LOCKDEP.\n\nBecause there are no uninitialized memory access risks or info-leaks, a dedicated KMSAN fuzzing session is not warranted.",
  "NeedsKMSAN": false
}

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