From: Oleg Nesterov <oleg@redhat.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: "Ni, BaoleX" <baolex.ni@intel.com>,
"mingo@redhat.com" <mingo@redhat.com>,
"acme@kernel.org" <acme@kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"alexander.shishkin@linux.intel.com"
<alexander.shishkin@linux.intel.com>,
"Liu, Chuansheng" <chuansheng.liu@intel.com>
Subject: Re: hit a KASan bug related to Perf during stress test
Date: Wed, 26 Oct 2016 18:10:39 +0200 [thread overview]
Message-ID: <20161026161038.GB28832@redhat.com> (raw)
In-Reply-To: <20161026090332.GA3102@twins.programming.kicks-ass.net>
On 10/26, Peter Zijlstra wrote:
>
> On Tue, Oct 25, 2016 at 04:41:26PM +0200, Oleg Nesterov wrote:
> > >
> > > So what serialization would close that race? __task_pid_nr_ns() only
> > > seems to use RCU nothing more.
> >
> > I do not see how can we close this race, we obviously do not want to use
> > any locking.
> >
> > That is why I tried to suggest
> >
> > nr = __task_pid_nr_ns(p, type, event->ns);
> > if (!nr && !is_idle_task(p))
> > nr = -1;
> > return nr;
> >
> > but this will report -1 if p runs in another namespace, so perhaps we
> > can do
> >
> > nr = __task_pid_nr_ns(p, type, event->ns);
> > if (!nr && p->exit_state)
> > // it has already called exit_notify
> > nr = -1;
> > return nr;
>
> I think I'm asking how __task_pid_nr_ns() isn't susceptible to this race
> ;-)
which race ? ;) it seems that I confused you. Lets ignore the original
problem with perf_event_pid()->task_tgid_nr_ns() which can access the
freed memory. Lets suppose it is already fixed.
Another problem, as you noted, is that task_tgid_nr_ns/task_pid_nr_ns
returns zero if the task exits and this zero can be confused with the
swapper's pid.
return pid_alive(p) ? task_pid_nr_ns(p, event->ns) : ~0
still can return zero because pid_alive(p) == T is not stable if we can
race with the exiting task, so it can't guarantee that task_pid_nr_ns()
won't return 0.
So we can check ->exit_state or, even better, that same pid_alive() after
task_pid_nr_ns() returns 0.
nr = task_pid_nr_ns(p);
/* avoid -1 if it is idle thread or runs in another ns */
if (!nr && !pid_alive(p))
nr = -1;
return nr;
Or I misunderstood you?
Oleg.
next prev parent reply other threads:[~2016-10-26 16:12 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <318B87A793BE164187D8851D6CE09D64371C8811@shsmsx102.ccr.corp.intel.com>
2016-10-24 9:53 ` hit a KASan bug related to Perf during stress test Peter Zijlstra
2016-10-24 11:15 ` Oleg Nesterov
2016-10-24 11:24 ` Peter Zijlstra
2016-10-24 12:02 ` Oleg Nesterov
2016-10-24 12:10 ` Oleg Nesterov
2016-10-24 12:22 ` Peter Zijlstra
2016-10-24 12:29 ` Oleg Nesterov
2016-10-24 12:38 ` Peter Zijlstra
2016-10-24 13:25 ` Oleg Nesterov
2016-10-24 13:40 ` Oleg Nesterov
2016-10-24 14:17 ` Peter Zijlstra
2016-10-24 14:36 ` Peter Zijlstra
2016-10-24 15:39 ` Oleg Nesterov
2016-10-24 15:53 ` Oleg Nesterov
2016-10-25 6:55 ` Ni, BaoleX
2016-10-25 9:28 ` Peter Zijlstra
2016-10-25 14:41 ` Oleg Nesterov
2016-10-26 9:03 ` Peter Zijlstra
2016-10-26 16:10 ` Oleg Nesterov [this message]
2016-10-24 12:19 ` Peter Zijlstra
2016-10-24 11:27 ` Peter Zijlstra
2016-10-24 11:29 ` Peter Zijlstra
2016-10-24 12:04 ` Jiri Olsa
2016-10-24 12:12 ` Peter Zijlstra
2016-10-24 12:11 ` Peter Zijlstra
2016-10-24 12:21 ` Oleg Nesterov
2016-10-24 12:27 ` 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=20161026161038.GB28832@redhat.com \
--to=oleg@redhat.com \
--cc=acme@kernel.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=baolex.ni@intel.com \
--cc=chuansheng.liu@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.