From patchwork Sat Feb 2 09:41:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 157336 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp1510372jaa; Sat, 2 Feb 2019 01:42:17 -0800 (PST) X-Google-Smtp-Source: AHgI3IZqpt/NmRP7R1S1s1nV51w2ZwdUNXhp6JdLqcQggAuWeDB49ViTBp3hTjEizdrGJAHVhkMP X-Received: by 2002:a63:c503:: with SMTP id f3mr5443214pgd.431.1549100537517; Sat, 02 Feb 2019 01:42:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549100537; cv=none; d=google.com; s=arc-20160816; b=SDoOLn9P2uy2nJldM9gfl7dwTaiAdsiGn9cV/I7MWmRMKF81v6Pe3cZ40tHz8eSp0h OCNqmXz1TkHo74PKAPlcC6yuecXz13Ib+kLNs5/Ppn6aVYVamUxMcyzzj+ePXOp5zXAN i0A/WF+8DQhqjFvIS7SF9/sp7NNhdwi+9PDK7UHU6enMgF4upar8Hg2gY+zNEu3HRh4g 152bsEIBU/kPeLepobJHQC3E6P9iR05k/rl2BmzXbOQcmIgaCrlDXxO9VoJwiZcFIEj3 +/jfuE22KyC7/O1jB8luWbhi3tE2/lSM5VO/UcZydoS4volRfLk+Q4OrodU/UhAE9F0K LSLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=O2XzZIsl3vvBFchu48mWrW+Bva6lWuZ8ML/K496KFP0=; b=kfVCPp1Nf4OqxJ/I3bsOnQ2oPtsrKeIAJV/FsgbhL4j9+a1nCAmwqS3W0bP2/2wVGC JKSjjIyo0zclkx06jqtKyJrkHo1sqswn0mwIaxGB52KC+OJ5q9tvUvlCGTDDoNGE7wC9 wG33xSMZ8rwOJbZLuLond4DtMYpB7tRfjn7IMk0JIoRbgfvt3Pk5E3eCJYwctx7sXfpH dTT+faPLlPG8gtKW+oWwQ6QkLjdJ/jUCDZcrOVSE28G3INi21QfYrJUlq5XjQCVOJ8If oA0CPgzyfAxsqIxsRFZ/p1khFVEFku+WX4A4ozeCXfebaJ2wa2OvIvTPGzMOcF3SXRvf v5zw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Xc+QCRFS; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y26si9951364pfd.25.2019.02.02.01.42.17; Sat, 02 Feb 2019 01:42:17 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Xc+QCRFS; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727944AbfBBJmP (ORCPT + 31 others); Sat, 2 Feb 2019 04:42:15 -0500 Received: from mail-ed1-f68.google.com ([209.85.208.68]:43845 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727397AbfBBJle (ORCPT ); Sat, 2 Feb 2019 04:41:34 -0500 Received: by mail-ed1-f68.google.com with SMTP id f9so7433609eds.10 for ; Sat, 02 Feb 2019 01:41:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=O2XzZIsl3vvBFchu48mWrW+Bva6lWuZ8ML/K496KFP0=; b=Xc+QCRFSH4rqU01My7TyOmCVs82S37Gb0U7UVb81L0TmzDKVp8+pcJ2GFBFc8va+6e AaUZ5V2dYbFTTxdtn+JqRTVL6YdqY01wU8MGQU+B49KXGri7yYJCRO+P0qWdmu13XECE hkRppfRYCgn3xjhy4ITLLr4rYe/BvRaH1K3Nk= 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; bh=O2XzZIsl3vvBFchu48mWrW+Bva6lWuZ8ML/K496KFP0=; b=XG23/YCFkLzQLFkwrwt0lNzq9h3OKg+IIToF0BX+bQq8tglWYVPvIv/IuVlZS/TeWG 7GGD+t92P0cQDcA/QUOXyTXmf2tSvEyJHeydtnNoDbNteCGJdK3ylXJ5y4ULUXWdL2jN YiLlBoqoQoiwUDXzAxmiSsGpzx8rJgvwTFMd9ZjjVePpHxHVXH8qGgYt1qxopp8uthc+ mSSMnFq9Ruw85VLtW406SdTHaCMQpjr7/UynRboM4KrvcLSjYGwc/Pd0oKdYU5XGhkXx RWv81r14+dHv2shcOSweelQt4o+Kqum48l3hd2K2WSzMSZvXd6mr65dCvFy1h4MplXhG P2Hw== X-Gm-Message-State: AJcUukcsnCDXf5TkqYhe9xtQ9saM0s48GMwC/uRrrLQfTc0qlYy00Mu6 3ffScxGC8V75v5QHfH4voS6+mw== X-Received: by 2002:aa7:d9d6:: with SMTP id v22mr41768865eds.265.1549100492978; Sat, 02 Feb 2019 01:41:32 -0800 (PST) Received: from mba13.c.hoisthospitality.com ([109.236.135.164]) by smtp.gmail.com with ESMTPSA id l41sm2608824eda.83.2019.02.02.01.41.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 02 Feb 2019 01:41:32 -0800 (PST) From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Ard Biesheuvel , linux-kernel@vger.kernel.org, AKASHI Takahiro , Alexander Graf , Bjorn Andersson , Borislav Petkov , Heinrich Schuchardt , Jeffrey Hugo , Lee Jones , Leif Lindholm , Linus Torvalds , Peter Jones , Peter Zijlstra , Sai Praneeth Prakhya Subject: [PATCH 04/10] efi: use 32-bit alignment for efi_guid_t Date: Sat, 2 Feb 2019 10:41:13 +0100 Message-Id: <20190202094119.13230-5-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190202094119.13230-1-ard.biesheuvel@linaro.org> References: <20190202094119.13230-1-ard.biesheuvel@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The UEFI spec and EDK2 reference implementation both define EFI_GUID as struct { u32 a; u16; b; u16 c; u8 d[8]; }; and so the implied alignment is 32 bits not 8 bits like our guid_t. In some cases (i.e., on 32-bit ARM), this means that firmware services invoked by the kernel may assume that efi_guid_t* arguments are 32-bit aligned, and use memory accessors that do not tolerate misalignment. So let's set the minimum alignment to 32 bits. Note that the UEFI spec as well as some comments in the EDK2 code base suggest that EFI_GUID should be 64-bit aligned, but this appears to be a mistake, given that no code seems to exist that actually enforces that or relies on it. Reported-by: Heinrich Schuchardt Reviewed-by: Leif Lindholm Signed-off-by: Ard Biesheuvel --- include/linux/efi.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) -- 2.17.1 diff --git a/include/linux/efi.h b/include/linux/efi.h index 45ff763fba76..be08518c2553 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -48,7 +48,20 @@ typedef u16 efi_char16_t; /* UNICODE character */ typedef u64 efi_physical_addr_t; typedef void *efi_handle_t; -typedef guid_t efi_guid_t; +/* + * The UEFI spec and EDK2 reference implementation both define EFI_GUID as + * struct { u32 a; u16; b; u16 c; u8 d[8]; }; and so the implied alignment + * is 32 bits not 8 bits like our guid_t. In some cases (i.e., on 32-bit ARM), + * this means that firmware services invoked by the kernel may assume that + * efi_guid_t* arguments are 32-bit aligned, and use memory accessors that + * do not tolerate misalignment. So let's set the minimum alignment to 32 bits. + * + * Note that the UEFI spec as well as some comments in the EDK2 code base + * suggest that EFI_GUID should be 64-bit aligned, but this appears to be + * a mistake, given that no code seems to exist that actually enforces that + * or relies on it. + */ +typedef guid_t efi_guid_t __aligned(__alignof__(u32)); #define EFI_GUID(a,b,c,d0,d1,d2,d3,d4,d5,d6,d7) \ GUID_INIT(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7)