From: Thorsten Blum <blum@kernel.org>
To: Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
"Mike Rapoport (Microsoft)" <rppt@kernel.org>,
Ard Biesheuvel <ardb@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
"Pratyush Yadav (Google)" <pratyush@kernel.org>,
Grzegorz Jaszczyk <jaszczyk@chromium.org>,
Thomas Zimmermann <tzimmermann@suse.de>,
Breno Leitao <leitao@debian.org>,
Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>,
Thorsten Blum <blum@kernel.org>, Yinghai Lu <yinghai@kernel.org>,
Johannes Weiner <hannes@cmpxchg.org>
Cc: Ingo Molnar <mingo@kernel.org>, linux-kernel@vger.kernel.org
Subject: [PATCH v2] x86/setup: Report the page-aligned size in relocate_initrd()
Date: Mon, 16 Nov 2026 11:02:30 +0100 [thread overview]
Message-ID: <20261116100230.160085-3-blum@kernel.org> (raw)
Since commit c967da6a0ba8 ("x86: Make sure free_init_pages() frees
pages on page boundary"), relocate_initrd() allocates area_size bytes,
i.e., ramdisk_size rounded up to a page boundary.
However, the allocation message and the panic message still use the
unaligned ramdisk_size, so the reported range or size can be too small.
Use area_size there instead, matching the page-aligned ramdisk_end
reported by reserve_initrd().
The exact ramdisk_size is still required for initrd_end, the copy
length, and the copy message, as those describe the image itself and
must not include the padding.
While at it, pass ramdisk_image and ramdisk_size from reserve_initrd()
to relocate_initrd() instead of re-reading them, use pr_info() and %llu
for the u64 allocation size, clarify the reservation and copy messages,
and drop ret by checking copy_from_early_mem() directly.
Fixes: c967da6a0ba8 ("x86: Make sure free_init_pages() frees pages on page boundary")
Signed-off-by: Thorsten Blum <blum@kernel.org>
---
Tested with QEMU using a 4097-byte initrd:
Reserved RAMDISK: [mem 0x1ffde000-0x1ffdffff]
Allocated new RAMDISK: [mem 0x0fffe000-0x0fffffff]
Copied RAMDISK from [mem 0x1ffde000-0x1ffdf000] to [mem 0x0fffe000-0x0ffff000]
Changes in v2:
- Make it a single patch with a new title
- Make range and size reporting consistent
- Use area_size in the allocation panic message with %llu
- Clarify the reservation and copy messages
- Pass ramdisk_image and ramdisk_size to relocate_initrd()
- Update the commit message to explain allocation and image sizes
- v1: https://lore.kernel.org/r/20261111165608.78688-4-blum@kernel.org/
arch/x86/kernel/setup.c | 27 ++++++++++-----------------
1 file changed, 10 insertions(+), 17 deletions(-)
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index 19fc8e1714e6..6694ebc2dd11 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -316,32 +316,26 @@ static u64 __init get_ramdisk_size(void)
return ramdisk_size;
}
-static void __init relocate_initrd(void)
+static void __init relocate_initrd(u64 ramdisk_image, u64 ramdisk_size)
{
/* Assume only end is not page aligned */
- u64 ramdisk_image = get_ramdisk_image();
- u64 ramdisk_size = get_ramdisk_size();
- u64 area_size = PAGE_ALIGN(ramdisk_size);
- int ret = 0;
+ u64 area_size = PAGE_ALIGN(ramdisk_size);
/* We need to move the initrd down into directly mapped mem */
u64 relocated_ramdisk = memblock_phys_alloc_range(area_size, PAGE_SIZE, 0,
PFN_PHYS(max_pfn_mapped));
if (!relocated_ramdisk)
- panic("Cannot find place for new RAMDISK of size %lld\n",
- ramdisk_size);
+ panic("Cannot allocate %llu bytes for new RAMDISK\n", area_size);
initrd_start = relocated_ramdisk + PAGE_OFFSET;
initrd_end = initrd_start + ramdisk_size;
- printk(KERN_INFO "Allocated new RAMDISK: [mem %#010llx-%#010llx]\n",
- relocated_ramdisk, relocated_ramdisk + ramdisk_size - 1);
+ pr_info("Allocated new RAMDISK: [mem %#010llx-%#010llx]\n",
+ relocated_ramdisk, relocated_ramdisk + area_size - 1);
- ret = copy_from_early_mem((void *)initrd_start, ramdisk_image, ramdisk_size);
- if (ret)
- panic("Copy RAMDISK failed\n");
+ if (copy_from_early_mem((void *)initrd_start, ramdisk_image, ramdisk_size))
+ panic("Copying RAMDISK failed\n");
- printk(KERN_INFO "Move RAMDISK from [mem %#010llx-%#010llx] to"
- " [mem %#010llx-%#010llx]\n",
+ pr_info("Copied RAMDISK from [mem %#010llx-%#010llx] to [mem %#010llx-%#010llx]\n",
ramdisk_image, ramdisk_image + ramdisk_size - 1,
relocated_ramdisk, relocated_ramdisk + ramdisk_size - 1);
}
@@ -373,8 +367,7 @@ static void __init reserve_initrd(void)
initrd_start = 0;
- printk(KERN_INFO "RAMDISK: [mem %#010llx-%#010llx]\n", ramdisk_image,
- ramdisk_end - 1);
+ pr_info("Reserved RAMDISK: [mem %#010llx-%#010llx]\n", ramdisk_image, ramdisk_end - 1);
if (pfn_range_is_mapped(PFN_DOWN(ramdisk_image),
PFN_DOWN(ramdisk_end))) {
@@ -384,7 +377,7 @@ static void __init reserve_initrd(void)
return;
}
- relocate_initrd();
+ relocate_initrd(ramdisk_image, ramdisk_size);
memblock_phys_free(ramdisk_image, ramdisk_end - ramdisk_image);
}
reply other threads:[~2026-11-16 10:03 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261116100230.160085-3-blum@kernel.org \
--to=blum@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=ardb@kernel.org \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hannes@cmpxchg.org \
--cc=harshit.m.mogalapalli@oracle.com \
--cc=hpa@zytor.com \
--cc=jaszczyk@chromium.org \
--cc=leitao@debian.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=mingo@redhat.com \
--cc=pratyush@kernel.org \
--cc=rppt@kernel.org \
--cc=tglx@kernel.org \
--cc=tzimmermann@suse.de \
--cc=x86@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.