Limit the size of vmcore-dmesg.txt to 2G
Subsystems (2)
v2 cover Limit the size of vmcore-dmesg.txt to 2G
[PATCH 1/4] Cleanup: remove the read_elf_kcore()
Here, no need to wrap the read_elf() again, lets invoke it directly. So remove the read_elf_kcore() and clean up redundant code.
[PATCH 2/4] Fix an error definition about the variable 'fname' The variable 'fname' is mistakenly defined two twice, the first definition is in the vmcore-dmesg.c, and the second definition is in the elf_info.c. That is confused and incorrect although it's a static type, because the value of variable 'fname' is not assigned(set) in elf_info.c. Anyway, its value will be always 'null' when printing an error information.
[PATCH 3/4] Cleanup: move it back from util_lib/elf_info.c Some code related to vmcore-dmesg.c is put into the util_lib, which is not very reasonable, so lets move it back and tidy up those code. In addition, that will also help to limit the size of vmcore-dmesg.txt.
[PATCH 4/4] Limit the size of vmcore-dmesg.txt to 2G With some corrupted vmcore files, the vmcore-dmesg.txt file may grow forever till the kdump disk becomes full. Lets limit the size of vmcore-dmesg.txt to avoid such problems.
BTW: I tested this patch series on x86 64 and arm64, it also worked well.
Changes since v1:
[1] split them([patch 1/4] and [patch 2/4]) into a separate patch.
[2] remove a typedef definition for handler.
[3] remove some changes of variable 'fname' and fix its error.
Lianbo Jiang (4):
Cleanup: remove the read_elf_kcore()
Fix an error definition about the variable 'fname'
Cleanup: move it back from util_lib/elf_info.c Limit the size of vmcore-dmesg.txt to 2G
kexec/arch/arm64/kexec-arm64.c | 2 +- util_lib/elf_info.c | 65 ++++++++-------------------------- util_lib/include/elf_info.h | 4 +-- vmcore-dmesg/vmcore-dmesg.c | 42 ++++++++++++++++++++-- 4 files changed, 57 insertions(+), 56 deletions(-)
Signature · 7 lines
2.17.1 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
PATCH v2 1/4 Cleanup: remove the read_elf_kcore()
Here, no need to wrap the read_elf() again, lets invoke it directly. So remove the read_elf_kcore() and clean up redundant code.
--- kexec/arch/arm64/kexec-arm64.c | 2 +- util_lib/elf_info.c | 15 ++------------- util_lib/include/elf_info.h | 2 +- 3 files changed, 4 insertions(+), 15 deletions(-)
kexec/arch/arm64/kexec-arm64.c +1 -1
@@ -889,7 +889,7 @@ int get_phys_base_from_pt_load(unsigned long *phys_offset)return EFAILED ; } -read_elf_kcore (fd); +read_elf (fd); for (i = 0; get_pt_load(i, &phys_start, NULL, &virt_start, NULL);
util_lib/elf_info.c +2 -13
@@ -764,7 +764,7 @@ static void dump_dmesg(int fd)dump_dmesg_legacy (fd); } -static int read_elf (int fd) +int read_elf (int fd) {int ret;
@@ -824,24 +824,13 @@ int read_elf_vmcore(int fd)return 0 ; } -int read_elf_kcore (int fd) -{ -int ret; - - ret =read_elf (fd); -if (ret !=0 ) -return ret; - -return 0 ; -} -int read_phys_offset_elf_kcore (int fd,unsigned long *phys_off) {int ret; *phys_off =UINT64_MAX ; - ret =read_elf_kcore (fd); + ret =read_elf (fd);if (!ret) {/* If we have a valid 'PHYS_OFFSET' by now, * return it to the caller now.
util_lib/include/elf_info.h +1 -1
@@ -29,7 +29,7 @@ int get_pt_load(int idx,unsigned long long *virt_start, unsigned long long *virt_end);int read_phys_offset_elf_kcore (int fd,unsigned long *phys_off); -int read_elf_kcore (int fd); +int read_elf (int fd);int read_elf_vmcore (int fd);#endif /* ELF_INFO_H */
Signature · 7 lines
2.17.1 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
PATCH v2 2/4 Fix an error definition about the variable 'fname'
In reply to Lianbo JiangThe variable 'fname' is mistakenly defined two twice, the first definition is in the vmcore-dmesg.c, and the second definition is in the elf_info.c. That is confused and incorrect although it's a static type, because the value of variable 'fname' is not assigned(set) in elf_info.c. Anyway, its value will be always 'null' when printing an error information.
--- util_lib/elf_info.c | 2 +- vmcore-dmesg/vmcore-dmesg.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
util_lib/elf_info.c +1 -1
@@ -20,7 +20,7 @@/* The 32bit and 64bit note headers make it clear we don't care */ typedef Elf32_Nhdr Elf_Nhdr ; -static const char *fname; +const char *fname;static Elf64_Ehdr ehdr;static Elf64_Phdr *phdr;static int num_pt_loads;
vmcore-dmesg/vmcore-dmesg.c +1 -1
@@ -3,7 +3,7 @@/* The 32bit and 64bit note headers make it clear we don't care */ typedef Elf32_Nhdr Elf_Nhdr ; -static const char *fname; +extern const char *fname;int main (int argc,char **argv) {
Signature · 7 lines
2.17.1 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
PATCH v2 3/4 Cleanup: move it back from util_lib/elf_info.c
In reply to Lianbo JiangSome code related to vmcore-dmesg.c is put into the util_lib, which is not very reasonable, so lets move it back and tidy up those code.
In addition, that will also help to limit the size of vmcore-dmesg.txt in vmcore-dmesg.c instead of elf_info.c.
--- util_lib/elf_info.c | 48 +++++++++---------------------------- util_lib/include/elf_info.h | 2 +- vmcore-dmesg/vmcore-dmesg.c | 30 ++++++++++++++++++++++- 3 files changed, 41 insertions(+), 39 deletions(-)
util_lib/elf_info.c +11 -37
@@ -531,19 +531,7 @@ static int32_t read_file_s32(int fd, uint64_t addr)return read_file_u32 (fd, addr); } -static void write_to_stdout (char *buf,unsigned int nr) -{ -ssize_t ret; - - ret =write (STDOUT_FILENO , buf, nr); -if (ret != nr) { -fprintf (stderr,"Failed to write out the dmesg log buffer!:" -" %s\n" ,strerror (errno)); -exit (54 ); - } -} - -static void dump_dmesg_legacy (int fd) +static void dump_dmesg_legacy (int fd,void (*handler)(char *,unsigned int )) {uint64_t log_buf, log_buf_offset;unsigned log_end, logged_chars, log_end_wrapped;
@@ -604,7 +592,8 @@ static void dump_dmesg_legacy(int fd)*/ logged_chars = log_end < log_buf_len ? log_end : log_buf_len; -write_to_stdout (buf + (log_buf_len - logged_chars), logged_chars); +if (handler) +handler (buf + (log_buf_len - logged_chars), logged_chars); }static inline uint16_t struct_val_u16 (char *ptr,unsigned int offset)
@@ -623,7 +612,7 @@ static inline uint64_t struct_val_u64(char *ptr, unsigned int offset) }/* Read headers of log records and dump accordingly */ -static void dump_dmesg_structured (int fd) +static void dump_dmesg_structured (int fd,void (*handler)(char *,unsigned int )) {#define OUT_BUF_SIZE 4096uint64_t log_buf, log_buf_offset, ts_nsec;
@@ -733,7 +722,8 @@ static void dump_dmesg_structured(int fd) out_buf[len++] = c;if (len >=OUT_BUF_SIZE -64 ) { -write_to_stdout (out_buf, len); +if (handler) +handler (out_buf, len); len =0 ; } }
@@ -752,16 +742,16 @@ static void dump_dmesg_structured(int fd) current_idx += loglen; }free (buf); -if (len) -write_to_stdout (out_buf, len); +if (len && handler) +handler (out_buf, len); } -static void dump_dmesg (int fd) +void dump_dmesg (int fd,void (*handler)(char *,unsigned int )) {if (log_first_idx_vaddr) -dump_dmesg_structured (fd); +dump_dmesg_structured (fd, handler);else -dump_dmesg_legacy (fd); +dump_dmesg_legacy (fd, handler); }int read_elf (int fd)
@@ -808,22 +798,6 @@ int read_elf(int fd)return 0 ; } -int read_elf_vmcore (int fd) -{ -int ret; - - ret =read_elf (fd); -if (ret >0 ) { -fprintf (stderr,"Unable to read ELF information" -" from vmcore\n" ); -return ret; - } - -dump_dmesg (fd); - -return 0 ; -} -int read_phys_offset_elf_kcore (int fd,unsigned long *phys_off) {int ret;
util_lib/include/elf_info.h +1 -1
@@ -30,6 +30,6 @@ int get_pt_load(int idx, unsigned long long *virt_end);int read_phys_offset_elf_kcore (int fd,unsigned long *phys_off);int read_elf (int fd); -int read_elf_vmcore (int fd); +void dump_dmesg (int fd,void (*handler)(char *,unsigned int ));#endif /* ELF_INFO_H */
vmcore-dmesg/vmcore-dmesg.c +29 -1
@@ -5,6 +5,34 @@ typedef Elf32_Nhdr Elf_Nhdr;extern const char *fname; +static void write_to_stdout (char *buf,unsigned int nr) +{ +ssize_t ret; + + ret =write (STDOUT_FILENO , buf, nr); +if (ret != nr) { +fprintf (stderr,"Failed to write out the dmesg log buffer!:" +" %s\n" ,strerror (errno)); +exit (54 ); + } +} + +static int read_vmcore_dmesg (int fd,void (*handler)(char *,unsigned int )) +{ +int ret; + + ret =read_elf (fd); +if (ret >0 ) { +fprintf (stderr,"Unable to read ELF information" +" from vmcore\n" ); +return ret; + } + +dump_dmesg (fd, handler); + +return 0 ; +} +int main (int argc,char **argv) {ssize_t ret;
@@ -23,7 +51,7 @@ int main(int argc, char **argv)return 2 ; } - ret =read_elf_vmcore (fd); + ret =read_vmcore_dmesg (fd, write_to_stdout);close (fd);
Signature · 7 lines
2.17.1 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
PATCH v2 4/4 Limit the size of vmcore-dmesg.txt to 2G
In reply to Lianbo JiangWith some corrupted vmcore files, the vmcore-dmesg.txt file may grow forever till the kdump disk becomes full, and also probably causes
the disk error messages as follow:
...
sd 0:0:0:0: [sda] tag#6 FAILED Result: hostbyte=DID_BAD_TARGET driverbyte=DRIVER_OK sd 0:0:0:0: [sda] tag#6 CDB: Read(10) 28 00 08 06 4c 98 00 00 08 00blk_update_request: I/O error, dev sda, sector 134630552
sd 0:0:0:0: [sda] tag#7 FAILED Result: hostbyte=DID_BAD_TARGET driverbyte=DRIVER_OK sd 0:0:0:0: [sda] tag#7 CDB: Read(10) 28 00 08 06 4c 98 00 00 08 00blk_update_request: I/O error, dev sda, sector 134630552
...
If vmcore-dmesg.txt occupies the whole disk, the vmcore can not be saved, this is also a problem.
Lets limit the size of vmcore-dmesg.txt to avoid such problems.
--- vmcore-dmesg/vmcore-dmesg.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
vmcore-dmesg/vmcore-dmesg.c +10 -0
@@ -5,9 +5,19 @@ typedef Elf32_Nhdr Elf_Nhdr;extern const char *fname; +/* stole this macro from kernel printk.c */ +#define LOG_BUF_LEN_MAX (uint32_t)(1 << 31) +static void write_to_stdout (char *buf,unsigned int nr) {ssize_t ret; +static uint32_t n_bytes =0 ; + + n_bytes += nr; +if (n_bytes >LOG_BUF_LEN_MAX ) { +fprintf (stderr,"The vmcore-dmesg.txt over 2G in size is not supported.\n" ); +exit (53 ); + } ret =write (STDOUT_FILENO , buf, nr);if (ret != nr) {
Signature · 7 lines
2.17.1 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Hi, Simon and other reviewers, any comment about v2?
Thanks.
Lianbo
Quoted 34 lines
[PATCH 1/4] Cleanup: remove the
read_elf_kcore()
Here, no need to wrap theread_elf()again, lets invoke it directly. So remove theread_elf_kcore()and clean up redundant code.[PATCH 2/4] Fix an error definition about the variable 'fname' The variable 'fname' is mistakenly defined two twice, the first definition is in the
vmcore-dmesg.c, and the second definition is in theelf_info.c. That is confused and incorrect although it's a static type, because the value of variable 'fname' is not assigned(set) inelf_info.c. Anyway, its value will be always 'null' when printing an error information.[PATCH 3/4] Cleanup: move it back from
util_lib/elf_info.cSome code related tovmcore-dmesg.cis put into theutil_lib, which is not very reasonable, so lets move it back and tidy up those code. In addition, that will also help to limit the size of vmcore-dmesg.txt.[PATCH 4/4] Limit the size of vmcore-dmesg.txt to 2G With some corrupted vmcore files, the vmcore-dmesg.txt file may grow forever till the kdump disk becomes full. Lets limit the size of vmcore-dmesg.txt to avoid such problems.
BTW: I tested this patch series on x86 64 and arm64, it also worked well.
Changes since v1:
[1] splitthem([patch 1/4] and [patch 2/4])into a separate patch.
[2] remove a typedef definition for handler.
[3] remove some changes of variable 'fname' and fix its error.Lianbo Jiang (4):
Cleanup: remove theread_elf_kcore()
Fix an error definition about the variable 'fname'
Cleanup: move it back fromutil_lib/elf_info.cLimit the size of vmcore-dmesg.txt to 2G
Quoted 6 lines
kexec/arch/arm64/kexec-arm64.c | 2 +- util_lib/elf_info.c | 65 ++++++++-------------------------- util_lib/include/elf_info.h | 4 +-- vmcore-dmesg/vmcore-dmesg.c | 42 ++++++++++++++++++++-- 4 files changed, 57 insertions(+), 56 deletions(-)
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 1 line · lijiang
Hi, Simon and other reviewers, any comment about v2?
Hi,
sorry for the extended delay.
I will look over this.
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 8 lines · Simon Horman
Quoted 1 line · lijiang
Hi, Simon and other reviewers, any comment about v2?
Hi,
sorry for the extended delay.
I will look over this.
Never mind. Any suggestions will be appreciated.
Thank you in advance.
Lianbo
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 4 lines · lijiang
Quoted 3 lines · Simon Horman
Quoted 1 line · lijiang
Hi, Simon and other reviewers, any comment about v2?
Quoted 8 lines
Quoted 5 lines
Hi,
sorry for the extended delay.
I will look over this.Never mind. Any suggestions will be appreciated.
Thank you in advance.
Sorry once again for the delay.
I have applied this series.
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 10 lines · Simon Horman
Quoted 9 lines · lijiang
Quoted 8 lines · Simon Horman
Quoted 1 line · lijiang
Hi, Simon and other reviewers, any comment about v2?
Hi,
sorry for the extended delay.
I will look over this.
Quoted 8 lines
Quoted 3 lines
Never mind. Any suggestions will be appreciated.
Thank you in advance.
Sorry once again for the delay.
I have applied this series.
OK, thank you, Simon.
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec