Skip to content

Commit 838b0e9

Browse files
bonzinigregkh
authored andcommitted
KVM: x86: pass kvm_vcpu to kvm_read_guest_virt and kvm_write_guest_virt_system
commit ce14e86 upstream. 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: 129a72a ("KVM: x86: Introduce segmented_write_std", 2017-01-12) Cc: stable@vger.kernel.org Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 00b1391 commit 838b0e9

3 files changed

Lines changed: 38 additions & 28 deletions

File tree

arch/x86/kvm/vmx.c

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6928,8 +6928,7 @@ static int nested_vmx_check_vmptr(struct kvm_vcpu *vcpu, int exit_reason,
69286928
vmcs_read32(VMX_INSTRUCTION_INFO), false, &gva))
69296929
return 1;
69306930

6931-
if (kvm_read_guest_virt(&vcpu->arch.emulate_ctxt, gva, &vmptr,
6932-
sizeof(vmptr), &e)) {
6931+
if (kvm_read_guest_virt(vcpu, gva, &vmptr, sizeof(vmptr), &e)) {
69336932
kvm_inject_page_fault(vcpu, &e);
69346933
return 1;
69356934
}
@@ -7469,8 +7468,8 @@ static int handle_vmread(struct kvm_vcpu *vcpu)
74697468
vmx_instruction_info, true, &gva))
74707469
return 1;
74717470
/* _system ok, as nested_vmx_check_permission verified cpl=0 */
7472-
kvm_write_guest_virt_system(&vcpu->arch.emulate_ctxt, gva,
7473-
&field_value, (is_long_mode(vcpu) ? 8 : 4), NULL);
7471+
kvm_write_guest_virt_system(vcpu, gva, &field_value,
7472+
(is_long_mode(vcpu) ? 8 : 4), NULL);
74747473
}
74757474

74767475
nested_vmx_succeed(vcpu);
@@ -7505,8 +7504,8 @@ static int handle_vmwrite(struct kvm_vcpu *vcpu)
75057504
if (get_vmx_mem_address(vcpu, exit_qualification,
75067505
vmx_instruction_info, false, &gva))
75077506
return 1;
7508-
if (kvm_read_guest_virt(&vcpu->arch.emulate_ctxt, gva,
7509-
&field_value, (is_64_bit_mode(vcpu) ? 8 : 4), &e)) {
7507+
if (kvm_read_guest_virt(vcpu, gva, &field_value,
7508+
(is_64_bit_mode(vcpu) ? 8 : 4), &e)) {
75107509
kvm_inject_page_fault(vcpu, &e);
75117510
return 1;
75127511
}
@@ -7603,9 +7602,9 @@ static int handle_vmptrst(struct kvm_vcpu *vcpu)
76037602
vmx_instruction_info, true, &vmcs_gva))
76047603
return 1;
76057604
/* ok to use *_system, as nested_vmx_check_permission verified cpl=0 */
7606-
if (kvm_write_guest_virt_system(&vcpu->arch.emulate_ctxt, vmcs_gva,
7607-
(void *)&to_vmx(vcpu)->nested.current_vmptr,
7608-
sizeof(u64), &e)) {
7605+
if (kvm_write_guest_virt_system(vcpu, vmcs_gva,
7606+
(void *)&to_vmx(vcpu)->nested.current_vmptr,
7607+
sizeof(u64), &e)) {
76097608
kvm_inject_page_fault(vcpu, &e);
76107609
return 1;
76117610
}
@@ -7659,8 +7658,7 @@ static int handle_invept(struct kvm_vcpu *vcpu)
76597658
if (get_vmx_mem_address(vcpu, vmcs_readl(EXIT_QUALIFICATION),
76607659
vmx_instruction_info, false, &gva))
76617660
return 1;
7662-
if (kvm_read_guest_virt(&vcpu->arch.emulate_ctxt, gva, &operand,
7663-
sizeof(operand), &e)) {
7661+
if (kvm_read_guest_virt(vcpu, gva, &operand, sizeof(operand), &e)) {
76647662
kvm_inject_page_fault(vcpu, &e);
76657663
return 1;
76667664
}
@@ -7723,8 +7721,7 @@ static int handle_invvpid(struct kvm_vcpu *vcpu)
77237721
if (get_vmx_mem_address(vcpu, vmcs_readl(EXIT_QUALIFICATION),
77247722
vmx_instruction_info, false, &gva))
77257723
return 1;
7726-
if (kvm_read_guest_virt(&vcpu->arch.emulate_ctxt, gva, &vpid,
7727-
sizeof(u32), &e)) {
7724+
if (kvm_read_guest_virt(vcpu, gva, &vpid, sizeof(u32), &e)) {
77287725
kvm_inject_page_fault(vcpu, &e);
77297726
return 1;
77307727
}

arch/x86/kvm/x86.c

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4395,21 +4395,20 @@ static int kvm_fetch_guest_virt(struct x86_emulate_ctxt *ctxt,
43954395
return X86EMUL_CONTINUE;
43964396
}
43974397

4398-
int kvm_read_guest_virt(struct x86_emulate_ctxt *ctxt,
4398+
int kvm_read_guest_virt(struct kvm_vcpu *vcpu,
43994399
gva_t addr, void *val, unsigned int bytes,
44004400
struct x86_exception *exception)
44014401
{
4402-
struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt);
44034402
u32 access = (kvm_x86_ops->get_cpl(vcpu) == 3) ? PFERR_USER_MASK : 0;
44044403

44054404
return kvm_read_guest_virt_helper(addr, val, bytes, vcpu, access,
44064405
exception);
44074406
}
44084407
EXPORT_SYMBOL_GPL(kvm_read_guest_virt);
44094408

4410-
static int kvm_read_guest_virt_system(struct x86_emulate_ctxt *ctxt,
4411-
gva_t addr, void *val, unsigned int bytes,
4412-
struct x86_exception *exception)
4409+
static int emulator_read_std(struct x86_emulate_ctxt *ctxt,
4410+
gva_t addr, void *val, unsigned int bytes,
4411+
struct x86_exception *exception)
44134412
{
44144413
struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt);
44154414
return kvm_read_guest_virt_helper(addr, val, bytes, vcpu, 0, exception);
@@ -4424,18 +4423,16 @@ static int kvm_read_guest_phys_system(struct x86_emulate_ctxt *ctxt,
44244423
return r < 0 ? X86EMUL_IO_NEEDED : X86EMUL_CONTINUE;
44254424
}
44264425

4427-
int kvm_write_guest_virt_system(struct x86_emulate_ctxt *ctxt,
4428-
gva_t addr, void *val,
4429-
unsigned int bytes,
4430-
struct x86_exception *exception)
4426+
static int kvm_write_guest_virt_helper(gva_t addr, void *val, unsigned int bytes,
4427+
struct kvm_vcpu *vcpu, u32 access,
4428+
struct x86_exception *exception)
44314429
{
4432-
struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt);
44334430
void *data = val;
44344431
int r = X86EMUL_CONTINUE;
44354432

44364433
while (bytes) {
44374434
gpa_t gpa = vcpu->arch.walk_mmu->gva_to_gpa(vcpu, addr,
4438-
PFERR_WRITE_MASK,
4435+
access,
44394436
exception);
44404437
unsigned offset = addr & (PAGE_SIZE-1);
44414438
unsigned towrite = min(bytes, (unsigned)PAGE_SIZE - offset);
@@ -4456,6 +4453,22 @@ int kvm_write_guest_virt_system(struct x86_emulate_ctxt *ctxt,
44564453
out:
44574454
return r;
44584455
}
4456+
4457+
static int emulator_write_std(struct x86_emulate_ctxt *ctxt, gva_t addr, void *val,
4458+
unsigned int bytes, struct x86_exception *exception)
4459+
{
4460+
struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt);
4461+
4462+
return kvm_write_guest_virt_helper(addr, val, bytes, vcpu,
4463+
PFERR_WRITE_MASK, exception);
4464+
}
4465+
4466+
int kvm_write_guest_virt_system(struct kvm_vcpu *vcpu, gva_t addr, void *val,
4467+
unsigned int bytes, struct x86_exception *exception)
4468+
{
4469+
return kvm_write_guest_virt_helper(addr, val, bytes, vcpu,
4470+
PFERR_WRITE_MASK, exception);
4471+
}
44594472
EXPORT_SYMBOL_GPL(kvm_write_guest_virt_system);
44604473

44614474
static int vcpu_mmio_gva_to_gpa(struct kvm_vcpu *vcpu, unsigned long gva,
@@ -5180,8 +5193,8 @@ static void emulator_set_hflags(struct x86_emulate_ctxt *ctxt, unsigned emul_fla
51805193
static const struct x86_emulate_ops emulate_ops = {
51815194
.read_gpr = emulator_read_gpr,
51825195
.write_gpr = emulator_write_gpr,
5183-
.read_std = kvm_read_guest_virt_system,
5184-
.write_std = kvm_write_guest_virt_system,
5196+
.read_std = emulator_read_std,
5197+
.write_std = emulator_write_std,
51855198
.read_phys = kvm_read_guest_phys_system,
51865199
.fetch = kvm_fetch_guest_virt,
51875200
.read_emulated = emulator_read_emulated,

arch/x86/kvm/x86.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,11 @@ int kvm_inject_realmode_interrupt(struct kvm_vcpu *vcpu, int irq, int inc_eip);
161161
void kvm_write_tsc(struct kvm_vcpu *vcpu, struct msr_data *msr);
162162
u64 get_kvmclock_ns(struct kvm *kvm);
163163

164-
int kvm_read_guest_virt(struct x86_emulate_ctxt *ctxt,
164+
int kvm_read_guest_virt(struct kvm_vcpu *vcpu,
165165
gva_t addr, void *val, unsigned int bytes,
166166
struct x86_exception *exception);
167167

168-
int kvm_write_guest_virt_system(struct x86_emulate_ctxt *ctxt,
168+
int kvm_write_guest_virt_system(struct kvm_vcpu *vcpu,
169169
gva_t addr, void *val, unsigned int bytes,
170170
struct x86_exception *exception);
171171

0 commit comments

Comments
 (0)