All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michael Holzheu <holzheu@linux.vnet.ibm.com>
To: Xunlei Pang <xlpang@redhat.com>
Cc: linux-kernel@vger.kernel.org, kexec@lists.infradead.org,
	akpm@linux-foundation.org, ebiederm@xmission.com,
	Minfei Huang <mhuang@redhat.com>, Vivek Goyal <vgoyal@redhat.com>,
	Baoquan He <bhe@redhat.com>,
	Martin Schwidefsky <schwidefsky@de.ibm.com>,
	Heiko Carstens <heiko.carstens@de.ibm.com>
Subject: Re: [PATCH] s390/kexec: Consolidate crash_map/unmap_reserved_pages() and arch_kexec_protect(unprotect)_crashkres()
Date: Fri, 1 Apr 2016 19:41:54 +0200	[thread overview]
Message-ID: <20160401194154.1b4c623f@holzheu> (raw)
In-Reply-To: <1459338441-21919-1-git-send-email-xlpang@redhat.com>

Hello Xunlei again,

Some initial comments below...

On Wed, 30 Mar 2016 19:47:21 +0800
Xunlei Pang <xlpang@redhat.com> wrote:

> Commit 3f625002581b ("kexec: introduce a protection mechanism
> for the crashkernel reserved memory") is a similar mechanism
> for protecting the crash kernel reserved memory to previous
> crash_map/unmap_reserved_pages() implementation, the new one
> is more generic in name and cleaner in code (besides, some
> arch may not be allowed to unmap the pgtable).
> 
> Therefore, this patch consolidates them, and uses the new
> arch_kexec_protect(unprotect)_crashkres() to replace former
> crash_map/unmap_reserved_pages() which by now has been only
> used by S390.
> 
> The consolidation work needs the crash memory to be mapped
> initially, so get rid of S390 crash kernel memblock removal
> in reserve_crashkernel(). Once kdump kernel is loaded, the
> new arch_kexec_protect_crashkres() implemented for S390 will
> actually unmap the pgtable like before.
> 
> The patch also fixed a S390 crash_shrink_memory() bad page warning
> in passing due to not using memblock_reserve():
>   BUG: Bad page state in process bash  pfn:7e400
>   page:000003d101f90000 count:0 mapcount:1 mapping: (null) index:0x0
>   flags: 0x0()
>   page dumped because: nonzero mapcount
>   Modules linked in: ghash_s390 prng aes_s390 des_s390 des_generic
>   CPU: 0 PID: 1558 Comm: bash Not tainted 4.6.0-rc1-next-20160327 #1
>        0000000073007a58 0000000073007ae8 0000000000000002 0000000000000000
>        0000000073007b88 0000000073007b00 0000000073007b00 000000000022cf4e
>        0000000000a579b8 00000000007b0dd6 0000000000791a8c
>        000000000000000b
>        0000000073007b48 0000000073007ae8 0000000000000000 0000000000000000
>        070003d100000001 0000000000112f20 0000000073007ae8 0000000073007b48
>   Call Trace:
>   ([<0000000000112e0c>] show_trace+0x5c/0x78)
>   ([<0000000000112ed4>] show_stack+0x6c/0xe8)
>   ([<00000000003f28dc>] dump_stack+0x84/0xb8)
>   ([<0000000000235454>] bad_page+0xec/0x158)
>   ([<00000000002357a4>] free_pages_prepare+0x2e4/0x308)
>   ([<00000000002383a2>] free_hot_cold_page+0x42/0x198)
>   ([<00000000001c45e0>] crash_free_reserved_phys_range+0x60/0x88)
>   ([<00000000001c49b0>] crash_shrink_memory+0xb8/0x1a0)
>   ([<000000000015bcae>] kexec_crash_size_store+0x46/0x60)
>   ([<000000000033d326>] kernfs_fop_write+0x136/0x180)
>   ([<00000000002b253c>] __vfs_write+0x3c/0x100)
>   ([<00000000002b35ce>] vfs_write+0x8e/0x190)
>   ([<00000000002b4ca0>] SyS_write+0x60/0xd0)
>   ([<000000000063067c>] system_call+0x244/0x264)
> 
> Cc: Michael Holzheu <holzheu@linux.vnet.ibm.com>
> Signed-off-by: Xunlei Pang <xlpang@redhat.com>
> ---
> Tested kexec/kdump on S390x
> 
>  arch/s390/kernel/machine_kexec.c | 86 ++++++++++++++++++++++------------------
>  arch/s390/kernel/setup.c         |  7 ++--
>  include/linux/kexec.h            |  2 -
>  kernel/kexec.c                   | 12 ------
>  kernel/kexec_core.c              | 11 +----
>  5 files changed, 54 insertions(+), 64 deletions(-)
> 
> diff --git a/arch/s390/kernel/machine_kexec.c b/arch/s390/kernel/machine_kexec.c
> index 2f1b721..1ec6cfc 100644
> --- a/arch/s390/kernel/machine_kexec.c
> +++ b/arch/s390/kernel/machine_kexec.c
> @@ -35,6 +35,52 @@ extern const unsigned long long relocate_kernel_len;
>  #ifdef CONFIG_CRASH_DUMP
> 
>  /*
> + * Map or unmap crashkernel memory
> + */
> +static void crash_map_pages(int enable)
> +{
> +	unsigned long size = resource_size(&crashk_res);
> +
> +	BUG_ON(crashk_res.start % KEXEC_CRASH_MEM_ALIGN ||
> +	       size % KEXEC_CRASH_MEM_ALIGN);
> +	if (enable)
> +		vmem_add_mapping(crashk_res.start, size);
> +	else {
> +		vmem_remove_mapping(crashk_res.start, size);
> +		if (size)
> +			os_info_crashkernel_add(crashk_res.start, size);
> +		else
> +			os_info_crashkernel_add(0, 0);
> +	}
> +}

Please do not move these functions in the file. If you leave it at their
old location, the patch will be *much* smaller.

> +
> +/*
> + * Map crashkernel memory
> + */
> +static void crash_map_reserved_pages(void)
> +{
> +	crash_map_pages(1);
> +}
> +
> +/*
> + * Unmap crashkernel memory
> + */
> +static void crash_unmap_reserved_pages(void)
> +{
> +	crash_map_pages(0);
> +}
> +
> +void arch_kexec_protect_crashkres(void)
> +{
> +	crash_unmap_reserved_pages();
> +}
> +
> +void arch_kexec_unprotect_crashkres(void)
> +{
> +	crash_map_reserved_pages();
> +}

Please replace the crash_(un)map_reserved_pages functions
with the new arch_kexec_(un)protect() functions like the following:

/*
 * Unmap crashkernel memory
 */
void arch_kexec_protect_crashkres(void)
{
        crash_map_pages(0);
}

/*
 * Map crashkernel memory
 */
void arch_kexec_unprotect_crashkres(void)
{
        crash_map_pages(1);
}

... and remove the old functions.

> +
> +/*
>   * PM notifier callback for kdump
>   */
>  static int machine_kdump_pm_cb(struct notifier_block *nb, unsigned long action,
> @@ -43,12 +89,12 @@ static int machine_kdump_pm_cb(struct notifier_block *nb, unsigned long action,
>  	switch (action) {
>  	case PM_SUSPEND_PREPARE:
>  	case PM_HIBERNATION_PREPARE:
> -		if (crashk_res.start)
> +		if (kexec_crash_image)

Why this change?

>  			crash_map_reserved_pages();

arch_kexec_unprotect_crashkres();

>  		break;
>  	case PM_POST_SUSPEND:
>  	case PM_POST_HIBERNATION:
> -		if (crashk_res.start)
> +		if (kexec_crash_image)

Why this change?

>  			crash_unmap_reserved_pages();

arch_kexec_protect_crashkres();

>  		break;
>  	default:
> @@ -147,42 +193,6 @@ static int kdump_csum_valid(struct kimage *image)
>  }
> 
>  /*
> - * Map or unmap crashkernel memory
> - */
> -static void crash_map_pages(int enable)
> -{
> -	unsigned long size = resource_size(&crashk_res);
> -
> -	BUG_ON(crashk_res.start % KEXEC_CRASH_MEM_ALIGN ||
> -	       size % KEXEC_CRASH_MEM_ALIGN);
> -	if (enable)
> -		vmem_add_mapping(crashk_res.start, size);
> -	else {
> -		vmem_remove_mapping(crashk_res.start, size);
> -		if (size)
> -			os_info_crashkernel_add(crashk_res.start, size);
> -		else
> -			os_info_crashkernel_add(0, 0);
> -	}
> -}
> -
> -/*
> - * Map crashkernel memory
> - */
> -void crash_map_reserved_pages(void)
> -{
> -	crash_map_pages(1);
> -}
> -
> -/*
> - * Unmap crashkernel memory
> - */
> -void crash_unmap_reserved_pages(void)
> -{
> -	crash_map_pages(0);
> -}
> -
> -/*
>   * Give back memory to hypervisor before new kdump is loaded
>   */
>  static int machine_kexec_prepare_kdump(void)
> diff --git a/arch/s390/kernel/setup.c b/arch/s390/kernel/setup.c
> index d3f9688..5f00437 100644
> --- a/arch/s390/kernel/setup.c
> +++ b/arch/s390/kernel/setup.c
> @@ -603,7 +603,7 @@ static void __init reserve_crashkernel(void)
>  	crashk_res.start = crash_base;
>  	crashk_res.end = crash_base + crash_size - 1;
>  	insert_resource(&iomem_resource, &crashk_res);
> -	memblock_remove(crash_base, crash_size);
> +	memblock_reserve(crash_base, crash_size);

I will discuss this next week in our team.

>  	pr_info("Reserving %lluMB of memory at %lluMB "
>  		"for crashkernel (System RAM: %luMB)\n",
>  		crash_size >> 20, crash_base >> 20,
> @@ -871,7 +871,6 @@ void __init setup_arch(char **cmdline_p)
>  	setup_memory();
> 
>  	check_initrd();
> -	reserve_crashkernel();
>  #ifdef CONFIG_CRASH_DUMP
>  	/*
>  	 * Be aware that smp_save_dump_cpus() triggers a system reset.
> @@ -890,7 +889,9 @@ void __init setup_arch(char **cmdline_p)
>  	/*
>  	 * Create kernel page tables and switch to virtual addressing.
>  	 */
> -        paging_init();
> +	paging_init();
> +
> +	reserve_crashkernel();

I will discuss this next week in our team.

Michael

WARNING: multiple messages have this Message-ID (diff)
From: Michael Holzheu <holzheu@linux.vnet.ibm.com>
To: Xunlei Pang <xlpang@redhat.com>
Cc: Baoquan He <bhe@redhat.com>, Minfei Huang <mhuang@redhat.com>,
	Heiko Carstens <heiko.carstens@de.ibm.com>,
	kexec@lists.infradead.org, linux-kernel@vger.kernel.org,
	ebiederm@xmission.com,
	Martin Schwidefsky <schwidefsky@de.ibm.com>,
	akpm@linux-foundation.org, Vivek Goyal <vgoyal@redhat.com>
Subject: Re: [PATCH] s390/kexec: Consolidate crash_map/unmap_reserved_pages() and arch_kexec_protect(unprotect)_crashkres()
Date: Fri, 1 Apr 2016 19:41:54 +0200	[thread overview]
Message-ID: <20160401194154.1b4c623f@holzheu> (raw)
In-Reply-To: <1459338441-21919-1-git-send-email-xlpang@redhat.com>

Hello Xunlei again,

Some initial comments below...

On Wed, 30 Mar 2016 19:47:21 +0800
Xunlei Pang <xlpang@redhat.com> wrote:

> Commit 3f625002581b ("kexec: introduce a protection mechanism
> for the crashkernel reserved memory") is a similar mechanism
> for protecting the crash kernel reserved memory to previous
> crash_map/unmap_reserved_pages() implementation, the new one
> is more generic in name and cleaner in code (besides, some
> arch may not be allowed to unmap the pgtable).
> 
> Therefore, this patch consolidates them, and uses the new
> arch_kexec_protect(unprotect)_crashkres() to replace former
> crash_map/unmap_reserved_pages() which by now has been only
> used by S390.
> 
> The consolidation work needs the crash memory to be mapped
> initially, so get rid of S390 crash kernel memblock removal
> in reserve_crashkernel(). Once kdump kernel is loaded, the
> new arch_kexec_protect_crashkres() implemented for S390 will
> actually unmap the pgtable like before.
> 
> The patch also fixed a S390 crash_shrink_memory() bad page warning
> in passing due to not using memblock_reserve():
>   BUG: Bad page state in process bash  pfn:7e400
>   page:000003d101f90000 count:0 mapcount:1 mapping: (null) index:0x0
>   flags: 0x0()
>   page dumped because: nonzero mapcount
>   Modules linked in: ghash_s390 prng aes_s390 des_s390 des_generic
>   CPU: 0 PID: 1558 Comm: bash Not tainted 4.6.0-rc1-next-20160327 #1
>        0000000073007a58 0000000073007ae8 0000000000000002 0000000000000000
>        0000000073007b88 0000000073007b00 0000000073007b00 000000000022cf4e
>        0000000000a579b8 00000000007b0dd6 0000000000791a8c
>        000000000000000b
>        0000000073007b48 0000000073007ae8 0000000000000000 0000000000000000
>        070003d100000001 0000000000112f20 0000000073007ae8 0000000073007b48
>   Call Trace:
>   ([<0000000000112e0c>] show_trace+0x5c/0x78)
>   ([<0000000000112ed4>] show_stack+0x6c/0xe8)
>   ([<00000000003f28dc>] dump_stack+0x84/0xb8)
>   ([<0000000000235454>] bad_page+0xec/0x158)
>   ([<00000000002357a4>] free_pages_prepare+0x2e4/0x308)
>   ([<00000000002383a2>] free_hot_cold_page+0x42/0x198)
>   ([<00000000001c45e0>] crash_free_reserved_phys_range+0x60/0x88)
>   ([<00000000001c49b0>] crash_shrink_memory+0xb8/0x1a0)
>   ([<000000000015bcae>] kexec_crash_size_store+0x46/0x60)
>   ([<000000000033d326>] kernfs_fop_write+0x136/0x180)
>   ([<00000000002b253c>] __vfs_write+0x3c/0x100)
>   ([<00000000002b35ce>] vfs_write+0x8e/0x190)
>   ([<00000000002b4ca0>] SyS_write+0x60/0xd0)
>   ([<000000000063067c>] system_call+0x244/0x264)
> 
> Cc: Michael Holzheu <holzheu@linux.vnet.ibm.com>
> Signed-off-by: Xunlei Pang <xlpang@redhat.com>
> ---
> Tested kexec/kdump on S390x
> 
>  arch/s390/kernel/machine_kexec.c | 86 ++++++++++++++++++++++------------------
>  arch/s390/kernel/setup.c         |  7 ++--
>  include/linux/kexec.h            |  2 -
>  kernel/kexec.c                   | 12 ------
>  kernel/kexec_core.c              | 11 +----
>  5 files changed, 54 insertions(+), 64 deletions(-)
> 
> diff --git a/arch/s390/kernel/machine_kexec.c b/arch/s390/kernel/machine_kexec.c
> index 2f1b721..1ec6cfc 100644
> --- a/arch/s390/kernel/machine_kexec.c
> +++ b/arch/s390/kernel/machine_kexec.c
> @@ -35,6 +35,52 @@ extern const unsigned long long relocate_kernel_len;
>  #ifdef CONFIG_CRASH_DUMP
> 
>  /*
> + * Map or unmap crashkernel memory
> + */
> +static void crash_map_pages(int enable)
> +{
> +	unsigned long size = resource_size(&crashk_res);
> +
> +	BUG_ON(crashk_res.start % KEXEC_CRASH_MEM_ALIGN ||
> +	       size % KEXEC_CRASH_MEM_ALIGN);
> +	if (enable)
> +		vmem_add_mapping(crashk_res.start, size);
> +	else {
> +		vmem_remove_mapping(crashk_res.start, size);
> +		if (size)
> +			os_info_crashkernel_add(crashk_res.start, size);
> +		else
> +			os_info_crashkernel_add(0, 0);
> +	}
> +}

Please do not move these functions in the file. If you leave it at their
old location, the patch will be *much* smaller.

> +
> +/*
> + * Map crashkernel memory
> + */
> +static void crash_map_reserved_pages(void)
> +{
> +	crash_map_pages(1);
> +}
> +
> +/*
> + * Unmap crashkernel memory
> + */
> +static void crash_unmap_reserved_pages(void)
> +{
> +	crash_map_pages(0);
> +}
> +
> +void arch_kexec_protect_crashkres(void)
> +{
> +	crash_unmap_reserved_pages();
> +}
> +
> +void arch_kexec_unprotect_crashkres(void)
> +{
> +	crash_map_reserved_pages();
> +}

Please replace the crash_(un)map_reserved_pages functions
with the new arch_kexec_(un)protect() functions like the following:

/*
 * Unmap crashkernel memory
 */
void arch_kexec_protect_crashkres(void)
{
        crash_map_pages(0);
}

/*
 * Map crashkernel memory
 */
void arch_kexec_unprotect_crashkres(void)
{
        crash_map_pages(1);
}

... and remove the old functions.

> +
> +/*
>   * PM notifier callback for kdump
>   */
>  static int machine_kdump_pm_cb(struct notifier_block *nb, unsigned long action,
> @@ -43,12 +89,12 @@ static int machine_kdump_pm_cb(struct notifier_block *nb, unsigned long action,
>  	switch (action) {
>  	case PM_SUSPEND_PREPARE:
>  	case PM_HIBERNATION_PREPARE:
> -		if (crashk_res.start)
> +		if (kexec_crash_image)

Why this change?

>  			crash_map_reserved_pages();

arch_kexec_unprotect_crashkres();

>  		break;
>  	case PM_POST_SUSPEND:
>  	case PM_POST_HIBERNATION:
> -		if (crashk_res.start)
> +		if (kexec_crash_image)

Why this change?

>  			crash_unmap_reserved_pages();

arch_kexec_protect_crashkres();

>  		break;
>  	default:
> @@ -147,42 +193,6 @@ static int kdump_csum_valid(struct kimage *image)
>  }
> 
>  /*
> - * Map or unmap crashkernel memory
> - */
> -static void crash_map_pages(int enable)
> -{
> -	unsigned long size = resource_size(&crashk_res);
> -
> -	BUG_ON(crashk_res.start % KEXEC_CRASH_MEM_ALIGN ||
> -	       size % KEXEC_CRASH_MEM_ALIGN);
> -	if (enable)
> -		vmem_add_mapping(crashk_res.start, size);
> -	else {
> -		vmem_remove_mapping(crashk_res.start, size);
> -		if (size)
> -			os_info_crashkernel_add(crashk_res.start, size);
> -		else
> -			os_info_crashkernel_add(0, 0);
> -	}
> -}
> -
> -/*
> - * Map crashkernel memory
> - */
> -void crash_map_reserved_pages(void)
> -{
> -	crash_map_pages(1);
> -}
> -
> -/*
> - * Unmap crashkernel memory
> - */
> -void crash_unmap_reserved_pages(void)
> -{
> -	crash_map_pages(0);
> -}
> -
> -/*
>   * Give back memory to hypervisor before new kdump is loaded
>   */
>  static int machine_kexec_prepare_kdump(void)
> diff --git a/arch/s390/kernel/setup.c b/arch/s390/kernel/setup.c
> index d3f9688..5f00437 100644
> --- a/arch/s390/kernel/setup.c
> +++ b/arch/s390/kernel/setup.c
> @@ -603,7 +603,7 @@ static void __init reserve_crashkernel(void)
>  	crashk_res.start = crash_base;
>  	crashk_res.end = crash_base + crash_size - 1;
>  	insert_resource(&iomem_resource, &crashk_res);
> -	memblock_remove(crash_base, crash_size);
> +	memblock_reserve(crash_base, crash_size);

I will discuss this next week in our team.

>  	pr_info("Reserving %lluMB of memory at %lluMB "
>  		"for crashkernel (System RAM: %luMB)\n",
>  		crash_size >> 20, crash_base >> 20,
> @@ -871,7 +871,6 @@ void __init setup_arch(char **cmdline_p)
>  	setup_memory();
> 
>  	check_initrd();
> -	reserve_crashkernel();
>  #ifdef CONFIG_CRASH_DUMP
>  	/*
>  	 * Be aware that smp_save_dump_cpus() triggers a system reset.
> @@ -890,7 +889,9 @@ void __init setup_arch(char **cmdline_p)
>  	/*
>  	 * Create kernel page tables and switch to virtual addressing.
>  	 */
> -        paging_init();
> +	paging_init();
> +
> +	reserve_crashkernel();

I will discuss this next week in our team.

Michael


_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

  parent reply	other threads:[~2016-04-01 17:42 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-30 11:47 [PATCH] s390/kexec: Consolidate crash_map/unmap_reserved_pages() and arch_kexec_protect(unprotect)_crashkres() Xunlei Pang
2016-03-30 11:47 ` Xunlei Pang
2016-03-30 12:30 ` Baoquan He
2016-03-30 12:30   ` Baoquan He
2016-03-31  2:43   ` Minfei Huang
2016-03-31  2:43     ` Minfei Huang
2016-03-31  2:52     ` Baoquan He
2016-03-31  2:52       ` Baoquan He
2016-03-31  3:52       ` Xunlei Pang
2016-03-31  3:52         ` Xunlei Pang
2016-04-06 12:26         ` Xunlei Pang
2016-04-06 12:26           ` Xunlei Pang
2016-03-31  3:05   ` Xunlei Pang
2016-04-01 16:38 ` Michael Holzheu
2016-04-01 16:38   ` Michael Holzheu
2016-04-01 17:41 ` Michael Holzheu [this message]
2016-04-01 17:41   ` Michael Holzheu
2016-04-02  1:23   ` Xunlei Pang
2016-04-02  1:23     ` Xunlei Pang
2016-04-04 14:58     ` Michael Holzheu
2016-04-04 14:58       ` Michael Holzheu
2016-04-05  4:52       ` Xunlei Pang
2016-04-05  4:52         ` Xunlei Pang

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=20160401194154.1b4c623f@holzheu \
    --to=holzheu@linux.vnet.ibm.com \
    --cc=akpm@linux-foundation.org \
    --cc=bhe@redhat.com \
    --cc=ebiederm@xmission.com \
    --cc=heiko.carstens@de.ibm.com \
    --cc=kexec@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhuang@redhat.com \
    --cc=schwidefsky@de.ibm.com \
    --cc=vgoyal@redhat.com \
    --cc=xlpang@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.