Skip to contentSkip to conversation

x86/setup: Fix logged allocation range in relocate_initrd()

PATCH RESEND In review Thorsten Blum 2 participants 4 messages Nov 11 – Nov 15 x86

lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/3 x86/setup: Fix logged allocation range in relocate_initrd()

Since commit c967da6a0ba8 ("x86: Make sure free_init_pages() frees pages on page boundary"), relocate_initrd() allocates area_size bytes, which is ramdisk_size rounded up to a page boundary. However, the log still uses the potentially smaller ramdisk_size to calculate the end of the allocated range and can report it as too short.

Use area_size instead.

Fixes c967da6a0ba8 ("x86: Make sure free_init_pages() frees pages on page boundary")
---
 arch/x86/kernel/setup.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/setup.c +1 -1
index 19fc8e1714e6..4a6c54110e75 100644
@@ -334,7 +334,7 @@ static void __init relocate_initrd(void)
 	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);
+	       relocated_ramdisk, relocated_ramdisk + area_size - 1);
 
 	ret = copy_from_early_mem((void *)initrd_start, ramdisk_image, ramdisk_size);
 	if (ret)
#1 lore raw

PATCH RESEND 2/3 x86/setup: Simplify copy error handling in relocate_initrd()

Check the result of copy_from_early_mem() directly and drop the now-obsolete local ret variable.

No functional change.

---
 arch/x86/kernel/setup.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
arch/x86/kernel/setup.c +1 -3
index 4a6c54110e75..8f34bd61512e 100644
@@ -322,7 +322,6 @@ static void __init relocate_initrd(void)
 	u64 ramdisk_image = get_ramdisk_image();
 	u64 ramdisk_size  = get_ramdisk_size();
 	u64 area_size     = PAGE_ALIGN(ramdisk_size);
-	int ret = 0;
 
 	/* We need to move the initrd down into directly mapped mem */
 	u64 relocated_ramdisk = memblock_phys_alloc_range(area_size, PAGE_SIZE, 0,
@@ -336,8 +335,7 @@ static void __init relocate_initrd(void)
 	printk(KERN_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)
+	if (copy_from_early_mem((void *)initrd_start, ramdisk_image, ramdisk_size))
 		panic("Copy RAMDISK failed\n");
 
 	printk(KERN_INFO "Move RAMDISK from [mem %#010llx-%#010llx] to"
#2 lore raw

PATCH RESEND 3/3 x86/setup: Use pr_info() in relocate_initrd()

In reply to Thorsten Blum

Use pr_info() instead of printk(KERN_INFO) as suggested by checkpatch.

Also change "Move" to "Moved" to match the past tense of "Allocated".

---
 arch/x86/kernel/setup.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
arch/x86/kernel/setup.c +3 -4
index 8f34bd61512e..91acec0ff252 100644
@@ -332,14 +332,13 @@ static void __init relocate_initrd(void)
 
 	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 + area_size - 1);
+	pr_info("Allocated new RAMDISK: [mem %#010llx-%#010llx]\n",
+		relocated_ramdisk, relocated_ramdisk + area_size - 1);
 
 	if (copy_from_early_mem((void *)initrd_start, ramdisk_image, ramdisk_size))
 		panic("Copy RAMDISK failed\n");
 
-	printk(KERN_INFO "Move RAMDISK from [mem %#010llx-%#010llx] to"
-		" [mem %#010llx-%#010llx]\n",
+	pr_info("Moved RAMDISK from [mem %#010llx-%#010llx] to [mem %#010llx-%#010llx]\n",
 		ramdisk_image, ramdisk_image + ramdisk_size - 1,
 		relocated_ramdisk, relocated_ramdisk + ramdisk_size - 1);
 }
maintainer
#3 lore raw
In reply to Thorsten Blum
Quoted 19 lines · Thorsten Blum

Since commit c967da6a0ba8 ("x86: Make sure free_init_pages() frees pages on page boundary"), relocate_initrd() allocates area_size bytes, which is ramdisk_size rounded up to a page boundary. However, the log still uses the potentially smaller ramdisk_size to calculate the end of the allocated range and can report it as too short.

Use area_size instead.

Fixes c967da6a0ba8 ("x86: Make sure free_init_pages() frees pages on page boundary")
---
 arch/x86/kernel/setup.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/setup.c +0 -0
index 19fc8e1714e6..4a6c54110e75 100644

arch/x86/kernel/setup.c static void __init relocate_initrd(void) · line 340

Quoted 8 lines
arch/x86/kernel/setup.c +1 -1
@@ -334,7 +334,7 @@ static void __init relocate_initrd(void)
 	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);
+	       relocated_ramdisk, relocated_ramdisk + area_size - 1);
 
 	ret = copy_from_early_mem((void *)initrd_start, ramdisk_image, ramdisk_size);
 	if (ret)

What about the rest of the code in that function still using ramdisk_size? But reserve_initrd() using the page-aligned size?

Looks to me like this should be unified.

And that unification patch should contain all your other micro changes.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette