All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] ARM initrd updates
@ 2017-02-08 11:10 Russell King - ARM Linux
  2017-02-08 11:10 ` [PATCH 1/3] ARM: mm: move initrd init code out of arm_memblock_init() Russell King
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Russell King - ARM Linux @ 2017-02-08 11:10 UTC (permalink / raw)
  To: linux-arm-kernel

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(-)

-- 
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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/3] ARM: mm: move initrd init code out of arm_memblock_init()
  2017-02-08 11:10 [PATCH 0/3] ARM initrd updates Russell King - ARM Linux
@ 2017-02-08 11:10 ` Russell King
  2017-02-08 11:11 ` [PATCH 2/3] ARM: mm: clean up initrd initialisation Russell King
  2017-02-08 11:11 ` [PATCH 3/3] ARM: mm: round the initrd reservation to page boundaries Russell King
  2 siblings, 0 replies; 4+ messages in thread
From: Russell King @ 2017-02-08 11:10 UTC (permalink / raw)
  To: linux-arm-kernel

Move the ARM initrd initialisation code out of arm_memblock_init() into
its own function, so it can be cleaned up.

Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
---
 arch/arm/mm/init.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
index 50e5402a8ef3..43d8825e59bb 100644
--- a/arch/arm/mm/init.c
+++ b/arch/arm/mm/init.c
@@ -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();
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/3] ARM: mm: clean up initrd initialisation
  2017-02-08 11:10 [PATCH 0/3] ARM initrd updates Russell King - ARM Linux
  2017-02-08 11:10 ` [PATCH 1/3] ARM: mm: move initrd init code out of arm_memblock_init() Russell King
@ 2017-02-08 11:11 ` Russell King
  2017-02-08 11:11 ` [PATCH 3/3] ARM: mm: round the initrd reservation to page boundaries Russell King
  2 siblings, 0 replies; 4+ messages in thread
From: Russell King @ 2017-02-08 11:11 UTC (permalink / raw)
  To: linux-arm-kernel

Rather 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.

Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
---
 arch/arm/mm/init.c | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
index 43d8825e59bb..15739a95552a 100644
--- a/arch/arm/mm/init.c
+++ b/arch/arm/mm/init.c
@@ -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
 }
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 3/3] ARM: mm: round the initrd reservation to page boundaries
  2017-02-08 11:10 [PATCH 0/3] ARM initrd updates Russell King - ARM Linux
  2017-02-08 11:10 ` [PATCH 1/3] ARM: mm: move initrd init code out of arm_memblock_init() Russell King
  2017-02-08 11:11 ` [PATCH 2/3] ARM: mm: clean up initrd initialisation Russell King
@ 2017-02-08 11:11 ` Russell King
  2 siblings, 0 replies; 4+ messages in thread
From: Russell King @ 2017-02-08 11:11 UTC (permalink / raw)
  To: linux-arm-kernel

Round 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().

Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
---
 arch/arm/mm/init.c | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
index 15739a95552a..d1e26610977d 100644
--- a/arch/arm/mm/init.c
+++ b/arch/arm/mm/init.c
@@ -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);
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-02-08 11:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-08 11:10 [PATCH 0/3] ARM initrd updates Russell King - ARM Linux
2017-02-08 11:10 ` [PATCH 1/3] ARM: mm: move initrd init code out of arm_memblock_init() Russell King
2017-02-08 11:11 ` [PATCH 2/3] ARM: mm: clean up initrd initialisation Russell King
2017-02-08 11:11 ` [PATCH 3/3] ARM: mm: round the initrd reservation to page boundaries Russell King

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.