From nobody Mon Feb 9 02:42:34 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=1681309563; cv=none; d=zohomail.com; s=zohoarc; b=gELalpbn2ehwu6PRqx/VZC20sNp9GQvSg3rC938EUOjdeUeFk92NMvhRNwLuncKRu2LKlWTBO3bydDIOT4TXXwWlw8SuEHihUkDz3e4HLKrF60s+6Rlaoq/vDrRYiwo3dFYu9v3IBQOHZ9mNdQrxUOb98YiKjtjYBkz65I9iwGk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681309563; 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=MOSgyFYPh3oTRU5ohtzXZDuSNeD7iNckxO3SxFOx2MA=; b=gGnQf7RG2EXvT7BFZBLjlc0NetGEshvebYToJpsoG9z52ChANDk2ZgHzjFdfiRCTmTe2pXRFPE3NhlKDKD1t9wxjyKLm3utqQI6y0gKEmjIy5IF+fLE1Gs6wOQ1hUxTQTLAK2OSOdUCC8Taye9odXuMlQmvR/xdn/jUH/zZiSEs= 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 1681309563207776.43332772752; Wed, 12 Apr 2023 07:26: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-660-QMAsRir2Nt2AVvN3L2qs4w-1; Wed, 12 Apr 2023 10:25:21 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EC91C8996FF; Wed, 12 Apr 2023 14:25:16 +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 C30062166B2D; Wed, 12 Apr 2023 14:25:16 +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 9D8D61946A62; Wed, 12 Apr 2023 14:25:16 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 935AD1946587 for ; Wed, 12 Apr 2023 14:25:15 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 79CAE2027EAE; Wed, 12 Apr 2023 14:25:15 +0000 (UTC) Received: from localhost.localdomain (unknown [10.45.226.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id 11068202717C for ; Wed, 12 Apr 2023 14:25:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681309562; 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=MOSgyFYPh3oTRU5ohtzXZDuSNeD7iNckxO3SxFOx2MA=; b=GPLDdGQwgwhQLzIVMHIaV+Yi1H7rxWHn6OP1pVsfpUWaPEI66tGHcGKuoSo52c95nlx+IN dGKQHmr4luNv+lkYWUiHbH9p6P7wUPYXbuySh+GmE8bGpJCSuBbqogVeqYdUBku7fkqr/s 4WY6XggPMMwt3aqN9w4tOiCRMPH0ZIg= X-MC-Unique: QMAsRir2Nt2AVvN3L2qs4w-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 4/5] qemuDomainRemoveChrDevice: Deal with qemuDomainChrRemove() failure Date: Wed, 12 Apr 2023 16:25:09 +0200 Message-Id: <944e105424fa001b99a0b655a64df187a6a410b1.1681307447.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 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: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 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: 1681309563820100001 Content-Type: text/plain; charset="utf-8"; x-default="true" When cleaning up after removed device, qemuDomainChrRemove() is called. But this may fail, in which case we successfully ignore the failure and virDomainChrDefFree() the device anyway. While it decreases our memory consumption, it's a bit too far, especially if the next step is 'virsh dumpxml'. Then our memory consumption decreases all the way down to zero as we crash. Signed-off-by: Michal Privoznik --- src/qemu/qemu_hotplug.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index a6407f074b..d9a102191f 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -4695,6 +4695,7 @@ qemuDomainRemoveChrDevice(virQEMUDriver *driver, virObjectEvent *event; g_autofree char *charAlias =3D NULL; qemuDomainObjPrivate *priv =3D vm->privateData; + virDomainChrDef *chrRemoved =3D NULL; int rc =3D 0; =20 VIR_DEBUG("Removing character device %s from domain %p %s", @@ -4728,17 +4729,24 @@ qemuDomainRemoveChrDevice(virQEMUDriver *driver, if (qemuDomainNamespaceTeardownChardev(vm, chr) < 0) VIR_WARN("Unable to remove chr device from /dev"); =20 - qemuDomainReleaseDeviceAddress(vm, &chr->info); - qemuDomainChrRemove(vm->def, chr); + if (!(chrRemoved =3D qemuDomainChrRemove(vm->def, chr))) { + /* At this point, we only have bad options. The device + * was successfully removed from QEMU, denied in CGropus, + * etc. and yet, we failed to remove it from domain + * definition. */ + VIR_WARN("Unable to remove chr device from domain definition"); + } else { + qemuDomainReleaseDeviceAddress(vm, &chrRemoved->info); =20 - /* The caller does not emit the event, so we must do it here. Note - * that the event should be reported only after all backend - * teardown is completed. - */ - event =3D virDomainEventDeviceRemovedNewFromObj(vm, chr->info.alias); - virObjectEventStateQueue(driver->domainEventState, event); + /* The caller does not emit the event, so we must do it here. Note + * that the event should be reported only after all backend + * teardown is completed. + */ + event =3D virDomainEventDeviceRemovedNewFromObj(vm, chrRemoved->in= fo.alias); + virObjectEventStateQueue(driver->domainEventState, event); =20 - virDomainChrDefFree(chr); + virDomainChrDefFree(chrRemoved); + } return 0; } =20 --=20 2.39.2