dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Benjamin Leggett" <benjamin@edera.io>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH] drm/virtio: use the DMA API for resource backing on Xen
Date: Thu, 06 Aug 2026 23:10:01 +0000	[thread overview]
Message-ID: <20260806231002.27B4D1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260806-virtgpu-xen-dma-v1-1-e499b345bbad@edera.io>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Missing dma_sync_sgtable_for_cpu() in guest-bound transfer paths causes data corruption with SWIOTLB bounce buffers.
--

--- Patch [1]: [PATCH] drm/virtio: use the DMA API for resource backing on Xen ---
commit 5102ee1180b3819921a73a9ff7e4e18ce5a910f1
Author: Benjamin Leggett <benjamin@edera.io>

drm/virtio: use the DMA API for resource backing on Xen

This commit enables the use of the DMA API for virtio-gpu resource backing
on Xen PV domains, regardless of the VIRTIO_F_ACCESS_PLATFORM feature bit.
It introduces virtio_gpu_use_dma_api() and updates the resource
initialization and transfer paths to use it. This ensures that the host
receives correct DMA addresses instead of guest-physical addresses when
swiotlb is active.

> diff --git a/drivers/gpu/drm/virtio/virtgpu_vq.c b/drivers/gpu/drm/virtio/virtgpu_vq.c
> index 905b1f42cd983..568fefd713e0f 100644
> --- a/drivers/gpu/drm/virtio/virtgpu_vq.c
> +++ b/drivers/gpu/drm/virtio/virtgpu_vq.c

[ ... ]

> @@ -1231,7 +1231,7 @@ void virtio_gpu_cmd_transfer_to_host_3d(struct virtio_gpu_device *vgdev,
>  	struct virtio_gpu_object *bo = gem_to_virtio_gpu_obj(objs->objs[0]);
>  	struct virtio_gpu_transfer_host_3d *cmd_p;
>  	struct virtio_gpu_vbuffer *vbuf;
> -	bool use_dma_api = !virtio_has_dma_quirk(vgdev->vdev);
> +	bool use_dma_api = virtio_gpu_use_dma_api(vgdev->vdev);
>  
>  	if (virtio_gpu_is_shmem(bo) && use_dma_api)
>  		dma_sync_sgtable_for_device(vgdev->vdev->dev.parent,
>  					    bo->base.sgt, DMA_TO_DEVICE);

[Severity: High]
This is a pre-existing issue, but while enabling the DMA API for Xen PV
domains, does this leave guest-bound transfers vulnerable to data corruption
with SWIOTLB bounce buffers?

While this patch ensures dma_sync_sgtable_for_device() is called for
host-bound transfers (DMA_TO_DEVICE), it appears that guest-bound transfers
are missing the corresponding CPU synchronization:

drivers/gpu/drm/virtio/virtgpu_vq.c:virtio_gpu_cmd_transfer_from_host_3d() {
    ...
    // Missing dma_sync_sgtable_for_cpu() or
    // dma_sync_sgtable_for_device(..., DMA_FROM_DEVICE)
}

If a user-space application maps a virtio-gpu SHMEM buffer and triggers a
VIRTIO_GPU_CMD_TRANSFER_FROM_HOST_3D via
DRM_IOCTL_VIRTGPU_TRANSFER_FROM_HOST, will the CPU read stale data from
the original backing pages?

Because the driver never calls dma_sync_sgtable_for_cpu() when the transfer
completes, it looks like the SWIOTLB will never copy the bounce buffer
contents back to the original physical pages.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260806-virtgpu-xen-dma-v1-1-e499b345bbad@edera.io?part=1

  reply	other threads:[~2026-08-06 23:10 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-06 22:54 [PATCH] drm/virtio: use the DMA API for resource backing on Xen Benjamin Leggett via B4 Relay
2026-08-06 23:10 ` sashiko-bot [this message]
2026-08-06 23:53   ` Benjamin Leggett
2026-08-07  2:55   ` Benjamin Leggett
2026-08-11 15:49 ` Dmitry Osipenko
2026-08-14 13:41 ` Dmitry Osipenko
2026-08-18 17:48   ` Benjamin Leggett

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=20260806231002.27B4D1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=benjamin@edera.io \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=sashiko-reviews@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