From patchwork Fri Apr 25 16:29:22 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Thompson X-Patchwork-Id: 29102 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f198.google.com (mail-ob0-f198.google.com [209.85.214.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 60F43203AC for ; Fri, 25 Apr 2014 16:29:50 +0000 (UTC) Received: by mail-ob0-f198.google.com with SMTP id wn1sf22963230obc.9 for ; Fri, 25 Apr 2014 09:29:49 -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=jefk+rO9YWXmGMQ3iHCBg5mSGC6sE4+Lr3NK6MAJZtKZsPoU4cxTRRQ0mpRyF8nAff PzkLr3oOEv8/upj7x6KvmRZAegGOBhepKemDRhFxjfQ5AeJgiJm/2IUzB8JlO8ljyqKX O+8zkSzYmZ7Uo/1bpiL+vYUqVYOfxRlmDdDGtTPkwOAHyoUIbzSHZpjehS/ah2gVKRmu EHs/pEeXd177LxU0xNS3wpr3TZcwBNr2IlCCAaRN5kHh87P6ls0aqNJWNK6nv0VwSZnP D7Of/klYf1q1MHCbLeQ3Cqkxl01lFKxoJECrig8r+AJA2Bvp2pQWMFo7Mc49h+X9wsz+ gVQw== X-Gm-Message-State: ALoCoQnulDL9QHRFCImARHTk/XUtOPWWdvCfrS9Boj4cM6Wa2nIbG6Enft2skH72WHpZ++7ctHgO X-Received: by 10.182.105.1 with SMTP id gi1mr4954349obb.6.1398443389939; Fri, 25 Apr 2014 09:29:49 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.50.197 with SMTP id s63ls1547343qga.39.gmail; Fri, 25 Apr 2014 09:29:49 -0700 (PDT) X-Received: by 10.58.95.102 with SMTP id dj6mr71639veb.68.1398443389759; Fri, 25 Apr 2014 09:29:49 -0700 (PDT) Received: from mail-ve0-f169.google.com (mail-ve0-f169.google.com [209.85.128.169]) by mx.google.com with ESMTPS id tq2si1816842vdc.3.2014.04.25.09.29.49 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 25 Apr 2014 09:29:49 -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.169; Received: by mail-ve0-f169.google.com with SMTP id pa12so5068230veb.0 for ; Fri, 25 Apr 2014 09:29:49 -0700 (PDT) X-Received: by 10.53.1.69 with SMTP id be5mr6197031vdd.27.1398443389700; Fri, 25 Apr 2014 09:29:49 -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 ib8csp110882vcb; Fri, 25 Apr 2014 09:29:49 -0700 (PDT) X-Received: by 10.194.59.226 with SMTP id c2mr7587578wjr.6.1398443388511; Fri, 25 Apr 2014 09:29:48 -0700 (PDT) Received: from mail-wg0-f44.google.com (mail-wg0-f44.google.com [74.125.82.44]) by mx.google.com with ESMTPS id gi2si3923241wjd.112.2014.04.25.09.29.48 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 25 Apr 2014 09:29:48 -0700 (PDT) Received-SPF: none (google.com: daniel.thompson@linaro.org does not designate permitted sender hosts) client-ip=74.125.82.44; Received: by mail-wg0-f44.google.com with SMTP id m15so3782672wgh.3 for ; Fri, 25 Apr 2014 09:29:48 -0700 (PDT) X-Received: by 10.194.62.176 with SMTP id z16mr1815941wjr.67.1398443388117; Fri, 25 Apr 2014 09:29:48 -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 fw13sm6881026wic.6.2014.04.25.09.29.45 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 25 Apr 2014 09:29:46 -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 v3 1/9] sysrq: Implement __handle_sysrq_nolock to avoid recursive locking in kdb Date: Fri, 25 Apr 2014 17:29:22 +0100 Message-Id: <1398443370-12668-2-git-send-email-daniel.thompson@linaro.org> X-Mailer: git-send-email 1.9.0 In-Reply-To: <1398443370-12668-1-git-send-email-daniel.thompson@linaro.org> References: <1396453440-16445-1-git-send-email-daniel.thompson@linaro.org> <1398443370-12668-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. 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;