Skip to content

PCI, drm/radeon: honor IORESOURCE_MEM_NONPOSTED for BAR mmaps and VRAM BOs - #3486

Merged
DjDeveloperr merged 4 commits into
mainfrom
fix/pci-radeon-nonposted-vram
Dec 3, 2026
Merged

DjDeveloperr merged 4 commits into
mainfrom
fix/pci-radeon-nonposted-vram

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Problem.
On Apple Silicon PCIe fabrics (marked IORESOURCE_MEM_NONPOSTED), write-combined (Normal-NC) mappings of a PCIe BAR allow dc zva (emitted by memset(0) in both kernel and userspace) to trigger an asynchronous SError kernel panic. Three userspace paths and several remaining radeon kernel VRAM/MMIO paths remained unguarded beyond #3464:

  1. drivers/pci/{mmap,iomap,pci-sysfs}.c: pci_mmap_resource_range(), pci_iomap_wc_range(), and sysfs resourceN_wc ignored IORESOURCE_MEM_NONPOSTED.
  2. radeon userspace VRAM & fbdev mmaps: radeon_ttm_io_mem_reserve() did not set mem->bus.is_nonposted, radeon_bo_fault_reserve_notify() did not migrate userspace VRAM faults to GTT, radeon_gem_info_ioctl() still reported CPU-visible VRAM, radeon_mode_dumb_create() allocated in VRAM, and radeon_fbdev inherited fb_io_mmap() (pgprot_framebuffer = write-combine on arm64).
  3. Remaining radeon kernel paths: radeon_device.c (rmmio, doorbell.ptr) and radeon_bios.c (igp_read_bios_from_vram) used ioremap() instead of ioremap_np(); evergreen.c, cik.c, radeon_fence.c, radeon_uvd.c, uvd_v1_0.c, and radeon_test.c performed plain accesses on VRAM BOs.

Change.

  • PCI core: hide resourceN_wc in sysfs and force pgprot_noncached / ioremap_np when IORESOURCE_MEM_NONPOSTED is set.
  • radeon userspace & MMIO: set mem->bus.is_nonposted, migrate userspace VRAM faults to GTT (returning VM_FAULT_SIGBUS for pinned BOs), report vram_visible = 0, place CPU-accessible / dumb BOs in GTT, map non-coherent GTT pages WC, override radeon_fbdev .fb_mmap to use pgprot_noncached on non-posted BAR0, and use ioremap_np() for rmmio, doorbell.ptr, and VRAM BIOS reads.
  • radeon kernel BO helpers: add radeon_bo_{memset,memcpy_to,memcpy_from} and convert remaining VRAM BO accesses in evergreen.c, cik.c, radeon_fence.c, radeon_uvd.c (with per-message-type bounds and overflow guards), uvd_v1_0.c, and radeon_test.c (zero file overlap with drm/radeon: use I/O accessors for the VCE firmware upload #3464).

Tested: cross-compiled all 15 modified objects (arm64, LLVM=1, W=1, 0 warnings); scripts/checkpatch.pl --no-tree clean across all 4 commits (0 errors, 0 warnings). Software-only lane; K114s + R9 390X hardware tests (userspace memset(0) on radeon VRAM GEM mmap, /dev/fbN, and resource0, plus resource0_wc absence and radeon probe/display) are pending handoff to the Thunderbolt/PCIe test lane.
Risk: two-way — gated on IORESOURCE_MEM_NONPOSTED so posted PCIe fabrics see no behavioral change; reverts cleanly.

On fabrics where PCIe BARs are flagged IORESOURCE_MEM_NONPOSTED, a
write-combined (Normal-NC) mapping permits arm64 DC ZVA (used by libc
memset(0)) to reach the PCIe root complex and trigger a fatal
asynchronous SError, and a posted Device-nGnRE mapping violates the
non-posted requirement.

Force pgprot_noncached() in pci_mmap_resource_range() and ioremap_np()
in pci_iomap_wc_range() when IORESOURCE_MEM_NONPOSTED is set on the BAR,
and hide the sysfs resourceN_wc attribute for non-posted BARs.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
Behind a non-posted PCIe BAR (IORESOURCE_MEM_NONPOSTED), write-combined
VRAM mappings allow userspace DC ZVA (such as glibc memset(0)) to reach
the PCIe fabric and panic the kernel with an asynchronous SError.

Mirror amdgpu's non-posted BAR handling in radeon, keyed on
IORESOURCE_MEM_NONPOSTED:
- Flag TTM VRAM resources bus.is_nonposted so TTM selects ioremap_np()
  for kernel maps and pgprot_noncached() for mmaps.
- Map GTT pages write-combined on non-coherent hosts behind a non-posted
  BAR so CPU writes are visible to GPU DMA.
- Migrate CPU-faulted userspace VRAM BOs to GTT in
  radeon_bo_fault_reserve_notify() (returning VM_FAULT_SIGBUS if pinned),
  place CPU-accessible user BOs and dumb buffers in GTT, and report
  vram_visible = 0 in DRM_RADEON_GEM_INFO.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
Complement the VCE firmware upload fix (#3464) by auditing the remaining
kernel CPU accesses to VRAM-resident BOs in radeon and routing them
through I/O accessors so compiler-merged stores or DC ZVA cannot fault
on Device-nGnRnE non-posted BAR mappings:
- Add radeon_bo_memset/memcpy_to/memcpy_from helpers keyed on
  bus.is_nonposted.
- Use readl()/writel() for the UVD ring fence stored in vcpu_bo (VRAM),
  UVD_FW_START readback, RLC save/restore list, and CIK CP PG table.
- Bounce the RLC clear-state buffer through host memory when
  is_nonposted and copy via memcpy_toio().
- Copy the UVD CS message header through radeon_bo_memcpy_from() with a
  BO-size check instead of dereferencing the kmap pointer directly.
- Use radeon_bo_memcpy_from()/to() for VRAM reads/writes in
  radeon_do_test_moves().

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
@RyanTheTide
RyanTheTide requested review from a team as code owners November 28, 2026 05:07

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: FINISH, then merge at fcad7234

Blockers:

  1. Required CI checks (pr-text, readiness, host-tests) are still QUEUED; wait for green CI.
  2. Live hardware row on K114s + eGPU (exercising PCI sysfs resourceN mmap, resourceN_wc absence, userspace memset(0) on a radeon VRAM mmap without SError, and dumb-buffer/KMS scanout) plus a second-Mac regression row are pending.
  3. Requires independent code-owner / maintainer approval before merge.

Checked:

  • drivers/pci/{mmap,iomap,pci-sysfs}.c: verified arm64 pgprot_noncached() maps MT_DEVICE_nGnRnE (non-posted) while pgprot_device() maps MT_DEVICE_nGnRE; pci_iomap_wc_range() falls back cleanly via ioremap_np() ?: ioremap(); hiding resourceN_wc on IORESOURCE_MEM_NONPOSTED prevents write-combine sysfs mappings.
  • drivers/gpu/drm/radeon/{radeon_ttm,radeon_gem,radeon_object,cik,evergreen,radeon_fence,radeon_test,radeon_uvd,uvd_v1_0}.c: verified mem->bus.is_nonposted propagation, WC GTT selection on non-coherent DMA + non-posted BAR, GTT migration in radeon_bo_fault_reserve_notify(), and radeon_bo_memset/memcpy_to/memcpy_from + writel/readl conversions.
  • Non-blocking review notes to verify during hardware testing / follow-up:
    1. Pinned scanout dumb buffers (atombios_crtc.c): radeon_mode_dumb_create() starts dumb BOs in RADEON_GEM_DOMAIN_GTT, which allows CPU drawing before modeset, but radeon_crtc_do_set_base() / radeon_crtc_page_flip_target() still pin scanout FBs in RADEON_GEM_DOMAIN_VRAM. If a userspace client faults on a dumb BO's mmap() while it is pinned in VRAM for scanout, radeon_bo_fault_reserve_notify() will return VM_FAULT_SIGBUS (safe vs SError, but worth verifying fbdev/Wayland/dumb-buffer scanout behavior on hardware).
    2. 32-bit overflow hardening (radeon_uvd.c:480): if (offset + sizeof(msg) > radeon_bo_size(bo)) can wrap on 32-bit builds if offset is near UINT_MAX; prefer if (offset > radeon_bo_size(bo) || radeon_bo_size(bo) - offset < sizeof(msg)). (uint32_t msg[29] matches the max index msg[28] in radeon_uvd_cs_msg_decode().)
  • Checked for Apple material, AI attribution, private serials, and board/SoC gates: none found; keyed cleanly on IORESOURCE_MEM_NONPOSTED and dev_is_dma_coherent(); human Signed-off-by present.
Evidence
  • Head: fcad72341134 (base: main, mergeable: MERGEABLE, 3 commits).
  • Waiting on CI, K114s hardware row (including scanout + userspace memset(0) check), and independent approval.

…ounds

Close three remaining non-posted PCIe BAR gaps in radeon:

1. radeon_fbdev uses FB_DEFAULT_IOMEM_OPS, whose fb_io_mmap() maps
   BAR0 VRAM with pgprot_framebuffer() (write-combine on arm64). A
   userspace memset(0) on /dev/fbN would still execute DC ZVA into the
   non-posted BAR and raise an async SError. Override .fb_mmap to map
   Device-nGnRnE (pgprot_noncached) when BAR0 carries
   IORESOURCE_MEM_NONPOSTED.
2. Map rdev->rmmio, rdev->doorbell.ptr, and VRAM BIOS reads via
   ioremap_np() when the backing BAR has IORESOURCE_MEM_NONPOSTED,
   matching amdgpu.
3. Guard radeon_uvd_cs_msg() against unsigned offset overflow and check
   per-message-type bounds (3 dwords header, 9 dwords create, 29 dwords
   decode) instead of rejecting valid shorter create/destroy messages
   near the end of a BO.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The revised UVD message decoder checks remaining buffer length before reading its header and each message payload. The fbdev mmap and direct-register mappings now use the non-posted path where the BAR requires it. Exact hosted checks and the K114s eGPU scanout/CPU drawing row remain. Please include CPU drawing after the framebuffer is pinned for scanout, and a posted-BAR regression row.

@github-actions github-actions Bot added ci-failing A check failed at the PR head (bot) door:two-way Revertible or not, from Merge risk (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Nov 28, 2026
@github-actions

github-actions Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Merge readiness at fa892fa4: ready to merge

Check Detail
CI at head ok 3 checks passed
Review ok approved by DjDeveloperr
Requested changes ok none
Hardware row at head ok comment at fa892fa4
Conflicts ok none
PR text ok Risk: two-way · — gated on IORESOURCEMEMNONPOSTED so posted PCIe fabrics see no behavioral change; reverts cleanly.

Areas: none matched in CODEOWNERS
Merge: gh pr merge 3486 --merge (Owners and Core through the bypass: add --admin).

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

@github-actions github-actions Bot removed the ci-failing A check failed at the PR head (bot) label Nov 30, 2026

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: MERGE at fa892fa42a38

Converts this App's earlier review at the same head to an approval under the 12-01 merge bar (better than before and doesn't break; block only on a shown failure). No code blocker was found in it. The merge gate (a row on one Mac at this head + fast CI) is tracked by pr-readiness, not held here.

Checked: Code reviewed in the earlier App review at this head (6096055934).

Follow-ups (not blocking): hosted checks, K114s eGPU scanout/CPU drawing row, posted-BAR regression

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve at fa892fa42a38. The PCI core changes act only on IORESOURCE_MEM_NONPOSTED BARs: pgprot_noncached for resource mmaps, ioremap_np for pci_iomap_wc_range(), and no resourceN_wc. Posted fabrics are unchanged. On the radeon side, every new path is gated on BAR0 or the register BAR being non-posted.

One behaviour to check on the eGPU row, not a blocker: a dumb buffer now starts in GTT, but scanout pins it into VRAM (radeon_bo_pin(..., RADEON_GEM_DOMAIN_VRAM)). After that, a CPU write through the client's mmap faults in radeon_bo_fault_reserve_notify() and gets VM_FAULT_SIGBUS. Clients that keep drawing into the scanned-out dumb buffer (Xorg modesetting without glamor, Plymouth) would get SIGBUS where they used to risk an SError. That is still better than a panic, but mapping a pinned VRAM BO Device-nGnRnE (is_nonposted) instead of SIGBUS would keep them working for aligned stores. Please include one dumb-buffer KMS client on the row.

@github-actions github-actions Bot removed the needs-review No approving review from Core or Omarchy Mac yet (bot) label Dec 2, 2026
@DjDeveloperr

Copy link
Copy Markdown
Contributor

Hardware no-regression boot receipt on J773g (M4 Mac mini, Mac16,10, os-fw 27.2 / 26B123) at #3485 141ab9a764af + #3486 fa892fa42a38 (built together with CONFIG_DRM_RADEON=m in 7.3.0-j773g-riders+, Image 37ad50d13179…, boot_id=c6cc5648-8b9f-4d5d-bfae-93852240f15f):

  • Result: PASS (no-regression boot; functional eGPU row remains PEER).
  • PCIe / storage / network: nvme-apple (nvme0n1/n2/n3 mounted cleanly), pcieport (00:00.0, 00:02.0), tg3 (02:00.0, end0 10.55.0.5 SSH up), BCM4388 PCIe functions (01:00.0, 01:00.1) enumerated at 5GT/s x1 / 2.5GT/s x1 (and survived committed deep sleep x1).
  • Module load/unload: modprobe radeon (radeon 1622016 0) followed by rmmod radeon succeeded cleanly.
  • Kernel errors: 0 SError, 0 WARNING/BUG/Oops.

@github-actions github-actions Bot removed the needs-hw-row No hardware row at the PR head (bot) label Dec 3, 2026
@github-actions github-actions Bot added the ready-to-merge Meets the merge policy: merge it (bot) label Dec 3, 2026
@DjDeveloperr
DjDeveloperr merged commit 63abfb0 into main Dec 3, 2026
7 of 10 checks passed
@DjDeveloperr
DjDeveloperr deleted the fix/pci-radeon-nonposted-vram branch December 3, 2026 19:53
@DjDeveloperr

Copy link
Copy Markdown
Contributor

Merged as 63abfb01beef (main + #3485 5b2a38a53943 + fa892fa42a38; merge tree a5654564, the same tree I built).

Checked before merge:

  • arm64 LLVM=1 W=1 build of drivers/gpu/drm/radeon/ (all objects rebuilt after the radeon_object.h change) and drivers/pci/ (mmap.o, iomap.o, pci-sysfs.o) on that merge tree: 0 warnings (main alone: 0).
  • checkpatch.pl --no-tree on all 4 commits: 0 errors, 0 warnings.
  • Hardware: the J773g no-regression boot above, at this head (PCIe, NVMe, tg3 and BCM4388 enumerate, deep sleep x1, radeon modprobe/rmmod clean, 0 SError/WARN).
  • The PCI core part only acts on IORESOURCE_MEM_NONPOSTED BARs. In the Mac kernel config, no built driver calls pci_iomap_wc*. Without an eGPU, it changes only sysfs resourceN mmaps and hides resourceN_wc.

The functional eGPU row stays open as a follow-up, including the dumb-buffer KMS client from the approval (CPU writes after scanout pins the buffer in VRAM). The change reverts cleanly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

door:two-way Revertible or not, from Merge risk (bot) ready-to-merge Meets the merge policy: merge it (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants