From: Markus Armbruster <armbru@redhat.com>
To: "Daniel P. Berrangé" <berrange@redhat.com>
Cc: qemu-devel@nongnu.org,
"Manos Pitsidianakis" <manos.pitsidianakis@linaro.org>,
"Stefan Weil" <sw@weilnetz.de>,
"Dr. David Alan Gilbert" <dave@treblig.org>,
"Pierrick Bouvier" <pierrick.bouvier@linaro.org>,
devel@lists.libvirt.org,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Hanna Reitz" <hreitz@redhat.com>,
"Kevin Wolf" <kwolf@redhat.com>,
qemu-block@nongnu.org, qemu-rust@nongnu.org,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Gerd Hoffmann" <kraxel@redhat.com>,
"Christian Schoenebeck" <qemu_oss@crudebyte.com>,
"Richard Henderson" <richard.henderson@linaro.org>
Subject: Re: [PATCH v6 19/27] util: fix interleaving of error & trace output
Date: Wed, 18 Feb 2026 13:41:26 +0100 [thread overview]
Message-ID: <87fr6ycjgp.fsf@pond.sub.org> (raw)
In-Reply-To: <20260211152508.732487-20-berrange@redhat.com> ("Daniel P. Berrangé"'s message of "Wed, 11 Feb 2026 15:25:00 +0000")
Daniel P. Berrangé <berrange@redhat.com> writes:
> The monitor_cur_hmp() function will acquire/release mutex locks, which
> will trigger trace probes, which can in turn trigger qemu_log() calls.
> vreport() calls monitor_cur() multiple times through its execution
> both directly and indirectly via error_vprintf().
>
> The result is that the prefix information printed by vreport() gets
> interleaved with qemu_log() output, when run outside the context of
> an HMP command dispatcher. This can be seen with:
>
> $ qemu-system-x86_64 \
> -msg timestamp=on,guest-name=on \
> -display none \
> -object tls-creds-x509,id=f,dir=fish \
> -name fish \
> -d trace:qemu_mutex*
> 2025-09-10T16:30:42.514374Z qemu_mutex_unlock released mutex 0x560b0339b4c0 (/var/home/berrange/src/virt/qemu/include/qemu/lockable.h:56)
> 2025-09-10T16:30:42.514400Z qemu_mutex_lock waiting on mutex 0x560b033983e0 (/var/home/berrange/src/virt/qemu/include/qemu/lockable.h:56)
> 2025-09-10T16:30:42.514402Z qemu_mutex_locked taken mutex 0x560b033983e0 (/var/home/berrange/src/virt/qemu/include/qemu/lockable.h:56)
> 2025-09-10T16:30:42.514404Z qemu_mutex_unlock released mutex 0x560b033983e0 (/var/home/berrange/src/virt/qemu/include/qemu/lockable.h:56)
> 2025-09-10T16:30:42.516716Z qemu_mutex_lock waiting on mutex 0x560b03398560 (../monitor/monitor.c:91)
> 2025-09-10T16:30:42.516723Z qemu_mutex_locked taken mutex 0x560b03398560 (../monitor/monitor.c:91)
> 2025-09-10T16:30:42.516726Z qemu_mutex_unlock released mutex 0x560b03398560 (../monitor/monitor.c:96)
> 2025-09-10T16:30:42.516728Z qemu_mutex_lock waiting on mutex 0x560b03398560 (../monitor/monitor.c:91)
> 2025-09-10T16:31:04.842057Z qemu_mutex_locked taken mutex 0x564f5e401560 (../monitor/monitor.c:91)
> 2025-09-10T16:31:04.842058Z qemu_mutex_unlock released mutex 0x564f5e401560 (../monitor/monitor.c:96)
> 2025-09-10T16:31:04.842055Z 2025-09-10T16:31:04.842060Z qemu_mutex_lock waiting on mutex 0x564f5e401560 (../monitor/monitor.c:91)
> 2025-09-10T16:31:04.842061Z qemu_mutex_locked taken mutex 0x564f5e401560 (../monitor/monitor.c:91)
> 2025-09-10T16:31:04.842062Z qemu_mutex_unlock released mutex 0x564f5e401560 (../monitor/monitor.c:96)
> 2025-09-10T16:31:04.842064Z qemu_mutex_lock waiting on mutex 0x564f5e401560 (../monitor/monitor.c:91)
> 2025-09-10T16:31:04.842065Z qemu_mutex_locked taken mutex 0x564f5e401560 (../monitor/monitor.c:91)
> 2025-09-10T16:31:04.842066Z qemu_mutex_unlock released mutex 0x564f5e401560 (../monitor/monitor.c:96)
> fish 2025-09-10T16:31:04.842068Z qemu_mutex_lock waiting on mutex 0x564f5e401560 (../monitor/monitor.c:91)
> 2025-09-10T16:31:04.842069Z qemu_mutex_locked taken mutex 0x564f5e401560 (../monitor/monitor.c:91)
> 2025-09-10T16:31:04.842070Z qemu_mutex_unlock released mutex 0x564f5e401560 (../monitor/monitor.c:96)
> 2025-09-10T16:31:04.842072Z qemu_mutex_lock waiting on mutex 0x564f5e401560 (../monitor/monitor.c:91)
> 2025-09-10T16:31:04.842097Z qemu_mutex_locked taken mutex 0x564f5e401560 (../monitor/monitor.c:91)
> 2025-09-10T16:31:04.842099Z qemu_mutex_unlock released mutex 0x564f5e401560 (../monitor/monitor.c:96)
> qemu-system-x86_64:2025-09-10T16:31:04.842100Z qemu_mutex_lock waiting on mutex 0x564f5e401560 (../monitor/monitor.c:91)
> 2025-09-10T16:31:04.842102Z qemu_mutex_locked taken mutex 0x564f5e401560 (../monitor/monitor.c:91)
> 2025-09-10T16:31:04.842103Z qemu_mutex_unlock released mutex 0x564f5e401560 (../monitor/monitor.c:96)
> 2025-09-10T16:31:04.842105Z qemu_mutex_lock waiting on mutex 0x564f5e401560 (../monitor/monitor.c:91)
> 2025-09-10T16:31:04.842106Z qemu_mutex_locked taken mutex 0x564f5e401560 (../monitor/monitor.c:91)
> 2025-09-10T16:31:04.842107Z qemu_mutex_unlock released mutex 0x564f5e401560 (../monitor/monitor.c:96)
> Unable to access credentials fish/ca-cert.pem: No such file or directory2025-09-10T16:31:04.842109Z qemu_mutex_lock waiting on mutex 0x564f5e401560 (../monitor/monitor.c:91)
> 2025-09-10T16:31:04.842110Z qemu_mutex_locked taken mutex 0x564f5e401560 (../monitor/monitor.c:91)
> 2025-09-10T16:31:04.842111Z qemu_mutex_unlock released mutex 0x564f5e401560 (../monitor/monitor.c:96)
>
> To avoid this interleaving (as well as reduce the huge number of
> mutex lock/unlock calls) we need to ensure that monitor_cur_is_hmp()
> is only called once at the start of vreport(), and if no HMP is
> present, no further monitor APIs can be called.
>
> This implies error_[v]printf() cannot be called from vreport().
> Instead we must introduce error_[v]printf_mon() which accept a
> pre-acquired Monitor object. In some cases, however, fprintf
> can be called directly as output will never be directed to the
> monitor.
>
> $ qemu-system-x86_64 \
> -msg timestamp=on,guest-name=on \
> -display none \
> -object tls-creds-x509,id=f,dir=fish \
> -name fish \
> -d trace:qemu_mutex*
> 2025-09-10T16:31:22.701691Z qemu_mutex_unlock released mutex 0x5626fd3b84c0 (/var/home/berrange/src/virt/qemu/include/qemu/lockable.h:56)
> 2025-09-10T16:31:22.701728Z qemu_mutex_lock waiting on mutex 0x5626fd3b53e0 (/var/home/berrange/src/virt/qemu/include/qemu/lockable.h:56)
> 2025-09-10T16:31:22.701730Z qemu_mutex_locked taken mutex 0x5626fd3b53e0 (/var/home/berrange/src/virt/qemu/include/qemu/lockable.h:56)
> 2025-09-10T16:31:22.701732Z qemu_mutex_unlock released mutex 0x5626fd3b53e0 (/var/home/berrange/src/virt/qemu/include/qemu/lockable.h:56)
> 2025-09-10T16:31:22.703989Z qemu_mutex_lock waiting on mutex 0x5626fd3b5560 (../monitor/monitor.c:91)
> 2025-09-10T16:31:22.703996Z qemu_mutex_locked taken mutex 0x5626fd3b5560 (../monitor/monitor.c:91)
> 2025-09-10T16:31:22.703999Z qemu_mutex_unlock released mutex 0x5626fd3b5560 (../monitor/monitor.c:96)
> 2025-09-10T16:31:22.704000Z fish qemu-system-x86_64: Unable to access credentials fish/ca-cert.pem: No such file or directory
>
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
> util/error-report.c | 63 ++++++++++++++++++++++++++++++---------------
> 1 file changed, 42 insertions(+), 21 deletions(-)
>
> diff --git a/util/error-report.c b/util/error-report.c
> index f3aa24ec22..b34a2bc7bc 100644
> --- a/util/error-report.c
> +++ b/util/error-report.c
> @@ -32,9 +32,9 @@ const char *error_guest_name;
> /*
> * Print to the current human monitor if we have one, else to stderr.
This is now misleading. Let's use
* Print to @cur_mon if non-null, else to stderr.
> */
> -int error_vprintf(const char *fmt, va_list ap)
> +static int G_GNUC_PRINTF(2, 0)
> +error_vprintf_mon(Monitor *cur_mon, const char *fmt, va_list ap)
> {
> - Monitor *cur_mon = monitor_cur();
> /*
> * This will return -1 if 'cur_mon' is NULL, or is QMP.
> * IOW this will only print if in HMP, otherwise we
> @@ -47,13 +47,33 @@ int error_vprintf(const char *fmt, va_list ap)
> return ret;
> }
>
> +/*
> + * Print to the current human monitor if we have one, else to stderr.
Likewise.
> + */
> +static int G_GNUC_PRINTF(2, 3)
> +error_printf_mon(Monitor *cur_mon, const char *fmt, ...)
> +{
> + va_list ap;
> + int ret;
> +
> + va_start(ap, fmt);
> + ret = error_vprintf_mon(cur_mon, fmt, ap);
> + va_end(ap);
> + return ret;
> +}
> +
Keep its function comment, i.e.
/*
* Print to the current human monitor if we have one, else to stderr.
*/
> +int error_vprintf(const char *fmt, va_list ap)
> +{
> + return error_vprintf_mon(monitor_cur(), fmt, ap);
> +}
> +
This one lost its function comment in commit 397d30e9401. Let's correct
that accident:
/*
* Print to the current human monitor if we have one, else to stderr.
*/
> int error_printf(const char *fmt, ...)
> {
> va_list ap;
> int ret;
>
> va_start(ap, fmt);
> - ret = error_vprintf(fmt, ap);
> + ret = error_vprintf_mon(monitor_cur(), fmt, ap);
> va_end(ap);
> return ret;
> }
With these trivial touch-ups
Reviewed-by: Markus Armbruster <armbru@redhat.com>
[...]
next prev parent reply other threads:[~2026-02-18 12:41 UTC|newest]
Thread overview: 59+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-11 15:24 [PATCH v6 00/27] util: sync error_report & qemu_log output more closely Daniel P. Berrangé
2026-02-11 15:24 ` [PATCH v6 01/27] meson: don't access 'cxx' object without checking cpp lang Daniel P. Berrangé
2026-02-11 15:24 ` [PATCH v6 02/27] qemu-options: remove extraneous [] around arg values Daniel P. Berrangé
2026-02-11 15:24 ` [PATCH v6 03/27] include: define constant for early constructor priority Daniel P. Berrangé
2026-02-18 9:22 ` Markus Armbruster
2026-02-18 10:46 ` Daniel P. Berrangé
2026-02-18 13:23 ` Markus Armbruster
2026-02-11 15:24 ` [PATCH v6 04/27] monitor: initialize global data from a constructor Daniel P. Berrangé
2026-02-11 15:24 ` [PATCH v6 05/27] system: unconditionally enable thread naming Daniel P. Berrangé
2026-02-11 15:24 ` [PATCH v6 06/27] util: fix race setting thread name on Win32 Daniel P. Berrangé
2026-02-11 15:24 ` [PATCH v6 07/27] util: expose qemu_thread_set_name Daniel P. Berrangé
2026-02-11 15:24 ` [PATCH v6 08/27] audio: make jackaudio use qemu_thread_set_name Daniel P. Berrangé
2026-02-11 15:24 ` [PATCH v6 09/27] util: set the name for the 'main' thread on Windows Daniel P. Berrangé
2026-02-11 15:24 ` [PATCH v6 10/27] util: add API to fetch the current thread name Daniel P. Berrangé
2026-02-11 15:24 ` [PATCH v6 11/27] util: introduce some API docs for logging APIs Daniel P. Berrangé
2026-02-18 9:38 ` Markus Armbruster
2026-02-11 15:24 ` [PATCH v6 12/27] util: avoid repeated prefix on incremental qemu_log calls Daniel P. Berrangé
2026-02-18 9:52 ` Markus Armbruster
2026-02-18 10:45 ` Daniel P. Berrangé
2026-02-11 15:24 ` [PATCH v6 13/27] util/log: add missing error reporting in qemu_log_trylock_with_err Daniel P. Berrangé
2026-02-18 10:45 ` Markus Armbruster
2026-02-11 15:24 ` [PATCH v6 14/27] ui: add proper error reporting for password changes Daniel P. Berrangé
2026-02-18 12:10 ` Markus Armbruster
2026-02-25 16:08 ` Daniel P. Berrangé
2026-02-11 15:24 ` [PATCH v6 15/27] ui: remove redundant use of error_printf_unless_qmp() Daniel P. Berrangé
2026-02-18 12:12 ` Markus Armbruster
2026-02-11 15:24 ` [PATCH v6 16/27] monitor: remove redundant error_[v]printf_unless_qmp Daniel P. Berrangé
2026-02-11 15:24 ` [PATCH v6 17/27] monitor: refactor error_vprintf() Daniel P. Berrangé
2026-02-11 15:24 ` [PATCH v6 18/27] monitor: move error_vprintf back to error-report.c Daniel P. Berrangé
2026-02-11 15:25 ` [PATCH v6 19/27] util: fix interleaving of error & trace output Daniel P. Berrangé
2026-02-18 12:41 ` Markus Armbruster [this message]
2026-02-18 12:45 ` Markus Armbruster
2026-02-11 15:25 ` [PATCH v6 20/27] util: don't skip error prefixes when QMP is active Daniel P. Berrangé
2026-02-18 12:47 ` Markus Armbruster
2026-02-11 15:25 ` [PATCH v6 21/27] util: fix interleaving of error prefixes Daniel P. Berrangé
2026-02-11 15:25 ` [PATCH v6 22/27] util: introduce common helper for error-report & log code Daniel P. Berrangé
2026-02-18 14:04 ` Markus Armbruster
2026-02-25 16:18 ` Daniel P. Berrangé
2026-02-25 17:51 ` Markus Armbruster
2026-02-11 15:25 ` [PATCH v6 23/27] util: convert error-report & log to message API for timestamp Daniel P. Berrangé
2026-02-11 15:25 ` [PATCH v6 24/27] util: add support for formatting a workload name in messages Daniel P. Berrangé
2026-02-11 15:25 ` [PATCH v6 25/27] util: add support for formatting a program " Daniel P. Berrangé
2026-02-19 10:08 ` Markus Armbruster
2026-02-25 16:24 ` Daniel P. Berrangé
2026-02-26 7:11 ` Markus Armbruster
2026-02-19 10:23 ` Peter Maydell
2026-02-25 16:38 ` Daniel P. Berrangé
2026-02-25 17:43 ` Peter Maydell
2026-02-25 17:47 ` Daniel P. Berrangé
2026-02-11 15:25 ` [PATCH v6 26/27] util: add support for formatting thread info " Daniel P. Berrangé
2026-02-19 10:14 ` Markus Armbruster
2026-02-25 16:33 ` Daniel P. Berrangé
2026-02-19 10:29 ` Peter Maydell
2026-02-25 16:30 ` Daniel P. Berrangé
2026-02-25 17:39 ` Peter Maydell
2026-02-11 15:25 ` [PATCH v6 27/27] util: add brackets around guest name in message context Daniel P. Berrangé
2026-02-19 10:16 ` Markus Armbruster
2026-02-26 9:51 ` [PATCH v6 00/27] util: sync error_report & qemu_log output more closely Markus Armbruster
2026-02-26 9:58 ` Daniel P. Berrangé
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87fr6ycjgp.fsf@pond.sub.org \
--to=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=dave@treblig.org \
--cc=devel@lists.libvirt.org \
--cc=hreitz@redhat.com \
--cc=kraxel@redhat.com \
--cc=kwolf@redhat.com \
--cc=manos.pitsidianakis@linaro.org \
--cc=marcandre.lureau@redhat.com \
--cc=pbonzini@redhat.com \
--cc=philmd@linaro.org \
--cc=pierrick.bouvier@linaro.org \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-rust@nongnu.org \
--cc=qemu_oss@crudebyte.com \
--cc=richard.henderson@linaro.org \
--cc=sw@weilnetz.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox