From patchwork Mon Jun 22 14:26:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Garg X-Patchwork-Id: 191335 Delivered-To: patch@linaro.org Received: by 2002:a92:1f07:0:0:0:0:0 with SMTP id i7csp1092797ile; Mon, 22 Jun 2020 07:27:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxV22MwNhF1K3pRec9CyGRiiDyFLKAkc7Kv31iWVjirEikX4sdDv4MmIrIJFGphrkzdtIh3 X-Received: by 2002:a50:c44b:: with SMTP id w11mr17965346edf.317.1592836065941; Mon, 22 Jun 2020 07:27:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592836065; cv=none; d=google.com; s=arc-20160816; b=gtIpc8OotaELHRR1+5gyRe51fF9sKeNfBrzY1W5nDzhof7uZgVRPnh2XBZcrBG/dbl EURbg6f7S/HzoIfis/AxH5QDWbGn768C/gpC2+OZ5ak056JAkao2ODv4f2PbZZGamIP/ yG0OZcOhLx9mvZqBntOgs9203TuIGsCYBtChoDJjHjzLCYPYbBkU7m2ezn0d23SYxFpB ExFAWaFZGhLqWtaJZuFRNzuxupM7S4824EUkIYQ731rxq4RWzYVtkxPZ9Vw5wdv97HWh l/2zb96YF0FiteNntwS1nJHyXYqaYHbpe59DeEpdp/ux/uTCZ52PJJqqBIKrLStG3obq SbZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=sjUQXgLs8QLSZt9fRiSIf9rP+l/zfeDDFs4yVtYk7Z0=; b=zg8bvtAFAPL7NtdaZSQn0d/dqYmcGAMMTucP9w6YCCAuwjFQgVwuCrCoEd3vrRxY3p KUlpVsugLP9EC0w5DztrTM7gzevaDoUzaj+IlkN75ovtQ8RzVqL5fo7wRgJxhZI18Q/w CqG6RW/AzUHxjwt97ElKr8zJVfL6EwTtshRtcNa64NKD23E3gVjuU9W8Efm8tZUt28PI 9Z6aafIp9wWKYp/r3/IOMuakN0hAIwTonlSKaRqTe8ZCpypseH0mOIFj2uWXx9R4kIgu Fpou3y7dtrTQu8Hu4IYolAvIue6kP/Lz63AkO5OaHCVU3sJrhnNVfrIBURsVsTSBcPuw biTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QOeLXcXX; spf=pass (google.com: domain of linux-serial-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-serial-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y25si1753981edi.139.2020.06.22.07.27.45; Mon, 22 Jun 2020 07:27:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-serial-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QOeLXcXX; spf=pass (google.com: domain of linux-serial-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-serial-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729160AbgFVO1n (ORCPT + 1 other); Mon, 22 Jun 2020 10:27:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56748 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729485AbgFVO1k (ORCPT ); Mon, 22 Jun 2020 10:27:40 -0400 Received: from mail-pj1-x1043.google.com (mail-pj1-x1043.google.com [IPv6:2607:f8b0:4864:20::1043]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F6FFC061573 for ; Mon, 22 Jun 2020 07:27:40 -0700 (PDT) Received: by mail-pj1-x1043.google.com with SMTP id u14so2935097pjj.2 for ; Mon, 22 Jun 2020 07:27:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=sjUQXgLs8QLSZt9fRiSIf9rP+l/zfeDDFs4yVtYk7Z0=; b=QOeLXcXXYJY7Mbx/0GKxWfojZNvqp1+/iUKrhHvJJPT9TVW7hdHXE2t9l97MfMSFpN a08ODnr/u8hVAu7RVgm3nwaohgTk6yIAfdCRoM5WfyRsqxQHCEGEzi9wTA/yKOQSDDTn EspPlVmFhi6LGov/zu0zVQxHn0TORwdNIp4Tz25YBXpANqqkhTFuF4GxAxBipD+4hDqG jmvq8KHWY56pQ4Uhc3UmRVKr91Ozy+VR2DUlvgYbGewgO3jRkY/Dp81cKfOw8z4F75Dm Z8nwP0kHFAnNAqtxxXXSBop65W6O3MFJ//0g5Mpc6ZSBKBujqa7snPffto/Uxw5BV9qX S9qA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=sjUQXgLs8QLSZt9fRiSIf9rP+l/zfeDDFs4yVtYk7Z0=; b=QTmxIjEjqvvuCoQ0FZST/EAfc5XfdufzwuMMPIdTOu4t9vhoFClodMDYu2EPc5q9Ti b/+l0hTuFYXjFWdRcnAu143H0mBOefefx+/Fy3yBslvMGhRoc4u3fkjW2C5CQ+ZmS0/4 aqAX05Xb9rmhs73U/SSRv0xwDzgFRCvL3fkYtP6xwcpK/OupkMnhcP5XXFAqYFcKxsix Gl/q9jK2O953Kge/ylNJTToI9dXqCswvaX5J5CuhkYv523wx901RJEmYIt6l42i/Pcnz qE8a0ktwmYbk2UhZzTjA4iLFPZnN4munYdNPFxX3E8rtHaD3jEHSvvwnANNvy4zseYbD NpLg== X-Gm-Message-State: AOAM53194KlOUwCOdn1jEHNeqdBGsad0wfBWaiOmuHYkGfu7oBPh9z+8 Rv4cnoff/HIPXm4tJs7oQfVCoQmxli4= X-Received: by 2002:a17:90a:d485:: with SMTP id s5mr17596432pju.61.1592836060022; Mon, 22 Jun 2020 07:27:40 -0700 (PDT) Received: from localhost.localdomain ([117.252.67.186]) by smtp.gmail.com with ESMTPSA id d6sm14547939pjh.5.2020.06.22.07.27.35 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 22 Jun 2020 07:27:39 -0700 (PDT) From: Sumit Garg To: kgdb-bugreport@lists.sourceforge.net, linux-serial@vger.kernel.org Cc: gregkh@linuxfoundation.org, daniel.thompson@linaro.org, jason.wessel@windriver.com, dianders@chromium.org, jslaby@suse.com, linux@armlinux.org.uk, linux-kernel@vger.kernel.org, Sumit Garg Subject: [PATCH 4/7] serial: kgdb_nmi: Add support for interrupt based fallback Date: Mon, 22 Jun 2020 19:56:21 +0530 Message-Id: <1592835984-28613-5-git-send-email-sumit.garg@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1592835984-28613-1-git-send-email-sumit.garg@linaro.org> References: <1592835984-28613-1-git-send-email-sumit.garg@linaro.org> Sender: linux-serial-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org From: Daniel Thompson Add a generic NMI fallback to support kgdb NMI console feature which can be overridden by arch specific implementation. This common fallback mechanism utilizes kgdb IO based interrupt in order to support entry into kgdb if a user types in kgdb_nmi_magic sequence. So during NMI console init, NMI handler is installed corresponding to kgdb IO based NMI which is invoked when a character is pending and that can be cleared by calling @read_char until it returns NO_POLL_CHAR. Signed-off-by: Daniel Thompson Co-developed-by: Sumit Garg Signed-off-by: Sumit Garg --- drivers/tty/serial/kgdb_nmi.c | 47 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 7 deletions(-) -- 2.7.4 diff --git a/drivers/tty/serial/kgdb_nmi.c b/drivers/tty/serial/kgdb_nmi.c index b32c6b1..2580f39 100644 --- a/drivers/tty/serial/kgdb_nmi.c +++ b/drivers/tty/serial/kgdb_nmi.c @@ -42,9 +42,46 @@ MODULE_PARM_DESC(magic, "magic sequence to enter NMI debugger (default $3#33)"); static atomic_t kgdb_nmi_num_readers = ATOMIC_INIT(0); static struct console *orig_dbg_cons; +static int kgdb_nmi_poll_one_knock(void); + +static irqreturn_t kgdb_handle_nmi(int irq, void *dev_id) +{ + int ret; + + if (kgdb_nmi_knock < 0) { + kgdb_breakpoint(); + return IRQ_HANDLED; + } + + ret = kgdb_nmi_poll_one_knock(); + if (ret == NO_POLL_CHAR) + return IRQ_NONE; + + while (ret != 1) { + ret = kgdb_nmi_poll_one_knock(); + if (ret == NO_POLL_CHAR) + return IRQ_HANDLED; + } + + kgdb_breakpoint(); + return IRQ_HANDLED; +} + static int kgdb_nmi_console_setup(struct console *co, char *options) { - arch_kgdb_ops.enable_nmi(1); + int res; + + if (arch_kgdb_ops.enable_nmi) { + arch_kgdb_ops.enable_nmi(1); + } else if (dbg_io_ops->request_nmi) { + res = dbg_io_ops->request_nmi(kgdb_handle_nmi, co); + if (res) { + pr_err("ttyNMI0: Cannot request nmi/irq\n"); + return res; + } + } else { + return -ENODEV; + } /* The NMI console uses the dbg_io_ops to issue console messages. To * avoid duplicate messages during kdb sessions we must inform kdb's @@ -328,9 +365,6 @@ int kgdb_register_nmi_console(void) { int ret; - if (!arch_kgdb_ops.enable_nmi) - return 0; - kgdb_nmi_tty_driver = alloc_tty_driver(1); if (!kgdb_nmi_tty_driver) { pr_err("%s: cannot allocate tty\n", __func__); @@ -380,9 +414,8 @@ int kgdb_unregister_nmi_console(void) { int ret; - if (!arch_kgdb_ops.enable_nmi) - return 0; - arch_kgdb_ops.enable_nmi(0); + if (arch_kgdb_ops.enable_nmi) + arch_kgdb_ops.enable_nmi(0); ret = unregister_console(&kgdb_nmi_console); if (ret)