Re: Re: Re: Re: [PATCH] x86/bugs: KVM: Add support for SRSO_MSR_FIX

Patrick Bellasi
2025-02-13T17:51:28Z

> On Thu, Feb 13, 2025 at 01:44:08PM +0000, Patrick Bellasi wrote:
> > Following (yet another) updated versions accounting for this.
> >
> Here's a tested one. You could've simply waited as I told you I'm working on
> it.

Thanks Borislav, no problems for me, I'm just looking into these SRSO fixes and
what I did was mostly a way to ramp up.

> I'm going to queue this one next week into tip once Patrick's fix becomes part
> of -rc3.

Thanks for all the efforts.

Meanwhile I've a couple of questions about the approach proposed here.

> + * 'Mitigation: Reduced Speculation':
> +
> + This mitigation gets automatically enabled when the above one "IBPB on
> + VMEXIT" has been selected and the CPU supports the BpSpecReduce bit.
> +
> + It gets automatically enabled on machines which have the
> + SRSO_USER_KERNEL_NO=1 CPUID bit. In that case, the code logic is to switch
> + to the above =ibpb-vmexit mitigation because the user/kernel boundary is
> + not affected anymore and thus "safe RET" is not needed.
> +
> + After enabling the IBPB on VMEXIT mitigation option, the BpSpecReduce bit
> + is detected (functionality present on all such machines) and that
> + practically overrides IBPB on VMEXIT as it has a lot less performance
> + impact and takes care of the guest->host attack vector too.
> +
> + Currently, the mitigation uses KVM's user_return approach
> + (kvm_set_user_return_msr()) to set the BpSpecReduce bit when a vCPU runs
> + a guest and reset it upon return to host userspace or when the KVM module
> + is unloaded. The intent being, the small perf impact of BpSpecReduce should
> + be incurred only when really necessary.

According to [1], the AMD Whitepaper on SRSO says:

Processors which set SRSO_MSR_FIX=1 support an MSR bit which mitigates SRSO
across guest/host boundaries. Software may enable this by setting bit 4
(BpSpecReduce) of MSR C001_102E. This bit can be set once during boot and
should be set identically across all processors in the system.

The "should be set identically across all processors in the system" makes me
wondering if using the "KVM's user_return approach" proposed here is robust
enough. Could this not lead to the bit being possibly set only on some CPU
but not others?

Am I missing something? Is the MSR used something "shared" across all the cores
of a CPU, i.e. as long a vCPU is running the entire system is still protected?
Maybe there is even just a more recent whitepaper (I did not find) online with
a different recommendation?

Also, setting the MSR bit only while the guest is running, is it sufficient to
prevent both speculation and training?

Think about this scenario:
(a) Guest runs with BpSpecReduce MSR set by KVM and performs training.
(b) We exit into userspace and clear BpSpecReduce.
(c) We go back into the kernel with BpSpecReduce cleared and the guest
training intact.

If (a) can be done (i.e. the MSR does not prevent training), don't we end up in
a vulnerable state in (c)?

If BpSpecReduce does not prevent training, but only the training from being
used, should not we keep it consistently set after a guest has run, or until an
IBPB is executed?

Best,
Patrick

[1] https://www.amd.com/content/dam/amd/en/documents/corporate/cr/speculative-return-stack-overflow-whitepaper.pdf