From patchwork Thu Feb 11 21:53:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 61811 Delivered-To: patch@linaro.org Received: by 10.112.43.199 with SMTP id y7csp470647lbl; Thu, 11 Feb 2016 14:15:56 -0800 (PST) X-Received: by 10.66.142.200 with SMTP id ry8mr15952193pab.11.1455228956767; Thu, 11 Feb 2016 14:15:56 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y77si15081711pfa.187.2016.02.11.14.15.56; Thu, 11 Feb 2016 14:15:56 -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; dkim=pass header.i=@linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751897AbcBKWPy (ORCPT + 30 others); Thu, 11 Feb 2016 17:15:54 -0500 Received: from mail-pf0-f181.google.com ([209.85.192.181]:35449 "EHLO mail-pf0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751493AbcBKWPx (ORCPT ); Thu, 11 Feb 2016 17:15:53 -0500 Received: by mail-pf0-f181.google.com with SMTP id c10so36703203pfc.2 for ; Thu, 11 Feb 2016 14:15:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=R2oro1u0ve8FDvoMPzGEWnO6IHn1d04Bheri6fUIVQA=; b=G6rqp5ToiTFljjJ2qOlBgLpqIEA0vO4FX2KURy7MTd8+3mTsMvOZuuSOsUNO/SMfpm N1POO0/3h4tkloB6xul6EPN/ZkkT0JoUbWtgj/QtnntH02YO0FqNm5M6MsEmU4+F7hbP eAfBPpRmaL/8ewRYBWg0WcV1ZXUrCgQYulvh8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=R2oro1u0ve8FDvoMPzGEWnO6IHn1d04Bheri6fUIVQA=; b=bNaWz22UzFFBk4aSl1V3Cl+cYpm2dgVcUVL0fP195jHullzhQG/CW/fBwcl8UDu4h1 Pe4XRDlrAZYj+7i/0P/edPP40GR4362FxKVEOme3BIqwIKl2XzFrg6fAzmVqdOLE3r5Z zKwI5Fj4dNNLK6MJNnmFXYEc3mXIYKc0tbQJgZ6bwtKH7KcAHOorsz/ZanU4ZsG8Gudr kE67R3xcxwmZUlnfkiOTwyKY/PgXcrkLEtZ3E6wSioMe1OmoDKZXyifRbskokvLIuWId usCgbQQInqlxtubNYTwDy8I3ueqZ3AFHa7np1TiqqNAMQ+Zjmxhz34e+ncGHANoNbpfu 5Bxw== X-Gm-Message-State: AG10YORhAjuDsuUmtht+vvZCkEVJIKZufNCf1O3qZMBp9dF4t6iN1QHqP4bQ4ANhTJy3MNf7 X-Received: by 10.98.14.146 with SMTP id 18mr52673087pfo.35.1455228953057; Thu, 11 Feb 2016 14:15:53 -0800 (PST) Received: from yshi-Precision-T5600.corp.ad.wrs.com (unknown-216-82.windriver.com. [147.11.216.82]) by smtp.gmail.com with ESMTPSA id p8sm14510857pfi.34.2016.02.11.14.15.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Feb 2016 14:15:52 -0800 (PST) From: Yang Shi To: will.deacon@arm.com, catalin.marinas@arm.com, james.morse@arm.com Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linaro-kernel@lists.linaro.org, yang.shi@linaro.org Subject: [PATCH] arm64: make irq_stack_ptr more robust Date: Thu, 11 Feb 2016 13:53:10 -0800 Message-Id: <1455227590-9837-1-git-send-email-yang.shi@linaro.org> X-Mailer: git-send-email 2.0.2 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Switching between stacks is only valid if we are tracing ourselves while on the irq_stack, so it is only valid when in current and non-preemptible context, otherwise is is just zeroed off. Signed-off-by: Yang Shi --- arch/arm64/kernel/stacktrace.c | 13 ++++++------- arch/arm64/kernel/traps.c | 11 ++++++++++- 2 files changed, 16 insertions(+), 8 deletions(-) -- 2.0.2 diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c index 12a18cb..d9751a4 100644 --- a/arch/arm64/kernel/stacktrace.c +++ b/arch/arm64/kernel/stacktrace.c @@ -44,14 +44,13 @@ int notrace unwind_frame(struct task_struct *tsk, struct stackframe *frame) unsigned long irq_stack_ptr; /* - * Use raw_smp_processor_id() to avoid false-positives from - * CONFIG_DEBUG_PREEMPT. get_wchan() calls unwind_frame() on sleeping - * task stacks, we can be pre-empted in this case, so - * {raw_,}smp_processor_id() may give us the wrong value. Sleeping - * tasks can't ever be on an interrupt stack, so regardless of cpu, - * the checks will always fail. + * Switching between stacks is valid when tracing current and in + * non-preemptible context. */ - irq_stack_ptr = IRQ_STACK_PTR(raw_smp_processor_id()); + if (tsk == current && !preemptible()) + irq_stack_ptr = IRQ_STACK_PTR(smp_processor_id()); + else + irq_stack_ptr = 0; low = frame->sp; /* irq stacks are not THREAD_SIZE aligned */ diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c index cbedd72..7d8db3a 100644 --- a/arch/arm64/kernel/traps.c +++ b/arch/arm64/kernel/traps.c @@ -146,9 +146,18 @@ static void dump_instr(const char *lvl, struct pt_regs *regs) static void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk) { struct stackframe frame; - unsigned long irq_stack_ptr = IRQ_STACK_PTR(smp_processor_id()); + unsigned long irq_stack_ptr; int skip; + /* + * Switching between stacks is valid when tracing current and in + * non-preemptible context. + */ + if (tsk == current && !preemptible()) + irq_stack_ptr = IRQ_STACK_PTR(smp_processor_id()); + else + irq_stack_ptr = 0; + pr_debug("%s(regs = %p tsk = %p)\n", __func__, regs, tsk); if (!tsk)