summaryrefslogtreecommitdiffhomepage
path: root/pkg
diff options
context:
space:
mode:
authorgVisor bot <gvisor-bot@google.com>2021-08-09 19:37:03 +0000
committergVisor bot <gvisor-bot@google.com>2021-08-09 19:37:03 +0000
commit05a0c775ef7b49427917b8c5d043caea6b909658 (patch)
tree6660c598e502536f520c5d463d6b65e8ae816762 /pkg
parent25d4066279d90f206456e5b21c8b0cbf83e1ef60 (diff)
parent14d6cb4436f19d0500e98179c3215517f1a77b08 (diff)
Merge release-20210726.0-45-g14d6cb443 (automated)
Diffstat (limited to 'pkg')
-rw-r--r--pkg/sentry/platform/kvm/machine.go12
1 files changed, 9 insertions, 3 deletions
diff --git a/pkg/sentry/platform/kvm/machine.go b/pkg/sentry/platform/kvm/machine.go
index e7092a756..d67563958 100644
--- a/pkg/sentry/platform/kvm/machine.go
+++ b/pkg/sentry/platform/kvm/machine.go
@@ -519,15 +519,21 @@ func (c *vCPU) lock() {
//
//go:nosplit
func (c *vCPU) unlock() {
- if atomic.CompareAndSwapUint32(&c.state, vCPUUser|vCPUGuest, vCPUGuest) {
+ origState := atomicbitops.CompareAndSwapUint32(&c.state, vCPUUser|vCPUGuest, vCPUGuest)
+ if origState == vCPUUser|vCPUGuest {
// Happy path: no exits are forced, and we can continue
// executing on our merry way with a single atomic access.
return
}
// Clear the lock.
- origState := atomic.LoadUint32(&c.state)
- atomicbitops.AndUint32(&c.state, ^vCPUUser)
+ for {
+ state := atomicbitops.CompareAndSwapUint32(&c.state, origState, origState&^vCPUUser)
+ if state == origState {
+ break
+ }
+ origState = state
+ }
switch origState {
case vCPUUser:
// Normal state.