From patchwork Tue May 6 13:03:41 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Thompson X-Patchwork-Id: 29698 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qc0-f198.google.com (mail-qc0-f198.google.com [209.85.216.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 435CB20534 for ; Tue, 6 May 2014 13:04:41 +0000 (UTC) Received: by mail-qc0-f198.google.com with SMTP id m20sf10860468qcx.5 for ; Tue, 06 May 2014 06:04:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=8dUNeF71ME+K+0s+hp4fHIi28StFvfNIcP1RapUcVCc=; b=NyXfwnW1Y+TiUZ1e/NjRIFAPcq5ZtHKbTRLtM1gB7G1/JWnn2QdJNzoEXR0A2gGoah GTSVjMHiSYDpmOUvrstRbe+G8/z86vap0SNa/jY6cf2UyiXO5VtheVCu0C1LYn7+2KGn /kCSii3dEIym9NBMmqp0AD6kW1QC1mHdUirasU9BU9UKO4q5JIQZI5AtWQ5ZOEhjzvZE uzB/Gs2GOi9Wd4b7K65LV8ZkRl1sjqJs472XMQJxCWDEvR8LC74zvZReeN7vWqSoUYLt HfY5QYgAbE9sxCAsQ/WVyD45PCZE11uNEBzUV7u/Q07FCwuwfaqJh6Tv07iIUp2vSVbQ Q8/w== X-Gm-Message-State: ALoCoQnV7J7CXg2LmgUDUhJMCIs+x1uEJlTJ5Be826IwX/W3nbZ5SMwTHoxzSetmEQ3Yuu5lMcSa X-Received: by 10.52.165.179 with SMTP id yz19mr923677vdb.1.1399381480411; Tue, 06 May 2014 06:04:40 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.109.71 with SMTP id k65ls2849544qgf.88.gmail; Tue, 06 May 2014 06:04:40 -0700 (PDT) X-Received: by 10.52.118.212 with SMTP id ko20mr304198vdb.77.1399381480244; Tue, 06 May 2014 06:04:40 -0700 (PDT) Received: from mail-ve0-f177.google.com (mail-ve0-f177.google.com [209.85.128.177]) by mx.google.com with ESMTPS id xo2si2308349vec.116.2014.05.06.06.04.40 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 06 May 2014 06:04:40 -0700 (PDT) Received-SPF: none (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) client-ip=209.85.128.177; Received: by mail-ve0-f177.google.com with SMTP id db11so5660732veb.8 for ; Tue, 06 May 2014 06:04:40 -0700 (PDT) X-Received: by 10.52.227.138 with SMTP id sa10mr15278016vdc.25.1399381480162; Tue, 06 May 2014 06:04:40 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.221.72 with SMTP id ib8csp221735vcb; Tue, 6 May 2014 06:04:39 -0700 (PDT) X-Received: by 10.180.210.238 with SMTP id mx14mr2341783wic.61.1399381478940; Tue, 06 May 2014 06:04:38 -0700 (PDT) Received: from mail-wg0-f49.google.com (mail-wg0-f49.google.com [74.125.82.49]) by mx.google.com with ESMTPS id cg4si5644187wjb.144.2014.05.06.06.04.38 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 06 May 2014 06:04:38 -0700 (PDT) Received-SPF: none (google.com: daniel.thompson@linaro.org does not designate permitted sender hosts) client-ip=74.125.82.49; Received: by mail-wg0-f49.google.com with SMTP id m15so3713893wgh.32 for ; Tue, 06 May 2014 06:04:38 -0700 (PDT) X-Received: by 10.180.21.180 with SMTP id w20mr2463316wie.34.1399381478496; Tue, 06 May 2014 06:04:38 -0700 (PDT) Received: from sundance.lan (cpc4-aztw19-0-0-cust157.18-1.cable.virginm.net. [82.33.25.158]) by mx.google.com with ESMTPSA id by1sm21966350wjc.26.2014.05.06.06.04.36 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 May 2014 06:04:37 -0700 (PDT) From: Daniel Thompson To: kgdb-bugreport@lists.sourceforge.net, Jason Wessel Cc: patches@linaro.org, linaro-kernel@lists.linaro.org, Daniel Thompson , linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Jiri Slaby , Steven Rostedt , Frederic Weisbecker , Ingo Molnar , John Stultz , Anton Vorontsov , Colin Cross , kernel-team@android.com Subject: [PATCH v4 1/9] sysrq: Implement __handle_sysrq_nolock to avoid recursive locking in kdb Date: Tue, 6 May 2014 14:03:41 +0100 Message-Id: <1399381429-16194-2-git-send-email-daniel.thompson@linaro.org> X-Mailer: git-send-email 1.9.0 In-Reply-To: <1399381429-16194-1-git-send-email-daniel.thompson@linaro.org> References: <1398443370-12668-1-git-send-email-daniel.thompson@linaro.org> <1399381429-16194-1-git-send-email-daniel.thompson@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: daniel.thompson@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , If kdb is triggered using SysRq-g then any use of the sr command results in the SysRq key table lock being recursively acquired, killing the debug session. That patch resolves the problem by introducing a _nolock alternative for __handle_sysrq. Signed-off-by: Daniel Thompson --- drivers/tty/sysrq.c | 11 ++++++++--- include/linux/sysrq.h | 1 + kernel/debug/kdb/kdb_main.c | 9 ++++++++- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c index ce396ec..7b47b2d 100644 --- a/drivers/tty/sysrq.c +++ b/drivers/tty/sysrq.c @@ -505,14 +505,12 @@ static void __sysrq_put_key_op(int key, struct sysrq_key_op *op_p) sysrq_key_table[i] = op_p; } -void __handle_sysrq(int key, bool check_mask) +void __handle_sysrq_nolock(int key, bool check_mask) { struct sysrq_key_op *op_p; int orig_log_level; int i; - unsigned long flags; - spin_lock_irqsave(&sysrq_key_table_lock, flags); /* * Raise the apparent loglevel to maximum so that the sysrq header * is shown to provide the user with positive feedback. We do not @@ -554,6 +552,13 @@ void __handle_sysrq(int key, bool check_mask) printk("\n"); console_loglevel = orig_log_level; } +} + +void __handle_sysrq(int key, bool check_mask) +{ + unsigned long flags; + spin_lock_irqsave(&sysrq_key_table_lock, flags); + __handle_sysrq_nolock(key, check_mask); spin_unlock_irqrestore(&sysrq_key_table_lock, flags); } diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h index 387fa7d..1d51d64 100644 --- a/include/linux/sysrq.h +++ b/include/linux/sysrq.h @@ -44,6 +44,7 @@ struct sysrq_key_op { void handle_sysrq(int key); void __handle_sysrq(int key, bool check_mask); +void __handle_sysrq_nolock(int key, bool check_mask); int register_sysrq_key(int key, struct sysrq_key_op *op); int unregister_sysrq_key(int key, struct sysrq_key_op *op); struct sysrq_key_op *__sysrq_get_key_op(int key); diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c index 0b097c8..de439bb 100644 --- a/kernel/debug/kdb/kdb_main.c +++ b/kernel/debug/kdb/kdb_main.c @@ -1918,13 +1918,20 @@ static int kdb_rm(int argc, const char **argv) * kdb_sr - This function implements the 'sr' (SYSRQ key) command * which interfaces to the soi-disant MAGIC SYSRQ functionality. * sr + * + * Remarks: + * This command calls into the sysrq code without locking. The sysrq + * code is protected using spin_lock_irqsave meaning this command, + * whilst normally safe, must be used very carefully if kdb is entered + * using a mechanism, such as the NMI, which is immune to the interrupt + * mask. */ static int kdb_sr(int argc, const char **argv) { if (argc != 1) return KDB_ARGCOUNT; kdb_trap_printk++; - __handle_sysrq(*argv[1], false); + __handle_sysrq_nolock(*argv[1], false); kdb_trap_printk--; return 0;