mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Chris Metcalf <cmetcalf@mellanox.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Gilad Ben Yossef <giladb@ezchip.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Ingo Molnar <mingo@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Rik van Riel <riel@redhat.com>, Tejun Heo <tj@kernel.org>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
	Christoph Lameter <cl@linux.com>,
	Viresh Kumar <viresh.kumar@linaro.org>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will.deacon@arm.com>,
	Andy Lutomirski <luto@amacapital.net>,
	<linux-doc@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v12 07/13] task_isolation: add debug boot flag
Date: Thu, 19 May 2016 11:12:24 -0400	[thread overview]
Message-ID: <ff42f417-655f-199a-4200-d4a95f166cf8@mellanox.com> (raw)
In-Reply-To: <20160518170647.GL3193@twins.programming.kicks-ass.net>

(Resending in text/plain.  I just screwed around with my Thunderbird
config some more in hopes of getting it to pay attention to all the
settings that say "use plain text for LKML", but, we'll see.)

On 5/18/2016 1:06 PM, Peter Zijlstra wrote:
> 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.

So clearly once we have a task struct with an incremented usage count,
we are golden: the task isolation code only touches immediate fields
of task_struct, which are guaranteed to stick around until we
put_task_struct(), and the other path is into send_sig_info(), which
is already robust to the task struct being exited (the ->sighand
becomes NULL and we bail out in __lock_task_sighand, otherwise we're
holding sighand->siglock until we deliver the signal).

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?  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.

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().  And in fact, that code doesn't even bump
task->usage, as far as I can see, just relying on getting the
sighand->siglock.

Anyway, whatever more clarity you can offer me, or suggestions for
APIs to use are welcome.

> 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.

-- 
Chris Metcalf, Mellanox Technologies
http://www.mellanox.com

  reply	other threads:[~2016-05-19 15:12 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-05 17:38 [PATCH v12 00/13] support "task_isolation" mode Chris Metcalf
2016-04-05 17:38 ` [PATCH v12 01/13] vmstat: add quiet_vmstat_sync function Chris Metcalf
2016-04-05 17:38 ` [PATCH v12 02/13] vmstat: add vmstat_idle function Chris Metcalf
2016-04-05 17:38 ` [PATCH v12 03/13] lru_add_drain_all: factor out lru_add_drain_needed Chris Metcalf
2016-04-05 17:38 ` [PATCH v12 04/13] task_isolation: add initial support Chris Metcalf
2016-05-18 13:34   ` Peter Zijlstra
2016-05-18 16:34     ` Chris Metcalf
2016-05-18 17:09       ` Peter Zijlstra
2016-04-05 17:38 ` [PATCH v12 05/13] task_isolation: support CONFIG_TASK_ISOLATION_ALL Chris Metcalf
2016-05-18 13:35   ` Peter Zijlstra
2016-05-18 16:34     ` Chris Metcalf
2016-04-05 17:38 ` [PATCH v12 06/13] task_isolation: support PR_TASK_ISOLATION_STRICT mode Chris Metcalf
2016-05-18 13:44   ` Peter Zijlstra
2016-05-18 16:34     ` Chris Metcalf
2016-04-05 17:38 ` [PATCH v12 07/13] task_isolation: add debug boot flag Chris Metcalf
2016-05-18 13:56   ` Peter Zijlstra
2016-05-18 16:36     ` Chris Metcalf
     [not found]     ` <684587d7-3653-7570-215f-37d3e9e786bc@mellanox.com>
2016-05-18 17:06       ` Peter Zijlstra
2016-05-19 15:12         ` Chris Metcalf [this message]
     [not found]         ` <b22cf841-9555-fff3-435b-646c4fd95bdc@mellanox.com>
2016-05-19 17:54           ` Peter Zijlstra
2016-05-19 18:05             ` Chris Metcalf
2016-04-05 17:38 ` [PATCH v12 08/13] task_isolation: add PR_TASK_ISOLATION_ONE_SHOT flag Chris Metcalf
2016-04-05 17:38 ` [PATCH v12 09/13] arm, tile: turn off timer tick for oneshot_stopped state Chris Metcalf
2016-04-07 16:58   ` Daniel Lezcano
2016-04-05 17:38 ` [PATCH v12 10/13] arch/x86: enable task isolation functionality Chris Metcalf
2016-05-18 16:23   ` Peter Zijlstra
2016-05-18 16:35     ` Chris Metcalf
2016-05-18 17:10       ` Peter Zijlstra
2016-04-05 17:38 ` [PATCH v12 11/13] arch/tile: " Chris Metcalf
2016-04-05 17:38 ` [PATCH v12 12/13] arm64: factor work_pending state machine to C Chris Metcalf
2016-07-08 15:43   ` [PATCH]: " Chris Metcalf
2016-07-08 15:49     ` Will Deacon
2016-07-08 16:11       ` Chris Metcalf
2016-07-11 11:42       ` Will Deacon
2016-07-11 12:19         ` Mark Rutland
2016-07-29 18:16           ` Chris Metcalf
2016-08-09 10:21             ` Will Deacon
2016-04-05 17:38 ` [PATCH v12 13/13] arch/arm64: enable task isolation functionality Chris Metcalf
2016-05-12 18:26 ` [PATCH v12 00/13] support "task_isolation" mode Chris Metcalf

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=ff42f417-655f-199a-4200-d4a95f166cf8@mellanox.com \
    --to=cmetcalf@mellanox.com \
    --cc=akpm@linux-foundation.org \
    --cc=catalin.marinas@arm.com \
    --cc=cl@linux.com \
    --cc=fweisbec@gmail.com \
    --cc=giladb@ezchip.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=mingo@kernel.org \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=peterz@infradead.org \
    --cc=riel@redhat.com \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    --cc=tj@kernel.org \
    --cc=viresh.kumar@linaro.org \
    --cc=will.deacon@arm.com \
    /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®