[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20180215110844.GY12979@localhost.localdomain>
Date: Thu, 15 Feb 2018 12:08:44 +0100
From: Juri Lelli <juri.lelli@...hat.com>
To: Mathieu Poirier <mathieu.poirier@...aro.org>
Cc: Peter Zijlstra <peterz@...radead.org>,
Li Zefan <lizefan@...wei.com>, Ingo Molnar <mingo@...hat.com>,
Steven Rostedt <rostedt@...dmis.org>,
Claudio Scordino <claudio@...dence.eu.com>,
Daniel Bristot de Oliveira <bristot@...hat.com>,
Tommaso Cucinotta <tommaso.cucinotta@...tannapisa.it>,
"luca.abeni" <luca.abeni@...tannapisa.it>, cgroups@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH V3 04/10] sched/core: Prevent race condition between
cpuset and __sched_setscheduler()
On 15/02/18 11:33, Juri Lelli wrote:
> On 14/02/18 17:31, Juri Lelli wrote:
>
> [...]
>
> > Still grabbing it is a no-go, as do_sched_setscheduler calls
> > sched_setscheduler from inside an RCU read-side critical section.
>
> I was then actually thinking that trylocking might do.. not sure however
> if failing with -EBUSY in the contended case is feasible (and about the
> general uglyness of the solution :/).
Or, as suggested by Peter in IRC, the following (which still would
require conditional locking for the sysrq case).
--->8---
kernel/sched/core.c | 21 +++++++++++++++++----
1 file changed, 17 insertions(+), 4 deletions(-)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 0d8badcf1f0f..4e9405d50cbd 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -4312,6 +4312,7 @@ static int __sched_setscheduler(struct task_struct *p,
/* Avoid rq from going away on us: */
preempt_disable();
task_rq_unlock(rq, p, &rf);
+ cpuset_unlock();
if (pi)
rt_mutex_adjust_pi(p);
@@ -4409,10 +4410,16 @@ do_sched_setscheduler(pid_t pid, int policy, struct sched_param __user *param)
rcu_read_lock();
retval = -ESRCH;
p = find_process_by_pid(pid);
- if (p != NULL)
- retval = sched_setscheduler(p, policy, &lparam);
+ if (!p) {
+ rcu_read_unlock();
+ goto exit;
+ }
+ get_task_struct(p);
rcu_read_unlock();
+ retval = sched_setscheduler(p, policy, &lparam);
+ put_task_struct(p);
+exit:
return retval;
}
@@ -4540,10 +4547,16 @@ SYSCALL_DEFINE3(sched_setattr, pid_t, pid, struct sched_attr __user *, uattr,
rcu_read_lock();
retval = -ESRCH;
p = find_process_by_pid(pid);
- if (p != NULL)
- retval = sched_setattr(p, &attr);
+ if (!p) {
+ rcu_read_unlock();
+ goto exit;
+ }
+ get_task_struct(p);
rcu_read_unlock();
+ retval = sched_setattr(p, &attr);
+ put_task_struct(p);
+exit:
return retval;
}
Powered by blists - more mailing lists