Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp339543rdb; Mon, 18 Sep 2023 17:42:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEXC8uwoZzFWdILC6rgn7mXVKrHjQIWo3ArFHRNZ0xu/I4+5ufixwXihl0ZPmI7XEse4KTy X-Received: by 2002:a17:902:ec83:b0:1bb:fcb9:f85 with SMTP id x3-20020a170902ec8300b001bbfcb90f85mr1423950plg.32.1695084154186; Mon, 18 Sep 2023 17:42:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695084154; cv=none; d=google.com; s=arc-20160816; b=mM2+5zn/TFP5BSHs//hPvrQKk1Art0ctDdXntIl7A1IyOyIC2tQv3gP3djVQ/0nhPz yPWgd+K5pw+WZ2i75nJvyvgj96iO1kXxIITQc1vadd+ma8aF2JgTOrc08tE70q9P1BiO QBiaH5D7dQXWRYBH7PJ50KB8FFaXw+CQ2j03/LkwBTJPE/vLDsFWbNVO/DVe/alb+TkS tgUkRaKoRp1XFeXeiBzvENvNPnRTmnuVm/xGP77G74aiYLmrRNlC8GF78lWU/TFTvS6+ TYbG67gfQcaYpvRfvwxayJxEqKXMO75vHMUNJaccbEuizOh5ecRgZVWCgqp7GZV4P19V k56A== 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 23.128.96.31 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 morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id a13-20020a170902eccd00b001bf0ad16519si9285805plh.513.2023.09.18.17.42.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 17:42:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; 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 23.128.96.31 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 morse.vger.email (Postfix) with ESMTP id AAFCF8095DFB; Mon, 18 Sep 2023 13:57:21 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230099AbjIRU5S (ORCPT + 99 others); Mon, 18 Sep 2023 16:57:18 -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 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 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 morse.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 (morse.vger.email [0.0.0.0]); Mon, 18 Sep 2023 13:57:21 -0700 (PDT) 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); -- 2.41.0