Skip to content

LinuxKPI: Run irq_work callbacks under RCU protection - #2385

Open
JustAnotherHumanBeing wants to merge 1 commit into
freebsd:mainfrom
JustAnotherHumanBeing:agent/linuxkpi-irq-work-rcu
Open

LinuxKPI: Run irq_work callbacks under RCU protection#2385
JustAnotherHumanBeing wants to merge 1 commit into
freebsd:mainfrom
JustAnotherHumanBeing:agent/linuxkpi-irq-work-rcu

Conversation

@JustAnotherHumanBeing

Copy link
Copy Markdown

Problem

Linux irq_work callbacks execute in interrupt context, which provides
implicit RCU read-side protection on non-PREEMPT_RT kernels. LinuxKPI
dispatches these callbacks through a taskqueue without equivalent RCU
protection. A grace period can therefore complete while a callback is still
using an RCU-protected object. This produced the i915/GuC use-after-free
reported in freebsd/drm-kmod#489.

Change

Wrap irqw->func(irqw) in rcu_read_lock() and rcu_read_unlock(). The
current taskqueue selection is unchanged.

The LinuxKPI-level approach was proposed by @wulf7 in
freebsd/drm-kmod#489 (comment). He
subsequently confirmed that the RCU correction is independent of the
taskqueue-selection change discussed there:
freebsd/drm-kmod#489 (comment).

Testing

  • A purpose-built irq_work/RCU test failed deterministically on the
    unpatched kernel: synchronize_rcu() returned while the callback remained
    active.
  • The same test passed 27 consecutive times with this change.
  • A complete GENERIC kernel and module build from current main completed
    successfully with -Werror.
  • drm-kmod 6.12 was built without the driver-local workaround from
    drm/i915: Extend RCU protection in signal_irq_work() [FreeBSD] drm-kmod#491. Thirty controlled i915 recovery cycles were requested
    while a Mesa workload was active. No panic, use-after-free, or relevant
    INVARIANTS/WITNESS diagnostic occurred, and normal rendering succeeded
    afterward.

Related: freebsd/drm-kmod#489
Base-system alternative to: freebsd/drm-kmod#491

@github-actions

github-actions Bot commented Aug 23, 2026

Copy link
Copy Markdown

Thank you for taking the time to contribute to FreeBSD!

All issues resolved.

Linux executes irq_work callbacks from an interrupt context that
provides implicit RCU read-side protection. LinuxKPI dispatches these
callbacks through a taskqueue, so provide equivalent protection
explicitly.

This prevents an RCU grace period from completing while an irq_work
callback is still using an RCU-protected object.

Suggested by:	wulf
Tested by:	JustAnotherHumanBeing
Signed-off-by: JustAnotherHumanBeing <oleglelchuk@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant