From patchwork Mon Sep 18 20:56:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 14169 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp2953743vqi; Mon, 18 Sep 2023 14:08:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG8c9s0noWQ5xWYG7vzkVpM4bBlchj79UceHRMGoje5NwJhMnvMaEvTdhd5DjHS6RXtB9Po X-Received: by 2002:a05:6a00:c8d:b0:68f:cc67:e723 with SMTP id a13-20020a056a000c8d00b0068fcc67e723mr9267437pfv.17.1695071334369; Mon, 18 Sep 2023 14:08:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695071334; cv=none; d=google.com; s=arc-20160816; b=IDBbx9bleJWVVyNZlq87WfYe/YgbKWGGYQ6LRpXb52nk3Lkbs+axNjMmMlrAnMQBOO 2gs7Y/mzf9ajDuKZ1Jjm+7lqhDBPL1xFyAlTwC6zxJ/I7K9e14RYjVhgkVXTZ2wmNJNK 72c4MKI4GDuYhtqmJvXv02i/NUzK4JmJ+zyXXZWxTUmJyqNyQaWjlaIevjZL6pDQv6UZ b8VQwaDM5Xz93tob63jhEWMc0q88GBxkVc/LQchD3nzcVuZ0xBD9JIHlsMS3Qw6wRm+g yCvYuP+RQOWFFMR1ZmbkkFd0RpWwpty9Eqm9uwNy6xp/oCL8FLqxzEpqa5SEnHyC1Rf6 VKGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=Xi9oKb7wFPrQQdMnj2W18GElU0mEnwlSVsbSjcB2VJk=; fh=96HO1jz3bXAXthw3m3qvE5TGYQUSL46uSNZrHCuZ2IM=; b=k8M05V7vrCnnvuMvU4X7cNDUOHzcp1M6/+fxbXjT4Z7RCVZcyuVfUXMKuWG67T8Ipo 5W/i3Na/vqDGtJwRkPzpmowe1Zq+0dO3pSpXhtKzCqZQSruVnsfsOAQI7NzixBF+lBe6 sICmD7yBbk3fpUzbnjYPKkx/+YTdiMMgXH3cgEFoUV3DlvqhB3+Cn+Hkg6V0H7aPbGc0 lUbf81UhC26/+OlJ6JVph++HT4dNS+b1a3D4lN+wZG9Svn227kfIIGty2a11kfjXSOMt vVqPtwaJ+lCL6wMsRz++k3pvE5ylzlKiKEkj+ooi4ve3OSGdRiLsgTW378SFRxaVYxAL bXlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=V4M9JoRg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id i69-20020a638748000000b00578aa7b0e03si440140pge.695.2023.09.18.14.08.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 14:08:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=V4M9JoRg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id A592081B801A; Mon, 18 Sep 2023 13:57:11 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229988AbjIRU5L (ORCPT + 25 others); Mon, 18 Sep 2023 16:57:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229554AbjIRU5K (ORCPT ); Mon, 18 Sep 2023 16:57:10 -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 A0B2B8E for ; Mon, 18 Sep 2023 13:56:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695070583; 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: content-transfer-encoding:content-transfer-encoding; bh=Xi9oKb7wFPrQQdMnj2W18GElU0mEnwlSVsbSjcB2VJk=; b=V4M9JoRg4DD8gVnC5/6Hy0wbQij7WpmJCp17c4XuaJYT8Qr0VazqfnedmHnsJRbBGzltqY oCFMHVnZItEfTZGdkN/KZivM3hDfC/q/BbY+QzHbtkyfMTxoLI31ePtrJX/CMOH+exZxl+ IxInhhKBFvZDBaytFVd1sW6J2sszpmA= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-617-cBnr55QAP7yX35TbiBvzXA-1; Mon, 18 Sep 2023 16:56:20 -0400 X-MC-Unique: cBnr55QAP7yX35TbiBvzXA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BDDE585A5A8; Mon, 18 Sep 2023 20:56:19 +0000 (UTC) Received: from localhost (unknown [10.39.195.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 39B7540C6EA8; Mon, 18 Sep 2023 20:56:18 +0000 (UTC) From: Stefan Hajnoczi To: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Jason Gunthorpe , Alex Williamson , David Laight , "Tian, Kevin" , Stefan Hajnoczi Subject: [PATCH v3 0/3] vfio: use __aligned_u64 for ioctl structs Date: Mon, 18 Sep 2023 16:56:14 -0400 Message-ID: <20230918205617.1478722-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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_BLOCKED,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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 18 Sep 2023 13:57:11 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777411119094002808 X-GMAIL-MSGID: 1777411119094002808 v3: - Remove the output struct sizing code that copied out zeroed fields at the end of the struct. Alex pointed out that new fields (or repurposing a field that was previously reserved) must be guarded by a flag and this means userspace won't access those fields when they are absent. v2: - Rebased onto https://github.com/awilliam/linux-vfio.git next to get the vfio_iommu_type1_info pad field [Kevin] - Fixed min(minsz, sizeof(dmabuf)) -> min(dmabuf.argsz, sizeof(dmabuf)) [Jason, Kevin] - Squashed Patch 3 (vfio_iommu_type1_info) into Patch 1 since it is trivial now that the padding field is already there. Jason Gunthorpe pointed out that u64 VFIO ioctl struct fields have architecture-dependent alignment. iommufd already uses __aligned_u64 to avoid this problem. See the __aligned_u64 typedef in for details on why it is a good idea for kernel<->user interfaces. This series modifies the VFIO ioctl structs to use __aligned_u64. Some of the changes preserve the existing memory layout on all architectures, so I put them together into the first patch. The remaining patches are for structs where explanation is necessary about why changing the memory layout does not break the uapi. Stefan Hajnoczi (3): vfio: trivially use __aligned_u64 for ioctl structs vfio: use __aligned_u64 in struct vfio_device_gfx_plane_info vfio: use __aligned_u64 in struct vfio_device_ioeventfd include/uapi/linux/vfio.h | 26 ++++++++++++++------------ drivers/gpu/drm/i915/gvt/kvmgt.c | 2 +- samples/vfio-mdev/mbochs.c | 2 +- samples/vfio-mdev/mdpy.c | 2 +- 4 files changed, 17 insertions(+), 15 deletions(-)