* [PATCH 0/2 v2] KVM: x86 emulator: Simplify ModRM fetching
@ 2012-04-30 8:43 Takuya Yoshikawa
2012-04-30 8:46 ` [PATCH 1/2] KVM: x86 emulator: Move ModRM flags for groups to top level opcode tables Takuya Yoshikawa
` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: Takuya Yoshikawa @ 2012-04-30 8:43 UTC (permalink / raw)
To: avi, mtosatti; +Cc: kvm, yoshikawa.takuya
Updated based on Avi's advice.
Takuya Yoshikawa (2):
KVM: x86 emulator: Move ModRM flags for groups to top level opcode tables
KVM: x86 emulator: Avoid pushing back ModRM byte fetched for group decoding
arch/x86/kvm/emulate.c | 119 ++++++++++++++++++++++++------------------------
1 files changed, 59 insertions(+), 60 deletions(-)
--
1.7.5.4
^ permalink raw reply [flat|nested] 7+ messages in thread* [PATCH 1/2] KVM: x86 emulator: Move ModRM flags for groups to top level opcode tables 2012-04-30 8:43 [PATCH 0/2 v2] KVM: x86 emulator: Simplify ModRM fetching Takuya Yoshikawa @ 2012-04-30 8:46 ` Takuya Yoshikawa 2012-04-30 10:31 ` Avi Kivity 2012-04-30 8:48 ` [PATCH 2/2 v2] KVM: x86 emulator: Avoid pushing back ModRM byte fetched for group decoding Takuya Yoshikawa ` (2 subsequent siblings) 3 siblings, 1 reply; 7+ messages in thread From: Takuya Yoshikawa @ 2012-04-30 8:46 UTC (permalink / raw) To: avi, mtosatti; +Cc: kvm, yoshikawa.takuya From: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp> Needed for the following patch which simplifies ModRM fetching code. Signed-off-by: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp> --- arch/x86/kvm/emulate.c | 111 ++++++++++++++++++++++++------------------------ 1 files changed, 56 insertions(+), 55 deletions(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index 0d151e2..8d2c3d0 100644 --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c @@ -3359,8 +3359,8 @@ static int check_perm_out(struct x86_emulate_ctxt *ctxt) .check_perm = (_p) } #define N D(0) #define EXT(_f, _e) { .flags = ((_f) | RMExt), .u.group = (_e) } -#define G(_f, _g) { .flags = ((_f) | Group), .u.group = (_g) } -#define GD(_f, _g) { .flags = ((_f) | GroupDual), .u.gdual = (_g) } +#define G(_f, _g) { .flags = ((_f) | Group | ModRM), .u.group = (_g) } +#define GD(_f, _g) { .flags = ((_f) | GroupDual | ModRM), .u.gdual = (_g) } #define I(_f, _e) { .flags = (_f), .u.execute = (_e) } #define II(_f, _e, _i) \ { .flags = (_f), .u.execute = (_e), .intercept = x86_intercept_##_i } @@ -3380,25 +3380,25 @@ static int check_perm_out(struct x86_emulate_ctxt *ctxt) I2bv(((_f) & ~Lock) | DstAcc | SrcImm, _e) static struct opcode group7_rm1[] = { - DI(SrcNone | ModRM | Priv, monitor), - DI(SrcNone | ModRM | Priv, mwait), + DI(SrcNone | Priv, monitor), + DI(SrcNone | Priv, mwait), N, N, N, N, N, N, }; static struct opcode group7_rm3[] = { - DIP(SrcNone | ModRM | Prot | Priv, vmrun, check_svme_pa), - II(SrcNone | ModRM | Prot | VendorSpecific, em_vmmcall, vmmcall), - DIP(SrcNone | ModRM | Prot | Priv, vmload, check_svme_pa), - DIP(SrcNone | ModRM | Prot | Priv, vmsave, check_svme_pa), - DIP(SrcNone | ModRM | Prot | Priv, stgi, check_svme), - DIP(SrcNone | ModRM | Prot | Priv, clgi, check_svme), - DIP(SrcNone | ModRM | Prot | Priv, skinit, check_svme), - DIP(SrcNone | ModRM | Prot | Priv, invlpga, check_svme), + DIP(SrcNone | Prot | Priv, vmrun, check_svme_pa), + II(SrcNone | Prot | VendorSpecific, em_vmmcall, vmmcall), + DIP(SrcNone | Prot | Priv, vmload, check_svme_pa), + DIP(SrcNone | Prot | Priv, vmsave, check_svme_pa), + DIP(SrcNone | Prot | Priv, stgi, check_svme), + DIP(SrcNone | Prot | Priv, clgi, check_svme), + DIP(SrcNone | Prot | Priv, skinit, check_svme), + DIP(SrcNone | Prot | Priv, invlpga, check_svme), }; static struct opcode group7_rm7[] = { N, - DIP(SrcNone | ModRM, rdtscp, check_rdtsc), + DIP(SrcNone, rdtscp, check_rdtsc), N, N, N, N, N, N, }; @@ -3414,76 +3414,77 @@ static struct opcode group1[] = { }; static struct opcode group1A[] = { - I(DstMem | SrcNone | ModRM | Mov | Stack, em_pop), N, N, N, N, N, N, N, + I(DstMem | SrcNone | Mov | Stack, em_pop), N, N, N, N, N, N, N, }; static struct opcode group3[] = { - I(DstMem | SrcImm | ModRM, em_test), - I(DstMem | SrcImm | ModRM, em_test), - I(DstMem | SrcNone | ModRM | Lock, em_not), - I(DstMem | SrcNone | ModRM | Lock, em_neg), - I(SrcMem | ModRM, em_mul_ex), - I(SrcMem | ModRM, em_imul_ex), - I(SrcMem | ModRM, em_div_ex), - I(SrcMem | ModRM, em_idiv_ex), + I(DstMem | SrcImm, em_test), + I(DstMem | SrcImm, em_test), + I(DstMem | SrcNone | Lock, em_not), + I(DstMem | SrcNone | Lock, em_neg), + I(SrcMem, em_mul_ex), + I(SrcMem, em_imul_ex), + I(SrcMem, em_div_ex), + I(SrcMem, em_idiv_ex), }; static struct opcode group4[] = { - I(ByteOp | DstMem | SrcNone | ModRM | Lock, em_grp45), - I(ByteOp | DstMem | SrcNone | ModRM | Lock, em_grp45), + I(ByteOp | DstMem | SrcNone | Lock, em_grp45), + I(ByteOp | DstMem | SrcNone | Lock, em_grp45), N, N, N, N, N, N, }; static struct opcode group5[] = { - I(DstMem | SrcNone | ModRM | Lock, em_grp45), - I(DstMem | SrcNone | ModRM | Lock, em_grp45), - I(SrcMem | ModRM | Stack, em_grp45), - I(SrcMemFAddr | ModRM | ImplicitOps | Stack, em_call_far), - I(SrcMem | ModRM | Stack, em_grp45), - I(SrcMemFAddr | ModRM | ImplicitOps, em_grp45), - I(SrcMem | ModRM | Stack, em_grp45), N, + I(DstMem | SrcNone | Lock, em_grp45), + I(DstMem | SrcNone | Lock, em_grp45), + I(SrcMem | Stack, em_grp45), + I(SrcMemFAddr | ImplicitOps | Stack, em_call_far), + I(SrcMem | Stack, em_grp45), + I(SrcMemFAddr | ImplicitOps, em_grp45), + I(SrcMem | Stack, em_grp45), N, }; static struct opcode group6[] = { - DI(ModRM | Prot, sldt), - DI(ModRM | Prot, str), - DI(ModRM | Prot | Priv, lldt), - DI(ModRM | Prot | Priv, ltr), + DI(Prot, sldt), + DI(Prot, str), + DI(Prot | Priv, lldt), + DI(Prot | Priv, ltr), N, N, N, N, }; static struct group_dual group7 = { { - DI(ModRM | Mov | DstMem | Priv, sgdt), - DI(ModRM | Mov | DstMem | Priv, sidt), - II(ModRM | SrcMem | Priv, em_lgdt, lgdt), - II(ModRM | SrcMem | Priv, em_lidt, lidt), - II(SrcNone | ModRM | DstMem | Mov, em_smsw, smsw), N, - II(SrcMem16 | ModRM | Mov | Priv, em_lmsw, lmsw), - II(SrcMem | ModRM | ByteOp | Priv | NoAccess, em_invlpg, invlpg), + DI(Mov | DstMem | Priv, sgdt), + DI(Mov | DstMem | Priv, sidt), + II(SrcMem | Priv, em_lgdt, lgdt), + II(SrcMem | Priv, em_lidt, lidt), + II(SrcNone | DstMem | Mov, em_smsw, smsw), N, + II(SrcMem16 | Mov | Priv, em_lmsw, lmsw), + II(SrcMem | ByteOp | Priv | NoAccess, em_invlpg, invlpg), }, { - I(SrcNone | ModRM | Priv | VendorSpecific, em_vmcall), + I(SrcNone | Priv | VendorSpecific, em_vmcall), EXT(0, group7_rm1), N, EXT(0, group7_rm3), - II(SrcNone | ModRM | DstMem | Mov, em_smsw, smsw), N, - II(SrcMem16 | ModRM | Mov | Priv, em_lmsw, lmsw), EXT(0, group7_rm7), + II(SrcNone | DstMem | Mov, em_smsw, smsw), N, + II(SrcMem16 | Mov | Priv, em_lmsw, lmsw), + EXT(0, group7_rm7), } }; static struct opcode group8[] = { N, N, N, N, - I(DstMem | SrcImmByte | ModRM, em_bt), - I(DstMem | SrcImmByte | ModRM | Lock | PageTable, em_bts), - I(DstMem | SrcImmByte | ModRM | Lock, em_btr), - I(DstMem | SrcImmByte | ModRM | Lock | PageTable, em_btc), + I(DstMem | SrcImmByte, em_bt), + I(DstMem | SrcImmByte | Lock | PageTable, em_bts), + I(DstMem | SrcImmByte | Lock, em_btr), + I(DstMem | SrcImmByte | Lock | PageTable, em_btc), }; static struct group_dual group9 = { { - N, I(DstMem64 | ModRM | Lock | PageTable, em_cmpxchg8b), N, N, N, N, N, N, + N, I(DstMem64 | Lock | PageTable, em_cmpxchg8b), N, N, N, N, N, N, }, { N, N, N, N, N, N, N, N, } }; static struct opcode group11[] = { - I(DstMem | SrcImm | ModRM | Mov | PageTable, em_mov), + I(DstMem | SrcImm | Mov | PageTable, em_mov), X7(D(Undefined)), }; @@ -3541,10 +3542,10 @@ static struct opcode opcode_table[256] = { /* 0x70 - 0x7F */ X16(D(SrcImmByte)), /* 0x80 - 0x87 */ - G(ByteOp | DstMem | SrcImm | ModRM | Group, group1), - G(DstMem | SrcImm | ModRM | Group, group1), - G(ByteOp | DstMem | SrcImm | ModRM | No64 | Group, group1), - G(DstMem | SrcImmByte | ModRM | Group, group1), + G(ByteOp | DstMem | SrcImm, group1), + G(DstMem | SrcImm, group1), + G(ByteOp | DstMem | SrcImm | No64, group1), + G(DstMem | SrcImmByte, group1), I2bv(DstMem | SrcReg | ModRM, em_test), I2bv(DstMem | SrcReg | ModRM | Lock | PageTable, em_xchg), /* 0x88 - 0x8F */ -- 1.7.5.4 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] KVM: x86 emulator: Move ModRM flags for groups to top level opcode tables 2012-04-30 8:46 ` [PATCH 1/2] KVM: x86 emulator: Move ModRM flags for groups to top level opcode tables Takuya Yoshikawa @ 2012-04-30 10:31 ` Avi Kivity 2012-04-30 14:20 ` Takuya Yoshikawa 0 siblings, 1 reply; 7+ messages in thread From: Avi Kivity @ 2012-04-30 10:31 UTC (permalink / raw) To: Takuya Yoshikawa; +Cc: mtosatti, kvm, yoshikawa.takuya On 04/30/2012 11:46 AM, Takuya Yoshikawa wrote: > From: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp> > > Needed for the following patch which simplifies ModRM fetching code. > > Signed-off-by: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp> > --- > arch/x86/kvm/emulate.c | 111 ++++++++++++++++++++++++------------------------ > 1 files changed, 56 insertions(+), 55 deletions(-) > > diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c > index 0d151e2..8d2c3d0 100644 > --- a/arch/x86/kvm/emulate.c > +++ b/arch/x86/kvm/emulate.c > @@ -3359,8 +3359,8 @@ static int check_perm_out(struct x86_emulate_ctxt *ctxt) > .check_perm = (_p) } > #define N D(0) > #define EXT(_f, _e) { .flags = ((_f) | RMExt), .u.group = (_e) } > -#define G(_f, _g) { .flags = ((_f) | Group), .u.group = (_g) } > -#define GD(_f, _g) { .flags = ((_f) | GroupDual), .u.gdual = (_g) } > +#define G(_f, _g) { .flags = ((_f) | Group | ModRM), .u.group = (_g) } > +#define GD(_f, _g) { .flags = ((_f) | GroupDual | ModRM), .u.gdual = (_g) } > #define I(_f, _e) { .flags = (_f), .u.execute = (_e) } > #define II(_f, _e, _i) \ > { .flags = (_f), .u.execute = (_e), .intercept = x86_intercept_##_i } > @@ -3380,25 +3380,25 @@ static int check_perm_out(struct x86_emulate_ctxt *ctxt) > I2bv(((_f) & ~Lock) | DstAcc | SrcImm, _e) > > static struct opcode group7_rm1[] = { > - DI(SrcNone | ModRM | Priv, monitor), > - DI(SrcNone | ModRM | Priv, mwait), > + DI(SrcNone | Priv, monitor), > + DI(SrcNone | Priv, mwait), > N, N, N, N, N, N, > }; > Removing ModRM everywhere isn't strictly necessary (but is okay). -- error compiling committee.c: too many arguments to function ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] KVM: x86 emulator: Move ModRM flags for groups to top level opcode tables 2012-04-30 10:31 ` Avi Kivity @ 2012-04-30 14:20 ` Takuya Yoshikawa 0 siblings, 0 replies; 7+ messages in thread From: Takuya Yoshikawa @ 2012-04-30 14:20 UTC (permalink / raw) To: Avi Kivity; +Cc: mtosatti, kvm, yoshikawa.takuya On Mon, 30 Apr 2012 13:31:09 +0300 Avi Kivity <avi@redhat.com> wrote: > > static struct opcode group7_rm1[] = { > > - DI(SrcNone | ModRM | Priv, monitor), > > - DI(SrcNone | ModRM | Priv, mwait), > > + DI(SrcNone | Priv, monitor), > > + DI(SrcNone | Priv, mwait), > > N, N, N, N, N, N, > > }; > > > > Removing ModRM everywhere isn't strictly necessary (but is okay). As ModRMs were inconsistently distributed, I wanted to make them consistent. If they are consistently written in everywhere, I like that style too! Takuya ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 2/2 v2] KVM: x86 emulator: Avoid pushing back ModRM byte fetched for group decoding 2012-04-30 8:43 [PATCH 0/2 v2] KVM: x86 emulator: Simplify ModRM fetching Takuya Yoshikawa 2012-04-30 8:46 ` [PATCH 1/2] KVM: x86 emulator: Move ModRM flags for groups to top level opcode tables Takuya Yoshikawa @ 2012-04-30 8:48 ` Takuya Yoshikawa 2012-04-30 10:33 ` [PATCH 0/2 v2] KVM: x86 emulator: Simplify ModRM fetching Avi Kivity 2012-05-06 13:16 ` Avi Kivity 3 siblings, 0 replies; 7+ messages in thread From: Takuya Yoshikawa @ 2012-04-30 8:48 UTC (permalink / raw) To: avi, mtosatti; +Cc: kvm, yoshikawa.takuya From: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp> Although ModRM byte is fetched for group decoding, it is soon pushed back to make decode_modrm() fetch it later again. Now that ModRM flag can be found in the top level opcode tables, fetch ModRM byte before group decoding to make the code simpler. Signed-off-by: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp> --- arch/x86/kvm/emulate.c | 8 +++----- 1 files changed, 3 insertions(+), 5 deletions(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index 8d2c3d0..7fd2576 100644 --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c @@ -972,7 +972,6 @@ static int decode_modrm(struct x86_emulate_ctxt *ctxt, ctxt->modrm_rm = base_reg = (ctxt->rex_prefix & 1) << 3; /* REG.B */ } - ctxt->modrm = insn_fetch(u8, ctxt); ctxt->modrm_mod |= (ctxt->modrm & 0xc0) >> 6; ctxt->modrm_reg |= (ctxt->modrm & 0x38) >> 3; ctxt->modrm_rm |= (ctxt->modrm & 0x07); @@ -3976,17 +3975,16 @@ done_prefixes: } ctxt->d = opcode.flags; + if (ctxt->d & ModRM) + ctxt->modrm = insn_fetch(u8, ctxt); + while (ctxt->d & GroupMask) { switch (ctxt->d & GroupMask) { case Group: - ctxt->modrm = insn_fetch(u8, ctxt); - --ctxt->_eip; goffset = (ctxt->modrm >> 3) & 7; opcode = opcode.u.group[goffset]; break; case GroupDual: - ctxt->modrm = insn_fetch(u8, ctxt); - --ctxt->_eip; goffset = (ctxt->modrm >> 3) & 7; if ((ctxt->modrm >> 6) == 3) opcode = opcode.u.gdual->mod3[goffset]; -- 1.7.5.4 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 0/2 v2] KVM: x86 emulator: Simplify ModRM fetching 2012-04-30 8:43 [PATCH 0/2 v2] KVM: x86 emulator: Simplify ModRM fetching Takuya Yoshikawa 2012-04-30 8:46 ` [PATCH 1/2] KVM: x86 emulator: Move ModRM flags for groups to top level opcode tables Takuya Yoshikawa 2012-04-30 8:48 ` [PATCH 2/2 v2] KVM: x86 emulator: Avoid pushing back ModRM byte fetched for group decoding Takuya Yoshikawa @ 2012-04-30 10:33 ` Avi Kivity 2012-05-06 13:16 ` Avi Kivity 3 siblings, 0 replies; 7+ messages in thread From: Avi Kivity @ 2012-04-30 10:33 UTC (permalink / raw) To: Takuya Yoshikawa; +Cc: mtosatti, kvm, yoshikawa.takuya On 04/30/2012 11:43 AM, Takuya Yoshikawa wrote: > Updated based on Avi's advice. > > Takuya Yoshikawa (2): > KVM: x86 emulator: Move ModRM flags for groups to top level opcode tables > KVM: x86 emulator: Avoid pushing back ModRM byte fetched for group decoding > Looks good. -- error compiling committee.c: too many arguments to function ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 0/2 v2] KVM: x86 emulator: Simplify ModRM fetching 2012-04-30 8:43 [PATCH 0/2 v2] KVM: x86 emulator: Simplify ModRM fetching Takuya Yoshikawa ` (2 preceding siblings ...) 2012-04-30 10:33 ` [PATCH 0/2 v2] KVM: x86 emulator: Simplify ModRM fetching Avi Kivity @ 2012-05-06 13:16 ` Avi Kivity 3 siblings, 0 replies; 7+ messages in thread From: Avi Kivity @ 2012-05-06 13:16 UTC (permalink / raw) To: Takuya Yoshikawa; +Cc: mtosatti, kvm, yoshikawa.takuya On 04/30/2012 11:43 AM, Takuya Yoshikawa wrote: > Updated based on Avi's advice. > > Takuya Yoshikawa (2): > KVM: x86 emulator: Move ModRM flags for groups to top level opcode tables > KVM: x86 emulator: Avoid pushing back ModRM byte fetched for group decoding > > Thanks, applied. -- error compiling committee.c: too many arguments to function ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2012-05-06 13:16 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2012-04-30 8:43 [PATCH 0/2 v2] KVM: x86 emulator: Simplify ModRM fetching Takuya Yoshikawa 2012-04-30 8:46 ` [PATCH 1/2] KVM: x86 emulator: Move ModRM flags for groups to top level opcode tables Takuya Yoshikawa 2012-04-30 10:31 ` Avi Kivity 2012-04-30 14:20 ` Takuya Yoshikawa 2012-04-30 8:48 ` [PATCH 2/2 v2] KVM: x86 emulator: Avoid pushing back ModRM byte fetched for group decoding Takuya Yoshikawa 2012-04-30 10:33 ` [PATCH 0/2 v2] KVM: x86 emulator: Simplify ModRM fetching Avi Kivity 2012-05-06 13:16 ` Avi Kivity
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).