diff options
author | Avi Kivity <avi@redhat.com> | 2011-04-20 06:37:53 -0400 |
---|---|---|
committer | Avi Kivity <avi@redhat.com> | 2011-05-11 07:57:10 -0400 |
commit | 0f65dd70a442ff498da10cec0a599fbd9d2d6f9e (patch) | |
tree | a460005086619e5959242404c8cd7be0d766de3d /arch/x86/kvm/x86.c | |
parent | 7295261cdd42e6d41666df38d1b613cdd9e95f46 (diff) |
KVM: x86 emulator: drop vcpu argument from memory read/write callbacks
Making the emulator caller agnostic.
Signed-off-by: Avi Kivity <avi@redhat.com>
Diffstat (limited to 'arch/x86/kvm/x86.c')
-rw-r--r-- | arch/x86/kvm/x86.c | 54 |
1 files changed, 34 insertions, 20 deletions
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 6aa137701cda..274652ae6d52 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c | |||
@@ -63,6 +63,9 @@ | |||
63 | #define KVM_MAX_MCE_BANKS 32 | 63 | #define KVM_MAX_MCE_BANKS 32 |
64 | #define KVM_MCE_CAP_SUPPORTED (MCG_CTL_P | MCG_SER_P) | 64 | #define KVM_MCE_CAP_SUPPORTED (MCG_CTL_P | MCG_SER_P) |
65 | 65 | ||
66 | #define emul_to_vcpu(ctxt) \ | ||
67 | container_of(ctxt, struct kvm_vcpu, arch.emulate_ctxt) | ||
68 | |||
66 | /* EFER defaults: | 69 | /* EFER defaults: |
67 | * - enable syscall per default because its emulated by KVM | 70 | * - enable syscall per default because its emulated by KVM |
68 | * - enable LME and LMA per default on 64 bit KVM | 71 | * - enable LME and LMA per default on 64 bit KVM |
@@ -3760,37 +3763,43 @@ out: | |||
3760 | } | 3763 | } |
3761 | 3764 | ||
3762 | /* used for instruction fetching */ | 3765 | /* used for instruction fetching */ |
3763 | static int kvm_fetch_guest_virt(gva_t addr, void *val, unsigned int bytes, | 3766 | static int kvm_fetch_guest_virt(struct x86_emulate_ctxt *ctxt, |
3764 | struct kvm_vcpu *vcpu, | 3767 | gva_t addr, void *val, unsigned int bytes, |
3765 | struct x86_exception *exception) | 3768 | struct x86_exception *exception) |
3766 | { | 3769 | { |
3770 | struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt); | ||
3767 | u32 access = (kvm_x86_ops->get_cpl(vcpu) == 3) ? PFERR_USER_MASK : 0; | 3771 | u32 access = (kvm_x86_ops->get_cpl(vcpu) == 3) ? PFERR_USER_MASK : 0; |
3772 | |||
3768 | return kvm_read_guest_virt_helper(addr, val, bytes, vcpu, | 3773 | return kvm_read_guest_virt_helper(addr, val, bytes, vcpu, |
3769 | access | PFERR_FETCH_MASK, | 3774 | access | PFERR_FETCH_MASK, |
3770 | exception); | 3775 | exception); |
3771 | } | 3776 | } |
3772 | 3777 | ||
3773 | static int kvm_read_guest_virt(gva_t addr, void *val, unsigned int bytes, | 3778 | static int kvm_read_guest_virt(struct x86_emulate_ctxt *ctxt, |
3774 | struct kvm_vcpu *vcpu, | 3779 | gva_t addr, void *val, unsigned int bytes, |
3775 | struct x86_exception *exception) | 3780 | struct x86_exception *exception) |
3776 | { | 3781 | { |
3782 | struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt); | ||
3777 | u32 access = (kvm_x86_ops->get_cpl(vcpu) == 3) ? PFERR_USER_MASK : 0; | 3783 | u32 access = (kvm_x86_ops->get_cpl(vcpu) == 3) ? PFERR_USER_MASK : 0; |
3784 | |||
3778 | return kvm_read_guest_virt_helper(addr, val, bytes, vcpu, access, | 3785 | return kvm_read_guest_virt_helper(addr, val, bytes, vcpu, access, |
3779 | exception); | 3786 | exception); |
3780 | } | 3787 | } |
3781 | 3788 | ||
3782 | static int kvm_read_guest_virt_system(gva_t addr, void *val, unsigned int bytes, | 3789 | static int kvm_read_guest_virt_system(struct x86_emulate_ctxt *ctxt, |
3783 | struct kvm_vcpu *vcpu, | 3790 | gva_t addr, void *val, unsigned int bytes, |
3784 | struct x86_exception *exception) | 3791 | struct x86_exception *exception) |
3785 | { | 3792 | { |
3793 | struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt); | ||
3786 | return kvm_read_guest_virt_helper(addr, val, bytes, vcpu, 0, exception); | 3794 | return kvm_read_guest_virt_helper(addr, val, bytes, vcpu, 0, exception); |
3787 | } | 3795 | } |
3788 | 3796 | ||
3789 | static int kvm_write_guest_virt_system(gva_t addr, void *val, | 3797 | static int kvm_write_guest_virt_system(struct x86_emulate_ctxt *ctxt, |
3798 | gva_t addr, void *val, | ||
3790 | unsigned int bytes, | 3799 | unsigned int bytes, |
3791 | struct kvm_vcpu *vcpu, | ||
3792 | struct x86_exception *exception) | 3800 | struct x86_exception *exception) |
3793 | { | 3801 | { |
3802 | struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt); | ||
3794 | void *data = val; | 3803 | void *data = val; |
3795 | int r = X86EMUL_CONTINUE; | 3804 | int r = X86EMUL_CONTINUE; |
3796 | 3805 | ||
@@ -3818,12 +3827,13 @@ out: | |||
3818 | return r; | 3827 | return r; |
3819 | } | 3828 | } |
3820 | 3829 | ||
3821 | static int emulator_read_emulated(unsigned long addr, | 3830 | static int emulator_read_emulated(struct x86_emulate_ctxt *ctxt, |
3831 | unsigned long addr, | ||
3822 | void *val, | 3832 | void *val, |
3823 | unsigned int bytes, | 3833 | unsigned int bytes, |
3824 | struct x86_exception *exception, | 3834 | struct x86_exception *exception) |
3825 | struct kvm_vcpu *vcpu) | ||
3826 | { | 3835 | { |
3836 | struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt); | ||
3827 | gpa_t gpa; | 3837 | gpa_t gpa; |
3828 | int handled; | 3838 | int handled; |
3829 | 3839 | ||
@@ -3844,7 +3854,7 @@ static int emulator_read_emulated(unsigned long addr, | |||
3844 | if ((gpa & PAGE_MASK) == APIC_DEFAULT_PHYS_BASE) | 3854 | if ((gpa & PAGE_MASK) == APIC_DEFAULT_PHYS_BASE) |
3845 | goto mmio; | 3855 | goto mmio; |
3846 | 3856 | ||
3847 | if (kvm_read_guest_virt(addr, val, bytes, vcpu, exception) | 3857 | if (kvm_read_guest_virt(ctxt, addr, val, bytes, exception) |
3848 | == X86EMUL_CONTINUE) | 3858 | == X86EMUL_CONTINUE) |
3849 | return X86EMUL_CONTINUE; | 3859 | return X86EMUL_CONTINUE; |
3850 | 3860 | ||
@@ -3933,12 +3943,14 @@ mmio: | |||
3933 | return X86EMUL_CONTINUE; | 3943 | return X86EMUL_CONTINUE; |
3934 | } | 3944 | } |
3935 | 3945 | ||
3936 | int emulator_write_emulated(unsigned long addr, | 3946 | int emulator_write_emulated(struct x86_emulate_ctxt *ctxt, |
3947 | unsigned long addr, | ||
3937 | const void *val, | 3948 | const void *val, |
3938 | unsigned int bytes, | 3949 | unsigned int bytes, |
3939 | struct x86_exception *exception, | 3950 | struct x86_exception *exception) |
3940 | struct kvm_vcpu *vcpu) | ||
3941 | { | 3951 | { |
3952 | struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt); | ||
3953 | |||
3942 | /* Crossing a page boundary? */ | 3954 | /* Crossing a page boundary? */ |
3943 | if (((addr + bytes - 1) ^ addr) & PAGE_MASK) { | 3955 | if (((addr + bytes - 1) ^ addr) & PAGE_MASK) { |
3944 | int rc, now; | 3956 | int rc, now; |
@@ -3966,13 +3978,14 @@ int emulator_write_emulated(unsigned long addr, | |||
3966 | (cmpxchg64((u64 *)(ptr), *(u64 *)(old), *(u64 *)(new)) == *(u64 *)(old)) | 3978 | (cmpxchg64((u64 *)(ptr), *(u64 *)(old), *(u64 *)(new)) == *(u64 *)(old)) |
3967 | #endif | 3979 | #endif |
3968 | 3980 | ||
3969 | static int emulator_cmpxchg_emulated(unsigned long addr, | 3981 | static int emulator_cmpxchg_emulated(struct x86_emulate_ctxt *ctxt, |
3982 | unsigned long addr, | ||
3970 | const void *old, | 3983 | const void *old, |
3971 | const void *new, | 3984 | const void *new, |
3972 | unsigned int bytes, | 3985 | unsigned int bytes, |
3973 | struct x86_exception *exception, | 3986 | struct x86_exception *exception) |
3974 | struct kvm_vcpu *vcpu) | ||
3975 | { | 3987 | { |
3988 | struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt); | ||
3976 | gpa_t gpa; | 3989 | gpa_t gpa; |
3977 | struct page *page; | 3990 | struct page *page; |
3978 | char *kaddr; | 3991 | char *kaddr; |
@@ -4028,7 +4041,7 @@ static int emulator_cmpxchg_emulated(unsigned long addr, | |||
4028 | emul_write: | 4041 | emul_write: |
4029 | printk_once(KERN_WARNING "kvm: emulating exchange as write\n"); | 4042 | printk_once(KERN_WARNING "kvm: emulating exchange as write\n"); |
4030 | 4043 | ||
4031 | return emulator_write_emulated(addr, new, bytes, exception, vcpu); | 4044 | return emulator_write_emulated(ctxt, addr, new, bytes, exception); |
4032 | } | 4045 | } |
4033 | 4046 | ||
4034 | static int kernel_pio(struct kvm_vcpu *vcpu, void *pd) | 4047 | static int kernel_pio(struct kvm_vcpu *vcpu, void *pd) |
@@ -5009,7 +5022,8 @@ int kvm_fix_hypercall(struct kvm_vcpu *vcpu) | |||
5009 | 5022 | ||
5010 | kvm_x86_ops->patch_hypercall(vcpu, instruction); | 5023 | kvm_x86_ops->patch_hypercall(vcpu, instruction); |
5011 | 5024 | ||
5012 | return emulator_write_emulated(rip, instruction, 3, NULL, vcpu); | 5025 | return emulator_write_emulated(&vcpu->arch.emulate_ctxt, |
5026 | rip, instruction, 3, NULL); | ||
5013 | } | 5027 | } |
5014 | 5028 | ||
5015 | void realmode_lgdt(struct kvm_vcpu *vcpu, u16 limit, unsigned long base) | 5029 | void realmode_lgdt(struct kvm_vcpu *vcpu, u16 limit, unsigned long base) |