Skip to contentSkip to conversation

makedumpfile: Clean up unused code

PATCH Applied Petr Tesarik 2 participants 7 messages Oct 7, 2020 – Oct 15, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover makedumpfile: Clean up unused code

I have noticed that some code in makedumpfile is either unused, or not really needed for correct operation. I suggest to remove that code, so other people don't have to waste time wondering why it is there.

Petr Tesarik (3):
Cleanup: Remove a superfluous seek to physical address 0
Cleanup: Remove unused elf_info.c functions
Cleanup: Remove offset_pt_load_memory

 elf_info.c     | 83 --------------------------------------------------
 elf_info.h     |  4 ---
 makedumpfile.c | 11 -------
 3 files changed, 98 deletions(-)
Signature · 7 lines
2.26.2


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
#1 lore raw

PATCH 1/3 Cleanup: Remove a superfluous seek to physical address 0

The file position is updated for each page in readmem() via a read_pfn(). There is no point in seeking to PFN 0 data first.

---
 makedumpfile.c | 11 -----------
 1 file changed, 11 deletions(-)
makedumpfile.c +0 -11
index 4c4251e..cdde040 100644
@@ -8385,7 +8385,6 @@ write_kdump_pages_cyclic(struct cache_data *cd_header, struct cache_data *cd_pag
 	unsigned char buf[info->page_size], *buf_out = NULL;
 	unsigned long len_buf_out;
 	struct timespec ts_start;
-	const off_t failed = (off_t)-1;
 	int ret = FALSE;
 	z_stream z_stream, *stream = NULL;
 #ifdef USELZO
@@ -8422,16 +8421,6 @@ write_kdump_pages_cyclic(struct cache_data *cd_header, struct cache_data *cd_pag
 	per = info->num_dumpable / 10000;
 	per = per ? per : 1;
 
-	/*
-	 * Set a fileoffset of Physical Address 0x0.
-	 */
-	if (lseek(info->fd_memory, get_offset_pt_load_memory(), SEEK_SET)
-	    == failed) {
-		ERRMSG("Can't seek the dump memory(%s). %s\n",
-		       info->name_memory, strerror(errno));
-		goto out;
-	}
-
 	start_pfn = cycle->start_pfn;
 	end_pfn   = cycle->end_pfn;
 
Signature · 7 lines
2.26.2


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
#2 lore raw

PATCH 2/3 Cleanup: Remove unused elf_info.c functions

In reply to Petr Tesarik

These functions are unused and can be removed:

- page_head_to_phys_start
- page_head_to_phys_end
- offset_to_pt_load_start
- get_offset_pt_load_memory

---
 elf_info.c | 66 ------------------------------------------------------
 elf_info.h |  4 ----
 2 files changed, 70 deletions(-)
elf_info.c +0 -66
index 7d72742..5ed65fc 100644
@@ -502,66 +502,6 @@ paddr_to_offset2(unsigned long long paddr, off_t hint)
 	return offset;
 }
 
-unsigned long long
-page_head_to_phys_start(unsigned long long head_paddr)
-{
-	int i;
-	struct pt_load_segment *pls;
-
-	for (i = 0; i < num_pt_loads; i++) {
-		pls = &pt_loads[i];
-		if ((pls->phys_start <= head_paddr + info->page_size)
-		    && (head_paddr < pls->phys_end)) {
-			return (pls->phys_start > head_paddr) ?
-				pls->phys_start : head_paddr;
-		}
-	}
-
-	return 0;
-}
-
-unsigned long long
-page_head_to_phys_end(unsigned long long head_paddr)
-{
-	int i;
-	struct pt_load_segment *pls;
-
-	for (i = 0; i < num_pt_loads; i++) {
-		pls = &pt_loads[i];
-		if ((pls->phys_start <= head_paddr + info->page_size)
-		    && (head_paddr < pls->phys_end)) {
-			return (pls->phys_end < head_paddr + info->page_size) ?
-				pls->phys_end : head_paddr + info->page_size;
-		}
-	}
-
-	return 0;
-}
-
-/*
- *  Calculate a start File Offset of PT_LOAD from a File Offset
- *  of a page. If this function returns 0x0, the input page is
- *  not in the memory image.
- */
-off_t
-offset_to_pt_load_start(off_t offset)
-{
-	int i;
-	off_t pt_load_start;
-	struct pt_load_segment *pls;
-
-	for (i = pt_load_start = 0; i < num_pt_loads; i++) {
-		pls = &pt_loads[i];
-		if ((offset >= pls->file_offset)
-		    && (offset < pls->file_offset +
-			(pls->phys_end - pls->phys_start))) {
-			pt_load_start = pls->file_offset;
-			break;
-		}
-	}
-	return pt_load_start;
-}
-
 /*
  *  Calculate a end File Offset of PT_LOAD from a File Offset
  *  of a page. If this function returns 0x0, the input page is
@@ -1120,12 +1060,6 @@ get_phdr_memory(int index, Elf64_Phdr *phdr)
 	return TRUE;
 }
 
-off_t
-get_offset_pt_load_memory(void)
-{
-	return offset_pt_load_memory;
-}
-
 int
 get_pt_load(int idx,
 	unsigned long long *phys_start,
elf_info.h +0 -4
index 934b608..d9b5d05 100644
@@ -32,9 +32,6 @@ int get_elf32_phdr(int fd, char *filename, int index, Elf32_Phdr *phdr);
 
 off_t paddr_to_offset(unsigned long long paddr);
 off_t paddr_to_offset2(unsigned long long paddr, off_t hint);
-unsigned long long page_head_to_phys_start(unsigned long long head_paddr);
-unsigned long long page_head_to_phys_end(unsigned long long head_paddr);
-off_t offset_to_pt_load_start(off_t offset);
 off_t offset_to_pt_load_end(off_t offset);
 unsigned long long vaddr_to_paddr_general(unsigned long long vaddr);
 off_t vaddr_to_offset_slow(int fd, char *filename, unsigned long long vaddr);
@@ -57,7 +54,6 @@ int is_xen_memory(void);
 int get_elf64_phnum(int fd, char *filename, Elf64_Ehdr *ehdr, int *phnum);
 int get_phnum_memory(void);
 int get_phdr_memory(int index, Elf64_Phdr *phdr);
-off_t get_offset_pt_load_memory(void);
 int get_pt_load(int idx,
 	unsigned long long *phys_start,
 	unsigned long long *phys_end,
Signature · 7 lines
2.26.2


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
#3 lore raw

PATCH 3/3 Cleanup: Remove offset_pt_load_memory

In reply to Petr Tesarik

After the previous commit, this variable has become write-only, so it is clearly no longer needed.

---
 elf_info.c | 17 -----------------
 1 file changed, 17 deletions(-)
elf_info.c +0 -17
index 5ed65fc..a6624b5 100644
@@ -63,7 +63,6 @@ static int			flags_memory;
  */
 static unsigned int		num_pt_loads;
 static struct pt_load_segment	*pt_loads;
-static off_t			offset_pt_load_memory;
 
 /*
  * PT_NOTE information about /proc/vmcore:
@@ -843,15 +842,6 @@ int get_kcore_dump_loads(void)
 			return FALSE;
 		}
 
-		if (j == 0) {
-			offset_pt_load_memory = p->file_offset;
-			if (offset_pt_load_memory == 0) {
-				ERRMSG("Can't get the offset of page data.\n");
-				free(pls);
-				return FALSE;
-			}
-		}
-
 		pls[j] = *p;
 		j++;
 	}
@@ -929,13 +919,6 @@ get_elf_info(int fd, char *filename)
 		if (phdr.p_type != PT_LOAD)
 			continue;
 
-		if (j == 0) {
-			offset_pt_load_memory = phdr.p_offset;
-			if (offset_pt_load_memory == 0) {
-				ERRMSG("Can't get the offset of page data.\n");
-				return FALSE;
-			}
-		}
 		if (j >= num_pt_loads)
 			return FALSE;
 		if(!dump_Elf_load(&phdr, j))
Signature · 7 lines
2.26.2


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
#4 lore raw

RE: [PATCH 3/3] Cleanup: Remove offset_pt_load_memory

Hi Petr,

Quoted 38 lines

-----Original Message-----
After the previous commit, this variable has become write-only, so it is clearly no longer needed.

---
 elf_info.c | 17 -----------------
 1 file changed, 17 deletions(-)
elf_info.c +0 -10
index 5ed65fc..a6624b5 100644
@@ -63,7 +63,6 @@ static int			flags_memory;
  */
 static unsigned int		num_pt_loads;
 static struct pt_load_segment	*pt_loads;
-static off_t			offset_pt_load_memory;
 
 /*
  * PT_NOTE information about /proc/vmcore:
@@ -843,15 +842,6 @@ int get_kcore_dump_loads(void)
 			return FALSE;
 		}
 
-		if (j == 0) {
-			offset_pt_load_memory = p->file_offset;
-			if (offset_pt_load_memory == 0) {
-				ERRMSG("Can't get the offset of page data.\n");
-				free(pls);
-				return FALSE;
-			}
-		}
-
 		pls[j] = *p;
 		j++;
 	}

elf_info.c get_elf_info(int fd, char *filename) · line 936

Quoted 8 lines
elf_info.c +0 -5
@@ -929,13 +919,6 @@ get_elf_info(int fd, char *filename)
 		if (phdr.p_type != PT_LOAD)
 			continue;
 
-		if (j == 0) {
-			offset_pt_load_memory = phdr.p_offset;
-			if (offset_pt_load_memory == 0) {
-				ERRMSG("Can't get the offset of page data.\n");
-				return FALSE;

I think this part is a kind of sanity check on ELF Phdr data, but checking only p_offset when j==0 doesn't make sense and there would be extremely rare cases where are aborted by this check, so it would be fine to remove completely.

So the patchset looks good to me.
Thank you for the cleanup!

Kazu

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#5 lore raw

RE: [PATCH 3/3] Cleanup: Remove offset_pt_load_memory

-----Original Message-----

Quoted 52 lines
Quoted 38 lines

-----Original Message-----
After the previous commit, this variable has become write-only, so it is clearly no longer needed.

---
 elf_info.c | 17 -----------------
 1 file changed, 17 deletions(-)
elf_info.c +0 -10
index 5ed65fc..a6624b5 100644
@@ -63,7 +63,6 @@ static int			flags_memory;
  */
 static unsigned int		num_pt_loads;
 static struct pt_load_segment	*pt_loads;
-static off_t			offset_pt_load_memory;
 
 /*
  * PT_NOTE information about /proc/vmcore:
@@ -843,15 +842,6 @@ int get_kcore_dump_loads(void)
 			return FALSE;
 		}
 
-		if (j == 0) {
-			offset_pt_load_memory = p->file_offset;
-			if (offset_pt_load_memory == 0) {
-				ERRMSG("Can't get the offset of page data.\n");
-				free(pls);
-				return FALSE;
-			}
-		}
-
 		pls[j] = *p;
 		j++;
 	}

elf_info.c get_elf_info(int fd, char *filename) · line 936

Quoted 8 lines
elf_info.c +0 -5
@@ -929,13 +919,6 @@ get_elf_info(int fd, char *filename)
 		if (phdr.p_type != PT_LOAD)
 			continue;
 
-		if (j == 0) {
-			offset_pt_load_memory = phdr.p_offset;
-			if (offset_pt_load_memory == 0) {
-				ERRMSG("Can't get the offset of page data.\n");
-				return FALSE;

I think this part is a kind of sanity check on ELF Phdr data, but checking only p_offset when j==0 doesn't make sense and there would be extremely rare cases where are aborted by this check, so it would be fine to remove completely.

Quoted 2 lines

So the patchset looks good to me.
Thank you for the cleanup!

Applied.
https://github.com/makedumpfile/makedumpfile/compare/64d2aee2c4654fa422633a683c1c3f2a8d3bf3a9...master

Thanks,
Kazu

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#6 lore raw

Re: [PATCH 3/3] Cleanup: Remove offset_pt_load_memory

Quoted 53 lines · On Thu, 15 Oct 2020 03:07:59 +0000 HAGIO KAZUHITO(萩尾 一仁) <[email protected]>…

-----Original Message-----

Quoted 52 lines
Quoted 38 lines

-----Original Message-----
After the previous commit, this variable has become write-only, so it is clearly no longer needed.

---
 elf_info.c | 17 -----------------
 1 file changed, 17 deletions(-)
elf_info.c +0 -10
index 5ed65fc..a6624b5 100644
@@ -63,7 +63,6 @@ static int			flags_memory;
  */
 static unsigned int		num_pt_loads;
 static struct pt_load_segment	*pt_loads;
-static off_t			offset_pt_load_memory;
 
 /*
  * PT_NOTE information about /proc/vmcore:
@@ -843,15 +842,6 @@ int get_kcore_dump_loads(void)
 			return FALSE;
 		}
 
-		if (j == 0) {
-			offset_pt_load_memory = p->file_offset;
-			if (offset_pt_load_memory == 0) {
-				ERRMSG("Can't get the offset of page data.\n");
-				free(pls);
-				return FALSE;
-			}
-		}
-
 		pls[j] = *p;
 		j++;
 	}

elf_info.c get_elf_info(int fd, char *filename) · line 936

Quoted 8 lines
elf_info.c +0 -5
@@ -929,13 +919,6 @@ get_elf_info(int fd, char *filename)
 		if (phdr.p_type != PT_LOAD)
 			continue;
 
-		if (j == 0) {
-			offset_pt_load_memory = phdr.p_offset;
-			if (offset_pt_load_memory == 0) {
-				ERRMSG("Can't get the offset of page data.\n");
-				return FALSE;  

I think this part is a kind of sanity check on ELF Phdr data, but checking only p_offset when j==0 doesn't make sense and there would be extremely rare cases where are aborted by this check, so it would be fine to remove completely.

Quoted 5 lines
Quoted 2 lines

So the patchset looks good to me.
Thank you for the cleanup!

Applied.
https://github.com/makedumpfile/makedumpfile/compare/64d2aee2c4654fa422633a683c1c3f2a8d3bf3a9...master

Thank you.

Petr T

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec