From patchwork Mon Sep 10 04:12:57 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Vorontsov X-Patchwork-Id: 1429561 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork2.kernel.org (Postfix) with ESMTP id 0CEECDF28C for ; Mon, 10 Sep 2012 04:18:34 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TAvPJ-0001up-19; Mon, 10 Sep 2012 04:15:33 +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 1TAvPG-0001qa-9N for linux-arm-kernel@lists.infradead.org; Mon, 10 Sep 2012 04:15:30 +0000 Received: by mail-pb0-f49.google.com with SMTP id rq8so2004197pbb.36 for ; Sun, 09 Sep 2012 21:15:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent :x-gm-message-state; bh=XLbWOObPqSmLbnD79Gl1rJ/bzAWA2dyb2KW79STVaEs=; b=dXgqMBMcCMs/2Tq+0QJEPUiLOPqw9XzesYAbI8rhmO3aorUoKVJFjNiQGzaguG26Bd w4D04Vh1rIMuueewQo/HXuptjC0thpaIE3v5/YBpYjSbXzA+rNSd+hfes46A7Hb0oP1k 1VVNJNf+yrbyAlU/gN1f05XidfENCJU0pukUI66BqfYgJtapmhBEBcPjVmIc/7QiGnxn lIeW/hggUi91tBhOcxyZLphtklM8lQ2N1IngFJzprNt482Cl7731hMZGKRIURanP4Sej k772OJnDtsFi2hB4O0b9lJ1bum+MzzeySvP8hj7J9510Peoi1VwlqtNjNH8QxdMlIPbV qYbQ== Received: by 10.68.129.164 with SMTP id nx4mr3848714pbb.28.1347250529942; Sun, 09 Sep 2012 21:15:29 -0700 (PDT) Received: from localhost (ip-64-134-230-8.public.wayport.net. [64.134.230.8]) by mx.google.com with ESMTPS id sr3sm7433035pbc.44.2012.09.09.21.15.28 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 09 Sep 2012 21:15:28 -0700 (PDT) Date: Sun, 9 Sep 2012 21:12:57 -0700 From: Anton Vorontsov To: Andrew Morton , Russell King , Jason Wessel , Greg Kroah-Hartman , Alan Cox Subject: [PATCH 03/14] kernel/debug: Mask KGDB NMI upon entry Message-ID: <20120910041257.GC29537@lizard> References: <20120910040802.GA1261@lizard> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20120910040802.GA1261@lizard> User-Agent: Mutt/1.5.21 (2010-09-15) X-Gm-Message-State: ALoCoQkQdkm62C7+P064dRM0mfI9m52wh34feeiwbiQ7QcoMcsO7Ju0EX35YTbGgVka0DdpokT7c 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, Arve =?utf-8?B?SGrDuG5uZXbDpWc=?= , John Stultz , linux-serial@vger.kernel.org, Colin Cross , kgdb-bugreport@lists.sourceforge.net, 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: , 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)