Solve BounceToKernel may hang issue

BounceToKernel will make vCPU quit from guest ring3 to guest ring0, but
vCPUWaiter is not cleared when we unlock the vCPU, when next time this vCPU
enter guest mode ring3, vCPU may enter guest mode with vCPUWaiter bit setted,
this will cause the following BounceToKernel to this vCPU hangs at
waitUntilNot.

Halt may workaroud this issue, because halt process will reset vCPU status into
vCPUUser, and notify all waiter for vCPU state change, but if there is no
exception or syscall in this period, BounceToKernel will hang at waitUntilNot.

PiperOrigin-RevId: 256299660
This commit is contained in:
Yong He 2019-07-02 22:02:15 -07:00 committed by gVisor bot
parent 753da9604e
commit 85b27a9f8f
1 changed files with 6 additions and 1 deletions

View File

@ -426,7 +426,12 @@ func (c *vCPU) unlock() {
// Normal state.
case vCPUUser | vCPUGuest | vCPUWaiter:
// Force a transition: this must trigger a notification when we
// return from guest mode.
// return from guest mode. We must clear vCPUWaiter here
// anyways, because BounceToKernel will force a transition only
// from ring3 to ring0, which will not clear this bit. Halt may
// workaround the issue, but if there is no exception or
// syscall in this period, BounceToKernel will hang.
atomicbitops.AndUint32(&c.state, ^vCPUWaiter)
c.notify()
case vCPUUser | vCPUWaiter:
// Waiting for the lock to be released; the responsibility is