Added VMEXIT instrumentation callback

Fixed possible RSP corruption in SMP mode - the speculative_rsp variable might be not reset properly
This commit is contained in:
Stanislav Shwartsman 2013-10-23 21:18:19 +00:00
parent 1fb469e77f
commit d9fc472ba7
11 changed files with 42 additions and 4 deletions

View File

@ -865,6 +865,7 @@ void BX_CPU_C::exception(unsigned vector, Bit16u error_code)
RIP = BX_CPU_THIS_PTR prev_rip;
if (BX_CPU_THIS_PTR speculative_rsp)
RSP = BX_CPU_THIS_PTR prev_rsp;
BX_CPU_THIS_PTR speculative_rsp = 0;
if (BX_CPU_THIS_PTR last_exception_type == BX_ET_DOUBLE_FAULT)
{

View File

@ -592,6 +592,7 @@ void BX_CPU_C::Svm_Vmexit(int reason, Bit64u exitinfo1, Bit64u exitinfo2)
RIP = BX_CPU_THIS_PTR prev_rip;
if (BX_CPU_THIS_PTR speculative_rsp)
RSP = BX_CPU_THIS_PTR prev_rsp;
BX_CPU_THIS_PTR speculative_rsp = 0;
if (BX_SUPPORT_SVM_EXTENSION(BX_CPUID_SVM_DECODE_ASSIST)) {
//

View File

@ -2408,6 +2408,8 @@ void BX_CPU_C::VMexit(Bit32u reason, Bit64u qualification)
BX_PANIC(("PANIC: VMEXIT not in VMX guest mode !"));
}
BX_INSTR_VMEXIT(BX_CPU_ID, reason, qualification);
//
// STEP 0: Update VMEXIT reason
//
@ -2446,6 +2448,7 @@ void BX_CPU_C::VMexit(Bit32u reason, Bit64u qualification)
if (BX_CPU_THIS_PTR speculative_rsp)
RSP = BX_CPU_THIS_PTR prev_rsp;
}
BX_CPU_THIS_PTR speculative_rsp = 0;
//
// STEP 1: Saving Guest State to VMCS

View File

@ -88,8 +88,8 @@ void bx_print_instruction(unsigned cpu, const instruction_t *i)
if(length != 0)
{
fprintf(stderr, "----------------------------------------------------------\n");
fprintf(stderr, "CPU: %d: %s\n", cpu, disasm_tbuf);
fprintf(stderr, "LEN: %d\tBYTES: ", length);
fprintf(stderr, "CPU %d: %s\n", cpu, disasm_tbuf);
fprintf(stderr, "LEN %d\tBYTES: ", length);
for(n=0;n < length;n++) fprintf(stderr, "%02x", i->opcode[n]);
if(i->is_branch)
{

View File

@ -104,6 +104,9 @@ void bx_instr_lin_access(unsigned cpu, bx_address lin, bx_phy_address phy, unsig
/* wrmsr callback */
#define BX_INSTR_WRMSR(cpu_id, addr, value)
/* vmexit callback */
#define BX_INSTR_VMEXIT(cpu_id, reason, qualification)
#else // BX_INSTRUMENTATION
/* initialization/deinitialization of instrumentalization */
@ -160,4 +163,7 @@ void bx_instr_lin_access(unsigned cpu, bx_address lin, bx_phy_address phy, unsig
/* wrmsr callback */
#define BX_INSTR_WRMSR(cpu_id, addr, value)
/* vmexit callback */
#define BX_INSTR_VMEXIT(cpu_id, reason, qualification)
#endif // BX_INSTRUMENTATION

View File

@ -61,8 +61,8 @@ void bxInstrumentation::bx_print_instruction(void)
unsigned n;
fprintf(stderr, "----------------------------------------------------------\n");
fprintf(stderr, "CPU: %d: %s\n", cpu_id, disasm_tbuf);
fprintf(stderr, "LEN: %d\tBYTES: ", opcode_length);
fprintf(stderr, "CPU %d: %s\n", cpu_id, disasm_tbuf);
fprintf(stderr, "LEN %d\tBYTES: ", opcode_length);
for(n=0;n < opcode_length;n++) fprintf(stderr, "%02x", opcode[n]);
if(is_branch)
{

View File

@ -155,6 +155,9 @@ extern bxInstrumentation *icpu;
/* wrmsr callback */
#define BX_INSTR_WRMSR(cpu_id, addr, value)
/* vmexit callback */
#define BX_INSTR_VMEXIT(cpu_id, reason, qualification)
#else // BX_INSTRUMENTATION
/* initialization/deinitialization of instrumentalization */
@ -211,4 +214,7 @@ extern bxInstrumentation *icpu;
/* wrmsr callback */
#define BX_INSTR_WRMSR(cpu_id, addr, value)
/* vmexit callback */
#define BX_INSTR_VMEXIT(cpu_id, reason, qualification)
#endif // BX_INSTRUMENTATION

View File

@ -95,6 +95,9 @@ void bx_instr_before_execution(unsigned cpu, bxInstruction_c *i);
/* wrmsr callback */
#define BX_INSTR_WRMSR(cpu_id, addr, value)
/* vmexit callback */
#define BX_INSTR_VMEXIT(cpu_id, reason, qualification)
#else // BX_INSTRUMENTATION
/* initialization/deinitialization of instrumentalization */
@ -152,4 +155,7 @@ void bx_instr_before_execution(unsigned cpu, bxInstruction_c *i);
/* wrmsr callback */
#define BX_INSTR_WRMSR(cpu_id, addr, value)
/* vmexit callback */
#define BX_INSTR_VMEXIT(cpu_id, reason, qualification)
#endif // BX_INSTRUMENTATION

View File

@ -104,6 +104,11 @@ Possible operation types, passed through bx_instr_ucnear_branch and bx_instr_far
#define BX_INSTR_IS_SYSEXIT 20
void bx_instr_vmexit(unsigned cpu, Bit32u reason, Bit64u qualification);
This callback is called right before Bochs executes a VMEXIT.
void bx_instr_opcode(unsigned cpu, bxInstruction_c *i, const Bit8u *opcode, unsigned len, bx_bool is32, bx_bool is64);
The callback is called each time, when Bochs completes to decode a new

View File

@ -65,4 +65,6 @@ void bx_instr_phy_access(unsigned cpu, bx_address phy, unsigned len, unsigned rw
void bx_instr_wrmsr(unsigned cpu, unsigned addr, Bit64u value) {}
void bx_instr_vmexit(unsigned cpu, Bit32u reason, Bit64u qualification) {}
#endif

View File

@ -69,6 +69,8 @@ void bx_instr_phy_access(unsigned cpu, bx_address phy, unsigned len, unsigned rw
void bx_instr_wrmsr(unsigned cpu, unsigned addr, Bit64u value);
void bx_instr_vmexit(unsigned cpu, Bit32u reason, Bit64u qualification);
/* initialization/deinitialization of instrumentalization*/
#define BX_INSTR_INIT_ENV() bx_instr_init_env()
#define BX_INSTR_EXIT_ENV() bx_instr_exit_env()
@ -129,6 +131,9 @@ void bx_instr_wrmsr(unsigned cpu, unsigned addr, Bit64u value);
/* wrmsr callback */
#define BX_INSTR_WRMSR(cpu_id, addr, value) bx_instr_wrmsr(cpu_id, addr, value)
/* vmexit callback */
#define BX_INSTR_VMEXIT(cpu_id, reason, qualification) bx_instr_vmexit(cpu_id, reason, qualification)
#else
/* initialization/deinitialization of instrumentalization */
@ -185,4 +190,7 @@ void bx_instr_wrmsr(unsigned cpu, unsigned addr, Bit64u value);
/* wrmsr callback */
#define BX_INSTR_WRMSR(cpu_id, addr, value)
/* vmexit callback */
#define BX_INSTR_VMEXIT(cpu_id, reason, qualification)
#endif