From b86196935fa3cd53e33a4e205b2de3d98f51ee7d Mon Sep 17 00:00:00 2001 From: David Rosca Date: Tue, 4 Feb 2025 10:55:27 +0100 Subject: [PATCH] radeonsi/video: Avoid stream handle duplicates in PID namespace Add current time when generating the stream handle initial value. When running inside PID namespace there can be multiple processes in the system that will share the same PID and with current code this could result in the same stream handle being used at the same time from different processes. This can easily happen with Flatpak when running two instances of the same application - both processes will have the same PID and we will use the same stream handles. For older UVDs kernel will reject the CS if we use duplicated handles. Cc: mesa-stable Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/12575 Reviewed-by: Ruijing Dong Part-of: (cherry picked from commit fdf747af3a7e6aa3101220005767515594c2ce53) --- .pick_status.json | 2 +- src/gallium/drivers/radeonsi/radeon_video.c | 11 ++++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 676321478b6..c72cd6eb686 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -64,7 +64,7 @@ "description": "radeonsi/video: Avoid stream handle duplicates in PID namespace", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": null, "notes": null diff --git a/src/gallium/drivers/radeonsi/radeon_video.c b/src/gallium/drivers/radeonsi/radeon_video.c index 2a2799d3659..f985b364fdc 100644 --- a/src/gallium/drivers/radeonsi/radeon_video.c +++ b/src/gallium/drivers/radeonsi/radeon_video.c @@ -21,15 +21,12 @@ unsigned si_vid_alloc_stream_handle() { static unsigned counter = 0; - unsigned stream_handle = 0; - unsigned pid = getpid(); - int i; + static unsigned handle_base = 0; - for (i = 0; i < 32; ++i) - stream_handle |= ((pid >> i) & 1) << (31 - i); + if (!handle_base) + handle_base = util_bitreverse(getpid() ^ os_time_get()); - stream_handle ^= ++counter; - return stream_handle; + return handle_base ^ ++counter; } /* create a buffer in the winsys */