Skip to contentSkip to conversation

board_f.c: Insure gd->new_bootstage alignment

PATCH Superseded Patrick DELAUNAY 2 participants 4 messages Jan 7, 2020 – Jan 22, 2020

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 board_f.c: Insure gd->new_bootstage alignment

Hi Patrice and Tom

Quoted 85 lines

Sent: mercredi 18 décembre 2019 10:10

Hi Simon,

Quoted 6 lines

From: Simon Glass <[email protected]>
Sent: mardi 17 décembre 2019 16:46

Hi Patrice,

On Wed, 27 Nov 2019 at 02:11, Patrice Chotard <[email protected]>

Quoted 10 lines · wrote:
Quoted 10 lines

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.

Quoted 6 lines
Quoted 6 lines
Fixes ac9cd4805c8b ("bootstage: Correct relocation algorithm")

For information, Patrice is absent for personal reason up to beginning next year. Don't wait a fast answer.

Quoted 2 lines

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,
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 = bootstage_get_size();
	gd->start_addr_sp -= size
	=> it is a unaligned address even if gd->start_addr_sp is 32 bytes alligned

	gd->new_bootstage = map_sysmem(gd->start_addr_sp, size);
	=> also unaligned

3- Then during relocation, in reloc_bootstage()

	gd->bootstage = gd->new_bootstage;

4- crash occur because in next bootstage function beaucse the boostage address don't respect pointer to struct allignement...

	struct bootstage_data *data = gd->bootstage
Quoted 5 lines

At some point we should also document that reservations must keep things aligned.

Perhaps this should be handled by a separate function called from all these 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 -= 16;
		gd->start_addr_sp &= ~0xf;
	 }
}

I prefer a function to reserved a size wich replace in any reserve_ function the line :

	gd->start_addr_sp -= ...
Quoted 8 lines

/* reserve size and make stack pointer 16-byte aligned */

 static int reserve(size_t size) {
	gd->start_addr_sp -= size;
	/* make stack pointer 16-byte aligned */
	gd->start_addr_sp = ALIGN_DOWN(gd->start_addr_sp, 16);
}

I think I will push it, when the patrice patch will be accepted.

I am preparing this patch....

Do you think it is ok to merge the Patrice v3 proposal first on master branch for v2020.04 release (he just align the reserved memory for bootstage), and after I make my patch (16-byte align all reserved area).

or it is better to make a more generic patch v4 to replace the Patrice one.

Regards
Patrick

#1 lore raw

PATCH v3 1/1 board_f.c: Insure gd->new_bootstage alignment

Hi,

Quoted 103 lines

From: Patrick DELAUNAY
Sent: mardi 7 janvier 2020 13:07

Hi Patrice and Tom

Quoted 55 lines

Sent: mercredi 18 décembre 2019 10:10

Hi Simon,

Quoted 7 lines

From: Simon Glass <[email protected]>
Sent: mardi 17 décembre 2019 16:46

Hi Patrice,

On Wed, 27 Nov 2019 at 02:11, Patrice Chotard
<[email protected]>

Quoted 11 lines · wrote:
Quoted 11 lines

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.

Quoted 6 lines
Quoted 6 lines
Fixes ac9cd4805c8b ("bootstage: Correct relocation algorithm")

For information, Patrice is absent for personal reason up to beginning next year. Don't wait a fast answer.

Quoted 2 lines

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,
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 = bootstage_get_size();
	gd->start_addr_sp -= size
	=> it is a unaligned address even if gd->start_addr_sp is 32 bytes

alligned

	gd->new_bootstage = map_sysmem(gd->start_addr_sp, size);
	=> also unaligned
Quoted 15 lines

3- Then during relocation, in reloc_bootstage()

	gd->bootstage = gd->new_bootstage;

4- crash occur because in next bootstage function beaucse the boostage address don't respect pointer to struct allignement...

	struct bootstage_data *data = gd->bootstage
Quoted 5 lines

At some point we should also document that reservations must keep things aligned.

Perhaps this should be handled by a separate function called from all these places, which subtracts gd->start_addr_sp and ensures 16-byte

alignment.

Quoted 19 lines

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 -= 16;
		gd->start_addr_sp &= ~0xf;
	 }
}

I prefer a function to reserved a size wich replace in any reserve_ function the line
:

	gd->start_addr_sp -= ...
Quoted 7 lines

/* reserve size and make stack pointer 16-byte aligned */ static int

reserve(size_t size) {
	gd->start_addr_sp -= size;
	/* make stack pointer 16-byte aligned */
	gd->start_addr_sp = ALIGN_DOWN(gd->start_addr_sp, 16); }

I think I will push it, when the patrice patch will be accepted.

Quoted 7 lines

I am preparing this patch....

Do you think it is ok to merge the Patrice v3 proposal first on master branch for v2020.04 release (he just align the reserved memory for bootstage), and after I make my patch (16-byte align all reserved area).

or it is better to make a more generic patch v4 to replace the Patrice one.

I push a serie, with my proposal:
[3/3] board_f.c: Insure 16 alignment of start_addr_sp and reserved memory

http://patchwork.ozlabs.org/project/uboot/list/?series=152226

As I found issue for ARM32 (I need to modify arch/arm/lib/crt0.S)
I think it is preferable that the Patrice Patch is merged in v2020.04, and my serie can live independently. But I can also squash of the 2 series.

Regards
Patrick

#2 lore raw

PATCH v3 1/1 board_f.c: Insure gd->new_bootstage alignment

Quoted 113 lines · Patrick DELAUNAY

Hi,

Quoted 103 lines

From: Patrick DELAUNAY
Sent: mardi 7 janvier 2020 13:07

Hi Patrice and Tom

Quoted 55 lines

Sent: mercredi 18 décembre 2019 10:10

Hi Simon,

Quoted 7 lines

From: Simon Glass <[email protected]>
Sent: mardi 17 décembre 2019 16:46

Hi Patrice,

On Wed, 27 Nov 2019 at 02:11, Patrice Chotard
<[email protected]>

Quoted 11 lines · wrote:
Quoted 11 lines

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.

Quoted 6 lines
Quoted 6 lines
Fixes ac9cd4805c8b ("bootstage: Correct relocation algorithm")

For information, Patrice is absent for personal reason up to beginning next year. Don't wait a fast answer.

Quoted 2 lines

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,
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 = bootstage_get_size();
	gd->start_addr_sp -= size
	=> it is a unaligned address even if gd->start_addr_sp is 32 bytes

alligned

	gd->new_bootstage = map_sysmem(gd->start_addr_sp, size);
	=> also unaligned
Quoted 15 lines

3- Then during relocation, in reloc_bootstage()

	gd->bootstage = gd->new_bootstage;

4- crash occur because in next bootstage function beaucse the boostage address don't respect pointer to struct allignement...

	struct bootstage_data *data = gd->bootstage
Quoted 5 lines

At some point we should also document that reservations must keep things aligned.

Perhaps this should be handled by a separate function called from all these places, which subtracts gd->start_addr_sp and ensures 16-byte

alignment.

Quoted 19 lines

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 -= 16;
		gd->start_addr_sp &= ~0xf;
	 }
}

I prefer a function to reserved a size wich replace in any reserve_ function the line
:

	gd->start_addr_sp -= ...
Quoted 7 lines

/* reserve size and make stack pointer 16-byte aligned */ static int

reserve(size_t size) {
	gd->start_addr_sp -= size;
	/* make stack pointer 16-byte aligned */
	gd->start_addr_sp = ALIGN_DOWN(gd->start_addr_sp, 16); }

I think I will push it, when the patrice patch will be accepted.

Quoted 7 lines

I am preparing this patch....

Do you think it is ok to merge the Patrice v3 proposal first on master branch for v2020.04 release (he just align the reserved memory for bootstage), and after I make my patch (16-byte align all reserved area).

or it is better to make a more generic patch v4 to replace the Patrice one.

Quoted 8 lines

I push a serie, with my proposal:
[3/3] board_f.c: Insure 16 alignment of start_addr_sp and reserved memory

http://patchwork.ozlabs.org/project/uboot/list/?series=152226

As I found issue for ARM32 (I need to modify arch/arm/lib/crt0.S)
I think it is preferable that the Patrice Patch is merged in v2020.04, and my serie can live independently. But I can also squash of the 2 series.

Sorry for the delay. Yes, please put together a single series that takes care of everything. Thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200121/12e6a0d7/attachment.sig>
#3 lore raw

PATCH v3 1/1 board_f.c: Insure gd->new_bootstage alignment

Hi Tom,

Quoted 127 lines

From: Tom Rini <[email protected]>
Sent: mercredi 22 janvier 2020 00:18

Quoted 39 lines · Patrick DELAUNAY

Hi,

Quoted 37 lines

From: Patrick DELAUNAY
Sent: mardi 7 janvier 2020 13:07

Hi Patrice and Tom

Quoted 32 lines

Sent: mercredi 18 décembre 2019 10:10

Hi Simon,

Quoted 7 lines

From: Simon Glass <[email protected]>
Sent: mardi 17 décembre 2019 16:46

Hi Patrice,

On Wed, 27 Nov 2019 at 02:11, Patrice Chotard
<[email protected]>

Quoted 11 lines · wrote:
Quoted 11 lines

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.

Quoted 7 lines
Quoted 7 lines
Fixes ac9cd4805c8b ("bootstage: Correct relocation

algorithm")

For information, Patrice is absent for personal reason up to beginning next

year.

Quoted 36 lines
Quoted 36 lines
Quoted 36 lines

Don't wait a fast answer.

Quoted 2 lines

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, 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 = bootstage_get_size();
	gd->start_addr_sp -= size
	=> it is a unaligned address even if gd->start_addr_sp is 32

bytes alligned

	gd->new_bootstage = map_sysmem(gd->start_addr_sp, size);
	=> also unaligned

3- Then during relocation, in reloc_bootstage()

	gd->bootstage = gd->new_bootstage;

4- crash occur because in next bootstage function beaucse the boostage address don't respect pointer to struct allignement...

	struct bootstage_data *data = gd->bootstage
Quoted 3 lines

At some point we should also document that reservations must keep things aligned.

Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
Quoted 3 lines

Perhaps this should be handled by a separate function called from all these places, which subtracts gd->start_addr_sp and ensures 16-byte

alignment.

Quoted 2 lines

Yes that can be a improvement, but perhaps ia a second step / second

serie....

Quoted 40 lines
Quoted 25 lines
Quoted 17 lines

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 -= 16;
		gd->start_addr_sp &= ~0xf;
	 }
}

I prefer a function to reserved a size wich replace in any reserve_ function the line
:

	gd->start_addr_sp -= ...
Quoted 7 lines

/* reserve size and make stack pointer 16-byte aligned */ static

int reserve(size_t size) {
	gd->start_addr_sp -= size;
	/* make stack pointer 16-byte aligned */
	gd->start_addr_sp = ALIGN_DOWN(gd->start_addr_sp, 16); }

I think I will push it, when the patrice patch will be accepted.

Quoted 8 lines

I am preparing this patch....

Do you think it is ok to merge the Patrice v3 proposal first on master branch for
v2020.04 release (he just align the reserved memory for bootstage), and after I make my patch (16-byte align all reserved area).

or it is better to make a more generic patch v4 to replace the Patrice one.

I push a serie, with my proposal:
[3/3] board_f.c: Insure 16 alignment of start_addr_sp and reserved memory

http://patchwork.ozlabs.org/project/uboot/list/?series=152226

Quoted 7 lines
Quoted 2 lines

As I found issue for ARM32 (I need to modify arch/arm/lib/crt0.S) I think it is preferable that the Patrice Patch is merged in v2020.04, and my serie

can live independently.

Quoted 1 line

But I can also squash of the 2 series.

Sorry for the delay. Yes, please put together a single series that takes care of everything. Thanks!

Done with serie = "Insure 16 alignment of reserved memory in board_f.c"

http://patchwork.ozlabs.org/project/uboot/list/?series=154685

I could merge the patches 1/4 and 4/4 if it is more clear.

Regards

Patrick