Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp6131535ybi; Wed, 29 May 2019 03:22:19 -0700 (PDT) X-Google-Smtp-Source: APXvYqy9DHuieDzPpbae6Z90kTcIZsklsVcFCGa08NNx7f/sWaLwN0PxcecgMps6U58D+dyr3zIy X-Received: by 2002:a17:902:2aab:: with SMTP id j40mr117533934plb.238.1559125339460; Wed, 29 May 2019 03:22:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559125339; cv=none; d=google.com; s=arc-20160816; b=qwzk2VC90p/2PeO0e3wMqYf8EyQmMX5plI0heS0rakMTixJCv5bq/F0WzvsICgUDVJ guiHShsfhRgiaf1Ngj0y3yvbM45f/oP6A3WxbITyb83UC11+dR+cSG1+HCIIPF3mEkEW UHPOrO7z4A+bL3v3hah5w00YxsRrRbwgrEYsxAYlqyO+fCCrDAfxjEjb853P9y4CIZqu hj1CE14z41aRu0P6xCNf59KwS1CNBaR3s7Fm+FtFsvL6Zid8YJEk0P3s4/n0AuAUkC0+ CcvH49jAOdqd6YwR6gt+31VU125c1EDS5S4tsfXgJwyruzcQgbV1PyVdnqaSi+Gt9shJ S0/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=hHd6b8pyaC7pd7Y72Y4isXENplGLT9CZLMGz7qeBjWk=; b=ANhLgk4/9L2gNYGVYY+nGg78DKDvIn2j6BKLnxcUnEphXxp064xuNMWJpm5fXjUhXR R//4V68+TtMI/busIO9oPTsQTerqTTmaxO1Gs5nV3v42t0FC+2EgpTU3msGHaqxhxoVN PQq8PpqVFdRIb+4jeGNodSJaD/xZc2IKhp3G7e7dxa2esEjesV/1ykq9oXX8HffGZDuo rR775fHdDikCar7AumLWcF1z3zKhzoHKmkNdJTDir6Vz5dglNQBz1j6gTQNAVrL4lrC5 oroasYo5lTKTUdOC+xjL3P4Z31P5jTufoVUk0Il83SIHJ/owM7lQkhXVaR3O6o4I4RvJ xkaQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j18si2482756pff.269.2019.05.29.03.22.03; Wed, 29 May 2019 03:22:19 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726744AbfE2KU2 (ORCPT + 99 others); Wed, 29 May 2019 06:20:28 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:42778 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726254AbfE2KU1 (ORCPT ); Wed, 29 May 2019 06:20:27 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 31E86341; Wed, 29 May 2019 03:20:27 -0700 (PDT) Received: from fuggles.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id ED5933F59C; Wed, 29 May 2019 03:20:24 -0700 (PDT) Date: Wed, 29 May 2019 11:20:22 +0100 From: Will Deacon To: Peter Zijlstra 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 Message-ID: <20190529102022.GC4485@fuggles.cambridge.arm.com> References: <1559046689-24091-1-git-send-email-92siuyang@gmail.com> <20190528140103.GT2623@hirez.programming.kicks-ass.net> <20190528153224.GE20758@fuggles.cambridge.arm.com> <20190528173228.GW2623@hirez.programming.kicks-ass.net> <20190529091733.GA4485@fuggles.cambridge.arm.com> <20190529101042.GN2623@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190529101042.GN2623@hirez.programming.kicks-ass.net> User-Agent: Mutt/1.11.1+86 (6f28e57d73f2) () Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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