drm/virtio: add fence sanity check
authorGerd Hoffmann <kraxel@redhat.com>
Thu, 29 Aug 2019 10:33:01 +0000 (12:33 +0200)
committerGerd Hoffmann <kraxel@redhat.com>
Wed, 4 Sep 2019 04:54:12 +0000 (06:54 +0200)
Make sure we don't leak half-initialized fences outside the driver.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20190829103301.3539-19-kraxel@redhat.com
drivers/gpu/drm/virtio/virtgpu_fence.c

index a0514f5bd0065a3ff293e0fd6994497cb49970e9..a4b9881ca1d399172135fd4c99726a1c9dd278ce 100644 (file)
@@ -41,6 +41,10 @@ bool virtio_fence_signaled(struct dma_fence *f)
 {
        struct virtio_gpu_fence *fence = to_virtio_fence(f);
 
+       if (WARN_ON_ONCE(fence->f.seqno == 0))
+               /* leaked fence outside driver before completing
+                * initialization with virtio_gpu_fence_emit */
+               return false;
        if (atomic64_read(&fence->drv->last_seq) >= fence->f.seqno)
                return true;
        return false;