Skip to content

Commit 6e3133d

Browse files
Fenghua Yusuryasaimadhu
authored andcommitted
tools/objtool: Check for use of the ENQCMD instruction in the kernel
The ENQCMD instruction implicitly accesses the PASID_MSR to fill in the pasid field of the descriptor being submitted to an accelerator. But there is no precise (and stable across kernel changes) point at which the PASID_MSR is updated from the value for one task to the next. Kernel code that uses accelerators must always use the ENQCMDS instruction which does not access the PASID_MSR. Check for use of the ENQCMD instruction in the kernel and warn on its usage. Signed-off-by: Fenghua Yu <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Reviewed-by: Tony Luck <[email protected]> Acked-by: Josh Poimboeuf <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 7c1ef59 commit 6e3133d

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

tools/objtool/arch/x86/decode.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ int arch_decode_instruction(struct objtool_file *file, const struct section *sec
112112
const struct elf *elf = file->elf;
113113
struct insn insn;
114114
int x86_64, ret;
115-
unsigned char op1, op2,
115+
unsigned char op1, op2, op3,
116116
rex = 0, rex_b = 0, rex_r = 0, rex_w = 0, rex_x = 0,
117117
modrm = 0, modrm_mod = 0, modrm_rm = 0, modrm_reg = 0,
118118
sib = 0, /* sib_scale = 0, */ sib_index = 0, sib_base = 0;
@@ -139,6 +139,7 @@ int arch_decode_instruction(struct objtool_file *file, const struct section *sec
139139

140140
op1 = insn.opcode.bytes[0];
141141
op2 = insn.opcode.bytes[1];
142+
op3 = insn.opcode.bytes[2];
142143

143144
if (insn.rex_prefix.nbytes) {
144145
rex = insn.rex_prefix.bytes[0];
@@ -491,6 +492,14 @@ int arch_decode_instruction(struct objtool_file *file, const struct section *sec
491492
/* nopl/nopw */
492493
*type = INSN_NOP;
493494

495+
} else if (op2 == 0x38 && op3 == 0xf8) {
496+
if (insn.prefixes.nbytes == 1 &&
497+
insn.prefixes.bytes[0] == 0xf2) {
498+
/* ENQCMD cannot be used in the kernel. */
499+
WARN("ENQCMD instruction at %s:%lx", sec->name,
500+
offset);
501+
}
502+
494503
} else if (op2 == 0xa0 || op2 == 0xa8) {
495504

496505
/* push fs/gs */

0 commit comments

Comments
 (0)