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

Jörg Rödel <[email protected]> Mon, 3 Aug 2026 14:58:25 +0200
Newsgroups dev.linux.lists.linux-coco,org.kernel.vger.linux-kernel
Message-ID <[email protected]>
From: Joerg Roedel <[email protected]>

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 <[email protected]>
---
 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