Skip to contentSkip to conversation

kexec,x86: remove duplicate get_memory_ranges

PATCH Applied Zhang Yanfei 2 participants 5 messages Jan 11, 2013 – Jan 30, 2013

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

PATCH 1/2 kexec,x86: remove duplicate get_memory_ranges

At first, we have already filled the kexec_info.memory_ranges by calling my_load() -> get_memory_ranges(). So if we want to get the memory information, we could just use the existing one instead of calling get_memory_ranges again.

---
 kexec/arch/i386/kexec-bzImage.c       |    2 +-
 kexec/arch/i386/kexec-elf-x86.c       |    2 +-
 kexec/arch/i386/kexec-multiboot-x86.c |    7 ++-----
 kexec/arch/i386/x86-linux-setup.c     |   10 ++++------
 kexec/arch/i386/x86-linux-setup.h     |    4 ++--
 kexec/arch/x86_64/kexec-elf-x86_64.c  |    2 +-
 6 files changed, 11 insertions(+), 16 deletions(-)
kexec/arch/i386/kexec-bzImage.c +1 -1
index 0605909..83a023d 100644
@@ -324,7 +324,7 @@ int do_bzImage_load(struct kexec_info *info,
 
 	/* Fill in the information BIOS calls would normally provide. */
 	if (!real_mode_entry) {
-		setup_linux_system_parameters(real_mode, info->kexec_flags);
+		setup_linux_system_parameters(info, real_mode);
 	}
 
 	return 0;
kexec/arch/i386/kexec-elf-x86.c +1 -1
index 8bd5ef6..e62ebcb 100644
@@ -272,7 +272,7 @@ int elf_x86_load(int argc, char **argv, const char *buf, off_t len,
 			ramdisk_buf, ramdisk_length);
 
 		/* Fill in the information bios calls would usually provide */
-		setup_linux_system_parameters(&hdr->hdr, info->kexec_flags);
+		setup_linux_system_parameters(info, &hdr->hdr);
 
 		/* Initialize the registers */
 		elf_rel_get_symbol(&info->rhdr, "entry32_regs", &regs, sizeof(regs));
kexec/arch/i386/kexec-multiboot-x86.c +2 -5
index 23dab7b..de2a423 100644
@@ -248,11 +248,8 @@ int multiboot_x86_load(int argc, char **argv, const char *buf, off_t len,
 	mbi->boot_loader_name = sizeof(*mbi) + command_line_len; 
 
 	/* Memory map */
-	if ((get_memory_ranges(&range, &ranges, info->kexec_flags) < 0)
-			|| ranges == 0) {
-		fprintf(stderr, "Cannot get memory information\n");
-		return -1;
-	}
+	range = info->memory_range;
+	ranges = info->memory_ranges;
 	mmap = xmalloc(ranges * sizeof(*mmap));
 	for (i=0; i<ranges; i++) {
 		unsigned long long length;
kexec/arch/i386/x86-linux-setup.c +4 -6
index b7ab8ea..ef62553 100644
@@ -441,8 +441,8 @@ close:
 	close(data_file);
 }
 
-void setup_linux_system_parameters(struct x86_linux_param_header *real_mode,
-					unsigned long kexec_flags)
+void setup_linux_system_parameters(struct kexec_info *info,
+				   struct x86_linux_param_header *real_mode)
 {
 	/* Fill in information the BIOS would usually provide */
 	struct memory_range *range;
@@ -486,10 +486,8 @@ void setup_linux_system_parameters(struct x86_linux_param_header *real_mode,
 	/* another safe default */
 	real_mode->aux_device_info = 0;
 
-	/* Fill in the memory info */
-	if ((get_memory_ranges(&range, &ranges, kexec_flags) < 0) || ranges == 0) {
-		die("Cannot get memory information\n");
-	}
+	range = info->memory_range;
+	ranges = info->memory_ranges;
 	if (ranges > E820MAX) {
 		fprintf(stderr, "Too many memory ranges, truncating...\n");
 		ranges = E820MAX;
kexec/arch/i386/x86-linux-setup.h +2 -2
index 8862513..96fbd33 100644
@@ -7,8 +7,8 @@ void setup_linux_bootloader_parameters(
 	unsigned long real_mode_base, unsigned long cmdline_offset,
 	const char *cmdline, off_t cmdline_len,
 	const char *initrd_buf, off_t initrd_size);
-void setup_linux_system_parameters(struct x86_linux_param_header *real_mode,
-					unsigned long kexec_flags);
+void setup_linux_system_parameters(struct kexec_info *info,
+	struct x86_linux_param_header *real_mode);
 
 
 #define SETUP_BASE    0x90000
kexec/arch/x86_64/kexec-elf-x86_64.c +1 -1
index fe4b76b..a3fc728 100644
@@ -253,7 +253,7 @@ int elf_x86_64_load(int argc, char **argv, const char *buf, off_t len,
 			ramdisk_buf, ramdisk_length);
 
 		/* Fill in the information bios calls would usually provide */
-		setup_linux_system_parameters(&hdr->hdr, info->kexec_flags);
+		setup_linux_system_parameters(info, &hdr->hdr);
 
 		/* Initialize the registers */
 		elf_rel_get_symbol(&info->rhdr, "entry64_regs", &regs, sizeof(regs));
Signature · 6 lines
1.7.1

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

PATCH 2/2 kexec: add additional check when getting memory info

This check makes sure that we indeed get the memory information.

---
 kexec/kexec.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
kexec/kexec.c +1 -1
index 89ec182..16c6308 100644
@@ -675,7 +675,7 @@ static int my_load(const char *type, int fileind, int argc, char **argv,
 #endif
 
 	if (get_memory_ranges(&info.memory_range, &info.memory_ranges,
-		info.kexec_flags) < 0) {
+		info.kexec_flags) < 0 || info.memory_ranges == 0) {
 		fprintf(stderr, "Could not get memory layout\n");
 		return -1;
 	}
Signature · 6 lines
1.7.1

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

ping...

Quoted 107 lines · Zhang Yanfei

At first, we have already filled the kexec_info.memory_ranges by calling my_load() -> get_memory_ranges(). So if we want to get the memory information, we could just use the existing one instead of calling get_memory_ranges again.

---
 kexec/arch/i386/kexec-bzImage.c       |    2 +-
 kexec/arch/i386/kexec-elf-x86.c       |    2 +-
 kexec/arch/i386/kexec-multiboot-x86.c |    7 ++-----
 kexec/arch/i386/x86-linux-setup.c     |   10 ++++------
 kexec/arch/i386/x86-linux-setup.h     |    4 ++--
 kexec/arch/x86_64/kexec-elf-x86_64.c  |    2 +-
 6 files changed, 11 insertions(+), 16 deletions(-)
kexec/arch/i386/kexec-bzImage.c +1 -1
index 0605909..83a023d 100644
@@ -324,7 +324,7 @@ int do_bzImage_load(struct kexec_info *info,
 
 	/* Fill in the information BIOS calls would normally provide. */
 	if (!real_mode_entry) {
-		setup_linux_system_parameters(real_mode, info->kexec_flags);
+		setup_linux_system_parameters(info, real_mode);
 	}
 
 	return 0;
kexec/arch/i386/kexec-elf-x86.c +1 -1
index 8bd5ef6..e62ebcb 100644
@@ -272,7 +272,7 @@ int elf_x86_load(int argc, char **argv, const char *buf, off_t len,
 			ramdisk_buf, ramdisk_length);
 
 		/* Fill in the information bios calls would usually provide */
-		setup_linux_system_parameters(&hdr->hdr, info->kexec_flags);
+		setup_linux_system_parameters(info, &hdr->hdr);
 
 		/* Initialize the registers */
 		elf_rel_get_symbol(&info->rhdr, "entry32_regs", &regs, sizeof(regs));
kexec/arch/i386/kexec-multiboot-x86.c +2 -5
index 23dab7b..de2a423 100644
@@ -248,11 +248,8 @@ int multiboot_x86_load(int argc, char **argv, const char *buf, off_t len,
 	mbi->boot_loader_name = sizeof(*mbi) + command_line_len; 
 
 	/* Memory map */
-	if ((get_memory_ranges(&range, &ranges, info->kexec_flags) < 0)
-			|| ranges == 0) {
-		fprintf(stderr, "Cannot get memory information\n");
-		return -1;
-	}
+	range = info->memory_range;
+	ranges = info->memory_ranges;
 	mmap = xmalloc(ranges * sizeof(*mmap));
 	for (i=0; i<ranges; i++) {
 		unsigned long long length;
kexec/arch/i386/x86-linux-setup.c +4 -6
index b7ab8ea..ef62553 100644
@@ -441,8 +441,8 @@ close:
 	close(data_file);
 }
 
-void setup_linux_system_parameters(struct x86_linux_param_header *real_mode,
-					unsigned long kexec_flags)
+void setup_linux_system_parameters(struct kexec_info *info,
+				   struct x86_linux_param_header *real_mode)
 {
 	/* Fill in information the BIOS would usually provide */
 	struct memory_range *range;
@@ -486,10 +486,8 @@ void setup_linux_system_parameters(struct x86_linux_param_header *real_mode,
 	/* another safe default */
 	real_mode->aux_device_info = 0;
 
-	/* Fill in the memory info */
-	if ((get_memory_ranges(&range, &ranges, kexec_flags) < 0) || ranges == 0) {
-		die("Cannot get memory information\n");
-	}
+	range = info->memory_range;
+	ranges = info->memory_ranges;
 	if (ranges > E820MAX) {
 		fprintf(stderr, "Too many memory ranges, truncating...\n");
 		ranges = E820MAX;
kexec/arch/i386/x86-linux-setup.h +2 -2
index 8862513..96fbd33 100644
@@ -7,8 +7,8 @@ void setup_linux_bootloader_parameters(
 	unsigned long real_mode_base, unsigned long cmdline_offset,
 	const char *cmdline, off_t cmdline_len,
 	const char *initrd_buf, off_t initrd_size);
-void setup_linux_system_parameters(struct x86_linux_param_header *real_mode,
-					unsigned long kexec_flags);
+void setup_linux_system_parameters(struct kexec_info *info,
+	struct x86_linux_param_header *real_mode);
 
 
 #define SETUP_BASE    0x90000
kexec/arch/x86_64/kexec-elf-x86_64.c +0 -0
index fe4b76b..a3fc728 100644

kexec/arch/x86_64/kexec-elf-x86_64.c int elf_x86_64_load(int argc, char **argv, const char *buf, off_t len, · line 259

Quoted 8 lines
kexec/arch/x86_64/kexec-elf-x86_64.c +1 -1
@@ -253,7 +253,7 @@ int elf_x86_64_load(int argc, char **argv, const char *buf, off_t len,
 			ramdisk_buf, ramdisk_length);
 
 		/* Fill in the information bios calls would usually provide */
-		setup_linux_system_parameters(&hdr->hdr, info->kexec_flags);
+		setup_linux_system_parameters(info, &hdr->hdr);
 
 		/* Initialize the registers */
 		elf_rel_get_symbol(&info->rhdr, "entry64_regs", &regs, sizeof(regs));

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

#4 lore raw
Quoted 9 lines · Zhang Yanfei
Quoted 6 lines · Zhang Yanfei

At first, we have already filled the kexec_info.memory_ranges by calling my_load() -> get_memory_ranges(). So if we want to get the memory information, we could just use the existing one instead of calling get_memory_ranges again.

ping...

Sorry for the extended delay. Applied.

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