From nobody Mon Apr 28 17:41:45 2025 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=1618244629; cv=none; d=zohomail.com; s=zohoarc; b=HYuMTgR12Kgf7Hhng8gqlCiZEuU+Z9y38cooBHswxBwV3KATDmBIzjeJQC0F1pEjpUyVvVpOR7PxNi9IVIphM3dBU61uhh3U1DW2rbNKy7m+azsqVBE3u5DA7Ptpp3yDkgYUz5YolkPwyAuq5N8WLjGO0s5cRW8ChKLreYefZmk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618244629; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=XnVZVJdAqa2izTDOLDCEtHHb3g8xeUePXwb3CMGzf8I=; b=C4jfxbkaVlb3lF7XouHyJRS3G/g96Nzio6nOOoQjlEFjzGmqqhLq9Ah0U32OMz4hTX/M2fHVEqCNyOxWz/P1sWyFBiPVPFVBoosFiL0cZP64ALOFZcUgbRftuNGh7iey0qAHI5DWT/ECnrWfAaVp0fw6dgEb9wKhkmeJS0LOPfs= 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=<mprivozn@redhat.com> (p=none dis=none) header.from=<mprivozn@redhat.com> Return-Path: <libvir-list-bounces@redhat.com> 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 1618244629489402.9349186557398; Mon, 12 Apr 2021 09:23:49 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-376-MZYg3SKEO422IxgmQBK14A-1; Mon, 12 Apr 2021 12:23:45 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C6797195D561; Mon, 12 Apr 2021 16:23:40 +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 942CE100238C; Mon, 12 Apr 2021 16:23:40 +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 291A81806D0E; Mon, 12 Apr 2021 16:23:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 13CGMUGi004545 for <libvir-list@listman.util.phx.redhat.com>; Mon, 12 Apr 2021 12:22:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id A38FD2BFED; Mon, 12 Apr 2021 16:22:30 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.194.200]) by smtp.corp.redhat.com (Postfix) with ESMTP id 26DC66062F for <libvir-list@redhat.com>; Mon, 12 Apr 2021 16:22:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618244628; 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: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=XnVZVJdAqa2izTDOLDCEtHHb3g8xeUePXwb3CMGzf8I=; b=YRAul9Ab4ZiapMlWSwlIzd8z0Tct/wv+InquRvXDEfcqIfBhZf3cExl9Tz/CfC4eCLaxKC IoPn8Z0EVJR/eUkUACdTUbnYvjlBSAJ4ohAwEUghtjXJJWydC05NRhysQ4YTDZoLMGDRJU bLfW6l2tueEqE4UGP2Uejq8NlcPqlHQ= X-MC-Unique: MZYg3SKEO422IxgmQBK14A-1 From: Michal Privoznik <mprivozn@redhat.com> To: libvir-list@redhat.com Subject: [PATCH 1/5] nodedev: Unlock @priv if initialization of mdevctlMonitors fails Date: Mon, 12 Apr 2021 18:22:20 +0200 Message-Id: <229815098534c90f57a246bec42bab2a83469674.1618243050.git.mprivozn@redhat.com> In-Reply-To: <cover.1618243050.git.mprivozn@redhat.com> References: <cover.1618243050.git.mprivozn@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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 <libvir-list.redhat.com> List-Unsubscribe: <https://listman.redhat.com/mailman/options/libvir-list>, <mailto:libvir-list-request@redhat.com?subject=unsubscribe> List-Archive: <https://listman.redhat.com/archives/libvir-list> List-Post: <mailto:libvir-list@redhat.com> List-Help: <mailto:libvir-list-request@redhat.com?subject=help> List-Subscribe: <https://listman.redhat.com/mailman/listinfo/libvir-list>, <mailto:libvir-list-request@redhat.com?subject=subscribe> Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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) Content-Type: text/plain; charset="utf-8" If initialization of priv->mdevctlMonitors fails, then the control jumps over to cleanup label where nodeStateCleanup() is called which tries to lock @priv. But since @priv was already locked before taking the jump a deadlock occurs. The solution is to jump onto @unlock label, just like the code around is doing. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Pavel Hrdina <phrdina@redhat.com> --- src/node_device/node_device_udev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 7d4e8f5c0b..04e1094e21 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -2274,7 +2274,7 @@ nodeStateInitialize(bool privileged, if (!(priv->mdevctlMonitors =3D monitorFileRecursively(priv, mdevctlConfigDir)= )) { virMutexUnlock(&priv->mdevctlLock); - goto cleanup; + goto unlock; } virMutexUnlock(&priv->mdevctlLock); =20 --=20 2.26.3 From nobody Mon Apr 28 17:41:45 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1618244732; cv=none; d=zohomail.com; s=zohoarc; b=d1nfGCnixqI0EVYYl8lkxPNPDqkQCmdFQNgm3l8xbtjIO55/jXNI5ib6osQBRW70lrJAmF/aW6A+E78HALcHodQbYD9Qg777j7KoYDjYjGBJHn6aChk7on9med+TrJsiuONHRzCYkeRhYGCsSMgMoRqsqm6tEfBmsRtw/77DOHg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618244732; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ndy6a4tGguR6ZbZ68hU5HPFY8EdODWyGLQ9virnqwGE=; b=RRwD4NIBcRMBvGb+4sWAbxTrqkDZdW4iVh8Hd2lLn6VvHTWxhl3gwQ4+Z95s8DrsH/Rfg1Bp17OhG7PRj6Ht/WZGZQXK/NxreFjBID59J3nGac+taFPY/uukuqE9caS2pnTsA3z++XN6n5KutZWu9F4bI3Q+g42N+SYVvtFeHp8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from=<mprivozn@redhat.com> (p=none dis=none) header.from=<mprivozn@redhat.com> Return-Path: <libvir-list-bounces@redhat.com> Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1618244732934345.45268534786544; Mon, 12 Apr 2021 09:25:32 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-83-hWA54AYjNrqkLEbyzs2b9g-1; Mon, 12 Apr 2021 12:25:29 -0400 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 374EA87A83F; Mon, 12 Apr 2021 16:25:23 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 149345D6DC; Mon, 12 Apr 2021 16:25:23 +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 CC99944A5B; Mon, 12 Apr 2021 16:25:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 13CGMVnN004557 for <libvir-list@listman.util.phx.redhat.com>; Mon, 12 Apr 2021 12:22:31 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7B4F22BFED; Mon, 12 Apr 2021 16:22:31 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.194.200]) by smtp.corp.redhat.com (Postfix) with ESMTP id F399E50DE3 for <libvir-list@redhat.com>; Mon, 12 Apr 2021 16:22:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618244731; 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: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=ndy6a4tGguR6ZbZ68hU5HPFY8EdODWyGLQ9virnqwGE=; b=ZfuZ3CGu/A+Z3wkvxUkAp+rM2ZoJWFP2SyXFnBFj0Uy0964Qd/M+zkvx5a7dV8BwQaNxDB yBiQc1KNryIMhcBoghuO0Abjy1d3oDrFr5S8RvRsN1yOcDoq88C/gZyQLDC6StQPjbGB6y 4btXgKgKYdmWlEh04CCjWNAuvmSQIj0= X-MC-Unique: hWA54AYjNrqkLEbyzs2b9g-1 From: Michal Privoznik <mprivozn@redhat.com> To: libvir-list@redhat.com Subject: [PATCH 2/5] nodedev: Lock @priv sooner Date: Mon, 12 Apr 2021 18:22:21 +0200 Message-Id: <12e2e6395094fbd25507eacd37929fc15496fbce.1618243050.git.mprivozn@redhat.com> In-Reply-To: <cover.1618243050.git.mprivozn@redhat.com> References: <cover.1618243050.git.mprivozn@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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 <libvir-list.redhat.com> List-Unsubscribe: <https://listman.redhat.com/mailman/options/libvir-list>, <mailto:libvir-list-request@redhat.com?subject=unsubscribe> List-Archive: <https://listman.redhat.com/archives/libvir-list> List-Post: <mailto:libvir-list@redhat.com> List-Help: <mailto:libvir-list-request@redhat.com?subject=help> List-Subscribe: <https://listman.redhat.com/mailman/listinfo/libvir-list>, <mailto:libvir-list-request@redhat.com?subject=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) Content-Type: text/plain; charset="utf-8" The nodedev driver private data object @priv is created by calling udevEventDataNew(). After that, driver->privateData pointer is set to the freshly allocated object and only a few lines after all of this the object is locked. Technically it is safe because there should not be any other thread at this point, but defensive style of programming says it's better if the object is locked before driver's privateData is set. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Pavel Hrdina <phrdina@redhat.com> --- src/node_device/node_device_udev.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 04e1094e21..da3754ff80 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -2212,21 +2212,21 @@ nodeStateInitialize(bool privileged, !(priv =3D udevEventDataNew())) goto cleanup; =20 + virObjectLock(priv); + driver->privateData =3D priv; driver->nodeDeviceEventState =3D virObjectEventStateNew(); =20 if (udevPCITranslateInit(privileged) < 0) - goto cleanup; + goto unlock; =20 udev =3D udev_new(); if (!udev) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("failed to create udev context")); - goto cleanup; + goto unlock; } =20 - virObjectLock(priv); - priv->udev_monitor =3D udev_monitor_new_from_netlink(udev, "udev"); if (!priv->udev_monitor) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", --=20 2.26.3 From nobody Mon Apr 28 17:41:45 2025 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=1618244636; cv=none; d=zohomail.com; s=zohoarc; b=mFlLTGYO7NFLWLliOvCkSXfWebwadhu9Ic3dfRe1vWoBeuQzqw6EOzzrm02sxBO2MtnKxbjbQhBrLHlAM0+l3SqX4Qplfo83ie+M9XpQcNSS8N0QtkRSUgil0KRF71Chr/mUCVieAfYds+PXDoVsNhDjiMUjpzJaJTqHE/24eZc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618244636; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=QH5f3rgSSHfzAOHOZ2ZkfUQEo4r4vroWqUH+bjuTb2M=; b=Qa5GAA28v/RXpKH9G06TFmpvKg9A7Tqth5Jf4kIdGYOmjaX1SzNdnfTEPySbTbLiynNn3GyUhvwxEfaqEJsEpm5MIQlWI7Rif7J10MOEWi3LykYSwe4XjQBeSqPNfRh0fnu2639zqxmRJJrNoeGgtTmbqmfPYtKrKJavQuKpo7g= 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=<mprivozn@redhat.com> (p=none dis=none) header.from=<mprivozn@redhat.com> Return-Path: <libvir-list-bounces@redhat.com> 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 1618244636915217.5299371383593; Mon, 12 Apr 2021 09:23:56 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-326-O81tZdSLPxOexE4aI9du-g-1; Mon, 12 Apr 2021 12:23:53 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BEF4C81746C; Mon, 12 Apr 2021 16:23:48 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9AD9959468; Mon, 12 Apr 2021 16:23:48 +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 56C7644A60; Mon, 12 Apr 2021 16:23:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 13CGMWn9004562 for <libvir-list@listman.util.phx.redhat.com>; Mon, 12 Apr 2021 12:22:32 -0400 Received: by smtp.corp.redhat.com (Postfix) id 543F650DE3; Mon, 12 Apr 2021 16:22:32 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.194.200]) by smtp.corp.redhat.com (Postfix) with ESMTP id CBD076062F for <libvir-list@redhat.com>; Mon, 12 Apr 2021 16:22:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618244635; 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: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=QH5f3rgSSHfzAOHOZ2ZkfUQEo4r4vroWqUH+bjuTb2M=; b=d3VFRRlhamuXhlzclWcLjkFFOIEWJajx4NIs2hgNOUEIAlwmtMrf8mu5kkILXxq8GOfYRT Q2or2Vy1PzZImFV7PQ/lB2LBbVHCBH08Srg9jBhNodP6MLWWmMl6GLEnP19pBNoZSlrIdb ug8wGBYQ7/NOmvsbXad2fSQXOKqXvDY= X-MC-Unique: O81tZdSLPxOexE4aI9du-g-1 From: Michal Privoznik <mprivozn@redhat.com> To: libvir-list@redhat.com Subject: [PATCH 3/5] nodedev: Don't join not spawned threads Date: Mon, 12 Apr 2021 18:22:22 +0200 Message-Id: <66d66227264fd9b5af311457f75980aab0979e3e.1618243050.git.mprivozn@redhat.com> In-Reply-To: <cover.1618243050.git.mprivozn@redhat.com> References: <cover.1618243050.git.mprivozn@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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 <libvir-list.redhat.com> List-Unsubscribe: <https://listman.redhat.com/mailman/options/libvir-list>, <mailto:libvir-list-request@redhat.com?subject=unsubscribe> List-Archive: <https://listman.redhat.com/archives/libvir-list> List-Post: <mailto:libvir-list@redhat.com> List-Help: <mailto:libvir-list-request@redhat.com?subject=help> List-Subscribe: <https://listman.redhat.com/mailman/listinfo/libvir-list>, <mailto:libvir-list-request@redhat.com?subject=subscribe> Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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) Content-Type: text/plain; charset="utf-8" During the nodedev driver initialization two threads are created: one for listening on udev events (like device plug/unplug) and the other for enumerating devices (so that the main thread doing the driver init is not blocked). If something goes wrong at any point then nodeStateCleanup() is called which joins those two threads (possibly) created before. But it tries to join them even they weren't created which is undefined behaviour (and it just so happens that it crashes on my system). If those two virThread variables are turned into pointers then we can use comparison against NULL to detect whether threads were created. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Pavel Hrdina <phrdina@redhat.com> --- src/node_device/node_device_udev.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index da3754ff80..3e9c7a8d80 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -63,13 +63,13 @@ struct _udevEventData { int watch; =20 /* Thread data */ - virThread th; + virThread *th; virCond threadCond; bool threadQuit; bool dataReady; =20 /* init thread */ - virThread initThread; + virThread *initThread; =20 GList *mdevctlMonitors; virMutex mdevctlLock; @@ -1685,8 +1685,14 @@ nodeStateCleanup(void) priv->threadQuit =3D true; virCondSignal(&priv->threadCond); virObjectUnlock(priv); - virThreadJoin(&priv->initThread); - virThreadJoin(&priv->th); + if (priv->initThread) { + virThreadJoin(priv->initThread); + g_clear_pointer(&priv->initThread, g_free); + } + if (priv->th) { + virThreadJoin(priv->th); + g_clear_pointer(&priv->th, g_free); + } } =20 virObjectUnref(priv); @@ -2243,10 +2249,12 @@ nodeStateInitialize(bool privileged, udev_monitor_set_receive_buffer_size(priv->udev_monitor, 128 * 1024 * 1024); =20 - if (virThreadCreateFull(&priv->th, true, udevEventHandleThread, + priv->th =3D g_new0(virThread, 1); + if (virThreadCreateFull(priv->th, true, udevEventHandleThread, "udev-event", false, NULL) < 0) { virReportSystemError(errno, "%s", _("failed to create udev handler thread")); + g_clear_pointer(&priv->th, g_free); goto unlock; } =20 @@ -2284,10 +2292,12 @@ nodeStateInitialize(bool privileged, if (udevSetupSystemDev() !=3D 0) goto cleanup; =20 - if (virThreadCreateFull(&priv->initThread, true, nodeStateInitializeEn= umerate, + priv->initThread =3D g_new0(virThread, 1); + if (virThreadCreateFull(priv->initThread, true, nodeStateInitializeEnu= merate, "nodedev-init", false, udev) < 0) { virReportSystemError(errno, "%s", _("failed to create udev enumerate thread")); + g_clear_pointer(&priv->initThread, g_free); goto cleanup; } =20 --=20 2.26.3 From nobody Mon Apr 28 17:41:45 2025 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=1618244745; cv=none; d=zohomail.com; s=zohoarc; b=XHW3lKpUytrErSAzHpnxVPcTIHi6ACbono1UaVWXEnli5hWte9hugQuSHVWBGNSH8p50FAYETnEHInRGtg0PsX+uQkEOFw9cGq1VnHQOa1VAl6BoarWem4EoYagkikN5Z58T2xqmpBtFPj7G2FOb1hNnqA99V1cCFjW7N/9IqJc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618244745; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=f/ph8nLyqpzT+uBi7XVemDKQ1U/rMHbKRUn8KohbAbw=; b=RpHfnZokCANZZ+wTFoQhczQXtY/cnqjgmue4y6rZGRdlYBSeeiitB+/q4nWpbb0QXHBouhaMGfxG47TBmTmerLCvz7vPtO1BTovjejpypSQZG+xR4Cvnq5elcRLwm40/8CU66LKVAFP+S4fHi3a8R2EkAIfPGx5tUnFSl2O+Gac= 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=<mprivozn@redhat.com> (p=none dis=none) header.from=<mprivozn@redhat.com> Return-Path: <libvir-list-bounces@redhat.com> 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 1618244745721452.4332995302069; Mon, 12 Apr 2021 09:25:45 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-162-kJMOl66YP2yDbpabGG4gXw-1; Mon, 12 Apr 2021 12:25:42 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3B19F87A826; Mon, 12 Apr 2021 16:25:37 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 16DE85D9DE; Mon, 12 Apr 2021 16:25:37 +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 D278E44A60; Mon, 12 Apr 2021 16:25:36 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 13CGMXIp004572 for <libvir-list@listman.util.phx.redhat.com>; Mon, 12 Apr 2021 12:22:33 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2C5D550DE3; Mon, 12 Apr 2021 16:22:33 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.194.200]) by smtp.corp.redhat.com (Postfix) with ESMTP id A48496062F for <libvir-list@redhat.com>; Mon, 12 Apr 2021 16:22:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618244744; 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: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=f/ph8nLyqpzT+uBi7XVemDKQ1U/rMHbKRUn8KohbAbw=; b=gpDX53wumOmxpsKg81q5Rslo/Bq9uD2zM/z8Lj1Wq5w+2ebxL04xo+pmQnGdyWhEQ6JJp4 C5MqqvUvcjWuQkZ4NbRitPkNZ12oXDXB7zIzCk0u1BW4FbQe9CKja+btDHG43rGXuiYhUZ Fw9bneFsQAqo+Y+LlCe7i60lb7eM8iA= X-MC-Unique: kJMOl66YP2yDbpabGG4gXw-1 From: Michal Privoznik <mprivozn@redhat.com> To: libvir-list@redhat.com Subject: [PATCH 4/5] nodedev: Separate mdevctl monitor setup into a function Date: Mon, 12 Apr 2021 18:22:23 +0200 Message-Id: <0752102c7000e1d5cdfa2e3f3d36dbbab0e7d9cb.1618243050.git.mprivozn@redhat.com> In-Reply-To: <cover.1618243050.git.mprivozn@redhat.com> References: <cover.1618243050.git.mprivozn@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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 <libvir-list.redhat.com> List-Unsubscribe: <https://listman.redhat.com/mailman/options/libvir-list>, <mailto:libvir-list-request@redhat.com?subject=unsubscribe> List-Archive: <https://listman.redhat.com/archives/libvir-list> List-Post: <mailto:libvir-list@redhat.com> List-Help: <mailto:libvir-list-request@redhat.com?subject=help> List-Subscribe: <https://listman.redhat.com/mailman/listinfo/libvir-list>, <mailto:libvir-list-request@redhat.com?subject=subscribe> Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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) Content-Type: text/plain; charset="utf-8" Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Pavel Hrdina <phrdina@redhat.com> --- src/node_device/node_device_udev.c | 37 +++++++++++++++++++----------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 3e9c7a8d80..18219175c5 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -2119,6 +2119,29 @@ monitorFileRecursively(udevEventData *udev, } =20 =20 +static int +mdevctlEnableMonitor(udevEventData *priv) +{ + g_autoptr(GFile) mdevctlConfigDir =3D g_file_new_for_path("/etc/mdevct= l.d"); + + /* mdevctl may add notification events in the future: + * https://github.com/mdevctl/mdevctl/issues/27. For now, fall back to + * monitoring the mdevctl configuration directory for changes. + * mdevctl configuration is stored in a directory tree within + * /etc/mdevctl.d/. There is a directory for each parent device, which + * contains a file defining each mediated device */ + virMutexLock(&priv->mdevctlLock); + if (!(priv->mdevctlMonitors =3D monitorFileRecursively(priv, + mdevctlConfigDir)= )) { + virMutexUnlock(&priv->mdevctlLock); + return -1; + } + virMutexUnlock(&priv->mdevctlLock); + + return 0; +} + + static void mdevctlEventHandleCallback(GFileMonitor *monitor G_GNUC_UNUSED, GFile *file, @@ -2168,7 +2191,6 @@ nodeStateInitialize(bool privileged, { udevEventDataPtr priv =3D NULL; struct udev *udev =3D NULL; - g_autoptr(GFile) mdevctlConfigDir =3D g_file_new_for_path("/etc/mdevct= l.d"); =20 if (root !=3D NULL) { virReportError(VIR_ERR_INVALID_ARG, "%s", @@ -2272,19 +2294,8 @@ nodeStateInitialize(bool privileged, if (priv->watch =3D=3D -1) goto unlock; =20 - /* mdevctl may add notification events in the future: - * https://github.com/mdevctl/mdevctl/issues/27. For now, fall back to - * monitoring the mdevctl configuration directory for changes. - * mdevctl configuration is stored in a directory tree within - * /etc/mdevctl.d/. There is a directory for each parent device, which - * contains a file defining each mediated device */ - virMutexLock(&priv->mdevctlLock); - if (!(priv->mdevctlMonitors =3D monitorFileRecursively(priv, - mdevctlConfigDir)= )) { - virMutexUnlock(&priv->mdevctlLock); + if (mdevctlEnableMonitor(priv) < 0) goto unlock; - } - virMutexUnlock(&priv->mdevctlLock); =20 virObjectUnlock(priv); =20 --=20 2.26.3 From nobody Mon Apr 28 17:41:45 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1618244750; cv=none; d=zohomail.com; s=zohoarc; b=GMC7HG9s3a9vIBQW4PaN9KAVGtyTJ4MaA3XZwYU5fIimdJ/SaocgQosVjKMU7xEfLCe2B9ChBs+psdM7k5WX3C5gmB9WRZR2VL+gGiHMRNtR66jjQDwPJzrc2rErjyrraPOGsAIRn++tOagdiVUZxivXz0h9ChQMReFwGffuVg0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618244750; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=X3hrrLJc9f3KljFBkROsUHE2OAudWrP0S76LqXF8U54=; b=QAGb8qc29zvFGQbg4+5WfI4VuQ1q+x0W+s18LCdTlSzJrfhYpJ+E6eEWmEkOyO+dPBapb7Kg+uNk2PsUzu941e+sq5fi1lyJO2E7rOLZuxbnHZIviWj2wA90AD3do1gtBd5+RXrQJT33821ZBS/Ck8oJRVO18JatQTkUX39uVD4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from=<mprivozn@redhat.com> (p=none dis=none) header.from=<mprivozn@redhat.com> Return-Path: <libvir-list-bounces@redhat.com> Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1618244750797666.9170626917978; Mon, 12 Apr 2021 09:25:50 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-353-dytpygw_NLq1YTVMPyy_aQ-1; Mon, 12 Apr 2021 12:25:47 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6D12B107ACF5; Mon, 12 Apr 2021 16:25:40 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3939419D7C; Mon, 12 Apr 2021 16:25:40 +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 EF66A44A6D; Mon, 12 Apr 2021 16:25:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 13CGMYxE004580 for <libvir-list@listman.util.phx.redhat.com>; Mon, 12 Apr 2021 12:22:34 -0400 Received: by smtp.corp.redhat.com (Postfix) id 050B750DE3; Mon, 12 Apr 2021 16:22:34 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.194.200]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7D75E6062F for <libvir-list@redhat.com>; Mon, 12 Apr 2021 16:22:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618244749; 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: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=X3hrrLJc9f3KljFBkROsUHE2OAudWrP0S76LqXF8U54=; b=C62wAxLfOTo57T1ioMEdEYKCZymQSFPUBVWOWLxnfyXIoookEdBB1zGqjMeohg/XNzhScN /7c4/5brMcgC416NlcIULZYNUD2I3bmJERlapHyUOM07cNQqqwF/Nb831esgu3YYIbmzAa Ck13W8oN6hy01t+yAGWCXNRgInUVbrw= X-MC-Unique: dytpygw_NLq1YTVMPyy_aQ-1 From: Michal Privoznik <mprivozn@redhat.com> To: libvir-list@redhat.com Subject: [PATCH 5/5] nodedev: Only set up mdevctl monitors if mdevctl.d exist Date: Mon, 12 Apr 2021 18:22:24 +0200 Message-Id: <38b976c5c3d9567b64c1214823de120c15cf5273.1618243050.git.mprivozn@redhat.com> In-Reply-To: <cover.1618243050.git.mprivozn@redhat.com> References: <cover.1618243050.git.mprivozn@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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 <libvir-list.redhat.com> List-Unsubscribe: <https://listman.redhat.com/mailman/options/libvir-list>, <mailto:libvir-list-request@redhat.com?subject=unsubscribe> List-Archive: <https://listman.redhat.com/archives/libvir-list> List-Post: <mailto:libvir-list@redhat.com> List-Help: <mailto:libvir-list-request@redhat.com?subject=help> List-Subscribe: <https://listman.redhat.com/mailman/listinfo/libvir-list>, <mailto:libvir-list-request@redhat.com?subject=subscribe> Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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) Content-Type: text/plain; charset="utf-8" During its initialization, the nodedev driver tries to set up monitors for /etc/mdevctl.d directory, so that it can register mdevs as they come and go. However, if the file doesn't exist there is nothing to monitor and therefore we can exit early. In fact, we have to otherwise monitorFileRecursively() fails and whole driver initialization fails with it. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Pavel Hrdina <phrdina@redhat.com> --- src/node_device/node_device_udev.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 18219175c5..c4040c2fd6 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -2122,7 +2122,13 @@ monitorFileRecursively(udevEventData *udev, static int mdevctlEnableMonitor(udevEventData *priv) { - g_autoptr(GFile) mdevctlConfigDir =3D g_file_new_for_path("/etc/mdevct= l.d"); + g_autoptr(GFile) mdevctlConfigDir =3D NULL; + const char *mdevctlDir =3D "/etc/mdevctl.d"; + + if (!virFileExists(mdevctlDir)) + return 0; + + mdevctlConfigDir =3D g_file_new_for_path("/etc/mdevctl.d"); =20 /* mdevctl may add notification events in the future: * https://github.com/mdevctl/mdevctl/issues/27. For now, fall back to --=20 2.26.3