Page MenuHomeFreeBSD

bhyve: Advance RIP after userspace instruction decode

Authored by on Mon, Nov 16, 7:33 PM.



Add update to RIP after a userspace instruction decode (as is done for
the in-kernel counterpart of this case).

Test Plan

Found while making use of this facility to prototype some instruction
emulations in userspace. Without this patch, the guest would hang,
endlessly repeating the userspace-prototyped instruction. With this
patch, the guest would continue executing past the userspace-prototyped
instruction as expected.

Diff Detail

rS FreeBSD src repository
Automatic diff as part of commit; lint not applicable.
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

markj added a subscriber: markj.
markj added inline comments.
771 ↗(On Diff #79623)

Indentation should also be by 4 spaces on this line. It might be a bit clearer if the two conditions were split into separate if-statements.

This revision is now accepted and ready to land.Tue, Nov 17, 4:36 PM

Some notes I sent Adam earlier, might be useful for someone in the future:

I think the key is sys/amd64/vmm/vmm.c vm_run(9), where
we set vcpu->nextrip to rip + inst_length on vm exit. Inst_length
will be zero if decoding failed in the kernel. Additionally,
libvmmapi vm_run(3) zeros out the entire passed-in vm_exit context, so
we can't just update vmexit->rip in userspace and expect it to be
passed in during the next vm_run(3) — we need the vm_set_register()
ioctl you've used.

Incorporate review feedback from @markj.

This revision now requires review to proceed.Wed, Nov 18, 6:33 PM

Thanks for the review, @markj and @cem! Diff updated with @markj's requested changes.

This revision is now accepted and ready to land.Wed, Nov 18, 6:57 PM
This revision was automatically updated to reflect the committed changes.