dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Aditya Tipre" <tipreaditya@gmail.com>, dri-devel@lists.freedesktop.org
Cc: virtualization@lists.linux.dev,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Eugenio Perez" <eperezma@redhat.com>
Subject: Re: [RFC PATCH 2/2] drm/virtio: test transfer and damage history
Date: Sat, 05 Dec 2026 06:58:09 +0000	[thread overview]
Message-ID: <sashiko-outbox-251169@kernel.org> (raw)
In-Reply-To: <20261205063321.56168-3-tipreaditya@gmail.com>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] drm/virtio: self-deadlock in virtio_gpu_dequeue_ctrl_func() via
  free_vbuf()
- [Medium] drm/virtio: NULL dereference in transfer_test_exit() on init
  failure
- [Low] drm/virtio: duplicate conflicting MODULE_LICENSE() in embedded
  KUnit tests
--

commit dd698453aabfa8903931653819f0e8fe9b1fff6e
Author: Aditya Tipre <tipreaditya@gmail.com>

drm/virtio: test transfer and damage history

This commit adds KUnit tests for virtio-gpu transfer ownership, response
validation, and bounded damage history, linked into the virtio-gpu module
when CONFIG_DRM_VIRTIO_GPU_KUNIT_TEST is enabled.

> diff --git a/drivers/gpu/drm/virtio/Makefile b/drivers/gpu/drm/virtio/Makefile
> index cede1184fa4ea..9db1b859d9a4f 100644
> --- a/drivers/gpu/drm/virtio/Makefile
> +++ b/drivers/gpu/drm/virtio/Makefile
> @@ -9,4 +9,7 @@ virtio-gpu-y := virtgpu_drv.o virtgpu_kms.o virtgpu_gem.o virtgpu_vram.o \
>  	virtgpu_ioctl.o virtgpu_prime.o virtgpu_trace_points.o virtgpu_submit.o \
>  	virtgpu_transfer.o virtgpu_damage.o
>  
> +virtio-gpu-$(CONFIG_DRM_VIRTIO_GPU_KUNIT_TEST) += tests/virtgpu_transfer_test.o
> +virtio-gpu-$(CONFIG_DRM_VIRTIO_GPU_KUNIT_TEST) += tests/virtgpu_damage_test.o
> +
>  obj-$(CONFIG_DRM_VIRTIO_GPU) += virtio-gpu.o

[Severity: Low]
Does linking tests/virtgpu_transfer_test.o and tests/virtgpu_damage_test.o
directly into virtio-gpu.o cause their MODULE_LICENSE("GPL") declarations to
conflict with MODULE_LICENSE("GPL and additional rights") in virtgpu_drv.c?

Because these tests are compiled into the composite virtio-gpu module rather
than standalone test modules, each MODULE_LICENSE() adds a duplicate,
conflicting license= entry (and duplicate virtio_gpu.file= entries when
built-in) to .modinfo.  Removing MODULE_LICENSE("GPL") from both test files
avoids this.

[ ... ]

> diff --git a/drivers/gpu/drm/virtio/tests/virtgpu_transfer_test.c b/drivers/gpu/drm/virtio/tests/virtgpu_transfer_test.c
> new file mode 100644
> index 0000000000000..a6ad76f601e19
> --- /dev/null
> +++ b/drivers/gpu/drm/virtio/tests/virtgpu_transfer_test.c

[ ... ]

> +static int transfer_test_init(struct kunit *test)
> +{
> +	struct transfer_test *ctx;
> +	struct drm_gem_object *obj;
> +
> +	ctx = kunit_kzalloc(test, sizeof(*ctx), GFP_KERNEL);
> +	if (!ctx)
> +		return -ENOMEM;
> +	ctx->vgdev = kunit_kzalloc(test, sizeof(*ctx->vgdev), GFP_KERNEL);
> +	ctx->bo = kunit_kzalloc(test, sizeof(*ctx->bo), GFP_KERNEL);
> +	if (!ctx->vgdev || !ctx->bo)
> +		return -ENOMEM;
> +	test->priv = ctx;

[ ... ]

> +static void transfer_test_exit(struct kunit *test)
> +{
> +	struct transfer_test *ctx = test->priv;
> +	unsigned int i;
> +
> +	virtio_gpu_transfer_stop(ctx->vgdev);

[Severity: Medium]
Can transfer_test_exit() dereference a NULL ctx when transfer_test_init()
fails?

If any of the three kunit_kzalloc() calls returns NULL, transfer_test_init()
returns -ENOMEM before setting test->priv.  KUnit still invokes
suite->exit(test) in kunit_run_case_cleanup() on init failure, so
transfer_test_exit() dereferences ctx->vgdev and oopses.  Returning early
when !ctx avoids the crash while letting KUnit free any partial allocations.

[ ... ]

> +static void transfer_test_success(struct kunit *test)
> +{
> +	struct transfer_test *ctx = test->priv;
> +	struct virtio_gpu_transfer *transfer = transfer_test_alloc(test);
> +	struct virtio_gpu_ctrl_hdr response;
> +
> +	KUNIT_ASSERT_NOT_NULL(test, transfer);
> +	KUNIT_ASSERT_EQ(test, transfer_test_publish(ctx, transfer), 0);
> +	response = transfer_test_response(transfer);
> +	KUNIT_EXPECT_TRUE(test, virtio_gpu_transfer_reply(ctx->vgdev, transfer,
> +							  &response, sizeof(response)));
> +	KUNIT_EXPECT_EQ(test, transfer->state, VIRTIO_GPU_TRANSFER_COMPLETE);
> +	KUNIT_EXPECT_EQ(test, ctx->vgdev->transfer_count[0], 0);
> +	KUNIT_EXPECT_EQ(test, kref_read(&transfer->ref), 1);
> +	virtio_gpu_fence_event_process(ctx->vgdev, transfer->fence_id);
> +}

[Severity: High]
In the real completion path added by commit "drm/virtio: accumulate
confirmed dumb-buffer damage", can free_vbuf() self-deadlock
ctrlq.dequeue_work when virtio_gpu_transfer_put() drops the last BO
reference?

A damage-tracked transfer holds one GEM reference in entry->objs and another
in transfer->bo.  If userspace closes the GEM handle while the transfer is
in flight, virtio_gpu_dequeue_ctrl_func() wakes ctrlq.ack_queue (allowing
submitters to refill ctrlq.vq), schedules obj_free_work to drop entry->objs,
and then calls free_vbuf() synchronously:

CPU0 (ctrlq.dequeue_work)               CPU1 (obj_free_work)
virtio_gpu_dequeue_ctrl_func()
  virtio_gpu_transfer_reply()
    virtio_gpu_transfer_put()
  wake_up(&vgdev->ctrlq.ack_queue)
  virtio_gpu_array_put_free_delayed()
                                        virtio_gpu_array_put_free_work()
                                          drm_gem_object_put(bo)
  free_vbuf(vgdev, entry)
    virtio_gpu_transfer_put()
      virtio_gpu_transfer_release()
        drm_gem_object_put(bo)
          virtio_gpu_free_object()
            virtio_gpu_cmd_unref_resource()
              virtio_gpu_queue_ctrl_sgs()
                wait_event(ctrlq.ack_queue, ...)  <-- self-deadlock

Because ctrlq.dequeue_work is the only worker that reclaims ctrlq
descriptors and wakes ctrlq.ack_queue, the entire control virtqueue hangs
permanently.  This is the same deadlock commit f0c6cef7e717 ("drm/virtio:
add worker for object release") avoided by deferring GEM object release to
obj_free_work.  Deferring transfer release (or its BO reference drop) to
obj_free_work would avoid running drm_gem_object_put() from
ctrlq.dequeue_work.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261205063321.56168-1-tipreaditya@gmail.com?part=2

      reply	other threads:[~2026-12-05  6:58 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-05  6:33 [RFC PATCH 0/2] drm/virtio: avoid full uploads for rotating dumb buffers Aditya Tipre
2026-12-05  6:33 ` [RFC PATCH 1/2] drm/virtio: accumulate confirmed dumb-buffer damage Aditya Tipre
2026-12-05  6:59   ` sashiko-bot
2026-12-05  6:33 ` [RFC PATCH 2/2] drm/virtio: test transfer and damage history Aditya Tipre
2026-12-05  6:58   ` sashiko-bot [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-251169@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=eperezma@redhat.com \
    --cc=mst@redhat.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=tipreaditya@gmail.com \
    --cc=virtualization@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox