vmm(4): fix vcpu locking issues reported by syzbot
authordv <dv@openbsd.org>
Sun, 5 Sep 2021 13:13:31 +0000 (13:13 +0000)
committerdv <dv@openbsd.org>
Sun, 5 Sep 2021 13:13:31 +0000 (13:13 +0000)
commit5f3d69798ad5a04e95493d31d8f03b163ea94bd4
treefabed201c21e99c4b9c0d7cfcf8cff3b13ec1fc3
parent94151407c9d6e6f1c07fe806c570e103e2ee8d67
vmm(4): fix vcpu locking issues reported by syzbot

Syzbot found 3 issues related to the new vcpu lock. This diff adds
a write lock to vm_rwregs (needed on VMX as vmread instructions
require taking ownership of the vcpu to load the VMCS) and prevents
locking the vcpu in vm_run if we fail the cas operation for toggling
vcpu state.

In the future, we can push the locking in vm_rwregs on AMD SVM
systems.

The panics in question:

 panic: rw_enter: vcpulock locking against myself
 panic: lock (rwlock) vcpulock not locked
 panic: vcpulock: lock not held

Reported-by: syzbot+1dab11e14aa7a159cadf@syzkaller.appspotmail.com
Reported-by: syzbot+36244e105daffa1a81b6@syzkaller.appspotmail.com
Reported-by: syzbot+c78b5644c7dc3d9b689a@syzkaller.appspotmail.com
ok mlarkin@
sys/arch/amd64/amd64/vmm.c