Skip to content

Commit

Permalink
x86: Factor out vmx_handle_cpuid
Browse files Browse the repository at this point in the history
Shortens vcpu_handle_exit and improves readability.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
  • Loading branch information
jan-kiszka committed Apr 10, 2015
1 parent 511fcdb commit f5132aa
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions hypervisor/arch/x86/vmx.c
Expand Up @@ -879,6 +879,20 @@ void vcpu_skip_emulated_instruction(unsigned int inst_len)
vmcs_write64(GUEST_RIP, vmcs_read64(GUEST_RIP) + inst_len);
}

static void vmx_handle_cpuid(union registers *guest_regs)
{
/* clear upper 32 bits of the involved registers */
guest_regs->rax &= 0xffffffff;
guest_regs->rbx &= 0xffffffff;
guest_regs->rcx &= 0xffffffff;
guest_regs->rdx &= 0xffffffff;

cpuid((u32 *)&guest_regs->rax, (u32 *)&guest_regs->rbx,
(u32 *)&guest_regs->rcx, (u32 *)&guest_regs->rdx);

vcpu_skip_emulated_instruction(X86_INST_LEN_CPUID);
}

static void update_efer(void)
{
unsigned long efer = vmcs_read64(GUEST_IA32_EFER);
Expand Down Expand Up @@ -1059,13 +1073,7 @@ void vcpu_handle_exit(struct per_cpu *cpu_data)
iommu_check_pending_faults(cpu_data);
return;
case EXIT_REASON_CPUID:
vcpu_skip_emulated_instruction(X86_INST_LEN_CPUID);
guest_regs->rax &= 0xffffffff;
guest_regs->rbx &= 0xffffffff;
guest_regs->rcx &= 0xffffffff;
guest_regs->rdx &= 0xffffffff;
cpuid((u32 *)&guest_regs->rax, (u32 *)&guest_regs->rbx,
(u32 *)&guest_regs->rcx, (u32 *)&guest_regs->rdx);
vmx_handle_cpuid(&cpu_data->guest_regs);
return;
case EXIT_REASON_VMCALL:
vcpu_handle_hypercall();
Expand Down

0 comments on commit f5132aa

Please sign in to comment.