From nobody Thu Apr 2 20:20:25 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1774540385; cv=none; d=zohomail.com; s=zohoarc; b=Gck2YA/rdeFlAacOavqN3MpoWpQ9pLfD1aiGPPg+rrjyoM4EvJH/AJqWsUufnFd2Kh5OQVIUJv3MmCsC47eQHLY/kgb94R5koA3cVy2ajUvpfT+IqPEncbHFyoyibcgtIOf+DNwlKjHlRszD/ORpVnj3InvcO/YUCigPcVgK4+k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1774540385; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:Subject:Subject:To:To:Message-Id:Cc; bh=q4rirorF8x34tpSR3kFbVrha+UZ3R0c4yKrOpikzKUY=; b=ZQWnssn6y7IT3UhOYZbLgL+wmAFiW5ik+9UhFKD170AHsX2SLKdqUOp4Y0WETV8qA0vmUhFJaARnM+ZWmwtJSdOoeldhkxucfjCj2QSoBfXXLAjBEQ3VlLt7KxxrOPML60gOMriigvASt1anuFCCzOCDFriZizW7l448MnrQY7M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1774540384950680.7455170139799; Thu, 26 Mar 2026 08:53:04 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 993) id D2F673F348; Thu, 26 Mar 2026 11:53:03 -0400 (EDT) Received: from [172.19.199.12] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id B17743F8A8; Thu, 26 Mar 2026 11:52:28 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 97DA43F328; Thu, 26 Mar 2026 11:52:24 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 7BD513F309 for ; Thu, 26 Mar 2026 11:52:23 -0400 (EDT) Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-70-ylPuDneqNASwQ1_A6KdL_A-1; Thu, 26 Mar 2026 11:52:21 -0400 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 0CD1118002C7 for ; Thu, 26 Mar 2026 15:52:21 +0000 (UTC) Received: from antique-work.redhat.com (unknown [10.44.34.72]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5DB701800673 for ; Thu, 26 Mar 2026 15:52:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HELO_MISC_IP,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1774540343; h=from:from: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; bh=q4rirorF8x34tpSR3kFbVrha+UZ3R0c4yKrOpikzKUY=; b=PUjKMj5yin941ld0ZxRQViFcxg3Cv8zwRqzAIgQ7rsoEqD22vJJcSdP4blgV00Q5thWTxp AE1yFqWuQ+sWQvywDx4QVnqDvvJCTgBh0S5Izyty8T26yyoqptU5eShdPECbc2eot9vSuZ 0ObHSDKfxxoI7cFopyeYC4b2KNM4kNs= X-MC-Unique: ylPuDneqNASwQ1_A6KdL_A-1 X-Mimecast-MFC-AGG-ID: ylPuDneqNASwQ1_A6KdL_A_1774540341 To: devel@lists.libvirt.org Subject: [libvirt PATCH] hypervisor: Call virWaitForDevices() after detaching host devices Date: Thu, 26 Mar 2026 16:52:19 +0100 Message-ID: <03d047bd50ada3fb573d83ebcd6018b8367d1ace.1774540324.git.phrdina@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: q593GwwFP5cWUhm_IS9nWRrQGWHbbUMVxcTGTNa75_Q_1774540341 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: FAVS272FHPBO27O2XRWB55563CGEOELG X-Message-ID-Hash: FAVS272FHPBO27O2XRWB55563CGEOELG X-MailFrom: phrdina@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Pavel Hrdina via Devel Reply-To: Pavel Hrdina X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1774540387644158500 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Pavel Hrdina On systems with selinux enabled starting a VM with managed host device using IOMMUFD backend can run into race-condition where both libvirt and udev are setting selinux label on /dev/vfio/devices/vfioX device. If udev is the last one to set selinux label starting VM fails with: error: internal error: QEMU unexpectedly closed the monitor (vm=3D'test'): = 2026-03-26T15:47:36.620422Z qemu-kvm: -device {"driver":"vfio-pci","id":"ho= stdev0","iommufd":"iommufd0","fd":"20","bus":"pci.7","addr":"0x0"}: vfio ho= stdev0: Failed to add fd 20 to KVM VFIO device: Invalid argument We need to wait for udev to finish processing all events. Signed-off-by: Pavel Hrdina Reviewed-by: J=C3=A1n Tomko --- src/hypervisor/virhostdev.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/hypervisor/virhostdev.c b/src/hypervisor/virhostdev.c index f4d2176204..b063a44f62 100644 --- a/src/hypervisor/virhostdev.c +++ b/src/hypervisor/virhostdev.c @@ -782,6 +782,9 @@ virHostdevPreparePCIDevicesImpl(virHostdevManager *mgr, } } =20 + /* Step 2.5: Wait for udev to handle all events for devices. */ + virWaitForDevices(); + /* At this point, all devices are attached to the stub driver and have * been marked as inactive */ =20 --=20 2.53.0