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.

Diff Detail

Repository
R10 FreeBSD src repository
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

sys/amd64/amd64/vm_machdep.c
188

Should we clear PCB_KERNFPU_THR, or leave it alone?

sys/amd64/amd64/vm_machdep.c
188

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

600

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