From nobody Fri Oct 2 06:59:10 2026 Received: from canpmsgout06.his.huawei.com (canpmsgout06.his.huawei.com [113.46.200.221]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DA10A3E49CF for ; Tue, 4 Aug 2026 09:17:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.221 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785835082; cv=none; b=IxSlK+t/0x7viFNXPpXrZFwaBTN300b/1M0iBQ7nD2hnsBy10Ytas9ualWhKfn42yVksXG+vn9Iszr+tUw5kJ3AjCYnVgnvTxzoqNDEllYgORLgqesg1/zfX9kiTr/grHSmHmiOp/MIwGzQIBLcwXyvPtWS9XTfXa+9inUFduyQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785835082; c=relaxed/simple; bh=Elo54nMQyRjNYa91d8LqWlRvotPqNtDPUqUnx/U/LyU=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=V7LToxbyX52flysmP8JpELtWr2D1y0oH8TRru69vpwy3TLiuIn/BEL63ERQXjUKngmeeP/mHI7fTWcU45vCtS6l000tMPsXr8VOpIBaYtmW+NbRCpe1m2h7DcbkyUZXmWKBJCaywdTvt1QXgxYl2mOhtuhYNplZsv2+DMrXEOYY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=xK59aKig; arc=none smtp.client-ip=113.46.200.221 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="xK59aKig" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=Cxddir9IrObFkKcW9KoLoVHCxnrw5R/WPh3JAszW7eU=; b=xK59aKigDN2rV4iHrfsdcjupbqVfoiVld6JKuN/Dgwm2P6ObeqoNEuspSLMCv49MkOM7WBr1k PTkSO3v51HIqjM38IpOEXRmAoVdgwMyuBlja5VHd5UwqLLCtnYCeShyxR4KrhUpractHnE+Y0co FfTb78jmK4SvTkSgJgp6L+0= Received: from mail.maildlp.com (unknown [172.19.163.104]) by canpmsgout06.his.huawei.com (SkyGuard) with ESMTPS id 4hDnl718cTzRhQt; Tue, 4 Aug 2026 17:08:19 +0800 (CST) Received: from kwepemr500016.china.huawei.com (unknown [7.202.195.68]) by mail.maildlp.com (Postfix) with ESMTPS id 8C1004058C; Tue, 4 Aug 2026 17:17:48 +0800 (CST) Received: from huawei.com (10.67.174.242) by kwepemr500016.china.huawei.com (7.202.195.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.45; Tue, 4 Aug 2026 17:17:48 +0800 From: Chen Jinghuang To: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Paolo Bonzini CC: Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , K Prateek Nayak , Subject: [PATCH v2] sched/numa: Prevent race on sysctl_numa_balancing static key Date: Tue, 4 Aug 2026 08:53:20 +0000 Message-ID: <20260804085320.570021-1-chenjinghuang2@huawei.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems500001.china.huawei.com (7.221.188.70) To kwepemr500016.china.huawei.com (7.202.195.68) While fuzzing with syzkaller, a concurrent 1/0 write race to /proc/sys/kernel/numa_balancing was found that trips a jump_label WARN_ON_ONCE(). Concurrent writes of 1/0 to /proc/sys/kernel/numa_balancing enable/disable the same static key. Enable sets key->enabled to -1 while holding the lock, restoring it to 1 only after jump_label_update(); disable checks enabled before taking the lock. Under concurrency, disable reads -1 and trips WARN_ON_ONCE(). Timeline: write 1 =E2=86=92 enable write 0 =E2=86=92 disable =E2=94=82 =E2=94=82 =E2=94=9C=E2=94=80 static_key_enable_cpuslocked() =E2=94=9C=E2=94=80= static_key_disable_cpuslocked() =E2=94=82 jump_label_lock() =E2=94=82 atomic_read(ena= bled) =E2=86=90 before lock =E2=94=82 atomic_set(enabled, -1) =E2=97=84=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=BC=E2=94=80=E2=94=80 reads -1 =E2=94=82 jump_label_update() =E2=94=82 WARN_ON_ONCE(en= abled!=3D0) =E2=94=82 atomic_set_release(enabled,1) =E2=94=82 return =E2=86= =90 disable skipped =E2=94=82 jump_label_unlock() =E2=94=82 Serialize the enable/disable switch at the convergence point in sysctl_numa_balancing() with a mutex, so the transient -1 in key->enabled never leaks to a concurrent disable and this WARN_ON_ONCE no longer trips. This follows existing kernel practice, e.g. timer_key_mutex guarding timers_update_migration() (kernel/time/timer.c) and perf_sched_mutex guarding static_branch_enable() (kernel/events/core.c). Fixes: 1dbb6704de91 ("jump_label: Fix concurrent static_key_enable/disable(= )") Reported-by: Zhang zhaotian Suggested-by: K Prateek Nayak Signed-off-by: Chen Jinghuang --- Changes since v1: https://lore.kernel.org/lkml/20260803123046.297426-1-chen= jinghuang2@huawei.com/ - Move numabalancing_mutex into the write path of sysctl_numa_balancing() (no locking needed during init). - Use guard(mutex) instead of the explicit mutex_lock()/mutex_unlock(). --- kernel/sched/core.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 96226707c2f6..87c7c727b743 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -4650,6 +4650,8 @@ static void reset_memory_tiering(void) } } =20 +static DEFINE_MUTEX(numabalancing_mutex); + static int sysctl_numa_balancing(const struct ctl_table *table, int write, void *buffer, size_t *lenp, loff_t *ppos) { @@ -4666,6 +4668,7 @@ static int sysctl_numa_balancing(const struct ctl_tab= le *table, int write, if (err < 0) return err; if (write) { + guard(mutex)(&numabalancing_mutex); if (!(sysctl_numa_balancing_mode & NUMA_BALANCING_MEMORY_TIERING) && (state & NUMA_BALANCING_MEMORY_TIERING)) reset_memory_tiering(); --=20 2.34.1