public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Yinghai Lu <yinghai@kernel.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Ingo Molnar <mingo@elte.hu>,
	linux-kernel@vger.kernel.org, Tejun Heo <tj@kernel.org>,
	Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	Yinghai Lu <yinghai@kernel.org>
Subject: [PATCH] memblock: Make sure reserved.regions is freed really
Date: Fri, 15 Jun 2012 20:12:11 -0700	[thread overview]
Message-ID: <1339816331-23284-1-git-send-email-yinghai@kernel.org> (raw)

memblock_free() would double reserved.regions too, so we could free
old range for reserved.regions.

So need to check that regions get doubled. If it is doubled, we need to
free it.

Cc: Tejun Heo <tj@kernel.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Yinghai Lu <yinghai@kernel.org>

---
 mm/memblock.c |   23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

Index: linux-2.6/mm/memblock.c
===================================================================
--- linux-2.6.orig/mm/memblock.c
+++ linux-2.6/mm/memblock.c
@@ -148,11 +148,26 @@ phys_addr_t __init_memblock memblock_fin
  */
 int __init_memblock memblock_free_reserved_regions(void)
 {
+	struct memblock_region *r;
+	int ret;
+
 	if (memblock.reserved.regions == memblock_reserved_init_regions)
 		return 0;
 
-	return memblock_free(__pa(memblock.reserved.regions),
-		 sizeof(struct memblock_region) * memblock.reserved.max);
+	/*
+	 * During memblock_free, reserved.regions could be doubled,
+	 * try to check with old one for checking, and need to free the new one.
+	 */
+	do {
+		r = memblock.reserved.regions;
+		ret = memblock_free(__pa(memblock.reserved.regions),
+			sizeof(struct memblock_region) * memblock.reserved.max);
+
+		if (ret)
+			break;
+	} while (memblock.reserved.regions != r);
+
+	return ret;
 }
 
 /*
@@ -163,6 +178,10 @@ int __init_memblock memblock_reserve_res
 	if (memblock.reserved.regions == memblock_reserved_init_regions)
 		return 0;
 
+	/*
+	 * Don't need to worry about if reserved.regions get updated later,
+	 * and it is big enough after memblock_free_reserved_regions().
+	 */
 	return memblock_reserve(__pa(memblock.reserved.regions),
 		 sizeof(struct memblock_region) * memblock.reserved.max);
 }

             reply	other threads:[~2012-06-16  3:12 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-16  3:12 Yinghai Lu [this message]
2012-06-18 22:05 ` [PATCH] memblock: Make sure reserved.regions is freed really Tejun Heo
2012-06-18 22:58   ` Yinghai Lu
2012-06-18 23:09     ` Tejun Heo
2012-06-18 23:46       ` Yinghai Lu

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=1339816331-23284-1-git-send-email-yinghai@kernel.org \
    --to=yinghai@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=benh@kernel.crashing.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=tj@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