Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

lib/stackdepot: move documentation comments to stackdepot.h

Move all interface- and usage-related documentation comments to
include/linux/stackdepot.h.

It makes sense to have them in the header where they are available to
the interface users.

[akpm@linux-foundation.org: grammar fix, per Alexander]
Link: https://lkml.kernel.org/r/fbfee41495b306dd8881f9b1c1b80999c885e82f.1676063693.git.andreyknvl@google.com
Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
Reviewed-by: Alexander Potapenko <glider@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Andrey Konovalov and committed by
Andrew Morton
0621d160 b232b999

+87 -87
+87
include/linux/stackdepot.h
··· 2 2 /* 3 3 * Stack depot - a stack trace storage that avoids duplication. 4 4 * 5 + * Stack depot is intended to be used by subsystems that need to store and 6 + * later retrieve many potentially duplicated stack traces without wasting 7 + * memory. 8 + * 9 + * For example, KASAN needs to save allocation and free stack traces for each 10 + * object. Storing two stack traces per object requires a lot of memory (e.g. 11 + * SLUB_DEBUG needs 256 bytes per object for that). Since allocation and free 12 + * stack traces often repeat, using stack depot allows to save about 100x space. 13 + * 14 + * Stack traces are never removed from the stack depot. 15 + * 5 16 * Author: Alexander Potapenko <glider@google.com> 6 17 * Copyright (C) 2016 Google, Inc. 7 18 * ··· 68 57 static inline int stack_depot_early_init(void) { return 0; } 69 58 #endif 70 59 60 + /** 61 + * __stack_depot_save - Save a stack trace to stack depot 62 + * 63 + * @entries: Pointer to the stack trace 64 + * @nr_entries: Number of frames in the stack 65 + * @alloc_flags: Allocation GFP flags 66 + * @can_alloc: Allocate stack pools (increased chance of failure if false) 67 + * 68 + * Saves a stack trace from @entries array of size @nr_entries. If @can_alloc is 69 + * %true, stack depot can replenish the stack pools in case no space is left 70 + * (allocates using GFP flags of @alloc_flags). If @can_alloc is %false, avoids 71 + * any allocations and fails if no space is left to store the stack trace. 72 + * 73 + * If the provided stack trace comes from the interrupt context, only the part 74 + * up to the interrupt entry is saved. 75 + * 76 + * Context: Any context, but setting @can_alloc to %false is required if 77 + * alloc_pages() cannot be used from the current context. Currently 78 + * this is the case for contexts where neither %GFP_ATOMIC nor 79 + * %GFP_NOWAIT can be used (NMI, raw_spin_lock). 80 + * 81 + * Return: Handle of the stack struct stored in depot, 0 on failure 82 + */ 71 83 depot_stack_handle_t __stack_depot_save(unsigned long *entries, 72 84 unsigned int nr_entries, 73 85 gfp_t gfp_flags, bool can_alloc); 74 86 87 + /** 88 + * stack_depot_save - Save a stack trace to stack depot 89 + * 90 + * @entries: Pointer to the stack trace 91 + * @nr_entries: Number of frames in the stack 92 + * @alloc_flags: Allocation GFP flags 93 + * 94 + * Context: Contexts where allocations via alloc_pages() are allowed. 95 + * See __stack_depot_save() for more details. 96 + * 97 + * Return: Handle of the stack trace stored in depot, 0 on failure 98 + */ 75 99 depot_stack_handle_t stack_depot_save(unsigned long *entries, 76 100 unsigned int nr_entries, gfp_t gfp_flags); 77 101 102 + /** 103 + * stack_depot_fetch - Fetch a stack trace from stack depot 104 + * 105 + * @handle: Stack depot handle returned from stack_depot_save() 106 + * @entries: Pointer to store the address of the stack trace 107 + * 108 + * Return: Number of frames for the fetched stack 109 + */ 78 110 unsigned int stack_depot_fetch(depot_stack_handle_t handle, 79 111 unsigned long **entries); 80 112 113 + /** 114 + * stack_depot_print - Print a stack trace from stack depot 115 + * 116 + * @stack: Stack depot handle returned from stack_depot_save() 117 + */ 81 118 void stack_depot_print(depot_stack_handle_t stack); 82 119 120 + /** 121 + * stack_depot_snprint - Print a stack trace from stack depot into a buffer 122 + * 123 + * @handle: Stack depot handle returned from stack_depot_save() 124 + * @buf: Pointer to the print buffer 125 + * @size: Size of the print buffer 126 + * @spaces: Number of leading spaces to print 127 + * 128 + * Return: Number of bytes printed 129 + */ 83 130 int stack_depot_snprint(depot_stack_handle_t handle, char *buf, size_t size, 84 131 int spaces); 85 132 133 + /** 134 + * stack_depot_set_extra_bits - Set extra bits in a stack depot handle 135 + * 136 + * @handle: Stack depot handle returned from stack_depot_save() 137 + * @extra_bits: Value to set the extra bits 138 + * 139 + * Return: Stack depot handle with extra bits set 140 + * 141 + * Stack depot handles have a few unused bits, which can be used for storing 142 + * user-specific information. These bits are transparent to the stack depot. 143 + */ 86 144 depot_stack_handle_t __must_check stack_depot_set_extra_bits( 87 145 depot_stack_handle_t handle, unsigned int extra_bits); 88 146 147 + /** 148 + * stack_depot_get_extra_bits - Retrieve extra bits from a stack depot handle 149 + * 150 + * @handle: Stack depot handle with extra bits saved 151 + * 152 + * Return: Extra bits retrieved from the stack depot handle 153 + */ 89 154 unsigned int stack_depot_get_extra_bits(depot_stack_handle_t handle); 90 155 91 156 #endif
-87
lib/stackdepot.c
··· 2 2 /* 3 3 * Stack depot - a stack trace storage that avoids duplication. 4 4 * 5 - * Stack depot is intended to be used by subsystems that need to store and 6 - * later retrieve many potentially duplicated stack traces without wasting 7 - * memory. 8 - * 9 - * For example, KASAN needs to save allocation and free stack traces for each 10 - * object. Storing two stack traces per object requires a lot of memory (e.g. 11 - * SLUB_DEBUG needs 256 bytes per object for that). Since allocation and free 12 - * stack traces often repeat, using stack depot allows to save about 100x space. 13 - * 14 5 * Internally, stack depot maintains a hash table of unique stacktraces. The 15 6 * stack traces themselves are stored contiguously one after another in a set 16 7 * of separate page allocations. 17 - * 18 - * Stack traces are never removed from stack depot. 19 8 * 20 9 * Author: Alexander Potapenko <glider@google.com> 21 10 * Copyright (C) 2016 Google, Inc. ··· 349 360 return NULL; 350 361 } 351 362 352 - /** 353 - * __stack_depot_save - Save a stack trace to stack depot 354 - * 355 - * @entries: Pointer to the stack trace 356 - * @nr_entries: Number of frames in the stack 357 - * @alloc_flags: Allocation GFP flags 358 - * @can_alloc: Allocate stack pools (increased chance of failure if false) 359 - * 360 - * Saves a stack trace from @entries array of size @nr_entries. If @can_alloc is 361 - * %true, stack depot can replenish the stack pools in case no space is left 362 - * (allocates using GFP flags of @alloc_flags). If @can_alloc is %false, avoids 363 - * any allocations and fails if no space is left to store the stack trace. 364 - * 365 - * If the provided stack trace comes from the interrupt context, only the part 366 - * up to the interrupt entry is saved. 367 - * 368 - * Context: Any context, but setting @can_alloc to %false is required if 369 - * alloc_pages() cannot be used from the current context. Currently 370 - * this is the case for contexts where neither %GFP_ATOMIC nor 371 - * %GFP_NOWAIT can be used (NMI, raw_spin_lock). 372 - * 373 - * Return: Handle of the stack struct stored in depot, 0 on failure 374 - */ 375 363 depot_stack_handle_t __stack_depot_save(unsigned long *entries, 376 364 unsigned int nr_entries, 377 365 gfp_t alloc_flags, bool can_alloc) ··· 443 477 } 444 478 EXPORT_SYMBOL_GPL(__stack_depot_save); 445 479 446 - /** 447 - * stack_depot_save - Save a stack trace to stack depot 448 - * 449 - * @entries: Pointer to the stack trace 450 - * @nr_entries: Number of frames in the stack 451 - * @alloc_flags: Allocation GFP flags 452 - * 453 - * Context: Contexts where allocations via alloc_pages() are allowed. 454 - * See __stack_depot_save() for more details. 455 - * 456 - * Return: Handle of the stack trace stored in depot, 0 on failure 457 - */ 458 480 depot_stack_handle_t stack_depot_save(unsigned long *entries, 459 481 unsigned int nr_entries, 460 482 gfp_t alloc_flags) ··· 451 497 } 452 498 EXPORT_SYMBOL_GPL(stack_depot_save); 453 499 454 - /** 455 - * stack_depot_fetch - Fetch a stack trace from stack depot 456 - * 457 - * @handle: Stack depot handle returned from stack_depot_save() 458 - * @entries: Pointer to store the address of the stack trace 459 - * 460 - * Return: Number of frames for the fetched stack 461 - */ 462 500 unsigned int stack_depot_fetch(depot_stack_handle_t handle, 463 501 unsigned long **entries) 464 502 { ··· 483 537 } 484 538 EXPORT_SYMBOL_GPL(stack_depot_fetch); 485 539 486 - /** 487 - * stack_depot_print - Print a stack trace from stack depot 488 - * 489 - * @stack: Stack depot handle returned from stack_depot_save() 490 - */ 491 540 void stack_depot_print(depot_stack_handle_t stack) 492 541 { 493 542 unsigned long *entries; ··· 494 553 } 495 554 EXPORT_SYMBOL_GPL(stack_depot_print); 496 555 497 - /** 498 - * stack_depot_snprint - Print a stack trace from stack depot into a buffer 499 - * 500 - * @handle: Stack depot handle returned from stack_depot_save() 501 - * @buf: Pointer to the print buffer 502 - * @size: Size of the print buffer 503 - * @spaces: Number of leading spaces to print 504 - * 505 - * Return: Number of bytes printed 506 - */ 507 556 int stack_depot_snprint(depot_stack_handle_t handle, char *buf, size_t size, 508 557 int spaces) 509 558 { ··· 506 575 } 507 576 EXPORT_SYMBOL_GPL(stack_depot_snprint); 508 577 509 - /** 510 - * stack_depot_set_extra_bits - Set extra bits in a stack depot handle 511 - * 512 - * @handle: Stack depot handle returned from stack_depot_save() 513 - * @extra_bits: Value to set the extra bits 514 - * 515 - * Return: Stack depot handle with extra bits set 516 - * 517 - * Stack depot handles have a few unused bits, which can be used for storing 518 - * user-specific information. These bits are transparent to the stack depot. 519 - */ 520 578 depot_stack_handle_t __must_check stack_depot_set_extra_bits( 521 579 depot_stack_handle_t handle, unsigned int extra_bits) 522 580 { ··· 520 600 } 521 601 EXPORT_SYMBOL(stack_depot_set_extra_bits); 522 602 523 - /** 524 - * stack_depot_get_extra_bits - Retrieve extra bits from a stack depot handle 525 - * 526 - * @handle: Stack depot handle with extra bits saved 527 - * 528 - * Return: Extra bits retrieved from the stack depot handle 529 - */ 530 603 unsigned int stack_depot_get_extra_bits(depot_stack_handle_t handle) 531 604 { 532 605 union handle_parts parts = { .handle = handle };