Commit d4d5be94 authored by Mark Brown's avatar Mark Brown Committed by Will Deacon

arm64/fpsimd: Ensure SME storage is allocated after SVE VL changes

When we reconfigure the SVE vector length we discard the backing storage
for the SVE vectors and then reallocate on next SVE use, leaving the SME
specific state alone. This means that we do not enable SME traps if they
were already disabled. That means that userspace code can enter streaming
mode without trapping, putting the task in a state where if we try to save
the state of the task we will fault.

Since the ABI does not specify that changing the SVE vector length disturbs
SME state, and since SVE code may not be aware of SME code in the process,
we shouldn't simply discard any ZA state. Instead immediately reallocate
the storage for SVE, and disable SME if we change the SVE vector length
while there is no SME state active.

Disabling SME traps on SVE vector length changes would make the overall
code more complex since we would have a state where we have valid SME state
stored but might get a SME trap.

Fixes: 9e4ab6c8 ("arm64/sme: Implement vector length configuration prctl()s")
Reported-by: default avatarDavid Spickett <David.Spickett@arm.com>
Signed-off-by: default avatarMark Brown <broonie@kernel.org>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/20230720-arm64-fix-sve-sme-vl-change-v2-1-8eea06b82d57@kernel.orgSigned-off-by: default avatarWill Deacon <will@kernel.org>
parent 71e06e1a
...@@ -847,6 +847,8 @@ void sve_sync_from_fpsimd_zeropad(struct task_struct *task) ...@@ -847,6 +847,8 @@ void sve_sync_from_fpsimd_zeropad(struct task_struct *task)
int vec_set_vector_length(struct task_struct *task, enum vec_type type, int vec_set_vector_length(struct task_struct *task, enum vec_type type,
unsigned long vl, unsigned long flags) unsigned long vl, unsigned long flags)
{ {
bool free_sme = false;
if (flags & ~(unsigned long)(PR_SVE_VL_INHERIT | if (flags & ~(unsigned long)(PR_SVE_VL_INHERIT |
PR_SVE_SET_VL_ONEXEC)) PR_SVE_SET_VL_ONEXEC))
return -EINVAL; return -EINVAL;
...@@ -897,21 +899,36 @@ int vec_set_vector_length(struct task_struct *task, enum vec_type type, ...@@ -897,21 +899,36 @@ int vec_set_vector_length(struct task_struct *task, enum vec_type type,
task->thread.fp_type = FP_STATE_FPSIMD; task->thread.fp_type = FP_STATE_FPSIMD;
} }
if (system_supports_sme() && type == ARM64_VEC_SME) { if (system_supports_sme()) {
if (type == ARM64_VEC_SME ||
!(task->thread.svcr & (SVCR_SM_MASK | SVCR_ZA_MASK))) {
/*
* We are changing the SME VL or weren't using
* SME anyway, discard the state and force a
* reallocation.
*/
task->thread.svcr &= ~(SVCR_SM_MASK | task->thread.svcr &= ~(SVCR_SM_MASK |
SVCR_ZA_MASK); SVCR_ZA_MASK);
clear_thread_flag(TIF_SME); clear_thread_flag(TIF_SME);
free_sme = true;
}
} }
if (task == current) if (task == current)
put_cpu_fpsimd_context(); put_cpu_fpsimd_context();
/* /*
* Force reallocation of task SVE and SME state to the correct * Free the changed states if they are not in use, SME will be
* size on next use: * reallocated to the correct size on next use and we just
* allocate SVE now in case it is needed for use in streaming
* mode.
*/ */
if (system_supports_sve()) {
sve_free(task); sve_free(task);
if (system_supports_sme() && type == ARM64_VEC_SME) sve_alloc(task, true);
}
if (free_sme)
sme_free(task); sme_free(task);
task_set_vl(task, type, vl); task_set_vl(task, type, vl);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment