kdb: Get rid of custom debug heap allocator
PATCH v2 1/1 kdb: Get rid of custom debug heap allocator
Currently the only user for debug heap is kdbnearsym() which can be modified to rather use statically allocated buffer for symbol name as per it's current usage. So do that and hence remove custom debug heap allocator.
Note that this change puts a restriction on kdbnearsym() callers to carefully use shared namebuf such that a caller should consume the symbol returned immediately prior to another call to fetch a different symbol.
This change has been tested using kgdbtest on arm64 which doesn't show any regressions.
---
Changes in v2:
- Use single static buffer for symbol name in kdbnearsym() instead of per caller buffers allocated on stack.
kernel/debug/kdb/kdb_debugger.c | 1 - kernel/debug/kdb/kdb_private.h | 5 - kernel/debug/kdb/kdb_support.c | 318 ++------------------------------ 3 files changed, 15 insertions(+), 309 deletions(-)
kernel/debug/kdb/kdb_debugger.c +0 -1
@@ -140,7 +140,6 @@ int kdb_stub(struct kgdb_state *ks)*/ kdb_common_deinit_state ();KDB_STATE_CLEAR (PAGER ); -kdbnearsym_cleanup ();if (error ==KDB_CMD_KGDB ) {if (KDB_STATE (DOING_KGDB ))KDB_STATE_CLEAR (DOING_KGDB );
kernel/debug/kdb/kdb_private.h +0 -5
@@ -109,7 +109,6 @@ extern int kdbgetaddrarg(int, const char **, int*, unsigned long *, long *, char **);extern int kdbgetsymval (const char *,kdb_symtab_t *);extern int kdbnearsym (unsigned long ,kdb_symtab_t *); -extern void kdbnearsym_cleanup (void );extern char *kdb_strdup (const char *str,gfp_t type);extern void kdb_symbol_print (unsigned long ,const kdb_symtab_t *,unsigned int );
@@ -233,10 +232,6 @@ extern struct task_struct *kdb_curr_task(int);#define GFP_KDB (in_dbg_master() ? GFP_ATOMIC : GFP_KERNEL) -extern void *debug_kmalloc (size_t size,gfp_t flags); -extern void debug_kfree (void *); -extern void debug_kusage (void ); -extern struct task_struct *kdb_current_task;extern struct pt_regs *kdb_current_regs;
kernel/debug/kdb/kdb_support.c +15 -303
367 lines not on this page · raw message
Signature · 1 line
2.25.1
Quoted 9 lines · Sumit Garg
Currently the only user for debug heap is
kdbnearsym()which can be modified to rather use statically allocated buffer for symbol name as per it's current usage. So do that and hence remove custom debug heap allocator.Note that this change puts a restriction on
kdbnearsym()callers to carefully use shared namebuf such that a caller should consume the symbol returned immediately prior to another call to fetch a different symbol.
Quoted 5 lines
This change has been tested using kgdbtest on arm64 which doesn't show any regressions.
Suggested-by Daniel Thompson <[email protected]>Signed-off-by Sumit Garg <[email protected]>
I'm afraid the passage of time (mostly due to my dropping the ball) means this no longer applies cleanly to latest kernel and git am -3way tells me that "sha1 information is lacking or useless". Please can you rebase this on v5.13-rc4 and repost?
Also...
Quoted 28 lines
kernel/debug/kdb/kdb_private.h +0
-0kernel/debug/kdb/kdb_support.c +4
-12@@ -57,35 +57,26 @@ int kdbgetsymval(const char *symname, kdb_symtab_t *symtab) }EXPORT_SYMBOL (kdbgetsymval); -static char *kdb_name_table[100 ];/* arbitrary size */ -/* -* kdbnearsym - Return the name of the symbol with the nearest address -* less than 'addr'. +* kdbnearsym() - Return the name of the symbol with the nearest address +* less than @addr. +* @addr: Address to check for near symbol +* @symtab: Structure to receive results * -* Parameters: -* addr Address to check for symbol near -* symtab Structure to receive results -* Returns: -* 0 No sections contain this address, symtab zero filled -* 1 Address mapped to module/symbol/section, data in symtab -* Remarks: -* 2.6 kallsyms has a "feature" where it unpacks the name into a
kernel/debug/kdb/kdb_support.c int kdbgetsymval(const char *symname, kdb_symtab_t *symtab) · line 68
Quoted 10 lines
kernel/debug/kdb/kdb_support.c +3
-7-* string. If that string is reused before the caller expects it -* then the caller sees its string change without warning. To -* avoid cluttering up the main kdb code with lots of kdb_strdup, -* tests and kfree calls, kdbnearsym maintains an LRU list of the -* last few unique strings. The list is sized large enough to -* hold active strings, no kdb caller of kdbnearsym makes more -* than ~20 later calls before using a saved value. +* Note here that only single statically allocated namebuf is used for every +* symbol, so the caller should consume it immediately prior to another call +* to fetch a different symbol.
This still looks like it will confused experienced kernel devs who aren't aware of kdb's calling context. Nor does it help future kdb developers understand some of the subtlty of interactions here.
Can you enlarge this to the following (editing anything below that you don't want git to blame you for ;-) ):
~~~
WARNING: This function may return a pointer to a single statically allocated buffer (namebuf). kdb's unusual calling context (single threaded, all other CPUs halted) provides us sufficient locking for this to be safe. The only constraint imposed by the static buffer is that the caller must consume any previous reply prior to another call to lookup a new symbol.
Note that, strictly speaking, some architectures may re-enter the kdb trap if the system turns out to be very badly damaged and this breaks the single-threaded assumption above. In these circumstances successful continuation and exit from the inner trap is unlikely to work and any user attempting this receives a prominent warning before being allowed to progress. In these circumstances we remain memory safe because namebuf[KSYM_NAME_LEN-1] will never change from '\0' although we do tolerate the possibility of garbled symbol display from the outer kdb trap.
~~~
Thanks
Daniel.
Quoted 14 lines · Daniel Thompson
Quoted 12 lines · Sumit Garg
Currently the only user for debug heap is
kdbnearsym()which can be modified to rather use statically allocated buffer for symbol name as per it's current usage. So do that and hence remove custom debug heap allocator.Note that this change puts a restriction on
kdbnearsym()callers to carefully use shared namebuf such that a caller should consume the symbol returned immediately prior to another call to fetch a different symbol.This change has been tested using kgdbtest on arm64 which doesn't show any regressions.
Quoted 8 lines
Quoted 2 lines
Suggested-by Daniel Thompson <[email protected]>Signed-off-by Sumit Garg <[email protected]>I'm afraid the passage of time (mostly due to my dropping the ball) means this no longer applies cleanly to latest kernel and
git am -3waytells me that "sha1 information is lacking or useless". Please can you rebase this on v5.13-rc4 and repost?
Sure.
Quoted 57 lines
Also...
Quoted 28 lines
kernel/debug/kdb/kdb_private.h +0
-0kernel/debug/kdb/kdb_support.c +4
-12@@ -57,35 +57,26 @@ int kdbgetsymval(const char *symname, kdb_symtab_t *symtab) }EXPORT_SYMBOL (kdbgetsymval); -static char *kdb_name_table[100 ];/* arbitrary size */ -/* -* kdbnearsym - Return the name of the symbol with the nearest address -* less than 'addr'. +* kdbnearsym() - Return the name of the symbol with the nearest address +* less than @addr. +* @addr: Address to check for near symbol +* @symtab: Structure to receive results * -* Parameters: -* addr Address to check for symbol near -* symtab Structure to receive results -* Returns: -* 0 No sections contain this address, symtab zero filled -* 1 Address mapped to module/symbol/section, data in symtab -* Remarks: -* 2.6 kallsyms has a "feature" where it unpacks the name into a kernel/debug/kdb/kdb_support.c int kdbgetsymval(const char *symname, kdb_symtab_t *symtab) · line 68
Quoted 10 lines
kernel/debug/kdb/kdb_support.c +3
-7-* string. If that string is reused before the caller expects it -* then the caller sees its string change without warning. To -* avoid cluttering up the main kdb code with lots of kdb_strdup, -* tests and kfree calls, kdbnearsym maintains an LRU list of the -* last few unique strings. The list is sized large enough to -* hold active strings, no kdb caller of kdbnearsym makes more -* than ~20 later calls before using a saved value. +* Note here that only single statically allocated namebuf is used for every +* symbol, so the caller should consume it immediately prior to another call +* to fetch a different symbol. This still looks like it will confused experienced kernel devs who aren't aware of kdb's calling context. Nor does it help future kdb developers understand some of the subtlty of interactions here.
Can you enlarge this to the following (editing anything below that you don't want git to blame you for ;-) ):
~~~
WARNING: This function may return a pointer to a single statically allocated buffer (namebuf). kdb's unusual calling context (single threaded, all other CPUs halted) provides us sufficient locking for this to be safe. The only constraint imposed by the static buffer is that the caller must consume any previous reply prior to another call to lookup a new symbol.
Quoted 11 lines
Note that, strictly speaking, some architectures may re-enter the kdb trap if the system turns out to be very badly damaged and this breaks the single-threaded assumption above. In these circumstances successful continuation and exit from the inner trap is unlikely to work and any user attempting this receives a prominent warning before being allowed to progress. In these circumstances we remain memory safe because namebuf[KSYM_NAME_LEN-1] will never change from '\0' although we do tolerate the possibility of garbled symbol display from the outer kdb trap.
~~~
Okay I will use this comment instead.
-Sumit
Quoted 4 lines
Thanks
Daniel.