Received: by 2002:a05:6358:51dd:b0:131:369:b2a3 with SMTP id 29csp253512rwl; Wed, 9 Aug 2023 14:06:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE8Pcv3i46xhjxqBwFr410xRs4a2I8GqtFQouzT4mLV0Sr/jHfVJiPQnqazV8wu6a74L9FI X-Received: by 2002:a50:ef13:0:b0:522:37ca:a51c with SMTP id m19-20020a50ef13000000b0052237caa51cmr262569eds.40.1691615169019; Wed, 09 Aug 2023 14:06:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691615169; cv=none; d=google.com; s=arc-20160816; b=H7Z/X71SVodasyM0TgVKfDXJRCngmqTlhn40WxwSpXKFU/PMEWsQHJOwe1Mqz3bgaO ND5cy27JjHmRIU73c0xJeHmZQYvvQLh4b+lxV9twK3RIGfbXQDwcRixs0Dx3aHY3Fbxh JzmirnLrJFpsHclLxiApE2QzfAIHr2ESRljcr0sBFcBRTtav+ji903c+AuphxZJFFQDi hobOSNx73rwp9qiSVS0YKICWRWDl8QDULrjKHvzkH7J0rIFKF+X0c8itwZjI+K02b6Cp nQfttSr+H0CRagbHiWoE5q7y5XHiwJWL8ZvLzt/jqqPpe30eKIXoHjRe5uw5J5iVS0Xs p49Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=bqFcX9n0/AXL5Snz2n5C8CYOWe+BpAWNtYa9e5JE8Gw=; fh=riAOv9V+ghdazpURgId1Gqe5a57537ihrnczGgO1KZY=; b=TaI5cMXD0yiz7Sz6E1ntbY0O4FEcW1JlQ8lK+ZHAbZpm4U7NAI39FAw4AdDaJlEe6d 51/VoRbA3bNOxqTgEKdS72NRXtB2gjSaiukdf8ZBGUTnjk0+g+fyQANMbEHaaN4up1S2 btNiCmQcU3zJC3R0kzbXyNfjxltIHScrPOE346AQvH3eveSLoW3S9GR5JpdHjmwUclMM oz//yNvWA1a7d6HBZo+380AomzJeAV1MST/F6KAxSboGNED3Q73pq86PXTeIWOXddqOV nupO3I8COCEoSrWRth+13f4kogm6K6qSb1s6i+WHqgGXXjtQMpsKj9tcIzttwQ2aygBJ bVzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=AYR8q7xP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e21-20020a50fb95000000b0052328ffc610si7361952edq.249.2023.08.09.14.05.44; Wed, 09 Aug 2023 14:06:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=AYR8q7xP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234453AbjHIUc4 (ORCPT + 99 others); Wed, 9 Aug 2023 16:32:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229620AbjHIUcz (ORCPT ); Wed, 9 Aug 2023 16:32:55 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 680B52103 for ; Wed, 9 Aug 2023 13:32:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1691613128; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=bqFcX9n0/AXL5Snz2n5C8CYOWe+BpAWNtYa9e5JE8Gw=; b=AYR8q7xPH+1j7/qZ//grOe2B+LSaaWKVN8DXgJosp6OtiC2p9NgAvBIc3lXaXzAYGJkPKN BZvKyUp7DRsTGqt/lMSdgGiKRCCGyrW+A75qSSbL8TcHGfJW1YfLstI2Auczcp9KNN4sck 01y8H/uFoicbbSUznL79pUAQCSFd2lo= Received: from mimecast-mx02.redhat.com (66.187.233.73 [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-685-EyRVbDjEMWOzvL_gLHDfPQ-1; Wed, 09 Aug 2023 16:32:06 -0400 X-MC-Unique: EyRVbDjEMWOzvL_gLHDfPQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 830253C0DDB9; Wed, 9 Aug 2023 20:32:06 +0000 (UTC) Received: from localhost (unknown [10.39.192.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 450CC140E96D; Wed, 9 Aug 2023 20:32:04 +0000 (UTC) Date: Wed, 9 Aug 2023 16:24:58 -0400 From: Stefan Hajnoczi To: Jason Gunthorpe Cc: Alex Williamson , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] vfio: align capability structures Message-ID: <20230809202458.GB2852727@fedora> References: <20230803144109.2331944-1-stefanha@redhat.com> <20230803151823.4e5943e6.alex.williamson@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="ewDSavC46Cyk/Sng" Content-Disposition: inline In-Reply-To: X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --ewDSavC46Cyk/Sng Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Aug 08, 2023 at 08:29:25PM -0300, Jason Gunthorpe wrote: > On Thu, Aug 03, 2023 at 03:18:23PM -0600, Alex Williamson wrote: >=20 > > diff --git a/drivers/vfio/vfio_main.c b/drivers/vfio/vfio_main.c > > index 902f06e52c48..2d074cbd371d 100644 > > --- a/drivers/vfio/vfio_main.c > > +++ b/drivers/vfio/vfio_main.c > > @@ -1362,6 +1362,8 @@ struct vfio_info_cap_header *vfio_info_cap_add(st= ruct vfio_info_cap *caps, > > void *buf; > > struct vfio_info_cap_header *header, *tmp; > > =20 > > + size =3D ALIGN(size, sizeof(u64)); > > + > > buf =3D krealloc(caps->buf, caps->size + size, GFP_KERNEL); > > if (!buf) { > > kfree(caps->buf); > > @@ -1395,6 +1397,8 @@ void vfio_info_cap_shift(struct vfio_info_cap *ca= ps, size_t offset) > > struct vfio_info_cap_header *tmp; > > void *buf =3D (void *)caps->buf; > > =20 > > + WARN_ON(!IS_ALIGNED(offset, sizeof(u64))); > > + > > for (tmp =3D buf; tmp->next; tmp =3D buf + tmp->next - offset) > > tmp->next +=3D offset; > > } > > diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h > > index fa06e3eb4955..fd2761841ffe 100644 > > --- a/include/uapi/linux/vfio.h > > +++ b/include/uapi/linux/vfio.h > > @@ -217,6 +217,7 @@ struct vfio_device_info { > > __u32 num_regions; /* Max region index + 1 */ > > __u32 num_irqs; /* Max IRQ index + 1 */ > > __u32 cap_offset; /* Offset within info struct of first cap */ > > + __u32 pad; /* Size must be aligned for caps */ > > }; > > #define VFIO_DEVICE_GET_INFO _IO(VFIO_TYPE, VFIO_BASE + 7) > > =20 > > @@ -1444,6 +1445,7 @@ struct vfio_iommu_type1_info { > > #define VFIO_IOMMU_INFO_CAPS (1 << 1) /* Info supports caps */ > > __u64 iova_pgsizes; /* Bitmap of supported page sizes */ > > __u32 cap_offset; /* Offset within info struct of first cap */ > > + __u32 pad; /* Size must be aligned for caps */ > > }; >=20 > IMHO this is partially being caused by not using __aligned_u64 for the > other __u64's in the same struct.. >=20 > Both of these structs have u64s in them and many arches will > automatically add the above padding. __aligned_u64 will force the > reset to do it, and then making padding explicit as you have done will > make it really true. >=20 > This is a subtle x64/x32 compatability issue also. It is probably best > just to do the change across the whole header file. I will send a separate series that switches the struct definitions to __aligned_u64. > Please also include the matching hunk for iommufd: >=20 > --- a/drivers/iommu/iommufd/vfio_compat.c > +++ b/drivers/iommu/iommufd/vfio_compat.c > @@ -483,6 +483,8 @@ static int iommufd_vfio_iommu_get_info(struct iommufd= _ctx *ictx, > rc =3D cap_size; > goto out_put; > } > + cap_size =3D ALIGN(cap_size, sizeof(u64)); > + > if (last_cap && info.argsz >=3D total_cap_size && > put_user(total_cap_size, &last_cap->next)) { > rc =3D -EFAULT; Okay, will fix. Stefan --ewDSavC46Cyk/Sng Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEEhpWov9P5fNqsNXdanKSrs4Grc8gFAmTT9hoACgkQnKSrs4Gr c8hfNQf9Ep+MFw6fuOjO2uXkkTRrzYDdXnDkRsjFw02p9qwpa2HNoo3GsvFouF7R UdgnX9fZxBjgYmTz6yQjCpg2aqhZTQzJeFqoeyaNzyoY8xgehsr6sD+AlY3EMiyw zJcF0X9FA/EklB6zGbMNtvyqxszIL2fEQEQFXioXnkut+L4H3M6guNuLPxjE/PIL O8uAmaZHRpw3DOA2MPUU+LY0lxn1+hPCoY/pz5ksNbkPCltLySbb/64JTwYZc2EA AxD424qBvka0nEgC7fxmPitWE32K78jRCM/gmWdvA3viq2YmReWaAQJSx9Bkttl+ ZUXxYyjQw0UDv/1OkRm0wY7JdKpBmA== =5aKp -----END PGP SIGNATURE----- --ewDSavC46Cyk/Sng--