Skip to content

Commit

Permalink
kvm: enable PVI mode
Browse files Browse the repository at this point in the history
  • Loading branch information
stsp committed Feb 27, 2021
1 parent 87603ed commit 4035a35
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions src/base/emu-i386/kvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ void init_kvm_monitor(void)
sizeof(monitor->code), PROT_READ | PROT_EXEC);

sregs->cr0 |= X86_CR0_PE | X86_CR0_PG | X86_CR0_NE | X86_CR0_ET;
sregs->cr4 |= X86_CR4_VME;
sregs->cr4 |= X86_CR4_VME | X86_CR4_PVI;

/* setup registers to point to VM86 monitor */
sregs->cs.base = 0;
Expand Down Expand Up @@ -816,17 +816,12 @@ static unsigned int kvm_run(void)
In this case the registers are pushed on and popped from the stack.
2. KVM_EXIT_INTR: (with ret==-1) after a signal. In this case we
must restore and save registers using ioctls.
3. KVM_EXIT_IRQ_WINDOW_OPEN: if it is not possible to inject interrupts
(or in our case properly interrupt using reason 2)
KVM is re-entered asking it to exit when interrupt injection is
possible, then it exits with this code. This only happens if a signal
occurs during execution of the monitor code in kvmmon.S.
4. ret==-1 and errno == EFAULT: this can happen if code in vgaemu.c
3. ret==-1 and errno == EFAULT: this can happen if code in vgaemu.c
calls mprotect in parallel and the TLB is out of sync with the
actual page tables; if this happen we retry and it should not happen
again since the KVM exit/entry makes everything sync'ed.
*/
if (mprotected_kvm) { // case 4
if (mprotected_kvm) { // case 3
mprotected_kvm = 0;
if (ret == -1 && errn == EFAULT)
ret = ioctl(vcpufd, KVM_RUN, NULL);
Expand All @@ -849,13 +844,6 @@ static unsigned int kvm_run(void)
kvm_sync_regs(0, -1);
exit_reason = KVM_EXIT_HLT;
break;
case KVM_EXIT_IRQ_WINDOW_OPEN:
if (!kvm_post_run()) {
error("KVM: IRQ_WINDOW in ring0?\n");
leavedos_main(99);
}
exit_reason = KVM_EXIT_IRQ_WINDOW_OPEN;
break;
case KVM_EXIT_FAIL_ENTRY:
error("KVM_EXIT_FAIL_ENTRY: hardware_entry_failure_reason = 0x%llx\n",
(unsigned long long)run->fail_entry.hardware_entry_failure_reason);
Expand Down Expand Up @@ -997,8 +985,12 @@ int kvm_dpmi(sigcontext_t *scp)
kregs->rsp = _esp;
kregs->rip = _eip;
kregs->rflags = _eflags;
kregs->rflags &= (SAFE_MASK | X86_EFLAGS_VIF | X86_EFLAGS_VIP);
kregs->rflags &= SAFE_MASK;
kregs->rflags |= X86_EFLAGS_FIXED | X86_EFLAGS_IF;
if (isset_VIP())
kregs->rflags |= X86_EFLAGS_VIP;
if (isset_IF())
kregs->rflags |= X86_EFLAGS_VIF;
run->kvm_dirty_regs |= KVM_SYNC_X86_REGS;

set_ldt_seg(&sregs->cs, _cs);
Expand Down

0 comments on commit 4035a35

Please sign in to comment.