makedumpfile: call initial before use cache
Subsystems (2)
PATCH 1/1 makedumpfile: call initial before use cache
Run 'makedumpfile --mem-usage /proc/kcore' will coredump on ppc64, it is because show_mem_usage()->get_page_offset()->get_versiondep_info_ppc64() ->readmem() use cache before it is inited by initial().
Currently only ppc64 has this issue because onlyget_versiondep_info_ppc64() call readmem().
--- makedumpfile.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
makedumpfile.c +3 -3
@@ -12019,6 +12019,9 @@ int show_mem_usage(void)DEBUG_MSG ("Read vmcoreinfo from NOTE segment: %d\n" , vmcoreinfo); } +if (!initial ()) +return FALSE; +if (!get_page_offset ())return FALSE;
@@ -12034,9 +12037,6 @@ int show_mem_usage(void)return FALSE; } -if (!initial ()) -return FALSE; -if (!open_dump_bitmap ())return FALSE;
Signature · 7 lines
2.44.0 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Hi Lichen,
sorry for the long delay.
Quoted 27 lines · Lichen Liu
Run 'makedumpfile --mem-usage
/proc/kcore' will coredump on ppc64, it is because show_mem_usage()->get_page_offset()->get_versiondep_info_ppc64() ->readmem() use cache before it is inited byinitial().Currently only ppc64 has this issue because only
get_versiondep_info_ppc64()callreadmem().Signed-off-by Lichen Liu <[email protected]>--- makedumpfile.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)makedumpfile.c +3
-0@@ -12019,6 +12019,9 @@ int show_mem_usage(void)DEBUG_MSG ("Read vmcoreinfo from NOTE segment: %d\n" , vmcoreinfo); } +if (!initial ()) +return FALSE; +if (!get_page_offset ())return FALSE;
makedumpfile.c int show_mem_usage(void) · line 12042
Quoted 9 lines
makedumpfile.c +0
-3@@ -12034,9 +12037,6 @@ int show_mem_usage(void)return FALSE; } -if (!initial ()) -return FALSE; -if (!open_dump_bitmap ())return FALSE;
initial() needs to be called after set_kcore_vmcoreinfo(), when there is no vmcoreinfo in /proc/kcore ELF note.
So with the patch, "makedumpfile --mem-usage" fails on kernels that do not have a vmcoreinfo in ELF note, e.g. RHEL7 kernel:
# makedumpfile-dev -f --mem-usage /proc/kcore exclude_free_page: Can't get necessary symbols for excluding free pages.
makedumpfile Failed.
Probably readmem() should not be called before initial() in the first place. I think it's the root cause, but I'm not sure how we can fix it.
A workaround I thought of is that moving get_page_offset() and get_phys_base() into the !vmcoreinfo block. These are needed by set_kcore_vmcoreinfo(), so we can avoid calling them if there is a vmcoreinfo in ELF note:
makedumpfile.c +0 -0
@@ -12019,14 +12019,14 @@ int show_mem_usage(void) DEBUG_MSG("Read vmcoreinfo from NOTE segment: %d\n",
vmcoreinfo);
}- if (!get_page_offset())
- return FALSE;
+ if (!vmcoreinfo) {
+ if (!get_page_offset())
+ return FALSE;
- /* paddr_to_vaddr() on arm64 needs phys_base. */
- if (!get_phys_base())
- return FALSE; + /* paddr_to_vaddr() on arm64 needs phys_base. */ + if (!get_phys_base())
+ return FALSE;
- if (!vmcoreinfo) {
if (!get_sys_kernel_vmcoreinfo(&vmcoreinfo_addr,&vmcoreinfo_len))
return FALSE;
This will work only for 4.19 and later kernels, but might reduce users that hit the issue. Does this work for you?
Thanks,
Kazu
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Thanks for your explanation!
Quoted 89 lines · HAGIO KAZUHITO(萩尾 一仁)
Hi Lichen,
sorry for the long delay.
Quoted 27 lines · Lichen Liu
Run 'makedumpfile --mem-usage
/proc/kcore' will coredump on ppc64, it is because show_mem_usage()->get_page_offset()->get_versiondep_info_ppc64() ->readmem() use cache before it is inited byinitial().Currently only ppc64 has this issue because only
get_versiondep_info_ppc64()callreadmem().Signed-off-by Lichen Liu <[email protected]>--- makedumpfile.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)makedumpfile.c +3
-0@@ -12019,6 +12019,9 @@ int show_mem_usage(void)DEBUG_MSG ("Read vmcoreinfo from NOTE segment: %d\n" , vmcoreinfo); } +if (!initial ()) +return FALSE; +if (!get_page_offset ())return FALSE;makedumpfile.c int show_mem_usage(void) · line 12042
Quoted 9 lines
makedumpfile.c +0
-3@@ -12034,9 +12037,6 @@ int show_mem_usage(void)return FALSE; } -if (!initial ()) -return FALSE; -if (!open_dump_bitmap ())return FALSE;
initial()needs to be called afterset_kcore_vmcoreinfo(), when there is no vmcoreinfo in/proc/kcoreELF note.So with the patch, "makedumpfile --mem-usage" fails on kernels that do not have a vmcoreinfo in ELF note, e.g. RHEL7 kernel:
# makedumpfile-dev -f --mem-usage /proc/kcore exclude_free_page: Can't get necessary symbols for excluding free pages.makedumpfile Failed.
Probably
readmem()should not be called beforeinitial()in the first place. I think it's the root cause, but I'm not sure how we can fix it.A workaround I thought of is that moving
get_page_offset()andget_phys_base()into the !vmcoreinfo block. These are needed byset_kcore_vmcoreinfo(), so we can avoid calling them if there is a vmcoreinfo in ELF note:makedumpfile.c +6
-6@@ -12019,14 +12019,14 @@ int show_mem_usage(void)DEBUG_MSG ("Read vmcoreinfo from NOTE segment: %d\n" , vmcoreinfo); } -if (!get_page_offset ()) -return FALSE; +if (!vmcoreinfo) { +if (!get_page_offset ()) +return FALSE; -/* paddr_to_vaddr() on arm64 needs phys_base. */ -if (!get_phys_base ()) -return FALSE; +/* paddr_to_vaddr() on arm64 needs phys_base. */ +if (!get_phys_base ()) +return FALSE; -if (!vmcoreinfo) {if (!get_sys_kernel_vmcoreinfo (&vmcoreinfo_addr, &vmcoreinfo_len))return FALSE;
Quoted 2 lines
This will work only for 4.19 and later kernels, but might reduce users that hit the issue. Does this work for you?
That works for me because I'm testing for the 6.x kernel.
Thanks,
Lichen
Quoted 3 lines
Thanks,
Kazu
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 3 lines · Lichen Liu
Quoted 2 lines
This will work only for 4.19 and later kernels, but might reduce users that hit the issue. Does this work for you?
That works for me because I'm testing for the 6.x kernel.
Thanks for the check. Is the issue a segmentation fault? I've made a patch below, is this OK?
From 084742cba5b81da563074454ab8c879e8e411cb0 Mon Sep 17 00:00:00 2001
From: Kazuhito Hagio <[email protected]>
Date: Mon, 22 Jul 2024 14:31:43 +0900
Subject: [PATCH] Workaround for segfault by "makedumpfile --mem-usage" on PPC64
"makedumpfile --mem-usage /proc/kcore" can cause a segmentation fault on PPC64, because the readmem() of the following code path uses cache before it's initialized in initial().
show_mem_usage
get_page_offset
get_versiondep_info_ppc64
readmem
...
initial
cache_initThe get_page_offset() is needed to get vmcoreinfo from /proc/kcore data, so we can avoid calling it when a vmcoreinfo exists in the ELF NOTE segment of /proc/kcore, i.e. on Linux 4.19 and later.
(Note: for older kernels, we will need another way to fix it.)
--- makedumpfile.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
makedumpfile.c +6 -6
@@ -12019,14 +12019,14 @@ int show_mem_usage(void)DEBUG_MSG ("Read vmcoreinfo from NOTE segment: %d\n" , vmcoreinfo); } -if (!get_page_offset ()) -return FALSE; +if (!vmcoreinfo) { +if (!get_page_offset ()) +return FALSE; -/* paddr_to_vaddr() on arm64 needs phys_base. */ -if (!get_phys_base ()) -return FALSE; +/* paddr_to_vaddr() on arm64 needs phys_base. */ +if (!get_phys_base ()) +return FALSE; -if (!vmcoreinfo) {if (!get_sys_kernel_vmcoreinfo (&vmcoreinfo_addr, &vmcoreinfo_len))return FALSE;
Signature · 5 lines
2.31.1 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Yes, it works!
Thank you so much!
Quoted 66 lines · HAGIO KAZUHITO(萩尾 一仁)
Quoted 3 lines · Lichen Liu
Quoted 2 lines
This will work only for 4.19 and later kernels, but might reduce users that hit the issue. Does this work for you?
That works for me because I'm testing for the 6.x kernel.
Thanks for the check. Is the issue a segmentation fault? I've made a patch below, is this OK?
From
084742cba5b81da563074454ab8c879e8e411cb0Mon Sep 17 00:00:00 2001
From: Kazuhito Hagio <[email protected]>
Date: Mon, 22 Jul 2024 14:31:43 +0900
Subject: [PATCH] Workaround for segfault by "makedumpfile --mem-usage" on PPC64"makedumpfile --mem-usage
/proc/kcore" can cause a segmentation fault on PPC64, because thereadmem()of the following code path uses cache before it's initialized ininitial().show_mem_usage get_page_offset get_versiondep_info_ppc64 readmem ... initial cache_initThe
get_page_offset()is needed to get vmcoreinfo from/proc/kcoredata, so we can avoid calling it when a vmcoreinfo exists in the ELF NOTE segment of/proc/kcore, i.e. on Linux 4.19 and later.(Note: for older kernels, we will need another way to fix it.)
Reported-by Lichen Liu <[email protected]>Signed-off-by Kazuhito Hagio <[email protected]>--- makedumpfile.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)makedumpfile.c +6
-7@@ -12019,14 +12019,14 @@ int show_mem_usage(void)DEBUG_MSG ("Read vmcoreinfo from NOTE segment: %d\n" , vmcoreinfo); } -if (!get_page_offset ()) -return FALSE; +if (!vmcoreinfo) { +if (!get_page_offset ()) +return FALSE; -/* paddr_to_vaddr() on arm64 needs phys_base. */ -if (!get_phys_base ()) -return FALSE; +/* paddr_to_vaddr() on arm64 needs phys_base. */ +if (!get_phys_base ()) +return FALSE; -if (!vmcoreinfo) {if (!get_sys_kernel_vmcoreinfo (&vmcoreinfo_addr, &vmcoreinfo_len))return FALSE; --
Quoted 1 line
2.31.1
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
HAGIO KAZUHITO(萩尾 一仁)
AppliedQuoted 2 lines · Lichen Liu
Yes, it works!
Thank you so much!
Thanks, applied.
https://github.com/makedumpfile/makedumpfile/commit/900190de6b67b2de410cfc8023c1b198a416ceb3
Kazu
Quoted 64 lines
Quoted 61 lines · HAGIO KAZUHITO(萩尾 一仁)
Quoted 3 lines · Lichen Liu
Quoted 2 lines
This will work only for 4.19 and later kernels, but might reduce users that hit the issue. Does this work for you?
That works for me because I'm testing for the 6.x kernel.
Thanks for the check. Is the issue a segmentation fault? I've made a patch below, is this OK?
From
084742cba5b81da563074454ab8c879e8e411cb0Mon Sep 17 00:00:00 2001
From: Kazuhito Hagio <[email protected]>
Date: Mon, 22 Jul 2024 14:31:43 +0900
Subject: [PATCH] Workaround for segfault by "makedumpfile --mem-usage" on PPC64"makedumpfile --mem-usage
/proc/kcore" can cause a segmentation fault on PPC64, because thereadmem()of the following code path uses cache before it's initialized ininitial().show_mem_usage get_page_offset get_versiondep_info_ppc64 readmem ... initial cache_initThe
get_page_offset()is needed to get vmcoreinfo from/proc/kcoredata, so we can avoid calling it when a vmcoreinfo exists in the ELF NOTE segment of/proc/kcore, i.e. on Linux 4.19 and later.(Note: for older kernels, we will need another way to fix it.)
Reported-by Lichen Liu <[email protected]>Signed-off-by Kazuhito Hagio <[email protected]>--- makedumpfile.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)makedumpfile.c +6
-5@@ -12019,14 +12019,14 @@ int show_mem_usage(void)DEBUG_MSG ("Read vmcoreinfo from NOTE segment: %d\n" , vmcoreinfo); } -if (!get_page_offset ()) -return FALSE; +if (!vmcoreinfo) { +if (!get_page_offset ()) +return FALSE; -/* paddr_to_vaddr() on arm64 needs phys_base. */ -if (!get_phys_base ()) -return FALSE; +/* paddr_to_vaddr() on arm64 needs phys_base. */ +if (!get_phys_base ()) +return FALSE;
Quoted 6 lines
Quoted 6 lines
makedumpfile.c +0
-2-if (!vmcoreinfo) {if (!get_sys_kernel_vmcoreinfo (&vmcoreinfo_addr, &vmcoreinfo_len))return FALSE; --2.31.1
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec