@samitouri / QOSamiQemu / commits / 9743cd30f3

target/i386: SEV: Consolidate SEV feature validation to common init path

Currently, check_sev_features() is called in multiple places when processing IGVM files: both when processing the initial VMSA SEV features from IGVM, as well as when validating the full contents of the VMSA. Move this to a single point in sev_common_kvm_init() to simplify the flow, as well as to re-use this function when VMSA SEV features are being set without using IGVM files. Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com> Signed-off-by: Naveen N Rao (AMD) <naveen@kernel.org> Link: https://lore.kernel.org/r/35449df94eb20c29923a7cd0e2742ddba605928c.1779281646.git.naveen@kernel.org Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Naveen N Rao (AMD) committed May 20, 2026 at 18:57 UTC 9743cd30f33ff9ab5338efc3801505f125280587
1 file changed +4 -6
target/i386/sev.c
+4 -6
@@ -600,9 +600,6 @@ static int check_vmsa_supported(SevCommonState *sev_common, hwaddr gpa,
600 vmsa_check.x87_fcw = 0;
601 vmsa_check.mxcsr = 0;
602
603 - if (check_sev_features(sev_common, vmsa_check.sev_features, errp) < 0) {
604 - return -1;
605 - }
603 vmsa_check.sev_features = 0;
604
605 if (!buffer_is_zero(&vmsa_check, sizeof(vmsa_check))) {
@@ -1920,6 +1917,10 @@ static int sev_common_kvm_init(ConfidentialGuestSupport *cgs, Error **errp)
1917 }
1918 }
1919
1920 + if (check_sev_features(sev_common, sev_common->sev_features, errp) < 0) {
1921 + return -1;
1922 + }
1923 +
1924 /*
1925 * KVM maintains a bitmask of allowed sev_features. This does not
1926 * include SVM_SEV_FEAT_SNP_ACTIVE which is set accordingly by KVM
@@ -2581,9 +2582,6 @@ static int cgs_set_guest_state(hwaddr gpa, uint8_t *ptr, uint64_t len,
2582 __func__);
2583 return -1;
2584 }
2584 - if (check_sev_features(sev_common, sa->sev_features, errp) < 0) {
2585 - return -1;
2586 - }
2585 sev_common->sev_features = sa->sev_features;
2586 }
2587 return 0;