Skip to contentSkip to conversation

x86: insn decoder: create artificial 3rd byte for 2-byte VEX

PATCH In review Denys Vlasenko 4 participants 4 messages Feb 12, 2015 – Feb 19, 2015 x86

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

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]>

---

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(+)
arch/x86/lib/insn.c +6 -0
index 54fcffe..829ca4c 100644
@@ -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;
 		}
Signature · 1 line
1.8.1.4
Acked-by on v1 1/1
#1 lore raw
Quoted 9 lines · Denys Vlasenko

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;
        }
Quoted 3 lines

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

Looks OK for me :)

BTW, where would you use this ??

Quoted 35 lines
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]>

---

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(+)
arch/x86/lib/insn.c +6 -0
index 54fcffe..829ca4c 100644
@@ -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;
 		}
Signature · 4 lines
Masami HIRAMATSU
Software Platform Research Dept. Linux Technology Research Center
Hitachi, Ltd., Yokohama Research Laboratory
E-mail: [email protected]
#2 lore raw
Quoted 12 lines · Masami Hiramatsu
Quoted 11 lines · Denys Vlasenko

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.

Quoted 7 lines
Quoted 1 line

Looks OK for me :)

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

#3 lore raw

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

In reply to Denys Vlasenko
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.

---
 arch/x86/lib/insn.c | 6 ++++++
 1 file changed, 6 insertions(+)
arch/x86/lib/insn.c +6 -0
index 1313ae6..5ea00dd 100644
@@ -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;
 		}