Set the FRED_VIRT_ENABLE bit (bit 4) in the VIRT_EXT field of VMCB to enable
FRED Virtualization for the guest. This enables automatic save/restore of
FRED MSRs.
Signed-off-by: Shivansh Dhiman <shivansh.dhiman@amd.com>
---
Changes in v2:
- Confined the enabling of vFRED to svm_vcpu_after_set_cpuid() only
(Sean Christopherson).
---
arch/x86/include/asm/svm.h | 1 +
arch/x86/kvm/svm/svm.c | 5 +++++
2 files changed, 6 insertions(+)
diff --git a/arch/x86/include/asm/svm.h b/arch/x86/include/asm/svm.h
index c0f6523e2b2d..f4a9781c1d6c 100644
--- a/arch/x86/include/asm/svm.h
+++ b/arch/x86/include/asm/svm.h
@@ -224,6 +224,7 @@ struct __attribute__ ((__packed__)) vmcb_control_area {
#define LBR_CTL_ENABLE_MASK BIT_ULL(0)
#define VIRTUAL_VMLOAD_VMSAVE_ENABLE_MASK BIT_ULL(1)
+#define FRED_VIRT_ENABLE_MASK BIT_ULL(4)
#define SVM_INTERRUPT_SHADOW_MASK BIT_ULL(0)
#define SVM_GUEST_INTERRUPT_MASK BIT_ULL(1)
diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
index 7d411df3dd78..4b270490b2fd 100644
--- a/arch/x86/kvm/svm/svm.c
+++ b/arch/x86/kvm/svm/svm.c
@@ -4540,6 +4540,11 @@ static void svm_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu)
if (guest_cpuid_is_intel_compatible(vcpu))
guest_cpu_cap_clear(vcpu, X86_FEATURE_V_VMSAVE_VMLOAD);
+ if (guest_cpu_cap_has(vcpu, X86_FEATURE_FRED))
+ svm->vmcb->control.virt_ext |= FRED_VIRT_ENABLE_MASK;
+ else
+ svm->vmcb->control.virt_ext &= ~FRED_VIRT_ENABLE_MASK;
+
if (sev_guest(vcpu->kvm))
sev_vcpu_after_set_cpuid(svm);
}
--
2.43.0