[Steam Frame] msm DRM: mmap() of an imported GEM object leaks it permanently; hardware video decode fails with ENOMEM after ~2 days of streaming
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 15/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- c, linux
- Ambito
- computer-graphics, operating-systems
Direzione di ricerca
Read the mmap path in drivers/gpu/drm/msm/msm_gem.c (msm_gem_object_mmap, called from drm_gem_mmap), then compare it with drm_gem_shmem_mmap() in drivers/gpu/drm/drm_gem_shmem_helper.c, which drops the reference drm_gem_mmap_obj() took when it hands the VMA to the exporter. Build and run the report's msm_mmap_import_leak.c reproducer on the device; done means the udmabuf count from /sys/kernel/debug/dma_buf/bufinfo stays flat after the process exits and msm_gem_free_object / drm_prime_gem_destroy are reached on close. This needs a kernel build and the headset hardware, so expect a long loop.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Your system information
- Steam client version: not recorded (stable channel)
- SteamOS version: 0.4.5 build 20261022.6150929 (variant
vr), kernel6.18.0-ge66bc2ca6f8c, Mesa 26.2.7 (Turnip) - Opted into Steam client beta?: No
- Opted into SteamOS beta?: No
- Have you checked for updates in Settings > System?: Not re-tested on a newer build yet
Please describe your issue in as much detail as possible:
Summary
When a dma-buf is imported into the msm DRM driver (DRM_IOCTL_PRIME_FD_TO_HANDLE) and the resulting GEM object is
mapped once through the DRM fd (MSM_INFO_GET_OFFSET + mmap()), one reference on the GEM object is never dropped.
After munmap(), GEM_CLOSE, closing every fd and exiting the process, the object is still alive: it has no handle,
no VMA and no owner, but it keeps the dma-buf attached forever. Only a reboot frees it.
Without the mmap() the same sequence frees the object normally, so the reference taken for the mapping is the one
that is lost (a non-imported GEM object mapped the same way is released correctly).
Why it matters
Any Vulkan application that imports decoder output as dma-bufs and whose allocator maps imported memory hits this.
libplacebo does (vk_malloc_import() calls vkMapMemory on host-visible imported memory), and Turnip implements
vkMapMemory with exactly the mmap above. Each imported V4L2 (iris) capture buffer therefore leaks: about 6 buffers
(35 MB at 2304x2304) per streaming session in a game-streaming client that uses FFmpeg v4l2m2m + libplacebo. After roughly two days of normal use ~470 buffers / 2.6 GB of
videobuf2_dma_contig memory were pinned and the iris decoder could no longer allocate:
qcom-iris aa00000.video-codec: dma alloc of size 17694720 failed
WARNING: ... at drivers/media/common/videobuf2/videobuf2-core.c:1803 vb2_start_streaming+0xe8/0x190
From then on every hardware decode on the headset fails (VIDIOC_STREAMON / first packet: ENOMEM) until reboot.
Reproducer
msm_mmap_import_leak.c (~50 lines, no Vulkan needed, source at the end of this report):
gcc -O1 -I/usr/include/libdrm -o repro msm_mmap_import_leak.c
sudo grep -c udmabuf /sys/kernel/debug/dma_buf/bufinfo # N
./repro
sudo grep -c udmabuf /sys/kernel/debug/dma_buf/bufinfo # N+1, stays after the process has exited
Each run adds one entry; observed 1 → 2 → 3 on two consecutive runs. Removing the mmap()/munmap() lines makes the
count stay at N. The same happens with a dma-buf exported by the iris decoder (VIDIOC_EXPBUF).
Evidence from the leaked state
/sys/kernel/debug/dma_buf/bufinfo: the leaked buffers have refcount 1,Attached Devices: ae01000.display-controller,
and no process holds an fd for them./sys/kernel/debug/dri/0/gem: one object per leaked buffer withref 1and novmas:line.- kprobe trace of one buffer's life in the real application:
msm_gem_import→ VM_BIND map →MSM_INFO_GET_OFFSET→
drm_gem_mmap→msm_gem_object_mmap→ … → VM_BIND unmap (msm_gem_vma_close,drm_gpuvm_bo_destroy) →
msm_gem_close;msm_gem_free_object/drm_prime_gem_destroyare never reached. With the mmap removed they are
reached right after the close.
Likely cause (not verified against this kernel's source)
For an imported object the mmap path seems to hand the VMA over to the exporter (dma_buf_mmap) without dropping the
reference drm_gem_mmap_obj() took, the way drm_gem_shmem_mmap() does (“Drop the reference drm_gem_mmap_obj()
acquired”); the exporter's vm_ops then never put the GEM object on unmap.
Workaround
A libplacebo build patched to not map dma-bufs imported for textures. Verified on the device: 5 imports, 5 frees per
session, leak counter unchanged.
Steps for reproducing this issue:
- Build and run the reproducer below on the headset (SSH / desktop mode).
sudo grep -c udmabuf /sys/kernel/debug/dma_buf/bufinfobefore and after: the count grows by one per run and never drops, even though the process has exited.
msm_mmap_import_leak.c
// Minimal reproducer: mmap() of an imported GEM object through the msm DRM fd leaks one object reference.
// Build: gcc -O1 -I/usr/include/libdrm -o repro msm_mmap_import_leak.c
// Run: ./repro (needs access to /dev/udmabuf and /dev/dri/renderD128)
// Check: sudo grep -c udmabuf /sys/kernel/debug/dma_buf/bufinfo -> grows by one per run and never shrinks,
// although the process has exited and nothing holds the dma-buf fd or a GEM handle any more.
// Without the mmap()/munmap() pair the object is freed as expected.
#define _GNU_SOURCE
#include <stdio.h>
#include <stdint.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <linux/udmabuf.h>
#include <drm.h>
#define DRM_MSM_GEM_INFO 0x03
#define MSM_INFO_GET_OFFSET 0x00
struct msm_gem_info { uint32_t handle, info; uint64_t value; uint32_t len, pad; };
int main(void)
{
const size_t size = 311 * 4096;
// 1. a dma-buf from any exporter (udmabuf here; a V4L2 decoder capture buffer behaves the same)
int memfd = memfd_create("repro", MFD_ALLOW_SEALING);
if (memfd < 0 || ftruncate(memfd, size) || fcntl(memfd, F_ADD_SEALS, F_SEAL_SHRINK) < 0) { perror("memfd"); return 1; }
int u = open("/dev/udmabuf", O_RDWR);
struct udmabuf_create c = { .memfd = memfd, .flags = UDMABUF_FLAGS_CLOEXEC, .offset = 0, .size = size };
int dmabuf = ioctl(u, UDMABUF_CREATE, &c);
if (dmabuf < 0) { perror("UDMABUF_CREATE"); return 1; }
// 2. import it into msm
int drm = open("/dev/dri/renderD128", O_RDWR | O_CLOEXEC);
struct drm_prime_handle ph = { .fd = dmabuf };
if (drm < 0 || ioctl(drm, DRM_IOCTL_PRIME_FD_TO_HANDLE, &ph)) { perror("import"); return 1; }
// 3. mmap the imported GEM object through the DRM fd, then unmap it <-- this is what leaks
struct msm_gem_info gi = { .handle = ph.handle, .info = MSM_INFO_GET_OFFSET };
if (ioctl(drm, DRM_IOWR(DRM_COMMAND_BASE + DRM_MSM_GEM_INFO, struct msm_gem_info), &gi)) { perror("GET_OFFSET"); return 1; }
void* p = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, drm, (off_t)gi.value);
if (p == MAP_FAILED) { perror("mmap"); return 1; }
munmap(p, size);
// 4. release everything userspace holds
struct drm_gem_close gc = { .handle = ph.handle };
ioctl(drm, DRM_IOCTL_GEM_CLOSE, &gc);
close(dmabuf); close(drm); close(u); close(memfd);
return 0;
}
- Lingua principale
- Nessun dato sulla lingua
- Stelle
- 2.7k
- Fork
- 89
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
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
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di ValveSoftware/SteamOS
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
ValveSoftware/SteamOS#3037 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
ValveSoftware/SteamOS#2983 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
ValveSoftware/SteamOS#2927 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
ValveSoftware/SteamOS#2875 · 1 commento ·
-
steam-short-session-tracker: incorrect registry backup path resets settings during automatic repairAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 80/100
ValveSoftware/SteamOS#2829 ·
Tutte le issue di ValveSoftware/SteamOS
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
carla-simulator/carla#10411 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
mapbox/mapbox-gl-js#13760 ·
-
[Bug]: a layout legend's title longer than its box runs past itForse già presa Una pull request collegata a questa issue è aperta o già unita. Apertaunconfirmed possible issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
gkjohnson/three-mesh-bvh#1029 ·
I maintainer di solito rispondono entro 1 giorno
-
Python projects: node colours are written with 4 significant digits, positions rounded to integersApertadifficulty:easy func:python prio:low type:bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 79/100
NatronGitHub/Natron#2008 ·
I maintainer di solito rispondono entro 1 giorno