Skip to contentSkip to conversation

target/i386: sev: Add cmdline option to enable the Allowed SEV Features feature

RFC In review Kim Phillips 3 participants 5 messages Feb 7, 2025 – Feb 11, 2025 KVM

lore
Share & tools
lore
#0 lore raw

RFC 1/1 target/i386: sev: Add cmdline option to enable the Allowed SEV Features feature

The Allowed SEV Features feature allows the host kernel to control which SEV features it does not want the guest to enable [1].

This has to be explicitly opted-in by the user because it has the ability to break existing VMs if it were set automatically.

Currently, both the PmcVirtualization and SecureAvic features require the Allowed SEV Features feature to be set.

Based on a similar patch written for Secure TSC [2].

[1] Section 15.36.20 "Allowed SEV Features", AMD64 Architecture

    Programmer's Manual, Pub. 24593 Rev. 3.42 - March 2024:
    https://bugzilla.kernel.org/attachment.cgi?id=306250

[2] https://github.com/qemu/qemu/commit/4b2288dc6025ba32519ee8d202ca72d565cbbab7

---
 qapi/qom.json     |  6 ++++-
 target/i386/sev.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++
 target/i386/sev.h |  2 ++
 3 files changed, 67 insertions(+), 1 deletion(-)
qapi/qom.json +5 -1
index 28ce24cd8d..113b44ad74 100644
@@ -948,13 +948,17 @@
 #     designated guest firmware page for measured boot with -kernel
 #     (default: false) (since 6.2)
 #
+# @allowed-sev-features: true if secure allowed-sev-features feature
+#     is to be enabled in an SEV-ES or SNP guest. (default: false)
+#
 # Since: 9.1
 ##
 { 'struct': 'SevCommonProperties',
   'data': { '*sev-device': 'str',
             '*cbitpos': 'uint32',
             'reduced-phys-bits': 'uint32',
-            '*kernel-hashes': 'bool' } }
+            '*kernel-hashes': 'bool',
+            '*allowed-sev-features': 'bool' } }
 
 ##
 # @SevGuestProperties:
target/i386/sev.c +60 -0

90 lines not on this page · raw message

target/i386/sev.h +2 -0
index 373669eaac..07447c4b01 100644
@@ -44,6 +44,8 @@ bool sev_snp_enabled(void);
 #define SEV_SNP_POLICY_SMT      0x10000
 #define SEV_SNP_POLICY_DBG      0x80000
 
+#define SEV_VMSA_ALLOWED_SEV_FEATURES BIT_ULL(63)
+
 typedef struct SevKernelLoaderContext {
     char *setup_data;
     size_t setup_size;
Signature · 1 line
2.43.0
#1 lore raw
Quoted 9 lines · Kim Phillips

The Allowed SEV Features feature allows the host kernel to control which SEV features it does not want the guest to enable [1].

This has to be explicitly opted-in by the user because it has the ability to break existing VMs if it were set automatically.

Currently, both the PmcVirtualization and SecureAvic features require the Allowed SEV Features feature to be set.

Quoted 7 lines

Based on a similar patch written for Secure TSC [2].

[1] Section 15.36.20 "Allowed SEV Features", AMD64 Architecture

    Programmer's Manual, Pub. 24593 Rev. 3.42 - March 2024:
    https://bugzilla.kernel.org/attachment.cgi?id=306250

[2] https://github.com/qemu/qemu/commit/4b2288dc6025ba32519ee8d202ca72d565cbbab7

Despite that URL, that commit also does not appear to be merged into the QEMU git repo, and indeed I can't find any record of it even being posted as a patch for review on qemu-devel.

This is horribly misleading to reviewers, suggesting that the referenced patch was already accepted :-(

Quoted 13 lines
---
 qapi/qom.json     |  6 ++++-
 target/i386/sev.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++
 target/i386/sev.h |  2 ++
 3 files changed, 67 insertions(+), 1 deletion(-)
qapi/qom.json +0 -0
index 28ce24cd8d..113b44ad74 100644

qapi/qom.json line 952

Quoted 5 lines
qapi/qom.json +2 -0
@@ -948,13 +948,17 @@
 #     designated guest firmware page for measured boot with -kernel
 #     (default: false) (since 6.2)
 #
+# @allowed-sev-features: true if secure allowed-sev-features feature
+#     is to be enabled in an SEV-ES or SNP guest. (default: false)

Missing 'since' annotation.

Quoted 63 lines
qapi/qom.json +3 -1
+#
 # Since: 9.1
 ##
 { 'struct': 'SevCommonProperties',
   'data': { '*sev-device': 'str',
             '*cbitpos': 'uint32',
             'reduced-phys-bits': 'uint32',
-            '*kernel-hashes': 'bool' } }
+            '*kernel-hashes': 'bool',
+            '*allowed-sev-features': 'bool' } }
 
 ##
 # @SevGuestProperties:
target/i386/sev.c +28 -0
index 0e1dbb6959..85ad73f9a0 100644
@@ -98,6 +98,7 @@ struct SevCommonState {
     uint32_t cbitpos;
     uint32_t reduced_phys_bits;
     bool kernel_hashes;
+    uint64_t vmsa_features;
 
     /* runtime state */
     uint8_t api_major;
@@ -411,6 +412,33 @@ sev_get_reduced_phys_bits(void)
     return sev_common ? sev_common->reduced_phys_bits : 0;
 }
 
+static __u64
+sev_supported_vmsa_features(void)
+{
+    uint64_t supported_vmsa_features = 0;
+    struct kvm_device_attr attr = {
+        .group = KVM_X86_GRP_SEV,
+        .attr = KVM_X86_SEV_VMSA_FEATURES,
+        .addr = (unsigned long) &supported_vmsa_features
+    };
+
+    bool sys_attr = kvm_check_extension(kvm_state, KVM_CAP_SYS_ATTRIBUTES);
+    if (!sys_attr) {
+        return 0;
+    }
+
+    int rc = kvm_ioctl(kvm_state, KVM_GET_DEVICE_ATTR, &attr);
+    if (rc < 0) {
+        if (rc != -ENXIO) {
+            warn_report("KVM_GET_DEVICE_ATTR(0, KVM_X86_SEV_VMSA_FEATURES) "
+                        "error: %d", rc);
+        }
+        return 0;
+    }
+
+    return supported_vmsa_features;
+}
+
 static SevInfo *sev_get_info(void)
 {
     SevInfo *info;
@@ -1524,6 +1552,20 @@ static int sev_common_kvm_init(ConfidentialGuestSupport *cgs, Error **errp)
     case KVM_X86_SNP_VM: {
         struct kvm_sev_init args = { 0 };
 

target/i386/sev.c static int sev_common_kvm_init(ConfidentialGuestSupport *cgs, Error **errp) · line 1564

Quoted 10 lines
target/i386/sev.c +10 -0
+        if (sev_es_enabled()) {
+            __u64 vmsa_features, supported_vmsa_features;
+
+            supported_vmsa_features = sev_supported_vmsa_features();
+            vmsa_features = sev_common->vmsa_features;
+            if ((vmsa_features & supported_vmsa_features) != vmsa_features) {
+                error_setg(errp, "%s: requested sev feature mask (0x%llx) "
+                           "contains bits not supported by the host kernel "
+                           " (0x%llx)", __func__, vmsa_features,
+                           supported_vmsa_features);

This logic is being applied unconditionally, and not connected to the setting of the new 'allowed-sev-features' flag value. Is that correct ?

Will this end up breaking existing deployed guests, or is this a scenario that would have been blocked with an error later on regardless ?

target/i386/sev.c static int sev_common_kvm_init(ConfidentialGuestSupport *cgs, Error **errp) · line 1565

Quoted 1 line
target/i386/sev.c +1 -0
+            return -1;

Malformed indentation.

Quoted 55 lines
target/i386/sev.c +21 -0
+            }
+            args.vmsa_features = vmsa_features;
+        }
         ret = sev_ioctl(sev_common->sev_fd, KVM_SEV_INIT2, &args, &fw_error);
         break;
     }
@@ -2044,6 +2086,19 @@ static void sev_common_set_kernel_hashes(Object *obj, bool value, Error **errp)
     SEV_COMMON(obj)->kernel_hashes = value;
 }
 
+static bool
+sev_snp_guest_get_allowed_sev_features(Object *obj, Error **errp)
+{
+    return SEV_COMMON(obj)->vmsa_features & SEV_VMSA_ALLOWED_SEV_FEATURES;
+}
+
+static void
+sev_snp_guest_set_allowed_sev_features(Object *obj, bool value, Error **errp)
+{
+    if (value)
+        SEV_COMMON(obj)->vmsa_features |= SEV_VMSA_ALLOWED_SEV_FEATURES;
+}
+
 static void
 sev_common_class_init(ObjectClass *oc, void *data)
 {
@@ -2061,6 +2116,11 @@ sev_common_class_init(ObjectClass *oc, void *data)
                                    sev_common_set_kernel_hashes);
     object_class_property_set_description(oc, "kernel-hashes",
             "add kernel hashes to guest firmware for measured Linux boot");
+    object_class_property_add_bool(oc, "allowed-sev-features",
+                                   sev_snp_guest_get_allowed_sev_features,
+                                   sev_snp_guest_set_allowed_sev_features);
+    object_class_property_set_description(oc, "allowed-sev-features",
+            "Enable the Allowed SEV Features feature");
 }
 
 static void
target/i386/sev.h +2 -0
index 373669eaac..07447c4b01 100644
@@ -44,6 +44,8 @@ bool sev_snp_enabled(void);
 #define SEV_SNP_POLICY_SMT      0x10000
 #define SEV_SNP_POLICY_DBG      0x80000
 
+#define SEV_VMSA_ALLOWED_SEV_FEATURES BIT_ULL(63)
+
 typedef struct SevKernelLoaderContext {
     char *setup_data;
     size_t setup_size;
Signature · 1 line
2.43.0

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#2 lore raw
Quoted 16 lines · Daniel P. Berrangé
Quoted 15 lines · Kim Phillips

The Allowed SEV Features feature allows the host kernel to control which SEV features it does not want the guest to enable [1].

This has to be explicitly opted-in by the user because it has the ability to break existing VMs if it were set automatically.

Currently, both the PmcVirtualization and SecureAvic features require the Allowed SEV Features feature to be set.

Based on a similar patch written for Secure TSC [2].

[1] Section 15.36.20 "Allowed SEV Features", AMD64 Architecture

     Programmer's Manual, Pub. 24593 Rev. 3.42 - March 2024:
     https://bugzilla.kernel.org/attachment.cgi?id=306250
Quoted 8 lines
Quoted 1 line

[2] https://github.com/qemu/qemu/commit/4b2288dc6025ba32519ee8d202ca72d565cbbab7

Despite that URL, that commit also does not appear to be merged into the QEMU git repo, and indeed I can't find any record of it even being posted as a patch for review on qemu-devel.

This is horribly misleading to reviewers, suggesting that the referenced patch was already accepted :-(

Apologies, that was not the intent. I'll remove it from the next version.

Quoted 4 lines
Quoted 4 lines
target/i386/sev.c +0 -0
@@ -1524,6 +1552,20 @@ static int sev_common_kvm_init(ConfidentialGuestSupport *cgs, Error **errp)
      case KVM_X86_SNP_VM: {
          struct kvm_sev_init args = { 0 };
 
Quoted 14 lines

target/i386/sev.c static int sev_common_kvm_init(ConfidentialGuestSupport *cgs, Error **errp) · line 1564

Quoted 10 lines
target/i386/sev.c +10 -0
+        if (sev_es_enabled()) {
+            __u64 vmsa_features, supported_vmsa_features;
+
+            supported_vmsa_features = sev_supported_vmsa_features();
+            vmsa_features = sev_common->vmsa_features;
+            if ((vmsa_features & supported_vmsa_features) != vmsa_features) {
+                error_setg(errp, "%s: requested sev feature mask (0x%llx) "
+                           "contains bits not supported by the host kernel "
+                           " (0x%llx)", __func__, vmsa_features,
+                           supported_vmsa_features);

This logic is being applied unconditionally, and not connected to the setting of the new 'allowed-sev-features' flag value. Is that correct ?

That's correct.

Quoted 3 lines

Will this end up breaking existing deployed guests, or is this a scenario that would have been blocked with an error later on regardless ?

It would have been blocked regardless by this check in kvm's __sev_guest_init:

https://elixir.bootlin.com/linux/v6.13.2/source/arch/x86/kvm/svm/sev.c#L418

I've addressed all your other comments.

Thank you for your review,

Kim

#3 lore raw
In reply to Kim Phillips
Quoted 60 lines · Kim Phillips

The Allowed SEV Features feature allows the host kernel to control which SEV features it does not want the guest to enable [1].

This has to be explicitly opted-in by the user because it has the ability to break existing VMs if it were set automatically.

Currently, both the PmcVirtualization and SecureAvic features require the Allowed SEV Features feature to be set.

Based on a similar patch written for Secure TSC [2].

[1] Section 15.36.20 "Allowed SEV Features", AMD64 Architecture

    Programmer's Manual, Pub. 24593 Rev. 3.42 - March 2024:
    https://bugzilla.kernel.org/attachment.cgi?id=306250

[2] https://github.com/qemu/qemu/commit/4b2288dc6025ba32519ee8d202ca72d565cbbab7

---
 qapi/qom.json     |  6 ++++-
 target/i386/sev.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++
 target/i386/sev.h |  2 ++
 3 files changed, 67 insertions(+), 1 deletion(-)
qapi/qom.json +5 -1
index 28ce24cd8d..113b44ad74 100644
@@ -948,13 +948,17 @@
 #     designated guest firmware page for measured boot with -kernel
 #     (default: false) (since 6.2)
 #
+# @allowed-sev-features: true if secure allowed-sev-features feature
+#     is to be enabled in an SEV-ES or SNP guest. (default: false)
+#
 # Since: 9.1
 ##
 { 'struct': 'SevCommonProperties',
   'data': { '*sev-device': 'str',
             '*cbitpos': 'uint32',
             'reduced-phys-bits': 'uint32',
-            '*kernel-hashes': 'bool' } }
+            '*kernel-hashes': 'bool',
+            '*allowed-sev-features': 'bool' } }
 
 ##
 # @SevGuestProperties:
target/i386/sev.c +1 -0
index 0e1dbb6959..85ad73f9a0 100644
@@ -98,6 +98,7 @@ struct SevCommonState {
     uint32_t cbitpos;
     uint32_t reduced_phys_bits;
     bool kernel_hashes;
+    uint64_t vmsa_features;
 
     /* runtime state */
     uint8_t api_major;

target/i386/sev.c sev_get_reduced_phys_bits(void) · line 416

Quoted 5 lines
target/i386/sev.c +2 -0
@@ -411,6 +412,33 @@ sev_get_reduced_phys_bits(void)
     return sev_common ? sev_common->reduced_phys_bits : 0;
 }
 
+static __u64
+sev_supported_vmsa_features(void)

s/sev_/sev_get_/ ?

Quoted 29 lines
target/i386/sev.c +25 -0
+{
+    uint64_t supported_vmsa_features = 0;
+    struct kvm_device_attr attr = {
+        .group = KVM_X86_GRP_SEV,
+        .attr = KVM_X86_SEV_VMSA_FEATURES,
+        .addr = (unsigned long) &supported_vmsa_features
+    };
+
+    bool sys_attr = kvm_check_extension(kvm_state, KVM_CAP_SYS_ATTRIBUTES);
+    if (!sys_attr) {
+        return 0;
+    }
+
+    int rc = kvm_ioctl(kvm_state, KVM_GET_DEVICE_ATTR, &attr);
+    if (rc < 0) {
+        if (rc != -ENXIO) {
+            warn_report("KVM_GET_DEVICE_ATTR(0, KVM_X86_SEV_VMSA_FEATURES) "
+                        "error: %d", rc);
+        }
+        return 0;
+    }
+
+    return supported_vmsa_features;
+}
+
 static SevInfo *sev_get_info(void)
 {
     SevInfo *info;

target/i386/sev.c static int sev_common_kvm_init(ConfidentialGuestSupport *cgs, Error **errp) · line 1555

Quoted 4 lines
target/i386/sev.c +1 -0
@@ -1524,6 +1552,20 @@ static int sev_common_kvm_init(ConfidentialGuestSupport *cgs, Error **errp)
     case KVM_X86_SNP_VM: {
         struct kvm_sev_init args = { 0 };
 
+        if (sev_es_enabled()) {

Shouldn't this be

if (sev_es_enabled() && (sev_common->vmsa_features & SEV_VMSA_ALLOWED_SEV_FEATURES)) {

target/i386/sev.c static int sev_common_kvm_init(ConfidentialGuestSupport *cgs, Error **errp) · line 1556

Quoted 1 line
target/i386/sev.c +1 -0
+            __u64 vmsa_features, supported_vmsa_features;

s/__u64/uint64_t/ ?

target/i386/sev.c static int sev_common_kvm_init(ConfidentialGuestSupport *cgs, Error **errp) · line 1566

Quoted 10 lines
target/i386/sev.c +10 -0
+
+            supported_vmsa_features = sev_supported_vmsa_features();
+            vmsa_features = sev_common->vmsa_features;
+            if ((vmsa_features & supported_vmsa_features) != vmsa_features) {
+                error_setg(errp, "%s: requested sev feature mask (0x%llx) "
+                           "contains bits not supported by the host kernel "
+                           " (0x%llx)", __func__, vmsa_features,
+                           supported_vmsa_features);
+            return -1;
+            }

Add a blank line

target/i386/sev.c static int sev_common_kvm_init(ConfidentialGuestSupport *cgs, Error **errp) · line 1568

Quoted 2 lines
target/i386/sev.c +2 -0
+            args.vmsa_features = vmsa_features;
+        }

Add a blank line

Thanks,
Tom

Quoted 48 lines
target/i386/sev.c +18 -0
         ret = sev_ioctl(sev_common->sev_fd, KVM_SEV_INIT2, &args, &fw_error);
         break;
     }
@@ -2044,6 +2086,19 @@ static void sev_common_set_kernel_hashes(Object *obj, bool value, Error **errp)
     SEV_COMMON(obj)->kernel_hashes = value;
 }
 
+static bool
+sev_snp_guest_get_allowed_sev_features(Object *obj, Error **errp)
+{
+    return SEV_COMMON(obj)->vmsa_features & SEV_VMSA_ALLOWED_SEV_FEATURES;
+}
+
+static void
+sev_snp_guest_set_allowed_sev_features(Object *obj, bool value, Error **errp)
+{
+    if (value)
+        SEV_COMMON(obj)->vmsa_features |= SEV_VMSA_ALLOWED_SEV_FEATURES;
+}
+
 static void
 sev_common_class_init(ObjectClass *oc, void *data)
 {
@@ -2061,6 +2116,11 @@ sev_common_class_init(ObjectClass *oc, void *data)
                                    sev_common_set_kernel_hashes);
     object_class_property_set_description(oc, "kernel-hashes",
             "add kernel hashes to guest firmware for measured Linux boot");
+    object_class_property_add_bool(oc, "allowed-sev-features",
+                                   sev_snp_guest_get_allowed_sev_features,
+                                   sev_snp_guest_set_allowed_sev_features);
+    object_class_property_set_description(oc, "allowed-sev-features",
+            "Enable the Allowed SEV Features feature");
 }
 
 static void
target/i386/sev.h +2 -0
index 373669eaac..07447c4b01 100644
@@ -44,6 +44,8 @@ bool sev_snp_enabled(void);
 #define SEV_SNP_POLICY_SMT      0x10000
 #define SEV_SNP_POLICY_DBG      0x80000
 
+#define SEV_VMSA_ALLOWED_SEV_FEATURES BIT_ULL(63)
+
 typedef struct SevKernelLoaderContext {
     char *setup_data;
     size_t setup_size;
#4 lore raw
Quoted 101 lines · Tom Lendacky
Quoted 60 lines · Kim Phillips

The Allowed SEV Features feature allows the host kernel to control which SEV features it does not want the guest to enable [1].

This has to be explicitly opted-in by the user because it has the ability to break existing VMs if it were set automatically.

Currently, both the PmcVirtualization and SecureAvic features require the Allowed SEV Features feature to be set.

Based on a similar patch written for Secure TSC [2].

[1] Section 15.36.20 "Allowed SEV Features", AMD64 Architecture

    Programmer's Manual, Pub. 24593 Rev. 3.42 - March 2024:
    https://bugzilla.kernel.org/attachment.cgi?id=306250

[2] https://github.com/qemu/qemu/commit/4b2288dc6025ba32519ee8d202ca72d565cbbab7

---
 qapi/qom.json     |  6 ++++-
 target/i386/sev.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++
 target/i386/sev.h |  2 ++
 3 files changed, 67 insertions(+), 1 deletion(-)
qapi/qom.json +5 -1
index 28ce24cd8d..113b44ad74 100644
@@ -948,13 +948,17 @@
 #     designated guest firmware page for measured boot with -kernel
 #     (default: false) (since 6.2)
 #
+# @allowed-sev-features: true if secure allowed-sev-features feature
+#     is to be enabled in an SEV-ES or SNP guest. (default: false)
+#
 # Since: 9.1
 ##
 { 'struct': 'SevCommonProperties',
   'data': { '*sev-device': 'str',
             '*cbitpos': 'uint32',
             'reduced-phys-bits': 'uint32',
-            '*kernel-hashes': 'bool' } }
+            '*kernel-hashes': 'bool',
+            '*allowed-sev-features': 'bool' } }
 
 ##
 # @SevGuestProperties:
target/i386/sev.c +1 -0
index 0e1dbb6959..85ad73f9a0 100644
@@ -98,6 +98,7 @@ struct SevCommonState {
     uint32_t cbitpos;
     uint32_t reduced_phys_bits;
     bool kernel_hashes;
+    uint64_t vmsa_features;
 
     /* runtime state */
     uint8_t api_major;

target/i386/sev.c sev_get_reduced_phys_bits(void) · line 416

Quoted 5 lines
target/i386/sev.c +2 -0
@@ -411,6 +412,33 @@ sev_get_reduced_phys_bits(void)
     return sev_common ? sev_common->reduced_phys_bits : 0;
 }
 
+static __u64
+sev_supported_vmsa_features(void)

s/sev_/sev_get_/ ?

Quoted 32 lines
target/i386/sev.c +25 -0
+{
+    uint64_t supported_vmsa_features = 0;
+    struct kvm_device_attr attr = {
+        .group = KVM_X86_GRP_SEV,
+        .attr = KVM_X86_SEV_VMSA_FEATURES,
+        .addr = (unsigned long) &supported_vmsa_features
+    };
+
+    bool sys_attr = kvm_check_extension(kvm_state, KVM_CAP_SYS_ATTRIBUTES);
+    if (!sys_attr) {
+        return 0;
+    }
+
+    int rc = kvm_ioctl(kvm_state, KVM_GET_DEVICE_ATTR, &attr);
+    if (rc < 0) {
+        if (rc != -ENXIO) {
+            warn_report("KVM_GET_DEVICE_ATTR(0, KVM_X86_SEV_VMSA_FEATURES) "
+                        "error: %d", rc);
+        }
+        return 0;
+    }
+
+    return supported_vmsa_features;
+}
+
 static SevInfo *sev_get_info(void)
 {
     SevInfo *info;
@@ -1524,6 +1552,20 @@ static int sev_common_kvm_init(ConfidentialGuestSupport *cgs, Error **errp)
     case KVM_X86_SNP_VM: {
         struct kvm_sev_init args = { 0 };
 
Quoted 5 lines

target/i386/sev.c static int sev_common_kvm_init(ConfidentialGuestSupport *cgs, Error **errp) · line 1555

Quoted 1 line
target/i386/sev.c +1 -0
+        if (sev_es_enabled()) {

Shouldn't this be

if (sev_es_enabled() && (sev_common->vmsa_features & SEV_VMSA_ALLOWED_SEV_FEATURES)) {

Actually, I guess it doesn't matter. The vmsa_features field will be 0 by default and only be set if "allowed-sev-features=on" is specified. So doing this will just error out a bit earlier than KVM erroring out on the INIT2 call if some vmsa_feature bit is set that KVM doesn't know about.

Thanks,
Tom

Quoted 74 lines

target/i386/sev.c static int sev_common_kvm_init(ConfidentialGuestSupport *cgs, Error **errp) · line 1556

Quoted 2 lines
target/i386/sev.c +1 -0
+            __u64 vmsa_features, supported_vmsa_features;

s/__u64/uint64_t/ ?

target/i386/sev.c static int sev_common_kvm_init(ConfidentialGuestSupport *cgs, Error **errp) · line 1566

Quoted 10 lines
target/i386/sev.c +10 -0
+
+            supported_vmsa_features = sev_supported_vmsa_features();
+            vmsa_features = sev_common->vmsa_features;
+            if ((vmsa_features & supported_vmsa_features) != vmsa_features) {
+                error_setg(errp, "%s: requested sev feature mask (0x%llx) "
+                           "contains bits not supported by the host kernel "
+                           " (0x%llx)", __func__, vmsa_features,
+                           supported_vmsa_features);
+            return -1;
+            }

Add a blank line

target/i386/sev.c static int sev_common_kvm_init(ConfidentialGuestSupport *cgs, Error **errp) · line 1568

Quoted 2 lines
target/i386/sev.c +2 -0
+            args.vmsa_features = vmsa_features;
+        }

Add a blank line

Thanks,
Tom

Quoted 48 lines
target/i386/sev.c +18 -0
         ret = sev_ioctl(sev_common->sev_fd, KVM_SEV_INIT2, &args, &fw_error);
         break;
     }
@@ -2044,6 +2086,19 @@ static void sev_common_set_kernel_hashes(Object *obj, bool value, Error **errp)
     SEV_COMMON(obj)->kernel_hashes = value;
 }
 
+static bool
+sev_snp_guest_get_allowed_sev_features(Object *obj, Error **errp)
+{
+    return SEV_COMMON(obj)->vmsa_features & SEV_VMSA_ALLOWED_SEV_FEATURES;
+}
+
+static void
+sev_snp_guest_set_allowed_sev_features(Object *obj, bool value, Error **errp)
+{
+    if (value)
+        SEV_COMMON(obj)->vmsa_features |= SEV_VMSA_ALLOWED_SEV_FEATURES;
+}
+
 static void
 sev_common_class_init(ObjectClass *oc, void *data)
 {
@@ -2061,6 +2116,11 @@ sev_common_class_init(ObjectClass *oc, void *data)
                                    sev_common_set_kernel_hashes);
     object_class_property_set_description(oc, "kernel-hashes",
             "add kernel hashes to guest firmware for measured Linux boot");
+    object_class_property_add_bool(oc, "allowed-sev-features",
+                                   sev_snp_guest_get_allowed_sev_features,
+                                   sev_snp_guest_set_allowed_sev_features);
+    object_class_property_set_description(oc, "allowed-sev-features",
+            "Enable the Allowed SEV Features feature");
 }
 
 static void
target/i386/sev.h +2 -0
index 373669eaac..07447c4b01 100644
@@ -44,6 +44,8 @@ bool sev_snp_enabled(void);
 #define SEV_SNP_POLICY_SMT      0x10000
 #define SEV_SNP_POLICY_DBG      0x80000
 
+#define SEV_VMSA_ALLOWED_SEV_FEATURES BIT_ULL(63)
+
 typedef struct SevKernelLoaderContext {
     char *setup_data;
     size_t setup_size;