[PATCH RFC POC 16/50] sparc: commit fds on syscall exit

From: Christian Brauner

Date: Tue Sep 15 2026 - 07:49:06 EST


Add TIF_FD_SLOTS and test it together with the other syscall exit
work on the way out of a system call. A task that reserved
descriptors calls syscall_trace() on sparc32 and syscall_trace_leave()
on sparc64.

Signed-off-by: Christian Brauner (Amutable) <brauner@xxxxxxxxxx>
---
arch/sparc/include/asm/thread_info_32.h | 2 ++
arch/sparc/include/asm/thread_info_64.h | 9 ++++++++-
arch/sparc/kernel/entry.S | 2 +-
arch/sparc/kernel/ptrace_32.c | 4 ++++
arch/sparc/kernel/ptrace_64.c | 4 ++++
arch/sparc/kernel/syscalls.S | 4 +++-
6 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
index fdaf7b171e0a..fbd7af6bb427 100644
--- a/arch/sparc/include/asm/thread_info_32.h
+++ b/arch/sparc/include/asm/thread_info_32.h
@@ -105,6 +105,7 @@ register struct thread_info *current_thread_info_reg asm("g6");
#define TIF_NEED_RESCHED 3 /* rescheduling necessary */
#define TIF_RESTORE_SIGMASK 4 /* restore signal mask in do_signal() */
#define TIF_NOTIFY_SIGNAL 5 /* signal notifications exist */
+#define TIF_FD_SLOTS 6 /* syscall prepared descriptors */
#define TIF_USEDFPU 8 /* FPU was used by this task
* this quantum (SMP) */
#define TIF_POLLING_NRFLAG 9 /* true if poll_idle() is polling
@@ -117,6 +118,7 @@ register struct thread_info *current_thread_info_reg asm("g6");
#define _TIF_SIGPENDING (1<<TIF_SIGPENDING)
#define _TIF_NEED_RESCHED (1<<TIF_NEED_RESCHED)
#define _TIF_NOTIFY_SIGNAL (1<<TIF_NOTIFY_SIGNAL)
+#define _TIF_FD_SLOTS (1<<TIF_FD_SLOTS)
#define _TIF_USEDFPU (1<<TIF_USEDFPU)
#define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)

diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
index c8a73dff27f8..890ee65d9029 100644
--- a/arch/sparc/include/asm/thread_info_64.h
+++ b/arch/sparc/include/asm/thread_info_64.h
@@ -180,7 +180,7 @@ extern struct thread_info *current_thread_info(void);
#define TIF_SIGPENDING 2 /* signal pending */
#define TIF_NEED_RESCHED 3 /* rescheduling necessary */
#define TIF_NOTIFY_SIGNAL 4 /* signal notifications exist */
-#define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
+#define TIF_FD_SLOTS 5 /* syscall prepared descriptors */
#define TIF_UPROBE 6 /* breakpointed or singlestepped */
#define TIF_32BIT 7 /* 32-bit binary */
#define TIF_NOHZ 8 /* in adaptive nohz mode */
@@ -194,12 +194,14 @@ extern struct thread_info *current_thread_info(void);
#define TIF_MCDPER 12 /* Precise MCD exception */
#define TIF_MEMDIE 13 /* is terminating due to OOM killer */
#define TIF_POLLING_NRFLAG 14
+#define TIF_UNALIGNED 15 /* allowed to do unaligned accesses */

#define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
#define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)
#define _TIF_SIGPENDING (1<<TIF_SIGPENDING)
#define _TIF_NEED_RESCHED (1<<TIF_NEED_RESCHED)
#define _TIF_NOTIFY_SIGNAL (1<<TIF_NOTIFY_SIGNAL)
+#define _TIF_FD_SLOTS (1<<TIF_FD_SLOTS)
#define _TIF_UNALIGNED (1<<TIF_UNALIGNED)
#define _TIF_UPROBE (1<<TIF_UPROBE)
#define _TIF_32BIT (1<<TIF_32BIT)
@@ -209,6 +211,11 @@ extern struct thread_info *current_thread_info(void);
#define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
#define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)

+/* work to do in syscall_trace_leave() */
+#define _TIF_SYSCALL_EXIT_WORK (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | \
+ _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | \
+ _TIF_NOHZ | _TIF_FD_SLOTS)
+
#define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
_TIF_DO_NOTIFY_RESUME_MASK | \
_TIF_NEED_RESCHED)
diff --git a/arch/sparc/kernel/entry.S b/arch/sparc/kernel/entry.S
index ea51ef52c952..d2023b84db9e 100644
--- a/arch/sparc/kernel/entry.S
+++ b/arch/sparc/kernel/entry.S
@@ -1023,7 +1023,7 @@ ret_sys_call:
ld [%sp + STACKFRAME_SZ + PT_PSR], %g3
set PSR_C, %g2
bgeu 1f
- andcc %l5, _TIF_SYSCALL_TRACE, %g0
+ andcc %l5, (_TIF_SYSCALL_TRACE | _TIF_FD_SLOTS), %g0

/* System call success, clear Carry condition code. */
andn %g3, %g2, %g3
diff --git a/arch/sparc/kernel/ptrace_32.c b/arch/sparc/kernel/ptrace_32.c
index 5991b1731fee..042e60685418 100644
--- a/arch/sparc/kernel/ptrace_32.c
+++ b/arch/sparc/kernel/ptrace_32.c
@@ -11,6 +11,7 @@
*/

#include <linux/kernel.h>
+#include <linux/file.h>
#include <linux/sched.h>
#include <linux/mm.h>
#include <linux/errno.h>
@@ -437,6 +438,9 @@ asmlinkage int syscall_trace(struct pt_regs *regs, int syscall_exit_p)
{
int ret = 0;

+ if (syscall_exit_p && test_thread_flag(TIF_FD_SLOTS))
+ fd_slots_commit(regs);
+
if (test_thread_flag(TIF_SYSCALL_TRACE)) {
if (syscall_exit_p)
ptrace_report_syscall_exit(regs, 0);
diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
index 825ddf55fece..499b30c505fd 100644
--- a/arch/sparc/kernel/ptrace_64.c
+++ b/arch/sparc/kernel/ptrace_64.c
@@ -12,6 +12,7 @@
*/

#include <linux/kernel.h>
+#include <linux/file.h>
#include <linux/sched.h>
#include <linux/sched/task_stack.h>
#include <linux/mm.h>
@@ -1110,6 +1111,9 @@ asmlinkage void syscall_trace_leave(struct pt_regs *regs)
if (test_thread_flag(TIF_NOHZ))
user_exit();

+ if (test_thread_flag(TIF_FD_SLOTS))
+ fd_slots_commit(regs);
+
audit_syscall_exit(regs);

if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
index 96fe8763d70c..086fb8eaf133 100644
--- a/arch/sparc/kernel/syscalls.S
+++ b/arch/sparc/kernel/syscalls.S
@@ -269,10 +269,12 @@ ret_sys_call:
ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %g3
mov %ulo(TSTATE_XCARRY | TSTATE_ICARRY), %g2
sllx %g2, 32, %g2
+ /* Reload the flags, the syscall may have set TIF_FD_SLOTS. */
+ ldx [%g6 + TI_FLAGS], %l0

cmp %o0, -ERESTART_RESTARTBLOCK
bgeu,pn %xcc, 1f
- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
+ andcc %l0, _TIF_SYSCALL_EXIT_WORK, %g0
ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc

2:

--
2.53.0