[PATCH 8/8] KVM: SEV: Disallow the use of hardware-switched PMU

Sandipan Das <[email protected]>
Newsgroups org.kernel.vger.kvm
Message-ID <c88cd7d448c7ff998efae53979624b5b08a045c1.1786345201.git.sandipan.das@amd.com>
For hardware-switched mediated PMU, the guest PMU state resides in the
VMCB save area instead of struct kvm_pmu. To inspect or modify that
state in software, KVM uses the vendor state sync PMU ops.

When SEV-ES or SEV-SNP is used, these ops cannot work as the guest PMU
state resides in an encrypted VMSA that KVM can neither read nor write.
Clear KVM_MEDIATED_PMU_CAP_HW_SWITCHED for such guests so that they
fall back to the software-switched mode.

Signed-off-by: Sandipan Das <[email protected]>
---
 arch/x86/kvm/svm/sev.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
index fcb41dfde4c0..8e8cd4feb16a 100644
--- a/arch/x86/kvm/svm/sev.c
+++ b/arch/x86/kvm/svm/sev.c
@@ -534,6 +534,9 @@ static int __sev_guest_init(struct kvm *kvm, struct kvm_sev_cmd *argp,
 	if (snp_active)
 		sev->vmsa_features |= SVM_SEV_FEAT_SNP_ACTIVE;
 
+	if (es_active)
+		kvm_clr_mediated_pmu_caps(kvm, KVM_MEDIATED_PMU_CAP_HW_SWITCHED);
+
 	ret = sev_asid_new(sev, vm_type);
 	if (ret)
 		goto e_no_asid;
-- 
2.53.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.