Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp426598ybi; Thu, 30 May 2019 00:30:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqznbR+UblIUsv4dy2xlc5T0gG/ka1BKq8MtSvCgMtYPVI8DImHMZA03ZamB+ryIwcjcPbTH X-Received: by 2002:a05:6a00:c9:: with SMTP id e9mr2244031pfj.99.1559201440116; Thu, 30 May 2019 00:30:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559201440; cv=none; d=google.com; s=arc-20160816; b=Mwc7aPsfO9yKbWc1vXYW5A0DA/zudxLprOgdB+Xzh9H8EYc28sCI5qklpDUVTTrxeD XUp7gCQvFY+CwgFYtVS4aEntUQyEXbv8VOF+AmIRigC8EYDKRGA9iVLLJkS8mD4ObhGY dGlNnwyk96p2bJy+NphR5ykH6A6eYELAVYPNMQvUOXoZHMIJPVQrguYoc/QD28FUzXAG qz6FySpS3fBvO5aLYblM6aqg1pwWV6uhJIG/CXaqPZE0coxpp7kYqpPpHOQxsAtWZxVl j6fj14AvsiGC2pFW48kmJ63KQmrqDfned7xvVuGjX4YW1Zs/sPvSKbTO+L9M7l6tGUxU j/Uw== 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=B+1hlkJOUO38Kg6dL8Xn/4UYNahxxZC8bEa10mN6dcg=; b=Lvy4Ov5Li+ESfglzhAJXD/2JBT+wmrPsQP1weOODiRJNXMnquw4XROAt3LRY4OFZ91 Hw/Xlu83GBNWMgmsbl6BYiYa+BvYiWTtHaD5y+1QtreasB7ge/TFeeAWI4oLKJ18SuKd QASAHPSwOsQnM0bxe4Nkt1gSK9vwBIBdXdd8aceofCWSgHWT5rMBTOrguTZoxJKuuDzP HBQFuQI09buUdWXeFxNXpdDN6wuRf1jGi18dZPWvAnwIHqVW2GTZylI5+LLY5+8B+yUA ap/mhCjkv+clXKklAliXHmgxxD2yJHthLiA+EhfLQSjP8vWplax2HWaCOBTaIDvedxi6 kHAQ== 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 b129si2643903pfa.254.2019.05.30.00.30.21; Thu, 30 May 2019 00:30:40 -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 S1726688AbfE3H3H (ORCPT + 99 others); Thu, 30 May 2019 03:29:07 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:60002 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726027AbfE3H3H (ORCPT ); Thu, 30 May 2019 03:29:07 -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 E1D4BA78; Thu, 30 May 2019 00:29:05 -0700 (PDT) Received: from brain-police (usa-sjc-mx-foss1.foss.arm.com [217.140.101.70]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id F00F53F690; Thu, 30 May 2019 00:29:01 -0700 (PDT) Date: Thu, 30 May 2019 08:28:58 +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, acme@redhat.com, eranian@google.com, fweisbec@gmail.com, jolsa@redhat.com Subject: Re: [PATCH] perf: Fix oops when kthread execs user process Message-ID: <20190530072858.GB9955@brain-police> References: <20190529091733.GA4485@fuggles.cambridge.arm.com> <20190529101042.GN2623@hirez.programming.kicks-ass.net> <20190529102022.GC4485@fuggles.cambridge.arm.com> <20190529125557.GU2623@hirez.programming.kicks-ass.net> <20190529130521.GA11023@fuggles.cambridge.arm.com> <20190529132515.GW2623@hirez.programming.kicks-ass.net> <20190529143510.GA11154@fuggles.cambridge.arm.com> <20190529161955.GZ2623@hirez.programming.kicks-ass.net> <20190529162528.GB12420@fuggles.cambridge.arm.com> <20190529164407.GA2623@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190529164407.GA2623@hirez.programming.kicks-ass.net> User-Agent: Mutt/1.9.4 (2018-02-28) 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 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