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 | 1668 | for (i = 0; i < history->len; i++) { |
| 1669 | 1669 | const struct drm_dp_mst_topology_ref_entry *entry = |
| 1670 | 1670 | &history->entries[i]; |
| 1671 | − ulong *entries; | |
| 1672 | − uint nr_entries; | |
| 1673 | 1671 | u64 ts_nsec = entry->ts_nsec; |
| 1674 | 1672 | u32 rem_nsec = do_div(ts_nsec, 1000000000); |
| 1675 | 1673 | |
| 1676 | − nr_entries = stack_depot_fetch(entry->backtrace, &entries); | |
| 1677 | − stack_trace_snprint(buf, PAGE_SIZE, entries, nr_entries, 4); | |
| 1674 | + stack_depot_snprint(entry->backtrace, buf, PAGE_SIZE, 4); | |
| 1678 | 1675 | |
| 1679 | 1676 | drm_printf(&p, " %d %ss (last at %5llu.%06u):\n%s", |
| 1680 | 1677 | entry->count, |
| @@ -118,8 +118,6 @@ static noinline void save_stack(struct drm_mm_node *node) · 117 unmodified lines | ||
| 118 | 118 | static void show_leaks(struct drm_mm *mm) |
| 119 | 119 | { |
| 120 | 120 | struct drm_mm_node *node; |
| 121 | − unsigned long *entries; | |
| 122 | − unsigned int nr_entries; | |
| 123 | 121 | char *buf; |
| 124 | 122 | |
| 125 | 123 | buf = kmalloc(BUFSZ, GFP_KERNEL); |
| @@ -133,8 +131,7 @@ static void show_leaks(struct drm_mm *mm) · 7 unmodified lines | ||
| 133 | 131 | continue; |
| 134 | 132 | } |
| 135 | 133 | |
| 136 | − nr_entries = stack_depot_fetch(node->stack, &entries); | |
| 137 | − stack_trace_snprint(buf, BUFSZ, entries, nr_entries, 0); | |
| 134 | + stack_depot_snprint(node->stack, buf, BUFSZ, 0); | |
| 138 | 135 | DRM_ERROR("node [%08llx + %08llx]: inserted at\n%s", |
| 139 | 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 | 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 | 59 | char buf[512]; |
| 62 | 60 | |
| 63 | 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 | 64 | return; |
| 67 | 65 | } |
| 68 | 66 | |
| 69 | − nr_entries = stack_depot_fetch(vma->node.stack, &entries); | |
| 70 | − stack_trace_snprint(buf, sizeof(buf), entries, nr_entries, 0); | |
| 67 | + stack_depot_snprint(vma->node.stack, buf, sizeof(buf), 0); | |
| 71 | 68 | DRM_DEBUG_DRIVER("vma.node [%08llx + %08llx] %s: inserted at %s\n", |
| 72 | 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 | 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 | 68 | static void init_intel_runtime_pm_wakeref(struct intel_runtime_pm *rpm) |
| 79 | 69 | { |
| 80 | 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 | 136 | if (!buf) |
| 147 | 137 | return; |
| 148 | 138 | |
| 149 | − __print_depot_stack(stack, buf, PAGE_SIZE, 2); | |
| 139 | + stack_depot_snprint(stack, buf, PAGE_SIZE, 2); | |
| 150 | 140 | DRM_DEBUG_DRIVER("wakeref %x from\n%s", stack, buf); |
| 151 | 141 | |
| 152 | 142 | stack = READ_ONCE(rpm->debug.last_release); |
| 153 | 143 | if (stack) { |
| 154 | − __print_depot_stack(stack, buf, PAGE_SIZE, 2); | |
| 144 | + stack_depot_snprint(stack, buf, PAGE_SIZE, 2); | |
| 155 | 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 | 173 | return; |
| 184 | 174 | |
| 185 | 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 | 177 | drm_printf(p, "Wakeref last acquired:\n%s", buf); |
| 188 | 178 | } |
| 189 | 179 | |
| 190 | 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 | 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 | 193 | rep = 1; |
| 204 | 194 | while (i + 1 < dbg->count && dbg->owners[i + 1] == stack) |
| 205 | 195 | rep++, i++; |
| 206 | − __print_depot_stack(stack, buf, PAGE_SIZE, 2); | |
| 196 | + stack_depot_snprint(stack, buf, PAGE_SIZE, 2); | |
| 207 | 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 | 25 | unsigned int stack_depot_fetch(depot_stack_handle_t handle, |
| 26 | 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 | 31 | void stack_depot_print(depot_stack_handle_t stack); |
| 29 | 32 | |
| 30 | 33 | #ifdef CONFIG_STACKDEPOT |
| @@ -213,6 +213,31 @@ static inline struct stack_record *find_stack(struct stack_record *bucket, · 212 unmodified lines | ||
| 213 | 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 | 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 | 329 | depot_stack_handle_t handle) |
| 330 | 330 | { |
| 331 | 331 | int ret, pageblock_mt, page_mt; |
| 332 | − unsigned long *entries; | |
| 333 | − unsigned int nr_entries; | |
| 334 | 332 | char *kbuf; |
| 335 | 333 | |
| 336 | 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 | 359 | if (ret >= count) |
| 362 | 360 | goto err; |
| 363 | 361 | |
| 364 | − nr_entries = stack_depot_fetch(handle, &entries); | |
| 365 | − ret += stack_trace_snprint(kbuf + ret, count - ret, entries, nr_entries, 0); | |
| 362 | + ret += stack_depot_snprint(handle, kbuf + ret, count - ret, 0); | |
| 366 | 363 | if (ret >= count) |
| 367 | 364 | goto err; |
| 368 | 365 | |