From nobody Sat Feb 7 11:05:29 2026 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; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1609764929; cv=none; d=zohomail.com; s=zohoarc; b=UpBC5yMl45LsH508bUypy/34zc0Pm/2z9jiOcg6LgyrS/GgMXsrLf1huGA+0pCwv8z9bYUA8Kc03WlYeYOS42/IxpjDTnONihVyl9yeDqVi8054AUsWNGSEgRWkQy16Qk3aXto8SOEU+atL2c6iHsQlN2TShFIBQISw1UzcIIZY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609764929; h=Content-Type:Content-Transfer-Encoding:Cc: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=z19WsnDE7LVSTMUd6oVQKk7YJflEz2zp60QXJXfAjmc=; b=YeiaLrdE7o90dDStaI1LhaT9QycjIxwas0RuzfI9/OrWeICOUJgoHvbaf8vP1Z0QVT6q8vFrgPpenl3T+BVf3f3VeckKCR5GIbRAxsdZLOBZBSlLuuItJhvhSaDOTAAuv2a1tRudVPOnEijJoBsMH6J0wzKsKbfnl/XCZV3wKwQ= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail 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 1609764929251126.76147173322158; Mon, 4 Jan 2021 04:55: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-22-w59dSmqjNuKj2s6R86P_wA-1; Mon, 04 Jan 2021 07:55:24 -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 B3FD9107ACE4; Mon, 4 Jan 2021 12:55:19 +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 8AC9B19717; Mon, 4 Jan 2021 12:55:19 +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 24EA55002F; Mon, 4 Jan 2021 12:55:19 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 104CtAIi014163 for ; Mon, 4 Jan 2021 07:55:10 -0500 Received: by smtp.corp.redhat.com (Postfix) id 9DF25112D405; Mon, 4 Jan 2021 12:55:10 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9A0AA112D404 for ; Mon, 4 Jan 2021 12:55:10 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 87F9580122E for ; Mon, 4 Jan 2021 12:55:10 +0000 (UTC) Received: from mail-qt1-f175.google.com (mail-qt1-f175.google.com [209.85.160.175]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-283-vsIsVeK9MDy-w_1_wGl38Q-1; Mon, 04 Jan 2021 07:55:08 -0500 Received: by mail-qt1-f175.google.com with SMTP id c14so18360855qtn.0 for ; Mon, 04 Jan 2021 04:55:08 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c6:ca55:7a5d:da5b:906f:bedd]) by smtp.gmail.com with ESMTPSA id m64sm2342866qkb.90.2021.01.04.04.55.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jan 2021 04:55:07 -0800 (PST) X-MC-Unique: w59dSmqjNuKj2s6R86P_wA-1 X-MC-Unique: vsIsVeK9MDy-w_1_wGl38Q-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=z19WsnDE7LVSTMUd6oVQKk7YJflEz2zp60QXJXfAjmc=; b=X4kPeq6HVvcOgC5zNGYUp5iZ0K1//3eCl1DTFXzfCGR5dfKLd8cdHcv8Bd7R9NN4Qp WSft1FN9RS5GkiB6EiboQebD02HEOO/DbU0l60OQl97iYCMmaye7IqxIbLkoF1nUs24K 3i5fxnfB94oHetPkXJKIWc3uo9ful7Tu3ors9chJM6KJ3WxlGiee1kYz6YOQOG8FbjRx NjoXq0HUdUrWm4a2woT1NIxLKEx02SxdgOiBWe6uI9X4gyc4if2AxsHjQ+Iq7HTTHvYx AbMHPfFgBGqKgGuqicosgua271EG/b/tAkjFCbtiF3pZgHxuc1Ic2IrozmAiUlHFv7zY DsdQ== X-Gm-Message-State: AOAM531jZrf89U4gi5oMdbhA1nsY1PqGFwXbjDI2b72O8dWeJqDKHEKG 5mNik607dnLUmxfJp1MhJhzweM5RU6N7mA== X-Google-Smtp-Source: ABdhPJwjINXkBKXFIZy4S0vOkULswlcXVyBd6a0gWGqCoCNwsvTo8tte7Wqtd/FmDa6nry/ZTShRSg== X-Received: by 2002:ac8:5a0f:: with SMTP id n15mr72114434qta.88.1609764907762; Mon, 04 Jan 2021 04:55:07 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH 06/20] virhostdev.c: virHostdevGetPCIHostDevice() now reports missing device Date: Mon, 4 Jan 2021 09:54:30 -0300 Message-Id: <20210104125444.200536-7-danielhb413@gmail.com> In-Reply-To: <20210104125444.200536-1-danielhb413@gmail.com> References: <20210104125444.200536-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza 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 Content-Type: text/plain; charset="utf-8" Gitlab issue #72 [1] reports that removing SR-IOVs VFs before removing the devices from the running domains can have strange consequences. QEMU might be able to hotunplug the device inside the guest, but Libvirt will not be aware of that, and then the guest is now inconsistent with the domain definition. There's also the possibility of the VFs removal not succeeding while the domain is running but then, as soon as the domain is shutdown, all the VFs are removed. Libvirt can't handle the removal of the PCI devices while trying to reattach the hostdevs, and the Libvirt daemon can be left in an inconsistent state (see [2]). This patch starts to address the issue related in Gitlab #72, most notably the issue described in [2]. When shutting down a domain with SR-IOV hostdevs that got missing, virHostdevReAttachPCIDevices() is failing the whole process and failing to reattach all the PCI devices, including the ones that aren't related to the VFs that went missing. Let's make it more resilient with host changes by changing virHostdevGetPCIHostDevice() to return an exclusive error code '-2' for this case. virHostdevGetPCIHostDeviceList() can then tell when virHostdevGetPCIHostDevice() failed to find the PCI device of a hostdev and continue to make the list of PCI devices. virHostdevReAttachPCIDevices() will now be able to proceed reattaching all other valid PCI devices, at least. The 'ghost hostdevs' will be handled later on. [1] https://gitlab.com/libvirt/libvirt/-/issues/72 [2] https://gitlab.com/libvirt/libvirt/-/issues/72#note_459032148 Signed-off-by: Daniel Henrique Barboza --- src/hypervisor/virhostdev.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/hypervisor/virhostdev.c b/src/hypervisor/virhostdev.c index 7338ac0700..18373deb41 100644 --- a/src/hypervisor/virhostdev.c +++ b/src/hypervisor/virhostdev.c @@ -220,7 +220,8 @@ virHostdevManagerGetDefault(void) * is returned. * * Returns: 0 on success (@pci might be NULL though), - * -1 otherwise (with error reported). + * -1 otherwise (with error reported), + * -2 PCI device not found. @pci will be NULL */ static int virHostdevGetPCIHostDevice(const virDomainHostdevDef *hostdev, @@ -235,6 +236,9 @@ virHostdevGetPCIHostDevice(const virDomainHostdevDef *h= ostdev, hostdev->source.subsys.type !=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PC= I) return 0; =20 + if (!virPCIDeviceExists(&pcisrc->addr)) + return -2; + actual =3D virPCIDeviceNew(&pcisrc->addr); =20 if (!actual) @@ -270,7 +274,7 @@ virHostdevGetPCIHostDeviceList(virDomainHostdevDefPtr *= hostdevs, int nhostdevs) virDomainHostdevDefPtr hostdev =3D hostdevs[i]; g_autoptr(virPCIDevice) pci =3D NULL; =20 - if (virHostdevGetPCIHostDevice(hostdev, &pci) < 0) + if (virHostdevGetPCIHostDevice(hostdev, &pci) =3D=3D -1) return NULL; =20 if (!pci) --=20 2.26.2