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: 8285351 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 53176BEEE5 for ; Thu, 11 Feb 2016 22:17:49 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 60AE820380 for ; Thu, 11 Feb 2016 22:17:48 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8DD11202FE for ; Thu, 11 Feb 2016 22:17:27 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1aTzX8-0007Tw-37; Thu, 11 Feb 2016 22:16:18 +0000 Received: from mail-pf0-x22c.google.com ([2607:f8b0:400e:c00::22c]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aTzX3-0007OR-V0 for linux-arm-kernel@lists.infradead.org; Thu, 11 Feb 2016 22:16:14 +0000 Received: by mail-pf0-x22c.google.com with SMTP id e127so36173298pfe.3 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=AKQQRqbrwyr7Wx84wSh87EhFnZ00GZoJ+ayDz1zfmd2aO1ORqraKGfIaouPhGW2OsC en+hpBcS820t+RbxK3qcztapGa0uxZF/Clj0BLjAb6WUT/IJoyOSxq43zisIfo0i3M6R COgBqmDFzbOoJ+gSxe+zul/8tzLkQrBMasHy4ztKUkUHf+OafJEe10Eo1R2edZikaEPb YC2NKY2HlRODUU7Z0GeO5LrrqgFuNXjYVHcZK1APGp/3Tq2ZUkqBshoA8GtsrRx1/hb+ NoesYdzrlXVhTxHkhapcDUsRk9g4tk6bI1D5LtJDnTe2UaqSPdxmUMoqjv0wjkY9CsXj YeuQ== X-Gm-Message-State: AG10YOTcuqYjZ8hgGSF82zJj3Q2bWNW4ZkZNcwzosXoHjHaZHzN/0+u/ltnU/ygnyhiG4QlZ 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 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160211_141614_030791_056B6829 X-CRM114-Status: GOOD ( 12.79 ) X-Spam-Score: -2.7 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yang.shi@linaro.org, linaro-kernel@lists.linaro.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Acked-by: James Morse Tested-by: James Morse --- arch/arm64/kernel/stacktrace.c | 13 ++++++------- arch/arm64/kernel/traps.c | 11 ++++++++++- 2 files changed, 16 insertions(+), 8 deletions(-) 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)