Re: [PATCH] x86/retpoline: Also fill return buffer after idle

From: Peter Zijlstra
Date: Tue Jan 09 2018 - 04:39:18 EST


On Mon, Jan 08, 2018 at 03:51:26PM -0800, Andi Kleen wrote:

> @@ -107,8 +109,15 @@ static inline void mwait_idle_with_hints(unsigned long eax, unsigned long ecx)
> }
>
> __monitor((void *)&current_thread_info()->flags, 0, 0);
> - if (!need_resched())
> + if (!need_resched()) {
> __mwait(eax, ecx);
> + /*
> + * idle could have cleared the return buffer,
> + * so fill it to prevent uncontrolled
> + * speculation.
> + */
> + fill_return_buffer();

wouldn't something like:

if (static_cpu_has(X86_FEATURE_RETPOLINE))
fill_return_buffer();

be much saner? Then we avoid the entire call when not needed and you
don't have to muck with the asm either.

Also, you forgot mwait_idle() in process.c

> + }
> }
> current_clr_polling();
> }
> --
> 2.14.3
>