From nobody Mon Nov 23 04:26:31 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1793430420; cv=none; d=zohomail.com; s=zohoarc; b=QzGDUeqPDES+cPChr4nWWiGq09pjszPNNoc3QzQ1ZJjGhy5+QV8A677zYmBQZFWfFUuQ/gCiwFQKgGn9DDGTm9KYluhD0EAopInZ16T9P+F6HgTLRcJ58jrGD5BKP9nHNhmRUtmBhCOju80mlvQnzWam8EZ6niWob+1KzxxIlFM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793430420; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=HhBEslPlqsjAcYuTR9aZrMv5jQQbW5JpgDxoEn/I6Vk=; b=JndIbw67BzUyel/k4yK23T9KwjktInpNADpL8nagRnRcZDo60GOy7l+GN0nYKW0OqmIR4xP1bnBxQ40kVdjan7gG+3ybCKfFLhR1ZswdBvrrcLJuvzNyTB45j1o/mifJ+n6D72Gikj7cWT98cP1uraSfr5vBD3K5KuNmIrQL0GQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793430420303109.3637584898031; Sat, 31 Oct 2026 00:07:00 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xN38E-0001iB-0S; Sat, 31 Oct 2026 03:04:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xN36S-0000sT-S5 for qemu-devel@nongnu.org; Sat, 31 Oct 2026 03:02:15 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xN36Q-0003LU-92 for qemu-devel@nongnu.org; Sat, 31 Oct 2026 03:02:12 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-8-3o7h5qW3Nn6BOqQ_MN3MVQ-1; Sat, 31 Oct 2026 03:02:00 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id CA26A1800361; Sat, 31 Oct 2026 07:01:58 +0000 (UTC) Received: from circe.redhat.com (unknown [10.44.32.2]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 26B9C1800765; Sat, 31 Oct 2026 07:01:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1793430129; 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=HhBEslPlqsjAcYuTR9aZrMv5jQQbW5JpgDxoEn/I6Vk=; b=Y/evEnxAAqyvJGwJCR+MweCH9NyW4cdLEeHTzXsTG7hlgguhs7NeYcl5SqHwREY+I/F9uj CQK9SzZaRbN0bcXB5KkSKLgmoiNkiVozZyLAPVBx+HtJLK+Z9Ze4H/G/6FcowtxGmpckx1 McP+DJEvsnwuAb651lFVo/p7QCy3ft0= X-MC-Unique: 3o7h5qW3Nn6BOqQ_MN3MVQ-1 X-Mimecast-MFC-AGG-ID: 3o7h5qW3Nn6BOqQ_MN3MVQ_1793430118 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Naman Gulati , Thanos Makatos , John Levon , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 1/6] vfio-user: add multi-fd region mmap capability Date: Sat, 31 Oct 2026 08:01:47 +0100 Message-ID: <20261031070152.197043-2-clg@redhat.com> In-Reply-To: <20261031070152.197043-1-clg@redhat.com> References: <20261031070152.197043-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, WEIRD_QUOTING=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1793430424416154100 From: Naman Gulati Extend the vfio-user protocol specification to allow servers to pass multiple file descriptors for different sparse memory areas within a single device region with capability VFIO_REGION_INFO_CAP_SPARSE_MMAP_FDS (0x8001), negotiated via the "sparse_mmap_fds" capability in VFIO_USER_VERSION. VFIO_REGION_INFO_CAP_SPARSE_MMAP_FDS defines an array of sparse mmap areas where each area contains: - offset: Start of the area within the device region (BAR). - fd_offset: Start of the mapping within the backing file descriptor. - size: Size of the mappable area. - fd_index: Zero-based index into the array of file descriptors received in the SCM_RIGHTS ancillary data of the VFIO_USER_DEVICE_GET_REGION_INFO reply message. Reviewed-by: Thanos Makatos Reviewed-by: John Levon Signed-off-by: Naman Gulati Link: https://lore.kernel.org/qemu-devel/20261023223902.1275539-2-namangula= ti@google.com Signed-off-by: C=C3=A9dric Le Goater --- docs/interop/vfio-user.rst | 86 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 82 insertions(+), 4 deletions(-) diff --git a/docs/interop/vfio-user.rst b/docs/interop/vfio-user.rst index 1c92f442d232ce6ce880868bb7062e42481b69ae..b49781a7550a242a2dbb03fa5b7= 77aa87eac84ba 100644 --- a/docs/interop/vfio-user.rst +++ b/docs/interop/vfio-user.rst @@ -125,7 +125,13 @@ Sparse Regions A region can be memory-mappable in whole or in part. When only a subset of= a region can be mapped by the client, a ``VFIO_REGION_INFO_CAP_SPARSE_MMAP`` capability is included in the region info reply. This capability describes -which portions can be mapped by the client. +which portions can be mapped by the client. When sparse mmap areas are bac= ked +by multiple distinct file descriptors, a +``VFIO_REGION_INFO_CAP_SPARSE_MMAP_FDS`` capability is included in the reg= ion +info reply instead. ``VFIO_REGION_INFO_CAP_SPARSE_MMAP`` and +``VFIO_REGION_INFO_CAP_SPARSE_MMAP_FDS`` cannot both be specified for the = same +region; however, different regions of a device may independently use either +capability. =20 .. Note:: For example, in a virtual NVMe controller, sparse regions can be used so @@ -536,6 +542,10 @@ Capabilities: | write_multiple | boolean | ``VFIO_USER_REGION_WRITE_MULTI`` messages= | | | | are supported if the value is ``true``. = | +--------------------+---------+------------------------------------------= -----+ +| sparse_mmap_fds | boolean | ``VFIO_REGION_INFO_CAP_SPARSE_MMAP_FDS`` = | +| | | capability is supported if the value is = | +| | | ``true``. = | ++--------------------+---------+------------------------------------------= -----+ =20 The ``twin_socket`` capability object holds these name/value pairs: =20 @@ -859,9 +869,11 @@ Reply * ``VFIO_REGION_INFO_FLAG_READ`` allows client read access to the region. * ``VFIO_REGION_INFO_FLAG_WRITE`` allows client write access to the regi= on. * ``VFIO_REGION_INFO_FLAG_MMAP`` specifies the client can mmap() the reg= ion. - When this flag is set, the reply will include a file descriptor in its - meta-data. On ``AF_UNIX`` sockets, the file descriptors will be passed= as - ``SCM_RIGHTS`` type ancillary data. + When this flag is set, the reply will include one or more file descrip= tors + in its meta-data (up to the number of sparse mmap areas when + ``VFIO_REGION_INFO_CAP_SPARSE_MMAP_FDS`` is present, or a single file + descriptor otherwise). On ``AF_UNIX`` sockets, the file descriptors wi= ll be + passed as ``SCM_RIGHTS`` type ancillary data. * ``VFIO_REGION_INFO_FLAG_CAPS`` indicates additional capabilities found= in the reply. =20 @@ -950,6 +962,72 @@ The VFIO sparse mmap area is defined in ```` (``struct vfio_region_info_cap_sparse_mmap``). =20 =20 +VFIO sparse mmap fds cap header +""""""""""""""""""""""""""""""" + ++----------------------+--------------------------------------+ +| Name | Value | ++=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D+=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D+ +| id | VFIO_REGION_INFO_CAP_SPARSE_MMAP_FDS | ++----------------------+--------------------------------------+ +| version | 0x1 | ++----------------------+--------------------------------------+ +| next | | ++----------------------+--------------------------------------+ +| sparse mmap fds info | VFIO region info sparse mmap fds | ++----------------------+--------------------------------------+ + +This capability is defined when a region supports direct access by the cli= ent +via mmap() where different sparse mmap areas are backed by distinct file +descriptors in the ``SCM_RIGHTS`` ancillary data array. The server may only +include this capability if the client advertised ``sparse_mmap_fds`` as +``true`` in ``VFIO_USER_VERSION``. Capability ID +``VFIO_REGION_INFO_CAP_SPARSE_MMAP_FDS`` is defined as ``0x8001`` to avoid +clashing with kernel VFIO capabilities. + +VFIO region info cap sparse mmap fds +"""""""""""""""""""""""""""""""""""" + ++-----------+--------+------+ +| Name | Offset | Size | ++=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D+=3D=3D=3D=3D=3D=3D=3D=3D+=3D=3D=3D=3D= =3D=3D+ +| nr_areas | 0 | 4 | ++-----------+--------+------+ +| reserved | 4 | 4 | ++-----------+--------+------+ +| offset | 8 | 8 | ++-----------+--------+------+ +| fd_offset | 16 | 8 | ++-----------+--------+------+ +| size | 24 | 8 | ++-----------+--------+------+ +| fd_index | 32 | 4 | ++-----------+--------+------+ +| pad | 36 | 4 | ++-----------+--------+------+ +| ... | | | ++-----------+--------+------+ + +* *nr_areas* is the number of sparse mmap areas in the region. +* *offset*, *fd_offset*, *size*, and *fd_index* describe a single area tha= t can be + mapped by the client. There will be *nr_areas* tuples of offset, fd_offs= et, size, + fd_index, and pad. Sparse mmap areas must not overlap. +* *offset* specifies the start of the area within the device region (BAR). +* *fd_offset* specifies the start of the mapping within the backing file d= escriptor + referenced by *fd_index*. +* *size* specifies the size of the area. Zero-sized areas (*size* equal to= 0) + are not permitted, and *offset* + *size* must not exceed the region *siz= e*. +* *fd_index* is the zero-based index into the array of file descriptors + received in the ``SCM_RIGHTS`` ancillary data of the + ``VFIO_USER_DEVICE_GET_REGION_INFO`` reply message. The number of file + descriptors sent in ``SCM_RIGHTS`` must be at least 1 and must not exceed + *nr_areas*. + +If all sparse mmap areas are backed by a single file descriptor, the server +may instead send ``VFIO_REGION_INFO_CAP_SPARSE_MMAP`` and exactly one file +descriptor in ``SCM_RIGHTS`` for compatibility with older clients. + + ``VFIO_USER_DEVICE_GET_REGION_IO_FDS`` -------------------------------------- =20 --=20 2.56.0 From nobody Mon Nov 23 04:26:31 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1793430254; cv=none; d=zohomail.com; s=zohoarc; b=Q4Sjar1LHPRixtneiDVhF8Qix9w08FzmtxbXcYOr4OFrKEcVJQpXAlCHSBhxY9sRzpCnW6MrnGvIWRFnuChlbbssLQPX16WEHl34SYJMY9pjqHxIdQ2pD7KNsWRNlY3MhiPcjcuyTzrH0DKoJUukUUkpIjotHpWPw4nPrq4UD1Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793430254; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=XmeH2URBMvT4KV7ecm5Jkl5McJb9uzkwB0YMd+Tkx1g=; b=aBZNWMnBp78HJcD3Ohf/mylZ/I2MVA+1LirHt2PXDeMa9SekC7xEul9SkY1/rxcV2QT+X8zcxtvTLdjnHiHXaIo4GuIDgOQpaUIo5OWmUE96JZejXpoxzBQaxPUZYdteQjToNIB1gRUCPROoARAw/smCb4CV6BZxdn2G50+Hmyg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793430254573429.74676742673716; Sat, 31 Oct 2026 00:04:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xN36U-0000or-BQ; Sat, 31 Oct 2026 03:02:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xN36N-0000kC-Ov for qemu-devel@nongnu.org; Sat, 31 Oct 2026 03:02:07 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xN36L-0003LD-9F for qemu-devel@nongnu.org; Sat, 31 Oct 2026 03:02:06 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-58-6WUza2bJOayqk4wfP3LK5Q-1; Sat, 31 Oct 2026 03:02:02 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E8DDA1956079; Sat, 31 Oct 2026 07:02:00 +0000 (UTC) Received: from circe.redhat.com (unknown [10.44.32.2]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4441F1800495; Sat, 31 Oct 2026 07:01:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1793430124; 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=XmeH2URBMvT4KV7ecm5Jkl5McJb9uzkwB0YMd+Tkx1g=; b=TyhB6w1LH51ubplJztF/ckG9PcggkbIkfT5rBjSbAizhHbf0tg68gPzvwhyU5URdrPJBZg DOVfDInJa5D2FcXN2boFg1KD/QPDH0fo3szQbjXdDsmxr94KsRyMsJcpI+bXXiuQU0/04A vlYygspNck9kRSBVHyrnFCiR5ZoCzpc= X-MC-Unique: 6WUza2bJOayqk4wfP3LK5Q-1 X-Mimecast-MFC-AGG-ID: 6WUza2bJOayqk4wfP3LK5Q_1793430121 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Naman Gulati , Thanos Makatos , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , John Levon Subject: [PULL 2/6] vfio: add 'fd' and 'fd_offset' to VFIOMmap Date: Sat, 31 Oct 2026 08:01:48 +0100 Message-ID: <20261031070152.197043-3-clg@redhat.com> In-Reply-To: <20261031070152.197043-1-clg@redhat.com> References: <20261031070152.197043-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 5 X-Spam_score: 0.5 X-Spam_bar: / X-Spam_report: (0.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1793430257810154100 From: Naman Gulati Allow each sparse mmap subregion to specify its own file descriptor and file offset for the mmap call. Add 'fd' (set to -1 when the region fd should be used) and 'fd_offset' to VFIOMmap, and update vfio_region_mmap() to use them. Reviewed-by: Thanos Makatos Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: John Levon Signed-off-by: Naman Gulati Link: https://lore.kernel.org/qemu-devel/20261023223902.1275539-3-namangula= ti@google.com Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/vfio-region.h | 4 +++- hw/vfio/pci.c | 2 ++ hw/vfio/region.c | 26 +++++++++++++++++++------- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/hw/vfio/vfio-region.h b/hw/vfio/vfio-region.h index 58b236f1133e7e7f6c99b440d9125e96e6529085..9f6a5cf7d57e7747b3cbfa2c313= 2357cc3f8de95 100644 --- a/hw/vfio/vfio-region.h +++ b/hw/vfio/vfio-region.h @@ -14,8 +14,10 @@ typedef struct VFIOMmap { MemoryRegion mem; void *mmap; - off_t offset; + off_t offset; /* offset within the region */ size_t size; + int fd; /* per-mmap fd, or -1 to use the region fd */ + uint64_t fd_offset; /* offset within fd for the mmap call */ } VFIOMmap; =20 typedef struct VFIODevice VFIODevice; diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index ad13f2306f12bc960231a01ea1458ed34753ac1e..0da2e143b88a37b4be2dca17622= d87b7486cf924 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -1626,6 +1626,7 @@ static void vfio_pci_fixup_msix_region(VFIOPCIDevice = *vdev) vdev->msix->table_bar, 0, 0); } else { region->mmaps[0].offset =3D end; + region->mmaps[0].fd_offset +=3D end; region->mmaps[0].size =3D region->size - end; trace_vfio_msix_fixup(vdev->vbasedev.name, vdev->msix->table_bar, region->mmaps[0].offs= et, @@ -1652,6 +1653,7 @@ static void vfio_pci_fixup_msix_region(VFIOPCIDevice = *vdev) region->mmaps[0].offset + region->mmaps[0].s= ize); =20 region->mmaps[1].offset =3D end; + region->mmaps[1].fd_offset +=3D end; region->mmaps[1].size =3D region->size - end; trace_vfio_msix_fixup(vdev->vbasedev.name, vdev->msix->table_bar, region->mmaps[1].offs= et, diff --git a/hw/vfio/region.c b/hw/vfio/region.c index 54ad11a6c8ed8e04fa365262ccb8bd694bdb45f7..16efed2fce6141185e86bb636b3= 393209ace071a 100644 --- a/hw/vfio/region.c +++ b/hw/vfio/region.c @@ -189,6 +189,9 @@ static int vfio_setup_region_sparse_mmaps(VFIORegion *r= egion, sparse->areas[i].size - 1); region->mmaps[j].offset =3D sparse->areas[i].offset; region->mmaps[j].size =3D sparse->areas[i].size; + region->mmaps[j].fd =3D -1; + region->mmaps[j].fd_offset =3D region->fd_offset + + sparse->areas[i].offset; j++; } } @@ -262,6 +265,8 @@ int vfio_region_setup(Object *obj, VFIODevice *vbasedev= , VFIORegion *region, region->mmaps =3D g_new0(VFIOMmap, region->nr_mmaps); region->mmaps[0].offset =3D 0; region->mmaps[0].size =3D region->size; + region->mmaps[0].fd =3D -1; + region->mmaps[0].fd_offset =3D region->fd_offset; } else if (ret) { return ret; } @@ -354,7 +359,6 @@ int vfio_region_mmap(VFIORegion *region) off_t map_offset =3D 0; size_t align; char *name; - int fd; =20 if (!region->mem || !region->nr_mmaps) { return 0; @@ -391,8 +395,6 @@ int vfio_region_mmap(VFIORegion *region) return ret; } =20 - fd =3D vfio_device_get_region_fd(region->vbasedev, region->nr); - map_align =3D (void *)ROUND_UP((uintptr_t)map_base, (uintptr_t)align); munmap(map_base, map_align - map_base); munmap(map_align + region->size, @@ -404,12 +406,22 @@ int vfio_region_mmap(VFIORegion *region) * offsets being in ascending order. */ for (i =3D 0; i < region->nr_mmaps; i++) { + int fd =3D region->mmaps[i].fd; + + if (fd < 0) { + fd =3D vfio_device_get_region_fd(region->vbasedev, region->nr); + } + if (fd < 0) { + ret =3D -EINVAL; + munmap(map_align + map_offset, region->size - map_offset); + goto no_mmap; + } + munmap(map_align + map_offset, region->mmaps[i].offset - map_offse= t); region->mmaps[i].mmap =3D mmap(map_align + region->mmaps[i].offset, region->mmaps[i].size, prot, MAP_SHARED | MAP_FIXED, fd, - region->fd_offset + - region->mmaps[i].offset); + region->mmaps[i].fd_offset); if (region->mmaps[i].mmap =3D=3D MAP_FAILED) { ret =3D -errno; /* @@ -454,8 +466,8 @@ int vfio_region_mmap(VFIORegion *region) =20 no_mmap: trace_vfio_region_mmap_fault(memory_region_name(region->mem), i, - region->fd_offset + region->mmaps[i].offs= et, - region->fd_offset + region->mmaps[i].offs= et + + region->mmaps[i].fd_offset, + region->mmaps[i].fd_offset + region->mmaps[i].size - 1, ret); =20 region->mmaps[i].mmap =3D NULL; --=20 2.56.0 From nobody Mon Nov 23 04:26:31 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1793430242; cv=none; d=zohomail.com; s=zohoarc; b=ixm3b3+OxktcjcJg9lwUt7NrHrW/hBHh+pJ9IF6YQr15Jevz5jhE5ee54+PYhaiAcQHFgMfVd+GPYICS+JdF7JLepihFFmVEBMBvxc0qzNOFBNGEdm1dcxQlivfn4+Q+j7YOEjokBPwnruQBEPudLCnY/dGwpwKj3zs7SvfCq3I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793430242; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=zsz+F9N/wLIAOwnVBNqK4k0oivFXLvrTgUdLZvv8jrM=; b=nRQAUp6B56MIAminxpVoNyzM47/C3fxIaeAZ8gLEBY3tp+oeKe7LFjQZ6sSv8ogRHWafk7fR8bvl6DbqdckAaiiYX7Buug7svuJlvSKnWvvK1VM1mFktPKDcBsJeykCgMHfEj1ie5Wnl1M5mhcvmOlUet7yMvtTQFaeRfmsR3ec= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 179343024222288.9058385721022; Sat, 31 Oct 2026 00:04:02 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xN36x-0000x7-QY; Sat, 31 Oct 2026 03:02:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xN36R-0000s0-1X for qemu-devel@nongnu.org; Sat, 31 Oct 2026 03:02:12 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xN36O-0003LN-WA for qemu-devel@nongnu.org; Sat, 31 Oct 2026 03:02:10 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-370-9kbX3xacPlmi8Xdz2amlhQ-1; Sat, 31 Oct 2026 03:02:04 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 09CC119560B7; Sat, 31 Oct 2026 07:02:03 +0000 (UTC) Received: from circe.redhat.com (unknown [10.44.32.2]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 61E941803A40; Sat, 31 Oct 2026 07:02:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1793430128; 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=zsz+F9N/wLIAOwnVBNqK4k0oivFXLvrTgUdLZvv8jrM=; b=i6CUYq8HB/epqitTfq8YqoYTI3lv1z1XCOE6CvHBGlWxpQLdRiaF69YR8Q70esUGoidIlA VOQjMg6zQvr/GNkkWYFhehkCVEt1CkVwThnB0fEKkvICvHLI76JnbEn8MupIAaA6RM5zET Bq7qfcPMBe5rF0pfoPjbsk4nl2CSLgU= X-MC-Unique: 9kbX3xacPlmi8Xdz2amlhQ-1 X-Mimecast-MFC-AGG-ID: 9kbX3xacPlmi8Xdz2amlhQ_1793430123 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Naman Gulati , Thanos Makatos , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , John Levon Subject: [PULL 3/6] vfio: add setup_sparse_mmaps hook to VFIODeviceIOOps Date: Sat, 31 Oct 2026 08:01:49 +0100 Message-ID: <20261031070152.197043-4-clg@redhat.com> In-Reply-To: <20261031070152.197043-1-clg@redhat.com> References: <20261031070152.197043-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 5 X-Spam_score: 0.5 X-Spam_bar: / X-Spam_report: (0.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1793430243626158500 From: Naman Gulati Add a setup_sparse_mmaps callback to VFIODeviceIOOps so transport backends (such as vfio-user) can parse custom sparse mmap capabilities, falling back to vfio_region_setup_sparse_mmaps() to process shared VFIO mmap capabilities. Reviewed-by: Thanos Makatos Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: John Levon Signed-off-by: Naman Gulati Link: https://lore.kernel.org/qemu-devel/20261023223902.1275539-4-namangula= ti@google.com Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/vfio-region.h | 5 +++++ include/hw/vfio/vfio-device.h | 16 ++++++++++++++++ hw/vfio/device.c | 1 + hw/vfio/region.c | 19 ++++++++++++++++--- 4 files changed, 38 insertions(+), 3 deletions(-) diff --git a/hw/vfio/vfio-region.h b/hw/vfio/vfio-region.h index 9f6a5cf7d57e7747b3cbfa2c3132357cc3f8de95..abcfbacfff1b5d9d5337f9a8c8d= e303a5e2d141c 100644 --- a/hw/vfio/vfio-region.h +++ b/hw/vfio/vfio-region.h @@ -46,4 +46,9 @@ void vfio_region_mmaps_set_enabled(VFIORegion *region, bo= ol enabled); void vfio_region_exit(VFIORegion *region); void vfio_region_finalize(VFIORegion *region); =20 +struct vfio_region_info; +int vfio_region_setup_sparse_mmaps(VFIORegion *region, + struct vfio_region_info *info, + Error **errp); + #endif /* HW_VFIO_REGION_H */ diff --git a/include/hw/vfio/vfio-device.h b/include/hw/vfio/vfio-device.h index 8472420d3fac6c56e522a8dd253b6ab6b5ce58ea..3136e152f2ce5e0e736812ff655= 8c4f5060baa26 100644 --- a/include/hw/vfio/vfio-device.h +++ b/include/hw/vfio/vfio-device.h @@ -43,6 +43,7 @@ enum { =20 typedef struct VFIODeviceOps VFIODeviceOps; typedef struct VFIODeviceIOOps VFIODeviceIOOps; +typedef struct VFIORegion VFIORegion; typedef struct VFIOMigration VFIOMigration; =20 typedef struct IOMMUFDBackend IOMMUFDBackend; @@ -218,6 +219,21 @@ struct VFIODeviceIOOps { int (*get_region_info)(VFIODevice *vdev, struct vfio_region_info *info, int *fd); =20 + /** + * @setup_sparse_mmaps + * + * Parse sparse mmap capabilities for a region and initialize region->= mmaps. + * + * @region: #VFIORegion to set up + * @info: region info struct containing capabilities + * @errp: pointer to Error*, to store an error if it happens + * + * Returns 0 on success, -ENODEV if not sparse, or negative error code. + */ + int (*setup_sparse_mmaps)(VFIORegion *region, + struct vfio_region_info *info, + Error **errp); + /** * @get_irq_info * diff --git a/hw/vfio/device.c b/hw/vfio/device.c index 4f119596336fdfd3c54741e23f200ad55ad800e7..339c7242ed614b2bb11818f6286= 8f130853b320b 100644 --- a/hw/vfio/device.c +++ b/hw/vfio/device.c @@ -662,6 +662,7 @@ static VFIODeviceIOOps vfio_device_io_ops_ioctl =3D { =20 .device_feature =3D vfio_device_io_device_feature, .get_region_info =3D vfio_device_io_get_region_info, + .setup_sparse_mmaps =3D vfio_region_setup_sparse_mmaps, .get_irq_info =3D vfio_device_io_get_irq_info, .set_irqs =3D vfio_device_io_set_irqs, .region_read =3D vfio_device_io_region_read, diff --git a/hw/vfio/region.c b/hw/vfio/region.c index 16efed2fce6141185e86bb636b3393209ace071a..8de26f3d9b592a4b34578310c76= 975af8185ddca 100644 --- a/hw/vfio/region.c +++ b/hw/vfio/region.c @@ -162,9 +162,9 @@ static int vfio_mmap_compare_offset(const void *a, cons= t void *b) return 0; } =20 -static int vfio_setup_region_sparse_mmaps(VFIORegion *region, - struct vfio_region_info *info, - Error **errp) +int vfio_region_setup_sparse_mmaps(VFIORegion *region, + struct vfio_region_info *info, + Error **errp) { struct vfio_info_cap_header *hdr; struct vfio_region_info_cap_sparse_mmap *sparse; @@ -198,6 +198,19 @@ static int vfio_setup_region_sparse_mmaps(VFIORegion *= region, =20 region->nr_mmaps =3D j; region->mmaps =3D g_realloc(region->mmaps, j * sizeof(VFIOMmap)); + return 0; +} + +static int vfio_setup_region_sparse_mmaps(VFIORegion *region, + struct vfio_region_info *info, + Error **errp) +{ + int ret, i; + + ret =3D region->vbasedev->io_ops->setup_sparse_mmaps(region, info, err= p); + if (ret) { + return ret; + } =20 /* * Sort sparse mmaps by offset to ensure proper handling of gaps --=20 2.56.0 From nobody Mon Nov 23 04:26:31 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1793430308; cv=none; d=zohomail.com; s=zohoarc; b=XoPCgROUiYv4v12m1xgTywXfYfsUrtrdOBZ/HzXF/x+izP1kn8wAGA+Ta9yjir171f13sFvqN2WrfdKrd2Q97EJDNbLKu+EvQuP0bTWp1TGlHCtz9tJBY14/dTANDvPta2KjXYSZLvfs2fJnZPNL3jfFv9bhqrQ2+EZQ1cqZ6jw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793430308; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=dYBcQhX1FrvaNx4wOngjI9aAkSseUUHD+/VDcg5nUAs=; b=ewAbzEKsF0zHrnOaC2PCyu8yMUcjnqRewp4RNaqSRVQOoTsHfXD+jh2lUXnK0IDDQfHmUQLWF4S2IkscKygZ+hbG+0LDnr1oIbIxVAQ+/oqE+X1qWYWjOXivvZBSvvcveBGY7u3qFFS/Sh8yZr4d8YoKqwNX1tx49eDnVSUiTCU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793430308591722.0860072951998; Sat, 31 Oct 2026 00:05:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xN388-0001Ny-OE; Sat, 31 Oct 2026 03:03:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xN36T-0000sh-9O for qemu-devel@nongnu.org; Sat, 31 Oct 2026 03:02:17 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xN36Q-0003LW-DX for qemu-devel@nongnu.org; Sat, 31 Oct 2026 03:02:13 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-127-VjZQNX0ePjSD8upNi6s2LA-1; Sat, 31 Oct 2026 03:02:05 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id DD0F71956071; Sat, 31 Oct 2026 07:02:04 +0000 (UTC) Received: from circe.redhat.com (unknown [10.44.32.2]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7637B1803A40; Sat, 31 Oct 2026 07:02:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1793430129; 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=dYBcQhX1FrvaNx4wOngjI9aAkSseUUHD+/VDcg5nUAs=; b=hTIk7sX8djqGfTH7a2d0JWokmkb8nCGubozvFUa2H1b85VR1iwN3qbHtchc0mkSEms8qZ2 jKCfCzeHKq2oYE2WKOrKSQCQH7sPkzXgJwbkJKPuDyedczcm8vajrMa5qF3x+/+3aYiPJ3 axTg2qi8WAt4m2SwFJ7DLkqg7N0QHpM= X-MC-Unique: VjZQNX0ePjSD8upNi6s2LA-1 X-Mimecast-MFC-AGG-ID: VjZQNX0ePjSD8upNi6s2LA_1793430125 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Naman Gulati , Thanos Makatos , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 4/6] vfio-user: support multiple FDs for sparse mmap regions Date: Sat, 31 Oct 2026 08:01:50 +0100 Message-ID: <20261031070152.197043-5-clg@redhat.com> In-Reply-To: <20261031070152.197043-1-clg@redhat.com> References: <20261031070152.197043-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 5 X-Spam_score: 0.5 X-Spam_bar: / X-Spam_report: (0.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1793430311123158500 From: Naman Gulati Add client support for capability VFIO_REGION_INFO_CAP_SPARSE_MMAP_FDS (capability ID 0x8001) in vfio-user, and advertise support via the "sparse_mmap_fds" capability in VFIO_USER_VERSION. Update vfio_user_device_io_get_region_info() to receive multiple file descriptors passed in SCM_RIGHTS ancillary data for a region, store them in VFIOUserProxy, and implement setup_sparse_mmaps in vfio_user_device_io_ops_sock to validate and populate per-area file descriptors and fd_offset values. Reviewed-by: Thanos Makatos Signed-off-by: Naman Gulati Link: https://lore.kernel.org/qemu-devel/20261023223902.1275539-5-namangula= ti@google.com Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio-user/protocol.h | 39 +++++++++++-- hw/vfio-user/proxy.h | 2 + hw/vfio-user/device.c | 126 +++++++++++++++++++++++++++++++++++++--- hw/vfio-user/proxy.c | 52 +++++++++++++++-- 4 files changed, 202 insertions(+), 17 deletions(-) diff --git a/hw/vfio-user/protocol.h b/hw/vfio-user/protocol.h index c478d1353f9d618ef8c202cd28cd638aeed3bd57..b5d258c92bb8ab6489e64d9015c= 565ec94796a9d 100644 --- a/hw/vfio-user/protocol.h +++ b/hw/vfio-user/protocol.h @@ -15,6 +15,8 @@ * SPDX-License-Identifier: GPL-2.0-or-later */ =20 +#define VFIO_USER_MAX_REGIONS 100 + typedef struct { uint16_t id; uint16_t command; @@ -69,12 +71,13 @@ typedef struct { #define VFIO_USER_CAP "capabilities" =20 /* "capabilities" members */ -#define VFIO_USER_CAP_MAX_FDS "max_msg_fds" -#define VFIO_USER_CAP_MAX_XFER "max_data_xfer_size" -#define VFIO_USER_CAP_PGSIZES "pgsizes" -#define VFIO_USER_CAP_MAP_MAX "max_dma_maps" -#define VFIO_USER_CAP_MIGR "migration" -#define VFIO_USER_CAP_MULTI "write_multiple" +#define VFIO_USER_CAP_MAX_FDS "max_msg_fds" +#define VFIO_USER_CAP_MAX_XFER "max_data_xfer_size" +#define VFIO_USER_CAP_PGSIZES "pgsizes" +#define VFIO_USER_CAP_MAP_MAX "max_dma_maps" +#define VFIO_USER_CAP_MIGR "migration" +#define VFIO_USER_CAP_MULTI "write_multiple" +#define VFIO_USER_CAP_SPARSE_MMAP_FDS "sparse_mmap_fds" =20 /* "migration" members */ #define VFIO_USER_CAP_PGSIZE "pgsize" @@ -166,6 +169,30 @@ typedef struct { uint64_t offset; } VFIOUserRegionInfo; =20 +/* + * VFIO_REGION_INFO_CAP_SPARSE_MMAP_FDS + * + * Capability IDs with the most significant bit set (id >=3D 0x8000) are + * reserved for userspace VFIO extensions (such as vfio-user) to avoid + * colliding with kernel VFIO capabilities. + */ +#define VFIO_REGION_INFO_CAP_SPARSE_MMAP_FDS 0x8001 + +struct vfio_region_sparse_mmap_fd_area { + uint64_t offset; + uint64_t fd_offset; + uint64_t size; + uint32_t fd_index; + uint32_t pad; +}; + +struct vfio_region_info_cap_sparse_mmap_fds { + struct vfio_info_cap_header header; + uint32_t nr_areas; + uint32_t reserved; + struct vfio_region_sparse_mmap_fd_area areas[]; +}; + /* * VFIO_USER_DEVICE_GET_IRQ_INFO * imported from struct vfio_irq_info diff --git a/hw/vfio-user/proxy.h b/hw/vfio-user/proxy.h index 7b97460cc504a408e8e4299fa84fd56a2d674aa0..4b9834a4367541bc44db90e00ad= 40e8624483f55 100644 --- a/hw/vfio-user/proxy.h +++ b/hw/vfio-user/proxy.h @@ -72,6 +72,7 @@ typedef struct VFIOUserProxy { AioContext *ctx; QEMUBH *req_bh; bool async_ops; + VFIOUserFDs *region_fds[VFIO_USER_MAX_REGIONS]; =20 /* * above only changed when BQL is held @@ -111,6 +112,7 @@ bool vfio_user_validate_version(VFIOUserProxy *proxy, E= rror **errp); =20 VFIOUserFDs *vfio_user_getfds(int numfds); void vfio_user_putfds(VFIOUserMsg *msg); +void vfio_user_free_fds(VFIOUserFDs *fds); =20 void vfio_user_disable_posted_writes(VFIOUserProxy *proxy); =20 diff --git a/hw/vfio-user/device.c b/hw/vfio-user/device.c index 1a01e748cd43311cea65c749288fc2003064db09..237e33b57bf91ffd506e1044b05= 50204379fcc53 100644 --- a/hw/vfio-user/device.c +++ b/hw/vfio-user/device.c @@ -14,12 +14,14 @@ =20 #include "hw/vfio-user/device.h" #include "hw/vfio-user/trace.h" +#include "hw/vfio/vfio-region.h" +#include "hw/vfio/vfio-helpers.h" +#include "hw/vfio/trace.h" =20 /* * These are to defend against a malign server trying * to force us to run out of memory. */ -#define VFIO_USER_MAX_REGIONS 100 #define VFIO_USER_MAX_IRQS 50 =20 bool vfio_user_get_device_info(VFIOUserProxy *proxy, @@ -179,6 +181,11 @@ static int vfio_user_get_region_info(VFIOUserProxy *pr= oxy, return -EINVAL; } =20 + if (msgp->index !=3D info->index) { + error_printf("vfio_user_get_region_info reply index mismatch\n"); + return -EINVAL; + } + /* * The server can respond with a larger argsz in the reply to request a * larger buffer on the next iteration via vfio_device_get_region_info= (). @@ -209,14 +216,17 @@ static int vfio_user_device_io_get_region_info(VFIODe= vice *vbasedev, struct vfio_region_info *in= fo, int *fd) { - VFIOUserFDs fds =3D { 0, 1, fd}; - int ret; + int fds[VFIO_USER_MAX_MAX_FDS]; + VFIOUserFDs user_fds =3D { 0, VFIO_USER_MAX_MAX_FDS, fds }; + int i, ret; + + *fd =3D -1; =20 if (info->index > vbasedev->num_initial_regions) { return -EINVAL; } =20 - ret =3D vfio_user_get_region_info(vbasedev->proxy, info, &fds); + ret =3D vfio_user_get_region_info(vbasedev->proxy, info, &user_fds); if (ret) { return ret; } @@ -225,10 +235,30 @@ static int vfio_user_device_io_get_region_info(VFIODe= vice *vbasedev, if ((info->flags & VFIO_REGION_INFO_FLAG_CAPS) && (info->cap_offset < sizeof(*info) || info->cap_offset + sizeof(struct vfio_info_cap_header) > info-= >argsz)) { - return -EINVAL; + ret =3D -EINVAL; + } else if (vfio_get_region_info_cap(info, + VFIO_REGION_INFO_CAP_SPARSE_MMAP_F= DS)) { + if (user_fds.recv_fds > 0) { + VFIOUserFDs *saved =3D vfio_user_getfds(user_fds.recv_fds); + + saved->recv_fds =3D user_fds.recv_fds; + memcpy(saved->fds, fds, user_fds.recv_fds * sizeof(int)); + vfio_user_free_fds(vbasedev->proxy->region_fds[info->index]); + vbasedev->proxy->region_fds[info->index] =3D saved; + return 0; + } + ret =3D -EINVAL; + } else if (user_fds.recv_fds > 0) { + *fd =3D fds[0]; + fds[0] =3D -1; } =20 - return 0; + for (i =3D 0; i < user_fds.recv_fds; i++) { + if (fds[i] >=3D 0) { + close(fds[i]); + } + } + return ret; } =20 static int vfio_user_device_io_get_irq_info(VFIODevice *vbasedev, @@ -518,12 +548,94 @@ static int vfio_user_device_io_region_write(VFIODevic= e *vbasedev, uint8_t index, /* * Socket-based io_ops */ +static int vfio_user_device_io_setup_sparse_mmaps(VFIORegion *region, + struct vfio_region_info = *info, + Error **errp) +{ + struct vfio_info_cap_header *hdr; + struct vfio_region_info_cap_sparse_mmap_fds *sparse_fds; + VFIOUserFDs *user_fds; + size_t cap_offset; + int i; + + hdr =3D vfio_get_region_info_cap(info, VFIO_REGION_INFO_CAP_SPARSE_MMA= P_FDS); + if (!hdr) { + return vfio_region_setup_sparse_mmaps(region, info, errp); + } + + if (vfio_get_region_info_cap(info, VFIO_REGION_INFO_CAP_SPARSE_MMAP)) { + error_setg(errp, "%s: region %d cannot specify both " + "SPARSE_MMAP and SPARSE_MMAP_FDS", __func__, region->nr= ); + return -EINVAL; + } + + sparse_fds =3D container_of(hdr, struct vfio_region_info_cap_sparse_mm= ap_fds, + header); + + cap_offset =3D (uintptr_t)hdr - (uintptr_t)info; + if (cap_offset > info->argsz || + info->argsz - cap_offset < sizeof(*sparse_fds) || + sparse_fds->nr_areas > + (info->argsz - cap_offset - sizeof(*sparse_fds)) / + sizeof(sparse_fds->areas[0])) { + error_setg(errp, "%s: invalid nr_areas %u in region %d", + __func__, sparse_fds->nr_areas, region->nr); + return -EINVAL; + } + + trace_vfio_region_sparse_mmap_header(region->vbasedev->name, + region->nr, sparse_fds->nr_areas); + + user_fds =3D region->vbasedev->proxy->region_fds[region->nr]; + if (!user_fds || user_fds->recv_fds > sparse_fds->nr_areas) { + error_setg(errp, "%s: invalid fd count %d for %u sparse mmap areas= " + "in region %d", __func__, + user_fds ? user_fds->recv_fds : 0, + sparse_fds->nr_areas, region->nr); + return -EINVAL; + } + + region->mmaps =3D g_try_new0(VFIOMmap, sparse_fds->nr_areas); + if (!region->mmaps) { + error_setg(errp, "%s: failed to allocate %u mmaps for region %d", + __func__, sparse_fds->nr_areas, region->nr); + return -ENOMEM; + } + + for (i =3D 0; i < sparse_fds->nr_areas; i++) { + struct vfio_region_sparse_mmap_fd_area *area =3D &sparse_fds->area= s[i]; + + if (area->size =3D=3D 0 || area->offset > region->size || + area->size > region->size - area->offset || + area->fd_index >=3D user_fds->recv_fds) { + error_setg(errp, "%s: invalid sparse mmap area %d in region %d= " + "(offset=3D0x%"PRIx64" size=3D0x%"PRIx64 + " fd_offset=3D0x%"PRIx64" fd_index=3D%u)", + __func__, i, region->nr, area->offset, area->size, + area->fd_offset, area->fd_index); + g_free(region->mmaps); + region->mmaps =3D NULL; + return -EINVAL; + } + + trace_vfio_region_sparse_mmap_entry(i, area->offset, + area->offset + area->size - 1); + region->mmaps[i].offset =3D area->offset; + region->mmaps[i].fd_offset =3D area->fd_offset; + region->mmaps[i].size =3D area->size; + region->mmaps[i].fd =3D user_fds->fds[area->fd_index]; + } + + region->nr_mmaps =3D sparse_fds->nr_areas; + return 0; +} + VFIODeviceIOOps vfio_user_device_io_ops_sock =3D { .device_feature =3D vfio_user_device_io_device_feature, .get_region_info =3D vfio_user_device_io_get_region_info, + .setup_sparse_mmaps =3D vfio_user_device_io_setup_sparse_mmaps, .get_irq_info =3D vfio_user_device_io_get_irq_info, .set_irqs =3D vfio_user_device_io_set_irqs, .region_read =3D vfio_user_device_io_region_read, .region_write =3D vfio_user_device_io_region_write, - }; diff --git a/hw/vfio-user/proxy.c b/hw/vfio-user/proxy.c index 197aee07bf7a3e16b58f77b0ecb73bff46889ecb..ba290853219887dc0f3199280d1= b88c81d4647ce 100644 --- a/hw/vfio-user/proxy.c +++ b/hw/vfio-user/proxy.c @@ -363,6 +363,13 @@ static int vfio_user_recv_one(VFIOUserProxy *proxy, Er= ror **errp) } =20 memcpy(msg->fds->fds, fdp, numfds * sizeof(int)); + } else if (msg->fds !=3D NULL) { + /* + * recv_fds holds the capacity of msg->fds->fds on entry; reset it + * to 0 when the reply carries no FDs so the caller knows none were + * received. + */ + msg->fds->recv_fds =3D 0; } =20 /* @@ -740,6 +747,11 @@ bool vfio_user_send_wait(VFIOUserProxy *proxy, VFIOUse= rHdr *hdr, =20 qemu_mutex_unlock(&proxy->lock); =20 + if (!ok && fds !=3D NULL) { + /* No reply was received; report 0 received FDs to the caller. */ + fds->recv_fds =3D 0; + } + return ok; } =20 @@ -867,17 +879,30 @@ void vfio_user_send_error(VFIOUserProxy *proxy, VFIOU= serHdr *hdr, int error) } =20 /* - * Close FDs erroneously received in an incoming request. + * Close and free received FDs. */ -void vfio_user_putfds(VFIOUserMsg *msg) +void vfio_user_free_fds(VFIOUserFDs *fds) { - VFIOUserFDs *fds =3D msg->fds; int i; =20 + if (!fds) { + return; + } + for (i =3D 0; i < fds->recv_fds; i++) { - close(fds->fds[i]); + if (fds->fds[i] >=3D 0) { + close(fds->fds[i]); + } } g_free(fds); +} + +/* + * Close FDs erroneously received in an incoming request. + */ +void vfio_user_putfds(VFIOUserMsg *msg) +{ + vfio_user_free_fds(msg->fds); msg->fds =3D NULL; } =20 @@ -967,6 +992,7 @@ void vfio_user_set_handler(VFIODevice *vbasedev, void vfio_user_disconnect(VFIOUserProxy *proxy) { VFIOUserMsg *r1, *r2; + int i; =20 qemu_mutex_lock(&proxy->lock); =20 @@ -1027,6 +1053,10 @@ void vfio_user_disconnect(VFIOUserProxy *proxy) vfio_user_iothread =3D NULL; } =20 + for (i =3D 0; i < VFIO_USER_MAX_REGIONS; i++) { + vfio_user_free_fds(proxy->region_fds[i]); + } + g_free(proxy->sockname); g_free(proxy); } @@ -1214,6 +1244,18 @@ static bool check_multi(VFIOUserProxy *proxy, QObjec= t *qobj, Error **errp) return true; } =20 +static bool check_sparse_mmap_fds(VFIOUserProxy *proxy, QObject *qobj, + Error **errp) +{ + QBool *qb =3D qobject_to(QBool, qobj); + + if (qb =3D=3D NULL) { + error_setg(errp, "malformed %s", VFIO_USER_CAP_SPARSE_MMAP_FDS); + return false; + } + return true; +} + static struct cap_entry caps_cap[] =3D { { VFIO_USER_CAP_MAX_FDS, check_max_fds }, { VFIO_USER_CAP_MAX_XFER, check_max_xfer }, @@ -1221,6 +1263,7 @@ static struct cap_entry caps_cap[] =3D { { VFIO_USER_CAP_MAP_MAX, check_max_dma }, { VFIO_USER_CAP_MIGR, check_migr }, { VFIO_USER_CAP_MULTI, check_multi }, + { VFIO_USER_CAP_SPARSE_MMAP_FDS, check_sparse_mmap_fds }, { NULL } }; =20 @@ -1280,6 +1323,7 @@ static GString *caps_json(void) qdict_put_int(capdict, VFIO_USER_CAP_PGSIZES, VFIO_USER_DEF_PGSIZE); qdict_put_int(capdict, VFIO_USER_CAP_MAP_MAX, VFIO_USER_DEF_MAP_MAX); qdict_put_bool(capdict, VFIO_USER_CAP_MULTI, true); + qdict_put_bool(capdict, VFIO_USER_CAP_SPARSE_MMAP_FDS, true); =20 qdict_put_obj(dict, VFIO_USER_CAP, QOBJECT(capdict)); =20 --=20 2.56.0 From nobody Mon Nov 23 04:26:31 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1793430392; cv=none; d=zohomail.com; s=zohoarc; b=fxdwtlh9ZBP+AC1M4MgYjAemBLmWRZDIfw1sAPP9bRbeJrcGqKXj28phO9twSEpu4CExYRJF/UJ2zFK8y1sktzO1xGgVI4FpBmiEuJ+Q5zUwMtW6ke5NNVolWyJkORz3zPCJFugVQnXGXXG55rTrWJlT8p/YhVsKtL+OUPOvTIU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793430392; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=VsduHnZRqcJv//VkRPyuJVa7feRe67jV+XGB1rWZBdk=; b=IPxg5m9Y8uPGHczBrLBERjaTadBOZaluHed2TdwjkTcK3cx9jBZN0fVHd5SuqfCjTxs2Xej22TaJ3kk7+FiZCsKOXduDKyhv+nrzfj3u9Tp84djn0NxLSuO5DEL29YMm6JcUIW2dsFxkg2fpeIqy259QBP0YdUIxOFahEfO013Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793430392182280.6857677151886; Sat, 31 Oct 2026 00:06:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xN383-0001Hh-Kl; Sat, 31 Oct 2026 03:03:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xN36S-0000sG-10 for qemu-devel@nongnu.org; Sat, 31 Oct 2026 03:02:12 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xN36Q-0003LR-35 for qemu-devel@nongnu.org; Sat, 31 Oct 2026 03:02:11 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-101-iAbjh1--Of-Y1W-ShcWBcQ-1; Sat, 31 Oct 2026 03:02:07 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8675F1955F30; Sat, 31 Oct 2026 07:02:06 +0000 (UTC) Received: from circe.redhat.com (unknown [10.44.32.2]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 555611800495; Sat, 31 Oct 2026 07:02:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1793430129; 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=VsduHnZRqcJv//VkRPyuJVa7feRe67jV+XGB1rWZBdk=; b=Uvb4Ab8VG0b8FUrPvkPDO/sqcdC0X2iOTT4opsE1nzqrLNI9kvGpAcP02sjU/Y+SYNp9Rs RniISvZs57AuH+Hlv/x3aaSsUFNgg5TTVi0IUNnKCmAXWm5yKArL7RfUiAqCODoV5HEHDU OeElM2hOlto5lC4TgpYhdX6CQpBA9Js= X-MC-Unique: iAbjh1--Of-Y1W-ShcWBcQ-1 X-Mimecast-MFC-AGG-ID: iAbjh1--Of-Y1W-ShcWBcQ_1793430126 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PULL 5/6] vfio/pci: Reorganize pci.h declarations into sections Date: Sat, 31 Oct 2026 08:01:51 +0100 Message-ID: <20261031070152.197043-6-clg@redhat.com> In-Reply-To: <20261031070152.197043-1-clg@redhat.com> References: <20261031070152.197043-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 5 X-Spam_score: 0.5 X-Spam_bar: / X-Spam_report: (0.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1793430394800158500 Group function declarations in pci.h by topic for better readability. No functional change. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Link: https://lore.kernel.org/qemu-devel/20261028105543.1287795-1-clg@redha= t.com Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/pci.h | 62 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 25 deletions(-) diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h index c9ab9498708ec0343e206c7f343085b0be8a7a1e..7ff52e9a526561301dd4fd0c2fa= 3c9f7ac09f74b 100644 --- a/hw/vfio/pci.h +++ b/hw/vfio/pci.h @@ -221,28 +221,33 @@ bool vfio_pci_intx_enable(VFIOPCIDevice *vdev, Error = **errp); void vfio_pci_intx_set_handler(VFIOPCIDevice *vdev, bool enable); void vfio_pci_msix_set_notifiers(VFIOPCIDevice *vdev); void vfio_pci_msi_set_handler(VFIOPCIDevice *vdev, int nr, bool enable); +bool vfio_pci_interrupt_setup(VFIOPCIDevice *vdev, Error **errp); +void vfio_pci_intx_eoi(VFIODevice *vbasedev); +void vfio_pci_teardown_msi(VFIOPCIDevice *vdev); =20 +/* Config space */ uint32_t vfio_pci_read_config(PCIDevice *pdev, uint32_t addr, int len); void vfio_pci_write_config(PCIDevice *pdev, uint32_t addr, uint32_t val, int len); +bool vfio_pci_config_setup(VFIOPCIDevice *vdev, Error **errp); +void vfio_pci_config_register_vga(VFIOPCIDevice *vdev); + +/* ROM */ +bool vfio_opt_rom_in_denylist(VFIOPCIDevice *vdev); =20 +/* VGA */ uint64_t vfio_vga_read(void *opaque, hwaddr addr, unsigned size); void vfio_vga_write(void *opaque, hwaddr addr, uint64_t data, unsigned siz= e); +bool vfio_populate_vga(VFIOPCIDevice *vdev, Error **errp); =20 -/** - * vfio_pci_from_vfio_device: Transform from VFIODevice to - * VFIOPCIDevice - * - * This function checks if the given @vbasedev is a VFIO PCI device. - * If it is, it returns the containing VFIOPCIDevice. - * - * @vbasedev: The VFIODevice to transform - * - * Return: The VFIOPCIDevice on success, NULL on failure. - */ -VFIOPCIDevice *vfio_pci_from_vfio_device(VFIODevice *vbasedev); +/* BARs */ +void vfio_pci_bars_exit(VFIOPCIDevice *vdev); void vfio_sub_page_bar_update_mappings(VFIOPCIDevice *vdev); -bool vfio_opt_rom_in_denylist(VFIOPCIDevice *vdev); + +/* Capabilities */ +bool vfio_pci_add_capabilities(VFIOPCIDevice *vdev, Error **errp); + +/* Quirks */ bool vfio_config_quirk_setup(VFIOPCIDevice *vdev, Error **errp); void vfio_vga_quirk_setup(VFIOPCIDevice *vdev); void vfio_vga_quirk_exit(VFIOPCIDevice *vdev); @@ -256,12 +261,14 @@ void vfio_rom_quirk_setup(VFIOPCIDevice *vdev); void vfio_quirk_reset(VFIOPCIDevice *vdev); VFIOQuirk *vfio_quirk_alloc(int nr_mem); =20 +/* IGD */ void vfio_probe_igd_bar0_quirk(VFIOPCIDevice *vdev, int nr); bool vfio_probe_igd_config_quirk(VFIOPCIDevice *vdev, Error **errp); void vfio_igd_legacy_rom_quirk(VFIOPCIDevice *vdev); =20 extern const PropertyInfo qdev_prop_nv_gpudirect_clique; =20 +/* Reset */ struct vfio_pci_hot_reset_info; =20 void vfio_pci_pre_reset(VFIOPCIDevice *vdev); @@ -270,25 +277,30 @@ bool vfio_pci_host_match(PCIHostDeviceAddress *addr, = const char *name); int vfio_pci_get_pci_hot_reset_info(VFIOPCIDevice *vdev, struct vfio_pci_hot_reset_info **info_= p); =20 -bool vfio_populate_vga(VFIOPCIDevice *vdev, Error **errp); - +/* Display */ void vfio_display_reset(VFIOPCIDevice *vdev); bool vfio_display_probe(VFIOPCIDevice *vdev, Error **errp); void vfio_display_exit(VFIOPCIDevice *vdev); void vfio_display_finalize(VFIOPCIDevice *vdev); - extern const VMStateDescription vfio_display_vmstate; =20 -void vfio_pci_bars_exit(VFIOPCIDevice *vdev); -bool vfio_pci_add_capabilities(VFIOPCIDevice *vdev, Error **errp); -void vfio_pci_config_register_vga(VFIOPCIDevice *vdev); -bool vfio_pci_config_setup(VFIOPCIDevice *vdev, Error **errp); -bool vfio_pci_interrupt_setup(VFIOPCIDevice *vdev, Error **errp); -void vfio_pci_intx_eoi(VFIODevice *vbasedev); -void vfio_pci_put_device(VFIOPCIDevice *vdev); -bool vfio_pci_populate_device(VFIOPCIDevice *vdev, Error **errp); +/* Notifiers */ void vfio_pci_register_err_notifier(VFIOPCIDevice *vdev); void vfio_pci_register_req_notifier(VFIOPCIDevice *vdev); -void vfio_pci_teardown_msi(VFIOPCIDevice *vdev); + +/** + * vfio_pci_from_vfio_device: Transform from VFIODevice to + * VFIOPCIDevice + * + * This function checks if the given @vbasedev is a VFIO PCI device. + * If it is, it returns the containing VFIOPCIDevice. + * + * @vbasedev: The VFIODevice to transform + * + * Return: The VFIOPCIDevice on success, NULL on failure. + */ +VFIOPCIDevice *vfio_pci_from_vfio_device(VFIODevice *vbasedev); +void vfio_pci_put_device(VFIOPCIDevice *vdev); +bool vfio_pci_populate_device(VFIOPCIDevice *vdev, Error **errp); =20 #endif /* HW_VFIO_VFIO_PCI_H */ --=20 2.56.0 From nobody Mon Nov 23 04:26:31 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1793430346; cv=none; d=zohomail.com; s=zohoarc; b=im3jb2F3hujApnucEt0NIunf+1aWtdurYpPmjqmzdQ5/KN/54qDnMKJaT8egojgB/SHhtEqWiXXLabksQnz09/aL6OUZnZEQvME3tW5UPf8bBK8+mDx0D/lBacX+jAQX8dwtKZvH3TRYWTvDYiwdtJsm3wu3pToxKRt/cpLPDDU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793430346; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=R9NtJTdgJOuxNOgX7IWRPzs1VYDjTzOeqz5UU10cxXg=; b=l3KZn6QYUheJuyI0mbXbhToMR/w7i5z33r70xvJBgpvRlgncrxMgxEXnHEGvY5RK73cT8laZWBNUxJkuNkCia/TkoIdF4k1v5QJMQZ1kGl4X9sF8ulR9P6v5k7f2C4IIqWBy9D/40uY8ydCjFcGXrFvn30PeeTMb96JUfPFEV2o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793430346400120.96567600050525; Sat, 31 Oct 2026 00:05:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xN38C-0001Sr-0b; Sat, 31 Oct 2026 03:04:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xN36V-0000sx-UI for qemu-devel@nongnu.org; Sat, 31 Oct 2026 03:02:19 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xN36U-0003M7-9Y for qemu-devel@nongnu.org; Sat, 31 Oct 2026 03:02:15 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-93-j9ROXr53PHaWI0cphVeAWQ-1; Sat, 31 Oct 2026 03:02:10 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E9E2019560B5; Sat, 31 Oct 2026 07:02:08 +0000 (UTC) Received: from circe.redhat.com (unknown [10.44.32.2]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 037271803A6F; Sat, 31 Oct 2026 07:02:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1793430133; 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=R9NtJTdgJOuxNOgX7IWRPzs1VYDjTzOeqz5UU10cxXg=; b=fzOSWw/LC0dJl/3FSoRvgoWqSBOpQcOBFVVuFQ0mMVgEc2XM+Ira+iFupEDY0t0I7zLzo+ Pz3wEy9x1N9jB/ffMqm1w2BqYrznYvJMVKObOwxmpTvPI2lZPONxoitvrsfdL0vAxU95J5 JXO3EN7ZIX8JLf7/ynTsrOWHf0mSXPQ= X-MC-Unique: j9ROXr53PHaWI0cphVeAWQ-1 X-Mimecast-MFC-AGG-ID: j9ROXr53PHaWI0cphVeAWQ_1793430129 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Tomita Moeko , Yuan Wang , Bosheng Xue , Junjie Cao , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 6/6] vfio/igd: Use version mapping for MTL/ARL quirk selection Date: Sat, 31 Oct 2026 08:01:52 +0100 Message-ID: <20261031070152.197043-7-clg@redhat.com> In-Reply-To: <20261031070152.197043-1-clg@redhat.com> References: <20261031070152.197043-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 5 X-Spam_score: 0.5 X-Spam_bar: / X-Spam_report: (0.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1793430349190154100 From: Tomita Moeko Meteor Lake and Arrow Lake use graphics IP version 12.70, but igd_gen() only returns the major version (generation). Encode the existing device ID mapping as (version * 100 + release) so that MTL/ARL can be selected in the BAR0 pcode stolen access quirk instead of a separate device ID check. Signed-off-by: Tomita Moeko Cc: Yuan Wang Cc: Bosheng Xue Cc: Junjie Cao Reviewed-by: C=C3=A9dric Le Goater Link: https://lore.kernel.org/qemu-devel/20261029161702.117078-1-tomitamoek= o@gmail.com Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/igd.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/hw/vfio/igd.c b/hw/vfio/igd.c index 4c7d6545924ca49cbe0285f77b422517b1c59159..728b60d3d4a5d3ed095d8bc9ae2= 67c6120b933b2 100644 --- a/hw/vfio/igd.c +++ b/hw/vfio/igd.c @@ -58,8 +58,9 @@ * not be taken as an indication that all the devices are supported, or ev= en * supportable, some of them don't even support VT-d. * See linux:include/drm/i915_pciids.h for IDs. + * Returns (version * 100 + release). */ -static int igd_gen(VFIOPCIDevice *vdev) +static int igd_graphics_ver(VFIOPCIDevice *vdev) { /* * Device IDs for Broxton/Apollo Lake are 0x0a84, 0x1a84, 0x1a85, 0x5a= 84 @@ -67,38 +68,39 @@ static int igd_gen(VFIOPCIDevice *vdev) * Prefix 0x0a is taken by Haswell, this rule should be matched first. */ if ((vdev->device_id & 0xffe) =3D=3D 0xa84) { - return 9; + return 900; } =20 switch (vdev->device_id & 0xff00) { case 0x0100: /* SandyBridge, IvyBridge */ - return 6; + return 600; case 0x0400: /* Haswell */ case 0x0a00: /* Haswell */ case 0x0c00: /* Haswell */ case 0x0d00: /* Haswell */ case 0x0f00: /* Valleyview/Bay Trail */ - return 7; + return 700; case 0x1600: /* Broadwell */ case 0x2200: /* Cherryview */ - return 8; + return 800; case 0x1900: /* Skylake */ case 0x3100: /* Gemini Lake */ case 0x5900: /* Kaby Lake */ case 0x3e00: /* Coffee Lake */ case 0x9B00: /* Comet Lake */ - return 9; + return 900; case 0x8A00: /* Ice Lake */ case 0x4500: /* Elkhart Lake */ case 0x4E00: /* Jasper Lake */ - return 11; + return 1100; case 0x9A00: /* Tiger Lake */ case 0x4C00: /* Rocket Lake */ case 0x4600: /* Alder Lake */ case 0xA700: /* Raptor Lake */ + return 1200; case 0x7D00: /* Meteor Lake / Arrow Lake */ case 0xB600: /* Arrow Lake */ - return 12; + return 1270; } =20 /* @@ -109,6 +111,12 @@ static int igd_gen(VFIOPCIDevice *vdev) return -1; } =20 +static int igd_gen(VFIOPCIDevice *vdev) +{ + int ver =3D igd_graphics_ver(vdev); + return ver < 0 ? -1 : ver / 100; +} + #define IGD_ASLS 0xfc /* ASL Storage Register */ #define IGD_GMCH 0x50 /* Graphics Control Register */ #define IGD_BDSM 0x5c /* Base Data of Stolen Memory */ @@ -458,10 +466,6 @@ static bool vfio_pci_igd_override_gms(int gen, uint32_= t gms, uint32_t *gmch) #define IGD_BDSM_MMIO_OFFSET 0x1080C0 #define IGD_MTL_PCODE_STOLEN_ACCESS 0x138914 =20 -#define IGD_IS_MTL_OR_ARL(vdev) \ - ((((vdev)->device_id & 0xff00) =3D=3D 0x7d00) || \ - (((vdev)->device_id & 0xff00) =3D=3D 0xb600)) - static uint64_t vfio_igd_pcode_stolen_access_read(void *opaque, hwaddr add= r, unsigned size) { @@ -591,7 +595,7 @@ void vfio_probe_igd_bar0_quirk(VFIOPCIDevice *vdev, int= nr) * Return 0 for PCODE stolen memory access detection (0x138914) so GOP * stays on the standard access path in the VM. */ - if (IGD_IS_MTL_OR_ARL(vdev)) { + if (igd_graphics_ver(vdev) =3D=3D 1270) { pcode_stolen_access_quirk =3D vfio_quirk_alloc(1); memory_region_init_io(pcode_stolen_access_quirk->mem, OBJECT(vdev), &vfio_igd_pcode_stolen_access_quirk, vdev, --=20 2.56.0