Re: [PATCH] x86: add hintable NOPs emulation

From: Marcos Del Sol Vives
Date: Thu Aug 21 2025 - 08:54:51 EST


El 21/08/2025 a las 14:26, David Laight escribió:
> Marcos Del Sol Vives <marcos@xxxxxxxx> wrote:
>> + if (!insn_decode_from_regs(&insn, regs, buf, nr_copied))
>> + return false;
>> +
>> + /* Hintable NOPs cover 0F 18 to 0F 1F */
>> + if (insn.opcode.bytes[0] != 0x0F ||
>> + insn.opcode.bytes[1] < 0x18 || insn.opcode.bytes[1] > 0x1F)
>> + return false;
>
> Can you swap the order of those tests?
> Looks like the 'decode' is only needed for the length.
>

Not really. The opcodes may have prefixes that are "removed" by the decode
function. ENDBR32 for instance is actually "F3 0F 1E FB", with a REP
prefix.

>> +#ifdef CONFIG_X86_HNOP_EMU
>> + if (user_mode(regs) && handle_hnop(regs))
>> + return;
>
> Why not move the user_mode() test into handle_hnop() ?
> Should make the config tests easier.
>

Other code I saw did this in the calling function itself (eg handle_bug)
so I did it here too.