Skip to content

nvme: apple: keep bounced segments aligned to the controller page - #2094

Merged
RyanTheTide merged 1 commit into
aurora-silicon:integration/aurorafrom
term-guy:apple-nvme-bounce-upstream
Nov 22, 2026
Merged

RyanTheTide merged 1 commit into
aurora-silicon:integration/aurorafrom
term-guy:apple-nvme-bounce-upstream

Conversation

@term-guy

@term-guy term-guy commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

PRP list entries must be NVME_CTRL_PAGE_SIZE aligned. The ANS is not DMA-coherent, so dma-direct bounces segments smaller than a cache line through swiotlb, and a bounce slot can start at any 2 KiB boundary. With O_DIRECT buffers that are not page aligned (Ubuntu 26.04's uutils dd uses page offset 0x10), every 1 MiB command ends in a 16-byte tail that gets bounced; on T8142 a tail bounced to page offset 0x800 made the ANS firmware assert ("SLL idx 0 F2H error 0x200 - PRP_DDR_ERR") and the controller could not recover without a reboot.

Set the DMA min_align_mask to NVME_CTRL_PAGE_SIZE - 1, as nvme-pci does. With it, the same unaligned 2 MiB read 30 times, 4 MiB direct reads and 4 GiB sequential reads complete.

Tested on J704 (read-only tests of the internal SSD). Written with an AI assistant and tested on the hardware by me.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor

Blockers: 1.

The fix is right. dma-direct bounces the sub-cache-line tail of a non-coherent mapping through swiotlb. Without a min_align_mask, the slot keeps only IO_TLB_SIZE alignment, so a bounced PRP entry can start at offset 0x800. drivers/nvme/host/apple.c:2584 sets the same mask as nvme-pci, before any queue or PRP pool is set up and right after the DMA mask. The device is an OF platform device, so it has dma_parms and the call can't hit its WARN.

  1. Commit 215e339 carries an Assisted-By: LLM trailer. Drop it from the commit, which should keep only your Signed-off-by. Put Assisted-by: LLM (<Vendor>:<Model>) as the last line of the PR body instead.

HW row: the body describes the failure on T8142 and the passing run on J704. Please give the J704's SoC and the kernel build. Also run the same uutils dd O_DIRECT read at page offset 0x10 on an M1 or M2 (SART-based ANS). Pass criteria: no ANS assert, the read completes, and the regression line shows 0 failed units, 0 SELinux denials and 0 new kernel errors.

Assisted-by: LLM (Claude:Opus 5.5)

PRP list entries must be NVME_CTRL_PAGE_SIZE aligned. When dma-direct
bounces a segment through swiotlb (the ANS is not DMA-coherent, so
segments smaller than the cache line are bounced), the bounce slot can
start at any IO_TLB_SIZE (2 KiB) boundary, and a bounced segment that
ends up as a PRP list entry is then misaligned.

This happens with O_DIRECT buffers that are not page aligned (e.g. the
uutils dd in Ubuntu 26.04 uses buffers at page offset 0x10): every 1 MiB
command ends in a 16-byte tail segment that gets bounced. On T8142 (M5)
a tail bounced to a slot at page offset 0x800 made the ANS firmware
assert ("SLL idx 0 F2H error 0x200 - PRP_DDR_ERR") and the controller
could not be recovered without a reboot.

Set the DMA min_align_mask to NVME_CTRL_PAGE_SIZE - 1, as nvme-pci does,
so swiotlb preserves the offset within the controller page. With this,
the same 2 MiB unaligned read 30 times, 4 MiB direct reads and 4 GiB
sequential reads complete without errors.

Signed-off-by: termg <[email protected]>
@term-guy
term-guy force-pushed the apple-nvme-bounce-upstream branch from 215e339 to 2cb43fe Compare November 21, 2026 12:53
@term-guy

Copy link
Copy Markdown
Contributor Author

Thanks. HW row details: the J704 is the 14-inch MacBook Pro M5, SoC T8142 (apple,t8142). I didn't keep the kernel build of the passing run, so I'll repeat it on a 7.3.0 build with this commit and post that row with uname -r and the commit.

We have no M1 or M2, so I can't give the SART row myself; it needs someone with one of those Macs.

Trailer: gone. I rewrote the branch once for it (same tree, new hash), so the commit carries only my Signed-off-by, and the PR body ends with the Assisted-by line.

Assisted-by: LLM (Claude:Opus 5.5)

@term-guy

Copy link
Copy Markdown
Contributor Author

J704 row with this commit: MacBook Pro 14-inch M5 (J704, SoC T8142), Fedora 44, kernel 7.3.0+ (aurora-silicon tree with the J704 DT, the same build as the installed kit kernel) with nvme-apple.ko rebuilt with 2cb43fe, chainloaded. Fedora's GNU dd aligns its buffers, so the unaligned case is a small read-only script that does what uutils dd does: O_DIRECT reads of /dev/nvme0n1 into a buffer at page offset 0x10.

  • 30 x 2 MiB reads: ok
  • 64 x 4 MiB reads: ok
  • 4 parallel readers, 64 x 2 MiB each: ok
  • then a 4 GiB sequential direct read (GNU dd, bs=4M): 4.2 GB/s

No ANS assert (no PRP_DDR, assert failed or RTKit crashed in dmesg), nvme0n1 still present, 0 new kernel error lines, 0 failed units, 0 SELinux denials (enforcing).

The M1/M2 (SART) row still needs someone with one of those Macs.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor

Re-review of 2cb43fe: No blockers.

From the last comment:

  • The agent trailer in the commit: resolved. 2cb43fe carries only the author's Signed-off-by, and the PR body ends with the Assisted-by line. The code is unchanged: drivers/nvme/host/apple.c:2584 still sets the mask right after the DMA mask.
  • HW row: the J704 (T8142) row on this commit covers the reported case. It includes O_DIRECT reads at page offset 0x10, parallel readers and a 4 GiB sequential read, with no assert and 0 failed units, 0 AVC denials and 0 new kernel errors.

The only row still open is a SART-based ANS. That needs a tester with the hardware; it doesn't block the change.

HW row: M1 or M2 (SART ANS), the same kernel plus 2cb43fe, and the same O_DIRECT read script at page offset 0x10. Pass: no controller assert, the reads complete, and the regression line shows 0 failed units, 0 AVC denials and 0 new kernel errors.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide
RyanTheTide merged commit a6d0a19 into aurora-silicon:integration/aurora Nov 22, 2026
1 check passed
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.

2 participants