Received: by 10.213.65.68 with SMTP id h4csp1293937imn; Wed, 14 Mar 2018 16:00:00 -0700 (PDT) X-Google-Smtp-Source: AG47ELvhHO+l3R0epdZQqXeUpuo33F9yQr99KnHUS22lvpLr6Vr8QrruvZ3i3vK+X5GnxJ0qvrwp X-Received: by 2002:a17:902:8c97:: with SMTP id t23-v6mr5798640plo.372.1521068400297; Wed, 14 Mar 2018 16:00:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521068400; cv=none; d=google.com; s=arc-20160816; b=QI0B5UEnUXb+Rb5l20NCcjWoBxWXnMhim1o+4k5ex4f/SmCDhSn4AA7q4VokNhSblv yq4Ntr364AYwict45/7cSGs3PaO3teCnSUn8XWXEKFPAQeOzMzGZfQg28cF6fMJhB7sq vgZUQ/nsQi3q27T+IA9HBEGuUvlMAK4pzmyiLCt+5lzuJHIJNYYxzF0pctUc0r1Q+e0U PzscMA86SMemiPK4NIb6tXmgtNvOX5vHGHpGuKuvXe8nRZtadYgaSQIYPZrJDzRwRlUB S989sBtthwcmdk3vdc60GjBayhflskA5ScOQEZ4h94f2o6MUYeTx1Z0Iyr1C3a4YUggh LZ2Q== 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 :references:in-reply-to:mime-version:dkim-signature:dkim-signature :arc-authentication-results; bh=1dX0W3zpWgTKTJfFYuqxTpEWtoAtqnSGrKa4EbEUuIQ=; b=mrWtpdaDHi9roYwNGgN3pKIR6rRfb16z6GOOR1gTDDfntQs6btNQrXFhH/9AkSWZxr /LTLFYFZ30DDqGGoMmwT5316gis1w7T65n1Bw5BDIeRQOU4hCx3NgANITMa6HN/i8WCY opBtW9a/v9LZk87D0bRz9E5nus9+58nIvUEqoC1dzgkIOpfP1r1d5ei9KFwA5lCza3r9 ps1gNLJxny8lpBE1471zpV6KlREwI0Rb6sRlmQPb1iV8jxTODHdR12Cnhiu1cZ16Ec2I PfhVbGHJMo2CrGfA0guEGh++duvUU29pZVQkS4GdBcxDV+Y/L+2AyyLbkdSzuiXelc0G ty3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@google.com header.s=20161025 header.b=DFidMlnn; dkim=fail header.i=@chromium.org header.s=google header.b=ZJB7dyjG; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b92-v6si2700040plb.747.2018.03.14.15.59.45; Wed, 14 Mar 2018 16:00:00 -0700 (PDT) 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; dkim=fail header.i=@google.com header.s=20161025 header.b=DFidMlnn; dkim=fail header.i=@chromium.org header.s=google header.b=ZJB7dyjG; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751871AbeCNW6Y (ORCPT + 99 others); Wed, 14 Mar 2018 18:58:24 -0400 Received: from mail-ua0-f194.google.com ([209.85.217.194]:35160 "EHLO mail-ua0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751714AbeCNW6U (ORCPT ); Wed, 14 Mar 2018 18:58:20 -0400 Received: by mail-ua0-f194.google.com with SMTP id c40so3191736uae.2 for ; Wed, 14 Mar 2018 15:58:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=1dX0W3zpWgTKTJfFYuqxTpEWtoAtqnSGrKa4EbEUuIQ=; b=DFidMlnn/I5LG6icNr49mAx3X1ImP5/twN8rVdsnsGwLWioAj79tW8WC8IftIErzad 5NKeF6MICpw4i9Yjic6Lzs8u0Bo8R4hVM12lTEKTvHQjTLoWY184Aqs2i1/7cfvsMZvU qAsxF2RDQ7GS1PowHdwVVHgDNNe/sTQ6V69M/eD1/ExDcPYTQygjUF/jeA4qPYmINvMu 9V0xA1HLtrIkctOslWR/0DdKJ1amFAtRqB03cVqjYh0vr1AIQlFNfaIw0sliMHuUhPuh rYFFZU/YQjzBclIidD/Z4aZK7MbAJCqZSBouklqkr1BhBmiG4ztFqcUCDQhp3rNl6m9R 9qvQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=1dX0W3zpWgTKTJfFYuqxTpEWtoAtqnSGrKa4EbEUuIQ=; b=ZJB7dyjG4fRG4kn9FWamZU266iceYc99SqgDLYGOO0YtNu37PVPj8zeY3TjziCsF8n 0NAxLTkSdLc6G1FfDwpPubGpbV5h8trMVeV3W/B76QMgqw7i5MaooT45NwyvtdjgudSA Gn/QS7L6SRWwHW4aFBk02PlwGjromo1t4s98o= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=1dX0W3zpWgTKTJfFYuqxTpEWtoAtqnSGrKa4EbEUuIQ=; b=CydRSL6xl846rV9qjADWGN34oL1efIf8ktuTEHmXFl5iEk03rtZl3laeW755OKBXRE xWoE52P/MQwEpuL4Zvee9dyRyezEBmYGXJFaGw7LC+i9RzFRhHaJYh8B9KUvwdIt7XVt 8fGWphwoNrQN/syAmT+Qu7BL+IpQIErYDiMI8F17C05NYejXCIn4t+zWNE/yqqzfsp2M 2QTXk8/FN3phRtIWOPl+X6ACyW8HqeYDaHI6jtkJHGs6h/aIcRRFDqa4Xuv6joF+rmZz owScb4PQ3JToaosHOFYODcT4BaCDGbisbnDpFn87VW6BuCc4ANW15+j85TaqBCtJYKEp VR5Q== X-Gm-Message-State: AElRT7F7E/4mNucU2CBUUwfIM8Ratxv0A72qNWLofwsLt77lxcjaUK5Y NzarIUVpZkyMjq17zbknve40QJSWKyyPgSOaxgd92Q== X-Received: by 10.176.22.50 with SMTP id k47mr4711724uae.176.1521068299756; Wed, 14 Mar 2018 15:58:19 -0700 (PDT) MIME-Version: 1.0 Received: by 10.31.172.6 with HTTP; Wed, 14 Mar 2018 15:58:18 -0700 (PDT) In-Reply-To: <20180314214439.27806-4-djkurtz@chromium.org> References: <20180314214439.27806-1-djkurtz@chromium.org> <20180314214439.27806-4-djkurtz@chromium.org> From: Kees Cook Date: Wed, 14 Mar 2018 15:58:18 -0700 X-Google-Sender-Auth: KrA--_o6y3FAYOP-jr0dFD8QllM Message-ID: Subject: Re: [PATCH v2 3/3] serial: core: Allow skipping old serial port initialization To: Daniel Kurtz Cc: Greg Kroah-Hartman , Aaron Durbin , LKML , "Rafael J. Wysocki" , Len Brown , Jiri Slaby , Andy Shevchenko , Matthias Brugger , David Howells , Vignesh R , Sean Young , Jeffy Chen , Douglas Anderson , Matt Redfearn , Marc Gonzalez , "open list:ACPI" , "open list:SERIAL DRIVERS" 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, Mar 14, 2018 at 2:44 PM, Daniel Kurtz wrote: > The old_serial_port global array in 8250_core is supposed to hold an entry > for each serial port on the system that cannot be discovered via a > standard enumeration mechanism (aka ACPI/PCI/DTS). The array is populated > at compile-time from the value specified in the SERIAL_PORT_DFNS macro. > This macro is defined in arch/serial.h. > > For x86, this macro is currently unconditionally initialized to supply > four ioport UARTs (0x3F8, 0x2F8, 0x3E8, 0x2E8). > > However, not all x86 CPUs have these four ioport UARTs. For example, the > UARTs on AMD Carrizo and later are separate memory mapped Designware IP > blocks. > > Fairly early in boot the console_initcall univ8250_console_init iterates > over this array and installs these old UARTs into the global array > serial8250_ports. Further, it attempts to register them for use as > the console. In other words, if, for example, the kernel commandline has > console=ttyS0, the console will be switched over to one of these > non-existent UARTs. Only later, when the real UART drivers are probed > and their devices are instantiated will the console switch back over to > the proper UART. > > This is noticeable when using earlycon, since part of the serial console > log will appear to disappear (when the bogus old takes over) and then > re-appear (when the real UART finally gets registered for the console). > > The problem is even more noticable when *not* using earlycon, since in > this case the entire console output is missing, having been incorrectly > played back to the non-existing serial port. > > Create a global variable to allow skipping old serial port initialization > and wire it up to the AMDCZ ACPI SPCR quirk and the special amdcz earlycon > setup handler. > > Signed-off-by: Daniel Kurtz > --- > Changes since v1: > * Rename variable to serial8250_skip_old_ports > * Also set variable in acpi/spcr. to support no-earlycon case. > > drivers/acpi/spcr.c | 2 ++ > drivers/tty/serial/8250/8250_core.c | 6 ++++++ > drivers/tty/serial/8250/8250_early.c | 1 + > include/linux/serial_8250.h | 6 ++++++ > 4 files changed, 15 insertions(+) > > diff --git a/drivers/acpi/spcr.c b/drivers/acpi/spcr.c > index 52d840d0e05b..f59591283410 100644 > --- a/drivers/acpi/spcr.c > +++ b/drivers/acpi/spcr.c > @@ -14,6 +14,7 @@ > #include > #include > #include > +#include > #include > > /* > @@ -208,6 +209,7 @@ int __init acpi_parse_spcr(bool enable_earlycon, bool enable_console) > } > > if (amdcz_present(table)) { > + serial8250_skip_old_ports = true; > if (enable_earlycon) > uart = "amdcz"; > } Sorry for being dense. What tree is this against? I can't find mention of amdcz in Linus's tree nor linux-next. > diff --git a/drivers/tty/serial/8250/8250_core.c b/drivers/tty/serial/8250/8250_core.c > index 9342fc2ee7df..a04da392a251 100644 > --- a/drivers/tty/serial/8250/8250_core.c > +++ b/drivers/tty/serial/8250/8250_core.c > @@ -66,6 +66,9 @@ static unsigned int skip_txen_test; /* force skip of txen test at init time */ > #define SERIAL_PORT_DFNS > #endif > > +bool serial8250_skip_old_ports; > +EXPORT_SYMBOL(serial8250_skip_old_ports); > + > static const struct old_serial_port old_serial_port[] = { > SERIAL_PORT_DFNS /* defined in asm/serial.h */ > }; > @@ -537,6 +540,9 @@ static void __init serial8250_isa_init_ports(void) > if (share_irqs) > irqflag = IRQF_SHARED; > > + if (serial8250_skip_old_ports) > + return; > + > for (i = 0, up = serial8250_ports; > i < ARRAY_SIZE(old_serial_port) && i < nr_uarts; > i++, up++) { > diff --git a/drivers/tty/serial/8250/8250_early.c b/drivers/tty/serial/8250/8250_early.c > index c6bf971a6038..288d2be82990 100644 > --- a/drivers/tty/serial/8250/8250_early.c > +++ b/drivers/tty/serial/8250/8250_early.c > @@ -202,6 +202,7 @@ static int __init early_amdcz_setup(struct earlycon_device *dev, > { > struct uart_port *port = &dev->port; > > + serial8250_skip_old_ports = true; > port->uartclk = 48000000; > > return early_serial8250_setup(dev, opt); > diff --git a/include/linux/serial_8250.h b/include/linux/serial_8250.h > index a27ef5f56431..02570edaddd8 100644 > --- a/include/linux/serial_8250.h > +++ b/include/linux/serial_8250.h > @@ -136,6 +136,12 @@ struct uart_8250_port { > struct uart_8250_em485 *em485; > }; > > +#ifdef CONFIG_SERIAL_8250 > +extern bool serial8250_skip_old_ports; > +#else > +static const bool serial8250_skip_old_ports; > +#endif Where does serial8250_skip_old_ports get used where CONFIG_SERIAL_8250 isn't defined? (i.e. why is the #ifdef needed here?) > + > static inline struct uart_8250_port *up_to_u8250p(struct uart_port *up) > { > return container_of(up, struct uart_8250_port, port); > -- > 2.16.2.804.g6dcf76e118-goog > Otherwise, sure, sounds good. :) -Kees -- Kees Cook Pixel Security