[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20190528173228.GW2623@hirez.programming.kicks-ass.net>
Date: Tue, 28 May 2019 19:32:28 +0200
From: Peter Zijlstra <peterz@...radead.org>
To: Will Deacon <will.deacon@....com>
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
Subject: Re: [PATCH] perf: Fix oops when kthread execs user process
On Tue, May 28, 2019 at 04:32:24PM +0100, Will Deacon wrote:
> On Tue, May 28, 2019 at 04:01:03PM +0200, Peter Zijlstra wrote:
> > On Tue, May 28, 2019 at 08:31:29PM +0800, Young Xiao wrote:
> > > When a kthread calls call_usermodehelper() the steps are:
> > > 1. allocate current->mm
> > > 2. load_elf_binary()
> > > 3. populate current->thread.regs
> > >
> > > While doing this, interrupts are not disabled. If there is a perf
> > > interrupt in the middle of this process (i.e. step 1 has completed
> > > but not yet reached to step 3) and if perf tries to read userspace
> > > regs, kernel oops.
>
> This seems to be because pt_regs(current) gives NULL for kthreads on Power.
'funny' thing that, perf_sample_regs_user() seems to assume that
anything with current->mm is in fact a user task, and that assumption is
just plain wrong, consider use_mm().
So I'm thinking the right thing to do here is something like the below;
umh should get PF_KTHREAD cleared when it passes exec(). And this should
also fix the power splat I'm thinking.
---
diff --git a/kernel/events/core.c b/kernel/events/core.c
index abbd4b3b96c2..9929404b6eb9 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -5923,7 +5923,7 @@ static void perf_sample_regs_user(struct perf_regs *regs_user,
if (user_mode(regs)) {
regs_user->abi = perf_reg_abi(current);
regs_user->regs = regs;
- } else if (current->mm) {
+ } else if (!(current->flags & PF_KTHREAD) && current->mm) {
perf_get_regs_user(regs_user, regs, regs_user_copy);
} else {
regs_user->abi = PERF_SAMPLE_REGS_ABI_NONE;
Powered by blists - more mailing lists