Skip to content

Commit 3c45ee6

Browse files
rppttorvalds
authored andcommitted
x86/setup: simplify initrd relocation and reservation
Currently, initrd image is reserved very early during setup and then it might be relocated and re-reserved after the initial physical memory mapping is created. The "late" reservation of memblock verifies that mapped memory size exceeds the size of initrd, then checks whether the relocation required and, if yes, relocates inirtd to a new memory allocated from memblock and frees the old location. The check for memory size is excessive as memblock allocation will anyway fail if there is not enough memory. Besides, there is no point to allocate memory from memblock using memblock_find_in_range() + memblock_reserve() when there exists memblock_phys_alloc_range() with required functionality. Remove the redundant check and simplify memblock allocation. Signed-off-by: Mike Rapoport <rppt@linux.ibm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Reviewed-by: Baoquan He <bhe@redhat.com> Acked-by: Ingo Molnar <mingo@kernel.org> Cc: Andy Lutomirski <luto@kernel.org> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Borislav Petkov <bp@alien8.de> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Christoph Hellwig <hch@lst.de> Cc: Daniel Axtens <dja@axtens.net> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: Emil Renner Berthing <kernel@esmil.dk> Cc: Hari Bathini <hbathini@linux.ibm.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Jonathan Cameron <Jonathan.Cameron@huawei.com> Cc: Marek Szyprowski <m.szyprowski@samsung.com> Cc: Max Filippov <jcmvbkbc@gmail.com> Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: Michal Simek <monstr@monstr.eu> Cc: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com> Cc: Palmer Dabbelt <palmer@dabbelt.com> Cc: Paul Mackerras <paulus@samba.org> Cc: Paul Walmsley <paul.walmsley@sifive.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Russell King <linux@armlinux.org.uk> Cc: Stafford Horne <shorne@gmail.com> Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Will Deacon <will@kernel.org> Cc: Yoshinori Sato <ysato@users.sourceforge.jp> Link: https://lkml.kernel.org/r/20200818151634.14343-14-rppt@kernel.org Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent b10d6bc commit 3c45ee6

1 file changed

Lines changed: 3 additions & 13 deletions

File tree

arch/x86/kernel/setup.c

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -264,16 +264,12 @@ static void __init relocate_initrd(void)
264264
u64 area_size = PAGE_ALIGN(ramdisk_size);
265265

266266
/* We need to move the initrd down into directly mapped mem */
267-
relocated_ramdisk = memblock_find_in_range(0, PFN_PHYS(max_pfn_mapped),
268-
area_size, PAGE_SIZE);
269-
267+
relocated_ramdisk = memblock_phys_alloc_range(area_size, PAGE_SIZE, 0,
268+
PFN_PHYS(max_pfn_mapped));
270269
if (!relocated_ramdisk)
271270
panic("Cannot find place for new RAMDISK of size %lld\n",
272271
ramdisk_size);
273272

274-
/* Note: this includes all the mem currently occupied by
275-
the initrd, we rely on that fact to keep the data intact. */
276-
memblock_reserve(relocated_ramdisk, area_size);
277273
initrd_start = relocated_ramdisk + PAGE_OFFSET;
278274
initrd_end = initrd_start + ramdisk_size;
279275
printk(KERN_INFO "Allocated new RAMDISK: [mem %#010llx-%#010llx]\n",
@@ -300,26 +296,20 @@ static void __init early_reserve_initrd(void)
300296

301297
memblock_reserve(ramdisk_image, ramdisk_end - ramdisk_image);
302298
}
299+
303300
static void __init reserve_initrd(void)
304301
{
305302
/* Assume only end is not page aligned */
306303
u64 ramdisk_image = get_ramdisk_image();
307304
u64 ramdisk_size = get_ramdisk_size();
308305
u64 ramdisk_end = PAGE_ALIGN(ramdisk_image + ramdisk_size);
309-
u64 mapped_size;
310306

311307
if (!boot_params.hdr.type_of_loader ||
312308
!ramdisk_image || !ramdisk_size)
313309
return; /* No initrd provided by bootloader */
314310

315311
initrd_start = 0;
316312

317-
mapped_size = memblock_mem_size(max_pfn_mapped);
318-
if (ramdisk_size >= (mapped_size>>1))
319-
panic("initrd too large to handle, "
320-
"disabling initrd (%lld needed, %lld available)\n",
321-
ramdisk_size, mapped_size>>1);
322-
323313
printk(KERN_INFO "RAMDISK: [mem %#010llx-%#010llx]\n", ramdisk_image,
324314
ramdisk_end - 1);
325315

0 commit comments

Comments
 (0)