[tip: x86/sev] x86/sev: Make SEV_STATUS available via SYSFS

tip-bot2 for Joerg Roedel
2025-03-05T11:11:46Z

The following commit has been merged into the x86/sev branch of tip:

Commit-ID: 1d307efcf3b75d1d3aa2f8e7e932eae182d5323a
Gitweb: https://git.kernel.org/tip/1d307efcf3b75d1d3aa2f8e7e932eae182d5323a
Author: Joerg Roedel <jroedel@suse.de>
AuthorDate: Wed, 05 Mar 2025 11:52:34 +01:00
Committer: Ingo Molnar <mingo@kernel.org>
CommitterDate: Wed, 05 Mar 2025 12:05:42 +01:00

x86/sev: Make SEV_STATUS available via SYSFS

Current user-space tooling which needs access to the SEV_STATUS MSR is
using the MSR module. The use of this module poses a security risk in
any trusted execution environment and is generally discouraged.

Instead, provide an file in SYSFS in the already existing
/sys/devices/system/cpu/sev/ directory to provide the value of the
SEV_STATUS MSR to user-space.

Signed-off-by: Joerg Roedel <jroedel@suse.de>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/20250305105234.235553-1-joro@8bytes.org
---
arch/x86/coco/sev/core.c | 9 +++++++++
1 file changed, 9 insertions(+)

diff --git a/arch/x86/coco/sev/core.c b/arch/x86/coco/sev/core.c
index 82492ef..7b23fb8 100644
--- a/arch/x86/coco/sev/core.c
+++ b/arch/x86/coco/sev/core.c
@@ -2678,10 +2678,19 @@ 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, "%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,
+ &sev_status_attr.attr,
NULL
};