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)