2015-02-12 19:05:23

by Denys Vlasenko

[permalink] [raw]
Subject: [PATCH] x86: insn decoder: create artificial 3rd byte for 2-byte VEX

Before this patch, users need to do this to fetch vex.vvvv:

if (insn->vex_prefix.nbytes == 2) {
vex_vvvv = ((insn->vex_prefix.bytes[1] >> 3) & 0xf) ^ 0xf;
}
if (insn->vex_prefix.nbytes == 3) {
vex_vvvv = ((insn->vex_prefix.bytes[2] >> 3) & 0xf) ^ 0xf;
}

Make it so that insn->vex_prefix.bytes[2] always contains vex.wvvvvLpp bits.

Signed-off-by: Denys Vlasenko <[email protected]>
Cc: Masami Hiramatsu <[email protected]>
Cc: Frank Ch. Eigler <[email protected]>
Cc: Srikar Dronamraju <[email protected]>
Cc: Ananth N Mavinakayanahalli <[email protected]>
Cc: Jim Keniston <[email protected]>
Cc: Oleg Nesterov <[email protected]>
Cc: Andi Kleen <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: [email protected]
---

Masami, you were ok with this patch last time it was posted.
Can you "officially" add your Acked-By?

arch/x86/lib/insn.c | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
index 54fcffe..829ca4c 100644
--- a/arch/x86/lib/insn.c
+++ b/arch/x86/lib/insn.c
@@ -163,6 +163,12 @@ found:
/* VEX.W overrides opnd_size */
insn->opnd_bytes = 8;
} else {
+ /*
+ * For VEX2, fake VEX3-like byte#2.
+ * Makes it easier to decode vex.W, vex.vvvv,
+ * vex.L and vex.pp. Masking with 0x7f sets vex.W == 0.
+ */
+ insn->vex_prefix.bytes[2] = b2 & 0x7f;
insn->vex_prefix.nbytes = 2;
insn->next_byte += 2;
}
--
1.8.1.4


Subject: Re: [PATCH] x86: insn decoder: create artificial 3rd byte for 2-byte VEX

(2015/02/13 4:04), Denys Vlasenko wrote:
> Before this patch, users need to do this to fetch vex.vvvv:
>
> if (insn->vex_prefix.nbytes == 2) {
> vex_vvvv = ((insn->vex_prefix.bytes[1] >> 3) & 0xf) ^ 0xf;
> }
> if (insn->vex_prefix.nbytes == 3) {
> vex_vvvv = ((insn->vex_prefix.bytes[2] >> 3) & 0xf) ^ 0xf;
> }
>
> Make it so that insn->vex_prefix.bytes[2] always contains vex.wvvvvLpp bits.
>
> Signed-off-by: Denys Vlasenko <[email protected]>

Looks OK for me :)

Acked-by: Masami Hiramatsu <[email protected]>

BTW, where would you use this ??

> Cc: Masami Hiramatsu <[email protected]>
> Cc: Frank Ch. Eigler <[email protected]>
> Cc: Srikar Dronamraju <[email protected]>
> Cc: Ananth N Mavinakayanahalli <[email protected]>
> Cc: Jim Keniston <[email protected]>
> Cc: Oleg Nesterov <[email protected]>
> Cc: Andi Kleen <[email protected]>
> Cc: Ingo Molnar <[email protected]>
> Cc: [email protected]
> ---
>
> Masami, you were ok with this patch last time it was posted.
> Can you "officially" add your Acked-By?
>
> arch/x86/lib/insn.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
> index 54fcffe..829ca4c 100644
> --- a/arch/x86/lib/insn.c
> +++ b/arch/x86/lib/insn.c
> @@ -163,6 +163,12 @@ found:
> /* VEX.W overrides opnd_size */
> insn->opnd_bytes = 8;
> } else {
> + /*
> + * For VEX2, fake VEX3-like byte#2.
> + * Makes it easier to decode vex.W, vex.vvvv,
> + * vex.L and vex.pp. Masking with 0x7f sets vex.W == 0.
> + */
> + insn->vex_prefix.bytes[2] = b2 & 0x7f;
> insn->vex_prefix.nbytes = 2;
> insn->next_byte += 2;
> }
>


--
Masami HIRAMATSU
Software Platform Research Dept. Linux Technology Research Center
Hitachi, Ltd., Yokohama Research Laboratory
E-mail: [email protected]

2015-02-13 14:13:10

by Denys Vlasenko

[permalink] [raw]
Subject: Re: [PATCH] x86: insn decoder: create artificial 3rd byte for 2-byte VEX

On Fri, Feb 13, 2015 at 1:32 PM, Masami Hiramatsu
<[email protected]> wrote:
> (2015/02/13 4:04), Denys Vlasenko wrote:
>> Before this patch, users need to do this to fetch vex.vvvv:
>>
>> if (insn->vex_prefix.nbytes == 2) {
>> vex_vvvv = ((insn->vex_prefix.bytes[1] >> 3) & 0xf) ^ 0xf;
>> }
>> if (insn->vex_prefix.nbytes == 3) {
>> vex_vvvv = ((insn->vex_prefix.bytes[2] >> 3) & 0xf) ^ 0xf;
>> }
>>
>> Make it so that insn->vex_prefix.bytes[2] always contains vex.wvvvvLpp bits.
>>
>> Signed-off-by: Denys Vlasenko <[email protected]>
>
> Looks OK for me :)
>
> Acked-by: Masami Hiramatsu <[email protected]>
>
> BTW, where would you use this ??

arch/x86/kernel/uprobes.c

reg2 = 0xff; /* Fetch vex.vvvv */
if (insn->vex_prefix.nbytes == 2)
reg2 = insn->vex_prefix.bytes[1];
else if (insn->vex_prefix.nbytes == 3)
reg2 = insn->vex_prefix.bytes[2];


https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/arch/x86/kernel/uprobes.c#n354

Subject: [tip:x86/asm] x86/asm/decoder: Create artificial 3rd byte for 2-byte VEX

Commit-ID: 8a764a875fe3cf3a83296bacd00bfc41917e95e2
Gitweb: http://git.kernel.org/tip/8a764a875fe3cf3a83296bacd00bfc41917e95e2
Author: Denys Vlasenko <[email protected]>
AuthorDate: Thu, 12 Feb 2015 20:04:39 +0100
Committer: Ingo Molnar <[email protected]>
CommitDate: Wed, 18 Feb 2015 21:01:50 +0100

x86/asm/decoder: Create artificial 3rd byte for 2-byte VEX

Before this patch, users need to do this to fetch vex.vvvv:

if (insn->vex_prefix.nbytes == 2) {
vex_vvvv = ((insn->vex_prefix.bytes[1] >> 3) & 0xf) ^ 0xf;
}
if (insn->vex_prefix.nbytes == 3) {
vex_vvvv = ((insn->vex_prefix.bytes[2] >> 3) & 0xf) ^ 0xf;
}

Make it so that insn->vex_prefix.bytes[2] always contains
vex.wvvvvLpp bits.

Signed-off-by: Denys Vlasenko <[email protected]>
Acked-by: Masami Hiramatsu <[email protected]>
Cc: Ananth N Mavinakayanahalli <[email protected]>
Cc: Frank Ch. Eigler <[email protected]>
Cc: Jim Keniston <[email protected]>
Cc: Oleg Nesterov <[email protected]>
Cc: Srikar Dronamraju <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Ingo Molnar <[email protected]>
---
arch/x86/lib/insn.c | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
index 1313ae6..5ea00dd 100644
--- a/arch/x86/lib/insn.c
+++ b/arch/x86/lib/insn.c
@@ -164,6 +164,12 @@ found:
/* VEX.W overrides opnd_size */
insn->opnd_bytes = 8;
} else {
+ /*
+ * For VEX2, fake VEX3-like byte#2.
+ * Makes it easier to decode vex.W, vex.vvvv,
+ * vex.L and vex.pp. Masking with 0x7f sets vex.W == 0.
+ */
+ insn->vex_prefix.bytes[2] = b2 & 0x7f;
insn->vex_prefix.nbytes = 2;
insn->next_byte += 2;
}