From patchwork Wed Jul 16 13:30:13 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Thompson X-Patchwork-Id: 33730 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f70.google.com (mail-pa0-f70.google.com [209.85.220.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 149DC20792 for ; Wed, 16 Jul 2014 13:31:10 +0000 (UTC) Received: by mail-pa0-f70.google.com with SMTP id lf10sf6667481pab.9 for ; Wed, 16 Jul 2014 06:31:09 -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:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=F4Mwa//7Vbl9A/fymPp6Se7EuMym/xisyJgffWrjuNs=; b=ePayr7sbc0c9tpc/cjpQiQnSz0CpVT+5BOSe8QituqZ1+GuQT066H+h+q/ef62qIuA HTeFh5crTBeSvvDXCmtndBqtsgfbaSukTMiXrosqKk8LUQIq0Dqf2X3TOgTx2YKckSiK XUFILSj6FTKy3l6iKRYmBlxpa4jDDbYlx7ku564nFeIdxor+vBYcFFOS7FcTBVK2KVql p6sZBQx5hWgvNnVBJLW0ACXh7dmvP1MoGjBPagZKaQlN8rg8tmeBE09fqUCDjww8x1Wd 10A1XhDvpIfPbqysCoVhLgaS1yxsa70YOFcMEYYwAuKB2qh9Zsv+zth31ApQPSLYQSr1 tY+w== X-Gm-Message-State: ALoCoQl4iba0p/X8K4g5bAVFx+J2Zt26lrEAtw6wlCeDo3Jti+4Z58byZiVVOAtzpKs4zE4qqbNa X-Received: by 10.66.182.170 with SMTP id ef10mr14990756pac.0.1405517469410; Wed, 16 Jul 2014 06:31:09 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.50.4.1 with SMTP id g1ls2910828igg.34.canary; Wed, 16 Jul 2014 06:31:09 -0700 (PDT) X-Received: by 10.70.103.45 with SMTP id ft13mr2698059pdb.152.1405517469132; Wed, 16 Jul 2014 06:31:09 -0700 (PDT) Received: from mail-vc0-f180.google.com (mail-vc0-f180.google.com [209.85.220.180]) by mx.google.com with ESMTPS id lr10si8432062veb.106.2014.07.16.06.31.09 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 16 Jul 2014 06:31:09 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.180 as permitted sender) client-ip=209.85.220.180; Received: by mail-vc0-f180.google.com with SMTP id ij19so1631078vcb.11 for ; Wed, 16 Jul 2014 06:31:09 -0700 (PDT) X-Received: by 10.52.244.138 with SMTP id xg10mr7134149vdc.40.1405517469005; Wed, 16 Jul 2014 06:31:09 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp298943vcb; Wed, 16 Jul 2014 06:31:06 -0700 (PDT) X-Received: by 10.68.130.130 with SMTP id oe2mr2734988pbb.154.1405517466163; Wed, 16 Jul 2014 06:31:06 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d10si7260116pdp.284.2014.07.16.06.31.05; Wed, 16 Jul 2014 06:31:05 -0700 (PDT) Received-SPF: none (google.com: linux-serial-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933785AbaGPNbE (ORCPT + 1 other); Wed, 16 Jul 2014 09:31:04 -0400 Received: from mail-we0-f179.google.com ([74.125.82.179]:52449 "EHLO mail-we0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933406AbaGPNbD (ORCPT ); Wed, 16 Jul 2014 09:31:03 -0400 Received: by mail-we0-f179.google.com with SMTP id u57so927357wes.38 for ; Wed, 16 Jul 2014 06:31:01 -0700 (PDT) X-Received: by 10.180.79.201 with SMTP id l9mr13899883wix.60.1405517460984; Wed, 16 Jul 2014 06:31:00 -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 n2sm39792364wjf.40.2014.07.16.06.30.49 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 16 Jul 2014 06:31:00 -0700 (PDT) From: Daniel Thompson To: Greg Kroah-Hartman Cc: Daniel Thompson , linux-kernel@vger.kernel.org, patches@linaro.org, linaro-kernel@lists.linaro.org, Jiri Slaby , linux-serial@vger.kernel.org, Jason Wessel , kgdb-bugreport@lists.sourceforge.net Subject: [PATCH v2] tty: kgdb_nmi: Automatically manage tty enable Date: Wed, 16 Jul 2014 14:30:13 +0100 Message-Id: <1405517413-11359-1-git-send-email-daniel.thompson@linaro.org> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1405081811-15254-1-git-send-email-daniel.thompson@linaro.org> References: <1405081811-15254-1-git-send-email-daniel.thompson@linaro.org> Sender: linux-serial-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-serial@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: daniel.thompson@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.180 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , At present it is not possible to boot with the ttyNMI0 console treating character input normally, instead character input triggers a prompt telling the user how to trigger the knock detector and enter the debugger. To use the console normally requires that kdb be entered and the nmi_console command be used to enable the console (or if only kgdb is present then gdb must directly manipulate the value of kgdb_nmi_tty_enabled). This patch automates the management of kgdb_nmi_tty_enabled by keeping track of the number of file handles that are open for reading and using that to determine how to tty should operate. The approach means that: 1. Behaviour before init starts is unchanged. 2. If the userspace runs a getty or some other interactive process on /dev/console (or explicitly on /dev/ttyNMI0) the tty will treat character input like any other tty. 3. If the userspace doesn't use /dev/console or if it uses /dev/console only to log messages (O_WRONLY) then the user prompt is retained. Signed-off-by: Daniel Thompson Cc: Greg Kroah-Hartman Cc: Jiri Slaby Cc: linux-serial@vger.kernel.org Cc: Jason Wessel Cc: kgdb-bugreport@lists.sourceforge.net --- drivers/tty/serial/kgdb_nmi.c | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/drivers/tty/serial/kgdb_nmi.c b/drivers/tty/serial/kgdb_nmi.c index cfadf29..6ec7501 100644 --- a/drivers/tty/serial/kgdb_nmi.c +++ b/drivers/tty/serial/kgdb_nmi.c @@ -42,7 +42,7 @@ static char *kgdb_nmi_magic = "$3#33"; module_param_named(magic, kgdb_nmi_magic, charp, 0600); MODULE_PARM_DESC(magic, "magic sequence to enter NMI debugger (default $3#33)"); -static bool kgdb_nmi_tty_enabled; +static atomic_t kgdb_nmi_num_readers = ATOMIC_INIT(0); static int kgdb_nmi_console_setup(struct console *co, char *options) { @@ -136,7 +136,7 @@ static int kgdb_nmi_poll_one_knock(void) n = 0; } - if (kgdb_nmi_tty_enabled) { + if (atomic_read(&kgdb_nmi_num_readers)) { kgdb_tty_recv(c); return 0; } @@ -197,7 +197,8 @@ static void kgdb_nmi_tty_receiver(unsigned long data) priv->timer.expires = jiffies + (HZ/100); add_timer(&priv->timer); - if (likely(!kgdb_nmi_tty_enabled || !kfifo_len(&priv->fifo))) + if (likely(!atomic_read(&kgdb_nmi_num_readers) || + !kfifo_len(&priv->fifo))) return; while (kfifo_out(&priv->fifo, &ch, 1)) @@ -270,13 +271,23 @@ static void kgdb_nmi_tty_cleanup(struct tty_struct *tty) static int kgdb_nmi_tty_open(struct tty_struct *tty, struct file *file) { struct kgdb_nmi_tty_priv *priv = tty->driver_data; + unsigned int mode = file->f_flags & O_ACCMODE; + int ret; + + ret = tty_port_open(&priv->port, tty, file); + if (!ret && (mode == O_RDONLY || mode == O_RDWR)) + atomic_inc(&kgdb_nmi_num_readers); - return tty_port_open(&priv->port, tty, file); + return ret; } static void kgdb_nmi_tty_close(struct tty_struct *tty, struct file *file) { struct kgdb_nmi_tty_priv *priv = tty->driver_data; + unsigned int mode = file->f_flags & O_ACCMODE; + + if (mode == O_RDONLY || mode == O_RDWR) + atomic_dec(&kgdb_nmi_num_readers); tty_port_close(&priv->port, tty, file); } @@ -313,12 +324,6 @@ static const struct tty_operations kgdb_nmi_tty_ops = { .write = kgdb_nmi_tty_write, }; -static int kgdb_nmi_enable_console(int argc, const char *argv[]) -{ - kgdb_nmi_tty_enabled = !(argc == 1 && !strcmp(argv[1], "off")); - return 0; -} - int kgdb_register_nmi_console(void) { int ret; @@ -348,19 +353,10 @@ int kgdb_register_nmi_console(void) goto err_drv_reg; } - ret = kdb_register("nmi_console", kgdb_nmi_enable_console, "[off]", - "switch to Linux NMI console", 0); - if (ret) { - pr_err("%s: can't register kdb command: %d\n", __func__, ret); - goto err_kdb_reg; - } - register_console(&kgdb_nmi_console); arch_kgdb_ops.enable_nmi(1); return 0; -err_kdb_reg: - tty_unregister_driver(kgdb_nmi_tty_driver); err_drv_reg: put_tty_driver(kgdb_nmi_tty_driver); return ret; @@ -375,8 +371,6 @@ int kgdb_unregister_nmi_console(void) return 0; arch_kgdb_ops.enable_nmi(0); - kdb_unregister("nmi_console"); - ret = unregister_console(&kgdb_nmi_console); if (ret) return ret;