Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp903638ybz; Fri, 1 May 2020 10:38:16 -0700 (PDT) X-Google-Smtp-Source: APiQypLzPG7qpF1h7xhU3PlKfGlr6Fwi1xS3e2QV+he+D3OVDNrRPzqcFG6lYzv3DX6vsDpoOog1 X-Received: by 2002:aa7:df8d:: with SMTP id b13mr4610366edy.145.1588354696386; Fri, 01 May 2020 10:38:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588354696; cv=none; d=google.com; s=arc-20160816; b=ZL6FoqnuDmeCeqbvg8j3UfHHfygyW9+NHvEOtdyB+svths8Ny7wvSfVFA/INbGrR9o ELOTgodnA++ymxSh9sGenDt+b+ZLtiGnQze6QK9S+eNTopJzS32DSt/Lpa0MpLylen2h uoEATGi/HnKrN/0YJedPSbUmDM14/uYhHhRTXX8i12mRDngsQ0im9b7gHBuhujzVnfAK VzaOwBmJDw1Qw03pn+pjY+TO/6BV5biwRPJbsT/OX4fg036tp9UqCixeuP4dXldOUrex zmq/tTYUhljI4lFJLAW5KOfHwLzbE2/w7REZFGQUJtK6OX7VT3WUdn0HxZV+rkT4UbUY 8zpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=TA6stwlQtMs0s5sdi3+tZ1ygYla8dV/bmC8ohmequGA=; b=wdhJ1mgnC1A0RLinA4XvPzMK1KW8lScvmXuU0e4uiMthvweQEs71wsB27HzOBVQaR5 Xw3Hg7x6stIR45R4+OgrsadxdeGp6IxgAL5IT2jQtUx2atVj+SCFdVkx4f0r0h7eiaMn Lsam4AHz5/gXFS65HlvmlUMqTJeinsQZCWfZTtjWmrsw24w2IIBIERzXOc6o4i75J8i3 ctk221gY7WOhwz7NER8adZNO7+Bbxgnu3jP4Ga6FVyW/wi2sjuldyr73Uobnf64ZDO/v vGzYDSeNppDCWNRaDdjozI4bxQoO3vUCZLRzCDM8+JKZEbOiw0px8Yrx6f14Zd8yy05Q op/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="KBM/6NPc"; 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=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a7si2055289edb.221.2020.05.01.10.37.53; Fri, 01 May 2020 10:38:16 -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=@chromium.org header.s=google header.b="KBM/6NPc"; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729998AbgEARg3 (ORCPT + 99 others); Fri, 1 May 2020 13:36:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1729659AbgEARg2 (ORCPT ); Fri, 1 May 2020 13:36:28 -0400 Received: from mail-vk1-xa44.google.com (mail-vk1-xa44.google.com [IPv6:2607:f8b0:4864:20::a44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6EBDC061A0C for ; Fri, 1 May 2020 10:36:28 -0700 (PDT) Received: by mail-vk1-xa44.google.com with SMTP id g129so2852088vkh.9 for ; Fri, 01 May 2020 10:36:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=TA6stwlQtMs0s5sdi3+tZ1ygYla8dV/bmC8ohmequGA=; b=KBM/6NPcoPyp2XNp6JUEX0Xt3PKjJ4OeWDSYAI2ClnarZon9yxFPFl0VQ1Z9H+zyGX 7H7FRh2pe/8P19+PEzHcCgj2mDQkmWTZTnHkastnytPBWT6e2Zv/spgFa23CPQY0iA4z tkPgdfzL0pxE3paW1H2UbOMPQjNB308rhBS6E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=TA6stwlQtMs0s5sdi3+tZ1ygYla8dV/bmC8ohmequGA=; b=DluubVNxhkxExWIKwOTGLcpN/U6NehrYuDD6DEOfJUNlzXpM9VzuEbYWAuYmvCE2oo DOokd5vX888MHKFqPpRvEXJRZZGtARMg0TVw/p8fec61B3YMRVKIAHnAHBk0cWzDEqbu nCd7hpzAFHxtlT3N7yM1928UQTrCgzY6vklppCvVnhglb6cmndiQzBkHwIPvEu0Ian3D Ar4L/HDtLOufUh2kkkyvLp8qG4gktoOucnsSyttuL8K96oHHYxYMFmZlF8NFFOmv1fDH wGh3/Fd28Ph9YfUXXYcykw1e5BIzt/MZ5ePGhq11lP+xzXD+U27Wy5RmvjTDR+SUKI9y 1uYg== X-Gm-Message-State: AGi0PuZPfhYhWjc5kTYHr2xzjGFyVuoDfhPm+6gjCDVH2MRY7d0STtIW jmu5RPgp/deGLCTPMxYJGXy+dQ3GYws= X-Received: by 2002:a1f:8dcd:: with SMTP id p196mr3680151vkd.64.1588354587398; Fri, 01 May 2020 10:36:27 -0700 (PDT) Received: from mail-ua1-f45.google.com (mail-ua1-f45.google.com. [209.85.222.45]) by smtp.gmail.com with ESMTPSA id b204sm950183vkb.17.2020.05.01.10.36.26 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 01 May 2020 10:36:26 -0700 (PDT) Received: by mail-ua1-f45.google.com with SMTP id s5so3997598uad.4 for ; Fri, 01 May 2020 10:36:26 -0700 (PDT) X-Received: by 2002:a9f:27ca:: with SMTP id b68mr3831812uab.8.1588354586095; Fri, 01 May 2020 10:36:26 -0700 (PDT) MIME-Version: 1.0 References: <20200430095819.1.Id37f71c69eb21747b9d9e2c7c242be130814b362@changeid> <20200501114943.ioetuxe24gi27bll@holly.lan> <20200501133202.GA2402281@wychelm.lan> In-Reply-To: <20200501133202.GA2402281@wychelm.lan> From: Doug Anderson Date: Fri, 1 May 2020 10:36:14 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] kgdboc: Be a bit more robust about handling earlycon leaving To: Daniel Thompson Cc: Jason Wessel , Sumit Garg , Greg Kroah-Hartman , Jiri Slaby , kgdb-bugreport@lists.sourceforge.net, LKML , linux-serial@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Fri, May 1, 2020 at 6:32 AM Daniel Thompson wrote: > > On Fri, May 01, 2020 at 12:49:43PM +0100, Daniel Thompson wrote: > > On Thu, Apr 30, 2020 at 09:59:09AM -0700, Douglas Anderson wrote: > > > The original implementation of kgdboc_earlycon included a comment > > > about how it was impossible to get notified about the boot console > > > going away without making changes to the Linux core. Since folks > > > often don't want to change the Linux core for kgdb's purposes, the > > > kgdboc_earlycon implementation did a bit of polling to figure out when > > > the boot console went away. > > > > > > It turns out, though, that it is possible to get notified about the > > > boot console going away. The solution is either clever or a hack > > > depending on your viewpoint. ...or, perhaps, a clever hack. All we > > > need to do is head-patch the "exit" routine of the boot console. We > > > know that "struct console" must be writable because it has a "next" > > > pointer in it, so we can just put our own exit routine in, do our > > > stuff, and then call back to the original. > > > > I think I'm in the hack camp on this one! > > > > > > > This works great to get notified about the boot console going away. > > > The (slight) problem is that in the context of the boot console's exit > > > routine we can't call tty_find_polling_driver(). > > > > I presume this is something to do with the tty_mutex? > > > We solve this by > > > kicking off some work on the system_wq when we get notified and this > > > works pretty well. > > > > There are some problems with the workqueue approach. > > ... so did a couple of experiments to avoid the workqueue. > > It occured to me that, since we have interfered with deinit() then the > console hasn't actually been uninitialized meaning we could still use it. > This does exposes us to risks similar to keep_bootcon but in exchange > there is no window where kgdb is broken (and no need to panic). > > My prototype is minimal but I did wonder about ripping out all the > code to defend against removal of the earlycon and simply keep the > earlycon around until a new kgdbio handler is installed. It took me a little while, but I finally see what you're saying. You're saying that we keep calling into the boot console even though it's no longer in the list of consoles. Then we temporarily disable the boot console's exit routine until kgdb_earlycon() is done. (side note: the exit routine was recently added and probably most consoles don't use it). OK, that doesn't seem totally insane. It actually works OK for you? It's probably at least worth a warning in the log if we detect that we're using the boot console and it's not in the console list anymore. Then if kgdb starts misbehaving someone might have a clue. If your solution is OK we might also want to remove the call to cleanup_earlycon_if_invalid() in configure_kgdboc() too. I think you might win the "hackiest solution" prize, but your solution definitely does seem better because I can't think of any other good way to handle people whose consoles register a long time before their tty. ;-) -Doug