Skip to content

Commit 8d35d87

Browse files
JasonChenCJlijinxia
authored andcommitted
instr_emul: remove vm_gva2gpa
- vm_gva2gpa is same as gva2gpa, so replace it with gva2gpa directly. - remove dead usage of vm_gva2gpa in emulate_movs. Signed-off-by: Jason Chen CJ <jason.cj.chen@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent 51528d4 commit 8d35d87

File tree

3 files changed

+11
-28
lines changed

3 files changed

+11
-28
lines changed

hypervisor/arch/x86/guest/instr_emul.c

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,6 @@ static uint64_t size2mask[] = {
243243
[8] = 0xffffffffffffffff,
244244
};
245245

246-
247246
static int
248247
vie_read_register(struct vcpu *vcpu, enum vm_reg_name reg, uint64_t *rval)
249248
{
@@ -671,10 +670,9 @@ emulate_movs(struct vcpu *vcpu, __unused uint64_t gpa, struct vie *vie,
671670
__unused mem_region_write_t memwrite,
672671
__unused void *arg)
673672
{
674-
uint64_t dstaddr, srcaddr, dstgpa, srcgpa;
673+
uint64_t dstaddr, srcaddr;
675674
uint64_t rcx, rdi, rsi, rflags;
676675
int error, fault, opsize, seg, repeat;
677-
uint32_t err_code;
678676

679677
opsize = (vie->op.op_byte == 0xA4) ? 1 : vie->opsize;
680678
error = 0;
@@ -714,14 +712,6 @@ emulate_movs(struct vcpu *vcpu, __unused uint64_t gpa, struct vie *vie,
714712
if (error || fault)
715713
goto done;
716714

717-
err_code = 0;
718-
error = vm_gva2gpa(vcpu, srcaddr, &srcgpa, &err_code);
719-
if (error)
720-
goto done;
721-
err_code = PAGE_FAULT_WR_FLAG;
722-
error = vm_gva2gpa(vcpu, dstaddr, &dstgpa, &err_code);
723-
if (error)
724-
goto done;
725715
memcpy_s((char *)dstaddr, 16, (char *)srcaddr, opsize);
726716

727717
error = vie_read_register(vcpu, VM_REG_GUEST_RSI, &rsi);
@@ -1310,13 +1300,19 @@ emulate_stack_op(struct vcpu *vcpu, uint64_t mmio_gpa, struct vie *vie,
13101300
return 0;
13111301
}
13121302

1303+
/* TODO: currently emulate_instruction is only for mmio, so here
1304+
* stack_gpa actually is unused for mmio_write & mmio_read, need
1305+
* take care of data trans if stack_gpa be used for memwrite in
1306+
* the future.
1307+
*/
13131308
if (pushop)
13141309
err_code |= PAGE_FAULT_WR_FLAG;
1315-
error = vm_gva2gpa(vcpu, stack_gla, &stack_gpa, &err_code);
1316-
if (error) {
1317-
pr_err("%s: failed to translate gva2gpa", __func__);
1310+
error = gva2gpa(vcpu, stack_gla, &stack_gpa, &err_code);
1311+
if (error == -EFAULT) {
1312+
vcpu_inject_pf(vcpu, stack_gla, err_code);
1313+
return error;
1314+
} else if (error < 0)
13181315
return error;
1319-
}
13201316
if (pushop) {
13211317
error = memread(vcpu, mmio_gpa, &val, size, arg);
13221318
if (error == 0)

hypervisor/arch/x86/guest/instr_emul_wrapper.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -287,17 +287,6 @@ static int mmio_write(struct vcpu *vcpu, __unused uint64_t gpa, uint64_t wval,
287287
return 0;
288288
}
289289

290-
int vm_gva2gpa(struct vcpu *vcpu, uint64_t gva, uint64_t *gpa,
291-
uint32_t *err_code)
292-
{
293-
294-
ASSERT(gpa != NULL, "Error in input arguments");
295-
ASSERT(vcpu != NULL,
296-
"Invalid vcpu id when gva2gpa");
297-
298-
return gva2gpa(vcpu, gva, gpa, err_code);
299-
}
300-
301290
int decode_instruction(struct vcpu *vcpu)
302291
{
303292
struct emul_cnx *emul_cnx;

hypervisor/include/arch/x86/guest/guest.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@ bool vm_lapic_disabled(struct vm *vm);
9393
uint64_t vcpumask2pcpumask(struct vm *vm, uint64_t vdmask);
9494

9595
int gva2gpa(struct vcpu *vcpu, uint64_t gva, uint64_t *gpa, uint32_t *err_code);
96-
int vm_gva2gpa(struct vcpu *vcpu, uint64_t gla, uint64_t *gpa,
97-
uint32_t *err_code);
9896

9997
struct vcpu *get_primary_vcpu(struct vm *vm);
10098
struct vcpu *vcpu_from_vid(struct vm *vm, int vcpu_id);

0 commit comments

Comments
 (0)