From: Stian Halseth <stian@itx.no>
To: "David S. Miller" <davem@davemloft.net>,
Andreas Larsson <andreas@gaisler.com>
Cc: sparclinux@vger.kernel.org, linux-kernel@vger.kernel.org,
Stian Halseth <stian@itx.no>
Subject: [PATCH] sparc64: Report the fault address when a user window cannot be saved
Date: Wed, 25 Nov 2026 10:44:46 +0100 [thread overview]
Message-ID: <20261125094446.537502-1-stian@itx.no> (raw)
When the kernel spills a user register window and the store faults,
the window is kept in the thread's window buffer. On the way back to
user space fault_in_user_windows() writes it to the stack. If that
write fails as well, it sends SIGSEGV with force_sig(). The handler
gets SI_KERNEL and si_addr == 0.
When a thread overflows its stack, the first store into the guard page
can be a window spill. If the kernel does that spill, for example
during a system call, the window goes through this path. Stack
overflow handlers compare si_addr with the guard page. With
si_addr == 0 they cannot tell that the stack overflowed. The Rust
runtime then resets the handler, and the process dies with SIGSEGV
instead of reporting the overflow. Rust's
tests/ui/runtime/out-of-stack.rs fails this way:
ferris[157185]: bad register window fault: SP fff800010f60bf90 (orig_sp fff800010f60b791) TPC fff800010f3a2db0 O7 00000100016039e4
Pass the address of the window to the signal, as stack_unaligned()
does for SIGBUS in the same file. Look up the VMA to choose the
si_code, as process_fpemu_return() does on MIPS. A spill into a
PROT_NONE guard page then reports SEGV_ACCERR, whether the hardware or
the kernel did the spill.
Closes: https://github.com/sparclinux/issues/issues/132
Signed-off-by: Stian Halseth <stian@itx.no>
---
Tested on a T4-1 (sun4v) and a V240 (sun4u) with 7.3.6. A thread
recurses and writes to a pipe at every level, so the kernel spills its
windows. Before, the handler got si_code 128 and si_addr 0. After, it
gets the window address and the same si_code as a spill by the
hardware: SEGV_ACCERR for a PROT_NONE guard, SEGV_MAPERR for an
unmapped hole. out-of-stack.rs passes 10/10 on the T4. A handler that
makes the guard writable and returns also works: the thread continues
and every frame unwinds with the right values.
arch/sparc/kernel/process_64.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
index e889da8..dedce75 100644
--- a/arch/sparc/kernel/process_64.c
+++ b/arch/sparc/kernel/process_64.c
@@ -518,6 +518,8 @@ void fault_in_user_windows(struct pt_regs *regs)
{
struct thread_info *t = current_thread_info();
unsigned long window;
+ unsigned long sp;
+ int si_code;
flush_user_windows();
window = get_thread_wsaved();
@@ -527,7 +529,7 @@ void fault_in_user_windows(struct pt_regs *regs)
do {
struct reg_window *rwin = &t->reg_window[window];
int winsize = sizeof(struct reg_window);
- unsigned long sp, orig_sp;
+ unsigned long orig_sp;
orig_sp = sp = t->rwbuf_stkptrs[window];
@@ -557,7 +559,13 @@ void fault_in_user_windows(struct pt_regs *regs)
barf:
set_thread_wsaved(window + 1);
- force_sig(SIGSEGV);
+ mmap_read_lock(current->mm);
+ if (vma_lookup(current->mm, sp))
+ si_code = SEGV_ACCERR;
+ else
+ si_code = SEGV_MAPERR;
+ mmap_read_unlock(current->mm);
+ force_sig_fault(SIGSEGV, si_code, (void __user *) sp);
}
/* Copy a Sparc thread. The fork() return value conventions
--
2.43.0
reply other threads:[~2026-11-25 9:45 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261125094446.537502-1-stian@itx.no \
--to=stian@itx.no \
--cc=andreas@gaisler.com \
--cc=davem@davemloft.net \
--cc=linux-kernel@vger.kernel.org \
--cc=sparclinux@vger.kernel.org \
/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®