kdump: force page alignment for per-CPU crash notes.
Subsystems (3)
PATCH 1/1 kdump: force page alignment for per-CPU crash notes.
Per-CPU allocations are not guaranteed to be physically contiguous. However, kdump kernel and user-space code assumes that per-CPU memory, used for saving CPU registers on crash, is.
This can cause corrupted /proc/vmcore in some cases - the main symptom being huge ELF note section.
Force page alignment for note_buf_t to ensure that this assumption holds.
--- kernel/kexec.c | 9 +++++++-- 1 files changed, 7 insertions(+), 2 deletions(-)
kernel/kexec.c +7 -2
@@ -1232,8 +1232,13 @@ void crash_save_cpu(struct pt_regs *regs, int cpu)static int __init crash_notes_memory_init (void ) { -/* Allocate memory for saving cpu registers. */ - crash_notes =alloc_percpu (note_buf_t); +/* Allocate memory for saving cpu registers. +* Force page alignment to avoid crossing physical page boundary - +* kexec-tools and kernel /proc/vmcore handler assume these per-CPU +* chunks are physically contiguous. +*/ + crash_notes = (note_buf_t __percpu *)__alloc_percpu (sizeof (note_buf_t), +PAGE_SIZE );if (!crash_notes) {printk ("Kexec: Memory allocation for saving cpu register" " states failed\n" );
Signature · 1 line
1.7.9.1
Quoted 7 lines · Eugene Surovegin
Per-CPU allocations are not guaranteed to be physically contiguous. However, kdump kernel and user-space code assumes that per-CPU memory, used for saving CPU registers on crash, is.
This can cause corrupted/proc/vmcorein some cases - the main symptom being huge ELF note section.Force page alignment for
note_buf_tto ensure that this assumption holds.
Ouch. I'm surprised there is an allocation on crash, perhaps it could at least be done earlier? And am I right in thinking that this change increases the likely hood that the allocation could fail?
Quoted 38 lines
Signed-off-by Eugene Surovegin <[email protected]>CC Eric Biederman <[email protected]>CC Vivek Goyal <[email protected]>CC kexec-list <[email protected]>--- kernel/kexec.c | 9 +++++++-- 1 files changed, 7 insertions(+), 2 deletions(-)kernel/kexec.c +7
-2@@ -1232,8 +1232,13 @@ void crash_save_cpu(struct pt_regs *regs, int cpu)static int __init crash_notes_memory_init (void ) { -/* Allocate memory for saving cpu registers. */ - crash_notes =alloc_percpu (note_buf_t); +/* Allocate memory for saving cpu registers. +* Force page alignment to avoid crossing physical page boundary - +* kexec-tools and kernel /proc/vmcore handler assume these per-CPU +* chunks are physically contiguous. +*/ + crash_notes = (note_buf_t __percpu *)__alloc_percpu (sizeof (note_buf_t), +PAGE_SIZE );if (!crash_notes) {printk ("Kexec: Memory allocation for saving cpu register" " states failed\n" );Signature · 7 lines
1.7.9.1 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Quoted 7 lines · Simon Horman
Quoted 6 lines · Eugene Surovegin
Per-CPU allocations are not guaranteed to be physically contiguous. However, kdump kernel and user-space code assumes that per-CPU memory, used for saving CPU registers on crash, is.
This can cause corrupted/proc/vmcorein some cases - the main symptom being huge ELF note section.
Quoted 7 lines
Quoted 1 line
Force page alignment for
note_buf_tto ensure that this assumption holds.Ouch. I'm surprised there is an allocation on crash, perhaps it could at least be done earlier? And am I right in thinking that this change increases the likely hood that the allocation could fail?
I'm not following. This allocation is done on start-up, not on crash. If you cannot allocate this much memory on system boot, I'm not sure what else you can do on this system....
Signature · 1 line
Eugene
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 17 lines · Eugene Surovegin
Quoted 7 lines · Simon Horman
Quoted 6 lines · Eugene Surovegin
Per-CPU allocations are not guaranteed to be physically contiguous. However, kdump kernel and user-space code assumes that per-CPU memory, used for saving CPU registers on crash, is.
This can cause corrupted/proc/vmcorein some cases - the main symptom being huge ELF note section.Quoted 7 lines
Quoted 1 line
Force page alignment for
note_buf_tto ensure that this assumption holds.Ouch. I'm surprised there is an allocation on crash, perhaps it could at least be done earlier? And am I right in thinking that this change increases the likely hood that the allocation could fail?
Quoted 3 lines
I'm not following. This allocation is done on start-up, not on crash. If you cannot allocate this much memory on system boot, I'm not sure what else you can do on this system....
Sorry, my eyes deceived me. You are correct and I agree.
Is it the case that note_buf_t is never larger than PAGE_SIZE? If so I your patch looks good to me.
Quoted 18 lines · Simon Horman
Quoted 17 lines · Eugene Surovegin
Quoted 14 lines · Simon Horman
Quoted 7 lines · Eugene Surovegin
Per-CPU allocations are not guaranteed to be physically contiguous. However, kdump kernel and user-space code assumes that per-CPU memory, used for saving CPU registers on crash, is.
This can cause corrupted/proc/vmcorein some cases - the main symptom being huge ELF note section.Force page alignment for
note_buf_tto ensure that this assumption holds.Ouch. I'm surprised there is an allocation on crash, perhaps it could at least be done earlier? And am I right in thinking that this change increases the likely hood that the allocation could fail?
Quoted 8 lines
Quoted 3 lines
I'm not following. This allocation is done on start-up, not on crash. If you cannot allocate this much memory on system boot, I'm not sure what else you can do on this system....
Sorry, my eyes deceived me. You are correct and I agree.
Is it the case that
note_buf_tis never larger thanPAGE_SIZE? If so I your patch looks good to me.
Currently, maximum note size is hardcoded in kexec-tools to 1024 (MAX_NOTE_BYTES).
Usually it's way less. IIRC on x86_64 it's 336 bytes.
--
Eugene
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
From: Eugene Surovegin <[email protected]>
Subject: Re: [PATCH] kdump: force page alignment for per-CPU crash notes.
Date: Wed, 29 Feb 2012 17:39:55 -0800
Quoted 23 lines · Simon Horman
Quoted 22 lines · Eugene Surovegin
Quoted 20 lines · Simon Horman
Quoted 8 lines · Eugene Surovegin
Quoted 6 lines
Per-CPU allocations are not guaranteed to be physically contiguous. However, kdump kernel and user-space code assumes that per-CPU memory, used for saving CPU registers on crash, is.
This can cause corrupted/proc/vmcorein some cases - the main symptom being huge ELF note section.Quoted 7 lines
Quoted 1 line
Force page alignment for
note_buf_tto ensure that this assumption holds.Ouch. I'm surprised there is an allocation on crash, perhaps it could at least be done earlier? And am I right in thinking that this change increases the likely hood that the allocation could fail?
I'm not following. This allocation is done on start-up, not on crash. If you cannot allocate this much memory on system boot, I'm not sure what else you can do on this system....
Quoted 9 lines
Quoted 4 lines
Sorry, my eyes deceived me. You are correct and I agree.
Is it the case that
note_buf_tis never larger thanPAGE_SIZE? If so I your patch looks good to me.Currently, maximum note size is hardcoded in kexec-tools to 1024 (
MAX_NOTE_BYTES).
Usually it's way less. IIRC onx86_64it's 336 bytes.
This is elf_prstatus and I guess it's mostly equal to registers.
crash> p sizeof(struct elf_prstatus)
$3 = 336
crash> ptype struct elf_prstatus
type = struct elf_prstatus {
struct elf_siginfo pr_info;
short int pr_cursig;
long unsigned int pr_sigpend;
long unsigned int pr_sighold;
pid_t pr_pid;
pid_t pr_ppid;
pid_t pr_pgrp;
pid_t pr_sid;
struct timeval pr_utime;
struct timeval pr_stime;
struct timeval pr_cutime;
struct timeval pr_cstime;
elf_gregset_t pr_reg; <-- this
int pr_fpvalid;
}What kinds of architecture does have so many registers? It's just my interest. Or possibly other kinds of notes is written here?
Thanks.
HATAYAMA, Daisuke
Quoted 59 lines · HATAYAMA Daisuke
From: Eugene Surovegin <[email protected]>
Subject: Re: [PATCH] kdump: force page alignment for per-CPU crash notes.
Date: Wed, 29 Feb 2012 17:39:55 -0800Quoted 23 lines · Simon Horman
Quoted 22 lines · Eugene Surovegin
Quoted 20 lines · Simon Horman
Quoted 8 lines · Eugene Surovegin
Quoted 6 lines
Per-CPU allocations are not guaranteed to be physically contiguous. However, kdump kernel and user-space code assumes that per-CPU memory, used for saving CPU registers on crash, is.
This can cause corrupted/proc/vmcorein some cases - the main symptom being huge ELF note section.Quoted 7 lines
Quoted 1 line
Force page alignment for
note_buf_tto ensure that this assumption holds.Ouch. I'm surprised there is an allocation on crash, perhaps it could at least be done earlier? And am I right in thinking that this change increases the likely hood that the allocation could fail?
I'm not following. This allocation is done on start-up, not on crash. If you cannot allocate this much memory on system boot, I'm not sure what else you can do on this system....
Quoted 9 lines
Quoted 4 lines
Sorry, my eyes deceived me. You are correct and I agree.
Is it the case that
note_buf_tis never larger thanPAGE_SIZE? If so I your patch looks good to me.Currently, maximum note size is hardcoded in kexec-tools to 1024 (
MAX_NOTE_BYTES).
Usually it's way less. IIRC onx86_64it's 336 bytes.This is
elf_prstatusand I guess it's mostly equal to registers.crash> p
sizeof(struct elf_prstatus)
$3 = 336
crash> ptype structelf_prstatus
type = structelf_prstatus{
structelf_siginfopr_info;
short intpr_cursig;
long unsigned intpr_sigpend;
long unsigned intpr_sighold;
pid_tpr_pid;
pid_tpr_ppid;
pid_tpr_pgrp;
pid_tpr_sid;
struct timevalpr_utime;
struct timevalpr_stime;
struct timevalpr_cutime;
struct timevalpr_cstime;
elf_gregset_tpr_reg; <-- this
intpr_fpvalid;
}
Quoted 2 lines
What kinds of architecture does have so many registers? It's just my interest. Or possibly other kinds of notes is written here?
I'm not sure about other archs, but we don't write there anything except for 'elf_prstatus' and sentinel "final" note.
--
Eugene
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 35 lines · HATAYAMA Daisuke
From: Eugene Surovegin <[email protected]>
Subject: Re: [PATCH] kdump: force page alignment for per-CPU crash notes.
Date: Wed, 29 Feb 2012 17:39:55 -0800Quoted 31 lines · Simon Horman
Quoted 18 lines · Eugene Surovegin
Quoted 17 lines · Simon Horman
Quoted 15 lines · Eugene Surovegin
Quoted 7 lines
Per-CPU allocations are not guaranteed to be physically contiguous. However, kdump kernel and user-space code assumes that per-CPU memory, used for saving CPU registers on crash, is.
This can cause corrupted/proc/vmcorein some cases - the main symptom being huge ELF note section.Force page alignment for
note_buf_tto ensure that this assumption holds.Ouch. I'm surprised there is an allocation on crash, perhaps it could at least be done earlier? And am I right in thinking that this change increases the likely hood that the allocation could fail?
Quoted 8 lines
Quoted 3 lines
I'm not following. This allocation is done on start-up, not on crash. If you cannot allocate this much memory on system boot, I'm not sure what else you can do on this system....
Sorry, my eyes deceived me. You are correct and I agree.
Is it the case that
note_buf_tis never larger thanPAGE_SIZE? If so I your patch looks good to me.Currently, maximum note size is hardcoded in kexec-tools to 1024 (
MAX_NOTE_BYTES).
Usually it's way less. IIRC onx86_64it's 336 bytes.
I presume that MAX_NOTE_BYTES was chosen to be large to minimise the chance that it would ever need to be changed.
Quoted 22 lines
This is
elf_prstatusand I guess it's mostly equal to registers.crash> p
sizeof(struct elf_prstatus)
$3 = 336
crash> ptype structelf_prstatustype = struct elf_prstatus { struct elf_siginfo pr_info; short int pr_cursig; long unsigned int pr_sigpend; long unsigned int pr_sighold; pid_t pr_pid; pid_t pr_ppid; pid_t pr_pgrp; pid_t pr_sid; struct timeval pr_utime; struct timeval pr_stime; struct timeval pr_cutime; struct timeval pr_cstime; elf_gregset_t pr_reg; <-- this int pr_fpvalid; }
Quoted 2 lines
What kinds of architecture does have so many registers? It's just my interest. Or possibly other kinds of notes is written here?
The winner seems to be ia64 with 128.
Simon Horman
Reviewed-byQuoted 23 lines · Eugene Surovegin
Quoted 22 lines · Simon Horman
Quoted 20 lines · Eugene Surovegin
Quoted 7 lines · Simon Horman
Quoted 6 lines · Eugene Surovegin
Per-CPU allocations are not guaranteed to be physically contiguous. However, kdump kernel and user-space code assumes that per-CPU memory, used for saving CPU registers on crash, is.
This can cause corrupted/proc/vmcorein some cases - the main symptom being huge ELF note section.Quoted 7 lines
Quoted 1 line
Force page alignment for
note_buf_tto ensure that this assumption holds.Ouch. I'm surprised there is an allocation on crash, perhaps it could at least be done earlier? And am I right in thinking that this change increases the likely hood that the allocation could fail?
I'm not following. This allocation is done on start-up, not on crash. If you cannot allocate this much memory on system boot, I'm not sure what else you can do on this system....
Quoted 8 lines
Quoted 4 lines
Sorry, my eyes deceived me. You are correct and I agree.
Is it the case that
note_buf_tis never larger thanPAGE_SIZE? If so I your patch looks good to me.Currently, maximum note size is hardcoded in kexec-tools to 1024 (
MAX_NOTE_BYTES).
Usually it's way less. IIRC onx86_64it's 336 bytes.
Ok, understood.
Quoted 8 lines · Eugene Surovegin
Per-CPU allocations are not guaranteed to be physically contiguous. However, kdump kernel and user-space code assumes that per-CPU memory, used for saving CPU registers on crash, is.
This can cause corrupted/proc/vmcorein some cases - the main symptom being huge ELF note section.Force page alignment for
note_buf_tto ensure that this assumption holds.
Hi Eugene,
Where do we make assumption that crash_notes address is page aligned?
In first kernel we save notes using virtual addresses as returned by per_cpu_ptr(). So first kernel should be fine (crash_save_cpu()).
In second kernel, fs/proc/vmcore.c code does not seem to be assuming that notes are stored as page aligned address.
merge_note_headers_elf64()
read_from_oldmem()
offset = (unsigned long)(*ppos % PAGE_SIZE);
pfn = (unsigned long)(*ppos / PAGE_SIZE);We see to calculate pfn and offset inside the page. Map the pfn and then access offset.
So as long as whole of the note section is stored on a single physical page it is not a problem.
Are you referring to the fact that note could be stored on two different physical pages and then kexec-tools does not know about the physical address of second page, hence second kernel does not know about it and we never read that data. That sounds like a problem.
So it make sense to force the page size alignment and if notes ever grow beyond 1 page, we need to come up with more complex ways of communicating more than 1 physical address to second kernel.
Thanks
Vivek
Quoted 30 lines
Signed-off-by Eugene Surovegin <[email protected]>CC Eric Biederman <[email protected]>CC Vivek Goyal <[email protected]>CC kexec-list <[email protected]>--- kernel/kexec.c | 9 +++++++-- 1 files changed, 7 insertions(+), 2 deletions(-)kernel/kexec.c +7
-2@@ -1232,8 +1232,13 @@ void crash_save_cpu(struct pt_regs *regs, int cpu)static int __init crash_notes_memory_init (void ) { -/* Allocate memory for saving cpu registers. */ - crash_notes =alloc_percpu (note_buf_t); +/* Allocate memory for saving cpu registers. +* Force page alignment to avoid crossing physical page boundary - +* kexec-tools and kernel /proc/vmcore handler assume these per-CPU +* chunks are physically contiguous. +*/ + crash_notes = (note_buf_t __percpu *)__alloc_percpu (sizeof (note_buf_t), +PAGE_SIZE );if (!crash_notes) {printk ("Kexec: Memory allocation for saving cpu register" " states failed\n" );Signature · 1 line
1.7.9.1
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 7 lines · Vivek Goyal
Quoted 6 lines · Eugene Surovegin
Per-CPU allocations are not guaranteed to be physically contiguous. However, kdump kernel and user-space code assumes that per-CPU memory, used for saving CPU registers on crash, is.
This can cause corrupted/proc/vmcorein some cases - the main symptom being huge ELF note section.
Quoted 6 lines
Quoted 2 lines
Force page alignment for
note_buf_tto ensure that this assumption holds.Hi Eugene,
Where do we make assumption that
crash_notesaddress is page aligned?
I never said that. I said that assumption was that note chunks were physically contiguous.
[snip]
Quoted 4 lines
Are you referring to the fact that note could be stored on two different physical pages and then kexec-tools does not know about the physical address of second page, hence second kernel does not know about it and we never read that data. That sounds like a problem.
Yes. This is exactly what happens in some cases.
Quoted 3 lines
So it make sense to force the page size alignment and if notes ever grow beyond 1 page, we need to come up with more complex ways of communicating more than 1 physical address to second kernel.
Yes. Thankfully notes so far are smaller than a page.
And if they do grow larger, than kexec-tools have to be modified anyways - currently maximum note size (1K) is hardcoded there. If this happens, I think instead of coming up with a way to communicate phys to virt mapping, it'd be easier just to change th way notes are allocated in the kernel so they are phys contiguous.
--
Eugene
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Vivek Goyal
Acked-byQuoted 18 lines · Eugene Surovegin
Quoted 7 lines · Vivek Goyal
Quoted 6 lines · Eugene Surovegin
Per-CPU allocations are not guaranteed to be physically contiguous. However, kdump kernel and user-space code assumes that per-CPU memory, used for saving CPU registers on crash, is.
This can cause corrupted/proc/vmcorein some cases - the main symptom being huge ELF note section.Quoted 6 lines
Quoted 2 lines
Force page alignment for
note_buf_tto ensure that this assumption holds.Hi Eugene,
Where do we make assumption that
crash_notesaddress is page aligned?I never said that. I said that assumption was that note chunks were physically contiguous.
Quoted 8 lines
[snip]
Quoted 4 lines
Are you referring to the fact that note could be stored on two different physical pages and then kexec-tools does not know about the physical address of second page, hence second kernel does not know about it and we never read that data. That sounds like a problem.
Yes. This is exactly what happens in some cases.
Ok. Thanks for clarifying. Patch looks good to me.
Vivek
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec