From nobody Tue Apr 23 15:38:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1637335490; cv=none; d=zohomail.com; s=zohoarc; b=MvODyUZ+IzLrRRcurgPsuTizljTlQSyckbM7iobKO0tDgOaFckNdfwB2x24/qlxPoyFn4EJpyXtkwv4sjKIKLbJba/tXEfjllT8i6QgwVxqtq6Ip6QTpRAxNp9nJSnVXGME488pVzysPcOk3L2MkC/f6bTijJrPfHephERW6Yc0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1637335490; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=MeDObHg4WlpI4WwECEIFz0i5IyCX3lFHt4bSsUKE/WU=; b=es9C4ZR4CcZiHfsXCs6jgVIsmxKtjLwvN4iaMolTy2MB8e/uZmI/SVEKuUuAxe10NaVkXcIhbXVAWTGJ8n/+HItJVFyKUA0VNtEYcfepzhwOW8cSSkoZLp7NrQYh7mva3MVHhGfduA+iUeBHv0BnCBam9G/mKkSVChQJ9FGdalw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1637335490189234.3963193766724; Fri, 19 Nov 2021 07:24:50 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.228087.394597 (Exim 4.92) (envelope-from ) id 1mo5kW-00036R-5P; Fri, 19 Nov 2021 15:24:24 +0000 Received: by outflank-mailman (output) from mailman id 228087.394597; Fri, 19 Nov 2021 15:24:24 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mo5kW-00036K-2X; Fri, 19 Nov 2021 15:24:24 +0000 Received: by outflank-mailman (input) for mailman id 228087; Fri, 19 Nov 2021 15:24:22 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mo5kU-00036E-Cn for xen-devel@lists.xenproject.org; Fri, 19 Nov 2021 15:24:22 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mo5kU-0001xe-5j for xen-devel@lists.xenproject.org; Fri, 19 Nov 2021 15:24:22 +0000 Received: from iwj (helo=mariner.uk.xensource.com) by xenbits.xenproject.org with local-bsmtp (Exim 4.92) (envelope-from ) id 1mo5kU-0004P8-4Z for xen-devel@lists.xenproject.org; Fri, 19 Nov 2021 15:24:22 +0000 Received: from [172.18.45.5] (helo=zealot.relativity.greenend.org.uk) by mariner.uk.xensource.com with esmtp (Exim 4.89) (envelope-from ) id 1mo5kI-0005r3-Bm; Fri, 19 Nov 2021 15:24:10 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xenproject.org; s=20200302mail; h=Content-Transfer-Encoding:Content-Type: MIME-Version:Message-Id:Date:Subject:Cc:To:From; bh=MeDObHg4WlpI4WwECEIFz0i5IyCX3lFHt4bSsUKE/WU=; b=584+YM4a0GK4hq4mYODPbk5txb SO0nmVvTLs2jYZRI+eqhFcdVAXwix83Dv1m5wfOj6nmbwPHqr02gRZ40wXMT73/iqtHIzu27xtab4 wC3wj7B2PhHN2MX/y3dGRa2d9hQn695NM9oxuuPkadOMlruEB9m6gQcdf2xhkIrWZnqM=; From: Ian Jackson To: xen-devel@lists.xenproject.org Cc: iwj@xenproject.org, Roger Pau Monne , Jan Beulich , Andrew Cooper Subject: [PATCH for-4.16 v3] efi: fix alignment of function parameters in compat mode Date: Fri, 19 Nov 2021 15:24:03 +0000 Message-Id: <20211119152403.12069-1-iwj@xenproject.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xenproject.org) X-ZM-MESSAGEID: 1637335492183100001 From: Roger Pau Monne Currently the max_store_size, remain_store_size and max_size in compat_pf_efi_runtime_call are 4 byte aligned, which makes clang 13.0.0 complain with: In file included from compat.c:30: ./runtime.c:646:13: error: passing 4-byte aligned argument to 8-byte aligne= d parameter 2 of 'QueryVariableInfo' may result in an unaligned pointer acc= ess [-Werror,-Walign-mismatch] &op->u.query_variable_info.max_store_size, ^ ./runtime.c:647:13: error: passing 4-byte aligned argument to 8-byte aligne= d parameter 3 of 'QueryVariableInfo' may result in an unaligned pointer acc= ess [-Werror,-Walign-mismatch] &op->u.query_variable_info.remain_store_size, ^ ./runtime.c:648:13: error: passing 4-byte aligned argument to 8-byte aligne= d parameter 4 of 'QueryVariableInfo' may result in an unaligned pointer acc= ess [-Werror,-Walign-mismatch] &op->u.query_variable_info.max_size); ^ Fix this by bouncing the variables on the stack in order for them to be 8 byte aligned. Note this could be done in a more selective manner to only apply to compat code calls, but given the overhead of making an EFI call doing an extra copy of 3 variables doesn't seem to warrant the special casing. Signed-off-by: Roger Pau Monn=C3=A9 Release-Acked-by: Ian Jackson Reviewed-by: Ian Jackson Signed-off-by: Ian Jackson Reviewed-by: Jan Beulich --- Changes since v2: - Adjust the commentary as per discussion. Changes since v1: - Copy back the results. --- xen/common/efi/runtime.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/xen/common/efi/runtime.c b/xen/common/efi/runtime.c index 375b94229e..089bb0eb1b 100644 --- a/xen/common/efi/runtime.c +++ b/xen/common/efi/runtime.c @@ -607,6 +607,9 @@ int efi_runtime_call(struct xenpf_efi_runtime_call *op) break; =20 case XEN_EFI_query_variable_info: + { + uint64_t max_store_size, remain_store_size, max_size; + if ( op->misc & ~XEN_EFI_VARINFO_BOOT_SNAPSHOT ) return -EINVAL; =20 @@ -638,16 +641,36 @@ int efi_runtime_call(struct xenpf_efi_runtime_call *o= p) =20 if ( !efi_enabled(EFI_RS) || (efi_rs->Hdr.Revision >> 16) < 2 ) return -EOPNOTSUPP; + + /* + * Bounce the variables onto the stack to make them 8 byte aligned= when + * called from the compat handler, as their placement in + * compat_pf_efi_runtime_call will make them 4 byte aligned instea= d and + * and compilers may validly complain. + * + * Note that while the function parameters are OUT only, copy the + * values here anyway just in case. This is done regardless of whether + * called from the compat handler or not, as it's not worth the extra + * logic to differentiate. + */ + max_store_size =3D op->u.query_variable_info.max_store_size; + remain_store_size =3D op->u.query_variable_info.remain_store_size; + max_size =3D op->u.query_variable_info.max_size; + state =3D efi_rs_enter(); if ( !state.cr3 ) return -EOPNOTSUPP; status =3D efi_rs->QueryVariableInfo( - op->u.query_variable_info.attr, - &op->u.query_variable_info.max_store_size, - &op->u.query_variable_info.remain_store_size, - &op->u.query_variable_info.max_size); + op->u.query_variable_info.attr, &max_store_size, &remain_store= _size, + &max_size); efi_rs_leave(&state); + + op->u.query_variable_info.max_store_size =3D max_store_size; + op->u.query_variable_info.remain_store_size =3D remain_store_size; + op->u.query_variable_info.max_size =3D max_size; + break; + } =20 case XEN_EFI_query_capsule_capabilities: case XEN_EFI_update_capsule: --=20 2.20.1