[Steam Frame] msm DRM: mmap() of an imported GEM object leaks it permanently; hardware video decode fails with ENOMEM after ~2 days of streaming

オープン
#3,128 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
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 の本文から書いたものです。

説明

Steam Frame
Your system information
  • Steam client version: not recorded (stable channel)
  • SteamOS version: 0.4.5 build 20261022.6150929 (variant vr), kernel 6.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 with ref 1 and no vmas: 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_destroy are 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:
  1. Build and run the reproducer below on the headset (SSH / desktop mode).
  2. sudo grep -c udmabuf /sys/kernel/debug/dma_buf/bufinfo before 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 を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

ValveSoftware/SteamOS のほかの issue

ValveSoftware/SteamOS の issue をすべて見る

似ている issue

Computer Graphics の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。