KVM: x86: Allow guests to see MSR_IA32_TSX_CTRL even if tsx=off
authorPaolo Bonzini <pbonzini@redhat.com>
Thu, 28 Jan 2021 16:45:00 +0000 (11:45 -0500)
committerPaolo Bonzini <pbonzini@redhat.com>
Mon, 1 Feb 2021 17:43:00 +0000 (12:43 -0500)
commit7131636e7ea5b50ca910f8953f6365ef2d1f741c
tree1bda4dd798326915c21e97b70242e51aec3bbda1
parent19a23da53932bc8011220bd8c410cb76012de004
KVM: x86: Allow guests to see MSR_IA32_TSX_CTRL even if tsx=off

Userspace that does not know about KVM_GET_MSR_FEATURE_INDEX_LIST
will generally use the default value for MSR_IA32_ARCH_CAPABILITIES.
When this happens and the host has tsx=on, it is possible to end up with
virtual machines that have HLE and RTM disabled, but TSX_CTRL available.

If the fleet is then switched to tsx=off, kvm_get_arch_capabilities()
will clear the ARCH_CAP_TSX_CTRL_MSR bit and it will not be possible to
use the tsx=off hosts as migration destinations, even though the guests
do not have TSX enabled.

To allow this migration, allow guests to write to their TSX_CTRL MSR,
while keeping the host MSR unchanged for the entire life of the guests.
This ensures that TSX remains disabled and also saves MSR reads and
writes, and it's okay to do because with tsx=off we know that guests will
not have the HLE and RTM features in their CPUID.  (If userspace sets
bogus CPUID data, we do not expect HLE and RTM to work in guests anyway).

Cc: stable@vger.kernel.org
Fixes: cbbaa2727aa3 ("KVM: x86: fix presentation of TSX feature in ARCH_CAPABILITIES")
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/vmx/vmx.c
arch/x86/kvm/x86.c