diff mbox series

[1/3] lib/hexdump: Add a raw pointer printing format for slub debugging

Message ID 20210520013539.3733631-2-swboyd@chromium.org (mailing list archive)
State New, archived
Headers show
Series slub: Print non-hashed pointers in slub debugging | expand

Commit Message

Stephen Boyd May 20, 2021, 1:35 a.m. UTC
We want to get actual pointer addresses when we're looking at slub
debugging reports. Add another prefix format specifier that says we want
raw pointer addresses, i.e. %px, in the printk format.

Signed-off-by: Stephen Boyd <swboyd@chromium.org>
---
 include/linux/printk.h |  1 +
 lib/hexdump.c          | 12 ++++++++++--
 2 files changed, 11 insertions(+), 2 deletions(-)

Comments

David Rientjes May 24, 2021, 5:11 a.m. UTC | #1
On Wed, 19 May 2021, Stephen Boyd wrote:

> We want to get actual pointer addresses when we're looking at slub
> debugging reports. Add another prefix format specifier that says we want
> raw pointer addresses, i.e. %px, in the printk format.
> 
> Signed-off-by: Stephen Boyd <swboyd@chromium.org>

Acked-by: David Rientjes <rientjes@google.com>
Petr Mladek May 24, 2021, 11:36 a.m. UTC | #2
On Wed 2021-05-19 18:35:37, Stephen Boyd wrote:
> We want to get actual pointer addresses when we're looking at slub
> debugging reports. Add another prefix format specifier that says we want
> raw pointer addresses, i.e. %px, in the printk format.

This patch makes sense only with the 2nd patch.

Please, do not do this! Raw pointers might be printed safely
only in panic(). Users should be warned by the fat warning
triggered by "no_hash_pointers" in other use-cases. And
this patch is not needed when "no_hash_pointers" are enabled.

Best Regards,
Petr
diff mbox series

Patch

diff --git a/include/linux/printk.h b/include/linux/printk.h
index fe7eb2351610..a7b0b620982d 100644
--- a/include/linux/printk.h
+++ b/include/linux/printk.h
@@ -567,6 +567,7 @@  extern const struct file_operations kmsg_fops;
 enum {
 	DUMP_PREFIX_NONE,
 	DUMP_PREFIX_ADDRESS,
+	DUMP_PREFIX_RAW_ADDRESS,
 	DUMP_PREFIX_OFFSET
 };
 extern int hex_dump_to_buffer(const void *buf, size_t len, int rowsize,
diff --git a/lib/hexdump.c b/lib/hexdump.c
index 9301578f98e8..87af5755563f 100644
--- a/lib/hexdump.c
+++ b/lib/hexdump.c
@@ -211,8 +211,12 @@  EXPORT_SYMBOL(hex_dump_to_buffer);
  * @level: kernel log level (e.g. KERN_DEBUG)
  * @prefix_str: string to prefix each line with;
  *  caller supplies trailing spaces for alignment if desired
- * @prefix_type: controls whether prefix of an offset, address, or none
- *  is printed (%DUMP_PREFIX_OFFSET, %DUMP_PREFIX_ADDRESS, %DUMP_PREFIX_NONE)
+ * @prefix_type: controls how prefix is printed
+ *   %DUMP_PREFIX_OFFSET - offset prefix
+ *   %DUMP_PREFIX_ADDRESS - hashed address prefix
+ *   %DUMP_PREFIX_RAW_ADDRESS - non-hashed address prefix
+ *   %DUMP_PREFIX_NONE - no prefix
+ *
  * @rowsize: number of bytes to print per line; must be 16 or 32
  * @groupsize: number of bytes to print at a time (1, 2, 4, 8; default = 1)
  * @buf: data blob to dump
@@ -260,6 +264,10 @@  void print_hex_dump(const char *level, const char *prefix_str, int prefix_type,
 			printk("%s%s%p: %s\n",
 			       level, prefix_str, ptr + i, linebuf);
 			break;
+		case DUMP_PREFIX_RAW_ADDRESS:
+			printk("%s%s%px: %s\n",
+			       level, prefix_str, ptr + i, linebuf);
+			break;
 		case DUMP_PREFIX_OFFSET:
 			printk("%s%s%.8x: %s\n", level, prefix_str, i, linebuf);
 			break;