Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp356770ybg; Wed, 3 Jun 2020 02:35:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyDYvCbxcLwGexwlECqO6YA9x0dwJveznW3cpcs/o/T8G1HstXn/RuJGBM4btCvg/iY4eeD X-Received: by 2002:aa7:cd42:: with SMTP id v2mr5339512edw.360.1591176902634; Wed, 03 Jun 2020 02:35:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591176902; cv=none; d=google.com; s=arc-20160816; b=rlONtwWpdLVI6Iu4TVZWp2z8/lEX7LCzORPSfASs5cj2TCjxg+DkA0u+dtDEOBy82w mqg5mLQ1hhxpQ8Mx/LVZUYoaqqa1mWJVH9if5XF1h/F/duldvRfAEjJwuS3iOu+Nqaqh Lj1A/lU78qtzJY7P1172xOqGQsd2jh+Oq9Wp/5aaxbDvEPvCxahDGxdDNff0WjwAjdWz qkatvy+U7VbD3hAuGEUY2Pp/fgvyhK8DFb9RuuyNUL2/7lJTbRfcWxWi//oUjriC35c+ H6l9jSBGNK8shAVRvkpccit7EX5LfQrMZn9vTQeJPNgLFVM/fwRv+zq6t5DYSs6Ty1nN nGIA== 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=4f1Cyl0YeI3L9KPObQmKLYBSMli65+QxBgDMxC3xLDI=; b=B12uLQhb+uGsMwkXyNlGy7EZHI38TDdW8U9psRE4HIZmJpirw9lCn4msO0eKio0/Ed IHbdZXg8Nf/9iKjvom50euxSwHezsgKVzOOrQf1YEkz/9CWO+YCLaRZQqNo8Spo+mgRc mtd6VfXhT3TVdHsDKnnqcmf5+kGcDN+vwy4DRG7kSnhQcuuyIf3UtU946+G61vVRGCNO K3tHcQI/XzPeWW5fO//F1H9igbCSK2fuERYq0/ownpcqJ+kpwagaxWkkCQ+TRmF1/Ux3 1/2nnlNwelbB9PV/i0DfdGGpNZTrWZfxig73qXns3VYUDi84F4iLqyUAOHYJJGtw23Ss eh6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WFyguRK5; 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 a9si825140edm.76.2020.06.03.02.34.39; Wed, 03 Jun 2020 02:35:02 -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=WFyguRK5; 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 S1726360AbgFCJcR (ORCPT + 99 others); Wed, 3 Jun 2020 05:32:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725854AbgFCJcQ (ORCPT ); Wed, 3 Jun 2020 05:32:16 -0400 Received: from mail-lf1-x142.google.com (mail-lf1-x142.google.com [IPv6:2a00:1450:4864:20::142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F33E9C05BD43 for ; Wed, 3 Jun 2020 02:32:15 -0700 (PDT) Received: by mail-lf1-x142.google.com with SMTP id e125so894747lfd.1 for ; Wed, 03 Jun 2020 02:32:15 -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=4f1Cyl0YeI3L9KPObQmKLYBSMli65+QxBgDMxC3xLDI=; b=WFyguRK5TZF/ig1HlfEo56DPZl6QsdgRHwyzME5BE9Cnyzh2Tin6y4QU1grNXFyGi7 N+BBHNjCVoSyp0epO1PvM0r3VVWE7M7b3aV4cyAxiVaeYZy4V/JpEMw0p/Vk+ZX/cMsR 6Pfhxh2sdhOnCKXfTurwp8zJiRYQTtHBFCIwwvWuFCPGTgHDFHJtdlwVC5Qf4zMdhBn+ KCtZHx9z/kFQYyABvuuX+NuXAWMJ/Bbe32m618ClyK4WM9RDLFndtES3lvMWfl435RkJ cozY/g85V6O70ZfWKJYXXrw/Kmi6KNj4Golqm2vioeoIO20wEANgjNEx9INwfPOg6ujn 91cw== 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=4f1Cyl0YeI3L9KPObQmKLYBSMli65+QxBgDMxC3xLDI=; b=N3PoFyWP4uOE5c5/opZkDIsYTK6ysqv53D+fEx0q+s1SRKMbLl5tr4T/ATgkbHE+SK wtJrtDzVtllrR5TTyqtb6nRlPFiwkFA8GSAKUUkjAGT5lYFuJ08CmIABOb8sM2o3BdET kkDgEXis1IQn5oeUjKk+W4glOYZIU2pKg4KwiI0Ex/nd104e5ONfwLjJNiL1Q+0Dzkxf kTBJGKymj06DzBlxq6tPxlaZEnkrxKl8qEkHVDBWY+Bya/9o0xaqZGB5qC3phQrLz/jw JtGdowU/dQjxDWKCawMh2cWLToY2AZU8ZulZilgnlOUfR+rWBC53mfaGaEmjwP/3LVca cMKQ== X-Gm-Message-State: AOAM533nReB+fOgG0b65fjQQgIvJaXwiIX0ueJkIoJSHQaEXjOuqpm6p eIT9ivkUM1ZAhhVgOg0zrioDt3X53q2t2SSqlqJP1Q== X-Received: by 2002:ac2:41d4:: with SMTP id d20mr2002613lfi.204.1591176734387; Wed, 03 Jun 2020 02:32:14 -0700 (PDT) MIME-Version: 1.0 References: <1591168935-6382-1-git-send-email-sumit.garg@linaro.org> <1591168935-6382-5-git-send-email-sumit.garg@linaro.org> <20200603082503.GD14855@linux-b0ei> In-Reply-To: <20200603082503.GD14855@linux-b0ei> From: Sumit Garg Date: Wed, 3 Jun 2020 15:02:02 +0530 Message-ID: Subject: Re: [PATCH v5 4/4] kdb: Switch to use safer dbg_io_ops over console APIs To: Petr Mladek Cc: Daniel Thompson , kgdb-bugreport@lists.sourceforge.net, Jason Wessel , Douglas Anderson , Sergey Senozhatsky , Greg Kroah-Hartman , Jiri Slaby , 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 Wed, 3 Jun 2020 at 13:55, Petr Mladek wrote: > > On Wed 2020-06-03 12:52:15, Sumit Garg wrote: > > In kgdb context, calling console handlers aren't safe due to locks used > > in those handlers which could in turn 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. > > > > In order to achieve this we need to reverse the order of preference to > > use dbg_io_ops (uses polling I/O mode) over console APIs. So we just > > store "struct console" that represents debugger I/O in dbg_io_ops and > > while emitting kdb messages, skip console that matches dbg_io_ops > > console in order to avoid duplicate messages. After this change, > > "is_console" param becomes redundant and hence removed. > > > > diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c > > index 4139698..6e182aa 100644 > > --- a/drivers/tty/serial/kgdboc.c > > +++ b/drivers/tty/serial/kgdboc.c > > @@ -558,6 +557,7 @@ static int __init kgdboc_earlycon_init(char *opt) > > } > > > > earlycon = con; > > + kgdboc_earlycon_io_ops.cons = con; > > pr_info("Going to register kgdb with earlycon '%s'\n", con->name); > > if (kgdb_register_io_module(&kgdboc_earlycon_io_ops) != 0) { > > earlycon = NULL; > > Should we clear kgdboc_earlycon_io_ops.cons here when > kgdb_register_io_module() failed? > AFAIK, kgdboc_earlycon_io_ops won't be used at any later stage in case registration fails. So IMO, it would be a redundant assignment unless I missed something. -Sumit > > diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h > > index c62d764..529116b 100644 > > --- a/include/linux/kgdb.h > > +++ b/include/linux/kgdb.h > > @@ -276,8 +276,7 @@ struct kgdb_arch { > > * the I/O driver. > > * @post_exception: Pointer to a function that will do any cleanup work > > * 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 > > + * @cons: valid if the I/O device is a console; else NULL. > > */ > > struct kgdb_io { > > const char *name; > > @@ -288,7 +287,7 @@ struct kgdb_io { > > void (*deinit) (void); > > void (*pre_exception) (void); > > void (*post_exception) (void); > > - int is_console; > > + struct console *cons; > > Nit: I would call it "con". The trailing 's' makes me feel that that the > variable points to an array or list of consoles. > > > }; > > > > Otherwise, it looks pretty straightforward. > > Best Regards, > Petr