freedreno: serialize drmPrimeFDToHandle under table_lock
fixes the prime sharing race condition described by "intel: Serialize drmPrimeFDToHandle with struct_mutex". we inline fd_bo_from_handle() into fd_bo_from_dmabuf() and allow locking. Signed-off-by: Varad Gautam <varadgautam@gmail.com> Signed-off-by: Rob Clark <robclark@freedesktop.org>main
parent
cc7db673fa
commit
c3301d0134
|
@ -230,18 +230,26 @@ fd_bo_from_dmabuf(struct fd_device *dev, int fd)
|
||||||
uint32_t handle;
|
uint32_t handle;
|
||||||
struct fd_bo *bo;
|
struct fd_bo *bo;
|
||||||
|
|
||||||
|
pthread_mutex_lock(&table_lock);
|
||||||
ret = drmPrimeFDToHandle(dev->fd, fd, &handle);
|
ret = drmPrimeFDToHandle(dev->fd, fd, &handle);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bo = lookup_bo(dev->handle_table, handle);
|
||||||
|
if (bo)
|
||||||
|
goto out_unlock;
|
||||||
|
|
||||||
/* lseek() to get bo size */
|
/* lseek() to get bo size */
|
||||||
size = lseek(fd, 0, SEEK_END);
|
size = lseek(fd, 0, SEEK_END);
|
||||||
lseek(fd, 0, SEEK_CUR);
|
lseek(fd, 0, SEEK_CUR);
|
||||||
|
|
||||||
bo = fd_bo_from_handle(dev, handle, size);
|
bo = bo_from_handle(dev, size, handle);
|
||||||
bo->fd = fd;
|
bo->fd = fd;
|
||||||
|
|
||||||
|
out_unlock:
|
||||||
|
pthread_mutex_unlock(&table_lock);
|
||||||
|
|
||||||
return bo;
|
return bo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue