[BUG] dm-raid/raid1: IRQ stack overflow in bio completion during fstrim on NVMe

From
张晓宜 <hidden>
Date
2026-12-02 07:10:59
Also in
dm-devel, linux-block
This is a plain-text resend. The earlier message was rejected by the
lists because it contained an HTML part.

Ubuntu Launchpad bug:
https://bugs.launchpad.net/ubuntu/+source/linux/+bug/2179436

Running fstrim on an XFS filesystem located on an LVM RAID1 logical
volume backed by two NVMe SSDs can overflow the x86_64 IRQ stack and
panic the kernel.

I reproduced this on Ubuntu 6.17.0-14-generic and 7.0.0-44-generic
kernels. The kernels were not tainted. Ubuntu's default weekly
fstrim.timer was sufficient to trigger the original panics; no special
application workload was required.

Reducing the dm-raid device's discard_max_bytes avoids the panic in
repeated tests and appears to bound the problematic bio-completion
chain. This is a workaround, not a fix.

Only Ubuntu distribution kernels have been tested so far. I have not
yet reproduced this on an unmodified upstream/mainline kernel.

Affected versions
=================

- 6.17.0-14-generic (#14~24.04.1-Ubuntu)
- 7.0.0-44-generic (#44-Ubuntu), Ubuntu 26.04 LTS

Hardware and storage topology
=============================

- Dell PowerEdge R640
- Two Samsung MZPLJ12THALA NVMe SSDs
- No hardware RAID controller in this storage path

The filesystem stack is:

    XFS on /export
      -> LVM RAID1 logical volume (dm-raid, raid1)
        -> dm-linear rimage/rmeta mappings
          -> partitions on the two NVMe SSDs

The RAID1 members are in sync. No MCE/EDAC errors or NVMe media errors
were observed. The same failure occurred on multiple CPUs and across
several boots.

Reproduction
============

WARNING: These steps can panic the machine. Use them only on a test
system or during a maintenance window, with a working console and
crash-dump/recovery mechanism.

With the default dm-raid queue limit:

    discard_max_bytes = 2199023255040 bytes (approximately 2 TiB)

running:

    fstrim -v /export

was enough to trigger the panic in multiple independent tests. The
default weekly fstrim.timer also triggered it.

The failure is more reproducible with a value just below 4 GiB:

    echo 4294963200 > /sys/block/dm-X/queue/discard_max_bytes
    fstrim -v /export

Replace dm-X with the top-level dm-raid device. This setting caused
the panic within seconds in two separate tests.

Actual result
=============

The kernel reports an IRQ stack guard-page hit, followed by an oops and:

    Kernel panic - not syncing: Fatal exception in interrupt

The following is an abridged trace from 7.0.0-44-generic. Register
dumps, kernel addresses, and dozens of repeated callback groups have
been omitted.

    BUG: IRQ stack guard page was hit ...
    Oops: stack guard page: 0000 [#1] SMP PTI
    CPU: 1 UID: 0 PID: 0 Comm: swapper/1 Not tainted 7.0.0-44-generic #44-Ubuntu
    Hardware name: Dell Inc. PowerEdge R640
    RIP: 0010:bdev_end_io_acct+0x6e/0x280
    Call Trace:
     <IRQ>
     dm_io_acct+0x70/0x160
     __dm_io_complete+0x1b3/0x330
     dm_io_dec_pending+0x3c/0xa0
     clone_endio+0x94/0x1d0
     bio_endio+0x15e/0x210
     __dm_io_complete+0x168/0x330
     dm_io_dec_pending+0x3c/0xa0
     clone_endio+0x94/0x1d0
     bio_endio+0x15e/0x210
     [the preceding callback group repeats dozens of times]
     md_end_clone_io+0x4f/0x140
     bio_endio+0x15e/0x210
     raid_end_bio_io+0x49/0x170 [raid1]
     r1_bio_write_done.part.0+0x3e/0x50 [raid1]
     raid1_end_write_request+0x122/0x3f0 [raid1]
     bio_endio+0x15e/0x210
     __dm_io_complete+0x168/0x330
     dm_io_dec_pending+0x3c/0xa0
     clone_endio+0x94/0x1d0
     bio_endio+0x15e/0x210
     blk_mq_end_request_batch+0x142/0x680
     nvme_pci_complete_batch+0x57/0x70 [nvme]
     nvme_irq+0x87/0xa0 [nvme]
     __handle_irq_event_percpu+0x59/0x230
     handle_irq_event+0x36/0x90
     handle_edge_irq+0xd3/0x1a0
     __common_interrupt+0x50/0x160
     common_interrupt+0x51/0xe0
     ...
    Kernel panic - not syncing: Fatal exception in interrupt

On 6.17.0-14-generic, the same IRQ stack guard-page failure occurred
with RIP in __slab_free and with __dm_io_complete, dm_io_dec_pending,
and clone_endio in the IRQ portion of the trace.

Expected result
===============

A legal discard size or queue limit must not overflow the IRQ stack.
Deep bio completion chains should be flattened, deferred, or otherwise
bounded rather than recursively consuming the interrupt stack.

discard_max_bytes experiments
=============================

Each "pass" below means one complete fstrim invocation over the same
XFS filesystem. A crash is probabilistic near the boundary, so a
single pass is not considered proof of safety.

- 16777216 bytes (16 MiB): 1 pass
- 134217728 bytes (128 MiB): 1 pass
- 536870912 bytes (512 MiB): 4 passes
- 1073741824 bytes (1 GiB): 6 passes
- 1342177280 bytes (1.25 GiB): 3 passes
- 1610612736 bytes (1.5 GiB): 3 passes
- 1879048192 bytes (1.75 GiB): 3 passes
- 2147483648 bytes (2 GiB): 1 pass and 1 panic
- 4294963200 bytes (4 GiB minus 4 KiB): 2 panics
- Default, approximately 2 TiB: multiple panics on both affected kernel series

At 16 MiB, bpftrace tracing of bio_split during one fstrim run counted
587762 discard-related splits, with most split sizes at the configured
16 MiB limit. During that test, upper-layer discard bios up to
approximately 4 GiB were still observed being split.

This suggests that the limit changes where bios are split and appears
to bound the problematic completion chain. It is not simply reducing
the duration of one hardware interrupt.

Workaround
==========

Setting the top-level dm-raid device's discard_max_bytes to 1 GiB has
survived six complete fstrim runs:

    echo 1073741824 > /sys/block/dm-X/queue/discard_max_bytes

I also installed a device-specific udev rule so the value is restored
after reboot or device reactivation. The weekly fstrim timer remains
enabled.

This is only an empirical workaround. In particular, 1.75 GiB passed
three tests while 2 GiB later crashed on a repeat test, so the exact
boundary is timing-dependent.

Additional observations
=======================

- Full kernel logs and vmcores were captured with pstore/ERST and kdump.
- The failure occurs in interrupt context while completing NVMe
requests, not in the fstrim process's own stack.
- The trace shows repeated synchronous parent/child bio completion
callbacks through DM core and md RAID1.
- No storage-media or machine-check errors were found.

Possibly related historical fix
================================

Commit c8156fc77d07 ("dm raid: fix updating of max_discard_sectors
limit", 2019) described nested clone_endio callbacks and stack
corruption for an older dm-raid queue-limit bug. I do not know whether
the current failure has the same root cause, but its failure mode is
similar enough to mention.

Data available for maintainers
==============================

Sanitized log excerpts are included above. Full raw logs and
compressed vmcores are retained locally. Because raw logs and
especially vmcores can contain site or application data, they are not
attached publicly; selected evidence can be shared privately with a
trusted maintainer if required.
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help