Received: by 10.223.185.116 with SMTP id b49csp106633wrg; Thu, 8 Mar 2018 13:45:26 -0800 (PST) X-Google-Smtp-Source: AG47ELscj8bbB8zsGCGjQifaHhC4O2THHKD5m6hyyIWN0pXYHqongNhxiZF51gcl+RMI4CDN/RSO X-Received: by 10.101.96.73 with SMTP id b9mr22419536pgv.339.1520545526800; Thu, 08 Mar 2018 13:45:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520545526; cv=none; d=google.com; s=arc-20160816; b=bU2a+V1CLps7Eml9Wd5J1JzJqm+EE+vMUUO0qn/gaU7fV/aJ+34zdgwXKaixq4mlsL j3kG3qKjFhbrCXIWuikAF+39bdoLjCruPUzB4InT6Cbk81nHTB8Bl3Aq0J3TVc1q0ltl 5wOaq8ufEa1/NIrtREJZAo///emDWXIIvovhDA/s5lL8/fukJuL8vn2V1ZDoBj/Dj5Bj aQwOOVvri+HnHl374CsajaqQRaRU1uXGX+EQ6O6RmBiAZp8LikC0MqD3JUr2NdK6eyi/ cvb8/6MYVYb+rB5HL0C/FLBCwhXJXY3cNhXLbeGxRhUvfryEYUz0vcmnRwO/Nm8iaDjW gYhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature:arc-authentication-results; bh=HX32U36Ep3nIg3lfGxPdvrKVAHH9vdSYtXL5rt9xTKE=; b=VImSPT/Xs6SEivblQUojhcqQ2AiNlYnu7CA5FX8MuwC1FpAkqsQtLX5+zRN+dVHvdR Ow7yP8bEmgJMkUSZxUZ7Zw2ZjBqZXdDhwJpeOO8yq0bMMqi7vZB4QSsg1Dpm7weWrR6j LBXNV9ojn1XsrhbD0pBHJIMnF5Lmwaw5kLw0j13fL7wFq27ZmhsAvjGkhRW8D5e+7f8g +vRbB6bwnkQHPjct4SYgCVmLzAVUjbkvG+/b3t/TV5xo61QXFVBuQWOw9My/7VWPvkCH uRKWBD0UPAuKiWY8/nwxfkc+Ol8hsVD+N5mS+bHU7D/rVvqrXi5ffVeoiK/dxdAIiUoM TeyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=hIe4FSX/; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u188si13592658pgb.648.2018.03.08.13.45.12; Thu, 08 Mar 2018 13:45:26 -0800 (PST) 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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=hIe4FSX/; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751244AbeCHVnv (ORCPT + 99 others); Thu, 8 Mar 2018 16:43:51 -0500 Received: from mail-pf0-f195.google.com ([209.85.192.195]:45436 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750792AbeCHVnt (ORCPT ); Thu, 8 Mar 2018 16:43:49 -0500 Received: by mail-pf0-f195.google.com with SMTP id h19so443730pfd.12; Thu, 08 Mar 2018 13:43:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=HX32U36Ep3nIg3lfGxPdvrKVAHH9vdSYtXL5rt9xTKE=; b=hIe4FSX/rRgBDBG1oUlHM7VnMBvBZFaZU3WFWkny9aVlcREO5WXGDlkv8OqJk8IyDr y88Db3IBoFkpGjdII1O1qm82cejNPPmYto4swcYEB0fhKq6D2oHJoh74xgo/6Msh09Cl T0FVtKBLFcG5v4LqeYRvhJb4ZmyEvgBuyezIaopbXDMROSxRdG+/ZOmCSuwJMJogE3CW PN5n/uRnXY/h/mx3rDXyEjqQNohoUaOpYWG1E3Da9pPAV/vSNHUGs7VcHQK9jM3cwpr1 eN1Iz80Mhm/Y6tQ4AzmAvoZmLtdvQClchvExwyDDypv+p71mw/a083c8Vo+3Kt532Thu Owtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HX32U36Ep3nIg3lfGxPdvrKVAHH9vdSYtXL5rt9xTKE=; b=XGorulNHWr7LMCo/LSCzf3Xo6c4QOrqfbZKSSZOkptTqAt7k5jcOEudI0O3BzBRCbK kWeDAo0AACKe1iZWjndABGtqv0D5SZzTj2YkHrC4ht4Ef+3Q8fwy+WDlXiYml3r/gLEG 4tK6IdZw+HTOYy8Mbb8mAUwOYDObp8pjr3x2ygMQXR6JDMHs3URL3KWW1/LiwfBmp+1I GlKOQLIunYkej77ZAh+236MV57cRPshAcfSnYg5TJnRyvMNCGeF70KTNBYVwgPQcE7m0 6djMKG9SWEacTDmkyrHQTPAZ6o8FcA4KCsvBdUrSmAcbWv96+kMyIRsMmad3eNgaV2pf c26g== X-Gm-Message-State: APf1xPAIoDSWcXqa+AZuU+dg/BEu2rudyOheGJZeVk6PqbH5Aa8xkjcq lpGizcr39IEWEvr7BDbhbV5dlCmG X-Received: by 10.99.120.193 with SMTP id t184mr22706243pgc.348.1520545428733; Thu, 08 Mar 2018 13:43:48 -0800 (PST) Received: from localhost ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id q67sm46530477pfg.180.2018.03.08.13.43.45 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 08 Mar 2018 13:43:48 -0800 (PST) Date: Fri, 9 Mar 2018 08:43:33 +1100 From: Balbir Singh To: Torsten Duwe Cc: Miroslav Benes , Michael Ellerman , Jiri Kosina , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, live-patching@vger.kernel.org Subject: Re: [PATCH 2/2] ppc64le save_stack_trace_tsk_reliable (Was: HAVE_RELIABLE_STACKTRACE) Message-ID: <20180309084333.23287074@gmail.com> In-Reply-To: <20180227160924.GA19111@lst.de> References: <20171004152516.25803-1-kamalesh@linux.vnet.ibm.com> <20171005124313.GA25100@lst.de> <9f388c9a-8d74-865a-b113-f77322918b39@linux.vnet.ibm.com> <20171017144733.GB2136@lst.de> <95e6f942-88b7-0208-0eb0-2f5462aec410@linux.vnet.ibm.com> <20171020120739.GA20306@lst.de> <1508547548.5662.2.camel@gmail.com> <39bb7180-1adf-4df6-c9ba-c6f92754767f@linux.vnet.ibm.com> <20171212113912.GA1907@lst.de> <20180227160924.GA19111@lst.de> X-Mailer: Claws Mail 3.15.1-dirty (GTK+ 2.24.31; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 27 Feb 2018 17:09:24 +0100 Torsten Duwe wrote: > On Tue, Dec 12, 2017 at 01:12:37PM +0100, Miroslav Benes wrote: > > > > I think that this is not enough. You need to also implement > > save_stack_trace_tsk_reliable() for powerpc defined as __weak in > > kernel/stacktrace.c. > > So here is my initial proposal. I'd really like to get the successful > exit stricter, i.e. hit the initial stack value exactly instead of just > a window. Also, the check for kernel code looks clumsy IMHO. IOW: > Comments more than welcome! > > Most of it is Copy&Waste, nonetheless: :) > > Signed-off-by: Torsten Duwe > > > diff --git a/arch/powerpc/kernel/stacktrace.c b/arch/powerpc/kernel/stacktrace.c > index d534ed901538..e08af49e71d0 100644 > --- a/arch/powerpc/kernel/stacktrace.c > +++ b/arch/powerpc/kernel/stacktrace.c > @@ -13,6 +13,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -76,3 +77,58 @@ save_stack_trace_regs(struct pt_regs *regs, struct stack_trace *trace) > save_context_stack(trace, regs->gpr[1], current, 0); > } > EXPORT_SYMBOL_GPL(save_stack_trace_regs); > + > +#ifdef CONFIG_HAVE_RELIABLE_STACKTRACE > +int > +save_stack_trace_tsk_reliable(struct task_struct *tsk, > + struct stack_trace *trace) Just double checking this is called under the task_rq_lock, so its safe to call task_stack_page() as opposed to try_get_task_stack() > +{ > + unsigned long sp; > + unsigned long stack_page = (unsigned long)task_stack_page(tsk); > + /* the last frame (unwinding first) may not yet have saved its LR onto the stack. */ > + int firstframe = 1; > + > + if (tsk == current) > + sp = current_stack_pointer(); > + else > + sp = tsk->thread.ksp; > + > + if (sp < stack_page + sizeof(struct thread_struct) > + || sp > stack_page + THREAD_SIZE - STACK_FRAME_OVERHEAD) > + return 1; Some of this is already present in validate_sp(), it also validates irq stacks, should we just reuse that? > + > + for (;;) { > + unsigned long *stack = (unsigned long *) sp; > + unsigned long newsp, ip; > + > + newsp = stack[0]; > + /* Stack grows downwards; unwinder may only go up */ > + if (newsp <= sp) > + return 1; > + > + if (newsp >= stack_page + THREAD_SIZE) > + return 1; /* invalid backlink, too far up! */ > + > + /* Examine the saved LR: it must point into kernel code. */ > + ip = stack[STACK_FRAME_LR_SAVE]; > + if ( (ip & 0xEFFF000000000000) != CONFIG_KERNEL_START > + && !firstframe) > + return 1; > + firstframe = 0; > + > + if (!trace->skip) > + trace->entries[trace->nr_entries++] = ip; > + else > + trace->skip--; > + > + if (newsp > stack_page + THREAD_SIZE - STACK_FRAME_OVERHEAD) > + break; /* hit the window for last frame */ > + > + if (trace->nr_entries >= trace->max_entries) > + return -E2BIG; > + > + sp = newsp; > + } > + return 0; > +} > +#endif /* CONFIG_HAVE_RELIABLE_STACKTRACE */ > Looks good to me otherwise. Acked-by: Balbir Singh