Skip to content

Commit 6ef1d77

Browse files
mrutland-armwilldeacon
authored andcommitted
arm64/fpsimd: Add task_smstop_sm()
In a few places we want to transition a task from streaming mode to non-streaming mode, e.g. signal delivery where we historically tried to use an SMSTOP SM instruction. Add a new helper to manipulate a task's state in the same way as an SMSTOP SM instruction. I have not added a corresponding helper to simulate the effects of SMSTART SM. Only ptrace transitions a task into streaming mode, and ptrace has distinct semantics for such transitions. Per ARM DDI 0487 L.a, section B1.4.6: | RRSWFQ | When the Effective value of PSTATE.SM is changed by any method from 0 | to 1, an entry to Streaming SVE mode is performed, and all implemented | bits of Streaming SVE register state are set to zero. | RKFRQZ | When the Effective value of PSTATE.SM is changed by any method from 1 | to 0, an exit from Streaming SVE mode is performed, and in the | newly-entered mode, all implemented bits of the SVE scalable vector | registers, SVE predicate registers, and FFR, are set to zero. Per ARM DDI 0487 L.a, section C5.2.9: | On entry to or exit from Streaming SVE mode, FPMR is set to 0 Per ARM DDI 0487 L.a, section C5.2.10: | On entry to or exit from Streaming SVE mode, FPSR.{IOC, DZC, OFC, UFC, | IXC, IDC, QC} are set to 1 and the remaining bits are set to 0. This means bits 0, 1, 2, 3, 4, 7, and 27 respectively, i.e. 0x0800009f Signed-off-by: Mark Rutland <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: Marc Zyngier <[email protected]> Cc: Mark Brown <[email protected]> Cc: Will Deacon <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent 8738288 commit 6ef1d77

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

arch/arm64/include/asm/fpsimd.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ static inline bool thread_za_enabled(struct thread_struct *thread)
111111
return system_supports_sme() && (thread->svcr & SVCR_ZA_MASK);
112112
}
113113

114+
extern void task_smstop_sm(struct task_struct *task);
115+
114116
/* Maximum VL that SVE/SME VL-agnostic software can transparently support */
115117
#define VL_ARCH_MAX 0x100
116118

arch/arm64/kernel/fpsimd.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,28 @@ static inline void sve_to_fpsimd(struct task_struct *task)
695695
}
696696
}
697697

698+
static inline void __fpsimd_zero_vregs(struct user_fpsimd_state *fpsimd)
699+
{
700+
memset(&fpsimd->vregs, 0, sizeof(fpsimd->vregs));
701+
}
702+
703+
/*
704+
* Simulate the effects of an SMSTOP SM instruction.
705+
*/
706+
void task_smstop_sm(struct task_struct *task)
707+
{
708+
if (!thread_sm_enabled(&task->thread))
709+
return;
710+
711+
__fpsimd_zero_vregs(&task->thread.uw.fpsimd_state);
712+
task->thread.uw.fpsimd_state.fpsr = 0x0800009f;
713+
if (system_supports_fpmr())
714+
task->thread.uw.fpmr = 0;
715+
716+
task->thread.svcr &= ~SVCR_SM_MASK;
717+
task->thread.fp_type = FP_STATE_FPSIMD;
718+
}
719+
698720
void cpu_enable_fpmr(const struct arm64_cpu_capabilities *__always_unused p)
699721
{
700722
write_sysreg_s(read_sysreg_s(SYS_SCTLR_EL1) | SCTLR_EL1_EnFPM_MASK,

0 commit comments

Comments
 (0)