From patchwork Tue Jul 21 12:10:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Garg X-Patchwork-Id: 11675581 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 58DD614E3 for ; Tue, 21 Jul 2020 12:12:33 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 32642206E9 for ; Tue, 21 Jul 2020 12:12:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="VPGimHB4"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="jcbCCb7h" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 32642206E9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:MIME-Version:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Owner; bh=7PH7SaTqc9mHpYaEYkzCK3gf1MGko4G7vjclu5wS0Fw=; b=VPGimHB4ca0UD96X0Vm5c0ibl2 tt7HKUnkLG3BETLk/qbikS+wsAfH8+j2KtLYhzMeSSa+/VWSL6QtruE3014fHwQLZqw+UITYqlHgl OM/wMMtIK4aroCa8dUSgc0AVMb1rr1ljlWqZqst58Ha5hUKuLmekpdpITjSUH7Vg3lqKkshRLM2ur aaNpFb8RW9rNQThIfz7USFiBfDAD28d2VgmXu1xfKs1KUXtGd168zG32rncZm9qrd/wRKXv5SSAPX 0StdMwbGs4r6A/kbnhWbryJGMFNBApnEU+uO1o7ot3/fjWFJ9JpC8fNQ3LDOVz8JqsoZ6E3BrtvWY iUUYH0jA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jxr6k-0000Jq-G8; Tue, 21 Jul 2020 12:10:54 +0000 Received: from mail-pj1-x1041.google.com ([2607:f8b0:4864:20::1041]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jxr6i-0000JF-04 for linux-arm-kernel@lists.infradead.org; Tue, 21 Jul 2020 12:10:52 +0000 Received: by mail-pj1-x1041.google.com with SMTP id o22so1583447pjw.2 for ; Tue, 21 Jul 2020 05:10:49 -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; bh=DUhxoUHdk/G5hcIoHHmedsybYx4YWFvLP5ZmToBFcQA=; b=jcbCCb7hQJlHIsdcZ51dQFHY/9ZAio9o8npqoAFikBjrRS5rSX8azSndpIfoxx4pB+ 36zJ9XHfNsZaRy7DSN1DP/aiQPS1wdywIz2HH7ZUeQPS9pMnDDMBFScXUX8tkATs9D3Q AgbIybVi4CKkW8frVqni9KeOc3TfJHu2wgPhSRbqmU1CzyLw2BnPvo3mq5J7vWHydhVG ykZd7ucwFth+Pedeigm9B3p8zNkoO+gfshaZ2vqKoy3ykznGytstafoT6n4A86ml+rYT oMyEtsd0jdPbtn+jYCfaazIcKecvvJ9MCT/0T4bbqk2TDYe3Ou5Vdbc5vVEP2p1XGntN aHHg== 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; bh=DUhxoUHdk/G5hcIoHHmedsybYx4YWFvLP5ZmToBFcQA=; b=nji0yCBbztoiuitQW+3Y6vCXtvpNPSYtebVoMQJQd6KfNasBrIC9Ek1bqOn2peWpxY ldLbnfagnxiIXWm+uPyY78Nv9gC/MGHdYH3nvZv5nMvC5BK6V96HOopSsCU2zN3n2qQS pLPsbgcZfZGcUlhfuOoiRcliDp0GFRWzEKOWPh7fXr76fJVCRmD2luuo8V19EZ69zjwP qzHOIVv0Pvk0qxfc8CyV8MY8X7ScyvhuwS+ZmdXcc457GK3elT5siE4LCXE6WU7RLQPJ T6HCwzx11ZIk0H4QRQSDYE62QEgGMOvSBZAbY1gGKGCeRplpLpTFXubPMNQvsPBsiMEO 5HbQ== X-Gm-Message-State: AOAM53219tbxqjGC0ZO9JvMd6Efz5Y53pHatUejSIZ+J58juAL1rkqD9 3IykQeKkWcfCM7tvkpguHofGjg== X-Google-Smtp-Source: ABdhPJyRExe3Qfy877FM+lq0KPlLWXAqsMqBIE5QqFOrqY5bkLpSCnvsNe2TWxlOTPk4HSLRIyix+g== X-Received: by 2002:a17:902:d698:: with SMTP id v24mr21585075ply.163.1595333447996; Tue, 21 Jul 2020 05:10:47 -0700 (PDT) Received: from localhost.localdomain ([117.210.211.74]) by smtp.gmail.com with ESMTPSA id w9sm20601992pfq.178.2020.07.21.05.10.42 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Jul 2020 05:10:47 -0700 (PDT) From: Sumit Garg To: gregkh@linuxfoundation.org, daniel.thompson@linaro.org, dianders@chromium.org, linux-serial@vger.kernel.org, kgdb-bugreport@lists.sourceforge.net Subject: [RFC 0/5] Introduce NMI aware serial drivers Date: Tue, 21 Jul 2020 17:40:08 +0530 Message-Id: <1595333413-30052-1-git-send-email-sumit.garg@linaro.org> X-Mailer: git-send-email 2.7.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200721_081052_052140_90FB6517 X-CRM114-Status: GOOD ( 16.33 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:1041 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sumit Garg , jslaby@suse.com, linux-kernel@vger.kernel.org, linux@armlinux.org.uk, jason.wessel@windriver.com, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Make it possible for UARTs to trigger magic sysrq from an NMI. With the advent of pseudo NMIs on arm64 it became quite generic to request serial device interrupt as an NMI rather than IRQ. And having NMI driven serial RX will allow us to trigger magic sysrq as an NMI and hence drop into kernel debugger in NMI context. The major use-case is to add NMI debugging capabilities to the kernel in order to debug scenarios such as: - Primary CPU is stuck in deadlock with interrupts disabled and hence doesn't honor serial device interrupt. So having magic sysrq triggered as an NMI is helpful for debugging. - Always enabled NMI based magic sysrq irrespective of whether the serial TTY port is active or not. Currently there is an existing kgdb NMI serial driver which provides partial implementation in upstream to have a separate ttyNMI0 port but that remained in silos with the serial core/drivers which made it a bit odd to enable using serial device interrupt and hence remained unused. It seems to be clearly intended to avoid almost all custom NMI changes to the UART driver. But this patch-set allows the serial core/drivers to be NMI aware which in turn provides NMI debugging capabilities via magic sysrq and hence there is no specific reason to keep this special driver. So remove it instead. Approach: --------- The overall idea is to intercept serial RX characters in NMI context, if those are specific to magic sysrq then allow corresponding handler to run in NMI context. Otherwise, defer all other RX and TX operations onto IRQ work queue in order to run those in normal interrupt context. This approach is demonstrated using amba-pl011 driver. Patch-wise description: ----------------------- Patch #1 prepares magic sysrq handler to be NMI aware. Patch #2 adds NMI framework to serial core. Patch #3 and #4 demonstrates NMI aware uart port using amba-pl011 driver. Patch #5 removes kgdb NMI serial driver. Goal of this RFC: ----------------- My main reason for sharing this as an RFC is to help decide whether or not to continue with this approach. The next step for me would to port the work to a system with an 8250 UART. Usage: ------ This RFC has been developed on top of 5.8-rc3 and if anyone is interested to give this a try on QEMU, just enable following config options additional to arm64 defconfig: CONFIG_KGDB=y CONFIG_KGDB_KDB=y CONFIG_ARM64_PSEUDO_NMI=y Qemu command line to test: $ qemu-system-aarch64 -nographic -machine virt,gic-version=3 -cpu cortex-a57 \ -smp 2 -kernel arch/arm64/boot/Image -append 'console=ttyAMA0,38400 \ keep_bootcon root=/dev/vda2 irqchip.gicv3_pseudo_nmi=1 kgdboc=ttyAMA0' \ -initrd rootfs-arm64.cpio.gz NMI entry into kgdb via sysrq: - Ctrl a + b + g Reference: ---------- For more details about NMI/FIQ debugger, refer to this blog post [1]. [1] https://www.linaro.org/blog/debugging-arm-kernels-using-nmifiq/ I do look forward to your comments and feedback. Sumit Garg (5): tty/sysrq: Make sysrq handler NMI aware serial: core: Add framework to allow NMI aware serial drivers serial: amba-pl011: Re-order APIs definition serial: amba-pl011: Enable NMI aware uart port serial: Remove KGDB NMI serial driver drivers/tty/serial/Kconfig | 19 -- drivers/tty/serial/Makefile | 1 - drivers/tty/serial/amba-pl011.c | 232 +++++++++++++++++------- drivers/tty/serial/kgdb_nmi.c | 383 --------------------------------------- drivers/tty/serial/kgdboc.c | 8 - drivers/tty/serial/serial_core.c | 120 +++++++++++- drivers/tty/sysrq.c | 33 +++- include/linux/kgdb.h | 10 - include/linux/serial_core.h | 67 +++++++ include/linux/sysrq.h | 1 + kernel/debug/debug_core.c | 1 + 11 files changed, 386 insertions(+), 489 deletions(-) delete mode 100644 drivers/tty/serial/kgdb_nmi.c