Skip to contentSkip to conversation

initrd: move initrd_start calculate within linear mapping range check

PATCH Superseded pierre Kuo 2 participants 2 messages Mar 12, 2019 – Mar 13, 2019 arm64

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

pierre Kuo

author
#0 lore raw

PATCH 1/1 initrd: move initrd_start calculate within linear mapping range check

in the previous case, initrd_start and initrd_end can be successfully returned even (base < memblock_start_of_DRAM()) or (base + size > memblock_start_of_DRAM() + linear_region_size).

That means even linear mapping range check fail for initrd_start and initrd_end, it still can get virtual address. Here we put initrd_start/initrd_end to be calculated only when linear mapping check pass.

---
 arch/arm64/mm/init.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
arch/arm64/mm/init.c +3 -5
index 7205a9085b4d..1adf418de685 100644
@@ -425,6 +425,9 @@ void __init arm64_memblock_init(void)
 			memblock_remove(base, size); /* clear MEMBLOCK_ flags */
 			memblock_add(base, size);
 			memblock_reserve(base, size);
+			/* the generic initrd code expects virtual addresses */
+			initrd_start = __phys_to_virt(phys_initrd_start);
+			initrd_end = initrd_start + phys_initrd_size;
 		}
 	}
 
@@ -450,11 +453,6 @@ void __init arm64_memblock_init(void)
 	 * pagetables with memblock.
 	 */
 	memblock_reserve(__pa_symbol(_text), _end - _text);
-	if (IS_ENABLED(CONFIG_BLK_DEV_INITRD) && phys_initrd_size) {
-		/* the generic initrd code expects virtual addresses */
-		initrd_start = __phys_to_virt(phys_initrd_start);
-		initrd_end = initrd_start + phys_initrd_size;
-	}
 
 	early_init_fdt_scan_reserved_mem();
 
Signature · 1 line
2.17.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · pierre Kuo

in the previous case, initrd_start and initrd_end can be successfully returned even (base < memblock_start_of_DRAM()) or (base + size > memblock_start_of_DRAM() + linear_region_size).

That means even linear mapping range check fail for initrd_start and initrd_end, it still can get virtual address. Here we put initrd_start/initrd_end to be calculated only when linear mapping check pass.

From what I can see this was broken in commit c756c592e442ba101c91daed3524ba5b3a784ba6 ("arm64: Utilize phys_initrd_start/phys_initrd_size") which switched the condition for setting initrd_start/initrd_end to depending on phys_initrd_size (rather than initrd_start). This means that when the code detects the initrd is not fully accessible sets initrd_start = 0 it no longer has the desired effect.

So you might want to add a Fixes tag. Otherwise FWIW:

Thanks,

Steve

Quoted 32 lines
---
 arch/arm64/mm/init.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
arch/arm64/mm/init.c +3 -5
index 7205a9085b4d..1adf418de685 100644
@@ -425,6 +425,9 @@ void __init arm64_memblock_init(void)
 			memblock_remove(base, size); /* clear MEMBLOCK_ flags */
 			memblock_add(base, size);
 			memblock_reserve(base, size);
+			/* the generic initrd code expects virtual addresses */
+			initrd_start = __phys_to_virt(phys_initrd_start);
+			initrd_end = initrd_start + phys_initrd_size;
 		}
 	}
 
@@ -450,11 +453,6 @@ void __init arm64_memblock_init(void)
 	 * pagetables with memblock.
 	 */
 	memblock_reserve(__pa_symbol(_text), _end - _text);
-	if (IS_ENABLED(CONFIG_BLK_DEV_INITRD) && phys_initrd_size) {
-		/* the generic initrd code expects virtual addresses */
-		initrd_start = __phys_to_virt(phys_initrd_start);
-		initrd_end = initrd_start + phys_initrd_size;
-	}
 
 	early_init_fdt_scan_reserved_mem();