[tip: x86/sev] x86/sev: Report MSR_AMD64_SEV in sysfs

tip-bot2 for Joerg Roedel posted 1 patch 2 days, 12 hours ago
Documentation/ABI/testing/sysfs-devices-system-cpu | 10 +++-
arch/x86/coco/sev/core.c                           | 30 ++++++++++---
2 files changed, 33 insertions(+), 7 deletions(-)
[tip: x86/sev] x86/sev: Report MSR_AMD64_SEV in sysfs
Posted by tip-bot2 for Joerg Roedel 2 days, 12 hours ago
The following commit has been merged into the x86/sev branch of tip:

Commit-ID:     250ee734115bca1c1f7a38d838909aa83cce87ae
Gitweb:        https://git.kernel.org/tip/250ee734115bca1c1f7a38d838909aa83cce87ae
Author:        Joerg Roedel <joerg.roedel@amd.com>
AuthorDate:    Wed, 09 Sep 2026 20:35:46 -07:00
Committer:     Borislav Petkov (AMD) <bp@alien8.de>
CommitterDate: Mon, 21 Sep 2026 20:28:44 -07:00

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@amd.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com>
Link: https://lore.kernel.org/all/20260803125827.718024-1-joro@8bytes.org
---
 Documentation/ABI/testing/sysfs-devices-system-cpu | 10 +++-
 arch/x86/coco/sev/core.c                           | 30 ++++++++++---
 2 files changed, 33 insertions(+), 7 deletions(-)

diff --git a/Documentation/ABI/testing/sysfs-devices-system-cpu b/Documentation/ABI/testing/sysfs-devices-system-cpu
index 82d10d5..7b0aef8 100644
--- a/Documentation/ABI/testing/sysfs-devices-system-cpu
+++ b/Documentation/ABI/testing/sysfs-devices-system-cpu
@@ -689,15 +689,21 @@ Description:	Umwait control
 			  Low order two bits must be zero.
 
 What:		/sys/devices/system/cpu/sev
+		/sys/devices/system/cpu/sev/sev_status
 		/sys/devices/system/cpu/sev/vmpl
 Date:		May 2024
 Contact:	Linux kernel mailing list <linux-kernel@vger.kernel.org>
 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.
+
+		sev_status: Reports the value of the SEV_STATUS MSR which
+			    enumerates the enabled features of an SEV
+			    environment.
 
 		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.
 
 
 What:		/sys/devices/system/cpu/svm
diff --git a/arch/x86/coco/sev/core.c b/arch/x86/coco/sev/core.c
index cc292d7..eb2e853 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;
 }