Page MenuHomeFreeBSD

x86: Always use clean FPU and segment base state for new kthreads.
ClosedPublic

Authored by jhb on Mar 10 2021, 10:13 PM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Oct 23, 9:42 AM
Unknown Object (File)
Oct 10 2024, 11:13 PM
Unknown Object (File)
Oct 3 2024, 9:04 PM
Unknown Object (File)
Oct 3 2024, 8:48 AM
Unknown Object (File)
Oct 1 2024, 4:36 PM
Unknown Object (File)
Oct 1 2024, 10:34 AM
Unknown Object (File)
Sep 30 2024, 8:09 PM
Unknown Object (File)
Sep 30 2024, 8:08 PM
Subscribers

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

sys/amd64/amd64/vm_machdep.c
189

Should we clear PCB_KERNFPU_THR, or leave it alone?

sys/amd64/amd64/vm_machdep.c
189

To get clean state we should probably clear it as well. That's probably a (small) bug that we don't clear it now.

601

We could perhaps assert that neither KERNFPU nor KERNFPU_THR is set here instead of clearing. No user process calling thr_new() should have active kernel FPU state here. cpu_fork() doesn't currently bother clearing this flag (so I didn't add it), but I would like these two code blocks to be as identical as possible between cpu_fork() and cpu_copy_thread(). (It's somewhat temping to see if I could come up with some kind of 'copy_pcb' function for the shared logic between the two functions.)

609

This comment seems a bit stale as it doesn't create a stack at all. For exec_setregs where I think this was copied from, we bzero the trap frame before setting registers. I wonder if for the trapframe cpu_thread_copy() shouldn't be more like exec and rely on cpu_set_upcall() instead.

jhb marked an inline comment as done.Mar 11 2021, 6:16 PM
sys/amd64/amd64/vm_machdep.c
609

This comment seems a bit stale as it doesn't create a stack at all. For exec_setregs where I think this was copied from, we bzero the trap frame before setting registers. I wonder if for the trapframe cpu_thread_copy() shouldn't be more like exec and rely on cpu_set_upcall() instead.

I tried doing a bzero here and it didn't work out well. cpu_set_upcall() below doesn't set tf_ss (though it sets all the others) which blew up. The 32-bit cpu_set_upcall() doesn't set any seg regs at all, and linux_set_upcall_kse() assumes a copy instead of clear. I will make the comment more accurate though.

  • Clear PCB_KERN*_THR as well.
This revision is now accepted and ready to land.Mar 12 2021, 12:56 PM