From: Patrick DELAUNAY Date: Wed, 18 Dec 2019 09:10:14 +0000 Subject: [PATCH v3] board_f.c: Insure gd->new_bootstage alignment In-Reply-To: References: <20191127091138.29223-1-patrice.chotard@st.com> Message-ID: <125dd84d74934c97bb7aca1477972ec2@SFHDAG6NODE3.st.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable To: u-boot@lists.denx.de Hi Simon, > From: Simon Glass > Sent: mardi 17 d=C3=A9cembre 2019 16:46 >=20 > Hi Patrice, >=20 > On Wed, 27 Nov 2019 at 02:11, Patrice Chotard wr= ote: > > > > In reserve_bootstage(), in case size is odd, gd->new_bootstage is not > > aligned. In bootstage_relocate(), the platform hangs when getting > > access to data->record[i].name. > > To avoid this issue, make gd->new_bootstage 16 byte aligned. > > > > To insure that new_bootstage is 16 byte aligned (at least needed for > > x86_64 and ARMv8) and new_bootstage starts down to get enough space, > > ALIGN_DOWN macro is used. > > > > Fixes: ac9cd4805c8b ("bootstage: Correct relocation algorithm") > > > > Signed-off-by: Patrice Chotard > > Reviewed-by: Vikas MANOCHA > > Reviewed-by: Patrick Delaunay > > Tested-by: Patrick Delaunay For information, Patrice is absent for personal reason up to beginning next= year. Don't wait a fast answer. > For this patch I think it would be better to update reserve_fdt() to keep= things > aligned, assuming that is the problem. I don't sure that solve the issue,=20 for me the problem is only for the bootstage struct (gd->bootstage) And reserve_fdt() already alligne size on 32 bytes If I remember the Patrice analysis: 1- bootstage_get_size return a odd value (or at least not 16 bytes aligned = I don't remember). 2- In reserve_bootstage() int size =3D bootstage_get_size(); gd->start_addr_sp -=3D size =3D> it is a unaligned address even if gd->start_addr_sp is 32 bytes allig= ned gd->new_bootstage =3D map_sysmem(gd->start_addr_sp, size); =3D> also unaligned 3- Then during relocation, in reloc_bootstage() gd->bootstage =3D gd->new_bootstage; 4- crash occur because in next bootstage function beaucse the boostage addr= ess don't respect pointer to struct allignement... struct bootstage_data *data =3D gd->bootstage > At some point we should also document that reservations must keep things > aligned. >=20 > Perhaps this should be handled by a separate function called from all the= se > places, which subtracts gd->start_addr_sp and ensures 16-byte alignment. Yes that can be a improvement, but perhaps ia a second step / second serie= .... Do you think about a function called in all reversed_ functions (when start= _addr_sp is modified)... static int reserved_allign_check(void) { /* make stack pointer 16-byte aligned */ if (gd->start_addr_sp & 0xf) { gd->start_addr_sp -=3D 16; gd->start_addr_sp &=3D ~0xf; } } I prefer a function to reserved a size wich replace in any reserve_ functio= n the line :=20 gd->start_addr_sp -=3D ... /* reserve size and make stack pointer 16-byte aligned */ static int reserve(size_t size) { gd->start_addr_sp -=3D size; /* make stack pointer 16-byte aligned */ gd->start_addr_sp =3D ALIGN_DOWN(gd->start_addr_sp, 16); } I think I will push it, when the patrice patch will be accepted. > Regards, > Simon Regards Patrick