On Wed, Dec 11, 2024 at 02:27:42PM -0800, Sean Christopherson wrote: > How much cost are we talking? Likely 1-2%. That's why I'm simply enabling it by default. > IIUC, this magic bit reduces how much the CPU is allowed to speculate in order > to mitigate potential VM=>host attacks, and that reducing speculation also reduces > overall performance. > > If that's correct, then enabling the magic bit needs to be gated by an appropriate > mitagation being enabled, not forced on automatically just because the CPU supports > X86_FEATURE_SRSO_MSR_FIX. Well, in the default case we have safe-RET - the default - but since it is not needed anymore, it falls back to this thing which is needed when the mitigation is enabled. That's why it also is in the SRSO_CMD_IBPB_ON_VMEXIT case as it is part of the spec_rstack_overflow=ibpb-vmexit mitigation option. So it kinda already does that. When you disable the mitigation, this one won't get enabled either. > And depending on the cost, it might also make sense to set the bit on-demand, and > then clean up when KVM disables virtualization. E.g. wait to set the bit until > entry to a guest is imminent. So the "when to set that bit" discussion kinda remained unfinished the last time. Here's gist: You: | "It's not strictly KVM module load, it's when KVM enables virtualization. E.g. | if userspace clears enable_virt_at_load, the MSR will be toggled every time the | number of VMs goes from 0=>1 and 1=>0. | | But why do this in KVM? E.g. why not set-and-forget in init_amd_zen4()?" I: | "Because there's no need to impose an unnecessary - albeit small - perf impact | on users who don't do virt. | | I'm currently gravitating towards the MSR toggling thing, i.e., only when the | VMs number goes 0=>1 but I'm not sure. If udev rules *always* load kvm.ko then | yes, the toggling thing sounds better. I.e., set it only when really needed." So to answer your current question, it sounds like the user can control the on-demand thing with enable_virt_at_load=0, right? Or do you mean something else different? Thx. -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette