From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753550AbcEWQqc (ORCPT ); Mon, 23 May 2016 12:46:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45465 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752992AbcEWQqa (ORCPT ); Mon, 23 May 2016 12:46:30 -0400 Date: Mon, 23 May 2016 11:46:28 -0500 From: Josh Poimboeuf To: Brian Gerst Cc: Andy Lutomirski , Thomas Gleixner , Denys Vlasenko , Ingo Molnar , "linux-kernel@vger.kernel.org" , Borislav Petkov , "H. Peter Anvin" , X86 ML , Dave Anderson Subject: Re: [PATCH 3/4] x86: Rewrite switch_to() code Message-ID: <20160523164628.tcb7ofbd3w4iq42a@treble> References: <1463846691-18498-1-git-send-email-brgerst@gmail.com> <1463846691-18498-4-git-send-email-brgerst@gmail.com> <20160523023414.laljasegs2cex5be@treble> <20160523114722.4nv3dpb2e5xr7ku7@treble> <20160523114903.fhmaqgiwod2vcvli@treble> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20160523114903.fhmaqgiwod2vcvli@treble> User-Agent: Mutt/1.6.0.1 (2016-04-01) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 23 May 2016 16:46:29 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, May 23, 2016 at 06:49:03AM -0500, Josh Poimboeuf wrote: > On Mon, May 23, 2016 at 06:47:22AM -0500, Josh Poimboeuf wrote: > > On Mon, May 23, 2016 at 07:14:14AM -0400, Brian Gerst wrote: > > > On Sun, May 22, 2016 at 10:34 PM, Josh Poimboeuf wrote: > > > > On Sun, May 22, 2016 at 10:59:38AM -0700, Andy Lutomirski wrote: > > > >> cc: Josh Poimboeuf: do you care about the exact stack layout of the > > > >> bottom of the stack of an inactive task? > > > > > > > > So there's one minor issue with this patch, relating to unwinding the > > > > stack of a newly forked task. For detecting reliable stacks, the > > > > unwinder needs to unwind all the way to the syscall pt_regs to make sure > > > > the stack is sane. But for newly forked tasks, that won't be possible > > > > here because the unwinding will stop at the fork_frame instead. > > > > > > > > So from an unwinder standpoint it might be nice for copy_thread_tls() to > > > > place a frame pointer on the stack next to the ret_from_fork return > > > > address, so that it would resemble an actual stack frame. The frame > > > > pointer could probably just be hard-coded to zero. And then the first > > > > bp in fork_frame would need to be a pointer to it instead of zero. That > > > > would make it nicely resemble the stack of any other task. > > > > > > > > Alternatively I could teach the unwinder that if the unwinding starts at > > > > the fork_frame offset from the end of the stack page, and the saved rbp > > > > is zero, it can assume that it's a newly forked task. But that seems a > > > > little more brittle to me, as it requires the unwinder to understand > > > > more of the internal workings of the fork code. > > > > > > > > But overall I think this patch is a really nice cleanup, and other than > > > > the above minor issue it should be fine with my reliable unwinder, since > > > > rbp is still at the top of the stack. > > > > > > Ok, how about if it pushed RBP first, then we teach get_wchan() to add > > > the fixed offset from thread.sp to get bp? that way it don't have to > > > push it twice. > > > > In theory I like the idea, and it would work: the unwinder could just > > use the inactive_task_frame struct (as Andy suggested) to find the frame > > pointer. > > > > But I suspect it would break all existing unwinders, both in-tree and > > out-of-tree. The only out-of-tree one I know of is crash, not sure if > > there are more out there. > > I should mention it would only affect those unwinders which know how to > do sleeping kernel tasks. So generic tools like gdb wouldn't be > affected. [continuing my conversation with myself...] To clarify, I still think we should do it. The stack format of a sleeping task isn't exactly an ABI, and I wouldn't expect many tools to rely on it. I can help with the fixing of in-tree unwinders if needed. Or I could even do the moving of the frame pointer as a separate patch on top of this one, since it might cause breakage elsewhere. Adding Dave Anderson (crash maintainer) to cc, as an FYI. -- Josh