From patchwork Mon Sep 18 20:56:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 141882 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp3364071vqi; Tue, 19 Sep 2023 06:01:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGfOqo2UYVIaRXwQNuNBJfWb5PIjP/VVZdNIiVIa8JDsAOUVgYe5x2hqaZMQ5TvYvkPoaLr X-Received: by 2002:a17:903:2286:b0:1b8:76fc:5bf6 with SMTP id b6-20020a170903228600b001b876fc5bf6mr14556548plh.43.1695128480830; Tue, 19 Sep 2023 06:01:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695128480; cv=none; d=google.com; s=arc-20160816; b=FwOIm3VUaXO7dupMoHOVyBNkWFs8zzejorf9LpMFXcvf2KBuDmkT79Sv0cXRjYHx2+ cQ1y/aVKfo8V7ex4Pqmy4nOI3ogWbIWVjSZUyZZ5a1zbmvB9wEbpN3Z//Mf1x77H651o Z3mcnOEBeaz3pid3AIYB+Mk6IO8tdKrmbS44vinfpstDa2/d9xKlYWwX3YTREeWDunaN KpkmuXTu5IssD+K0ez5U0qnDhq5Mi4kI+uI706+MruiqWFvrDXvhviC4RrYILH6JOL/d jkBqCWsIiXHFOf6gQzC+69bsO6iUcm9QkA2Dz38Vc/xKw4w5chbLD0PE3xVOejP0OFyu rpew== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=BLJVBc/pzccugePJdqT4Or41HsOp/4DxwdzX8mZIktY=; fh=rtm8eCWQTZN1DdtHrlyuNr29zexmVCqfq1PTVUama8o=; b=fCaYvUPT7y0ZmaluqGDE6r37YGCLcxrX7lvKdZd2Dpxb4kK2VLU0sYN0mTYKDOfYcg Rj0s0yjTt1CydY8eh5PreWxDKrODsmXDcGvs0DZRQrAxpgifF+juaoo5pCDdpZfHn7MD vZkVxrSIDakWlClyFfC5l/ZLRVHWBhpVXd19h5o1Ar4FiEjRcg/try7XJmdLqVauwpBy ZRCkssjV7jSU9HcEt8189qgwaHTFtwoEc9SR3X6oWRkRyEN33iFjgDrw+JmKIQTegun4 yt4/tqYwrsUMz0vLTyKZcuhIxio3YpAmYGw+YY5iW2QZVn9lSwQm/LJkTbriq5YQw2hf zpIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="X4+SNYw/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id s18-20020a17090330d200b001b25e9a76d7si9356499plc.316.2023.09.19.06.01.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 06:01:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="X4+SNYw/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (Postfix) with ESMTP id 7921D823EF1B; Mon, 18 Sep 2023 13:57:46 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230142AbjIRU5W (ORCPT + 25 others); Mon, 18 Sep 2023 16:57:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230078AbjIRU5R (ORCPT ); Mon, 18 Sep 2023 16:57:17 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B3483115 for ; Mon, 18 Sep 2023 13:56:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695070587; 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: in-reply-to:in-reply-to:references:references; bh=BLJVBc/pzccugePJdqT4Or41HsOp/4DxwdzX8mZIktY=; b=X4+SNYw/FuXqUJ4KyJkwYfzOVVERp8CdeJrzw2X/vg1+QF+6x392KRuvxKiUBhvPdOGco0 BOW9aiyNHiHqdfNZv4DhYSNYmbxzRUx/rfwT2y7BIQdbNhQJ8xwiGbBCsdXoq54WsC8vwr VQdDUYWmWH5lVu1I+iDb1edFDUJWjkE= 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-150-CjqjOcAdPzOEQ4KcAmIYmg-1; Mon, 18 Sep 2023 16:56:22 -0400 X-MC-Unique: CjqjOcAdPzOEQ4KcAmIYmg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (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 96B51800883; Mon, 18 Sep 2023 20:56:21 +0000 (UTC) Received: from localhost (unknown [10.39.195.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1BD9040C2064; Mon, 18 Sep 2023 20:56:20 +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 , Jason Gunthorpe , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v3 1/3] vfio: trivially use __aligned_u64 for ioctl structs Date: Mon, 18 Sep 2023 16:56:15 -0400 Message-ID: <20230918205617.1478722-2-stefanha@redhat.com> In-Reply-To: <20230918205617.1478722-1-stefanha@redhat.com> References: <20230918205617.1478722-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email 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 (fry.vger.email [0.0.0.0]); Mon, 18 Sep 2023 13:57:46 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777471042204503755 X-GMAIL-MSGID: 1777471042204503755 u64 alignment behaves differently depending on the architecture and so offers __aligned_u64 to achieve consistent behavior in kernel<->userspace ABIs. There are structs in that can trivially be updated to __aligned_u64 because the struct sizes are multiples of 8 bytes. There is no change in memory layout on any CPU architecture and therefore this change is safe. The commits that follow this one handle the trickier cases where explanation about ABI breakage is necessary. Suggested-by: Jason Gunthorpe Reviewed-by: Jason Gunthorpe Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Kevin Tian Signed-off-by: Stefan Hajnoczi --- include/uapi/linux/vfio.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h index afc1369216d9..4dc0182c6bcb 100644 --- a/include/uapi/linux/vfio.h +++ b/include/uapi/linux/vfio.h @@ -277,8 +277,8 @@ struct vfio_region_info { #define VFIO_REGION_INFO_FLAG_CAPS (1 << 3) /* Info supports caps */ __u32 index; /* Region index */ __u32 cap_offset; /* Offset within info struct of first cap */ - __u64 size; /* Region size (bytes) */ - __u64 offset; /* Region offset from start of device fd */ + __aligned_u64 size; /* Region size (bytes) */ + __aligned_u64 offset; /* Region offset from start of device fd */ }; #define VFIO_DEVICE_GET_REGION_INFO _IO(VFIO_TYPE, VFIO_BASE + 8) @@ -294,8 +294,8 @@ struct vfio_region_info { #define VFIO_REGION_INFO_CAP_SPARSE_MMAP 1 struct vfio_region_sparse_mmap_area { - __u64 offset; /* Offset of mmap'able area within region */ - __u64 size; /* Size of mmap'able area */ + __aligned_u64 offset; /* Offset of mmap'able area within region */ + __aligned_u64 size; /* Size of mmap'able area */ }; struct vfio_region_info_cap_sparse_mmap { @@ -450,9 +450,9 @@ struct vfio_device_migration_info { VFIO_DEVICE_STATE_V1_RESUMING) __u32 reserved; - __u64 pending_bytes; - __u64 data_offset; - __u64 data_size; + __aligned_u64 pending_bytes; + __aligned_u64 data_offset; + __aligned_u64 data_size; }; /* @@ -476,7 +476,7 @@ struct vfio_device_migration_info { struct vfio_region_info_cap_nvlink2_ssatgt { struct vfio_info_cap_header header; - __u64 tgt; + __aligned_u64 tgt; }; /* @@ -1449,7 +1449,7 @@ struct vfio_iommu_type1_info { __u32 flags; #define VFIO_IOMMU_INFO_PGSIZES (1 << 0) /* supported page sizes info */ #define VFIO_IOMMU_INFO_CAPS (1 << 1) /* Info supports caps */ - __u64 iova_pgsizes; /* Bitmap of supported page sizes */ + __aligned_u64 iova_pgsizes; /* Bitmap of supported page sizes */ __u32 cap_offset; /* Offset within info struct of first cap */ __u32 pad; }; From patchwork Mon Sep 18 20:56:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 141581 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp2966004vqi; Mon, 18 Sep 2023 14:33:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGQM8yRUuma8QOeWEgBTRF3bjRKtwsvgW3PuIsRCRoU0vRxhNsUKTD11HSmghHWS1gwdQBs X-Received: by 2002:a17:902:e546:b0:1bf:7dfd:5b05 with SMTP id n6-20020a170902e54600b001bf7dfd5b05mr718408plf.27.1695072786929; Mon, 18 Sep 2023 14:33:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695072786; cv=none; d=google.com; s=arc-20160816; b=RSfAwNWW2h0XY02cV6sHf+eHY+uD6oI9ASIM1XvnwTJOdTmYU6v8FNl9FhzDvFLLoL 1uyFe/Db/jn+Q28KTu5+5rSiTNaCvbgtEjZ1ItQ0l7GXv32gG3ov5fi0ujazJqbMDvfH rUp9MhMjbSNppMrZHi4VxVYD8+gNviY2eFev+ZtwgQHVWEOidXQ9G1llGfj2DwVBhAIP Cz4WmYdxo7rEpjV5WRoeN2hh8+Idh6tVYJSHOCYgj9qNzXrjj0GSLFKXsJp7ed6vLhLX JDEma/d4VtqV/01O6PiuCyr0YfkR80rqeY0n8buZxHJCKMNlIboxppXKxw+fqHfFj2yf +rNQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=FQDD0pkq9/UtADo9UYzkWMKduX2RKacPnCgn9XTsyXU=; fh=96HO1jz3bXAXthw3m3qvE5TGYQUSL46uSNZrHCuZ2IM=; b=iIs0Cm3RqOQQAeR/J6y7UVGTwCJnhFpZ6fQxVW7gX0nqeL9KviXuxf6nMtrr4hImGT 5y241lOu0MXLANdaq6bXIOFq54OW+FVBgy9bSY9Co7O1jkTN8lssUbYKJTfUE/g1xenL 1adLkWHKN0RofEvLcVS1LgKZ9t3gGPI2wt2Ceb4RAQ0S7F2c4uMsG1D51bgWDqkKNwhr V9HfzLpvuE96hO4d56Rmj5sp0duTva06xR5TwAxxEO3oR03yhaJAS2mz83eikjMRjb9O jVh2hVtdkm43cSVGNv9KJ+RTeP5VxrZExCiv4aujt8UTwUCQwyXHOJ3Tpvh1NuutdCc2 5HkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=HK9FygUE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id o15-20020a170902d4cf00b001c1e4f9c63esi8992425plg.491.2023.09.18.14.33.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 14:33:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=HK9FygUE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (Postfix) with ESMTP id B36918091C67; Mon, 18 Sep 2023 13:57:23 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230124AbjIRU5T (ORCPT + 25 others); Mon, 18 Sep 2023 16:57:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230071AbjIRU5Q (ORCPT ); Mon, 18 Sep 2023 16:57:16 -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 1482E116 for ; Mon, 18 Sep 2023 13:56:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695070587; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FQDD0pkq9/UtADo9UYzkWMKduX2RKacPnCgn9XTsyXU=; b=HK9FygUEgLxMFD9TnSsFd9wEs0XhTCjvS6uTIIZox0E3z5PFKiZnX4pi4DDOLj+6Q3y6Z1 Hq/uu+Y8njjU0ENpghsNTuO4pEFRQk84Sjt8rzCb4+RLTG0w8L3OkgO1c6BAOt/d9EDs/n gfSO1P3Gchpx6v9YhkN35h/A5u3Rw+I= 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-201-a0vd4XBkPZaB3qrBnjW9Nw-1; Mon, 18 Sep 2023 16:56:23 -0400 X-MC-Unique: a0vd4XBkPZaB3qrBnjW9Nw-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (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 7456E101A585; Mon, 18 Sep 2023 20:56:23 +0000 (UTC) Received: from localhost (unknown [10.39.195.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id E01D0492B16; Mon, 18 Sep 2023 20:56:22 +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 2/3] vfio: use __aligned_u64 in struct vfio_device_gfx_plane_info Date: Mon, 18 Sep 2023 16:56:16 -0400 Message-ID: <20230918205617.1478722-3-stefanha@redhat.com> In-Reply-To: <20230918205617.1478722-1-stefanha@redhat.com> References: <20230918205617.1478722-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 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=unavailable 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 (howler.vger.email [0.0.0.0]); Mon, 18 Sep 2023 13:57:23 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777412642350411214 X-GMAIL-MSGID: 1777412642350411214 The memory layout of struct vfio_device_gfx_plane_info is architecture-dependent due to a u64 field and a struct size that is not a multiple of 8 bytes: - On x86_64 the struct size is padded to a multiple of 8 bytes. - On x32 the struct size is only a multiple of 4 bytes, not 8. - Other architectures may vary. Use __aligned_u64 to make memory layout consistent. This reduces the chance of 32-bit userspace on a 64-bit kernel breakage. This patch increases the struct size on x32 but this is safe because of the struct's argsz field. The kernel may grow the struct as long as it still supports smaller argsz values from userspace (e.g. applications compiled against older kernel headers). Suggested-by: Jason Gunthorpe Reviewed-by: Kevin Tian Signed-off-by: Stefan Hajnoczi --- include/uapi/linux/vfio.h | 3 ++- drivers/gpu/drm/i915/gvt/kvmgt.c | 2 +- samples/vfio-mdev/mbochs.c | 2 +- samples/vfio-mdev/mdpy.c | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h index 4dc0182c6bcb..ee98b6d4a112 100644 --- a/include/uapi/linux/vfio.h +++ b/include/uapi/linux/vfio.h @@ -816,7 +816,7 @@ struct vfio_device_gfx_plane_info { __u32 drm_plane_type; /* type of plane: DRM_PLANE_TYPE_* */ /* out */ __u32 drm_format; /* drm format of plane */ - __u64 drm_format_mod; /* tiled mode */ + __aligned_u64 drm_format_mod; /* tiled mode */ __u32 width; /* width of plane */ __u32 height; /* height of plane */ __u32 stride; /* stride of plane */ @@ -829,6 +829,7 @@ struct vfio_device_gfx_plane_info { __u32 region_index; /* region index */ __u32 dmabuf_id; /* dma-buf id */ }; + __u32 reserved; }; #define VFIO_DEVICE_QUERY_GFX_PLANE _IO(VFIO_TYPE, VFIO_BASE + 14) diff --git a/drivers/gpu/drm/i915/gvt/kvmgt.c b/drivers/gpu/drm/i915/gvt/kvmgt.c index 42ce20e72db7..faf21be724c3 100644 --- a/drivers/gpu/drm/i915/gvt/kvmgt.c +++ b/drivers/gpu/drm/i915/gvt/kvmgt.c @@ -1379,7 +1379,7 @@ static long intel_vgpu_ioctl(struct vfio_device *vfio_dev, unsigned int cmd, intel_gvt_reset_vgpu(vgpu); return 0; } else if (cmd == VFIO_DEVICE_QUERY_GFX_PLANE) { - struct vfio_device_gfx_plane_info dmabuf; + struct vfio_device_gfx_plane_info dmabuf = {}; int ret = 0; minsz = offsetofend(struct vfio_device_gfx_plane_info, diff --git a/samples/vfio-mdev/mbochs.c b/samples/vfio-mdev/mbochs.c index 3764d1911b51..93405264ff23 100644 --- a/samples/vfio-mdev/mbochs.c +++ b/samples/vfio-mdev/mbochs.c @@ -1262,7 +1262,7 @@ static long mbochs_ioctl(struct vfio_device *vdev, unsigned int cmd, case VFIO_DEVICE_QUERY_GFX_PLANE: { - struct vfio_device_gfx_plane_info plane; + struct vfio_device_gfx_plane_info plane = {}; minsz = offsetofend(struct vfio_device_gfx_plane_info, region_index); diff --git a/samples/vfio-mdev/mdpy.c b/samples/vfio-mdev/mdpy.c index 064e1c0a7aa8..72ea5832c927 100644 --- a/samples/vfio-mdev/mdpy.c +++ b/samples/vfio-mdev/mdpy.c @@ -591,7 +591,7 @@ static long mdpy_ioctl(struct vfio_device *vdev, unsigned int cmd, case VFIO_DEVICE_QUERY_GFX_PLANE: { - struct vfio_device_gfx_plane_info plane; + struct vfio_device_gfx_plane_info plane = {}; minsz = offsetofend(struct vfio_device_gfx_plane_info, region_index); From patchwork Mon Sep 18 20:56:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 141701 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp3142902vqi; Mon, 18 Sep 2023 22:21:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHnbYjOXCTcn7QbrfCkLBpw8L/LsmTW6uKTQMTj7I4uKXNWIZpMC8ElvsXjXnxfwJ7LRGFK X-Received: by 2002:a05:6a21:193:b0:159:f884:4d6e with SMTP id le19-20020a056a21019300b00159f8844d6emr16751157pzb.40.1695100867713; Mon, 18 Sep 2023 22:21:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695100867; cv=none; d=google.com; s=arc-20160816; b=nVnOgttHs7Tt9EZDFoSOEH2YDoCS7wPsExXYCW2hX/sAagCLTXb5aMyiSCweYNhtnD auuWJQDmAfT96A2F4XEypUOnfcCsgg2I1YogxjHQSOTiyCiwdMYZz5vWtJN0BqyHjvJx d4mQQR8vaG6j/NNj32n72/i/lxVdLC1GIt7WbzxB07+XXStDC2GRtAX6NeZfrfQG964X YlzBhUwmOJLn0pJfgMCPNMVl/suNQy5EIhtieQputOz/PSiYu+nDzVyAFqqR6fQ1oGq2 Xq+DJzwHdU1QK6N3dyNAyCoYGDQKv2IglogmHqWlC98U9niukKgDeNwtMga1nUmzFcsL KYwA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=yLsvJ8l6b+MBG1WK2YqkwTaPRwUV38lxkQNhQoUhHr4=; fh=KiZLIkqQfz8t2DBe29nWgYmi9TZ/QkHWuFRiaNk6QnM=; b=AyENG9VLL8uQ0May3P5kCsXQj0xizUomK4sUteDoVhT7ClaMJaV5YbILd6/kZvMBwj nJ8M2es9yJ0QruC+yIbYBvmwgdNe5TfGwsF+Sxi7mG551i7mkADOBQG1tN6W6EEMbPue iVwqJUahuaIdsGVDZ2lxDqQpxmuwRt8OJC4aAupszDuyKmk1gvhTFVM5mXsd3ZRcD7PT kh23U7uiJo3Zu5uSU06zr7Vw/d5e+X7FQnoXJr6g92bjy5GRVYcrbeOVaQgK7VdCtYXk t3eDsw2wbPqrfJaoMR5xvMqiRkI9eMMyq/hBo6qyb2pr0xZbb/n+YDaEMPj8t1Z3A58b jdsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Sgmkz1z5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id s4-20020a17090a948400b00269584b6a10si2512372pjo.15.2023.09.18.22.21.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 22:21:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Sgmkz1z5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (Postfix) with ESMTP id 2A87E80934B9; Mon, 18 Sep 2023 13:57:29 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230158AbjIRU5Z (ORCPT + 25 others); Mon, 18 Sep 2023 16:57:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230083AbjIRU5R (ORCPT ); Mon, 18 Sep 2023 16:57:17 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E47EE126 for ; Mon, 18 Sep 2023 13:56:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695070589; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yLsvJ8l6b+MBG1WK2YqkwTaPRwUV38lxkQNhQoUhHr4=; b=Sgmkz1z5E/eYs0cNHrUb2U2SVRiA1enLs+j/OLDBsJL6qrszhZKNqinJebcVuhtmnUFUNk cXhGs/lCbUyJAue/YvWIlT1uXA4tb2tVfRE2dZipwu2iqUpXrXJUfP64SgAVxQ8oLQb6Ld ntY7dQdYhlBaKX4AE5sq4ksyBe6B9b8= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [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-418-udjHwg-TN4W0iNphIn-i9w-1; Mon, 18 Sep 2023 16:56:27 -0400 X-MC-Unique: udjHwg-TN4W0iNphIn-i9w-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 8338A3C11A00; Mon, 18 Sep 2023 20:56:26 +0000 (UTC) Received: from localhost (unknown [10.39.195.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 02F621C5BB; Mon, 18 Sep 2023 20:56:24 +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 , Jason Gunthorpe Subject: [PATCH v3 3/3] vfio: use __aligned_u64 in struct vfio_device_ioeventfd Date: Mon, 18 Sep 2023 16:56:17 -0400 Message-ID: <20230918205617.1478722-4-stefanha@redhat.com> In-Reply-To: <20230918205617.1478722-1-stefanha@redhat.com> References: <20230918205617.1478722-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 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_H3,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 (howler.vger.email [0.0.0.0]); Mon, 18 Sep 2023 13:57:29 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777442087427287457 X-GMAIL-MSGID: 1777442087427287457 The memory layout of struct vfio_device_ioeventfd is architecture-dependent due to a u64 field and a struct size that is not a multiple of 8 bytes: - On x86_64 the struct size is padded to a multiple of 8 bytes. - On x32 the struct size is only a multiple of 4 bytes, not 8. - Other architectures may vary. Use __aligned_u64 to make memory layout consistent. This reduces the chance that 32-bit userspace on a 64-bit kernel breakage. This patch increases the struct size on x32 but this is safe because of the struct's argsz field. The kernel may grow the struct as long as it still supports smaller argsz values from userspace (e.g. applications compiled against older kernel headers). The code that uses struct vfio_device_ioeventfd already works correctly when the struct size grows, so only the struct definition needs to be changed. Suggested-by: Jason Gunthorpe Reviewed-by: Jason Gunthorpe Reviewed-by: Kevin Tian Signed-off-by: Stefan Hajnoczi --- include/uapi/linux/vfio.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h index ee98b6d4a112..049ce8065a32 100644 --- a/include/uapi/linux/vfio.h +++ b/include/uapi/linux/vfio.h @@ -864,9 +864,10 @@ struct vfio_device_ioeventfd { #define VFIO_DEVICE_IOEVENTFD_32 (1 << 2) /* 4-byte write */ #define VFIO_DEVICE_IOEVENTFD_64 (1 << 3) /* 8-byte write */ #define VFIO_DEVICE_IOEVENTFD_SIZE_MASK (0xf) - __u64 offset; /* device fd offset of write */ - __u64 data; /* data to be written */ + __aligned_u64 offset; /* device fd offset of write */ + __aligned_u64 data; /* data to be written */ __s32 fd; /* -1 for de-assignment */ + __u32 reserved; }; #define VFIO_DEVICE_IOEVENTFD _IO(VFIO_TYPE, VFIO_BASE + 16)