Re: [PATCH 7/8] tools/objtool: Check for use of the ENQCMD instruction in the kernel

From: Peter Zijlstra
Date: Wed Sep 22 2021 - 17:04:10 EST


On Mon, Sep 20, 2021 at 07:23:48PM +0000, Fenghua Yu wrote:


> diff --git a/tools/objtool/check.c b/tools/objtool/check.c
> index e5947fbb9e7a..91d13521d9d6 100644
> --- a/tools/objtool/check.c
> +++ b/tools/objtool/check.c
> @@ -3133,6 +3133,21 @@ static int validate_reachable_instructions(struct objtool_file *file)
> return 0;
> }
>
> +static int validate_enqcmd(struct objtool_file *file)
> +{
> + struct instruction *insn;
> +
> + for_each_insn(file, insn) {
> + if (insn->type == INSN_ENQCMD) {
> + WARN_FUNC("enqcmd instruction", insn->sec,
> + insn->offset);
> + return 1;
> + }
> + }
> +
> + return 0;
> +}
> +
> int check(struct objtool_file *file)
> {
> int ret, warnings = 0;
> @@ -3147,6 +3162,11 @@ int check(struct objtool_file *file)
> if (list_empty(&file->insn_list))
> goto out;
>
> + ret = validate_enqcmd(file);
> + if (ret < 0)
> + goto out;
> + warnings += ret;
> +
> if (vmlinux && !validate_dup) {
> ret = validate_vmlinux_functions(file);
> if (ret < 0)

Since you're making it a fatal error, before doing much of anything
else, you might at well fail decode and keep it all in the x86/decode.c
file, no need to spread this 'knowledge' any further.

There's no actual state associated with it, you just want to avoid the
instruction being present.

Much simpler patch too.