From patchwork Fri Sep 23 07:33:27 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 76830 Delivered-To: patch@linaro.org Received: by 10.140.106.72 with SMTP id d66csp425317qgf; Fri, 23 Sep 2016 00:27:15 -0700 (PDT) X-Received: by 10.66.190.38 with SMTP id gn6mr10290938pac.8.1474615635511; Fri, 23 Sep 2016 00:27:15 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id sq10si6552364pab.73.2016.09.23.00.27.15; Fri, 23 Sep 2016 00:27:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965152AbcIWH1O (ORCPT + 3 others); Fri, 23 Sep 2016 03:27:14 -0400 Received: from mail-pa0-f45.google.com ([209.85.220.45]:35787 "EHLO mail-pa0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965025AbcIWH1O (ORCPT ); Fri, 23 Sep 2016 03:27:14 -0400 Received: by mail-pa0-f45.google.com with SMTP id oz2so37595225pac.2 for ; Fri, 23 Sep 2016 00:27:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=1Ln+FYofFP/zzTYRGxSL2McSlN+El+cJddFUD4wXKjI=; b=Mra3h4Hq1ra23QEEUU2m/J/bBGi9MqYm2BcJIa1YrDf9fyTpELoHr7//nOTZCBslEb gxX9IcEj+VJENbuGE1fPDQzkDkYEf61lacFOY9UMEKnDVKUUInM2cBDV8TVBfTAcI0PL /wDQBxgfvB4HKpQBkPQ6oeDxWlQbImVlwswSc= 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:in-reply-to :references; bh=1Ln+FYofFP/zzTYRGxSL2McSlN+El+cJddFUD4wXKjI=; b=URBPQtPw0IRFD5PufpkpSz5XmMkUd/fqth4JDJ4XBbBxCt0BZeBJk9F8suOCTmljfo m/VnnIzZc37PSx0JZiZq1sT8bx0qFlZZlE0znVDcOPvmrMs8YY0+BET3u4cTwVW1s9MW i0NANTk/UeY7peSTuxSZ46Ox/XObNnyjsCtYLDtH98C0Day/UVPzvk92D+OOUmdFj2Hq 9ARy20n3CHNuDIAfZr+DJIUfLs5BXscUgS/xVkF1VHPEs3BWBSFuEpIgTjEm/CYoTfMY q9ce/2822sf1T2Y67FRtBq7SlDvTr4gLRI2t4zenEGmayuJbn079yQAOVOPXQSaN3b9J ZZhw== X-Gm-Message-State: AE9vXwN6DTQDkiJonDkO5ZBHrP1ZiI5XYm+6akMMMakOgk98sHNec0zpas1OJFmXJ0nO3FE5 X-Received: by 10.66.148.167 with SMTP id tt7mr10177258pab.21.1474615633595; Fri, 23 Sep 2016 00:27:13 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id xw10sm8951156pab.0.2016.09.23.00.27.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Sep 2016 00:27:13 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, jason.wessel@windriver.com Cc: linux-arm-kernel@lists.infradead.org, kgdb-bugreport@lists.sourceforge.net, stable@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v2 3/3] arm64: kgdb: disable interrupts while a software step is enabled Date: Fri, 23 Sep 2016 16:33:27 +0900 Message-Id: <20160923073327.9657-4-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.10.0 In-Reply-To: <20160923073327.9657-1-takahiro.akashi@linaro.org> References: <20160923073327.9657-1-takahiro.akashi@linaro.org> Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org After entering kgdb mode, 'stepi' may unexpectedly breaks the execution somewhere in el1_irq. This happens because a debug exception is always enabled in el1_irq due to the following commit merged in v3.16: commit 2a2830703a23 ("arm64: debug: avoid accessing mdscr_el1 on fault paths where possible") A pending interrupt can be taken after kgdb has enabled a software step, but before a debug exception is actually taken. This patch enforces interrupts to be masked while single stepping. Signed-off-by: AKASHI Takahiro Cc: Catalin Marinas Cc: Will Deacon Cc: Jason Wessel Cc: # 3.16- --- arch/arm64/kernel/kgdb.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) -- 2.10.0 -- To unsubscribe from this list: send the line "unsubscribe stable" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/arch/arm64/kernel/kgdb.c b/arch/arm64/kernel/kgdb.c index 59c4aec..6732a27 100644 --- a/arch/arm64/kernel/kgdb.c +++ b/arch/arm64/kernel/kgdb.c @@ -26,6 +26,7 @@ #include #include #include +#include #include struct dbg_reg_def_t dbg_reg_def[DBG_MAX_REG_NUM] = { @@ -109,6 +110,7 @@ struct dbg_reg_def_t dbg_reg_def[DBG_MAX_REG_NUM] = { { "fpcr", 4, -1 }, }; +static DEFINE_PER_CPU(unsigned int, kgdb_pstate); static DEFINE_PER_CPU(struct irq_work, kgdb_irq_work); char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs) @@ -198,6 +200,10 @@ int kgdb_arch_handle_exception(int exception_vector, int signo, err = 0; break; case 's': + /* mask interrupts while single stepping */ + __this_cpu_write(kgdb_pstate, linux_regs->pstate); + linux_regs->pstate |= PSR_I_BIT; + /* * Update step address value with address passed * with step packet. @@ -239,9 +245,18 @@ NOKPROBE_SYMBOL(kgdb_compiled_brk_fn); static int kgdb_step_brk_fn(struct pt_regs *regs, unsigned int esr) { + unsigned int pstate; + kernel_disable_single_step(); atomic_set(&kgdb_cpu_doing_single_step, -1); + /* restore interrupt mask status */ + pstate = __this_cpu_read(kgdb_pstate); + if (pstate & PSR_I_BIT) + regs->pstate |= PSR_I_BIT; + else + regs->pstate &= ~PSR_I_BIT; + kgdb_handle_exception(1, SIGTRAP, 0, regs); return 0; }