freebsd-nq/sys
Vladimir Kondratyev ec25b6fa5f LinuxKPI: Reimplement irq_work queue on top of fast taskqueue
Summary:
Linux's irq_work queue was created for asynchronous execution of code from contexts where spin_lock's are not available like "hardware interrupt context". FreeBSD's fast taskqueues was created for the same purposes.

Drm-kmod 5.4 uses irq_work_queue() at least in one place to schedule execution of task/work from the critical section that triggers following INVARIANTS-induced panic:

```
panic: acquiring blockable sleep lock with spinlock or critical section held (sleep mutex) linuxkpi_short_wq @ /usr/src/sys/kern/subr_taskqueue.c:281
cpuid = 6
time = 1605048416
KDB: stack backtrace:
db_trace_self_wrapper() at db_trace_self_wrapper+0x2b/frame 0xfffffe006b538c90
vpanic() at vpanic+0x182/frame 0xfffffe006b538ce0
panic() at panic+0x43/frame 0xfffffe006b538d40
witness_checkorder() at witness_checkorder+0xf3e/frame 0xfffffe006b538f00
__mtx_lock_flags() at __mtx_lock_flags+0x94/frame 0xfffffe006b538f50
taskqueue_enqueue() at taskqueue_enqueue+0x42/frame 0xfffffe006b538f70
linux_queue_work_on() at linux_queue_work_on+0xe9/frame 0xfffffe006b538fb0
irq_work_queue() at irq_work_queue+0x21/frame 0xfffffe006b538fd0
semaphore_notify() at semaphore_notify+0xb2/frame 0xfffffe006b539020
__i915_sw_fence_notify() at __i915_sw_fence_notify+0x2e/frame 0xfffffe006b539050
__i915_sw_fence_complete() at __i915_sw_fence_complete+0x63/frame 0xfffffe006b539080
i915_sw_fence_complete() at i915_sw_fence_complete+0x8e/frame 0xfffffe006b5390c0
dma_i915_sw_fence_wake() at dma_i915_sw_fence_wake+0x4f/frame 0xfffffe006b539100
dma_fence_signal_locked() at dma_fence_signal_locked+0x105/frame 0xfffffe006b539180
dma_fence_signal() at dma_fence_signal+0x72/frame 0xfffffe006b5391c0
dma_fence_is_signaled() at dma_fence_is_signaled+0x80/frame 0xfffffe006b539200
dma_resv_add_shared_fence() at dma_resv_add_shared_fence+0xb3/frame 0xfffffe006b539270
i915_vma_move_to_active() at i915_vma_move_to_active+0x18a/frame 0xfffffe006b5392b0
eb_move_to_gpu() at eb_move_to_gpu+0x3ad/frame 0xfffffe006b539320
eb_submit() at eb_submit+0x15/frame 0xfffffe006b539350
i915_gem_do_execbuffer() at i915_gem_do_execbuffer+0x7d4/frame 0xfffffe006b539570
i915_gem_execbuffer2_ioctl() at i915_gem_execbuffer2_ioctl+0x1c1/frame 0xfffffe006b539600
drm_ioctl_kernel() at drm_ioctl_kernel+0xd9/frame 0xfffffe006b539670
drm_ioctl() at drm_ioctl+0x5cd/frame 0xfffffe006b539820
linux_file_ioctl() at linux_file_ioctl+0x323/frame 0xfffffe006b539880
kern_ioctl() at kern_ioctl+0x1f4/frame 0xfffffe006b5398f0
sys_ioctl() at sys_ioctl+0x12a/frame 0xfffffe006b5399c0
amd64_syscall() at amd64_syscall+0x121/frame 0xfffffe006b539af0
fast_syscall_common() at fast_syscall_common+0xf8/frame 0xfffffe006b539af0
--- syscall (54, FreeBSD ELF64, sys_ioctl), rip = 0x800a6f09a, rsp = 0x7fffffffe588, rbp = 0x7fffffffe640 ---
KDB: enter: panic
```
Here, the  dma_resv_add_shared_fence() performs a critical_enter() and following call of schedule_work() from semaphore_notify() triggers 'acquiring blockable sleep lock with spinlock or critical section held' panic.

Switching irq_work implementation to fast taskqueue fixes the panic for me.

Other report with the similar bug: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=247166

Reviewed By: hselasky
Differential Revision: https://reviews.freebsd.org/D27171
2021-01-17 12:47:28 +01:00
..
amd64 hid: Replace USBHID_ENABLED kernel config option with loader tunable 2021-01-14 23:04:47 +03:00
arm arm: arm64: Directly use #include <dt-binding/...> 2021-01-15 14:17:03 +01:00
arm64 Extract the logic from pmap_kextract 2021-01-15 19:08:01 +00:00
bsm Add aio_writev and aio_readv 2021-01-02 19:57:58 -07:00
cam cam: Remove Giant handling from cam_sim_alloc() 2021-01-03 11:50:31 -05:00
cddl riscv: fix kernel build 2021-01-15 11:57:04 -04:00
compat LinuxKPI: Reimplement irq_work queue on top of fast taskqueue 2021-01-17 12:47:28 +01:00
conf mips: Add the device-tree path to the include paths 2021-01-16 11:33:37 +01:00
contrib Re-apply f81b2b9a8a to the new device-tree import 2021-01-15 20:07:13 +01:00
crypto armv8crypto: add AES-XTS support 2021-01-07 15:35:20 -04:00
ddb ddb: add ability to print user registers 2021-01-08 14:53:06 -04:00
dev openpromio(4): remove obsolete pseudo device driver 2021-01-16 23:53:13 +01:00
dts Switch to the new device-tree vendor tree 2021-01-15 20:08:39 +01:00
fs tmpfs_reclaim: detach unlinked node on dereferencing. 2021-01-14 14:51:37 +02:00
gdb gdb(4): allow bulk write of registers 2020-12-23 14:37:05 -04:00
geom geom(4): make g_newprovider_event() return if G_P_WITHER is set 2020-12-29 14:29:59 +00:00
gnu Remove the old dts imported tree. 2021-01-15 20:09:55 +01:00
i386 wl(4): remove obsolete header 2021-01-17 00:03:17 +01:00
isa
kern Save on getpid in setproctitle by supporting -1 as curproc. 2021-01-16 09:36:54 +01:00
kgssapi State kgssapi dependency on xdr. 2020-09-17 22:29:38 +00:00
libkern libkern/strcasestr.c: Drop xlocale support and connect to build. 2021-01-08 02:18:42 +03:00
mips mips: Fix build by using the correct device-tree include path 2021-01-16 11:34:10 +01:00
modules Add driver for Synopsys Designware Watchdog timer. 2021-01-13 18:43:47 +01:00
net Split rtinit() into multiple functions. 2021-01-16 22:42:41 +00:00
net80211 net80211: fix a typo 2020-11-04 12:07:33 +00:00
netgraph pccard: Remove bt3c(4) driver 2021-01-07 20:40:41 -07:00
netinet Split rtinit() into multiple functions. 2021-01-16 22:42:41 +00:00
netinet6 Split rtinit() into multiple functions. 2021-01-16 22:42:41 +00:00
netipsec Trigger soft lifetime expiration on sequence number 2020-10-16 11:27:01 +00:00
netpfil pf: Don't hold PF_RULES_WLOCK during copyin() on DIOCRCLRTSTATS 2021-01-13 19:49:42 +01:00
netsmb
nfs
nfsclient
nfsserver nfs: Mark unused statistics variable as reserved 2020-11-18 04:35:49 +00:00
nlm
ofed Update user access region, UAR, APIs in the core in mlx5core. 2021-01-08 13:33:46 +01:00
opencrypto Remove the cloned file descriptors for /dev/crypto. 2020-11-25 00:10:54 +00:00
powerpc Split out the NODEBUG options to a common file 2021-01-14 16:57:53 +00:00
riscv riscv: Fix build by using the correct device-tree include path 2021-01-16 11:31:39 +01:00
rpc nfs-over-tls: handle res.gid.gid_val correctly for memory allocation 2021-01-12 13:59:52 -08:00
security Convert remaining cap_rights_init users to cap_rights_init_one 2021-01-12 13:16:10 +00:00
sys fd: add refcount argument to falloc_noinstall 2021-01-13 15:29:34 +00:00
teken loader: implement framebuffer console 2021-01-02 21:41:36 +02:00
tests Add fib lookup testing module. 2021-01-09 13:20:30 +00:00
tools Switch to the new device-tree vendor tree 2021-01-15 20:08:39 +01:00
ufs Eliminate a locking panic when cleaning up UFS snapshots after a 2021-01-15 16:36:42 -08:00
vm vm_map_protect(): remove not needed recalculations of new_prot, new_maxprot 2021-01-14 10:02:43 +02:00
x86 Revert "x86 busdma_bounce: do not make assumptions about alignment of malloc(9) results." 2021-01-13 17:44:00 +02:00
xdr
xen xen: remove .swp file from public headers 2021-01-11 18:14:11 +01:00
Makefile