Re: [PATCH 1/2] x86/bhi: Add BHB clearing for CPUs with larger branch history
From: Pawan Gupta
Date: Thu Sep 25 2025 - 16:49:51 EST
On Thu, Sep 25, 2025 at 10:54:48AM -0700, Jim Mattson wrote:
> On Wed, Sep 24, 2025 at 8:09 PM Pawan Gupta
> <pawan.kumar.gupta@xxxxxxxxxxxxxxx> wrote:
> >
> > Add a version of clear_bhb_loop() that works on CPUs with larger branch
> > history table such as Alder Lake and newer. This could serve as a cheaper
> > alternative to IBPB mitigation for VMSCAPE.
>
> Yay!
>
> Can we also use this longer loop as a BHI mitigation on (virtual)
> processors with larger branch history tables that don't support
> BHI_DIS_S? Today, we just use the short BHB clearing loop and call it
> good.
I believe you are referring to guests that don't enumerate BHI_DIS_S, but
are running on a host that supports BHI_DIS_S. In that case the longer loop
would work to mitigate BHI.
You probably know it already, the longer loop is not an optimal mitigation
compared to BHI_DIS_S. And on CPUs that don't support BHI_DIS_S, short loop
is sufficient.
I think you are talking about some special use cases like a guest migrating
from a CPU that didn't support BHI_DIS_S to a CPU that does. Using the long
loop in that case would be an option.