From nobody Fri Apr 19 23:26:51 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1498695975370386.58547137633275; Wed, 28 Jun 2017 17:26:15 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id B27A47D0E8; Thu, 29 Jun 2017 00:26:11 +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 0EF46182F2; Thu, 29 Jun 2017 00:26:11 +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 616A6184383E; Thu, 29 Jun 2017 00:26:07 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v5T0Q5aD008893 for ; Wed, 28 Jun 2017 20:26:05 -0400 Received: by smtp.corp.redhat.com (Postfix) id 065E460467; Thu, 29 Jun 2017 00:26:05 +0000 (UTC) Received: from mx1.redhat.com (ext-mx01.extmail.prod.ext.phx2.redhat.com [10.5.110.25]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F403160462 for ; Thu, 29 Jun 2017 00:26:03 +0000 (UTC) Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 44F0481226 for ; Thu, 29 Jun 2017 00:26:02 +0000 (UTC) Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v5T0NiOk110586 for ; Wed, 28 Jun 2017 20:26:02 -0400 Received: from e14.ny.us.ibm.com (e14.ny.us.ibm.com [129.33.205.204]) by mx0a-001b2d01.pphosted.com with ESMTP id 2bcpgks073-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 28 Jun 2017 20:26:01 -0400 Received: from localhost by e14.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 28 Jun 2017 20:26:00 -0400 Received: from b01cxnp22033.gho.pok.ibm.com (9.57.198.23) by e14.ny.us.ibm.com (146.89.104.201) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 28 Jun 2017 20:25:56 -0400 Received: from b01ledav005.gho.pok.ibm.com (b01ledav005.gho.pok.ibm.com [9.57.199.110]) by b01cxnp22033.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v5T0PtVS51576884; Thu, 29 Jun 2017 00:25:55 GMT Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 472C1AE034; Wed, 28 Jun 2017 20:25:58 -0400 (EDT) Received: from localhost (unknown [9.80.98.208]) by b01ledav005.gho.pok.ibm.com (Postfix) with ESMTP id F2E56AE03B; Wed, 28 Jun 2017 20:25:57 -0400 (EDT) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B27A47D0E8 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com B27A47D0E8 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 44F0481226 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=none smtp.mailfrom=mdroth@linux.vnet.ibm.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 44F0481226 From: Michael Roth To: libvir-list@redhat.com Date: Wed, 28 Jun 2017 19:24:56 -0500 In-Reply-To: <1498695900-1648-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1498695900-1648-1-git-send-email-mdroth@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17062900-0052-0000-0000-0000023149E8 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00007292; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000214; SDB=6.00880136; UDB=6.00438730; IPR=6.00660291; BA=6.00005445; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00015996; XFM=3.00000015; UTC=2017-06-29 00:25:59 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17062900-0053-0000-0000-000051238EA2 Message-Id: <1498695900-1648-2-git-send-email-mdroth@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-06-28_15:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1706290006 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 203 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 29 Jun 2017 00:26:02 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 29 Jun 2017 00:26:02 +0000 (UTC) for IP:'148.163.156.1' DOMAIN:'mx0a-001b2d01.pphosted.com' HELO:'mx0a-001b2d01.pphosted.com' FROM:'mdroth@linux.vnet.ibm.com' RCPT:'' X-RedHat-Spam-Score: 0.08 (BAYES_50, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL) 148.163.156.1 mx0a-001b2d01.pphosted.com 148.163.156.1 mx0a-001b2d01.pphosted.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.25 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: pkrempa@redhat.com, aik@ozlabs.ru, mprivozn@redhat.com, qemu-devel@nongnu.org, abologna@redhat.com, qemu-ppc@nongnu.org, laine@laine.org Subject: [libvirt] [RFC PATCH 1/5] virhostdev: factor release out from reattach and export it for use later 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 29 Jun 2017 00:26:12 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Michael Roth --- src/libvirt_private.syms | 1 + src/util/virhostdev.c | 83 ++++++++++++++++++++++++++++++++++++++++----= ---- src/util/virhostdev.h | 8 +++++ 3 files changed, 78 insertions(+), 14 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index c1e9471..2bd3581 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1798,6 +1798,7 @@ virHostdevReAttachPCIDevices; virHostdevReAttachSCSIDevices; virHostdevReAttachSCSIVHostDevices; virHostdevReAttachUSBDevices; +virHostdevReleasePCIDevices; virHostdevUpdateActiveDomainDevices; virHostdevUpdateActiveMediatedDevices; virHostdevUpdateActivePCIDevices; diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c index 579563c..2cd3f34 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -932,16 +932,20 @@ virHostdevReattachPCIDevice(virHostdevManagerPtr mgr, } } =20 -/* @oldStateDir: - * For upgrade purpose: see virHostdevRestoreNetConfig +/* + * Move PCI devices to inactive list and prepare them for reattaching + * to host driver + * + * Pre-condition: inactivePCIHostdevs & activePCIHostdevs + * are locked */ -void -virHostdevReAttachPCIDevices(virHostdevManagerPtr mgr, - const char *drv_name, - const char *dom_name, - virDomainHostdevDefPtr *hostdevs, - int nhostdevs, - const char *oldStateDir) +static void +virHostdevReleasePCIDevicesInternal(virHostdevManagerPtr mgr, + const char *drv_name, + const char *dom_name, + virDomainHostdevDefPtr *hostdevs, + int nhostdevs, + const char *oldStateDir) { virPCIDeviceListPtr pcidevs; size_t i; @@ -949,9 +953,6 @@ virHostdevReAttachPCIDevices(virHostdevManagerPtr mgr, if (!nhostdevs) return; =20 - virObjectLock(mgr->activePCIHostdevs); - virObjectLock(mgr->inactivePCIHostdevs); - if (!(pcidevs =3D virHostdevGetPCIHostDeviceList(hostdevs, nhostdevs))= ) { VIR_ERROR(_("Failed to allocate PCI device list: %s"), virGetLastErrorMessage()); @@ -1056,8 +1057,62 @@ virHostdevReAttachPCIDevices(virHostdevManagerPtr mg= r, } } =20 - /* Step 5: Reattach managed devices to their host drivers; unmanaged - * devices don't need to be processed further */ + cleanup: + virObjectUnref(pcidevs); +} + +void +virHostdevReleasePCIDevices(virHostdevManagerPtr mgr, + const char *drv_name, + const char *dom_name, + virDomainHostdevDefPtr *hostdevs, + int nhostdevs, + const char *oldStateDir) +{ + virObjectLock(mgr->activePCIHostdevs); + virObjectLock(mgr->inactivePCIHostdevs); + + + virHostdevReleasePCIDevicesInternal(mgr, drv_name, dom_name, + hostdevs, nhostdevs, oldStateDir); + + virObjectUnlock(mgr->activePCIHostdevs); + virObjectUnlock(mgr->inactivePCIHostdevs); +} + +/* @oldStateDir: + * For upgrade purpose: see virHostdevRestoreNetConfig + */ +void +virHostdevReAttachPCIDevices(virHostdevManagerPtr mgr, + const char *drv_name, + const char *dom_name, + virDomainHostdevDefPtr *hostdevs, + int nhostdevs, + const char *oldStateDir) +{ + virPCIDeviceListPtr pcidevs; + size_t i; + + if (!nhostdevs) + return; + + virObjectLock(mgr->activePCIHostdevs); + virObjectLock(mgr->inactivePCIHostdevs); + + /* Release PCI devices to the inactive list */ + virHostdevReleasePCIDevicesInternal(mgr, drv_name, dom_name, + hostdevs, nhostdevs, oldStateDir); + + if (!(pcidevs =3D virHostdevGetPCIHostDeviceList(hostdevs, nhostdevs))= ) { + VIR_ERROR(_("Failed to allocate PCI device list: %s"), + virGetLastErrorMessage()); + virResetLastError(); + goto cleanup; + } + + /* Reattach managed devices to their host drivers; unmanaged + * devices don't need to be processed further */ for (i =3D 0; i < virPCIDeviceListCount(pcidevs); i++) { virPCIDevicePtr pci =3D virPCIDeviceListGet(pcidevs, i); virPCIDevicePtr actual; diff --git a/src/util/virhostdev.h b/src/util/virhostdev.h index 54e1c66..fbc7fbd 100644 --- a/src/util/virhostdev.h +++ b/src/util/virhostdev.h @@ -114,6 +114,14 @@ virHostdevReAttachPCIDevices(virHostdevManagerPtr host= dev_mgr, const char *oldStateDir) ATTRIBUTE_NONNULL(1); void +virHostdevReleasePCIDevices(virHostdevManagerPtr mgr, + const char *drv_name, + const char *dom_name, + virDomainHostdevDefPtr *hostdevs, + int nhostdevs, + const char *oldStateDir) + ATTRIBUTE_NONNULL(1); +void virHostdevReAttachUSBDevices(virHostdevManagerPtr hostdev_mgr, const char *drv_name, const char *dom_name, --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 23:26:51 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1498695974207124.46079479340699; Wed, 28 Jun 2017 17:26:14 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id D1E66C05689C; Thu, 29 Jun 2017 00:26:11 +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 E0ECC8D1DF; Thu, 29 Jun 2017 00:26:10 +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 EF86A1841C41; Thu, 29 Jun 2017 00:26:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v5T0Q5C3008898 for ; Wed, 28 Jun 2017 20:26:05 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9B6DE8D1DD; Thu, 29 Jun 2017 00:26:05 +0000 (UTC) Received: from mx1.redhat.com (ext-mx05.extmail.prod.ext.phx2.redhat.com [10.5.110.29]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 94B788D1DE for ; Thu, 29 Jun 2017 00:26:03 +0000 (UTC) Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E7B3ABDD0 for ; Thu, 29 Jun 2017 00:26:01 +0000 (UTC) Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v5T0O3a7121478 for ; Wed, 28 Jun 2017 20:26:01 -0400 Received: from e13.ny.us.ibm.com (e13.ny.us.ibm.com [129.33.205.203]) by mx0a-001b2d01.pphosted.com with ESMTP id 2bcpxtr2s3-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 28 Jun 2017 20:26:01 -0400 Received: from localhost by e13.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 28 Jun 2017 20:26:00 -0400 Received: from b01cxnp22036.gho.pok.ibm.com (9.57.198.26) by e13.ny.us.ibm.com (146.89.104.200) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 28 Jun 2017 20:25:57 -0400 Received: from b01ledav006.gho.pok.ibm.com (b01ledav006.gho.pok.ibm.com [9.57.199.111]) by b01cxnp22036.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v5T0PuU062652456; Thu, 29 Jun 2017 00:25:56 GMT Received: from b01ledav006.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 70202AC03F; Wed, 28 Jun 2017 20:25:59 -0400 (EDT) Received: from localhost (unknown [9.80.98.208]) by b01ledav006.gho.pok.ibm.com (Postfix) with ESMTP id 28960AC03A; Wed, 28 Jun 2017 20:25:59 -0400 (EDT) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com D1E66C05689C Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com D1E66C05689C DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E7B3ABDD0 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=none smtp.mailfrom=mdroth@linux.vnet.ibm.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com E7B3ABDD0 From: Michael Roth To: libvir-list@redhat.com Date: Wed, 28 Jun 2017 19:24:57 -0500 In-Reply-To: <1498695900-1648-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1498695900-1648-1-git-send-email-mdroth@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17062900-0008-0000-0000-000002504A68 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00007292; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000214; SDB=6.00880136; UDB=6.00438730; IPR=6.00660291; BA=6.00005445; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00015996; XFM=3.00000015; UTC=2017-06-29 00:25:59 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17062900-0009-0000-0000-000035D6A669 Message-Id: <1498695900-1648-3-git-send-email-mdroth@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-06-28_15:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=3 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1706290006 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 203 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 29 Jun 2017 00:26:02 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 29 Jun 2017 00:26:02 +0000 (UTC) for IP:'148.163.156.1' DOMAIN:'mx0a-001b2d01.pphosted.com' HELO:'mx0a-001b2d01.pphosted.com' FROM:'mdroth@linux.vnet.ibm.com' RCPT:'' X-RedHat-Spam-Score: 0.08 (BAYES_50, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL) 148.163.156.1 mx0a-001b2d01.pphosted.com 148.163.156.1 mx0a-001b2d01.pphosted.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.29 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: pkrempa@redhat.com, aik@ozlabs.ru, mprivozn@redhat.com, qemu-devel@nongnu.org, abologna@redhat.com, qemu-ppc@nongnu.org, laine@laine.org Subject: [libvirt] [RFC PATCH 2/5] qemu_hotplug: squash qemuDomainRemovePCIHostDevice into caller 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 29 Jun 2017 00:26:12 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" It's only called from one place, and only takes the extra step of freeing the device alias after reattach. Since another path through qemuDomainRemoveHostDevice introduced in a subsequent patch will also need to free the device alias, it'll be more readable to just start calling it directly. Signed-off-by: Michael Roth --- src/qemu/qemu_hotplug.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index a486fb4..b557e82 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -3805,15 +3805,6 @@ qemuDomainRemoveMemoryDevice(virQEMUDriverPtr driver, =20 =20 static void -qemuDomainRemovePCIHostDevice(virQEMUDriverPtr driver, - virDomainObjPtr vm, - virDomainHostdevDefPtr hostdev) -{ - qemuHostdevReAttachPCIDevices(driver, vm->def->name, &hostdev, 1); - qemuDomainReleaseDeviceAddress(vm, hostdev->info, NULL); -} - -static void qemuDomainRemoveUSBHostDevice(virQEMUDriverPtr driver, virDomainObjPtr vm, virDomainHostdevDefPtr hostdev) @@ -3905,7 +3896,8 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver, =20 switch ((virDomainHostdevSubsysType) hostdev->source.subsys.type) { case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: - qemuDomainRemovePCIHostDevice(driver, vm, hostdev); + qemuHostdevReAttachPCIDevices(driver, vm->def->name, &hostdev, 1); + qemuDomainReleaseDeviceAddress(vm, hostdev->info, NULL); /* QEMU might no longer need to lock as much memory, eg. we just * detached the last VFIO device, so adjust the limit here */ if (qemuDomainAdjustMaxMemLock(vm) < 0) --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 23:26:51 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1498695995901616.3749589655789; Wed, 28 Jun 2017 17:26:35 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 27C6C12B6; Thu, 29 Jun 2017 00:26:33 +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 CBEE4182F0; Thu, 29 Jun 2017 00:26:32 +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 6C4D61853E34; Thu, 29 Jun 2017 00:26:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v5T0Q6Wl008903 for ; Wed, 28 Jun 2017 20:26:06 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7DA87989B0; Thu, 29 Jun 2017 00:26:06 +0000 (UTC) Received: from mx1.redhat.com (ext-mx01.extmail.prod.ext.phx2.redhat.com [10.5.110.25]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 752BD9817D for ; Thu, 29 Jun 2017 00:26:04 +0000 (UTC) Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AF55C81224 for ; Thu, 29 Jun 2017 00:26:03 +0000 (UTC) Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v5T0O46w121525 for ; Wed, 28 Jun 2017 20:26:03 -0400 Received: from e34.co.us.ibm.com (e34.co.us.ibm.com [32.97.110.152]) by mx0a-001b2d01.pphosted.com with ESMTP id 2bcpxtr2te-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 28 Jun 2017 20:26:03 -0400 Received: from localhost by e34.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 28 Jun 2017 18:26:02 -0600 Received: from b03cxnp08025.gho.boulder.ibm.com (9.17.130.17) by e34.co.us.ibm.com (192.168.1.134) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 28 Jun 2017 18:25:58 -0600 Received: from b03ledav001.gho.boulder.ibm.com (b03ledav001.gho.boulder.ibm.com [9.17.130.232]) by b03cxnp08025.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v5T0Pwfl066004; Wed, 28 Jun 2017 17:25:58 -0700 Received: from b03ledav001.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 07C7E6E03F; Wed, 28 Jun 2017 18:25:58 -0600 (MDT) Received: from localhost (unknown [9.80.98.208]) by b03ledav001.gho.boulder.ibm.com (Postfix) with ESMTP id BF57F6E038; Wed, 28 Jun 2017 18:25:57 -0600 (MDT) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 27C6C12B6 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 27C6C12B6 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com AF55C81224 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=none smtp.mailfrom=mdroth@linux.vnet.ibm.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com AF55C81224 From: Michael Roth To: libvir-list@redhat.com Date: Wed, 28 Jun 2017 19:24:58 -0500 In-Reply-To: <1498695900-1648-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1498695900-1648-1-git-send-email-mdroth@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17062900-0016-0000-0000-00000710BCB8 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00007292; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000214; SDB=6.00880137; UDB=6.00438730; IPR=6.00660291; BA=6.00005445; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00015996; XFM=3.00000015; UTC=2017-06-29 00:26:01 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17062900-0017-0000-0000-00003A565FDD Message-Id: <1498695900-1648-4-git-send-email-mdroth@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-06-28_15:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1706290006 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 203 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 29 Jun 2017 00:26:03 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 29 Jun 2017 00:26:03 +0000 (UTC) for IP:'148.163.156.1' DOMAIN:'mx0a-001b2d01.pphosted.com' HELO:'mx0a-001b2d01.pphosted.com' FROM:'mdroth@linux.vnet.ibm.com' RCPT:'' X-RedHat-Spam-Score: 0.08 (BAYES_50, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL) 148.163.156.1 mx0a-001b2d01.pphosted.com 148.163.156.1 mx0a-001b2d01.pphosted.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.25 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: pkrempa@redhat.com, aik@ozlabs.ru, mprivozn@redhat.com, qemu-devel@nongnu.org, abologna@redhat.com, qemu-ppc@nongnu.org, laine@laine.org Subject: [libvirt] [RFC PATCH 3/5] virpci: introduce virPCIIOMMUGroupIterate() 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 29 Jun 2017 00:26:34 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This serves a similar purpose to virPCIDeviceAddressIOMMUGroupIterate, but uses the iommu group number to find matches instead of a device within the group. We refactor the code to use this new function and also export it for use in subsequent patches. Signed-off-by: Michael Roth --- src/util/virpci.c | 42 ++++++++++++++++++++++++++++++------------ src/util/virpci.h | 3 +++ 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/src/util/virpci.c b/src/util/virpci.c index 2c1b758..b842f44 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -49,6 +49,7 @@ VIR_LOG_INIT("util.pci"); =20 #define PCI_SYSFS "/sys/bus/pci/" +#define IOMMU_GROUP_SYSFS "/sys/kernel/iommu_groups/" #define PCI_ID_LEN 10 /* "XXXX XXXX" */ #define PCI_ADDR_LEN 13 /* "XXXX:XX:XX.X" */ =20 @@ -2178,16 +2179,13 @@ int virPCIDeviceFileIterate(virPCIDevicePtr dev, return ret; } =20 - -/* virPCIDeviceAddressIOMMUGroupIterate: - * Call @actor for all devices in the same iommu_group as orig - * (including orig itself) Even if there is no iommu_group for the - * device, call @actor once for orig. +/* virPCIIOMMUGroupIterate: + * Call @actor for all devices in a particular iommu_group. */ int -virPCIDeviceAddressIOMMUGroupIterate(virPCIDeviceAddressPtr orig, - virPCIDeviceAddressActor actor, - void *opaque) +virPCIIOMMUGroupIterate(int iommu_group, + virPCIDeviceAddressActor actor, + void *opaque) { char *groupPath =3D NULL; DIR *groupDir =3D NULL; @@ -2196,13 +2194,11 @@ virPCIDeviceAddressIOMMUGroupIterate(virPCIDeviceAd= dressPtr orig, int direrr; =20 if (virAsprintf(&groupPath, - PCI_SYSFS "devices/%04x:%02x:%02x.%x/iommu_group/devic= es", - orig->domain, orig->bus, orig->slot, orig->function) <= 0) + IOMMU_GROUP_SYSFS "%d/devices", + iommu_group) < 0) goto cleanup; =20 if (virDirOpenQuiet(&groupDir, groupPath) < 0) { - /* just process the original device, nothing more */ - ret =3D (actor)(orig, opaque); goto cleanup; } =20 @@ -2230,6 +2226,28 @@ virPCIDeviceAddressIOMMUGroupIterate(virPCIDeviceAdd= ressPtr orig, return ret; } =20 +/* virPCIDeviceAddressIOMMUGroupIterate: + * Call @actor for all devices in the same iommu_group as orig + * (including orig itself) Even if there is no iommu_group for the + * device, call @actor once for orig. + */ +int +virPCIDeviceAddressIOMMUGroupIterate(virPCIDeviceAddressPtr orig, + virPCIDeviceAddressActor actor, + void *opaque) +{ + int ret =3D -1; + + ret =3D virPCIIOMMUGroupIterate(virPCIDeviceAddressGetIOMMUGroupNum(or= ig), + actor, opaque); + if (ret < 0) { + /* just process the original device, nothing more */ + ret =3D (actor)(orig, opaque); + } + + return ret; +} + =20 static int virPCIDeviceGetIOMMUGroupAddOne(virPCIDeviceAddressPtr newDevAddr, void *o= paque) diff --git a/src/util/virpci.h b/src/util/virpci.h index 570684e..5ec1306 100644 --- a/src/util/virpci.h +++ b/src/util/virpci.h @@ -176,6 +176,9 @@ typedef int (*virPCIDeviceAddressActor)(virPCIDeviceAdd= ressPtr addr, int virPCIDeviceAddressIOMMUGroupIterate(virPCIDeviceAddressPtr orig, virPCIDeviceAddressActor actor, void *opaque); +int virPCIIOMMUGroupIterate(int iommu_group, + virPCIDeviceAddressActor actor, + void *opaque); virPCIDeviceListPtr virPCIDeviceGetIOMMUGroupList(virPCIDevicePtr dev); int virPCIDeviceAddressGetIOMMUGroupAddresses(virPCIDeviceAddressPtr devAd= dr, virPCIDeviceAddressPtr **iom= muGroupDevices, --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 23:26:51 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1498695980187863.095724447269; Wed, 28 Jun 2017 17:26:20 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 3CE7718E687; Thu, 29 Jun 2017 00:26:15 +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 0BF85182D3; Thu, 29 Jun 2017 00:26:15 +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 B3DCC4A492; Thu, 29 Jun 2017 00:26:14 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v5T0Q7Vc008911 for ; Wed, 28 Jun 2017 20:26:07 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4B5927D510; Thu, 29 Jun 2017 00:26:07 +0000 (UTC) Received: from mx1.redhat.com (ext-mx06.extmail.prod.ext.phx2.redhat.com [10.5.110.30]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 453B960462 for ; Thu, 29 Jun 2017 00:26:07 +0000 (UTC) Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 83DAA3DBDE for ; Thu, 29 Jun 2017 00:26:05 +0000 (UTC) Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v5T0Nmed030797 for ; Wed, 28 Jun 2017 20:26:05 -0400 Received: from e33.co.us.ibm.com (e33.co.us.ibm.com [32.97.110.151]) by mx0a-001b2d01.pphosted.com with ESMTP id 2bck158aed-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 28 Jun 2017 20:26:04 -0400 Received: from localhost by e33.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 28 Jun 2017 18:26:04 -0600 Received: from b03cxnp08028.gho.boulder.ibm.com (9.17.130.20) by e33.co.us.ibm.com (192.168.1.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 28 Jun 2017 18:25:59 -0600 Received: from b03ledav002.gho.boulder.ibm.com (b03ledav002.gho.boulder.ibm.com [9.17.130.233]) by b03cxnp08028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v5T0PxeJ27394238; Wed, 28 Jun 2017 17:25:59 -0700 Received: from b03ledav002.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 42110136040; Wed, 28 Jun 2017 18:25:59 -0600 (MDT) Received: from localhost (unknown [9.80.98.208]) by b03ledav002.gho.boulder.ibm.com (Postfix) with ESMTP id 0325113603A; Wed, 28 Jun 2017 18:25:58 -0600 (MDT) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3CE7718E687 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 3CE7718E687 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 83DAA3DBDE Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=none smtp.mailfrom=mdroth@linux.vnet.ibm.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 83DAA3DBDE From: Michael Roth To: libvir-list@redhat.com Date: Wed, 28 Jun 2017 19:24:59 -0500 In-Reply-To: <1498695900-1648-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1498695900-1648-1-git-send-email-mdroth@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17062900-0008-0000-0000-0000081EBC3E X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00007292; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000214; SDB=6.00880137; UDB=6.00438730; IPR=6.00660291; BA=6.00005445; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00015996; XFM=3.00000015; UTC=2017-06-29 00:26:02 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17062900-0009-0000-0000-000042D76900 Message-Id: <1498695900-1648-5-git-send-email-mdroth@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-06-28_15:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1706290006 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 203 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 29 Jun 2017 00:26:05 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 29 Jun 2017 00:26:05 +0000 (UTC) for IP:'148.163.156.1' DOMAIN:'mx0a-001b2d01.pphosted.com' HELO:'mx0a-001b2d01.pphosted.com' FROM:'mdroth@linux.vnet.ibm.com' RCPT:'' X-RedHat-Spam-Score: 0.08 (BAYES_50, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL) 148.163.156.1 mx0a-001b2d01.pphosted.com 148.163.156.1 mx0a-001b2d01.pphosted.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.30 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: pkrempa@redhat.com, aik@ozlabs.ru, mprivozn@redhat.com, qemu-devel@nongnu.org, abologna@redhat.com, qemu-ppc@nongnu.org, laine@laine.org Subject: [libvirt] [RFC PATCH 4/5] qemu: hotplug: unbind VFIO devices as a group 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 29 Jun 2017 00:26:18 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Currently we bind a managed hostdev back to the host driver (or "unbind" from the perspective of the stub driver) immediately upon receiving a DEVICE_DELETED event from QEMU. In cases where we have more one device from the group attached to a guest, this runs the risk of putting the group in a "non-viable" state where both a guest and host are using devices from a group simultaneously. This patch addresses this by deferring the unbind step until all hostdevs from a group have been detached from the guest. In the meantime, they are left on the drvManager's inactiveList, in a similar state as they would be if they were unmanaged devices that were bound to VFIO via nodedev-detach but not yet plugged into a guest. Signed-off-by: Michael Roth --- src/libvirt_private.syms | 3 ++ src/qemu/qemu_hostdev.c | 16 +++++++++ src/qemu/qemu_hostdev.h | 4 +++ src/qemu/qemu_hotplug.c | 16 ++++++++- src/util/virhostdev.c | 90 ++++++++++++++++++++++++++++++++++++++++++++= ++++ src/util/virhostdev.h | 8 +++++ src/util/virpci.c | 27 +++++++++++++++ src/util/virpci.h | 1 + 8 files changed, 164 insertions(+), 1 deletion(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 2bd3581..ba7fa39 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1783,6 +1783,8 @@ virHostCPUStatsAssign; virHostdevFindUSBDevice; virHostdevIsSCSIDevice; virHostdevManagerGetDefault; +virHostdevPCIDeviceGroupUnbind; +virHostdevPCIDeviceGroupUnbindable; virHostdevPCINodeDeviceDetach; virHostdevPCINodeDeviceReAttach; virHostdevPCINodeDeviceReset; @@ -2342,6 +2344,7 @@ virPCIDeviceWaitForCleanup; virPCIEDeviceInfoFree; virPCIGetDeviceAddressFromSysfsLink; virPCIGetHeaderType; +virPCIGetIOMMUGroupList; virPCIGetNetName; virPCIGetPhysicalFunction; virPCIGetVirtualFunctionIndex; diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c index 73d26f4..fdc52fe 100644 --- a/src/qemu/qemu_hostdev.c +++ b/src/qemu/qemu_hostdev.c @@ -384,6 +384,22 @@ qemuHostdevPrepareDomainDevices(virQEMUDriverPtr drive= r, } =20 void +qemuHostdevReleasePCIDevices(virQEMUDriverPtr driver, + const char *name, + virDomainHostdevDefPtr *hostdevs, + int nhostdevs) +{ + virQEMUDriverConfigPtr cfg =3D virQEMUDriverGetConfig(driver); + const char *oldStateDir =3D cfg->stateDir; + virHostdevManagerPtr hostdev_mgr =3D driver->hostdevMgr; + + virHostdevReleasePCIDevices(hostdev_mgr, QEMU_DRIVER_NAME, name, + hostdevs, nhostdevs, oldStateDir); + + virObjectUnref(cfg); +} + +void qemuHostdevReAttachPCIDevices(virQEMUDriverPtr driver, const char *name, virDomainHostdevDefPtr *hostdevs, diff --git a/src/qemu/qemu_hostdev.h b/src/qemu/qemu_hostdev.h index 9a7c7f1..b010085 100644 --- a/src/qemu/qemu_hostdev.h +++ b/src/qemu/qemu_hostdev.h @@ -74,6 +74,10 @@ void qemuHostdevReAttachPCIDevices(virQEMUDriverPtr driv= er, const char *name, virDomainHostdevDefPtr *hostdevs, int nhostdevs); +void qemuHostdevReleasePCIDevices(virQEMUDriverPtr driver, + const char *name, + virDomainHostdevDefPtr *hostdevs, + int nhostdevs); void qemuHostdevReAttachUSBDevices(virQEMUDriverPtr driver, const char *name, virDomainHostdevDefPtr *hostdevs, diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index b557e82..af5ee6f 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -3896,7 +3896,10 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver, =20 switch ((virDomainHostdevSubsysType) hostdev->source.subsys.type) { case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: - qemuHostdevReAttachPCIDevices(driver, vm->def->name, &hostdev, 1); + if (is_vfio) + qemuHostdevReleasePCIDevices(driver, vm->def->name, &hostdev, = 1); + else + qemuHostdevReAttachPCIDevices(driver, vm->def->name, &hostdev,= 1); qemuDomainReleaseDeviceAddress(vm, hostdev->info, NULL); /* QEMU might no longer need to lock as much memory, eg. we just * detached the last VFIO device, so adjust the limit here */ @@ -3925,6 +3928,17 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver, virDomainNetDefFree(net); } =20 + if (is_vfio) { + int iommu_group =3D + virPCIDeviceAddressGetIOMMUGroupNum(&hostdev->source.subsys.u.= pci.addr); + if (virHostdevPCIDeviceGroupUnbindable(driver->hostdevMgr, + iommu_group)) { + virHostdevPCIDeviceGroupUnbind(driver->hostdevMgr, + iommu_group); + } + } + + ret =3D 0; =20 cleanup: diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c index 2cd3f34..a7f04fe 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -905,6 +905,96 @@ virHostdevPreparePCIDevices(virHostdevManagerPtr mgr, return ret; } =20 +static bool +virHostdevPCIDeviceUnbindableInternal(virHostdevManagerPtr mgr, + int iommu_group) +{ + struct virHostdevIsPCINodeDeviceUsedData data =3D { mgr, NULL, true }; + + if (virPCIIOMMUGroupIterate(iommu_group, + virHostdevIsPCINodeDeviceUsed, + &data) < 0) { + VIR_DEBUG("IOMMU group %d is not unbindable", iommu_group); + return false; + } + + VIR_DEBUG("IOMMU group %d is unbindable", iommu_group); + return true; +} + +/* + * Check if devices within IOMMU group are in use by any domains + */ +bool +virHostdevPCIDeviceGroupUnbindable(virHostdevManagerPtr mgr, + int iommu_group) +{ + bool result; + + virObjectLock(mgr->activePCIHostdevs); + result =3D virHostdevPCIDeviceUnbindableInternal(mgr, iommu_group); + virObjectUnlock(mgr->activePCIHostdevs); + + return result; +} + +/* + * Confirm all devices in IOMMU group are in inactiveList + * before attempting to reattach to host driver. Devices in IOMMU + * group that aren't in either activeList or inactiveList are considered + * outside our control, so we treat them as inactive as well. + * + * Callers can check virHostdevPCIDeviceGroupUnbindable() beforehand + * for some indication that the group is ready for reattach to the + * host, but since it's possible for a hostdev from the group to get + * re-attached to a guest prior to subsequently calling this function + * there is no guarantee of this, which should be fine since it would + * only be immediately rebound to the stub driver anyway. + */ +void +virHostdevPCIDeviceGroupUnbind(virHostdevManagerPtr mgr, + int iommu_group) +{ + virPCIDeviceListPtr pcidevs =3D NULL; + size_t i; + + virObjectLock(mgr->activePCIHostdevs); + virObjectLock(mgr->inactivePCIHostdevs); + + if (!virHostdevPCIDeviceUnbindableInternal(mgr, iommu_group)) { + VIR_DEBUG("IOMMU group %d still in use, deferring reattach " + "of PCI devices to host", iommu_group); + goto cleanup; + } + + pcidevs =3D virPCIGetIOMMUGroupList(iommu_group); + for (i =3D 0; i < virPCIDeviceListCount(pcidevs); i++) { + virPCIDevicePtr actual, pci =3D virPCIDeviceListGet(pcidevs, i); + virPCIDeviceAddressPtr devAddr =3D virPCIDeviceGetAddress(pci); + + actual =3D virPCIDeviceListFindByIDs(mgr->inactivePCIHostdevs, + devAddr->domain, + devAddr->bus, + devAddr->slot, + devAddr->function); + if (actual) { + VIR_DEBUG("Reattaching PCI device %s", virPCIDeviceGetName(act= ual)); + if (virPCIDeviceGetManaged(actual)) + if (virPCIDeviceReattach(actual, mgr->activePCIHostdevs, + mgr->inactivePCIHostdevs) < 0) { + VIR_ERROR(_("Failed to re-attach PCI device: %s"), + virGetLastErrorMessage()); + virResetLastError(); + } + } + } + + cleanup: + virObjectUnref(pcidevs); + virObjectUnlock(mgr->activePCIHostdevs); + virObjectUnlock(mgr->inactivePCIHostdevs); +} + /* * Pre-condition: inactivePCIHostdevs & activePCIHostdevs * are locked diff --git a/src/util/virhostdev.h b/src/util/virhostdev.h index fbc7fbd..2ab8101 100644 --- a/src/util/virhostdev.h +++ b/src/util/virhostdev.h @@ -122,6 +122,14 @@ virHostdevReleasePCIDevices(virHostdevManagerPtr mgr, const char *oldStateDir) ATTRIBUTE_NONNULL(1); void +virHostdevPCIDeviceGroupUnbind(virHostdevManagerPtr mgr, + int iommu_group) + ATTRIBUTE_NONNULL(1); +bool +virHostdevPCIDeviceGroupUnbindable(virHostdevManagerPtr mgr, + int iommu_group) + ATTRIBUTE_NONNULL(1); +void virHostdevReAttachUSBDevices(virHostdevManagerPtr hostdev_mgr, const char *drv_name, const char *dom_name, diff --git a/src/util/virpci.c b/src/util/virpci.c index b842f44..a8e5190 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -2298,6 +2298,33 @@ virPCIDeviceGetIOMMUGroupList(virPCIDevicePtr dev) } =20 =20 +/* + * virPCIGetIOMMUGroupList - return a virPCIDeviceList containing + * all of the devices in @iommu_group. + * + * Return the new list, or NULL on failure + */ +virPCIDeviceListPtr +virPCIGetIOMMUGroupList(int iommu_group) +{ + virPCIDeviceListPtr groupList =3D virPCIDeviceListNew(); + + if (!groupList) + goto error; + + if (virPCIIOMMUGroupIterate(iommu_group, + virPCIDeviceGetIOMMUGroupAddOne, + groupList) < 0) + goto error; + + return groupList; + + error: + virObjectUnref(groupList); + return NULL; +} + + typedef struct { virPCIDeviceAddressPtr **iommuGroupDevices; size_t *nIommuGroupDevices; diff --git a/src/util/virpci.h b/src/util/virpci.h index 5ec1306..5bcacb2 100644 --- a/src/util/virpci.h +++ b/src/util/virpci.h @@ -180,6 +180,7 @@ int virPCIIOMMUGroupIterate(int iommu_group, virPCIDeviceAddressActor actor, void *opaque); virPCIDeviceListPtr virPCIDeviceGetIOMMUGroupList(virPCIDevicePtr dev); +virPCIDeviceListPtr virPCIGetIOMMUGroupList(int iommu_group); int virPCIDeviceAddressGetIOMMUGroupAddresses(virPCIDeviceAddressPtr devAd= dr, virPCIDeviceAddressPtr **iom= muGroupDevices, size_t *nIommuGroupDevices); --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 23:26:51 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1498695995369789.0986487952478; Wed, 28 Jun 2017 17:26:35 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0798E7486A; Thu, 29 Jun 2017 00:26:33 +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 C33E217DCE; Thu, 29 Jun 2017 00:26:32 +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 698A11853E33; Thu, 29 Jun 2017 00:26:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v5T0Q98b008928 for ; Wed, 28 Jun 2017 20:26:09 -0400 Received: by smtp.corp.redhat.com (Postfix) id 80136757B6; Thu, 29 Jun 2017 00:26:09 +0000 (UTC) Received: from mx1.redhat.com (ext-mx01.extmail.prod.ext.phx2.redhat.com [10.5.110.25]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7AE8F757C0 for ; Thu, 29 Jun 2017 00:26:07 +0000 (UTC) Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E91E881235 for ; Thu, 29 Jun 2017 00:26:05 +0000 (UTC) Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v5T0NtlO026906 for ; Wed, 28 Jun 2017 20:26:05 -0400 Received: from e37.co.us.ibm.com (e37.co.us.ibm.com [32.97.110.158]) by mx0b-001b2d01.pphosted.com with ESMTP id 2bcj0cjw4k-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 28 Jun 2017 20:26:05 -0400 Received: from localhost by e37.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 28 Jun 2017 18:26:04 -0600 Received: from b03cxnp08026.gho.boulder.ibm.com (9.17.130.18) by e37.co.us.ibm.com (192.168.1.137) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 28 Jun 2017 18:26:00 -0600 Received: from b03ledav003.gho.boulder.ibm.com (b03ledav003.gho.boulder.ibm.com [9.17.130.234]) by b03cxnp08026.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v5T0Q0AT65208530; Wed, 28 Jun 2017 17:26:00 -0700 Received: from b03ledav003.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4BD256A042; Wed, 28 Jun 2017 18:26:00 -0600 (MDT) Received: from localhost (unknown [9.80.98.208]) by b03ledav003.gho.boulder.ibm.com (Postfix) with ESMTP id 00C756A03C; Wed, 28 Jun 2017 18:25:59 -0600 (MDT) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0798E7486A Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 0798E7486A DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E91E881235 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=none smtp.mailfrom=mdroth@linux.vnet.ibm.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com E91E881235 From: Michael Roth To: libvir-list@redhat.com Date: Wed, 28 Jun 2017 19:25:00 -0500 In-Reply-To: <1498695900-1648-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1498695900-1648-1-git-send-email-mdroth@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17062900-0024-0000-0000-000016BEEE3A X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00007292; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000214; SDB=6.00880137; UDB=6.00438730; IPR=6.00660291; BA=6.00005445; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00015996; XFM=3.00000015; UTC=2017-06-29 00:26:03 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17062900-0025-0000-0000-00004B98403B Message-Id: <1498695900-1648-6-git-send-email-mdroth@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-06-28_15:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=3 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1706290006 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 203 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 29 Jun 2017 00:26:06 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 29 Jun 2017 00:26:06 +0000 (UTC) for IP:'148.163.158.5' DOMAIN:'mx0b-001b2d01.pphosted.com' HELO:'mx0a-001b2d01.pphosted.com' FROM:'mdroth@linux.vnet.ibm.com' RCPT:'' X-RedHat-Spam-Score: -2.7 (BAYES_50, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2) 148.163.158.5 mx0b-001b2d01.pphosted.com 148.163.158.5 mx0b-001b2d01.pphosted.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.25 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: pkrempa@redhat.com, aik@ozlabs.ru, mprivozn@redhat.com, qemu-devel@nongnu.org, abologna@redhat.com, qemu-ppc@nongnu.org, laine@laine.org Subject: [libvirt] [RFC PATCH 5/5] qemu: hotplug: wait for VFIO group FD close before unbind 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 29 Jun 2017 00:26:34 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" QEMU emits DEVICE_DELETED events during a device's "unparent" callback, but some additional cleanup occurs afterward via "finalize". In most cases libvirt can ignore the latter, but in the case of VFIO the closing of a device's group FD happens here, which is something libvirt needs to wait for before attempting to bind a hostdev back to a host driver. In the case of powernv, and possibly other host archs as well, failing to do this can lead to the host device driver crashing due to necessary setup (like restoring default DMA windows for the IOMMU group) not being completed yet. We attempt to avoid this here by polling the QEMU process for open FDs referencing /dev/vfio/ and waiting for a certain period of time. In practice the delay between the DEVICE_DELETED event and closing of the group FD seems to be around 6 seconds, so we set the max wait time at 15 seconds. If we time out we leave the device in the inactiveList and bound to VFIO. We only attempt the wait if the last hostdev from an IOMMU group is being detached and there's reasonable expectation that the group FD will be closed soon. There are alternatives to this approach, like adding a specific group delete event to QEMU and handling this cleanup via and asynchronous event handler, nut since we do a similar poll-wait for things like KVM device passthrough this simple approach is hopefully a reasonable starting point at least. Signed-off-by: Michael Roth --- src/libvirt_private.syms | 1 + src/qemu/qemu_hotplug.c | 34 +++++++++++++++++++++++++++++-- src/util/virfile.c | 52 ++++++++++++++++++++++++++++++++++++++++++++= ++++ src/util/virfile.h | 1 + 4 files changed, 86 insertions(+), 2 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index ba7fa39..787267c 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1657,6 +1657,7 @@ virFileIsDir; virFileIsExecutable; virFileIsLink; virFileIsMountPoint; +virFileIsOpenByPid; virFileIsSharedFS; virFileIsSharedFSType; virFileLength; diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index af5ee6f..d200bab 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -68,6 +68,8 @@ VIR_LOG_INIT("qemu.qemu_hotplug"); /* Wait up to 5 seconds for device removal to finish. */ unsigned long long qemuDomainRemoveDeviceWaitTime =3D 1000ull * 5; =20 +/* Wait up to 15 seconds for iommu group close */ +unsigned long long qemuDomainRemoveDeviceGroupWaitTime =3D 1000ull * 15; =20 /** * qemuDomainPrepareDisk: @@ -3830,6 +3832,32 @@ qemuDomainRemoveSCSIVHostDevice(virQEMUDriverPtr dri= ver, } =20 static int +qemuDomainWaitForDeviceGroupClose(virDomainObjPtr vm, int iommu_group) +{ + char *group_path; + unsigned long long remaining_ms =3D qemuDomainRemoveDeviceGroupWaitTim= e; + int rc =3D -1; + + if (virAsprintf(&group_path, "/dev/vfio/%d", iommu_group) < 0) + return -1; + + while ((rc =3D virFileIsOpenByPid(group_path, vm->pid)) =3D=3D 1) { + if (remaining_ms <=3D 0) + break; + usleep(100*1000); + remaining_ms -=3D 100; + } + + VIR_DEBUG("IOMMU group %d FD status: %d, wait time: %llu ms", + iommu_group, rc, + qemuDomainRemoveDeviceGroupWaitTime - remaining_ms); + + VIR_FREE(group_path); + return rc; +} + + +static int qemuDomainRemoveHostDevice(virQEMUDriverPtr driver, virDomainObjPtr vm, virDomainHostdevDefPtr hostdev) @@ -3933,8 +3961,10 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver, virPCIDeviceAddressGetIOMMUGroupNum(&hostdev->source.subsys.u.= pci.addr); if (virHostdevPCIDeviceGroupUnbindable(driver->hostdevMgr, iommu_group)) { - virHostdevPCIDeviceGroupUnbind(driver->hostdevMgr, - iommu_group); + if (qemuDomainWaitForDeviceGroupClose(vm, iommu_group) =3D=3D = 0) { + virHostdevPCIDeviceGroupUnbind(driver->hostdevMgr, + iommu_group); + } } } =20 diff --git a/src/util/virfile.c b/src/util/virfile.c index d444b32..29b762f 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -4162,3 +4162,55 @@ virFileReadValueString(char **value, const char *for= mat, ...) VIR_FREE(str); return ret; } + +int +virFileIsOpenByPid(const char *path, pid_t pid) +{ + struct dirent *ent; + DIR *filelist_dir; + char *filelist_path; + bool found =3D false; + int rc =3D -1; + + if (!path || !IS_ABSOLUTE_FILE_NAME(path)) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("invalid path: %s"), path ? path : "null"); + goto error; + } + + if (virAsprintf(&filelist_path, "/proc/%d/fd", pid) < 0) + goto error; + + if (virDirOpen(&filelist_dir, filelist_path) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unable to open directory: %s"), filelist_path); + goto error; + } + + while (!found && + (rc =3D virDirRead(filelist_dir, &ent, filelist_path)) =3D=3D 1= ) { + char *resolved_path =3D NULL; + char *link_path; + if ((rc =3D virAsprintf(&link_path, "%s/%s", filelist_path, ent->d= _name)) < 0) + break; + if (virFileResolveLink(link_path, &resolved_path) =3D=3D 0) { + if (resolved_path) { + VIR_DEBUG("checking absolute path for match (need: %s, got= : %s)", + path, resolved_path); + if (STREQ(resolved_path, path)) + found =3D true; + VIR_FREE(resolved_path); + } + } + } + + VIR_DIR_CLOSE(filelist_dir); + error: + VIR_FREE(filelist_path); + + VIR_DEBUG("returning, rc: %d, found: %d", rc, found); + if (rc < 0) + return rc; + + return found ? 1 : 0; +} diff --git a/src/util/virfile.h b/src/util/virfile.h index 57ceb80..fb86786 100644 --- a/src/util/virfile.h +++ b/src/util/virfile.h @@ -347,6 +347,7 @@ int virFileReadValueScaledInt(unsigned long long *value= , const char *format, ... int virFileReadValueString(char **value, const char *format, ...) ATTRIBUTE_FMT_PRINTF(2, 3); =20 +int virFileIsOpenByPid(const char *path, pid_t pid); =20 int virFileInData(int fd, int *inData, --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list