ARM initrd updates
Russell King - ARM Linux
maintainercover ARM initrd updates
Three patches to cleanup and update the ARM initrd handling, after problems identified by William Helsby.
The first patch merely moves the early initrd code into a separate function, rather than being bundled up inside arm_memblock_init().
The second patch restructures the initrd code to be cleaner, but with no functional changes. We get rid of the repetitive phys_initrd_size checks, as we can now just "return" from the function.
The third patch changes how we check for overlaps and the region that we reserve. Since the kernel deals with pages and not bytes for allocation, the minimum granule for marking addresses reserved and later freeing them is one page. We already adjust the initrd addresses in free_initrd_mem(), but we fail to mark the partially used pages entirely reserved. Add this.
arch/arm/mm/init.c | 57 +++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 18 deletions(-)
Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/ FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up according to speedtest.net.
PATCH 1/3 ARM: mm: move initrd init code out of arm_memblock_init()
Move the ARM initrd initialisation code out of arm_memblock_init() into its own function, so it can be cleaned up.
--- arch/arm/mm/init.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
arch/arm/mm/init.c +9 -4
@@ -228,11 +228,8 @@ phys_addr_t __init arm_memblock_steal(phys_addr_t size, phys_addr_t align)return phys; } -void __init arm_memblock_init (const struct machine_desc *mdesc) +static void __init arm_initrd_init (void ) { -/* Register the kernel text, kernel data and initrd with memblock. */ -memblock_reserve (__pa (KERNEL_START ),KERNEL_END -KERNEL_START ); -#ifdef CONFIG_BLK_DEV_INITRD /* FDT scan will populate initrd_start */ if (initrd_start && !phys_initrd_size) {
@@ -260,6 +257,14 @@ void __init arm_memblock_init(const struct machine_desc *mdesc) initrd_end = initrd_start + phys_initrd_size; }#endif +} + +void __init arm_memblock_init (const struct machine_desc *mdesc) +{ +/* Register the kernel text, kernel data and initrd with memblock. */ +memblock_reserve (__pa (KERNEL_START ),KERNEL_END -KERNEL_START ); + +arm_initrd_init ();arm_mm_memblock_reserve ();
Signature · 1 line
2.7.4
PATCH 2/3 ARM: mm: clean up initrd initialisation
In reply to Russell King - ARM LinuxRather than repeatedly testing phys_initrd_size to see if the initrd is still enabled, return from the new function to avoid executing the remaining initialisation.
--- arch/arm/mm/init.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-)
arch/arm/mm/init.c +15 -12
@@ -236,26 +236,29 @@ static void __init arm_initrd_init(void) phys_initrd_start =__virt_to_phys (initrd_start); phys_initrd_size = initrd_end - initrd_start; } + initrd_start = initrd_end =0 ; -if (phys_initrd_size && - !memblock_is_region_memory (phys_initrd_start, phys_initrd_size)) { + +if (!phys_initrd_size) +return ; + +if (!memblock_is_region_memory (phys_initrd_start, phys_initrd_size)) {pr_err ("INITRD: 0x%08llx+0x%08lx is not a memory region - disabling initrd\n" , (u64 )phys_initrd_start, phys_initrd_size); - phys_initrd_start = phys_initrd_size =0 ; +return ; } -if (phys_initrd_size && -memblock_is_region_reserved (phys_initrd_start, phys_initrd_size)) { + +if (memblock_is_region_reserved (phys_initrd_start, phys_initrd_size)) {pr_err ("INITRD: 0x%08llx+0x%08lx overlaps in-use memory region - disabling initrd\n" , (u64 )phys_initrd_start, phys_initrd_size); - phys_initrd_start = phys_initrd_size =0 ; +return ; } -if (phys_initrd_size) { -memblock_reserve (phys_initrd_start, phys_initrd_size); -/* Now convert initrd to virtual addresses */ - initrd_start =__phys_to_virt (phys_initrd_start); - initrd_end = initrd_start + phys_initrd_size; - } +memblock_reserve (phys_initrd_start, phys_initrd_size); + +/* Now convert initrd to virtual addresses */ + initrd_start =__phys_to_virt (phys_initrd_start); + initrd_end = initrd_start + phys_initrd_size;#endif }
Signature · 1 line
2.7.4
PATCH 3/3 ARM: mm: round the initrd reservation to page boundaries
In reply to Russell King - ARM LinuxRound the initrd memblock reservation to page boundaries to prevent other data sharing the initrd pages. This prevents an allocation possibly overlapping with the initrd, which would later get trampled on in free_initrd_mem().
--- arch/arm/mm/init.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-)
arch/arm/mm/init.c +18 -5
@@ -231,6 +231,9 @@ phys_addr_t __init arm_memblock_steal(phys_addr_t size, phys_addr_t align)static void __init arm_initrd_init (void ) {#ifdef CONFIG_BLK_DEV_INITRD +phys_addr_t start; +unsigned long size; +/* FDT scan will populate initrd_start */ if (initrd_start && !phys_initrd_size) { phys_initrd_start =__virt_to_phys (initrd_start);
@@ -242,19 +245,29 @@ static void __init arm_initrd_init(void)if (!phys_initrd_size)return ; -if (!memblock_is_region_memory (phys_initrd_start, phys_initrd_size)) { +/* +* Round the memory region to page boundaries as per free_initrd_mem() +* This allows us to detect whether the pages overlapping the initrd +* are in use, but more importantly, reserves the entire set of pages +* as we don't want these pages allocated for other purposes. +*/ + start =round_down (phys_initrd_start,PAGE_SIZE ); + size = phys_initrd_size + (phys_initrd_start - start); + size =round_up (size,PAGE_SIZE ); + +if (!memblock_is_region_memory (start, size)) {pr_err ("INITRD: 0x%08llx+0x%08lx is not a memory region - disabling initrd\n" , - (u64 )phys_initrd_start, phys_initrd_size); + (u64 )start, size);return ; } -if (memblock_is_region_reserved (phys_initrd_start, phys_initrd_size)) { +if (memblock_is_region_reserved (start, size)) {pr_err ("INITRD: 0x%08llx+0x%08lx overlaps in-use memory region - disabling initrd\n" , - (u64 )phys_initrd_start, phys_initrd_size); + (u64 )start, size);return ; } -memblock_reserve (phys_initrd_start, phys_initrd_size); +memblock_reserve (start, size);/* Now convert initrd to virtual addresses */ initrd_start =__phys_to_virt (phys_initrd_start);
Signature · 1 line
2.7.4