Kernel with INVARIANTS panicing if drm is loaded

From: Oleg V. Nauman <oleg.nauman_at_gmail.com>
Date: Sun, 05 Nov 2023 17:54:39 UTC
 I am observing kernel panic when entering multiuser mode after sucessful 
system boot. It happens when I load CURRENT kernel with INVARIANTS and drm 
module loaded ( drm-515-kmod-5.15.118_1 in particular ) . drm module and kenel 
are in sync


FreeBSD moonset.home 15.0-CURRENT FreeBSD 15.0-CURRENT #3 main-n266267-
e116e040f309: Sun Nov  5 10:00:51 EET 2023     root@moonset.home:/usr/obj/usr/
src/amd64.amd64/sys/moonset  amd64

panic: sleepq_add: td 0xfffff8000203c000 to sleep on wchan 0xfffff800021d8648 
with sleeping prohibited
...............
Reading symbols from /boot/kernel/kernel...
Reading symbols from /usr/lib/debug//boot/kernel/kernel.debug...

Unread portion of the kernel message buffer:
panic: malloc(M_WAITOK) with sleeping prohibited
cpuid = 0
time = 1699171621
.............
__curthread () at /usr/src/sys/amd64/include/pcpu_aux.h:57
57              __asm("movq %%gs:%P1,%0" : "=r" (td) : "n" (offsetof(struct 
pcpu,
(kgdb) #0  __curthread () at /usr/src/sys/amd64/include/pcpu_aux.h:57
#1  doadump (textdump=<optimized out>)
    at /usr/src/sys/kern/kern_shutdown.c:405
#2  0xffffffff81e2ec53 in vt_kms_postswitch () from /boot/modules/drm.ko
#3  0xffffffff8043ad6e in vt_window_switch (vw=0xfffff800021d8640)
    at /usr/src/sys/dev/vt/vt_core.c:595
#4  0xffffffff804ec583 in kern_reboot (howto=4)
    at /usr/src/sys/kern/kern_shutdown.c:501
#5  0xffffffff804eccfa in vpanic (
    fmt=0xffffffff808263fb "malloc(M_WAITOK) with sleeping prohibited",
    ap=ap@entry=0xfffffe00ce259850) at /usr/src/sys/kern/kern_shutdown.c:970
#6  0xffffffff804ecb03 in panic (fmt=<unavailable>)
    at /usr/src/sys/kern/kern_shutdown.c:894
#7  0xffffffff804c8a04 in malloc_dbg (vap=<optimized out>,
    sizep=<optimized out>, mtp=<optimized out>, flags=<optimized out>)
    at /usr/src/sys/kern/kern_malloc.c:540
#8  0xffffffff804c885c in malloc (size=<optimized out>,
    mtp=0xffffffff81e931c0 <M_KMALLOC>, flags=<unavailable>)
    at /usr/src/sys/kern/kern_malloc.c:641
#9  0xffffffff81c5a750 in intel_atomic_state_alloc ()
   from /boot/modules/i915kms.ko
#10 0xffffffff81dfe404 in drm_client_modeset_commit_atomic ()
   from /boot/modules/drm.ko
#11 0xffffffff81dfe614 in drm_client_modeset_commit_locked ()
   from /boot/modules/drm.ko
#12 0xffffffff81dfe7a1 in drm_client_modeset_commit ()
   from /boot/modules/drm.ko
#13 0xffffffff81e41ab3 in drm_fb_helper_restore_fbdev_mode_unlocked ()
   from /boot/modules/drm.ko
#14 0xffffffff81e2ed91 in vt_kms_postswitch () from /boot/modules/drm.ko
#15 0xffffffff8043ac31 in vt_window_switch (vw=0xfffff80001d3a600,
    vw@entry=0xffffffff80a47178 <vt_conswindow>)
    at /usr/src/sys/dev/vt/vt_core.c:612
#16 0xffffffff8043be0f in vtterm_cngrab (tm=<unavailable>,
    tm@entry=<error reading variable: value is not available>)
    at /usr/src/sys/dev/vt/vt_core.c:1863
#17 0xffffffff804893f6 in cngrab () at /usr/src/sys/kern/kern_cons.c:385
#18 0xffffffff804ecc79 in vpanic (
    fmt=0xffffffff808799a9 "%s: td %p to sleep on wchan %p with sleeping 
prohibited", ap=ap@entry=0xfffffe00ce259c20)
    at /usr/src/sys/kern/kern_shutdown.c:942
#19 0xffffffff804ecb03 in panic (fmt=<unavailable>)
    at /usr/src/sys/kern/kern_shutdown.c:894
#20 0xffffffff805465b3 in sleepq_add (wchan=wchan@entry=0xfffff800021d8648,
    lock=lock@entry=0xfffff80001823340,
    wmesg=wmesg@entry=0xffffffff808b194e "tq_drain", flags=0,
    flags@entry=<unavailable>, queue=queue@entry=0)
    at /usr/src/sys/kern/subr_sleepqueue.c:326
#21 0xffffffff804f8efe in _sleep (ident=ident@entry=0xfffff800021d8648,
    lock=lock@entry=0xfffff80001823340, priority=priority@entry=0,
    wmesg=0xffffffff808b194e "tq_drain", sbt=sbt@entry=0, pr=pr@entry=0,
    flags=256) at /usr/src/sys/kern/kern_synch.c:207
#22 0xffffffff8054cffb in TQ_SLEEP (tq=0xfffff80001823300,
    p=0xfffff800021d8648, wm=<optimized out>)
    at /usr/src/sys/kern/subr_taskqueue.c:124
#23 taskqueue_drain (queue=0xfffff80001823300, task=0xfffff800021d8648)
    at /usr/src/sys/kern/subr_taskqueue.c:614
#24 0xffffffff81e2ed35 in vt_kms_postswitch () from /boot/modules/drm.ko
#25 0xffffffff8043ac31 in vt_window_switch (vw=0xfffff800021d8648,
    vw@entry=0xfffff800038fb180) at /usr/src/sys/dev/vt/vt_core.c:612
#26 0xffffffff8043b3b2 in vt_late_window_switch (vw=0xfffff800038fb180)
    at /usr/src/sys/dev/vt/vt_core.c:468
#27 vt_proc_window_switch (vw=0xfffff800038fb180)
    at /usr/src/sys/dev/vt/vt_core.c:553
#28 0xffffffff8043e318 in vt_processkey (
    kbd=0xffffffff80cef898 <default_kbd>, vd=0xffffffff80a472c8 <vt_consdev>,
    c=<optimized out>) at /usr/src/sys/dev/vt/vt_core.c:903
#29 vt_kbdevent (kbd=0xffffffff80cef898 <default_kbd>, event=<optimized out>,
    arg=0xffffffff80a472c8 <vt_consdev>) at /usr/src/sys/dev/vt/vt_core.c:1018
#30 0xffffffff8078ffcf in atkbd_intr (kbd=0xffffffff80cef898 <default_kbd>,
    arg=<optimized out>) at /usr/src/sys/dev/atkbdc/atkbd.c:565
#31 0xffffffff804b1376 in intr_event_execute_handlers (ie=0xfffff800010ece00,
    p=<optimized out>) at /usr/src/sys/kern/kern_intr.c:1205
#32 ithread_execute_handlers (ie=0xfffff800010ece00, p=<optimized out>)
    at /usr/src/sys/kern/kern_intr.c:1218
#33 ithread_loop (arg=arg@entry=0xfffff80001c5aea0)
    at /usr/src/sys/kern/kern_intr.c:1306
#34 0xffffffff804adae2 in fork_exit (
    callout=0xffffffff804b1120 <ithread_loop>, arg=0xfffff80001c5aea0,
    frame=0xfffffe00ce259f40) at /usr/src/sys/kern/kern_fork.c:1160
#35 <signal handler called>
#36 0x0000000000000b88 in ?? ()
Backtrace stopped: Cannot access memory at address 0xbc7
(kgdb)