Re: [PATCH] Fix for "kmem <addr>" for kernels configured with CONFIG_SLUB and SLAB_RED_ZONE.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



OGAWA Hirofumi <hirofumi@xxxxxxxxxxxxxxxxxx> writes:

>> Attached is a patch for your review.  You will have to
>> enter "set redzone on" in order for the adjusted object
>> addresses to be displayed.
>
> Thanks! This seems to be what I want.

While testing this patch, I noticed what you pointed out in my
patch. Right, the part comparing "si->spec_addr" with "p" is wrong.

redzone.patch is version of fixed my bug (removed trailing whitespace too).

And while testing, I confused whether "redzone on" is meaning exclude or
not (because "redzone on" looks like "show redzone")? :)
So redzone-exclude.patch renamed "redzone" to "exclude_redzone".  This
patch can be rejected freely if you don't want.

Thanks.
-- 
OGAWA Hirofumi <hirofumi@xxxxxxxxxxxxxxxxxx>


---

 defs.h    |    2 ++
 help.c    |    7 ++++++-
 main.c    |    2 ++
 memory.c  |   15 +++++++++++++--
 symbols.c |    2 ++
 tools.c   |   26 ++++++++++++++++++++++++++
 6 files changed, 51 insertions(+), 3 deletions(-)

diff -puN defs.h~redzone defs.h
--- crash-64/defs.h~redzone	2017-02-04 06:02:56.779628912 +0900
+++ crash-64-hirofumi/defs.h	2017-02-04 06:47:39.582704036 +0900
@@ -536,6 +536,7 @@ struct program_context {
 #define EXCLUDED_VMEMMAP (0x40000ULL)
 #define is_excluded_vmemmap() (pc->flags2 & EXCLUDED_VMEMMAP)
 #define MEMSRC_LOCAL         (0x80000ULL)
+#define REDZONE             (0x100000ULL)
 	char *cleanup;
 	char *namelist_orig;
 	char *namelist_debug_orig;
@@ -1979,6 +1980,7 @@ struct offset_table {
 	long task_struct_stack;
 	long tnt_mod;
 	long radix_tree_node_shift;
+	long kmem_cache_red_left_pad;
 };
 
 struct size_table {         /* stash of commonly-used sizes */
diff -puN help.c~redzone help.c
--- crash-64/help.c~redzone	2017-02-04 06:02:56.780628917 +0900
+++ crash-64-hirofumi/help.c	2017-02-04 06:47:39.584704047 +0900
@@ -1072,8 +1072,12 @@ char *help_set[] = {
 "                               must be a kernel or module text address, which", 
 "                               may be expressed symbolically or as a hexadecimal",
 "                               value.",
-"         offline  show | hide  Show or hide command output that is associated",
+"         offline  show | hide  show or hide command output that is associated",
 "                               with offline cpus.",
+"         redzone  on | off     if on, CONFIG_SLUB object addresses displayed by",
+"                               the kmem command will be adjusted to reflect the",
+"                               SLAB_RED_ZONE padding inserted at the beginning",
+"                               of the object.",
 " ",
 "  Internal variables may be set in four manners:\n",
 "    1. entering the set command in $HOME/.%src.",
@@ -1124,6 +1128,7 @@ char *help_set[] = {
 "               gdb: off",
 "             scope: (not set)",
 "           offline: show",
+"           redzone: off",
 " ",
 "  Show the current context:\n",
 "    %s> set",
diff -puN main.c~redzone main.c
--- crash-64/main.c~redzone	2017-02-04 06:02:56.780628917 +0900
+++ crash-64-hirofumi/main.c	2017-02-04 06:47:39.582704036 +0900
@@ -1469,6 +1469,8 @@ dump_program_context(void)
 		fprintf(fp, "%sSNAP", others++ ? "|" : "");
 	if (pc->flags2 & EXCLUDED_VMEMMAP)
 		fprintf(fp, "%sEXCLUDED_VMEMMAP", others++ ? "|" : "");
+	if (pc->flags2 & REDZONE)
+		fprintf(fp, "%sREDZONE", others++ ? "|" : "");
 	fprintf(fp, ")\n");
 
 	fprintf(fp, "         namelist: %s\n", pc->namelist);
diff -puN memory.c~redzone memory.c
--- crash-64/memory.c~redzone	2017-02-04 06:02:56.781628923 +0900
+++ crash-64-hirofumi/memory.c	2017-02-04 06:47:39.583704041 +0900
@@ -723,6 +723,7 @@ vm_init(void)
 		MEMBER_OFFSET_INIT(kmem_cache_node, "kmem_cache", "node");
 		MEMBER_OFFSET_INIT(kmem_cache_cpu_slab, "kmem_cache", "cpu_slab");
 		MEMBER_OFFSET_INIT(kmem_cache_list, "kmem_cache", "list");
+		MEMBER_OFFSET_INIT(kmem_cache_red_left_pad, "kmem_cache", "red_left_pad");
 		MEMBER_OFFSET_INIT(kmem_cache_name, "kmem_cache", "name");
 		MEMBER_OFFSET_INIT(kmem_cache_flags, "kmem_cache", "flags");
 		MEMBER_OFFSET_INIT(kmem_cache_cpu_freelist, "kmem_cache_cpu", "freelist");
@@ -18357,6 +18358,7 @@ do_slab_slub(struct meminfo *si, int ver
 	ulong freelist, cpu_freelist, cpu_slab_ptr;
 	int i, free_objects, cpu_slab, is_free, node;
 	ulong p, q;
+	ulong red_left_pad;
 
 	if (!si->slab) {
 		if (CRASHDEBUG(1))
@@ -18442,6 +18444,14 @@ do_slab_slub(struct meminfo *si, int ver
 			fprintf(fp, "< SLUB: free list END (%d found) >\n", i);
 	}
 
+	red_left_pad = 0;
+	if (VALID_MEMBER(kmem_cache_red_left_pad)) {
+#define SLAB_RED_ZONE 0x00000400UL
+		ulong flags = ULONG(si->cache_buf + OFFSET(kmem_cache_flags));
+		if (flags & SLAB_RED_ZONE)
+			red_left_pad = ULONG(si->cache_buf + OFFSET(kmem_cache_red_left_pad));
+	}
+
 	for (p = vaddr; p < vaddr + objects * si->size; p += si->size) {
 		hq_open();
 		is_free = FALSE;
@@ -18457,7 +18467,7 @@ do_slab_slub(struct meminfo *si, int ver
 				}
 				if (q & PAGE_MAPPING_ANON)
 					break;
-				if (p == q) {
+				if (p + red_left_pad == q) {
 					is_free = TRUE;
 					goto found_object;
 				}
@@ -18482,7 +18492,8 @@ do_slab_slub(struct meminfo *si, int ver
 
 		fprintf(fp, "  %s%lx%s", 
 			is_free ? " " : "[",
-			p, is_free ? "  " : "]");
+			pc->flags2 & REDZONE ? p + red_left_pad : p,
+			is_free ? "  " : "]");
 		if (is_free && (cpu_slab >= 0))
 			fprintf(fp, "(cpu %d cache)", cpu_slab);
 		fprintf(fp, "\n");
diff -puN symbols.c~redzone symbols.c
--- crash-64/symbols.c~redzone	2017-02-04 06:02:56.782628928 +0900
+++ crash-64-hirofumi/symbols.c	2017-02-04 06:02:56.788628962 +0900
@@ -9332,6 +9332,8 @@ dump_offset_table(char *spec, ulong make
                 OFFSET(kmem_cache_name));
         fprintf(fp, "               kmem_cache_list: %ld\n",
                 OFFSET(kmem_cache_list));
+        fprintf(fp, "       kmem_cache_red_left_pad: %ld\n",
+                OFFSET(kmem_cache_red_left_pad));
         fprintf(fp, "               kmem_cache_node: %ld\n",
                 OFFSET(kmem_cache_node));
         fprintf(fp, "           kmem_cache_cpu_slab: %ld\n",
diff -puN tools.c~redzone tools.c
--- crash-64/tools.c~redzone	2017-02-04 06:02:56.783628934 +0900
+++ crash-64-hirofumi/tools.c	2017-02-04 06:47:39.581704029 +0900
@@ -2435,6 +2435,31 @@ cmd_set(void)
 
 			return;
 
+		} else if (STREQ(args[optind], "redzone")) {
+                        if (args[optind+1]) {
+                                optind++;
+                                if (STREQ(args[optind], "on"))
+                                        pc->flags2 |= REDZONE;
+                                else if (STREQ(args[optind], "off"))
+                                        pc->flags2 &= ~REDZONE;
+                                else if (IS_A_NUMBER(args[optind])) {
+                                        value = stol(args[optind],
+                                                FAULT_ON_ERROR, NULL);
+                                        if (value)
+                                                pc->flags2 |= REDZONE;
+                                        else
+                                                pc->flags2 &= ~REDZONE;
+                                } else
+                                        goto invalid_set_command;
+                        }
+
+			if (runtime) {
+				fprintf(fp, "redzone: %s\n",
+					pc->flags2 & REDZONE ?
+					"on" : "off");
+			}
+			return;
+
 		} else if (XEN_HYPER_MODE()) {
 			error(FATAL, "invalid argument for the Xen hypervisor\n");
 		} else if (pc->flags & MINIMAL_MODE) {
@@ -2541,6 +2566,7 @@ show_options(void)
 	else
 		fprintf(fp, "(not set)\n");
 	fprintf(fp, "       offline: %s\n", pc->flags2 & OFFLINE_HIDE ? "hide" : "show");
+	fprintf(fp, "       redzone: %s\n", pc->flags2 & REDZONE ? "on" : "off");
 }
 
 
_

---

 defs.h   |    2 +-
 help.c   |    4 ++--
 main.c   |    4 ++--
 memory.c |    2 +-
 tools.c  |   54 +++++++++++++++++++++++++++---------------------------
 5 files changed, 33 insertions(+), 33 deletions(-)

diff -puN tools.c~redzone-exclude tools.c
--- crash-64/tools.c~redzone-exclude	2017-02-04 06:47:57.889809852 +0900
+++ crash-64-hirofumi/tools.c	2017-02-04 06:47:57.896809892 +0900
@@ -2435,27 +2435,27 @@ cmd_set(void)
 
 			return;
 
-		} else if (STREQ(args[optind], "redzone")) {
+		} else if (STREQ(args[optind], "exclude_redzone")) {
                         if (args[optind+1]) {
                                 optind++;
                                 if (STREQ(args[optind], "on"))
-                                        pc->flags2 |= REDZONE;
+                                        pc->flags2 |= EXCLUDE_REDZONE;
                                 else if (STREQ(args[optind], "off"))
-                                        pc->flags2 &= ~REDZONE;
+                                        pc->flags2 &= ~EXCLUDE_REDZONE;
                                 else if (IS_A_NUMBER(args[optind])) {
                                         value = stol(args[optind],
                                                 FAULT_ON_ERROR, NULL);
                                         if (value)
-                                                pc->flags2 |= REDZONE;
+                                                pc->flags2 |= EXCLUDE_REDZONE;
                                         else
-                                                pc->flags2 &= ~REDZONE;
+                                                pc->flags2 &= ~EXCLUDE_REDZONE;
                                 } else
                                         goto invalid_set_command;
                         }
 
 			if (runtime) {
-				fprintf(fp, "redzone: %s\n",
-					pc->flags2 & REDZONE ?
+				fprintf(fp, "exclude_redzone: %s\n",
+					pc->flags2 & EXCLUDE_REDZONE ?
 					"on" : "off");
 			}
 			return;
@@ -2522,7 +2522,7 @@ show_options(void)
 {
 	char buf[BUFSIZE];
 
-	fprintf(fp, "        scroll: %s ",
+	fprintf(fp, "         scroll: %s ",
 		pc->flags & SCROLL ? "on" : "off");
 	switch (pc->scroll_command)
 	{
@@ -2539,34 +2539,34 @@ show_options(void)
 		fprintf(fp, "(CRASHPAGER: %s)\n", getenv("CRASHPAGER"));
 		break;
 	}
-        fprintf(fp, "         radix: %d (%s)\n", pc->output_radix,
+        fprintf(fp, "          radix: %d (%s)\n", pc->output_radix,
                 pc->output_radix == 10 ? "decimal" :
                 pc->output_radix == 16 ? "hexadecimal" : "unknown");
-	fprintf(fp, "       refresh: %s\n", tt->flags & TASK_REFRESH ? "on" : "off");
-	fprintf(fp, "     print_max: %d\n", *gdb_print_max);
-	fprintf(fp, "   print_array: %s\n", *gdb_prettyprint_arrays ? "on" : "off");
-	fprintf(fp, "       console: %s\n", pc->console ? 
+	fprintf(fp, "        refresh: %s\n", tt->flags & TASK_REFRESH ? "on" : "off");
+	fprintf(fp, "      print_max: %d\n", *gdb_print_max);
+	fprintf(fp, "    print_array: %s\n", *gdb_prettyprint_arrays ? "on" : "off");
+	fprintf(fp, "        console: %s\n", pc->console ?
 		pc->console : "(not assigned)");
-	fprintf(fp, "         debug: %ld\n", pc->debug);
-	fprintf(fp, "          core: %s\n", pc->flags & DROP_CORE ? "on" : "off");
-	fprintf(fp, "          hash: %s\n", pc->flags & HASH ? "on" : "off");
-	fprintf(fp, "        silent: %s\n", pc->flags & SILENT ? "on" : "off"); 
-	fprintf(fp, "          edit: %s\n", pc->editing_mode);
-	fprintf(fp, "      namelist: %s\n", pc->namelist);
-	fprintf(fp, "      dumpfile: %s\n", pc->dumpfile);
-	fprintf(fp, "        unwind: %s\n", kt->flags & DWARF_UNWIND ? "on" : "off");
-	fprintf(fp, " zero_excluded: %s\n",
+	fprintf(fp, "          debug: %ld\n", pc->debug);
+	fprintf(fp, "           core: %s\n", pc->flags & DROP_CORE ? "on" : "off");
+	fprintf(fp, "           hash: %s\n", pc->flags & HASH ? "on" : "off");
+	fprintf(fp, "         silent: %s\n", pc->flags & SILENT ? "on" : "off");
+	fprintf(fp, "           edit: %s\n", pc->editing_mode);
+	fprintf(fp, "       namelist: %s\n", pc->namelist);
+	fprintf(fp, "       dumpfile: %s\n", pc->dumpfile);
+	fprintf(fp, "         unwind: %s\n", kt->flags & DWARF_UNWIND ? "on" : "off");
+	fprintf(fp, "  zero_excluded: %s\n",
 		(*diskdump_flags & ZERO_EXCLUDED) || sadump_is_zero_excluded() ?
 		"on" : "off");
-	fprintf(fp, "     null-stop: %s\n", *gdb_stop_print_at_null ? "on" : "off");
-	fprintf(fp, "           gdb: %s\n", pc->flags2 & GDB_CMD_MODE ? "on" : "off");
-	fprintf(fp, "         scope: %lx ", pc->scope);
+	fprintf(fp, "      null-stop: %s\n", *gdb_stop_print_at_null ? "on" : "off");
+	fprintf(fp, "            gdb: %s\n", pc->flags2 & GDB_CMD_MODE ? "on" : "off");
+	fprintf(fp, "          scope: %lx ", pc->scope);
 	if (pc->scope)
 		fprintf(fp, "(%s)\n", value_to_symstr(pc->scope, buf, 0));
 	else
 		fprintf(fp, "(not set)\n");
-	fprintf(fp, "       offline: %s\n", pc->flags2 & OFFLINE_HIDE ? "hide" : "show");
-	fprintf(fp, "       redzone: %s\n", pc->flags2 & REDZONE ? "on" : "off");
+	fprintf(fp, "        offline: %s\n", pc->flags2 & OFFLINE_HIDE ? "hide" : "show");
+	fprintf(fp, "exclude_redzone: %s\n", pc->flags2 & EXCLUDE_REDZONE ? "on" : "off");
 }
 
 
diff -puN defs.h~redzone-exclude defs.h
--- crash-64/defs.h~redzone-exclude	2017-02-04 06:47:57.890809858 +0900
+++ crash-64-hirofumi/defs.h	2017-02-04 06:47:57.897809898 +0900
@@ -536,7 +536,7 @@ struct program_context {
 #define EXCLUDED_VMEMMAP (0x40000ULL)
 #define is_excluded_vmemmap() (pc->flags2 & EXCLUDED_VMEMMAP)
 #define MEMSRC_LOCAL         (0x80000ULL)
-#define REDZONE             (0x100000ULL)
+#define EXCLUDE_REDZONE     (0x100000ULL)
 	char *cleanup;
 	char *namelist_orig;
 	char *namelist_debug_orig;
diff -puN main.c~redzone-exclude main.c
--- crash-64/main.c~redzone-exclude	2017-02-04 06:47:57.891809864 +0900
+++ crash-64-hirofumi/main.c	2017-02-04 06:47:57.897809898 +0900
@@ -1469,8 +1469,8 @@ dump_program_context(void)
 		fprintf(fp, "%sSNAP", others++ ? "|" : "");
 	if (pc->flags2 & EXCLUDED_VMEMMAP)
 		fprintf(fp, "%sEXCLUDED_VMEMMAP", others++ ? "|" : "");
-	if (pc->flags2 & REDZONE)
-		fprintf(fp, "%sREDZONE", others++ ? "|" : "");
+	if (pc->flags2 & EXCLUDE_REDZONE)
+		fprintf(fp, "%sEXCLUDE_REDZONE", others++ ? "|" : "");
 	fprintf(fp, ")\n");
 
 	fprintf(fp, "         namelist: %s\n", pc->namelist);
diff -puN memory.c~redzone-exclude memory.c
--- crash-64/memory.c~redzone-exclude	2017-02-04 06:47:57.892809869 +0900
+++ crash-64-hirofumi/memory.c	2017-02-04 06:47:57.898809904 +0900
@@ -18492,7 +18492,7 @@ do_slab_slub(struct meminfo *si, int ver
 
 		fprintf(fp, "  %s%lx%s", 
 			is_free ? " " : "[",
-			pc->flags2 & REDZONE ? p + red_left_pad : p,
+			pc->flags2 & EXCLUDE_REDZONE ? p + red_left_pad : p,
 			is_free ? "  " : "]");
 		if (is_free && (cpu_slab >= 0))
 			fprintf(fp, "(cpu %d cache)", cpu_slab);
diff -puN help.c~redzone-exclude help.c
--- crash-64/help.c~redzone-exclude	2017-02-04 06:47:57.892809869 +0900
+++ crash-64-hirofumi/help.c	2017-02-04 06:47:57.899809910 +0900
@@ -1074,7 +1074,7 @@ char *help_set[] = {
 "                               value.",
 "         offline  show | hide  show or hide command output that is associated",
 "                               with offline cpus.",
-"         redzone  on | off     if on, CONFIG_SLUB object addresses displayed by",
+" exclude_redzone  on | off     if on, CONFIG_SLUB object addresses displayed by",
 "                               the kmem command will be adjusted to reflect the",
 "                               SLAB_RED_ZONE padding inserted at the beginning",
 "                               of the object.",
@@ -1128,7 +1128,7 @@ char *help_set[] = {
 "               gdb: off",
 "             scope: (not set)",
 "           offline: show",
-"           redzone: off",
+"   exclude_redzone: off",
 " ",
 "  Show the current context:\n",
 "    %s> set",
_
--
Crash-utility mailing list
Crash-utility@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/crash-utility

[Index of Archives]     [Fedora Development]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [KDE Users]     [Fedora Tools]

 

Powered by Linux