summaryrefslogtreecommitdiff
path: root/kexec/arch
diff options
context:
space:
mode:
authorVivek Goyal <vivek@in.ibm.com>2005-12-15 11:36:37 +0530
committerEric W. Biederman <ebiederm@xmission.com>2006-07-27 10:40:38 -0600
commit920fca9abfba3f5b86b2f73b54ba6f45148847cf (patch)
tree75f936be5224af9ff3a2ccb9427341eabab6481b /kexec/arch
parente2a925519d24e1aef1fd8d6e2f0d6f659d128ea7 (diff)
kexec-tools: i386 sys interface changes compatibility
On Wed, Dec 14, 2005 at 02:50:52PM -0600, Milton Miller wrote: [..] > >>(2) why do you stat the files instead of just trying to open them and > >>check for ENOENT? > >> > >>milton > >> > > > >I wanted to differentiate between two cases. One being sysfs not > >mounted > >and other being file not being present (Due to kernel bug or cpu not > >present), hence used stat(). In case of sysfs not being mounted, we > >simply exit after giving an error message. In other case we continue > >to loop through other cpus and ignore cpu, which is not present. > > > > Ok, but try to open the file first. IF you want to do this diagnostic > after the open fails, that is ok. But don't do this check n times (n = > number of cpus) when the file exists. > I have moved the sysfs mounted check in failure condition. > > > > >On Tue, Dec 13, 2005 at 09:36:26AM -0800, Haren Myneni wrote: > >>Vivek, I believe, we should push this func into arch independent code. > >>Otherwise, we have to copy it for every platform. > >> > > > >We have reworked the patch and moved this code to architecture > >independent > >portion. > > > > > Only the x86 code has the fallback the old name, not the genric code. > Only i386 port of kdump was available when crash_notes was exported through /sys/kernel/crash_notes. Rest of the architectures see new arch- independent percpu crash_notes sysfs interface only. Hence thought no point copying backward compatibility code in generic code. > > Also, there are error paths that do not set the address, others that > zero it. > The error paths which do not set address to zero are non return path. They call die() which inturn calls exit(1) after printing appropriate error messasge. > What happens if the base kernel is too old for kexec-panic, where > neiter file will exist? > In that case kexec will fail much earlier. There will be no reserved memory area for loading second kernel (crashkernel=X&Y) hence attempt to load the second kernel will fail and control will not reach this place at all. Modifed patch appended. Thanks Vivek o This patch moves per cpu interface to retrieve crash_notes address to architecture independent section. (As suggested by Haren) o For i386, kernels older than 2.6.15-rc1-mm2 used to export crash_notes through /sys/kernel/crash_notes. This patch also provides backward compatibility with older kernel versions. o Definition of MAX_NOTE_BYTES moved to architecture independent header file as everybody is using same definition. o Definition of MAX_LINE moved to architecture independent header file. Seems to be a better option than defining it in many C files. Signed-off-by: Maneesh Soni <maneesh@in.ibm.com> Signed-off-by: Vivek Goyal <vgoyal@in.ibm.com> Signed-off-by: Maneesh Soni <maneesh@in.ibm.com>
Diffstat (limited to 'kexec/arch')
-rw-r--r--kexec/arch/i386/crashdump-x86.c61
-rw-r--r--kexec/arch/i386/kexec-x86.c2
-rw-r--r--kexec/arch/ia64/kexec-ia64.c1
-rw-r--r--kexec/arch/ppc/kexec-ppc.c1
-rw-r--r--kexec/arch/x86_64/crashdump-x86_64.c49
-rw-r--r--kexec/arch/x86_64/kexec-x86_64.c1
6 files changed, 31 insertions, 84 deletions
diff --git a/kexec/arch/i386/crashdump-x86.c b/kexec/arch/i386/crashdump-x86.c
index 9553faf..03995d8 100644
--- a/kexec/arch/i386/crashdump-x86.c
+++ b/kexec/arch/i386/crashdump-x86.c
@@ -29,12 +29,11 @@
#include "../../kexec.h"
#include "../../kexec-elf.h"
#include "../../kexec-syscall.h"
+#include "../../crashdump.h"
#include "kexec-x86.h"
#include "crashdump-x86.h"
#include <x86/x86-linux.h>
-#define MAX_LINE 160
-
extern struct arch_options_t arch_options;
/* Forward Declaration. */
@@ -429,41 +428,36 @@ static int cmdline_add_elfcorehdr(char *cmdline, unsigned long addr)
return 0;
}
-/* Returns the virtual address of start of crash notes buffer for a cpu. */
-static int get_crash_notes_section_addr(int cpu, unsigned long long *addr)
+
+/*
+ * This routine is specific to i386 architecture to maintain the
+ * 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)
{
-#define MAX_SYSFS_PATH_LEN 70
- char crash_notes[MAX_SYSFS_PATH_LEN];
+ char crash_notes[PATH_MAX];
char line[MAX_LINE];
FILE *fp;
- struct stat cpu_stat;
+ unsigned long vaddr;
+ int count;
- sprintf(crash_notes, "/sys/devices/system/cpu");
- if (stat(crash_notes, &cpu_stat)) {
- die("Cannot stat %s: %s\nTry mounting sysfs\n",
- crash_notes, strerror(errno));
- }
-
- sprintf(crash_notes, "/sys/devices/system/cpu/cpu%d/crash_notes", cpu);
+ sprintf(crash_notes, "/sys/kernel/crash_notes");
fp = fopen(crash_notes, "r");
- if (!fp) {
- /* CPU is not physically present.*/
- *addr = 0;
- return -1;
- }
-
- if (fgets(line, sizeof(line), fp) != 0) {
- int count;
- count = sscanf(line, "%Lx", addr);
- if (count != 1) {
- *addr = 0;
- return -1;
+ if (fp) {
+ if (fgets(line, sizeof(line), fp) != 0) {
+ count = sscanf(line, "%lx", &vaddr);
+ if (count != 1)
+ die("Cannot parse %s: %s\n", crash_notes,
+ strerror(errno));
}
+ *addr = __pa(vaddr + (cpu * MAX_NOTE_BYTES));
#if 0
printf("crash_notes addr = %Lx\n", *addr);
#endif
- }
- return 0;
+ return 0;
+ } else
+ return get_crash_notes_per_cpu(cpu, addr);
}
/* Prepares the crash memory elf64 headers and stores in supplied buffer. */
@@ -475,7 +469,7 @@ static int prepare_crash_memory_elf64_headers(struct kexec_info *info,
int i;
char *bufp;
long int nr_cpus = 0;
- unsigned long long notes_addr;
+ uint64_t notes_addr;
bufp = (char*) buf;
@@ -508,11 +502,8 @@ static int prepare_crash_memory_elf64_headers(struct kexec_info *info,
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 (i, &notes_addr) < 0) {
+ if (get_crash_notes(i, &notes_addr) < 0) {
/* This cpu is not present. Skip it. */
continue;
}
@@ -571,7 +562,7 @@ static int prepare_crash_memory_elf32_headers(struct kexec_info *info,
int i;
char *bufp;
long int nr_cpus = 0;
- unsigned long long notes_addr;
+ uint64_t notes_addr;
bufp = (char*) buf;
@@ -607,7 +598,7 @@ static int prepare_crash_memory_elf32_headers(struct kexec_info *info,
/* 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 (i, &notes_addr) < 0) {
+ if (get_crash_notes(i, &notes_addr) < 0) {
/* This cpu is not present. Skip it. */
return -1;
}
diff --git a/kexec/arch/i386/kexec-x86.c b/kexec/arch/i386/kexec-x86.c
index 26cbbb0..1c8d188 100644
--- a/kexec/arch/i386/kexec-x86.c
+++ b/kexec/arch/i386/kexec-x86.c
@@ -33,8 +33,6 @@
#include "crashdump-x86.h"
#include <arch/options.h>
-#define MAX_LINE 160
-
static struct memory_range memory_range[MAX_MEMORY_RANGES];
/* Return a sorted list of memory ranges. */
diff --git a/kexec/arch/ia64/kexec-ia64.c b/kexec/arch/ia64/kexec-ia64.c
index a2221e6..f631cef 100644
--- a/kexec/arch/ia64/kexec-ia64.c
+++ b/kexec/arch/ia64/kexec-ia64.c
@@ -34,7 +34,6 @@
#include <arch/options.h>
#define MAX_MEMORY_RANGES 64
-#define MAX_LINE 160
static struct memory_range memory_range[MAX_MEMORY_RANGES];
/* Return a sorted list of available memory ranges. */
diff --git a/kexec/arch/ppc/kexec-ppc.c b/kexec/arch/ppc/kexec-ppc.c
index 455febf..16ea584 100644
--- a/kexec/arch/ppc/kexec-ppc.c
+++ b/kexec/arch/ppc/kexec-ppc.c
@@ -19,7 +19,6 @@
#include <arch/options.h>
#define MAX_MEMORY_RANGES 64
-#define MAX_LINE 160
static struct memory_range memory_range[MAX_MEMORY_RANGES];
/* Return a sorted list of memory ranges. */
diff --git a/kexec/arch/x86_64/crashdump-x86_64.c b/kexec/arch/x86_64/crashdump-x86_64.c
index f104b89..3d0f3a5 100644
--- a/kexec/arch/x86_64/crashdump-x86_64.c
+++ b/kexec/arch/x86_64/crashdump-x86_64.c
@@ -30,12 +30,11 @@
#include "../../kexec.h"
#include "../../kexec-elf.h"
#include "../../kexec-syscall.h"
+#include "../../crashdump.h"
#include "kexec-x86_64.h"
#include "crashdump-x86_64.h"
#include <x86/x86-linux.h>
-#define MAX_LINE 160
-
extern struct arch_options_t arch_options;
/* Forward Declaration. */
@@ -471,44 +470,6 @@ static int cmdline_add_memmap_acpi(char *cmdline, unsigned long start,
return 0;
}
-/* Returns the virtual address of start of crash notes buffer for a cpu. */
-static int get_crash_notes_section_addr(int cpu, unsigned long long *addr)
-{
-
-#define MAX_SYSFS_PATH_LEN 70
- char crash_notes[MAX_SYSFS_PATH_LEN];
- char line[MAX_LINE];
- FILE *fp;
- struct stat cpu_stat;
-
- sprintf(crash_notes, "/sys/devices/system/cpu");
- if (stat(crash_notes, &cpu_stat)) {
- die("Cannot stat %s: %s\nTry mounting sysfs\n",
- crash_notes, strerror(errno));
- }
-
- sprintf(crash_notes, "/sys/devices/system/cpu/cpu%d/crash_notes", cpu);
- fp = fopen(crash_notes, "r");
- if (!fp) {
- /* CPU is not physically present.*/
- *addr = 0;
- return -1;
- }
-
- if (fgets(line, sizeof(line), fp) != 0) {
- int count;
- count = sscanf(line, "%Lx", addr);
- if (count != 1) {
- *addr = 0;
- return -1;
- }
-#if 0
- printf("crash_notes addr = %Lx\n", *addr);
-#endif
- }
- return 0;
-}
-
/* Prepares the crash memory elf64 headers and stores in supplied buffer. */
static int prepare_crash_memory_elf64_headers(struct kexec_info *info,
void *buf, unsigned long size)
@@ -518,7 +479,7 @@ static int prepare_crash_memory_elf64_headers(struct kexec_info *info,
int i;
char *bufp;
long int nr_cpus = 0;
- unsigned long long notes_addr;
+ uint64_t notes_addr;
bufp = (char*) buf;
@@ -554,7 +515,7 @@ static int prepare_crash_memory_elf64_headers(struct kexec_info *info,
/* 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 (i, &notes_addr) < 0) {
+ if (get_crash_notes_per_cpu(i, &notes_addr) < 0) {
/* This cpu is not present. Skip it. */
continue;
}
@@ -624,7 +585,7 @@ static int prepare_crash_memory_elf32_headers(struct kexec_info *info,
int i;
char *bufp;
long int nr_cpus = 0;
- unsigned long long notes_addr;
+ uint64_t notes_addr;
bufp = (char*) buf;
@@ -660,7 +621,7 @@ static int prepare_crash_memory_elf32_headers(struct kexec_info *info,
/* 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 (i, &notes_addr) < 0) {
+ if (get_crash_notes_per_cpu(i, &notes_addr) < 0) {
/* This cpu is not present. Skip it. */
return -1;
}
diff --git a/kexec/arch/x86_64/kexec-x86_64.c b/kexec/arch/x86_64/kexec-x86_64.c
index 3ed3844..db3e5d4 100644
--- a/kexec/arch/x86_64/kexec-x86_64.c
+++ b/kexec/arch/x86_64/kexec-x86_64.c
@@ -34,7 +34,6 @@
#include <arch/options.h>
#define MAX_MEMORY_RANGES 64
-#define MAX_LINE 160
static struct memory_range memory_range[MAX_MEMORY_RANGES];
/* Return a sorted list of memory ranges. */