public inbox for linux-arm-kernel@lists.infradead.org 
 help / color / mirror / Atom feed
From: james.morse@arm•com (James Morse)
To: linux-arm-kernel@lists•infradead.org
Subject: [PATCH v18 04/13] arm64/kexec: Add pr_debug output
Date: Wed, 15 Jun 2016 18:14:19 +0100	[thread overview]
Message-ID: <57618CEB.6040807@arm.com> (raw)
In-Reply-To: <cfd2d457d5f1991c82b641970ce20475bcc6c7dd.1465502767.git.geoff@infradead.org>

Hi Geoff,

On 09/06/16 21:08, Geoff Levand wrote:
> To aid in debugging kexec problems or when adding new functionality to kexec add
> a new routine kexec_image_info() and several inline pr_debug statements.
> 
> Signed-off-by: Geoff Levand <geoff@infradead•org>
> ---
>  arch/arm64/kernel/machine_kexec.c | 63 +++++++++++++++++++++++++++++++++++++++
>  1 file changed, 63 insertions(+)
> 
> diff --git a/arch/arm64/kernel/machine_kexec.c b/arch/arm64/kernel/machine_kexec.c
> index 05f7c21..0a8b04d 100644
> --- a/arch/arm64/kernel/machine_kexec.c
> +++ b/arch/arm64/kernel/machine_kexec.c
> @@ -11,6 +11,7 @@
>  
>  #include <linux/highmem.h>
>  #include <linux/kexec.h>
> +#include <linux/libfdt_env.h>
>  #include <linux/of_fdt.h>
>  #include <linux/slab.h>
>  #include <linux/smp.h>
> @@ -29,6 +30,47 @@ extern const unsigned long arm64_relocate_new_kernel_size;
>  
>  static unsigned long kimage_start;
>  
> +/**
> + * kexec_is_dtb - Helper routine to check the device tree header signature.
> + */
> +static bool kexec_is_dtb(const void *dtb)
> +{
> +	__be32 magic;
> +
> +	if (get_user(magic, (__be32 *)dtb))
> +		return false;
> +

You pass this function 'kimage->segment[i].buf', this looks like the user space
memory that contained the dtb when kexec-tools first ran to load the image.

This will work when you call it from machine_kexec_prepare(), but by the time we
get to machine_kexec() that process is long gone, and this pointer should be
considered junk.

I don't think its possible to find this information from machine_kexec(), as the
DTB will be split up into page size chunks and scattered through memory.


> +	return fdt32_to_cpu(magic) == OF_DT_HEADER;
> +}
> +
> +/**
> + * kexec_image_info - For debugging output.
> + */
> +#define kexec_image_info(_i) _kexec_image_info(__func__, __LINE__, _i)
> +static void _kexec_image_info(const char *func, int line,
> +	const struct kimage *kimage)
> +{
> +	unsigned long i;
> +
> +	pr_debug("%s:%d:\n", func, line);
> +	pr_debug("  kexec kimage info:\n");
> +	pr_debug("    type:        %d\n", kimage->type);
> +	pr_debug("    start:       %lx\n", kimage->start);
> +	pr_debug("    head:        %lx\n", kimage->head);
> +	pr_debug("    nr_segments: %lu\n", kimage->nr_segments);
> +
> +	for (i = 0; i < kimage->nr_segments; i++) {
> +		pr_debug("      segment[%lu]: %016lx - %016lx, 0x%lx bytes, %lu pages%s\n",
> +			i,
> +			kimage->segment[i].mem,
> +			kimage->segment[i].mem + kimage->segment[i].memsz,
> +			kimage->segment[i].memsz,
> +			kimage->segment[i].memsz /  PAGE_SIZE,
> +			(kexec_is_dtb(kimage->segment[i].buf) ?
> +				", dtb segment" : ""));
> +	}
> +}
> +
>  void machine_kexec_cleanup(struct kimage *kimage)
>  {
>  	/* Empty routine needed to avoid build errors. */
> @@ -65,6 +107,8 @@ int machine_kexec_prepare(struct kimage *kimage)
>  		}
>  	}
>  
> +	kexec_image_info(kimage);
> +

You want to put this at the start of machine_kexec_prepare(), otherwise we may
return from:
> #ifdef CONFIG_HOTPLUG_CPU
> 	/* any_cpu as we don't mind being preempted */
> 	int any_cpu = raw_smp_processor_id();
>
> 	if (cpu_ops[any_cpu]->cpu_die)
> 		return 0;
> #endif /* CONFIG_HOTPLUG_CPU */

This maybe-return-an-error block needs to be the last thing in the function.


I'm not sure if the debug output is actually useful this early: kexec-tools
prints out exactly the same information shortly after this function returns.


>  	return 0;
>  }
>  
> @@ -140,6 +184,25 @@ void machine_kexec(struct kimage *kimage)
>  	reboot_code_buffer_phys = page_to_phys(kimage->control_code_page);
>  	reboot_code_buffer = kmap(kimage->control_code_page);
>  
> +	kexec_image_info(kimage);
> +
> +	pr_debug("%s:%d: control_code_page:        %p\n", __func__, __LINE__,
> +		kimage->control_code_page);
> +	pr_debug("%s:%d: reboot_code_buffer_phys:  %pa\n", __func__, __LINE__,
> +		&reboot_code_buffer_phys);
> +	pr_debug("%s:%d: reboot_code_buffer:       %p\n", __func__, __LINE__,
> +		reboot_code_buffer);
> +	pr_debug("%s:%d: relocate_new_kernel:      %p\n", __func__, __LINE__,
> +		arm64_relocate_new_kernel);
> +	pr_debug("%s:%d: relocate_new_kernel_size: 0x%lx(%lu) bytes\n",
> +		__func__, __LINE__, arm64_relocate_new_kernel_size,
> +		arm64_relocate_new_kernel_size);
> +
> +	pr_debug("%s:%d: kimage_head:              %lx\n", __func__, __LINE__,
> +		kimage->head);
> +	pr_debug("%s:%d: kimage_start:             %lx\n", __func__, __LINE__,
> +		kimage_start);
> +
>  	/*
>  	 * Copy arm64_relocate_new_kernel to the reboot_code_buffer for use
>  	 * after the kernel is shut down.
> 


Thanks,

James

  reply	other threads:[~2016-06-15 17:14 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-09 20:08 [PATCH v18 00/13] arm64 kexec kernel patches Geoff Levand
2016-06-09 20:08 ` [PATCH v18 07/13] arm64: limit memory regions based on DT property, usable-memory Geoff Levand
2016-06-09 20:08 ` [PATCH v18 06/13] arm64: kdump: reserve memory for crash dump kernel Geoff Levand
2016-06-09 20:08 ` [PATCH v18 03/13] arm64/kexec: Add core kexec support Geoff Levand
2016-06-15  8:14   ` AKASHI Takahiro
2016-06-15 17:10   ` James Morse
2016-06-16 22:41     ` Geoff Levand
2016-06-09 20:08 ` [PATCH v18 09/13] arm64: kdump: add kdump support Geoff Levand
2016-06-09 20:08 ` [PATCH v18 01/13] arm64: Add back cpu reset routines Geoff Levand
2016-06-09 20:08 ` [PATCH v18 05/13] arm64/kexec: Enable kexec in the arm64 defconfig Geoff Levand
2016-06-09 20:08 ` [PATCH v18 08/13] arm64: kdump: implement machine_crash_shutdown() Geoff Levand
2016-06-14  7:13   ` AKASHI Takahiro
2016-06-14 21:56     ` Geoff Levand
2016-06-09 20:08 ` [PATCH v18 04/13] arm64/kexec: Add pr_debug output Geoff Levand
2016-06-15 17:14   ` James Morse [this message]
2016-06-16 22:58     ` Geoff Levand
2016-06-09 20:08 ` [PATCH v18 02/13] arm64: Add cpus_are_stuck_in_kernel Geoff Levand
2016-06-09 20:08 ` [PATCH v18 13/13] Documentation: dt: usable-memory and elfcorehdr nodes for arm64 kexec Geoff Levand
2016-06-09 20:08 ` [PATCH v18 12/13] arm64: kdump: update a kernel doc Geoff Levand
2016-06-09 20:08 ` [PATCH v18 11/13] arm64: kdump: enable kdump in the arm64 defconfig Geoff Levand
2016-06-09 20:08 ` [PATCH v18 10/13] arm64: kdump: add VMCOREINFO for user-space coredump tools Geoff Levand

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=57618CEB.6040807@arm.com \
    --to=james.morse@arm$(echo .)com \
    --cc=linux-arm-kernel@lists$(echo .)infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox