From: Peter Zijlstra <peterz@infradead.org>
To: Waiman Long <longman@redhat.com>
Cc: Ingo Molnar <mingo@redhat.com>,
Juri Lelli <juri.lelli@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
Dietmar Eggemann <dietmar.eggemann@arm.com>,
Steven Rostedt <rostedt@goodmis.org>,
Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
Daniel Bristot de Oliveira <bristot@redhat.com>,
Phil Auld <pauld@redhat.com>,
linux-kernel@vger.kernel.org, Paul McKenney <paulmck@kernel.org>
Subject: Re: [PATCH-tip] sched: Don't call kfree() in do_set_cpus_allowed()
Date: Tue, 22 Nov 2022 20:24:04 +0100 [thread overview]
Message-ID: <Y30h1NXFmDrHAXcy@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <70b65b5b-385d-1c47-f003-1e42de290e86@redhat.com>
On Tue, Nov 22, 2022 at 10:23:43AM -0500, Waiman Long wrote:
> index 78b2d5cabcc5..5fac4aa6ac7f 100644
> --- a/kernel/sched/core.c
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index 78b2d5cabcc5..5fac4aa6ac7f 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -2593,6 +2593,11 @@ __do_set_cpus_allowed(struct task_struct *p, struct
> affinity_context *ctx)
> set_next_task(rq, p);
> }
>
> +union cpumask_rcuhead {
> + void *cpumask;
> + struct rcu_head rcu;
> +};
> +
Hehe; I had this union too; I just figured it'd be nice to not have to
spend these 4 lines to express this. Esp. since we're casting pointers
*anyway*.
> /*
> * Used for kthread_bind() and select_fallback_rq(), in both cases the user
> * affinity (if any) should be destroyed too.
> @@ -2606,7 +2611,12 @@ void do_set_cpus_allowed(struct task_struct *p, const
> struct cpumask *new_mask)
> };
>
> __do_set_cpus_allowed(p, &ac);
> - kfree(ac.user_mask);
> + /*
> + * Because this is called with p->pi_lock held, it is not possible
> + * to use kfree() here (when PREEMPT_RT=y), therefore punt to using
> + * kfree_rcu().
> + */
> + kfree_rcu((union cpumask_rcuhead *)ac.user_mask, rcu);
> }
>
> int dup_user_cpus_ptr(struct task_struct *dst, struct task_struct *src,
> @@ -8196,7 +8206,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();
>
> @@ -8229,7 +8239,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(union cpumask_rcuhead));
> + user_mask = kmalloc(size, GFP_KERNEL);
> if (!user_mask) {
> retval = -ENOMEM;
> goto out_put_task;
>
We also should fix the allocation in dup_user_cpus_ptr() -- perhaps pull
the thing into a helper.
next prev parent reply other threads:[~2022-11-22 19:24 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-18 19:33 Waiman Long
2022-11-21 10:38 ` Peter Zijlstra
2022-11-21 15:04 ` Waiman Long
2022-11-22 12:37 ` Peter Zijlstra
2022-11-22 15:23 ` Waiman Long
2022-11-22 16:33 ` Paul E. McKenney
2022-11-22 19:24 ` Peter Zijlstra [this message]
2022-11-22 19:30 ` Waiman Long
2022-11-22 19:58 ` Peter Zijlstra
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y30h1NXFmDrHAXcy@hirez.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=bristot@redhat.com \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=juri.lelli@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=longman@redhat.com \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=pauld@redhat.com \
--cc=paulmck@kernel.org \
--cc=rostedt@goodmis.org \
--cc=vincent.guittot@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®