Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp3047819ybt; Mon, 29 Jun 2020 13:53:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJymD49tHZBLnLRfibET9ToM8jyYfBC7W0j70rntvQXQXdZ6+/6XKju2wAsBdTHyMRyy2b/l X-Received: by 2002:a50:8186:: with SMTP id 6mr19954876ede.45.1593464023324; Mon, 29 Jun 2020 13:53:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593464023; cv=none; d=google.com; s=arc-20160816; b=j3/VKKJSK63zrYr26cdwz2mLsK04uMMbDqDPHlOt7jz3uiUlv1yJSGwEkR3bbSFSbQ jUdYLCta8SfGWaierP+h51VdPaKC09cuQADPNPHkUzHoYeUkqb9i0cIuoPRJonva9tz9 6BUtc1btT3DsTSyxDA16WUxE5Jz69EdYL8svKaVt0GIJbEgInXqGW/FS8TMKtMUQ167l 9pf13DIpWzgnddD6CxcFDju2PnajS++Q+9EUOWs+r/jcJz5pqw13G6SXRPuwhPvqoRie H7kkecLRaoa2rT4L6cjuF5vfiAi2jqOcdXNgNUmRosG9shRq4wPrW2HqGA2TF42Fzp8h yIvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=XGw/iLKNRAiVkZjoBpYpVGlTMGowb6J/RzcIqE9oUnc=; b=T+nOkkuU0cWeKfoU+0rX6qr6n1bSP+FqmQ7CSrrsM9JjcX4EW7hXg/RMxlLTpaFR5c WSWNnWV8PnJ0s2Gvg1mROxPXVe5W9JY3ZgXGbMsnYegZXDm8HxtjzG4dyMG+VOXZaL/8 jiiuq9xgKUXo+7J19ZxNwJJLYNgLSXHT0R011YO0TPOHAxxZIXtpHQtf+NPKc7mBTupK FHuTMd2PqYFDZOWIP+QWPUvNxCfTr/V1SSgYJDVSWJCQSha6CFjsdDzf1qoUzCurt9nI /iPa7+PEbwTuAJFf/yaugZK6oGWUKmK/NoSMUy6ZUb9GuBp55VWYBe56q/e4ykpqrEN1 Gxng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rS5h5EDV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-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 o6si343793edq.450.2020.06.29.13.53.20; Mon, 29 Jun 2020 13:53:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=rS5h5EDV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-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 S2389870AbgF2UwI (ORCPT + 99 others); Mon, 29 Jun 2020 16:52:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43380 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731375AbgF2TN1 (ORCPT ); Mon, 29 Jun 2020 15:13:27 -0400 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D435CC0068FB for ; Mon, 29 Jun 2020 04:45:04 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id b6so16191824wrs.11 for ; Mon, 29 Jun 2020 04:45:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=XGw/iLKNRAiVkZjoBpYpVGlTMGowb6J/RzcIqE9oUnc=; b=rS5h5EDVXcM6nddGacPz/Nj3KgrOPH0q0nYOztg+J1s+b0tDo9soLUxF+5ac5OLI08 4pj4d8PGVhb2QpuWHGjPLdHrKX0AJKO5kd4h+mlDscVYvZ+wmgjgPcaGK+I6f94mzM4l fb7mw0e8YVatfs/UV5KEfnEtOEVMtAaikz8UK4gdg/86d82CkVVrazsC2z8uZG7CUXUZ niM55Y4S1aOeUjTWaFRV7epBvRNNInwxRoJNp/+oJDa1DqvxWLK+V7ia1o54br2dUWjk r2bBnqELUcWJVWzHCzsw9/yfgbDJJaiY6No8zpA3wSx7ZRHXQyrZbqiOr9LQIvxuxb/V Q9Pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=XGw/iLKNRAiVkZjoBpYpVGlTMGowb6J/RzcIqE9oUnc=; b=sLpBb/NcFJyu4MVOEuDEQuGyCVFEVFJ0+6cz/c/QH7QU+jO1TiZgZzDita3lmPMoF4 jV+uUt+yP3ed/8PtN/tBkZ6IfJUvytNmhHZ6bOrm3G50v+lKgA8aEWbAKRZq95qoLmmE MGL/oe7asTiH9zC3VUrJbGwzQBAtzH1HL8RJPOsxsK53f2BBiNUjeat2cgXZXlL969m4 j1goZkGTxP3uxhYqxZqhfKssUWqHfig7iuxVJKN87EfGDPfqD2NpjDU4qfvzd5wdrE6l fR0dxSYLbh+R/R/dqpfHY2GNJ2VCMAsg9f8HoPUWuSiQDRjC08qOXCkPxie/zYGsJ2N7 Uqwg== X-Gm-Message-State: AOAM531i5EOShdklP+JnzxbJf19cSChu3XAmTvgqPVsDfe41rHJPdlJP UBcLoNYg5ZizR39UFj/7Jeb/1Q== X-Received: by 2002:adf:c142:: with SMTP id w2mr15839442wre.337.1593431103458; Mon, 29 Jun 2020 04:45:03 -0700 (PDT) Received: from holly.lan (cpc141214-aztw34-2-0-cust773.18-1.cable.virginm.net. [86.9.19.6]) by smtp.gmail.com with ESMTPSA id s10sm17859915wme.31.2020.06.29.04.45.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jun 2020 04:45:02 -0700 (PDT) Date: Mon, 29 Jun 2020 12:45:01 +0100 From: Daniel Thompson To: Doug Anderson Cc: Sumit Garg , kgdb-bugreport@lists.sourceforge.net, linux-serial@vger.kernel.org, Greg Kroah-Hartman , Jason Wessel , Jiri Slaby , Russell King - ARM Linux admin , Linux Kernel Mailing List Subject: Re: [PATCH 3/7] kgdb: Add request_nmi() to the io ops table for kgdboc Message-ID: <20200629114501.7aq547dzo6o2abrt@holly.lan> References: <1592835984-28613-1-git-send-email-sumit.garg@linaro.org> <1592835984-28613-4-git-send-email-sumit.garg@linaro.org> <20200622160300.avgfhnfkpqzqqtsr@holly.lan> <20200623105934.wvyidi3xgqgd35af@holly.lan> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 26, 2020 at 12:44:15PM -0700, Doug Anderson wrote: > Hi, > > On Tue, Jun 23, 2020 at 3:59 AM Daniel Thompson > wrote: > > > > On Tue, Jun 23, 2020 at 02:07:47PM +0530, Sumit Garg wrote: > > > On Mon, 22 Jun 2020 at 21:33, Daniel Thompson > > > wrote: > > > > > + irq_set_status_flags(irq, IRQ_NOAUTOEN); > > > > > + res = request_nmi(irq, fn, IRQF_PERCPU, "kgdboc", dev_id); > > > > > > > > Why do we need IRQF_PERCPU here. A UART interrupt is not normally > > > > per-cpu? > > > > > > > > > > Have a look at this comment [1] and corresponding check in > > > request_nmi(). So essentially yes UART interrupt is not normally > > > per-cpu but in order to make it an NMI, we need to request it in > > > per-cpu mode. > > > > > > [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/kernel/irq/manage.c#n2112 > > > > Thanks! This is clear. > > > > > > > + if (res) { > > > > > + res = request_irq(irq, fn, IRQF_SHARED, "kgdboc", dev_id); > > > > > > > > IRQF_SHARED? > > > > > > > > Currrently there is nothing that prevents concurrent activation of > > > > ttyNMI0 and the underlying serial driver. Using IRQF_SHARED means it > > > > becomes possible for both drivers to try to service the same interrupt. > > > > That risks some rather "interesting" problems. > > > > > > > > > > Could you elaborate more on "interesting" problems? > > > > Er... one of the serial drivers we have allowed the userspace to open > > will, at best, be stone dead and not passing any characters. > > > > > > > BTW, I noticed one more problem with this patch that is IRQF_SHARED > > > doesn't go well with IRQ_NOAUTOEN status flag. Earlier I tested it > > > with auto enable set. > > > > > > But if we agree that both shouldn't be active at the same time due to > > > some real problems(?) then I can rid of IRQF_SHARED as well. Also, I > > > think we should unregister underlying tty driver (eg. /dev/ttyAMA0) as > > > well as otherwise it would provide a broken interface to user-space. > > > > I don't have a particular strong opinion on whether IRQF_SHARED is > > correct or not correct since I think that misses the point. > > > > Firstly, using IRQF_SHARED shows us that there is no interlocking > > between kgdb_nmi and the underlying serial driver. That probably tells > > us about the importance of the interlock than about IRQF_SHARED. > > > > To some extent I'm also unsure that kgdb_nmi could ever actually know > > the correct flags to use in all cases (that was another reason for the > > TODO comment about poll_get_irq() being a bogus API). > > I do wonder a little bit if the architecture of the "kgdb_nmi_console" > should change. I remember looking at it in the past and thinking it a > little weird that if I wanted to get it to work I'd need to change my > "console=" command line to go through this new driver and (I guess) > change the agetty I have running on my serial port to point to > ttyNMI0. Is that how it's supposed to work? Then if I want to do a > build without kgdb then I need to go in and change my agetty to point > back at my normal serial port? > > It kinda feels like a better way to much of what the driver does would be to: > > 1. Allow kgdb to sniff incoming serial bytes on a port and look for > its characters. We already have this feature in the kernel to a small > extent for sniffing a break / sysrq character. > > 2. If userspace doesn't happen to have the serial port open then > ideally we could open the port (using all the standard APIs that > already exist) from in the kernel and just throw away all the bytes > (since we already sniffed them). As soon as userspace tried to open > the port when it would get ownership and if userspace ever closed the > port then we'd start reading / throwing away bytes again. > > If we had a solution like that: > > a) No serial drivers would need to change. > > b) No kernel command line parameters would need to change. > > Obviously that solution wouldn't magically get you an NMI, though. > For that I'd presume the right answer would be to add a parameter for > each serial driver that can support it to run its rx interrupt in NMI > mode. ... or allow modal changes to the uart driver when kgdboc comes up? We already allow UART drivers to de-optimize themselves and use different code paths when polling is enabled so its not totally crazy ;-). > Of course, perhaps I'm just confused and crazy and the above is a > really bad idea. Thanks for bringing this up. Sumit and I were chatting last week and our discussion went in a similar direction (I think not exactly the same which is why it is good to see your thoughts too). Personally I think it comes down to how intrusive adding NMI support is to serial drivers. kgdb_nmi is rather hacky and feels a bit odd to enable. It is clearly intended to avoid almost all changes to the UART driver. On our side we have been wondering whether the serial core can add helpers to make it easy for a serial driver to implement an simple, safe but not optimal NMI implementation. Making it easy to have safety-first might make NMI more palatable. > Speaking of confused: is there actually any way to use the existing > kgdb NMI driver (CONFIG_SERIAL_KGDB_NMI) in mainline without out of > tree patches? When I looked before I assumed it was just me that was > outta luck because I didn't have NMI at the time, but I just did some > grepping and I can't find anyplace in mainline where > "arch_kgdb_ops.enable_nmi" would not be NULL. Did I miss it, or do we > need out-of-tree patches to enable this? Out-of-tree... If, after looking at other approaches, we do all agree to nuke kgdb_nmi then there shouldn't be much impediment (nor that many tears). Daniel.