<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Wed, Feb 26, 2025 at 12:28 PM Thomas Zimmermann <<a href="mailto:tzimmermann@suse.de">tzimmermann@suse.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Add drm_gem_is_imported() that tests if a GEM object's buffer has<br>
been imported. Update the GEM code accordingly.<br>
<br>
GEM code usually tests for imports if import_attach has been set<br>
in struct drm_gem_object. But attaching a dma-buf on import requires<br>
a DMA-capable importer device, which is not the case for many serial<br>
busses like USB or I2C. The new helper tests if a GEM object's dma-buf<br>
has been created from the GEM object.<br>
<br>
Signed-off-by: Thomas Zimmermann <<a href="mailto:tzimmermann@suse.de" target="_blank">tzimmermann@suse.de</a>><br>
---<br>
drivers/gpu/drm/drm_gem.c | 4 ++--<br>
include/drm/drm_gem.h | 14 ++++++++++++++<br>
2 files changed, 16 insertions(+), 2 deletions(-)<br>
<br>
diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c<br>
index ee811764c3df..c6240bab3fa5 100644<br>
--- a/drivers/gpu/drm/drm_gem.c<br>
+++ b/drivers/gpu/drm/drm_gem.c<br>
@@ -348,7 +348,7 @@ int drm_gem_dumb_map_offset(struct drm_file *file, struct drm_device *dev,<br>
return -ENOENT;<br>
<br>
/* Don't allow imported objects to be mapped */<br>
- if (obj->import_attach) {<br>
+ if (drm_gem_is_imported(obj)) {<br>
ret = -EINVAL;<br>
goto out;<br>
}<br>
@@ -1178,7 +1178,7 @@ void drm_gem_print_info(struct drm_printer *p, unsigned int indent,<br>
drm_vma_node_start(&obj->vma_node));<br>
drm_printf_indent(p, indent, "size=%zu\n", obj->size);<br>
drm_printf_indent(p, indent, "imported=%s\n",<br>
- str_yes_no(obj->import_attach));<br>
+ str_yes_no(drm_gem_is_imported(obj)));<br>
<br>
if (obj->funcs->print_info)<br>
obj->funcs->print_info(p, indent, obj);<br>
diff --git a/include/drm/drm_gem.h b/include/drm/drm_gem.h<br>
index fdae947682cd..2bf893eabb4b 100644<br>
--- a/include/drm/drm_gem.h<br>
+++ b/include/drm/drm_gem.h<br>
@@ -35,6 +35,7 @@<br>
*/<br>
<br>
#include <linux/kref.h><br>
+#include <linux/dma-buf.h><br>
#include <linux/dma-resv.h><br>
#include <linux/list.h><br>
#include <linux/mutex.h><br>
@@ -575,6 +576,19 @@ static inline bool drm_gem_object_is_shared_for_memory_stats(struct drm_gem_obje<br>
return (obj->handle_count > 1) || obj->dma_buf;<br>
}<br>
<br>
+/**<br>
+ * drm_gem_is_imported() - Tests if GEM object's buffer has been imported<br>
+ * @obj: the GEM object<br>
+ *<br>
+ * Returns:<br>
+ * True if the GEM object's buffer has been imported, false otherwise<br>
+ */<br>
+static inline bool drm_gem_is_imported(const struct drm_gem_object *obj)<br>
+{<br>
+ /* The dma-buf's priv field points to the original GEM object. */<br>
+ return obj->dma_buf && (obj->dma_buf->priv != obj);<br>
+}<br>
+<br></blockquote><div><br></div><div>Looks good to me.</div><div>Reviewed-by: Anusha Srivatsa <<a href="mailto:asrivats@redhat.com">asrivats@redhat.com</a>> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
#ifdef CONFIG_LOCKDEP<br>
/**<br>
* drm_gem_gpuva_set_lock() - Set the lock protecting accesses to the gpuva list.<br>
-- <br>
2.48.1<br>
<br>
</blockquote></div></div>