From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
To: Oleg Nesterov <oleg@redhat.com>
Cc: linux-kernel@vger.kernel.org, Ben Segall <bsegall@google.com>,
Daniel Bristot de Oliveira <bristot@redhat.com>,
Dietmar Eggemann <dietmar.eggemann@arm.com>,
Ingo Molnar <mingo@redhat.com>,
Juri Lelli <juri.lelli@redhat.com>, Mel Gorman <mgorman@suse.de>,
Peter Zijlstra <peterz@infradead.org>,
Steven Rostedt <rostedt@goodmis.org>,
Thomas Gleixner <tglx@linutronix.de>,
Vincent Guittot <vincent.guittot@linaro.org>
Subject: Re: [PATCH] ptrace: fix ptrace vs tasklist_lock race on PREEMPT_RT.
Date: Wed, 16 Mar 2022 09:23:19 +0100 [thread overview]
Message-ID: <YjGed4pvP1RM9liz@linutronix.de> (raw)
In-Reply-To: <20220315142944.GA22670@redhat.com>
On 2022-03-15 15:29:46 [+0100], Oleg Nesterov wrote:
> > > > --- a/kernel/sched/core.c
> > > > +++ b/kernel/sched/core.c
> > > > @@ -3239,7 +3239,8 @@ unsigned long wait_task_inactive(struct task_struct *p, unsigned int match_state
> > > > * is actually now running somewhere else!
> > > > */
> > > > while (task_running(rq, p)) {
> > > > - if (match_state && unlikely(READ_ONCE(p->__state) != match_state))
> > > > + if (match_state &&
> > > > + unlikely(!task_state_match_eq(p, match_state)))
> > > > return 0;
> > >
> > > So wait_task_inactive() can return 0 but the task can run after that, right?
> > > This is not what we want...
> >
> > Without checking both states you may never observe the requested state
> > because it is set to TASK_RTLOCK_WAIT while waiting for a lock. Other
> > than that, it may run briefly because it tries to acquire a lock or just
> > acquired and this shouldn't be different from a task spinning on a lock.
>
> I don't understand. wait_task_inactive() is used to ensure that this task
> doesn't and can't run again, until debugger resumes these tracee.
>
> Now. Unless I missed something, the tracee can leave CPU with saved_state
> = TRACED (so task_state_match_eq() returns T) and wait_task_inactive() will
> return. Then later the tracee will park in schedule again, yes.
>
> But, for example, what if debugger clears TIF_BLOCKSTEP in between, while
> the tracee is running? Can't this race with __switch_to_xtra() ?
If you describe like that, then it appears better to only look at
->state. Otherwise, yes, you would see the expected state in
->saved_state and the task might still be on the CPU. Even if it is not
actually running/ on the runqueue, it could be the case if the lock has
been made available shortly after.
> Oleg.
Sebastian
next prev parent reply other threads:[~2022-03-16 8:23 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-02 21:04 [PATCH] ptrace: fix ptrace vs tasklist_lock race on PREEMPT_RT Sebastian Andrzej Siewior
2022-03-14 9:27 ` Sebastian Andrzej Siewior
2022-03-14 18:54 ` Oleg Nesterov
2022-03-15 8:31 ` Sebastian Andrzej Siewior
2022-03-15 14:29 ` Oleg Nesterov
2022-03-16 8:23 ` Sebastian Andrzej Siewior [this message]
2022-03-31 14:25 ` [PATCH v2] " Sebastian Andrzej Siewior
2022-04-04 16:13 ` Oleg Nesterov
2022-04-05 8:34 ` Oleg Nesterov
2022-04-05 10:10 ` Peter Zijlstra
2022-04-05 10:29 ` Oleg Nesterov
2022-04-05 11:28 ` Peter Zijlstra
2022-04-07 12:13 ` Peter Zijlstra
2022-04-07 17:51 ` Eric W. Biederman
2022-04-07 22:50 ` Eric W. Biederman
2022-04-08 9:09 ` Peter Zijlstra
2022-04-08 19:40 ` Eric W. Biederman
2022-04-08 20:06 ` Peter Zijlstra
2022-04-11 11:35 ` Peter Zijlstra
2022-04-11 13:44 ` Eric W. Biederman
2022-04-11 17:07 ` Peter Zijlstra
2022-04-12 11:59 ` 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=YjGed4pvP1RM9liz@linutronix.de \
--to=bigeasy@linutronix.de \
--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=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=oleg@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
--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