* [PATCH 0/3 v2] x86/sev: Report MSR_AMD64_SEV in SYSFS
@ 2026-08-03 12:58 Jörg Rödel
2026-08-03 12:58 ` [PATCH 1/3] x86/coco: Add CC_ATTR_GUEST_SEV Jörg Rödel
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Jörg Rödel @ 2026-08-03 12:58 UTC (permalink / raw)
To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86
Cc: hpa, Tom Lendacky, joro, linux-kernel, linux-coco, Joerg Roedel
From: Joerg Roedel <joerg.roedel@amd.com>
Hi,
Here is an updated version of my original patch to report
MSR_AMD64_SEV in SYSFS. The intention is to give user-space tooling a
way to access the MSR value without needing to expose all MSRs via
the msr.ko module.
The patches here are updated to address a Sashiko comment asking why
SEV_STATUS is only reported for SEV-SNP guests. The sev_status file is
now created for SEV and SEV-ES guests as well.
Please review.
Thanks,
Joerg
Joerg Roedel (3):
x86/coco: Add CC_ATTR_GUEST_SEV
x86/sev: Create /sys/devices/system/cpu/sev/ for all SEV guests
x86/coco/sev: Make SEV_STATUS available via SYSFS
.../ABI/testing/sysfs-devices-system-cpu | 9 +++--
arch/x86/coco/core.c | 3 ++
arch/x86/coco/sev/core.c | 33 ++++++++++++++++---
include/linux/cc_platform.h | 9 +++++
4 files changed, 47 insertions(+), 7 deletions(-)
--
2.53.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/3] x86/coco: Add CC_ATTR_GUEST_SEV
2026-08-03 12:58 [PATCH 0/3 v2] x86/sev: Report MSR_AMD64_SEV in SYSFS Jörg Rödel
@ 2026-08-03 12:58 ` Jörg Rödel
2026-08-03 12:58 ` [PATCH 2/3] x86/sev: Create /sys/devices/system/cpu/sev/ for all SEV guests Jörg Rödel
2026-08-03 12:58 ` [PATCH 3/3] x86/coco/sev: Make SEV_STATUS available via SYSFS Jörg Rödel
2 siblings, 0 replies; 4+ messages in thread
From: Jörg Rödel @ 2026-08-03 12:58 UTC (permalink / raw)
To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86
Cc: hpa, Tom Lendacky, joro, linux-kernel, linux-coco, Joerg Roedel
From: Joerg Roedel <joerg.roedel@amd.com>
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).
Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
---
arch/x86/coco/core.c | 3 +++
include/linux/cc_platform.h | 9 +++++++++
2 files changed, 12 insertions(+)
diff --git a/arch/x86/coco/core.c b/arch/x86/coco/core.c
index 989ca9f72ba3..63c06c2ac409 100644
--- a/arch/x86/coco/core.c
+++ b/arch/x86/coco/core.c
@@ -95,6 +95,9 @@ static bool noinstr amd_cc_platform_has(enum cc_attr attr)
return (sev_status & MSR_AMD64_SEV_ENABLED) &&
!(sev_status & MSR_AMD64_SEV_ES_ENABLED);
+ case CC_ATTR_GUEST_SEV:
+ return sev_status & MSR_AMD64_SEV_ENABLED;
+
case CC_ATTR_GUEST_SEV_SNP:
return sev_status & MSR_AMD64_SEV_SNP_ENABLED;
diff --git a/include/linux/cc_platform.h b/include/linux/cc_platform.h
index 559353ad64ac..f87ee0652b04 100644
--- a/include/linux/cc_platform.h
+++ b/include/linux/cc_platform.h
@@ -73,6 +73,15 @@ enum cc_attr {
*/
CC_ATTR_GUEST_UNROLL_STRING_IO,
+ /**
+ * @CC_ATTR_GUEST_SEV: Guest SEV is active.
+ *
+ * The platform/OS is running as a virtual machine guest and actively
+ * using AMD SEV memory encryption. This is true for SEV, SEV-ES, and
+ * SEV-SNP guests.
+ */
+ CC_ATTR_GUEST_SEV,
+
/**
* @CC_ATTR_GUEST_SEV_SNP: Guest SNP is active.
*
--
2.53.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/3] x86/sev: Create /sys/devices/system/cpu/sev/ for all SEV guests
2026-08-03 12:58 [PATCH 0/3 v2] x86/sev: Report MSR_AMD64_SEV in SYSFS Jörg Rödel
2026-08-03 12:58 ` [PATCH 1/3] x86/coco: Add CC_ATTR_GUEST_SEV Jörg Rödel
@ 2026-08-03 12:58 ` Jörg Rödel
2026-08-03 12:58 ` [PATCH 3/3] x86/coco/sev: Make SEV_STATUS available via SYSFS Jörg Rödel
2 siblings, 0 replies; 4+ messages in thread
From: Jörg Rödel @ 2026-08-03 12:58 UTC (permalink / raw)
To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86
Cc: hpa, Tom Lendacky, joro, linux-kernel, linux-coco, Joerg Roedel
From: Joerg Roedel <joerg.roedel@amd.com>
The SYSFS directory for SEV is only created for SEV-SNP guests right
now. Change it to create it for SEV and SEV-ES guests as well so
attributes available on all versions of SEV have a place.
Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
---
.../ABI/testing/sysfs-devices-system-cpu | 5 ++--
arch/x86/coco/sev/core.c | 29 ++++++++++++-------
2 files changed, 22 insertions(+), 12 deletions(-)
diff --git a/Documentation/ABI/testing/sysfs-devices-system-cpu b/Documentation/ABI/testing/sysfs-devices-system-cpu
index 82d10d556cc8..63586e299aa8 100644
--- a/Documentation/ABI/testing/sysfs-devices-system-cpu
+++ b/Documentation/ABI/testing/sysfs-devices-system-cpu
@@ -694,10 +694,11 @@ 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.
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 ecd77d3217f3..5770b99feb9b 100644
--- a/arch/x86/coco/sev/core.c
+++ b/arch/x86/coco/sev/core.c
@@ -1433,14 +1433,7 @@ static ssize_t vmpl_show(struct kobject *kobj,
static struct kobj_attribute vmpl_attr = __ATTR_RO(vmpl);
-static struct attribute *vmpl_attrs[] = {
- &vmpl_attr.attr,
- NULL
-};
-
-static struct attribute_group sev_attr_group = {
- .attrs = vmpl_attrs,
-};
+static struct attribute_group sev_attr_group = {};
static int __init sev_sysfs_init(void)
{
@@ -1448,7 +1441,7 @@ static int __init sev_sysfs_init(void)
struct device *dev_root;
int ret;
- if (!cc_platform_has(CC_ATTR_GUEST_SEV_SNP))
+ if (!cc_platform_has(CC_ATTR_GUEST_SEV))
return -ENODEV;
dev_root = bus_get_dev_root(&cpu_subsys);
@@ -1463,9 +1456,25 @@ 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;
+
+ /* Add SEV-SNP specific attributes */
+ if (cc_platform_has(CC_ATTR_GUEST_SEV_SNP)) {
+ /* VMPL */
+ 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;
+
}
arch_initcall(sev_sysfs_init);
#endif // CONFIG_SYSFS
--
2.53.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 3/3] x86/coco/sev: Make SEV_STATUS available via SYSFS
2026-08-03 12:58 [PATCH 0/3 v2] x86/sev: Report MSR_AMD64_SEV in SYSFS Jörg Rödel
2026-08-03 12:58 ` [PATCH 1/3] x86/coco: Add CC_ATTR_GUEST_SEV Jörg Rödel
2026-08-03 12:58 ` [PATCH 2/3] x86/sev: Create /sys/devices/system/cpu/sev/ for all SEV guests Jörg Rödel
@ 2026-08-03 12:58 ` Jörg Rödel
2 siblings, 0 replies; 4+ messages in thread
From: Jörg Rödel @ 2026-08-03 12:58 UTC (permalink / raw)
To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86
Cc: hpa, Tom Lendacky, joro, linux-kernel, linux-coco, Joerg Roedel
From: Joerg Roedel <joerg.roedel@amd.com>
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 /sys/devices/system/cpu/sev/
directory to provide the value of the SEV_STATUS MSR to user-space.
Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
---
.../ABI/testing/sysfs-devices-system-cpu | 4 ++++
arch/x86/coco/sev/core.c | 16 +++++++++++++++-
2 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/Documentation/ABI/testing/sysfs-devices-system-cpu b/Documentation/ABI/testing/sysfs-devices-system-cpu
index 63586e299aa8..cec413a71491 100644
--- a/Documentation/ABI/testing/sysfs-devices-system-cpu
+++ b/Documentation/ABI/testing/sysfs-devices-system-cpu
@@ -690,6 +690,7 @@ 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@vger.kernel.org>
Description: Secure Encrypted Virtualization (SEV) information
@@ -700,6 +701,9 @@ Description: Secure Encrypted Virtualization (SEV) information
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 5770b99feb9b..4532ffc27041 100644
--- a/arch/x86/coco/sev/core.c
+++ b/arch/x86/coco/sev/core.c
@@ -1431,9 +1431,23 @@ 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_group sev_attr_group = {};
+static struct attribute *sev_status_attrs[] = {
+ &sev_status_attr.attr,
+ NULL
+};
+
+static struct attribute_group sev_attr_group = {
+ .attrs = sev_status_attrs,
+};
static int __init sev_sysfs_init(void)
{
--
2.53.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-08-03 12:58 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-03 12:58 [PATCH 0/3 v2] x86/sev: Report MSR_AMD64_SEV in SYSFS Jörg Rödel
2026-08-03 12:58 ` [PATCH 1/3] x86/coco: Add CC_ATTR_GUEST_SEV Jörg Rödel
2026-08-03 12:58 ` [PATCH 2/3] x86/sev: Create /sys/devices/system/cpu/sev/ for all SEV guests Jörg Rödel
2026-08-03 12:58 ` [PATCH 3/3] x86/coco/sev: Make SEV_STATUS available via SYSFS Jörg Rödel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox