From 6c0e4a0ece1ab50bcbeb074bf827ed0f8278296a Mon Sep 17 00:00:00 2001 From: Pierre-Eric Pelloux-Prayer Date: Thu, 27 Jun 2024 10:53:06 +0200 Subject: [PATCH] ac/virtio: add virtio-only AMDGPU_GEM_CREATE flag MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On the host side virglrenderer creates dmabuf on demand when: * cpu mapping is requested * setting up scan out * sharing buffers between guest processes On-demand dmabuf creation only works if the ctx that created the BO still exists and knows about this BO. This assumption works ok for the first 2 cases, but can break with the last one (and it does cause issues on Android). eg: * process A allocates BO and exports it as a guest dmabuf * process A closes its handle to the BO (-> detach_resource) * process B imports the guest dmabuf -> this triggers the attach_resource function in virglrenderer. If the given resource isn't a VIRGL_RESOURCE_FD_DMABUF it'll try to get one... But for this to work, process A needs to be used -> this fails because this resource was detached from it. The reason we create dmabuf on demand is to avoid hitting the number of open file descriptor limit. So to cover the 3rd case, we'll use the VIRTGPU_BLOB_FLAG_USE_SHAREABLE flag, but try to limit to as few possible buffers as possible. Acked-by: Samuel Pitoiset Tested-by: Dmitry Osipenko Reviewed-by: Dmitry Osipenko Reviewed-by: Marek Olšák Part-of: --- src/amd/common/sid.h | 5 +++++ src/amd/common/virtio/amdgpu_virtio_bo.c | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/src/amd/common/sid.h b/src/amd/common/sid.h index 4249dfb9bef..ab7772c1e94 100644 --- a/src/amd/common/sid.h +++ b/src/amd/common/sid.h @@ -403,4 +403,9 @@ enum amd_cmp_class_flags P_INFINITY = 1 << 9 // Positive infinity }; +/* Use the last bit of AMDGPU_GEM_CREATE_* flag as a virtio-only + * flag. + */ +#define AMDGPU_GEM_CREATE_VIRTIO_SHARED 1u << 31 + #endif /* _SID_H */ diff --git a/src/amd/common/virtio/amdgpu_virtio_bo.c b/src/amd/common/virtio/amdgpu_virtio_bo.c index dc6505ffe1e..999816142cb 100644 --- a/src/amd/common/virtio/amdgpu_virtio_bo.c +++ b/src/amd/common/virtio/amdgpu_virtio_bo.c @@ -13,6 +13,7 @@ #include "util/os_mman.h" #include "util/os_time.h" #include "util/u_math.h" +#include "sid.h" #include #include @@ -177,6 +178,11 @@ int amdvgpu_bo_alloc(amdvgpu_device_handle dev, if (!(request->flags & AMDGPU_GEM_CREATE_NO_CPU_ACCESS)) blob_flags |= VIRTGPU_BLOB_FLAG_USE_MAPPABLE; + if (request->flags & AMDGPU_GEM_CREATE_VIRTIO_SHARED) { + blob_flags |= VIRTGPU_BLOB_FLAG_USE_SHAREABLE; + req.r.flags &= ~AMDGPU_GEM_CREATE_VIRTIO_SHARED; + } + /* blob_id 0 is reserved for the shared memory buffer. */ assert(req.blob_id > 0);