From: Jens Axboe <axboe@kernel.dk>
To: io-uring@vger.kernel.org
Cc: linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, tglx@kernel.org, mingo@redhat.com,
peterz@infradead.org, Jens Axboe <axboe@kernel.dk>
Subject: [PATCH 03/15] arm64: implement thread identity handoff
Date: Fri, 11 Sep 2026 09:40:53 -0600 [thread overview]
Message-ID: <20260911154148.644489-4-axboe@kernel.dk> (raw)
In-Reply-To: <20260911154148.644489-1-axboe@kernel.dk>
Implement the arch_thread_handoff_*() hooks and select
ARCH_HAS_THREAD_HANDOFF.
The source is inside a syscall, so only the FPSIMD view of the vector
registers needs to move. Tasks with SME streaming mode or ZA enabled,
compat tasks, tasks with a guarded control stack and tasks trapping
counter-timer access are refused.
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
arch/arm64/Kconfig | 1 +
arch/arm64/kernel/process.c | 109 ++++++++++++++++++++++++++++++++++++
2 files changed, 110 insertions(+)
diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index b5a51b0ef944..a919570c80cd 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -46,6 +46,7 @@ config ARM64
select ARCH_HAS_PTE_SPECIAL
select ARCH_HAS_HW_PTE_YOUNG
select ARCH_HAS_SETUP_DMA_OPS
+ select ARCH_HAS_THREAD_HANDOFF
select ARCH_HAS_SET_DIRECT_MAP
select ARCH_HAS_SET_MEMORY
select ARCH_HAS_FORCE_DMA_UNENCRYPTED
diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c
index 581f80e9b9b7..e669a2717106 100644
--- a/arch/arm64/kernel/process.c
+++ b/arch/arm64/kernel/process.c
@@ -11,6 +11,7 @@
#include <linux/elf.h>
#include <linux/export.h>
#include <linux/sched.h>
+#include <linux/thread_handoff.h>
#include <linux/sched/debug.h>
#include <linux/sched/task.h>
#include <linux/sched/task_stack.h>
@@ -1003,3 +1004,111 @@ int set_tsc_mode(unsigned int val)
return do_set_tsc_mode(val);
}
+
+#ifdef CONFIG_THREAD_HANDOFF
+/*
+ * Thread identity handoff. The source is inside a syscall, so only the FPSIMD
+ * view of the vector registers needs to move. SME state is refused.
+ */
+static bool thread_handoff_task_ok(struct task_struct *tsk)
+{
+ if (is_compat_thread(task_thread_info(tsk)))
+ return false;
+ /* the GCS is per-thread and would have to move along */
+ if (task_gcs_el0_enabled(tsk))
+ return false;
+ /* counter-timer trapping doesn't move, see update_cntkctl_el1() */
+ if (test_tsk_thread_flag(tsk, TIF_TSC_SIGSEGV))
+ return false;
+ return true;
+}
+
+bool arch_thread_handoff_allowed(struct task_struct *tsk)
+{
+ return thread_handoff_task_ok(tsk);
+}
+
+bool arch_thread_handoff_compatible(struct task_struct *src,
+ struct task_struct *dst)
+{
+ return thread_handoff_task_ok(dst);
+}
+
+/* sync the live user state, fpsimd_syscall_enter() guarantees FPSIMD format */
+bool arch_thread_handoff_prepare(void)
+{
+ struct thread_struct *thread = ¤t->thread;
+
+ fpsimd_preserve_current_state();
+ tls_preserve_current_state();
+ if (system_supports_poe())
+ thread->por_el0 = read_sysreg_s(SYS_POR_EL0);
+
+ if (WARN_ON_ONCE(thread->fp_type != FP_STATE_FPSIMD))
+ return false;
+ /* ZA and streaming mode state doesn't move, for now */
+ if (thread_sm_enabled(thread) || thread_za_enabled(thread))
+ return false;
+ return true;
+}
+
+/* copy the user register state over, load what the return to user won't */
+int arch_thread_handoff_finish(struct task_struct *src, bool leader)
+{
+ struct task_struct *dst = current;
+ struct pt_regs *regs = task_pt_regs(dst);
+ struct frame_record_meta stackframe = regs->stackframe;
+
+ /* the syscall frame, this is what the return to userspace restores */
+ *regs = *task_pt_regs(src);
+ regs->stackframe = stackframe;
+
+ /*
+ * Marks our FP state foreign so nothing saves over what's copied in
+ * below, and frees the SVE/SME buffers, the vector lengths may differ.
+ */
+ fpsimd_flush_thread();
+
+ preempt_disable();
+
+ dst->thread.uw = src->thread.uw;
+ dst->thread.fp_type = FP_STATE_FPSIMD;
+ memcpy(dst->thread.vl, src->thread.vl, sizeof(dst->thread.vl));
+ memcpy(dst->thread.vl_onexec, src->thread.vl_onexec,
+ sizeof(dst->thread.vl_onexec));
+ dst->thread.svcr = src->thread.svcr;
+ dst->thread.tpidr2_el0 = src->thread.tpidr2_el0;
+ dst->thread.por_el0 = src->thread.por_el0;
+ dst->thread.sctlr_user = src->thread.sctlr_user;
+#ifdef CONFIG_ARM64_MTE
+ dst->thread.mte_ctrl = src->thread.mte_ctrl;
+#endif
+#ifdef CONFIG_ARM64_PTR_AUTH
+ dst->thread.keys_user = src->thread.keys_user;
+#endif
+ update_tsk_thread_flag(dst, TIF_SVE_VL_INHERIT,
+ test_tsk_thread_flag(src, TIF_SVE_VL_INHERIT));
+ update_tsk_thread_flag(dst, TIF_SME_VL_INHERIT,
+ test_tsk_thread_flag(src, TIF_SME_VL_INHERIT));
+ update_tsk_thread_flag(dst, TIF_TAGGED_ADDR,
+ test_tsk_thread_flag(src, TIF_TAGGED_ADDR));
+ update_tsk_thread_flag(dst, TIF_SSBD,
+ test_tsk_thread_flag(src, TIF_SSBD));
+ if (test_and_clear_tsk_thread_flag(src, TIF_MTE_ASYNC_FAULT))
+ set_tsk_thread_flag(dst, TIF_MTE_ASYNC_FAULT);
+
+ /* load what __switch_to() would have, FPSIMD gets restored on exit */
+ write_sysreg(dst->thread.uw.tp_value, tpidr_el0);
+ if (system_supports_tpidr2())
+ write_sysreg_s(dst->thread.tpidr2_el0, SYS_TPIDR2_EL0);
+ if (system_supports_poe())
+ write_sysreg_s(dst->thread.por_el0, SYS_POR_EL0);
+ contextidr_thread_switch(dst);
+ ptrauth_thread_switch_user(dst);
+ mte_thread_switch(dst);
+ update_sctlr_el1(dst->thread.sctlr_user);
+
+ preempt_enable();
+ return 0;
+}
+#endif
--
2.55.0
next prev parent reply other threads:[~2026-09-11 15:42 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-11 15:40 [RFC PATCH 00/15] io_uring: thread identity handoff for blocking inline issue Jens Axboe
2026-09-11 15:40 ` [PATCH 01/15] kernel: add thread identity handoff Jens Axboe
2026-09-11 15:40 ` [PATCH 02/15] sched: call into io_uring when a PF_IO_HANDOFF task blocks Jens Axboe
2026-09-11 15:40 ` Jens Axboe [this message]
2026-09-11 15:40 ` [PATCH 04/15] x86: implement thread identity handoff Jens Axboe
2026-09-11 15:40 ` [PATCH 05/15] io_uring/kbuf: use io_ring_submit_unlock() helper Jens Axboe
2026-09-11 15:40 ` [PATCH 06/15] io_uring: keep the tctx nodes on a list Jens Axboe
2026-09-11 15:40 ` [PATCH 07/15] io_uring: add uring_lock section depth tracking and blockable opdef flag Jens Axboe
2026-09-11 15:40 ` [PATCH 08/15] io_uring: split io_uring_enter() and io_submit_sqes() into helpers Jens Axboe
2026-09-11 15:40 ` [PATCH 09/15] io_uring: keep the submission plug on the io_submit_sqes() stack Jens Axboe
2026-09-11 15:41 ` [PATCH 10/15] io-wq: support handing a task identity to an idle worker Jens Axboe
2026-09-11 15:41 ` [PATCH 11/15] io_uring: enable handing submitter identity to an io-wq worker Jens Axboe
2026-09-11 15:41 ` [PATCH 12/15] io_uring: defer the identity migration to the end of the submission Jens Axboe
2026-09-11 15:41 ` [PATCH 13/15] io_uring: issue blockable requests inline in blocking mode Jens Axboe
2026-09-11 15:41 ` [PATCH 14/15] io_uring: add tracepoints for the handoff operation Jens Axboe
2026-09-11 15:41 ` [PATCH 15/15] io_uring: issue IOSQE_ASYNC requests inline when a handoff is possible Jens Axboe
2026-09-11 17:33 ` [RFC PATCH 00/15] io_uring: thread identity handoff for blocking inline issue Gabriel Krisman Bertazi
2026-09-11 17:51 ` Jens Axboe
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=20260911154148.644489-4-axboe@kernel.dk \
--to=axboe@kernel.dk \
--cc=io-uring@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=tglx@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.