From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) (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 7D3B833065D for ; Wed, 12 Aug 2026 19:51:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.10 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786564321; cv=none; b=XH/tdRBO42p4TBeSUtN9FMldMuSp5qxVczFkR4oN2lAdUWUq7MjGQPub4V429uw38d3s/o2tddMlWVKQwNcTya9XgHEUE9HxukzeUPRTTXFhA3c/EXSW+op1r+TKJgqau9TLLZaj+Vouh07fhJmSWitCYsqHoUgv281dr2sVi1E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786564321; c=relaxed/simple; bh=l5LXVIlqzoYylOiFte2dtLiYTzR8e0c/06BcZ1+YExA=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=TAgaFckubpAP6Hfulk7zhgNtGB6kdphFyPCotwp73/WsnRaC6fh1oAsCtF/IayW7vDrxhafut+td7xeJ0HOe3UBgYGBL1hKKeSDMgqoYQs90LgnqVjHr+J3siP9zLH6AyEQZaDhFy512QPAGnKiMUZ0dA3hDWvqEw/pKwNVO848= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=RBHAiLUQ; arc=none smtp.client-ip=198.175.65.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="RBHAiLUQ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1786564320; x=1818100320; h=message-id:subject:from:to:cc:date:in-reply-to: references:content-transfer-encoding:mime-version; bh=l5LXVIlqzoYylOiFte2dtLiYTzR8e0c/06BcZ1+YExA=; b=RBHAiLUQ8qS6YI+aI9AVWeOFvx6KJE9JHKT9XAIS/i4ddNs3ZO0/Lm6W vKygpDU+pU0nqR3wV7Na1gsGF1YMTMR94p727P5pmQVi3kLHJdLRHUBtA SMjUQrEQtbjmHHFwtEIY7rd/pAij2mzu04t4t+NKKuwz1nKNrrXgsiAN1 zMyu8WSBSyRbmz4dsdFxsbTNfLK+8nvx0r0VfoVwCfI4uhEoNcAV3RHXK NAqb9l85dEAE9Pht7tZ5RJgQplfhxnFzhzTmJtbmm8Vw2ftpI8+yGMoe6 fay8/WzCM6Z5ZFGh65xJal+S3bvtkd/vn4SsJSGaLe+fLJuMrcAqsbaEb g==; X-CSE-ConnectionGUID: UeiFWwvwRxuK85jQpTfdNg== X-CSE-MsgGUID: YWUmQI3aQ5ycfVByGNRECw== X-IronPort-AV: E=McAfee;i="6800,10657,11873"; a="104516559" X-IronPort-AV: E=Sophos;i="6.25,220,1779174000"; d="scan'208";a="104516559" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Aug 2026 12:51:59 -0700 X-CSE-ConnectionGUID: fvyQzZp6QhWBTjYOFTSxxg== X-CSE-MsgGUID: u/BTuvf4SVqXbr+Fg4QhUA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.25,220,1779174000"; d="scan'208";a="268001260" Received: from unknown (HELO [10.241.243.185]) ([10.241.243.185]) by orviesa005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Aug 2026 12:51:59 -0700 Message-ID: <5adf2cf613a99399750da3d2ea1a095b228d33af.camel@linux.intel.com> Subject: Re: [PATCH v2] sched/topology: Free NUMA masks on topology allocation failure From: Tim Chen To: Fengyu Wang , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot Cc: Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , K Prateek Nayak , Chen Yu , Shrikanth Hegde , linux-kernel@vger.kernel.org, wujianyong , zhongyuan , huangshijie Date: Wed, 12 Aug 2026 12:51:58 -0700 In-Reply-To: <20260812062206.82410-1-wangfengyu@hygon.cn> References: <20260812062206.82410-1-wangfengyu@hygon.cn> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.58.1 (3.58.1-1.fc43) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 On Wed, 2026-08-12 at 14:22 +0800, Fengyu Wang wrote: > 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. >=20 > Free the masks on that path, and publish them only once the topology > array they were built for has been allocated. >=20 Reviewed-by: Tim Chen Tim > Fixes: cb83b629bae0 ("sched/numa: Rewrite the CONFIG_NUMA sched domain su= pport") > Signed-off-by: Fengyu Wang > --- > 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). >=20 > v1: https://lore.kernel.org/lkml/20260731081413.5505-1-wangfengyu@hygon.c= n/ >=20 > Tested by hardcoding tl to NULL right after the kzalloc() to force the > failure path; the masks are released and the machine boots normally. >=20 > kernel/sched/topology.c | 12 ++++++++++-- > 1 file changed, 10 insertions(+), 2 deletions(-) >=20 > 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..