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: 1780192 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=JlvbwTSu; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QHHhT085dz213w for ; Fri, 12 May 2023 02:40:57 +1000 (AEST) 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-Google-Smtp-Source: ACHHUZ5RHIw3l/PxK/I6KLtUmK1F4Usv+ZEtyHqDJn8n5wag/qiTQQwqzsktDon0YThvju5ZwzBDLg== 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 */