Skip to content

Commit fbaff2a

Browse files
yonghuahlijinxia
authored andcommitted
HV:remove redundant field 'mmio' from 'struct emul_cnx'
Acked-by: Eddie Dong <eddie.dong@intel.com> Signed-off-by: Yonghua Huang <yonghua.huang@intel.com>
1 parent b2c2ca2 commit fbaff2a

File tree

4 files changed

+17
-51
lines changed

4 files changed

+17
-51
lines changed

hypervisor/arch/x86/ept.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ int dm_emulate_mmio_post(struct vcpu *vcpu)
326326
if (vcpu->mmio.read_write == HV_MEM_IO_READ) {
327327
vcpu->mmio.value = vcpu->req.reqs.mmio_request.value;
328328
/* Emulate instruction and update vcpu register set */
329-
ret = emulate_instruction(vcpu, &vcpu->mmio);
329+
ret = emulate_instruction(vcpu);
330330
if (ret != 0)
331331
goto out;
332332
}
@@ -340,7 +340,7 @@ static int dm_emulate_mmio_pre(struct vcpu *vcpu, uint64_t exit_qual)
340340
int status;
341341

342342
if (vcpu->mmio.read_write == HV_MEM_IO_WRITE) {
343-
status = emulate_instruction(vcpu, &vcpu->mmio);
343+
status = emulate_instruction(vcpu);
344344
if (status != 0)
345345
return status;
346346
vcpu->req.reqs.mmio_request.value = vcpu->mmio.value;
@@ -420,7 +420,7 @@ int ept_violation_vmexit_handler(struct vcpu *vcpu)
420420
}
421421

422422
if (mmio->read_write == HV_MEM_IO_WRITE) {
423-
if (emulate_instruction(vcpu, mmio) != 0)
423+
if (emulate_instruction(vcpu) != 0)
424424
goto out;
425425
}
426426

@@ -432,7 +432,7 @@ int ept_violation_vmexit_handler(struct vcpu *vcpu)
432432
hv_emulate_mmio(vcpu, mmio, mmio_handler);
433433
if (mmio->read_write == HV_MEM_IO_READ) {
434434
/* Emulate instruction and update vcpu register set */
435-
if (emulate_instruction(vcpu, mmio) != 0)
435+
if (emulate_instruction(vcpu) != 0)
436436
goto out;
437437
}
438438

hypervisor/arch/x86/guest/instr_emul.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ void vie_init(struct vie *vie, const char *inst_bytes, uint32_t inst_length);
8989
int __decode_instruction(struct vcpu *vcpu, uint64_t gla,
9090
enum vm_cpu_mode cpu_mode, int csd, struct vie *vie);
9191

92-
int emulate_instruction(struct vcpu *vcpu, struct mem_io *mmio);
92+
int emulate_instruction(struct vcpu *vcpu);
9393
uint8_t decode_instruction(struct vcpu *vcpu);
9494

9595
#endif /* _VMM_INSTRUCTION_EMUL_H_ */

hypervisor/arch/x86/guest/instr_emul_wrapper.c

Lines changed: 10 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ struct emul_cnx {
4242
struct vie vie;
4343
struct vm_guest_paging paging;
4444
struct vcpu *vcpu;
45-
struct mem_io *mmio;
4645
};
4746

4847
static DEFINE_CPU_DATA(struct emul_cnx, g_inst_ctxt);
@@ -334,38 +333,20 @@ static void get_guest_paging_info(struct vcpu *vcpu, struct emul_cnx *emul_cnx)
334333
static int mmio_read(struct vcpu *vcpu, __unused uint64_t gpa, uint64_t *rval,
335334
__unused int size, __unused void *arg)
336335
{
337-
struct emul_cnx *emul_cnx;
338-
struct mem_io *mmio;
339-
340336
if (!vcpu)
341337
return -EINVAL;
342338

343-
emul_cnx = &per_cpu(g_inst_ctxt, vcpu->pcpu_id);
344-
mmio = emul_cnx->mmio;
345-
346-
ASSERT(mmio != NULL, "invalid mmio when reading");
347-
348-
*rval = mmio->value;
349-
339+
*rval = vcpu->mmio.value;
350340
return 0;
351341
}
352342

353343
static int mmio_write(struct vcpu *vcpu, __unused uint64_t gpa, uint64_t wval,
354344
__unused int size, __unused void *arg)
355345
{
356-
struct emul_cnx *emul_cnx;
357-
struct mem_io *mmio;
358-
359346
if (!vcpu)
360347
return -EINVAL;
361348

362-
emul_cnx = &per_cpu(g_inst_ctxt, vcpu->pcpu_id);
363-
mmio = emul_cnx->mmio;
364-
365-
ASSERT(mmio != NULL, "invalid mmio when writing");
366-
367-
mmio->value = wval;
368-
349+
vcpu->mmio.value = wval;
369350
return 0;
370351
}
371352

@@ -398,7 +379,6 @@ uint8_t decode_instruction(struct vcpu *vcpu)
398379

399380
guest_rip_hva = GPA2HVA(vcpu->vm, guest_rip_gpa);
400381
emul_cnx = &per_cpu(g_inst_ctxt, vcpu->pcpu_id);
401-
emul_cnx->mmio = &vcpu->mmio;
402382
emul_cnx->vcpu = vcpu;
403383

404384
/* by now, HVA <-> HPA is 1:1 mapping, so use hpa is OK*/
@@ -409,8 +389,6 @@ uint8_t decode_instruction(struct vcpu *vcpu)
409389
csar = exec_vmread(VMX_GUEST_CS_ATTR);
410390
cpu_mode = get_vmx_cpu_mode();
411391

412-
vcpu->mmio.private_data = emul_cnx;
413-
414392
retval = __decode_instruction(vcpu, guest_rip_gva,
415393
cpu_mode, SEG_DESC_DEF32(csar), &emul_cnx->vie);
416394

@@ -423,32 +401,20 @@ uint8_t decode_instruction(struct vcpu *vcpu)
423401
return emul_cnx->vie.opsize;
424402
}
425403

426-
int emulate_instruction(struct vcpu *vcpu, struct mem_io *mmio)
404+
int emulate_instruction(struct vcpu *vcpu)
427405
{
428-
struct emul_cnx *emul_cnx = (struct emul_cnx *)(mmio->private_data);
429-
struct vm_guest_paging *paging = &emul_cnx->paging;
430-
int i, retval = 0;
431-
uint64_t gpa = mmio->paddr;
406+
struct emul_cnx *emul_cnx;
407+
struct vm_guest_paging *paging;
408+
int retval = 0;
409+
uint64_t gpa = vcpu->mmio.paddr;
432410
mem_region_read_t mread = mmio_read;
433411
mem_region_write_t mwrite = mmio_write;
434412

413+
emul_cnx = &per_cpu(g_inst_ctxt, vcpu->pcpu_id);
414+
paging = &emul_cnx->paging;
415+
435416
retval = vmm_emulate_instruction(vcpu, gpa,
436417
&emul_cnx->vie, paging, mread, mwrite, &retval);
437418

438-
if (retval != 0) {
439-
/* dump to instruction when emulation failed */
440-
pr_err("emulate following instruction failed @ 0x%016llx:",
441-
exec_vmread(VMX_GUEST_RIP));
442-
for (i = 0; i < emul_cnx->vie.num_valid; i++) {
443-
if (i >= VIE_INST_SIZE)
444-
break;
445-
446-
if (i == 0)
447-
pr_err("\n");
448-
449-
pr_err("%d=%02hhx ",
450-
i, emul_cnx->vie.inst[i]);
451-
}
452-
}
453419
return retval;
454420
}

hypervisor/arch/x86/guest/vlapic.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2180,11 +2180,11 @@ int apic_access_vmexit_handler(struct vcpu *vcpu)
21802180

21812181
decode_instruction(vcpu);
21822182
if (access_type == 1) {
2183-
if (!emulate_instruction(vcpu, &vcpu->mmio))
2183+
if (!emulate_instruction(vcpu))
21842184
vlapic_write(vlapic, 1, offset, vcpu->mmio.value);
21852185
} else if (access_type == 0) {
21862186
vlapic_read(vlapic, 1, offset, &vcpu->mmio.value);
2187-
emulate_instruction(vcpu, &vcpu->mmio);
2187+
emulate_instruction(vcpu);
21882188
}
21892189

21902190
TRACE_2L(TRC_VMEXIT_APICV_ACCESS, qual, (uint64_t)vlapic);

0 commit comments

Comments
 (0)