Page MenuHomeFreeBSD

linuxkpi: implement irqs_disabled
Needs ReviewPublic

Authored by ashafer on Tue, Jun 23, 7:01 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Jul 11, 8:41 PM
Unknown Object (File)
Sat, Jul 11, 8:10 AM
Unknown Object (File)
Fri, Jul 10, 6:45 PM
Unknown Object (File)
Sun, Jul 5, 9:24 PM
Unknown Object (File)
Sun, Jul 5, 9:21 PM
Unknown Object (File)
Sat, Jul 4, 8:55 AM
Unknown Object (File)
Sat, Jul 4, 1:25 AM
Unknown Object (File)
Sat, Jul 4, 1:22 AM

Details

Reviewers
None
Group Reviewers
linuxkpi
Summary

This adds a function which is used from various places in drm-kmod
to detect if the code can sleep or not. Currently, these locations
(such as intel_guc_send_busy_loop) are ifdeffed to freebsd specific
solutions (usually drm_can_sleep).

This change implements irqs_disabled. We check td_pinned as spinlocks
will call sched_pin, and td_critnest to check if we are in a critical
section.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 74161
Build 71044: arc lint + arc unit

Event Timeline

I like it and I love your detailed explanation!

I'll wait for @dumbbell as wireless does not seem to use it currently.
I am wondering how much code can/must be adjusted in the follow-up and do we do the right thing (cpu_relax)?

There's a few places in drm-kmod but it's not much:

% rg -i irqs_disabled .       
./drivers/gpu/drm/i915/i915_request.c
622:	GEM_BUG_ON(!irqs_disabled());
734:	GEM_BUG_ON(!irqs_disabled());

./drivers/gpu/drm/i915/intel_runtime_pm.h
33: * The irqs_disabled variable becomes true exactly after we disable the IRQs and

./include/drm/drm_util.h
84:	if (in_atomic() || in_dbg_master() || irqs_disabled())

./drivers/gpu/drm/i915/gt/intel_engine_cs.c
1616:	if (in_atomic() || irqs_disabled()) /* inside atomic preempt-reset? */

./drivers/gpu/drm/i915/gt/uc/intel_guc.h
370:	bool not_atomic = !in_atomic() && !irqs_disabled();
wulf added inline comments.
sys/compat/linuxkpi/common/include/linux/hardirq.h
60

According to Linux docs, spin_lock() does not disable local IRQs. Only spin_lock_irq() and spin_lock_irqsave() do it.
Probably this implementation will result in false positive if ordinary spinlock is held.

Historically drm-kmod had bundled irqs_disabled() implementation that was lost during bundled->insystem LinuxKPI transition.
See commit 530462939f6. IMO we should revert it.

Reverting 530462939f6 (or moving its irqs_disabled() definition somewhere else) seems reasonable to me. What was the motivation of that change originally? It sounds like just removing that header file? Is that a change you'd like to make or want me to post?