Fix clobber of current in kthread.c
authorBarret Rhoden <brho@cs.berkeley.edu>
Mon, 3 Oct 2016 19:03:50 +0000 (15:03 -0400)
committerBarret Rhoden <brho@cs.berkeley.edu>
Thu, 6 Oct 2016 19:41:48 +0000 (15:41 -0400)
commit664b9e5222edce8dea4e374ffc1bb13c698db80e
treea9ea4e37edde7697b076ff3173580423f4e3e02d
parentd883193b637d81928c1876e6b466171a3cf04c8f
Fix clobber of current in kthread.c

Originally, there wasn't a KTH_SAVE_ADDR_SPACE flag.  When I added that, I
didn't update this code.  The resulting bug was that if we had to undo a
kthread swap, that kthread was for a ktask (which doesn't have a proc), and
we had a process's address space loaded, then we'd clobber current
(clearing it).  That would result in a reference counting problem, since we
effectively deleted a counted reference to whatever process was current.
I'd see this on occasion under heavy networking and process load.

This also clears kthread->proc whenever the kthread is not blocked.
Previously, we were leaving the value of the uncounted proc reference.  The
code was okay, but it was surprising when debugging and was a source for
potential bugs.

Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
kern/src/kthread.c