public inbox for linux-kernel@vger.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>,
	bhelgaas@google.com
Subject: [PATCH 2/2 v2] x86: reimplement mem boot option
Date: Mon, 11 Jun 2012 16:46:00 +0800	[thread overview]
Message-ID: <4FD5B048.30602@cn.fujitsu.com> (raw)
In-Reply-To: <4FD5AFF2.3040306@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 cd07226..b234b25 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 16be6dc..a3c4ac3 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -815,6 +815,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-06-11  8:42 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-11  8:44 [PATCH 1/2 v2] x86: add max_addr boot option Wen Congyang
2012-06-11  8:46 ` Wen Congyang [this message]
2012-06-11 17:35 ` Bjorn Helgaas
2012-06-12  6:29   ` Wen Congyang
2012-06-12 11:30     ` Bjorn Helgaas
2012-06-13  1:55       ` Kamezawa Hiroyuki
2012-06-13  4:59         ` Rob Landley
2012-06-14  2:06           ` Kamezawa Hiroyuki
2012-06-14 20:00             ` Rob Landley
2012-06-11 21:15 ` H. Peter Anvin
2012-06-12  6:26   ` Wen Congyang
2012-06-12 16:10     ` H. Peter Anvin
2012-06-13  2:21       ` Kamezawa Hiroyuki
2012-06-13  3:29         ` H. Peter Anvin
2012-06-13  5:20           ` Kamezawa Hiroyuki
2012-06-13  5:36           ` Wen Congyang

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=4FD5B048.30602@cn.fujitsu.com \
    --to=wency@cn.fujitsu.com \
    --cc=bhelgaas@google.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox