linux-coco.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Joerg Roedel <joro@8bytes.org>
To: x86@kernel.org
Cc: hpa@zytor.com, Tom Lendacky <thomas.lendacky@amd.com>,
	Nikunj A Dadhania <nikunj@amd.com>,
	Larry.Dewey@amd.com, linux-kernel@vger.kernel.org,
	linux-coco@lists.linux.dev, Juergen Gross <jgross@suse.com>,
	kirill.shutemov@linux.intel.com, alexey.gladkov@intel.com,
	Joerg Roedel <jroedel@suse.de>
Subject: [PATCH 1/2] x86/coco/sev: Move SEV SYSFS group to /sys/hypervisor/
Date: Wed, 12 Mar 2025 15:41:06 +0100	[thread overview]
Message-ID: <20250312144107.108451-2-joro@8bytes.org> (raw)
In-Reply-To: <20250312144107.108451-1-joro@8bytes.org>

From: Joerg Roedel <jroedel@suse.de>

Move the SYSFS information about SEV to the /sys/hypervisor/ directory and link
to it from the old location. The /sys/hypervisor/ hierarchy makes more
sense for this information, as it is only relevant in a virtualized
environment and contains values influenced by the hypervisor.

Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
 .../ABI/testing/sysfs-devices-system-cpu      | 11 ++--------
 Documentation/ABI/testing/sysfs-hypervisor    | 10 +++++++++
 arch/x86/Kconfig                              |  1 +
 arch/x86/coco/sev/core.c                      | 21 +++++++++++++------
 4 files changed, 28 insertions(+), 15 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-hypervisor

diff --git a/Documentation/ABI/testing/sysfs-devices-system-cpu b/Documentation/ABI/testing/sysfs-devices-system-cpu
index 206079d3bd5b..f056c401a550 100644
--- a/Documentation/ABI/testing/sysfs-devices-system-cpu
+++ b/Documentation/ABI/testing/sysfs-devices-system-cpu
@@ -607,16 +607,9 @@ Description:	Umwait control
 			  Low order two bits must be zero.
 
 What:		/sys/devices/system/cpu/sev
-		/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.
-
-		vmpl: Reports the Virtual Machine Privilege Level (VMPL) at which
-		      the SEV-SNP guest is running.
-
+Description:	This symbolic link to /sys/hypervisor/sev/ is only present when
+		running as an SEV-SNP guest.
 
 What:		/sys/devices/system/cpu/svm
 Date:		August 2019
diff --git a/Documentation/ABI/testing/sysfs-hypervisor b/Documentation/ABI/testing/sysfs-hypervisor
new file mode 100644
index 000000000000..aca8b02c878c
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-hypervisor
@@ -0,0 +1,10 @@
+What:		/sys/devices/system/cpu/sev
+		/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.
+
+		vmpl: Reports the Virtual Machine Privilege Level (VMPL) at which
+		      the SEV-SNP guest is running.
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 1665ebaba251..5b717f6ccbbb 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -1497,6 +1497,7 @@ config AMD_MEM_ENCRYPT
 	select X86_MEM_ENCRYPT
 	select UNACCEPTED_MEMORY
 	select CRYPTO_LIB_AESGCM
+	select SYS_HYPERVISOR
 	help
 	  Say yes to enable support for the encryption of system memory.
 	  This requires an AMD processor that supports Secure Memory
diff --git a/arch/x86/coco/sev/core.c b/arch/x86/coco/sev/core.c
index 96c7bc698e6b..51a04a19449b 100644
--- a/arch/x86/coco/sev/core.c
+++ b/arch/x86/coco/sev/core.c
@@ -2698,12 +2698,10 @@ static int __init sev_sysfs_init(void)
 	if (!cc_platform_has(CC_ATTR_GUEST_SEV_SNP))
 		return -ENODEV;
 
-	dev_root = bus_get_dev_root(&cpu_subsys);
-	if (!dev_root)
-		return -ENODEV;
-
-	sev_kobj = kobject_create_and_add("sev", &dev_root->kobj);
-	put_device(dev_root);
+	/*
+	 * Create /sys/hypervisor/sev/ with attributes
+	 */
+	sev_kobj = kobject_create_and_add("sev", hypervisor_kobj);
 
 	if (!sev_kobj)
 		return -ENOMEM;
@@ -2712,6 +2710,17 @@ static int __init sev_sysfs_init(void)
 	if (ret)
 		kobject_put(sev_kobj);
 
+	/*
+	 * Link from /sys/devices/system/cpu/sev to /sys/hypervisor/sev/ for
+	 * compatibility reasons.
+	 */
+	dev_root = bus_get_dev_root(&cpu_subsys);
+	if (!dev_root)
+		return -ENODEV;
+
+	ret = compat_only_sysfs_link_entry_to_kobj(&dev_root->kobj, hypervisor_kobj, "sev", NULL);
+	put_device(dev_root);
+
 	return ret;
 }
 arch_initcall(sev_sysfs_init);
-- 
2.48.1


  reply	other threads:[~2025-03-12 14:41 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-12 14:41 [PATCH 0/2 v2] Move SEV sysfs information and expose MSR_SEV_STATUS Joerg Roedel
2025-03-12 14:41 ` Joerg Roedel [this message]
2025-03-12 15:11   ` [PATCH 1/2] x86/coco/sev: Move SEV SYSFS group to /sys/hypervisor/ Tom Lendacky
2025-03-12 15:13     ` Joerg Roedel
2025-03-12 15:32   ` Liam Merwick
2025-03-12 15:43     ` Joerg Roedel
2025-03-12 14:41 ` [PATCH 2/2] x86/sev: Make SEV_STATUS available via SYSFS Joerg Roedel
2025-03-12 14:46   ` Tom Lendacky
2025-03-12 14:56     ` Joerg Roedel
2025-03-12 14:57   ` Dave Hansen
2025-03-12 15:07     ` Joerg Roedel
2025-03-12 16:04       ` Dave Hansen
2025-03-12 16:19         ` Joerg Roedel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250312144107.108451-2-joro@8bytes.org \
    --to=joro@8bytes.org \
    --cc=Larry.Dewey@amd.com \
    --cc=alexey.gladkov@intel.com \
    --cc=hpa@zytor.com \
    --cc=jgross@suse.com \
    --cc=jroedel@suse.de \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=linux-coco@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nikunj@amd.com \
    --cc=thomas.lendacky@amd.com \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).