From: Michal Simek <michal.simek@amd.com>
To: Neal Frager <neal.frager@amd.com>, linux-kernel@vger.kernel.org
Cc: gopi@sankhya.com
Subject: Re: [PATCH v2 1/1] microblaze: allocate stack space for register params
Date: Tue, 1 Sep 2026 15:50:35 +0200 [thread overview]
Message-ID: <b856b54a-b9ca-45d8-a4c0-dde33d0ffdff@amd.com> (raw)
In-Reply-To: <20260421122154.2659404-1-neal.frager@amd.com>
On 4/21/26 14:21, Neal Frager wrote:
> C functions are invoked with arguments without allocating stack space for
> register params (for potential register spills). As a result kernel built
> with gcc v15 boot hangs at the point of starting init.
>
> Add necessary stack space for few C function calls from entry.S
> (not all). With this change, the kernel boots all the way to login prompt
> and root login works. Simple commands like ps work and show normal
> output.
>
> Fixes: ca54502bd52a ("microblaze_mmu_v2: entry.S, entry.h")
>
> From: Gopi Kumar Bulusu <gopi@sankhya.com>
> Co-developed-by: Neal Frager <neal.frager@amd.com>
> Signed-off-by: Neal Frager <neal.frager@amd.com>
> ---
> V1->V2:
> - removed whitespaces
> - changed ret_from_trap2 to ret_from_trap_noadj
> - added comment for SYSCALL_ARGS_SIZE
> - cleaned up language in commit message
> ---
> arch/microblaze/kernel/entry.S | 21 +++++++++++++++------
> 1 file changed, 15 insertions(+), 6 deletions(-)
>
> diff --git a/arch/microblaze/kernel/entry.S b/arch/microblaze/kernel/entry.S
> index 582d7256d815..30d42b84f156 100644
> --- a/arch/microblaze/kernel/entry.S
> +++ b/arch/microblaze/kernel/entry.S
> @@ -339,6 +339,10 @@ C_ENTRY(mb_invalidate_icache):
> * Trap entered via brki instruction, so BIP bit is set, and interrupts
> * are masked. This is nice, means we don't have to CLI before state save
> */
> +
> +/* Syscall args in r5-r10 and the link register or 28 bytes */
> +#define SYSCALL_ARGS_SIZE 28
> +
> C_ENTRY(_user_exception):
> swi r1, r0, TOPHYS(PER_CPU(ENTRY_SP)) /* save stack */
> addi r14, r14, 4 /* return address is 4 byte after call */
> @@ -422,16 +426,19 @@ C_ENTRY(_user_exception):
> lwi r12, r12, sys_call_table
> /* where the trap should return need -8 to adjust for rtsd r15, 8 */
> addi r15, r0, ret_from_trap-8
> + addik r1, r1, -SYSCALL_ARGS_SIZE
> bra r12
>
> /* The syscall number is invalid, return an error. */
> 5:
> - braid ret_from_trap
> + braid ret_from_trap_noadj
> addi r3, r0, -ENOSYS;
>
> /* Entry point used to return from a syscall/trap */
> /* We re-enable BIP bit before state restore */
> C_ENTRY(ret_from_trap):
> + addik r1, r1, SYSCALL_ARGS_SIZE
> +C_ENTRY(ret_from_trap_noadj):
> swi r3, r1, PT_R3
> swi r4, r1, PT_R4
>
> @@ -504,7 +511,7 @@ C_ENTRY(ret_from_fork):
> bralid r15, schedule_tail; /* ...which is schedule_tail's arg */
> add r5, r3, r0; /* switch_thread returns the prev task */
> /* ( in the delay slot ) */
> - brid ret_from_trap; /* Do normal trap return */
> + brid ret_from_trap_noadj; /* Do normal trap return */
> add r3, r0, r0; /* Child's fork call should return 0. */
>
> C_ENTRY(ret_from_kernel_thread):
> @@ -513,13 +520,13 @@ C_ENTRY(ret_from_kernel_thread):
> /* ( in the delay slot ) */
> brald r15, r20 /* fn was left in r20 */
> addk r5, r0, r19 /* ... and argument - in r19 */
> - brid ret_from_trap
> + brid ret_from_trap_noadj
> add r3, r0, r0
>
> C_ENTRY(sys_rt_sigreturn_wrapper):
> addik r30, r0, 0 /* no restarts */
> brid sys_rt_sigreturn /* Do real work */
> - addik r5, r1, 0; /* add user context as 1st arg */
> + addik r5, r1, SYSCALL_ARGS_SIZE; /* add user context as 1st arg */
>
> /*
> * HW EXCEPTION rutine start
> @@ -729,11 +736,13 @@ C_ENTRY(_interrupt):
> lwi CURRENT_TASK, r0, TOPHYS(PER_CPU(CURRENT_SAVE));
> tovirt(r1,r1)
> addik r15, r0, irq_call;
> + addik r1, r1, -SYSCALL_ARGS_SIZE
> irq_call:rtbd r0, do_IRQ;
> - addik r5, r1, 0;
> + addik r5, r1, SYSCALL_ARGS_SIZE;
>
> /* MS: we are in virtual mode */
> ret_from_irq:
> + addik r1, r1, SYSCALL_ARGS_SIZE
> lwi r11, r1, PT_MODE;
> bnei r11, 2f;
>
> @@ -1302,7 +1311,7 @@ type_SYSCALL_PREEMPT:
> .global microblaze_trap_handlers
> microblaze_trap_handlers:
> /* Exact matches come first */
> - .word ret_from_trap; .word ret_from_trap ; .word type_SYSCALL
> + .word ret_from_trap; .word ret_from_trap_noadj ; .word type_SYSCALL
> .word ret_from_irq ; .word ret_from_irq ; .word type_IRQ
> /* Fuzzy matches go here */
> .word ret_from_irq ; .word no_intr_resched ; .word type_IRQ_PREEMPT
For a record this patch has be replaced by
https://lore.kernel.org/all/20260821151809.1233057-1-ramin.moussavi@yacoub.de/
Thanks,
Michal
prev parent reply other threads:[~2026-09-01 13:50 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-21 12:21 Neal Frager
2026-09-01 13:50 ` Michal Simek [this message]
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=b856b54a-b9ca-45d8-a4c0-dde33d0ffdff@amd.com \
--to=michal.simek@amd.com \
--cc=gopi@sankhya.com \
--cc=linux-kernel@vger.kernel.org \
--cc=neal.frager@amd.com \
/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®