Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp265482ybm; Thu, 28 May 2020 22:51:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz6VwYZQ/zjt969lqg97Ghed7p4LoxK56JY2u579gPa+IZWmpemnRSHd+mTS4V9Lrw6x2my X-Received: by 2002:a05:6402:1bc1:: with SMTP id ch1mr6744476edb.90.1590731477271; Thu, 28 May 2020 22:51:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590731477; cv=none; d=google.com; s=arc-20160816; b=FI/snJwvq2AVb3khtvbUiQpSciqy/Y7oW1Rr6HPvuEDc00UujnBIEgHg96vb8krow2 uyluIPoj3HR+aW8NmtyQeqCX0V5S/VJmZg1QVh8b0wL3mIE/b5vfxelA4u9Ih2VQBV/7 YzfWkmhgiS026cX0qtNpPswh5aFPUmHeOoM3q4/YFXyJK7SrJvQFduuRdYv0SBzwvC1w nqhUpFK+bZd3WNY+/8KaEC7VjoooxpeWMft/92R4UMN1OLkqMOZgTjVj/HovwAL43Vdj LHWiywzM751n6nQSyUd3feHFZOAJ65RMGK/5WKDVyoXVizpA2Y1mAujEhzelxCpEq/Am uKVQ== 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=1uVbFFVStB5c4phiwJ2viwNKkm/fPEp8ZAWXEnpfQC8=; b=tNzF5XYf7yz9CE19nG2yRegqt5vs59w2rfEEmOd+QLBsY/mgR4yfRYDZ+4nSEab759 ofYATlXnjS/lxWMvd01kX03M62Y9Skebh/NqAg3YJLwhWeZyQxvbl2mHoDOLOSn+qzps BcNYormoLwGp32EXo7TZSlYxCvuj0mts+zAoPTXDDtjueORnFi6pITiA+VJ/M0S90am3 TfOV3d0MycfzR6u86HwMExbUJbj9td9iOvY82HkR5PZ6Qr0R1g8eg7Kl3R7eTu44NEQS lWvVFtwRXWMI+egP9bbu8HgD9al7Dz4Aum2DgMnYlpNdQ9NPLgNnkXmCFuTuRtbBPLaO JfiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cjh1PibL; 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 d17si4675466eje.142.2020.05.28.22.50.53; Thu, 28 May 2020 22:51:17 -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=cjh1PibL; 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 S1726054AbgE2FqS (ORCPT + 99 others); Fri, 29 May 2020 01:46:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725355AbgE2FqS (ORCPT ); Fri, 29 May 2020 01:46:18 -0400 Received: from mail-lj1-x242.google.com (mail-lj1-x242.google.com [IPv6:2a00:1450:4864:20::242]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD128C08C5C6 for ; Thu, 28 May 2020 22:46:17 -0700 (PDT) Received: by mail-lj1-x242.google.com with SMTP id m18so1070145ljo.5 for ; Thu, 28 May 2020 22:46:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=1uVbFFVStB5c4phiwJ2viwNKkm/fPEp8ZAWXEnpfQC8=; b=cjh1PibL62d5fJAUTjBlkQsSL7zCsGTOMqk736jIfcWC1sG9LZqJEabmt3REI7veqF tN9Wz7UF34ddA06WkbiuwPboV0K7lqGseYo+JQc34MgOOzcboAnsvYmTKYmtO0vZSR2s FvRbAmGKYG54if9bPUjzF6/4VYV4vRYsvInbEtUpqTMdhjJdvJFfEqtm9YkYs/fXUNpR 1Dwst0XNB81qxZGK0p8WFWs52i2Jk22tiFu083B4vsLufEO6c6b+/6RpafXCOPhROt9E /h2a4pUhYwx3tMw72JV5RwIrdZpBQ1w8DBxyl6QgQcMJV/q7cowRocFd9lLiiLUV3fOm iTEw== 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=1uVbFFVStB5c4phiwJ2viwNKkm/fPEp8ZAWXEnpfQC8=; b=AUT9POIClkZtbW80xT+vyCWzy1mowzt20MUT9KgyZ9c1biODMVkD1spnstmfJz0/nf 8bt0qj21GUPqm26/SAjDE0kbNNpYLI6ZX/CFvffjcLhc9THe0PQ1am4pbpB3Se1uLF9R ZQQn8ulOCz6J2xmE2vMJkQshzymanPz1Y9LraPzrUwKQSULPzBKd+oK8zSxv4STZuKvm LXMG/24lOhmsY5J/yeSvFgnxEc1rEeqO7oiFh1YZGXLcfptFl9VtthDsBv89C4fXPtiA yfPPZpnk8m0A4WEqtca8u6oer/Ka2CnaGLJyLR8WXnkKsrZn6S/v8U/YJ7fk6IGVBZ7o DmEA== X-Gm-Message-State: AOAM532aykSXmgJrWBJNg/vUBiLxY3DbemehAsEnXTiRHza9WuQ5QDrb Bu2SrD83TLTNyddWPtO5md8oGWM8EAuYUCKB1L41Qw== X-Received: by 2002:a2e:2204:: with SMTP id i4mr3411851lji.110.1590731176287; Thu, 28 May 2020 22:46:16 -0700 (PDT) MIME-Version: 1.0 References: <1590560759-21453-1-git-send-email-sumit.garg@linaro.org> <1590560759-21453-5-git-send-email-sumit.garg@linaro.org> <20200527133115.x5hqzttsg73saiky@holly.lan> <20200528112620.a6zhgnkl2izuggsa@holly.lan> <20200528145721.GE11286@linux-b0ei> In-Reply-To: <20200528145721.GE11286@linux-b0ei> From: Sumit Garg Date: Fri, 29 May 2020 11:16:04 +0530 Message-ID: Subject: Re: [PATCH v3 4/4] kdb: Switch kdb_msg_write() to use safer polling I/O To: Petr Mladek Cc: Daniel Thompson , kgdb-bugreport@lists.sourceforge.net, Jason Wessel , Douglas Anderson , Sergey Senozhatsky , Linux Kernel Mailing List 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 On Thu, 28 May 2020 at 20:27, Petr Mladek wrote: > > On Thu 2020-05-28 12:26:20, Daniel Thompson wrote: > > On Thu, May 28, 2020 at 11:48:48AM +0530, Sumit Garg wrote: > > > On Wed, 27 May 2020 at 19:01, Daniel Thompson > > > wrote: > > > > > > > > On Wed, May 27, 2020 at 11:55:59AM +0530, Sumit Garg wrote: > > > > > In kgdb NMI context, calling console handlers isn't safe due to locks > > > > > used in those handlers which could lead to a deadlock. Although, using > > > > > oops_in_progress increases the chance to bypass locks in most console > > > > > handlers but it might not be sufficient enough in case a console uses > > > > > more locks (VT/TTY is good example). > > > > > > > > > > Currently when a driver provides both polling I/O and a console then kdb > > > > > will output using the console. We can increase robustness by using the > > > > > currently active polling I/O driver (which should be lockless) instead > > > > > of the corresponding console. For several common cases (e.g. an > > > > > embedded system with a single serial port that is used both for console > > > > > output and debugger I/O) this will result in no console handler being > > > > > used. > > > > > > > > > diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h > > > > > index b072aeb..05d165d 100644 > > > > > --- a/include/linux/kgdb.h > > > > > +++ b/include/linux/kgdb.h > > > > > @@ -275,6 +275,7 @@ struct kgdb_arch { > > > > > * for the I/O driver. > > > > > * @is_console: 1 if the end device is a console 0 if the I/O device is > > > > > * not a console > > > > > + * @tty_drv: Pointer to polling tty driver. > > > > > */ > > > > > struct kgdb_io { > > > > > const char *name; > > > > > @@ -285,6 +286,7 @@ struct kgdb_io { > > > > > void (*pre_exception) (void); > > > > > void (*post_exception) (void); > > > > > int is_console; > > > > > + struct tty_driver *tty_drv; > > > > > > > > Should this be a struct tty_driver or a struct console? > > > > > > > > In other words if the lifetime the console structure is the same as the > > > > tty_driver then isn't it better to capture the console instead > > > > (easier to compare and works with non-tty devices such as the > > > > USB debug mode). > > > > > > > > > > IIUC, you mean to say we can easily replace "is_console" with "struct > > > console". This sounds feasible and should be a straightforward > > > comparison in order to prefer "dbg_io_ops" over console handlers. So I > > > will switch to use "struct console" instead. > > > > My comment contains an if ("if the lifetime of the console structure is > > the same") so you need to check that it is true before sharing a patch to > > make the change. > > Honestly, I am not completely familiar with the console an tty drivers > code. > > Anyway, struct console is typically statically defined by the console > driver code. It is not must to have but I am not aware of any > driver where it would be dynamically defined. > Yes this is mine understanding as well. > On the other hand, struct tty_driver is dynamically allocated > when the driver gets initialized. > > So I would say that it is pretty safe to store struct console. Okay. > Well, you need to call con->device() to see if the tty_driver > is actually initialized. Agree and con->device() is already invoked here [1]. So we only need to store struct console if con->device() invocation returns success. [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/tty/serial/kgdboc.c#n174 -Sumit > > Best Regards, > Petr