From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D9C44C77B7C for ; Fri, 12 May 2023 00:05:17 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1B4F8861AF; Fri, 12 May 2023 02:05:15 +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="FLm918Fg"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 48296861FA; Fri, 12 May 2023 02:05:14 +0200 (CEST) Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) (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 0B476861AB for ; Fri, 12 May 2023 02:05:11 +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=takahiro.akashi@linaro.org Received: by mail-pf1-x441.google.com with SMTP id d2e1a72fcca58-6439bf89cb7so1790676b3a.0 for ; Thu, 11 May 2023 17:05:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1683849909; x=1686441909; h=in-reply-to:content-disposition:mime-version:references :mail-followup-to:message-id:subject:cc:to:from:date:from:to:cc :subject:date:message-id:reply-to; bh=4ibLG+jwDe/YjEhIbL48g5zJIgsB+8HVnnas9sZ1OKQ=; b=FLm918Fg/IideEp5EoyYQY/+Umbb2AqnQJxvwg+cMWknapR7NEKrfn/xQreC/hmSq9 lQkj6fAW4n8V1Sh3fJI45oPcZLlbtzvIeSrti1GNNV2R2NFoE+5WSN3MZsz95N+CBaqM e3lamknmRK7mwKJrYguASKR/aqFQ4TI37l6P0Vn1Nd18cmvPvfppg5QU4H24ppoOZyIJ 5lSmya96LvG+P4Bf/WbS3vB1a305GkWKk3CC2W+EP8VD6Ly2+5OMv00OsXrOE5gqo9hn ezwxGFG+stQOw7I0KaF6UFyplaLCH3nBTtyX2SvN33smqUG3q98e6vMdm7MYLT2cxs1f Pd4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683849909; x=1686441909; h=in-reply-to:content-disposition:mime-version:references :mail-followup-to:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=4ibLG+jwDe/YjEhIbL48g5zJIgsB+8HVnnas9sZ1OKQ=; b=imZgfeD/zLDUc+0D1kv/dUr4lNuPM+f4m9OUdnPXqDLSUn/t/kwP1yXqf7amMkTm3Z MV4+IsKM8RqreE8XlIT7jCUYEmj4XHW7BTb4xFKlY2Grdj29yYfQR1TVVBt5812bvKXB b1sSY8ttL1T+jkpe4XVmqJSsQwfGzszR9Mfnxj7N6ihXcB/AWI0+e887j8ACa/L+nRC6 ms60kUg72V6r8tgBn9FWj/1GJGJPBS0ufzO7ozbwtfkCogk7NJN0i9RcoeOXRP7nBIk7 0SFM1ehvFKSFU0B1DFv6KFLyV6dcvSWQ2gs715W/X/lTSrc3d+EyOgBBvUpYwl2/v1MM 9JYw== X-Gm-Message-State: AC+VfDxALV4KVqzIuWUybk0/BIUDpYPMMAT1pQXSSi12ha4F9W0NbgXl taTvSIRC2/G+9i251Dlh7yEvvQ== X-Google-Smtp-Source: ACHHUZ7pG+VcDhnYcPXPWKXn1KF3tKNtHMs0GXR6hgyC12Y4Ljrm05mPwTWUUQcZuf/RDgALD7twgg== X-Received: by 2002:a05:6a20:a108:b0:100:b92b:e8be with SMTP id q8-20020a056a20a10800b00100b92be8bemr17647567pzk.2.1683849909261; Thu, 11 May 2023 17:05:09 -0700 (PDT) Received: from laputa ([2400:4050:c3e1:100:f0e3:df11:b680:3d8f]) by smtp.gmail.com with ESMTPSA id p16-20020a170902e75000b001aadd0d7364sm6531603plf.83.2023.05.11.17.05.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 May 2023 17:05:08 -0700 (PDT) Date: Fri, 12 May 2023 09:05:05 +0900 From: AKASHI Takahiro To: Ilias Apalodimas Cc: Heinrich Schuchardt , trini@konsulko.com, u-boot@lists.denx.de Subject: Re: [PATCH v2] efi_loader: Fix warnings for unaligned accesses Message-ID: <20230512000505.GA8438@laputa> Mail-Followup-To: AKASHI Takahiro , Ilias Apalodimas , Heinrich Schuchardt , trini@konsulko.com, u-boot@lists.denx.de References: <20230511164035.913574-1-ilias.apalodimas@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 Hi Ilias, On Thu, May 11, 2023 at 08:00:32PM +0300, Ilias Apalodimas wrote: > Hi Heinrich, > > On Thu, 11 May 2023 at 19:56, Heinrich Schuchardt wrote: > > > > On 5/11/23 18:40, Ilias Apalodimas wrote: > > > 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 > > > --- > > > 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(-) > > > > > > 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]; I thought that you have agreed with my comment, saying keep "efi_guid_t" here. https://lists.denx.de/pipermail/u-boot/2023-April/515831.html -Takahiro Akashi > > > u32 layout_descriptor_string_offset; > > > u8 descriptor_count; > > > /* struct efi_key_descriptor descriptors[]; follows here */ > > > -- > > > 2.39.2 > > > > > > > Thank you for investigating this in depth. > > yw :) > > > > > Commit messages should preferably limited to 75 characters per line, see > > scripts/checkpatch.pl. No need to resubmit. > > Yea I know, I just prefered to keep the clang warning intact in the > commit message > > Thanks > /Ilias > > > > Reviewed-by: Heinrich Schuchardt