[Steam Frame] msm DRM: mmap() of an imported GEM object leaks it permanently; hardware video decode fails with ENOMEM after ~2 days of streaming
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 15/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- c, linux
調査の方向性
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.
索引モデルが issue の本文から書いたものです。
説明
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;
}
- 主要言語
- 言語のデータがありません
- スター
- 2.7k
- フォーク
- 89
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
ValveSoftware/SteamOS のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
ValveSoftware/SteamOS#3037 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
ValveSoftware/SteamOS#2983 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
ValveSoftware/SteamOS#2927 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
ValveSoftware/SteamOS#2875 · コメント 1 件 ·
-
steam-short-session-tracker: incorrect registry backup path resets settings during automatic repairオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 80/100
ValveSoftware/SteamOS#2829 ·
ValveSoftware/SteamOS の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
carla-simulator/carla#10411 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
mapbox/mapbox-gl-js#13760 ·
-
[Bug]: a layout legend's title longer than its box runs past it対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープンunconfirmed possible issue
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
gkjohnson/three-mesh-bvh#1029 ·
メンテナーはふだん 1 日以内に返信
-
Python projects: node colours are written with 4 significant digits, positions rounded to integersオープンdifficulty:easy func:python prio:low type:bug
難易度 2/5 1〜3時間 初心者へのやさしさ 79/100
NatronGitHub/Natron#2008 ·
メンテナーはふだん 1 日以内に返信