drm/virtio: track created object state
authorGerd Hoffmann <kraxel@redhat.com>
Fri, 19 Oct 2018 06:18:42 +0000 (08:18 +0200)
committerGerd Hoffmann <kraxel@redhat.com>
Mon, 29 Oct 2018 21:50:55 +0000 (22:50 +0100)
Track whenever the virtio_gpu_object is already created (i.e. host knows
about it) in a new variable.  Add checks to virtio_gpu_object_attach()
to do nothing on objects not created yet.

Make virtio_gpu_ttm_bo_destroy() use the new variable too, instead of
expecting hw_res_handle indicating the object state.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Dave Airlie <airlied@redhat.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20181019061847.18958-2-kraxel@redhat.com
drivers/gpu/drm/virtio/virtgpu_drv.h
drivers/gpu/drm/virtio/virtgpu_fb.c
drivers/gpu/drm/virtio/virtgpu_gem.c
drivers/gpu/drm/virtio/virtgpu_ioctl.c
drivers/gpu/drm/virtio/virtgpu_object.c
drivers/gpu/drm/virtio/virtgpu_vq.c

index d29f0c7c768c199b7e959883becf6f893d54ee9a..5edc22d7a72f16dfb2b076cd265942345439d591 100644 (file)
@@ -65,6 +65,7 @@ struct virtio_gpu_object {
        struct ttm_placement            placement;
        struct ttm_buffer_object        tbo;
        struct ttm_bo_kmap_obj          kmap;
+       bool created;
 };
 #define gem_to_virtio_gpu_obj(gobj) \
        container_of((gobj), struct virtio_gpu_object, gem_base)
@@ -263,6 +264,7 @@ void virtio_gpu_resource_id_get(struct virtio_gpu_device *vgdev,
                               uint32_t *resid);
 void virtio_gpu_resource_id_put(struct virtio_gpu_device *vgdev, uint32_t id);
 void virtio_gpu_cmd_create_resource(struct virtio_gpu_device *vgdev,
+                                   struct virtio_gpu_object *bo,
                                    uint32_t resource_id,
                                    uint32_t format,
                                    uint32_t width,
@@ -324,6 +326,7 @@ void virtio_gpu_cmd_transfer_to_host_3d(struct virtio_gpu_device *vgdev,
                                        struct virtio_gpu_fence **fence);
 void
 virtio_gpu_cmd_resource_create_3d(struct virtio_gpu_device *vgdev,
+                                 struct virtio_gpu_object *bo,
                                  struct virtio_gpu_resource_create_3d *rc_3d,
                                  struct virtio_gpu_fence **fence);
 void virtio_gpu_ctrl_ack(struct virtqueue *vq);
index cea749f4ec3930886f8c9f0dc14287bfccfd77c0..d39f4f3350d0cb522c0fd53e10d470a0ad0e14f0 100644 (file)
@@ -232,7 +232,7 @@ static int virtio_gpufb_create(struct drm_fb_helper *helper,
                return PTR_ERR(obj);
 
        virtio_gpu_resource_id_get(vgdev, &resid);
-       virtio_gpu_cmd_create_resource(vgdev, resid, format,
+       virtio_gpu_cmd_create_resource(vgdev, obj, resid, format,
                                       mode_cmd.width, mode_cmd.height);
 
        ret = virtio_gpu_object_kmap(obj);
index 82c817f37cf7d68ebe2cf72fe022978fb1b02291..33dbd5aed705efb0bddfed5240451659d2703b0c 100644 (file)
@@ -103,8 +103,9 @@ int virtio_gpu_mode_dumb_create(struct drm_file *file_priv,
                goto fail;
 
        format = virtio_gpu_translate_format(DRM_FORMAT_HOST_XRGB8888);
+       obj = gem_to_virtio_gpu_obj(gobj);
        virtio_gpu_resource_id_get(vgdev, &resid);
-       virtio_gpu_cmd_create_resource(vgdev, resid, format,
+       virtio_gpu_cmd_create_resource(vgdev, obj, resid, format,
                                       args->width, args->height);
 
        /* attach the object to the resource */
index f16b875d6a46b32c4c8a6a3694aaec05da3727f7..98bb238e91749ebcf41eb7bad4cdbf08c9ec3f72 100644 (file)
@@ -260,7 +260,7 @@ static int virtio_gpu_resource_create_ioctl(struct drm_device *dev, void *data,
        obj = &qobj->gem_base;
 
        if (!vgdev->has_virgl_3d) {
-               virtio_gpu_cmd_create_resource(vgdev, res_id, rc->format,
+               virtio_gpu_cmd_create_resource(vgdev, qobj, res_id, rc->format,
                                               rc->width, rc->height);
 
                ret = virtio_gpu_object_attach(vgdev, qobj, res_id, NULL);
@@ -288,7 +288,7 @@ static int virtio_gpu_resource_create_ioctl(struct drm_device *dev, void *data,
                rc_3d.nr_samples = cpu_to_le32(rc->nr_samples);
                rc_3d.flags = cpu_to_le32(rc->flags);
 
-               virtio_gpu_cmd_resource_create_3d(vgdev, &rc_3d, NULL);
+               virtio_gpu_cmd_resource_create_3d(vgdev, qobj, &rc_3d, NULL);
                ret = virtio_gpu_object_attach(vgdev, qobj, res_id, &fence);
                if (ret) {
                        ttm_eu_backoff_reservation(&ticket, &validate_list);
index eca7655374701f628990410c99f7a71ea20b5435..6611c487d79807da0a459741aecdf2fe2dd07684 100644 (file)
@@ -33,7 +33,7 @@ static void virtio_gpu_ttm_bo_destroy(struct ttm_buffer_object *tbo)
        bo = container_of(tbo, struct virtio_gpu_object, tbo);
        vgdev = (struct virtio_gpu_device *)bo->gem_base.dev->dev_private;
 
-       if (bo->hw_res_handle)
+       if (bo->created)
                virtio_gpu_cmd_unref_resource(vgdev, bo->hw_res_handle);
        if (bo->pages)
                virtio_gpu_object_free_sg_table(bo);
index 4e2e037aed34a22551225f2cb623f5492484c72a..3b6904c5b307e1f81e24222f680ba8987c9482d7 100644 (file)
@@ -388,6 +388,7 @@ retry:
 
 /* create a basic resource */
 void virtio_gpu_cmd_create_resource(struct virtio_gpu_device *vgdev,
+                                   struct virtio_gpu_object *bo,
                                    uint32_t resource_id,
                                    uint32_t format,
                                    uint32_t width,
@@ -406,6 +407,7 @@ void virtio_gpu_cmd_create_resource(struct virtio_gpu_device *vgdev,
        cmd_p->height = cpu_to_le32(height);
 
        virtio_gpu_queue_ctrl_buffer(vgdev, vbuf);
+       bo->created = true;
 }
 
 void virtio_gpu_cmd_unref_resource(struct virtio_gpu_device *vgdev,
@@ -772,6 +774,7 @@ void virtio_gpu_cmd_context_detach_resource(struct virtio_gpu_device *vgdev,
 
 void
 virtio_gpu_cmd_resource_create_3d(struct virtio_gpu_device *vgdev,
+                                 struct virtio_gpu_object *bo,
                                  struct virtio_gpu_resource_create_3d *rc_3d,
                                  struct virtio_gpu_fence **fence)
 {
@@ -786,6 +789,7 @@ virtio_gpu_cmd_resource_create_3d(struct virtio_gpu_device *vgdev,
        cmd_p->hdr.flags = 0;
 
        virtio_gpu_queue_fenced_ctrl_buffer(vgdev, vbuf, &cmd_p->hdr, fence);
+       bo->created = true;
 }
 
 void virtio_gpu_cmd_transfer_to_host_3d(struct virtio_gpu_device *vgdev,
@@ -869,6 +873,9 @@ int virtio_gpu_object_attach(struct virtio_gpu_device *vgdev,
        struct scatterlist *sg;
        int si, nents;
 
+       if (!obj->created)
+               return 0;
+
        if (!obj->pages) {
                int ret;