vc4: swiotlb bounce-buffer import check bypassed since "drm/vc4: Set DRM DMA device directly from HVS and V3D" (Pi 4 scans out frozen frames)

Aperta
#7,816 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
c, linux

Direzione di ricerca

Start with vc4_prime_import_sg_table() and the dma_to_phys()/swiotlb_find_pool() check described in the issue; compare its device argument with the device used to map the imported scatter-gather table. The issue proposes checking with attach->dev or drm_dev_dma_dev(dev), but notes this is untested on hardware. Confirm that bounce-buffer imports are rejected on Raspberry Pi 4 full KMS and that the compositor falls back to GPU composition without frozen frames.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Describe the bug

On a Raspberry Pi 4 with full KMS, the check that rejects swiotlb bounce buffers on dma-buf import (356662cda96f, "drm: vc4: Block swiotlb bounce buffers being imported as dmabuf", #5734) no longer works since the stable backport of upstream b0a6b769cc17 ("drm/vc4: Set DRM DMA device directly from HVS and V3D") was merged into rpi-6.18.y with 6.18.65 (008dd935c79d).

After that change, imports are attached and mapped for the HVS device (drm_dev_dma_dev()), but vc4_prime_import_sg_table() still checks against dev->dev:

	phys_addr_t phys = dma_to_phys(dev->dev, sg_dma_address(sgt->sgl));

	if (swiotlb_find_pool(dev->dev, phys))
		return ERR_PTR(-EINVAL);

dev->dev is the /gpu platform device. In full KMS mode vc4_drm_bind() no longer calls of_dma_configure() for it, and /gpu is a child of the DT root, which has no dma-ranges, so the device has no dma_range_map. dma_to_phys() then returns the bus address unchanged (for example 0xc6660000 instead of 0x06660000), swiotlb_find_pool() does not recognise it as a swiotlb address, and the bounce-buffered import is accepted.

The result is the problem the original check was written to prevent. When the compositor does direct scanout of a client buffer that lies outside the HVS's 1 GB DMA window, the HVS scans out the swiotlb bounce buffer. That buffer holds a copy of the client buffer from the moment of import and is never synced again, so the screen shows a frozen image. In our case some client buffers are imported this way (the bounce happened to be contiguous) and the others are rejected and composited by the GPU, so the display alternates many times per second between stale still images and the live video.

With 6.18.53, the same imports are rejected and the compositor falls back to GPU composition, as intended. Going by the source, 6.18.64-3 does not contain the backport either, but we have not run it.

A possible fix (not tested on hardware) is to check against the device the sg_table was actually mapped for:

	struct device *dma_dev = attach->dev;	/* or drm_dev_dma_dev(dev) */
	phys_addr_t phys = dma_to_phys(dma_dev, sg_dma_address(sgt->sgl));

	if (swiotlb_find_pool(dma_dev, phys))
		return ERR_PTR(-EINVAL);
Steps to reproduce the behaviour
  1. Raspberry Pi 4, dtoverlay=vc4-kms-v3d, kernel from rpi-6.18.y at 6.18.65 or later.
  2. Run a wlroots-based compositor that does direct scanout (we use sway 1.12 with wlroots 0.20.2).
  3. Run a fullscreen EGL client at the output resolution. Ours is a GStreamer 1.28 video player; its buffers are ARGB2101010, LINEAR, 1920x1080, allocated by v3d through Mesa 26.x.
  4. The compositor tries direct scanout. Some client buffers are imported into vc4 through swiotlb, and the frames using them show a frozen image.

To check whether it happened:

  • /sys/kernel/debug/dma_buf/bufinfo lists fe400000.hvs as an attached device of the client buffers.
  • /sys/kernel/debug/dri/1/framebuffer shows framebuffers whose dma_addr minus 0xc0000000 falls inside the swiotlb pool reported in dmesg.
Device (s)

Raspberry Pi 4 Mod. B

System
  • Raspberry Pi 4 Model B Rev 1.5
  • OS: Arch Linux ARM (aarch64)
  • Kernel: Arch Linux ARM linux-rpi 6.18.65-3 (raspberrypi/linux 16ae2649dcfa)
    Linux 6.18.65-3-rpi #1 SMP PREEMPT Mon Nov 30 21:20:51 UTC 2026 aarch64 GNU/Linux
  • vc4_drv.c and vc4_hvs.c are unchanged in linux-rpi 6.18.66-1 (342dfe848204). We have not run that version on hardware.
  • Works as intended: linux-rpi 6.18.53-1 (d9e1735f5339). 6.18.64-3 (a40f73532539) does not contain the backport.
  • Firmware: Nov 25 2026 18:52:17, version a23b4fbc8895a3a09818ac5dea47ad8680630f55 (clean) (release) (start)
  • CONFIG_SWIOTLB=y, CONFIG_SWIOTLB_DYNAMIC not set
Logs
software IO TLB: area num 4.
software IO TLB: mapped [mem 0x0000000003000000-0x0000000007000000] (64MB)

On the affected 6.18.65 system:

  • /sys/kernel/debug/dri/1/framebuffer shows two AR30 framebuffers allocated by the compositor with dma_addr=0x00000000c6660000 and dma_addr=0x00000000c5496000. These are physical 0x06660000 and 0x05496000, inside the swiotlb pool.
  • /sys/kernel/debug/dma_buf/bufinfo shows those two client buffers attached to fe400000.hvs. The third client buffer has no attachment, and the compositor composites it.
  • /sys/kernel/debug/swiotlb/io_tlb_used is 12156, which is 3 x 4052 slabs, i.e. three mappings of the 8298496-byte buffers (one buffer is attached twice).
  • Reading RAM at dma_addr - 0xc0000000 through /dev/mem gives an image that stays the same over several seconds (identical md5) and differs from the dma-buf contents read through an mmap of the PRIME fd. For the compositor's own vc4-allocated framebuffer, the two reads are identical.
  • Sampling hvs_dlists 300 times showed the two bounce-buffer framebuffers being scanned out about 75% of the time.

On three Raspberry Pi 4s running the same software stack with 6.18.53:

  • The client buffers have no attachments.
  • io_tlb_used is 0 and io_tlb_used_hiwater is 4308 to 4566 slabs, which is consistent with one 8 MB mapping being created and then rejected.
Additional context

A Raspberry Pi 5 running the same software is not affected, because the HVS there is behind the IOMMU and no bounce buffer is involved.

The fkms path in vc4_drm_bind() still calls of_dma_configure() on /gpu for gen < 6, so the check may still work there. We have only looked at full KMS.

Lingua principale
C
Stelle
13.4k
Fork
5.5k
Merge medio
1g 8h
PR unite (30g)
37

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di raspberrypi/linux

Tutte le issue di raspberrypi/linux

Issue simili

Altre issue su C

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.