2022-06-30 21:00:53

by Dmitry Osipenko

[permalink] [raw]
Subject: [PATCH v7 0/9] VirtIO-GPU driver fixes and improvements

This series fixes few problem found in the VirtIO-GPU driver and makes
couple improvements. The "DMA API usage improvement" patch will be needed
later on when we will be about to add memory shrinker support to the driver,
it also cleans up code nicely.

Changelog:

v7: - Factored out VirtIO fixes from [1] since I'll be working on the
dma-buf locking in a separate patchset now.

[1] https://lore.kernel.org/all/[email protected]/

- Added r-b from Thomas Hellström.

- Added more fixes-tags to the patches.

- The part of the v6 "Correct drm_gem_shmem_get_sg_table() error handling"
patch got merged into linux-next recent from another patch [2],
but that patch missed to zero out shmem->pages on error. Hence I
updated my patch to fix the merged fix.

[2] https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id=c24968734abfed81c8f93dc5f44a7b7a9aecadfa

Dmitry Osipenko (9):
drm/virtio: Correct drm_gem_shmem_get_sg_table() error handling
drm/virtio: Check whether transferred 2D BO is shmem
drm/virtio: Unlock reservations on virtio_gpu_object_shmem_init()
error
drm/virtio: Unlock reservations on dma_resv_reserve_fences() error
drm/virtio: Use appropriate atomic state in
virtio_gpu_plane_cleanup_fb()
drm/virtio: Simplify error handling of virtio_gpu_object_create()
drm/virtio: Improve DMA API usage for shmem BOs
drm/virtio: Use dev_is_pci()
drm/virtio: Return proper error codes instead of -1

drivers/gpu/drm/virtio/virtgpu_drv.c | 53 +++++---------------
drivers/gpu/drm/virtio/virtgpu_drv.h | 5 +-
drivers/gpu/drm/virtio/virtgpu_gem.c | 4 +-
drivers/gpu/drm/virtio/virtgpu_kms.c | 7 ++-
drivers/gpu/drm/virtio/virtgpu_object.c | 65 ++++++-------------------
drivers/gpu/drm/virtio/virtgpu_plane.c | 6 +--
drivers/gpu/drm/virtio/virtgpu_vq.c | 21 ++++----
7 files changed, 47 insertions(+), 114 deletions(-)

--
2.36.1


2022-06-30 21:01:26

by Dmitry Osipenko

[permalink] [raw]
Subject: [PATCH v7 5/9] drm/virtio: Use appropriate atomic state in virtio_gpu_plane_cleanup_fb()

Make virtio_gpu_plane_cleanup_fb() to clean the state which DRM core
wants to clean up and not the current plane's state. Normally the older
atomic state is cleaned up, but the newer state could also be cleaned up
in case of aborted commits.

Cc: [email protected]
Signed-off-by: Dmitry Osipenko <[email protected]>
---
drivers/gpu/drm/virtio/virtgpu_plane.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/virtio/virtgpu_plane.c b/drivers/gpu/drm/virtio/virtgpu_plane.c
index 6d3cc9e238a4..7148f3813d8b 100644
--- a/drivers/gpu/drm/virtio/virtgpu_plane.c
+++ b/drivers/gpu/drm/virtio/virtgpu_plane.c
@@ -266,14 +266,14 @@ static int virtio_gpu_plane_prepare_fb(struct drm_plane *plane,
}

static void virtio_gpu_plane_cleanup_fb(struct drm_plane *plane,
- struct drm_plane_state *old_state)
+ struct drm_plane_state *state)
{
struct virtio_gpu_framebuffer *vgfb;

- if (!plane->state->fb)
+ if (!state->fb)
return;

- vgfb = to_virtio_gpu_framebuffer(plane->state->fb);
+ vgfb = to_virtio_gpu_framebuffer(state->fb);
if (vgfb->fence) {
dma_fence_put(&vgfb->fence->f);
vgfb->fence = NULL;
--
2.36.1

2022-06-30 21:01:40

by Dmitry Osipenko

[permalink] [raw]
Subject: [PATCH v7 2/9] drm/virtio: Check whether transferred 2D BO is shmem

Transferred 2D BO always must be a shmem BO. Add check for that to prevent
NULL dereference if userspace passes a VRAM BO.

Cc: [email protected]
Reviewed-by: Emil Velikov <[email protected]>
Signed-off-by: Dmitry Osipenko <[email protected]>
---
drivers/gpu/drm/virtio/virtgpu_vq.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/virtio/virtgpu_vq.c b/drivers/gpu/drm/virtio/virtgpu_vq.c
index b7529b2b9883..1262fd0b3bef 100644
--- a/drivers/gpu/drm/virtio/virtgpu_vq.c
+++ b/drivers/gpu/drm/virtio/virtgpu_vq.c
@@ -597,7 +597,7 @@ void virtio_gpu_cmd_transfer_to_host_2d(struct virtio_gpu_device *vgdev,
bool use_dma_api = !virtio_has_dma_quirk(vgdev->vdev);
struct virtio_gpu_object_shmem *shmem = to_virtio_gpu_shmem(bo);

- if (use_dma_api)
+ if (virtio_gpu_is_shmem(bo) && use_dma_api)
dma_sync_sgtable_for_device(vgdev->vdev->dev.parent,
shmem->pages, DMA_TO_DEVICE);

--
2.36.1