From nobody Fri May 17 23:27:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1643719161; cv=none; d=zohomail.com; s=zohoarc; b=M2bKAzlq857SbeRcfYprJVUuoy56sFxDrPmZR1s20dbwsFGUgVM3Vgu3rhaTuAk1H1ZZJlzTN2Oh2wdPSZBTtjgVHAtWALkuQDzkfLvde2PeX07aseF5eh/NdoRBdwz0EtmpNmi2q3DicQQPC4rw6qx+5FfYz4YztsCqBBFzE0A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1643719161; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=X+1cHXn7006Dllz4yEYCTLf33kSAYz+PvdLjyxXLOLA=; b=CVzFgUrjEE4iQoU26kQvRJcdh0M4LeBHqTqlZ4ud8fArC61gIYkUAOiHLM+qoE6xClrqMskHM9dXk4/N6fQdfGZFjwIwyTRWmuceIdTPD0KBi7dB1uNaVZMGdGIOV/gkpfNW95V5uQrmPyoDa0er2ZAVrgZyNNfOinrdUQGOrgo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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.129.124]) by mx.zohomail.com with SMTPS id 1643719161175428.659708763037; Tue, 1 Feb 2022 04:39:21 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-505-g8_6pXEHPsqmpPDMvMLv-A-1; Tue, 01 Feb 2022 07:39:17 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EA65B100CCC0; Tue, 1 Feb 2022 12:39:11 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C29786FB88; Tue, 1 Feb 2022 12:39:11 +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 562C41806D03; Tue, 1 Feb 2022 12:39:11 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 211CdAFf003505 for ; Tue, 1 Feb 2022 07:39:10 -0500 Received: by smtp.corp.redhat.com (Postfix) id 6667960C40; Tue, 1 Feb 2022 12:39:10 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.195.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id DD32D752A7 for ; Tue, 1 Feb 2022 12:38:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643719160; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=X+1cHXn7006Dllz4yEYCTLf33kSAYz+PvdLjyxXLOLA=; b=S5q/UbpKCGY4Shz3aHRpFRn26vZs0GbnwOlPfPWGvBTJ2k9yHstEaOCNYzfxy+i3Q9qhJW cPd/fnHKM8ipYDIObccZ0YRPy2WqP0uFdgMToeueaO3VPYwHbaxHmQAbV8VEkGGrB4oFlV cI11X17G+IGo0xTJcGXGqkR5IS6ptuw= X-MC-Unique: g8_6pXEHPsqmpPDMvMLv-A-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH] virnwfilterobj: Unlock virNWFilterObj before triggering rebuild Date: Tue, 1 Feb 2022 13:38:53 +0100 Message-Id: <47f6f74bc626950d4816a04e5a88fba03f44d5a6.1643719090.git.mprivozn@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com 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.79 on 10.5.11.15 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 X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1643719162673100001 Content-Type: text/plain; charset="utf-8" When updating am NWFilter, rebuilding of all NWFilters is triggered. This happens in virNWFilterObjListAssignDef() by calling virNWFilterTriggerRebuild(). Now consider another thread, that's currently executing virNWFilterBindingCreateXML() over the same NWFilter. What happens is that this second thread gets all the way into virNWFilterInstantiateFilterInternal(), acquires @updateMutex and transitively calls virNWFilterObjListFindByName() which iterates over list of NWFilters, locking one by one, comparing names trying to find the desired one. Sooner or later it will try to lock the object that the other, original thread is redefining and which it holds locked. Now that thread can't continue either because it's waiting for the @updateMutex lock. So we end up in a typical deadlock situation, one thread holding lock A trying to acquire lock B, the other thread holding B and trying to acquire A. The solution is to unlock the virNWFilterObj in the first thread, just before triggering rebuild. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=3D2044379 Signed-off-by: Michal Privoznik --- I'm not sure this is 100% correct, but hey - it make that particular bug go away. src/conf/virnwfilterobj.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/conf/virnwfilterobj.c b/src/conf/virnwfilterobj.c index 6bbdf6e6fa..d6c2e59ce8 100644 --- a/src/conf/virnwfilterobj.c +++ b/src/conf/virnwfilterobj.c @@ -352,12 +352,17 @@ virNWFilterObjListAssignDef(virNWFilterObjList *nwfil= ters, } =20 obj->newDef =3D def; - /* trigger the update on VMs referencing the filter */ + + /* Trigger the update on VMs referencing the filter, but + * unlock the filter because rebuild will lock it again. */ + virNWFilterObjUnlock(obj); if (virNWFilterTriggerRebuild() < 0) { + virNWFilterObjLock(obj); obj->newDef =3D NULL; virNWFilterObjUnlock(obj); return NULL; } + virNWFilterObjLock(obj); =20 virNWFilterDefFree(objdef); obj->def =3D def; --=20 2.34.1