Skip to contentSkip to conversation

kernel/module: add name size info to pr_debug() calls

PATCH Superseded Jim Cromie 2 participants 3 messages Jun 11, 2020 – Jun 30, 2020

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jim Cromie

author
#0 lore raw

PATCH 1/1 kernel/module: add name size info to pr_debug() calls

when booted with arg: module.dyndbg=+p
dmesg gets volumes of info about loaded modules. This adds module & symbol names, and sizes where pertinent. Now I can know which module's info Im looking at.

---
 kernel/module.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
kernel/module.c +7 -7
index e8a198588f26..d871d9cee9eb 100644
@@ -2294,8 +2294,8 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
 
 		case SHN_ABS:
 			/* Don't need to do anything */
-			pr_debug("Absolute symbol: 0x%08lx\n",
-			       (long)sym[i].st_value);
+			pr_debug("Absolute symbol: 0x%08lx %s\n",
+				 (long)sym[i].st_value, name);
 			break;
 
 		case SHN_LIVEPATCH:
@@ -2409,7 +2409,7 @@ static void layout_sections(struct module *mod, struct load_info *info)
 	for (i = 0; i < info->hdr->e_shnum; i++)
 		info->sechdrs[i].sh_entsize = ~0UL;
 
-	pr_debug("Core section allocation order:\n");
+	pr_debug("Core section allocation order for: %s\n", mod->name);
 	for (m = 0; m < ARRAY_SIZE(masks); ++m) {
 		for (i = 0; i < info->hdr->e_shnum; ++i) {
 			Elf_Shdr *s = &info->sechdrs[i];
@@ -2442,7 +2442,7 @@ static void layout_sections(struct module *mod, struct load_info *info)
 		}
 	}
 
-	pr_debug("Init section allocation order:\n");
+	pr_debug("Init section allocation order for: %s\n", mod->name);
 	for (m = 0; m < ARRAY_SIZE(masks); ++m) {
 		for (i = 0; i < info->hdr->e_shnum; ++i) {
 			Elf_Shdr *s = &info->sechdrs[i];
@@ -3276,7 +3276,7 @@ static int move_module(struct module *mod, struct load_info *info)
 		mod->init_layout.base = NULL;
 
 	/* Transfer each section which specifies SHF_ALLOC */
-	pr_debug("final section addresses:\n");
+	pr_debug("final section addresses for: %s\n", mod->name);
 	for (i = 0; i < info->hdr->e_shnum; i++) {
 		void *dest;
 		Elf_Shdr *shdr = &info->sechdrs[i];
@@ -3294,8 +3294,8 @@ static int move_module(struct module *mod, struct load_info *info)
 			memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
 		/* Update sh_addr to point to copy in image. */
 		shdr->sh_addr = (unsigned long)dest;
-		pr_debug("\t0x%lx %s\n",
-			 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
+		pr_debug("\t0x%lx 0x%.8lx %s\n", (long)shdr->sh_addr,
+			 (long)shdr->sh_size, info->secstrings + shdr->sh_name);
 	}
 
 	return 0;
Signature · 1 line
2.26.2
#1 lore raw

+++ Jim Cromie [11/06/20 08:20 -0600]:

Quoted 4 lines

when booted with arg: module.dyndbg=+p
dmesg gets volumes of info about loaded modules. This adds module & symbol names, and sizes where pertinent. Now I can know which module's info Im looking at.

Hi,

Could you please fix the changelog formatting according to Documentation/process/submitting-patches.rst? More specifically, complete sentences, line wrapped at 75 columns, and a Signed-off-by:
line at the end. There are plenty of examples if you look through the lkml mailing list.

Quoted 9 lines

---
kernel/module.c | 14 +++++++-------

1 file changed, 7 insertions(+), 7 deletions(-)
kernel/module.c +0 -0
index e8a198588f26..d871d9cee9eb 100644

kernel/module.c static int simplify_symbols(struct module *mod, const struct load_info *info) · line 2298

Quoted 7 lines
kernel/module.c +2 -2
@@ -2294,8 +2294,8 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
 
 		case SHN_ABS:
 			/* Don't need to do anything */
-			pr_debug("Absolute symbol: 0x%08lx\n",
-			       (long)sym[i].st_value);
+			pr_debug("Absolute symbol: 0x%08lx %s\n",
+				 (long)sym[i].st_value, name);

I would prefer "Absolute symbol %s:" rather than putting the symbol name at the end.

kernel/module.c static void layout_sections(struct module *mod, struct load_info *info) · line 2412

Quoted 9 lines
kernel/module.c +1 -1
 			break;
 
 		case SHN_LIVEPATCH:
@@ -2409,7 +2409,7 @@ static void layout_sections(struct module *mod, struct load_info *info)
 	for (i = 0; i < info->hdr->e_shnum; i++)
 		info->sechdrs[i].sh_entsize = ~0UL;
 
-	pr_debug("Core section allocation order:\n");
+	pr_debug("Core section allocation order for: %s\n", mod->name);

I would slightly prefer "Core section allocation order for %s:", but it's a matter of taste.

kernel/module.c static void layout_sections(struct module *mod, struct load_info *info) · line 2445

Quoted 9 lines
kernel/module.c +1 -1
 	for (m = 0; m < ARRAY_SIZE(masks); ++m) {
 		for (i = 0; i < info->hdr->e_shnum; ++i) {
 			Elf_Shdr *s = &info->sechdrs[i];
@@ -2442,7 +2442,7 @@ static void layout_sections(struct module *mod, struct load_info *info)
 		}
 	}
 
-	pr_debug("Init section allocation order:\n");
+	pr_debug("Init section allocation order for: %s\n", mod->name);

Same here.

kernel/module.c static int move_module(struct module *mod, struct load_info *info) · line 3279

Quoted 9 lines
kernel/module.c +1 -1
 	for (m = 0; m < ARRAY_SIZE(masks); ++m) {
 		for (i = 0; i < info->hdr->e_shnum; ++i) {
 			Elf_Shdr *s = &info->sechdrs[i];
@@ -3276,7 +3276,7 @@ static int move_module(struct module *mod, struct load_info *info)
 		mod->init_layout.base = NULL;
 
 	/* Transfer each section which specifies SHF_ALLOC */
-	pr_debug("final section addresses:\n");
+	pr_debug("final section addresses for: %s\n", mod->name);

Let's capitalize the "f" in "final section addresses" to be consistent with the other two above.

kernel/module.c static int move_module(struct module *mod, struct load_info *info) · line 3298

Quoted 11 lines
kernel/module.c +2 -2
 	for (i = 0; i < info->hdr->e_shnum; i++) {
 		void *dest;
 		Elf_Shdr *shdr = &info->sechdrs[i];
@@ -3294,8 +3294,8 @@ static int move_module(struct module *mod, struct load_info *info)
 			memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
 		/* Update sh_addr to point to copy in image. */
 		shdr->sh_addr = (unsigned long)dest;
-		pr_debug("\t0x%lx %s\n",
-			 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
+		pr_debug("\t0x%lx 0x%.8lx %s\n", (long)shdr->sh_addr,
+			 (long)shdr->sh_size, info->secstrings + shdr->sh_name);

Any reason why you added sh_size here? Is it really needed? You can usually deduce how much space a section is taking up in a module by looking at the final section address printout. Plus the elf section size is not entirely accurate here as each module section is aligned to page boundaries when the module loader allocates memory for each section. I would prefer to just leave it out.

Thanks,

Jessica

#2 lore raw
Quoted 7 lines · Jessica Yu

+++ Jim Cromie [11/06/20 08:20 -0600]:

Quoted 4 lines

when booted with arg: module.dyndbg=+p
dmesg gets volumes of info about loaded modules. This adds module & symbol names, and sizes where pertinent. Now I can know which module's info Im looking at.

Quoted 8 lines

Hi,

Could you please fix the changelog formatting according to Documentation/process/submitting-patches.rst? More specifically, complete sentences, line wrapped at 75 columns, and a Signed-off-by:
line at the end. There are plenty of examples if you look through the lkml mailing list.

ack. less casual next time. and with -s

Quoted 10 lines
Quoted 10 lines

---
kernel/module.c | 14 +++++++-------

1 file changed, 7 insertions(+), 7 deletions(-)
kernel/module.c +0 -0
index e8a198588f26..d871d9cee9eb 100644
@@ -2294,8 +2294,8 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
 
Quoted 9 lines

kernel/module.c static int simplify_symbols(struct module *mod, const struct load_info *info) · line 2298

Quoted 6 lines
kernel/module.c +2 -2
              case SHN_ABS:
                      /* Don't need to do anything */
-                      pr_debug("Absolute symbol: 0x%08lx\n",
-                             (long)sym[i].st_value);
+                      pr_debug("Absolute symbol: 0x%08lx %s\n",
+                               (long)sym[i].st_value, name);

I would prefer "Absolute symbol %s:" rather than putting the symbol name at the end.

i chose this for a more tabular appearance,
names vary in length, so value afterwards looks cluttered. plus its more consistent with preceding messages

[    3.458007] 0xffffffffc0023d40 0x00000030 .bss
[    3.458008] 0xffffffffc0028000 0x00001158 .symtab
[    3.458010] 0xffffffffc0029158 0x00000af5 .strtab
[    3.458021] Absolute symbol: 0x00000000 rapl.mod.c
[    3.458022] Absolute symbol: 0x00000000 rapl.c
Quoted 8 lines
Quoted 8 lines
kernel/module.c +0 -0
                      break;
 
              case SHN_LIVEPATCH:
@@ -2409,7 +2409,7 @@ static void layout_sections(struct module *mod, struct load_info *info)
      for (i = 0; i < info->hdr->e_shnum; i++)
              info->sechdrs[i].sh_entsize = ~0UL;
 
Quoted 6 lines

kernel/module.c static void layout_sections(struct module *mod, struct load_info *info) · line 2412

Quoted 2 lines
kernel/module.c +1 -1
-      pr_debug("Core section allocation order:\n");
+      pr_debug("Core section allocation order for: %s\n", mod->name);

I would slightly prefer "Core section allocation order for %s:", but it's a matter of taste.

done everywhere you noted.

Quoted 35 lines

kernel/module.c static void layout_sections(struct module *mod, struct load_info *info) · line 2445

Quoted 9 lines
kernel/module.c +1 -1
      for (m = 0; m < ARRAY_SIZE(masks); ++m) {
              for (i = 0; i < info->hdr->e_shnum; ++i) {
                      Elf_Shdr *s = &info->sechdrs[i];
@@ -2442,7 +2442,7 @@ static void layout_sections(struct module *mod, struct load_info *info)
              }
      }
 
-      pr_debug("Init section allocation order:\n");
+      pr_debug("Init section allocation order for: %s\n", mod->name);

Same here.

kernel/module.c static int move_module(struct module *mod, struct load_info *info) · line 3279

Quoted 9 lines
kernel/module.c +1 -1
      for (m = 0; m < ARRAY_SIZE(masks); ++m) {
              for (i = 0; i < info->hdr->e_shnum; ++i) {
                      Elf_Shdr *s = &info->sechdrs[i];
@@ -3276,7 +3276,7 @@ static int move_module(struct module *mod, struct load_info *info)
              mod->init_layout.base = NULL;
 
      /* Transfer each section which specifies SHF_ALLOC */
-      pr_debug("final section addresses:\n");
+      pr_debug("final section addresses for: %s\n", mod->name);

Let's capitalize the "f" in "final section addresses" to be consistent with the other two above.

Quoted 10 lines
kernel/module.c +1 -2
      for (i = 0; i < info->hdr->e_shnum; i++) {
              void *dest;
              Elf_Shdr *shdr = &info->sechdrs[i];
@@ -3294,8 +3294,8 @@ static int move_module(struct module *mod, struct load_info *info)
                      memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
              /* Update sh_addr to point to copy in image. */
              shdr->sh_addr = (unsigned long)dest;
-              pr_debug("\t0x%lx %s\n",
-                       (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
+              pr_debug("\t0x%lx 0x%.8lx %s\n", (long)shdr->sh_addr,
Quoted 9 lines

kernel/module.c static int move_module(struct module *mod, struct load_info *info) · line 3298

Quoted 1 line
kernel/module.c +1 -0
+                       (long)shdr->sh_size, info->secstrings + shdr->sh_name);

Any reason why you added sh_size here? Is it really needed? You can usually deduce how much space a section is taking up in a module by looking at the final section address printout. Plus the elf section size is not entirely accurate here as each module section is aligned to page boundaries when the module loader allocates memory for each section. I would prefer to just leave it out.

mostly I added it cuz it was available.
I do not know when it might be useful, but seeing it can help decide that. Having the data there makes your deduction possible,
without seeing the data, it wouldnt occur to me that there are "inaccuracies". And seeing it in hex form might illuminate the page alignment too.

Also, this is in move-module, which I havent seen in action AFAIK

I'll send v2 shortly, as above, unless you want a tweak.

Quoted 3 lines

Thanks,

Jessica