From nobody Tue Mar 3 04:55:51 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=1771245311; cv=none; d=zohomail.com; s=zohoarc; b=g8njwa+PmHmmJEqemPcaVN/pLES7DXn2sVyAzvnJd3eh+z/O7OkAWa0r7iIEEvJrTE2QT4l/68iMwgpyenLCa+WZXF64CZvpdlV3+qYGVSk2GYSHGkQfLxgAL6xwn89TF5RZsSpNEoa2p+/g+k0t/UXN7pNhQ0cjP+BRrM4MB14= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771245311; 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=StWclDInuzK+2LS1Vf35KXjq+710M9ZgqLKRVVp6C9E=; b=QVtm8r6CLQ9WJ2uPsOu+SpB+wM3gI5MHExDcvCGPyysJMcRFFEZEYgNvZggXahLQAa6sY87Q4nWdMiN8lkOLgc2ygAEL3KD++hp7yS7Xt77FFwR1WgoZ4F9yYOKYklIQ8W74yvdI2rmg4PBHCy63CZpMiKhVjbLSM0l5w49YJes= 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 1771245311567314.70711104590987; Mon, 16 Feb 2026 04:35:11 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 993) id AA1A0418B1; Mon, 16 Feb 2026 07:35:10 -0500 (EST) Received: from [172.19.199.9] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 4576541A2C; Mon, 16 Feb 2026 07:28:44 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 993) id 9D5133F956; Mon, 16 Feb 2026 07:28:39 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 586E03F8A4 for ; Mon, 16 Feb 2026 07:28:26 -0500 (EST) Received: from mx-prod-mc-01.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-615-Imsbsl9JPDKB_6r6nNF3mQ-1; Mon, 16 Feb 2026 07:28:24 -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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id F207B1955DE7 for ; Mon, 16 Feb 2026 12:28:23 +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 4F27430001A5 for ; Mon, 16 Feb 2026 12:28:23 +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=1771244905; 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=StWclDInuzK+2LS1Vf35KXjq+710M9ZgqLKRVVp6C9E=; b=Es+4orWJJR4azdjpPIQ6uvQkEtBuPhpxOe2qUOiLB0OAGcL/Jq7F/0dOxeHRnDBz1HEOZw HAyuDSkultw1ExZmCmb58THniBkuw93Ozj/zjOWhSjfrj7T0LJYGwYuJNTabnD2TTVbGaU eaMmC0XYJcI+VolAmlBx4Evi8PF5k0o= X-MC-Unique: Imsbsl9JPDKB_6r6nNF3mQ-1 X-Mimecast-MFC-AGG-ID: Imsbsl9JPDKB_6r6nNF3mQ_1771244904 To: devel@lists.libvirt.org Subject: [libvirt PATCH 05/24] util: Move openning VFIO device to virpci Date: Mon, 16 Feb 2026 13:27:57 +0100 Message-ID: <670328117ea92229756f0aad76d27a3c3dc49a7d.1771244723.git.phrdina@redhat.com> 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: f-T0n0gQrgP8Wk9GPpT8qgc7Q8Ob2OJ2ViMbSpBWBQE_1771244904 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: KEGZ3QXD7ZCB2UGCOB54ITCLWPKD7WMM X-Message-ID-Hash: KEGZ3QXD7ZCB2UGCOB54ITCLWPKD7WMM 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: 1771245312949158500 Content-Type: text/plain; charset="utf-8"; x-default="true" Signed-off-by: Pavel Hrdina --- src/libvirt_private.syms | 1 + src/qemu/qemu_process.c | 23 +---------------------- src/util/virpci.c | 28 ++++++++++++++++++++++++++++ src/util/virpci.h | 2 ++ 4 files changed, 32 insertions(+), 22 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 576b1f6595..4d29512e0b 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3175,6 +3175,7 @@ virPCIDeviceListNew; virPCIDeviceListSteal; virPCIDeviceListStealIndex; virPCIDeviceNew; +virPCIDeviceOpenVfioFd; virPCIDeviceReattach; virPCIDeviceRebind; virPCIDeviceReset; diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index d21abb9eb6..cc2a9c8abc 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -7711,9 +7711,6 @@ qemuProcessOpenIommuFd(virDomainObj *vm) static int qemuProcessOpenVfioDeviceFd(virDomainHostdevDef *hostdev) { - g_autofree char *vfioPath =3D NULL; - int fd =3D -1; - if (hostdev->mode !=3D VIR_DOMAIN_HOSTDEV_MODE_SUBSYS || hostdev->source.subsys.type !=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PC= I) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -7721,25 +7718,7 @@ qemuProcessOpenVfioDeviceFd(virDomainHostdevDef *hos= tdev) return -1; } =20 - if (virPCIDeviceGetVfioPath(&hostdev->source.subsys.u.pci.addr, &vfioP= ath) < 0) - return -1; - - VIR_DEBUG("Opening VFIO device %s", vfioPath); - - if ((fd =3D open(vfioPath, O_RDWR | O_CLOEXEC)) < 0) { - if (errno =3D=3D ENOENT) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("VFIO device %1$s not found - ensure device i= s bound to vfio-pci driver"), - vfioPath); - } else { - virReportSystemError(errno, - _("cannot open VFIO device %1$s"), vfioPa= th); - } - return -1; - } - - VIR_DEBUG("Opened VFIO device FD %d for %s", fd, vfioPath); - return fd; + return virPCIDeviceOpenVfioFd(&hostdev->source.subsys.u.pci.addr); } =20 /** diff --git a/src/util/virpci.c b/src/util/virpci.c index 2348a98003..30feec6dae 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -3359,3 +3359,31 @@ virPCIDeviceGetVfioPath(virPCIDeviceAddress *addr, addrStr); return -1; } + +/** + * virPCIDeviceOpenVfioFd: + * @addr: + * + * Opens VFIO device and returns its FD. + * + * Returns: FD on success, -1 on failure + */ +int +virPCIDeviceOpenVfioFd(virPCIDeviceAddress *addr) +{ + g_autofree char *vfioPath =3D NULL; + int fd =3D -1; + + if (virPCIDeviceGetVfioPath(addr, &vfioPath) < 0) + return -1; + + VIR_DEBUG("Opening VFIO device %s", vfioPath); + + if ((fd =3D open(vfioPath, O_RDWR | O_CLOEXEC)) < 0) { + virReportSystemError(errno, _("cannot open VFIO device %1$s"), vfi= oPath); + return -1; + } + + VIR_DEBUG("Opened VFIO device FD %d for %s", fd, vfioPath); + return fd; +} diff --git a/src/util/virpci.h b/src/util/virpci.h index 24ede10755..7848567285 100644 --- a/src/util/virpci.h +++ b/src/util/virpci.h @@ -298,6 +298,8 @@ void virPCIDeviceAddressFree(virPCIDeviceAddress *addre= ss); =20 int virPCIDeviceGetVfioPath(virPCIDeviceAddress *addr, char **vfioPath); =20 +int virPCIDeviceOpenVfioFd(virPCIDeviceAddress *addr); + G_DEFINE_AUTOPTR_CLEANUP_FUNC(virPCIDevice, virPCIDeviceFree); G_DEFINE_AUTOPTR_CLEANUP_FUNC(virPCIDeviceAddress, virPCIDeviceAddressFree= ); G_DEFINE_AUTOPTR_CLEANUP_FUNC(virPCIEDeviceInfo, virPCIEDeviceInfoFree); --=20 2.53.0