Skip to content
This repository has been archived by the owner on Jan 28, 2023. It is now read-only.

Move selector validity checking to vcpu_set_regs #250

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions core/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,29 +370,6 @@ int cpu_vmx_execute(struct vcpu_t *vcpu, struct hax_tunnel *htun)
vcpu_handle_vmcs_pending(vcpu);
vcpu_inject_intr(vcpu, htun);

/* sometimes, the code segment type from qemu can be 10 (code segment),
* this will cause invalid guest state, since 11 (accessed code segment),
* not 10 is required by vmx hardware. Note: 11 is one of the allowed
* values by vmx hardware.
*/
{
uint32_t temp= vmread(vcpu, GUEST_CS_AR);

if( (temp & 0xf) == 0xa) {
temp = temp +1;
vmwrite(vcpu, GUEST_CS_AR, temp);
}
}
/* sometimes, the TSS segment type from qemu is not right.
* let's hard-code it for now
*/
{
uint32_t temp = vmread(vcpu, GUEST_TR_AR);

temp = (temp & ~0xf) | 0xb;
vmwrite(vcpu, GUEST_TR_AR, temp);
}

res = cpu_vmx_run(vcpu, htun);
if (res) {
hax_log(HAX_LOGE, "cpu_vmx_run error, code:%x\n", res);
Expand Down
13 changes: 13 additions & 0 deletions core/vcpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -4107,6 +4107,19 @@ int vcpu_set_regs(struct vcpu_t *vcpu, struct vcpu_state_t *ustate)
vcpu->dr_dirty = 0;
}

/* sometimes, the code segment type from qemu can be 10 (code segment),
* this will cause invalid guest state, since 11 (accessed code segment),
* not 10 is required by vmx hardware. Note: 11 is one of the allowed
* values by vmx hardware.
*/
if( (state->_cs.ar & 0xf) == 0xa)
state->_cs.ar = state->_cs.ar +1;

/* sometimes, the TSS segment type from qemu is not right.
* let's hard-code it for now
*/
state->_tr.ar = (state->_tr.ar & ~0xf) | 0xb;

UPDATE_SEGMENT_STATE(CS, _cs);
UPDATE_SEGMENT_STATE(DS, _ds);
UPDATE_SEGMENT_STATE(ES, _es);
Expand Down