From patchwork Thu Sep 13 15:03:25 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Vorontsov X-Patchwork-Id: 1453041 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from merlin.infradead.org (unknown [205.233.59.134]) by patchwork2.kernel.org (Postfix) with ESMTP id 9765DDFFD0 for ; Thu, 13 Sep 2012 15:18:43 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TCAzw-0002LV-DZ; Thu, 13 Sep 2012 15:06:32 +0000 Received: from mail-pb0-f49.google.com ([209.85.160.49]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1TCAzr-0002LB-M1 for linux-arm-kernel@lists.infradead.org; Thu, 13 Sep 2012 15:06:28 +0000 Received: by pbbrq8 with SMTP id rq8so4392405pbb.36 for ; Thu, 13 Sep 2012 08:06:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=XLbWOObPqSmLbnD79Gl1rJ/bzAWA2dyb2KW79STVaEs=; b=e1ssCwmcT21OhJzK9Ce8vqMlRNqufJkbpuAkiYdAi/zwYrreXJrlFPCOMVXs3CpkWx gnDeiGjiRo7beBirMQJRCtpJBWI0jrAyoEFdBBJIKgpbP21OX1HXSseB8d5emFF7y+57 SCmrE1XmNSmkOk7MRic/1HkXTncn3U+g7VtPjbexQPVGZ3bJ7rypO4qh12bcAJjtIZcS ZiIxgKyD8xZaT/Vm+HPZKCilkUBaWKKVj56kfx5OO01t8hbe1w7pWRUgsE3bcpjCRygf wRk2FzDL/Ct7jdGWUuGqt9XwhA0uDrtnqNvu+vPQc1snQhkYAifNFmEBZ/Xckc+Wgu/M ScnA== Received: by 10.66.76.165 with SMTP id l5mr3559812paw.79.1347548786419; Thu, 13 Sep 2012 08:06:26 -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 st6sm13205414pbc.58.2012.09.13.08.06.24 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 13 Sep 2012 08:06:25 -0700 (PDT) From: Anton Vorontsov To: Andrew Morton , Russell King , Jason Wessel , Greg Kroah-Hartman , Alan Cox Subject: [PATCH 01/11] kernel/debug: Mask KGDB NMI upon entry Date: Thu, 13 Sep 2012 08:03:25 -0700 Message-Id: <1347548615-18227-1-git-send-email-anton.vorontsov@linaro.org> X-Mailer: git-send-email 1.7.11.5 In-Reply-To: <20120913150133.GA16238@lizard> References: <20120913150133.GA16238@lizard> X-Gm-Message-State: ALoCoQn3sHxLGasfGiZs4RnU1OuqfjxL/dc5YvvF71LRluW6aC9XQSn+4rVxBjYsGj0GTc0qJ887 X-Spam-Note: CRM114 invocation failed X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.160.49 listed in list.dnswl.org] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: linaro-kernel@lists.linaro.org, patches@linaro.org, Brian Swetland , linux-kernel@vger.kernel.org, =?UTF-8?q?Arve=20Hj=C3=B8nnev=C3=A5g?= , John Stultz , linux-serial@vger.kernel.org, Colin Cross , kgdb-bugreport@lists.sourceforge.net, Thomas Gleixner , kernel-team@android.com, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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)