From patchwork Thu May 11 16:40:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 680906 Delivered-To: patch@linaro.org Received: by 2002:a5d:4a41:0:0:0:0:0 with SMTP id v1csp3505560wrs; Thu, 11 May 2023 09:40:58 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6ce4ClTU3h2PgIVqpyLXfM/17mX0tf/+xllP9FzUi++LYCWxoWwecqUwWUT6SjHTfYXPG3 X-Received: by 2002:a17:902:ce82:b0:1a9:9a18:345c with SMTP id f2-20020a170902ce8200b001a99a18345cmr26944935plg.44.1683823258515; Thu, 11 May 2023 09:40:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683823258; cv=none; d=google.com; s=arc-20160816; b=e8dsI5EAXdNz18Br9DsTrRkMZGkSRJe0Ho2k1bmkJz4eEZ4ePsAqumvLcfsEgB+gni 9Im3RkP+mLGY8p07O/NkiWTLBTPFJr/d9VLCH4WVjp4kUwaIxXhw4EMmJtGwNbcKv3js Smf10R59PDk2SZuSSGz0Kykhq00xhvjah5GfG3uasbipU8Or6iIYZSntjMRBix5vZawC PJ0L66b5o6EuQHQe/xAN2vO5neQiZSoCBSpVEL6AU1swIYmKSlGmapl3D/8n+Exbbzak w2ifDA3qAK9dxc1ypTt4KkW4uR6FX+JNiMwfkBV0qHzNf+28SNQVKCcPt1JD0I8EmDtL vNyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=ivzFTYvwBIURR37Wj8ZB9CE9AwvJsXF5eh8/tiJHupI=; b=c/XArQu/m1/IvKBg+XtbpOf9m65xqHRvxCOaq0SnxsBdfLUPw3nFSa7lbAijKZ+yeU 16xqUT6JORnXYpEmra50TxPFnUmkYGhq6PxoBJnR6Epm6MK5ElguW99/lLATzjOS6Cxg pX4yiCe6WjmaVlL5/Q2z0EVT9uar1MnqnFQdG9b7cuwlxNBpij6ZzE23Jjsm9RgIa4Oc CZ92qb3oukmSYMUb+xBiGOO9p4cZH5YvLYfzCyS5erhxCigr2UnWLcAztm3hxMXoFuKC eRtFHosaAyDAhkE5dNbRziLLPmYrmd8sxVnUSgbI8ssOP5ft3Xj8but6YBpdYAxAOS33 ZZSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JlvbwTSu; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id a12-20020a170902900c00b001a94429df88si6564815plp.123.2023.05.11.09.40.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 May 2023 09:40:58 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JlvbwTSu; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8103A86149; Thu, 11 May 2023 18:40:53 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="JlvbwTSu"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 864DB8610D; Thu, 11 May 2023 18:40:52 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 7913E86183 for ; Thu, 11 May 2023 18:40:49 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ilias.apalodimas@linaro.org Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-304935cc79bso8348311f8f.2 for ; Thu, 11 May 2023 09:40:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1683823249; x=1686415249; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=ivzFTYvwBIURR37Wj8ZB9CE9AwvJsXF5eh8/tiJHupI=; b=JlvbwTSutSiIOlLbdCaJ/biarvRuF8vKHN+49ibSeHZd50igF71NXP3yKXcNDoWe9o IjRDFVjYWz0ODOzKy0HcRqOcrTHK1PbeElK4Q3NemVd1/arEAjh2OQNayLZpYZy3i3u1 vtDsxwHj2XO6qdO2G62pTG6XfSNjKz+jnTgie+U90Bu9YRrn5E+r4b32410GPEzie0PQ O6CrfiyC7+dVjT768GcAhZDzGH+U76PnQkAOBd2WsWyQl86/UGUM83kq9VJ9Rs63fUZ1 81wtE90bnANFS9KAwOXQPZFJEjBDzMbeYt9P/xCtVADFcC8LHm+xR2FaZHzKodAdbyVP e8hQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683823249; x=1686415249; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ivzFTYvwBIURR37Wj8ZB9CE9AwvJsXF5eh8/tiJHupI=; b=gnya+xW7iMPAPpPz7llIcEZAy5XF9G49uG454PfsL1vIMcCOK6nHhXaH7R1nJuIz9Y aOLa++/0KMUngeDF+YkmD7hN34HCBacrMIYB1PG6jarYWTt9LMNNKDCWlaetJodLvVBn DB4GzBRcfyffqXHMtHlTVR4FyywjCyomPuY46NSRW87Av0GCzXEsqV/PXp8VWT+1e1AK /Rh83ko4idvrCn3iKPnd9Ar7EDIQViYtr4Lym7QdwU6utcutX1OM/dDMZYfwQpMLK4jt ZC1AhTASqrJ2Qc41QuBrdwtccOuO2hw/bbJvG/giaA20EPmMV0wvP5FrRBNaSBYhmmH0 7q+A== X-Gm-Message-State: AC+VfDxd9tiF/x/rp5E7RHkbDFD2uALDEu8LMBXAHj7irDPwZCaBLLV8 jO4TJYsVD7G2lIwDAB2RlYNSZFmTa9an9CBOV6Qz3w== X-Received: by 2002:a5d:5143:0:b0:306:3bfb:fe94 with SMTP id u3-20020a5d5143000000b003063bfbfe94mr15320590wrt.53.1683823248875; Thu, 11 May 2023 09:40:48 -0700 (PDT) Received: from localhost.localdomain (ppp176092130041.access.hol.gr. [176.92.130.41]) by smtp.gmail.com with ESMTPSA id p6-20020adfe606000000b002e5f6f8fc4fsm20984954wrm.100.2023.05.11.09.40.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 May 2023 09:40:48 -0700 (PDT) From: Ilias Apalodimas To: u-boot@lists.denx.de Cc: trini@konsulko.com, takahiro.akashi@linaro.org, Ilias Apalodimas , Heinrich Schuchardt , Heinrich Schuchardt Subject: [PATCH v2] efi_loader: Fix warnings for unaligned accesses Date: Thu, 11 May 2023 19:40:35 +0300 Message-Id: <20230511164035.913574-1-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Tom reports that when building with clang we see this warning: field guid within 'struct efi_hii_keyboard_layout' is less aligned than 'efi_guid_t' and is usually due to 'struct efi_hii_keyboard_layout' being packed, which can lead to unaligned accesses [-Wunaligned-access] This happens because 'struct efi_hii_keyboard_layout' is defined as packed and thus has 1-byte alignment but efi_guid_t is a type that requires greater alignment than that. However the EFI spec describes the EFI_GUID as "128-bit buffer containing a unique identifier value. Unless otherwise specified" So convert the efi_guid_t -> u8 b[16] here and skip the alignment requirements. Since the struct is packed to begin with, it makes no difference on the final memory layout. Suggested-by: Heinrich Schuchardt Reported-by: Tom Rini Signed-off-by: Ilias Apalodimas Reviewed-by: Heinrich Schuchardt --- Changes since v1: - Adjust the commit message and add a comment on why this happens include/efi_api.h | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) -- 2.39.2 diff --git a/include/efi_api.h b/include/efi_api.h index 2fd0221c1c77..55a4c989fc7c 100644 --- a/include/efi_api.h +++ b/include/efi_api.h @@ -1170,7 +1170,33 @@ struct efi_key_descriptor { struct efi_hii_keyboard_layout { u16 layout_length; - efi_guid_t guid; + /* + * The EFI spec defines this as efi_guid_t. + * clang and gcc both report alignment problems here. + * clang with -Wunaligned-access + * warning: field guid within 'struct efi_hii_keyboard_layout' is less + * aligned than 'efi_guid_t' and is usually due to + * 'struct efi_hii_keyboard_layout' being packed, which can lead to + * unaligned accesses + * + * GCC with -Wpacked-not-aligned -Waddress-of-packed-member + * 'efi_guid_t' offset 2 in 'struct efi_hii_keyboard_layout' + * isn't aligned to 4 + * + * Removing the alignment from efi_guid_t is not an option, since + * it is also used in non-packed structs and that would break + * calculations with offsetof + * + * This is the only place we get a report for. That happens because + * all other declarations of efi_guid_t within a packed struct happens + * to be 4-byte aligned. i.e a u32, a u64 a 2 * u16 or any combination + * that ends up landing efi_guid_t on a 4byte boundary precedes. + * + * Replace this with a 1-byte aligned counterpart of b[16]. This is a + * packed struct so the memory placement of efi_guid_t should not change + * + */ + u8 guid[16]; u32 layout_descriptor_string_offset; u8 descriptor_count; /* struct efi_key_descriptor descriptors[]; follows here */