From nobody Thu May 2 23:01:07 2024 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; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: 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 1613746457503381.7476607150022; Fri, 19 Feb 2021 06:54:17 -0800 (PST) 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-119-ZM9WNaZ7M8OyX0MFFereEg-1; Fri, 19 Feb 2021 09:54:13 -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 B06F91005501; Fri, 19 Feb 2021 14:54:06 +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 E8BA45D720; Fri, 19 Feb 2021 14:54:05 +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 225A818095CB; Fri, 19 Feb 2021 14:54:04 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 11JEnmVo032598 for ; Fri, 19 Feb 2021 09:49:49 -0500 Received: by smtp.corp.redhat.com (Postfix) id CB46020CA487; Fri, 19 Feb 2021 14:49:48 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast05.extmail.prod.ext.rdu2.redhat.com [10.11.55.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C550120CA486 for ; Fri, 19 Feb 2021 14:49:44 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EA134803903 for ; Fri, 19 Feb 2021 14:49:43 +0000 (UTC) Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-476-Kye9fNqgOQmnfIcq099FcA-1; Fri, 19 Feb 2021 09:49:41 -0500 Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 11JEWFHP191399; Fri, 19 Feb 2021 09:49:41 -0500 Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 36tew0s4e1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Feb 2021 09:49:40 -0500 Received: from m0098414.ppops.net (m0098414.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 11JEiQ9P043992; Fri, 19 Feb 2021 09:49:40 -0500 Received: from ppma04dal.us.ibm.com (7a.29.35a9.ip4.static.sl-reverse.com [169.53.41.122]) by mx0b-001b2d01.pphosted.com with ESMTP id 36tew0s4dp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Feb 2021 09:49:40 -0500 Received: from pps.filterd (ppma04dal.us.ibm.com [127.0.0.1]) by ppma04dal.us.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 11JEmD31012275; Fri, 19 Feb 2021 14:49:39 GMT Received: from b03cxnp08028.gho.boulder.ibm.com (b03cxnp08028.gho.boulder.ibm.com [9.17.130.20]) by ppma04dal.us.ibm.com with ESMTP id 36p6da9mjy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Feb 2021 14:49:39 +0000 Received: from b03ledav005.gho.boulder.ibm.com (b03ledav005.gho.boulder.ibm.com [9.17.130.236]) by b03cxnp08028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 11JEncoN37093850 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Feb 2021 14:49:38 GMT Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7D161BE051; Fri, 19 Feb 2021 14:49:38 +0000 (GMT) Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E5FD5BE04F; Fri, 19 Feb 2021 14:49:37 +0000 (GMT) Received: from sbct-3.pok.ibm.com (unknown [9.47.158.153]) by b03ledav005.gho.boulder.ibm.com (Postfix) with ESMTP; Fri, 19 Feb 2021 14:49:37 +0000 (GMT) X-MC-Unique: ZM9WNaZ7M8OyX0MFFereEg-1 X-MC-Unique: Kye9fNqgOQmnfIcq099FcA-1 From: Stefan Berger To: libvir-list@redhat.com Subject: [PATCH] qemu: Fix libvirt hang due to early TPM device stop Date: Fri, 19 Feb 2021 09:49:36 -0500 Message-Id: <20210219144936.2416060-1-stefanb@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.369, 18.0.761 definitions=2021-02-19_05:2021-02-18, 2021-02-19 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 mlxlogscore=774 priorityscore=1501 mlxscore=0 bulkscore=0 adultscore=0 lowpriorityscore=0 spamscore=0 malwarescore=0 clxscore=1011 impostorscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2102190112 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: libvir-list@redhat.com Cc: Masayoshi Mizuma , marcandre.lureau@redhat.com, Stefan Berger , mprivozn@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 Content-Type: text/plain; charset="utf-8" This patch partially reverts commit 5cde9dee where the qemuExtDevicesStop() was moved to a location before the QEMU process is stopped. It may be alright to tear down some devices before QEMU is stopped, but it doesn't wo= rk for the external TPM (swtpm) which assumes that QEMU sends it a signal to s= top it before libvirt may try to clean it up. So this patch introduces a functi= on qemuExtDevicesStopEarly() to accommodate those devices that can/must be torn down early, which seems to be the case with virtio and its virtiofs= d, and recreates the location of the call to qemuExtDevicesStop() from before = the regression for all other devices. Fixes: 5cde9dee8c70b17c458d031ab6cf71dce476eea2 Cc: Masayoshi Mizuma Signed-off-by: Stefan Berger --- src/qemu/qemu_extdevice.c | 27 ++++++++++++++++++++------- src/qemu/qemu_extdevice.h | 4 ++++ src/qemu/qemu_process.c | 5 ++++- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/qemu/qemu_extdevice.c b/src/qemu/qemu_extdevice.c index 8fe7ceaa10..96fdc9a589 100644 --- a/src/qemu/qemu_extdevice.c +++ b/src/qemu/qemu_extdevice.c @@ -205,7 +205,27 @@ qemuExtDevicesStart(virQEMUDriverPtr driver, return 0; } =20 +/* qemuExtDevicesStopEarly stops devices that may be stopped + * before QEMU terminates + */ +void +qemuExtDevicesStopEarly(virQEMUDriverPtr driver, + virDomainObjPtr vm) +{ + virDomainDefPtr def =3D vm->def; + size_t i; =20 + for (i =3D 0; i < def->nfss; i++) { + virDomainFSDefPtr fs =3D def->fss[i]; + + if (fs->fsdriver =3D=3D VIR_DOMAIN_FS_DRIVER_TYPE_VIRTIOFS) + qemuVirtioFSStop(driver, vm, fs); + } +} + +/* qemuExtDevicesStop stops devices that may only be stopped + * after QEMU terminated + */ void qemuExtDevicesStop(virQEMUDriverPtr driver, virDomainObjPtr vm) @@ -236,13 +256,6 @@ qemuExtDevicesStop(virQEMUDriverPtr driver, if (actualType =3D=3D VIR_DOMAIN_NET_TYPE_ETHERNET && net->downscr= ipt) virNetDevRunEthernetScript(net->ifname, net->downscript); } - - for (i =3D 0; i < def->nfss; i++) { - virDomainFSDefPtr fs =3D def->fss[i]; - - if (fs->fsdriver =3D=3D VIR_DOMAIN_FS_DRIVER_TYPE_VIRTIOFS) - qemuVirtioFSStop(driver, vm, fs); - } } =20 =20 diff --git a/src/qemu/qemu_extdevice.h b/src/qemu/qemu_extdevice.h index 49373a15a1..df0cbd6993 100644 --- a/src/qemu/qemu_extdevice.h +++ b/src/qemu/qemu_extdevice.h @@ -51,6 +51,10 @@ int qemuExtDevicesStart(virQEMUDriverPtr driver, ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT; =20 +void qemuExtDevicesStopEarly(virQEMUDriverPtr driver, + virDomainObjPtr vm) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); + void qemuExtDevicesStop(virQEMUDriverPtr driver, virDomainObjPtr vm) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 7feb35e609..b5b2ddef4c 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -7659,7 +7659,7 @@ void qemuProcessStop(virQEMUDriverPtr driver, /* Do this before we delete the tree and remove pidfile. */ qemuProcessKillManagedPRDaemon(vm); =20 - qemuExtDevicesStop(driver, vm); + qemuExtDevicesStopEarly(driver, vm); =20 virFileDeleteTree(priv->libDir); virFileDeleteTree(priv->channelTargetDir); @@ -7677,6 +7677,9 @@ void qemuProcessStop(virQEMUDriverPtr driver, =20 qemuDomainCleanupRun(driver, vm); =20 + /* tear down external devices after QEMU is gone */ + qemuExtDevicesStop(driver, vm); + qemuDBusStop(driver, vm); =20 vm->def->id =3D -1; --=20 2.26.2