Commit ce14e868 authored by Paolo Bonzini's avatar Paolo Bonzini

KVM: x86: pass kvm_vcpu to kvm_read_guest_virt and kvm_write_guest_virt_system

Int the next patch the emulator's .read_std and .write_std callbacks will
grow another argument, which is not needed in kvm_read_guest_virt and
kvm_write_guest_virt_system's callers.  Since we have to make separate
functions, let's give the currently existing names a nicer interface, too.

Fixes: 129a72a0 ("KVM: x86: Introduce segmented_write_std", 2017-01-12)
Cc: stable@vger.kernel.org
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 79367a65
...@@ -7823,8 +7823,7 @@ static int nested_vmx_get_vmptr(struct kvm_vcpu *vcpu, gpa_t *vmpointer) ...@@ -7823,8 +7823,7 @@ static int nested_vmx_get_vmptr(struct kvm_vcpu *vcpu, gpa_t *vmpointer)
vmcs_read32(VMX_INSTRUCTION_INFO), false, &gva)) vmcs_read32(VMX_INSTRUCTION_INFO), false, &gva))
return 1; return 1;
if (kvm_read_guest_virt(&vcpu->arch.emulate_ctxt, gva, vmpointer, if (kvm_read_guest_virt(vcpu, gva, vmpointer, sizeof(*vmpointer), &e)) {
sizeof(*vmpointer), &e)) {
kvm_inject_page_fault(vcpu, &e); kvm_inject_page_fault(vcpu, &e);
return 1; return 1;
} }
...@@ -8295,8 +8294,8 @@ static int handle_vmread(struct kvm_vcpu *vcpu) ...@@ -8295,8 +8294,8 @@ static int handle_vmread(struct kvm_vcpu *vcpu)
vmx_instruction_info, true, &gva)) vmx_instruction_info, true, &gva))
return 1; return 1;
/* _system ok, nested_vmx_check_permission has verified cpl=0 */ /* _system ok, nested_vmx_check_permission has verified cpl=0 */
kvm_write_guest_virt_system(&vcpu->arch.emulate_ctxt, gva, kvm_write_guest_virt_system(vcpu, gva, &field_value,
&field_value, (is_long_mode(vcpu) ? 8 : 4), NULL); (is_long_mode(vcpu) ? 8 : 4), NULL);
} }
nested_vmx_succeed(vcpu); nested_vmx_succeed(vcpu);
...@@ -8334,8 +8333,8 @@ static int handle_vmwrite(struct kvm_vcpu *vcpu) ...@@ -8334,8 +8333,8 @@ static int handle_vmwrite(struct kvm_vcpu *vcpu)
if (get_vmx_mem_address(vcpu, exit_qualification, if (get_vmx_mem_address(vcpu, exit_qualification,
vmx_instruction_info, false, &gva)) vmx_instruction_info, false, &gva))
return 1; return 1;
if (kvm_read_guest_virt(&vcpu->arch.emulate_ctxt, gva, if (kvm_read_guest_virt(vcpu, gva, &field_value,
&field_value, (is_64_bit_mode(vcpu) ? 8 : 4), &e)) { (is_64_bit_mode(vcpu) ? 8 : 4), &e)) {
kvm_inject_page_fault(vcpu, &e); kvm_inject_page_fault(vcpu, &e);
return 1; return 1;
} }
...@@ -8460,7 +8459,7 @@ static int handle_vmptrst(struct kvm_vcpu *vcpu) ...@@ -8460,7 +8459,7 @@ static int handle_vmptrst(struct kvm_vcpu *vcpu)
vmx_instruction_info, true, &vmcs_gva)) vmx_instruction_info, true, &vmcs_gva))
return 1; return 1;
/* *_system ok, nested_vmx_check_permission has verified cpl=0 */ /* *_system ok, nested_vmx_check_permission has verified cpl=0 */
if (kvm_write_guest_virt_system(&vcpu->arch.emulate_ctxt, vmcs_gva, if (kvm_write_guest_virt_system(vcpu, vmcs_gva,
(void *)&to_vmx(vcpu)->nested.current_vmptr, (void *)&to_vmx(vcpu)->nested.current_vmptr,
sizeof(u64), &e)) { sizeof(u64), &e)) {
kvm_inject_page_fault(vcpu, &e); kvm_inject_page_fault(vcpu, &e);
...@@ -8509,8 +8508,7 @@ static int handle_invept(struct kvm_vcpu *vcpu) ...@@ -8509,8 +8508,7 @@ static int handle_invept(struct kvm_vcpu *vcpu)
if (get_vmx_mem_address(vcpu, vmcs_readl(EXIT_QUALIFICATION), if (get_vmx_mem_address(vcpu, vmcs_readl(EXIT_QUALIFICATION),
vmx_instruction_info, false, &gva)) vmx_instruction_info, false, &gva))
return 1; return 1;
if (kvm_read_guest_virt(&vcpu->arch.emulate_ctxt, gva, &operand, if (kvm_read_guest_virt(vcpu, gva, &operand, sizeof(operand), &e)) {
sizeof(operand), &e)) {
kvm_inject_page_fault(vcpu, &e); kvm_inject_page_fault(vcpu, &e);
return 1; return 1;
} }
...@@ -8574,8 +8572,7 @@ static int handle_invvpid(struct kvm_vcpu *vcpu) ...@@ -8574,8 +8572,7 @@ static int handle_invvpid(struct kvm_vcpu *vcpu)
if (get_vmx_mem_address(vcpu, vmcs_readl(EXIT_QUALIFICATION), if (get_vmx_mem_address(vcpu, vmcs_readl(EXIT_QUALIFICATION),
vmx_instruction_info, false, &gva)) vmx_instruction_info, false, &gva))
return 1; return 1;
if (kvm_read_guest_virt(&vcpu->arch.emulate_ctxt, gva, &operand, if (kvm_read_guest_virt(vcpu, gva, &operand, sizeof(operand), &e)) {
sizeof(operand), &e)) {
kvm_inject_page_fault(vcpu, &e); kvm_inject_page_fault(vcpu, &e);
return 1; return 1;
} }
......
...@@ -4798,11 +4798,10 @@ static int kvm_fetch_guest_virt(struct x86_emulate_ctxt *ctxt, ...@@ -4798,11 +4798,10 @@ static int kvm_fetch_guest_virt(struct x86_emulate_ctxt *ctxt,
return X86EMUL_CONTINUE; return X86EMUL_CONTINUE;
} }
int kvm_read_guest_virt(struct x86_emulate_ctxt *ctxt, int kvm_read_guest_virt(struct kvm_vcpu *vcpu,
gva_t addr, void *val, unsigned int bytes, gva_t addr, void *val, unsigned int bytes,
struct x86_exception *exception) struct x86_exception *exception)
{ {
struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt);
u32 access = (kvm_x86_ops->get_cpl(vcpu) == 3) ? PFERR_USER_MASK : 0; u32 access = (kvm_x86_ops->get_cpl(vcpu) == 3) ? PFERR_USER_MASK : 0;
return kvm_read_guest_virt_helper(addr, val, bytes, vcpu, access, return kvm_read_guest_virt_helper(addr, val, bytes, vcpu, access,
...@@ -4810,7 +4809,7 @@ int kvm_read_guest_virt(struct x86_emulate_ctxt *ctxt, ...@@ -4810,7 +4809,7 @@ int kvm_read_guest_virt(struct x86_emulate_ctxt *ctxt,
} }
EXPORT_SYMBOL_GPL(kvm_read_guest_virt); EXPORT_SYMBOL_GPL(kvm_read_guest_virt);
static int kvm_read_guest_virt_system(struct x86_emulate_ctxt *ctxt, static int emulator_read_std(struct x86_emulate_ctxt *ctxt,
gva_t addr, void *val, unsigned int bytes, gva_t addr, void *val, unsigned int bytes,
struct x86_exception *exception) struct x86_exception *exception)
{ {
...@@ -4827,18 +4826,16 @@ static int kvm_read_guest_phys_system(struct x86_emulate_ctxt *ctxt, ...@@ -4827,18 +4826,16 @@ static int kvm_read_guest_phys_system(struct x86_emulate_ctxt *ctxt,
return r < 0 ? X86EMUL_IO_NEEDED : X86EMUL_CONTINUE; return r < 0 ? X86EMUL_IO_NEEDED : X86EMUL_CONTINUE;
} }
int kvm_write_guest_virt_system(struct x86_emulate_ctxt *ctxt, static int kvm_write_guest_virt_helper(gva_t addr, void *val, unsigned int bytes,
gva_t addr, void *val, struct kvm_vcpu *vcpu, u32 access,
unsigned int bytes,
struct x86_exception *exception) struct x86_exception *exception)
{ {
struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt);
void *data = val; void *data = val;
int r = X86EMUL_CONTINUE; int r = X86EMUL_CONTINUE;
while (bytes) { while (bytes) {
gpa_t gpa = vcpu->arch.walk_mmu->gva_to_gpa(vcpu, addr, gpa_t gpa = vcpu->arch.walk_mmu->gva_to_gpa(vcpu, addr,
PFERR_WRITE_MASK, access,
exception); exception);
unsigned offset = addr & (PAGE_SIZE-1); unsigned offset = addr & (PAGE_SIZE-1);
unsigned towrite = min(bytes, (unsigned)PAGE_SIZE - offset); unsigned towrite = min(bytes, (unsigned)PAGE_SIZE - offset);
...@@ -4859,6 +4856,22 @@ int kvm_write_guest_virt_system(struct x86_emulate_ctxt *ctxt, ...@@ -4859,6 +4856,22 @@ int kvm_write_guest_virt_system(struct x86_emulate_ctxt *ctxt,
out: out:
return r; return r;
} }
static int emulator_write_std(struct x86_emulate_ctxt *ctxt, gva_t addr, void *val,
unsigned int bytes, struct x86_exception *exception)
{
struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt);
return kvm_write_guest_virt_helper(addr, val, bytes, vcpu,
PFERR_WRITE_MASK, exception);
}
int kvm_write_guest_virt_system(struct kvm_vcpu *vcpu, gva_t addr, void *val,
unsigned int bytes, struct x86_exception *exception)
{
return kvm_write_guest_virt_helper(addr, val, bytes, vcpu,
PFERR_WRITE_MASK, exception);
}
EXPORT_SYMBOL_GPL(kvm_write_guest_virt_system); EXPORT_SYMBOL_GPL(kvm_write_guest_virt_system);
int handle_ud(struct kvm_vcpu *vcpu) int handle_ud(struct kvm_vcpu *vcpu)
...@@ -5611,8 +5624,8 @@ static int emulator_pre_leave_smm(struct x86_emulate_ctxt *ctxt, u64 smbase) ...@@ -5611,8 +5624,8 @@ static int emulator_pre_leave_smm(struct x86_emulate_ctxt *ctxt, u64 smbase)
static const struct x86_emulate_ops emulate_ops = { static const struct x86_emulate_ops emulate_ops = {
.read_gpr = emulator_read_gpr, .read_gpr = emulator_read_gpr,
.write_gpr = emulator_write_gpr, .write_gpr = emulator_write_gpr,
.read_std = kvm_read_guest_virt_system, .read_std = emulator_read_std,
.write_std = kvm_write_guest_virt_system, .write_std = emulator_write_std,
.read_phys = kvm_read_guest_phys_system, .read_phys = kvm_read_guest_phys_system,
.fetch = kvm_fetch_guest_virt, .fetch = kvm_fetch_guest_virt,
.read_emulated = emulator_read_emulated, .read_emulated = emulator_read_emulated,
......
...@@ -247,11 +247,11 @@ int kvm_inject_realmode_interrupt(struct kvm_vcpu *vcpu, int irq, int inc_eip); ...@@ -247,11 +247,11 @@ int kvm_inject_realmode_interrupt(struct kvm_vcpu *vcpu, int irq, int inc_eip);
void kvm_write_tsc(struct kvm_vcpu *vcpu, struct msr_data *msr); void kvm_write_tsc(struct kvm_vcpu *vcpu, struct msr_data *msr);
u64 get_kvmclock_ns(struct kvm *kvm); u64 get_kvmclock_ns(struct kvm *kvm);
int kvm_read_guest_virt(struct x86_emulate_ctxt *ctxt, int kvm_read_guest_virt(struct kvm_vcpu *vcpu,
gva_t addr, void *val, unsigned int bytes, gva_t addr, void *val, unsigned int bytes,
struct x86_exception *exception); struct x86_exception *exception);
int kvm_write_guest_virt_system(struct x86_emulate_ctxt *ctxt, int kvm_write_guest_virt_system(struct kvm_vcpu *vcpu,
gva_t addr, void *val, unsigned int bytes, gva_t addr, void *val, unsigned int bytes,
struct x86_exception *exception); struct x86_exception *exception);
......
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