mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Artur Rojek <contact@artur-rojek.eu>
To: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Cc: Yoshinori Sato <ysato@users.sourceforge.jp>,
	Rich Felker <dalias@libc.org>,
	Daniel Lezcano <daniel.lezcano@linaro.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Uros Bizjak <ubizjak@gmail.com>,
	Geert Uytterhoeven <geert+renesas@glider.be>,
	"D . Jeff Dionne" <jeff@coresemi.io>,
	Rob Landley <rob@landley.net>,
	linux-sh@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] sh: align .bss section padding to 8-byte boundary
Date: Wed, 12 Mar 2025 00:40:40 +0100	[thread overview]
Message-ID: <433bc8a0732bf8a63c64c4bf0e6ad4a7@artur-rojek.eu> (raw)
In-Reply-To: <5365422a9715376c76a89e255c978fc39064e243.camel@physik.fu-berlin.de>

On 2025-03-11 18:28, John Paul Adrian Glaubitz wrote:
> Hi Artur,

Hey Adrian,
thanks for looking into this patch.

> 
> I'm currently trying to review this patch, but I'm not 100% sure how it
> this change helps grows the .bss section, see below. Maybe you can help
> me understand what's happening.
> 
> On Sun, 2025-02-16 at 18:55 +0100, Artur Rojek wrote:
>> J2 based devices expect to find a devicetree blob at the end of the 
>> bss
>> section. As of a77725a9a3c5, libfdt enforces 8-byte alignment for the
>> dtb, causing J2 devices to fail early in sh_fdt_init.
>> 
>> As J2 loader firmware calculates the dtb location based on the kernel
>> image .bss section size, rather than the __bss_stop symbol offset, the
>> required alignment can't be enforced with BSS_SECTION(0, PAGE_SIZE, 
>> 8).
>> Instead, inline modified version of the above macro, which grows .bss
>> by the required size.
>> 
>> While this change affects all existing SH boards, it should be benign 
>> on
>> platforms which don't need this alignment.
>> 
>> Signed-off-by: Artur Rojek <contact@artur-rojek.eu>
>> ---
>>  arch/sh/kernel/vmlinux.lds.S | 15 ++++++++++++++-
>>  1 file changed, 14 insertions(+), 1 deletion(-)
>> 
>> diff --git a/arch/sh/kernel/vmlinux.lds.S 
>> b/arch/sh/kernel/vmlinux.lds.S
>> index 9644fe187a3f..008c30289eaa 100644
>> --- a/arch/sh/kernel/vmlinux.lds.S
>> +++ b/arch/sh/kernel/vmlinux.lds.S
>> @@ -71,7 +71,20 @@ SECTIONS
>> 
>>  	. = ALIGN(PAGE_SIZE);
>>  	__init_end = .;
>> -	BSS_SECTION(0, PAGE_SIZE, 4)
>> +	__bss_start = .;
>> +	SBSS(0)
>> +	. = ALIGN(PAGE_SIZE);
> 
> What this effectively does is removing ". = ALIGN(sbss_align);" first 
> from BSS_SECTION().
> 
> Then it inserts ". = ALIGN(PAGE_SIZE);" after the "SBSS(0)".
> 
> If I understand this correctly, SBSS() inserts a zero-padding and if 
> I'm not mistaken,
> inserting ". = ALIGN(PAGE_SIZE);" will cause this padding to grow to at 
> least PAGE_SIZE
> due the alignment.
> 
> Is this correct?
> 
>> +	.bss : AT(ADDR(.bss) - LOAD_OFFSET) {
>> +		BSS_FIRST_SECTIONS
>> +		. = ALIGN(PAGE_SIZE);
>> +		*(.bss..page_aligned)
>> +		. = ALIGN(PAGE_SIZE);
>> +		*(.dynbss)
>> +		*(BSS_MAIN)
>> +		*(COMMON)
>> +		. = ALIGN(8);
> 
> If my understanding above is correct, why do we will need an additional 
> ". = ALIGN(8)"
> here?

I'll tackle both of the above questions at once.
I'm by no means an expert at GNU Linker syntax, but the intention of
this patch is to put . = ALIGN(8) inside the .bss : { ... } section
definition, so that the section itself grows by the requested padding.

In the original BSS_SECTION(0, PAGE_SIZE, 4), the last argument inserts
a 4 byte padding after the closing brace of .bss section definition,
causing the __bss_stop symbol offset to grow, but not the .bss section
itself:

#define BSS_SECTION(sbss_align, bss_align, stop_align)			\
	. = ALIGN(sbss_align);						\
	__bss_start = .;						\
	SBSS(sbss_align)						\
	BSS(bss_align)							\
	. = ALIGN(stop_align);						\
	__bss_stop = .;

TurtleBoard loader is only concerned with the .bss section size - it
doesn't care about any symbol offsets - and hence this seemingly cryptic
change (you can display the section size information with
readelf -t kernel_image).
The rest of the changes are simply to "inline" the BSS() macro (as I
needed to access that closing brace), and the former sbss_align,
bss_align (that's your PAGE_SIZE) and stop_align arguments are passed
accordingly, the same way they used to be passed before. The only
visible effect should be the move of ALIGN(stop_align) inside of .bss
section definition, and the change of stop_align value from 4 to 8.

Arguably the TurtleBoard loader should read the __bss_stop symbol offset
instead, but in this patch I'm trying to solve the issue from kernel's
point of view.

Cheers,
Artur

> 
>> +	}
>> +	__bss_stop = .;
>>  	_end = . ;
>> 
>>  	STABS_DEBUG
> 
> Thanks,
> Adrian

  reply	other threads:[~2025-03-11 23:40 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-16 17:55 [PATCH 0/2] J2 Turtle Board fixes Artur Rojek
2025-02-16 17:55 ` [PATCH 1/2] sh: align .bss section padding to 8-byte boundary Artur Rojek
2025-02-18 12:41   ` Rob Landley
2025-03-11 17:28   ` John Paul Adrian Glaubitz
2025-03-11 23:40     ` Artur Rojek [this message]
2025-03-12  8:06       ` Geert Uytterhoeven
2025-03-13 10:36         ` John Paul Adrian Glaubitz
2025-03-12  8:21       ` John Paul Adrian Glaubitz
2025-03-12  8:32         ` Uros Bizjak
2025-03-12  8:44           ` John Paul Adrian Glaubitz
2025-03-12  9:47           ` Geert Uytterhoeven
2025-03-12  9:55             ` Uros Bizjak
2025-03-13  9:38             ` David Laight
2025-04-05 17:38   ` John Paul Adrian Glaubitz
2025-02-16 17:55 ` [PATCH 2/2] irqchip: clocksource: fix jcore-pit irq request Artur Rojek
2025-02-17  7:14   ` Uros Bizjak
2025-02-17 22:35   ` [tip: irq/urgent] irqchip/jcore-aic, clocksource/drivers/jcore: Fix jcore-pit interrupt request tip-bot2 for Artur Rojek
2025-02-18 12:43   ` [PATCH 2/2] irqchip: clocksource: fix jcore-pit irq request Rob Landley
2025-02-19 14:43   ` Daniel Lezcano
2025-02-19 14:50     ` Geert Uytterhoeven
2025-02-19 14:52       ` Daniel Lezcano
2025-02-27  7:52 ` [PATCH 0/2] J2 Turtle Board fixes John Paul Adrian Glaubitz
2025-02-28  3:03   ` Rob Landley
2025-02-28  8:34     ` John Paul Adrian Glaubitz
2025-02-28 22:19       ` Rob Landley
2025-02-28 22:34         ` John Paul Adrian Glaubitz
2025-03-01  3:20           ` Rob Landley
2025-04-08 15:23         ` John Paul Adrian Glaubitz
2025-04-11 11:25           ` Rob Landley
2025-06-09 10:01             ` John Paul Adrian Glaubitz
2025-06-10 20:22               ` Rob Landley

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=433bc8a0732bf8a63c64c4bf0e6ad4a7@artur-rojek.eu \
    --to=contact@artur-rojek.eu \
    --cc=dalias@libc.org \
    --cc=daniel.lezcano@linaro.org \
    --cc=geert+renesas@glider.be \
    --cc=glaubitz@physik.fu-berlin.de \
    --cc=jeff@coresemi.io \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sh@vger.kernel.org \
    --cc=rob@landley.net \
    --cc=tglx@linutronix.de \
    --cc=ubizjak@gmail.com \
    --cc=ysato@users.sourceforge.jp \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®