From nobody Mon Feb 9 17:23:55 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1607701701; cv=none; d=zohomail.com; s=zohoarc; b=lUHAJ2jx/0LjOD4z5Kn2lzs0TeaZHOSH5QigDrQtXpFT6MIncZ0ybkxnzr1orFNpM3MnyP2UvhkvZB70vQzBxPCNfOK5YgalbX9X5tIydhLvjrZO2v7zjvIxA0nttY/3tORJEUIAK9vtW++JEejVTo1/XN0obWfFkJgEJHrPw/s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1607701701; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=25k4T6nu3ioI0AUbPYdOdw9bJMIoOJviis5Rfiv0TiU=; b=O9DkPkTiqIpB3e95I76c2iA73+3iLFLorRNbimA/dJCjp0Y/iyKK4kS0aZl7UbqA4rSICZoI6+GTb9KRd7oT/6K7U7Tk0V4y7ao8k9DM4oeSldBUwf11kPnzoifZcbTOQmzWQuQFnzX/ZQQ+2vPoNXVqfiB2ARCFLS0qrmM3HJw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1607701701591267.02252589692955; Fri, 11 Dec 2020 07:48:21 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-531-nGLsW9LLMCOOm4HKZJytzA-1; Fri, 11 Dec 2020 10:48:18 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9D93ADF8A9; Fri, 11 Dec 2020 15:48:06 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7C3976F99C; Fri, 11 Dec 2020 15:48:06 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 0F4F71809CA3; Fri, 11 Dec 2020 15:48:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0BBFlXO4013825 for ; Fri, 11 Dec 2020 10:47:33 -0500 Received: by smtp.corp.redhat.com (Postfix) id 7574760BFA; Fri, 11 Dec 2020 15:47:33 +0000 (UTC) Received: from vhost2.laine.org (ovpn-113-158.phx2.redhat.com [10.3.113.158]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3D7C260BF1 for ; Fri, 11 Dec 2020 15:47:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607701700; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=25k4T6nu3ioI0AUbPYdOdw9bJMIoOJviis5Rfiv0TiU=; b=UmxpaUppylFjMc0OOqPWpilipGAUfsGjpwWa7o+7yCzTtpA+E9k7iLCklvzGRnr35+lmnA tUX4Roc41hl79PS/CnjhkSeNw6uIieLHfaZ8FnjftohIz8zKkepfKMgum5a3xcy1j6Zsqp YvSt66Ae8GwHAkKpbNxJ10nkmV2nOjM= X-MC-Unique: nGLsW9LLMCOOm4HKZJytzA-1 From: Laine Stump To: libvir-list@redhat.com Subject: [libvirt PATCH v2 7/7] qemu: remove now-redundant check for file length when determining PCIe vs. PCI Date: Fri, 11 Dec 2020 10:47:28 -0500 Message-Id: <20201211154728.1117948-8-laine@redhat.com> In-Reply-To: <20201211154728.1117948-1-laine@redhat.com> References: <20201211154728.1117948-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Now that virPCIDeviceIsPCIExpress() checks the length of the file when the process lacks sufficient privilege to read the entire PCI config file in sysfs, we can remove the open-coding for that case from its consumer. Signed-off-by: Laine Stump --- src/qemu/qemu_domain_address.c | 38 +++------------------------------- 1 file changed, 3 insertions(+), 35 deletions(-) diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index b07672e2f4..f0ba318cc8 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -579,7 +579,6 @@ qemuDomainDeviceCalculatePCIAddressExtensionFlags(virQE= MUCapsPtr qemuCaps, */ static virDomainPCIConnectFlags qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDefPtr dev, - virQEMUDriverPtr driver, virDomainPCIConnectFlags pcieFlag= s, virDomainPCIConnectFlags virtioFl= ags) { @@ -802,7 +801,6 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDevic= eDefPtr dev, =20 case VIR_DOMAIN_DEVICE_HOSTDEV: { virDomainHostdevDefPtr hostdev =3D dev->data.hostdev; - bool isExpress =3D false; g_autoptr(virPCIDevice) pciDev =3D NULL; virPCIDeviceAddressPtr hostAddr =3D &hostdev->source.subsys.u.pci.= addr; =20 @@ -873,37 +871,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDevi= ceDefPtr dev, return pcieFlags; } =20 - if (!driver->privileged) { - /* unprivileged libvirtd is unable to read *all* of a - * device's PCI config (it can only read the first 64 - * bytes, which isn't enough for the check that's done - * in virPCIDeviceIsPCIExpress()), so instead of - * trying and failing, we make an educated guess based - * on the length of the device's config file - if it - * is 256 bytes, then it is definitely a legacy PCI - * device. If it's larger than that, then it is - * *probably PCIe (although it could be PCI-x, but - * those are extremely rare). If the config file can't - * be found (in which case the "length" will be -1), - * then we blindly assume the most likely outcome - - * PCIe. - */ - off_t configLen - =3D virFileLength(virPCIDeviceGetConfigPath(pciDev), -1); - - if (configLen =3D=3D 256) - return pciFlags; - - return pcieFlags; - } - - /* If we are running with privileges, we can examine the - * PCI config contents with virPCIDeviceIsPCIExpress() for - * a definitive answer. - */ - isExpress =3D virPCIDeviceIsPCIExpress(pciDev); - - if (isExpress) + if (virPCIDeviceIsPCIExpress(pciDev)) return pcieFlags; =20 return pciFlags; @@ -1124,7 +1092,7 @@ qemuDomainFillDevicePCIConnectFlagsIter(virDomainDefP= tr def G_GNUC_UNUSED, qemuDomainFillDevicePCIConnectFlagsIterData *data =3D opaque; =20 info->pciConnectFlags - =3D qemuDomainDeviceCalculatePCIConnectFlags(dev, data->driver, + =3D qemuDomainDeviceCalculatePCIConnectFlags(dev, data->pcieFlags, data->virtioFlags); return 0; @@ -1468,7 +1436,7 @@ qemuDomainFillDevicePCIConnectFlags(virDomainDefPtr d= ef, qemuDomainFillDevicePCIConnectFlagsIterInit(def, qemuCaps, driver,= &data); =20 info->pciConnectFlags - =3D qemuDomainDeviceCalculatePCIConnectFlags(dev, data.driver, + =3D qemuDomainDeviceCalculatePCIConnectFlags(dev, data.pcieFlags, data.virtioFlags); } --=20 2.28.0