From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from canpmsgout11.his.huawei.com (canpmsgout11.his.huawei.com [113.46.200.226]) (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 0A36642AF88 for ; Tue, 4 Aug 2026 08:52:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.226 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785833531; cv=none; b=A/t2Jgn55g4+kLOBdorrrhs6EdOUnqtC5Y7gMqqZuK60mpgxqw2O4vVIwLLLdS/jMWwM9ovR67cTSSqLt2HIiJTNFe9GtCebJ0zgjepA0YYkG5t7WWzaJJ5Ew980JBVYeDwX9ghOMNpjwRGtvfCTgz4yvlQmx9m/SynNGR3gPIc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785833531; c=relaxed/simple; bh=5sP55dT+7Ti0k39ARosNbEMfA0Yy27Uvu7rkmN7djzA=; h=Message-ID:Date:MIME-Version:Subject:To:CC:References:From: In-Reply-To:Content-Type; b=i78WS4aLVPxPdBXaI3jG456CHI6jWBIvYwgks1B9gkIs4zXdpXCWHaBnA3teMaxrrQTMHD9r+HM171eglaIflsxKCBPL+GFNY8bmTvf1VawcneOWrGcMggUj8xkTq9ap6MZP6yugyJVCgK3WKjwjs1hLr2BPAucxYKVWdMntbgA= 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=TgA9PvbT; arc=none smtp.client-ip=113.46.200.226 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="TgA9PvbT" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=ZRQV0fSt/xr/NMSRdIdEv1Xp4x0s+Ih3/12ZzONHSNg=; b=TgA9PvbTWkWlG2sP7ClxE2jlFUQauVqgA2XOVzpdJCNmn/22hSUJP0YOUF5VvPuv02VXtG2a8 nlqjQO33EP1XXDre0wuXWndvtjMpilmPrwwL1Dr4zaSj5cCPfWRlU7Ua+mkYPST3fCRbyI41xDA Ef37PbS/+St5GQGH3Varzqs= Received: from mail.maildlp.com (unknown [172.19.163.163]) by canpmsgout11.his.huawei.com (SkyGuard) with ESMTPS id 4hDn9L1HWyzKmSx; Tue, 4 Aug 2026 16:42:30 +0800 (CST) Received: from kwepemr500016.china.huawei.com (unknown [7.202.195.68]) by mail.maildlp.com (Postfix) with ESMTPS id 6481C4057A; Tue, 4 Aug 2026 16:52:03 +0800 (CST) Received: from [10.67.111.161] (10.67.111.161) 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 16:52:02 +0800 Message-ID: Date: Tue, 4 Aug 2026 16:52:02 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] sched/numa: Prevent race on sysctl_numa_balancing static key To: K Prateek Nayak , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Paolo Bonzini CC: Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , References: <20260803123046.297426-1-chenjinghuang2@huawei.com> <3149b834-b4bc-485c-8ea5-6b5c6d2d4db1@amd.com> <7bf9d48c-2a74-45b6-bfdc-faf10830f3f1@amd.com> From: chenjinghuang In-Reply-To: <7bf9d48c-2a74-45b6-bfdc-faf10830f3f1@amd.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-ClientProxiedBy: kwepems200002.china.huawei.com (7.221.188.68) To kwepemr500016.china.huawei.com (7.202.195.68) On 8/4/2026 4:44 PM, K Prateek Nayak wrote: > Hello Chen, > > On 8/4/2026 2:05 PM, chenjinghuang wrote: >> You're right - my mistake, I'll move numabalancing_mutex into sysctl_numa_balancing() >> and drop it from the early-init path. No one races during init, so the lock is only >> needed for sysfs writes: >> >> +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,11 +4668,13 @@ static int sysctl_numa_balancing(const struct ctl_table *table, int write, >> if (err < 0) >> return err; >> if (write) { >> + mutex_lock(&numabalancing_mutex); > > nit. You can just use a: > > guard(mutex)(&numabalancing_mutex); > >> if (!(sysctl_numa_balancing_mode & NUMA_BALANCING_MEMORY_TIERING) && >> (state & NUMA_BALANCING_MEMORY_TIERING)) >> reset_memory_tiering(); >> sysctl_numa_balancing_mode = state; >> __set_numabalancing_state(state); >> + mutex_unlock(&numabalancing_mutex); > > ... and save on the need to explicitly call unlock here. > >> } >> return err; >> } > Thanks Prateek, I'll update the patch accordingly.