Skip to content

Commit 356e711

Browse files
brooniegregkh
authored andcommitted
arm64/sme: Set new vector length before reallocating
commit 05d881b upstream. As part of fixing the allocation of the buffer for SVE state when changing SME vector length we introduced an immediate reallocation of the SVE state, this is also done when changing the SVE vector length for consistency. Unfortunately this reallocation is done prior to writing the new vector length to the task struct, meaning the allocation is done with the old vector length and can lead to memory corruption due to an undersized buffer being used. Move the update of the vector length before the allocation to ensure that the new vector length is taken into account. For some reason this isn't triggering any problems when running tests on the arm64 fixes branch (even after repeated tries) but is triggering issues very often after merge into mainline. Fixes: d4d5be9 ("arm64/fpsimd: Ensure SME storage is allocated after SVE VL changes") Signed-off-by: Mark Brown <[email protected]> Cc: <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Catalin Marinas <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent ff54cb9 commit 356e711

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

arch/arm64/kernel/fpsimd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,8 @@ int vec_set_vector_length(struct task_struct *task, enum vec_type type,
871871
if (task == current)
872872
put_cpu_fpsimd_context();
873873

874+
task_set_vl(task, type, vl);
875+
874876
/*
875877
* Free the changed states if they are not in use, SME will be
876878
* reallocated to the correct size on next use and we just
@@ -885,8 +887,6 @@ int vec_set_vector_length(struct task_struct *task, enum vec_type type,
885887
if (free_sme)
886888
sme_free(task);
887889

888-
task_set_vl(task, type, vl);
889-
890890
out:
891891
update_tsk_thread_flag(task, vec_vl_inherit_flag(type),
892892
flags & PR_SVE_VL_INHERIT);

0 commit comments

Comments
 (0)