kexec.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Dave Young <dyoung@redhat.com>
To: Xunlei Pang <xlpang@redhat.com>
Cc: Baoquan He <bhe@redhat.com>,
	kexec@lists.infradead.org, linux-kernel@vger.kernel.org,
	ebiederm@xmission.com, akpm@linux-foundation.org,
	yinghai@kernel.org, Vivek Goyal <vgoyal@redhat.com>
Subject: Re: [PATCH v2 1/2] kexec: Introduce "/sys/kernel/kexec_crash_low_size"
Date: Wed, 17 Aug 2016 16:20:34 +0800	[thread overview]
Message-ID: <20160817082034.GA11837@dhcp-128-65.nay.redhat.com> (raw)
In-Reply-To: <1471398657-20237-1-git-send-email-xlpang@redhat.com>

On 08/17/16 at 09:50am, Xunlei Pang wrote:
> "/sys/kernel/kexec_crash_size" only handles crashk_res, it
> is fine in most cases, but sometimes we have crashk_low_res.
> For example, when "crashkernel=size[KMG],high" combined with
> "crashkernel=size[KMG],low" is used for 64-bit x86.
> 
> Like crashk_res, we introduce the corresponding sysfs file
> "/sys/kernel/kexec_crash_low_size" for crashk_low_res.
> 
> So, the exact total reserved memory is the sum of the two.
> 
> crashk_low_res can also be shrunk via this new interface,
> and users should be aware of what they are doing.

Cc Yinghai Lu for review since he introduced the ,high and ,low logic.

> 
> Suggested-by: Dave Young <dyoung@redhat.com>
> Signed-off-by: Xunlei Pang <xlpang@redhat.com>
> ---
>  include/linux/kexec.h |  4 ++--
>  kernel/kexec_core.c   | 23 ++++++++++++-----------
>  kernel/ksysfs.c       | 25 +++++++++++++++++++++++--
>  3 files changed, 37 insertions(+), 15 deletions(-)
> 
> diff --git a/include/linux/kexec.h b/include/linux/kexec.h
> index d743777..4f271fc 100644
> --- a/include/linux/kexec.h
> +++ b/include/linux/kexec.h
> @@ -304,8 +304,8 @@ int parse_crashkernel_high(char *cmdline, unsigned long long system_ram,
>  		unsigned long long *crash_size, unsigned long long *crash_base);
>  int parse_crashkernel_low(char *cmdline, unsigned long long system_ram,
>  		unsigned long long *crash_size, unsigned long long *crash_base);
> -int crash_shrink_memory(unsigned long new_size);
> -size_t crash_get_memory_size(void);
> +int crash_shrink_memory(struct resource *res, unsigned long new_size);
> +size_t crash_get_memory_size(struct resource *res);
>  void crash_free_reserved_phys_range(unsigned long begin, unsigned long end);
>  
>  int __weak arch_kexec_kernel_image_probe(struct kimage *image, void *buf,
> diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c
> index 5616755..707d18e 100644
> --- a/kernel/kexec_core.c
> +++ b/kernel/kexec_core.c
> @@ -925,13 +925,13 @@ void crash_kexec(struct pt_regs *regs)
>  	}
>  }
>  
> -size_t crash_get_memory_size(void)
> +size_t crash_get_memory_size(struct resource *res)
>  {
>  	size_t size = 0;
>  
>  	mutex_lock(&kexec_mutex);
> -	if (crashk_res.end != crashk_res.start)
> -		size = resource_size(&crashk_res);
> +	if (res->end != res->start)
> +		size = resource_size(res);
>  	mutex_unlock(&kexec_mutex);
>  	return size;
>  }
> @@ -945,7 +945,7 @@ void __weak crash_free_reserved_phys_range(unsigned long begin,
>  		free_reserved_page(boot_pfn_to_page(addr >> PAGE_SHIFT));
>  }
>  
> -int crash_shrink_memory(unsigned long new_size)
> +int crash_shrink_memory(struct resource *res, unsigned long new_size)
>  {
>  	int ret = 0;
>  	unsigned long start, end;
> @@ -958,8 +958,9 @@ int crash_shrink_memory(unsigned long new_size)
>  		ret = -ENOENT;
>  		goto unlock;
>  	}
> -	start = crashk_res.start;
> -	end = crashk_res.end;
> +
> +	start = res->start;
> +	end = res->end;
>  	old_size = (end == 0) ? 0 : end - start + 1;
>  	if (new_size >= old_size) {
>  		ret = (new_size == old_size) ? 0 : -EINVAL;
> @@ -975,17 +976,17 @@ int crash_shrink_memory(unsigned long new_size)
>  	start = roundup(start, KEXEC_CRASH_MEM_ALIGN);
>  	end = roundup(start + new_size, KEXEC_CRASH_MEM_ALIGN);
>  
> -	crash_free_reserved_phys_range(end, crashk_res.end);
> +	crash_free_reserved_phys_range(end, res->end);
>  
> -	if ((start == end) && (crashk_res.parent != NULL))
> -		release_resource(&crashk_res);
> +	if ((start == end) && (res->parent != NULL))
> +		release_resource(res);
>  
>  	ram_res->start = end;
> -	ram_res->end = crashk_res.end;
> +	ram_res->end = res->end;
>  	ram_res->flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM;
>  	ram_res->name = "System RAM";
>  
> -	crashk_res.end = end - 1;
> +	res->end = end - 1;
>  
>  	insert_resource(&iomem_resource, ram_res);
>  
> diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
> index ee1bc1b..3336fd5 100644
> --- a/kernel/ksysfs.c
> +++ b/kernel/ksysfs.c
> @@ -105,10 +105,30 @@ static ssize_t kexec_crash_loaded_show(struct kobject *kobj,
>  }
>  KERNEL_ATTR_RO(kexec_crash_loaded);
>  
> +static ssize_t kexec_crash_low_size_show(struct kobject *kobj,
> +				       struct kobj_attribute *attr, char *buf)
> +{
> +	return sprintf(buf, "%zu\n", crash_get_memory_size(&crashk_low_res));
> +}
> +static ssize_t kexec_crash_low_size_store(struct kobject *kobj,
> +				   struct kobj_attribute *attr,
> +				   const char *buf, size_t count)
> +{
> +	unsigned long cnt;
> +	int ret;
> +
> +	if (kstrtoul(buf, 0, &cnt))
> +		return -EINVAL;
> +
> +	ret = crash_shrink_memory(&crashk_low_res, cnt);
> +	return ret < 0 ? ret : count;
> +}
> +KERNEL_ATTR_RW(kexec_crash_low_size);
> +
>  static ssize_t kexec_crash_size_show(struct kobject *kobj,
>  				       struct kobj_attribute *attr, char *buf)
>  {
> -	return sprintf(buf, "%zu\n", crash_get_memory_size());
> +	return sprintf(buf, "%zu\n", crash_get_memory_size(&crashk_res));
>  }
>  static ssize_t kexec_crash_size_store(struct kobject *kobj,
>  				   struct kobj_attribute *attr,
> @@ -120,7 +140,7 @@ static ssize_t kexec_crash_size_store(struct kobject *kobj,
>  	if (kstrtoul(buf, 0, &cnt))
>  		return -EINVAL;
>  
> -	ret = crash_shrink_memory(cnt);
> +	ret = crash_shrink_memory(&crashk_res, cnt);
>  	return ret < 0 ? ret : count;
>  }
>  KERNEL_ATTR_RW(kexec_crash_size);
> @@ -218,6 +238,7 @@ static struct attribute * kernel_attrs[] = {
>  #ifdef CONFIG_KEXEC_CORE
>  	&kexec_loaded_attr.attr,
>  	&kexec_crash_loaded_attr.attr,
> +	&kexec_crash_low_size_attr.attr,
>  	&kexec_crash_size_attr.attr,
>  	&vmcoreinfo_attr.attr,
>  #endif
> -- 
> 1.8.3.1
> 

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

  parent reply	other threads:[~2016-08-17  8:21 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-17  1:50 [PATCH v2 1/2] kexec: Introduce "/sys/kernel/kexec_crash_low_size" Xunlei Pang
2016-08-17  1:50 ` [PATCH v2 2/2] kexec: Consider crashk_low_res in sanity_check_segment_list() Xunlei Pang
2016-08-17  7:24   ` Dave Young
2016-08-17  7:43     ` Xunlei Pang
2016-08-17  8:20 ` Dave Young [this message]
2016-08-24  1:11   ` [PATCH v2 1/2] kexec: Introduce "/sys/kernel/kexec_crash_low_size" Yinghai Lu
2016-08-24  8:20     ` Dave Young
2016-08-24 11:37       ` 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=20160817082034.GA11837@dhcp-128-65.nay.redhat.com \
    --to=dyoung@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=bhe@redhat.com \
    --cc=ebiederm@xmission.com \
    --cc=kexec@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=vgoyal@redhat.com \
    --cc=xlpang@redhat.com \
    --cc=yinghai@kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).