kexec-tools: Add length parameter to get_crash_notes_per_cpu()

Let get_crash_notes_per_cpu() pass both physical base address and length.
Under Xen we export this information from the hypervisor, and it would be
a nice improvement for the kernel to actually export the size too. So let's
change the framework to use both base address and length.

Signed-off-by: Magnus Damm <[EMAIL PROTECTED]>
---

 kexec/arch/i386/crashdump-x86.c      |   20 ++++++++++----------
 kexec/arch/ia64/crashdump-ia64.c     |   16 +++++++++-------
 kexec/arch/ppc64/crashdump-ppc64.c   |    8 +++-----
 kexec/arch/x86_64/crashdump-x86_64.c |    8 +++-----
 kexec/crashdump.c                    |    5 ++++-
 kexec/crashdump.h                    |    2 +-
 6 files changed, 30 insertions(+), 29 deletions(-)

--- 0001/kexec/arch/i386/crashdump-x86.c
+++ work/kexec/arch/i386/crashdump-x86.c        2006-11-17 13:14:11.000000000 
+0900
@@ -434,7 +434,7 @@ static int cmdline_add_elfcorehdr(char *
  * backward compatibility, other architectures can use the per
  * cpu version get_crash_notes_per_cpu() directly.
  */
-static int get_crash_notes(int cpu, uint64_t *addr)
+static int get_crash_notes(int cpu, uint64_t *addr, uint64_t *len)
 {
        char crash_notes[PATH_MAX];
        char line[MAX_LINE];
@@ -451,13 +451,15 @@ static int get_crash_notes(int cpu, uint
                                die("Cannot parse %s: %s\n", crash_notes,
                                                strerror(errno));
                }
+
                *addr = __pa(vaddr + (cpu * MAX_NOTE_BYTES));
+               *len = MAX_NOTE_BYTES;
 #if 0
                printf("crash_notes addr = %Lx\n", *addr);
 #endif
                return 0;
        } else
-               return get_crash_notes_per_cpu(cpu, addr);
+               return get_crash_notes_per_cpu(cpu, addr, len);
 }
 
 /* Prepares the crash memory elf64 headers and stores in supplied buffer. */
@@ -469,7 +471,7 @@ static int prepare_crash_memory_elf64_he
        int i;
        char *bufp;
        long int nr_cpus = 0;
-       uint64_t notes_addr;
+       uint64_t notes_addr, notes_len;
 
        bufp = (char*) buf;
 
@@ -503,7 +505,7 @@ static int prepare_crash_memory_elf64_he
        }
 
        for (i = 0; i < nr_cpus; i++) {
-               if (get_crash_notes(i, &notes_addr) < 0) {
+               if (get_crash_notes(i, &notes_addr, &notes_len) < 0) {
                        /* This cpu is not present. Skip it. */
                        continue;
                }
@@ -513,7 +515,7 @@ static int prepare_crash_memory_elf64_he
                phdr->p_flags   = 0;
                phdr->p_offset  = phdr->p_paddr = notes_addr;
                phdr->p_vaddr   = 0;
-               phdr->p_filesz  = phdr->p_memsz = MAX_NOTE_BYTES;
+               phdr->p_filesz  = phdr->p_memsz = notes_len;
                /* Do we need any alignment of segments? */
                phdr->p_align   = 0;
 
@@ -564,7 +566,7 @@ static int prepare_crash_memory_elf32_he
        int i;
        char *bufp;
        long int nr_cpus = 0;
-       uint64_t notes_addr;
+       uint64_t notes_addr, notes_len;
 
        bufp = (char*) buf;
 
@@ -597,10 +599,8 @@ static int prepare_crash_memory_elf32_he
                return -1;
        }
 
-       /* Need to find a better way to determine per cpu notes section size. */
-#define MAX_NOTE_BYTES 1024
        for (i = 0; i < nr_cpus; i++) {
-               if (get_crash_notes(i, &notes_addr) < 0) {
+               if (get_crash_notes(i, &notes_addr, &notes_len) < 0) {
                        /* This cpu is not present. Skip it. */
                        return -1;
                }
@@ -610,7 +610,7 @@ static int prepare_crash_memory_elf32_he
                phdr->p_flags   = 0;
                phdr->p_offset  = phdr->p_paddr = notes_addr;
                phdr->p_vaddr   = 0;
-               phdr->p_filesz  = phdr->p_memsz = MAX_NOTE_BYTES;
+               phdr->p_filesz  = phdr->p_memsz = notes_len;
                /* Do we need any alignment of segments? */
                phdr->p_align   = 0;
 
--- 0001/kexec/arch/ia64/crashdump-ia64.c
+++ work/kexec/arch/ia64/crashdump-ia64.c       2006-11-17 13:14:11.000000000 
+0900
@@ -80,7 +80,8 @@ static void add_loaded_segments_info(str
        }
 }
 
-static int get_crash_notes_section_addr(unsigned long *addr, int cpu)
+static int get_crash_notes_section_addr(int cpu, unsigned long *addr, 
+                                       unsigned long *len)
 {
         char crash_notes[128];
         char line[MAX_LINE];
@@ -97,6 +98,9 @@ static int get_crash_notes_section_addr(
                *addr = 0;
                return -1;
        }
+
+       *len = MAX_NOTE_BYTES;
+
         return 0;
 }
 
@@ -157,7 +161,7 @@ static int prepare_crash_memory_elf64_he
        int i;
        long int nr_cpus = 0;
        char *bufp = buf;
-       unsigned long notes_addr, notes_offset;
+       unsigned long notes_addr, notes_offset, notes_len;
 
        /* Setup ELF Header*/
        elf = (Elf64_Ehdr *) bufp;
@@ -188,11 +192,9 @@ static int prepare_crash_memory_elf64_he
                return -1;
        }
 
-        /* Need to find a better way to determine per cpu notes section size. 
*/
-#define MAX_NOTE_BYTES  1024
-
         for (i = 0; i < nr_cpus; i++) {
-               if (get_crash_notes_section_addr (&notes_addr, i) < 0)
+               if (get_crash_notes_section_addr (i, &notes_addr, 
+                                                 &notes_len) < 0)
                        break;
                notes_offset = notes_addr;
                phdr = (Elf64_Phdr *) bufp;
@@ -201,7 +203,7 @@ static int prepare_crash_memory_elf64_he
                 phdr->p_flags   = 0;
                 phdr->p_offset  = notes_offset;
                 phdr->p_vaddr   = phdr->p_paddr = notes_offset;
-                phdr->p_filesz  = phdr->p_memsz = MAX_NOTE_BYTES;
+                phdr->p_filesz  = phdr->p_memsz = notes_len;
                 /* Do we need any alignment of segments? */
                 phdr->p_align   = 0;
 
--- 0001/kexec/arch/ppc64/crashdump-ppc64.c
+++ work/kexec/arch/ppc64/crashdump-ppc64.c     2006-11-17 13:14:11.000000000 
+0900
@@ -269,7 +269,7 @@ static int prepare_crash_memory_elf64_he
        int i;
        char *bufp;
        long int nr_cpus = 0;
-       unsigned long notes_addr;
+       unsigned long notes_addr, notes_len;
 
        bufp = (char*) buf;
 
@@ -301,10 +301,8 @@ static int prepare_crash_memory_elf64_he
        if (nr_cpus < 0)
                return -1;
 
-       /* Need to find a better way to determine per cpu notes section size. */
-#define MAX_NOTE_BYTES  1024
        for (i = 0; i < nr_cpus; i++) {
-               if (get_crash_notes_per_cpu(i, &notes_addr) < 0) {
+               if (get_crash_notes_per_cpu(i, &notes_addr, &notes_len) < 0) {
                        /* This cpu is not present. Skip it. */
                        continue;
                }
@@ -314,7 +312,7 @@ static int prepare_crash_memory_elf64_he
                phdr->p_flags   = 0;
                phdr->p_offset  = phdr->p_paddr =  notes_addr;
                phdr->p_vaddr   = 0;
-               phdr->p_filesz  = phdr->p_memsz = MAX_NOTE_BYTES;
+               phdr->p_filesz  = phdr->p_memsz = notes_len;
                /* Do we need any alignment of segments? */
                phdr->p_align   = 0;
 
--- 0001/kexec/arch/x86_64/crashdump-x86_64.c
+++ work/kexec/arch/x86_64/crashdump-x86_64.c   2006-11-17 13:14:11.000000000 
+0900
@@ -602,7 +602,7 @@ static int prepare_crash_memory_elf64_he
        int i;
        char *bufp;
        long int nr_cpus = 0;
-       uint64_t notes_addr;
+       uint64_t notes_addr, notes_len;
 
        bufp = (char*) buf;
 
@@ -635,10 +635,8 @@ static int prepare_crash_memory_elf64_he
                return -1;
        }
 
-       /* Need to find a better way to determine per cpu notes section size. */
-#define MAX_NOTE_BYTES 1024
        for (i = 0; i < nr_cpus; i++) {
-               if (get_crash_notes_per_cpu(i, &notes_addr) < 0) {
+               if (get_crash_notes_per_cpu(i, &notes_addr, &notes_len) < 0) {
                        /* This cpu is not present. Skip it. */
                        continue;
                }
@@ -649,7 +647,7 @@ static int prepare_crash_memory_elf64_he
                phdr->p_flags   = 0;
                phdr->p_offset  = phdr->p_paddr = notes_addr;
                phdr->p_vaddr   = 0;
-               phdr->p_filesz  = phdr->p_memsz = MAX_NOTE_BYTES;
+               phdr->p_filesz  = phdr->p_memsz = notes_len;
                /* Do we need any alignment of segments? */
                phdr->p_align   = 0;
 
--- 0001/kexec/crashdump.c
+++ work/kexec/crashdump.c      2006-11-17 13:17:28.000000000 +0900
@@ -26,9 +26,10 @@
 #include <sys/stat.h>
 #include <unistd.h>
 #include "kexec.h"
+#include "crashdump.h"
 
 /* Returns the physical address of start of crash notes buffer for a cpu. */
-int get_crash_notes_per_cpu(int cpu, uint64_t *addr)
+int get_crash_notes_per_cpu(int cpu, uint64_t *addr, uint64_t *len)
 {
        char crash_notes[PATH_MAX];
        char line[MAX_LINE];
@@ -40,6 +41,7 @@ int get_crash_notes_per_cpu(int cpu, uin
        int stat_errno;
 
        *addr = 0;
+       *len = 0;
 
        sprintf(crash_notes, "/sys/devices/system/cpu/cpu%d/crash_notes", cpu);
        fp = fopen(crash_notes, "r");
@@ -68,6 +70,7 @@ int get_crash_notes_per_cpu(int cpu, uin
        if (count != 1)
                die("Cannot parse %s: %s\n", crash_notes, strerror(errno));
        *addr = (uint64_t) temp;
+       *len = MAX_NOTE_BYTES; /* we should get this from the kernel instead */
 #if 0
        printf("crash_notes addr = %Lx\n", *addr);
 #endif
--- 0001/kexec/crashdump.h
+++ work/kexec/crashdump.h      2006-11-17 13:14:11.000000000 +0900
@@ -1,7 +1,7 @@
 #ifndef CRASHDUMP_H
 #define CRASHDUMP_H
 
-extern int get_crash_notes_per_cpu(int cpu, uint64_t *addr);
+extern int get_crash_notes_per_cpu(int cpu, uint64_t *addr, uint64_t *len);
 
 /* Need to find a better way to determine per cpu notes section size. */
 #define MAX_NOTE_BYTES         1024
_______________________________________________
fastboot mailing list
fastboot@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/fastboot

Reply via email to