summaryrefslogtreecommitdiffstats
path: root/src/gallium/winsys
diff options
context:
space:
mode:
authorDave Airlie <[email protected]>2019-04-09 14:49:01 +1000
committerDave Airlie <[email protected]>2019-04-25 06:05:43 +1000
commit92ef4cf9f047278f5d1e509b3ec68e3522a4fc30 (patch)
tree859af820d89fc698fa8c5bfb2bf8e039917ca465 /src/gallium/winsys
parent19b246257dba0e81eb57592fe8e66d7715b4ff09 (diff)
virgl/drm: cleanup buffer from handle creation (v2)
This cleans up and realigns this code with what is in radeon v2: fix names->handles (Lepton Wu) Reviewed-by: Chia-I Wu <[email protected]>
Diffstat (limited to 'src/gallium/winsys')
-rw-r--r--src/gallium/winsys/virgl/drm/virgl_drm_winsys.c27
-rw-r--r--src/gallium/winsys/virgl/drm/virgl_drm_winsys.h1
2 files changed, 13 insertions, 15 deletions
diff --git a/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c b/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c
index 4cefbe92077..08509224b4f 100644
--- a/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c
+++ b/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c
@@ -394,7 +394,7 @@ virgl_drm_winsys_resource_create_handle(struct virgl_winsys *qws,
struct virgl_drm_winsys *qdws = virgl_drm_winsys(qws);
struct drm_gem_open open_arg = {};
struct drm_virtgpu_resource_info info_arg = {};
- struct virgl_hw_res *res;
+ struct virgl_hw_res *res = NULL;
uint32_t handle = whandle->handle;
if (whandle->offset != 0) {
@@ -405,25 +405,25 @@ virgl_drm_winsys_resource_create_handle(struct virgl_winsys *qws,
mtx_lock(&qdws->bo_handles_mutex);
+ /* We must maintain a list of pairs <handle, bo>, so that we always return
+ * the same BO for one particular handle. If we didn't do that and created
+ * more than one BO for the same handle and then relocated them in a CS,
+ * we would hit a deadlock in the kernel.
+ *
+ * The list of pairs is guarded by a mutex, of course. */
if (whandle->type == WINSYS_HANDLE_TYPE_SHARED) {
res = util_hash_table_get(qdws->bo_names, (void*)(uintptr_t)handle);
- if (res) {
- struct virgl_hw_res *r = NULL;
- virgl_drm_resource_reference(qdws, &r, res);
- goto done;
- }
- }
-
- if (whandle->type == WINSYS_HANDLE_TYPE_FD) {
+ } else if (whandle->type == WINSYS_HANDLE_TYPE_FD) {
int r;
r = drmPrimeFDToHandle(qdws->fd, whandle->handle, &handle);
- if (r) {
- res = NULL;
+ if (r)
goto done;
- }
+ res = util_hash_table_get(qdws->bo_handles, (void*)(uintptr_t)handle);
+ } else {
+ /* Unknown handle type */
+ goto done;
}
- res = util_hash_table_get(qdws->bo_handles, (void*)(uintptr_t)handle);
if (res) {
struct virgl_hw_res *r = NULL;
virgl_drm_resource_reference(qdws, &r, res);
@@ -446,7 +446,6 @@ virgl_drm_winsys_resource_create_handle(struct virgl_winsys *qws,
}
res->bo_handle = open_arg.handle;
}
- res->name = handle;
memset(&info_arg, 0, sizeof(info_arg));
info_arg.bo_handle = res->bo_handle;
diff --git a/src/gallium/winsys/virgl/drm/virgl_drm_winsys.h b/src/gallium/winsys/virgl/drm/virgl_drm_winsys.h
index d7db03b89da..d30fe2a0dcc 100644
--- a/src/gallium/winsys/virgl/drm/virgl_drm_winsys.h
+++ b/src/gallium/winsys/virgl/drm/virgl_drm_winsys.h
@@ -37,7 +37,6 @@ struct virgl_hw_res {
struct pipe_reference reference;
uint32_t res_handle;
uint32_t bo_handle;
- uint32_t name;
int num_cs_references;
uint32_t size;
void *ptr;