From nobody Sat Nov 23 00:44:58 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1685938563; cv=none; d=zohomail.com; s=zohoarc; b=AmXRcxBNUy/00WQfrL4ZdVu0nnFS0iom0QTrkn3RyuLH7JeykoEAiBSFu26QeGw6dUNUDpUSpPiMdq4SZfNfeDQorF2VQOkOvk2Q4221abvBTbjLn9vI3utGDoe/Tjy2bxu2iLgyQqwmsA+lobbzlXJVNjJqwpdk5W2b/ObV184= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685938563; 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=fFgs9bpcPoXZ4f7Yb0NWc0SjgOeSbyquwktqNbhp0Lw=; b=QC4YpGCQzVpJawucjMvFMB1ACNwnsjQctGdOVvZN2gcJvevE5fFmCqgIqVB/T9xZ+puFNUXPt7yf7KDxkCng4EDWgyWRZk/tlAaokBzhdhPnBWp5mCB4wxUL3MGgAtrWr1Mer6bHNKKLNEGNt6cJ1n2SG6FP/ugZWZrdrt2GHAY= 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 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 1685938563574899.320613303395; Sun, 4 Jun 2023 21:16:03 -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-119-Zg4S8wHRNz-fL_7uTCCTLg-1; Mon, 05 Jun 2023 00:15:23 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 61B2285A5BB; Mon, 5 Jun 2023 04:15:21 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7C75740CFD46; Mon, 5 Jun 2023 04:15:18 +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 4A22519465A0; Mon, 5 Jun 2023 04:15:18 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 0DFE71946595 for ; Mon, 5 Jun 2023 04:15:18 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id EF5969E72; Mon, 5 Jun 2023 04:15:17 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast05.extmail.prod.ext.rdu2.redhat.com [10.11.55.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E7D517AE4 for ; Mon, 5 Jun 2023 04:15:17 +0000 (UTC) Received: from us-smtp-inbound-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D08558015D8 for ; Mon, 5 Jun 2023 04:15:17 +0000 (UTC) Received: from baidu.com (mx21.baidu.com [220.181.3.85]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-98-7T_rTlPjPZO-oMEgpaV5gg-1; Mon, 05 Jun 2023 00:15:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685938562; 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=fFgs9bpcPoXZ4f7Yb0NWc0SjgOeSbyquwktqNbhp0Lw=; b=YaNOAOqB9x7Uy7mmG7rYHfFe4Pu1/Nr8HP+zaQHvNoA8NEBbk5CcEtbY6htJbiOywP7/Oy czB3/EQ0nb380RAtIrNWTADECa4kh8Xl6EHNOEFqZszbQ2UxPLNNwFhnZrNoTkmnpxQmo/ z9iZeI3R6dCAWJldKxCCJFp8NGTLpgk= X-MC-Unique: Zg4S8wHRNz-fL_7uTCCTLg-1 X-Original-To: libvir-list@listman.corp.redhat.com X-MC-Unique: 7T_rTlPjPZO-oMEgpaV5gg-1 From: zuoboqun To: Subject: [PATCH] qemuDomainWaitForDeviceRemoval: recheck the value of priv->unplug.alias when timeout Date: Mon, 5 Jun 2023 11:59:36 +0800 Message-ID: <20230605035936.2704-1-zuoboqun@baidu.com> MIME-Version: 1.0 X-Originating-IP: [172.31.62.12] X-ClientProxiedBy: BJHW-Mail-Ex06.internal.baidu.com (10.127.64.16) To BJHW-MAIL-EX26.internal.baidu.com (10.127.64.41) X-FEAS-Client-IP: 172.31.51.47 X-FE-Policy-ID: 15:10:21:SYSTEM 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 3.1 on 10.11.54.5 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: zuoboqun Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: baidu.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1685938567867100001 Content-Type: text/plain; charset="utf-8" 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 --- src/qemu/qemu_hotplug.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 972df572a7..c8028df93a 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -5399,8 +5399,12 @@ qemuDomainWaitForDeviceRemoval(virDomainObj *vm) until +=3D qemuDomainGetUnplugTimeout(vm); =20 while (priv->unplug.alias) { - if ((rc =3D virDomainObjWaitUntil(vm, until)) =3D=3D 1) - return 0; + if ((rc =3D virDomainObjWaitUntil(vm, until)) =3D=3D 1) { + if (priv->unplug.alias) + return 0; + else + return 1; + } =20 if (rc < 0) { VIR_WARN("Failed to wait on unplug condition for domain '%s' " --=20 2.34.0.windows.1