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 <ruijing.dong@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/33374>
(cherry picked from commit fdf747af3a)
This commit is contained in:
David Rosca 2025-02-04 10:55:27 +01:00 committed by Eric Engestrom
parent 2ea6b340ac
commit b86196935f
2 changed files with 5 additions and 8 deletions

View file

@ -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

View file

@ -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 */