Skip to content

Commit b26deb0

Browse files
author
Peter Zijlstra
committed
KVM: x86: Introduce EM_ASM_2
Replace the FASTOP2 instructions. Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Acked-by: Sean Christopherson <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 6204aea commit b26deb0

1 file changed

Lines changed: 47 additions & 38 deletions

File tree

arch/x86/kvm/emulate.c

Lines changed: 47 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,15 @@ static int em_##op(struct x86_emulate_ctxt *ctxt) \
317317
ON64(case 8: __EM_ASM_1(op##q, rax); break;) \
318318
EM_ASM_END
319319

320+
/* 2-operand, using "a" (dst), "d" (src) */
321+
#define EM_ASM_2(op) \
322+
EM_ASM_START(op) \
323+
case 1: __EM_ASM_2(op##b, al, dl); break; \
324+
case 2: __EM_ASM_2(op##w, ax, dx); break; \
325+
case 4: __EM_ASM_2(op##l, eax, edx); break; \
326+
ON64(case 8: __EM_ASM_2(op##q, rax, rdx); break;) \
327+
EM_ASM_END
328+
320329
/*
321330
* fastop functions have a special calling convention:
322331
*
@@ -1027,15 +1036,16 @@ static int read_descriptor(struct x86_emulate_ctxt *ctxt,
10271036
return rc;
10281037
}
10291038

1030-
FASTOP2(add);
1031-
FASTOP2(or);
1032-
FASTOP2(adc);
1033-
FASTOP2(sbb);
1034-
FASTOP2(and);
1035-
FASTOP2(sub);
1036-
FASTOP2(xor);
1037-
FASTOP2(cmp);
1038-
FASTOP2(test);
1039+
EM_ASM_2(add);
1040+
EM_ASM_2(or);
1041+
EM_ASM_2(adc);
1042+
EM_ASM_2(sbb);
1043+
EM_ASM_2(and);
1044+
EM_ASM_2(sub);
1045+
EM_ASM_2(xor);
1046+
EM_ASM_2(cmp);
1047+
EM_ASM_2(test);
1048+
EM_ASM_2(xadd);
10391049

10401050
FASTOP1SRC2(mul, mul_ex);
10411051
FASTOP1SRC2(imul, imul_ex);
@@ -1067,7 +1077,6 @@ FASTOP2W(bts);
10671077
FASTOP2W(btr);
10681078
FASTOP2W(btc);
10691079

1070-
FASTOP2(xadd);
10711080

10721081
FASTOP2R(cmp, cmp_r);
10731082

@@ -2304,7 +2313,7 @@ static int em_cmpxchg(struct x86_emulate_ctxt *ctxt)
23042313
ctxt->dst.val = reg_read(ctxt, VCPU_REGS_RAX);
23052314
ctxt->src.orig_val = ctxt->src.val;
23062315
ctxt->src.val = ctxt->dst.orig_val;
2307-
fastop(ctxt, em_cmp);
2316+
em_cmp(ctxt);
23082317

23092318
if (ctxt->eflags & X86_EFLAGS_ZF) {
23102319
/* Success: write back to memory; no update of EAX */
@@ -3069,7 +3078,7 @@ static int em_das(struct x86_emulate_ctxt *ctxt)
30693078
ctxt->src.type = OP_IMM;
30703079
ctxt->src.val = 0;
30713080
ctxt->src.bytes = 1;
3072-
fastop(ctxt, em_or);
3081+
em_or(ctxt);
30733082
ctxt->eflags &= ~(X86_EFLAGS_AF | X86_EFLAGS_CF);
30743083
if (cf)
30753084
ctxt->eflags |= X86_EFLAGS_CF;
@@ -3095,7 +3104,7 @@ static int em_aam(struct x86_emulate_ctxt *ctxt)
30953104
ctxt->src.type = OP_IMM;
30963105
ctxt->src.val = 0;
30973106
ctxt->src.bytes = 1;
3098-
fastop(ctxt, em_or);
3107+
em_or(ctxt);
30993108

31003109
return X86EMUL_CONTINUE;
31013110
}
@@ -3113,7 +3122,7 @@ static int em_aad(struct x86_emulate_ctxt *ctxt)
31133122
ctxt->src.type = OP_IMM;
31143123
ctxt->src.val = 0;
31153124
ctxt->src.bytes = 1;
3116-
fastop(ctxt, em_or);
3125+
em_or(ctxt);
31173126

31183127
return X86EMUL_CONTINUE;
31193128
}
@@ -3998,9 +4007,9 @@ static int check_perm_out(struct x86_emulate_ctxt *ctxt)
39984007
#define I2bvIP(_f, _e, _i, _p) \
39994008
IIP((_f) | ByteOp, _e, _i, _p), IIP(_f, _e, _i, _p)
40004009

4001-
#define F6ALU(_f, _e) F2bv((_f) | DstMem | SrcReg | ModRM, _e), \
4002-
F2bv(((_f) | DstReg | SrcMem | ModRM) & ~Lock, _e), \
4003-
F2bv(((_f) & ~Lock) | DstAcc | SrcImm, _e)
4010+
#define I6ALU(_f, _e) I2bv((_f) | DstMem | SrcReg | ModRM, _e), \
4011+
I2bv(((_f) | DstReg | SrcMem | ModRM) & ~Lock, _e), \
4012+
I2bv(((_f) & ~Lock) | DstAcc | SrcImm, _e)
40044013

40054014
static const struct opcode group7_rm0[] = {
40064015
N,
@@ -4038,14 +4047,14 @@ static const struct opcode group7_rm7[] = {
40384047
};
40394048

40404049
static const struct opcode group1[] = {
4041-
F(Lock, em_add),
4042-
F(Lock | PageTable, em_or),
4043-
F(Lock, em_adc),
4044-
F(Lock, em_sbb),
4045-
F(Lock | PageTable, em_and),
4046-
F(Lock, em_sub),
4047-
F(Lock, em_xor),
4048-
F(NoWrite, em_cmp),
4050+
I(Lock, em_add),
4051+
I(Lock | PageTable, em_or),
4052+
I(Lock, em_adc),
4053+
I(Lock, em_sbb),
4054+
I(Lock | PageTable, em_and),
4055+
I(Lock, em_sub),
4056+
I(Lock, em_xor),
4057+
I(NoWrite, em_cmp),
40494058
};
40504059

40514060
static const struct opcode group1A[] = {
@@ -4064,8 +4073,8 @@ static const struct opcode group2[] = {
40644073
};
40654074

40664075
static const struct opcode group3[] = {
4067-
F(DstMem | SrcImm | NoWrite, em_test),
4068-
F(DstMem | SrcImm | NoWrite, em_test),
4076+
I(DstMem | SrcImm | NoWrite, em_test),
4077+
I(DstMem | SrcImm | NoWrite, em_test),
40694078
I(DstMem | SrcNone | Lock, em_not),
40704079
I(DstMem | SrcNone | Lock, em_neg),
40714080
F(DstXacc | Src2Mem, em_mul_ex),
@@ -4258,29 +4267,29 @@ static const struct instr_dual instr_dual_8d = {
42584267

42594268
static const struct opcode opcode_table[256] = {
42604269
/* 0x00 - 0x07 */
4261-
F6ALU(Lock, em_add),
4270+
I6ALU(Lock, em_add),
42624271
I(ImplicitOps | Stack | No64 | Src2ES, em_push_sreg),
42634272
I(ImplicitOps | Stack | No64 | Src2ES, em_pop_sreg),
42644273
/* 0x08 - 0x0F */
4265-
F6ALU(Lock | PageTable, em_or),
4274+
I6ALU(Lock | PageTable, em_or),
42664275
I(ImplicitOps | Stack | No64 | Src2CS, em_push_sreg),
42674276
N,
42684277
/* 0x10 - 0x17 */
4269-
F6ALU(Lock, em_adc),
4278+
I6ALU(Lock, em_adc),
42704279
I(ImplicitOps | Stack | No64 | Src2SS, em_push_sreg),
42714280
I(ImplicitOps | Stack | No64 | Src2SS, em_pop_sreg),
42724281
/* 0x18 - 0x1F */
4273-
F6ALU(Lock, em_sbb),
4282+
I6ALU(Lock, em_sbb),
42744283
I(ImplicitOps | Stack | No64 | Src2DS, em_push_sreg),
42754284
I(ImplicitOps | Stack | No64 | Src2DS, em_pop_sreg),
42764285
/* 0x20 - 0x27 */
4277-
F6ALU(Lock | PageTable, em_and), N, N,
4286+
I6ALU(Lock | PageTable, em_and), N, N,
42784287
/* 0x28 - 0x2F */
4279-
F6ALU(Lock, em_sub), N, I(ByteOp | DstAcc | No64, em_das),
4288+
I6ALU(Lock, em_sub), N, I(ByteOp | DstAcc | No64, em_das),
42804289
/* 0x30 - 0x37 */
4281-
F6ALU(Lock, em_xor), N, N,
4290+
I6ALU(Lock, em_xor), N, N,
42824291
/* 0x38 - 0x3F */
4283-
F6ALU(NoWrite, em_cmp), N, N,
4292+
I6ALU(NoWrite, em_cmp), N, N,
42844293
/* 0x40 - 0x4F */
42854294
X8(I(DstReg, em_inc)), X8(I(DstReg, em_dec)),
42864295
/* 0x50 - 0x57 */
@@ -4306,7 +4315,7 @@ static const struct opcode opcode_table[256] = {
43064315
G(DstMem | SrcImm, group1),
43074316
G(ByteOp | DstMem | SrcImm | No64, group1),
43084317
G(DstMem | SrcImmByte, group1),
4309-
F2bv(DstMem | SrcReg | ModRM | NoWrite, em_test),
4318+
I2bv(DstMem | SrcReg | ModRM | NoWrite, em_test),
43104319
I2bv(DstMem | SrcReg | ModRM | Lock | PageTable, em_xchg),
43114320
/* 0x88 - 0x8F */
43124321
I2bv(DstMem | SrcReg | ModRM | Mov | PageTable, em_mov),
@@ -4329,7 +4338,7 @@ static const struct opcode opcode_table[256] = {
43294338
I2bv(SrcSI | DstDI | Mov | String | TwoMemOp, em_mov),
43304339
F2bv(SrcSI | DstDI | String | NoWrite | TwoMemOp, em_cmp_r),
43314340
/* 0xA8 - 0xAF */
4332-
F2bv(DstAcc | SrcImm | NoWrite, em_test),
4341+
I2bv(DstAcc | SrcImm | NoWrite, em_test),
43334342
I2bv(SrcAcc | DstDI | Mov | String, em_mov),
43344343
I2bv(SrcSI | DstAcc | Mov | String, em_mov),
43354344
F2bv(SrcAcc | DstDI | String | NoWrite, em_cmp_r),
@@ -4467,7 +4476,7 @@ static const struct opcode twobyte_table[256] = {
44674476
I(DstReg | SrcMem | ModRM, em_bsr_c),
44684477
D(DstReg | SrcMem8 | ModRM | Mov), D(DstReg | SrcMem16 | ModRM | Mov),
44694478
/* 0xC0 - 0xC7 */
4470-
F2bv(DstMem | SrcReg | ModRM | SrcWrite | Lock, em_xadd),
4479+
I2bv(DstMem | SrcReg | ModRM | SrcWrite | Lock, em_xadd),
44714480
N, ID(0, &instr_dual_0f_c3),
44724481
N, N, N, GD(0, &group9),
44734482
/* 0xC8 - 0xCF */

0 commit comments

Comments
 (0)