From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: "Thomas Zimmermann" <tzimmermann@suse.de>,
"Anusha Srivatsa" <asrivats@redhat.com>,
"Christian König" <christian.koenig@amd.com>,
"Sasha Levin" <sashal@kernel.org>,
maarten.lankhorst@linux.intel.com, mripard@kernel.org,
airlied@gmail.com, simona@ffwll.ch, sumit.semwal@linaro.org,
dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org,
linaro-mm-sig@lists.linaro.org
Subject: [PATCH AUTOSEL 6.12 192/486] drm/gem: Test for imported GEM buffers with helper
Date: Mon, 5 May 2025 18:34:28 -0400 [thread overview]
Message-ID: <20250505223922.2682012-192-sashal@kernel.org> (raw)
In-Reply-To: <20250505223922.2682012-1-sashal@kernel.org>
From: Thomas Zimmermann <tzimmermann@suse.de>
[ Upstream commit b57aa47d39e94dc47403a745e2024664e544078c ]
Add drm_gem_is_imported() that tests if a GEM object's buffer has
been imported. Update the GEM code accordingly.
GEM code usually tests for imports if import_attach has been set
in struct drm_gem_object. But attaching a dma-buf on import requires
a DMA-capable importer device, which is not the case for many serial
busses like USB or I2C. The new helper tests if a GEM object's dma-buf
has been created from the GEM object.
Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: Anusha Srivatsa <asrivats@redhat.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20250226172457.217725-2-tzimmermann@suse.de
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
drivers/gpu/drm/drm_gem.c | 4 ++--
include/drm/drm_gem.h | 14 ++++++++++++++
2 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c
index 149b8e25da5bb..426d0867882df 100644
--- a/drivers/gpu/drm/drm_gem.c
+++ b/drivers/gpu/drm/drm_gem.c
@@ -322,7 +322,7 @@ int drm_gem_dumb_map_offset(struct drm_file *file, struct drm_device *dev,
return -ENOENT;
/* Don't allow imported objects to be mapped */
- if (obj->import_attach) {
+ if (drm_gem_is_imported(obj)) {
ret = -EINVAL;
goto out;
}
@@ -1152,7 +1152,7 @@ void drm_gem_print_info(struct drm_printer *p, unsigned int indent,
drm_vma_node_start(&obj->vma_node));
drm_printf_indent(p, indent, "size=%zu\n", obj->size);
drm_printf_indent(p, indent, "imported=%s\n",
- str_yes_no(obj->import_attach));
+ str_yes_no(drm_gem_is_imported(obj)));
if (obj->funcs->print_info)
obj->funcs->print_info(p, indent, obj);
diff --git a/include/drm/drm_gem.h b/include/drm/drm_gem.h
index d8b86df2ec0da..70c0f8c83629d 100644
--- a/include/drm/drm_gem.h
+++ b/include/drm/drm_gem.h
@@ -35,6 +35,7 @@
*/
#include <linux/kref.h>
+#include <linux/dma-buf.h>
#include <linux/dma-resv.h>
#include <linux/list.h>
#include <linux/mutex.h>
@@ -570,6 +571,19 @@ static inline bool drm_gem_object_is_shared_for_memory_stats(struct drm_gem_obje
return (obj->handle_count > 1) || obj->dma_buf;
}
+/**
+ * drm_gem_is_imported() - Tests if GEM object's buffer has been imported
+ * @obj: the GEM object
+ *
+ * Returns:
+ * True if the GEM object's buffer has been imported, false otherwise
+ */
+static inline bool drm_gem_is_imported(const struct drm_gem_object *obj)
+{
+ /* The dma-buf's priv field points to the original GEM object. */
+ return obj->dma_buf && (obj->dma_buf->priv != obj);
+}
+
#ifdef CONFIG_LOCKDEP
/**
* drm_gem_gpuva_set_lock() - Set the lock protecting accesses to the gpuva list.
--
2.39.5
next prev parent reply other threads:[~2025-05-05 22:45 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20250505223922.2682012-1-sashal@kernel.org>
2025-05-05 22:34 ` [PATCH AUTOSEL 6.12 187/486] media: c8sectpfe: Call of_node_put(i2c_bus) only once in c8sectpfe_probe() Sasha Levin
2025-05-05 22:34 ` Sasha Levin [this message]
2025-05-05 22:34 ` [PATCH AUTOSEL 6.12 203/486] media: cx231xx: set device_caps for 417 Sasha Levin
2025-05-05 22:34 ` [PATCH AUTOSEL 6.12 211/486] media: imx335: Set vblank immediately Sasha Levin
2025-05-05 22:34 ` [PATCH AUTOSEL 6.12 220/486] media: uvcvideo: Add sanity check to uvc_ioctl_xu_ctrl_map Sasha Levin
2025-05-05 22:34 ` [PATCH AUTOSEL 6.12 221/486] media: uvcvideo: Handle uvc menu translation inside uvc_get_le_value Sasha Levin
2025-05-05 22:35 ` [PATCH AUTOSEL 6.12 261/486] media: adv7180: Disable test-pattern control on adv7180 Sasha Levin
2025-05-05 22:35 ` [PATCH AUTOSEL 6.12 262/486] media: tc358746: improve calculation of the D-PHY timing registers Sasha Levin
2025-05-05 22:35 ` [PATCH AUTOSEL 6.12 277/486] drm/amdgpu: remove all KFD fences from the BO on release Sasha Levin
2025-05-05 22:36 ` [PATCH AUTOSEL 6.12 320/486] media: test-drivers: vivid: don't call schedule in loop Sasha Levin
2025-05-05 22:36 ` [PATCH AUTOSEL 6.12 339/486] media: i2c: imx219: Correct the minimum vblanking value Sasha Levin
2025-05-05 22:36 ` [PATCH AUTOSEL 6.12 340/486] media: v4l: Memset argument to 0 before calling get_mbus_config pad op Sasha Levin
2025-05-05 22:38 ` [PATCH AUTOSEL 6.12 417/486] media: qcom: camss: csid: Only add TPG v4l2 ctrl if TPG hardware is available Sasha Levin
2025-05-05 22:38 ` [PATCH AUTOSEL 6.12 418/486] media: qcom: camss: Add default case in vfe_src_pad_code Sasha Levin
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=20250505223922.2682012-192-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=airlied@gmail.com \
--cc=asrivats@redhat.com \
--cc=christian.koenig@amd.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=linaro-mm-sig@lists.linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=simona@ffwll.ch \
--cc=stable@vger.kernel.org \
--cc=sumit.semwal@linaro.org \
--cc=tzimmermann@suse.de \
/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