thread_create(): call cpu_copy_thread() after td_pflags is zeroed

By calling the function too early we might still have the td_pflags
value cached from the previous struct thread use. cpu_copy_thread()
depends on correct value for TDP_KTHREAD at least on x86.

Reported, bisected, and tested by:	pho
Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D36069
This commit is contained in:
Konstantin Belousov 2022-08-07 20:00:02 +03:00
parent 28b64169ea
commit 1b0a4974c5
2 changed files with 4 additions and 4 deletions

View File

@ -280,8 +280,6 @@ linux_clone_thread(struct thread *td, struct l_clone_args *args)
if (error)
goto fail;
cpu_copy_thread(newtd, td);
bzero(&newtd->td_startzero,
__rangeof(struct thread, td_startzero, td_endzero));
bcopy(&td->td_startcopy, &newtd->td_startcopy,
@ -290,6 +288,8 @@ linux_clone_thread(struct thread *td, struct l_clone_args *args)
newtd->td_proc = p;
thread_cow_get(newtd, td);
cpu_copy_thread(newtd, td);
/* create the emuldata */
linux_proc_init(td, newtd, true);

View File

@ -231,8 +231,6 @@ thread_create(struct thread *td, struct rtprio *rtp,
if (error)
goto fail;
cpu_copy_thread(newtd, td);
bzero(&newtd->td_startzero,
__rangeof(struct thread, td_startzero, td_endzero));
bcopy(&td->td_startcopy, &newtd->td_startcopy,
@ -241,6 +239,8 @@ thread_create(struct thread *td, struct rtprio *rtp,
newtd->td_rb_list = newtd->td_rbp_list = newtd->td_rb_inact = 0;
thread_cow_get(newtd, td);
cpu_copy_thread(newtd, td);
error = initialize_thread(newtd, thunk);
if (error != 0) {
thread_cow_free(newtd);