From ee72bc1d1ff8aa8704d5861a10ea3514154ff74d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Date: Thu, 2 May 2024 15:12:16 +0200 Subject: [PATCH] xen/debug: remove usage of sbuf_{clear,finish}() on drained sbuf Using sbuf_clear() on a drained sbuf is explicitly prohibited, and using sbuf_finish() after printing a trace leads to a single trace being printed, as after calling sbuf_finish() further attempts to use the same sbuf will lead to a panic. While there also switch to using xen_emergency_print() instead of attempting to write directly to the hypervisor console. xen_emergency_print() can be implemented per-arch to use a different mechanism than the console hypercall (note the default implementation still uses the console hypercall). Fixes: df62b8a25f47 ('xen: add a handler for the debug interrupt') Sponsored by: Cloud Software Group Reviewed by: markj Differential review: https://reviews.freebsd.org/D45060 --- sys/dev/xen/debug/debug.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/sys/dev/xen/debug/debug.c b/sys/dev/xen/debug/debug.c index f17d0c612262..2889b5efdba7 100644 --- a/sys/dev/xen/debug/debug.c +++ b/sys/dev/xen/debug/debug.c @@ -58,8 +58,11 @@ static struct sbuf *buf; static int xendebug_drain(void *arg, const char *str, int len) { - - HYPERVISOR_console_write(__DECONST(char *, str), len); + /* + * Use xen_emergency_print() instead of xc_printf() to avoid the + * overhead of parsing a format string when it's not needed. + */ + xen_emergency_print(str, len); return (len); } @@ -75,10 +78,9 @@ xendebug_filter(void *arg __unused) stack_save(&st); mtx_lock_spin(&lock); - sbuf_clear(buf); xc_printf("Printing stack trace vCPU%u\n", XEN_VCPUID()); stack_sbuf_print_ddb(buf, &st); - sbuf_finish(buf); + sbuf_drain(buf); mtx_unlock_spin(&lock); #endif