From: Russell King - ARM Linux <linux@arm.linux.org.uk>
To: "Wang, Yalin" <Yalin.Wang@sonymobile.com>
Cc: 'Will Deacon' <will.deacon@arm.com>,
"'linux-kernel@vger.kernel.org'" <linux-kernel@vger.kernel.org>,
"'linux-arm-kernel@lists.infradead.org'"
<linux-arm-kernel@lists.infradead.org>,
"'linux-mm@kvack.org'" <linux-mm@kvack.org>,
"'linux-arm-msm@vger.kernel.org'" <linux-arm-msm@vger.kernel.org>
Subject: Re: [RFC v2] arm:extend the reserved mrmory for initrd to be page aligned
Date: Mon, 15 Sep 2014 12:33:25 +0100 [thread overview]
Message-ID: <20140915113325.GD12361@n2100.arm.linux.org.uk> (raw)
In-Reply-To: <35FD53F367049845BC99AC72306C23D103D6DB491609@CNBJMBX05.corpusers.net>
On Mon, Sep 15, 2014 at 07:07:20PM +0800, Wang, Yalin wrote:
> this patch extend the start and end address of initrd to be page aligned,
> so that we can free all memory including the un-page aligned head or tail
> page of initrd, if the start or end address of initrd are not page
> aligned, the page can't be freed by free_initrd_mem() function.
Better, but I think it's more complicated than it needs to be:
> Signed-off-by: Yalin Wang <yalin.wang@sonymobile.com>
> ---
> arch/arm/mm/init.c | 19 +++++++++++++++++--
> arch/arm64/mm/init.c | 37 +++++++++++++++++++++++++++++++++----
> 2 files changed, 50 insertions(+), 6 deletions(-)
>
> diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
> index 659c75d..8490b70 100644
> --- a/arch/arm/mm/init.c
> +++ b/arch/arm/mm/init.c
> @@ -277,6 +277,8 @@ phys_addr_t __init arm_memblock_steal(phys_addr_t size, phys_addr_t align)
> void __init arm_memblock_init(const struct machine_desc *mdesc)
> {
> /* Register the kernel text, kernel data and initrd with memblock. */
> + phys_addr_t phys_initrd_start_orig __maybe_unused;
> + phys_addr_t phys_initrd_size_orig __maybe_unused;
> #ifdef CONFIG_XIP_KERNEL
> memblock_reserve(__pa(_sdata), _end - _sdata);
> #else
> @@ -289,6 +291,13 @@ void __init arm_memblock_init(const struct machine_desc *mdesc)
> phys_initrd_size = initrd_end - initrd_start;
> }
> initrd_start = initrd_end = 0;
> + phys_initrd_start_orig = phys_initrd_start;
> + phys_initrd_size_orig = phys_initrd_size;
> + /* make sure the start and end address are page aligned */
> + phys_initrd_size = round_up(phys_initrd_start + phys_initrd_size, PAGE_SIZE);
> + phys_initrd_start = round_down(phys_initrd_start, PAGE_SIZE);
> + phys_initrd_size -= phys_initrd_start;
> +
> if (phys_initrd_size &&
> !memblock_is_region_memory(phys_initrd_start, phys_initrd_size)) {
> pr_err("INITRD: 0x%08llx+0x%08lx is not a memory region - disabling initrd\n",
> @@ -305,9 +314,10 @@ void __init arm_memblock_init(const struct machine_desc *mdesc)
> memblock_reserve(phys_initrd_start, phys_initrd_size);
>
> /* Now convert initrd to virtual addresses */
> - initrd_start = __phys_to_virt(phys_initrd_start);
> - initrd_end = initrd_start + phys_initrd_size;
> + initrd_start = __phys_to_virt(phys_initrd_start_orig);
> + initrd_end = initrd_start + phys_initrd_size_orig;
> }
> +
I think all the above is entirely unnecessary. The memblock APIs
(especially memblock_reserve()) will mark the overlapped pages as reserved
- they round down the starting address, and round up the end address
(calculated from start + size).
Hence, this:
> @@ -636,6 +646,11 @@ static int keep_initrd;
> void free_initrd_mem(unsigned long start, unsigned long end)
> {
> if (!keep_initrd) {
> + if (start == initrd_start)
> + start = round_down(start, PAGE_SIZE);
> + if (end == initrd_end)
> + end = round_up(end, PAGE_SIZE);
> +
> poison_init_mem((void *)start, PAGE_ALIGN(end) - start);
> free_reserved_area((void *)start, (void *)end, -1, "initrd");
> }
is the only bit of code you likely need to achieve your goal.
Thinking about this, I think that you are quite right to align these.
The memory around the initrd is defined to be system memory, and we
already free the pages around it, so it *is* wrong not to free the
partial initrd pages.
Good catch.
--
FTTC broadband for 0.8mile line: currently at 9.5Mbps down 400kbps up
according to speedtest.net.
--
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/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2014-09-15 11:33 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-15 11:07 Wang, Yalin
2014-09-15 11:33 ` Russell King - ARM Linux [this message]
2014-09-15 14:20 ` Wang, Yalin
2014-12-04 12:03 ` Catalin Marinas
2014-12-05 2:35 ` Wang, Yalin
2014-12-05 14:41 ` Catalin Marinas
2014-12-05 12:05 ` Will Deacon
2014-12-05 17:07 ` Catalin Marinas
2014-12-05 17:27 ` Russell King - ARM Linux
2014-12-05 17:52 ` Peter Maydell
2014-12-05 18:44 ` Catalin Marinas
2014-12-05 18:59 ` Peter Maydell
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=20140915113325.GD12361@n2100.arm.linux.org.uk \
--to=linux@arm.linux.org.uk \
--cc=Yalin.Wang@sonymobile.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=will.deacon@arm.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox