Received: by 10.223.185.116 with SMTP id b49csp5160170wrg; Tue, 27 Feb 2018 08:41:57 -0800 (PST) X-Google-Smtp-Source: AG47ELuu6UC7LmRhvTFN4fbwLdkEiniP0u1Situ7t+/Dqp9GiJiY95dyt5VQgwf2FHVxkFiadii+ X-Received: by 2002:a17:902:b7cc:: with SMTP id v12-v6mr7434005plz.249.1519749717293; Tue, 27 Feb 2018 08:41:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519749717; cv=none; d=google.com; s=arc-20160816; b=cY3dqhobdhWsQU0H3sqQYcqXh8tOZROlJX2EDzIBJWcJqG+l+kMQIJCL0UuWrceUc9 2y1tje9nKJk6x27IIQTWglsJ1l9kU91OOAT/w+A+64Mp9/4AT5egFC+b402eSrKGRpwy QKumNi5dzWQZ8sOsdZ3G2cQ2emNlx2rmZyaqG4Me1nNLae2/pPIX0kH5xxqbvhkVoaqS WhBHqlxX7myE+bYL5av4Mc8ZDqhKxhYgULvUwoTyQKzZVCltDcLhoJ1iYJ5YgiAWV9Rm bpvhKlWAwfLUIvShEP+GF6MTPCdN5WlS4pq1bd6C3KZZ/d2dJkruMRyqFHcZ1j/qTlBV IEZQ== 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:arc-authentication-results; bh=anvoewmVIZjtRDrAkPFNg0i0TbdWVntwyxErSliYJSQ=; b=tZAFwO5cv1xuH4U3Ew4z+hT1MH9lNrdqmXibeCOWrQVBMykkYaTbtn2yWGrJbMoMbA L++eHA2sX1+j76RgHBZ+xS+69Oc+dWkB8bzjgLcapdfjNpTNR/fi4MJCshfJjomQ6VY3 BgDdyg/RMAvOGvrYTv7m0SIXho3suuo09pxXECxYc3b+OucBH/tNTJ6FVEOVq1iBHphF hoNhrldSaZ/JTmqULYJhVVYU9PFJBfEyRY13P35BXL1TCyUJPVWAuQd9VOpHf2wA565a KoZ3uxY4HI9NhNpTJOK8wr539hDm5Ugl59ZXG6uWtZCgxVIslWnErwWE4Q0sKxOlI2EO A4VA== 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 i7si7174666pgs.308.2018.02.27.08.41.42; Tue, 27 Feb 2018 08:41:57 -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; 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 S1752070AbeB0QJ1 (ORCPT + 99 others); Tue, 27 Feb 2018 11:09:27 -0500 Received: from verein.lst.de ([213.95.11.211]:49343 "EHLO newverein.lst.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751004AbeB0QJZ (ORCPT ); Tue, 27 Feb 2018 11:09:25 -0500 Received: by newverein.lst.de (Postfix, from userid 2005) id 3408E68DBB; Tue, 27 Feb 2018 17:09:24 +0100 (CET) Date: Tue, 27 Feb 2018 17:09:24 +0100 From: Torsten Duwe To: Miroslav Benes Cc: Michael Ellerman , Jiri Kosina , Balbir Singh , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, live-patching@vger.kernel.org Subject: [PATCH 2/2] ppc64le save_stack_trace_tsk_reliable (Was: HAVE_RELIABLE_STACKTRACE) Message-ID: <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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.17 (2007-11-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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) +{ + 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; + + 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 */