git: ee72bc1d1ff8 - main - xen/debug: remove usage of sbuf_{clear,finish}() on drained sbuf
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 09 May 2024 11:05:37 UTC
The branch main has been updated by royger:
URL: https://cgit.FreeBSD.org/src/commit/?id=ee72bc1d1ff8aa8704d5861a10ea3514154ff74d
commit ee72bc1d1ff8aa8704d5861a10ea3514154ff74d
Author: Roger Pau Monné <royger@FreeBSD.org>
AuthorDate: 2024-05-02 13:12:16 +0000
Commit: Roger Pau Monné <royger@FreeBSD.org>
CommitDate: 2024-05-09 10:50:08 +0000
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