From nobody Mon Sep 14 04:47:39 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 38.145.34.151 as permitted sender) client-ip=38.145.34.151; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 38.145.34.151 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1787948284; cv=none; d=zohomail.com; s=zohoarc; b=hGVMRckV5fR2MiqW9wG7xF4fW6izOF20nBrEm/mzSKuQjwLwSZOtBX/3wxGzokg8ya+XQ2cI465seWPrRxlbS9rAwe24NM9vhcSmPJ2ldTF0+mHXjZPagFsBISdZgwtvdJRZyjchYGWj5A6mc/k1HVz/yaxm5jhbQQqp8kNzI/I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787948284; h=Content-Transfer-Encoding:Date:Date:From:From:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:Subject:Subject:To:To:Message-Id:Cc; bh=aPS7iQlQMP6vxrifgVKYVpPZnMRXCihXiObCa2/hJRY=; b=B+wj0NXvRHiCyxMrfybjEB75l/LDp15tKb9l/0daKN2tU1AjUy7xi3g42Z60EVJLVsfVcfHwcaRuyqvoVT62ofOm3UxvatHPIp6XgEIITsiNdBE+9uKQgy9AG6Cz/sUAaqrIGOofPnFuJnH3bpkPWapc9B1tg59LMPShA2irez4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 38.145.34.151 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [38.145.34.151]) by mx.zohomail.com with SMTPS id 1787948284119819.4808935147068; Fri, 28 Aug 2026 13:18:04 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 993) id ABB333F335; Fri, 28 Aug 2026 16:18:01 -0400 (EDT) Received: from [172.19.199.13] (unknown [10.16.107.18]) by lists.libvirt.org (Postfix) with ESMTP id 72EBC3FD2B for ; Fri, 28 Aug 2026 16:16:39 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 993) id C8B683F2FE; Fri, 28 Aug 2026 16:16:31 -0400 (EDT) Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 2E0A53F2FC for ; Fri, 28 Aug 2026 16:16:30 -0400 (EDT) Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-49b9320423cso12732685e9.0 for ; Fri, 28 Aug 2026 13:16:30 -0700 (PDT) Received: from localhost ([69.51.117.24]) by smtp.gmail.com with UTF8SMTPSA id 5a478bee46e88-3286f552473sm9032842eec.0.2026.08.28.13.16.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Aug 2026 13:16:27 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1787948188; x=1788552988; darn=lists.libvirt.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=aPS7iQlQMP6vxrifgVKYVpPZnMRXCihXiObCa2/hJRY=; b=DekpDnWLZOeFeDqEPW6oW9zdbq8e2swiMDvvu/idnlcEQCj0Fu2v8SI5+ctwI3wwCY K0+4LqXIFJfDgy05loeg+19UJG5Ppsh3eewUZPkS+atBI+FhizFvrPXXe6IoRtMhYW80 MkHn11ZnTJQGqyoqJNMle/SH4ocRUQHV/ojMcSrAfJgqZ2GQOUXsfvAZE5GhJnUZQS1m W+2F42uAirLlevJWiyhn+Gmit92scVp1ls4upFW7H5Fwy84ZUXPuQxs1resjriG/i1Ca B8d3FSKlqfHh5TBGM84WoAj6Y1SkjKcBlMWgCrNa5Dwz0g/Ur1Qw3IHm9bA28ZNtxVIo fNpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787948188; x=1788552988; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to:content-type; bh=aPS7iQlQMP6vxrifgVKYVpPZnMRXCihXiObCa2/hJRY=; b=RqrggrEdW9kPiI7W3pX5YTvCsDlOKo7ZWPWDImZ/KnhS65nG/aG+TUqkAgm5HhQsVF 69zzyxqpPhFaDF5JEbywiCkS0XKinkNSp3IHrXzSy/72/G+UJ+3jpEFUO6EK2mUfoWjW nv7R5fFLaWUtKBP2/OR2PvSi6tMBKDVYV6T+wm7b7I7XQxYQHYDnsx4RY58upl8On5G4 RUGlGFOpSihcZcvToXc1H8hdCIH0AJnLv7SyvTlny/dEVrJRcE7rGtc4pTM6FcjNS7TB +QaHi1D6AmlhcCUfnFWIdOfwS68M3l1NUiKsK5VF6ox+7dmWvv0ysdYpTG8LHFMywtuu 5h7Q== X-Gm-Message-State: AFuF++lCPB55bJoLsYidkvUw2ayEHlearlZdLNGZlPRJjvhvGTVduU8y FcdBXXzoEiSpnlKEm0FKbkVjs1wjMMiq+dXM6uTcfoY7p4/iQgujskoR12AS6/KLd/Kz+QzIvU/ GMejI2Xc= X-Gm-Gg: AR+sD13Ffhjhp9IL0qrndc9WRIawA1kVFyswRCmntZgpEC4Wzzaj/DEAh3gCG6aoiGt vfHU/AVL7+mQcaqHFlY2ttL0EijXkijAJj27AzkZfvZKkzbMLTvfIVt8ol/rpOoVzseao5UZLP0 pgZSqwa/kWvVaJ+PPXk05W3RwXwEzQlzuY8U3+QaF7/30zvuQA2dJ25nczTbCYezbwpOHBsmuJe 4ZOH8GqkSEC7b6oT4UdE+6/N8TGpxFuhWV4Y/yKmHAKvzN9IrscHagGDVZXrgJajqwAvcEkdzDg BTXiXBce3h2Wc4FZZIdnob6TWGBGw+9OnQqyQi1j5WMtTqTgfChOMvrjkkL0PQxDeWWg5CJ6oIF 6sT5k9Ou/sloIjqbaEUp9SMOYGpPIQoLSt37dAZOHqLVfdGHpI/COQpZ7b4pKrqJHp8ud6QZZoO e/cdHpA9hKKdiAnNPDAOGv6hMSohSVObxsCzYiwOv3aUVw8NXXOA== X-Received: by 2002:a05:600c:1394:b0:499:83f1:398 with SMTP id 5b1f17b1804b1-49b91c47b6bmr119276065e9.9.1787948188563; Fri, 28 Aug 2026 13:16:28 -0700 (PDT) To: devel@lists.libvirt.org Subject: [PATCH] qemu: add process_exit_wait configuration setting Date: Fri, 28 Aug 2026 14:16:17 -0600 Message-ID: <20260828201625.13483-1-jfehlig@suse.com> X-Mailer: git-send-email 2.51.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: CMAGRFM6A7WBUSZBUUKXE57ZN6LOZN3M X-Message-ID-Hash: CMAGRFM6A7WBUSZBUUKXE57ZN6LOZN3M X-MailFrom: jfehlig@suse.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Jim Fehlig via Devel Reply-To: Jim Fehlig X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1787948288657158500 Content-Type: text/plain; charset="utf-8" From: Jim Fehlig When shutting down a VM, libvirt sends the associated QEMU process SIGTERM, waits 10 seconds for it to disappear, optionally sends SIGKILL, then waits up to another 30 seconds for the process to exit before reporting and returning an error. Commit be2ca04447 added 2 seconds per assigned host device to the total time libvirt waits for a QEMU process to terminate. Other scenarios than the one described in be2ca04447 could delay the clean exit of QEMU, e.g. reclaiming memory of VMs with large memory allocations backed by 4k pages on the host. Instead of trying to cover all such scenarios based on VM configuration, introduce a 'process_exit_wait' setting in qemu.conf to control how much additional time (in seconds) libvirt will wait for a QEMU process to terminate before reporting an error. Signed-off-by: Jim Fehlig --- src/qemu/libvirtd_qemu.aug | 1 + src/qemu/qemu.conf.in | 12 ++++++++++++ src/qemu/qemu_conf.c | 3 +++ src/qemu/qemu_conf.h | 1 + src/qemu/qemu_process.c | 13 ++++++++++--- src/qemu/test_libvirtd_qemu.aug.in | 1 + 6 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/qemu/libvirtd_qemu.aug b/src/qemu/libvirtd_qemu.aug index 311992e441..dc3d6d61df 100644 --- a/src/qemu/libvirtd_qemu.aug +++ b/src/qemu/libvirtd_qemu.aug @@ -132,6 +132,7 @@ module Libvirtd_qemu =3D | bool_entry "dump_guest_core" | str_entry "stdio_handler" | int_entry "max_threads_per_process" + | int_entry "process_exit_wait" | str_entry "sched_core" =20 let device_entry =3D bool_entry "mac_filter" diff --git a/src/qemu/qemu.conf.in b/src/qemu/qemu.conf.in index 97b0141cf6..2f24059053 100644 --- a/src/qemu/qemu.conf.in +++ b/src/qemu/qemu.conf.in @@ -844,6 +844,18 @@ #max_threads_per_process =3D 0 =20 =20 +# When shutting down a VM, libvirt will wait up to 40 seconds for +# the associated QEMU process to exit before reporting an error. +# For some VM configurations, QEMU might require more time to +# cleanup and exit, e.g. VMs with very large memory allocations. +# +# If process_exit_wait is set to a positive interger, libvirt +# will use the value as additional time to wait for the QEMU +# process to exit before reporting it cannot be terminated. +# +#process_exit_wait =3D 0 + + # If max_core is set to a non-zero integer, then QEMU will be # permitted to create core dumps when it crashes, provided its # RAM size is smaller than the limit set. diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index e30b146634..adcba137cc 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -934,6 +934,9 @@ virQEMUDriverConfigLoadProcessEntry(virQEMUDriverConfig= *cfg, cfg->schedCore =3D val; } =20 + if (virConfGetValueUInt(conf, "process_exit_wait", &cfg->processExitWa= it) < 0) + return -1; + return 0; } =20 diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index 1d29f35c5d..bc78982123 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -211,6 +211,7 @@ struct _virQEMUDriverConfig { unsigned int maxProcesses; unsigned int maxFiles; unsigned int maxThreadsPerProc; + unsigned int processExitWait; unsigned long long maxCore; bool dumpGuestCore; =20 diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index b2506edce0..5042ffe339 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -9218,6 +9218,9 @@ qemuProcessInShutdownStartMonitor(virDomainObj *vm) int qemuProcessKill(virDomainObj *vm, unsigned int flags) { + qemuDomainObjPrivate *priv =3D vm->privateData; + g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(priv->dr= iver); + unsigned int delay =3D cfg->processExitWait; int ret =3D -1; =20 VIR_DEBUG("vm=3D%p name=3D%s pid=3D%lld flags=3D0x%x", @@ -9238,11 +9241,15 @@ qemuProcessKill(virDomainObj *vm, unsigned int flag= s) return 0; } =20 - /* Request an extra delay of two seconds per current nhostdevs - * to be safe against stalls by the kernel freeing up the resources */ + /* If the administrator has not requested an explicit shutdown wait pe= riod, + * add an extra delay of two seconds per current nhostdevs to be safe = against + * stalls by the kernel freeing up the resources */ + if (delay =3D=3D 0) + delay =3D vm->def->nhostdevs * 2; + ret =3D virProcessKillPainfullyDelay(vm->pid, !!(flags & VIR_QEMU_PROCESS_KILL_FO= RCE), - vm->def->nhostdevs * 2, + delay, false); =20 if (ret < 0 && (flags & VIR_QEMU_PROCESS_KILL_MONITOR_ON_ERROR)) { diff --git a/src/qemu/test_libvirtd_qemu.aug.in b/src/qemu/test_libvirtd_qe= mu.aug.in index c4cf9cf634..fb6cb1a1d4 100644 --- a/src/qemu/test_libvirtd_qemu.aug.in +++ b/src/qemu/test_libvirtd_qemu.aug.in @@ -97,6 +97,7 @@ module Test_libvirtd_qemu =3D { "max_processes" =3D "0" } { "max_files" =3D "0" } { "max_threads_per_process" =3D "0" } +{ "process_exit_wait" =3D "0" } { "max_core" =3D "unlimited" } { "dump_guest_core" =3D "1" } { "mac_filter" =3D "1" } --=20 2.51.0