From c397b61ea5441ea9180cc7c27b425f6a871a37ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Date: Wed, 20 Jul 2016 09:29:39 +0000 Subject: [PATCH] vesa: fix panic on suspend Fix the following panic seen when migrating a FreeBSD guest on Xen: panic: mtx_lock() of destroyed mutex @ /usr/src/sys/dev/fb/vesa.c:541 cpuid = 0 KDB: stack backtrace: db_trace_self_wrapper() at db_trace_self_wrapper+0x2b/frame 0xfffffe001d2fa4f0 vpanic() at vpanic+0x182/frame 0xfffffe001d2fa570 kassert_panic() at kassert_panic+0x126/frame 0xfffffe001d2fa5e0 __mtx_lock_flags() at __mtx_lock_flags+0x15b/frame 0xfffffe001d2fa630 vesa_bios_save_restore() at vesa_bios_save_restore+0x78/frame 0xfffffe001d2fa680 vga_suspend() at vga_suspend+0xa3/frame 0xfffffe001d2fa6b0 isavga_suspend() at isavga_suspend+0x1d/frame 0xfffffe001d2fa6d0 bus_generic_suspend_child() at bus_generic_suspend_child+0x44/frame [...] This is caused because vga_sub_configure (which is called if the VGA adapter is attached after VESA tried to initialize), points to vesa_configure, which doesn't initialize the VESA mutex. In order to fix it, make sure vga_sub_configure points to vesa_load, so that all the needed vesa components are properly initialized. Sponsored by: Citrix Systems R&D MFC after: 3 days PR: 209203 Reviewed by: dumbbell Differential revision: https://reviews.freebsd.org/D7196 --- sys/dev/fb/vesa.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/sys/dev/fb/vesa.c b/sys/dev/fb/vesa.c index bd6b759a0497..810d5d88e99b 100644 --- a/sys/dev/fb/vesa.c +++ b/sys/dev/fb/vesa.c @@ -134,6 +134,7 @@ static vi_fill_rect_t vesa_fill_rect; static vi_bitblt_t vesa_bitblt; static vi_diag_t vesa_diag; static int vesa_bios_info(int level); +static int vesa_late_load(int flags); static video_switch_t vesavidsw = { vesa_probe, @@ -1141,7 +1142,7 @@ vesa_configure(int flags) * initialization for now and try again later. */ if (adp == NULL) { - vga_sub_configure = vesa_configure; + vga_sub_configure = vesa_late_load; return (ENODEV); } @@ -1908,6 +1909,17 @@ vesa_bios_info(int level) static int vesa_load(void) +{ + + return (vesa_late_load(0)); +} + +/* + * To be called from the vga_sub_configure hook in case the VGA adapter is + * not found when VESA is loaded. + */ +static int +vesa_late_load(int flags) { int error; @@ -1918,7 +1930,7 @@ vesa_load(void) /* locate a VGA adapter */ vesa_adp = NULL; - error = vesa_configure(0); + error = vesa_configure(flags); if (error == 0) vesa_bios_info(bootverbose);