opnsense-src/sys/compat/linuxkpi/common/include/linux
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
..
acpi.h LinuxKPI: Exclude linux/acpi.h content on non-ACPI archs. 2020-11-14 10:34:18 +00:00
atomic.h LinuxKPI: Include asm/atomic-long.h from atomic.h. 2019-05-15 17:44:25 +00:00
backlight.h linuxkpi: Add backlight support 2020-10-02 18:26:41 +00:00
bitfield.h LinuxKPI: add a bitfield.h implementation. 2020-10-07 22:07:26 +00:00
bitmap.h Implement the bitmap_subset() function in the LinuxKPI. This function 2020-07-10 12:06:18 +00:00
bitops.h Prefer using the MIN() function macro over the min() inline function 2020-12-07 09:48:06 +00:00
bottom_half.h Add support for LinuxKPI tasklets. 2017-02-21 13:23:53 +00:00
cache.h
cdev.h linuxkpi: Remove extraneous NULL check on M_WAITOK allocation 2019-01-01 19:56:49 +00:00
clocksource.h Remove cycle_t type from the LinuxKPI similar to Linux upstream. 2017-07-31 09:17:54 +00:00
compat.h compat: clean up empty lines in .c and .h files 2020-09-01 21:24:33 +00:00
compiler.h linuxkpi: Add __same_type and __must_be_array macros 2020-05-25 12:42:55 +00:00
completion.h Correct macroname in the LinuxKPI. 2018-05-31 12:55:38 +00:00
dcache.h Refactor dentry structure into its own header file in the LinuxKPI similary 2018-02-18 08:29:25 +00:00
debugfs.h import linux debugfs support 2019-02-23 20:56:41 +00:00
delay.h Use mstosbt() instead of SBT_1MS in the LinuxKPI to get the last few bits 2018-03-03 19:26:40 +00:00
device.h linuxkpi: Add backlight support 2020-10-02 18:26:41 +00:00
dma-attrs.h compat: clean up empty lines in .c and .h files 2020-09-01 21:24:33 +00:00
dma-mapping.h compat: clean up empty lines in .c and .h files 2020-09-01 21:24:33 +00:00
dmapool.h compat: clean up empty lines in .c and .h files 2020-09-01 21:24:33 +00:00
dmi.h linuxkpi: Add dmi_* function 2020-10-02 18:28:00 +00:00
err.h Cleanups to *ERR* compat shims. 2020-12-17 20:28:53 +00:00
errno.h linuxkpi: Add EBADRQC to errno.h 2020-05-13 07:49:12 +00:00
etherdevice.h Replace read_random(9) with more appropriate arc4rand(9) KPIs 2019-04-04 01:02:50 +00:00
export.h Move the EXPORT_SYMBOL_XXX() function macros into own header file. 2018-06-07 11:34:59 +00:00
file.h fd: remove the seq argument from fget_unlocked 2020-02-03 22:27:55 +00:00
fs.h linuxkpi: Add dmi_* function 2020-10-02 18:28:00 +00:00
gcd.h linuxkpi: Add gcd function 2020-10-06 10:35:03 +00:00
gfp.h Add necessary bits for Linux KPI to work correctly on powerpc 2019-08-04 19:28:10 +00:00
hardirq.h linuxkpi: Include hardirq.h in preempt.h and lockdep.h in hardirq.h 2020-07-26 16:30:59 +00:00
hrtimer.h Improve high resolution timer support in the LinuxKPI. 2018-06-01 11:33:14 +00:00
idr.h Resolve duplicate symbol name conflict after r345095, when building LINT. 2019-03-13 19:53:20 +00:00
if_arp.h
if_ether.h linuxkpi whitespace cleanup 2018-03-23 15:50:01 +00:00
if_vlan.h linuxkpi whitespace cleanup 2018-03-23 15:50:01 +00:00
in.h Add support for more IPv4 and IPv6 related macros in the LinuxKPI. 2017-03-22 15:44:00 +00:00
in6.h Unconditionally include "opt_inet6.h" in the LinuxKPI. 2017-11-01 12:21:28 +00:00
inetdevice.h Mechanical cleanup of epoch(9) usage in network stack. 2019-01-09 01:11:19 +00:00
interrupt.h Fix broken DECLARE_TASKLET() macro after r347852. 2019-09-11 07:53:49 +00:00
io-mapping.h Let io_mapping_init_wc() fall back to an uncacheable mapping. 2017-07-03 02:01:16 +00:00
io.h compat: clean up empty lines in .c and .h files 2020-09-01 21:24:33 +00:00
ioctl.h Define _IOC_SIZE() in the LinuxKPI. 2016-05-13 11:42:36 +00:00
irq_work.h LinuxKPI: Reimplement irq_work queue on top of fast taskqueue 2021-01-17 12:47:28 +01:00
irqreturn.h Move the IRQ_RETVAL() and irqreturn definitions to irqreturn.h in the 2018-02-17 20:37:21 +00:00
jhash.h compat: clean up empty lines in .c and .h files 2020-09-01 21:24:33 +00:00
jiffies.h linuxkpi: Add time_after32 and time_before32 2020-08-04 15:27:32 +00:00
kdev_t.h Fix LinuxKPI regression after r321920. The mda_unit and si_drv0 fields are not 2017-08-02 14:27:27 +00:00
kernel.h Remove ifdefs around IS_ALIGNED() definition in the LinuxKPI. 2020-10-16 11:01:21 +00:00
kmod.h compat: clean up empty lines in .c and .h files 2020-09-01 21:24:33 +00:00
kobject.h linuxkpi whitespace cleanup 2018-03-23 15:50:01 +00:00
kref.h compat: clean up empty lines in .c and .h files 2020-09-01 21:24:33 +00:00
kthread.h Add kthread parking support to the LinuxKPI. 2017-06-18 19:22:05 +00:00
ktime.h LinuxKPI: Expand ktime functionality. 2019-05-15 16:59:04 +00:00
list.h Allow the list header file in the LinuxKPI to be used in standalone code. 2020-12-04 15:46:48 +00:00
llist.h LinuxKPI: Reimplement irq_work queue on top of fast taskqueue 2021-01-17 12:47:28 +01:00
lockdep.h Fix r363565 2020-07-26 18:33:29 +00:00
log2.h linuxkpi whitespace cleanup 2018-03-23 15:50:01 +00:00
math64.h Implement DIV64_U64_ROUND_UP() in the LinuxKPI. 2020-05-01 10:25:07 +00:00
miscdevice.h linuxkpi whitespace cleanup 2018-03-23 15:50:01 +00:00
mm.h Remove set_page_dirty_lock(). 2020-01-02 19:29:14 +00:00
mm_types.h Implement mmget_not_zero() in the LinuxKPI. 2020-01-24 13:05:53 +00:00
mod_devicetable.h linuxkpi: Add dmi_* function 2020-10-02 18:28:00 +00:00
module.h Move the EXPORT_SYMBOL_XXX() function macros into own header file. 2018-06-07 11:34:59 +00:00
moduleparam.h Stub kernel_param_lock() and kernel_param_unlock() in the LinuxKPI. 2018-03-04 19:10:30 +00:00
mutex.h linuxkpi: Add nested variant of mutex_lock_interruptible 2020-08-04 14:45:22 +00:00
net.h
net_dim.h Add support for Dynamic Interrupt Moderation, DIM, in mlx5en(4). 2019-05-08 10:23:33 +00:00
netdevice.h Fix missing epochification of the LinuxKPI after r353292. 2019-10-15 11:14:14 +00:00
notifier.h Add definition for the NETDEV_CHANGE event and tidy up the LinuxKPI 2016-01-26 14:27:00 +00:00
numa.h linuxkpi: Add numa.h 2020-10-06 10:36:16 +00:00
overflow.h Implement the array_size() function in the LinuxKPI. This function 2020-07-10 11:27:54 +00:00
page.h Make sure the "vm_flags" and "vm_page_prot" fields get set correctly 2017-08-11 10:44:40 +00:00
pagemap.h linuxkpi: Add pagemap.h 2020-10-06 10:41:00 +00:00
pci.h linuxkpi: Add more pci functions needed by DRM 2021-01-12 12:31:00 +01:00
pfn.h Implement a series of physical page management related functions in 2017-03-27 17:04:11 +00:00
pfn_t.h Implement a series of physical page management related functions in 2017-03-27 17:04:11 +00:00
pid.h Implement get_task_pid() function macro in the LinuxKPI. 2018-02-17 22:33:26 +00:00
poll.h Properly implement poll_wait() in the LinuxKPI. This prevents direct 2017-09-09 06:29:29 +00:00
power_supply.h linuxkpi: Add power_supply.h 2020-10-06 10:39:40 +00:00
preempt.h linuxkpi: Include hardirq.h in preempt.h and lockdep.h in hardirq.h 2020-07-26 16:30:59 +00:00
prefetch.h linuxkpi: Add prefetch.h 2020-10-06 10:37:21 +00:00
printk.h Use the 't' modifier to print a ptrdiff_t. 2020-12-16 00:11:30 +00:00
radix-tree.h Implement radix_tree_store() in the LinuxKPI for use with the coming 2020-08-07 16:15:44 +00:00
random.h linuxkpi: Fix the "error: unknown type name 'u32'" compilation issue when 2021-01-09 15:27:04 -08:00
rbtree.h Allow the rbtree header file in the LinuxKPI to be used in standalone code. 2020-12-04 15:50:44 +00:00
rculist.h Implement more RCU list functions in the LinuxKPI. 2020-10-13 16:19:21 +00:00
rcupdate.h linuxkpi: Add rcu_swap_protected 2020-05-27 10:01:30 +00:00
refcount.h linuxkpi: Add refcount.h 2020-05-25 12:44:07 +00:00
rwlock.h linuxkpi whitespace cleanup 2018-03-23 15:50:01 +00:00
rwsem.h linuxkpi whitespace cleanup 2018-03-23 15:50:01 +00:00
scatterlist.h Prefer using the MIN() function macro over the min() inline function 2020-12-07 09:48:06 +00:00
sched.h Need to clone the task struct fields related to RCU aswell in the 2020-08-11 12:17:46 +00:00
semaphore.h Use function macro for sema_init() in the LinuxKPI to limit macro expansion scope. 2020-11-30 09:47:53 +00:00
seq_file.h LinuxKPI: Finalize import of seq_file. 2019-05-16 21:17:18 +00:00
shmem_fs.h linuxkpi: Move shmem related functions in it's own file 2020-02-21 09:28:45 +00:00
shrinker.h linuxkpi: Add shrinker support 2021-01-12 12:31:00 +01:00
sizes.h linuxkpi: Add linux/sizes.h 2020-08-04 14:42:38 +00:00
slab.h LinuxKPI: Reimplement irq_work queue on top of fast taskqueue 2021-01-17 12:47:28 +01:00
smp.h Add on_each_cpu() and wbinvd_on_all_cpus(). 2017-05-01 16:32:28 +00:00
socket.h
spinlock.h linuxkpi whitespace cleanup 2018-03-23 15:50:01 +00:00
srcu.h Implement synchronize_srcu_expedited() in the LinuxKPI. 2020-05-16 14:27:50 +00:00
string.h linuxkpi: Ignore NULL pointers passed to string parameter of kstr(n)dup 2020-07-14 21:56:59 +00:00
swap.h linuxkpi: Use pageproc instead of vmproc 2018-11-21 04:34:18 +00:00
sysfs.h compat: clean up empty lines in .c and .h files 2020-09-01 21:24:33 +00:00
time.h Make timespecadd(3) and friends public 2018-07-30 15:46:40 +00:00
timer.h linuxkpi: Fix mod_timer and del_timer_sync 2020-05-25 12:46:05 +00:00
types.h Allow LinuxKPI types to be used in bootloaders, by checking for the 2020-11-18 13:47:11 +00:00
uaccess.h LinuxKPI: Update access_ok macro for v5.0. 2019-05-16 17:44:17 +00:00
usb.h linuxkpi whitespace cleanup 2018-03-23 15:50:01 +00:00
vmalloc.h
wait.h linuxkpi: Add a few wait_bit functions 2020-08-14 08:48:17 +00:00
wait_bit.h linuxkpi: Add a few wait_bit functions 2020-08-14 08:48:17 +00:00
workqueue.h linuxkpi: Add rcu_work functions 2020-05-21 20:18:38 +00:00
ww_mutex.h Populate the acquire context field of a ww_mutex in the LinuxKPI. 2020-10-04 17:23:39 +00:00
xarray.h Implement xa_init() in the LinuxKPI as a wrapper for xa_init_flags(). 2020-10-24 13:16:10 +00:00