From nobody Tue Mar 3 04:55:56 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=1771245442; cv=none; d=zohomail.com; s=zohoarc; b=Gv5EKaBqvaZz48wGLB27IqPNj1moAaKV9MVIUzP/vUQh2j8zd69f6QkxT2LB1pLjCxOTs6QxBd5Vv2bcjRmCdClc5bvN+U2oFk+zYJz4hyhmOEU9cRqtfzIJx4v1t/Svmwoh12Ht5Wjgx+dc6Yp3tEeIfmyZXeo3HCO7JQCaCQ0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771245442; 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=Ck9sSWP/Yw1F6giQxBLaU1BNRFuOClpDnJu0NaWBc1I=; b=nViX0/btcfmJpCaa/h+slDJwqkONNIXyZLbFuAFo4ZG0g+6OugHFKSiYFvNDph57mRKxjCcwQ1A5zAkUGryJouXaRw0soG2x2aYGgFcUE/+rpfJiMCsjOKcd91amoOp6xPjVuGWnq3bzhsGBNuCRPfkhfRSAdIOyXiGP00U2H3Q= 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 177124544239056.77793131397016; Mon, 16 Feb 2026 04:37:22 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 993) id AD8C6418A9; Mon, 16 Feb 2026 07:37:21 -0500 (EST) Received: from [172.19.199.9] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 7A98941ABF; Mon, 16 Feb 2026 07:29:49 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 993) id 4B0883FBCB; Mon, 16 Feb 2026 07:29:45 -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 D6BAF3F95B for ; Mon, 16 Feb 2026 07:28:28 -0500 (EST) 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-652-hJQ-o3-gP3SeSn9BR9U_dQ-1; Mon, 16 Feb 2026 07:28:26 -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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1CDA51955D8C for ; Mon, 16 Feb 2026 12:28:26 +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 6EA7F30001B9 for ; Mon, 16 Feb 2026 12:28:25 +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=1771244908; 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=Ck9sSWP/Yw1F6giQxBLaU1BNRFuOClpDnJu0NaWBc1I=; b=YEVSEK3OiaC34nArYRQLJAfedq/ECn7X6vGduoMbnIlxvJ6Np1cXqzxMpUftjT4Tb2lmqP rmB6pdlsdXbM+rxnZQjExz2qMD18NSZl4DoOiiheZBR6AT7foylIG+2QhSvOaVoLEN9559 gdnVqXbIy9uzb4l41o0+Oj+WjBUqAhc= X-MC-Unique: hJQ-o3-gP3SeSn9BR9U_dQ-1 X-Mimecast-MFC-AGG-ID: hJQ-o3-gP3SeSn9BR9U_dQ_1771244906 To: devel@lists.libvirt.org Subject: [libvirt PATCH 07/24] util: Use virPCIDevice as argument in virPCIDeviceGetVfioPath Date: Mon, 16 Feb 2026 13:27:59 +0100 Message-ID: <58969223656ed602f62bbe1d5ab9cf35ed003d8c.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: eMaMR8L6OeHknnd5Q0jJZM3Kl1_68PYAk5pdkDv01IY_1771244906 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 66C3TXICZRK2NNLO7T62GGYTOXH6TQTQ X-Message-ID-Hash: 66C3TXICZRK2NNLO7T62GGYTOXH6TQTQ 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: 1771245445189154100 Content-Type: text/plain; charset="utf-8"; x-default="true" Signed-off-by: Pavel Hrdina --- src/security/security_apparmor.c | 2 +- src/security/security_dac.c | 4 ++-- src/security/security_selinux.c | 4 ++-- src/util/virpci.c | 14 ++++++++------ src/util/virpci.h | 2 +- 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/security/security_apparmor.c b/src/security/security_appar= mor.c index 934acfb461..6c5da2a650 100644 --- a/src/security/security_apparmor.c +++ b/src/security/security_apparmor.c @@ -860,7 +860,7 @@ AppArmorSetSecurityHostdevLabel(virSecurityManager *mgr, } else { g_autofree char *vfiofdDev =3D NULL; =20 - if (virPCIDeviceGetVfioPath(&dev->source.subsys.u.pci.addr= , &vfiofdDev) < 0) + if (virPCIDeviceGetVfioPath(pci, &vfiofdDev) < 0) goto done; =20 ret =3D AppArmorSetSecurityPCILabel(pci, vfiofdDev, ptr); diff --git a/src/security/security_dac.c b/src/security/security_dac.c index d0ed22db2d..704c8dbfec 100644 --- a/src/security/security_dac.c +++ b/src/security/security_dac.c @@ -1295,7 +1295,7 @@ virSecurityDACSetHostdevLabel(virSecurityManager *mgr, } else { g_autofree char *vfiofdDev =3D NULL; =20 - if (virPCIDeviceGetVfioPath(&dev->source.subsys.u.pci.addr= , &vfiofdDev) < 0) + if (virPCIDeviceGetVfioPath(pci, &vfiofdDev) < 0) return -1; =20 ret =3D virSecurityDACSetHostdevLabelHelper(vfiofdDev, fal= se, &cbdata); @@ -1468,7 +1468,7 @@ virSecurityDACRestoreHostdevLabel(virSecurityManager = *mgr, } else { g_autofree char *vfiofdDev =3D NULL; =20 - if (virPCIDeviceGetVfioPath(&dev->source.subsys.u.pci.addr= , &vfiofdDev) < 0) + if (virPCIDeviceGetVfioPath(pci, &vfiofdDev) < 0) return -1; =20 ret =3D virSecurityDACRestoreFileLabelInternal(mgr, NULL, diff --git a/src/security/security_selinux.c b/src/security/security_selinu= x.c index 834383a7de..4a5f61d16b 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -2269,7 +2269,7 @@ virSecuritySELinuxSetHostdevSubsysLabel(virSecurityMa= nager *mgr, } else { g_autofree char *vfiofdDev =3D NULL; =20 - if (virPCIDeviceGetVfioPath(&dev->source.subsys.u.pci.addr= , &vfiofdDev) < 0) + if (virPCIDeviceGetVfioPath(pci, &vfiofdDev) < 0) return -1; =20 ret =3D virSecuritySELinuxSetHostdevLabelHelper(vfiofdDev,= false, &data); @@ -2515,7 +2515,7 @@ virSecuritySELinuxRestoreHostdevSubsysLabel(virSecuri= tyManager *mgr, } else { g_autofree char *vfiofdDev =3D NULL; =20 - if (virPCIDeviceGetVfioPath(&dev->source.subsys.u.pci.addr= , &vfiofdDev) < 0) + if (virPCIDeviceGetVfioPath(pci, &vfiofdDev) < 0) return -1; =20 ret =3D virSecuritySELinuxRestoreFileLabel(mgr, vfiofdDev,= false, false); diff --git a/src/util/virpci.c b/src/util/virpci.c index 30feec6dae..78c47869ef 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -3331,19 +3331,17 @@ virPCIDeviceAddressFree(virPCIDeviceAddress *addres= s) * Returns: 0 on success, -1 on failure */ int -virPCIDeviceGetVfioPath(virPCIDeviceAddress *addr, +virPCIDeviceGetVfioPath(virPCIDevice *pci, char **vfioPath) { - g_autofree char *addrStr =3D NULL; g_autofree char *sysfsPath =3D NULL; g_autoptr(DIR) dir =3D NULL; struct dirent *entry =3D NULL; =20 *vfioPath =3D NULL; - addrStr =3D virPCIDeviceAddressAsString(addr); =20 /* Look in device's vfio-dev subdirectory */ - sysfsPath =3D g_strdup_printf("/sys/bus/pci/devices/%s/vfio-dev/", add= rStr); + sysfsPath =3D virPCIFile(pci->name, "vfio-dev"); =20 if (virDirOpen(&dir, sysfsPath) =3D=3D 1) { while (virDirRead(dir, &entry, sysfsPath) > 0) { @@ -3356,7 +3354,7 @@ virPCIDeviceGetVfioPath(virPCIDeviceAddress *addr, =20 virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot find VFIO device for PCI device %1$s"), - addrStr); + pci->name); return -1; } =20 @@ -3371,10 +3369,14 @@ virPCIDeviceGetVfioPath(virPCIDeviceAddress *addr, int virPCIDeviceOpenVfioFd(virPCIDeviceAddress *addr) { + g_autoptr(virPCIDevice) pci =3D NULL; g_autofree char *vfioPath =3D NULL; int fd =3D -1; =20 - if (virPCIDeviceGetVfioPath(addr, &vfioPath) < 0) + if (!(pci =3D virPCIDeviceNew(addr))) + return -1; + + if (virPCIDeviceGetVfioPath(pci, &vfioPath) < 0) return -1; =20 VIR_DEBUG("Opening VFIO device %s", vfioPath); diff --git a/src/util/virpci.h b/src/util/virpci.h index 7848567285..933099da6c 100644 --- a/src/util/virpci.h +++ b/src/util/virpci.h @@ -296,7 +296,7 @@ void virPCIEDeviceInfoFree(virPCIEDeviceInfo *dev); =20 void virPCIDeviceAddressFree(virPCIDeviceAddress *address); =20 -int virPCIDeviceGetVfioPath(virPCIDeviceAddress *addr, char **vfioPath); +int virPCIDeviceGetVfioPath(virPCIDevice *pci, char **vfioPath); =20 int virPCIDeviceOpenVfioFd(virPCIDeviceAddress *addr); =20 --=20 2.53.0