Re: [PATCH 30/35] x86/speculation: Use Indirect Branch Prediction Barrier in context switch

From: Tim Chen
Date: Thu Jan 18 2018 - 19:38:43 EST


On 01/18/2018 05:48 AM, Peter Zijlstra wrote:
>
>+ /*
>+ * Avoid user/user BTB poisoning by flushing the branch predictor
>+ * when switching between processes. This stops one process from
>+ * doing spectre-v2 attacks on another process's data.
>+ */
>+ indirect_branch_prediction_barrier();
>+

Some optimizations can be done here to avoid overhead in barrier call.

For example, don't do the barrier if prev and next mm are
the same. If the two process trust each other, or the new process
already have rights to look into the previous process,
the barrier could be skipped.

Tim