Commit d5ae7ce8 authored by Xiao Guangrong's avatar Xiao Guangrong Committed by Avi Kivity

KVM: x86: tag the instructions which are used to write page table

The idea is from Avi:
| tag instructions that are typically used to modify the page tables, and
| drop shadow if any other instruction is used.
| The list would include, I'd guess, and, or, bts, btc, mov, xchg, cmpxchg,
| and cmpxchg8b.

This patch is used to tag the instructions and in the later path, shadow page
is dropped if it is written by other instructions
Signed-off-by: default avatarXiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Signed-off-by: default avatarAvi Kivity <avi@redhat.com>
parent f759e2b4
...@@ -125,8 +125,9 @@ ...@@ -125,8 +125,9 @@
#define Lock (1<<26) /* lock prefix is allowed for the instruction */ #define Lock (1<<26) /* lock prefix is allowed for the instruction */
#define Priv (1<<27) /* instruction generates #GP if current CPL != 0 */ #define Priv (1<<27) /* instruction generates #GP if current CPL != 0 */
#define No64 (1<<28) #define No64 (1<<28)
#define PageTable (1 << 29) /* instruction used to write page table */
/* Source 2 operand type */ /* Source 2 operand type */
#define Src2Shift (29) #define Src2Shift (30)
#define Src2None (OpNone << Src2Shift) #define Src2None (OpNone << Src2Shift)
#define Src2CL (OpCL << Src2Shift) #define Src2CL (OpCL << Src2Shift)
#define Src2ImmByte (OpImmByte << Src2Shift) #define Src2ImmByte (OpImmByte << Src2Shift)
...@@ -3033,10 +3034,10 @@ static struct opcode group7_rm7[] = { ...@@ -3033,10 +3034,10 @@ static struct opcode group7_rm7[] = {
static struct opcode group1[] = { static struct opcode group1[] = {
I(Lock, em_add), I(Lock, em_add),
I(Lock, em_or), I(Lock | PageTable, em_or),
I(Lock, em_adc), I(Lock, em_adc),
I(Lock, em_sbb), I(Lock, em_sbb),
I(Lock, em_and), I(Lock | PageTable, em_and),
I(Lock, em_sub), I(Lock, em_sub),
I(Lock, em_xor), I(Lock, em_xor),
I(0, em_cmp), I(0, em_cmp),
...@@ -3096,18 +3097,21 @@ static struct group_dual group7 = { { ...@@ -3096,18 +3097,21 @@ static struct group_dual group7 = { {
static struct opcode group8[] = { static struct opcode group8[] = {
N, N, N, N, N, N, N, N,
D(DstMem | SrcImmByte | ModRM), D(DstMem | SrcImmByte | ModRM | Lock), D(DstMem | SrcImmByte | ModRM),
D(DstMem | SrcImmByte | ModRM | Lock), D(DstMem | SrcImmByte | ModRM | Lock), D(DstMem | SrcImmByte | ModRM | Lock | PageTable),
D(DstMem | SrcImmByte | ModRM | Lock),
D(DstMem | SrcImmByte | ModRM | Lock | PageTable),
}; };
static struct group_dual group9 = { { static struct group_dual group9 = { {
N, D(DstMem64 | ModRM | Lock), N, N, N, N, N, N, N, D(DstMem64 | ModRM | Lock | PageTable), N, N, N, N, N, N,
}, { }, {
N, N, N, N, N, N, N, N, N, N, N, N, N, N, N, N,
} }; } };
static struct opcode group11[] = { static struct opcode group11[] = {
I(DstMem | SrcImm | ModRM | Mov, em_mov), X7(D(Undefined)), I(DstMem | SrcImm | ModRM | Mov | PageTable, em_mov),
X7(D(Undefined)),
}; };
static struct gprefix pfx_0f_6f_0f_7f = { static struct gprefix pfx_0f_6f_0f_7f = {
...@@ -3120,7 +3124,7 @@ static struct opcode opcode_table[256] = { ...@@ -3120,7 +3124,7 @@ static struct opcode opcode_table[256] = {
I(ImplicitOps | Stack | No64 | Src2ES, em_push_sreg), I(ImplicitOps | Stack | No64 | Src2ES, em_push_sreg),
I(ImplicitOps | Stack | No64 | Src2ES, em_pop_sreg), I(ImplicitOps | Stack | No64 | Src2ES, em_pop_sreg),
/* 0x08 - 0x0F */ /* 0x08 - 0x0F */
I6ALU(Lock, em_or), I6ALU(Lock | PageTable, em_or),
I(ImplicitOps | Stack | No64 | Src2CS, em_push_sreg), I(ImplicitOps | Stack | No64 | Src2CS, em_push_sreg),
N, N,
/* 0x10 - 0x17 */ /* 0x10 - 0x17 */
...@@ -3132,7 +3136,7 @@ static struct opcode opcode_table[256] = { ...@@ -3132,7 +3136,7 @@ static struct opcode opcode_table[256] = {
I(ImplicitOps | Stack | No64 | Src2DS, em_push_sreg), I(ImplicitOps | Stack | No64 | Src2DS, em_push_sreg),
I(ImplicitOps | Stack | No64 | Src2DS, em_pop_sreg), I(ImplicitOps | Stack | No64 | Src2DS, em_pop_sreg),
/* 0x20 - 0x27 */ /* 0x20 - 0x27 */
I6ALU(Lock, em_and), N, N, I6ALU(Lock | PageTable, em_and), N, N,
/* 0x28 - 0x2F */ /* 0x28 - 0x2F */
I6ALU(Lock, em_sub), N, I(ByteOp | DstAcc | No64, em_das), I6ALU(Lock, em_sub), N, I(ByteOp | DstAcc | No64, em_das),
/* 0x30 - 0x37 */ /* 0x30 - 0x37 */
...@@ -3165,11 +3169,11 @@ static struct opcode opcode_table[256] = { ...@@ -3165,11 +3169,11 @@ static struct opcode opcode_table[256] = {
G(ByteOp | DstMem | SrcImm | ModRM | No64 | Group, group1), G(ByteOp | DstMem | SrcImm | ModRM | No64 | Group, group1),
G(DstMem | SrcImmByte | ModRM | Group, group1), G(DstMem | SrcImmByte | ModRM | Group, group1),
I2bv(DstMem | SrcReg | ModRM, em_test), I2bv(DstMem | SrcReg | ModRM, em_test),
I2bv(DstMem | SrcReg | ModRM | Lock, em_xchg), I2bv(DstMem | SrcReg | ModRM | Lock | PageTable, em_xchg),
/* 0x88 - 0x8F */ /* 0x88 - 0x8F */
I2bv(DstMem | SrcReg | ModRM | Mov, em_mov), I2bv(DstMem | SrcReg | ModRM | Mov | PageTable, em_mov),
I2bv(DstReg | SrcMem | ModRM | Mov, em_mov), I2bv(DstReg | SrcMem | ModRM | Mov, em_mov),
I(DstMem | SrcNone | ModRM | Mov, em_mov_rm_sreg), I(DstMem | SrcNone | ModRM | Mov | PageTable, em_mov_rm_sreg),
D(ModRM | SrcMem | NoAccess | DstReg), D(ModRM | SrcMem | NoAccess | DstReg),
I(ImplicitOps | SrcMem16 | ModRM, em_mov_sreg_rm), I(ImplicitOps | SrcMem16 | ModRM, em_mov_sreg_rm),
G(0, group1A), G(0, group1A),
...@@ -3182,7 +3186,7 @@ static struct opcode opcode_table[256] = { ...@@ -3182,7 +3186,7 @@ static struct opcode opcode_table[256] = {
II(ImplicitOps | Stack, em_popf, popf), N, N, II(ImplicitOps | Stack, em_popf, popf), N, N,
/* 0xA0 - 0xA7 */ /* 0xA0 - 0xA7 */
I2bv(DstAcc | SrcMem | Mov | MemAbs, em_mov), I2bv(DstAcc | SrcMem | Mov | MemAbs, em_mov),
I2bv(DstMem | SrcAcc | Mov | MemAbs, em_mov), I2bv(DstMem | SrcAcc | Mov | MemAbs | PageTable, em_mov),
I2bv(SrcSI | DstDI | Mov | String, em_mov), I2bv(SrcSI | DstDI | Mov | String, em_mov),
I2bv(SrcSI | DstDI | String, em_cmp), I2bv(SrcSI | DstDI | String, em_cmp),
/* 0xA8 - 0xAF */ /* 0xA8 - 0xAF */
...@@ -3280,12 +3284,13 @@ static struct opcode twobyte_table[256] = { ...@@ -3280,12 +3284,13 @@ static struct opcode twobyte_table[256] = {
D(DstMem | SrcReg | Src2CL | ModRM), N, N, D(DstMem | SrcReg | Src2CL | ModRM), N, N,
/* 0xA8 - 0xAF */ /* 0xA8 - 0xAF */
I(Stack | Src2GS, em_push_sreg), I(Stack | Src2GS, em_pop_sreg), I(Stack | Src2GS, em_push_sreg), I(Stack | Src2GS, em_pop_sreg),
DI(ImplicitOps, rsm), D(DstMem | SrcReg | ModRM | BitOp | Lock), DI(ImplicitOps, rsm),
D(DstMem | SrcReg | ModRM | BitOp | Lock | PageTable),
D(DstMem | SrcReg | Src2ImmByte | ModRM), D(DstMem | SrcReg | Src2ImmByte | ModRM),
D(DstMem | SrcReg | Src2CL | ModRM), D(DstMem | SrcReg | Src2CL | ModRM),
D(ModRM), I(DstReg | SrcMem | ModRM, em_imul), D(ModRM), I(DstReg | SrcMem | ModRM, em_imul),
/* 0xB0 - 0xB7 */ /* 0xB0 - 0xB7 */
D2bv(DstMem | SrcReg | ModRM | Lock), D2bv(DstMem | SrcReg | ModRM | Lock | PageTable),
I(DstReg | SrcMemFAddr | ModRM | Src2SS, em_lseg), I(DstReg | SrcMemFAddr | ModRM | Src2SS, em_lseg),
D(DstMem | SrcReg | ModRM | BitOp | Lock), D(DstMem | SrcReg | ModRM | BitOp | Lock),
I(DstReg | SrcMemFAddr | ModRM | Src2FS, em_lseg), I(DstReg | SrcMemFAddr | ModRM | Src2FS, em_lseg),
...@@ -3293,7 +3298,7 @@ static struct opcode twobyte_table[256] = { ...@@ -3293,7 +3298,7 @@ static struct opcode twobyte_table[256] = {
D(ByteOp | DstReg | SrcMem | ModRM | Mov), D(DstReg | SrcMem16 | ModRM | Mov), D(ByteOp | DstReg | SrcMem | ModRM | Mov), D(DstReg | SrcMem16 | ModRM | Mov),
/* 0xB8 - 0xBF */ /* 0xB8 - 0xBF */
N, N, N, N,
G(BitOp, group8), D(DstMem | SrcReg | ModRM | BitOp | Lock), G(BitOp, group8), D(DstMem | SrcReg | ModRM | BitOp | Lock | PageTable),
D(DstReg | SrcMem | ModRM), D(DstReg | SrcMem | ModRM), D(DstReg | SrcMem | ModRM), D(DstReg | SrcMem | ModRM),
D(ByteOp | DstReg | SrcMem | ModRM | Mov), D(DstReg | SrcMem16 | ModRM | Mov), D(ByteOp | DstReg | SrcMem | ModRM | Mov), D(DstReg | SrcMem16 | ModRM | Mov),
/* 0xC0 - 0xCF */ /* 0xC0 - 0xCF */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment