Re: [PATCH] sched/numa: Prevent race on sysctl_numa_balancing static key

K Prateek Nayak <[email protected]>
Newsgroups gmane.linux.kernel
Message-ID <[email protected]>
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 and Regards,
Prateek
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.