From nobody Tue Feb 10 04:58:43 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1687528121; cv=none; d=zohomail.com; s=zohoarc; b=jPDhAjeBZj6Rc5+CzyYpcum2F9wFfPQGtBSThp0im8borwyv8Zg3a6JEvfvY52rLEOipHOzDRzF5sL4tWN/MZDMacldFq8tD0fgsAX0AhaScaK4ienF5rIqmZ4Z9ZLoQ0hmB4pfzpfYAj1YDKHby9+OAYeJx6ROASsjKnCVOU8Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1687528121; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=yyFKrBR5oeoFS6wkFo4PsrDmhuO+s+Xxy4ZtSzUn9JE=; b=XZGoZVUtULo0SlVFUI+ygbg54NBxD0jBE8UiRiwhPcJ/SWNS5YhIHaqw0KBDqdnI9eW6OtMSuUkNNnBoDI1hk3yr9OIxnibzqem/laBT8Bf3LNkYB8+s3yuhM39me+Cc/MipqQAXLnC6unZJUNOt83GbWGVDoc8SsJq2kL4u4j0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1687528121565707.6210041692016; Fri, 23 Jun 2023 06:48:41 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-672-xxdNad5eO76hR45d-p7UNw-1; Fri, 23 Jun 2023 09:48:36 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 10CDC805BC3; Fri, 23 Jun 2023 13:48:33 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7CB5E207B2BC; Fri, 23 Jun 2023 13:48:31 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 29A9C1946588; Fri, 23 Jun 2023 13:48:31 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id E794A1946587 for ; Fri, 23 Jun 2023 13:48:24 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 56C9D40C2071; Fri, 23 Jun 2023 13:48:24 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.45.242.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7E22440C2063; Fri, 23 Jun 2023 13:48:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687528120; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=yyFKrBR5oeoFS6wkFo4PsrDmhuO+s+Xxy4ZtSzUn9JE=; b=U7BzHi6p77gAfYud+G/URWW2Cq7V99Mi1diRb/gIcZuC70fwXbnJ5wZ3jMz3q08/ovFn8g vWVTJ9+PMzNm6E25qgfZXNqO8HfBpDn83osZNPbnrdnJGMIt2cbUyv18LHqF37eFnTpVB0 k9yNdopSH9iyl4nZPbftT3U6YHaNF6g= X-MC-Unique: xxdNad5eO76hR45d-p7UNw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH v2] qemuDomainWaitForDeviceRemoval: recheck the value of priv->unplug.alias when timeout Date: Fri, 23 Jun 2023 15:48:14 +0200 Message-Id: <33c3ddcd40b48a90c1043cb1548ccae4a150991d.1687528003.git.pkrempa@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Krempa , zuoboqun Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1687528122118100001 Content-Type: text/plain; charset="utf-8" From: zuoboqun When detaching a device, the following race condition may happen: Once qemuDomainSignalDeviceRemoval() marks the device for removal, it returns true, which means it is the caller that marked the device for removal is going to remove the device from domain definition. But qemuDomainWaitForDeviceRemoval() may still receive timeout from virDomainObjWaitUntil() which is implemented by pthread_cond_timedwait() due to an unavoidable race between the expiration of the timeout and the predicate state(priv->unplug.alias) change. And then qemuDomainWaitForDeviceRemoval() will return 0, thus the caller will not remove the device from domain definition. In this situation, the device is still present in the domain definition but doesn't exist in qemu anymore. Worse, there is no way to remove it from the domain definition. Solution is to recheck the value of priv->unplug.alias to determine who is going to remove the device from domain definition. Signed-off-by: zuo boqun Reviewed-by: Peter Krempa Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- v2: - rewrote waiting loop so that we always check the unplug status if the thread was notified - added comments explaining the logic src/qemu/qemu_hotplug.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index ba9e44945b..2e3c99760d 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -5391,21 +5391,27 @@ qemuDomainWaitForDeviceRemoval(virDomainObj *vm) { qemuDomainObjPrivate *priv =3D vm->privateData; unsigned long long until; - int rc; if (virTimeMillisNow(&until) < 0) return 1; until +=3D qemuDomainGetUnplugTimeout(vm); - while (priv->unplug.alias) { - if ((rc =3D virDomainObjWaitUntil(vm, until)) =3D=3D 1) - return 0; + while (true) { + int rc; - if (rc < 0) { - VIR_WARN("Failed to wait on unplug condition for domain '%s' " - "device '%s'", vm->def->name, priv->unplug.alias); + if ((rc =3D virDomainObjWaitUntil(vm, until)) < 0) { + VIR_WARN("Failed to wait on unplug condition for domain '%s' d= evice '%s'", + vm->def->name, priv->unplug.alias); return 1; } + + /* unplug event for this device was received, check the status */ + if (!priv->unplug.alias) + break; + + /* timeout */ + if (rc =3D=3D 1) + return 0; } if (priv->unplug.status =3D=3D QEMU_DOMAIN_UNPLUGGING_DEVICE_STATUS_GU= EST_REJECTED) { --=20 2.40.1