[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <12505066-eb42-4ddf-9c6d-29eca6eefdbc@amd.com>
Date: Wed, 10 Jan 2024 11:46:35 +0100
From: Christian König <christian.koenig@....com>
To: Julia Zhang <julia.zhang@....com>,
Gurchetan Singh <gurchetansingh@...omium.org>, Chia-I Wu
<olvaffe@...il.com>, David Airlie <airlied@...hat.com>,
Gerd Hoffmann <kraxel@...hat.com>, linux-kernel@...r.kernel.org,
dri-devel@...ts.freedesktop.org, amd-gfx@...ts.freedesktop.org,
virtualization@...ts.linux-foundation.org,
Alex Deucher <alexander.deucher@....com>, David Airlie <airlied@...il.com>,
Erik Faye-Lund <kusmabite@...il.com>, Marek Olšák
<marek.olsak@....com>,
Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@....com>,
Honglei Huang <honglei1.huang@....com>, Chen Jiqian <Jiqian.Chen@....com>,
Huang Rui <ray.huang@....com>
Subject: Re: [PATCH 1/1] drm/virtio: Implement device_attach
Am 10.01.24 um 11:22 schrieb Daniel Vetter:
> On Wed, Jan 10, 2024 at 11:19:37AM +0100, Christian König wrote:
>> Am 10.01.24 um 10:56 schrieb Julia Zhang:
>>> drm_gem_map_attach() requires drm_gem_object_funcs.get_sg_table to be
>>> implemented, or else return ENOSYS. Virtio has no get_sg_table
>>> implemented for vram object. To fix this, add a new device_attach to
>>> call drm_gem_map_attach() for shmem object and return 0 for vram object
>>> instead of calling drm_gem_map_attach for both of these two kinds of
>>> object.
>> Well as far as I can see this is nonsense from the DMA-buf side of things.
>>
>> SG tables are always needed as long as you don't re-import the same object
>> into your driver and then you shouldn't end up in this function in the first
>> place.
>>
>> So that drm_gem_map_attach() requires get_sg_table to be implemented is
>> intentional and should never be overridden like this.
> See my reply, tldr; you're allowed to reject ->attach with -EBUSY to
> handle exactly this case of non-shareable buffer types. But definitely
> don't silently fail, that's a "we'll oops on map_attachment" kind of bug
> :-)
Ah, yes that makes much more sense!
So basically just the "return 0;" needs to be "return -EBUSY;".
Regards,
Christian.
> -Sima
>
>> Regards,
>> Christian.
>>
>>> Signed-off-by: Julia Zhang <julia.zhang@....com>
>>> ---
>>> drivers/gpu/drm/virtio/virtgpu_prime.c | 14 +++++++++++++-
>>> 1 file changed, 13 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/gpu/drm/virtio/virtgpu_prime.c b/drivers/gpu/drm/virtio/virtgpu_prime.c
>>> index 44425f20d91a..f0b0ff6f3813 100644
>>> --- a/drivers/gpu/drm/virtio/virtgpu_prime.c
>>> +++ b/drivers/gpu/drm/virtio/virtgpu_prime.c
>>> @@ -71,6 +71,18 @@ static void virtgpu_gem_unmap_dma_buf(struct dma_buf_attachment *attach,
>>> drm_gem_unmap_dma_buf(attach, sgt, dir);
>>> }
>>> +static int virtgpu_gem_device_attach(struct dma_buf *dma_buf,
>>> + struct dma_buf_attachment *attach)
>>> +{
>>> + struct drm_gem_object *obj = attach->dmabuf->priv;
>>> + struct virtio_gpu_object *bo = gem_to_virtio_gpu_obj(obj);
>>> +
>>> + if (virtio_gpu_is_vram(bo))
>>> + return 0;
>>> +
>>> + return drm_gem_map_attach(dma_buf, attach);
>>> +}
>>> +
>>> static const struct virtio_dma_buf_ops virtgpu_dmabuf_ops = {
>>> .ops = {
>>> .cache_sgt_mapping = true,
>>> @@ -83,7 +95,7 @@ static const struct virtio_dma_buf_ops virtgpu_dmabuf_ops = {
>>> .vmap = drm_gem_dmabuf_vmap,
>>> .vunmap = drm_gem_dmabuf_vunmap,
>>> },
>>> - .device_attach = drm_gem_map_attach,
>>> + .device_attach = virtgpu_gem_device_attach,
>>> .get_uuid = virtgpu_virtio_get_uuid,
>>> };
Powered by blists - more mailing lists