[Steam Frame] msm DRM: mmap() of an imported GEM object leaks it permanently; hardware video decode fails with ENOMEM after ~2 days of streaming
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 15/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- c, linux
- Lĩnh vực
- computer-graphics, operating-systems
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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;
}
- Ngôn ngữ chính
- Không có dữ liệu ngôn ngữ
- Star
- 2.7k
- Fork
- 89
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của ValveSoftware/SteamOS
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
ValveSoftware/SteamOS#3037 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
ValveSoftware/SteamOS#2983 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
ValveSoftware/SteamOS#2927 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
ValveSoftware/SteamOS#2875 · 1 bình luận ·
-
steam-short-session-tracker: incorrect registry backup path resets settings during automatic repairĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 80/100
ValveSoftware/SteamOS#2829 ·
Tất cả issue của ValveSoftware/SteamOS
Issue tương tự
-
ue58-dev: BoundingBoxCalculator logs Error 'has no SM assigned to the ISM' on every map loadĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
carla-simulator/carla#10411 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
mapbox/mapbox-gl-js#13760 ·
-
[Bug]: a layout legend's title longer than its box runs past itCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mởunconfirmed possible issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
gkjohnson/three-mesh-bvh#1029 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Python projects: node colours are written with 4 significant digits, positions rounded to integersĐang mởdifficulty:easy func:python prio:low type:bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 79/100
NatronGitHub/Natron#2008 ·
Maintainer thường phản hồi trong vòng 1 ngày