From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from canpmsgout10.his.huawei.com (canpmsgout10.his.huawei.com [113.46.200.225]) (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 73AC43D3CE3 for ; Tue, 4 Aug 2026 08:35:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.225 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785832530; cv=none; b=reaJevILUXu/fQhCvChrJ/SdmFVeIl1TqonrJm9yej+Atrr0wCe3j7gDLuJ2gXLYim9dh3KyewNlsjMxRyfYPrzjInLgsMjLTztlVxn8B0ElK6OSdb+HHig+e4HWVy4H6Ye90bIJC6eWHM7nKwu7cVJ14CcldGgR4YQ6fc0zX4M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785832530; c=relaxed/simple; bh=VXbGCKtbXjBkK+Bu5aYn1CkUKuNbikKT8wzkDuQ2iqM=; h=Message-ID:Date:MIME-Version:Subject:To:CC:References:From: In-Reply-To:Content-Type; b=I+ycbumPRS4rggzq/TbXIfVStLcukRpfv9kEZmGK+TxYCyVSSBcyzN3C1PjcZIb7JASMFhitM28t29G25d6sASwcmXjeitOT9jk0Yb+07E8ur/ceARKrE6XzprHLQkmCYAJl1I/0z4uHembvVGZh/K/VgSzL4dP2BGj9F03J8PI= 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=yxWLvHXr; arc=none smtp.client-ip=113.46.200.225 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="yxWLvHXr" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=7HC+z1GHrUxpiRPkPygZNI+rkByE5NWygemRmHdt6rU=; b=yxWLvHXrquGSH6ovWcab4qSSfTO/aoOd2D2FQNDX4QimEtofc4U4LeejVT9cOXwP912OHhIyJ dab0RPHqdoou0liznJsfG73FGT5GH5C38tmgyQlBK4lLS8gqFWnuVarLRt+nirI0KqP0owFVoDc gGPdrzUBejZC+BT+gzRY+Z8= Received: from mail.maildlp.com (unknown [172.19.163.214]) by canpmsgout10.his.huawei.com (SkyGuard) with ESMTPS id 4hDmp51hw2z1K9D2; Tue, 4 Aug 2026 16:25:49 +0800 (CST) Received: from kwepemr500016.china.huawei.com (unknown [7.202.195.68]) by mail.maildlp.com (Postfix) with ESMTPS id B20BB4056C; Tue, 4 Aug 2026 16:35:18 +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:35:18 +0800 Message-ID: Date: Tue, 4 Aug 2026 16:35:17 +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> From: chenjinghuang In-Reply-To: <3149b834-b4bc-485c-8ea5-6b5c6d2d4db1@amd.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-ClientProxiedBy: kwepems500002.china.huawei.com (7.221.188.17) To kwepemr500016.china.huawei.com (7.202.195.68) On 8/4/2026 1:09 PM, K Prateek Nayak wrote: > Hell Chen, > > On 8/3/2026 6:00 PM, Chen Jinghuang wrote: >> +static DEFINE_MUTEX(numabalancing_mutex); >> + >> void set_numabalancing_state(bool enabled) >> { >> + mutex_lock(&numabalancing_mutex); >> if (enabled) >> sysctl_numa_balancing_mode = NUMA_BALANCING_NORMAL; >> else >> sysctl_numa_balancing_mode = NUMA_BALANCING_DISABLED; >> __set_numabalancing_state(enabled); >> + mutex_unlock(&numabalancing_mutex); >> } > > Doesn't sysctl_numa_balancing() directly call __set_numabalancing_state() > and this bit is only used by check_numabalancing_enable() on the mm side > during early init? > > I think you should move this serialization into sysctl_numa_balancing() > because nothing can race during early init and we only need this for sysfs > writes. > 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); 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); } return err; }