Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp707668pxb; Tue, 3 Nov 2020 10:16:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJy0Cz4Ir/HLL7eEoJSIT0bHlEL33ipAGI6mpe88Yh0VRv+QJTpXS9WjHI61b9+jCPEQjy3C X-Received: by 2002:aa7:d64b:: with SMTP id v11mr22559100edr.253.1604427412994; Tue, 03 Nov 2020 10:16:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604427412; cv=none; d=google.com; s=arc-20160816; b=0OOWz2ow9tC0vJGmjo0NovU/xwORiXRB22XAxiPDq+Qlb6+1oJKRzERqbQDsDoI+xN aJBJizE/rnneHdM5FwXVTxBtZ6PjRFnCifrzWG8Gp7pVvrjRAsApbYcnbLTEwuutPO8p riTfcSbjxbOLFpXQ6Mvf7DsvNxWth1zRlZCqixcWwPeOjclje43dj7Q4pmtXBmOQz0ij X7QC/DSH7vCMkt/k0L7ExhYF0/oVAd+y+QDmfVYDVfAJzmHQeyZRnSOnnh6TtP+Dnmzh NQjHjCMm0IutTwjmcY47ZMS8WA27yzDiwBnnB/WDZO27DcHWsnvHKh877gXM0un4FcGn t6XA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=76fujNvmaDU5izlocC2iDYMlwXY99PLp9hN2X9PjG0k=; b=lx40UT4CqjioOJhYXD4JoCwnPKN4AkSX3C/sDEKLKecXP/on3KuSLVN2KOHeFGdvs/ NGU7lasb/Xq7NtE2XSMN6WNBoY8Rfc5Pib1/eoI/dlM1teQvkm/ZveVIxtE5tTX+opbD pLfR5GiMent3zFb1czqtt7yWSL4HkT0518ZaYggNTLqozlXEUa3wrxmiQm8ulibS9uwi cH2bQpqQK4oMAWeQUwtaaHzOmRO9otjORZ9WGaOoANmXunSIkZZV6lYOwh1xM6nMLazk 3y9hIenWIQiQuId4CgFJhP9ZEaKB6lwiSvJ/oBMA3DXBAsd4wprXw4yusCDfhQh7hAhZ m8xw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a25si3347938edx.171.2020.11.03.10.16.29; Tue, 03 Nov 2020 10:16:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729075AbgKCSMc (ORCPT + 99 others); Tue, 3 Nov 2020 13:12:32 -0500 Received: from mail-lj1-f194.google.com ([209.85.208.194]:39602 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728880AbgKCSME (ORCPT ); Tue, 3 Nov 2020 13:12:04 -0500 Received: by mail-lj1-f194.google.com with SMTP id m16so20086894ljo.6; Tue, 03 Nov 2020 10:12:02 -0800 (PST) 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=76fujNvmaDU5izlocC2iDYMlwXY99PLp9hN2X9PjG0k=; b=SBohuV1MmKS50OO3v6YK9Sk7/tOFIho5ZZISZHogAe7B0oWR+MwU9Prb0J1dzZlRs/ f7dnPjikh2cu/er94c4HKfCSuJj/sLK0egl76EtIrmZIDDbaD1pfwZSu+ikMLBuAk409 d71+sOMChWpCw6hFfktJEGQPH6L1Fuk20DpPdwOTWFKP2G/B4ex5hp+po1sqGS7w8IH8 WaVAenyH+BVCTDzu7x0qbwYtkjIsACXyXRopr4X4kcy//q3pz33nUoWbOPT71Dk3S66j e36A+B2iu5zM9R9nM3rmw2QrKHX56SuUhD9OEJRBlaAc3BBEPWdt1z0E1E9kGp1PGeT3 sBJQ== X-Gm-Message-State: AOAM531B8Nq2TSTnS5Vj1etW6RKMCRwL0a/UYBzoJkkn7EX5GzvYQ4JX NiNVwAwsmC1tx707fPQRfk5357lhwrWfgA== X-Received: by 2002:a2e:7617:: with SMTP id r23mr9525714ljc.0.1604427120842; Tue, 03 Nov 2020 10:12:00 -0800 (PST) Received: from xi.terra (c-beaee455.07-184-6d6c6d4.bbcust.telenor.se. [85.228.174.190]) by smtp.gmail.com with ESMTPSA id a25sm3688646lfo.141.2020.11.03.10.11.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 10:11:59 -0800 (PST) Received: from johan by xi.terra with local (Exim 4.93.0.4) (envelope-from ) id 1ka0mn-0002rR-Jv; Tue, 03 Nov 2020 19:12:01 +0100 From: Johan Hovold To: linux-kernel@vger.kernel.org Cc: Linus Torvalds , Rob Herring , Frank Rowand , Greg Kroah-Hartman , Jessica Yu , Nick Desaulniers , Arnd Bergmann , Geert Uytterhoeven , Dmitry Torokhov , David Miller , Jakub Jelinek , Peter Zijlstra , Thomas Gleixner , Steven Rostedt , Daniel Kurtz , linux-arch@vger.kernel.org, linux-m68k@lists.linux-m68k.org, Johan Hovold , stable Subject: [PATCH 1/8] of: fix linker-section match-table corruption Date: Tue, 3 Nov 2020 18:57:04 +0100 Message-Id: <20201103175711.10731-2-johan@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201103175711.10731-1-johan@kernel.org> References: <20201103175711.10731-1-johan@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Specify type alignment when declaring linker-section match-table entries to prevent gcc from increasing alignment and corrupting the various tables with padding (e.g. timers, irqchips, clocks, reserved memory). This is specifically needed on x86 where gcc (typically) aligns larger objects like struct of_device_id with static extent on 32-byte boundaries which at best prevents matching on anything but the first entry. Here's a 64-bit example where all entries are corrupt as 16 bytes of padding has been inserted before the first entry: ffffffff8266b4b0 D __clk_of_table ffffffff8266b4c0 d __of_table_fixed_factor_clk ffffffff8266b5a0 d __of_table_fixed_clk ffffffff8266b680 d __clk_of_table_sentinel And here's a 32-bit example where the 8-byte-aligned table happens to be placed on a 32-byte boundary so that all but the first entry are corrupt due to the 28 bytes of padding inserted between entries: 812b3ec0 D __irqchip_of_table 812b3ec0 d __of_table_irqchip1 812b3fa0 d __of_table_irqchip2 812b4080 d __of_table_irqchip3 812b4160 d irqchip_of_match_end Verified on x86 using gcc-9.3 and gcc-4.9 (which uses 64-byte alignment), and on arm using gcc-7.2. Note that there are no in-tree users of these tables on x86 currently (even if they are included in the image). Fixes: 54196ccbe0ba ("of: consolidate linker section OF match table declarations") Fixes: f6e916b82022 ("irqchip: add basic infrastructure") Cc: stable # 3.9 Signed-off-by: Johan Hovold --- include/linux/of.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/linux/of.h b/include/linux/of.h index 5d51891cbf1a..af655d264f10 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -1300,6 +1300,7 @@ static inline int of_get_available_child_count(const struct device_node *np) #define _OF_DECLARE(table, name, compat, fn, fn_type) \ static const struct of_device_id __of_table_##name \ __used __section("__" #table "_of_table") \ + __aligned(__alignof__(struct of_device_id)) \ = { .compatible = compat, \ .data = (fn == (fn_type)NULL) ? fn : fn } #else -- 2.26.2