[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 5/5] hvf: save away type as well as vector so we can reinject
From: |
Cameron Esfahani |
Subject: |
[PATCH v2 5/5] hvf: save away type as well as vector so we can reinject them |
Date: |
Sun, 24 Nov 2019 12:05:27 -0800 |
Save away type as well as vector in hvf_store_events() so we can
correctly reinject both in hvf_inject_interrupts().
Make sure to clear ins_len and has_error_code when ins_len isn't
valid and error_code isn't set.
Signed-off-by: Cameron Esfahani <address@hidden>
---
target/i386/hvf/hvf.c | 18 ++++++++++++++----
target/i386/hvf/x86hvf.c | 22 ++++++++++------------
2 files changed, 24 insertions(+), 16 deletions(-)
diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c
index 784e67d77e..8a8aee4495 100644
--- a/target/i386/hvf/hvf.c
+++ b/target/i386/hvf/hvf.c
@@ -641,14 +641,18 @@ static void hvf_store_events(CPUState *cpu, uint32_t
ins_len, uint64_t idtvec_in
switch (idtvec_info & VMCS_IDT_VEC_TYPE) {
case VMCS_IDT_VEC_HWINTR:
case VMCS_IDT_VEC_SWINTR:
- env->interrupt_injected = idtvec_info & VMCS_IDT_VEC_VECNUM;
+ /* Save event type as well so we can inject the correct type. */
+ env->interrupt_injected =
+ idtvec_info & (VMCS_IDT_VEC_TYPE | VMCS_IDT_VEC_VECNUM);
break;
case VMCS_IDT_VEC_NMI:
env->nmi_injected = true;
break;
case VMCS_IDT_VEC_HWEXCEPTION:
case VMCS_IDT_VEC_SWEXCEPTION:
- env->exception_nr = idtvec_info & VMCS_IDT_VEC_VECNUM;
+ /* Save event type as well so we can inject the correct type. */
+ env->exception_nr =
+ idtvec_info & (VMCS_IDT_VEC_TYPE | VMCS_IDT_VEC_VECNUM);
env->exception_injected = 1;
break;
case VMCS_IDT_VEC_PRIV_SWEXCEPTION:
@@ -658,10 +662,16 @@ static void hvf_store_events(CPUState *cpu, uint32_t
ins_len, uint64_t idtvec_in
if ((idtvec_info & VMCS_IDT_VEC_TYPE) == VMCS_IDT_VEC_SWEXCEPTION ||
(idtvec_info & VMCS_IDT_VEC_TYPE) == VMCS_IDT_VEC_SWINTR) {
env->ins_len = ins_len;
+ } else {
+ /* Clear ins_len when it isn't valid. */
+ env->ins_len = 0;
}
- if (idtvec_info & VMCS_INTR_DEL_ERRCODE) {
+ if (idtvec_info & VMCS_IDT_VEC_ERRCODE_VALID) {
env->has_error_code = true;
env->error_code = rvmcs(cpu->hvf_fd, VMCS_IDT_VECTORING_ERROR);
+ } else {
+ /* Clear has_error_code when error_code isn't valid. */
+ env->has_error_code = false;
}
}
if ((rvmcs(cpu->hvf_fd, VMCS_GUEST_INTERRUPTIBILITY) &
@@ -942,7 +952,7 @@ int hvf_vcpu_exec(CPUState *cpu)
macvm_set_rip(cpu, rip + ins_len);
break;
case VMX_REASON_VMCALL:
- env->exception_nr = EXCP0D_GPF;
+ env->exception_nr = VMCS_INTR_T_HWEXCEPTION | EXCP0D_GPF;
env->exception_injected = 1;
env->has_error_code = true;
env->error_code = 0;
diff --git a/target/i386/hvf/x86hvf.c b/target/i386/hvf/x86hvf.c
index 1485b95776..d25ae4585b 100644
--- a/target/i386/hvf/x86hvf.c
+++ b/target/i386/hvf/x86hvf.c
@@ -345,8 +345,6 @@ void vmx_clear_int_window_exiting(CPUState *cpu)
~VMCS_PRI_PROC_BASED_CTLS_INT_WINDOW_EXITING);
}
-#define NMI_VEC 2
-
bool hvf_inject_interrupts(CPUState *cpu_state)
{
X86CPU *x86cpu = X86_CPU(cpu_state);
@@ -356,17 +354,15 @@ bool hvf_inject_interrupts(CPUState *cpu_state)
uint64_t intr_type;
bool have_event = true;
if (env->interrupt_injected != -1) {
- vector = env->interrupt_injected;
- intr_type = VMCS_INTR_T_SWINTR;
+ /* Type and vector are both saved in interrupt_injected. */
+ vector = env->interrupt_injected & VMCS_IDT_VEC_VECNUM;
+ intr_type = env->interrupt_injected & VMCS_IDT_VEC_TYPE;
} else if (env->exception_nr != -1) {
- vector = env->exception_nr;
- if (vector == EXCP03_INT3 || vector == EXCP04_INTO) {
- intr_type = VMCS_INTR_T_SWEXCEPTION;
- } else {
- intr_type = VMCS_INTR_T_HWEXCEPTION;
- }
+ /* Type and vector are both saved in exception_nr. */
+ vector = env->exception_nr & VMCS_IDT_VEC_VECNUM;
+ intr_type = env->exception_nr & VMCS_IDT_VEC_TYPE;
} else if (env->nmi_injected) {
- vector = NMI_VEC;
+ vector = EXCP02_NMI;
intr_type = VMCS_INTR_T_NMI;
} else {
have_event = false;
@@ -390,6 +386,8 @@ bool hvf_inject_interrupts(CPUState *cpu_state)
if (env->has_error_code) {
wvmcs(cpu_state->hvf_fd, VMCS_ENTRY_EXCEPTION_ERROR,
env->error_code);
+ /* Indicate that VMCS_ENTRY_EXCEPTION_ERROR is valid */
+ info |= VMCS_INTR_DEL_ERRCODE;
}
/*printf("reinject %lx err %d\n", info, err);*/
wvmcs(cpu_state->hvf_fd, VMCS_ENTRY_INTR_INFO, info);
@@ -399,7 +397,7 @@ bool hvf_inject_interrupts(CPUState *cpu_state)
if (cpu_state->interrupt_request & CPU_INTERRUPT_NMI) {
if (!(env->hflags2 & HF2_NMI_MASK) && !(info & VMCS_INTR_VALID)) {
cpu_state->interrupt_request &= ~CPU_INTERRUPT_NMI;
- info = VMCS_INTR_VALID | VMCS_INTR_T_NMI | NMI_VEC;
+ info = VMCS_INTR_VALID | VMCS_INTR_T_NMI | EXCP02_NMI;
wvmcs(cpu_state->hvf_fd, VMCS_ENTRY_INTR_INFO, info);
} else {
vmx_set_nmi_window_exiting(cpu_state);
--
2.24.0
- [PATCH v2 0/5] hvf: stability fixes for HVF, Cameron Esfahani, 2019/11/24
- [PATCH v2 4/5] hvf: more accurately match SDM when setting CR0 and PDPTE registers, Cameron Esfahani, 2019/11/24
- [PATCH v2 2/5] hvf: remove TSC synchronization code because it isn't fully complete, Cameron Esfahani, 2019/11/24
- [PATCH v2 3/5] hvf: correctly handle REX prefix in relation to legacy prefixes, Cameron Esfahani, 2019/11/24
- [PATCH v2 5/5] hvf: save away type as well as vector so we can reinject them,
Cameron Esfahani <=
- Re: [PATCH v2 5/5] hvf: save away type as well as vector so we can reinject them, Paolo Bonzini, 2019/11/25
- Re: [PATCH v2 5/5] hvf: save away type as well as vector so we can reinject them, Paolo Bonzini, 2019/11/28
- Re: [PATCH v2 5/5] hvf: save away type as well as vector so we can reinject them, Paolo Bonzini, 2019/11/28
- Re: [PATCH v2 5/5] hvf: save away type as well as vector so we can reinject them, Cameron Esfahani, 2019/11/30
- Re: [PATCH v2 5/5] hvf: save away type as well as vector so we can reinject them, Paolo Bonzini, 2019/11/30
[PATCH v2 1/5] hvf: non-RAM, non-ROMD memory ranges are now correctly mapped in, Cameron Esfahani, 2019/11/24
Re: [PATCH v2 0/5] hvf: stability fixes for HVF, Paolo Bonzini, 2019/11/25