* [PATCH] arm64/sme: Set new vector length before reallocating
@ 2023-07-26 12:12 Mark Brown
2023-07-26 17:37 ` Catalin Marinas
2023-07-26 18:45 ` Catalin Marinas
0 siblings, 2 replies; 3+ messages in thread
From: Mark Brown @ 2023-07-26 12:12 UTC (permalink / raw)
To: Catalin Marinas, Will Deacon; +Cc: linux-arm-kernel, linux-kernel, Mark Brown
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: d4d5be94a878 ("arm64/fpsimd: Ensure SME storage is allocated after SVE VL changes")
Signed-off-by: Mark Brown <broonie@kernel.org>
---
arch/arm64/kernel/fpsimd.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/arm64/kernel/fpsimd.c b/arch/arm64/kernel/fpsimd.c
index 89d54a5242d1..c19092642920 100644
--- a/arch/arm64/kernel/fpsimd.c
+++ b/arch/arm64/kernel/fpsimd.c
@@ -917,6 +917,8 @@ int vec_set_vector_length(struct task_struct *task, enum vec_type type,
if (task == current)
put_cpu_fpsimd_context();
+ task_set_vl(task, type, vl);
+
/*
* Free the changed states if they are not in use, SME will be
* reallocated to the correct size on next use and we just
@@ -931,8 +933,6 @@ int vec_set_vector_length(struct task_struct *task, enum vec_type type,
if (free_sme)
sme_free(task);
- task_set_vl(task, type, vl);
-
out:
update_tsk_thread_flag(task, vec_vl_inherit_flag(type),
flags & PR_SVE_VL_INHERIT);
---
base-commit: d4d5be94a87872421ea2569044092535aff0b886
change-id: 20230726-arm64-fix-sme-fix-d02461350e06
Best regards,
--
Mark Brown <broonie@kernel.org>
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] arm64/sme: Set new vector length before reallocating
2023-07-26 12:12 [PATCH] arm64/sme: Set new vector length before reallocating Mark Brown
@ 2023-07-26 17:37 ` Catalin Marinas
2023-07-26 18:45 ` Catalin Marinas
1 sibling, 0 replies; 3+ messages in thread
From: Catalin Marinas @ 2023-07-26 17:37 UTC (permalink / raw)
To: Mark Brown; +Cc: Will Deacon, linux-arm-kernel, linux-kernel
On Wed, Jul 26, 2023 at 01:12:26PM +0100, Mark Brown wrote:
> 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: d4d5be94a878 ("arm64/fpsimd: Ensure SME storage is allocated after SVE VL changes")
> Signed-off-by: Mark Brown <broonie@kernel.org>
I'll add a cc stable here since the above commit was fixing code that
went in for 5.19.
--
Catalin
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] arm64/sme: Set new vector length before reallocating
2023-07-26 12:12 [PATCH] arm64/sme: Set new vector length before reallocating Mark Brown
2023-07-26 17:37 ` Catalin Marinas
@ 2023-07-26 18:45 ` Catalin Marinas
1 sibling, 0 replies; 3+ messages in thread
From: Catalin Marinas @ 2023-07-26 18:45 UTC (permalink / raw)
To: Will Deacon, Mark Brown; +Cc: linux-arm-kernel, linux-kernel
On Wed, 26 Jul 2023 13:12:26 +0100, Mark Brown wrote:
> 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.
>
> [...]
Applied to arm64 (for-next/fixes), thanks!
[1/1] arm64/sme: Set new vector length before reallocating
https://git.kernel.org/arm64/c/05d881b85b48
--
Catalin
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-07-26 18:45 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-26 12:12 [PATCH] arm64/sme: Set new vector length before reallocating Mark Brown
2023-07-26 17:37 ` Catalin Marinas
2023-07-26 18:45 ` Catalin Marinas
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox