From 92ef4cf9f047278f5d1e509b3ec68e3522a4fc30 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Tue, 9 Apr 2019 14:49:01 +1000 Subject: [PATCH] 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 --- src/gallium/winsys/virgl/drm/virgl_drm_winsys.c | 27 ++++++++++++------------- src/gallium/winsys/virgl/drm/virgl_drm_winsys.h | 1 - 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 4cefbe9..0850922 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 , 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 d7db03b..d30fe2a 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; -- 2.7.4