Skip to contentSkip to conversation

dma-buf: add some tracepoints to debug.

PATCH Superseded Xiang Gao 3 participants 5 messages Dec 1, 2025 – Dec 16, 2025

Subsystems (3)

v5 of 13 Superseded Latest is v13 →

lore
Share & tools
lore

Xiang Gao

author
#0 lore raw

PATCH v5 1/1 dma-buf: add some tracepoints to debug.

From: gaoxiang17 <[email protected]>

Since we can only inspect dmabuf by iterating over process FDs or the dmabuf_list, we need to add our own tracepoints to track its status in real time in production.

For example:

   binder:3016_1-3102    [006] ...1.   255.126521: dma_buf_export: exp_name=qcom,system size=12685312 ino=2738
   binder:3016_1-3102    [006] ...1.   255.126528: dma_buf_fd: exp_name=qcom,system size=12685312 ino=2738 fd=8
   binder:3016_1-3102    [006] ...1.   255.126642: dma_buf_mmap_internal: exp_name=qcom,system size=28672 ino=2739
     kworker/6:1-86      [006] ...1.   255.127194: dma_buf_put: exp_name=qcom,system size=12685312 ino=2738
    RenderThread-9293    [006] ...1.   316.618179: dma_buf_get: exp_name=qcom,system size=12771328 ino=2762 fd=176
    RenderThread-9293    [006] ...1.   316.618195: dma_buf_dynamic_attach: exp_name=qcom,system size=12771328 ino=2762 attachment:ffffff880a18dd00 is_dynamic=0 dev_name=kgsl-3d0
    RenderThread-9293    [006] ...1.   318.878220: dma_buf_detach: exp_name=qcom,system size=12771328 ino=2762 attachment:ffffff880a18dd00 is_dynamic=0 dev_name=kgsl-3d0
---
 drivers/dma-buf/dma-buf.c      |  34 +++++++-
 include/trace/events/dma_buf.h | 154 +++++++++++++++++++++++++++++++++
 2 files changed, 187 insertions(+), 1 deletion(-)
 create mode 100644 include/trace/events/dma_buf.h
drivers/dma-buf/dma-buf.c +33 -1
index 2bcf9ceca997..fc05e2114922 100644
@@ -35,6 +35,17 @@
 
 #include "dma-buf-sysfs-stats.h"
 
+#define CREATE_TRACE_POINTS
+#include <trace/events/dma_buf.h>
+
+#define DMA_BUF_TRACE(FUNC, ...)                  \
+    do {                                          \
+        if (FUNC##_enabled()) {                   \
+            guard(spinlock)(&dmabuf->name_lock); \
+            FUNC(__VA_ARGS__);                    \
+        }                                         \
+    } while (0)
+
 static inline int is_dma_buf_file(struct file *);
 
 static DEFINE_MUTEX(dmabuf_list_mutex);
@@ -220,6 +231,8 @@ static int dma_buf_mmap_internal(struct file *file, struct vm_area_struct *vma)
 	    dmabuf->size >> PAGE_SHIFT)
 		return -EINVAL;
 
+	DMA_BUF_TRACE(trace_dma_buf_mmap_internal, dmabuf);
+
 	return dmabuf->ops->mmap(dmabuf, vma);
 }
 
@@ -745,6 +758,8 @@ struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info)
 
 	__dma_buf_list_add(dmabuf);
 
+	DMA_BUF_TRACE(trace_dma_buf_export, dmabuf);
+
 	return dmabuf;
 
 err_dmabuf:
@@ -779,6 +794,8 @@ int dma_buf_fd(struct dma_buf *dmabuf, int flags)
 
 	fd_install(fd, dmabuf->file);
 
+	DMA_BUF_TRACE(trace_dma_buf_fd, dmabuf, fd);
+
 	return fd;
 }
 EXPORT_SYMBOL_NS_GPL(dma_buf_fd, "DMA_BUF");
@@ -794,6 +811,7 @@ EXPORT_SYMBOL_NS_GPL(dma_buf_fd, "DMA_BUF");
 struct dma_buf *dma_buf_get(int fd)
 {
 	struct file *file;
+	struct dma_buf *dmabuf;
 
 	file = fget(fd);
 
@@ -805,7 +823,11 @@ struct dma_buf *dma_buf_get(int fd)
 		return ERR_PTR(-EINVAL);
 	}
 
-	return file->private_data;
+	dmabuf = file->private_data;
+
+	DMA_BUF_TRACE(trace_dma_buf_get, dmabuf, fd);
+
+	return dmabuf;
 }
 EXPORT_SYMBOL_NS_GPL(dma_buf_get, "DMA_BUF");
 
@@ -825,6 +847,8 @@ void dma_buf_put(struct dma_buf *dmabuf)
 		return;
 
 	fput(dmabuf->file);
+
+	DMA_BUF_TRACE(trace_dma_buf_put, dmabuf);
 }
 EXPORT_SYMBOL_NS_GPL(dma_buf_put, "DMA_BUF");
 
@@ -979,6 +1003,9 @@ dma_buf_dynamic_attach(struct dma_buf *dmabuf, struct device *dev,
 	list_add(&attach->node, &dmabuf->attachments);
 	dma_resv_unlock(dmabuf->resv);
 
+	DMA_BUF_TRACE(trace_dma_buf_dynamic_attach, dmabuf, attach,
+		dma_buf_attachment_is_dynamic(attach), dev);
+
 	return attach;
 
 err_attach:
@@ -1023,6 +1050,9 @@ void dma_buf_detach(struct dma_buf *dmabuf, struct dma_buf_attachment *attach)
 	if (dmabuf->ops->detach)
 		dmabuf->ops->detach(dmabuf, attach);
 
+	DMA_BUF_TRACE(trace_dma_buf_detach, dmabuf, attach,
+		dma_buf_attachment_is_dynamic(attach), attach->dev);
+
 	kfree(attach);
 }
 EXPORT_SYMBOL_NS_GPL(dma_buf_detach, "DMA_BUF");
@@ -1488,6 +1518,8 @@ int dma_buf_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma,
 	vma_set_file(vma, dmabuf->file);
 	vma->vm_pgoff = pgoff;
 
+	DMA_BUF_TRACE(trace_dma_buf_mmap, dmabuf);
+
 	return dmabuf->ops->mmap(dmabuf, vma);
 }
 EXPORT_SYMBOL_NS_GPL(dma_buf_mmap, "DMA_BUF");
include/trace/events/dma_buf.h new file +154 -0

154 lines not on this page · raw message

Signature · 1 line
2.34.1
#1 lore raw

Hi, Christian König, please review this patch in your spare time, thanks.

________________________________
发件人: Xiang Gao <[email protected]>
发送时间: 2025年12月1日 19:21:48
收件人: [email protected]; [email protected]; [email protected]; [email protected]
抄送: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; 高翔 主题: [External Mail][PATCH v5] dma-buf: add some tracepoints to debug.

[外部邮件] 此邮件来源于小米公司外部,请谨慎处理。若对邮件安全性存疑,请将邮件转发给[email protected]进行反馈

From: gaoxiang17 <[email protected]>

Since we can only inspect dmabuf by iterating over process FDs or the dmabuf_list, we need to add our own tracepoints to track its status in real time in production.

For example:

   binder:3016_1-3102    [006] ...1.   255.126521: dma_buf_export: exp_name=qcom,system size=12685312 ino=2738
   binder:3016_1-3102    [006] ...1.   255.126528: dma_buf_fd: exp_name=qcom,system size=12685312 ino=2738 fd=8
   binder:3016_1-3102    [006] ...1.   255.126642: dma_buf_mmap_internal: exp_name=qcom,system size=28672 ino=2739
     kworker/6:1-86      [006] ...1.   255.127194: dma_buf_put: exp_name=qcom,system size=12685312 ino=2738
    RenderThread-9293    [006] ...1.   316.618179: dma_buf_get: exp_name=qcom,system size=12771328 ino=2762 fd=176
    RenderThread-9293    [006] ...1.   316.618195: dma_buf_dynamic_attach: exp_name=qcom,system size=12771328 ino=2762 attachment:ffffff880a18dd00 is_dynamic=0 dev_name=kgsl-3d0
    RenderThread-9293    [006] ...1.   318.878220: dma_buf_detach: exp_name=qcom,system size=12771328 ino=2762 attachment:ffffff880a18dd00 is_dynamic=0 dev_name=kgsl-3d0
---
 drivers/dma-buf/dma-buf.c      |  34 +++++++-
 include/trace/events/dma_buf.h | 154 +++++++++++++++++++++++++++++++++
 2 files changed, 187 insertions(+), 1 deletion(-)
 create mode 100644 include/trace/events/dma_buf.h
drivers/dma-buf/dma-buf.c +33 -1
index 2bcf9ceca997..fc05e2114922 100644
@@ -35,6 +35,17 @@
 
 #include "dma-buf-sysfs-stats.h"
 
+#define CREATE_TRACE_POINTS
+#include <trace/events/dma_buf.h>
+
+#define DMA_BUF_TRACE(FUNC, ...)                  \
+    do {                                          \
+        if (FUNC##_enabled()) {                   \
+            guard(spinlock)(&dmabuf->name_lock); \
+            FUNC(__VA_ARGS__);                    \
+        }                                         \
+    } while (0)
+
 static inline int is_dma_buf_file(struct file *);
 
 static DEFINE_MUTEX(dmabuf_list_mutex);
@@ -220,6 +231,8 @@ static int dma_buf_mmap_internal(struct file *file, struct vm_area_struct *vma)
            dmabuf->size >> PAGE_SHIFT)
                return -EINVAL;
 
+       DMA_BUF_TRACE(trace_dma_buf_mmap_internal, dmabuf);
+
        return dmabuf->ops->mmap(dmabuf, vma);
 }
 
@@ -745,6 +758,8 @@ struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info)
 
        __dma_buf_list_add(dmabuf);
 
+       DMA_BUF_TRACE(trace_dma_buf_export, dmabuf);
+
        return dmabuf;
 
 err_dmabuf:
@@ -779,6 +794,8 @@ int dma_buf_fd(struct dma_buf *dmabuf, int flags)
 
        fd_install(fd, dmabuf->file);
 
+       DMA_BUF_TRACE(trace_dma_buf_fd, dmabuf, fd);
+
        return fd;
 }
 EXPORT_SYMBOL_NS_GPL(dma_buf_fd, "DMA_BUF");
@@ -794,6 +811,7 @@ EXPORT_SYMBOL_NS_GPL(dma_buf_fd, "DMA_BUF");
 struct dma_buf *dma_buf_get(int fd)
 {
        struct file *file;
+       struct dma_buf *dmabuf;
 
        file = fget(fd);
 
@@ -805,7 +823,11 @@ struct dma_buf *dma_buf_get(int fd)
                return ERR_PTR(-EINVAL);
        }
 
-       return file->private_data;
+       dmabuf = file->private_data;
+
+       DMA_BUF_TRACE(trace_dma_buf_get, dmabuf, fd);
+
+       return dmabuf;
 }
 EXPORT_SYMBOL_NS_GPL(dma_buf_get, "DMA_BUF");
 
@@ -825,6 +847,8 @@ void dma_buf_put(struct dma_buf *dmabuf)
                return;
 
        fput(dmabuf->file);
+
+       DMA_BUF_TRACE(trace_dma_buf_put, dmabuf);
 }
 EXPORT_SYMBOL_NS_GPL(dma_buf_put, "DMA_BUF");
 
@@ -979,6 +1003,9 @@ dma_buf_dynamic_attach(struct dma_buf *dmabuf, struct device *dev,
        list_add(&attach->node, &dmabuf->attachments);
        dma_resv_unlock(dmabuf->resv);
 
+       DMA_BUF_TRACE(trace_dma_buf_dynamic_attach, dmabuf, attach,
+               dma_buf_attachment_is_dynamic(attach), dev);
+
        return attach;
 
 err_attach:
@@ -1023,6 +1050,9 @@ void dma_buf_detach(struct dma_buf *dmabuf, struct dma_buf_attachment *attach)
        if (dmabuf->ops->detach)
                dmabuf->ops->detach(dmabuf, attach);
 
+       DMA_BUF_TRACE(trace_dma_buf_detach, dmabuf, attach,
+               dma_buf_attachment_is_dynamic(attach), attach->dev);
+
        kfree(attach);
 }
 EXPORT_SYMBOL_NS_GPL(dma_buf_detach, "DMA_BUF");
@@ -1488,6 +1518,8 @@ int dma_buf_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma,
        vma_set_file(vma, dmabuf->file);
        vma->vm_pgoff = pgoff;
 
+       DMA_BUF_TRACE(trace_dma_buf_mmap, dmabuf);
+
        return dmabuf->ops->mmap(dmabuf, vma);
 }
 EXPORT_SYMBOL_NS_GPL(dma_buf_mmap, "DMA_BUF");
include/trace/events/dma_buf.h new file +154 -0

154 lines not on this page · raw message

--
2.34.1

maintainer
#2 lore raw
In reply to Xiang Gao

drivers/dma-buf/dma-buf.c line 40

Quoted 9 lines · On Mon, 1 Dec 2025 19:21:48 +0800 Xiang Gao <[email protected]> wrote:
drivers/dma-buf/dma-buf.c +3 -0
@@ -35,6 +35,17 @@
 
 #include "dma-buf-sysfs-stats.h"
 
+#define CREATE_TRACE_POINTS
+#include <trace/events/dma_buf.h>
+

From a tracing point of view I'm OK with this patch, but this macro really needs a comment.

-- Steve

Quoted 11 lines
drivers/dma-buf/dma-buf.c +8 -0
+#define DMA_BUF_TRACE(FUNC, ...)                  \
+    do {                                          \
+        if (FUNC##_enabled()) {                   \
+            guard(spinlock)(&dmabuf->name_lock); \
+            FUNC(__VA_ARGS__);                    \
+        }                                         \
+    } while (0)
+
 static inline int is_dma_buf_file(struct file *);
 
 static DEFINE_MUTEX(dmabuf_list_mutex);
#3 lore raw

ok, thanks.

________________________________
发件人: Steven Rostedt <[email protected]>
发送时间: 2025年12月16日 4:30:31
收件人: Xiang Gao
抄送: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; 高翔 主题: [External Mail]Re: [PATCH v5] dma-buf: add some tracepoints to debug.

[外部邮件] 此邮件来源于小米公司外部,请谨慎处理。若对邮件安全性存疑,请将邮件转发给[email protected]进行反馈

drivers/dma-buf/dma-buf.c line 40

Quoted 9 lines · On Mon, 1 Dec 2025 19:21:48 +0800 Xiang Gao <[email protected]> wrote:
drivers/dma-buf/dma-buf.c +3 -0
@@ -35,6 +35,17 @@
 
 #include "dma-buf-sysfs-stats.h"
 
+#define CREATE_TRACE_POINTS
+#include <trace/events/dma_buf.h>
+

From a tracing point of view I'm OK with this patch, but this macro really needs a comment.

-- Steve

Quoted 11 lines
drivers/dma-buf/dma-buf.c +8 -0
+#define DMA_BUF_TRACE(FUNC, ...)                  \
+    do {                                          \
+        if (FUNC##_enabled()) {                   \
+            guard(spinlock)(&dmabuf->name_lock); \
+            FUNC(__VA_ARGS__);                    \
+        }                                         \
+    } while (0)
+
 static inline int is_dma_buf_file(struct file *);
 
 static DEFINE_MUTEX(dmabuf_list_mutex);
#4 lore raw
In reply to Xiang Gao

Hi, Christian König, please help to review this patch in your spare time, thanks.

________________________________
发件人: Xiang Gao <[email protected]>
发送时间: 2025年12月1日 19:21:48
收件人: [email protected]; [email protected]; [email protected]; [email protected]
抄送: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; 高翔 主题: [External Mail][PATCH v5] dma-buf: add some tracepoints to debug.

[外部邮件] 此邮件来源于小米公司外部,请谨慎处理。若对邮件安全性存疑,请将邮件转发给[email protected]进行反馈

From: gaoxiang17 <[email protected]>

Since we can only inspect dmabuf by iterating over process FDs or the dmabuf_list, we need to add our own tracepoints to track its status in real time in production.

For example:

   binder:3016_1-3102    [006] ...1.   255.126521: dma_buf_export: exp_name=qcom,system size=12685312 ino=2738
   binder:3016_1-3102    [006] ...1.   255.126528: dma_buf_fd: exp_name=qcom,system size=12685312 ino=2738 fd=8
   binder:3016_1-3102    [006] ...1.   255.126642: dma_buf_mmap_internal: exp_name=qcom,system size=28672 ino=2739
     kworker/6:1-86      [006] ...1.   255.127194: dma_buf_put: exp_name=qcom,system size=12685312 ino=2738
    RenderThread-9293    [006] ...1.   316.618179: dma_buf_get: exp_name=qcom,system size=12771328 ino=2762 fd=176
    RenderThread-9293    [006] ...1.   316.618195: dma_buf_dynamic_attach: exp_name=qcom,system size=12771328 ino=2762 attachment:ffffff880a18dd00 is_dynamic=0 dev_name=kgsl-3d0
    RenderThread-9293    [006] ...1.   318.878220: dma_buf_detach: exp_name=qcom,system size=12771328 ino=2762 attachment:ffffff880a18dd00 is_dynamic=0 dev_name=kgsl-3d0
---
 drivers/dma-buf/dma-buf.c      |  34 +++++++-
 include/trace/events/dma_buf.h | 154 +++++++++++++++++++++++++++++++++
 2 files changed, 187 insertions(+), 1 deletion(-)
 create mode 100644 include/trace/events/dma_buf.h
drivers/dma-buf/dma-buf.c +33 -1
index 2bcf9ceca997..fc05e2114922 100644
@@ -35,6 +35,17 @@
 
 #include "dma-buf-sysfs-stats.h"
 
+#define CREATE_TRACE_POINTS
+#include <trace/events/dma_buf.h>
+
+#define DMA_BUF_TRACE(FUNC, ...)                  \
+    do {                                          \
+        if (FUNC##_enabled()) {                   \
+            guard(spinlock)(&dmabuf->name_lock); \
+            FUNC(__VA_ARGS__);                    \
+        }                                         \
+    } while (0)
+
 static inline int is_dma_buf_file(struct file *);
 
 static DEFINE_MUTEX(dmabuf_list_mutex);
@@ -220,6 +231,8 @@ static int dma_buf_mmap_internal(struct file *file, struct vm_area_struct *vma)
            dmabuf->size >> PAGE_SHIFT)
                return -EINVAL;
 
+       DMA_BUF_TRACE(trace_dma_buf_mmap_internal, dmabuf);
+
        return dmabuf->ops->mmap(dmabuf, vma);
 }
 
@@ -745,6 +758,8 @@ struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info)
 
        __dma_buf_list_add(dmabuf);
 
+       DMA_BUF_TRACE(trace_dma_buf_export, dmabuf);
+
        return dmabuf;
 
 err_dmabuf:
@@ -779,6 +794,8 @@ int dma_buf_fd(struct dma_buf *dmabuf, int flags)
 
        fd_install(fd, dmabuf->file);
 
+       DMA_BUF_TRACE(trace_dma_buf_fd, dmabuf, fd);
+
        return fd;
 }
 EXPORT_SYMBOL_NS_GPL(dma_buf_fd, "DMA_BUF");
@@ -794,6 +811,7 @@ EXPORT_SYMBOL_NS_GPL(dma_buf_fd, "DMA_BUF");
 struct dma_buf *dma_buf_get(int fd)
 {
        struct file *file;
+       struct dma_buf *dmabuf;
 
        file = fget(fd);
 
@@ -805,7 +823,11 @@ struct dma_buf *dma_buf_get(int fd)
                return ERR_PTR(-EINVAL);
        }
 
-       return file->private_data;
+       dmabuf = file->private_data;
+
+       DMA_BUF_TRACE(trace_dma_buf_get, dmabuf, fd);
+
+       return dmabuf;
 }
 EXPORT_SYMBOL_NS_GPL(dma_buf_get, "DMA_BUF");
 
@@ -825,6 +847,8 @@ void dma_buf_put(struct dma_buf *dmabuf)
                return;
 
        fput(dmabuf->file);
+
+       DMA_BUF_TRACE(trace_dma_buf_put, dmabuf);
 }
 EXPORT_SYMBOL_NS_GPL(dma_buf_put, "DMA_BUF");
 
@@ -979,6 +1003,9 @@ dma_buf_dynamic_attach(struct dma_buf *dmabuf, struct device *dev,
        list_add(&attach->node, &dmabuf->attachments);
        dma_resv_unlock(dmabuf->resv);
 
+       DMA_BUF_TRACE(trace_dma_buf_dynamic_attach, dmabuf, attach,
+               dma_buf_attachment_is_dynamic(attach), dev);
+
        return attach;
 
 err_attach:
@@ -1023,6 +1050,9 @@ void dma_buf_detach(struct dma_buf *dmabuf, struct dma_buf_attachment *attach)
        if (dmabuf->ops->detach)
                dmabuf->ops->detach(dmabuf, attach);
 
+       DMA_BUF_TRACE(trace_dma_buf_detach, dmabuf, attach,
+               dma_buf_attachment_is_dynamic(attach), attach->dev);
+
        kfree(attach);
 }
 EXPORT_SYMBOL_NS_GPL(dma_buf_detach, "DMA_BUF");
@@ -1488,6 +1518,8 @@ int dma_buf_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma,
        vma_set_file(vma, dmabuf->file);
        vma->vm_pgoff = pgoff;
 
+       DMA_BUF_TRACE(trace_dma_buf_mmap, dmabuf);
+
        return dmabuf->ops->mmap(dmabuf, vma);
 }
 EXPORT_SYMBOL_NS_GPL(dma_buf_mmap, "DMA_BUF");
include/trace/events/dma_buf.h new file +154 -0

154 lines not on this page · raw message

--
2.34.1