From nobody Tue Mar 3 04:54:09 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1771245815; cv=none; d=zohomail.com; s=zohoarc; b=P+DFgjLOiFr85YW3UbF+f84VSLoBlRT6oMs62crZDRD8/1M4b8I5b1rmLCHdUAzt/CfjvNvI79sVnxbx5PYBDBofGYKwalEljsYfrr//X/2N7aJQ0KoD7pqiRaOpVA7f12wJ6vII4sbl2CEJjeij2e7cCL5MhZhVZC9eS+KAIU4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771245815; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id:Cc; bh=fVpMXbpHTK71YnqyEo+MzcAvlZzcy7gW9aQU/boGJAY=; b=HeKsNvvonn9Ze1a0oYcRiXNNhSRFbGvIEE1RA2Xu5Wz/iObhWXoi+5q1Ljl3pd/g2TVdYloRO1oczGoGTxKJ7LdmQkewh1OVLHuQwfrRQHatqzJ1w01wcwx28T3UdJ+2DDnIURSu2pprnJPGZt6M5e5/kOZec1TPwLeKFZTaU3U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1771245815977485.42263866227836; Mon, 16 Feb 2026 04:43:35 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 993) id 35CC43F93E; Mon, 16 Feb 2026 07:43:35 -0500 (EST) Received: from [172.19.199.9] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id D9A0341C72; Mon, 16 Feb 2026 07:34:17 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 993) id EAD033F881; Mon, 16 Feb 2026 07:34:12 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id A140E3F8A4 for ; Mon, 16 Feb 2026 07:28:39 -0500 (EST) 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-676-IqgFc5xpN2yVRrUwwX5Tiw-1; Mon, 16 Feb 2026 07:28:38 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 8572718005BC for ; Mon, 16 Feb 2026 12:28:37 +0000 (UTC) Received: from antique-laptop.rosnicka.net (unknown [10.45.242.10]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C055530001A5 for ; Mon, 16 Feb 2026 12:28:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1771244919; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fVpMXbpHTK71YnqyEo+MzcAvlZzcy7gW9aQU/boGJAY=; b=dEohSXUZcaGsr6mXqX9gfj2ataPPOS1jAMWHO/LGKw6pbBeajNv4ERbOF/vaHqWJjCPvP+ xt6JehYkwFVoKiPz3rMASK+fjNnvoe1vXpnJdBjfX+iB4pf9YAFe8BeIQBZkjd0tSie7o2 nAesNjr2LKN3M/wfBk6TdeQdddKdNMs= X-MC-Unique: IqgFc5xpN2yVRrUwwX5Tiw-1 X-Mimecast-MFC-AGG-ID: IqgFc5xpN2yVRrUwwX5Tiw_1771244917 To: devel@lists.libvirt.org Subject: [libvirt PATCH 17/24] qemu: Convert vfioDeviceFd to qemuFDPassDirect Date: Mon, 16 Feb 2026 13:28:09 +0100 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 6lRUXPWMg5BEcb0lJKsQ9y16wqnK5obq_2wrNXoj3KI_1771244917 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: U5GXL7NOKJP3D2JTG5L3FTMQL3T7FWDS X-Message-ID-Hash: U5GXL7NOKJP3D2JTG5L3FTMQL3T7FWDS X-MailFrom: phrdina@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Pavel Hrdina via Devel Reply-To: Pavel Hrdina X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1771245817379158500 Content-Type: text/plain; charset="utf-8"; x-default="true" This cleans up creating QEMU command line and makes it easier when adding hotplug support. Signed-off-by: Pavel Hrdina --- src/qemu/qemu_command.c | 15 +++++---------- src/qemu/qemu_domain.c | 4 ++-- src/qemu/qemu_domain.h | 2 +- src/qemu/qemu_process.c | 6 +++++- tests/qemuxmlconftest.c | 4 +++- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 204fdf152b..91eb3cb27d 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -4818,12 +4818,10 @@ qemuBuildPCIHostdevDevProps(const virDomainDef *def, pcisrc->driver.iommufd =3D=3D VIR_TRISTATE_BOOL_YES) { qemuDomainHostdevPrivate *hostdevPriv =3D QEMU_DOMAIN_HOSTDEV_PRIV= ATE(dev); =20 - if (hostdevPriv->vfioDeviceFd !=3D -1) { - g_autofree char *fdstr =3D g_strdup_printf("%d", hostdevPriv->= vfioDeviceFd); - if (virJSONValueObjectAdd(&props, "S:fd", fdstr, NULL) < 0) - return NULL; - hostdevPriv->vfioDeviceFd =3D -1; - } + if (virJSONValueObjectAdd(&props, + "S:fd", qemuFDPassDirectGetPath(hostdevP= riv->vfioDeviceFd), + NULL) < 0) + return NULL; } =20 if (qemuBuildDeviceAddressProps(props, def, dev->info) < 0) @@ -5273,10 +5271,7 @@ qemuBuildHostdevCommandLine(virCommand *cmd, if (subsys->u.pci.driver.iommufd =3D=3D VIR_TRISTATE_BOOL_YES)= { qemuDomainHostdevPrivate *hostdevPriv =3D QEMU_DOMAIN_HOST= DEV_PRIVATE(hostdev); =20 - if (hostdevPriv->vfioDeviceFd !=3D -1) { - virCommandPassFD(cmd, hostdevPriv->vfioDeviceFd, - VIR_COMMAND_PASS_FD_CLOSE_PARENT); - } + qemuFDPassDirectTransferCommand(hostdevPriv->vfioDeviceFd,= cmd); } =20 if (!(devprops =3D qemuBuildPCIHostdevDevProps(def, hostdev))) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index d9cd9324e0..ada9d3431c 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -1245,7 +1245,7 @@ qemuDomainHostdevPrivateDispose(void *obj) { qemuDomainHostdevPrivate *priv =3D obj; =20 - VIR_FORCE_CLOSE(priv->vfioDeviceFd); + g_clear_pointer(&priv->vfioDeviceFd, qemuFDPassDirectFree); } =20 =20 @@ -1271,7 +1271,7 @@ qemuDomainHostdevPrivateNew(void) if (!(priv =3D virObjectNew(qemuDomainHostdevPrivateClass))) return NULL; =20 - priv->vfioDeviceFd =3D -1; + priv->vfioDeviceFd =3D NULL; =20 return (virObject *) priv; } diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index c6430b1bfb..fa7d4ab40f 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -463,7 +463,7 @@ struct _qemuDomainHostdevPrivate { virObject parent; =20 /* VFIO device file descriptor for iommufd passthrough */ - int vfioDeviceFd; + qemuFDPassDirect *vfioDeviceFd; }; =20 =20 diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index c814f992bb..fc7e7bc980 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -7714,10 +7714,14 @@ qemuProcessOpenVfioDeviceFd(virDomainHostdevDef *ho= stdev) { qemuDomainHostdevPrivate *hostdevPriv =3D QEMU_DOMAIN_HOSTDEV_PRIVATE(= hostdev); virDomainHostdevSubsysPCI *pci =3D &hostdev->source.subsys.u.pci; + g_autofree char *name =3D g_strdup_printf("hostdev-%s-fd", hostdev->in= fo->alias); + int vfioDeviceFd; =20 - if ((hostdevPriv->vfioDeviceFd =3D virPCIDeviceOpenVfioFd(&pci->addr))= < 0) + if ((vfioDeviceFd =3D virPCIDeviceOpenVfioFd(&pci->addr)) < 0) return -1; =20 + hostdevPriv->vfioDeviceFd =3D qemuFDPassDirectNew(name, &vfioDeviceFd); + return 0; } =20 diff --git a/tests/qemuxmlconftest.c b/tests/qemuxmlconftest.c index 13055eef84..d2ab4a71b5 100644 --- a/tests/qemuxmlconftest.c +++ b/tests/qemuxmlconftest.c @@ -357,8 +357,10 @@ testQemuPrepareHostdevPCI(virDomainHostdevDef *hostdev) qemuDomainHostdevPrivate *hostdevPriv =3D QEMU_DOMAIN_HOSTDEV_PRIVATE(= hostdev); =20 if (virHostdevIsPCIDeviceWithIOMMUFD(hostdev)) { + g_autofree char *name =3D g_strdup_printf("hostdev-%s-fd", hostdev= ->info->alias); /* Use a placeholder FD value for tests */ - hostdevPriv->vfioDeviceFd =3D 0; + int vfioDeviceFD =3D 0; + hostdevPriv->vfioDeviceFd =3D qemuFDPassDirectNew(name, &vfioDevic= eFD); } } =20 --=20 2.53.0