From nobody Tue Sep 29 05:35:09 2026 Received: from mailgw1.hygon.cn (unknown [101.204.27.37]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F0C1433F5B4 for ; Wed, 12 Aug 2026 06:23:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=101.204.27.37 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786515830; cv=none; b=oJJXHqlQs+aDNDEKa8Ku2yNiIazPZuZIDQd8HBadaxTRHPWFymcgn0fqoO0dOC0OdTLFNi8mwfJxXqsLe+Fn4UycvOvwA8sUY3YvBQ/VudVXtHfWQWzHN1o/eWigDxJZTRjAmzn3sDeDgDf4fyHmWus2FGjiGKCvEmQGRw2FgI8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786515830; c=relaxed/simple; bh=UsHnB03xGyR1o+CZHoxqztn26lyv2ASdJSFE7s1qSPw=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=pILk8O2Pfq/deRLggnQCfbe06822nq9xZ4h6pBHcI8kVym8VZS3sDL6UnNaKYVTKgHEFk4e/RooNCa2YCh8kpfV+Lgt6Ztdp/adyU6eYTXW+MmRUMglm2DMm0Qa3fLcLrB3EWvU5xFCeZtKXc1lDjzHk/gXtJNmfugrx/97OZp8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=hygon.cn; spf=pass smtp.mailfrom=hygon.cn; arc=none smtp.client-ip=101.204.27.37 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=hygon.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=hygon.cn Received: from maildlp2.hygon.cn (unknown [127.0.0.1]) by mailgw1.hygon.cn (Postfix) with ESMTP id 4hKdj93qBhzTZhW; Wed, 12 Aug 2026 14:23:25 +0800 (CST) Received: from maildlp2.hygon.cn (unknown [172.23.18.61]) by mailgw1.hygon.cn (Postfix) with ESMTP id 4hKdj910zLzTZhW; Wed, 12 Aug 2026 14:23:25 +0800 (CST) Received: from cncheex04.Hygon.cn (unknown [172.23.18.114]) by maildlp2.hygon.cn (Postfix) with ESMTPS id 4645731F108F; Wed, 12 Aug 2026 14:20:10 +0800 (CST) Received: from hygon.cn (172.19.21.128) by cncheex04.Hygon.cn (172.23.18.114) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.36; Wed, 12 Aug 2026 14:23:17 +0800 From: Fengyu Wang To: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot CC: Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , K Prateek Nayak , Chen Yu , Tim Chen , Shrikanth Hegde , , wujianyong , zhongyuan , huangshijie , wangfengyu Subject: [PATCH v2] sched/topology: Free NUMA masks on topology allocation failure Date: Wed, 12 Aug 2026 14:22:06 +0800 Message-ID: <20260812062206.82410-1-wangfengyu@hygon.cn> 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-Transfer-Encoding: quoted-printable X-ClientProxiedBy: cncheex05.Hygon.cn (172.23.18.115) To cncheex04.Hygon.cn (172.23.18.114) Content-Type: text/plain; charset="utf-8" sched_init_numa() publishes sched_domains_numa_masks before it allocates the topology array. When that allocation fails, the early return leaves the masks published while sched_domains_numa_levels is still zero: nothing dereferences them, but nothing can free them either, and the topology they were built for is never installed. Free the masks on that path, and publish them only once the topology array they were built for has been allocated. Fixes: cb83b629bae0 ("sched/numa: Rewrite the CONFIG_NUMA sched domain supp= ort") Signed-off-by: Fengyu Wang Reviewed-by: Tim Chen Reviewed-by: Valentin Schneider --- v2: - Publish sched_domains_numa_masks only after the topology array has been allocated, instead of publishing it early and unpublishing it on the failure path. This drops the rcu_assign_pointer(NULL) and the synchronize_rcu() from the error path (Tim Chen). v1: https://lore.kernel.org/lkml/20260731081413.5505-1-wangfengyu@hygon.cn/ Tested by hardcoding tl to NULL right after the kzalloc() to force the failure path; the masks are released and the machine boots normally. kernel/sched/topology.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c index 21e816ad23ee..50457f720808 100644 --- a/kernel/sched/topology.c +++ b/kernel/sched/topology.c @@ -2392,15 +2392,23 @@ void sched_init_numa(int offline_node) } } } - rcu_assign_pointer(sched_domains_numa_masks, masks); =20 /* Compute default topology size */ for (i =3D 0; sched_domain_topology[i].mask; i++); =20 tl =3D kzalloc((i + nr_levels + 1) * sizeof(struct sched_domain_topology_level), GFP_KERNEL); - if (!tl) + if (!tl) { + for (i =3D 0; i < nr_levels; i++) { + for_each_node(j) + kfree(masks[i][j]); + kfree(masks[i]); + } + kfree(masks); return; + } + + rcu_assign_pointer(sched_domains_numa_masks, masks); =20 /* * Copy the default topology bits.. --=20 2.34.1