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: df62b8a25f ('xen: add a handler for the debug interrupt')
Sponsored by: Cloud Software Group
Reviewed by: markj
Differential review: https://reviews.freebsd.org/D45060
This commit is contained in:
Roger Pau Monné 2024-05-02 15:12:16 +02:00
parent ce7756fdca
commit ee72bc1d1f

View File

@ -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