From patchwork Fri Jul 17 06:20:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Garg X-Patchwork-Id: 235670 Delivered-To: patches@linaro.org Received: by 2002:a92:d244:0:0:0:0:0 with SMTP id v4csp1428463ilg; Thu, 16 Jul 2020 23:21:20 -0700 (PDT) X-Received: by 2002:a63:d02:: with SMTP id c2mr7274693pgl.338.1594966880563; Thu, 16 Jul 2020 23:21:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594966880; cv=none; d=google.com; s=arc-20160816; b=unx1smpddoRjNxORSyB31bSwVlPcHxkDU2T5i8whaLtr5t0uJ6pHeT2xXZHbVEOmph g7YEVkHQUNvgvTbeajqH2drgJUOfwewI/zwH4MlwUnWJBMT8ZgKGbluRS/Vaey/gLQe3 R9Fpgn6jMdlVEyL3ETiKAxSb8V2ZUVZ8SAR5NRXKCT7x5NYkiH16HVFd81qeATD7fYkO TfSC+/JA3FbzngEwyy0vtOnVLVTin/dmCBGDpARCMTD610EgabCs4YuZbVUNi/X3kS8b vW+TXMa+zBghesthAgWxmaGHrvcEyULnsvBPPeioIOKHUGD2AKbHpzs6eSg4Fnh/sHix pZcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:dkim-signature; bh=Rx1jyX2OghzR80dqhEJSX2n5nm+7iul/iZfPX4kvhjA=; b=iQK9MbI7reY3nzpTXtzjulq5n21G3YubGntCiqEvpbofBQUNwA3Fiff+nDa4FRqn+7 uiCMhJ55ZtShaCQMntGq8cvV/03Z6KV90J0aXBzzzpZTOYKgPMIdNFZNThLkx1x/4PTc lbZyUjf2il7RZXmd2XurU6N9MLvbaw062omY0oX99iayvq+R42eHxmNwZlbe99l9TrU3 7PAAQeszX1O5rJi+uUwiXIyQoKAWMsHoirfIWJoz+z1F6oLNsHH9dIrSgrBsvIw2flg2 OrLU1kVfX5y1dvIpSlvHFL0mXQtZfaNO9kjn2h7ZGc8EOsvG06zLZqa8QbF9izID0DWk fI0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zMhYbgdb; spf=pass (google.com: domain of sumit.garg@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=sumit.garg@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id mw7sor2925288pjb.35.2020.07.16.23.21.20 for (Google Transport Security); Thu, 16 Jul 2020 23:21:20 -0700 (PDT) Received-SPF: pass (google.com: domain of sumit.garg@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zMhYbgdb; spf=pass (google.com: domain of sumit.garg@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=sumit.garg@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=Rx1jyX2OghzR80dqhEJSX2n5nm+7iul/iZfPX4kvhjA=; b=zMhYbgdbXw2ARw9Q/wbAHV5BexmiPTLLJm5cdBQO0o+36WynT08/mKy1D+CWiTB/X/ 2AXhnEUM0qZiPmp361Ktx6PrRoRVx7DODrS3XE3yjzP9ZAcFeZST1kUcMZVboeUn9uZ0 09v7pikOfoVe6c/U0WtFKXvJKe8WCSpSED+M275W2IMUrKy8bUDLtvFTjPCo8axGYHl1 OwsW5V9H/7niv4oAnxhraRNWFI07e2wCvfnAleTtosbfZW6oCdp9DwuP0EXG2R9su86U C2mEfZ3L5tZ7/0kg7qnHZOptO5b7TXy6d55qKrLDgQpJ8BefXYcmX+tAnzDlrdLMpuCj hJeg== 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=Rx1jyX2OghzR80dqhEJSX2n5nm+7iul/iZfPX4kvhjA=; b=ZNIk61YY0h8nrjfXoXjcuKqF0PyQoOr4UzN8A+FLpEZjxjCHCzEiLH0uBONaeXduhG N3its5bReKgrQW4J4K2FUBfztBxrL1GQymso1DLlSylcSjPtTR0U3Nnb5DVMfY7Iioax iFSbMdVB+RoC2oHYEmfxbw3oEvdGWrpoCUlQbGWbisbHwfNMpnEchSzCpytp0dVCYm6I UdxS70dsALUHKRhOzIV5KmIk1LTyXd1IH8EVedIuiZwr2+wPKMaI3QkgotWrxUlB1Vu+ qa24wZtv343/8fH4GDwKVNYOV76ly8aucVgpcHVswiGPO9NMXo9QfHf5ADPs7iUxWXef 9G1A== X-Gm-Message-State: AOAM533FEwc4lzHmRV3PihVBlOy1Xip3DWKat9yus+5vwnIve17BTwg/ 7oHFxXq38lDtrkuofXR7YcHgtVwf X-Google-Smtp-Source: ABdhPJyNFkcfS38KAR/p0FmqnDNoDuEOb1/0rifeFyrPefxMSDVH6kRlBeKnj6jgvtNOkJGvgwf+9g== X-Received: by 2002:a17:90a:2069:: with SMTP id n96mr8972408pjc.213.1594966880007; Thu, 16 Jul 2020 23:21:20 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([117.210.211.74]) by smtp.gmail.com with ESMTPSA id b4sm6630466pfo.137.2020.07.16.23.21.16 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Jul 2020 23:21:19 -0700 (PDT) From: Sumit Garg To: daniel.thompson@linaro.org Cc: patches@linaro.org, Sumit Garg Subject: [RFC INTERNAL v3 0/4] Introduce NMI aware serial drivers Date: Fri, 17 Jul 2020 11:50:53 +0530 Message-Id: <1594966857-5215-1-git-send-email-sumit.garg@linaro.org> X-Mailer: git-send-email 2.7.4 Motivation: ----------- The major driver for this work has been the prior efforts around the NMI/FIQ debugger which is pretty well described here [1]. Also, there is an existing kgdb NMI serial driver which provides partial implementatation in upstream to have 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 now 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 do a magic sysrq in NMI context rather than in normal IRQ context and hence drop into kernel debugger in NMI context. [1] https://www.linaro.org/blog/debugging-arm-kernels-using-nmifiq/ Use-cases: ---------- The major use-case is to enhance kernel debugging capabilities to debug scenarios such as: - Primary CPU is stuck in deadlock with interrupts disabled and doesn't honour serial device interrupt. So having sysrq running in NMI context is helpful for debugging. - Always enabled NMI based magic sysrq irrespective of whether the serial TTY port is active or not. - Leverage kgdb capabilities in NMI context. 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 NMI unsafe 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. 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 I do look forward to your comments and feedback. Changes since RFC v2: - Added/updated cover-letter and commit descriptions. - Keep serial core NMI feature under CONFIG_CONSOLE_POLL. - Removed misc. redundant checks. - Used container_of() instead of a backlink. Changes since RFC v1: - Switch TX to be NMI driven rather than poolling mode. - Move common NMI framework bits to serial core. - Make uart_handle_sysrq_char() and uart_handle_break() NMI safe. - Correct poll_init() initialization sequence. - Misc. comments. - Regaring NMI alloc API, I thought about moving it to serial core but then after looking at it more closely there seems to be multiple serial driver specific bits like NMI handler, name, device ID which refrained me from moving it to serial core. But if you still think otherwise then I could just move it with aforementioned params as arguments. Sumit Garg (4): 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 polling mode drivers/tty/serial/amba-pl011.c | 236 ++++++++++++++++++++++++++++----------- drivers/tty/serial/serial_core.c | 120 +++++++++++++++++++- drivers/tty/sysrq.c | 33 +++++- include/linux/serial_core.h | 67 +++++++++++ include/linux/sysrq.h | 1 + kernel/debug/debug_core.c | 1 + 6 files changed, 390 insertions(+), 68 deletions(-) -- 2.7.4