genode/repos/ports/src/virtualbox/spec/muen/guest_interrupts.h

78 lines
1.4 KiB
C
Raw Normal View History

vbox: Implement hwaccl support for Muen * Implement VMMR0_DO_VMMR0_INIT operation for Muen - Indicate VT-x support - Enable unrestricted guest mode - Set CR[0|4] mask to enable masking of guest CR0.[NE,NW,CD] and CR4.VMXE bits. * Implement VMMR0_DO_GVMM_CREATE_VM on Muen Return error if trying to create SMP VM as VMs with multiple CPUs are currently not supported on hw_x86_64_muen. * Add Muen-specific Mem_region type On hw_x86_64_muen the guest memory layout is static, thus regions are handed out from an array of memory regions. Use sinfo API to calculate the base address of the VM RAM physical 0x0 region. This allows to dynamically modify the VM RAM size by adjusting the Muen policy and Genode vbox files accordingly. Zeroize all memory regions apart from VM Ram since Virtualbox expects these regions to be cleared. * Add Muen subject state struct The subject state encompasses the guest VM machine state that is transfered between Virtualbox and hardware accelerated execution on Muen. * Add Muen-specific Vm_handler class * Use Vm_handler to run VM * Instruct recompiler to flush its code cache * Copy the Muen subject state to/from the Vbox PCPUMCTX. * Use the VM interruptibility state to inform the recompiler whether interrupts are currently inhibited. * Explicitly handle control register access If a VM-exit occurs due to a control register access, handle it and directly continue hardware accelerated execution of guest VM. Note: On NOVA control register accesses are handled by the kernel [1]. [1] - https://github.com/alex-ab/NOVA/blob/master/src/ec_vmx.cpp#L106 * Reset guest interruptibility state Assert that interrupts are not inhibited in the Virtualbox machine state and clear Blocking-by-[STI|MOV to SS] guest interruptibility flags prior to running a guest VM in hwaccel mode. * Set return code depending on exit reason Do not unconditionally emulate the next instruction on VM exit. This makes sharing the VM FPU state with Virtualbox unnecessary, as FPU instructions are not emulated by the recompiler any longer. Also, assert that the FPU has not been used by the recompiler * Inject pending guest VM interrupts on Muen Use mapped subject pending interrupts page of guest VM to perform interrupt injection. IRQs are transferred from the Virtualbox trap manager state to the pending interrupts region for injection. If an IRQ remains pending upon returning to the recompiler, it is copied back to the trap manager state and cleared in the subject interrupts region. * Inform recompiler about changed SYSENTER_[CS|EIP|ESP] values, otherwise values set while running the guest VM hardware accelerated may get lost. * Implement genode_cpu_hz() on Muen Determine the CPU frequency dynamically using the sinfo API. Issue #2016
2015-06-02 19:46:50 +02:00
/*
* \brief Muen subject pending interrupt handling
* \author Adrian-Ken Rueegsegger
* \author Reto Buerki
* \date 2016-04-27
*/
/*
* Copyright (C) 2016-2017 Genode Labs GmbH
vbox: Implement hwaccl support for Muen * Implement VMMR0_DO_VMMR0_INIT operation for Muen - Indicate VT-x support - Enable unrestricted guest mode - Set CR[0|4] mask to enable masking of guest CR0.[NE,NW,CD] and CR4.VMXE bits. * Implement VMMR0_DO_GVMM_CREATE_VM on Muen Return error if trying to create SMP VM as VMs with multiple CPUs are currently not supported on hw_x86_64_muen. * Add Muen-specific Mem_region type On hw_x86_64_muen the guest memory layout is static, thus regions are handed out from an array of memory regions. Use sinfo API to calculate the base address of the VM RAM physical 0x0 region. This allows to dynamically modify the VM RAM size by adjusting the Muen policy and Genode vbox files accordingly. Zeroize all memory regions apart from VM Ram since Virtualbox expects these regions to be cleared. * Add Muen subject state struct The subject state encompasses the guest VM machine state that is transfered between Virtualbox and hardware accelerated execution on Muen. * Add Muen-specific Vm_handler class * Use Vm_handler to run VM * Instruct recompiler to flush its code cache * Copy the Muen subject state to/from the Vbox PCPUMCTX. * Use the VM interruptibility state to inform the recompiler whether interrupts are currently inhibited. * Explicitly handle control register access If a VM-exit occurs due to a control register access, handle it and directly continue hardware accelerated execution of guest VM. Note: On NOVA control register accesses are handled by the kernel [1]. [1] - https://github.com/alex-ab/NOVA/blob/master/src/ec_vmx.cpp#L106 * Reset guest interruptibility state Assert that interrupts are not inhibited in the Virtualbox machine state and clear Blocking-by-[STI|MOV to SS] guest interruptibility flags prior to running a guest VM in hwaccel mode. * Set return code depending on exit reason Do not unconditionally emulate the next instruction on VM exit. This makes sharing the VM FPU state with Virtualbox unnecessary, as FPU instructions are not emulated by the recompiler any longer. Also, assert that the FPU has not been used by the recompiler * Inject pending guest VM interrupts on Muen Use mapped subject pending interrupts page of guest VM to perform interrupt injection. IRQs are transferred from the Virtualbox trap manager state to the pending interrupts region for injection. If an IRQ remains pending upon returning to the recompiler, it is copied back to the trap manager state and cleared in the subject interrupts region. * Inform recompiler about changed SYSENTER_[CS|EIP|ESP] values, otherwise values set while running the guest VM hardware accelerated may get lost. * Implement genode_cpu_hz() on Muen Determine the CPU frequency dynamically using the sinfo API. Issue #2016
2015-06-02 19:46:50 +02:00
*
* This file is distributed under the terms of the GNU General Public License
* version 2.
*/
#ifndef _VIRTUALBOX__SPEC__MUEN__INTERRUPTS_H_
#define _VIRTUALBOX__SPEC__MUEN__INTERRUPTS_H_
/* Genode includes */
#include <base/stdint.h>
namespace Genode
{
/**
* Vm execution handler.
*/
class Guest_interrupts;
}
class Genode::Guest_interrupts
{
private:
addr_t _base;
public:
Guest_interrupts (addr_t base) : _base(base) { }
/**
* Returns true if the bit corresponding to the specified IRQ is set.
*/
bool is_pending_interrupt(uint8_t irq)
{
bool result;
asm volatile ("bt %1, %2;"
"sbb %0, %0;"
: "=r" (result)
: "Ir" ((uint32_t)irq), "m" (*(char *)_base)
: "memory");
return result;
}
/**
* Set bit corresponding to given IRQ in pending interrupts region.
*/
void set_pending_interrupt(uint8_t irq)
{
asm volatile ("bts %1, %0"
vbox: Implement hwaccl support for Muen * Implement VMMR0_DO_VMMR0_INIT operation for Muen - Indicate VT-x support - Enable unrestricted guest mode - Set CR[0|4] mask to enable masking of guest CR0.[NE,NW,CD] and CR4.VMXE bits. * Implement VMMR0_DO_GVMM_CREATE_VM on Muen Return error if trying to create SMP VM as VMs with multiple CPUs are currently not supported on hw_x86_64_muen. * Add Muen-specific Mem_region type On hw_x86_64_muen the guest memory layout is static, thus regions are handed out from an array of memory regions. Use sinfo API to calculate the base address of the VM RAM physical 0x0 region. This allows to dynamically modify the VM RAM size by adjusting the Muen policy and Genode vbox files accordingly. Zeroize all memory regions apart from VM Ram since Virtualbox expects these regions to be cleared. * Add Muen subject state struct The subject state encompasses the guest VM machine state that is transfered between Virtualbox and hardware accelerated execution on Muen. * Add Muen-specific Vm_handler class * Use Vm_handler to run VM * Instruct recompiler to flush its code cache * Copy the Muen subject state to/from the Vbox PCPUMCTX. * Use the VM interruptibility state to inform the recompiler whether interrupts are currently inhibited. * Explicitly handle control register access If a VM-exit occurs due to a control register access, handle it and directly continue hardware accelerated execution of guest VM. Note: On NOVA control register accesses are handled by the kernel [1]. [1] - https://github.com/alex-ab/NOVA/blob/master/src/ec_vmx.cpp#L106 * Reset guest interruptibility state Assert that interrupts are not inhibited in the Virtualbox machine state and clear Blocking-by-[STI|MOV to SS] guest interruptibility flags prior to running a guest VM in hwaccel mode. * Set return code depending on exit reason Do not unconditionally emulate the next instruction on VM exit. This makes sharing the VM FPU state with Virtualbox unnecessary, as FPU instructions are not emulated by the recompiler any longer. Also, assert that the FPU has not been used by the recompiler * Inject pending guest VM interrupts on Muen Use mapped subject pending interrupts page of guest VM to perform interrupt injection. IRQs are transferred from the Virtualbox trap manager state to the pending interrupts region for injection. If an IRQ remains pending upon returning to the recompiler, it is copied back to the trap manager state and cleared in the subject interrupts region. * Inform recompiler about changed SYSENTER_[CS|EIP|ESP] values, otherwise values set while running the guest VM hardware accelerated may get lost. * Implement genode_cpu_hz() on Muen Determine the CPU frequency dynamically using the sinfo API. Issue #2016
2015-06-02 19:46:50 +02:00
: "+m" (*(char *)_base)
: "Ir" ((uint32_t)irq)
: "memory");
}
/**
* Clear bit corresponding to given IRQ in pending interrupts region.
*/
void clear_pending_interrupt(uint8_t irq)
{
asm volatile ("btr %1, %0"
vbox: Implement hwaccl support for Muen * Implement VMMR0_DO_VMMR0_INIT operation for Muen - Indicate VT-x support - Enable unrestricted guest mode - Set CR[0|4] mask to enable masking of guest CR0.[NE,NW,CD] and CR4.VMXE bits. * Implement VMMR0_DO_GVMM_CREATE_VM on Muen Return error if trying to create SMP VM as VMs with multiple CPUs are currently not supported on hw_x86_64_muen. * Add Muen-specific Mem_region type On hw_x86_64_muen the guest memory layout is static, thus regions are handed out from an array of memory regions. Use sinfo API to calculate the base address of the VM RAM physical 0x0 region. This allows to dynamically modify the VM RAM size by adjusting the Muen policy and Genode vbox files accordingly. Zeroize all memory regions apart from VM Ram since Virtualbox expects these regions to be cleared. * Add Muen subject state struct The subject state encompasses the guest VM machine state that is transfered between Virtualbox and hardware accelerated execution on Muen. * Add Muen-specific Vm_handler class * Use Vm_handler to run VM * Instruct recompiler to flush its code cache * Copy the Muen subject state to/from the Vbox PCPUMCTX. * Use the VM interruptibility state to inform the recompiler whether interrupts are currently inhibited. * Explicitly handle control register access If a VM-exit occurs due to a control register access, handle it and directly continue hardware accelerated execution of guest VM. Note: On NOVA control register accesses are handled by the kernel [1]. [1] - https://github.com/alex-ab/NOVA/blob/master/src/ec_vmx.cpp#L106 * Reset guest interruptibility state Assert that interrupts are not inhibited in the Virtualbox machine state and clear Blocking-by-[STI|MOV to SS] guest interruptibility flags prior to running a guest VM in hwaccel mode. * Set return code depending on exit reason Do not unconditionally emulate the next instruction on VM exit. This makes sharing the VM FPU state with Virtualbox unnecessary, as FPU instructions are not emulated by the recompiler any longer. Also, assert that the FPU has not been used by the recompiler * Inject pending guest VM interrupts on Muen Use mapped subject pending interrupts page of guest VM to perform interrupt injection. IRQs are transferred from the Virtualbox trap manager state to the pending interrupts region for injection. If an IRQ remains pending upon returning to the recompiler, it is copied back to the trap manager state and cleared in the subject interrupts region. * Inform recompiler about changed SYSENTER_[CS|EIP|ESP] values, otherwise values set while running the guest VM hardware accelerated may get lost. * Implement genode_cpu_hz() on Muen Determine the CPU frequency dynamically using the sinfo API. Issue #2016
2015-06-02 19:46:50 +02:00
: "+m" (*(char *)_base)
: "Ir" ((uint32_t)irq)
: "memory");
}
};
#endif /* _VIRTUALBOX__SPEC__MUEN__INTERRUPTS_H_ */