From: Mike Rapoport <rppt@kernel.org>
To: Sang-Heon Jeon <ekffu200098@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Jason Gunthorpe <jgg@ziepe.ca>,
linux-mm@kvack.org, Pratyush Yadav <pratyush@kernel.org>
Subject: Re: [PATCH] memblock: fix page count when preserving reserve_mem regions
Date: Tue, 1 Sep 2026 21:49:45 +0300 [thread overview]
Message-ID: <apceSXvb6soT2U1-@kernel.org> (raw)
In-Reply-To: <20260901165237.1025973-1-ekffu200098@gmail.com>
Hi,
On Wed, Sep 02, 2026 at 01:52:35AM +0900, Sang-Heon Jeon wrote:
> When map->start or map->size is not page aligned,
> reserved_mem_preserve() does not preserve the last pages of the region
I believe it's the last page, not pages.
> from map->start to map->start + map->size.
>
> After kexec the new kernel reserves only the preserved pages, so the
> last pages are released to the buddy allocator. But
> reserve_mem_find_by_name() still returns the whole region including the
> last pages, so they can be allocated while the subsystem is still using
> them.
>
> Preserve every page the region spans so the new kernel reserves all of
> it.
If there are two adjacent not page aligned reserve_mem regions, we'll
preserve them twice, or worse unintentionally unpreserve one of them on
error handling of another.
I think it's better to restrict the reserve_mem alignment to PAGE_SIZE.
> Fixes: 8375b76517cb ("kho: replace kho_preserve_phys() with kho_preserve_pages()")
> Signed-off-by: Sang-Heon Jeon <ekffu200098@gmail.com>
> ---
>
> QEMU-based test results
>
> - Booted with "memblock=debug kho=on reserve_mem=5000:64:oops"
>
> # kexec -s -l /bzImage --initrd=/initramfs.gz --reuse-cmdline
> # kexec -e
> # dmesg | grep kho_preserved_memory_reserve
>
> 1) AS-IS (before fix)
> [ 0.188536] __memblock_reserve: [0x000000013ffee000-0x000000013ffeefff] nid=-1 flags=0 kho_preserved_memory_reserve+0x3d/0x70
>
> 2) TO-BE (after fix)
> [ 0.076935] __memblock_reserve: [0x000000013ffee000-0x000000013ffeffff] nid=-1 flags=0 kho_preserved_memory_reserve+0x3d/0x70
>
> mm/memblock.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/mm/memblock.c b/mm/memblock.c
> index 777c69f05400..a17b1cccaf3d 100644
> --- a/mm/memblock.c
> +++ b/mm/memblock.c
> @@ -2534,7 +2534,8 @@ static int __init reserved_mem_preserve(void)
> for (unsigned int i = 0; i < reserved_mem_count; i++, nr_preserved++) {
> struct reserve_mem_table *map = &reserved_mem_table[i];
> struct page *page = phys_to_page(map->start);
> - unsigned int nr_pages = map->size >> PAGE_SHIFT;
> + unsigned int nr_pages = PFN_UP(map->start + map->size) -
> + PFN_DOWN(map->start);
>
> err = kho_preserve_pages(page, nr_pages);
> if (err)
> @@ -2547,7 +2548,8 @@ static int __init reserved_mem_preserve(void)
> for (unsigned int i = 0; i < nr_preserved; i++) {
> struct reserve_mem_table *map = &reserved_mem_table[i];
> struct page *page = phys_to_page(map->start);
> - unsigned int nr_pages = map->size >> PAGE_SHIFT;
> + unsigned int nr_pages = PFN_UP(map->start + map->size) -
> + PFN_DOWN(map->start);
>
> kho_unpreserve_pages(page, nr_pages);
> }
>
> base-commit: dde94c26af59f5020adafafa08ece21ccd32590b
> --
> 2.43.0
>
--
Sincerely yours,
Mike.
next prev parent reply other threads:[~2026-09-01 18:49 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-01 16:52 [PATCH] memblock: fix page count when preserving reserve_mem regions Sang-Heon Jeon
2026-09-01 18:49 ` Mike Rapoport [this message]
2026-09-02 15:19 ` Sang-Heon Jeon
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=apceSXvb6soT2U1-@kernel.org \
--to=rppt@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=ekffu200098@gmail.com \
--cc=jgg@ziepe.ca \
--cc=linux-mm@kvack.org \
--cc=pratyush@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