Skip to contentSkip to conversation

Iomem fixes

PATCH New Simon Horman 1 participant 6 messages Feb 27, 2008

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

cover Iomem fixes

Hi,

while working on the xen ia64 port of kexec I stumbled upon a couple of problems with the handling of iomem. This patch series resolves this problems (I hope) and also fixes up a few related cosmetic problems.

Signature · 7 lines
Horms


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

PATCH 1/5 kexec-tools: always use /proc/iomem_machine on ia64 xen

When I first added proc_iomem() it was for ia64 Xen as certain regions are added /proc/iomem_machine instead of /proc/iomem on that platform.

On further examination I have found that all regions need to be added to /proc/iomem_machine.

This patch changes the ia64 implementation of proc_iomem() to always return /proc/iomem_machine if xen is in use.

A subsequent patch will remove the machine parameter to proc_iomem() which is no longer of any use.

---

 kexec/arch/ia64/kexec-iomem.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kexec/arch/ia64/kexec-iomem.c +1 -1
index 97f7730..7696113 100644
@@ -17,7 +17,7 @@ static const char proc_iomem_machine_str[]= "/proc/iomem_machine";
  */
 const char *proc_iomem(int machine)
 {
-	if (machine && xen_present())
+	if (xen_present())
 		return proc_iomem_machine_str;
 	return proc_iomem_str;
 }
Signature · 8 lines
-- 
Horms


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

PATCH 2/5 kexec-tools: no machine machine to proc_iomem()

In reply to Simon Horman

Removes the machine parameter to proc_iomem() which is no longer of any use.

---

 kexec/arch/i386/crashdump-x86.c      |    4 ++--
 kexec/arch/i386/kexec-x86.c          |    2 +-
 kexec/arch/ia64/crashdump-ia64.c     |    4 ++--
 kexec/arch/ia64/kexec-elf-ia64.c     |    2 +-
 kexec/arch/ia64/kexec-ia64.c         |    4 +++-
 kexec/arch/ia64/kexec-iomem.c        |    4 ++--
 kexec/arch/s390/kexec-s390.c         |    2 +-
 kexec/arch/x86_64/crashdump-x86_64.c |    6 +++---
 kexec/arch/x86_64/kexec-x86_64.c     |    2 +-
 kexec/crashdump-xen.c                |    4 ++--
 kexec/kexec-iomem.c                  |   10 +++++-----
 kexec/kexec.h                        |    6 +++---
 12 files changed, 26 insertions(+), 24 deletions(-)
kexec/arch/ia64/kexec-elf-ia64.c +1 -1
Index: kexec-tools-testing-ia64-xen/kexec/arch/ia64/kexec-elf-ia64.c
===================================================================
@@ -195,7 +195,7 @@ int elf_ia64_load(int argc, char **argv,
 	if (info->kexec_flags & KEXEC_ON_CRASH ) {
 		if ((mem_min == 0x00) && (mem_max == ULONG_MAX)) {
 			fprintf(stderr, "Failed to find crash kernel region "
-				"in %s\n", proc_iomem(1));
+				"in %s\n", proc_iomem());
 			free_elf_info(&ehdr);
 			return -1;
 		}
kexec/arch/i386/crashdump-x86.c +2 -2
Index: kexec-tools-testing-ia64-xen/kexec/arch/i386/crashdump-x86.c
===================================================================
@@ -59,7 +59,7 @@ static struct memory_range crash_reserve
  */
 static int get_crash_memory_ranges(struct memory_range **range, int *ranges)
 {
-	const char *iomem = proc_iomem(1);
+	const char *iomem = proc_iomem();
 	int memory_ranges = 0;
 	char line[MAX_LINE];
 	FILE *fp;
@@ -582,6 +582,6 @@ int is_crashkernel_mem_reserved(void)
 {
 	uint64_t start, end;
 
-	return parse_iomem_single("Crash kernel\n", 1, &start, &end) == 0 ?
+	return parse_iomem_single("Crash kernel\n", &start, &end) == 0 ?
 	  (start != end) : 0;
 }
kexec/arch/i386/kexec-x86.c +1 -1
Index: kexec-tools-testing-ia64-xen/kexec/arch/i386/kexec-x86.c
===================================================================
@@ -39,7 +39,7 @@ static struct memory_range memory_range[
 int get_memory_ranges(struct memory_range **range, int *ranges,
 				unsigned long kexec_flags)
 {
-	const char *iomem= proc_iomem(kexec_flags & KEXEC_ON_CRASH);
+	const char *iomem= proc_iomem();
 	int memory_ranges = 0;
 	char line[MAX_LINE];
 	FILE *fp;
kexec/arch/ia64/crashdump-ia64.c +2 -2
Index: kexec-tools-testing-ia64-xen/kexec/arch/ia64/crashdump-ia64.c
===================================================================
@@ -143,7 +143,7 @@ static int exclude_crash_reserve_region(
 
 static int get_crash_memory_ranges(struct memory_range **range, int *ranges)
 {
-	const char *iomem = proc_iomem(1);
+	const char *iomem = proc_iomem();
         char line[MAX_LINE];
         FILE *fp;
         unsigned long start, end;
@@ -262,6 +262,6 @@ int is_crashkernel_mem_reserved(void)
 {
 	uint64_t start, end;
 
-	return parse_iomem_single("Crash kernel\n", 1, &start,
+	return parse_iomem_single("Crash kernel\n", &start,
 				  &end) == 0 ?  (start != end) : 0;
 }
kexec/arch/ia64/kexec-ia64.c +3 -1
Index: kexec-tools-testing-ia64-xen/kexec/arch/ia64/kexec-ia64.c
===================================================================
@@ -80,7 +80,7 @@ static int split_range(int range, unsign
 int get_memory_ranges(struct memory_range **range, int *ranges,
 				unsigned long kexec_flags)
 {
-	const char *iomem = proc_iomem(kexec_flags & KEXEC_ON_CRASH);
+	const char *iomem = proc_iomem();
 	char line[MAX_LINE];
 	FILE *fp;
 	fp = fopen(iomem, "r");
@@ -134,9 +134,11 @@ int get_memory_ranges(struct memory_rang
 			}
 			continue;
 		} else if (memcmp(str, "Boot parameter\n", 14) == 0) {
+			printf("Boot parameter\n");
 			memory_ranges = split_range(memory_ranges, start, end);
 			continue;
 		} else if (memcmp(str, "EFI Memory Map\n", 14) == 0) {
+			printf("EFI Memory Map\n");
 			memory_ranges = split_range(memory_ranges, start, end);
 			saved_efi_memmap_size = end - start;
 			continue;
kexec/arch/ia64/kexec-iomem.c +2 -2
Index: kexec-tools-testing-ia64-xen/kexec/arch/ia64/kexec-iomem.c
===================================================================
@@ -13,9 +13,9 @@ static const char proc_iomem_machine_str
  * If Xen is in use, then /proc/iomem is used for memory regions relating
  * to the currently running dom0 kernel, and /proc/iomem_machine is used
  * for regions relating to the machine itself or the hypervisor.
- * If Xen is not in used, then /proc/iomem is always used.
+ * If Xen is not in used, then /proc/iomem used.
  */
-const char *proc_iomem(int machine)
+const char *proc_iomem(void)
 {
 	if (xen_present())
 		return proc_iomem_machine_str;
kexec/arch/s390/kexec-s390.c +1 -1
Index: kexec-tools-testing-ia64-xen/kexec/arch/s390/kexec-s390.c
===================================================================
@@ -40,7 +40,7 @@ static struct memory_range memory_range[
 int get_memory_ranges(struct memory_range **range, int *ranges, unsigned long flags)
 {
 	char sys_ram[] = "System RAM\n";
-	char *iomem = proc_iomem(flags & KEXEC_ON_CRASH);
+	char *iomem = proc_iomem();
 	FILE *fp;
 	char line[80];
 	int current_range = 0;
kexec/arch/x86_64/crashdump-x86_64.c +3 -3
Index: kexec-tools-testing-ia64-xen/kexec/arch/x86_64/crashdump-x86_64.c
===================================================================
@@ -61,7 +61,7 @@ static int get_kernel_paddr(struct kexec
 	if (xen_present()) /* Kernel not entity mapped under Xen */
 		return 0;
 
-	if (parse_iomem_single("Kernel code\n", 0, &start, NULL) == 0) {
+	if (parse_iomem_single("Kernel code\n", &start, NULL) == 0) {
 		info->kern_paddr_start = start;
 #ifdef DEBUG
 		printf("kernel load physical addr start = 0x%016Lx\n", start);
@@ -164,7 +164,7 @@ static struct memory_range crash_reserve
  */
 static int get_crash_memory_ranges(struct memory_range **range, int *ranges)
 {
-	const char *iomem= proc_iomem(1);
+	const char *iomem= proc_iomem();
 	int memory_ranges = 0;
 	char line[MAX_LINE];
 	FILE *fp;
@@ -642,6 +642,6 @@ int is_crashkernel_mem_reserved(void)
 {
 	uint64_t start, end;
 
-	return parse_iomem_single("Crash kernel\n", 1, &start, &end) == 0 ?
+	return parse_iomem_single("Crash kernel\n", &start, &end) == 0 ?
 	  (start != end) : 0;
 }
kexec/arch/x86_64/kexec-x86_64.c +1 -1
Index: kexec-tools-testing-ia64-xen/kexec/arch/x86_64/kexec-x86_64.c
===================================================================
@@ -40,7 +40,7 @@ static struct memory_range memory_range[
 int get_memory_ranges(struct memory_range **range, int *ranges,
 					unsigned long kexec_flags)
 {
-	const char *iomem= proc_iomem(kexec_flags & KEXEC_ON_CRASH);
+	const char *iomem= proc_iomem();
 	int memory_ranges = 0;
 	char line[MAX_LINE];
 	FILE *fp;
kexec/crashdump-xen.c +2 -2
Index: kexec-tools-testing-ia64-xen/kexec/crashdump-xen.c
===================================================================
@@ -93,7 +93,7 @@ int xen_get_nr_phys_cpus(void)
 	if (xen_phys_cpus)
 		return xen_phys_cpus;
 
-	if ((cpus = kexec_iomem_for_each_line(match, 1, NULL, NULL))) {
+	if ((cpus = kexec_iomem_for_each_line(match, NULL, NULL))) {
 		n = sizeof(struct crash_note_info) * cpus;
 		xen_phys_notes = malloc(n);
 		if (!xen_phys_notes) {
@@ -101,7 +101,7 @@ int xen_get_nr_phys_cpus(void)
 			return -1;
 		}
 		memset(xen_phys_notes, 0, n);
-		kexec_iomem_for_each_line(match, 1,
+		kexec_iomem_for_each_line(match,
 					  xen_crash_note_callback, NULL);
 		xen_phys_cpus = cpus;
 	}
kexec/kexec-iomem.c +5 -5
Index: kexec-tools-testing-ia64-xen/kexec/kexec-iomem.c
===================================================================
@@ -22,7 +22,7 @@
  * Return the number of lines matched.
  */
 
-int kexec_iomem_for_each_line(char *match, int machine,
+int kexec_iomem_for_each_line(char *match,
 			      int (*callback)(void *data,
 					      int nr,
 					      char *str,
@@ -30,7 +30,7 @@ int kexec_iomem_for_each_line(char *matc
 					      unsigned long length),
 			      void *data)
 {
-	const char *iomem = proc_iomem(machine);
+	const char *iomem = proc_iomem();
 	char line[MAX_LINE];
 	FILE *fp;
 	unsigned long long start, end, size;
@@ -78,14 +78,14 @@ static int kexec_iomem_single_callback(v
 	return 0;
 }
 
-int parse_iomem_single(char *str, int machine, uint64_t *start, uint64_t *end)
+int parse_iomem_single(char *str, uint64_t *start, uint64_t *end)
 {
 	struct memory_range range;
 	int ret;
 
 	memset(&range, 0, sizeof(range));
 
-	ret = kexec_iomem_for_each_line(str, machine,
+	ret = kexec_iomem_for_each_line(str,
 	                                kexec_iomem_single_callback, &range);
 
 	if (ret == 1) {
@@ -109,7 +109,7 @@ static const char proc_iomem_str[]= "/pr
  * function to override the location of a file looking a lot
  * like /proc/iomem
  */
-const char * __attribute__((weak)) proc_iomem(int machine)
+const char * __attribute__((weak)) proc_iomem(void)
 {
         return proc_iomem_str;
 }
kexec/kexec.h +3 -3
Index: kexec-tools-testing-ia64-xen/kexec/kexec.h
===================================================================
@@ -207,15 +207,15 @@ int arch_compat_trampoline(struct kexec_
 void arch_update_purgatory(struct kexec_info *info);
 int is_crashkernel_mem_reserved(void);
 
-int kexec_iomem_for_each_line(char *match, int machine,
+int kexec_iomem_for_each_line(char *match,
 			      int (*callback)(void *data,
 					      int nr,
 					      char *str,
 					      unsigned long base,
 					      unsigned long length),
 			      void *data);
-int parse_iomem_single(char *str, int machine, uint64_t *start, uint64_t *end);
-const char * proc_iomem(int machine);
+int parse_iomem_single(char *str, uint64_t *start, uint64_t *end);
+const char * proc_iomem(void);
 
 #define MAX_LINE	160
 
Signature · 8 lines
-- 
Horms


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

PATCH 3/5 kexec-tools: use proc_iomem()

In reply to Simon Horman

Use proc_iomem() on arm for consistency with other architectures.

---

 kexec/arch/arm/kexec-arm.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kexec/arch/arm/kexec-arm.c +1 -1
Index: kexec-tools-testing-ia64-xen/kexec/arch/arm/kexec-arm.c
===================================================================
@@ -26,7 +26,7 @@ static struct memory_range memory_range[
 int get_memory_ranges(struct memory_range **range, int *ranges,
 		unsigned long kexec_flags)
 {
-	const char iomem[]= "/proc/iomem";
+	const char iomem[]= proc_iomem();
 	int memory_ranges = 0;
 	char line[MAX_LINE];
 	FILE *fp;
Signature · 8 lines
-- 
Horms


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

PATCH 4/5 kexec-tools: merge segments

In reply to Simon Horman

A list of segments is passed into the kernel at kexec_load time and these are subsequently passed to purgatory which uses them to mangle the EFI memory table.

Each of these segments represents a PT_LOAD segment in the elf image to be booted after purgatory. They are already aligned 64k by this code,

The problem with the code as it stands is that it creates a separate segment for each PT_LOAD segment. Which in the end results in separate EFI memory regions for each PT_LOAD segment. And when linux or xen goes to insert its kernel/hypervisor regions into /proc/iomem
or /proc/iomem_mashine, they don't fit because those regions actually span several of the new EFI regions created.

So it makes sense to merge these segments if they are adjacent after alignment - which they always seem to be. This results in one EFI region that can contain the relevent kernel/hypervisor iomem region. Problem solved.

This merging could be done in purgatory. But its easier and cleaner to do it here (IMHO).

The test for this code is to kexec a machine running kexec it into linux and then inspect /proc/iomem to see of the kernel code, text and bss regions are present. Without this fix, they won't be. With it they should be.

This patch is part of the solution to the same problem for the hypervisor, though it requires an additional change to split the code from the heap as the later resides in convential memory rather than the load segment created by purgatory's mangling.

---

 kexec/arch/ia64/crashdump-ia64.c |   21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)
kexec/arch/ia64/crashdump-ia64.c +16 -5
Index: kexec-tools-testing-ia64-xen/kexec/arch/ia64/crashdump-ia64.c
===================================================================
@@ -76,18 +76,29 @@ static void add_loaded_segments_info(str
 {
 	 int i;
          for(i = 0; i < ehdr->e_phnum; i++) {
-                unsigned long start, end;
                 struct mem_phdr *phdr;
                 phdr = &ehdr->e_phdr[i];
                 if (phdr->p_type != PT_LOAD)
                         continue;
-                start = phdr->p_paddr;
-                end = phdr->p_paddr + phdr->p_memsz;
 
 		loaded_segments[loaded_segments_num].start =
-                        start&~(ELF_PAGE_SIZE-1);
+			phdr->p_paddr & ~(ELF_PAGE_SIZE-1);
                 loaded_segments[loaded_segments_num].end =
-                        (end + ELF_PAGE_SIZE - 1)&~(ELF_PAGE_SIZE - 1);
+			loaded_segments[loaded_segments_num].start;
+
+		while (i < ehdr->e_phnum) {
+			phdr = &ehdr->e_phdr[i];
+	                if (phdr->p_type != PT_LOAD)
+	                        break;
+			if (loaded_segments[loaded_segments_num].end !=
+				phdr->p_paddr & ~(ELF_PAGE_SIZE-1))
+				break;
+			loaded_segments[loaded_segments_num].end +=
+				(phdr->p_memsz + ELF_PAGE_SIZE - 1) &
+				~(ELF_PAGE_SIZE - 1);
+			i++;
+		}
+
 		loaded_segments_num++;
 	}
 }
Signature · 8 lines
-- 
Horms


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

PATCH 5/5 kexec-tools: redivide efi memory in purgatory

In reply to Simon Horman

From my observations the way that the EFI_LOAD_DATA is provided on the inital boot works like this:

There is a large EFI_CONVENTIONAL_MEMORY region. The portion begining at the first load segment of the image to be loading and ending with the last segment, aligned to 64K, is turned into a separate region of type EFI_LOAD_DATA.

A truncated example of this:

...
mem04: type= 7, attr=0x0000000000000008, range=[0x0000000000100000-0x0000000004000000) ( 63MB)
mem05: type= 2, attr=0x0000000000000008, range=[0x0000000004000000-0x000000000481f000) ( 8MB)
mem06: type= 7, attr=0x0000000000000008, range=[0x000000000481f000-0x000000003e876000) ( 928MB)
...

Where type 7 is EFI_CONVENTIONAL_MEMORY and
type 3 is EFI_LOAD_DATA.

There is a patch to the user-space portion of kexec-tools that merges the segments supplied to this code if they are adjacent. This seems to always result in a single segment being passed to this code, that should start at the same address as the existing EFI_LOAD_DATA segment.

So all that should be left to do is to merge the existing EFI_LOAD_DATA region with the following EFI_CONVENTIONAL_MEMORY region, and then split it up to accommodate the segment passed from user-space.

The new EFI_LOAD_DATA region created with this code will always start at the same address as the old EFI_LOAD_DATA region. If this proves to be overly simplistic it should be easy to update.

This code also allows merging of multiple regions to accommodate the new EFI_LOAD_DATA region. I strongly doubt this will ever be used, but it is in line with the way the existing code works.

If the same image is used after kexec, then the
EFI regions in question will turn out the same as the original regions.

This is important, otherwise kernel / hypervisor regions will not be able to be inserted into /proc/iomem / /proc/iomem_machine.

---

 purgatory/arch/ia64/purgatory-ia64.c |   16 ++++++++++++++++
 1 file changed, 16 insertions(+)
purgatory/arch/ia64/purgatory-ia64.c +16 -0
Index: kexec-tools-testing-ia64-xen/purgatory/arch/ia64/purgatory-ia64.c
===================================================================
@@ -190,6 +190,22 @@ patch_efi_memmap(struct kexec_boot_param
 				mend = src_md->phys_addr +
 					(src_md->num_pages << EFI_PAGE_SHIFT);
 			}
+                        if (seg->end < mend && src < src_end) {
+                                void *src_next;
+                                efi_memory_desc_t *src_next_md;
+                                src_next = src + boot_param->efi_memdesc_size;
+                                src_next_md = src_next;
+                                if (src_next_md->type ==
+                                    EFI_CONVENTIONAL_MEMORY) {
+				        /* TODO check contig and attribute */
+                                        src += boot_param->efi_memdesc_size;
+                                        src_md = src;
+				        mend = src_md->phys_addr +
+					        (src_md->num_pages <<
+                                                 EFI_PAGE_SHIFT);
+                                }
+
+                        }
 			start_pages = (seg->start - mstart) >> EFI_PAGE_SHIFT;
 			mid_pages = (seg->end - seg->start) >> EFI_PAGE_SHIFT;
 			end_pages = (mend - seg->end) >> EFI_PAGE_SHIFT;
Signature · 8 lines
-- 
Horms


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