From nobody Wed Nov 27 20:29:30 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.zohomail.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 1535701461664631.0730104794561; Fri, 31 Aug 2018 00:44:21 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 31780285BB; Fri, 31 Aug 2018 07:44:18 +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 5D6A926541; Fri, 31 Aug 2018 07:44:16 +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 D4E144BB75; Fri, 31 Aug 2018 07:44:12 +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 w7V7iAnT000932 for ; Fri, 31 Aug 2018 03:44:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id F114B80E6; Fri, 31 Aug 2018 07:44:10 +0000 (UTC) Received: from mx1.redhat.com (ext-mx20.extmail.prod.ext.phx2.redhat.com [10.5.110.49]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E96095D6B5 for ; Fri, 31 Aug 2018 07:44:07 +0000 (UTC) Received: from huawei.com (szxga05-in.huawei.com [45.249.212.191]) (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 3E6253086250 for ; Fri, 31 Aug 2018 07:44:06 +0000 (UTC) Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 995813446A7C4 for ; Fri, 31 Aug 2018 15:44:01 +0800 (CST) Received: from localhost.localdomain (10.184.157.230) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.399.0; Fri, 31 Aug 2018 15:43:56 +0800 From: Wu Zongyong To: Date: Fri, 31 Aug 2018 15:34:27 +0800 Message-ID: <1535700867-86300-1-git-send-email-cordius.wu@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.184.157.230] X-CFilter-Loop: Reflected X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 212 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Fri, 31 Aug 2018 07:44:06 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Fri, 31 Aug 2018 07:44:06 +0000 (UTC) for IP:'45.249.212.191' DOMAIN:'szxga05-in.huawei.com' HELO:'huawei.com' FROM:'cordius.wu@huawei.com' RCPT:'' X-RedHat-Spam-Score: -0.012 (RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS) 45.249.212.191 szxga05-in.huawei.com 45.249.212.191 szxga05-in.huawei.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.49 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: cordius.wu@huawei.com, chenlixin1@huawei.com, wanzongshun@huawei.com, weifuqiang@huawei.com Subject: [libvirt] [PATCH] virhostdev: Fix PCI devices are still attatched to stub driver bug 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 31 Aug 2018 07:44:20 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Currently, PCI devices will not be rebound to host drivers but attached to the stub driver when: 1) use libvirt to start a virtual machine with PCI devices assigned, then stop libvirtd process and shutdown the virtual machine. Finally, PCI devices are still bound to the stub driver instead of host drivers after libvirt start again. 2) use libvirt to shutdown a virtual machine wtih PCI devices assigned, then stop libvirtd process before libvirt try to rebind PCI devices to host drivers. Finally, PCI devices are still bound to the stub driver after libvirt start again. Notice that the comment on the top of virPCIDeviceDetach as follows: activeDevs should be a list of all PCI devices currently in use by a domain.inactiveDevs is a list of all PCI devices that libvirt has detached from the host driver + attached to the stub driver, but hasn't yet assigned to a domain. It's not reasonable that libvirt filter out devices that are either not active or not used by the current domain and driver. For devices belong to domains that has been shutdown before libvirt start, we should put them into inactiveDevs if then meet the condition that PCI devices have been detached from the host driver + attached to the stub driver. Moreover, we set orignal states of PCI devices when build PCI devices list in virHostdevGetPCIHostDeviceList if states has been set in struct virDomainHostdevDefPtr. Signed-off-by: Wu Zongyong --- src/util/virhostdev.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c index ca79c37..ecf95e3 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -235,6 +235,7 @@ virHostdevGetPCIHostDeviceList(virDomainHostdevDefPtr *= hostdevs, int nhostdevs) for (i =3D 0; i < nhostdevs; i++) { virDomainHostdevDefPtr hostdev =3D hostdevs[i]; virDomainHostdevSubsysPCIPtr pcisrc =3D &hostdev->source.subsys.u.= pci; + virDomainHostdevOrigStatesPtr origstates =3D &hostdev->origstates; virPCIDevicePtr pci; =20 if (hostdev->mode !=3D VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) @@ -262,6 +263,10 @@ virHostdevGetPCIHostDeviceList(virDomainHostdevDefPtr = *hostdevs, int nhostdevs) virPCIDeviceSetStubDriver(pci, VIR_PCI_STUB_DRIVER_XEN); else virPCIDeviceSetStubDriver(pci, VIR_PCI_STUB_DRIVER_KVM); + + virPCIDeviceSetUnbindFromStub(pci, origstates->states.pci.unbind_f= rom_stub); + virPCIDeviceSetRemoveSlot(pci, origstates->states.pci.remove_slot); + virPCIDeviceSetReprobe(pci, origstates->states.pci.reprobe); } =20 return pcidevs; @@ -1008,8 +1013,19 @@ virHostdevReAttachPCIDevices(virHostdevManagerPtr mg= r, continue; } } else { - virPCIDeviceListDel(pcidevs, pci); - continue; + int stub =3D virPCIDeviceGetStubDriver(pci); + if (stub > VIR_PCI_STUB_DRIVER_NONE && + stub < VIR_PCI_STUB_DRIVER_LAST) { + /* The device is bound to a known stub driver: add a copy + * to the inactive list */ + VIR_DEBUG("Adding PCI device %s to inactive list", + virPCIDeviceGetName(pci)); + if (virPCIDeviceListAddCopy(mgr->inactivePCIHostdevs, pci)= < 0) { + VIR_ERROR(_("Failed to add PCI device %s to the inacti= ve list"), + virGetLastErrorMessage()); + virResetLastError(); + } + } } =20 i++; --=20 1.9.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list