From nobody Sat May 4 00:11:05 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1509364187766214.36098986780007; Mon, 30 Oct 2017 04:49:47 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CFAFD7EA8E; Mon, 30 Oct 2017 11:49:45 +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 31865CBC62; Mon, 30 Oct 2017 11:49:45 +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 9CF7B1804480; Mon, 30 Oct 2017 11:49:43 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v9UBnfYB029978 for ; Mon, 30 Oct 2017 07:49:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id D58D9BC5ED; Mon, 30 Oct 2017 11:49:41 +0000 (UTC) Received: from mx1.redhat.com (ext-mx10.extmail.prod.ext.phx2.redhat.com [10.5.110.39]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D0C90BC5EC for ; Mon, 30 Oct 2017 11:49:40 +0000 (UTC) Received: from relay.sw.ru (mailhub.sw.ru [195.214.232.25]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9016F61460 for ; Mon, 30 Oct 2017 11:49:36 +0000 (UTC) Received: from dim-vz7.qa.sw.ru (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id v9UBnXNV018208 for ; Mon, 30 Oct 2017 14:49:34 +0300 (MSK) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CFAFD7EA8E Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=fail (p=none dis=none) header.from=virtuozzo.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com CFAFD7EA8E DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9016F61460 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=pass (p=none dis=none) header.from=virtuozzo.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=nshirokovskiy@virtuozzo.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 9016F61460 From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Mon, 30 Oct 2017 14:49:32 +0300 Message-Id: <1509364172-79169-1-git-send-email-nshirokovskiy@virtuozzo.com> X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 30 Oct 2017 11:49:38 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 30 Oct 2017 11:49:38 +0000 (UTC) for IP:'195.214.232.25' DOMAIN:'mailhub.sw.ru' HELO:'relay.sw.ru' FROM:'nshirokovskiy@virtuozzo.com' RCPT:'' X-RedHat-Spam-Score: -0.001 (SPF_PASS) 195.214.232.25 mailhub.sw.ru 195.214.232.25 mailhub.sw.ru X-Scanned-By: MIMEDefang 2.78 on 10.5.110.39 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] nwfilter: fix deadlock on firewalld restart/reload 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 30 Oct 2017 11:49:46 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Deadlock scenario: 1. domain is being started and domain driver takes read lock for nwfilter update lock thru virNWFilterReadLockFilterUpdates. 2. firewalld restarted and event loop hangs trying to take write lock for nwfilter update lock in nwfilterStateReload. This is deadlock because for thread 1 to proceed we need a response from qemu/timeout but whole event loop is stuck by 2. Let's just offload nwfilter driver reload to a distinct thread. Besides resolving a deadlock this change offloads rather heavy operation (many hypervisor drivers X many domains for a driver) off the event loop. --- Concrete stacktrace. Thread 17 (Thread 0x7fbd5a22d880 (LWP 7329)): 0 0x00007fbd56bb903e in pthread_rwlock_wrlock () from /lib64/libpthread.s= o.0 1 0x00007fbd3d511297 in nwfilterStateReload () from /usr/lib64/libvirt/co= nnection-driver/libvirt_driver_nwfilter.so 2 0x00007fbd3d511355 in nwfilterFirewalldDBusFilter () from /usr/lib64/li= bvirt/connection-driver/libvirt_driver_nwfilter.so 3 0x00007fbd57bc5dfe in dbus_connection_dispatch () from /lib64/libdbus-1= .so.3 4 0x00007fbd5953e641 in virDBusWatchCallback () from /lib64/libvirt.so.0 5 0x00007fbd5954868e in virEventPollRunOnce () from /lib64/libvirt.so.0 6 0x00007fbd59547942 in virEventRunDefaultImpl () from /lib64/libvirt.so.0 7 0x00007fbd596a94ed in virNetDaemonRun () from /lib64/libvirt.so.0 8 0x00007fbd5a28b07c in main () Thread 3 (Thread 0x7fbd49553700 (LWP 8029)): 0 0x00007fbd56bb96d5 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/lib= pthread.so.0 1 0x00007fbd59596816 in virCondWait () from /lib64/libvirt.so.0 2 0x00007fbd3d0183db in qemuMonitorSend () from /usr/lib64/libvirt/connec= tion-driver/libvirt_driver_qemu.so 3 0x00007fbd3d02c8d0 in qemuMonitorJSONCommandWithFd () from /usr/lib64/l= ibvirt/connection-driver/libvirt_driver_qemu.so 4 0x00007fbd3d02e1a1 in qemuMonitorJSONSetCapabilities () from /usr/lib64= /libvirt/connection-driver/libvirt_driver_qemu.so 5 0x00007fbd3cff965c in qemuConnectMonitor () from /usr/lib64/libvirt/con= nection-driver/libvirt_driver_qemu.so 6 0x00007fbd3cffcb70 in qemuProcessWaitForMonitor () from /usr/lib64/libv= irt/connection-driver/libvirt_driver_qemu.so 7 0x00007fbd3d004668 in qemuProcessLaunch () from /usr/lib64/libvirt/conn= ection-driver/libvirt_driver_qemu.so 8 0x00007fbd3d0062a8 in qemuProcessStart () from /usr/lib64/libvirt/conne= ction-driver/libvirt_driver_qemu.so 9 0x00007fbd3d0679cb in qemuDomainObjStart.constprop.50 () from /usr/lib6= 4/libvirt/connection-driver/libvirt_driver_qemu.so 10 0x00007fbd3d068106 in qemuDomainCreateWithFlags () from /usr/lib64/libv= irt/connection-driver/libvirt_driver_qemu.so 11 0x00007fbd5964247d in virDomainCreateWithFlags () from /lib64/libvirt.s= o.0 12 0x00007fbd5a2a3b81 in remoteDispatchDomainCreateWithFlagsHelper () 13 0x00007fbd596af3c3 in virNetServerProgramDispatch () from /lib64/libvir= t.so.0 14 0x00007fbd5a2c56cd in virNetServerHandleJob () 15 0x00007fbd59597221 in virThreadPoolWorker () from /lib64/libvirt.so.0 16 0x00007fbd595965a8 in virThreadHelper () from /lib64/libvirt.so.0 17 0x00007fbd56bb5dc5 in start_thread () from /lib64/libpthread.so.0 18 0x00007fbd568e473d in clone () from /lib64/libc.so.6 src/nwfilter/nwfilter_driver.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/nwfilter/nwfilter_driver.c b/src/nwfilter/nwfilter_driver.c index 2f9a51c..bcb4400 100644 --- a/src/nwfilter/nwfilter_driver.c +++ b/src/nwfilter/nwfilter_driver.c @@ -81,6 +81,12 @@ static void nwfilterDriverUnlock(void) =20 #if HAVE_FIREWALLD =20 +static void +nwfilterStateReloadAdapter(void *opaque ATTRIBUTE_UNUSED) +{ + nwfilterStateReload(); +} + static DBusHandlerResult nwfilterFirewalldDBusFilter(DBusConnection *connection ATTRIBUTE_UNUSED, DBusMessage *message, @@ -90,8 +96,12 @@ nwfilterFirewalldDBusFilter(DBusConnection *connection A= TTRIBUTE_UNUSED, "NameOwnerChanged") || dbus_message_is_signal(message, "org.fedoraproject.FirewallD1", "Reloaded")) { + virThread thread; + VIR_DEBUG("Reload in nwfilter_driver because of firewalld."); - nwfilterStateReload(); + if (virThreadCreate(&thread, false, nwfilterStateReloadAdapter, NU= LL) < 0) + VIR_ERROR(_("Could not create thread. Network filter " + "driver reload failed")); } =20 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list