From nobody Mon Feb 9 09:29:06 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=1635493241; cv=none; d=zohomail.com; s=zohoarc; b=OL+XU+jSzl5WG+nYJfrwWBgOAmSHkeT2b5Gumit7bVmWHfOyKQcE+I8aZ/eITS+ZS867NNjY+vhPqhZN9Q3gbr6UBGkAm142iJ5QaRNpqGudGfsQum5kP6oPZpT4EuBcr9e0kUkZ5p8k6S231Ne16psubD5562l2pWU+mWlEX54= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1635493241; 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=ArPUouMv6ut1wI6OQGbWAxSp0xbFf0jYXCsx3xJoDuI=; b=RtN+CYDGI5E41Ga0v95E5Aot1L4SJNhJkOUstU6vEI+SmvenxB9BS2k5q5ttG4dudDjJl363oA2gRiMJqd9uCli+TsUSUQq4MRxuifqCNnf/Sb0ZSKtSHm7gbY5oXzxxH1uqGOfxJoMMC7t0HJzwLM0UtkYk94xCOXrDuq2JT58= 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 1635493241475889.3018973269891; Fri, 29 Oct 2021 00:40:41 -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-476-MtBuQ8WYN0Ka5Hg0RIrHig-1; Fri, 29 Oct 2021 03:40:38 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 83BF610A8E07; Fri, 29 Oct 2021 07:40:33 +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 5FDAE60BF1; Fri, 29 Oct 2021 07:40:33 +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 EE1FB1806D04; Fri, 29 Oct 2021 07:40:32 +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 19T7eUX7011000 for ; Fri, 29 Oct 2021 03:40:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9A171652AC; Fri, 29 Oct 2021 07:40:30 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id EBFE51981F for ; Fri, 29 Oct 2021 07:40:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635493240; 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=ArPUouMv6ut1wI6OQGbWAxSp0xbFf0jYXCsx3xJoDuI=; b=EraV1LvpELhzhS6G4p/hF6CxaVXOhgsGZZ/AxgHbfuufLlOAGOg7c8te66dz8pMA1K7SKJ 5Xf7XwJYtJpt5alLIRb61lvXhlfcpOyFKJH/J6MoYtblH0xwPL0I6p4bPGTfCCdUhKnPiD LCrnjsii4wbi+z/WOL8WaYLPlz/aQVI= X-MC-Unique: MtBuQ8WYN0Ka5Hg0RIrHig-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 1/4] qemu_agent: Rework domain object locking when opening agent Date: Fri, 29 Oct 2021 09:40:20 +0200 Message-Id: In-Reply-To: References: 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 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.12 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: 1635493242286100003 Content-Type: text/plain; charset="utf-8" Just like qemuMonitorOpen(), hold the domain object locked throughout the whole time of qemuConnectAgent() and unlock it only for a brief time of actual connect() (because this is the only part that has a potential of blocking). The reason is that qemuAgentOpen() does access domain object (well, its privateData) AND also at least one argument (@context) depends on domain object. Accessing these without the lock is potentially dangerous. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=3D1845468#c12 Signed-off-by: Michal Privoznik --- src/qemu/qemu_agent.c | 3 +++ src/qemu/qemu_process.c | 4 ---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index 5f421be6f6..166cfaf485 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -704,7 +704,10 @@ qemuAgentOpen(virDomainObj *vm, goto cleanup; } =20 + virObjectUnlock(vm); agent->fd =3D qemuAgentOpenUnix(config->data.nix.path); + virObjectLock(vm); + if (agent->fd =3D=3D -1) goto cleanup; =20 diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index d5f8a47ac2..d2ea9b55fe 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -238,16 +238,12 @@ qemuConnectAgent(virQEMUDriver *driver, virDomainObj = *vm) * deleted while the agent is active */ virObjectRef(vm); =20 - virObjectUnlock(vm); - agent =3D qemuAgentOpen(vm, config->source, virEventThreadGetContext(priv->eventThread), &agentCallbacks, virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_VSERPOR= T_CHANGE)); =20 - virObjectLock(vm); - if (agent =3D=3D NULL) virObjectUnref(vm); =20 --=20 2.32.0