From patchwork Tue Sep 11 09:34:55 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Vorontsov X-Patchwork-Id: 11291 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id AE76D23EFE for ; Tue, 11 Sep 2012 09:38:03 +0000 (UTC) Received: from mail-ie0-f180.google.com (mail-ie0-f180.google.com [209.85.223.180]) by fiordland.canonical.com (Postfix) with ESMTP id 471F8A1866A for ; Tue, 11 Sep 2012 09:38:03 +0000 (UTC) Received: by ieak11 with SMTP id k11so513911iea.11 for ; Tue, 11 Sep 2012 02:38:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to:cc :subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=XLbWOObPqSmLbnD79Gl1rJ/bzAWA2dyb2KW79STVaEs=; b=lkn2ka7ZeDx650HVJRNn4i7VY+QB8gXWieoHmCq75cCwZyHn87tg0QffLFWJOjvkW9 lb6bRqqN+1CgH4IP6LAlm3xmOaEEtkBS6VYSFsgkSek1ZGLvFAZpnKpj572DOuZflqeQ uZX2N4e8rxIb82vooERTOIuVUp635I1xxhzaYM6GSjv8+GXQuTOgWZxQaFxf1+bpQdJ6 AgK2iReYhNA5hS6EIouk5M2aigVfZ1BDM2JAeQlg18sG0S5B9EcdUEcdrDJzgrBnRX3g zbcFeLGaDR6LrfDc5sbi9zZSBGG628DQiroZKwFc22NFaizPqIKzpMNFCr7OMRawJglQ 0uGw== Received: by 10.50.180.129 with SMTP id do1mr15900083igc.28.1347356282707; Tue, 11 Sep 2012 02:38:02 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.50.184.232 with SMTP id ex8csp4764igc; Tue, 11 Sep 2012 02:38:02 -0700 (PDT) Received: by 10.68.194.165 with SMTP id hx5mr10738623pbc.40.1347356281591; Tue, 11 Sep 2012 02:38:01 -0700 (PDT) Received: from mail-pb0-f50.google.com (mail-pb0-f50.google.com [209.85.160.50]) by mx.google.com with ESMTPS id pn6si24191257pbb.160.2012.09.11.02.38.01 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 11 Sep 2012 02:38:01 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.160.50 is neither permitted nor denied by best guess record for domain of anton.vorontsov@linaro.org) client-ip=209.85.160.50; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.160.50 is neither permitted nor denied by best guess record for domain of anton.vorontsov@linaro.org) smtp.mail=anton.vorontsov@linaro.org Received: by mail-pb0-f50.google.com with SMTP id md12so636245pbc.37 for ; Tue, 11 Sep 2012 02:38:01 -0700 (PDT) Received: by 10.68.134.230 with SMTP id pn6mr10500706pbb.44.1347356280993; Tue, 11 Sep 2012 02:38:00 -0700 (PDT) Received: from localhost (c-71-204-165-222.hsd1.ca.comcast.net. [71.204.165.222]) by mx.google.com with ESMTPS id ih2sm7858155pbc.65.2012.09.11.02.37.58 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 11 Sep 2012 02:38:00 -0700 (PDT) From: Anton Vorontsov To: Andrew Morton , Russell King , Jason Wessel , Greg Kroah-Hartman , Alan Cox Cc: =?UTF-8?q?Arve=20Hj=C3=B8nnev=C3=A5g?= , Colin Cross , Brian Swetland , John Stultz , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linaro-kernel@lists.linaro.org, patches@linaro.org, kernel-team@android.com, kgdb-bugreport@lists.sourceforge.net, linux-serial@vger.kernel.org Subject: [PATCH 01/12] kernel/debug: Mask KGDB NMI upon entry Date: Tue, 11 Sep 2012 02:34:55 -0700 Message-Id: <1347356106-25368-1-git-send-email-anton.vorontsov@linaro.org> X-Mailer: git-send-email 1.7.11.5 In-Reply-To: <20120911093042.GA12471@lizard> References: <20120911093042.GA12471@lizard> X-Gm-Message-State: ALoCoQlR6O9cQqN3E4iYWkWX/hTw/YS9s6Q25rg72V46GINfvuivCnR0Rlzhv3bWgL5kbWx71VEc The new arch callback should manage NMIs that usually cause KGDB to enter. That is, not all NMIs should be enabled/disabled, but only those that issue kgdb_handle_exception(). We must mask it as serial-line interrupt can be used as an NMI, so if the original KGDB-entry cause was say a breakpoint, then every input to KDB console will cause KGDB to reenter, which we don't want. Signed-off-by: Anton Vorontsov --- include/linux/kgdb.h | 23 +++++++++++++++++++++++ kernel/debug/debug_core.c | 36 +++++++++++++++++++++++++++++++++--- 2 files changed, 56 insertions(+), 3 deletions(-) diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h index c4d2fc1..3b111a6 100644 --- a/include/linux/kgdb.h +++ b/include/linux/kgdb.h @@ -221,6 +221,29 @@ extern int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt); */ extern void kgdb_arch_late(void); +/** + * kgdb_arch_enable_nmi - Enable or disable KGDB-entry NMI + * @on: Flag to either enable or disable an NMI + * + * This is an architecture-specific "back-end" for kgdb_enable_nmi(). The + * call does not count disable/enable requests, do not use it directly. + */ +extern void kgdb_arch_enable_nmi(bool on); + +/** + * kgdb_enable_nmi - Enable or disable KGDB-entry NMI + * @on: Flag to either enable or disable an NMI + * + * This function manages NMIs that usually cause KGDB to enter. That is, + * not all NMIs should be enabled or disabled, but only those that issue + * kgdb_handle_exception(). + * + * The call counts disable requests, and thus allows to nest disables. + * But trying to enable already enabled NMI is an error. The call returns + * 1 if NMI has been actually enabled after the call, and a value <= 0 if + * it is still disabled. + */ +extern int kgdb_enable_nmi(bool on); /** * struct kgdb_arch - Describe architecture specific values. diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c index 0557f24..b621d1e 100644 --- a/kernel/debug/debug_core.c +++ b/kernel/debug/debug_core.c @@ -214,6 +214,30 @@ int __weak kgdb_skipexception(int exception, struct pt_regs *regs) return 0; } +void __weak kgdb_arch_enable_nmi(bool on) +{ +} + +int kgdb_enable_nmi(bool on) +{ + static atomic_t cnt; + int ret; + + ret = atomic_add_return(on ? 1 : -1, &cnt); + if (ret > 1 && on) { + /* + * There should be only one instance that calls this function + * in "enable, disable" order. All other users must call + * disable first, then enable. If not, something is wrong. + */ + WARN_ON(1); + return 1; + } + + kgdb_arch_enable_nmi(ret > 0); + return ret; +} + /* * Some architectures need cache flushes when we set/clear a * breakpoint: @@ -672,6 +696,9 @@ kgdb_handle_exception(int evector, int signo, int ecode, struct pt_regs *regs) { struct kgdb_state kgdb_var; struct kgdb_state *ks = &kgdb_var; + int ret = 0; + + kgdb_enable_nmi(0); ks->cpu = raw_smp_processor_id(); ks->ex_vector = evector; @@ -681,11 +708,14 @@ kgdb_handle_exception(int evector, int signo, int ecode, struct pt_regs *regs) ks->linux_regs = regs; if (kgdb_reenter_check(ks)) - return 0; /* Ouch, double exception ! */ + goto out; /* Ouch, double exception ! */ if (kgdb_info[ks->cpu].enter_kgdb != 0) - return 0; + goto out; - return kgdb_cpu_enter(ks, regs, DCPU_WANT_MASTER); + ret = kgdb_cpu_enter(ks, regs, DCPU_WANT_MASTER); +out: + kgdb_enable_nmi(1); + return ret; } int kgdb_nmicallback(int cpu, void *regs)