Skip to content

Commit 81b674d

Browse files
bonziniZhengShunQian
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: [email protected] Signed-off-by: Paolo Bonzini <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent fc7ffc9 commit 81b674d

File tree

3 files changed

+38
-28
lines changed

3 files changed

+38
-28
lines changed

arch/x86/kvm/vmx.c

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

6695-
if (kvm_read_guest_virt(&vcpu->arch.emulate_ctxt, gva, &vmptr,
6696-
sizeof(vmptr), &e)) {
6695+
if (kvm_read_guest_virt(vcpu, gva, &vmptr, sizeof(vmptr), &e)) {
66976696
kvm_inject_page_fault(vcpu, &e);
66986697
return 1;
66996698
}
@@ -7211,8 +7210,8 @@ static int handle_vmread(struct kvm_vcpu *vcpu)
72117210
vmx_instruction_info, true, &gva))
72127211
return 1;
72137212
/* _system ok, as nested_vmx_check_permission verified cpl=0 */
7214-
kvm_write_guest_virt_system(&vcpu->arch.emulate_ctxt, gva,
7215-
&field_value, (is_long_mode(vcpu) ? 8 : 4), NULL);
7213+
kvm_write_guest_virt_system(vcpu, gva, &field_value,
7214+
(is_long_mode(vcpu) ? 8 : 4), NULL);
72167215
}
72177216

72187217
nested_vmx_succeed(vcpu);
@@ -7247,8 +7246,8 @@ static int handle_vmwrite(struct kvm_vcpu *vcpu)
72477246
if (get_vmx_mem_address(vcpu, exit_qualification,
72487247
vmx_instruction_info, false, &gva))
72497248
return 1;
7250-
if (kvm_read_guest_virt(&vcpu->arch.emulate_ctxt, gva,
7251-
&field_value, (is_64_bit_mode(vcpu) ? 8 : 4), &e)) {
7249+
if (kvm_read_guest_virt(vcpu, gva, &field_value,
7250+
(is_64_bit_mode(vcpu) ? 8 : 4), &e)) {
72527251
kvm_inject_page_fault(vcpu, &e);
72537252
return 1;
72547253
}
@@ -7338,9 +7337,9 @@ static int handle_vmptrst(struct kvm_vcpu *vcpu)
73387337
vmx_instruction_info, true, &vmcs_gva))
73397338
return 1;
73407339
/* ok to use *_system, as nested_vmx_check_permission verified cpl=0 */
7341-
if (kvm_write_guest_virt_system(&vcpu->arch.emulate_ctxt, vmcs_gva,
7342-
(void *)&to_vmx(vcpu)->nested.current_vmptr,
7343-
sizeof(u64), &e)) {
7340+
if (kvm_write_guest_virt_system(vcpu, vmcs_gva,
7341+
(void *)&to_vmx(vcpu)->nested.current_vmptr,
7342+
sizeof(u64), &e)) {
73447343
kvm_inject_page_fault(vcpu, &e);
73457344
return 1;
73467345
}
@@ -7394,8 +7393,7 @@ static int handle_invept(struct kvm_vcpu *vcpu)
73947393
if (get_vmx_mem_address(vcpu, vmcs_readl(EXIT_QUALIFICATION),
73957394
vmx_instruction_info, false, &gva))
73967395
return 1;
7397-
if (kvm_read_guest_virt(&vcpu->arch.emulate_ctxt, gva, &operand,
7398-
sizeof(operand), &e)) {
7396+
if (kvm_read_guest_virt(vcpu, gva, &operand, sizeof(operand), &e)) {
73997397
kvm_inject_page_fault(vcpu, &e);
74007398
return 1;
74017399
}
@@ -7454,8 +7452,7 @@ static int handle_invvpid(struct kvm_vcpu *vcpu)
74547452
if (get_vmx_mem_address(vcpu, vmcs_readl(EXIT_QUALIFICATION),
74557453
vmx_instruction_info, false, &gva))
74567454
return 1;
7457-
if (kvm_read_guest_virt(&vcpu->arch.emulate_ctxt, gva, &vpid,
7458-
sizeof(u32), &e)) {
7455+
if (kvm_read_guest_virt(vcpu, gva, &vpid, sizeof(u32), &e)) {
74597456
kvm_inject_page_fault(vcpu, &e);
74607457
return 1;
74617458
}

arch/x86/kvm/x86.c

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4245,21 +4245,20 @@ static int kvm_fetch_guest_virt(struct x86_emulate_ctxt *ctxt,
42454245
return X86EMUL_CONTINUE;
42464246
}
42474247

4248-
int kvm_read_guest_virt(struct x86_emulate_ctxt *ctxt,
4248+
int kvm_read_guest_virt(struct kvm_vcpu *vcpu,
42494249
gva_t addr, void *val, unsigned int bytes,
42504250
struct x86_exception *exception)
42514251
{
4252-
struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt);
42534252
u32 access = (kvm_x86_ops->get_cpl(vcpu) == 3) ? PFERR_USER_MASK : 0;
42544253

42554254
return kvm_read_guest_virt_helper(addr, val, bytes, vcpu, access,
42564255
exception);
42574256
}
42584257
EXPORT_SYMBOL_GPL(kvm_read_guest_virt);
42594258

4260-
static int kvm_read_guest_virt_system(struct x86_emulate_ctxt *ctxt,
4261-
gva_t addr, void *val, unsigned int bytes,
4262-
struct x86_exception *exception)
4259+
static int emulator_read_std(struct x86_emulate_ctxt *ctxt,
4260+
gva_t addr, void *val, unsigned int bytes,
4261+
struct x86_exception *exception)
42634262
{
42644263
struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt);
42654264
return kvm_read_guest_virt_helper(addr, val, bytes, vcpu, 0, exception);
@@ -4274,18 +4273,16 @@ static int kvm_read_guest_phys_system(struct x86_emulate_ctxt *ctxt,
42744273
return r < 0 ? X86EMUL_IO_NEEDED : X86EMUL_CONTINUE;
42754274
}
42764275

4277-
int kvm_write_guest_virt_system(struct x86_emulate_ctxt *ctxt,
4278-
gva_t addr, void *val,
4279-
unsigned int bytes,
4280-
struct x86_exception *exception)
4276+
static int kvm_write_guest_virt_helper(gva_t addr, void *val, unsigned int bytes,
4277+
struct kvm_vcpu *vcpu, u32 access,
4278+
struct x86_exception *exception)
42814279
{
4282-
struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt);
42834280
void *data = val;
42844281
int r = X86EMUL_CONTINUE;
42854282

42864283
while (bytes) {
42874284
gpa_t gpa = vcpu->arch.walk_mmu->gva_to_gpa(vcpu, addr,
4288-
PFERR_WRITE_MASK,
4285+
access,
42894286
exception);
42904287
unsigned offset = addr & (PAGE_SIZE-1);
42914288
unsigned towrite = min(bytes, (unsigned)PAGE_SIZE - offset);
@@ -4306,6 +4303,22 @@ int kvm_write_guest_virt_system(struct x86_emulate_ctxt *ctxt,
43064303
out:
43074304
return r;
43084305
}
4306+
4307+
static int emulator_write_std(struct x86_emulate_ctxt *ctxt, gva_t addr, void *val,
4308+
unsigned int bytes, struct x86_exception *exception)
4309+
{
4310+
struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt);
4311+
4312+
return kvm_write_guest_virt_helper(addr, val, bytes, vcpu,
4313+
PFERR_WRITE_MASK, exception);
4314+
}
4315+
4316+
int kvm_write_guest_virt_system(struct kvm_vcpu *vcpu, gva_t addr, void *val,
4317+
unsigned int bytes, struct x86_exception *exception)
4318+
{
4319+
return kvm_write_guest_virt_helper(addr, val, bytes, vcpu,
4320+
PFERR_WRITE_MASK, exception);
4321+
}
43094322
EXPORT_SYMBOL_GPL(kvm_write_guest_virt_system);
43104323

43114324
static int vcpu_mmio_gva_to_gpa(struct kvm_vcpu *vcpu, unsigned long gva,
@@ -5025,8 +5038,8 @@ static void emulator_set_hflags(struct x86_emulate_ctxt *ctxt, unsigned emul_fla
50255038
static const struct x86_emulate_ops emulate_ops = {
50265039
.read_gpr = emulator_read_gpr,
50275040
.write_gpr = emulator_write_gpr,
5028-
.read_std = kvm_read_guest_virt_system,
5029-
.write_std = kvm_write_guest_virt_system,
5041+
.read_std = emulator_read_std,
5042+
.write_std = emulator_write_std,
50305043
.read_phys = kvm_read_guest_phys_system,
50315044
.fetch = kvm_fetch_guest_virt,
50325045
.read_emulated = emulator_read_emulated,

arch/x86/kvm/x86.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,11 @@ int kvm_inject_realmode_interrupt(struct kvm_vcpu *vcpu, int irq, int inc_eip);
164164

165165
void kvm_write_tsc(struct kvm_vcpu *vcpu, struct msr_data *msr);
166166

167-
int kvm_read_guest_virt(struct x86_emulate_ctxt *ctxt,
167+
int kvm_read_guest_virt(struct kvm_vcpu *vcpu,
168168
gva_t addr, void *val, unsigned int bytes,
169169
struct x86_exception *exception);
170170

171-
int kvm_write_guest_virt_system(struct x86_emulate_ctxt *ctxt,
171+
int kvm_write_guest_virt_system(struct kvm_vcpu *vcpu,
172172
gva_t addr, void *val, unsigned int bytes,
173173
struct x86_exception *exception);
174174

0 commit comments

Comments
 (0)