linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] arm: Support initrd with address in boot alias region
@ 2020-09-29  7:54 Matija Glavinic Pecotic
  2020-09-29 17:21 ` Florian Fainelli
  0 siblings, 1 reply; 4+ messages in thread
From: Matija Glavinic Pecotic @ 2020-09-29  7:54 UTC (permalink / raw)
  To: linux-arm-kernel; +Cc: f.fainelli, Sverdlin, Alexander (Nokia - DE/Ulm)

If bootloader passes address of initrd in boot alias region, initrd
will fail on memblock_is_region_memory as memblock with such address
doesn't exist.

Issue was observed with kexec which passed initrd address in boot alias
region, while bootloader will typically pass physical address. Commit
fe7db7570379 ("of/fdt: Populate phys_initrd_start/phys_initrd_size from FDT")
uncovered problem by removing virt_to_phys on the initrd physical
address. __virt_to_phys on our platform coincidentally fixed address.

Fix by trying to correct address in case of invalid physical address.

Signed-off-by: Matija Glavinic Pecotic <matija.glavinic-pecotic.ext@nokia.com>
---
 arch/arm/mm/init.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
index 000c1b48e973..6cbf64383cfc 100644
--- a/arch/arm/mm/init.c
+++ b/arch/arm/mm/init.c
@@ -164,6 +164,17 @@ static void __init arm_initrd_init(void)
 	if (!phys_initrd_size)
 		return;
 
+	/*
+	 * In case initrd is not valid physical address, try with boot
+	 * memory region alias as bootloader may have passed address
+	 * within.
+	 */
+	if (!pfn_valid(__phys_to_pfn(phys_initrd_start))) {
+		pr_info("initrd at invalid address, trying with boot alias\n");
+		if (arm_has_idmap_alias())
+			phys_initrd_start = idmap_to_phys(phys_initrd_start);
+	}
+
 	/*
 	 * Round the memory region to page boundaries as per free_initrd_mem()
 	 * This allows us to detect whether the pages overlapping the initrd
-- 
2.28.0

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] arm: Support initrd with address in boot alias region
  2020-09-29  7:54 [PATCH] arm: Support initrd with address in boot alias region Matija Glavinic Pecotic
@ 2020-09-29 17:21 ` Florian Fainelli
  2020-09-30 10:35   ` Russell King - ARM Linux admin
  0 siblings, 1 reply; 4+ messages in thread
From: Florian Fainelli @ 2020-09-29 17:21 UTC (permalink / raw)
  To: Matija Glavinic Pecotic, linux-arm-kernel, Rob Herring, Russell King
  Cc: Sverdlin, Alexander (Nokia - DE/Ulm)

+Rob, Russell,

On 9/29/2020 12:54 AM, Matija Glavinic Pecotic wrote:
> If bootloader passes address of initrd in boot alias region, initrd
> will fail on memblock_is_region_memory as memblock with such address
> doesn't exist.
> 
> Issue was observed with kexec which passed initrd address in boot alias
> region, while bootloader will typically pass physical address. Commit
> fe7db7570379 ("of/fdt: Populate phys_initrd_start/phys_initrd_size from FDT")
> uncovered problem by removing virt_to_phys on the initrd physical
> address. __virt_to_phys on our platform coincidentally fixed address.
> 
> Fix by trying to correct address in case of invalid physical address.
> 
> Signed-off-by: Matija Glavinic Pecotic <matija.glavinic-pecotic.ext@nokia.com>

This should have a Fixes tag:

fe7db7570379 ("of/fdt: Populate phys_initrd_start/phys_initrd_size from 
FDT")

I am not familiar enough with how the identity map works, but it seems 
to do what you want it to.
-- 
Florian

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] arm: Support initrd with address in boot alias region
  2020-09-29 17:21 ` Florian Fainelli
@ 2020-09-30 10:35   ` Russell King - ARM Linux admin
  2020-09-30 11:07     ` Matija Glavinic Pecotic
  0 siblings, 1 reply; 4+ messages in thread
From: Russell King - ARM Linux admin @ 2020-09-30 10:35 UTC (permalink / raw)
  To: Florian Fainelli
  Cc: Sverdlin, Alexander (Nokia - DE/Ulm),
	Rob Herring, Matija Glavinic Pecotic, linux-arm-kernel

On Tue, Sep 29, 2020 at 10:21:35AM -0700, Florian Fainelli wrote:
> +Rob, Russell,
> 
> On 9/29/2020 12:54 AM, Matija Glavinic Pecotic wrote:
> > If bootloader passes address of initrd in boot alias region, initrd
> > will fail on memblock_is_region_memory as memblock with such address
> > doesn't exist.
> > 
> > Issue was observed with kexec which passed initrd address in boot alias
> > region, while bootloader will typically pass physical address. Commit
> > fe7db7570379 ("of/fdt: Populate phys_initrd_start/phys_initrd_size from FDT")
> > uncovered problem by removing virt_to_phys on the initrd physical
> > address. __virt_to_phys on our platform coincidentally fixed address.
> > 
> > Fix by trying to correct address in case of invalid physical address.
> > 
> > Signed-off-by: Matija Glavinic Pecotic <matija.glavinic-pecotic.ext@nokia.com>
> 
> This should have a Fixes tag:
> 
> fe7db7570379 ("of/fdt: Populate phys_initrd_start/phys_initrd_size from
> FDT")
> 
> I am not familiar enough with how the identity map works, but it seems to do
> what you want it to.

It seems strange to pass the initrd in using an address that is not
listed as part of the system memory map, especially as the initrd is
freed during kernel initialisation.

Which boot loader is this, and is there a reason it operates this way?

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] arm: Support initrd with address in boot alias region
  2020-09-30 10:35   ` Russell King - ARM Linux admin
@ 2020-09-30 11:07     ` Matija Glavinic Pecotic
  0 siblings, 0 replies; 4+ messages in thread
From: Matija Glavinic Pecotic @ 2020-09-30 11:07 UTC (permalink / raw)
  To: Russell King - ARM Linux admin, Florian Fainelli
  Cc: Rob Herring, Sverdlin, Alexander (Nokia - DE/Ulm), linux-arm-kernel

On 09/30/2020 12:35 PM, Russell King - ARM Linux admin wrote:
> It seems strange to pass the initrd in using an address that is not
> listed as part of the system memory map, especially as the initrd is
> freed during kernel initialisation.
> 
> Which boot loader is this, and is there a reason it operates this way?

It is kexec which populates this address. Kexec is allowed to do that
as this region is listed as boot alias:

$ cat /proc/iomem 
[cut]
c0000000-d4da1fff : System RAM (boot alias)
840000000-854da1fff : System RAM
  840008000-840bfffff : Kernel code
  840e00000-840ee56fb : Kernel data
[cut]
880000000-8ffffffff : System RAM

it is arch/arm/kernel/setup.c which populates this entry on line 870:

/*
 * Some systems have a special memory alias which is only
 * used for booting.  We need to advertise this region to
 * kexec-tools so they know where bootable RAM is located.
 */
boot_alias_start = phys_to_idmap(start);
if (arm_has_idmap_alias() && boot_alias_start != IDMAP_INVALID_ADDR) {
        res = memblock_alloc(sizeof(*res), SMP_CACHE_BYTES);
        if (!res)
                panic("%s: Failed to allocate %zu bytes\n",
                      __func__, sizeof(*res));
        res->name = "System RAM (boot alias)";
        res->start = boot_alias_start;
        res->end = phys_to_idmap(end);
        res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
        request_resource(&iomem_resource, res);
}

This is likely reason why problem has gone unnoticed for so long. I dont
think there is large number of platforms which have boot alias regions +
they use kexec. As noted earlier, bootloader passes correct address, it
is kexec which passes invalid one resulting with:

[    0.000000] INITRD: 0xc49bb000+0x01a1a000 is not a memory region - disabling initrd

and later with failure to mount it.

Regards,

Matija

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2020-09-30 11:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-29  7:54 [PATCH] arm: Support initrd with address in boot alias region Matija Glavinic Pecotic
2020-09-29 17:21 ` Florian Fainelli
2020-09-30 10:35   ` Russell King - ARM Linux admin
2020-09-30 11:07     ` Matija Glavinic Pecotic

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).