linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Will Deacon <will.deacon@arm.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Young Xiao <92siuyang@gmail.com>,
	linux@armlinux.org.uk, mark.rutland@arm.com, mingo@redhat.com,
	bp@alien8.de, hpa@zytor.com, x86@kernel.org,
	kan.liang@linux.intel.com, linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, ravi.bangoria@linux.vnet.ibm.com,
	mpe@ellerman.id.au
Subject: Re: [PATCH] perf: Fix oops when kthread execs user process
Date: Wed, 29 May 2019 11:20:22 +0100	[thread overview]
Message-ID: <20190529102022.GC4485@fuggles.cambridge.arm.com> (raw)
In-Reply-To: <20190529101042.GN2623@hirez.programming.kicks-ass.net>

On Wed, May 29, 2019 at 12:10:42PM +0200, Peter Zijlstra wrote:
> On Wed, May 29, 2019 at 10:17:33AM +0100, Will Deacon wrote:
> > On Tue, May 28, 2019 at 07:32:28PM +0200, Peter Zijlstra wrote:
> 
> > > '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().
> > 
> > Right, I suppose that was attempting to handle interrupt skid from the PMU
> > overflow?
> 
> Nah, just a broken test to determine if there is userspace at all. It is
> mostly right, just not completely :-)
> 
> > > 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);
> > 
> > Makes sense, but under which circumstances would we have a NULL mm here?
> 
> Dunno; I'm paranoid, and also:
> 
>   mm/memcontrol.c:        if (in_interrupt() || !current->mm || (current->flags & PF_KTHREAD))

So this one I also don't understand...

>   mm/vmacache.c:  return current->mm == mm && !(current->flags & PF_KTHREAD);

... but this one is just about an mm mismatch, rather than a NULL mm.

Anyway, you can add my ack to your patch, but I bet we can remove that mm
check :D

Will

  reply	other threads:[~2019-05-29 10:20 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-28 12:31 [PATCH] perf: Fix oops when kthread execs user process Young Xiao
2019-05-28 12:41 ` Russell King - ARM Linux admin
2019-05-28 14:01 ` Peter Zijlstra
2019-05-28 15:32   ` Will Deacon
2019-05-28 16:12     ` Mark Rutland
2019-05-28 17:32     ` Peter Zijlstra
2019-05-29  9:17       ` Will Deacon
2019-05-29 10:10         ` Peter Zijlstra
2019-05-29 10:20           ` Will Deacon [this message]
2019-05-29 12:55             ` Peter Zijlstra
2019-05-29 13:05               ` Will Deacon
2019-05-29 13:25                 ` Peter Zijlstra
2019-05-29 14:35                   ` Will Deacon
2019-05-29 16:19                     ` Peter Zijlstra
2019-05-29 16:24                       ` Mark Rutland
2019-05-29 16:38                         ` Mark Rutland
2019-05-29 17:03                           ` Peter Zijlstra
2019-05-30 10:35                             ` Mark Rutland
2019-05-29 16:25                       ` Will Deacon
2019-05-29 16:44                         ` Peter Zijlstra
2019-05-30  7:28                           ` Will Deacon
2019-05-30  8:38               ` Ravi Bangoria
2019-05-30 10:27                 ` Ravi Bangoria
2019-05-31 15:37                   ` Will Deacon
2019-06-03 11:23                     ` Will Deacon
2019-06-03 11:48                     ` Peter Zijlstra
2019-06-03 13:30                     ` Michael Ellerman
2019-05-29 10:11       ` Mark Rutland
2019-05-29  4:21     ` Michael Ellerman
2019-05-29  1:44   ` Michael Ellerman

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=20190529102022.GC4485@fuggles.cambridge.arm.com \
    --to=will.deacon@arm.com \
    --cc=92siuyang@gmail.com \
    --cc=bp@alien8.de \
    --cc=hpa@zytor.com \
    --cc=kan.liang@linux.intel.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=mpe@ellerman.id.au \
    --cc=peterz@infradead.org \
    --cc=ravi.bangoria@linux.vnet.ibm.com \
    --cc=x86@kernel.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;
as well as URLs for NNTP newsgroup(s).