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 4077AC77B7C for ; Fri, 12 May 2023 05:28:25 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id E065386177; Fri, 12 May 2023 07:28:23 +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="ZcktwKZf"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8414E8617F; Fri, 12 May 2023 07:28:21 +0200 (CEST) Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) (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 BBDA786124 for ; Fri, 12 May 2023 07:28:18 +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-x430.google.com with SMTP id ffacd0b85a97d-3063b5f32aaso6159038f8f.2 for ; Thu, 11 May 2023 22:28:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1683869298; x=1686461298; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=6vBZEEnwaTAZq1ELMHy2T2YuFljA31HQdA8lwyA59eo=; b=ZcktwKZfEAuqic4EkFoJsrrgF215bz5E/dPpATjtSQ+e95X/eYgIOyUapFVQSZft1S vmUFhMJEo9ZMgm2YUBarJ6dtTEOQQFLWQD3J4Zo7o0tsIoV00PQ3wUXd2cTK0qqKhXdD RCjJvOJW47m3oxTXtgWY8AsAPNl9Gj/U4b7r9lIlJVUNIOQKthDqAvAr3EngE8k8U12z U+K+EBNFpbV+yM4RqHA+Gxp5C+6lIq/ZGjjyuIz7GlYRELdkt3wlLHjf65krD3lvcbxh htzSKNAGid5HAJSBhslpok3d/9avohJftcLN00oYR3Udbb24zhZnh5m2KqDBd5/2hJIA xlzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683869298; x=1686461298; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=6vBZEEnwaTAZq1ELMHy2T2YuFljA31HQdA8lwyA59eo=; b=lvAnIDIEMBnYVeSsJr1ClfsxDKj/UHoJrNzMi6itiZ01cgvdUGMkkRZhIFBew+zH4f v/ObTlc48K4lZn3JeH+2aCywAMmVNg18josqeLlDIKnukFo3fzfBX5sgQLFssN1hV9Oc pttKL2OFaur3yYpw/q2ABvtXKgLwUt+LpIPQiuqYnuJ0m5Vc7RyTFtowsuwnxPrSwvR6 nSaevCEoOmxUS0Eh98l73YGKjBHGO6MkJL2bmQDueW0YQWwahXVHdw4tKUCMigEfqxIN g1CMP/00X2vF8OWTkQ5P1ISVN80gHLAesLOhIGBGWve2tthg0rggAOwfymvB16kmjys3 8tDA== X-Gm-Message-State: AC+VfDx9kb3SeOSWnrHtPLpHdPKwfweObs/MEdFaDa/BBIOS0yeI1XNn 1teX9PG+PKXYsXcgXtxIpXm0eA== X-Google-Smtp-Source: ACHHUZ6rxjBaUGesYvYEHvZa1OEte/jrsFUPQ0cJ9bj7ZXZohUimeoX1SFJU4Oz3ZLm92K8vaxVWUA== X-Received: by 2002:a5d:45cd:0:b0:306:2b83:2d32 with SMTP id b13-20020a5d45cd000000b003062b832d32mr16889675wrs.43.1683869298050; Thu, 11 May 2023 22:28:18 -0700 (PDT) Received: from hera (ppp176092130041.access.hol.gr. [176.92.130.41]) by smtp.gmail.com with ESMTPSA id n3-20020a5d4003000000b003063176ef0dsm22304202wrp.97.2023.05.11.22.28.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 May 2023 22:28:17 -0700 (PDT) Date: Fri, 12 May 2023 08:28:15 +0300 From: Ilias Apalodimas To: AKASHI Takahiro , Heinrich Schuchardt , trini@konsulko.com, u-boot@lists.denx.de Subject: Re: [PATCH v2] efi_loader: Fix warnings for unaligned accesses Message-ID: References: <20230511164035.913574-1-ilias.apalodimas@linaro.org> <20230512000505.GA8438@laputa> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230512000505.GA8438@laputa> 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 Akashi-san, On Fri, May 12, 2023 at 09:05:05AM +0900, AKASHI Takahiro wrote: > 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 I changed my mind since then since keeping efi_guid_t is indeed a problem, so i won't silence that. The compiler might emit code with memory instructions that don't tolerate misalignment What we could do if we get more than one structs is add a efi_guid_ua_t which wont have the alignment requirements and use that. Regards /Ilias > > -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