drm/prime: Unbreak virtgpu dma-buf export
Subsystems (3)
PATCH 1/1 drm/prime: Unbreak virtgpu dma-buf export
From: Rob Clark <[email protected]>
virtgpu "vram" GEM objects do not implement obj->get_sg_table(). But they also don't use drm_gem_map_dma_buf(). In fact they may not even have guest visible pages. But it is perfectly fine to export and share with other virtual devices.
--- drivers/gpu/drm/drm_prime.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_prime.c +6 -1
@@ -582,7 +582,12 @@ int drm_gem_map_attach(struct dma_buf *dma_buf, {struct drm_gem_object *obj = dma_buf->priv; -if (!obj->funcs->get_sg_table) +/* +* drm_gem_map_dma_buf() requires obj->get_sg_table(), but drivers +* that implement their own ->map_dma_buf() do not. +*/ +if ((dma_buf->ops->map_dma_buf == drm_gem_map_dma_buf) && + !obj->funcs->get_sg_table)return -ENOSYS ;return drm_gem_pin (obj);
Signature · 1 line
2.44.0
It also fixes importing virtgpu blobs into real hardware, for instance amdgpu for DRI_PRIME rendering.
Quoted 36 lines · Rob Clark
From: Rob Clark <[email protected]>
virtgpu "vram" GEM objects do not implement
obj->get_sg_table(). But they also don't usedrm_gem_map_dma_buf(). In fact they may not even have guest visible pages. But it is perfectly fine to export and share with other virtual devices.Reported-by Dominik Behr <[email protected]>Fixes 207395da5a97 ("drm/prime: reject DMA-BUF attach when get_sg_table is missing")Signed-off-by Rob Clark <[email protected]>--- drivers/gpu/drm/drm_prime.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)drivers/gpu/drm/drm_prime.c +6
-2@@ -582,7 +582,12 @@ int drm_gem_map_attach(struct dma_buf *dma_buf, {struct drm_gem_object *obj = dma_buf->priv; -if (!obj->funcs->get_sg_table) +/* +* drm_gem_map_dma_buf() requires obj->get_sg_table(), but drivers +* that implement their own ->map_dma_buf() do not. +*/ +if ((dma_buf->ops->map_dma_buf == drm_gem_map_dma_buf) && + !obj->funcs->get_sg_table)return -ENOSYS ;return drm_gem_pin (obj); --2.44.0
It also fixes importing virtgpu blobs into real hardware, for instance amdgpu for DRI_PRIME rendering.
Quoted 37 lines · Rob Clark
From: Rob Clark <[email protected]>
virtgpu "vram" GEM objects do not implement
obj->get_sg_table(). But they also don't usedrm_gem_map_dma_buf(). In fact they may not even have guest visible pages. But it is perfectly fine to export and share with other virtual devices.Reported-by Dominik Behr <[email protected]>Fixes 207395da5a97 ("drm/prime: reject DMA-BUF attach when get_sg_tableis missing")
Signed-off-by Rob Clark <[email protected]>--- drivers/gpu/drm/drm_prime.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)drivers/gpu/drm/drm_prime.c +6
-2@@ -582,7 +582,12 @@ int drm_gem_map_attach(struct dma_buf *dma_buf, {struct drm_gem_object *obj = dma_buf->priv; -if (!obj->funcs->get_sg_table) +/* +* drm_gem_map_dma_buf() requires obj->get_sg_table(), but drivers +* that implement their own ->map_dma_buf() do not. +*/ +if ((dma_buf->ops->map_dma_buf == drm_gem_map_dma_buf) && + !obj->funcs->get_sg_table)return -ENOSYS ;return drm_gem_pin (obj); --2.44.0
This is actually a bit concerning.. importing a host page backed buffer without guest mapping into a passthru device probably doesn't work and should be rejected earlier.
I do think we should relax the restriction (either taking my patch or reverting the commit it fixes) until we work this out properly (because the original patch is a regression), but importing a buffer without guest pages into a passthru device can't possibly work properly. Maybe it works by chance if the host buffer is mapped to the guest, but that is not guaranteed.
BR,
-R
Quoted 40 lines · Dominik Behr
It also fixes importing virtgpu blobs into real hardware, for instance amdgpu for
DRI_PRIMErendering.Quoted 36 lines · Rob Clark
From: Rob Clark <[email protected]>
virtgpu "vram" GEM objects do not implement
obj->get_sg_table(). But they also don't usedrm_gem_map_dma_buf(). In fact they may not even have guest visible pages. But it is perfectly fine to export and share with other virtual devices.Reported-by Dominik Behr <[email protected]>Fixes 207395da5a97 ("drm/prime: reject DMA-BUF attach when get_sg_table is missing")Signed-off-by Rob Clark <[email protected]>--- drivers/gpu/drm/drm_prime.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)drivers/gpu/drm/drm_prime.c +6
-2@@ -582,7 +582,12 @@ int drm_gem_map_attach(struct dma_buf *dma_buf, {struct drm_gem_object *obj = dma_buf->priv; -if (!obj->funcs->get_sg_table) +/* +* drm_gem_map_dma_buf() requires obj->get_sg_table(), but drivers +* that implement their own ->map_dma_buf() do not. +*/ +if ((dma_buf->ops->map_dma_buf == drm_gem_map_dma_buf) && + !obj->funcs->get_sg_table)return -ENOSYS ;return drm_gem_pin (obj); --2.44.0
It is mapped, via iommu interface (vfio-iommu) when map_dma is called. --
Dominik
Quoted 56 lines · Rob Clark
This is actually a bit concerning.. importing a host page backed buffer without guest mapping into a passthru device probably doesn't work and should be rejected earlier.
I do think we should relax the restriction (either taking my patch or reverting the commit it fixes) until we work this out properly (because the original patch is a regression), but importing a buffer without guest pages into a passthru device can't possibly work properly. Maybe it works by chance if the host buffer is mapped to the guest, but that is not guaranteed.
BR,
-RQuoted 40 lines · Dominik Behr
It also fixes importing virtgpu blobs into real hardware, for instance amdgpu for
DRI_PRIMErendering.Quoted 36 lines · Rob Clark
From: Rob Clark <[email protected]>
virtgpu "vram" GEM objects do not implement
obj->get_sg_table(). But they also don't usedrm_gem_map_dma_buf(). In fact they may not even have guest visible pages. But it is perfectly fine to export and share with other virtual devices.Reported-by Dominik Behr <[email protected]>Fixes 207395da5a97 ("drm/prime: reject DMA-BUF attach when get_sg_table is missing")Signed-off-by Rob Clark <[email protected]>--- drivers/gpu/drm/drm_prime.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)drivers/gpu/drm/drm_prime.c +6
-2@@ -582,7 +582,12 @@ int drm_gem_map_attach(struct dma_buf *dma_buf, {struct drm_gem_object *obj = dma_buf->priv; -if (!obj->funcs->get_sg_table) +/* +* drm_gem_map_dma_buf() requires obj->get_sg_table(), but drivers +* that implement their own ->map_dma_buf() do not. +*/ +if ((dma_buf->ops->map_dma_buf == drm_gem_map_dma_buf) && + !obj->funcs->get_sg_table)return -ENOSYS ;return drm_gem_pin (obj); --2.44.0
Makes sense to me!
Quoted 4 lines · Simon Ser
Makes sense to me!
Reviewed-by Simon Ser <[email protected]>
Thanks.. any chance I could talk you into pushing to drm-misc-fixes?
BR,
-R
Quoted 1 line · Rob Clark
any chance I could talk you into pushing to drm-misc-fixes?
Oh sorry, I thought you had access… Pushed with a minor edit to remove unnecessary parentheses to make checkpatch happy!
Quoted 7 lines · Simon Ser
Quoted 1 line · Rob Clark
any chance I could talk you into pushing to drm-misc-fixes?
Oh sorry, I thought you had access… Pushed with a minor edit to remove unnecessary parentheses to make checkpatch happy!
Thanks!
BR,
-R