From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752417AbdC0UJu (ORCPT ); Mon, 27 Mar 2017 16:09:50 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:54822 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751683AbdC0UJo (ORCPT ); Mon, 27 Mar 2017 16:09:44 -0400 From: Thadeu Lima de Souza Cascardo To: linuxppc-dev@lists.ozlabs.org Cc: linux-kernel@vger.kernel.org, Paul Mackerras , Benjamin Herrenschmidt , Michael Ellerman Subject: [PATCH v2] powerpc: make /proc/self/stack always print the current stack Date: Mon, 27 Mar 2017 16:32:33 -0300 Message-Id: <20170327193233.25147-1-cascardo@canonical.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170317155921.24369-1-cascardo@canonical.com> References: <20170317155921.24369-1-cascardo@canonical.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For the current task, the kernel stack would only tell the last time the process was rescheduled, if ever. Use the current stack pointer for the current task. Otherwise, every once in a while, the stacktrace printed when reading /proc/self/stack would look like the process is running in userspace, while it's not, which some may consider as a bug. This is also consistent with some other architectures, like x86 and arm, at least. Signed-off-by: Thadeu Lima de Souza Cascardo --- arch/powerpc/kernel/stacktrace.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/kernel/stacktrace.c b/arch/powerpc/kernel/stacktrace.c index 6671195..d534ed9 100644 --- a/arch/powerpc/kernel/stacktrace.c +++ b/arch/powerpc/kernel/stacktrace.c @@ -59,7 +59,14 @@ EXPORT_SYMBOL_GPL(save_stack_trace); void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace) { - save_context_stack(trace, tsk->thread.ksp, tsk, 0); + unsigned long sp; + + if (tsk == current) + sp = current_stack_pointer(); + else + sp = tsk->thread.ksp; + + save_context_stack(trace, sp, tsk, 0); } EXPORT_SYMBOL_GPL(save_stack_trace_tsk); -- 2.9.3