Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp280233rdb; Mon, 18 Sep 2023 15:10:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH1bLASeT/4eB8glQDq9eNq6M3qg/mF0xi6KempbG0wVRE+APY5p8TdzNpfC/Z5fUTTNic8 X-Received: by 2002:a17:902:e881:b0:1bc:203f:3b3c with SMTP id w1-20020a170902e88100b001bc203f3b3cmr13707220plg.24.1695075015012; Mon, 18 Sep 2023 15:10:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695075014; cv=none; d=google.com; s=arc-20160816; b=m2fXjce1ONWsdQk+K7L6LNMh5HfDJdtjd2HyNiwSNbUliTlJPgxu17H8/3q8F2VdVA eTF3qxC2Tn/fGzjwtXMZo3bzt8RtuqProz2YLhlwB/j6utqOasfWGPLRIS3XtPhk+QHi 2i7ooKdvDFwW6cCT1kvJ6hXHWg88u6JFol/YuaNAIHbybkxMeqvnclKuhdS/+WQWwb41 +KBhHVcjBk8DWs38pK4VTTCgzW7QZbif97wEwHA+rICLd3QknsB5Zkqvt4RFxfrfCGm/ Dj+wdCsWF1AC4sSfDzQRnGfK/YDz/IpCI2J2ZN4HJXC/n/knYDOWzBCvWjE5IDUzHPje OYSw== 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 23.128.96.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id a7-20020a170902b58700b001bd9ae2a3dfsi8595770pls.237.2023.09.18.15.10.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 15:10:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; 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 23.128.96.34 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 416018091C62; Mon, 18 Sep 2023 13:57:25 -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 S230154AbjIRU5Z (ORCPT + 99 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 Content-Transfer-Encoding: 8bit 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:26 -0700 (PDT) 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) -- 2.41.0