hv: exception: fault type exception should set resume flag in rflags

According to SDM 17.3.1.1, for any fault-class exception except a
debug exception generated in response to an instruction breakpoint,
the value pushed for RF is 1.

This patch set Resume Flag for fault class exceptions.

Tracked-On: #2405
Signed-off-by: Binbin Wu <binbin.wu@intel.com>
Acked-by: Anthony Xu <anthony.xu@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
Binbin Wu 2019-01-23 07:12:49 +00:00 committed by wenlingz
parent 2638518349
commit 827fffedda
2 changed files with 33 additions and 0 deletions

View File

@ -14,6 +14,12 @@
#define EXCEPTION_CLASS_CONT 2
#define EXCEPTION_CLASS_PF 3
/* Exception types */
#define EXCEPTION_FAULT 0U
#define EXCEPTION_TRAP 1U
#define EXCEPTION_ABORT 2U
#define EXCEPTION_INTERRUPT 3U
static const uint16_t exception_type[32] = {
[0] = VMX_INT_TYPE_HW_EXP,
[1] = VMX_INT_TYPE_HW_EXP,
@ -49,6 +55,24 @@ static const uint16_t exception_type[32] = {
[31] = VMX_INT_TYPE_HW_EXP
};
static uint8_t get_exception_type(uint32_t vector)
{
uint8_t type;
/* Treat #DB as trap until decide to support Debug Registers */
if ((vector > 31U) || (vector == IDT_NMI)) {
type = EXCEPTION_INTERRUPT;
} else if ((vector == IDT_DB) || (vector == IDT_BP) || (vector == IDT_OF)) {
type = EXCEPTION_TRAP;
} else if ((vector == IDT_DF) || (vector == IDT_MC)) {
type = EXCEPTION_ABORT;
} else {
type = EXCEPTION_FAULT;
}
return type;
}
static bool is_guest_irq_enabled(struct acrn_vcpu *vcpu)
{
uint64_t guest_rflags, guest_state;
@ -254,6 +278,14 @@ static void vcpu_inject_exception(struct acrn_vcpu *vcpu, uint32_t vector)
/* retain rip for exception injection */
vcpu_retain_rip(vcpu);
/* SDM 17.3.1.1 For any fault-class exception except a debug exception generated in response to an
* instruction breakpoint, the value pushed for RF is 1.
* #DB is treated as Trap in get_exception_type, so RF will not be set for instruction breakpoint.
*/
if (get_exception_type(vector) == EXCEPTION_FAULT) {
vcpu_set_rflags(vcpu, vcpu_get_rflags(vcpu) | HV_ARCH_VCPU_RFLAGS_RF);
}
}
static int32_t vcpu_inject_hi_exception(struct acrn_vcpu *vcpu)

View File

@ -107,6 +107,7 @@ uint32_t irq_to_vector(uint32_t irq);
/* RFLAGS */
#define HV_ARCH_VCPU_RFLAGS_IF (1UL<<9U)
#define HV_ARCH_VCPU_RFLAGS_RF (1UL<<16U)
/* Interruptability State info */
#define HV_ARCH_VCPU_BLOCKED_BY_MOVSS (1UL<<1U)