Linux virtualization list
 help / color / mirror / Atom feed
From: Dmitry Osipenko <dmitry.osipenko@collabora.com>
To: David Airlie <airlied@redhat.com>,
	Gerd Hoffmann <kraxel@redhat.com>,
	Gurchetan Singh <gurchetansingh@chromium.org>,
	Chia-I Wu <olvaffe@gmail.com>,
	Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>,
	Alyssa Rosenzweig <alyssa@rosenzweig.io>
Cc: Rob Clark <robdclark@gmail.com>,
	dri-devel@lists.freedesktop.org, virtualization@lists.linux.dev,
	linux-kernel@vger.kernel.org, kernel@collabora.com,
	Nagapuri Ramesh <ram.nagapuri@gmail.com>
Subject: Re: [PATCH v2] drm/virtio: Extend blob UAPI with deferred-mapping hinting
Date: Thu, 14 May 2026 01:10:48 +0300	[thread overview]
Message-ID: <1efb8795-3345-46ae-8195-1b391159b90b@collabora.com> (raw)
In-Reply-To: <20260501000043.2483678-1-dmitry.osipenko@collabora.com>

On 5/1/26 03:00, Dmitry Osipenko wrote:
> If userspace never maps GEM object, then BO wastes hostmem space
> because VirtIO-GPU driver maps VRAM BO at the BO's creating time.
> 
> Make mappings on-demand by adding new RESOURCE_CREATE_BLOB IOCTL/UAPI
> hinting flag telling that host mapping should be deferred until first
> mapping is made when the flag is set by userspace.
> 
> Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
> Reviewed-by: Rob Clark <robdclark@gmail.com>
> ---
> 
> Changelog:
> 
> v2: Rebased on recent kernel. Intel i915 native ctx landed to Mesa, lets to
>     proceed with merging the mapping hint as a first user of the feature.
> 
>  drivers/gpu/drm/virtio/virtgpu_drv.h   |  2 ++
>  drivers/gpu/drm/virtio/virtgpu_ioctl.c |  1 +
>  drivers/gpu/drm/virtio/virtgpu_vram.c  | 30 +++++++++++++++++++++-----
>  include/uapi/drm/virtgpu_drm.h         |  4 ++++
>  4 files changed, 32 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/gpu/drm/virtio/virtgpu_drv.h b/drivers/gpu/drm/virtio/virtgpu_drv.h
> index f17660a71a3e..6f49213e23f8 100644
> --- a/drivers/gpu/drm/virtio/virtgpu_drv.h
> +++ b/drivers/gpu/drm/virtio/virtgpu_drv.h
> @@ -84,6 +84,7 @@ struct virtio_gpu_object_params {
>  	uint32_t blob_mem;
>  	uint32_t blob_flags;
>  	uint64_t blob_id;
> +	uint32_t blob_hints;
>  };
>  
>  struct virtio_gpu_object {
> @@ -507,6 +508,7 @@ struct sg_table *virtio_gpu_vram_map_dma_buf(struct virtio_gpu_object *bo,
>  void virtio_gpu_vram_unmap_dma_buf(struct device *dev,
>  				   struct sg_table *sgt,
>  				   enum dma_data_direction dir);
> +void virtio_gpu_vram_map_deferred(struct virtio_gpu_object_vram *vram);
>  
>  /* virtgpu_submit.c */
>  int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,
> diff --git a/drivers/gpu/drm/virtio/virtgpu_ioctl.c b/drivers/gpu/drm/virtio/virtgpu_ioctl.c
> index c33c057365f8..01daa72b1310 100644
> --- a/drivers/gpu/drm/virtio/virtgpu_ioctl.c
> +++ b/drivers/gpu/drm/virtio/virtgpu_ioctl.c
> @@ -489,6 +489,7 @@ static int verify_blob(struct virtio_gpu_device *vgdev,
>  	params->size = rc_blob->size;
>  	params->blob = true;
>  	params->blob_flags = rc_blob->blob_flags;
> +	params->blob_hints = rc_blob->blob_hints;
>  	return 0;
>  }
>  
> diff --git a/drivers/gpu/drm/virtio/virtgpu_vram.c b/drivers/gpu/drm/virtio/virtgpu_vram.c
> index 084e80227433..4ae3cbc35dd3 100644
> --- a/drivers/gpu/drm/virtio/virtgpu_vram.c
> +++ b/drivers/gpu/drm/virtio/virtgpu_vram.c
> @@ -3,6 +3,8 @@
>  
>  #include <linux/dma-mapping.h>
>  
> +static DEFINE_MUTEX(map_lock);
> +
>  static void virtio_gpu_vram_free(struct drm_gem_object *obj)
>  {
>  	struct virtio_gpu_object *bo = gem_to_virtio_gpu_obj(obj);
> @@ -42,6 +44,11 @@ static int virtio_gpu_vram_mmap(struct drm_gem_object *obj,
>  	if (!(bo->blob_flags & VIRTGPU_BLOB_FLAG_USE_MAPPABLE))
>  		return -EINVAL;
>  
> +	virtio_gpu_vram_map_deferred(vram);
> +
> +	if (vram->map_state == STATE_INITIALIZING)
> +		virtio_gpu_notify(vgdev);
> +
>  	wait_event(vgdev->resp_wq, vram->map_state != STATE_INITIALIZING);
>  	if (vram->map_state != STATE_OK)
>  		return -EINVAL;
> @@ -218,14 +225,27 @@ int virtio_gpu_vram_create(struct virtio_gpu_device *vgdev,
>  
>  	virtio_gpu_cmd_resource_create_blob(vgdev, &vram->base, params, NULL,
>  					    0);
> -	if (params->blob_flags & VIRTGPU_BLOB_FLAG_USE_MAPPABLE) {
> -		ret = virtio_gpu_vram_map(&vram->base);
> -		if (ret) {
> -			virtio_gpu_vram_free(obj);
> -			return ret;
> +	if (!(params->blob_hints & DRM_VIRTGPU_BLOB_FLAG_HINT_DEFER_MAPPING)) {
> +		if (params->blob_flags & VIRTGPU_BLOB_FLAG_USE_MAPPABLE) {
> +			ret = virtio_gpu_vram_map(&vram->base);
> +			if (ret) {
> +				virtio_gpu_vram_free(obj);
> +				return ret;
> +			}
>  		}
>  	}
>  
>  	*bo_ptr = &vram->base;
>  	return 0;
>  }
> +
> +void virtio_gpu_vram_map_deferred(struct virtio_gpu_object_vram *vram)
> +{
> +	if (!(vram->base.blob_flags & VIRTGPU_BLOB_FLAG_USE_MAPPABLE))
> +		return;
> +
> +	mutex_lock(&map_lock);
> +	if (!drm_mm_node_allocated(&vram->vram_node))
> +		virtio_gpu_vram_map(&vram->base);
> +	mutex_unlock(&map_lock);
> +}
> diff --git a/include/uapi/drm/virtgpu_drm.h b/include/uapi/drm/virtgpu_drm.h
> index 9debb320c34b..ba09a4ee3e77 100644
> --- a/include/uapi/drm/virtgpu_drm.h
> +++ b/include/uapi/drm/virtgpu_drm.h
> @@ -200,6 +200,10 @@ struct drm_virtgpu_resource_create_blob {
>  	__u32 cmd_size;
>  	__u64 cmd;
>  	__u64 blob_id;
> +
> +#define DRM_VIRTGPU_BLOB_FLAG_HINT_DEFER_MAPPING        0x0001
> +	__u32 blob_hints;
> +	__u32 pad2;
>  };
>  
>  #define VIRTGPU_CONTEXT_PARAM_CAPSET_ID       0x0001

Applied patch to misc-next

-- 
Best regards,
Dmitry

      reply	other threads:[~2026-05-13 22:11 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-01  0:00 [PATCH v2] drm/virtio: Extend blob UAPI with deferred-mapping hinting Dmitry Osipenko
2026-05-13 22:10 ` Dmitry Osipenko [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=1efb8795-3345-46ae-8195-1b391159b90b@collabora.com \
    --to=dmitry.osipenko@collabora.com \
    --cc=airlied@redhat.com \
    --cc=alyssa@rosenzweig.io \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gurchetansingh@chromium.org \
    --cc=kernel@collabora.com \
    --cc=kraxel@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=olvaffe@gmail.com \
    --cc=pierre-eric.pelloux-prayer@amd.com \
    --cc=ram.nagapuri@gmail.com \
    --cc=robdclark@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