From nobody Fri May 17 20:54:19 2024 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=1607477886; cv=none; d=zohomail.com; s=zohoarc; b=KekH4xCv19h4aBs2ZCP7+wDafIzqGAo3I45CCXxfakgpx4uSVU4431hvUcvRABdQaPKjHcFRaKPLE1gOiCpC6obI0s099Ce6vXLbO4TPPqe3dOqeaZQ9tA2aQOKfQms8xLEmLtyDsmLNX7ThvS1Qv/y90BIeLjQh/Na7GdDETIU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1607477886; 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=q7ZJQENtCtg4f0WnT0RWcsSRu4lg4DSzYTO+BZXAU+8=; b=KHR9bqqnX/blCP1/0qmuUYMgsWzC45Y+dMsZuwpn7iW+gJsA43Xo41EMJoRotowWnvDneuKCbh1ZUL5/9Ih9d/Frajfo2HkUz6Dg1RrM8rwQxbTTT5807Q/0/7uTWf+idODTf/G6kHLFiRJQub+cLFcmIYdiGBZrkaxFcJ6feC4= 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 1607477886758819.6075745525833; Tue, 8 Dec 2020 17:38:06 -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-537-5FDRjTPqMeWi1j9yIxsZFQ-1; Tue, 08 Dec 2020 20:38:03 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E2B7A51E8; Wed, 9 Dec 2020 01:37:56 +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 72DF65C230; Wed, 9 Dec 2020 01:37:56 +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 D9CB9180954D; Wed, 9 Dec 2020 01:37:52 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0B91bpPU007381 for ; Tue, 8 Dec 2020 20:37:51 -0500 Received: by smtp.corp.redhat.com (Postfix) id 485A55D6D5; Wed, 9 Dec 2020 01:37:51 +0000 (UTC) Received: from vhost2.laine.org (ovpn-112-50.phx2.redhat.com [10.3.112.50]) by smtp.corp.redhat.com (Postfix) with ESMTP id 10E9F5D6AB for ; Wed, 9 Dec 2020 01:37:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607477885; 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=q7ZJQENtCtg4f0WnT0RWcsSRu4lg4DSzYTO+BZXAU+8=; b=FcDpAlHR0tulIMQ+7DRTIcOPG6QX818F89PRVScDJ2FiR04WweclzYSNZExwk5xdinonJU mALM5mL412eRAnQBHruOTObCGU4uUHXz6Zs23pKJb+Vp5RoYkUX7waVyKy+CBtdJXYOhCD t6RWclPPFO62uQUwSPBwXHVduZ/o9wM= X-MC-Unique: 5FDRjTPqMeWi1j9yIxsZFQ-1 From: Laine Stump To: libvir-list@redhat.com Subject: [PATCH 1/7] qemu: use g_autoptr for a virPCIDevice Date: Tue, 8 Dec 2020 20:37:39 -0500 Message-Id: <20201209013745.599662-2-laine@redhat.com> In-Reply-To: <20201209013745.599662-1-laine@redhat.com> References: <20201209013745.599662-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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.16 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" The one instance of a virPCIDevice in qemuDomainDeviceCalculatePCIConnectFlags() needs to be converted to use g_autoptr as a prerequisite for a bugfix. It's in this patch by itself (rather than in a patch converting all virPCIDevice usages to g_autoptr) to simplify any backport of said bugfix. Signed-off-by: Laine Stump Reviewed-by: Michal Privoznik --- src/qemu/qemu_domain_address.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index d872f75b38..b07672e2f4 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -803,7 +803,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDevic= eDefPtr dev, case VIR_DOMAIN_DEVICE_HOSTDEV: { virDomainHostdevDefPtr hostdev =3D dev->data.hostdev; bool isExpress =3D false; - virPCIDevicePtr pciDev; + g_autoptr(virPCIDevice) pciDev =3D NULL; virPCIDeviceAddressPtr hostAddr =3D &hostdev->source.subsys.u.pci.= addr; =20 if (!virHostdevIsMdevDevice(hostdev) && @@ -891,8 +891,6 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDevic= eDefPtr dev, off_t configLen =3D virFileLength(virPCIDeviceGetConfigPath(pciDev), -1); =20 - virPCIDeviceFree(pciDev); - if (configLen =3D=3D 256) return pciFlags; =20 @@ -904,7 +902,6 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDevic= eDefPtr dev, * a definitive answer. */ isExpress =3D virPCIDeviceIsPCIExpress(pciDev); - virPCIDeviceFree(pciDev); =20 if (isExpress) return pcieFlags; --=20 2.28.0 From nobody Fri May 17 20:54:19 2024 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=1607477902; cv=none; d=zohomail.com; s=zohoarc; b=Hoa161SRtO3vq5b1J951ihyandln5XdgZKZfxv4CrlH4oZKFx8tg65L4Nol7kulywl21knY/FhocZK8NE4BTzaJQmMJhijff6+MIt0dLEQ2zRP0A6Y5sEBvP0tX57fN3u/pv0RSuM0JfxDKS/hWh1oubczU16HdrGkcGhZhbcIc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1607477902; 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=NuMdpFC/V+Dyw8ez/m/KfYOwUD2pbure1i7s3wnXcOw=; b=hC0TOgE/wyYsLd19agC8QEXmWNWpiWDSKkT0WgkNRjHvx0qJIxfRO4t451iAIkyYaYLfW05109hxKbrNPQUl66/1xYAaAc6gLf0lElGXxbUw3WRSCkk7q38WN9bLh/7eVK+4o6sbSgMF1e8UTERI5uC5KMv6yjsKT+RXvwaj8+s= 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 1607477901997258.735782073535; Tue, 8 Dec 2020 17:38: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-457-zTJXumyzOviEomGqlcjfag-1; Tue, 08 Dec 2020 20:38:18 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4DA845210; Wed, 9 Dec 2020 01:38:12 +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 2A9AE13470; Wed, 9 Dec 2020 01:38:12 +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 B29F71809CA1; Wed, 9 Dec 2020 01:38:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0B91bpoM007388 for ; Tue, 8 Dec 2020 20:37:51 -0500 Received: by smtp.corp.redhat.com (Postfix) id A39805D6D5; Wed, 9 Dec 2020 01:37:51 +0000 (UTC) Received: from vhost2.laine.org (ovpn-112-50.phx2.redhat.com [10.3.112.50]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6AB145D6AB for ; Wed, 9 Dec 2020 01:37:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607477901; 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=NuMdpFC/V+Dyw8ez/m/KfYOwUD2pbure1i7s3wnXcOw=; b=TK0OBMjM3Kssb8zL9N/sDpqaje7pd7MQpck4YsJ9fDVL3QPgHXE4RBTh66U7BXTacfg2qk axEcKtRguVzlNQ7N5G2pg0aMhei9q/dVDzmWUnklawGJ0/gOvS+zKv2ef4ipmspvkJ3Dkn EwDLF1dKUhtUsf7nPUMLDZle5W+jfXY= X-MC-Unique: zTJXumyzOviEomGqlcjfag-1 From: Laine Stump To: libvir-list@redhat.com Subject: [PATCH 2/7] util: simplify calling of virPCIDeviceDetectFunctionLevelReset() Date: Tue, 8 Dec 2020 20:37:40 -0500 Message-Id: <20201209013745.599662-3-laine@redhat.com> In-Reply-To: <20201209013745.599662-1-laine@redhat.com> References: <20201209013745.599662-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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.11 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" This function returned an int, and that int was being checked for < 0 in its solitary caller, but within the function it would only ever return 0 or 1. Change the function itself to return a bool, and the caller to just directly set the flag in the virPCIDevice. Signed-off-by: Laine Stump Reviewed-by: Michal Privoznik --- src/util/virpci.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/util/virpci.c b/src/util/virpci.c index b63abac8cc..403ef1ec8e 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -549,7 +549,7 @@ virPCIDeviceFindExtendedCapabilityOffset(virPCIDevicePt= r dev, /* detects whether this device has FLR. Returns 0 if the device does * not have FLR, 1 if it does, and -1 on error */ -static int +static bool virPCIDeviceDetectFunctionLevelReset(virPCIDevicePtr dev, int cfgfd) { uint32_t caps; @@ -567,7 +567,7 @@ virPCIDeviceDetectFunctionLevelReset(virPCIDevicePtr de= v, int cfgfd) caps =3D virPCIDeviceRead32(dev, cfgfd, dev->pcie_cap_pos + PCI_EX= P_DEVCAP); if (caps & PCI_EXP_DEVCAP_FLR) { VIR_DEBUG("%s %s: detected PCIe FLR capability", dev->id, dev-= >name); - return 1; + return true; } } =20 @@ -580,7 +580,7 @@ virPCIDeviceDetectFunctionLevelReset(virPCIDevicePtr de= v, int cfgfd) caps =3D virPCIDeviceRead16(dev, cfgfd, pos + PCI_AF_CAP); if (caps & PCI_AF_CAP_FLR) { VIR_DEBUG("%s %s: detected PCI FLR capability", dev->id, dev->= name); - return 1; + return true; } } =20 @@ -596,12 +596,12 @@ virPCIDeviceDetectFunctionLevelReset(virPCIDevicePtr = dev, int cfgfd) if (found) { VIR_DEBUG("%s %s: buggy device didn't advertise FLR, but is a VF; = forcing flr on", dev->id, dev->name); - return 1; + return true; } =20 VIR_DEBUG("%s %s: no FLR capability found", dev->id, dev->name); =20 - return 0; + return false; } =20 /* Require the device has the PCI Power Management capability @@ -885,15 +885,10 @@ virPCIDeviceTryPowerManagementReset(virPCIDevicePtr d= ev, int cfgfd) static int virPCIDeviceInit(virPCIDevicePtr dev, int cfgfd) { - int flr; - dev->pcie_cap_pos =3D virPCIDeviceFindCapabilityOffset(dev, cfgfd, P= CI_CAP_ID_EXP); dev->pci_pm_cap_pos =3D virPCIDeviceFindCapabilityOffset(dev, cfgfd, P= CI_CAP_ID_PM); - flr =3D virPCIDeviceDetectFunctionLevelReset(dev, cfgfd); - if (flr < 0) - return flr; - dev->has_flr =3D !!flr; - dev->has_pm_reset =3D !!virPCIDeviceDetectPowerManagementReset(dev, = cfgfd); + dev->has_flr =3D virPCIDeviceDetectFunctionLevelReset(dev, cfgfd); + dev->has_pm_reset =3D !!virPCIDeviceDetectPowerManagementReset(dev, cf= gfd); =20 return 0; } --=20 2.28.0 From nobody Fri May 17 20:54:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1607477885; cv=none; d=zohomail.com; s=zohoarc; b=CDvnrglsZVtKlD0x4a86mn9mHTgnC+H0uNrQWTY6D29H9RAGmNeRvrCXcqQSHcFdhaNq6uHQGeijxm1x1uIrTr5hhINabAVObPP9JLPF4VuNHyPrfazb3eZ5wtmKxih9hyf88Yotx1W5X8PbHYa7WsN+evl3joPyr6Wl5fHHYNY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1607477885; 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=SwLpD5NqkdXY1AYIKGCuq8JUTymUN7TIYykMLAnFkmY=; b=gPBrhdF/uppE0beYWGn0Ok/4QFyCmBwFO9he7XZ1hMLegj2wfD3DWu+NsmG286TlJloBjqyjKOn6asvn4fEvPLr/9sIsSGPltjpAWvrVQBByJqmM/uqlZGIr7MTOJ8GkRKj+Lhh1jeQ0PBULYU+pZKRTEocz89Bb2rJbZnjd1Lk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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 [63.128.21.124]) by mx.zohomail.com with SMTPS id 1607477885504849.6168709997629; Tue, 8 Dec 2020 17:38:05 -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-438-5RKnfIvxPjad_ifICm51Vg-1; Tue, 08 Dec 2020 20:38:02 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E399618C89CF; Wed, 9 Dec 2020 01:37:56 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9476B19C78; Wed, 9 Dec 2020 01:37:55 +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 DD4524A7C6; Wed, 9 Dec 2020 01:37:52 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0B91bqHH007397 for ; Tue, 8 Dec 2020 20:37:52 -0500 Received: by smtp.corp.redhat.com (Postfix) id 093E25D6D5; Wed, 9 Dec 2020 01:37:52 +0000 (UTC) Received: from vhost2.laine.org (ovpn-112-50.phx2.redhat.com [10.3.112.50]) by smtp.corp.redhat.com (Postfix) with ESMTP id C53855D6AB for ; Wed, 9 Dec 2020 01:37:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607477884; 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=SwLpD5NqkdXY1AYIKGCuq8JUTymUN7TIYykMLAnFkmY=; b=AYBV9SB6z2+pyuUWoi7098+pgjB7aX4EntRArpsAwcnEWInIG189sHCVBb8Gp892c7XhzD MH/Z6bOC6KGmYfdYht9WjPDVQN349Tq3ACBP7+hPMmaftvXexx7MG5is1KZCaZdoADM77d t4KR+M8wnSlLv42x0AmiMAdkLX69LZc= X-MC-Unique: 5RKnfIvxPjad_ifICm51Vg-1 From: Laine Stump To: libvir-list@redhat.com Subject: [PATCH 3/7] util: simplify call to virPCIDeviceDetectPowerManagementReset() Date: Tue, 8 Dec 2020 20:37:41 -0500 Message-Id: <20201209013745.599662-4-laine@redhat.com> In-Reply-To: <20201209013745.599662-1-laine@redhat.com> References: <20201209013745.599662-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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.84 on 10.5.11.23 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" This function returned an int, but would only return 0 or 1, and the one place it was called would just use !! to convert that value to a bool. Change the function to directly return bool instead. Signed-off-by: Laine Stump Reviewed-by: Michal Privoznik --- src/util/virpci.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/util/virpci.c b/src/util/virpci.c index 403ef1ec8e..31622cddfa 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -608,7 +608,7 @@ virPCIDeviceDetectFunctionLevelReset(virPCIDevicePtr de= v, int cfgfd) * and that a D3hot->D0 transition will results in a full * internal reset, not just a soft reset. */ -static unsigned int +static bool virPCIDeviceDetectPowerManagementReset(virPCIDevicePtr dev, int cfgfd) { if (dev->pci_pm_cap_pos) { @@ -618,13 +618,13 @@ virPCIDeviceDetectPowerManagementReset(virPCIDevicePt= r dev, int cfgfd) ctl =3D virPCIDeviceRead32(dev, cfgfd, dev->pci_pm_cap_pos + PCI_P= M_CTRL); if (!(ctl & PCI_PM_CTRL_NO_SOFT_RESET)) { VIR_DEBUG("%s %s: detected PM reset capability", dev->id, dev-= >name); - return 1; + return true; } } =20 VIR_DEBUG("%s %s: no PM reset capability found", dev->id, dev->name); =20 - return 0; + return false; } =20 /* Any active devices on the same domain/bus ? */ @@ -888,7 +888,7 @@ virPCIDeviceInit(virPCIDevicePtr dev, int cfgfd) dev->pcie_cap_pos =3D virPCIDeviceFindCapabilityOffset(dev, cfgfd, P= CI_CAP_ID_EXP); dev->pci_pm_cap_pos =3D virPCIDeviceFindCapabilityOffset(dev, cfgfd, P= CI_CAP_ID_PM); dev->has_flr =3D virPCIDeviceDetectFunctionLevelReset(dev, cfgfd); - dev->has_pm_reset =3D !!virPCIDeviceDetectPowerManagementReset(dev, cf= gfd); + dev->has_pm_reset =3D virPCIDeviceDetectPowerManagementReset(dev, cfgf= d); =20 return 0; } --=20 2.28.0 From nobody Fri May 17 20:54:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1607477946; cv=none; d=zohomail.com; s=zohoarc; b=MFR2CRGobgMgHvaDwu98AkSwyKWbTVvxuE6wCNaF2G5to5/5FSaNORGgdCHJbqrGnnHggI2lcbeoas/XDGabnfRmF/otRsTUZdWx5SPvu1ksqhXx4atf8gZZeqVkd0xDZ8kZQ/oMROwr40L3fIoMA66RStUnOlflPcDrXzAGBe0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1607477946; 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=5AhflgcYQu+9DEDf6zs09rHMAGztyaqr6nmsj/zWToM=; b=DCx1U4BIxn+AvNB2TArOw5/Mhv2k0oEPLoGo3xBeil1pX9Sc0KVhA2CdMA/SF0Ig7jMgtGXV/i+IOY0xJLzra7YxqvwYXQbQLrtq4MnQw6uEpy8+4GVK4DeRuxyGKn3h9MXzLcM6pSAZ2/+dEkUaBblM5112sXkQoILs7Nkd5Ts= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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 [63.128.21.124]) by mx.zohomail.com with SMTPS id 160747794656097.08443722754714; Tue, 8 Dec 2020 17:39:06 -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-207-dXcaqaaRMKOPQ-UvZysiww-1; Tue, 08 Dec 2020 20:38:24 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D8A2918C89DD; Wed, 9 Dec 2020 01:38:14 +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 B3DB75D6D5; Wed, 9 Dec 2020 01:38:14 +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 8173F1809CA4; Wed, 9 Dec 2020 01:38:14 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0B91bqa7007406 for ; Tue, 8 Dec 2020 20:37:52 -0500 Received: by smtp.corp.redhat.com (Postfix) id 62E1A5D6D5; Wed, 9 Dec 2020 01:37:52 +0000 (UTC) Received: from vhost2.laine.org (ovpn-112-50.phx2.redhat.com [10.3.112.50]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2AFFB5D6AB for ; Wed, 9 Dec 2020 01:37:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607477945; 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=5AhflgcYQu+9DEDf6zs09rHMAGztyaqr6nmsj/zWToM=; b=dtIdOIXrBFs1btFSOTBAoOTaVhG9Blsip5KNexuzCyhLThTl+LgYlY/JtCa4OAWpfhRHD6 4kagojB7XZsYhL2znUU8BfA5prrknHMfy7V/HWspKizjpEQwGMh9eBB+0hJ2aBjXjt58zB 2b+AAaPaMei5yylbqY10DH91uq/Mmto= X-MC-Unique: dXcaqaaRMKOPQ-UvZysiww-1 From: Laine Stump To: libvir-list@redhat.com Subject: [PATCH 4/7] util: make read error of PCI config file more detailed Date: Tue, 8 Dec 2020 20:37:42 -0500 Message-Id: <20201209013745.599662-5-laine@redhat.com> In-Reply-To: <20201209013745.599662-1-laine@redhat.com> References: <20201209013745.599662-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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.15 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" The new message is more verbose/useful, but only logged at debug level instead of as a warning (since it could easily happen in a non-error situation). Signed-off-by: Laine Stump Reviewed-by: Michal Privoznik --- src/util/virpci.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/util/virpci.c b/src/util/virpci.c index 31622cddfa..9109fb4f3a 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -332,8 +332,8 @@ virPCIDeviceRead(virPCIDevicePtr dev, =20 if (lseek(cfgfd, pos, SEEK_SET) !=3D pos || saferead(cfgfd, buf, buflen) !=3D buflen) { - VIR_WARN("Failed to read from '%s' : %s", dev->path, - g_strerror(errno)); + VIR_DEBUG("Failed to read %u bytes at %u from '%s' : %s", + buflen, pos, dev->path, g_strerror(errno)); return -1; } return 0; --=20 2.28.0 From nobody Fri May 17 20:54:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1607477908; cv=none; d=zohomail.com; s=zohoarc; b=YXoqOG3cKoX7yvhlnUJEAnBGHW97DYaSnZrK8pF44rgdK/uYwWvSgNUD6UGKnuHzfc+oBz7mDJodhynLu3FfzlsXZ9F90qFGF+UhOpZHVwpCmwOuv7D0QqO/myN3KxYtoRChf4P8b4k8KUToCzGFnZ6gOOEqJGXnqjZ8B82wpBI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1607477908; 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=7dId7oKEYiTVx3iRtXwNN7DHcv5blot4PZtIpbnFhYc=; b=XL1VXU9g2d3N/qHWWZj0AKdpg41ZlrjpuE2bMqhHhX5bjTG+4yh9yec8KJAtQTA1KvTEUFYlUJFN8ictuAvjGsyva2FNZO2kvzSvYF+VRHCqexsWQuWrffkLuEREn+nKVgqlpuHnoHVLtqKeOH/khS6nx2g9iumvhCrb7qu0LS8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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 [63.128.21.124]) by mx.zohomail.com with SMTPS id 1607477908991152.8015580012759; Tue, 8 Dec 2020 17:38:28 -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-566-0Z6vxLjIOjSiFojC0MSXBA-1; Tue, 08 Dec 2020 20:38:23 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 976B818C89DF; Wed, 9 Dec 2020 01:38:17 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 73FF55D71D; Wed, 9 Dec 2020 01:38:17 +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 3C51C5002E; Wed, 9 Dec 2020 01:38:17 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0B91bqIg007411 for ; Tue, 8 Dec 2020 20:37:52 -0500 Received: by smtp.corp.redhat.com (Postfix) id BD9E35D6D5; Wed, 9 Dec 2020 01:37:52 +0000 (UTC) Received: from vhost2.laine.org (ovpn-112-50.phx2.redhat.com [10.3.112.50]) by smtp.corp.redhat.com (Postfix) with ESMTP id 85CDD5D6AB for ; Wed, 9 Dec 2020 01:37:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607477905; 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=7dId7oKEYiTVx3iRtXwNN7DHcv5blot4PZtIpbnFhYc=; b=VfObW/xnO8FMH2rmkrD7P5Fp73ldo2hO965iz/LcxU7XUXl6ce5mnR5Oqk0oYhxqzcOJWE Y/Obi2JjdD2YObwfi+wVhlhD0zXVnBcZ3vJGSLwLEjvLGoQfhDol2D0m+MeEFQwRPmWW2T QzMebe0xFt0TI8eUu4FlI6JnzBFICdo= X-MC-Unique: 0Z6vxLjIOjSiFojC0MSXBA-1 From: Laine Stump To: libvir-list@redhat.com Subject: [PATCH 5/7] util: change call sequence for virPCIDeviceFindCapabilityOffset() Date: Tue, 8 Dec 2020 20:37:43 -0500 Message-Id: <20201209013745.599662-6-laine@redhat.com> In-Reply-To: <20201209013745.599662-1-laine@redhat.com> References: <20201209013745.599662-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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.15 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" Previously there was no way to differentiate between this function 1) encountering an error while reading the pci config, and 2) determining that the device in question is a conventional PCI device, and so has no Express Capabilities. The difference between these two conditions is important, because an unprivileged libvirtd will be unable to read all of the pci config (it can only read the first 64 bytes, and will get ENOENT when it tries to seek past that limit) even though the device is in fact a PCIe device. This patch just changes virPCIDeviceFindCapabilityOffset() to put the determined offset into an argument of the function (rather than sending it back as the return value), and to return the standard "0 on success, -1 on failure". Failure is determined by checking the value of errno after each attemptd read of the config file (which can only work reliably if errno is reset to 0 before each read, and after virPCIDeviceFindCapabilityOffset() has finished examining it). (NB: if the config file is read successfully, but no Express Capabilities are found, then the function returns success, but the returned offset will be 0 (which is an impossible offset for Express Capabilities, and so easily recognizeable). An upcoming patch will take advantage of the change made here. Signed-off-by: Laine Stump Reviewed-by: Michal Privoznik --- src/util/virpci.c | 42 +++++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/src/util/virpci.c b/src/util/virpci.c index 9109fb4f3a..2f99bb93bd 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -329,6 +329,7 @@ virPCIDeviceRead(virPCIDevicePtr dev, unsigned int buflen) { memset(buf, 0, buflen); + errno =3D 0; =20 if (lseek(cfgfd, pos, SEEK_SET) !=3D pos || saferead(cfgfd, buf, buflen) !=3D buflen) { @@ -483,19 +484,24 @@ virPCIDeviceIterDevices(virPCIDeviceIterPredicate pre= dicate, return ret; } =20 -static uint8_t +static int virPCIDeviceFindCapabilityOffset(virPCIDevicePtr dev, int cfgfd, - unsigned int capability) + unsigned int capability, + unsigned int *offset) { uint16_t status; uint8_t pos; =20 + *offset =3D 0; /* assume failure (*nothing* can be at offset 0) */ + status =3D virPCIDeviceRead16(dev, cfgfd, PCI_STATUS); - if (!(status & PCI_STATUS_CAP_LIST)) - return 0; + if (errno !=3D 0 || !(status & PCI_STATUS_CAP_LIST)) + goto error; =20 pos =3D virPCIDeviceRead8(dev, cfgfd, PCI_CAPABILITY_LIST); + if (errno !=3D 0) + goto error; =20 /* Zero indicates last capability, capabilities can't * be in the config space header and 0xff is returned @@ -506,18 +512,31 @@ virPCIDeviceFindCapabilityOffset(virPCIDevicePtr dev, */ while (pos >=3D PCI_CONF_HEADER_LEN && pos !=3D 0xff) { uint8_t capid =3D virPCIDeviceRead8(dev, cfgfd, pos); + if (errno !=3D 0) + goto error; + if (capid =3D=3D capability) { VIR_DEBUG("%s %s: found cap 0x%.2x at 0x%.2x", dev->id, dev->name, capability, pos); - return pos; + *offset =3D pos; + return 0; } =20 pos =3D virPCIDeviceRead8(dev, cfgfd, pos + 1); + if (errno !=3D 0) + goto error; } =20 - VIR_DEBUG("%s %s: failed to find cap 0x%.2x", dev->id, dev->name, capa= bility); + error: + VIR_DEBUG("%s %s: failed to find cap 0x%.2x (%s)", + dev->id, dev->name, capability, g_strerror(errno)); =20 - return 0; + /* reset errno in case the failure was due to insufficient + * privileges to read the entire PCI config file + */ + errno =3D 0; + + return -1; } =20 static unsigned int @@ -553,7 +572,7 @@ static bool virPCIDeviceDetectFunctionLevelReset(virPCIDevicePtr dev, int cfgfd) { uint32_t caps; - uint8_t pos; + unsigned int pos; g_autofree char *path =3D NULL; int found; =20 @@ -575,7 +594,8 @@ virPCIDeviceDetectFunctionLevelReset(virPCIDevicePtr de= v, int cfgfd) * the same thing, except for conventional PCI * devices. This is not common yet. */ - pos =3D virPCIDeviceFindCapabilityOffset(dev, cfgfd, PCI_CAP_ID_AF); + virPCIDeviceFindCapabilityOffset(dev, cfgfd, PCI_CAP_ID_AF, &pos); + if (pos) { caps =3D virPCIDeviceRead16(dev, cfgfd, pos + PCI_AF_CAP); if (caps & PCI_AF_CAP_FLR) { @@ -885,8 +905,8 @@ virPCIDeviceTryPowerManagementReset(virPCIDevicePtr dev= , int cfgfd) static int virPCIDeviceInit(virPCIDevicePtr dev, int cfgfd) { - dev->pcie_cap_pos =3D virPCIDeviceFindCapabilityOffset(dev, cfgfd, P= CI_CAP_ID_EXP); - dev->pci_pm_cap_pos =3D virPCIDeviceFindCapabilityOffset(dev, cfgfd, P= CI_CAP_ID_PM); + virPCIDeviceFindCapabilityOffset(dev, cfgfd, PCI_CAP_ID_EXP, &dev->pci= e_cap_pos); + virPCIDeviceFindCapabilityOffset(dev, cfgfd, PCI_CAP_ID_PM, &dev->pci_= pm_cap_pos); dev->has_flr =3D virPCIDeviceDetectFunctionLevelReset(dev, cfgfd); dev->has_pm_reset =3D virPCIDeviceDetectPowerManagementReset(dev, cfgf= d); =20 --=20 2.28.0 From nobody Fri May 17 20:54:19 2024 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=1607477909; cv=none; d=zohomail.com; s=zohoarc; b=eUpIcUJ99S3CLGryq+MNXhnPXYxqLxjyagfFS8UiDNuxaHc3I4aW1AlC3qScb2om89hFfmLFTfKup77aLvcILOqxO9momqP//VzQXiMbBPqtKUK+elYfeUVhPiFa79SXOEtfBRlQ3zlVwAhKdPRZudsnkYRBeLbB2V6SBTF3AH8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1607477909; 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=MPkU6PElZqAUS2Rp2utfe3u0xUV0JUZsDCaw6D4Ls2I=; b=D8gJ7uKRiWAOl1tWB0UbIvMQE1OMgMt4MnOQRzBpOJdoL/4xB63L83c0hYMT/sjfenAcCztiPnPkloy0qi1W7wiIbK7cu0Cfq8Zl9inmuiOJUC2VOLwA44Hf6c54gUZWcQXlg/Q/oCRWu4UO4hnUPFq8LmQk1btQ5zhuAP0P5IM= 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 1607477909317468.2336723884962; Tue, 8 Dec 2020 17:38:29 -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-397-QTLVwPWgM6qIhrTZhdGKBA-1; Tue, 08 Dec 2020 20:38:25 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4055C8030AD; Wed, 9 Dec 2020 01:38:20 +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 1DA6E60BF1; Wed, 9 Dec 2020 01:38:20 +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 DB4851809CA4; Wed, 9 Dec 2020 01:38:19 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0B91br39007416 for ; Tue, 8 Dec 2020 20:37:53 -0500 Received: by smtp.corp.redhat.com (Postfix) id 23E3B5D6D5; Wed, 9 Dec 2020 01:37:53 +0000 (UTC) Received: from vhost2.laine.org (ovpn-112-50.phx2.redhat.com [10.3.112.50]) by smtp.corp.redhat.com (Postfix) with ESMTP id E153A5D6AB for ; Wed, 9 Dec 2020 01:37:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607477908; 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=MPkU6PElZqAUS2Rp2utfe3u0xUV0JUZsDCaw6D4Ls2I=; b=Ng3k93H0rLNjpM7kwouxl8WtRAYavoWvLhiC2SeDUw6/gM2Mpu4nG/iVOYv98GgoISlCNW jzE4zeYAuE3Ve8p7jpLJHTn29EZUX0thjdLyBo2X9YnSax34CmjjVGAxPrtoFhG0EcHIKU kW1+4v3i38zJgjFDMPjxphUl97shhTA= X-MC-Unique: QTLVwPWgM6qIhrTZhdGKBA-1 From: Laine Stump To: libvir-list@redhat.com Subject: [PATCH 6/7] util: make virPCIDeviceIsPCIExpress() more intelligent Date: Tue, 8 Dec 2020 20:37:44 -0500 Message-Id: <20201209013745.599662-7-laine@redhat.com> In-Reply-To: <20201209013745.599662-1-laine@redhat.com> References: <20201209013745.599662-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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.12 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" Until now there has been an extra bit of code in qemuDomainDeviceCalculatePCIConnectFlag() (one of the two callers of virPCIDeviceIsPCIExpress()) that tries to determine if a device is PCIe by looking at the *length* of its sysfs config file; it only does this when libvirt is running as a non-root process. This patch takes advantage of our newfound ability to tell the difference between "I read a 0 from the device PCI config file" and "I couldn't read the PCI Express Capabilities because I don't have sufficient permission" to move the file length check down into virPCIDeviceIsPCIExpress(), and do that check any time we fail while reading the config file (not only when the process is non-root). Fixes: https://bugzilla.redhat.com/1901685 Signed-off-by: Laine Stump Reviewed-by: Michal Privoznik --- src/util/virpci.c | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/src/util/virpci.c b/src/util/virpci.c index 2f99bb93bd..01a156dfcf 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -73,10 +73,18 @@ struct _virPCIDevice { char *used_by_drvname; char *used_by_domname; =20 + /* The following 5 items are only valid after virPCIDeviceInit() + * has been called for the virPCIDevice object. This is *not* done + * in most cases (because it creates extra overhead, and parts of + * it can fail if libvirtd is running unprivileged) + */ unsigned int pcie_cap_pos; unsigned int pci_pm_cap_pos; bool has_flr; bool has_pm_reset; + bool is_pcie; + /**/ + bool managed; =20 virPCIStubDriver stubDriver; @@ -594,7 +602,8 @@ virPCIDeviceDetectFunctionLevelReset(virPCIDevicePtr de= v, int cfgfd) * the same thing, except for conventional PCI * devices. This is not common yet. */ - virPCIDeviceFindCapabilityOffset(dev, cfgfd, PCI_CAP_ID_AF, &pos); + if (virPCIDeviceFindCapabilityOffset(dev, cfgfd, PCI_CAP_ID_AF, &pos) = < 0) + goto error; =20 if (pos) { caps =3D virPCIDeviceRead16(dev, cfgfd, pos + PCI_AF_CAP); @@ -619,8 +628,8 @@ virPCIDeviceDetectFunctionLevelReset(virPCIDevicePtr de= v, int cfgfd) return true; } =20 + error: VIR_DEBUG("%s %s: no FLR capability found", dev->id, dev->name); - return false; } =20 @@ -905,7 +914,32 @@ virPCIDeviceTryPowerManagementReset(virPCIDevicePtr de= v, int cfgfd) static int virPCIDeviceInit(virPCIDevicePtr dev, int cfgfd) { - virPCIDeviceFindCapabilityOffset(dev, cfgfd, PCI_CAP_ID_EXP, &dev->pci= e_cap_pos); + dev->is_pcie =3D false; + if (virPCIDeviceFindCapabilityOffset(dev, cfgfd, PCI_CAP_ID_EXP, &dev-= >pcie_cap_pos) < 0) { + /* an unprivileged process is unable to read *all* of a + * device's PCI config (it can only read the first 64 + * bytes, which isn't enough for see the Express + * Capabilities data). If virPCIDeviceFindCapabilityOffset + * returns failure (and not just a pcie_cap_pos =3D=3D 0, + * which is *success* at determining the device is *not* + * PCIe) 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(dev), = -1); + + if (configLen !=3D 256) + dev->is_pcie =3D true; + + } else { + dev->is_pcie =3D (dev->pcie_cap_pos !=3D 0); + } + virPCIDeviceFindCapabilityOffset(dev, cfgfd, PCI_CAP_ID_PM, &dev->pci_= pm_cap_pos); dev->has_flr =3D virPCIDeviceDetectFunctionLevelReset(dev, cfgfd); dev->has_pm_reset =3D virPCIDeviceDetectPowerManagementReset(dev, cfgf= d); @@ -2609,7 +2643,7 @@ virPCIDeviceIsPCIExpress(virPCIDevicePtr dev) if (virPCIDeviceInit(dev, fd) < 0) goto cleanup; =20 - ret =3D dev->pcie_cap_pos !=3D 0; + ret =3D dev->is_pcie; =20 cleanup: virPCIDeviceConfigClose(dev, fd); --=20 2.28.0 From nobody Fri May 17 20:54:19 2024 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=1607477903; cv=none; d=zohomail.com; s=zohoarc; b=Xnhzmi/Jf+OH/L5xz0iKLmbyUvrUMyCt63O7I4sjFJFp6fVpq/qQVhFZt7CkiR23BL7GE8u9cZBNK3Kuzhor2TP3aU8Rs38tSILrCa0Z7qqbnGhGhBallsGZzGJlwbg54KQdeLQfEsEhX9mDQ9N3IG3ZNR9N3LrfdCjM0cKFLSA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1607477903; 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=KcjZKC6b9yq3x/zHLRkFcAMshQhN52eSTVnpBKLqh+DMhFoxn3qMb0id/jQRaPMZesyTQjM5E9y7oMf3vUgZjt9ACgw0vUR/2hbuvKDLOiQ0LACoZEe6gHUrR1oxK93A9kh09ulzuFucNaSZ/7pKMqhW8Tz3tW0EnQRXpNpcgOY= 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 1607477903650638.0056637076426; Tue, 8 Dec 2020 17:38:23 -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-411-cibLboYbN-q3wOsL-4xG9g-1; Tue, 08 Dec 2020 20:38:19 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5C9D0107ACE6; Wed, 9 Dec 2020 01:38:13 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 379791002D43; Wed, 9 Dec 2020 01:38:13 +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 01DAC4EEF6; Wed, 9 Dec 2020 01:38:13 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0B91brjs007426 for ; Tue, 8 Dec 2020 20:37:53 -0500 Received: by smtp.corp.redhat.com (Postfix) id 7EDAD5D6D5; Wed, 9 Dec 2020 01:37:53 +0000 (UTC) Received: from vhost2.laine.org (ovpn-112-50.phx2.redhat.com [10.3.112.50]) by smtp.corp.redhat.com (Postfix) with ESMTP id 46BBA5D6AB for ; Wed, 9 Dec 2020 01:37:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607477902; 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=RjNwU3v1FwxrW/6R9LmTqbzNA3iBoFINWm/7MkpoSx09WnUm+UUukxZ5mvVaLNO1CR5FSq OhHd9bXrs0ba9FzWFR9D9bixfNrsesVMtoFprdvmahnSgyJgKXbzy7NnYt7zPHGGNCL6QR lQPJaRcGfZnGAV9oV8JexSw2T+qrZsA= X-MC-Unique: cibLboYbN-q3wOsL-4xG9g-1 From: Laine Stump To: libvir-list@redhat.com Subject: [PATCH 7/7] qemu: remove now-redundant check for file length when determining PCIe vs. PCI Date: Tue, 8 Dec 2020 20:37:45 -0500 Message-Id: <20201209013745.599662-8-laine@redhat.com> In-Reply-To: <20201209013745.599662-1-laine@redhat.com> References: <20201209013745.599662-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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.84 on 10.5.11.22 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 Reviewed-by: Michal Privoznik --- 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