Bug 250297 - OpenZFS crash -- zvol_geom_bio_getattr called when volmode=dev
Summary: OpenZFS crash -- zvol_geom_bio_getattr called when volmode=dev
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: CURRENT
Hardware: amd64 Any
: --- Affects Some People
Assignee: freebsd-fs (Nobody)
Depends on:
Reported: 2020-10-12 15:22 UTC by Eric van Gyzen
Modified: 2021-01-06 18:25 UTC (History)
3 users (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Eric van Gyzen freebsd_committer 2020-10-12 15:22:56 UTC
There seems to be a race between creating a zvol with volmode=dev.  We create the zvol with the default mode, then destroy it and re-create it with dev mode.  It seems that if I/O occurs in that window, it takes the geom code path and walks through a NULL pointer.

This seems to be introduced by the OpenZFS merge.  I've used this workflow often for over a year, mostly on head, and this appeared only recently.  I first saw it on r366500+84ccaf49083c-c272054.

I hit it reliably on my workstation with the following command.  I also hit it on a VM, though it takes more tries to hit the window.

# zfs create -s -V 20G -o primarycache=none -o volmode=dev head_root/testvol
zvol_create_minor_impl:1250[1]: Creating ZVOL head_root/testvol...
zvol_create_minor_impl:1371[1]: ZVOL head_root/testvol created.

Fatal trap 12: page fault while in kernel mode
cpuid = 7; apic id = 07
fault virtual address    = 0x110
fault code        = supervisor read data, page not present
instruction pointer    = 0x20:0xffffffff82167fca
stack pointer            = 0x28:0xfffffe000edcdb30
frame pointer            = 0x28:0xfffffe000edcdb70
code segment        = base rx0, limit 0xfffff, type 0x1b
            = DPL 0, pres 1, long 1, def32 0, gran 1
processor eflags    = interrupt enabled, resume, IOPL = 0
current process        = 13 (g_down)
trap number        = 12

db> acttrace

Tracing command zfskern pid 21 tid 100478 td 0xfffffe00610c9800 (CPU 6)
cpustop_handler() at cpustop_handler+0x28/frame 0xfffffe0011880e00
ipi_nmi_handler() at ipi_nmi_handler+0x39/frame 0xfffffe0011880e10
trap() at trap+0x56/frame 0xfffffe0011880f20
nmi_calltrap() at nmi_calltrap+0x8/frame 0xfffffe0011880f20
--- trap 0x13, rip = 0xffffffff80c25fb2, rsp = 0xfffffe006168c820, rbp = 0xfffffe006168c830 ---
lock_delay() at lock_delay+0x42/frame 0xfffffe006168c830
_mtx_lock_spin_cookie() at _mtx_lock_spin_cookie+0xc1/frame 0xfffffe006168c8a0
__mtx_lock_spin_flags() at __mtx_lock_spin_flags+0xd5/frame 0xfffffe006168c8e0
cnputs() at cnputs+0x58/frame 0xfffffe006168c910
vprintf() at vprintf+0xcd/frame 0xfffffe006168c9e0
printf() at printf+0x43/frame 0xfffffe006168ca40
zvol_free() at zvol_free+0x53/frame 0xfffffe006168ca80
zvol_task_cb() at zvol_task_cb+0x271/frame 0xfffffe006168cae0
taskq_run() at taskq_run+0x1f/frame 0xfffffe006168cb00
taskqueue_run_locked() at taskqueue_run_locked+0xaa/frame 0xfffffe006168cb80
taskqueue_thread_loop() at taskqueue_thread_loop+0x94/frame 0xfffffe006168cbb0
fork_exit() at fork_exit+0x80/frame 0xfffffe006168cbf0
fork_trampoline() at fork_trampoline+0xe/frame 0xfffffe006168cbf0
--- trap 0, rip = 0, rsp = 0, rbp = 0 ---

Tracing command geom pid 13 tid 100049 td 0xfffffe0011862700 (CPU 7)
kdb_enter() at kdb_enter+0x37/frame 0xfffffe000edcd7e0
vpanic() at vpanic+0x19e/frame 0xfffffe000edcd830
panic() at panic+0x43/frame 0xfffffe000edcd890
trap_fatal() at trap_fatal+0x387/frame 0xfffffe000edcd8f0
trap_pfault() at trap_pfault+0x97/frame 0xfffffe000edcd950
trap() at trap+0x2ab/frame 0xfffffe000edcda60
calltrap() at calltrap+0x8/frame 0xfffffe000edcda60
--- trap 0xc, rip = 0xffffffff82167fca, rsp = 0xfffffe000edcdb30, rbp = 0xfffffe000edcdb70 ---
zvol_geom_bio_start() at zvol_geom_bio_start+0x2a/frame 0xfffffe000edcdb70
g_io_schedule_down() at g_io_schedule_down+0x134/frame 0xfffffe000edcdba0
g_down_procbody() at g_down_procbody+0x5c/frame 0xfffffe000edcdbb0
fork_exit() at fork_exit+0x80/frame 0xfffffe000edcdbf0
fork_trampoline() at fork_trampoline+0xe/frame 0xfffffe000edcdbf0
--- trap 0, rip = 0, rsp = 0, rbp = 0 ---

(The other CPUs were idle.)
Comment 1 Alan Somers freebsd_committer 2020-12-13 23:29:42 UTC
FWIW on current head I don't see this behavior.  What I see instead is that we create the zvol with default mode, but don't destroy and recreate it.  So it ends up with the wrong mode.  Only if I subsequently do "zfs set volmode=dev <volname>" does the zvol get the correct mode.  I opened bug 251828 for that.
Comment 2 Eric van Gyzen freebsd_committer 2021-01-06 18:25:33 UTC
I still see this behavior on main commit f7cd7fe51c4 (25 December).  Remember, it's a race, so if you get lucky, you won't see it.