Commit d5084f17 authored by Dave Airlie's avatar Dave Airlie Committed by Gerd Hoffmann

virtio-gpu: add locking for vbuf pool

Signed-off-by: default avatarDave Airlie <airlied@redhat.com>
Signed-off-by: default avatarGerd Hoffmann <kraxel@redhat.com>
parent 441012af
...@@ -162,6 +162,7 @@ struct virtio_gpu_device { ...@@ -162,6 +162,7 @@ struct virtio_gpu_device {
struct virtio_gpu_queue ctrlq; struct virtio_gpu_queue ctrlq;
struct virtio_gpu_queue cursorq; struct virtio_gpu_queue cursorq;
struct list_head free_vbufs; struct list_head free_vbufs;
spinlock_t free_vbufs_lock;
void *vbufs; void *vbufs;
bool vqs_ready; bool vqs_ready;
......
...@@ -79,6 +79,7 @@ int virtio_gpu_alloc_vbufs(struct virtio_gpu_device *vgdev) ...@@ -79,6 +79,7 @@ int virtio_gpu_alloc_vbufs(struct virtio_gpu_device *vgdev)
void *ptr; void *ptr;
INIT_LIST_HEAD(&vgdev->free_vbufs); INIT_LIST_HEAD(&vgdev->free_vbufs);
spin_lock_init(&vgdev->free_vbufs_lock);
count += virtqueue_get_vring_size(vgdev->ctrlq.vq); count += virtqueue_get_vring_size(vgdev->ctrlq.vq);
count += virtqueue_get_vring_size(vgdev->cursorq.vq); count += virtqueue_get_vring_size(vgdev->cursorq.vq);
size = count * VBUFFER_SIZE; size = count * VBUFFER_SIZE;
...@@ -106,6 +107,7 @@ void virtio_gpu_free_vbufs(struct virtio_gpu_device *vgdev) ...@@ -106,6 +107,7 @@ void virtio_gpu_free_vbufs(struct virtio_gpu_device *vgdev)
count += virtqueue_get_vring_size(vgdev->ctrlq.vq); count += virtqueue_get_vring_size(vgdev->ctrlq.vq);
count += virtqueue_get_vring_size(vgdev->cursorq.vq); count += virtqueue_get_vring_size(vgdev->cursorq.vq);
spin_lock(&vgdev->free_vbufs_lock);
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
if (WARN_ON(list_empty(&vgdev->free_vbufs))) if (WARN_ON(list_empty(&vgdev->free_vbufs)))
return; return;
...@@ -113,6 +115,7 @@ void virtio_gpu_free_vbufs(struct virtio_gpu_device *vgdev) ...@@ -113,6 +115,7 @@ void virtio_gpu_free_vbufs(struct virtio_gpu_device *vgdev)
struct virtio_gpu_vbuffer, list); struct virtio_gpu_vbuffer, list);
list_del(&vbuf->list); list_del(&vbuf->list);
} }
spin_unlock(&vgdev->free_vbufs_lock);
kfree(vgdev->vbufs); kfree(vgdev->vbufs);
} }
...@@ -123,10 +126,12 @@ virtio_gpu_get_vbuf(struct virtio_gpu_device *vgdev, ...@@ -123,10 +126,12 @@ virtio_gpu_get_vbuf(struct virtio_gpu_device *vgdev,
{ {
struct virtio_gpu_vbuffer *vbuf; struct virtio_gpu_vbuffer *vbuf;
spin_lock(&vgdev->free_vbufs_lock);
BUG_ON(list_empty(&vgdev->free_vbufs)); BUG_ON(list_empty(&vgdev->free_vbufs));
vbuf = list_first_entry(&vgdev->free_vbufs, vbuf = list_first_entry(&vgdev->free_vbufs,
struct virtio_gpu_vbuffer, list); struct virtio_gpu_vbuffer, list);
list_del(&vbuf->list); list_del(&vbuf->list);
spin_unlock(&vgdev->free_vbufs_lock);
memset(vbuf, 0, VBUFFER_SIZE); memset(vbuf, 0, VBUFFER_SIZE);
BUG_ON(size > MAX_INLINE_CMD_SIZE); BUG_ON(size > MAX_INLINE_CMD_SIZE);
...@@ -201,7 +206,9 @@ static void free_vbuf(struct virtio_gpu_device *vgdev, ...@@ -201,7 +206,9 @@ static void free_vbuf(struct virtio_gpu_device *vgdev,
if (vbuf->resp_size > MAX_INLINE_RESP_SIZE) if (vbuf->resp_size > MAX_INLINE_RESP_SIZE)
kfree(vbuf->resp_buf); kfree(vbuf->resp_buf);
kfree(vbuf->data_buf); kfree(vbuf->data_buf);
spin_lock(&vgdev->free_vbufs_lock);
list_add(&vbuf->list, &vgdev->free_vbufs); list_add(&vbuf->list, &vgdev->free_vbufs);
spin_unlock(&vgdev->free_vbufs_lock);
} }
static void reclaim_vbufs(struct virtqueue *vq, struct list_head *reclaim_list) static void reclaim_vbufs(struct virtqueue *vq, struct list_head *reclaim_list)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment