[PATCH v4 4/5] drm/virtio: Import prime buffers from other devices as guest blobs
Kasireddy, Vivek
vivek.kasireddy at intel.com
Tue Nov 26 03:19:44 UTC 2024
Hi Dmitry,
> Subject: Re: [PATCH v4 4/5] drm/virtio: Import prime buffers from other
> devices as guest blobs
>
> > struct drm_gem_object *virtgpu_gem_prime_import(struct drm_device
> *dev,
> > struct dma_buf *buf)
> > {
> > + struct virtio_gpu_device *vgdev = dev->dev_private;
> > + struct dma_buf_attachment *attach;
> > + struct virtio_gpu_object *bo;
> > struct drm_gem_object *obj;
> > + int ret;
> >
> > if (buf->ops == &virtgpu_dmabuf_ops.ops) {
> > obj = buf->priv;
> > @@ -275,7 +304,32 @@ struct drm_gem_object
> *virtgpu_gem_prime_import(struct drm_device *dev,
> > }
> > }
> >
> > - return drm_gem_prime_import(dev, buf);
> > + if (!vgdev->has_resource_blob || vgdev->has_virgl_3d)
> > + return drm_gem_prime_import(dev, buf);
> > +
> > + bo = kzalloc(sizeof(*bo), GFP_KERNEL);
> > + if (!bo)
> > + return ERR_PTR(-ENOMEM);
> > +
> > + obj = &bo->base.base;
> > + obj->funcs = &virtgpu_gem_dma_buf_funcs;
> > + drm_gem_private_object_init(dev, obj, buf->size);
> > +
> > + attach = dma_buf_dynamic_attach(buf, dev->dev,
> > + &virtgpu_dma_buf_attach_ops, obj);
> > + if (IS_ERR(attach)) {
> > + kfree(bo);
> > + return ERR_CAST(attach);
> > + }
> > +
> > + obj->import_attach = attach;
> > + get_dma_buf(buf);
> > +
> > + ret = virtgpu_dma_buf_init_obj(dev, bo, attach);
> > + if (ret < 0)
> > + return ERR_PTR(ret);
>
> Perhaps for a future improvement. Think we can defer
> virtgpu_dma_buf_init_obj() until first use of the object in a case where
I believe it might be possible to do that. I think I started out that way but
figured we would need the addresses/backing in order to create a guest
blob resource. Anyway, I'll try to test this idea again when I get a chance.
> exporter supports dynamic attachment. Otherwise, we're pinning object at
> the import time, partially defeating the purpose of the dynamic
> attachment, AFAICT. I.e. if importer never uses object, then there is no
> need to bother the exporter with the pinning.
Yeah, I agree. It makes sense to defer the initialization until first usage.
Thanks,
Vivek
>
> --
> Best regards,
> Dmitry
More information about the dri-devel
mailing list