To print stack entries into a buffer, users of stackdepot, first get a list of stack entries using stack_depot_fetch and then print this list into a buffer using stack_trace_snprint. Provide a helper in stackdepot for this purpose. Also change above mentioned users to use this helper. [imran.f.khan@oracle.com: fix build error] Link: https://lkml.kernel.org/r/20210915175321.3472770-4-imran.f.khan@oracle.com [imran.f.khan@oracle.com: export stack_depot_snprint() to modules] Link: https://lkml.kernel.org/r/20210916133535.3592491-4-imran.f.khan@oracle.com
Unified · Split
| @@ -1668,13 +1668,10 @@ __dump_topology_ref_history(struct drm_dp_mst_topology_ref_history *history, · 1667 unmodified lines | |||
| 1668 | for (i = 0; i < history->len; i++) { | 1668 | for (i = 0; i < history->len; i++) { |
| 1669 | const struct drm_dp_mst_topology_ref_entry *entry = | 1669 | const struct drm_dp_mst_topology_ref_entry *entry = |
| 1670 | &history->entries[i]; | 1670 | &history->entries[i]; |
| 1671 | ulong *entries; | ||
| 1672 | uint nr_entries; | ||
| 1673 | u64 ts_nsec = entry->ts_nsec; | 1671 | u64 ts_nsec = entry->ts_nsec; |
| 1674 | u32 rem_nsec = do_div(ts_nsec, 1000000000); | 1672 | u32 rem_nsec = do_div(ts_nsec, 1000000000); |
| 1675 | 1673 | ||
| 1676 | nr_entries = stack_depot_fetch(entry->backtrace, &entries); | 1674 | stack_depot_snprint(entry->backtrace, buf, PAGE_SIZE, 4); |
| 1677 | stack_trace_snprint(buf, PAGE_SIZE, entries, nr_entries, 4); | ||
| 1678 | 1675 | ||
| 1679 | drm_printf(&p, " %d %ss (last at %5llu.%06u):\n%s", | 1676 | drm_printf(&p, " %d %ss (last at %5llu.%06u):\n%s", |
| 1680 | entry->count, | 1677 | entry->count, |
| @@ -118,8 +118,6 @@ static noinline void save_stack(struct drm_mm_node *node) · 117 unmodified lines | |||
| 118 | static void show_leaks(struct drm_mm *mm) | 118 | static void show_leaks(struct drm_mm *mm) |
| 119 | { | 119 | { |
| 120 | struct drm_mm_node *node; | 120 | struct drm_mm_node *node; |
| 121 | unsigned long *entries; | ||
| 122 | unsigned int nr_entries; | ||
| 123 | char *buf; | 121 | char *buf; |
| 124 | 122 | ||
| 125 | buf = kmalloc(BUFSZ, GFP_KERNEL); | 123 | buf = kmalloc(BUFSZ, GFP_KERNEL); |
| @@ -133,8 +131,7 @@ static void show_leaks(struct drm_mm *mm) · 7 unmodified lines | |||
| 133 | continue; | 131 | continue; |
| 134 | } | 132 | } |
| 135 | 133 | ||
| 136 | nr_entries = stack_depot_fetch(node->stack, &entries); | 134 | stack_depot_snprint(node->stack, buf, BUFSZ, 0); |
| 137 | stack_trace_snprint(buf, BUFSZ, entries, nr_entries, 0); | ||
| 138 | DRM_ERROR("node [%08llx + %08llx]: inserted at\n%s", | 135 | DRM_ERROR("node [%08llx + %08llx]: inserted at\n%s", |
| 139 | node->start, node->size, buf); | 136 | node->start, node->size, buf); |
| 140 | } | 137 | } |
| @@ -56,8 +56,6 @@ void i915_vma_free(struct i915_vma *vma) · 55 unmodified lines | |||
| 56 | 56 | ||
| 57 | static void vma_print_allocator(struct i915_vma *vma, const char *reason) | 57 | static void vma_print_allocator(struct i915_vma *vma, const char *reason) |
| 58 | { | 58 | { |
| 59 | unsigned long *entries; | ||
| 60 | unsigned int nr_entries; | ||
| 61 | char buf[512]; | 59 | char buf[512]; |
| 62 | 60 | ||
| 63 | if (!vma->node.stack) { | 61 | if (!vma->node.stack) { |
| @@ -66,8 +64,7 @@ static void vma_print_allocator(struct i915_vma *vma, const char *reason) · 2 unmodified lines | |||
| 66 | return; | 64 | return; |
| 67 | } | 65 | } |
| 68 | 66 | ||
| 69 | nr_entries = stack_depot_fetch(vma->node.stack, &entries); | 67 | stack_depot_snprint(vma->node.stack, buf, sizeof(buf), 0); |
| 70 | stack_trace_snprint(buf, sizeof(buf), entries, nr_entries, 0); | ||
| 71 | DRM_DEBUG_DRIVER("vma.node [%08llx + %08llx] %s: inserted at %s\n", | 68 | DRM_DEBUG_DRIVER("vma.node [%08llx + %08llx] %s: inserted at %s\n", |
| 72 | vma->node.start, vma->node.size, reason, buf); | 69 | vma->node.start, vma->node.size, reason, buf); |
| 73 | } | 70 | } |
| @@ -65,16 +65,6 @@ static noinline depot_stack_handle_t __save_depot_stack(void) · 64 unmodified lines | |||
| 65 | return stack_depot_save(entries, n, GFP_NOWAIT | __GFP_NOWARN); | 65 | return stack_depot_save(entries, n, GFP_NOWAIT | __GFP_NOWARN); |
| 66 | } | 66 | } |
| 67 | 67 | ||
| 68 | static void __print_depot_stack(depot_stack_handle_t stack, | ||
| 69 | char *buf, int sz, int indent) | ||
| 70 | { | ||
| 71 | unsigned long *entries; | ||
| 72 | unsigned int nr_entries; | ||
| 73 | |||
| 74 | nr_entries = stack_depot_fetch(stack, &entries); | ||
| 75 | stack_trace_snprint(buf, sz, entries, nr_entries, indent); | ||
| 76 | } | ||
| 77 | |||
| 78 | static void init_intel_runtime_pm_wakeref(struct intel_runtime_pm *rpm) | 68 | static void init_intel_runtime_pm_wakeref(struct intel_runtime_pm *rpm) |
| 79 | { | 69 | { |
| 80 | spin_lock_init(&rpm->debug.lock); | 70 | spin_lock_init(&rpm->debug.lock); |
| @@ -146,12 +136,12 @@ static void untrack_intel_runtime_pm_wakeref(struct intel_runtime_pm *rpm, · 65 unmodified lines | |||
| 146 | if (!buf) | 136 | if (!buf) |
| 147 | return; | 137 | return; |
| 148 | 138 | ||
| 149 | __print_depot_stack(stack, buf, PAGE_SIZE, 2); | 139 | stack_depot_snprint(stack, buf, PAGE_SIZE, 2); |
| 150 | DRM_DEBUG_DRIVER("wakeref %x from\n%s", stack, buf); | 140 | DRM_DEBUG_DRIVER("wakeref %x from\n%s", stack, buf); |
| 151 | 141 | ||
| 152 | stack = READ_ONCE(rpm->debug.last_release); | 142 | stack = READ_ONCE(rpm->debug.last_release); |
| 153 | if (stack) { | 143 | if (stack) { |
| 154 | __print_depot_stack(stack, buf, PAGE_SIZE, 2); | 144 | stack_depot_snprint(stack, buf, PAGE_SIZE, 2); |
| 155 | DRM_DEBUG_DRIVER("wakeref last released at\n%s", buf); | 145 | DRM_DEBUG_DRIVER("wakeref last released at\n%s", buf); |
| 156 | } | 146 | } |
| 157 | 147 | ||
| @@ -183,12 +173,12 @@ __print_intel_runtime_pm_wakeref(struct drm_printer *p, · 25 unmodified lines | |||
| 183 | return; | 173 | return; |
| 184 | 174 | ||
| 185 | if (dbg->last_acquire) { | 175 | if (dbg->last_acquire) { |
| 186 | __print_depot_stack(dbg->last_acquire, buf, PAGE_SIZE, 2); | 176 | stack_depot_snprint(dbg->last_acquire, buf, PAGE_SIZE, 2); |
| 187 | drm_printf(p, "Wakeref last acquired:\n%s", buf); | 177 | drm_printf(p, "Wakeref last acquired:\n%s", buf); |
| 188 | } | 178 | } |
| 189 | 179 | ||
| 190 | if (dbg->last_release) { | 180 | if (dbg->last_release) { |
| 191 | __print_depot_stack(dbg->last_release, buf, PAGE_SIZE, 2); | 181 | stack_depot_snprint(dbg->last_release, buf, PAGE_SIZE, 2); |
| 192 | drm_printf(p, "Wakeref last released:\n%s", buf); | 182 | drm_printf(p, "Wakeref last released:\n%s", buf); |
| 193 | } | 183 | } |
| 194 | 184 | ||
| @@ -203,7 +193,7 @@ __print_intel_runtime_pm_wakeref(struct drm_printer *p, · 8 unmodified lines | |||
| 203 | rep = 1; | 193 | rep = 1; |
| 204 | while (i + 1 < dbg->count && dbg->owners[i + 1] == stack) | 194 | while (i + 1 < dbg->count && dbg->owners[i + 1] == stack) |
| 205 | rep++, i++; | 195 | rep++, i++; |
| 206 | __print_depot_stack(stack, buf, PAGE_SIZE, 2); | 196 | stack_depot_snprint(stack, buf, PAGE_SIZE, 2); |
| 207 | drm_printf(p, "Wakeref x%lu taken at:\n%s", rep, buf); | 197 | drm_printf(p, "Wakeref x%lu taken at:\n%s", rep, buf); |
| 208 | } | 198 | } |
| 209 | 199 | ||
| @@ -25,6 +25,9 @@ depot_stack_handle_t stack_depot_save(unsigned long *entries, · 24 unmodified lines | |||
| 25 | unsigned int stack_depot_fetch(depot_stack_handle_t handle, | 25 | unsigned int stack_depot_fetch(depot_stack_handle_t handle, |
| 26 | unsigned long **entries); | 26 | unsigned long **entries); |
| 27 | 27 | ||
| 28 | int stack_depot_snprint(depot_stack_handle_t handle, char *buf, size_t size, | ||
| 29 | int spaces); | ||
| 30 | |||
| 28 | void stack_depot_print(depot_stack_handle_t stack); | 31 | void stack_depot_print(depot_stack_handle_t stack); |
| 29 | 32 | ||
| 30 | #ifdef CONFIG_STACKDEPOT | 33 | #ifdef CONFIG_STACKDEPOT |
| @@ -213,6 +213,31 @@ static inline struct stack_record *find_stack(struct stack_record *bucket, · 212 unmodified lines | |||
| 213 | return NULL; | 213 | return NULL; |
| 214 | } | 214 | } |
| 215 | 215 | ||
| 216 | /** | ||
| 217 | * stack_depot_snprint - print stack entries from a depot into a buffer | ||
| 218 | * | ||
| 219 | * @handle: Stack depot handle which was returned from | ||
| 220 | * stack_depot_save(). | ||
| 221 | * @buf: Pointer to the print buffer | ||
| 222 | * | ||
| 223 | * @size: Size of the print buffer | ||
| 224 | * | ||
| 225 | * @spaces: Number of leading spaces to print | ||
| 226 | * | ||
| 227 | * Return: Number of bytes printed. | ||
| 228 | */ | ||
| 229 | int stack_depot_snprint(depot_stack_handle_t handle, char *buf, size_t size, | ||
| 230 | int spaces) | ||
| 231 | { | ||
| 232 | unsigned long *entries; | ||
| 233 | unsigned int nr_entries; | ||
| 234 | |||
| 235 | nr_entries = stack_depot_fetch(handle, &entries); | ||
| 236 | return nr_entries ? stack_trace_snprint(buf, size, entries, nr_entries, | ||
| 237 | spaces) : 0; | ||
| 238 | } | ||
| 239 | EXPORT_SYMBOL_GPL(stack_depot_snprint); | ||
| 240 | |||
| 216 | /** | 241 | /** |
| 217 | * stack_depot_print - print stack entries from a depot | 242 | * stack_depot_print - print stack entries from a depot |
| 218 | * | 243 | * |
| @@ -329,8 +329,6 @@ print_page_owner(char __user *buf, size_t count, unsigned long pfn, · 328 unmodified lines | |||
| 329 | depot_stack_handle_t handle) | 329 | depot_stack_handle_t handle) |
| 330 | { | 330 | { |
| 331 | int ret, pageblock_mt, page_mt; | 331 | int ret, pageblock_mt, page_mt; |
| 332 | unsigned long *entries; | ||
| 333 | unsigned int nr_entries; | ||
| 334 | char *kbuf; | 332 | char *kbuf; |
| 335 | 333 | ||
| 336 | count = min_t(size_t, count, PAGE_SIZE); | 334 | count = min_t(size_t, count, PAGE_SIZE); |
| @@ -361,8 +359,7 @@ print_page_owner(char __user *buf, size_t count, unsigned long pfn, · 24 unmodified lines | |||
| 361 | if (ret >= count) | 359 | if (ret >= count) |
| 362 | goto err; | 360 | goto err; |
| 363 | 361 | ||
| 364 | nr_entries = stack_depot_fetch(handle, &entries); | 362 | ret += stack_depot_snprint(handle, kbuf + ret, count - ret, 0); |
| 365 | ret += stack_trace_snprint(kbuf + ret, count - ret, entries, nr_entries, 0); | ||
| 366 | if (ret >= count) | 363 | if (ret >= count) |
| 367 | goto err; | 364 | goto err; |
| 368 | 365 | ||