From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com ([134.134.136.24]:31254 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751215AbdDCFTZ (ORCPT ); Mon, 3 Apr 2017 01:19:25 -0400 Message-ID: <1491225561.3531.4.camel@intel.com> Subject: Re: [PATCH] nios2: reserve boot memory for device tree From: Ley Foon Tan To: Tobias Klauser , nios2-dev@lists.rocketboards.org Cc: Guenter Roeck , linux-kernel@vger.kernel.org, stable@vger.kernel.org, "lftan.linux@gmail.com" Date: Mon, 03 Apr 2017 06:19:21 -0700 In-Reply-To: <20170331094059.21394-1-tklauser@distanz.ch> References: <20170331094059.21394-1-tklauser@distanz.ch> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: On Fri, 2017-03-31 at 11:40 +0200, Tobias Klauser wrote: > Make sure to reserve the boot memory for the flattened device tree. > Otherwise it might get overwritten, e.g. when initial_boot_params is > copied, leading to a corrupted FDT and a boot hang/crash: >=20 > =C2=A0 bootconsole [early0] enabled > =C2=A0 Early console on uart16650 initialized at 0xf8001600 > =C2=A0 OF: fdt: Error -11 processing FDT > =C2=A0 Kernel panic - not syncing: setup_cpuinfo: No CPU found in > devicetree! >=20 > =C2=A0 ---[ end Kernel panic - not syncing: setup_cpuinfo: No CPU found i= n > devicetree! >=20 > Guenter Roeck says: >=20 > >=20 > > I think I found the problem. In unflatten_and_copy_device_tree(), > > with added > > debug information: > >=20 > > OF: fdt: initial_boot_params=3Dc861e400, dt=3Dc861f000 size=3D28874 > > (0x70ca) > >=20 > > ... and then initial_boot_params is copied to dt, which results in > > corrupted > > fdt since the memory overlaps. Looks like the initial_boot_params > > memory > > is not reserved and (re-)allocated by > > early_init_dt_alloc_memory_arch(). > Cc: stable@vger.kernel.org > Reported-by: Guenter Roeck > Reference: http://lkml.kernel.org/r/20170226210338.GA19476@roeck-us.n > et > Tested-by: Guenter Roeck > Signed-off-by: Tobias Klauser Acked-by: Ley Foon Tan Thanks for the fix. Will add this for 4.11. Regards Ley Foon > --- > =C2=A0arch/nios2/kernel/prom.c=C2=A0=C2=A0| 7 +++++++ > =C2=A0arch/nios2/kernel/setup.c | 3 +++ > =C2=A02 files changed, 10 insertions(+) >=20 > diff --git a/arch/nios2/kernel/prom.c b/arch/nios2/kernel/prom.c > index 367c5426157b..3901b80d4420 100644 > --- a/arch/nios2/kernel/prom.c > +++ b/arch/nios2/kernel/prom.c > @@ -48,6 +48,13 @@ void * __init early_init_dt_alloc_memory_arch(u64 > size, u64 align) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0return alloc_bootmem_alig= n(size, align); > =C2=A0} >=20 > +int __init early_init_dt_reserve_memory_arch(phys_addr_t base, > phys_addr_t size, > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0bool nomap) > +{ > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0reserve_bootmem(base, size, BO= OTMEM_DEFAULT); > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0return 0; > +} > + > =C2=A0void __init early_init_devtree(void *params) > =C2=A0{ > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0__be32 *dtb =3D (u32 *)__= dtb_start; > diff --git a/arch/nios2/kernel/setup.c b/arch/nios2/kernel/setup.c > index 6e57ffa5db27..6044d9be28b4 100644 > --- a/arch/nios2/kernel/setup.c > +++ b/arch/nios2/kernel/setup.c > @@ -201,6 +201,9 @@ void __init setup_arch(char **cmdline_p) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0} > =C2=A0#endif /* CONFIG_BLK_DEV_INITRD */ >=20 > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0early_init_fdt_reserve_self(); > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0early_init_fdt_scan_reserved_m= em(); > + > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0unflatten_and_copy_device= _tree(); >=20 > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0setup_cpuinfo(); > -- > 2.12.2.399.g034667a45805 >=20 >=20 >=20 > ________________________________ >=20 > Confidentiality Notice. > This message may contain information that is confidential or > otherwise protected from disclosure. If you are not the intended > recipient, you are hereby notified that any use, disclosure, > dissemination, distribution, or copying of this message, or any > attachments, is strictly prohibited. If you have received this > message in error, please advise the sender by reply e-mail, and > delete the message and any attachments. Thank you.