Repository navigation
PCI, drm/radeon: honor IORESOURCE_MEM_NONPOSTED for BAR mmaps and VRAM BOs - #3486
Conversation
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>
There was a problem hiding this comment.
Verdict: FINISH, then merge at fcad7234
Blockers:
- Required CI checks (
pr-text,readiness,host-tests) are stillQUEUED; wait for green CI. - Live hardware row on K114s + eGPU (exercising PCI sysfs
resourceNmmap,resourceN_wcabsence, userspacememset(0)on a radeon VRAM mmap without SError, and dumb-buffer/KMS scanout) plus a second-Mac regression row are pending. - Requires independent code-owner / maintainer approval before merge.
Checked:
drivers/pci/{mmap,iomap,pci-sysfs}.c: verified arm64pgprot_noncached()mapsMT_DEVICE_nGnRnE(non-posted) whilepgprot_device()mapsMT_DEVICE_nGnRE;pci_iomap_wc_range()falls back cleanly viaioremap_np() ?: ioremap(); hidingresourceN_wconIORESOURCE_MEM_NONPOSTEDprevents 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: verifiedmem->bus.is_nonpostedpropagation, WC GTT selection on non-coherent DMA + non-posted BAR, GTT migration inradeon_bo_fault_reserve_notify(), andradeon_bo_memset/memcpy_to/memcpy_from+writel/readlconversions.- Non-blocking review notes to verify during hardware testing / follow-up:
- Pinned scanout dumb buffers (
atombios_crtc.c):radeon_mode_dumb_create()starts dumb BOs inRADEON_GEM_DOMAIN_GTT, which allows CPU drawing before modeset, butradeon_crtc_do_set_base()/radeon_crtc_page_flip_target()still pin scanout FBs inRADEON_GEM_DOMAIN_VRAM. If a userspace client faults on a dumb BO'smmap()while it is pinned in VRAM for scanout,radeon_bo_fault_reserve_notify()will returnVM_FAULT_SIGBUS(safe vs SError, but worth verifying fbdev/Wayland/dumb-buffer scanout behavior on hardware). - 32-bit overflow hardening (
radeon_uvd.c:480):if (offset + sizeof(msg) > radeon_bo_size(bo))can wrap on 32-bit builds ifoffsetis nearUINT_MAX; preferif (offset > radeon_bo_size(bo) || radeon_bo_size(bo) - offset < sizeof(msg)). (uint32_t msg[29]matches the max indexmsg[28]inradeon_uvd_cs_msg_decode().)
- Pinned scanout dumb buffers (
- Checked for Apple material, AI attribution, private serials, and board/SoC gates: none found; keyed cleanly on
IORESOURCE_MEM_NONPOSTEDanddev_is_dma_coherent(); humanSigned-off-bypresent.
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>
There was a problem hiding this comment.
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.
|
Merge readiness at
Areas: none matched in CODEOWNERS Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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.
|
Hardware no-regression boot receipt on J773g (M4 Mac mini,
|
|
Merged as Checked before merge:
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. |
Problem.
On Apple Silicon PCIe fabrics (marked
IORESOURCE_MEM_NONPOSTED), write-combined (Normal-NC) mappings of a PCIe BAR allowdc zva(emitted bymemset(0)in both kernel and userspace) to trigger an asynchronous SError kernel panic. Three userspace paths and several remainingradeonkernel VRAM/MMIO paths remained unguarded beyond #3464:drivers/pci/{mmap,iomap,pci-sysfs}.c:pci_mmap_resource_range(),pci_iomap_wc_range(), and sysfsresourceN_wcignoredIORESOURCE_MEM_NONPOSTED.radeonuserspace VRAM & fbdev mmaps:radeon_ttm_io_mem_reserve()did not setmem->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, andradeon_fbdevinheritedfb_io_mmap()(pgprot_framebuffer= write-combine on arm64).radeonkernel paths:radeon_device.c(rmmio,doorbell.ptr) andradeon_bios.c(igp_read_bios_from_vram) usedioremap()instead ofioremap_np();evergreen.c,cik.c,radeon_fence.c,radeon_uvd.c,uvd_v1_0.c, andradeon_test.cperformed plain accesses on VRAM BOs.Change.
resourceN_wcin sysfs and forcepgprot_noncached/ioremap_npwhenIORESOURCE_MEM_NONPOSTEDis set.radeonuserspace & MMIO: setmem->bus.is_nonposted, migrate userspace VRAM faults to GTT (returningVM_FAULT_SIGBUSfor pinned BOs), reportvram_visible = 0, place CPU-accessible / dumb BOs in GTT, map non-coherent GTT pages WC, overrideradeon_fbdev.fb_mmapto usepgprot_noncachedon non-posted BAR0, and useioremap_np()forrmmio,doorbell.ptr, and VRAM BIOS reads.radeonkernel BO helpers: addradeon_bo_{memset,memcpy_to,memcpy_from}and convert remaining VRAM BO accesses inevergreen.c,cik.c,radeon_fence.c,radeon_uvd.c(with per-message-type bounds and overflow guards),uvd_v1_0.c, andradeon_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-treeclean across all 4 commits (0 errors, 0 warnings). Software-only lane; K114s + R9 390X hardware tests (userspacememset(0)on radeon VRAM GEM mmap,/dev/fbN, andresource0, plusresource0_wcabsence and radeon probe/display) are pending handoff to the Thunderbolt/PCIe test lane.Risk: two-way — gated on
IORESOURCE_MEM_NONPOSTEDso posted PCIe fabrics see no behavioral change; reverts cleanly.