[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20190530072858.GB9955@brain-police>
Date: Thu, 30 May 2019 08:28:58 +0100
From: Will Deacon <will.deacon@....com>
To: Peter Zijlstra <peterz@...radead.org>
Cc: Young Xiao <92siuyang@...il.com>, linux@...linux.org.uk,
mark.rutland@....com, mingo@...hat.com, bp@...en8.de,
hpa@...or.com, x86@...nel.org, kan.liang@...ux.intel.com,
linux-arm-kernel@...ts.infradead.org, linux-kernel@...r.kernel.org,
ravi.bangoria@...ux.vnet.ibm.com, mpe@...erman.id.au,
acme@...hat.com, eranian@...gle.com, fweisbec@...il.com,
jolsa@...hat.com
Subject: Re: [PATCH] perf: Fix oops when kthread execs user process
On Wed, May 29, 2019 at 06:44:07PM +0200, Peter Zijlstra wrote:
> On Wed, May 29, 2019 at 05:25:28PM +0100, Will Deacon wrote:
>
> > > > > On Wed, May 29, 2019 at 02:05:21PM +0100, Will Deacon wrote:
> > > > > > On Wed, May 29, 2019 at 02:55:57PM +0200, Peter Zijlstra wrote:
> > > > >
> > > > > > > if (user_mode(regs)) {
> > > > > >
> > > > > > Hmm, so it just occurred to me that Mark's observation is that the regs
> > > > > > can be junk in some cases. In which case, should we be checking for
> > > > > > kthreads first?
>
> > Sorry, I'm not trying to catch you out! Just trying to understand what the
> > semantics are supposed to be.
> >
> > I do find the concept of user_mode(regs) bizarre for the idle task. By the
> > above, we definitely have a bug on arm64 (user_mode(regs) tends to be
> > true for the idle task), and I couldn't figure out how you avoided it on
> > x86. I guess it happens to work because the stack is zero-initialised or
> > something?
>
> So lets take the whole thing:
>
> static void perf_sample_regs_user(struct perf_regs *regs_user,
> struct pt_regs *regs,
> struct pt_regs *regs_user_copy)
> {
> if (user_mode(regs)) {
> regs_user->abi = perf_reg_abi(current);
> regs_user->regs = regs;
> } else if (!(current->flags & PF_KTHREAD)) {
> perf_get_regs_user(regs_user, regs, regs_user_copy);
> } else {
> regs_user->abi = PERF_SAMPLE_REGS_ABI_NONE;
> regs_user->regs = NULL;
> }
> }
>
> This is called from the perf-generate-a-sample path, which is typically
> an exception (IRQ/NMI/whatever) or a software/tracepoint thing.
Yes, sorry, fell into the same trap as Mark here and misunderstood your
assertion about user_mode(regs) always needing to be valid. Then I went down
a stupid rabbit hole and dragged you with me. I can't ack a patch twice, so
I'll just go do something else for a bit...
Thanks for your patience!
Will
Powered by blists - more mailing lists