Commit 6de12732 authored by Avi Kivity's avatar Avi Kivity

KVM: VMX: Optimize vmx_get_rflags()

If called several times within the same exit, return cached results.
Signed-off-by: default avatarAvi Kivity <avi@redhat.com>
parent f6e78475
...@@ -118,6 +118,7 @@ enum kvm_reg { ...@@ -118,6 +118,7 @@ enum kvm_reg {
enum kvm_reg_ex { enum kvm_reg_ex {
VCPU_EXREG_PDPTR = NR_VCPU_REGS, VCPU_EXREG_PDPTR = NR_VCPU_REGS,
VCPU_EXREG_CR3, VCPU_EXREG_CR3,
VCPU_EXREG_RFLAGS,
}; };
enum { enum {
......
...@@ -130,6 +130,7 @@ struct vcpu_vmx { ...@@ -130,6 +130,7 @@ struct vcpu_vmx {
u8 fail; u8 fail;
u32 exit_intr_info; u32 exit_intr_info;
u32 idt_vectoring_info; u32 idt_vectoring_info;
ulong rflags;
struct shared_msr_entry *guest_msrs; struct shared_msr_entry *guest_msrs;
int nmsrs; int nmsrs;
int save_nmsrs; int save_nmsrs;
...@@ -970,17 +971,23 @@ static unsigned long vmx_get_rflags(struct kvm_vcpu *vcpu) ...@@ -970,17 +971,23 @@ static unsigned long vmx_get_rflags(struct kvm_vcpu *vcpu)
{ {
unsigned long rflags, save_rflags; unsigned long rflags, save_rflags;
rflags = vmcs_readl(GUEST_RFLAGS); if (!test_bit(VCPU_EXREG_RFLAGS, (ulong *)&vcpu->arch.regs_avail)) {
if (to_vmx(vcpu)->rmode.vm86_active) { __set_bit(VCPU_EXREG_RFLAGS, (ulong *)&vcpu->arch.regs_avail);
rflags &= RMODE_GUEST_OWNED_EFLAGS_BITS; rflags = vmcs_readl(GUEST_RFLAGS);
save_rflags = to_vmx(vcpu)->rmode.save_rflags; if (to_vmx(vcpu)->rmode.vm86_active) {
rflags |= save_rflags & ~RMODE_GUEST_OWNED_EFLAGS_BITS; rflags &= RMODE_GUEST_OWNED_EFLAGS_BITS;
save_rflags = to_vmx(vcpu)->rmode.save_rflags;
rflags |= save_rflags & ~RMODE_GUEST_OWNED_EFLAGS_BITS;
}
to_vmx(vcpu)->rflags = rflags;
} }
return rflags; return to_vmx(vcpu)->rflags;
} }
static void vmx_set_rflags(struct kvm_vcpu *vcpu, unsigned long rflags) static void vmx_set_rflags(struct kvm_vcpu *vcpu, unsigned long rflags)
{ {
__set_bit(VCPU_EXREG_RFLAGS, (ulong *)&vcpu->arch.regs_avail);
to_vmx(vcpu)->rflags = rflags;
if (to_vmx(vcpu)->rmode.vm86_active) { if (to_vmx(vcpu)->rmode.vm86_active) {
to_vmx(vcpu)->rmode.save_rflags = rflags; to_vmx(vcpu)->rmode.save_rflags = rflags;
rflags |= X86_EFLAGS_IOPL | X86_EFLAGS_VM; rflags |= X86_EFLAGS_IOPL | X86_EFLAGS_VM;
...@@ -4124,6 +4131,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu) ...@@ -4124,6 +4131,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
); );
vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP) vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
| (1 << VCPU_EXREG_RFLAGS)
| (1 << VCPU_EXREG_PDPTR) | (1 << VCPU_EXREG_PDPTR)
| (1 << VCPU_EXREG_CR3)); | (1 << VCPU_EXREG_CR3));
vcpu->arch.regs_dirty = 0; vcpu->arch.regs_dirty = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment