From: Ronit Halder <ronit.crj@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, bp@suse.de,
dyoung@redhat.com, jroedel@suse.de, krzysiek@podlesie.net,
msalter@redhat.com, ebiederm@xmission.com,
akpm@linux-foundation.org, bhe@redhat.com, vgoyal@redhat.com,
mnfhuang@gmail.com, kexec@lists.infradead.org,
kirill.shutemov@linux.intel.com, mchehab@osg.samsung.com,
aarcange@redhat.com, vdavydov@parallels.com,
dan.j.williams@intel.com, jack@suse.cz, linux-mm@kvack.org,
Ronit Halder <ronit.crj@gmail.com>
Subject: [RFC 2/4] Functions for memory reservation and release
Date: Fri, 12 Aug 2016 19:51:59 +0530 [thread overview]
Message-ID: <20160812142159.6101-1-ronit.crj@gmail.com> (raw)
In-Reply-To: <20160812141838.5973-1-ronit.crj@gmail.com>
Functions reserve and release memory from CMA area(s).
Signed-off-by: Ronit Halder <ronit.crj@gmail.com>
---
include/linux/kexec.h | 11 ++++++-
kernel/kexec_core.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 93 insertions(+), 1 deletion(-)
diff --git a/include/linux/kexec.h b/include/linux/kexec.h
index d140b1e..9a1af44 100644
--- a/include/linux/kexec.h
+++ b/include/linux/kexec.h
@@ -307,7 +307,6 @@ extern size_t vmcoreinfo_max_size;
/* flag to track if kexec reboot is in progress */
extern bool kexec_in_progress;
-
int __init parse_crashkernel(char *cmdline, unsigned long long system_ram,
unsigned long long *crash_size, unsigned long long *crash_base);
int parse_crashkernel_high(char *cmdline, unsigned long long system_ram,
@@ -318,6 +317,16 @@ int crash_shrink_memory(unsigned long new_size);
size_t crash_get_memory_size(void);
void crash_free_reserved_phys_range(unsigned long begin, unsigned long end);
+#ifdef CONFIG_KEXEC_CMA
+#ifdef CONFIG_X86
+ extern struct cma *crashk_cma, *crashk_cma_low;
+ int crash_free_memory(unsigned int size);
+ int crash_alloc_memory(unsigned int size);
+ int crash_alloc_memory_low(void);
+ int crash_free_memory_low(void);
+ size_t crash_get_memory_size_low(void);
+#endif
+#endif
int __weak arch_kexec_kernel_image_probe(struct kimage *image, void *buf,
unsigned long buf_len);
void * __weak arch_kexec_kernel_image_load(struct kimage *image);
diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c
index 11b64a6..0ef3385 100644
--- a/kernel/kexec_core.c
+++ b/kernel/kexec_core.c
@@ -39,6 +39,7 @@
#include <linux/compiler.h>
#include <linux/hugetlb.h>
+#include <linux/cma.h>
#include <asm/page.h>
#include <asm/sections.h>
@@ -46,7 +47,9 @@
#include <crypto/sha.h>
#include "kexec_internal.h"
+#define CRASH_ALIGN (16 << 20)
DEFINE_MUTEX(kexec_mutex);
+DEFINE_MUTEX(kexec_mutex_low);
/* Per cpu memory for storing cpu states in case of system crash. */
note_buf_t __percpu *crash_notes;
@@ -57,6 +60,7 @@ u32 vmcoreinfo_note[VMCOREINFO_NOTE_SIZE/4];
size_t vmcoreinfo_size;
size_t vmcoreinfo_max_size = sizeof(vmcoreinfo_data);
+static struct page *pages, *pages_low;
/* Flag to indicate we are going to kexec a new kernel */
bool kexec_in_progress = false;
@@ -946,6 +950,85 @@ unlock:
mutex_unlock(&kexec_mutex);
return ret;
}
+#ifdef CONFIG_KEXEC_CMA
+#ifdef CONFIG_X86
+ size_t crash_get_memory_size_low(void)
+ {
+ size_t size = 0;
+
+ mutex_lock(&kexec_mutex_low);
+ if (crashk_low_res.end != crashk_low_res.start)
+ size = resource_size(&crashk_low_res);
+ mutex_unlock(&kexec_mutex_low);
+ return size;
+ }
+ int crash_free_memory(unsigned int size)
+ {
+ int ret;
+
+ if (!crashk_cma)
+ return 0;
+ ret = cma_release(crashk_cma, pages, size >> PAGE_SHIFT);
+
+ if (!ret) {
+ pr_info("Crash memory release failed");
+ return ret;
+ }
+ release_resource(&crashk_res);
+ return 0;
+ }
+
+ int crash_alloc_memory(unsigned int size)
+ {
+ if (!crashk_cma)
+ return 0;
+ pages = cma_alloc(crashk_cma, size >> PAGE_SHIFT, KEXEC_CRASH_MEM_ALIGN);
+
+ if (!pages) {
+ pr_info("Memory for crash kernel not allocated");
+ return -ENOMEM;
+ }
+
+ crashk_res.start = page_to_pfn(pages) << PAGE_SHIFT;
+ crashk_res.end = crashk_res.start + size - 1;
+ insert_resource(&iomem_resource, &crashk_res);
+ return 0;
+ }
+
+ int crash_free_memory_low(void)
+ {
+ int ret;
+
+ if (!crashk_cma_low)
+ return 0;
+ ret = cma_release(crashk_cma_low, pages_low, cma_get_size(crashk_cma_low) >> PAGE_SHIFT);
+
+ if (!ret) {
+ pr_info("Crash low memory release failed");
+ return ret;
+ }
+ release_resource(&crashk_low_res);
+ return 0;
+ }
+
+ int crash_alloc_memory_low(void)
+ {
+ if (!crashk_cma_low)
+ return 0;
+ pages = cma_alloc(crashk_cma_low, cma_get_size(crashk_cma_low) >> PAGE_SHIFT, KEXEC_CRASH_MEM_ALIGN);
+
+ if (!pages) {
+ pr_info("Low memory for crash kernel not allocated");
+ return -ENOMEM;
+ }
+
+ crashk_low_res.start = page_to_pfn(pages) << PAGE_SHIFT;
+ crashk_low_res.end = crashk_low_res.start + cma_get_size(crashk_cma_low) - 1;
+ insert_resource(&iomem_resource, &crashk_low_res);
+ return 0;
+ }
+#endif
+#endif
static u32 *append_elf_note(u32 *buf, char *name, unsigned type, void *data,
size_t data_len)
--
2.9.0.GIT
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2016-08-12 14:22 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-12 14:18 [RFC 0/4] Kexec: Enable run time memory resrvation of crash kernel Ronit Halder
2016-08-12 14:20 ` [RFC 1/4] Creating one or two CMA area at Boot time Ronit Halder
2016-08-12 14:21 ` Ronit Halder [this message]
2016-08-12 14:25 ` [RFC 3/4] Adding a new kernel configuration to enable the feature Ronit Halder
2016-08-12 14:26 ` [RFC 4/4] Enable memory allocation through sysfs interface Ronit Halder
2016-08-22 10:59 ` [RFC 0/4] Kexec: Enable run time memory resrvation of crash kernel Pratyush Anand
2016-08-23 7:08 ` 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=20160812142159.6101-1-ronit.crj@gmail.com \
--to=ronit.crj@gmail.com \
--cc=aarcange@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=bhe@redhat.com \
--cc=bp@suse.de \
--cc=dan.j.williams@intel.com \
--cc=dyoung@redhat.com \
--cc=ebiederm@xmission.com \
--cc=hpa@zytor.com \
--cc=jack@suse.cz \
--cc=jroedel@suse.de \
--cc=kexec@lists.infradead.org \
--cc=kirill.shutemov@linux.intel.com \
--cc=krzysiek@podlesie.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mchehab@osg.samsung.com \
--cc=mingo@redhat.com \
--cc=mnfhuang@gmail.com \
--cc=msalter@redhat.com \
--cc=tglx@linutronix.de \
--cc=vdavydov@parallels.com \
--cc=vgoyal@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 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).