Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp162858ybl; Tue, 10 Dec 2019 20:03:46 -0800 (PST) X-Google-Smtp-Source: APXvYqwO9juvxalOe32NCzTey8fxlKR4/e6aA+0yQiPNzg+mld8E5e5mk3wjng4kz2oB0NBLuAJo X-Received: by 2002:aca:4f48:: with SMTP id d69mr1238473oib.103.1576037025956; Tue, 10 Dec 2019 20:03:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576037025; cv=none; d=google.com; s=arc-20160816; b=rKkyNLZJJp5zmkI0yhZJCGBF0CRpAiWuU3mEh5C16ZZfC1HxKCJUasEz6/DiwchzcJ dIqxzf40h5OC/9sCLmT5KX4Y/NgiCFTF3mui1CX1fJOjDHjU+ziH8++ZEnmbIvoMIMnO gRbjs/EgBZyjy/q9SgtQPocsyHNQgruoKfO/Z1uEOfG7cPbjnPk4BWdaGZp5NCvL0Jrm kXjRedIqLEF84Pa6GleAeo4pGRQpCZVw1PsE6xkiax1f99RCwrRmVjwoLGI11W+2oSBv z8mD8ErnyXXIBiFty4nQsmxEtfdVCH6nFlvofl3+zyBRDlp8fELjF04elrjfx8ew3A+P oU5Q== 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=wv2ac5zoJ+GpH27BYoG2FUtNJXZsUYayhdA3bRXfL2Y=; b=iITP1Qgo9VTJp51PeROIjcg8ff+0z09QSKDC7v7HeDKkTqX8WlbaXNw/c2Co7DTpDd pZ/HxbGM4kMNpt+heQmXBeK7XqjV/gGnyO19oP0j4UdnxOgcgDLz868smH78mcSP38aD 3t53yuA9et0+gp/MlbrnCZ2p3WRdfeZE7B1eduAfPsIiYLlda7W3iWk0r6NPWbj4nXpW icsPauinwBSYXlQzrlEjShCIA8b6F2Qc8harnQrXoAW2ByNktLoJlXI1mB2dQAIMA3fu 3xi0Qq1XTEVWpf+g6M4F08B0GqVdaXtyT6uGw63flEJKsnAXSnC3SO2FILAjzHzFr1DV njGQ== 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 i8si423616oia.137.2019.12.10.20.03.33; Tue, 10 Dec 2019 20:03:45 -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 S1727319AbfLKEDA (ORCPT + 99 others); Tue, 10 Dec 2019 23:03:00 -0500 Received: from gate.crashing.org ([63.228.1.57]:48317 "EHLO gate.crashing.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726831AbfLKEC7 (ORCPT ); Tue, 10 Dec 2019 23:02:59 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.14.1) with ESMTP id xBB422AG012504; Tue, 10 Dec 2019 22:02:03 -0600 Message-ID: <38b543cb91e936d7bd9f8885e585dd55032d83a4.camel@kernel.crashing.org> Subject: Re: [RFC/PATCH] printk: Fix preferred console selection with multiple matches From: Benjamin Herrenschmidt To: Sergey Senozhatsky Cc: linux-kernel@vger.kernel.org, Petr Mladek , Sergey Senozhatsky , Steven Rostedt , Linus Torvalds Date: Wed, 11 Dec 2019 15:02:02 +1100 In-Reply-To: <20191211020149.GN88619@google.com> References: <20191210080154.GJ88619@google.com> <98df321d16adb67c5579ac4b67d845fc0c2c97df.camel@kernel.crashing.org> <20191211020149.GN88619@google.com> 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 Wed, 2019-12-11 at 11:01 +0900, Sergey Senozhatsky wrote: > On (19/12/11 09:26), Benjamin Herrenschmidt wrote: > > As far as I know, ->match() does not only match but also does ->setup(). > If we have two console list entries that match (one via aliasing and one > via exact match) then the console driver is setup twice. Do all console > drivers handle it? [double setup] I don't think it's an issue but I may be wrong. I had a quick look at some of the drivers and I don't really see why they would break but I couldn't look at them all and I might be mistaken. We could skip setup if the console is already enabled but I would advise against that since the two calls might have different options (the firmware baud rate could be different from the command line one for example) and we want the options for the last one. > If we could perform simple alias matching, without ->setup() call, and > exact matching (strcmp()), and then, if newcon would match two entries, > we would pick up the last matching entry and configure newcon only once. > > This changes the order, tho. Walking the array backwards might just be what we want actually for the case at hand, but of course if some platforms or driver call add_preferred_console *after* the command line parsing, then it will break those. Simple alias matching would require re-working all the match() callbacks. That said I think it was a mistake to begin with to have them include setup(). Those should have remained separate. What about a compromise here: Instead of walking the array and testing for preferred_console as we do so, we first test the array entry pointed to by preferred_console (doing both match & setup as today) and if that doesn't work, fallback to our existing mechanism ? It would be a first step. It wouldn't fix all cases but would be something reasonable to backport. Another approach woudl be to pass to add_preferred_console an argument "bool user_specified" which we would use to set a CON_USER flag. We could then do a two-pass lookup of the array where we first only match user specified entries, then match the rest. > [..] > > - Another match that is marked preferred_console, in which case in > > addition to being enabled, the newly registered console will also be > > made the default console (ie, first in the list with CONSDEV set). This > > is actually what we want ! IE. The console matches the last specified > > one on the command line. > > Well, it still looks to me that what you want is to "ignore alias > match and prefer exact match". We don't want to ignore the alias match. But we do want to prefer the exact match. We still want to keep the fallback to the alias match. Cheers, Ben.