Received: by 10.213.65.68 with SMTP id h4csp52710imn; Thu, 15 Mar 2018 09:16:58 -0700 (PDT) X-Google-Smtp-Source: AG47ELt5Py0Ie1W6mKDug+XYgXCKpT9e9A+Tgeip2J4drZuFIvQb/lZEFktn5GqOMQy1yKFMeS6T X-Received: by 10.101.101.133 with SMTP id u5mr7100704pgv.151.1521130618677; Thu, 15 Mar 2018 09:16:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521130618; cv=none; d=google.com; s=arc-20160816; b=yxHkMaiOHVkeN4Ot7LGUtb1KjJSWU5y7J81xv+hnENdb+Ze/oDmACI93HYFMrqhRsT lZVliccXzx2glxcKncRHGt7L4PBkQDwIpFpgVn998VpKdOruwLo7feKwTDQdsjZnr5LP ApobTQNnU8nCkZYhlqUmuYD+fZo3QisB4eIb4cJSe9HE9IUdD0/Xq67trGR/M6JVuPPR ctcGnen7w4mQ56wAGKSaD/7b+kATJIMazXu6RRg/aVvETRdbHTf55jRwnLLwYCQMqaGk NxkVnQ7X8WHW9hKFXnMdwqDuh+QkrcKuMzgd2lMrnpH15TO5jO3sM8vgWzohRPLTyETN Pvug== 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:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature:arc-authentication-results; bh=kPyemYBPCtVOe/+H1PJzy3smKbNY6sa+r9JoeFfq9TI=; b=hGbUOQn34nUZQA72itjpq1KgtC359PblePikRCPeGlCOcyn7tnpM4yX1lJSTQka6ix uLNg48eD9YOxWf2Pr8zVRHwVIgqgNrYTejbXRjjavLblriHQNMFm/qkfIV1QPFd30vHC gffb/FehVDdWMA2+bVGnZ3MNJk4SA0ovIbpat571mH1Rwe7rYV8eZoY/lrz6G4bBtvig 9smVAlGirKyy4iUH0XBOBd96HEwq8osuYy44+ZQod5Zb24ZTkLd6ECUIc0z/jpinTb4/ f0x05151uB3A1gfc4a7nzj8Ie8hOZq5Ybix9qnp/48+AbD3I2B+bu/xo4YM7bX4emizD mNMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=kOynXttW; 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=pass (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 h10si1539382pgc.296.2018.03.15.09.16.44; Thu, 15 Mar 2018 09:16:58 -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=pass header.i=@chromium.org header.s=google header.b=kOynXttW; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751693AbeCOQPx (ORCPT + 99 others); Thu, 15 Mar 2018 12:15:53 -0400 Received: from mail-vk0-f65.google.com ([209.85.213.65]:46538 "EHLO mail-vk0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751353AbeCOQPv (ORCPT ); Thu, 15 Mar 2018 12:15:51 -0400 Received: by mail-vk0-f65.google.com with SMTP id x125so4517292vkc.13 for ; Thu, 15 Mar 2018 09:15:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=kPyemYBPCtVOe/+H1PJzy3smKbNY6sa+r9JoeFfq9TI=; b=kOynXttW1ehJ3siSLEJjXpXEvZgZ5pPNsEMWmSnl3XdY5EsRxPFxHMVzLq9SYhq/UT Y1d3yr8cI1FulQ9LafiBWTOFkqzfWbFai7qaglkRkjLs0fJ2MDl3jtAU7usLYdj8KHKb byBc5sqlmvpQuMzQ/6Kenbgb2W427W7pOleSA= 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:content-transfer-encoding; bh=kPyemYBPCtVOe/+H1PJzy3smKbNY6sa+r9JoeFfq9TI=; b=pUmvb/9tJx+Mxb+JholpjmFaqjUTyscVXF4Z4Wy8VEXM+7Pw6taJac7d4kZbhHGeuP 3lbOe0n6qavBkThnWAbzqtQ8+9zmHn3fjbJRDnskgTB9EleUkwanfaPVLx+1TQ5fLWJ/ C77eLpGZSNG+I8JKTRWSKKMADKOKIvBES/tPHKEugD7P4T6I5PBCnw3546rNqLqesico U12DoJkHKlY39c8VBUsG7DFRfhjxHM8Fq2Ktwh2O1QuCISKgeVPHflgb/3B+EjX8ee/D dtKyazyMkRmnEH8jiAagWLIyTt1Sdz0dnSKMb7fjIQe/KxceEHjis+/pKWEPk7PFa7Ql 5Dvg== X-Gm-Message-State: AElRT7Hf9jTo7BmTQH1dxupVDDXzPIfCXcCDU3S+FndYgeL9HpRNXjSj J7BRT10Sp5EXJArN/3j28GuVtw6YNSCLi++9bg2nG8ZbvTnsivGl/otEUHtFUAyZeZVyJZdQXJn kQpQJx2aL+kX894Jma3BKj8ZfxUqfOJI= X-Received: by 10.31.223.135 with SMTP id w129mr6907699vkg.48.1521130549509; Thu, 15 Mar 2018 09:15:49 -0700 (PDT) MIME-Version: 1.0 References: <20180315014817.142930-1-djkurtz@chromium.org> <398eebd9-9ec9-50ef-88ea-c3d5ae9f5d90@infradead.org> In-Reply-To: <398eebd9-9ec9-50ef-88ea-c3d5ae9f5d90@infradead.org> From: Daniel Kurtz Date: Thu, 15 Mar 2018 16:15:38 +0000 Message-ID: Subject: Re: [PATCH v2] earlycon: Fix __earlycon_table stride... again To: Randy Dunlap Cc: peter@hurleysoftware.com, Rob Herring , adurbin@chromium.org, Greg Kroah-Hartman , linux-kernel@vger.kernel.org, Grant Likely , Rob Herring , frowand.list@gmail.com, jslaby@suse.com, Arnd Bergmann , "open list:OPEN FIRMWARE AND..." , linux-serial@vger.kernel.org, linux-arch@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-ccpol: medium 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 8:33 PM Randy Dunlap wrote: > On 03/14/2018 06:48 PM, Daniel Kurtz wrote: > > Commit 470ca0de69fe ("serial: earlycon: Enable earlycon without command > > line param") added EARLYCON_TABLE(). > > > > Commit 99492c39f39f ("earlycon: Fix __earlycon_table stride") reference= d > > commit 07fca0e57fca92 ("tracing: Properly align linker defined symbols"= ) > > and tried to fix EARLYCON_TABLE() using __aligned(32). > > > > However, the fix copied just works around compiler behavior. In fact, it > > was subsequently re-implemented for tracing using a table of pointers i= n > > commit 3d56e331b653 ("tracing: Replace syscall_meta_data struct array with > > pointer array"), commit 654986462939 ("tracepoints: Fix section alignment > > using pointer array") and commit e4a9ea5ee7c8 ("tracing: Replace > > trace_event struct array with pointer array"). > > > > Let's do the same "array of pointers to structs" approach for > > EARLYCON_TABLE. > Please describe what the problem is instead of just what the fix is. > Thanks. The problem is the same as in 99492c39f39f; the __earlycon_table stride may be wrong depending on how the compiler decides to align the contents of __earlycon_table. See the other referenced patches for a detailed description of the problem and its solution. -Dan > > Signed-off-by: Daniel Kurtz > > --- > > Changes since v1: > > * Change __earlycon_table to an array of pointers. > > > > Note: I do not have a convenient system to test the of/fdt.c part of this > > patch, so would apreciate help verifying it. Thanks! > > > > drivers/of/fdt.c | 7 +++++-- > > drivers/tty/serial/earlycon.c | 6 ++++-- > > include/asm-generic/vmlinux.lds.h | 2 +- > > include/linux/serial_core.h | 21 ++++++++++++++------- > > 4 files changed, 24 insertions(+), 12 deletions(-) > > > > diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c > > index 84aa9d676375..6da20b9688f7 100644=EF=BF=BC > > --- a/drivers/of/fdt.c > > +++ b/drivers/of/fdt.c > > @@ -942,7 +942,7 @@ int __init early_init_dt_scan_chosen_stdout(void) > > int offset; > > const char *p, *q, *options =3D NULL; > > int l; > > - const struct earlycon_id *match; > > + const struct earlycon_id **p_match; > > const void *fdt =3D initial_boot_params; > > > > offset =3D fdt_path_offset(fdt, "/chosen"); > > @@ -969,7 +969,10 @@ int __init early_init_dt_scan_chosen_stdout(void) > > return 0; > > } > > > > - for (match =3D __earlycon_table; match < __earlycon_table_end; match++) { > > + for (p_match =3D __earlycon_table; p_match < __earlycon_table_end= ; > > + p_match++) { > > + const struct earlycon_id *match =3D *p_match; > > + > > if (!match->compatible[0]) > > continue; > > > > diff --git a/drivers/tty/serial/earlycon.c b/drivers/tty/serial/earlycon.c > > index a24278380fec..22683393a0f2 100644 > > --- a/drivers/tty/serial/earlycon.c > > +++ b/drivers/tty/serial/earlycon.c > > @@ -169,7 +169,7 @@ static int __init register_earlycon(char *buf, const struct earlycon_id *match) > > */ > > int __init setup_earlycon(char *buf) > > { > > - const struct earlycon_id *match; > > + const struct earlycon_id **p_match; > > > > if (!buf || !buf[0]) > > return -EINVAL; > > @@ -177,7 +177,9 @@ int __init setup_earlycon(char *buf) > > if (early_con.flags & CON_ENABLED) > > return -EALREADY; > > > > - for (match =3D __earlycon_table; match < __earlycon_table_end; match++) { > > + for (p_match =3D __earlycon_table; p_match < __earlycon_table_end= ; > > + p_match++) { > > + const struct earlycon_id *match =3D *p_match; > > size_t len =3D strlen(match->name); > > > > if (strncmp(buf, match->name, len)) > > diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h > > index 1ab0e520d6fc..e17de55c2542 100644 > > --- a/include/asm-generic/vmlinux.lds.h > > +++ b/include/asm-generic/vmlinux.lds.h > > @@ -179,7 +179,7 @@ > > #endif > > > > #ifdef CONFIG_SERIAL_EARLYCON > > -#define EARLYCON_TABLE() STRUCT_ALIGN(); \ > > +#define EARLYCON_TABLE() . =3D ALIGN(8); = \ > > VMLINUX_SYMBOL(__earlycon_table) =3D .; \ > > KEEP(*(__earlycon_table)) \ > > VMLINUX_SYMBOL(__earlycon_table_end) =3D .; > > diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h > > index b32df49a3bd5..93b7add47087 100644 > > --- a/include/linux/serial_core.h > > +++ b/include/linux/serial_core.h > > @@ -351,10 +351,10 @@ struct earlycon_id { > > char name[16]; > > char compatible[128]; > > int (*setup)(struct earlycon_device *, const char *options); > > -} __aligned(32); > > +}; > > > > -extern const struct earlycon_id __earlycon_table[]; > > -extern const struct earlycon_id __earlycon_table_end[]; > > +extern const struct earlycon_id *__earlycon_table[]; > > +extern const struct earlycon_id *__earlycon_table_end[]; > > > > #if defined(CONFIG_SERIAL_EARLYCON) && !defined(MODULE) > > #define EARLYCON_USED_OR_UNUSED __used > > @@ -362,12 +362,19 @@ extern const struct earlycon_id __earlycon_table_end[]; > > #define EARLYCON_USED_OR_UNUSED __maybe_unused > > #endif > > > > -#define OF_EARLYCON_DECLARE(_name, compat, fn) \ > > - static const struct earlycon_id __UNIQUE_ID(__earlycon_##_name) \ > > - EARLYCON_USED_OR_UNUSED __section(__earlycon_table) \ > > +#define _OF_EARLYCON_DECLARE(_name, compat, fn, unique_id) \ > > + static const struct earlycon_id unique_id \ > > + EARLYCON_USED_OR_UNUSED __initdata \ > > =3D { .name =3D __stringify(_name), = \ > > .compatible =3D compat, = \ > > - .setup =3D fn } > > + .setup =3D fn }; = \ > > + static const struct earlycon_id EARLYCON_USED_OR_UNUSED \ > > + __section(__earlycon_table) \ > > + * const __PASTE(__p, unique_id) =3D &unique_id > > + > > +#define OF_EARLYCON_DECLARE(_name, compat, fn) \ > > + _OF_EARLYCON_DECLARE(_name, compat, fn, \ > > + __UNIQUE_ID(__earlycon_##_name)) > > > > #define EARLYCON_DECLARE(_name, fn) OF_EARLYCON_DECLARE(_name, "", fn= ) > > > > > -- > ~Randy