diff options
author | Avi Kivity <avi@redhat.com> | 2010-07-29 08:11:50 -0400 |
---|---|---|
committer | Avi Kivity <avi@redhat.com> | 2010-10-24 04:50:21 -0400 |
commit | 9aabc88fc8687ba3a520e2ec459821d05f72474e (patch) | |
tree | 6e57c011a783af6a8a0e2ca92e3f55eb4d2701ae | |
parent | ab85b12b1a7fd125588f9447653a71ec8e1b5024 (diff) |
KVM: x86 emulator: store x86_emulate_ops in emulation context
It doesn't ever change, so we don't need to pass it around everywhere.
Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
-rw-r--r-- | arch/x86/include/asm/kvm_emulate.h | 9 | ||||
-rw-r--r-- | arch/x86/kvm/emulate.c | 8 | ||||
-rw-r--r-- | arch/x86/kvm/x86.c | 7 |
3 files changed, 13 insertions, 11 deletions
diff --git a/arch/x86/include/asm/kvm_emulate.h b/arch/x86/include/asm/kvm_emulate.h index 1f99ecfc48e1..9ddfa5ed2289 100644 --- a/arch/x86/include/asm/kvm_emulate.h +++ b/arch/x86/include/asm/kvm_emulate.h | |||
@@ -208,6 +208,8 @@ struct decode_cache { | |||
208 | }; | 208 | }; |
209 | 209 | ||
210 | struct x86_emulate_ctxt { | 210 | struct x86_emulate_ctxt { |
211 | struct x86_emulate_ops *ops; | ||
212 | |||
211 | /* Register state before/after emulation. */ | 213 | /* Register state before/after emulation. */ |
212 | struct kvm_vcpu *vcpu; | 214 | struct kvm_vcpu *vcpu; |
213 | 215 | ||
@@ -249,12 +251,9 @@ struct x86_emulate_ctxt { | |||
249 | #define X86EMUL_MODE_HOST X86EMUL_MODE_PROT64 | 251 | #define X86EMUL_MODE_HOST X86EMUL_MODE_PROT64 |
250 | #endif | 252 | #endif |
251 | 253 | ||
252 | int x86_decode_insn(struct x86_emulate_ctxt *ctxt, | 254 | int x86_decode_insn(struct x86_emulate_ctxt *ctxt); |
253 | struct x86_emulate_ops *ops); | 255 | int x86_emulate_insn(struct x86_emulate_ctxt *ctxt); |
254 | int x86_emulate_insn(struct x86_emulate_ctxt *ctxt, | ||
255 | struct x86_emulate_ops *ops); | ||
256 | int emulator_task_switch(struct x86_emulate_ctxt *ctxt, | 256 | int emulator_task_switch(struct x86_emulate_ctxt *ctxt, |
257 | struct x86_emulate_ops *ops, | ||
258 | u16 tss_selector, int reason, | 257 | u16 tss_selector, int reason, |
259 | bool has_error_code, u32 error_code); | 258 | bool has_error_code, u32 error_code); |
260 | 259 | ||
diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index d7e3ea4797f1..3689f34a303a 100644 --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c | |||
@@ -943,8 +943,9 @@ done: | |||
943 | } | 943 | } |
944 | 944 | ||
945 | int | 945 | int |
946 | x86_decode_insn(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops) | 946 | x86_decode_insn(struct x86_emulate_ctxt *ctxt) |
947 | { | 947 | { |
948 | struct x86_emulate_ops *ops = ctxt->ops; | ||
948 | struct decode_cache *c = &ctxt->decode; | 949 | struct decode_cache *c = &ctxt->decode; |
949 | int rc = X86EMUL_CONTINUE; | 950 | int rc = X86EMUL_CONTINUE; |
950 | int mode = ctxt->mode; | 951 | int mode = ctxt->mode; |
@@ -2586,10 +2587,10 @@ static int emulator_do_task_switch(struct x86_emulate_ctxt *ctxt, | |||
2586 | } | 2587 | } |
2587 | 2588 | ||
2588 | int emulator_task_switch(struct x86_emulate_ctxt *ctxt, | 2589 | int emulator_task_switch(struct x86_emulate_ctxt *ctxt, |
2589 | struct x86_emulate_ops *ops, | ||
2590 | u16 tss_selector, int reason, | 2590 | u16 tss_selector, int reason, |
2591 | bool has_error_code, u32 error_code) | 2591 | bool has_error_code, u32 error_code) |
2592 | { | 2592 | { |
2593 | struct x86_emulate_ops *ops = ctxt->ops; | ||
2593 | struct decode_cache *c = &ctxt->decode; | 2594 | struct decode_cache *c = &ctxt->decode; |
2594 | int rc; | 2595 | int rc; |
2595 | 2596 | ||
@@ -2619,8 +2620,9 @@ static void string_addr_inc(struct x86_emulate_ctxt *ctxt, unsigned long base, | |||
2619 | } | 2620 | } |
2620 | 2621 | ||
2621 | int | 2622 | int |
2622 | x86_emulate_insn(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops) | 2623 | x86_emulate_insn(struct x86_emulate_ctxt *ctxt) |
2623 | { | 2624 | { |
2625 | struct x86_emulate_ops *ops = ctxt->ops; | ||
2624 | u64 msr_data; | 2626 | u64 msr_data; |
2625 | struct decode_cache *c = &ctxt->decode; | 2627 | struct decode_cache *c = &ctxt->decode; |
2626 | int rc = X86EMUL_CONTINUE; | 2628 | int rc = X86EMUL_CONTINUE; |
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 3a09c625d526..33deb75f16ee 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c | |||
@@ -3998,7 +3998,7 @@ int emulate_instruction(struct kvm_vcpu *vcpu, | |||
3998 | vcpu->arch.emulate_ctxt.interruptibility = 0; | 3998 | vcpu->arch.emulate_ctxt.interruptibility = 0; |
3999 | vcpu->arch.emulate_ctxt.exception = -1; | 3999 | vcpu->arch.emulate_ctxt.exception = -1; |
4000 | 4000 | ||
4001 | r = x86_decode_insn(&vcpu->arch.emulate_ctxt, &emulate_ops); | 4001 | r = x86_decode_insn(&vcpu->arch.emulate_ctxt); |
4002 | trace_kvm_emulate_insn_start(vcpu); | 4002 | trace_kvm_emulate_insn_start(vcpu); |
4003 | 4003 | ||
4004 | /* Only allow emulation of specific instructions on #UD | 4004 | /* Only allow emulation of specific instructions on #UD |
@@ -4048,7 +4048,7 @@ int emulate_instruction(struct kvm_vcpu *vcpu, | |||
4048 | memcpy(c->regs, vcpu->arch.regs, sizeof c->regs); | 4048 | memcpy(c->regs, vcpu->arch.regs, sizeof c->regs); |
4049 | 4049 | ||
4050 | restart: | 4050 | restart: |
4051 | r = x86_emulate_insn(&vcpu->arch.emulate_ctxt, &emulate_ops); | 4051 | r = x86_emulate_insn(&vcpu->arch.emulate_ctxt); |
4052 | 4052 | ||
4053 | if (r) { /* emulation failed */ | 4053 | if (r) { /* emulation failed */ |
4054 | if (reexecute_instruction(vcpu, cr2)) | 4054 | if (reexecute_instruction(vcpu, cr2)) |
@@ -5067,7 +5067,7 @@ int kvm_task_switch(struct kvm_vcpu *vcpu, u16 tss_selector, int reason, | |||
5067 | memset(c, 0, sizeof(struct decode_cache)); | 5067 | memset(c, 0, sizeof(struct decode_cache)); |
5068 | memcpy(c->regs, vcpu->arch.regs, sizeof c->regs); | 5068 | memcpy(c->regs, vcpu->arch.regs, sizeof c->regs); |
5069 | 5069 | ||
5070 | ret = emulator_task_switch(&vcpu->arch.emulate_ctxt, &emulate_ops, | 5070 | ret = emulator_task_switch(&vcpu->arch.emulate_ctxt, |
5071 | tss_selector, reason, has_error_code, | 5071 | tss_selector, reason, has_error_code, |
5072 | error_code); | 5072 | error_code); |
5073 | 5073 | ||
@@ -5424,6 +5424,7 @@ int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu) | |||
5424 | BUG_ON(vcpu->kvm == NULL); | 5424 | BUG_ON(vcpu->kvm == NULL); |
5425 | kvm = vcpu->kvm; | 5425 | kvm = vcpu->kvm; |
5426 | 5426 | ||
5427 | vcpu->arch.emulate_ctxt.ops = &emulate_ops; | ||
5427 | vcpu->arch.mmu.root_hpa = INVALID_PAGE; | 5428 | vcpu->arch.mmu.root_hpa = INVALID_PAGE; |
5428 | if (!irqchip_in_kernel(kvm) || kvm_vcpu_is_bsp(vcpu)) | 5429 | if (!irqchip_in_kernel(kvm) || kvm_vcpu_is_bsp(vcpu)) |
5429 | vcpu->arch.mp_state = KVM_MP_STATE_RUNNABLE; | 5430 | vcpu->arch.mp_state = KVM_MP_STATE_RUNNABLE; |