From nobody Tue Mar 3 04:56:07 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=1772183086; cv=none; d=zohomail.com; s=zohoarc; b=eqV2nzSxEEeCb4SP5fEh+gwz33PsIL0pidBhuqodBQyrNXwxtWHFn+VFpCRcgltRohUI3RIIUAkjIuUdVr7OBSY2QchkO9POQqAz/CjFu9EKnQxFK3/3iROtgu9Y0725Z23ToNOmBUCX3+bXMd9bitbo/QEC61I3xpVrPuxPhqk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772183086; 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=xLVYEOmcL8uTJUmnWnatwLZjQQsSVHPOANjfylH9mvs=; b=kJfnZs9t/F53Z7Bo7gVqiTNcc78fpdyC5YZORyG2RfXOnYd0jdtgyWPdjFJk8zDgR6GQloDb0FGwhl6qSpwpcFlNVIkxRxzOl2m9DqcJRLJ341UhPcuDN8yQYpC/vGKs5uhvrvSAfNJNHvyH3lyJhbv3HOEvg8urdnwkqEnLAo4= 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 1772183086346725.2923446549772; Fri, 27 Feb 2026 01:04:46 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 993) id 617BE41D65; Fri, 27 Feb 2026 04:04:45 -0500 (EST) Received: from [172.19.199.12] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id CA43841E2F; Fri, 27 Feb 2026 04:03:13 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 993) id D58C33F97E; Fri, 27 Feb 2026 04:03:08 -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 7597D417D0 for ; Fri, 27 Feb 2026 04:03:08 -0500 (EST) Received: from mx-prod-mc-08.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-211-ahtTtOu6Pdmna6ybPd1f9Q-1; Fri, 27 Feb 2026 04:03:06 -0500 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A131218002E6 for ; Fri, 27 Feb 2026 09:03:05 +0000 (UTC) Received: from moe (unknown [10.43.3.236]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 100CA19560B5 for ; Fri, 27 Feb 2026 09:03:04 +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=-2.6 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HELO_MISC_IP,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=1772182988; 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=xLVYEOmcL8uTJUmnWnatwLZjQQsSVHPOANjfylH9mvs=; b=P+K3qT1UpMX4RbUple9sVJnjd2Yf67UrZRNPu/YYF+iB6huMMfDcorERMxDE6sEuvfhmZS 6M840PENN/BoXD4YqYCND15Rjn2mplnNMiKaOjyLgbsAi9WmH6cICZAqm0rFHXe3SFx2go jPqgV9Hpz0aPn3uGH5D1t65flu/1ADs= X-MC-Unique: ahtTtOu6Pdmna6ybPd1f9Q-1 X-Mimecast-MFC-AGG-ID: ahtTtOu6Pdmna6ybPd1f9Q_1772182985 To: devel@lists.libvirt.org Subject: [PATCH 1/4] virpcimock: Create sriov_totalvfs file and virtfnN symlinks Date: Fri, 27 Feb 2026 10:02:56 +0100 Message-ID: <6b65355bbd523cb17de19570a2c9bbcf1f5667dc.1772182866.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: UckORSNN2UAolhR3cUmGt7Pug5wlXTtufHwsP_9m4io_1772182985 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 3W27YHUA7EOSQ745IISGTM5PLMCL5I6T X-Message-ID-Hash: 3W27YHUA7EOSQ745IISGTM5PLMCL5I6T X-MailFrom: mprivozn@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: Michal Privoznik via Devel Reply-To: Michal Privoznik X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1772183088281158500 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Michal Privoznik In case of an SRIOV device the sysfs struct looks like this: -r--r--r--. 1 root root 4096 Feb 26 14:40 /sys/bus/pci/devices/0000:82:00.0= /sriov_totalvfs lrwxrwxrwx. 1 root root 0 Feb 25 22:51 /sys/bus/pci/devices/0000:82:00.0= /virtfn0 -> ../0000:82:10.0 lrwxrwxrwx. 1 root root 0 Feb 25 22:51 /sys/bus/pci/devices/0000:82:00.0= /virtfn1 -> ../0000:82:10.4 lrwxrwxrwx. 1 root root 0 Feb 25 22:51 /sys/bus/pci/devices/0000:82:00.0= /virtfn2 -> ../0000:82:11.0 lrwxrwxrwx. 1 root root 0 Feb 25 22:51 /sys/bus/pci/devices/0000:82:00.0= /virtfn3 -> ../0000:82:11.4 Of course, there is much more, I've just picked up files that our code touches during hotplug of an . The first file 'sriov_totalvfs' contains the maximum number of VFs supported. Then, for each VF created there's 'virtfnN' symlink to individual VFs. Teach our virpcimock to create the file and symlinks. Signed-off-by: Michal Privoznik --- tests/virpcimock.c | 50 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/tests/virpcimock.c b/tests/virpcimock.c index ca345f37a3..c59359b889 100644 --- a/tests/virpcimock.c +++ b/tests/virpcimock.c @@ -141,6 +141,8 @@ struct pciDevice { int device; int klass; int iommuGroup; + int sriovTotalvfs; + unsigned int virtfnCount; const char *physfn; struct pciDriver *driver; /* Driver attached. NULL if attached to no= driver */ struct pciVPD vpd; @@ -439,6 +441,38 @@ pci_device_create_iommu(const struct pciDevice *dev, } =20 =20 +static void +register_vf(struct pciDevice *vf) +{ + struct pciDeviceAddress pfAddr; + struct pciDevice *pf; + g_autofree char *relPath =3D NULL; + g_autofree char *pfPath =3D NULL; + g_autofree char *virtfnName =3D NULL; + + if (pci_address_parse(&pfAddr, vf->physfn) < 0) + ABORT("Unable to parse PCI address %s", vf->physfn); + + if (!(pf =3D pci_device_find_by_id(&pfAddr))) { + ABORT("Unable to find PF for VF %s", vf->physfn); + } + + relPath =3D g_strdup_printf("../" ADDR_STR_FMT, + vf->addr.domain, + vf->addr.bus, + vf->addr.device, + vf->addr.function); + + virtfnName =3D g_strdup_printf("virtfn%u", pf->virtfnCount); + + pfPath =3D pci_device_get_path(pf, NULL, true); + + make_symlink(pfPath, virtfnName, relPath); + + pf->virtfnCount++; +} + + static void pci_device_new_from_stub(const struct pciDevice *data) { @@ -537,6 +571,14 @@ pci_device_new_from_stub(const struct pciDevice *data) =20 make_symlink(devsympath, devid, tmp); =20 + if (dev->sriovTotalvfs) { + if (g_snprintf(tmp, sizeof(tmp), "%d\n", dev->sriovTotalvfs) < 0) { + ABORT("@tmp overflow"); + } + + make_file(devpath, "sriov_totalvfs", tmp, -1); + } + if (dev->physfn) { if (g_snprintf(tmp, sizeof(tmp), "%s%s/devices/%s", fakerootdir, @@ -544,6 +586,8 @@ pci_device_new_from_stub(const struct pciDevice *data) ABORT("@tmp overflow"); } make_symlink(devpath, "physfn", tmp); + + register_vf(dev); } =20 if (dev->vpd.data && dev->vpd.vpd_len) @@ -1043,12 +1087,14 @@ init_env(void) MAKE_PCI_DEVICE("0000:0a:01.0", 0x8086, 0x0047, 8); MAKE_PCI_DEVICE("0000:0a:02.0", 0x8286, 0x0048, 8); MAKE_PCI_DEVICE("0000:0a:03.0", 0x8386, 0x0048, 8); - MAKE_PCI_DEVICE("0000:06:12.0", 0x8086, 0x0047, 9); + MAKE_PCI_DEVICE("0000:06:12.0", 0x8086, 0x0047, 9, + .sriovTotalvfs =3D 7); MAKE_PCI_DEVICE("0000:06:12.1", 0x8086, 0x0047, 10, .physfn =3D "0000:06:12.0"); /* Virtual Function */ MAKE_PCI_DEVICE("0000:06:12.2", 0x8086, 0x0047, 11, .physfn =3D "0000:06:12.0"); /* Virtual Function */ - MAKE_PCI_DEVICE("0021:de:1f.0", 0x8086, 0x0047, 12); + MAKE_PCI_DEVICE("0021:de:1f.0", 0x8086, 0x0047, 12, + .sriovTotalvfs =3D 7); MAKE_PCI_DEVICE("0021:de:1f.1", 0x8086, 0x0047, 13, .physfn =3D "0021:de:1f.0"); /* Virtual Function */ =20 --=20 2.52.0