I was reading this article about a theoretical CPU vulnerability similar to Spectre, and it noted that:
"The attacker needs to train the branch predictor such that it reliably mispredicts the branch."
I roughly understand what branch prediction is and how it works, but what does it mean to "train" a branch predictor? Does this mean biasing one branch such that it is much more computationally expensive than the other, or does it mean to (in a loop) continually have the CPU to correctly predict a particular branch before proceeding to the next, mispredicted branch?
E.g.,
// Train branch predictor
for (int i = 0; i < 512; i++)
{
if (true){
// Do some instructions
} else {
// Do some other instruction
}
}
// The branch predictor is now "trained"/biased to predict the first branch?
// Proceed to attack
Do the branch predictors use weights to bias the prediction or one way or the other based on previous predictions/mispredictions?