Subject: Re: [PATCH 13/33] cpuset: Update HK_TYPE_DOMAIN cpumask from cpuset

From: Frederic Weisbecker <[email-masked]>
Date: Wed, 5 Nov 2025 16:45:53 +0100

Le Tue, Oct 21, 2025 at 09:39:10AM -0400, Waiman Long a écrit :
> On 10/13/25 4:31 PM, Frederic Weisbecker wrote:
> > @@ -80,12 +110,45 @@ EXPORT_SYMBOL_GPL(housekeeping_affine);
> >   bool housekeeping_test_cpu(int cpu, enum hk_type type)
> >   {
> > -	if (housekeeping.flags & BIT(type))
> > +	if (READ_ONCE(housekeeping.flags) & BIT(type))
> >   		return cpumask_test_cpu(cpu, housekeeping_cpumask(type));
> >   	return true;
> >   }
> >   EXPORT_SYMBOL_GPL(housekeeping_test_cpu);
> > +int housekeeping_update(struct cpumask *mask, enum hk_type type)
> > +{
> > +	struct cpumask *trial, *old = NULL;
> > +
> > +	if (type != HK_TYPE_DOMAIN)
> > +		return -ENOTSUPP;
> > +
> > +	trial = kmalloc(sizeof(*trial), GFP_KERNEL);
> Should you use cpumask_size() instead of sizeof(*trial) as the latter can be
> much bigger?

Good point!

> > +	if (!trial)
> > +		return -ENOMEM;
> > +
> > +	cpumask_andnot(trial, housekeeping_cpumask(HK_TYPE_DOMAIN_BOOT), mask);
> > +	if (!cpumask_intersects(trial, cpu_online_mask)) {
> > +		kfree(trial);
> > +		return -EINVAL;
> > +	}
> > +
> > +	if (!housekeeping.flags)
> > +		static_branch_enable(&housekeeping_overridden);
> > +
> > +	if (!(housekeeping.flags & BIT(type)))
> > +		old = housekeeping_cpumask_dereference(type);
> > +	else
> > +		WRITE_ONCE(housekeeping.flags, housekeeping.flags | BIT(type));
> > +	rcu_assign_pointer(housekeeping.cpumasks[type], trial);
> > +
> > +	synchronize_rcu();
> > +
> > +	kfree(old);
> 
> If "isolcpus" boot command line option is set, old can be a pointer to the
> boot time memblock area which isn't a pointer that can be handled by the
> slab allocator AFAIU. I don't know the exact consequence, but it may not be
> good. One possible solution I can think of is to make HK_TYPE_DOMAIN and
> HK_TYPE_DOMAIN_ROOT point to the same memblock pointer and don't pass the
> old HK_TYPE_DOMAIN pointer to kfree() if it matches HK_TYPE_DOMAIN_BOOT one.
> Alternatively, we can just set the HK_TYPE_DOMAIN_BOOT pointer at boot and
> make HK_TYPE_DOMAIN falls back to HK_TYPE_DOMAIN_BOOT if not set.

Have a look at housekeeping_init() which reallocates the memblock
allocated memory with kmalloc to avoid these troubles.

Thanks!

-- 
Frederic Weisbecker
SUSE Labs