From patchwork Wed Apr 2 15:43:51 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Thompson X-Patchwork-Id: 27634 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f200.google.com (mail-ob0-f200.google.com [209.85.214.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 7471B20341 for ; Wed, 2 Apr 2014 15:44:15 +0000 (UTC) Received: by mail-ob0-f200.google.com with SMTP id gq1sf1779911obb.3 for ; Wed, 02 Apr 2014 08:44:15 -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=FpJVIbSSHxMGzSrkS5xDUbDkrU1obHTvBPBrBQvqJ2k=; b=l95+gW/8n7SKJ0Dk8+hc92TvLgzDpv6z2pyQ65EvBFm/Vd9Kep2tQ3sLUKgm1BBZQ5 EmA9lXE0+XanL6u0fvvoIl82J2HqdOq1cnxGERZiaON5Cdp0oGoY9nzRu1RPdB4J2Cqk 66LT8h1O0QXOkkiaJ1JbMk6gIE4dLw2F1qfliZiAKURiB6n3Al7XPsJahHcnnXJZb1r8 gCNfLyYoXmYbN6bfxjAABN7kTg7O3J8ZdXO7On0xLLC7KpWrnybBg0kcVLqDuvQxYVrX fRcrC0IZI5Rud19P9kkRx0cjZ/sMLeubJSsmNqX6Q3iBN66h+gpM65J4At7LqmtzqrGl Q3Fw== X-Gm-Message-State: ALoCoQmbJ+91zzxoPbJovSt9D4+S+8ryTLaQsfNu5uHSysQJPUx5eYVphgoGLP23CIy47fZc3RzD X-Received: by 10.182.19.231 with SMTP id i7mr422667obe.25.1396453455037; Wed, 02 Apr 2014 08:44:15 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.105.161 with SMTP id c30ls356497qgf.88.gmail; Wed, 02 Apr 2014 08:44:14 -0700 (PDT) X-Received: by 10.52.251.199 with SMTP id zm7mr1237200vdc.21.1396453454849; Wed, 02 Apr 2014 08:44:14 -0700 (PDT) Received: from mail-vc0-f176.google.com (mail-vc0-f176.google.com [209.85.220.176]) by mx.google.com with ESMTPS id sn5si639296vdc.11.2014.04.02.08.44.14 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 02 Apr 2014 08:44:14 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.176 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.176; Received: by mail-vc0-f176.google.com with SMTP id lc6so559614vcb.7 for ; Wed, 02 Apr 2014 08:44:14 -0700 (PDT) X-Received: by 10.52.137.74 with SMTP id qg10mr1160797vdb.61.1396453454772; Wed, 02 Apr 2014 08:44:14 -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.12.8 with SMTP id v8csp334233vcv; Wed, 2 Apr 2014 08:44:13 -0700 (PDT) X-Received: by 10.194.59.226 with SMTP id c2mr2044464wjr.6.1396453453542; Wed, 02 Apr 2014 08:44:13 -0700 (PDT) Received: from mail-wi0-f178.google.com (mail-wi0-f178.google.com [209.85.212.178]) by mx.google.com with ESMTPS id wv8si1067231wjb.32.2014.04.02.08.44.13 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 02 Apr 2014 08:44:13 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.212.178 is neither permitted nor denied by best guess record for domain of daniel.thompson@linaro.org) client-ip=209.85.212.178; Received: by mail-wi0-f178.google.com with SMTP id bs8so788089wib.5 for ; Wed, 02 Apr 2014 08:44:13 -0700 (PDT) X-Received: by 10.180.211.207 with SMTP id ne15mr22897828wic.31.1396453453025; Wed, 02 Apr 2014 08:44:13 -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 dg7sm3450581wjc.4.2014.04.02.08.44.11 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 02 Apr 2014 08:44:12 -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: [RFC v2 01/10] sysrq: Implement __handle_sysrq_nolock to avoid recursive locking in kdb Date: Wed, 2 Apr 2014 16:43:51 +0100 Message-Id: <1396453440-16445-2-git-send-email-daniel.thompson@linaro.org> X-Mailer: git-send-email 1.9.0 In-Reply-To: <1396453440-16445-1-git-send-email-daniel.thompson@linaro.org> References: <1396453440-16445-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: 209.85.220.176 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) 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. Strictly speaking this approach risks racing on the key table when kdb is triggered by something other than SysRq-g however in that case any other CPU involved should release the spin lock before kgdb parks the slave CPUs. Signed-off-by: Daniel Thompson --- drivers/tty/sysrq.c | 11 ++++++++--- include/linux/sysrq.h | 1 + kernel/debug/kdb/kdb_main.c | 2 +- 3 files changed, 10 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..f39f926 100644 --- a/kernel/debug/kdb/kdb_main.c +++ b/kernel/debug/kdb/kdb_main.c @@ -1924,7 +1924,7 @@ 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;