Skip to contentSkip to conversation

KVM: VMX: add MSR_IA32_TSX_CTRL into msrs_to_save

PATCH Superseded Mingwei Zhang 3 participants 4 messages May 3, 2023

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 KVM: VMX: add MSR_IA32_TSX_CTRL into msrs_to_save

Add MSR_IA32_TSX_CTRL into msrs_to_save[] to explicitly tell userspace to save/restore the register value during migration. Missing this may cause userspace that relies on KVM ioctl(KVM_GET_MSR_INDEX_LIST) fail to port the value to the target VM.

Fixes b07a5c53d42a ("KVM: vmx: use MSR_IA32_TSX_CTRL to hard-disable TSX on guest that lack it")
---
 arch/x86/kvm/x86.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/x86.c +1 -1
index 237c483b1230..2236cfee4b7a 100644
@@ -1431,7 +1431,7 @@ static const u32 msrs_to_save_base[] = {
 #endif
 	MSR_IA32_TSC, MSR_IA32_CR_PAT, MSR_VM_HSAVE_PA,
 	MSR_IA32_FEAT_CTL, MSR_IA32_BNDCFGS, MSR_TSC_AUX,
-	MSR_IA32_SPEC_CTRL,
+	MSR_IA32_SPEC_CTRL, MSR_IA32_TSX_CTRL,
 	MSR_IA32_RTIT_CTL, MSR_IA32_RTIT_STATUS, MSR_IA32_RTIT_CR3_MATCH,
 	MSR_IA32_RTIT_OUTPUT_BASE, MSR_IA32_RTIT_OUTPUT_MASK,
 	MSR_IA32_RTIT_ADDR0_A, MSR_IA32_RTIT_ADDR0_B,
Signature · 1 line
2.40.1.495.gc816e09b53d-goog
#1 lore raw
Quoted 18 lines · Mingwei Zhang

Add MSR_IA32_TSX_CTRL into msrs_to_save[] to explicitly tell userspace to save/restore the register value during migration. Missing this may cause userspace that relies on KVM ioctl(KVM_GET_MSR_INDEX_LIST) fail to port the value to the target VM.

Fixes b07a5c53d42a ("KVM: vmx: use MSR_IA32_TSX_CTRL to hard-disable TSX on guest that lack it")
---
 arch/x86/kvm/x86.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/x86.c +0 -0
index 237c483b1230..2236cfee4b7a 100644

arch/x86/kvm/x86.c static const u32 msrs_to_save_base[] = { · line 1437

Quoted 8 lines
arch/x86/kvm/x86.c +1 -1
@@ -1431,7 +1431,7 @@ static const u32 msrs_to_save_base[] = {
 #endif
 	MSR_IA32_TSC, MSR_IA32_CR_PAT, MSR_VM_HSAVE_PA,
 	MSR_IA32_FEAT_CTL, MSR_IA32_BNDCFGS, MSR_TSC_AUX,
-	MSR_IA32_SPEC_CTRL,
+	MSR_IA32_SPEC_CTRL, MSR_IA32_TSX_CTRL,
 	MSR_IA32_RTIT_CTL, MSR_IA32_RTIT_STATUS, MSR_IA32_RTIT_CR3_MATCH,
 	MSR_IA32_RTIT_OUTPUT_BASE, MSR_IA32_RTIT_OUTPUT_MASK,
 	MSR_IA32_RTIT_ADDR0_A, MSR_IA32_RTIT_ADDR0_B,

Hmm, KVM shouldn't report the MSR if it can't be written by the guest. Over- reporting won't cause functional issues, and the odds of the MSR existing but not being reported in ARCH_CAPILIBITES are basically zilch, but IMO it's worth adding the check if only to document when the MSRs is fully supported.

arch/x86/kvm/x86.c +4 -0
index e7f78fe79b32..d8608c6753ff 100644
@@ -7152,6 +7152,10 @@ static void kvm_probe_msr_to_save(u32 msr_index)
                if (!kvm_cpu_cap_has(X86_FEATURE_XFD))
                        return;
                break;
+       case MSR_IA32_TSX_CTRL:
+               if (!(kvm_get_arch_capabilities() & ARCH_CAP_TSX_CTRL_MSR))
+                       return;
+               break;
        default:
                break;
        }
#2 lore raw
Quoted 14 lines · Sean Christopherson
Quoted 12 lines · Mingwei Zhang

Add MSR_IA32_TSX_CTRL into msrs_to_save[] to explicitly tell userspace to save/restore the register value during migration. Missing this may cause userspace that relies on KVM ioctl(KVM_GET_MSR_INDEX_LIST) fail to port the value to the target VM.

Fixes b07a5c53d42a ("KVM: vmx: use MSR_IA32_TSX_CTRL to hard-disable TSX on guest that lack it")
---
 arch/x86/kvm/x86.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 16 lines
Quoted 5 lines
arch/x86/kvm/x86.c +0 -0
index 237c483b1230..2236cfee4b7a 100644

arch/x86/kvm/x86.c static const u32 msrs_to_save_base[] = {

Quoted 9 lines
arch/x86/kvm/x86.c +1 -2
@@ -1431,7 +1431,7 @@ static const u32 msrs_to_save_base[] = {
 #endif
      MSR_IA32_TSC, MSR_IA32_CR_PAT, MSR_VM_HSAVE_PA,
      MSR_IA32_FEAT_CTL, MSR_IA32_BNDCFGS, MSR_TSC_AUX,
-     MSR_IA32_SPEC_CTRL,
+     MSR_IA32_SPEC_CTRL, MSR_IA32_TSX_CTRL,
      MSR_IA32_RTIT_CTL, MSR_IA32_RTIT_STATUS, MSR_IA32_RTIT_CR3_MATCH,
      MSR_IA32_RTIT_OUTPUT_BASE, MSR_IA32_RTIT_OUTPUT_MASK,
      MSR_IA32_RTIT_ADDR0_A, MSR_IA32_RTIT_ADDR0_B,
--

Hmm, KVM shouldn't report the MSR if it can't be written by the guest. Over-

I think you mean to say that KVM shouldn't report the MSR if it can't be written by *any* guest. KVM_GET_MSR_INDEX_LIST is a device ioctl, so it isn't capable of filtering out MSRs that can't be written by *the* guest, for some occurrence of "the."

Quoted 19 lines

reporting won't cause functional issues, and the odds of the MSR existing but not being reported in ARCH_CAPILIBITES are basically zilch, but IMO it's worth adding the check if only to document when the MSRs is fully supported.

arch/x86/kvm/x86.c +4 -0
index e7f78fe79b32..d8608c6753ff 100644
@@ -7152,6 +7152,10 @@ static void kvm_probe_msr_to_save(u32 msr_index)
                if (!kvm_cpu_cap_has(X86_FEATURE_XFD))
                        return;
                break;
+       case MSR_IA32_TSX_CTRL:
+               if (!(kvm_get_arch_capabilities() & ARCH_CAP_TSX_CTRL_MSR))
+                       return;
+               break;
        default:
                break;
        }
#3 lore raw
Quoted 32 lines · Jim Mattson
Quoted 14 lines · Sean Christopherson
Quoted 12 lines · Mingwei Zhang

Add MSR_IA32_TSX_CTRL into msrs_to_save[] to explicitly tell userspace to save/restore the register value during migration. Missing this may cause userspace that relies on KVM ioctl(KVM_GET_MSR_INDEX_LIST) fail to port the value to the target VM.

Fixes b07a5c53d42a ("KVM: vmx: use MSR_IA32_TSX_CTRL to hard-disable TSX on guest that lack it")
---
 arch/x86/kvm/x86.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 16 lines
Quoted 5 lines
arch/x86/kvm/x86.c +0 -0
index 237c483b1230..2236cfee4b7a 100644

arch/x86/kvm/x86.c static const u32 msrs_to_save_base[] = {

Quoted 9 lines
arch/x86/kvm/x86.c +1 -2
@@ -1431,7 +1431,7 @@ static const u32 msrs_to_save_base[] = {
 #endif
      MSR_IA32_TSC, MSR_IA32_CR_PAT, MSR_VM_HSAVE_PA,
      MSR_IA32_FEAT_CTL, MSR_IA32_BNDCFGS, MSR_TSC_AUX,
-     MSR_IA32_SPEC_CTRL,
+     MSR_IA32_SPEC_CTRL, MSR_IA32_TSX_CTRL,
      MSR_IA32_RTIT_CTL, MSR_IA32_RTIT_STATUS, MSR_IA32_RTIT_CR3_MATCH,
      MSR_IA32_RTIT_OUTPUT_BASE, MSR_IA32_RTIT_OUTPUT_MASK,
      MSR_IA32_RTIT_ADDR0_A, MSR_IA32_RTIT_ADDR0_B,
--

Hmm, KVM shouldn't report the MSR if it can't be written by the guest. Over-

Quoted 4 lines

I think you mean to say that KVM shouldn't report the MSR if it can't be written by *any* guest. KVM_GET_MSR_INDEX_LIST is a device ioctl, so it isn't capable of filtering out MSRs that can't be written by *the* guest, for some occurrence of "the."

Doh, yes, "the guest" was a handwavy reference to any/all guests.