All of lore.kernel.org
 help / color / mirror / Atom feed
From: Amerigo Wang <amwang@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: linux-ia64@vger.kernel.org, Neil Horman <nhorman@redhat.com>,
	"Eric W. Biederman" <ebiederm@xmission.com>,
	Andi Kleen <andi@firstfloor.org>,
	Amerigo Wang <amwang@redhat.com>,
	akpm@linux-foundation.org, Ingo Molnar <mingo@elte.hu>
Subject: [RFC Patch 1/2] kexec: show memory info in /proc/iomem
Date: Tue, 11 Aug 2009 10:39:22 +0000	[thread overview]
Message-ID: <20090811104144.5154.77871.sendpatchset@localhost.localdomain> (raw)


This patch implements showing kexec memory area via /proc/iomem.
For example, with this patch we can see:

# cat /proc/iomem
...
00100000-7ffeffff : System RAM
  01000000-012e1424 : Kernel code
  012e1425-015f1aff : Kernel data
  0166b000-01b4b88f : Kernel bss
  02000000-083fffff : Crash kernel
    02000000-028fffff : Used
    02900000-083fffff : Unused
...

So that user can know how much memory the kernel uses for crash kernel.

Signed-off-by: WANG Cong <amwang@redhat.com>
Cc: Neil Horman <nhorman@redhat.com>
Cc: Eric W. Biederman <ebiederm@xmission.com>
Cc: Andi Kleen <andi@firstfloor.org>


---
diff --git a/kernel/kexec.c b/kernel/kexec.c
index f336e21..01673ad 100644
--- a/kernel/kexec.c
+++ b/kernel/kexec.c
@@ -931,6 +931,8 @@ static int kimage_load_segment(struct kimage *image,
  */
 struct kimage *kexec_image;
 struct kimage *kexec_crash_image;
+struct resource *kexec_res = NULL;
+struct resource *kexec_free_res = NULL;
 
 static DEFINE_MUTEX(kexec_mutex);
 
@@ -939,6 +941,8 @@ SYSCALL_DEFINE4(kexec_load, unsigned long, entry, unsigned long, nr_segments,
 {
 	struct kimage **dest_image, *image;
 	int result;
+	unsigned long kexec_start = crashk_res.start;
+	unsigned long kexec_end = kexec_start;
 
 	/* We only trust the superuser with rebooting the system. */
 	if (!capable(CAP_SYS_BOOT))
@@ -994,6 +998,7 @@ SYSCALL_DEFINE4(kexec_load, unsigned long, entry, unsigned long, nr_segments,
 			kimage_free(xchg(&kexec_crash_image, NULL));
 			result = kimage_crash_alloc(&image, entry,
 						     nr_segments, segments);
+			kexec_end += KEXEC_CONTROL_PAGE_SIZE;
 		}
 		if (result)
 			goto out;
@@ -1008,6 +1013,42 @@ SYSCALL_DEFINE4(kexec_load, unsigned long, entry, unsigned long, nr_segments,
 			result = kimage_load_segment(image, &image->segment[i]);
 			if (result)
 				goto out;
+			if (flags & KEXEC_ON_CRASH)
+				kexec_end += image->segment[i].memsz;
+		}
+		if (flags & KEXEC_ON_CRASH) {
+			if (kexec_res) {
+				release_resource(kexec_res);
+				release_resource(kexec_free_res);
+				kfree(kexec_res);
+				kfree(kexec_free_res);
+			}
+			kexec_res = kzalloc(sizeof(*kexec_res), GFP_KERNEL);
+			if (!kexec_res) {
+				result = -ENOMEM;
+				goto out;
+			}
+			kexec_free_res = kzalloc(sizeof(*kexec_free_res), GFP_KERNEL);
+			if (!kexec_free_res) {
+				result = -ENOMEM;
+				goto out_free;
+			}
+			kexec_res->name = "Used";
+			kexec_res->start = kexec_start;
+			kexec_res->end = roundup(kexec_end, 1<<20) - 1;
+			kexec_res->flags = IORESOURCE_BUSY | IORESOURCE_MEM;
+			if (insert_resource(&crashk_res, kexec_res)) {
+				result = -EBUSY;
+				goto out_free;
+			}
+			kexec_free_res->name = "Unused";
+			kexec_free_res->start = kexec_res->end + 1;
+			kexec_free_res->end = crashk_res.end;
+			kexec_free_res->flags = IORESOURCE_BUSY | IORESOURCE_MEM;
+			if (insert_resource(&crashk_res, kexec_free_res)) {
+				result = -EBUSY;
+				goto out_release;
+			}
 		}
 		kimage_terminate(image);
 	}
@@ -1019,6 +1060,13 @@ out:
 	kimage_free(image);
 
 	return result;
+
+out_free:
+	kfree(kexec_free_res);
+	kfree(kexec_res);
+out_release:
+	release_resource(kexec_res);
+	goto out;
 }
 
 #ifdef CONFIG_COMPAT

WARNING: multiple messages have this Message-ID (diff)
From: Amerigo Wang <amwang@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: linux-ia64@vger.kernel.org, Neil Horman <nhorman@redhat.com>,
	"Eric W. Biederman" <ebiederm@xmission.com>,
	Andi Kleen <andi@firstfloor.org>,
	Amerigo Wang <amwang@redhat.com>,
	akpm@linux-foundation.org, Ingo Molnar <mingo@elte.hu>
Subject: [RFC Patch 1/2] kexec: show memory info in /proc/iomem
Date: Tue, 11 Aug 2009 06:39:22 -0400	[thread overview]
Message-ID: <20090811104144.5154.77871.sendpatchset@localhost.localdomain> (raw)


This patch implements showing kexec memory area via /proc/iomem.
For example, with this patch we can see:

# cat /proc/iomem
...
00100000-7ffeffff : System RAM
  01000000-012e1424 : Kernel code
  012e1425-015f1aff : Kernel data
  0166b000-01b4b88f : Kernel bss
  02000000-083fffff : Crash kernel
    02000000-028fffff : Used
    02900000-083fffff : Unused
...

So that user can know how much memory the kernel uses for crash kernel.

Signed-off-by: WANG Cong <amwang@redhat.com>
Cc: Neil Horman <nhorman@redhat.com>
Cc: Eric W. Biederman <ebiederm@xmission.com>
Cc: Andi Kleen <andi@firstfloor.org>


---
diff --git a/kernel/kexec.c b/kernel/kexec.c
index f336e21..01673ad 100644
--- a/kernel/kexec.c
+++ b/kernel/kexec.c
@@ -931,6 +931,8 @@ static int kimage_load_segment(struct kimage *image,
  */
 struct kimage *kexec_image;
 struct kimage *kexec_crash_image;
+struct resource *kexec_res = NULL;
+struct resource *kexec_free_res = NULL;
 
 static DEFINE_MUTEX(kexec_mutex);
 
@@ -939,6 +941,8 @@ SYSCALL_DEFINE4(kexec_load, unsigned long, entry, unsigned long, nr_segments,
 {
 	struct kimage **dest_image, *image;
 	int result;
+	unsigned long kexec_start = crashk_res.start;
+	unsigned long kexec_end = kexec_start;
 
 	/* We only trust the superuser with rebooting the system. */
 	if (!capable(CAP_SYS_BOOT))
@@ -994,6 +998,7 @@ SYSCALL_DEFINE4(kexec_load, unsigned long, entry, unsigned long, nr_segments,
 			kimage_free(xchg(&kexec_crash_image, NULL));
 			result = kimage_crash_alloc(&image, entry,
 						     nr_segments, segments);
+			kexec_end += KEXEC_CONTROL_PAGE_SIZE;
 		}
 		if (result)
 			goto out;
@@ -1008,6 +1013,42 @@ SYSCALL_DEFINE4(kexec_load, unsigned long, entry, unsigned long, nr_segments,
 			result = kimage_load_segment(image, &image->segment[i]);
 			if (result)
 				goto out;
+			if (flags & KEXEC_ON_CRASH)
+				kexec_end += image->segment[i].memsz;
+		}
+		if (flags & KEXEC_ON_CRASH) {
+			if (kexec_res) {
+				release_resource(kexec_res);
+				release_resource(kexec_free_res);
+				kfree(kexec_res);
+				kfree(kexec_free_res);
+			}
+			kexec_res = kzalloc(sizeof(*kexec_res), GFP_KERNEL);
+			if (!kexec_res) {
+				result = -ENOMEM;
+				goto out;
+			}
+			kexec_free_res = kzalloc(sizeof(*kexec_free_res), GFP_KERNEL);
+			if (!kexec_free_res) {
+				result = -ENOMEM;
+				goto out_free;
+			}
+			kexec_res->name = "Used";
+			kexec_res->start = kexec_start;
+			kexec_res->end = roundup(kexec_end, 1<<20) - 1;
+			kexec_res->flags = IORESOURCE_BUSY | IORESOURCE_MEM;
+			if (insert_resource(&crashk_res, kexec_res)) {
+				result = -EBUSY;
+				goto out_free;
+			}
+			kexec_free_res->name = "Unused";
+			kexec_free_res->start = kexec_res->end + 1;
+			kexec_free_res->end = crashk_res.end;
+			kexec_free_res->flags = IORESOURCE_BUSY | IORESOURCE_MEM;
+			if (insert_resource(&crashk_res, kexec_free_res)) {
+				result = -EBUSY;
+				goto out_release;
+			}
 		}
 		kimage_terminate(image);
 	}
@@ -1019,6 +1060,13 @@ out:
 	kimage_free(image);
 
 	return result;
+
+out_free:
+	kfree(kexec_free_res);
+	kfree(kexec_res);
+out_release:
+	release_resource(kexec_res);
+	goto out;
 }
 
 #ifdef CONFIG_COMPAT

             reply	other threads:[~2009-08-11 10:39 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-11 10:39 Amerigo Wang [this message]
2009-08-11 10:39 ` [RFC Patch 1/2] kexec: show memory info in /proc/iomem Amerigo Wang
2009-08-11 10:39 ` [RFC Patch 2/2] kexec: allow to shrink reserved memory Amerigo Wang
2009-08-11 10:39   ` Amerigo Wang
2009-08-11 10:46   ` Neil Horman
2009-08-11 10:46     ` Neil Horman
2009-08-11 20:55     ` Yu, Fenghua
2009-08-11 20:55       ` Yu, Fenghua
2009-08-12  1:32     ` Amerigo Wang
2009-08-12  1:32       ` Amerigo Wang
2009-08-11 19:57   ` Eric W. Biederman
2009-08-11 19:57     ` Eric W. Biederman
2009-08-12  1:25     ` Amerigo Wang
2009-08-12  1:25       ` Amerigo Wang
2009-08-12  1:46       ` Eric W. Biederman
2009-08-12  1:46         ` Eric W. Biederman
2009-08-12  2:08         ` Amerigo Wang
2009-08-12  2:08           ` Amerigo Wang
2009-08-12  2:43           ` Eric W. Biederman
2009-08-12  2:43             ` Eric W. Biederman
2009-08-12  3:14             ` Amerigo Wang
2009-08-12  3:14               ` Amerigo Wang
2009-08-11 19:49 ` [RFC Patch 1/2] kexec: show memory info in /proc/iomem Eric W. Biederman
2009-08-11 19:49   ` Eric W. Biederman
2009-08-12  1:17   ` Amerigo Wang
2009-08-12  1:17     ` Amerigo Wang
2009-08-12  1:51     ` Eric W. Biederman
2009-08-12  1:51       ` Eric W. Biederman
2009-08-12  2:15       ` Amerigo Wang
2009-08-12  2:15         ` Amerigo Wang
2009-08-12  2:39         ` Eric W. Biederman
2009-08-12  2:39           ` Eric W. Biederman
2009-08-11 20:50 ` Yu, Fenghua
2009-08-11 20:50   ` Yu, Fenghua
2009-08-12  1:27   ` Amerigo Wang
2009-08-12  1:27     ` Amerigo Wang

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=20090811104144.5154.77871.sendpatchset@localhost.localdomain \
    --to=amwang@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=andi@firstfloor.org \
    --cc=ebiederm@xmission.com \
    --cc=linux-ia64@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=nhorman@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.