<div dir="ltr"><div dir="ltr">On Mon, Mar 28, 2022 at 5:04 PM <<a href="mailto:crash-utility-request@redhat.com">crash-utility-request@redhat.com</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Date: Mon, 28 Mar 2022 11:03:38 +0200<br>
From: Alexander Egorenkov <<a href="mailto:egorenar@linux.ibm.com" target="_blank">egorenar@linux.ibm.com</a>><br>
To: "<a href="mailto:d.hatayama@fujitsu.com" target="_blank">d.hatayama@fujitsu.com</a>" <<a href="mailto:d.hatayama@fujitsu.com" target="_blank">d.hatayama@fujitsu.com</a>>,<br>
        "<a href="mailto:crash-utility@redhat.com" target="_blank">crash-utility@redhat.com</a>" <<a href="mailto:crash-utility@redhat.com" target="_blank">crash-utility@redhat.com</a>><br>
Subject: Re: [Crash-utility] [PATCH] kernel: fix start-up time<br>
        degradation caused by strings command<br>
Message-ID: <<a href="mailto:87ee2m4ff9.fsf@oc8242746057.ibm.com" target="_blank">87ee2m4ff9.fsf@oc8242746057.ibm.com</a>><br>
Content-Type: text/plain<br>
<br>
"<a href="mailto:d.hatayama@fujitsu.com" target="_blank">d.hatayama@fujitsu.com</a>" <<a href="mailto:d.hatayama@fujitsu.com" target="_blank">d.hatayama@fujitsu.com</a>> writes:<br>
<br>
> verify_namelist() uses strings command and scans full part of vmlinux<br>
> file to find linux_banner string. However, vmlinux file is quite large<br>
> these days, reaching over 500MB. As a result, this degradates start-up<br>
> time of crash command 10 or more seconds. (Of course, this depends on<br>
> machines you use for investigation, but I guess typically we cannot<br>
> use such powerful machines to investigate crash dump...)<br>
><br>
> To resolve this issue, let's use bfd library and read linux_banner<br>
> string in vmlinux file directly.<br>
><br>
> A simple benchmark shows the following result:<br>
><br>
> Without the fix:<br>
><br>
>     # cat ./commands.txt<br>
>     quit<br>
>     # time ./crash -i ./commands.txt \<br>
>         /usr/lib/debug/lib/modules/5.16.15-201.fc35.x86_64/vmlinux \<br>
>         /var/crash/*/vmcore >/dev/null 2>&1<br>
><br>
>     real        0m20.251s<br>
>     user        0m19.022s<br>
>     sys 0m1.054s<br>
><br>
> With the fix:<br>
><br>
>     # time ./crash -i ./commands.txt \<br>
>         /usr/lib/debug/lib/modules/5.16.15-201.fc35.x86_64/vmlinux \<br>
>         /var/crash/*/vmcore >/dev/null 2>&1<br>
><br>
>     real        0m6.528s<br>
>     user        0m6.143s<br>
>     sys 0m0.431s<br>
><br>
> Note that this commit keeps the original logic that uses strings<br>
> command for backward compatibility for in case.<br>
><br>
> Signed-off-by: HATAYAMA Daisuke <<a href="mailto:d.hatayama@fujitsu.com" target="_blank">d.hatayama@fujitsu.com</a>><br>
> ---<br>
>  Makefile |  2 +-<br>
>  kernel.c | 41 +++++++++++++++++++++++++++++++++++++++++<br>
>  2 files changed, 42 insertions(+), 1 deletion(-)<br>
><br>
> diff --git a/Makefile b/Makefile<br>
> index 007d030..e520b12 100644<br>
> --- a/Makefile<br>
> +++ b/Makefile<br>
> @@ -364,7 +364,7 @@ task.o: ${GENERIC_HFILES} task.c<br>
>       ${CC} -c ${CRASH_CFLAGS} task.c ${WARNING_OPTIONS} ${WARNING_ERROR}<br>
>  <br>
>  kernel.o: ${GENERIC_HFILES} kernel.c<br>
> -     ${CC} -c ${CRASH_CFLAGS} kernel.c ${WARNING_OPTIONS} ${WARNING_ERROR}<br>
> +     ${CC} -c ${CRASH_CFLAGS} kernel.c -I${BFD_DIRECTORY} -I${GDB_INCLUDE_DIRECTORY} ${WARNING_OPTIONS} ${WARNING_ERROR}<br>
>  <br>
>  printk.o: ${GENERIC_HFILES} printk.c<br>
>       ${CC} -c ${CRASH_CFLAGS} printk.c ${WARNING_OPTIONS} ${WARNING_ERROR}<br>
> diff --git a/kernel.c b/kernel.c<br>
> index 1c63447..92434a3 100644<br>
> --- a/kernel.c<br>
> +++ b/kernel.c<br>
> @@ -23,6 +23,11 @@<br>
>  #include <ctype.h><br>
>  #include <stdbool.h><br>
>  #include "xendump.h"<br>
> +#if defined(GDB_7_6) || defined(GDB_10_2)<br>
> +#define __CONFIG_H__ 1<br>
> +#include "config.h"<br>
> +#endif<br>
> +#include "bfd.h"<br>
>  <br>
>  static void do_module_cmd(ulong, char *, ulong, char *, char *);<br>
>  static void show_module_taint(void);<br>
> @@ -97,6 +102,7 @@ static void dump_printk_safe_seq_buf(int);<br>
>  static char *vmcoreinfo_read_string(const char *);<br>
>  static void check_vmcoreinfo(void);<br>
>  static int is_pvops_xen(void);<br>
> +static int get_linux_banner_from_vmlinux(char *, size_t);<br>
>  <br>
>  <br>
>  /*<br>
> @@ -1324,6 +1330,12 @@ verify_namelist()<br>
>       target_smp = strstr(kt->utsname.version, " SMP ") ? TRUE : FALSE;<br>
>       namelist_smp = FALSE;<br>
>  <br>
> +     if (get_linux_banner_from_vmlinux(buffer, sizeof(buffer)) &&<br>
> +         strstr(buffer, kt->proc_version)) {<br>
> +             found = TRUE;<br>
> +             goto found;<br>
> +     }<br>
> +<br>
>          sprintf(command, "/usr/bin/strings %s", namelist);<br>
>          if ((pipe = popen(command, "r")) == NULL) {<br>
>                  error(INFO, "%s: %s\n", namelist, strerror(errno));<br>
> @@ -1384,6 +1396,7 @@ verify_namelist()<br>
>               }<br>
>       }<br>
>  <br>
> +found:<br>
>       if (found) {<br>
>                  if (CRASHDEBUG(1)) {<br>
>                       fprintf(fp, "verify_namelist:\n");<br>
> @@ -11770,3 +11783,31 @@ check_vmcoreinfo(void)<br>
>               }<br>
>       }<br>
>  }<br>
> +<br>
> +static<br>
> +int get_linux_banner_from_vmlinux(char *buf, size_t size)<br>
> +{<br>
> +     struct bfd_section *sect;<br>
> +     long offset;<br>
> +<br>
> +     sect = bfd_get_section_by_name(st->bfd, ".rodata");<br>
> +     if (!sect)<br>
> +             return FALSE;<br>
> +<br>
> +     /*<br>
> +      * Although symbol_value() returns dynamic symbol value that<br>
> +      * is affected by kaslr, which is different from static symbol<br>
> +      * value in vmlinux file, but relative offset to linux_banner<br>
> +      * object in .rodata section is idential.<br>
> +      */<br>
> +     offset = symbol_value("linux_banner") - symbol_value(".rodata");<br>
> +<br>
> +     if (!bfd_get_section_contents(st->bfd,<br>
> +                                   sect,<br>
> +                                   buf,<br>
> +                                   offset,<br>
> +                                   size))<br>
> +             return FALSE;<br>
> +<br>
> +     return TRUE;<br>
> +}<br>
> -- <br>
> 2.31.1<br>
><br>
><br>
><br>
> --<br>
> Crash-utility mailing list<br>
> <a href="mailto:Crash-utility@redhat.com" target="_blank">Crash-utility@redhat.com</a><br>
> <a href="https://listman.redhat.com/mailman/listinfo/crash-utility" rel="noreferrer" target="_blank">https://listman.redhat.com/mailman/listinfo/crash-utility</a><br>
> Contribution Guidelines: <a href="https://github.com/crash-utility/crash/wiki" rel="noreferrer" target="_blank">https://github.com/crash-utility/crash/wiki</a><br>
<br>
Hi,<br>
<br>
this patch broke crash-utility on s390.<br>
When i try to open a dump file, then i get this error message:<br>
<br>
crash: cannot resolve ".rodata"<br>
<br></blockquote><div><br></div><div>Thank you for pointing out this issue,  Alex.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Any idea why .rodata symbol is missing ?<br>
Maybe test for its existence first ?<br></blockquote><div><br></div><div>Does the following patch work for you?</div><div><br></div>diff --git a/kernel.c b/kernel.c<br>index 92434a3..b504564 100644<br>--- a/kernel.c<br>+++ b/kernel.c<br>@@ -11790,6 +11790,9 @@ int get_linux_banner_from_vmlinux(char *buf, size_t size)<br>        struct bfd_section *sect;<br>        long offset;<br> <br>+       if (!symbol_exists(".rodata"))<br>+               return FALSE;<br>+<br>        sect = bfd_get_section_by_name(st->bfd, ".rodata");<br>        if (!sect)<br>                return FALSE;<br><div> </div><div>Thanks.</div><div>Lianbo</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Regards<br>
Alex<br>
<br>
<br>
<br>
------------------------------<br>
<br>
Subject: Digest Footer<br>
<br>
--<br>
Crash-utility mailing list<br>
<a href="mailto:Crash-utility@redhat.com" target="_blank">Crash-utility@redhat.com</a><br>
<a href="https://listman.redhat.com/mailman/listinfo/crash-utility" rel="noreferrer" target="_blank">https://listman.redhat.com/mailman/listinfo/crash-utility</a><br>
<br>
<br>
------------------------------<br>
<br>
End of Crash-utility Digest, Vol 198, Issue 33<br>
**********************************************<br>
<br>
</blockquote></div></div>