Re: [PATCH 1/3] x86/coco: Add CC_ATTR_GUEST_SEV

From: Borislav Petkov

Date: Wed Sep 09 2026 - 23:41:18 EST


On Wed, Sep 09, 2026 at 07:40:27PM -0700, Borislav Petkov wrote:
> On Mon, Aug 03, 2026 at 02:58:25PM +0200, Jörg Rödel wrote:
> > From: Joerg Roedel <joerg.roedel@xxxxxxx>
> >
> > Add a new attribute to the CC platform code to check whether the
> > kernel runs in an environment using SEV memory encryption. This will
> > be used to establish the an sev/ directory in SYSFS (which is
> > currently SEV-SNP-only).
>
> Yeah, the initial intention for cc_plaform_has() is to use it in arch-agnostic
> code and for something which you're going to use in coco code itself, you're
> better off simply doing:
>
> if (sev_status & MSR_AMD64_SEV_ENABLED)
>
> I can fix that up when applying if you prefer - it is easy enough.

IOW, I merged them all three into this simple one.

Author: Joerg Roedel <joerg.roedel@xxxxxxx>
Date: Mon Aug 3 14:58:25 2026 +0200

x86/sev: Report MSR_AMD64_SEV in sysfs

Add SEV_STATUS to the cpu/sev/ sysfs hierarchy and report it for all SEV
guest types.

[ bp: Merge into a single patch, simplify. ]

Signed-off-by: Joerg Roedel <joerg.roedel@xxxxxxx>
Signed-off-by: Borislav Petkov (AMD) <bp@xxxxxxxxx>
Link: https://patch.msgid.link/20260803125827.718024-2-joro@xxxxxxxxxx

diff --git a/Documentation/ABI/testing/sysfs-devices-system-cpu b/Documentation/ABI/testing/sysfs-devices-system-cpu
index 82d10d556cc8..cec413a71491 100644
--- a/Documentation/ABI/testing/sysfs-devices-system-cpu
+++ b/Documentation/ABI/testing/sysfs-devices-system-cpu
@@ -690,15 +690,20 @@ Description: Umwait control

What: /sys/devices/system/cpu/sev
/sys/devices/system/cpu/sev/vmpl
+ /sys/devices/system/cpu/sev/sev_status
Date: May 2024
Contact: Linux kernel mailing list <linux-kernel@xxxxxxxxxxxxxxx>
Description: Secure Encrypted Virtualization (SEV) information

- This directory is only present when running as an SEV-SNP guest.
+ This directory is only present when running as an SEV guest.

vmpl: Reports the Virtual Machine Privilege Level (VMPL) at which
- the SEV-SNP guest is running.
+ the SEV-SNP guest is running. This file is only present
+ when running as an SEV-SNP guest.

+ sev_status: Reports the value of the SEV_STATUS MSR which
+ enumerates the enabled features of an SEV
+ environment.

What: /sys/devices/system/cpu/svm
Date: August 2019
diff --git a/arch/x86/coco/sev/core.c b/arch/x86/coco/sev/core.c
index ec8fc02bd636..4751bfbe694f 100644
--- a/arch/x86/coco/sev/core.c
+++ b/arch/x86/coco/sev/core.c
@@ -1431,15 +1431,22 @@ static ssize_t vmpl_show(struct kobject *kobj,
return sysfs_emit(buf, "%d\n", snp_vmpl);
}

+static ssize_t sev_status_show(struct kobject *kobj,
+ struct kobj_attribute *attr, char *buf)
+{
+ return sysfs_emit(buf, "0x%llx\n", sev_status);
+}
+
static struct kobj_attribute vmpl_attr = __ATTR_RO(vmpl);
+static struct kobj_attribute sev_status_attr = __ATTR_RO(sev_status);

-static struct attribute *vmpl_attrs[] = {
- &vmpl_attr.attr,
+static struct attribute *sev_status_attrs[] = {
+ &sev_status_attr.attr,
NULL
};

static struct attribute_group sev_attr_group = {
- .attrs = vmpl_attrs,
+ .attrs = sev_status_attrs,
};

static int __init sev_sysfs_init(void)
@@ -1448,7 +1455,7 @@ static int __init sev_sysfs_init(void)
struct device *dev_root;
int ret;

- if (!cc_platform_has(CC_ATTR_GUEST_SEV_SNP))
+ if (!(sev_status & MSR_AMD64_SEV_ENABLED))
return -ENODEV;

dev_root = bus_get_dev_root(&cpu_subsys);
@@ -1463,7 +1470,20 @@ static int __init sev_sysfs_init(void)

ret = sysfs_create_group(sev_kobj, &sev_attr_group);
if (ret)
- kobject_put(sev_kobj);
+ goto drop_kobj;
+
+ if (sev_status & MSR_AMD64_SEV_SNP_ENABLED) {
+ ret = sysfs_add_file_to_group(sev_kobj, &vmpl_attr.attr, NULL);
+ if (ret)
+ goto drop_sysfs;
+ }
+
+ return 0;
+
+drop_sysfs:
+ sysfs_remove_group(sev_kobj, &sev_attr_group);
+drop_kobj:
+ kobject_put(sev_kobj);

return ret;
}

>
> --
> Regards/Gruss,
> Boris.
>
> https://people.kernel.org/tglx/notes-about-netiquette

--
Regards/Gruss,
Boris.

https://people.kernel.org/tglx/notes-about-netiquette