Enhanced SMT Protection (ESMTP) protects an SEV-SNP guest from sibling side channels by requiring that, while a vCPU is in guest mode, its SMT sibling thread is either idle in host mode or executing a vCPU the guest has declared to be a legal sibling. Add an "esmtp" property to request and use it to advertize this feature for KVM to write it into the launch-time VMSAs. Sample command-line: -object sev-snp-guest,id=sev0,policy=0xb0000,cbitpos=51,reduced-phys-bits=1,esmtp=on Signed-off-by: Pratik R. Sampat --- qapi/qom.json | 9 ++++++++- target/i386/sev.c | 21 +++++++++++++++++++++ target/i386/sev.h | 1 + 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/qapi/qom.json b/qapi/qom.json index 3e270895a6d6..d60936a56be1 100644 --- a/qapi/qom.json +++ b/qapi/qom.json @@ -1107,6 +1107,12 @@ # provides additional protection but with runtime overhead. # (default: false) # +# @esmtp: Enable Enhanced SMT Protection support for the guest. Adds +# corresponding VMSA feature bit to KVM_SEV_INIT2 vmsa_features so +# the host applies it to each vCPU's VMSA. Opt-in feature as it +# provides additional protection but with runtime overhead. +# (default: false) (since 11.2) +# # Features: # # @confidential-guest-reset: If present, the hypervisor supports @@ -1126,7 +1132,8 @@ '*vcek-disabled': 'bool', '*secure-tsc': 'bool', '*tsc-frequency': 'uint32', - '*smtp': 'bool' }, + '*smtp': 'bool', + '*esmtp': 'bool' }, 'features': [ 'confidential-guest-reset' ] } ## diff --git a/target/i386/sev.c b/target/i386/sev.c index 845f0b1f37f2..1b5b833974cc 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -545,6 +545,12 @@ static int check_sev_features(SevCommonState *sev_common, uint64_t sev_features, "SEV: TSC frequency can only be set if Secure TSC is enabled"); return -1; } + if ((sev_features & SVM_SEV_FEAT_ESMTP) && + (sev_features & SVM_SEV_FEAT_SMTP)) { + error_setg(errp, + "SEV: SMT Protection and Enhanced SMT Protection are mutually exclusive"); + return -1; + } } else { if (sev_features && sev_es_enabled()) { error_setg(errp, @@ -3328,6 +3334,18 @@ sev_snp_guest_set_smtp(Object *obj, bool value, Error **errp) sev_set_feature(SEV_COMMON(obj), SVM_SEV_FEAT_SMTP, value); } +static bool +sev_snp_guest_get_esmtp(Object *obj, Error **errp) +{ + return is_sev_feature_set(SEV_COMMON(obj), SVM_SEV_FEAT_ESMTP); +} + +static void +sev_snp_guest_set_esmtp(Object *obj, bool value, Error **errp) +{ + sev_set_feature(SEV_COMMON(obj), SVM_SEV_FEAT_ESMTP, value); +} + static void sev_snp_guest_class_init(ObjectClass *oc, const void *data) { @@ -3372,6 +3390,9 @@ sev_snp_guest_class_init(ObjectClass *oc, const void *data) object_class_property_add_bool(oc, "smtp", sev_snp_guest_get_smtp, sev_snp_guest_set_smtp); + object_class_property_add_bool(oc, "esmtp", + sev_snp_guest_get_esmtp, + sev_snp_guest_set_esmtp); } static void diff --git a/target/i386/sev.h b/target/i386/sev.h index 2c16a73d9a61..566155417de8 100644 --- a/target/i386/sev.h +++ b/target/i386/sev.h @@ -50,6 +50,7 @@ bool sev_snp_enabled(void); #define SVM_SEV_FEAT_DEBUG_SWAP BIT(5) #define SVM_SEV_FEAT_SECURE_TSC BIT(9) #define SVM_SEV_FEAT_SMTP BIT(15) +#define SVM_SEV_FEAT_ESMTP BIT(17) typedef struct SevKernelLoaderContext { char *setup_data; -- 2.43.0