Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2449732ybl; Thu, 19 Dec 2019 13:57:10 -0800 (PST) X-Google-Smtp-Source: APXvYqwwcvF9Vgs/E/QWEx/dUCQPqfMpHlw+lDMobJCXjN5COweyBrGOpl26wobZf68tEtd1B7Bl X-Received: by 2002:a05:6830:22ee:: with SMTP id t14mr10828621otc.236.1576792630059; Thu, 19 Dec 2019 13:57:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576792630; cv=none; d=google.com; s=arc-20160816; b=iMeaq6Y3lZeCy7n5q9kZcmEr0AgbMCw6FRAxnSlz4BWs2iBVGXFILSEeZS1mt5yNsH fsZ/s7si7Z0lQGIN/e9COc1TZKOT7n/j5ARjR19uQRdJYYzbGeEFhKiFVOT2wuF7MPGw Aoe5uqwOTH9EgQe7L5uBaLre9MXqbwBCI0JynDnCusy528HPCdAjjBXRV6Mb70SGKNDQ TomzDocOhzCySHNeNlh1hZXBsea01o1xrgd09am/Q0nGtV97OWuVDMkIxP+E6lJ6Ql9v eKqA5J5K75BbX9FwC+OWXZGudCcrdF534e7SFaM9CdP6oWnuZ0s3EPDa4oE0zMq4XGUd pO5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:date:cc:to:from:subject:message-id; bh=SbGfmWodWKZ6C+zFry7VYan2Lf8HOIBz14hdzrtSUpc=; b=h85RdICD0d4INiJl7CdcEW0Lbxn+ZSmJPUDMLbJg7kz1YPIjANp5Z7edzJqQ8G7NpQ TT+i9/1gS63/XfrmG+bK0CxwtvBIQEb7IFQ7iHnPyRYn1raSc7eLY8AnOk9a50lLCFEw wa9EPH9Nz+GuZL3NrV6hJwt/pxidRSN9hV8zJdvY5tXh34za9kkUGfGF/7uh+19cTeIr LnqemafbdndHdjb1OyMxa945G2SDcW6GiUUnd9qJreRL+34kEg2qbSYCxOWMJ2UcaRMz +yORMaJ8QQdy3q7mwsV8beQ38hBVNBZIwZj7i0yK+rkiH9s7DY7X4cA0tYgUVG6BSOP8 6UYw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o15si4139152otp.314.2019.12.19.13.56.58; Thu, 19 Dec 2019 13:57:10 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727105AbfLSVzO (ORCPT + 99 others); Thu, 19 Dec 2019 16:55:14 -0500 Received: from kernel.crashing.org ([76.164.61.194]:52706 "EHLO kernel.crashing.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726986AbfLSVzN (ORCPT ); Thu, 19 Dec 2019 16:55:13 -0500 X-Greylist: delayed 357 seconds by postgrey-1.27 at vger.kernel.org; Thu, 19 Dec 2019 16:55:12 EST Received: from localhost (gate.crashing.org [63.228.1.57]) (authenticated bits=0) by kernel.crashing.org (8.14.7/8.14.7) with ESMTP id xBJLmPqL021727 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Thu, 19 Dec 2019 15:48:29 -0600 Message-ID: <32fde8cd451ea0eaff38108d9f2f2d4a97a43097.camel@kernel.crashing.org> Subject: Re: [PATCH v2] printk: Fix preferred console selection with multiple matches From: Benjamin Herrenschmidt To: Petr Mladek Cc: linux-kernel@vger.kernel.org, Sergey Senozhatsky , Steven Rostedt , Linus Torvalds Date: Fri, 20 Dec 2019 08:48:24 +1100 In-Reply-To: <20191219135053.xr67lybhycepcxkp@pathway.suse.cz> References: <2712d7e2fb68bca06a33e2e062fc8e65a2652410.camel@kernel.crashing.org> <20191219135053.xr67lybhycepcxkp@pathway.suse.cz> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.28.5-0ubuntu0.18.04.1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2019-12-19 at 14:50 +0100, Petr Mladek wrote: > > > NOTE: This may look convoluted because I'm trying to keep the existing > > behaviour identical when it comes to things like Braille selection, > > setup failures, on Braille consoles, or setup failures on normal consoles > > which all have subtly different results in the current code. > > > > Some of those behaviour are a bit dubious and we might be able to simply > > rely on CON_ENABLED and CON_BRL flags in newcon after the search but I > > don't want to change those corner cases in this patch. > > Yes, it is dubious. IMHO, the 5 error codes make it even harder to > see what happens in which case. Agreed. > The code really need simplification. I would prefer to take the risk > and reduce the amount of added conditions as much as possible. > I have an idea, see below. I wanted you to say that :-) I'll rework along those lines. Just a nit or two: > > > > --- a/kernel/printk/printk.c > > +++ b/kernel/printk/printk.c > > @@ -2542,6 +2545,53 @@ static int __init keep_bootcon_setup(char *str) > > > > early_param("keep_bootcon", keep_bootcon_setup); > > > > +enum con_match { > > + con_matched, > > + con_matched_preferred, > > + con_braille, > > + con_failed, > > + con_no_match, > > +}; > > Please, replace this with int, where: > > + con_matched -> 0 > + con_matched_preferred -> 0 and make "has_preferred" global variable > + con_braile -> 0 later check for CON_BRL flag > + con_failed -> -EFAULT > + con_no_match -> -ENOENT Not fan of using -EFAULT here, it's a detail since it's rather kernel internal, but I'd rather use -ENXIO for no match and -EIO for failed (or pass the original error code up if any). That said it's really bike shed painting at this point :-) > > > @@ -2615,41 +2664,19 @@ void register_console(struct console *newcon) > > + /* See if this console matches one we selected on the command line */ > > + match = try_match_new_console(newcon, true); > > + /* If it didn't, try matching the platform ones */ > > + if (match == con_no_match) > > + match = try_match_new_console(newcon, false); > > + /* If we matched a Braille console, bail out */ > > + if (match == con_braille) > > + return; > > + /* Check if we found a preferred one */ > > + if (match == con_matched_preferred) > > + has_preferred = true; > > > > + /* If we don't have an enabled console, bail out */ > > if (!(newcon->flags & CON_ENABLED)) > > return; > > Some of the comments describe what is obvious. I would simplify > it the following way: > > /* Prefer command line over platform specific defaults. */ > err = try_match_new_console(newcon, true); > if (err = -ENOENT) > err = try_match_new_console(newcon, false); > > /* printk() messages are not printed to Braille consoles. */ > if (err || console->flags | CON_BRL) > return; So this changes the existing behaviour in one way that may or may not matter, I don't know: If setup() fails, the existing code will not exit. That means that if the console has CON_ENABLED already set (some do set it statically or set it from outside this function, I haven't looked into details the various circumstances this can happen), the existing code will still insert it. Your patch will make us not insert it. > Finally, please split the change into two patches: > > 1st patch will "just" introduce try_match_new_console(console) and > use it the following way: > > err = try_match_new_console(newcon); > > /* printk() messages are not printed to the Braille console. */ > if (err || console->flags | CON_BRL) > return; > > 2nd patch will add the user_specified logic. > > This way bisection will distinguish regressions caused > by the refactoring and by the changed search order. > > Best Regards, > Petr > > PS: I have vacation between December 23 and January 1. I believe > that v3 will be ready for merging. Anyway, I will not push it > into linux-next before I am back from vacation. I would like > to stay off the computer and do not want to eventually break > linux-next for too long. No worries. This isn't super urgent. Cheers, Ben.