Eugene Surovegin | 1 Mar 2012 02:23
Picon
Favicon

Re: [PATCH] kdump: force page alignment for per-CPU crash notes.

On Wed, Feb 29, 2012 at 5:18 PM, Simon Horman <horms-/R6kz+dDXgoY1Siqtc7rAw@public.gmane.orgu> wrote:
On Wed, Feb 29, 2012 at 09:21:23AM -0800, Eugene Surovegin wrote:
> Per-CPU allocations are not guaranteed to be physically contiguous.
> However, kdump kernel and user-space code assumes that per-CPU
> memory, used for saving CPU registers on crash, is.
> This can cause corrupted /proc/vmcore in some cases - the main
> symptom being huge ELF note section.
>
> Force page alignment for note_buf_t to ensure that this assumption holds.

Ouch. I'm surprised there is an allocation on crash, perhaps
it could at least be done earlier? And am I right in thinking
that this change increases the likely hood that the allocation
could fail?

I'm not following. This allocation is done on start-up, not on crash.
If you cannot allocate this much memory on system boot, I'm not sure what else you can do on this system....

-- 
Eugene

_______________________________________________
kexec mailing list
kexec@...
http://lists.infradead.org/mailman/listinfo/kexec
Atsushi Kumagai | 1 Mar 2012 02:40
Picon
Picon

makedumpfile-1.4.3: Support for PPC32 architecture.

Hi,

makedumpfile version 1.4.3 is released.
Your comments/patches are welcome.

Suzuki implemented "Support for PPC32" feature. Thanks, Suzuki.

Changelog:
o New feature
   Commits related to "Support for PPC32"
    - [PATCH v1 1/3] Support for cross building. (by Suzuki K. Poulose) 96f24dc
    - [PATCH v1 2/3][ppc64] Rename the __powerpc__ macro to __powerpc64__ for PPC64. (by Suzuki K. Poulose) 3d8b733
    - [PATCH v1 3/3] Add support for PPC32. (by Suzuki K. Poulose) 9cfcdae
   Other commit
    - [PATCH] Support newer kernels. (by Atsushi Kumagai) 029ebaf

o Bugfix
    - [PATCH] Fix segmentation fault for makedumpfile -x/--split. (by Aruna Balakrishnaiah) 8bc7d44
    - [PATCH] Fix VtoP method for x86 remap allocator. (by Petr Tesarik) 3812217

o TODO
    - Send the patch to the LKML to store some symbols in VMCOREINFO.
      (VtoP method for x86 remap allocator needs some symbols that
       relate to remap allocator.)
    - Support newer kernels (Especially DISCONTIGMEM).

Explanation of makedumpfile:
  To shorten the size of the dumpfile and the time of creating the
  dumpfile, makedumpfile copies only the necessary pages for analysis
  to the dumpfile from /proc/vmcore. You can specify the kind of
  unnecessary pages with dump_level. If you want to shorten the size
  further, enable the compression of the page data.

Download:
  You can download the latest makedumpfile from the following URL.
  Details of the change are written on the git page of the following site.
  https://sourceforge.net/projects/makedumpfile/

Method of installation:
  You can compile the makedumpfile command as follows;
  1. "tar -zxvf makedumpfile-x.y.z.tar.gz"
  2. "cd makedumpfile-x.y.z"
  3. "make; make install"

Usage:
  makedumpfile [-c] [-E] [-d dump_level] [-x vmlinux] dump_mem dump_file

Example:
  If you want to exclude pages filled by zero, cache pages, user pages
  and free pages and to enable compression, please execute the following
  command.

  # makedumpfile -c -d 31 -x vmlinux /proc/vmcore dumpfile

Thanks
Atsushi Kumagai
HATAYAMA Daisuke | 1 Mar 2012 02:51
Favicon

Re: [PATCH] kdump: force page alignment for per-CPU crash notes.

From: Eugene Surovegin <surovegin@...>
Subject: Re: [PATCH] kdump: force page alignment for per-CPU crash notes.
Date: Wed, 29 Feb 2012 17:39:55 -0800

> On Wed, Feb 29, 2012 at 5:32 PM, Simon Horman <horms@...> wrote:
>> On Wed, Feb 29, 2012 at 05:23:10PM -0800, Eugene Surovegin wrote:
>>> On Wed, Feb 29, 2012 at 5:18 PM, Simon Horman <horms@...> wrote:
>>>
>>> > On Wed, Feb 29, 2012 at 09:21:23AM -0800, Eugene Surovegin wrote:
>>> > > Per-CPU allocations are not guaranteed to be physically contiguous.
>>> > > However, kdump kernel and user-space code assumes that per-CPU
>>> > > memory, used for saving CPU registers on crash, is.
>>> > > This can cause corrupted /proc/vmcore in some cases - the main
>>> > > symptom being huge ELF note section.
>>> > >
>>> > > Force page alignment for note_buf_t to ensure that this assumption holds.
>>> >
>>> > Ouch. I'm surprised there is an allocation on crash, perhaps
>>> > it could at least be done earlier? And am I right in thinking
>>> > that this change increases the likely hood that the allocation
>>> > could fail?
>>> >
>>>
>>> I'm not following. This allocation is done on start-up, not on crash.
>>> If you cannot allocate this much memory on system boot, I'm not sure what
>>> else you can do on this system....
>>
>> Sorry, my eyes deceived me. You are correct and I agree.
>>
>> Is it the case that note_buf_t is never larger than PAGE_SIZE?
>> If so I your patch looks good to me.
> 
> Currently, maximum note size is hardcoded in kexec-tools to 1024
> (MAX_NOTE_BYTES).
> Usually it's way less. IIRC on x86_64 it's 336 bytes.
> 

This is elf_prstatus and I guess it's mostly equal to registers.

crash> p sizeof(struct elf_prstatus)
$3 = 336
crash> ptype struct elf_prstatus
type = struct elf_prstatus {
    struct elf_siginfo pr_info;
    short int pr_cursig;
    long unsigned int pr_sigpend;
    long unsigned int pr_sighold;
    pid_t pr_pid;
    pid_t pr_ppid;
    pid_t pr_pgrp;
    pid_t pr_sid;
    struct timeval pr_utime;
    struct timeval pr_stime;
    struct timeval pr_cutime;
    struct timeval pr_cstime;
    elf_gregset_t pr_reg; <-- this
    int pr_fpvalid;
}

What kinds of architecture does have so many registers? It's just my
interest. Or possibly other kinds of notes is written here?

Thanks.
HATAYAMA, Daisuke
Eugene Surovegin | 1 Mar 2012 02:56
Picon
Favicon

Re: [PATCH] kdump: force page alignment for per-CPU crash notes.

On Wed, Feb 29, 2012 at 5:51 PM, HATAYAMA Daisuke
<d.hatayama@...> wrote:
> From: Eugene Surovegin <surovegin@...>
> Subject: Re: [PATCH] kdump: force page alignment for per-CPU crash notes.
> Date: Wed, 29 Feb 2012 17:39:55 -0800
>
>> On Wed, Feb 29, 2012 at 5:32 PM, Simon Horman <horms@...> wrote:
>>> On Wed, Feb 29, 2012 at 05:23:10PM -0800, Eugene Surovegin wrote:
>>>> On Wed, Feb 29, 2012 at 5:18 PM, Simon Horman <horms@...> wrote:
>>>>
>>>> > On Wed, Feb 29, 2012 at 09:21:23AM -0800, Eugene Surovegin wrote:
>>>> > > Per-CPU allocations are not guaranteed to be physically contiguous.
>>>> > > However, kdump kernel and user-space code assumes that per-CPU
>>>> > > memory, used for saving CPU registers on crash, is.
>>>> > > This can cause corrupted /proc/vmcore in some cases - the main
>>>> > > symptom being huge ELF note section.
>>>> > >
>>>> > > Force page alignment for note_buf_t to ensure that this assumption holds.
>>>> >
>>>> > Ouch. I'm surprised there is an allocation on crash, perhaps
>>>> > it could at least be done earlier? And am I right in thinking
>>>> > that this change increases the likely hood that the allocation
>>>> > could fail?
>>>> >
>>>>
>>>> I'm not following. This allocation is done on start-up, not on crash.
>>>> If you cannot allocate this much memory on system boot, I'm not sure what
>>>> else you can do on this system....
>>>
>>> Sorry, my eyes deceived me. You are correct and I agree.
>>>
>>> Is it the case that note_buf_t is never larger than PAGE_SIZE?
>>> If so I your patch looks good to me.
>>
>> Currently, maximum note size is hardcoded in kexec-tools to 1024
>> (MAX_NOTE_BYTES).
>> Usually it's way less. IIRC on x86_64 it's 336 bytes.
>>
>
> This is elf_prstatus and I guess it's mostly equal to registers.
>
> crash> p sizeof(struct elf_prstatus)
> $3 = 336
> crash> ptype struct elf_prstatus
> type = struct elf_prstatus {
>    struct elf_siginfo pr_info;
>    short int pr_cursig;
>    long unsigned int pr_sigpend;
>    long unsigned int pr_sighold;
>    pid_t pr_pid;
>    pid_t pr_ppid;
>    pid_t pr_pgrp;
>    pid_t pr_sid;
>    struct timeval pr_utime;
>    struct timeval pr_stime;
>    struct timeval pr_cutime;
>    struct timeval pr_cstime;
>    elf_gregset_t pr_reg; <-- this
>    int pr_fpvalid;
> }
>
> What kinds of architecture does have so many registers? It's just my
> interest. Or possibly other kinds of notes is written here?

I'm not sure about other archs, but we don't write there anything
except for 'elf_prstatus' and sentinel "final" note.

--
Eugene
Eugene Surovegin | 1 Mar 2012 18:04
Picon
Favicon

Re: [PATCH] kdump: force page alignment for per-CPU crash notes.

On Thu, Mar 1, 2012 at 7:09 AM, Vivek Goyal <vgoyal@...> wrote:
> On Wed, Feb 29, 2012 at 09:21:23AM -0800, Eugene Surovegin wrote:
>> Per-CPU allocations are not guaranteed to be physically contiguous.
>> However, kdump kernel and user-space code assumes that per-CPU
>> memory, used for saving CPU registers on crash, is.
>> This can cause corrupted /proc/vmcore in some cases - the main
>> symptom being huge ELF note section.
>>
>> Force page alignment for note_buf_t to ensure that this assumption holds.
>>
>
> Hi Eugene,
>
> Where do we make assumption that crash_notes address is page aligned?

I never said that. I said that assumption was that note chunks were
physically contiguous.

[snip]

> Are you referring to the fact that note could be stored on two different
> physical pages and then kexec-tools does not know about the physical
> address of second page, hence second kernel does not know about it
> and we never read that data. That sounds like a problem.

Yes. This is exactly what happens in some cases.

> So it make sense to force the page size alignment and if notes ever
> grow beyond 1 page, we need to come up with more complex ways of
> communicating more than 1 physical address to second kernel.

Yes. Thankfully notes so far are smaller than a page.
And if they do grow larger, than kexec-tools have to be modified
anyways - currently maximum note size (1K) is hardcoded there.
If this happens, I think instead of coming up with a way to
communicate phys to virt mapping, it'd be easier just to change th way
notes are allocated in the kernel so they are phys contiguous.

--
Eugene
Han Pingtian | 2 Mar 2012 10:28
Picon

[PATCH] remove useless call to setup_memory_ranges() in ppc64

setup_memory_ranges() is being called twice in ppc64. First in my_load()
through get_memory_ranges(), then in elf_ppc64_load(). Looks like we can
remove the latter.
---
 kexec/arch/ppc64/kexec-elf-ppc64.c |    2 --
 1 files changed, 0 insertions(+), 2 deletions(-)

diff --git a/kexec/arch/ppc64/kexec-elf-ppc64.c b/kexec/arch/ppc64/kexec-elf-ppc64.c
index ab6da7c..abd83dd 100644
--- a/kexec/arch/ppc64/kexec-elf-ppc64.c
+++ b/kexec/arch/ppc64/kexec-elf-ppc64.c
 <at>  <at>  -149,8 +149,6  <at>  <at>  int elf_ppc64_load(int argc, char **argv, const char *buf, off_t len,
 	if (ramdisk && reuse_initrd)
 		die("Can't specify --ramdisk or --initrd with --reuseinitrd\n");

-	setup_memory_ranges(info->kexec_flags);
-
 	/* Need to append some command line parameters internally in case of
 	 * taking crash dumps.
 	 */
--

-- 
1.7.6.5
Fernando Luis Vázquez Cao | 8 Mar 2012 02:29
Picon

Re: [tip:x86/debug] x86/kdump: No need to disable ioapic/ lapic in crash path

On 03/08/2012 03:27 AM, Yinghai Lu wrote:

> 2012/3/7 Vivek Goyal<vgoyal@...>:
>> On Wed, Mar 07, 2012 at 07:53:16PM +0900, Fernando Luis Vázquez Cao wrote:
>>> We run into the same NMI problems and wrote some patches that tackle
>>> the kernel boot side of things. They have been extensively tested using
>>> qemu-kvm and things seem to be working as expected (after receiving an
>>> early NMI the kernel continues without problem; after the iret there is no
>>> stack corruption or register corruption).
>> What happens if NMI happens while we are still in purgatory code?
The system triple faults. As Eric said we need to fix both the reboot path
to kdump and kdump kernel's boot code. The two patches I sent address the
later. I sent these first because I had time to test them properly, fix a
real issue and can be applied independently.

> yes, you are right. that is too late to set that in arch/x86/kernel/head64.c
Of course, the reboot path needs to be fixed too. Now that I solved some
problems I was having with my qemu-kvm test environment (NMIs injected
through the qemu monitor only get devivered to the BSP, etc), I will make
sure that the code I wrote for it works as expected.

In the meantime, I would appreciate it if you could review/ack yesterday's
patches.

Thanks,
Fernando
Fernando Luis Vázquez Cao | 8 Mar 2012 07:00
Picon

Re: [PATCH 2/2] boot: add early NMI counter

On 03/08/2012 01:50 PM, Eric W. Biederman wrote:
> Fernando Luis Vázquez Cao<fernando <at> oss.ntt.co.jp>  writes:
>
>> Subject: [PATCH] boot: add early NMI counter
>>
>> From: Fernando Luis Vazquez Cao<fernando <at> oss.ntt.co.jp>
>>
>> We currently ignore early NMIs but it would be nice to be able to
>> know whether they actually occurred.
>>
>> This patch adds an early NMI counter and exports it trough
>> /proc/interrupts with the name of ENM (Early NMI).
> For a userspace interface I suspect we just want to dump the count
> into the NMI counter.
>
> It probably makes sense to have a separate variable in early boot like
> you do, but then about the time we setup the normal NMI handler move the
> NMI count over and possibly do something like reboot if that is our
> policy.

I am fine with either approach. I guess that is the x86 maintainers'
call. Ingo, Thomas, Peter, what do you think? Should I add a new
entry to /proc/interrupts or move over the early NMI count to the
existing per-cpu NMI counter?

Thanks,
Fernando

_______________________________________________
kexec mailing list
kexec <at> lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec
Cong Wang | 8 Mar 2012 07:39
Picon

[PATCH 1/5] Add generic debug option

Currently the debugging code is under #ifdef DEBUG, which
means when we want to debug, we have to re-compile the source
code with -DDEBUG. This is not convenient, we want to have
a generic --debug option so that we can enable debugging code
without re-compiling.

This patch moves the arch-specific --debug to generic place
and moves code under #ifdef DEBUG to --debug on x86.

BTW, the size of kexec binary increases very little after this patch.

Signed-off-by: Cong Wang <xiyou.wangcong@...>
---
 kexec/arch/i386/crashdump-x86.c          |   74 +++++++++++++-----------------
 kexec/arch/i386/include/arch/options.h   |    1 -
 kexec/arch/i386/kexec-beoboot-x86.c      |   12 +----
 kexec/arch/i386/kexec-bzImage.c          |   18 ++-----
 kexec/arch/i386/kexec-x86.h              |    2 +-
 kexec/arch/i386/x86-linux-setup.c        |    1 -
 kexec/arch/ppc/include/arch/options.h    |    3 +-
 kexec/arch/ppc/kexec-dol-ppc.c           |    8 +---
 kexec/arch/x86_64/kexec-elf-rel-x86_64.c |    4 +-
 kexec/crashdump.c                        |    5 +-
 kexec/kexec-elf-rel.c                    |   11 ++--
 kexec/kexec.c                            |    4 ++
 kexec/kexec.h                            |   15 +++---
 13 files changed, 63 insertions(+), 95 deletions(-)

diff --git a/kexec/arch/i386/crashdump-x86.c b/kexec/arch/i386/crashdump-x86.c
index 436797a..590c883 100644
--- a/kexec/arch/i386/crashdump-x86.c
+++ b/kexec/arch/i386/crashdump-x86.c
 <at>  <at>  -76,9 +76,7  <at>  <at>  static int get_kernel_paddr(struct kexec_info *UNUSED(info),

 	if (parse_iomem_single("Kernel code\n", &start, NULL) == 0) {
 		elf_info->kern_paddr_start = start;
-#ifdef DEBUG
-		printf("kernel load physical addr start = 0x%016Lx\n", start);
-#endif
+		dbgprintf("kernel load physical addr start = 0x%016Lx\n", start);
 		return 0;
 	}

 <at>  <at>  -150,10 +148,8  <at>  <at>  static int get_kernel_vaddr_and_size(struct kexec_info *UNUSED(info),
 				/* Align size to page size boundary. */
 				size = (size + align - 1) & (~(align - 1));
 				elf_info->kern_size = size;
-#ifdef DEBUG
-				printf("kernel vaddr = 0x%lx size = 0x%llx\n",
+				dbgprintf("kernel vaddr = 0x%lx size = 0x%llx\n",
 					saddr, size);
-#endif
 				return 0;
 			}
 		}
 <at>  <at>  -211,10 +207,8  <at>  <at>  static int get_crash_memory_ranges(struct memory_range **range, int *ranges,
 		if (count != 2)
 			continue;
 		str = line + consumed;
-#ifdef DEBUG
-		printf("%016Lx-%016Lx : %s",
+		dbgprintf("%016Lx-%016Lx : %s",
 			start, end, str);
-#endif
 		/* Only Dumping memory of type System RAM. */
 		if (memcmp(str, "System RAM\n", 11) == 0) {
 			type = RANGE_RAM;
 <at>  <at>  -290,15 +284,15  <at>  <at>  static int get_crash_memory_ranges(struct memory_range **range, int *ranges,
 	}
 	*range = crash_memory_range;
 	*ranges = memory_ranges;
-#ifdef DEBUG
+
 	int i;
-	printf("CRASH MEMORY RANGES\n");
+	dbgprintf("CRASH MEMORY RANGES\n");
 	for(i = 0; i < memory_ranges; i++) {
 		start = crash_memory_range[i].start;
 		end = crash_memory_range[i].end;
-		printf("%016Lx-%016Lx\n", start, end);
+		dbgprintf("%016Lx-%016Lx\n", start, end);
 	}
-#endif
+
 	return 0;
 }

 <at>  <at>  -385,17 +379,17  <at>  <at>  static int add_memmap(struct memory_range *memmap_p, unsigned long long addr,
 			memmap_p[j+1] = memmap_p[j];
 		memmap_p[tidx].start = addr;
 		memmap_p[tidx].end = addr + size - 1;
-#ifdef DEBUG
-	printf("Memmap after adding segment\n");
+
+	dbgprintf("Memmap after adding segment\n");
 	for (i = 0; i < CRASH_MAX_MEMMAP_NR;  i++) {
 		mstart = memmap_p[i].start;
 		mend = memmap_p[i].end;
 		if (mstart == 0 && mend == 0)
 			break;
-		printf("%016llx - %016llx\n",
+		dbgprintf("%016llx - %016llx\n",
 			mstart, mend);
 	}
-#endif
+
 	return 0;
 }

 <at>  <at>  -471,18 +465,18  <at>  <at>  static int delete_memmap(struct memory_range *memmap_p, unsigned long long addr,
 			memmap_p[j-1] = memmap_p[j];
 		memmap_p[j-1].start = memmap_p[j-1].end = 0;
 	}
-#ifdef DEBUG
-	printf("Memmap after deleting segment\n");
+
+	dbgprintf("Memmap after deleting segment\n");
 	for (i = 0; i < CRASH_MAX_MEMMAP_NR;  i++) {
 		mstart = memmap_p[i].start;
 		mend = memmap_p[i].end;
 		if (mstart == 0 && mend == 0) {
 			break;
 		}
-		printf("%016llx - %016llx\n",
+		dbgprintf("%016llx - %016llx\n",
 			mstart, mend);
 	}
-#endif
+
 	return 0;
 }

 <at>  <at>  -546,10 +540,10  <at>  <at>  static int cmdline_add_memmap(char *cmdline, struct memory_range *memmap_p)
 			die("Command line overflow\n");
 		strcat(cmdline, str_mmap);
 	}
-#ifdef DEBUG
-		printf("Command line after adding memmap\n");
-		printf("%s\n", cmdline);
-#endif
+
+	dbgprintf("Command line after adding memmap\n");
+	dbgprintf("%s\n", cmdline);
+
 	return 0;
 }

 <at>  <at>  -574,10 +568,10  <at>  <at>  static int cmdline_add_elfcorehdr(char *cmdline, unsigned long addr)
 	if (cmdlen > (COMMAND_LINE_SIZE - 1))
 		die("Command line overflow\n");
 	strcat(cmdline, str);
-#ifdef DEBUG
-		printf("Command line after adding elfcorehdr\n");
-		printf("%s\n", cmdline);
-#endif
+
+	dbgprintf("Command line after adding elfcorehdr\n");
+	dbgprintf("%s\n", cmdline);
+
 	return 0;
 }

 <at>  <at>  -606,9 +600,9  <at>  <at>  static int get_crash_notes(int cpu, uint64_t *addr, uint64_t *len)

 		*addr = x86__pa(vaddr + (cpu * MAX_NOTE_BYTES));
 		*len = MAX_NOTE_BYTES;
-#ifdef DEBUG
-		printf("crash_notes addr = %Lx\n", *addr);
-#endif
+
+		dbgprintf("crash_notes addr = %Lx\n", *addr);
+
 		fclose(fp);
 		return 0;
 	} else
 <at>  <at>  -658,10 +652,9  <at>  <at>  static int cmdline_add_memmap_acpi(char *cmdline, unsigned long start,
 		die("Command line overflow\n");
 	strcat(cmdline, str_mmap);

-#ifdef DEBUG
-		printf("Command line after adding acpi memmap\n");
-		printf("%s\n", cmdline);
-#endif
+	dbgprintf("Command line after adding acpi memmap\n");
+	dbgprintf("%s\n", cmdline);
+
 	return 0;
 }

 <at>  <at>  -688,15 +681,12  <at>  <at>  static void get_backup_area(unsigned long *start, unsigned long *end)
 		if (count != 2)
 			continue;
 		str = line + consumed;
-#ifdef DEBUG
-		printf("%016lx-%016lx : %s",
+		dbgprintf("%016lx-%016lx : %s",
 			mstart, mend, str);
-#endif
+
 		/* Hopefully there is only one RAM region in the first 640K */
 		if (memcmp(str, "System RAM\n", 11) == 0 && mend <= 0xa0000 ) {
-#ifdef DEBUG
-			printf("%s: %016lx-%016lx : %s", __func__, mstart, mend, str);
-#endif
+			dbgprintf("%s: %016lx-%016lx : %s", __func__, mstart, mend, str);
 			*start = mstart;
 			*end = mend;
 			fclose(fp);
diff --git a/kexec/arch/i386/include/arch/options.h b/kexec/arch/i386/include/arch/options.h
index 990527c..89dbd26 100644
--- a/kexec/arch/i386/include/arch/options.h
+++ b/kexec/arch/i386/include/arch/options.h
 <at>  <at>  -67,7 +67,6  <at>  <at> 
 	{ "args-elf",		0, NULL, OPT_ARGS_ELF },	\
 	{ "args-linux",		0, NULL, OPT_ARGS_LINUX },	\
 	{ "args-none",		0, NULL, OPT_ARGS_NONE },	\
-	{ "debug",		0, NULL, OPT_DEBUG },		\
 	{ "module",		1, 0, OPT_MOD },		\
 	{ "real-mode",		0, NULL, OPT_REAL_MODE },

diff --git a/kexec/arch/i386/kexec-beoboot-x86.c b/kexec/arch/i386/kexec-beoboot-x86.c
index 6d459ae..a65e094 100644
--- a/kexec/arch/i386/kexec-beoboot-x86.c
+++ b/kexec/arch/i386/kexec-beoboot-x86.c
 <at>  <at>  -64,8 +64,7  <at>  <at>  int beoboot_probe(const char *buf, off_t len)

 void beoboot_usage(void)
 {
-	printf(	"-d, --debug               Enable debugging to help spot a failure.\n"
-		"    --real-mode           Use the kernels real mode entry point.\n"
+	printf(	"    --real-mode           Use the kernels real mode entry point.\n"
 		);

 	/* No parameters are parsed */
 <at>  <at>  -81,14 +80,13  <at>  <at>  int beoboot_load(int argc, char **argv, const char *buf, off_t UNUSED(len),
 	struct beoboot_header bb_header;
 	const char *command_line, *kernel, *initrd;

-	int debug, real_mode_entry;
+	int real_mode_entry;
 	int opt;
 	int result;

 	/* See options.h -- add any more there, too. */
 	static const struct option options[] = {
 		KEXEC_ARCH_OPTIONS
-		{ "debug",		0, 0, OPT_DEBUG },
 		{ "real-mode",		0, 0, OPT_REAL_MODE },
 		{ 0, 			0, 0, 0 },
 	};
 <at>  <at>  -97,7 +95,6  <at>  <at>  int beoboot_load(int argc, char **argv, const char *buf, off_t UNUSED(len),
 	/*
 	 * Parse the command line arguments
 	 */
-	debug = 0;
 	real_mode_entry = 0;
 	while((opt = getopt_long(argc, argv, short_options, options, 0)) != -1) {
 		switch(opt) {
 <at>  <at>  -109,9 +106,6  <at>  <at>  int beoboot_load(int argc, char **argv, const char *buf, off_t UNUSED(len),
 		case '?':
 			usage();
 			return -1;
-		case OPT_DEBUG:
-			debug = 1;
-			break;
 		case OPT_REAL_MODE:
 			real_mode_entry = 1;
 			break;
 <at>  <at>  -134,7 +128,7  <at>  <at>  int beoboot_load(int argc, char **argv, const char *buf, off_t UNUSED(len),
 		kernel,        bb_header.kernel_size,
 		command_line,  bb_header.cmdline_size,
 		initrd,        bb_header.initrd_size,
-		real_mode_entry, debug);
+		real_mode_entry);

 	return result;
 }
diff --git a/kexec/arch/i386/kexec-bzImage.c b/kexec/arch/i386/kexec-bzImage.c
index 29e9165..54c4427 100644
--- a/kexec/arch/i386/kexec-bzImage.c
+++ b/kexec/arch/i386/kexec-bzImage.c
 <at>  <at>  -85,8 +85,7  <at>  <at>  int bzImage_probe(const char *buf, off_t len)

 void bzImage_usage(void)
 {
-	printf(	"-d, --debug               Enable debugging to help spot a failure.\n"
-		"    --real-mode           Use the kernels real mode entry point.\n"
+	printf(	"    --real-mode           Use the kernels real mode entry point.\n"
 		"    --command-line=STRING Set the kernel command line to STRING.\n"
 		"    --append=STRING       Set the kernel command line to STRING.\n"
 		"    --reuse-cmdline       Use kernel command line from running system.\n"
 <at>  <at>  -100,7 +99,7  <at>  <at>  int do_bzImage_load(struct kexec_info *info,
 	const char *kernel, off_t kernel_len,
 	const char *command_line, off_t command_line_len,
 	const char *initrd, off_t initrd_len,
-	int real_mode_entry, int debug)
+	int real_mode_entry)
 {
 	struct x86_linux_header setup_header;
 	struct x86_linux_param_header *real_mode;
 <at>  <at>  -297,7 +296,7  <at>  <at>  int do_bzImage_load(struct kexec_info *info,
 		printf("Starting the kernel in real mode\n");
 		regs32.eip = elf_rel_get_addr(&info->rhdr, "entry16");
 	}
-	if (real_mode_entry && debug) {
+	if (real_mode_entry && kexec_debug) {
 		unsigned long entry16_debug, pre32, first32;
 		uint32_t old_first32;
 		/* Find the location of the symbols */
 <at>  <at>  -338,14 +337,13  <at>  <at>  int bzImage_load(int argc, char **argv, const char *buf, off_t len,
 	char *ramdisk_buf;
 	off_t ramdisk_length;
 	int command_line_len;
-	int debug, real_mode_entry;
+	int real_mode_entry;
 	int opt;
 	int result;

 	/* See options.h -- add any more there, too. */
 	static const struct option options[] = {
 		KEXEC_ARCH_OPTIONS
-		{ "debug",		0, 0, OPT_DEBUG },
 		{ "command-line",	1, 0, OPT_APPEND },
 		{ "append",		1, 0, OPT_APPEND },
 		{ "reuse-cmdline",	0, 0, OPT_REUSE_CMDLINE },
 <at>  <at>  -356,10 +354,6  <at>  <at>  int bzImage_load(int argc, char **argv, const char *buf, off_t len,
 	};
 	static const char short_options[] = KEXEC_ARCH_OPT_STR "d";

-	/*
-	 * Parse the command line arguments
-	 */
-	debug = 0;
 	real_mode_entry = 0;
 	ramdisk = 0;
 	ramdisk_length = 0;
 <at>  <at>  -373,8 +367,6  <at>  <at>  int bzImage_load(int argc, char **argv, const char *buf, off_t len,
 		case '?':
 			usage();
 			return -1;
-		case OPT_DEBUG:
-			debug = 1;
 			break;
 		case OPT_APPEND:
 			append = optarg;
 <at>  <at>  -403,7 +395,7  <at>  <at>  int bzImage_load(int argc, char **argv, const char *buf, off_t len,
 		buf, len,
 		command_line, command_line_len,
 		ramdisk_buf, ramdisk_length,
-		real_mode_entry, debug);
+		real_mode_entry);

 	free(command_line);
 	return result;
diff --git a/kexec/arch/i386/kexec-x86.h b/kexec/arch/i386/kexec-x86.h
index aca1841..dfcc51d 100644
--- a/kexec/arch/i386/kexec-x86.h
+++ b/kexec/arch/i386/kexec-x86.h
 <at>  <at>  -70,7 +70,7  <at>  <at>  int do_bzImage_load(struct kexec_info *info,
 	const char *kernel, off_t kernel_len,
 	const char *command_line, off_t command_line_len,
 	const char *initrd, off_t initrd_len,
-	int real_mode_entry, int debug);
+	int real_mode_entry);

 int beoboot_probe(const char *buf, off_t len);
 int beoboot_load(int argc, char **argv, const char *buf, off_t len,
diff --git a/kexec/arch/i386/x86-linux-setup.c b/kexec/arch/i386/x86-linux-setup.c
index 0528cea..95c9f97 100644
--- a/kexec/arch/i386/x86-linux-setup.c
+++ b/kexec/arch/i386/x86-linux-setup.c
 <at>  <at>  -13,7 +13,6  <at>  <at> 
  * GNU General Public License for more details.
  *
  */
-/* #define DEBUG 1 */
 #define _GNU_SOURCE
 #include <stdint.h>
 #include <stdio.h>
diff --git a/kexec/arch/ppc/include/arch/options.h b/kexec/arch/ppc/include/arch/options.h
index 0c00ea7..b2176ab 100644
--- a/kexec/arch/ppc/include/arch/options.h
+++ b/kexec/arch/ppc/include/arch/options.h
 <at>  <at>  -40,8 +40,7  <at>  <at> 
 	{"initrd",	 1, 0, OPT_APPEND},\
 	{"gamecube",	 1, 0, OPT_GAMECUBE},\
 	{"dtb",	    1, 0, OPT_DTB},\
-	{"reuse-node",	   1, 0, OPT_NODES},\
-	{"debug",	 0, 0, OPT_DEBUG},
+	{"reuse-node",	   1, 0, OPT_NODES},

 #define KEXEC_ALL_OPT_STR KEXEC_OPT_STR

diff --git a/kexec/arch/ppc/kexec-dol-ppc.c b/kexec/arch/ppc/kexec-dol-ppc.c
index 8de5293..5fc5e06 100644
--- a/kexec/arch/ppc/kexec-dol-ppc.c
+++ b/kexec/arch/ppc/kexec-dol-ppc.c
 <at>  <at>  -311,8 +311,7  <at>  <at>  int dol_ppc_probe(const char *buf, off_t dol_length)
 void dol_ppc_usage(void)
 {
 	printf
-	    ("-d, --debug               Enable debugging to help spot a failure.\n"
-	     "    --command-line=STRING Set the kernel command line to STRING.\n"
+	    ("    --command-line=STRING Set the kernel command line to STRING.\n"
 	     "    --append=STRING       Set the kernel command line to STRING.\n");

 }
 <at>  <at>  -339,7 +338,6  <at>  <at>  int dol_ppc_load(int argc, char **argv, const char *buf, off_t UNUSED(len),
 	/* See options.h -- add any more there, too. */
         static const struct option options[] = {
                 KEXEC_ARCH_OPTIONS
-                {"debug",        0, 0, OPT_DEBUG},
                 {"command-line", 1, 0, OPT_APPEND},
                 {"append",       1, 0, OPT_APPEND},
                 {0, 0, 0, 0},
 <at>  <at>  -349,7 +347,6  <at>  <at>  int dol_ppc_load(int argc, char **argv, const char *buf, off_t UNUSED(len),
 	/*
 	 * Parse the command line arguments
 	 */
-	debug = 0;
 	command_line = 0;
 	while ((opt = getopt_long(argc, argv, short_options, options, 0)) != -1) {
 		switch (opt) {
 <at>  <at>  -361,9 +358,6  <at>  <at>  int dol_ppc_load(int argc, char **argv, const char *buf, off_t UNUSED(len),
 		case '?':
 			usage();
 			return -1;
-		case OPT_DEBUG:
-			debug = 1;
-			break;
 		case OPT_APPEND:
 			command_line = optarg;
 			break;
diff --git a/kexec/arch/x86_64/kexec-elf-rel-x86_64.c b/kexec/arch/x86_64/kexec-elf-rel-x86_64.c
index 8b2e0e5..a1291a6 100644
--- a/kexec/arch/x86_64/kexec-elf-rel-x86_64.c
+++ b/kexec/arch/x86_64/kexec-elf-rel-x86_64.c
 <at>  <at>  -60,9 +60,7  <at>  <at>  static const char *reloc_name(unsigned long r_type)
 void machine_apply_elf_rel(struct mem_ehdr *UNUSED(ehdr), unsigned long r_type,
 	void *location, unsigned long address, unsigned long value)
 {
-#ifdef DEBUG
-	fprintf(stderr, "%s\n", reloc_name(r_type));
-#endif
+	dbgprintf("%s\n", reloc_name(r_type));
 	switch(r_type) {
 	case R_X86_64_NONE:
 		break;
diff --git a/kexec/crashdump.c b/kexec/crashdump.c
index 847d080..cdd3ef6 100644
--- a/kexec/crashdump.c
+++ b/kexec/crashdump.c
 <at>  <at>  -102,9 +102,8  <at>  <at>  int get_crash_notes_per_cpu(int cpu, uint64_t *addr, uint64_t *len)
 		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 */
-#ifdef DEBUG
-	printf("%s: crash_notes addr = %Lx\n", __FUNCTION__, *addr);
-#endif
+
+	dbgprintf("%s: crash_notes addr = %Lx\n", __FUNCTION__, *addr);

 	fclose(fp);
 	return 0;
diff --git a/kexec/kexec-elf-rel.c b/kexec/kexec-elf-rel.c
index f102fb8..c04c972 100644
--- a/kexec/kexec-elf-rel.c
+++ b/kexec/kexec-elf-rel.c
 <at>  <at>  -363,8 +363,8  <at>  <at>  int elf_rel_load(struct mem_ehdr *ehdr, struct kexec_info *info,
 				name = ehdr->e_shdr[ehdr->e_shstrndx].sh_data;
 				name += ehdr->e_shdr[sym.st_shndx].sh_name;
 			}
-#ifdef DEBUG
-			fprintf(stderr, "sym: %10s info: %02x other: %02x shndx: %lx value: %lx size: %lx\n",
+
+			dbgprintf("sym: %10s info: %02x other: %02x shndx: %lx value: %lx size: %lx\n",
 				name,
 				sym.st_info,
 				sym.st_other,
 <at>  <at>  -372,7 +372,6  <at>  <at>  int elf_rel_load(struct mem_ehdr *ehdr, struct kexec_info *info,
 				sym.st_value,
 				sym.st_size);

-#endif
 			if (sym.st_shndx == STN_UNDEF) {
 			/*
 			 * NOTE: ppc64 elf .ro shows up a  UNDEF section.
 <at>  <at>  -405,10 +404,10  <at>  <at>  int elf_rel_load(struct mem_ehdr *ehdr, struct kexec_info *info,
 			value = sym.st_value;
 			value += sec_base;
 			value += rel.r_addend;
-#ifdef DEBUG
-			fprintf(stderr, "sym: %s value: %lx addr: %lx\n",
+
+			dbgprintf("sym: %s value: %lx addr: %lx\n",
 				name, value, address);
-#endif
+
 			machine_apply_elf_rel(ehdr, rel.r_type,
 				(void *)location, address, value);
 		}
diff --git a/kexec/kexec.c b/kexec/kexec.c
index 89e725e..19133fa 100644
--- a/kexec/kexec.c
+++ b/kexec/kexec.c
 <at>  <at>  -50,6 +50,7  <at>  <at> 
 unsigned long long mem_min = 0;
 unsigned long long mem_max = ULONG_MAX;
 static unsigned long kexec_flags = 0;
+int kexec_debug = 0;

 void die(char *fmt, ...)
 {
 <at>  <at>  -893,6 +894,7  <at>  <at>  void usage(void)
 	       "                      context of current kernel during kexec.\n"
 	       "     --load-jump-back-helper Load a helper image to jump back\n"
 	       "                      to original kernel.\n"
+	       " -d, --debug           Enable debugging to help spot a failure.\n"
 	       "\n"
 	       "Supported kernel file types and options: \n");
 	for (i = 0; i < file_types; i++) {
 <at>  <at>  -1066,6 +1068,8  <at>  <at>  int main(int argc, char *argv[])
 		case OPT_VERSION:
 			version();
 			return 0;
+		case OPT_DEBUG:
+			kexec_debug = 1;
 		case OPT_NOIFDOWN:
 			do_ifdown = 0;
 			break;
diff --git a/kexec/kexec.h b/kexec/kexec.h
index 9b59890..dfd3630 100644
--- a/kexec/kexec.h
+++ b/kexec/kexec.h
 <at>  <at>  -95,6 +95,13  <at>  <at>  do { \
 } while(0)

 extern unsigned long long mem_min, mem_max;
+extern int kexec_debug;
+
+#define dbgprintf(...) \
+do { \
+	if (kexec_debug) \
+		fprintf(stderr, __VA_ARGS__); \
+} while(0)

 struct kexec_segment {
 	const void *buf;
 <at>  <at>  -198,6 +205,7  <at>  <at>  extern int file_types;
 	{ "mem-min",		1, 0, OPT_MEM_MIN }, \
 	{ "mem-max",		1, 0, OPT_MEM_MAX }, \
 	{ "reuseinitrd",	0, 0, OPT_REUSE_INITRD }, \
+	{ "debug",		0, 0, OPT_DEBUG }, \

 #define KEXEC_OPT_STR "hvdfxluet:p"

 <at>  <at>  -258,13 +266,6  <at>  <at>  extern int add_backup_segments(struct kexec_info *info,

 #define MAX_LINE	160

-#ifdef DEBUG
-#define dbgprintf(_args...) do {printf(_args);} while(0)
-#else
-static inline int __attribute__ ((format (printf, 1, 2)))
-	dbgprintf(const char *UNUSED(fmt), ...) {return 0;}
-#endif
-
 char *concat_cmdline(const char *base, const char *append);

 #endif /* KEXEC_H */
--

-- 
1.7.7.6
Cong Wang | 8 Mar 2012 07:39
Picon

[PATCH 2/5] ppc: move DEBUG code to --debug

Like patch 1/5, this one moves code under #if DEBUG to --debug
on ppc arch.

Signed-off-by: Cong Wang <xiyou.wangcong@...>
---
 kexec/arch/ppc/crashdump-powerpc.c |   18 ++++++++----------
 kexec/arch/ppc/fixup_dtb.c         |   25 +++++++++++--------------
 kexec/arch/ppc/fs2dt.c             |    6 +++---
 kexec/arch/ppc/kexec-ppc.c         |   17 ++++++++---------
 kexec/arch/ppc/libfdt-wrapper.c    |    4 ++--
 kexec/arch/ppc64/crashdump-ppc64.c |   16 ++++++----------
 kexec/arch/ppc64/kexec-elf-ppc64.c |   23 +++++++++++------------
 kexec/arch/ppc64/kexec-ppc64.c     |    9 +++------
 8 files changed, 52 insertions(+), 66 deletions(-)

diff --git a/kexec/arch/ppc/crashdump-powerpc.c b/kexec/arch/ppc/crashdump-powerpc.c
index 7c9dbff..1bef69b 100644
--- a/kexec/arch/ppc/crashdump-powerpc.c
+++ b/kexec/arch/ppc/crashdump-powerpc.c
 <at>  <at>  -226,15 +226,15  <at>  <at>  static int get_crash_memory_ranges(struct memory_range **range, int *ranges)

 	*range = crash_memory_range;
 	*ranges = memory_ranges;
-#if DEBUG
+
 	int j;
-	printf("CRASH MEMORY RANGES\n");
+	dbgprintf("CRASH MEMORY RANGES\n");
 	for (j = 0; j < *ranges; j++) {
 		start = crash_memory_range[j].start;
 		end = crash_memory_range[j].end;
-		fprintf(stderr, "%016Lx-%016Lx\n", start, end);
+		dbgprintf("%016Lx-%016Lx\n", start, end);
 	}
-#endif
+
 	return 0;

 err:
 <at>  <at>  -289,9 +289,9  <at>  <at>  static int add_cmdline_param(char *cmdline, unsigned long long addr,
 	if (cmdlen > (COMMAND_LINE_SIZE - 1))
 		die("Command line overflow\n");
 	strcat(cmdline, str);
-#if DEBUG
-	fprintf(stderr, "Command line after adding elfcorehdr: %s\n", cmdline);
-#endif
+
+	dbgprintf("Command line after adding elfcorehdr: %s\n", cmdline);
+
 	return 0;
 }

 <at>  <at>  -403,10 +403,8  <at>  <at>  void add_usable_mem_rgns(unsigned long long base, unsigned long long size)
 	usablemem_rgns.ranges[usablemem_rgns.size].start = base;
 	usablemem_rgns.ranges[usablemem_rgns.size++].end = end;

-#ifdef DEBUG
-	fprintf(stderr, "usable memory rgns size:%u base:%llx size:%llx\n",
+	dbgprintf("usable memory rgns size:%u base:%llx size:%llx\n",
 		usablemem_rgns.size, base, size);
-#endif
 }

 int is_crashkernel_mem_reserved(void)
diff --git a/kexec/arch/ppc/fixup_dtb.c b/kexec/arch/ppc/fixup_dtb.c
index 189e0c7..e5f2717 100644
--- a/kexec/arch/ppc/fixup_dtb.c
+++ b/kexec/arch/ppc/fixup_dtb.c
 <at>  <at>  -17,25 +17,26  <at>  <at> 

 const char proc_dts[] = "/proc/device-tree";

-#ifdef DEBUG
 static void print_fdt_reserve_regions(void)
 {
 	int i, num;

+	if (!kexec_debug)
+		return;
 	/* Print out a summary of the final reserve regions */
 	num =  fdt_num_mem_rsv(blob_buf);
-	printf ("reserve regions: %d\n", num);
+	dbgprintf ("reserve regions: %d\n", num);
 	for (i = 0; i < num; i++) {
 		uint64_t offset, size;

 		if (fdt_get_mem_rsv(blob_buf, i, &offset, &size) == 0) {
-			printf("%d: offset: %llx, size: %llx\n", i, offset, size);
+			dbgprintf("%d: offset: %llx, size: %llx\n", i, offset, size);
 		} else {
-			printf("Error retreiving reserved region\n");
+			dbgprintf("Error retreiving reserved region\n");
 		}
 	}
 }
-#endif
+

 static void fixup_nodes(char *nodes[])
 {
 <at>  <at>  -203,9 +204,7  <at>  <at>  static void fixup_reserve_regions(struct kexec_info *info, char *blob_buf)

 out:	;

-#ifdef DEBUG
 	print_fdt_reserve_regions();
-#endif
 }

 static void fixup_memory(struct kexec_info *info, char *blob_buf)
 <at>  <at>  -369,23 +368,23  <at>  <at>  char *fixup_dtb_init(struct kexec_info *info, char *blob_buf, off_t *blob_size,
 	return blob_buf;
 }

-#ifdef DEBUG
 static void save_fixed_up_dtb(char *blob_buf, off_t blob_size)
 {
 	FILE *fp;

+	if (!kexec_debug)
+		return;
 	fp = fopen("debug.dtb", "w");
 	if (fp) {
 		if ( blob_size == fwrite(blob_buf, sizeof(char), blob_size, fp)) {
-			printf("debug.dtb written\n");
+			dbgprintf("debug.dtb written\n");
 		} else {
-			printf("Unable to write debug.dtb\n");
+			dbgprintf("Unable to write debug.dtb\n");
 		}
 	} else {
-		printf("Unable to dump flat device tree to debug.dtb\n");
+		dbgprintf("Unable to dump flat device tree to debug.dtb\n");
 	}
 }
-#endif

 char *fixup_dtb_finalize(struct kexec_info *info, char *blob_buf, off_t *blob_size,
 			char *nodes[], char *cmdline)
 <at>  <at>  -400,9 +399,7  <at>  <at>  char *fixup_dtb_finalize(struct kexec_info *info, char *blob_buf, off_t *blob_si
 	blob_buf = (char *)dt_ops.finalize();
 	*blob_size = fdt_totalsize(blob_buf);

-#ifdef DEBUG
 	save_fixed_up_dtb(blob_buf, *blob_size);
-#endif

 	return blob_buf;
 }
diff --git a/kexec/arch/ppc/fs2dt.c b/kexec/arch/ppc/fs2dt.c
index 733515a..cdae69e 100644
--- a/kexec/arch/ppc/fs2dt.c
+++ b/kexec/arch/ppc/fs2dt.c
 <at>  <at>  -273,9 +273,9  <at>  <at>  static void putprops(char *fn, struct dirent **nlist, int numlist)
 			memcpy(dt, local_cmdline, cmd_len);
 			len = cmd_len;
 			*dt_len = cmd_len;
-#if	DEBUG
-			fprintf(stderr, "Modified cmdline:%s\n", local_cmdline);
-#endif
+
+			dbgprintf("Modified cmdline:%s\n", local_cmdline);
+
 		}

 		dt += (len + 3)/4;
diff --git a/kexec/arch/ppc/kexec-ppc.c b/kexec/arch/ppc/kexec-ppc.c
index 57852dc..6075477 100644
--- a/kexec/arch/ppc/kexec-ppc.c
+++ b/kexec/arch/ppc/kexec-ppc.c
 <at>  <at>  -378,9 +378,9  <at>  <at>  static int get_base_ranges(void)
 	nr_memory_ranges = local_memory_ranges;
 	sort_base_ranges();
 	memory_max = base_memory_range[nr_memory_ranges - 1].end;
-#ifdef DEBUG
-	fprintf(stderr, "get base memory ranges:%d\n", nr_memory_ranges);
-#endif
+
+	dbgprintf("get base memory ranges:%d\n", nr_memory_ranges);
+
 	return 0;
 }

 <at>  <at>  -716,13 +716,13  <at>  <at>  static int get_devtree_details(unsigned long kexec_flags)

 	sort_ranges();

-#ifdef DEBUG
+
 	int k;
 	for (k = 0; k < i; k++)
-		fprintf(stderr, "exclude_range sorted exclude_range[%d] "
+		dbgprintf("exclude_range sorted exclude_range[%d] "
 			"start:%llx, end:%llx\n", k, exclude_range[k].start,
 			exclude_range[k].end);
-#endif
+
 	return 0;

 error_openfile:
 <at>  <at>  -812,13 +812,12  <at>  <at>  static int setup_memory_ranges(unsigned long kexec_flags)
 	} else
 		nr_memory_ranges = j;

-#ifdef DEBUG
+
 	int k;
 	for (k = 0; k < j; k++)
-		fprintf(stderr, "setup_memory_ranges memory_range[%d] "
+		dbgprintf("setup_memory_ranges memory_range[%d] "
 				"start:%llx, end:%llx\n", k, memory_range[k].start,
 				memory_range[k].end);
-#endif
 	return 0;

 out:
diff --git a/kexec/arch/ppc/libfdt-wrapper.c b/kexec/arch/ppc/libfdt-wrapper.c
index f56ccc0..5fbd3a8 100644
--- a/kexec/arch/ppc/libfdt-wrapper.c
+++ b/kexec/arch/ppc/libfdt-wrapper.c
 <at>  <at>  -27,15 +27,15  <at>  <at> 
 #include <page.h>
 #include <libfdt.h>
 #include "ops.h"
+#include "../../kexec.h"

-#define DEBUG	0
 #define BAD_ERROR(err)	(((err) < 0) \
 			 && ((err) != -FDT_ERR_NOTFOUND) \
 			 && ((err) != -FDT_ERR_EXISTS))

 #define check_err(err) \
 	({ \
-		if (BAD_ERROR(err) || ((err < 0) && DEBUG)) \
+		if (BAD_ERROR(err) || ((err < 0) && kexec_debug)) \
 			printf("%s():%d  %s\n\r", __func__, __LINE__, \
 			       fdt_strerror(err)); \
 		if (BAD_ERROR(err)) \
diff --git a/kexec/arch/ppc64/crashdump-ppc64.c b/kexec/arch/ppc64/crashdump-ppc64.c
index d52b438..5805cdb 100644
--- a/kexec/arch/ppc64/crashdump-ppc64.c
+++ b/kexec/arch/ppc64/crashdump-ppc64.c
 <at>  <at>  -304,15 +304,15  <at>  <at>  static int get_crash_memory_ranges(struct memory_range **range, int *ranges)

 	*range = crash_memory_range;
 	*ranges = memory_ranges;
-#if DEBUG
+
 	int j;
-	printf("CRASH MEMORY RANGES\n");
+	dbgprintf("CRASH MEMORY RANGES\n");
 	for(j = 0; j < *ranges; j++) {
 		start = crash_memory_range[j].start;
 		end = crash_memory_range[j].end;
-		fprintf(stderr, "%016Lx-%016Lx\n", start, end);
+		dbgprintf("%016Lx-%016Lx\n", start, end);
 	}
-#endif
+
 	return 0;

 err:
 <at>  <at>  -367,9 +367,7  <at>  <at>  static int add_cmdline_param(char *cmdline, uint64_t addr, char *cmdstr,
 	if (cmdlen > (COMMAND_LINE_SIZE - 1))
 		die("Command line overflow\n");
 	strcat(cmdline, str);
-#if DEBUG
-	fprintf(stderr, "Command line after adding elfcorehdr: %s\n", cmdline);
-#endif
+	dbgprintf("Command line after adding elfcorehdr: %s\n", cmdline);
 	return 0;
 }

 <at>  <at>  -478,10 +476,8  <at>  <at>  void add_usable_mem_rgns(unsigned long long base, unsigned long long size)
 	usablemem_rgns.ranges[usablemem_rgns.size].start = base;
 	usablemem_rgns.ranges[usablemem_rgns.size++].end = end;

-#ifdef DEBUG
-	fprintf(stderr, "usable memory rgns size:%u base:%llx size:%llx\n",
+	dbgprintf("usable memory rgns size:%u base:%llx size:%llx\n",
 		usablemem_rgns.size, base, size);
-#endif
 }

 int is_crashkernel_mem_reserved(void)
diff --git a/kexec/arch/ppc64/kexec-elf-ppc64.c b/kexec/arch/ppc64/kexec-elf-ppc64.c
index abd83dd..f68f2bc 100644
--- a/kexec/arch/ppc64/kexec-elf-ppc64.c
+++ b/kexec/arch/ppc64/kexec-elf-ppc64.c
 <at>  <at>  -294,7 +294,7  <at>  <at>  int elf_ppc64_load(int argc, char **argv, const char *buf, off_t len,

 	/* Set debug */
 	elf_rel_set_symbol(&info->rhdr, "debug", &my_debug, sizeof(my_debug));
-#ifdef DEBUG
+
 	my_kernel = 0;
 	my_dt_offset = 0;
 	my_panic_kernel = 0;
 <at>  <at>  -318,19 +318,18  <at>  <at>  int elf_ppc64_load(int argc, char **argv, const char *buf, off_t len,
 				sizeof(toc_addr));
 	elf_rel_get_symbol(&info->rhdr, "debug", &my_debug, sizeof(my_debug));

-	fprintf(stderr, "info->entry is %p\n", info->entry);
-	fprintf(stderr, "kernel is %llx\n", (unsigned long long)my_kernel);
-	fprintf(stderr, "dt_offset is %llx\n",
+	dbgprintf("info->entry is %p\n", info->entry);
+	dbgprintf("kernel is %llx\n", (unsigned long long)my_kernel);
+	dbgprintf("dt_offset is %llx\n",
 		(unsigned long long)my_dt_offset);
-	fprintf(stderr, "run_at_load flag is %x\n", my_run_at_load);
-	fprintf(stderr, "panic_kernel is %x\n", my_panic_kernel);
-	fprintf(stderr, "backup_start is %llx\n",
+	dbgprintf("run_at_load flag is %x\n", my_run_at_load);
+	dbgprintf("panic_kernel is %x\n", my_panic_kernel);
+	dbgprintf("backup_start is %llx\n",
 		(unsigned long long)my_backup_start);
-	fprintf(stderr, "stack is %llx\n", (unsigned long long)my_stack);
-	fprintf(stderr, "toc_addr is %llx\n", (unsigned long long)toc_addr);
-	fprintf(stderr, "purgatory size is %zu\n", purgatory_size);
-	fprintf(stderr, "debug is %d\n", my_debug);
-#endif
+	dbgprintf("stack is %llx\n", (unsigned long long)my_stack);
+	dbgprintf("toc_addr is %llx\n", (unsigned long long)toc_addr);
+	dbgprintf("purgatory size is %zu\n", purgatory_size);
+	dbgprintf("debug is %d\n", my_debug);

 	for (i = 0; i < info->nr_segments; i++)
 		fprintf(stderr, "segment[%d].mem:%p memsz:%zu\n", i,
diff --git a/kexec/arch/ppc64/kexec-ppc64.c b/kexec/arch/ppc64/kexec-ppc64.c
index 48ea421..2f12907 100644
--- a/kexec/arch/ppc64/kexec-ppc64.c
+++ b/kexec/arch/ppc64/kexec-ppc64.c
 <at>  <at>  -594,13 +594,12  <at>  <at>  static int get_devtree_details(unsigned long kexec_flags)

 	sort_ranges();

-#ifdef DEBUG
 	int k;
 	for (k = 0; k < i; k++)
-		fprintf(stderr, "exclude_range sorted exclude_range[%d] "
+		dbgprintf("exclude_range sorted exclude_range[%d] "
 			"start:%llx, end:%llx\n", k, exclude_range[k].start,
 			exclude_range[k].end);
-#endif
+
 	return 0;

 error_openfile:
 <at>  <at>  -687,13 +686,11  <at>  <at>  int setup_memory_ranges(unsigned long kexec_flags)
 	}
 	nr_memory_ranges = j;

-#ifdef DEBUG
 	int k;
 	for (k = 0; k < j; k++)
-		fprintf(stderr, "setup_memory_ranges memory_range[%d] "
+		dbgprintf("setup_memory_ranges memory_range[%d] "
 			"start:%llx, end:%llx\n", k, memory_range[k].start,
 			memory_range[k].end);
-#endif
 	return 0;

 out:

Gmane