linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Avery Pennarun <apenwarr@gmail.com>
To: Andrew Morton <akpm@linux-foundation.org>,
	Josh Triplett <josh@joshtriplett.org>,
	"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
	Ingo Molnar <mingo@elte.hu>,
	"David S. Miller" <davem@davemloft.net>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	"Fabio M. Di Nitto" <fdinitto@redhat.com>,
	Avery Pennarun <apenwarr@gmail.com>,
	Johannes Weiner <hannes@cmpxchg.org>,
	Olaf Hering <olaf@aepfle.de>,
	Paul Gortmaker <paul.gortmaker@windriver.com>,
	Tejun Heo <tj@kernel.org>, "H. Peter Anvin" <hpa@linux.intel.com>,
	Yinghai LU <yinghai@kernel.org>,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: [PATCH 1/5] mm: bootmem: BUG() if you try to allocate bootmem too late.
Date: Tue, 13 Mar 2012 01:36:37 -0400	[thread overview]
Message-ID: <1331617001-20906-2-git-send-email-apenwarr@gmail.com> (raw)
In-Reply-To: <1331617001-20906-1-git-send-email-apenwarr@gmail.com>

If you try to allocate or reserve bootmem after the bootmem subsystem has
already been shut down and replaced with the real VM system, it would
succeed, but then your memory would silently get freed and could be
reallocated by the normal VM.

Add a few lines of code to catch this condition immediately rather than
manifesting as memory corruption.

Signed-off-by: Avery Pennarun <apenwarr@gmail.com>
---
 mm/bootmem.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/mm/bootmem.c b/mm/bootmem.c
index 668e94d..7a9f505 100644
--- a/mm/bootmem.c
+++ b/mm/bootmem.c
@@ -39,6 +39,7 @@ bootmem_data_t bootmem_node_data[MAX_NUMNODES] __initdata;
 static struct list_head bdata_list __initdata = LIST_HEAD_INIT(bdata_list);
 
 static int bootmem_debug;
+static int bootmem_stopped;
 
 static int __init bootmem_debug_setup(char *buf)
 {
@@ -182,6 +183,7 @@ static unsigned long __init free_all_bootmem_core(bootmem_data_t *bdata)
 
 	bdebug("nid=%td start=%lx end=%lx\n",
 		bdata - bootmem_node_data, start, end);
+	bootmem_stopped = 1;
 
 	while (start < end) {
 		unsigned long *map, idx, vec;
@@ -279,6 +281,7 @@ static int __init __reserve(bootmem_data_t *bdata, unsigned long sidx,
 	unsigned long idx;
 	int exclusive = flags & BOOTMEM_EXCLUSIVE;
 
+	BUG_ON(bootmem_stopped);
 	bdebug("nid=%td start=%lx end=%lx flags=%x\n",
 		bdata - bootmem_node_data,
 		sidx + bdata->node_min_pfn,
-- 
1.7.7.3

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  reply	other threads:[~2012-03-13  5:36 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-13  5:36 [PATCH 0/5] Persist printk buffer across reboots Avery Pennarun
2012-03-13  5:36 ` Avery Pennarun [this message]
2012-03-13  5:36 ` [PATCH 2/5] mm: bootmem: it's okay to reserve_bootmem an invalid address Avery Pennarun
2012-03-13  5:36 ` [PATCH 3/5] mm: nobootmem: implement reserve_bootmem() in terms of memblock Avery Pennarun
2012-03-13  5:36 ` [PATCH 4/5] printk: use alloc_bootmem() instead of memblock_alloc() Avery Pennarun
2012-03-13  6:13   ` Yinghai Lu
2012-03-13  6:40     ` Avery Pennarun
2012-03-13  8:26       ` Ingo Molnar
2012-03-13 21:50       ` Yinghai Lu
2012-03-14  2:23         ` Avery Pennarun
2012-03-13  5:36 ` [PATCH 5/5] printk: CONFIG_PRINTK_PERSIST: persist printk buffer across reboots Avery Pennarun
2012-03-13  5:53 ` [PATCH 0/5] Persist " David Miller
2012-03-13  6:00   ` Avery Pennarun
2012-03-13  6:50     ` David Miller
2012-03-13  7:14       ` Avery Pennarun
2012-03-13  7:18         ` David Miller
2012-03-13  8:10           ` Avery Pennarun
2012-03-13  8:16             ` David Miller
2012-03-13 13:50   ` Peter Zijlstra
2012-03-14  1:57     ` Daniel Walker
2012-03-13  8:32 ` Stephen Boyd
2012-03-13 17:08 ` Daniel Walker
2012-03-13 22:10   ` Andrew Morton
2012-03-14  2:19     ` Daniel Walker
2012-03-15 22:10       ` Seiji Aguchi
2012-03-14  2:21     ` Avery Pennarun

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=1331617001-20906-2-git-send-email-apenwarr@gmail.com \
    --to=apenwarr@gmail.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=akpm@linux-foundation.org \
    --cc=davem@davemloft.net \
    --cc=fdinitto@redhat.com \
    --cc=hannes@cmpxchg.org \
    --cc=hpa@linux.intel.com \
    --cc=josh@joshtriplett.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mingo@elte.hu \
    --cc=olaf@aepfle.de \
    --cc=paul.gortmaker@windriver.com \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=tj@kernel.org \
    --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