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

From: tip-bot2 for Joerg Roedel
Date: Wed Mar 05 2025 - 06:13:07 EST


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@xxxxxxx>
AuthorDate: Wed, 05 Mar 2025 11:52:34 +01:00
Committer: Ingo Molnar <mingo@xxxxxxxxxx>
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@xxxxxxx>
Signed-off-by: Ingo Molnar <mingo@xxxxxxxxxx>
Link: https://lore.kernel.org/r/20250305105234.235553-1-joro@xxxxxxxxxx
---
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
};