Re: [PATCH] drm/mm: Use debugobject to track lifetimes

2020-03-12 Thread kbuild test robot
Hi Chris,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on drm-tip/drm-tip]
[cannot apply to drm-intel/for-linux-next drm-exynos/exynos-drm-next 
tegra-drm/drm/tegra/for-next linus/master v5.6-rc5 next-20200312]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:
https://github.com/0day-ci/linux/commits/Chris-Wilson/drm-mm-Use-debugobject-to-track-lifetimes/20200313-035020
base:   git://anongit.freedesktop.org/drm/drm-tip drm-tip
config: x86_64-defconfig (attached as .config)
compiler: clang version 11.0.0 (git://gitmirror/llvm_project 
14a1b80e044aac1947c891525cf30521be0a79b7)
reproduce:
# FIXME the reproduce steps for clang is not ready yet

If you fix the issue, kindly add following tag
Reported-by: kbuild test robot 

All errors (new ones prefixed by >>):

>> drivers/gpu/drm/drm_mm.c:684:6: error: redefinition of '__drm_mm_node_init'
   void __drm_mm_node_init(struct drm_mm_node *node)
^
   include/drm/drm_mm.h:282:20: note: previous definition is here
   static inline void __drm_mm_node_init(struct drm_mm_node *node) { }
  ^
>> drivers/gpu/drm/drm_mm.c:690:6: error: redefinition of '__drm_mm_node_fini'
   void __drm_mm_node_fini(struct drm_mm_node *node)
^
   include/drm/drm_mm.h:283:20: note: previous definition is here
   static inline void __drm_mm_node_fini(struct drm_mm_node *node) { }
  ^
   2 errors generated.

vim +/__drm_mm_node_init +684 drivers/gpu/drm/drm_mm.c

   683  
 > 684  void __drm_mm_node_init(struct drm_mm_node *node)
   685  {
   686  debug_node_init(node);
   687  }
   688  EXPORT_SYMBOL(__drm_mm_node_init);
   689  
 > 690  void __drm_mm_node_fini(struct drm_mm_node *node)
   691  {
   692  debug_node_free(node);
   693  }
   694  EXPORT_SYMBOL(__drm_mm_node_fini);
   695  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-...@lists.01.org


.config.gz
Description: application/gzip
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [PATCH] drm/mm: Use debugobject to track lifetimes

2020-03-12 Thread kbuild test robot
Hi Chris,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on drm-tip/drm-tip]
[cannot apply to drm-intel/for-linux-next drm-exynos/exynos-drm-next 
tegra-drm/drm/tegra/for-next linus/master v5.6-rc5 next-20200312]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:
https://github.com/0day-ci/linux/commits/Chris-Wilson/drm-mm-Use-debugobject-to-track-lifetimes/20200313-035020
base:   git://anongit.freedesktop.org/drm/drm-tip drm-tip
config: openrisc-randconfig-a001-20200312 (attached as .config)
compiler: or1k-linux-gcc (GCC) 9.2.0
reproduce:
wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=9.2.0 make.cross ARCH=openrisc 

If you fix the issue, kindly add following tag
Reported-by: kbuild test robot 

All errors (new ones prefixed by >>):

>> drivers/gpu/drm/drm_mm.c:684:6: error: redefinition of '__drm_mm_node_init'
 684 | void __drm_mm_node_init(struct drm_mm_node *node)
 |  ^~
   In file included from drivers/gpu/drm/drm_mm.c:52:
   include/drm/drm_mm.h:282:20: note: previous definition of 
'__drm_mm_node_init' was here
 282 | static inline void __drm_mm_node_init(struct drm_mm_node *node) { }
 |^~
>> drivers/gpu/drm/drm_mm.c:690:6: error: redefinition of '__drm_mm_node_fini'
 690 | void __drm_mm_node_fini(struct drm_mm_node *node)
 |  ^~
   In file included from drivers/gpu/drm/drm_mm.c:52:
   include/drm/drm_mm.h:283:20: note: previous definition of 
'__drm_mm_node_fini' was here
 283 | static inline void __drm_mm_node_fini(struct drm_mm_node *node) { }
 |^~

vim +/__drm_mm_node_init +684 drivers/gpu/drm/drm_mm.c

   683  
 > 684  void __drm_mm_node_init(struct drm_mm_node *node)
   685  {
   686  debug_node_init(node);
   687  }
   688  EXPORT_SYMBOL(__drm_mm_node_init);
   689  
 > 690  void __drm_mm_node_fini(struct drm_mm_node *node)
   691  {
   692  debug_node_free(node);
   693  }
   694  EXPORT_SYMBOL(__drm_mm_node_fini);
   695  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-...@lists.01.org


.config.gz
Description: application/gzip
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH] drm/mm: Use debugobject to track lifetimes

2020-03-12 Thread Chris Wilson
Since drm_mm_node are intended to be embedded into larger structs, we
can use the DEBUG_OBJECTS facility to help track the lifetime of the
drm_mm_node and ensure that they are not being used after the containing
object has been freed, along with the usual verification that the
drm_mm_nodes are being used correctly.

Signed-off-by: Chris Wilson 
---
And now switch on for CI. Expect failure from unmarked drm_mm_nodes.
---
 drivers/gpu/drm/Kconfig  |  13 +++
 drivers/gpu/drm/drm_mm.c | 113 +++
 drivers/gpu/drm/i915/Kconfig.debug   |   1 +
 drivers/gpu/drm/i915/gt/gen6_ppgtt.c |   2 -
 drivers/gpu/drm/i915/i915_vma.c  |  17 +++-
 include/drm/drm_mm.h |  31 
 6 files changed, 158 insertions(+), 19 deletions(-)

diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig
index 43594978958e..33ac38be55b0 100644
--- a/drivers/gpu/drm/Kconfig
+++ b/drivers/gpu/drm/Kconfig
@@ -54,6 +54,19 @@ config DRM_DEBUG_MM
 
  If in doubt, say "N".
 
+config DRM_DEBUG_MM_OBJECTS
+   bool "Use debugobjects to track live drm_mm_nodes"
+   default n
+   depends on DRM_DEBUG_MM
+   depends on DEBUG_OBJECTS
+   help
+ Enable allocation tracking of memory manager and leak detection on
+ shutdown.
+
+ Recommended for driver developers only.
+
+ If in doubt, say "N".
+
 config DRM_DEBUG_SELFTEST
tristate "kselftests for DRM"
depends on DRM
diff --git a/drivers/gpu/drm/drm_mm.c b/drivers/gpu/drm/drm_mm.c
index bc6e208949e8..3cbee92f5832 100644
--- a/drivers/gpu/drm/drm_mm.c
+++ b/drivers/gpu/drm/drm_mm.c
@@ -116,38 +116,99 @@ static noinline void save_stack(struct drm_mm_node *node)
node->stack = stack_depot_save(entries, n, GFP_NOWAIT);
 }
 
-static void show_leaks(struct drm_mm *mm)
+static void __print_node(struct drm_mm_node *node,
+char *buf, int sz,
+const char *reason)
 {
-   struct drm_mm_node *node;
unsigned long *entries;
unsigned int nr_entries;
+
+   if (!node->stack) {
+   DRM_ERROR("node [%08llx + %08llx]: %s, unknown owner\n",
+ node->start, node->size, reason);
+   return;
+   }
+
+   nr_entries = stack_depot_fetch(node->stack, &entries);
+   stack_trace_snprint(buf, sz, entries, nr_entries, 0);
+   DRM_ERROR("node [%08llx + %08llx]: %s, inserted at\n%s",
+ node->start, node->size, reason, buf);
+}
+
+static void show_leaks(struct drm_mm *mm)
+{
+   struct drm_mm_node *node;
char *buf;
 
buf = kmalloc(BUFSZ, GFP_KERNEL);
if (!buf)
return;
 
-   list_for_each_entry(node, drm_mm_nodes(mm), node_list) {
-   if (!node->stack) {
-   DRM_ERROR("node [%08llx + %08llx]: unknown owner\n",
- node->start, node->size);
-   continue;
-   }
-
-   nr_entries = stack_depot_fetch(node->stack, &entries);
-   stack_trace_snprint(buf, BUFSZ, entries, nr_entries, 0);
-   DRM_ERROR("node [%08llx + %08llx]: inserted at\n%s",
- node->start, node->size, buf);
-   }
+   list_for_each_entry(node, drm_mm_nodes(mm), node_list)
+   __print_node(node, buf, BUFSZ, "leaked");
 
kfree(buf);
 }
 
+static void show_node(struct drm_mm_node *node, const char *reason)
+{
+   char buf[128];
+
+   __print_node(node, buf, sizeof(buf), reason);
+}
+
 #undef STACKDEPTH
 #undef BUFSZ
 #else
 static void save_stack(struct drm_mm_node *node) { }
 static void show_leaks(struct drm_mm *mm) { }
+
+static void show_node(struct drm_mm_node *node, const char *reason)
+{
+   DRM_ERROR("node [%08llx + %08llx]: %s\n",
+ node->start, node->size, reason);
+}
+#endif
+
+#ifdef CONFIG_DRM_DEBUG_MM_OBJECTS
+
+static struct debug_obj_descr drm_mm_debug_descr = {
+   .name = "drm_mm_node",
+};
+
+static inline void debug_node_init(struct drm_mm_node *node)
+{
+   debug_object_init(node, &drm_mm_debug_descr);
+}
+
+static inline void debug_node_activate(struct drm_mm_node *node)
+{
+   debug_object_activate(node, &drm_mm_debug_descr);
+}
+
+static inline void debug_node_deactivate(struct drm_mm_node *node)
+{
+   debug_object_deactivate(node, &drm_mm_debug_descr);
+}
+
+static inline void debug_node_free(struct drm_mm_node *node)
+{
+   debug_object_free(node, &drm_mm_debug_descr);
+}
+
+static inline void debug_node_assert(struct drm_mm_node *node)
+{
+   debug_object_assert_init(node, &drm_mm_debug_descr);
+}
+
+#else
+
+static inline void debug_node_init(struct drm_mm_node *node) { }
+static inline void debug_node_activate(struct drm_mm_node *node) { }
+static inline void debug_node_deactivate(struct drm_mm_node *node) { }
+static inline void debug_node_free(struct drm_mm_node *node) { }
+stat

[PATCH] drm/mm: Use debugobject to track lifetimes

2020-03-12 Thread Chris Wilson
Since drm_mm_node are intended to be embedded into larger structs, we
can use the DEBUG_OBJECTS facility to help track the lifetime of the
drm_mm_node and ensure that they are not being used after the containing
object has been freed, along with the usual verification that the
drm_mm_nodes are being used correctly.

Signed-off-by: Chris Wilson 
---
 drivers/gpu/drm/Kconfig  | 13 +++
 drivers/gpu/drm/drm_mm.c | 55 
 drivers/gpu/drm/i915/gt/gen6_ppgtt.c |  2 -
 drivers/gpu/drm/i915/i915_vma.c  | 17 +++--
 include/drm/drm_mm.h | 31 
 5 files changed, 113 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig
index 43594978958e..33ac38be55b0 100644
--- a/drivers/gpu/drm/Kconfig
+++ b/drivers/gpu/drm/Kconfig
@@ -54,6 +54,19 @@ config DRM_DEBUG_MM
 
  If in doubt, say "N".
 
+config DRM_DEBUG_MM_OBJECTS
+   bool "Use debugobjects to track live drm_mm_nodes"
+   default n
+   depends on DRM_DEBUG_MM
+   depends on DEBUG_OBJECTS
+   help
+ Enable allocation tracking of memory manager and leak detection on
+ shutdown.
+
+ Recommended for driver developers only.
+
+ If in doubt, say "N".
+
 config DRM_DEBUG_SELFTEST
tristate "kselftests for DRM"
depends on DRM
diff --git a/drivers/gpu/drm/drm_mm.c b/drivers/gpu/drm/drm_mm.c
index bc6e208949e8..073b417bdd7a 100644
--- a/drivers/gpu/drm/drm_mm.c
+++ b/drivers/gpu/drm/drm_mm.c
@@ -150,6 +150,41 @@ static void save_stack(struct drm_mm_node *node) { }
 static void show_leaks(struct drm_mm *mm) { }
 #endif
 
+#ifdef CONFIG_DRM_DEBUG_MM_OBJECTS
+
+static struct debug_obj_descr drm_mm_debug_descr = {
+   .name = "drm_mm_node",
+};
+
+static inline void debug_node_init(struct drm_mm_node *node)
+{
+   debug_object_init(node, &drm_mm_debug_descr);
+}
+
+static inline void debug_node_activate(struct drm_mm_node *node)
+{
+   debug_object_activate(node, &drm_mm_debug_descr);
+}
+
+static inline void debug_node_deactivate(struct drm_mm_node *node)
+{
+   debug_object_deactivate(node, &drm_mm_debug_descr);
+}
+
+static inline void debug_node_free(struct drm_mm_node *node)
+{
+   debug_object_free(node, &drm_mm_debug_descr);
+}
+
+#else
+
+static inline void debug_node_init(struct drm_mm_node *node) { }
+static inline void debug_node_activate(struct drm_mm_node *node) { }
+static inline void debug_node_deactivate(struct drm_mm_node *node) { }
+static inline void debug_node_free(struct drm_mm_node *node) { }
+
+#endif
+
 #define START(node) ((node)->start)
 #define LAST(node)  ((node)->start + (node)->size - 1)
 
@@ -428,6 +463,8 @@ int drm_mm_reserve_node(struct drm_mm *mm, struct 
drm_mm_node *node)
if (adj_start > node->start || adj_end < end)
return -ENOSPC;
 
+   debug_node_activate(node);
+
node->mm = mm;
 
__set_bit(DRM_MM_NODE_ALLOCATED_BIT, &node->flags);
@@ -543,6 +580,8 @@ int drm_mm_insert_node_in_range(struct drm_mm * const mm,
}
}
 
+   debug_node_activate(node);
+
node->mm = mm;
node->size = size;
node->start = adj_start;
@@ -587,6 +626,7 @@ void drm_mm_remove_node(struct drm_mm_node *node)
 
DRM_MM_BUG_ON(!drm_mm_node_allocated(node));
DRM_MM_BUG_ON(drm_mm_node_scanned_block(node));
+   debug_node_deactivate(node);
 
prev_node = list_prev_entry(node, node_list);
 
@@ -618,6 +658,8 @@ void drm_mm_replace_node(struct drm_mm_node *old, struct 
drm_mm_node *new)
struct drm_mm *mm = old->mm;
 
DRM_MM_BUG_ON(!drm_mm_node_allocated(old));
+   debug_node_deactivate(old);
+   debug_node_activate(new);
 
*new = *old;
 
@@ -639,6 +681,19 @@ void drm_mm_replace_node(struct drm_mm_node *old, struct 
drm_mm_node *new)
 }
 EXPORT_SYMBOL(drm_mm_replace_node);
 
+void __drm_mm_node_init(struct drm_mm_node *node)
+{
+   debug_node_init(node);
+}
+EXPORT_SYMBOL(__drm_mm_node_init);
+
+void __drm_mm_node_fini(struct drm_mm_node *node)
+{
+   DRM_MM_BUG_ON(drm_mm_node_allocated(node));
+   debug_node_free(node);
+}
+EXPORT_SYMBOL(__drm_mm_node_fini);
+
 /**
  * DOC: lru scan roster
  *
diff --git a/drivers/gpu/drm/i915/gt/gen6_ppgtt.c 
b/drivers/gpu/drm/i915/gt/gen6_ppgtt.c
index f4fec7eb4064..0c34d4dd6458 100644
--- a/drivers/gpu/drm/i915/gt/gen6_ppgtt.c
+++ b/drivers/gpu/drm/i915/gt/gen6_ppgtt.c
@@ -359,8 +359,6 @@ static struct i915_vma *pd_vma_create(struct gen6_ppgtt 
*ppgtt, int size)
 
i915_active_init(&vma->active, NULL, NULL);
 
-   kref_init(&vma->ref);
-   mutex_init(&vma->pages_mutex);
vma->vm = i915_vm_get(&ggtt->vm);
vma->ops = &pd_vma_ops;
vma->private = ppgtt;
diff --git a/drivers/gpu/drm/i915/i915_vma.c b/drivers/gpu/drm/i915/i915_vma.c
index 5b3efb43a8ef..64140d51ae2c 100644
--- a/drivers/gp

[PATCH] drm/mm: Use debugobject to track lifetimes

2020-03-12 Thread Chris Wilson
Since drm_mm_node are intended to be embedded into larger structs, we
can use the DEBUG_OBJECTS facility to help track the lifetime of the
drm_mm_node and ensure that they are not being used after the containing
object has been freed, along with the usual verification that the
drm_mm_nodes are being used correctly.

Signed-off-by: Chris Wilson 
---
 drivers/gpu/drm/Kconfig  | 13 +++
 drivers/gpu/drm/drm_mm.c | 54 
 drivers/gpu/drm/i915/gt/gen6_ppgtt.c |  2 --
 drivers/gpu/drm/i915/i915_vma.c  | 17 +++--
 include/drm/drm_mm.h | 19 ++
 5 files changed, 100 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig
index 43594978958e..33ac38be55b0 100644
--- a/drivers/gpu/drm/Kconfig
+++ b/drivers/gpu/drm/Kconfig
@@ -54,6 +54,19 @@ config DRM_DEBUG_MM
 
  If in doubt, say "N".
 
+config DRM_DEBUG_MM_OBJECTS
+   bool "Use debugobjects to track live drm_mm_nodes"
+   default n
+   depends on DRM_DEBUG_MM
+   depends on DEBUG_OBJECTS
+   help
+ Enable allocation tracking of memory manager and leak detection on
+ shutdown.
+
+ Recommended for driver developers only.
+
+ If in doubt, say "N".
+
 config DRM_DEBUG_SELFTEST
tristate "kselftests for DRM"
depends on DRM
diff --git a/drivers/gpu/drm/drm_mm.c b/drivers/gpu/drm/drm_mm.c
index bc6e208949e8..c149c54d8ede 100644
--- a/drivers/gpu/drm/drm_mm.c
+++ b/drivers/gpu/drm/drm_mm.c
@@ -150,6 +150,41 @@ static void save_stack(struct drm_mm_node *node) { }
 static void show_leaks(struct drm_mm *mm) { }
 #endif
 
+#ifdef CONFIG_DRM_DEBUG_MM_OBJECTS
+
+static struct debug_obj_descr drm_mm_debug_descr = {
+   .name = "drm_mm_node",
+};
+
+static inline void debug_node_init(struct drm_mm_node *node)
+{
+   debug_object_init(node, &drm_mm_debug_descr);
+}
+
+static inline void debug_node_activate(struct drm_mm_node *node)
+{
+   debug_object_activate(node, &drm_mm_debug_descr);
+}
+
+static inline void debug_node_deactivate(struct drm_mm_node *node)
+{
+   debug_object_deactivate(node, &drm_mm_debug_descr);
+}
+
+static inline void debug_node_free(struct drm_mm_node *node)
+{
+   debug_object_free(node, &drm_mm_debug_descr);
+}
+
+#else
+
+static inline void debug_node_init(struct drm_mm_node *node) { }
+static inline void debug_node_activate(struct drm_mm_node *node) { }
+static inline void debug_node_deactivate(struct drm_mm_node *node) { }
+static inline void debug_node_free(struct drm_mm_node *node) { }
+
+#endif
+
 #define START(node) ((node)->start)
 #define LAST(node)  ((node)->start + (node)->size - 1)
 
@@ -428,6 +463,8 @@ int drm_mm_reserve_node(struct drm_mm *mm, struct 
drm_mm_node *node)
if (adj_start > node->start || adj_end < end)
return -ENOSPC;
 
+   debug_node_activate(node);
+
node->mm = mm;
 
__set_bit(DRM_MM_NODE_ALLOCATED_BIT, &node->flags);
@@ -543,6 +580,8 @@ int drm_mm_insert_node_in_range(struct drm_mm * const mm,
}
}
 
+   debug_node_activate(node);
+
node->mm = mm;
node->size = size;
node->start = adj_start;
@@ -587,6 +626,7 @@ void drm_mm_remove_node(struct drm_mm_node *node)
 
DRM_MM_BUG_ON(!drm_mm_node_allocated(node));
DRM_MM_BUG_ON(drm_mm_node_scanned_block(node));
+   debug_node_deactivate(node);
 
prev_node = list_prev_entry(node, node_list);
 
@@ -618,6 +658,8 @@ void drm_mm_replace_node(struct drm_mm_node *old, struct 
drm_mm_node *new)
struct drm_mm *mm = old->mm;
 
DRM_MM_BUG_ON(!drm_mm_node_allocated(old));
+   debug_node_deactivate(old);
+   debug_node_activate(new);
 
*new = *old;
 
@@ -639,6 +681,18 @@ void drm_mm_replace_node(struct drm_mm_node *old, struct 
drm_mm_node *new)
 }
 EXPORT_SYMBOL(drm_mm_replace_node);
 
+void __drm_mm_node_init(struct drm_mm_node *node)
+{
+   debug_node_init(node);
+}
+EXPORT_SYMBOL(__drm_mm_node_init);
+
+void __drm_mm_node_fini(struct drm_mm_node *node)
+{
+   debug_node_free(node);
+}
+EXPORT_SYMBOL(__drm_mm_node_fini);
+
 /**
  * DOC: lru scan roster
  *
diff --git a/drivers/gpu/drm/i915/gt/gen6_ppgtt.c 
b/drivers/gpu/drm/i915/gt/gen6_ppgtt.c
index f4fec7eb4064..0c34d4dd6458 100644
--- a/drivers/gpu/drm/i915/gt/gen6_ppgtt.c
+++ b/drivers/gpu/drm/i915/gt/gen6_ppgtt.c
@@ -359,8 +359,6 @@ static struct i915_vma *pd_vma_create(struct gen6_ppgtt 
*ppgtt, int size)
 
i915_active_init(&vma->active, NULL, NULL);
 
-   kref_init(&vma->ref);
-   mutex_init(&vma->pages_mutex);
vma->vm = i915_vm_get(&ggtt->vm);
vma->ops = &pd_vma_ops;
vma->private = ppgtt;
diff --git a/drivers/gpu/drm/i915/i915_vma.c b/drivers/gpu/drm/i915/i915_vma.c
index 5b3efb43a8ef..64140d51ae2c 100644
--- a/drivers/gpu/drm/i915/i915_vma.c
+++ b/drivers/gpu/drm/i915/i915_vma