Received: by 10.213.65.68 with SMTP id h4csp1359865imn; Wed, 14 Mar 2018 18:49:37 -0700 (PDT) X-Google-Smtp-Source: AG47ELtp14px8jzlF0F9p6L20uKB0jGj7rd79W+1KswfRcIxuIVOzd0fwF9FYZvkSjCfKoLgDI41 X-Received: by 2002:a17:902:6717:: with SMTP id f23-v6mr6193924plk.188.1521078577501; Wed, 14 Mar 2018 18:49:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521078577; cv=none; d=google.com; s=arc-20160816; b=xnPCHKAjbmIYnI5wQWtSaRTrMPr/ecWYaGyiHWrYoCWY1uoVgijfaqc0GZ2s3U7a37 rpsjM5PHNNqNE2zGobMTWt/kJt9mK4fvnJx6WLDpX4hKFCdF1e2n2ZhXwb3oRoX2t9fo J+U/qAZJr56EldYoOCCEY4MTTf0vVnS4Sdj/74FKEpCZykBnGobVh+HJfx8/0v2Yu3uS /55mScL4NpAheUMCVpRFoLEYySZZlQmWreK+3G09NBp1z3uyulld1wfnhCkPXvj6uGFW vPxBhbFjt4CTLlwnCFQwCD3ax1qtCeCcdJN2BH5S22qI/e1e6OICnbR6yMuwMoEpNpO8 FHHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=aj2ddwvURJbGfgfGhO89UKUdo3orZYMlK4Q13q2MRAw=; b=yeKTHRVLR2Z5OOCTy5ctxuNnz4H1C03WlIlG69Tbf54VjVdRNzcG1T9mRyTYhfFN7S H9cD6PMU9N3M7hc384+jomTApbKq5F7lUD896FGqd3xVhm6EJj7Xpx7TE9HaUWtyHav/ O+5o5lEiB75Ch/CpO872RVeY9TRqTnjXpYwwbCoIJWYapmuw5kpMPS3US84gYlnyP5HR uGgYduLbNEdV3P3MHDdt88HRIV+Pm+QLo/z0FtmITYTU5Rp+YmE1j7VFCOHx+JygRnWE oShOsAeCT2DPc/oXpoqFJ3rGT+VpOw48aPnFrflH/kSEKPCs6Gh8WxM/3tGpj0KpelcK Hfsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=jtl+mjEF; 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 d1si2746111pgn.661.2018.03.14.18.49.23; Wed, 14 Mar 2018 18:49:37 -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=jtl+mjEF; 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 S1751901AbeCOBsW (ORCPT + 99 others); Wed, 14 Mar 2018 21:48:22 -0400 Received: from mail-ot0-f196.google.com ([74.125.82.196]:41019 "EHLO mail-ot0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751408AbeCOBsV (ORCPT ); Wed, 14 Mar 2018 21:48:21 -0400 Received: by mail-ot0-f196.google.com with SMTP id i28-v6so629855otf.8 for ; Wed, 14 Mar 2018 18:48:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id; bh=aj2ddwvURJbGfgfGhO89UKUdo3orZYMlK4Q13q2MRAw=; b=jtl+mjEFO/vUKVyyX+xahYuS/BNQ/xSjKJhONA0P1b6vKWD20h9PhdHv7rXa0Oif+w 7q3+zkgOJ2GMxItPeJILvS0ZFdA5uUtJri3o+uor3ntCxKYAP7UZa4x49wRAqhgQsurP HkJQ+ZuIWUtfzyISKOj0xIlGaijwLIZoB6SQA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=aj2ddwvURJbGfgfGhO89UKUdo3orZYMlK4Q13q2MRAw=; b=idCw7rt+iod39DSJAXhqFmg+DOLtXkTHVOuFZdHG0eC1M+rkvUy6+z262YCpXzai10 M6Td5KpKnaKDbR6jKbWEyuL9XwGdYCrVW/4sl7U53hltZA5XHkgX2jlQu3zk7ttAwoqp JsvdUf7XPWdLURXxahmfDCYPUvQ9lHiHdR5vCs1FSp9DQ03Eco4CDYR7YLyqvxkEDUjD wIeIqYrAtAICk5v6BXLJfsOr9lFtT3hKgOcXu77LeS6910NzMRl2fBZpxTsrUugvQVPm P6v42P1c59FNEURmW4qw6gfauYVOfftKVGSfE13XZhtW9JOiTWTvaveTo6XNXwjY46So Aggw== X-Gm-Message-State: AElRT7Fc8NJfN9W9mRiuGbek3v8L5UC38lobi7GKCTYiPG4farl6rU7F p9JeZnGk1Nxyl/h8Vy3Mcht4ig== X-Received: by 10.157.15.185 with SMTP id d54mr4739861otd.340.1521078500532; Wed, 14 Mar 2018 18:48:20 -0700 (PDT) Received: from djkurtz2.bld.corp.google.com ([2620:15c:183:0:1cfd:61a5:7215:5f9c]) by smtp.gmail.com with ESMTPSA id d45sm2379586otf.72.2018.03.14.18.48.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Mar 2018 18:48:19 -0700 (PDT) From: Daniel Kurtz To: Peter Hurley , Rob Herring Cc: adurbin@chromium.org, Greg Kroah-Hartman , linux-kernel@vger.kernel.org, Grant Likely , Daniel Kurtz , Rob Herring , Frank Rowand , Jiri Slaby , Arnd Bergmann , devicetree@vger.kernel.org (open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE), linux-serial@vger.kernel.org (open list:SERIAL DRIVERS), linux-arch@vger.kernel.org (open list:GENERIC INCLUDE/ASM HEADER FILES) Subject: [PATCH v2] earlycon: Fix __earlycon_table stride... again Date: Wed, 14 Mar 2018 19:48:16 -0600 Message-Id: <20180315014817.142930-1-djkurtz@chromium.org> X-Mailer: git-send-email 2.16.2.804.g6dcf76e118-goog Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit 470ca0de69fe ("serial: earlycon: Enable earlycon without command line param") added EARLYCON_TABLE(). Commit 99492c39f39f ("earlycon: Fix __earlycon_table stride") referenced 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 in 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. 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 --- 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 = NULL; int l; - const struct earlycon_id *match; + const struct earlycon_id **p_match; const void *fdt = initial_boot_params; offset = fdt_path_offset(fdt, "/chosen"); @@ -969,7 +969,10 @@ int __init early_init_dt_scan_chosen_stdout(void) return 0; } - for (match = __earlycon_table; match < __earlycon_table_end; match++) { + for (p_match = __earlycon_table; p_match < __earlycon_table_end; + p_match++) { + const struct earlycon_id *match = *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 = __earlycon_table; match < __earlycon_table_end; match++) { + for (p_match = __earlycon_table; p_match < __earlycon_table_end; + p_match++) { + const struct earlycon_id *match = *p_match; size_t len = 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() . = ALIGN(8); \ VMLINUX_SYMBOL(__earlycon_table) = .; \ KEEP(*(__earlycon_table)) \ VMLINUX_SYMBOL(__earlycon_table_end) = .; 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 \ = { .name = __stringify(_name), \ .compatible = compat, \ - .setup = fn } + .setup = fn }; \ + static const struct earlycon_id EARLYCON_USED_OR_UNUSED \ + __section(__earlycon_table) \ + * const __PASTE(__p, unique_id) = &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) -- 2.16.2.804.g6dcf76e118-goog