Re: [PATCH-tip v3] sched: Use kfree_rcu() in do_set_cpus_allowed()

From: Waiman Long
Date: Thu Dec 22 2022 - 16:04:35 EST



On 12/22/22 15:25, Peter Zijlstra wrote:
On Thu, Dec 22, 2022 at 03:18:29PM -0500, Waiman Long wrote:

@@ -8220,7 +8230,7 @@ long sched_setaffinity(pid_t pid, const struct cpumask *in_mask)
struct affinity_context ac;
struct cpumask *user_mask;
struct task_struct *p;
- int retval;
+ int retval, size;
rcu_read_lock();
@@ -8253,7 +8263,11 @@ long sched_setaffinity(pid_t pid, const struct cpumask *in_mask)
if (retval)
goto out_put_task;
- user_mask = kmalloc(cpumask_size(), GFP_KERNEL);
+ /*
+ * See do_set_cpus_allowed() for the rcu_head usage.
+ */
+ size = max_t(int, cpumask_size(), sizeof(struct rcu_head));
+ user_mask = kmalloc(size, GFP_KERNEL);
if (!user_mask) {
retval = -ENOMEM;
goto out_put_task;
AFAICT you forgot dup_user_cpus_ptr().
I haven't received any response from you for a while. So it is just a ping.
I was out sick :/

I am sorry to hear that. Hope you are all right now.



Of course, I am aware that there is another dup_user_cpus_ptr() patch
ouststanding. I will of course talk about that when you respond. I also have
a pending rwsem patch series waiting for your review:-)
The point was that dup_user_cpus_ptr() also does an allocation and needs
to allocate the possibly bigger size too, no?

Oh, yes. I missed that. I will combine the two patches into a patch series.

Thanks,
Longman