Merge v5.3-rc1 into drm-misc-next
[sfrench/cifs-2.6.git] / drivers / gpu / drm / virtio / virtgpu_vq.c
index 5bb0f0a084e9cb293a8a91030e8a6f9a050eb987..7ac20490e1b4c779fe34a3bbda9008e7307ae811 100644 (file)
  * OTHER DEALINGS IN THE SOFTWARE.
  */
 
-#include <drm/drmP.h>
-#include "virtgpu_drv.h"
+#include <linux/dma-mapping.h>
 #include <linux/virtio.h>
 #include <linux/virtio_config.h>
 #include <linux/virtio_ring.h>
 
+#include "virtgpu_drv.h"
+#include "virtgpu_trace.h"
+
 #define MAX_INLINE_CMD_SIZE   96
 #define MAX_INLINE_RESP_SIZE  24
 #define VBUFFER_SIZE          (sizeof(struct virtio_gpu_vbuffer) \
@@ -192,6 +194,9 @@ void virtio_gpu_dequeue_ctrl_func(struct work_struct *work)
 
        list_for_each_entry_safe(entry, tmp, &reclaim_list, list) {
                resp = (struct virtio_gpu_ctrl_hdr *)entry->resp_buf;
+
+               trace_virtio_gpu_cmd_response(vgdev->ctrlq.vq, resp);
+
                if (resp->type != cpu_to_le32(VIRTIO_GPU_RESP_OK_NODATA)) {
                        if (resp->type >= cpu_to_le32(VIRTIO_GPU_RESP_ERR_UNSPEC)) {
                                struct virtio_gpu_ctrl_hdr *cmd;
@@ -284,6 +289,9 @@ retry:
                spin_lock(&vgdev->ctrlq.qlock);
                goto retry;
        } else {
+               trace_virtio_gpu_cmd_queue(vq,
+                       (struct virtio_gpu_ctrl_hdr *)vbuf->buf);
+
                virtqueue_kick(vq);
        }
 
@@ -359,6 +367,9 @@ retry:
                spin_lock(&vgdev->cursorq.qlock);
                goto retry;
        } else {
+               trace_virtio_gpu_cmd_queue(vq,
+                       (struct virtio_gpu_ctrl_hdr *)vbuf->buf);
+
                virtqueue_kick(vq);
        }
 
@@ -583,12 +594,14 @@ static void virtio_gpu_cmd_capset_cb(struct virtio_gpu_device *vgdev,
                    cache_ent->id == le32_to_cpu(cmd->capset_id)) {
                        memcpy(cache_ent->caps_cache, resp->capset_data,
                               cache_ent->size);
+                       /* Copy must occur before is_valid is signalled. */
+                       smp_wmb();
                        atomic_set(&cache_ent->is_valid, 1);
                        break;
                }
        }
        spin_unlock(&vgdev->display_info_lock);
-       wake_up(&vgdev->resp_wq);
+       wake_up_all(&vgdev->resp_wq);
 }
 
 static int virtio_get_edid_block(void *data, u8 *buf,
@@ -684,8 +697,11 @@ int virtio_gpu_cmd_get_capset(struct virtio_gpu_device *vgdev,
        struct virtio_gpu_vbuffer *vbuf;
        int max_size;
        struct virtio_gpu_drv_cap_cache *cache_ent;
+       struct virtio_gpu_drv_cap_cache *search_ent;
        void *resp_buf;
 
+       *cache_p = NULL;
+
        if (idx >= vgdev->num_capsets)
                return -EINVAL;
 
@@ -716,9 +732,26 @@ int virtio_gpu_cmd_get_capset(struct virtio_gpu_device *vgdev,
        atomic_set(&cache_ent->is_valid, 0);
        cache_ent->size = max_size;
        spin_lock(&vgdev->display_info_lock);
-       list_add_tail(&cache_ent->head, &vgdev->cap_cache);
+       /* Search while under lock in case it was added by another task. */
+       list_for_each_entry(search_ent, &vgdev->cap_cache, head) {
+               if (search_ent->id == vgdev->capsets[idx].id &&
+                   search_ent->version == version) {
+                       *cache_p = search_ent;
+                       break;
+               }
+       }
+       if (!*cache_p)
+               list_add_tail(&cache_ent->head, &vgdev->cap_cache);
        spin_unlock(&vgdev->display_info_lock);
 
+       if (*cache_p) {
+               /* Entry was found, so free everything that was just created. */
+               kfree(resp_buf);
+               kfree(cache_ent->caps_cache);
+               kfree(cache_ent);
+               return 0;
+       }
+
        cmd_p = virtio_gpu_alloc_cmd_resp
                (vgdev, &virtio_gpu_cmd_capset_cb, &vbuf, sizeof(*cmd_p),
                 sizeof(struct virtio_gpu_resp_capset) + max_size,