All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wen Congyang <wency@cn.fujitsu.com>
To: rob@landley.net, tglx@linutronix.de,
	Ingo Molnar <mingo@redhat.com>,
	x86@kernel.org,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: [PATCH 2/2] x86: reimplement mem boot option
Date: Tue, 22 May 2012 15:05:11 +0800	[thread overview]
Message-ID: <4FBB3AA7.5070307@cn.fujitsu.com> (raw)
In-Reply-To: <4FBB3A23.50102@cn.fujitsu.com>

The boot option "mem=" specifies the total memory that the system can
use. But we implement it as max_addr.

The x86 system can be booted by EFI. If the user specify the boot
option "add_efi_memmap", we add all memory map from EFI, but we
donot handle the memory map according to the boot option "mem=".

This patch reimplement the boot option "mem=", and handle the memory
map after calling efi_init().

Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
---
 arch/x86/include/asm/e820.h |    1 +
 arch/x86/kernel/e820.c      |   36 +++++++++++++++++++++++++++++++-----
 arch/x86/kernel/setup.c     |    1 +
 3 files changed, 33 insertions(+), 5 deletions(-)

diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
index 3778256..d1bb772 100644
--- a/arch/x86/include/asm/e820.h
+++ b/arch/x86/include/asm/e820.h
@@ -127,6 +127,7 @@ extern void e820_reserve_resources(void);
 extern void e820_reserve_resources_late(void);
 extern void setup_memory_map(void);
 extern char *default_machine_specific_memory_setup(void);
+extern void set_memlimit(void);
 
 /*
  * Returns true iff the specified range [s,e) is completely contained inside
diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index 2a6bec7..0148944 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -48,6 +48,7 @@ unsigned long pci_mem_start = 0xaeedbabe;
 EXPORT_SYMBOL(pci_mem_start);
 #endif
 static u64 max_addr = ~0ULL;
+static u64 mem_limit = ~0ULL;
 
 /*
  * This function checks if any part of the range <start,end> is mapped
@@ -824,8 +825,6 @@ static int userdef __initdata;
 /* "mem=nopentium" disables the 4MB page tables. */
 static int __init parse_memopt(char *p)
 {
-	u64 mem_size;
-
 	if (!p)
 		return -EINVAL;
 
@@ -840,16 +839,43 @@ static int __init parse_memopt(char *p)
 	}
 
 	userdef = 1;
-	mem_size = memparse(p, &p);
+	mem_limit = memparse(p, &p);
 	/* don't remove all of memory when handling "mem={invalid}" param */
-	if (mem_size == 0)
+	if (mem_limit == 0)
 		return -EINVAL;
-	e820_remove_range(mem_size, ULLONG_MAX - mem_size, E820_RAM, 1);
 
 	return 0;
 }
 early_param("mem", parse_memopt);
 
+void __init set_memlimit(void)
+{
+	u64 total_size = 0;
+	int i;
+
+	if (mem_limit == ~0ULL)
+		return;
+
+	for (i = 0; i < e820.nr_map; i++) {
+		struct e820entry *ei = &e820.map[i];
+
+		if (ei->type != E820_RAM)
+			continue;
+
+		if (total_size >= mem_limit) {
+			memset(ei, 0, sizeof(struct e820entry));
+			continue;
+		}
+
+		if (mem_limit - total_size <= ei->size)
+			ei->size = mem_limit - total_size;
+
+		total_size += ei->size;
+	}
+
+	sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
+}
+
 static int __init parse_memmax_opt(char *p)
 {
 	char *oldp;
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index 1a29015..7938fae 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -823,6 +823,7 @@ void __init setup_arch(char **cmdline_p)
 
 	if (efi_enabled)
 		efi_init();
+	set_memlimit();
 
 	dmi_scan_machine();
 
-- 
1.7.1


  reply	other threads:[~2012-05-22  7:01 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-22  7:02 [PATCH 1/2] x86: add max_addr boot option Wen Congyang
2012-05-22  7:05 ` Wen Congyang [this message]
2012-05-22 19:51 ` Rob Landley
2012-05-23  1:23   ` Wen Congyang
2012-05-23  4:06   ` KAMEZAWA Hiroyuki
2012-05-23 14:25 ` Bjorn Helgaas
2012-05-24  5:19   ` Wen Congyang
2012-06-14  8:10 [PATCH 1/2] doc: update mem= option's spec Wen Congyang
2012-06-14  8:12 ` [PATCH 2/2] x86: reimplement mem boot option Wen Congyang
2012-06-28  1:29   ` Wen Congyang
2012-07-17  5:22     ` Wen Congyang
2012-07-18  9:16       ` Ingo Molnar

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=4FBB3AA7.5070307@cn.fujitsu.com \
    --to=wency@cn.fujitsu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=rob@landley.net \
    --cc=tglx@linutronix.de \
    --cc=x86@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 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.