Re: [PATCH] x86: add hintable NOPs emulation

From: Ahmed S. Darwish
Date: Wed Aug 20 2025 - 05:27:41 EST


Hi Marcos,

On Wed, 20 Aug 2025, Marcos Del Sol Vives wrote:
...
>
> --- a/arch/x86/include/asm/processor.h
> +++ b/arch/x86/include/asm/processor.h
> @@ -499,6 +499,10 @@ struct thread_struct {
>
> unsigned int iopl_warn:1;
>
> +#ifdef CONFIG_X86_HNOP_EMU
> + unsigned int hnop_warn:1;
> +#endif
> +
...
> --- a/arch/x86/kernel/process.c
> +++ b/arch/x86/kernel/process.c
> @@ -178,6 +178,9 @@ int copy_thread(struct task_struct *p, const struct kernel_clone_args *args)
> p->thread.io_bitmap = NULL;
> clear_tsk_thread_flag(p, TIF_IO_BITMAP);
> p->thread.iopl_warn = 0;
> +#ifdef CONFIG_X86_HNOP_EMU
> + p->thread.hnop_warn = 0;
> +#endif
...
> --- a/arch/x86/kernel/traps.c
> +++ b/arch/x86/kernel/traps.c
> +
> + if (!t->hnop_warn) {
> + pr_warn_ratelimited("%s[%d] emulating hintable NOP, ip:%lx\n",
> + current->comm, task_pid_nr(current), regs->ip);
> + t->hnop_warn = 1;
> + }

Can we please remove all this 'hnop_warn' trickery? Removing it will
simplifiy the code and avoid complicating 'thread_struct' further.

It's just the kernel doing its normal job.

And if the system is full of binaries with hintable NOPs, ratelimiting
will not save you much. I got hit recently by a 'ratelimited'
correctible error PCI subsystem warning, and it still overflows the log
buffers of my Thinkpad laptop, in just 4 to 5 days :(

>
> static inline void handle_invalid_op(struct pt_regs *regs)
> {
> +#ifdef CONFIG_X86_HNOP_EMU
> + if (user_mode(regs) && handle_hnop(regs))
> + return;
> +#endif
> +
>

CPP conditionals within C function code are ugly. Please do instead:

static bool handle_hnop(struct pt_regs *regs)
{
if (!IS_ENABLED(CONFIG_X86_HNOP_EMU))
return false;
...
}

Thanks for your contribution!

--
Ahmed S. Darwish
Linutronix GmbH