Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1403003 > unrolled thread
| Started by | Peter Zijlstra <peterz@infradead.org> |
|---|---|
| First post | 2016-05-18 16:00 +0200 |
| Last post | 2016-05-19 20:00 +0200 |
| Articles | 3 — 1 participant |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: [PATCH v12 07/13] task_isolation: add debug boot flag Peter Zijlstra <peterz@infradead.org> - 2016-05-18 16:00 +0200
Re: [PATCH v12 07/13] task_isolation: add debug boot flag Peter Zijlstra <peterz@infradead.org> - 2016-05-18 19:10 +0200
Re: [PATCH v12 07/13] task_isolation: add debug boot flag Peter Zijlstra <peterz@infradead.org> - 2016-05-19 20:00 +0200
| From | Peter Zijlstra <peterz@infradead.org> |
|---|---|
| Date | 2016-05-18 16:00 +0200 |
| Subject | Re: [PATCH v12 07/13] task_isolation: add debug boot flag |
| Message-ID | <rAab0-2Rm-15@gated-at.bofh.it> |
On Tue, Apr 05, 2016 at 01:38:36PM -0400, Chris Metcalf wrote:
> +#ifdef CONFIG_TASK_ISOLATION
> +void task_isolation_debug(int cpu)
> +{
> + struct task_struct *p;
> +
> + if (!task_isolation_possible(cpu))
> + return;
> +
> + rcu_read_lock();
> + p = cpu_curr(cpu);
> + get_task_struct(p);
> + rcu_read_unlock();
> + task_isolation_debug_task(cpu, p);
> + put_task_struct(p);
This is still broken...
Also, I really don't like how you sprinkle a call all over the core
kernel. At the very least make an inline fast path for this function to
avoid the call whenever possible.
> +}
> +#endif
[toc] | [next] | [standalone]
| From | Peter Zijlstra <peterz@infradead.org> |
|---|---|
| Date | 2016-05-18 19:10 +0200 |
| Message-ID | <rAd8S-4Ww-13@gated-at.bofh.it> |
| In reply to | #1403003 |
On Wed, May 18, 2016 at 12:35:19PM -0400, Chris Metcalf wrote:
> On 5/18/2016 9:56 AM, Peter Zijlstra wrote:
> >On Tue, Apr 05, 2016 at 01:38:36PM -0400, Chris Metcalf wrote:
> >>+#ifdef CONFIG_TASK_ISOLATION
> >>+void task_isolation_debug(int cpu)
> >>+{
> >>+ struct task_struct *p;
> >>+
> >>+ if (!task_isolation_possible(cpu))
> >>+ return;
> >>+
> >>+ rcu_read_lock();
> >>+ p = cpu_curr(cpu);
> >>+ get_task_struct(p);
> >>+ rcu_read_unlock();
> >>+ task_isolation_debug_task(cpu, p);
> >>+ put_task_struct(p);
> >
> >This is still broken...
>
> I don't know how or why, though. :-) Can you give me a better idiom?
> This looks to my eye just like how it's done for something like
> sched_setaffinity() by one task on another task, and I would have
> assumed the risks there of the other task evaporating part way
> through would be the same as the risks here.
Because rcu_read_lock() does not stop the task pointed to by
cpu_curr(cpu) from disappearing on you entirely.
See also the discussion around:
lkml.kernel.org/r/20160518170218.GY3192@twins.programming.kicks-ass.net
[toc] | [prev] | [next] | [standalone]
| From | Peter Zijlstra <peterz@infradead.org> |
|---|---|
| Date | 2016-05-19 20:00 +0200 |
| Message-ID | <rAAoN-2Ue-15@gated-at.bofh.it> |
| In reply to | #1403160 |
On Thu, May 19, 2016 at 10:42:39AM -0400, Chris Metcalf wrote: > >>>>+ rcu_read_lock(); > >>>>+ p = cpu_curr(cpu); Here @cpu can schedule, hit TASK_DEAD and do put_task_struct() and kfree() the task. > >>>>+ get_task_struct(p); And here we then do a use-after-free. > >>>>+ rcu_read_unlock(); > >>>>+ task_isolation_debug_task(cpu, p); > >>>>+ put_task_struct(p); > So, I think what you're saying is that there is a race between when we > read per_cpu(runqueues, cpu).curr, and when we increment the > p->usage value in the task, and that the RCU read lock doesn't help > with that? Yep, as per the above. > My impression was that by being the ".curr" task, we are > guaranteed that it hasn't gone through do_exit() yet, and thus we > benefit from an RCU guarantee around being able to validly dereference > the pointer, i.e. it hasn't yet been freed and so dereferencing is safe. Nope... the only way to avoid this from happening is taking @cpu's rq->lock to prevent the remote CPU from scheduling. > I don't see how grabbing the ->curr from the runqueue is any more > fragile from an RCU perspective than grabbing the task from the pid in > kill_pid_info(). The whole pid data structure is RCU managed, rq->curr is not. > Anyway, whatever more clarity you can offer me, or suggestions for > APIs to use are welcome. The API proposed in the discussion below.. > >See also the discussion around: > > > >lkml.kernel.org/r/20160518170218.GY3192@twins.programming.kicks-ass.net > > This makes me wonder if I should use rcu_dereference(&cpu_curr(p)) > just for clarity, though I think it's just as correct either way. Nope, that's just as broken. So the 'simple' thing is: struct rq *rq = cpu_rq(cpu); struct task_struct *task; raw_spin_lock_irq(&rq->lock); task = rq->curr; get_task_struct(task); raw_spin_unlock_irq(&rq->lock); Because by holding rq->lock, the remote CPU cannot schedule and the current task _must_ still be valid. And note; the above can result in a task which already has PF_EXITING set. The complex thing is described in the linked thread and will likely make your head hurt.
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web