arm64/sve: Fix wrong free for task->thread.sve_state
PATCH v2 1/1 arm64/sve: Fix wrong free for task->thread.sve_state
From: Masayoshi Mizuma <[email protected]>
The system which has SVE feature crashed because of the memory pointed by task->thread.sve_state was destroyed by someone.
That is because sve_state is freed while the forking the child process. The child process has the pointer of sve_state which is same as the parent's because the child's task_struct is copied from the parent's one. If the copy_process() fails as an error on somewhere, for example, copy_creds(), then the sve_state is freed even if the parent is alive. The flow is as follows.
copy_process
p = dup_task_struct
=> arch_dup_task_struct
*dst = *src; // copy the entire region.
:
retval = copy_creds
if (retval < 0)
goto bad_fork_free;
:
bad_fork_free:
...
delayed_free_task(p);
=> free_task
=> arch_release_task_struct
=> fpsimd_release_task
=> __sve_free
=> kfree(task->thread.sve_state);
// free the parent's sve_stateMove child's sve_state = NULL and clearing TIF_SVE flag to arch_dup_task_struct() so that the child doesn't free the parent's one.
--- arch/arm64/kernel/process.c | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-)
arch/arm64/kernel/process.c +4 -17
@@ -323,22 +323,16 @@ void arch_release_task_struct(struct task_struct *tsk)fpsimd_release_task (tsk); } -/* -* src and dst may temporarily have aliased sve_state after task_struct -* is copied. We cannot fix this properly here, because src may have -* live SVE state and dst's thread_info may not exist yet, so tweaking -* either src's or dst's TIF_SVE is not safe. -* -* The unaliasing is done in copy_thread() instead. This works because -* dst is not schedulable or traceable until both of these functions -* have been called. -*/ int arch_dup_task_struct (struct task_struct *dst,struct task_struct *src) {if (current->mm)fpsimd_preserve_current_state (); *dst = *src; +BUILD_BUG_ON (!IS_ENABLED (CONFIG_THREAD_INFO_IN_TASK )); + dst->thread.sve_state =NULL ; +clear_tsk_thread_flag (dst,TIF_SVE ); +return 0 ; }
@@ -351,13 +345,6 @@ int copy_thread(unsigned long clone_flags, unsigned long stack_start,memset (&p->thread.cpu_context,0 ,sizeof (struct cpu_context )); -/* -* Unalias p->thread.sve_state (if any) from the parent task -* and disable discard SVE state for p: -*/ -clear_tsk_thread_flag (p,TIF_SVE ); - p->thread.sve_state =NULL ; -/* * In case p was allocated the same task_struct pointer as some * other recently-exited task, make sure p is disassociated from
Signature · 1 line
2.18.1
Quoted 33 lines · Masayoshi Mizuma
From: Masayoshi Mizuma <[email protected]>
The system which has SVE feature crashed because of the memory pointed by
task->thread.sve_statewas destroyed by someone.That is because
sve_stateis freed while the forking the child process. The child process has the pointer ofsve_statewhich is same as the parent's because the child'stask_structis copied from the parent's one. If thecopy_process()fails as an error on somewhere, for example,copy_creds(), then thesve_stateis freed even if the parent is alive. The flow is as follows.
copy_process
p =dup_task_struct
=>arch_dup_task_struct
*dst = *src; // copy the entire region.
:retval = copy_creds if (retval < 0) goto bad_fork_free; : bad_fork_free: ... delayed_free_task(p); => free_task => arch_release_task_struct => fpsimd_release_task => __sve_free => kfree(task->thread.sve_state); // free the parent's sve_state
Quoted 3 lines
Move child's
sve_state= NULL and clearingTIF_SVEflag toarch_dup_task_struct()so that the child doesn't free the parent's one.
You could also add:
--8<--
There is no need to wait until copy_process() to clear TIF_SVE for dst, becuase the thread flags for dst are initialized already by copying the src task_struct.
This change simplifies the code, so get rid of comments that are no longer needed.
-->8--
Quoted 2 lines
Since SVE only exists from v4.15, it may be helpful to specify that, i.e., replace that Cc line with:
Otherwise, I'm happy to see this applied, but I'd like somebody to confirm that this change definitely fixes the bug.
Cheers
---Dave
[...]
Quoted 61 lines
Fixes bc0ee4760364 ("arm64/sve: Core task context handling")Signed-off-by Masayoshi Mizuma <[email protected]>Reported-by Hidetoshi Seto <[email protected]>Suggested-by Dave Martin <[email protected]>--- arch/arm64/kernel/process.c | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-)arch/arm64/kernel/process.c +4
-17@@ -323,22 +323,16 @@ void arch_release_task_struct(struct task_struct *tsk)fpsimd_release_task (tsk); } -/* -* src and dst may temporarily have aliased sve_state after task_struct -* is copied. We cannot fix this properly here, because src may have -* live SVE state and dst's thread_info may not exist yet, so tweaking -* either src's or dst's TIF_SVE is not safe. -* -* The unaliasing is done in copy_thread() instead. This works because -* dst is not schedulable or traceable until both of these functions -* have been called. -*/ int arch_dup_task_struct (struct task_struct *dst,struct task_struct *src) {if (current->mm)fpsimd_preserve_current_state (); *dst = *src; +BUILD_BUG_ON (!IS_ENABLED (CONFIG_THREAD_INFO_IN_TASK )); + dst->thread.sve_state =NULL ; +clear_tsk_thread_flag (dst,TIF_SVE ); +return 0 ; }@@ -351,13 +345,6 @@ int copy_thread(unsigned long clone_flags, unsigned long stack_start,memset (&p->thread.cpu_context,0 ,sizeof (struct cpu_context )); -/* -* Unalias p->thread.sve_state (if any) from the parent task -* and disable discard SVE state for p: -*/ -clear_tsk_thread_flag (p,TIF_SVE ); - p->thread.sve_state =NULL ; -/* * In case p was allocated the same task_struct pointer as some * other recently-exited task, make sure p is disassociated from Signature · 7 lines
2.18.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Hi Dave,
Quoted 52 lines · Dave Martin
Quoted 33 lines · Masayoshi Mizuma
From: Masayoshi Mizuma <[email protected]>
The system which has SVE feature crashed because of the memory pointed by
task->thread.sve_statewas destroyed by someone.That is because
sve_stateis freed while the forking the child process. The child process has the pointer ofsve_statewhich is same as the parent's because the child'stask_structis copied from the parent's one. If thecopy_process()fails as an error on somewhere, for example,copy_creds(), then thesve_stateis freed even if the parent is alive. The flow is as follows.
copy_process
p =dup_task_struct
=>arch_dup_task_struct
*dst = *src; // copy the entire region.
:retval = copy_creds if (retval < 0) goto bad_fork_free; : bad_fork_free: ... delayed_free_task(p); => free_task => arch_release_task_struct => fpsimd_release_task => __sve_free => kfree(task->thread.sve_state); // free the parent's sve_stateQuoted 3 lines
Move child's
sve_state= NULL and clearingTIF_SVEflag toarch_dup_task_struct()so that the child doesn't free the parent's one.You could also add:
--8<--
There is no need to wait untilcopy_process()to clearTIF_SVEfor dst, becuase the thread flags for dst are initialized already by copying the srctask_struct.This change simplifies the code, so get rid of comments that are no longer needed.
-->8--Quoted 2 lines
Quoted 8 lines
Since SVE only exists from v4.15, it may be helpful to specify that, i.e., replace that Cc line with:
Cc <[email protected]> # 4.15.x-Otherwise, I'm happy to see this applied, but I'd like somebody to confirm that this change definitely fixes the bug.
I am working on a reproducer for this. So I should be able to test it.
Cheers,
Signature · 5 lines
Julien Grall _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Hi,
Quoted 33 lines · Masayoshi Mizuma
From: Masayoshi Mizuma <[email protected]>
The system which has SVE feature crashed because of the memory pointed by
task->thread.sve_statewas destroyed by someone.That is because
sve_stateis freed while the forking the child process. The child process has the pointer ofsve_statewhich is same as the parent's because the child'stask_structis copied from the parent's one. If thecopy_process()fails as an error on somewhere, for example,copy_creds(), then thesve_stateis freed even if the parent is alive. The flow is as follows.
copy_process
p =dup_task_struct
=>arch_dup_task_struct
*dst = *src; // copy the entire region.
:retval = copy_creds if (retval < 0) goto bad_fork_free; : bad_fork_free: ... delayed_free_task(p); => free_task => arch_release_task_struct => fpsimd_release_task => __sve_free => kfree(task->thread.sve_state); // free the parent's sve_state
Quoted 6 lines
Move child's
sve_state= NULL and clearingTIF_SVEflag toarch_dup_task_struct()so that the child doesn't free the parent's one.Fixes bc0ee4760364 ("arm64/sve: Core task context handling")
Looking at the log, it looks like THREAD_INFO_IN_TASK was selected before the bc0ee4760364. So it should be fine to backport for all the Linux tree contain this commit.
Quoted 3 lines
Signed-off-by Masayoshi Mizuma <[email protected]>Reported-by Hidetoshi Seto <[email protected]>Suggested-by Dave Martin <[email protected]>
I have tested the patch and can confirm that double-free disappeared after the patch is applied:
See below for a few comments.
Quoted 12 lines
--- arch/arm64/kernel/process.c | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-)arch/arm64/kernel/process.c +0
-0@@ -323,22 +323,16 @@ void arch_release_task_struct(struct task_struct *tsk)fpsimd_release_task (tsk); }
arch/arm64/kernel/process.c void arch_release_task_struct(struct task_struct *tsk) · line 335
Quoted 10 lines
arch/arm64/kernel/process.c +0
-10-/* -* src and dst may temporarily have aliased sve_state after task_struct -* is copied. We cannot fix this properly here, because src may have -* live SVE state and dst's thread_info may not exist yet, so tweaking -* either src's or dst's TIF_SVE is not safe. -* -* The unaliasing is done in copy_thread() instead. This works because -* dst is not schedulable or traceable until both of these functions -* have been called. -*/
It would be good to explain in the commit message why tweaking "dst" in arch_dup_task_struct() is fine.
From my understanding, Arm64 used to have thread_info on the stack. So it would not be possible to clear TIF_SVE until the stack is initialized.
Now that the thread_info is part of the task, it should be valid to modify the flag from arch_dup_task_struct().
Note that technically, TIF_SVE does not need to be cleared from arch_dup_task_struct(). It could also be done from copy_thread(). But it is easier to keep the both changes together.
arch/arm64/kernel/process.c void arch_release_task_struct(struct task_struct *tsk) · line 332
Quoted 7 lines
arch/arm64/kernel/process.c +1
-0int arch_dup_task_struct (struct task_struct *dst,struct task_struct *src) {if (current->mm)fpsimd_preserve_current_state (); *dst = *src; +BUILD_BUG_ON (!IS_ENABLED (CONFIG_THREAD_INFO_IN_TASK ));
You may want to add a comment on top explaining why TIF_SVE is cleared here.
Quoted 11 lines
arch/arm64/kernel/process.c +3
-0+ dst->thread.sve_state =NULL ; +clear_tsk_thread_flag (dst,TIF_SVE ); +return 0 ; }@@ -351,13 +345,6 @@ int copy_thread(unsigned long clone_flags, unsigned long stack_start,memset (&p->thread.cpu_context,0 ,sizeof (struct cpu_context ));
arch/arm64/kernel/process.c int copy_thread(unsigned long clone_flags, unsigned long stack_start, · line 350
Quoted 10 lines
arch/arm64/kernel/process.c +0
-7-/* -* Unalias p->thread.sve_state (if any) from the parent task -* and disable discard SVE state for p: -*/ -clear_tsk_thread_flag (p,TIF_SVE ); - p->thread.sve_state =NULL ; -/* * In case p was allocated the same task_struct pointer as some * other recently-exited task, make sure p is disassociated from
Cheers,
Signature · 1 line
Julien Grall
Quoted 47 lines · Julien Grall
Hi,
Quoted 33 lines · Masayoshi Mizuma
From: Masayoshi Mizuma <[email protected]>
The system which has SVE feature crashed because of the memory pointed by
task->thread.sve_statewas destroyed by someone.That is because
sve_stateis freed while the forking the child process. The child process has the pointer ofsve_statewhich is same as the parent's because the child'stask_structis copied from the parent's one. If thecopy_process()fails as an error on somewhere, for example,copy_creds(), then thesve_stateis freed even if the parent is alive. The flow is as follows.
copy_process
p =dup_task_struct
=>arch_dup_task_struct
*dst = *src; // copy the entire region.
:retval = copy_creds if (retval < 0) goto bad_fork_free; : bad_fork_free: ... delayed_free_task(p); => free_task => arch_release_task_struct => fpsimd_release_task => __sve_free => kfree(task->thread.sve_state); // free the parent's sve_stateQuoted 6 lines
Move child's
sve_state= NULL and clearingTIF_SVEflag toarch_dup_task_struct()so that the child doesn't free the parent's one.Fixes bc0ee4760364 ("arm64/sve: Core task context handling")Looking at the log, it looks like
THREAD_INFO_IN_TASKwas selected before thebc0ee4760364. So it should be fine to backport for all the Linux tree contain this commit.
Quoted 8 lines
Quoted 3 lines
Signed-off-by Masayoshi Mizuma <[email protected]>Reported-by Hidetoshi Seto <[email protected]>Suggested-by Dave Martin <[email protected]>I have tested the patch and can confirm that double-free disappeared after the patch is applied:
Tested-by Julien Grall <[email protected]>
Good to have that confirmed -- thanks for verifying.
[...]
Quoted 28 lines
Quoted 11 lines
--- arch/arm64/kernel/process.c | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-)arch/arm64/kernel/process.c +0
-0@@ -323,22 +323,16 @@ void arch_release_task_struct(struct task_struct *tsk)fpsimd_release_task (tsk); }arch/arm64/kernel/process.c void arch_release_task_struct(struct task_struct *tsk) · line 334
Quoted 10 lines
arch/arm64/kernel/process.c +0
-10-/* -* src and dst may temporarily have aliased sve_state after task_struct -* is copied. We cannot fix this properly here, because src may have -* live SVE state and dst's thread_info may not exist yet, so tweaking -* either src's or dst's TIF_SVE is not safe. -* -* The unaliasing is done in copy_thread() instead. This works because -* dst is not schedulable or traceable until both of these functions -* have been called. -*/ It would be good to explain in the commit message why tweaking "dst" in
arch_dup_task_struct()is fine.From my understanding, Arm64 used to have
thread_infoon the stack. So it would not be possible to clearTIF_SVEuntil the stack is initialized.
Quoted 12 lines
Now that the
thread_infois part of the task, it should be valid to modify the flag fromarch_dup_task_struct().Note that technically,
TIF_SVEdoes not need to be cleared fromarch_dup_task_struct(). It could also be done fromcopy_thread(). But it is easier to keep the both changes together.Quoted 5 lines
arch/arm64/kernel/process.c +0
-0int arch_dup_task_struct (struct task_struct *dst,struct task_struct *src) {if (current->mm)fpsimd_preserve_current_state (); *dst = *src;
Ack, some more explanation would be a good idea here.
Maybe the following comments are sufficient?
/* We rely on the above assingment to initialise dst's thread_flags: */
Quoted 2 lines
arch/arm64/kernel/process.c void arch_release_task_struct(struct task_struct *tsk) · line 332
Quoted 1 line
arch/arm64/kernel/process.c +1
-0+BUILD_BUG_ON (!IS_ENABLED (CONFIG_THREAD_INFO_IN_TASK ));
and
/*
* Detach src's sve_state (if any) from dst so that it does not
* get erroneously used or freed prematurely. dst's sve_state
* will be allocated on demand later on if dst uses SVE.
* For consistency, also clear TIF_SVE here: this could be done
* later in copy_process(), but to avoid tripping up future
* maintainers it is best not to leave TIF_SVE and sve_state in
* an inconsistent state, even temporarily.
*/
Quoted 2 lines
arch/arm64/kernel/process.c void arch_release_task_struct(struct task_struct *tsk) · line 334
Quoted 2 lines
arch/arm64/kernel/process.c +2
-0+ dst->thread.sve_state =NULL ; +clear_tsk_thread_flag (dst,TIF_SVE );
(TIF_SVE should not usually be set in the first place of course, since we are in a fork() or clone() syscall in src. This may not be true if a task is created using kernel_thread() while running in the context of some user task that entered the kernel due to a trap or syscall -- though probably nobody should be doing that.)
[...]
Cheers
---DavE
Hi Julien and Dave,
Quoted 41 lines · Dave Martin
Quoted 40 lines · Julien Grall
Hi,
Quoted 37 lines · Masayoshi Mizuma
From: Masayoshi Mizuma <[email protected]>
The system which has SVE feature crashed because of the memory pointed by
task->thread.sve_statewas destroyed by someone.That is because
sve_stateis freed while the forking the child process. The child process has the pointer ofsve_statewhich is same as the parent's because the child'stask_structis copied from the parent's one. If thecopy_process()fails as an error on somewhere, for example,copy_creds(), then thesve_stateis freed even if the parent is alive. The flow is as follows.
copy_process
p =dup_task_struct
=>arch_dup_task_struct
*dst = *src; // copy the entire region.
:retval = copy_creds if (retval < 0) goto bad_fork_free; : bad_fork_free: ... delayed_free_task(p); => free_task => arch_release_task_struct => fpsimd_release_task => __sve_free => kfree(task->thread.sve_state); // free the parent's sve_stateMove child's
sve_state= NULL and clearingTIF_SVEflag toarch_dup_task_struct()so that the child doesn't free the parent's one.
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
Fixes bc0ee4760364 ("arm64/sve: Core task context handling")Looking at the log, it looks like
THREAD_INFO_IN_TASKwas selected before thebc0ee4760364. So it should be fine to backport for all the Linux tree contain this commit.
I think this patch is needed for the kernel has SVE support. I'll add the Cc tag as Dave said:
So, I suppose this patch will be backported to stables 5.3.X, 5.2.X and longterm 4.19.X.
Does this make sense?
Quoted 9 lines
Quoted 9 lines
Quoted 4 lines
Signed-off-by Masayoshi Mizuma <[email protected]>Reported-by Hidetoshi Seto <[email protected]>Suggested-by Dave Martin <[email protected]>I have tested the patch and can confirm that double-free disappeared after the patch is applied:
Tested-by Julien Grall <[email protected]>
Thank you so much!
Quoted 39 lines
Good to have that confirmed -- thanks for verifying.
[...]
Quoted 34 lines
Quoted 11 lines
--- arch/arm64/kernel/process.c | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-)arch/arm64/kernel/process.c +0
-0@@ -323,22 +323,16 @@ void arch_release_task_struct(struct task_struct *tsk)fpsimd_release_task (tsk); }arch/arm64/kernel/process.c void arch_release_task_struct(struct task_struct *tsk) · line 334
Quoted 10 lines
arch/arm64/kernel/process.c +0
-10-/* -* src and dst may temporarily have aliased sve_state after task_struct -* is copied. We cannot fix this properly here, because src may have -* live SVE state and dst's thread_info may not exist yet, so tweaking -* either src's or dst's TIF_SVE is not safe. -* -* The unaliasing is done in copy_thread() instead. This works because -* dst is not schedulable or traceable until both of these functions -* have been called. -*/ It would be good to explain in the commit message why tweaking "dst" in
arch_dup_task_struct()is fine.From my understanding, Arm64 used to have
thread_infoon the stack. So it would not be possible to clearTIF_SVEuntil the stack is initialized.Now that the
thread_infois part of the task, it should be valid to modify the flag fromarch_dup_task_struct().Note that technically,
TIF_SVEdoes not need to be cleared fromarch_dup_task_struct(). It could also be done fromcopy_thread(). But it is easier to keep the both changes together.
Thanks, let me add some comments to the commit log.
Quoted 7 lines
Quoted 6 lines
arch/arm64/kernel/process.c void arch_release_task_struct(struct task_struct *tsk) · line 330
Quoted 6 lines
arch/arm64/kernel/process.c +0
-0int arch_dup_task_struct (struct task_struct *dst,struct task_struct *src) {if (current->mm)fpsimd_preserve_current_state (); *dst = *src;
Quoted 5 lines
Ack, some more explanation would be a good idea here.
Maybe the following comments are sufficient?
/* We rely on the above assingment to initialise dst's thread_flags: */
Thanks, I'll add this comment.
Quoted 6 lines
Quoted 3 lines
arch/arm64/kernel/process.c void arch_release_task_struct(struct task_struct *tsk) · line 332
Quoted 2 lines
arch/arm64/kernel/process.c +1
-0+BUILD_BUG_ON (!IS_ENABLED (CONFIG_THREAD_INFO_IN_TASK ));and
Quoted 9 lines
/*
* Detach src'ssve_state(if any) from dst so that it does not
* get erroneously used or freed prematurely. dst'ssve_state
* will be allocated on demand later on if dst uses SVE.
* For consistency, also clearTIF_SVEhere: this could be done
* later incopy_process(), but to avoid tripping up future
* maintainers it is best not to leaveTIF_SVEandsve_statein
* an inconsistent state, even temporarily.
*/
I'll add this comments.
Quoted 9 lines
Quoted 3 lines
arch/arm64/kernel/process.c void arch_release_task_struct(struct task_struct *tsk) · line 334
Quoted 3 lines
arch/arm64/kernel/process.c +2
-0+ dst->thread.sve_state =NULL ; +clear_tsk_thread_flag (dst,TIF_SVE );(
TIF_SVEshould not usually be set in the first place of course, since we are in afork()orclone()syscall in src. This may not be true if a task is created usingkernel_thread()while running in the context of some user task that entered the kernel due to a trap or syscall -- though probably nobody should be doing that.)
Thanks!
Masa
Quoted 47 lines · Masayoshi Mizuma
Hi Julien and Dave,
Quoted 44 lines · Dave Martin
Quoted 43 lines · Julien Grall
Hi,
Quoted 39 lines · Masayoshi Mizuma
From: Masayoshi Mizuma <[email protected]>
The system which has SVE feature crashed because of the memory pointed by
task->thread.sve_statewas destroyed by someone.That is because
sve_stateis freed while the forking the child process. The child process has the pointer ofsve_statewhich is same as the parent's because the child'stask_structis copied from the parent's one. If thecopy_process()fails as an error on somewhere, for example,copy_creds(), then thesve_stateis freed even if the parent is alive. The flow is as follows.
copy_process
p =dup_task_struct
=>arch_dup_task_struct
*dst = *src; // copy the entire region.
:retval = copy_creds if (retval < 0) goto bad_fork_free; : bad_fork_free: ... delayed_free_task(p); => free_task => arch_release_task_struct => fpsimd_release_task => __sve_free => kfree(task->thread.sve_state); // free the parent's sve_stateMove child's
sve_state= NULL and clearingTIF_SVEflag toarch_dup_task_struct()so that the child doesn't free the parent's one.Fixes bc0ee4760364 ("arm64/sve: Core task context handling")
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
Looking at the log, it looks like
THREAD_INFO_IN_TASKwas selected before thebc0ee4760364. So it should be fine to backport for all the Linux tree contain this commit.I think this patch is needed for the kernel has SVE support. I'll add the Cc tag as Dave said:
Cc [email protected] # 4.15+
Based on running git log --grep='stable@vger.*#.*-', the most common syntax for this situation seems to be
Quoted 3 lines
So, I suppose this patch will be backported to stables 5.3.X, 5.2.X and longterm 4.19.X.
Does this make sense?
Yes, I think so. It's up to the stable maintainers to decide which trees the patch actually gets applied too.
Quoted 84 lines
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
Signed-off-by Masayoshi Mizuma <[email protected]>Reported-by Hidetoshi Seto <[email protected]>Suggested-by Dave Martin <[email protected]>I have tested the patch and can confirm that double-free disappeared after the patch is applied:
Tested-by Julien Grall <[email protected]>Thank you so much!
Quoted 39 lines
Good to have that confirmed -- thanks for verifying.
[...]
Quoted 34 lines
Quoted 11 lines
--- arch/arm64/kernel/process.c | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-)arch/arm64/kernel/process.c +0
-0@@ -323,22 +323,16 @@ void arch_release_task_struct(struct task_struct *tsk)fpsimd_release_task (tsk); }arch/arm64/kernel/process.c void arch_release_task_struct(struct task_struct *tsk) · line 334
Quoted 10 lines
arch/arm64/kernel/process.c +0
-10-/* -* src and dst may temporarily have aliased sve_state after task_struct -* is copied. We cannot fix this properly here, because src may have -* live SVE state and dst's thread_info may not exist yet, so tweaking -* either src's or dst's TIF_SVE is not safe. -* -* The unaliasing is done in copy_thread() instead. This works because -* dst is not schedulable or traceable until both of these functions -* have been called. -*/ It would be good to explain in the commit message why tweaking "dst" in
arch_dup_task_struct()is fine.From my understanding, Arm64 used to have
thread_infoon the stack. So it would not be possible to clearTIF_SVEuntil the stack is initialized.Now that the
thread_infois part of the task, it should be valid to modify the flag fromarch_dup_task_struct().Note that technically,
TIF_SVEdoes not need to be cleared fromarch_dup_task_struct(). It could also be done fromcopy_thread(). But it is easier to keep the both changes together.Thanks, let me add some comments to the commit log.
Quoted 7 lines
Quoted 6 lines
arch/arm64/kernel/process.c void arch_release_task_struct(struct task_struct *tsk) · line 330
Quoted 6 lines
arch/arm64/kernel/process.c +0
-0int arch_dup_task_struct (struct task_struct *dst,struct task_struct *src) {if (current->mm)fpsimd_preserve_current_state (); *dst = *src;Quoted 5 lines
Ack, some more explanation would be a good idea here.
Maybe the following comments are sufficient?
/* We rely on the above assingment to initialise dst's thread_flags: */Thanks, I'll add this comment.
Quoted 6 lines
Quoted 3 lines
arch/arm64/kernel/process.c void arch_release_task_struct(struct task_struct *tsk) · line 332
Quoted 2 lines
arch/arm64/kernel/process.c +1
-0+BUILD_BUG_ON (!IS_ENABLED (CONFIG_THREAD_INFO_IN_TASK ));and
Quoted 9 lines
/*
* Detach src'ssve_state(if any) from dst so that it does not
* get erroneously used or freed prematurely. dst'ssve_state
* will be allocated on demand later on if dst uses SVE.
* For consistency, also clearTIF_SVEhere: this could be done
* later incopy_process(), but to avoid tripping up future
* maintainers it is best not to leaveTIF_SVEandsve_statein
* an inconsistent state, even temporarily.
*/
Quoted 1 line
I'll add this comments.
OK, if these make sense to you, feel free to add them.
[...]
Cheers
---Dave