From nobody Fri Dec 19 02:56:03 2025 Received: from mail.8bytes.org (mail.8bytes.org [85.214.250.239]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DBF47253B4A for ; Wed, 12 Mar 2025 14:41:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=85.214.250.239 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741790512; cv=none; b=hRB/0EdxCKroKhYqFiIgs5Uwj3sBNH24vuwQhX7MupD1B7k8p2cHpLHNJ8ruiP7dwe97podF+5oJapaFjcd718Lni0heOJfYyRQ/iuIsfaWU39ZbaAhownGeY4fqL4QgXxlavwAw4POWxaaRQEMZETrSUOJR9Z2uI+9BG/EoB1o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741790512; c=relaxed/simple; bh=ABo5c/g/NmTfed1rIlmDQYaywrtYmQqrN3BxtbVRwXc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hsCrC83pn6nAmE8M2OznC5917f8YzdtMW6pCVb1fdVcZJOvBG13/PTrZj3BDOux4ywEC91cPGiMxGXxefQIy/GfT6N4/xrH3VKYT5Gv1ANtnMNdi3L/+F54QOjusnVOSLLKhlbam5xdPsTic+VP2HsaNsqwrKLPQLm9kfTix0oc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=8bytes.org; spf=pass smtp.mailfrom=8bytes.org; dkim=pass (2048-bit key) header.d=8bytes.org header.i=@8bytes.org header.b=jONsDT29; arc=none smtp.client-ip=85.214.250.239 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=8bytes.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=8bytes.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=8bytes.org header.i=@8bytes.org header.b="jONsDT29" Received: from cap.home.8bytes.org (p4ffe03ae.dip0.t-ipconnect.de [79.254.3.174]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.8bytes.org (Postfix) with ESMTPSA id 5A3C6457E7; Wed, 12 Mar 2025 15:41:43 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=8bytes.org; s=default; t=1741790503; bh=ABo5c/g/NmTfed1rIlmDQYaywrtYmQqrN3BxtbVRwXc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jONsDT290Lwv9Ht2/jlvKGwGGLafHTWbHFU4mB4/VoOFicXgIsSUkhYL0jV2MnF8n EK3Zu/q9AcxX19WMo7eu7zrn1Dfbi59sA8993HT7nav0x4P8xZe2Bb0eUVjgUSJNn+ 6dWxOYjHmSiS+VDUW91SoENeDJSADghOkggVAhetsRX50jj1nBe8z9hnC0YJ+bYoTX OKIMyqjXWy6D0xr/Uzn/cLo/VWS3TDjX91Lk9KJIc1RnZ2Lt/w9lldX2rIFqK9iiMV 1MaBMnO+RCnzySV4+P865EVoY+AkTF2140M9k5XUjlq8qnYk701xVzjBJVDAejH5mN r78ihaQr10a4w== From: Joerg Roedel To: x86@kernel.org Cc: hpa@zytor.com, Tom Lendacky , Nikunj A Dadhania , Larry.Dewey@amd.com, linux-kernel@vger.kernel.org, linux-coco@lists.linux.dev, Juergen Gross , kirill.shutemov@linux.intel.com, alexey.gladkov@intel.com, Joerg Roedel Subject: [PATCH 1/2] x86/coco/sev: Move SEV SYSFS group to /sys/hypervisor/ Date: Wed, 12 Mar 2025 15:41:06 +0100 Message-ID: <20250312144107.108451-2-joro@8bytes.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250312144107.108451-1-joro@8bytes.org> References: <20250312144107.108451-1-joro@8bytes.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Joerg Roedel 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 Reviewed-by: Liam Merwick Reviewed-by: Tom Lendacky --- .../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/Documenta= tion/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. =20 What: /sys/devices/system/cpu/sev - /sys/devices/system/cpu/sev/vmpl Date: May 2024 -Contact: Linux kernel mailing list -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 wh= en + running as an SEV-SNP guest. =20 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 +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; =20 - dev_root =3D bus_get_dev_root(&cpu_subsys); - if (!dev_root) - return -ENODEV; - - sev_kobj =3D kobject_create_and_add("sev", &dev_root->kobj); - put_device(dev_root); + /* + * Create /sys/hypervisor/sev/ with attributes + */ + sev_kobj =3D kobject_create_and_add("sev", hypervisor_kobj); =20 if (!sev_kobj) return -ENOMEM; @@ -2712,6 +2710,17 @@ static int __init sev_sysfs_init(void) if (ret) kobject_put(sev_kobj); =20 + /* + * Link from /sys/devices/system/cpu/sev to /sys/hypervisor/sev/ for + * compatibility reasons. + */ + dev_root =3D bus_get_dev_root(&cpu_subsys); + if (!dev_root) + return -ENODEV; + + ret =3D 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); --=20 2.48.1 From nobody Fri Dec 19 02:56:03 2025 Received: from mail.8bytes.org (mail.8bytes.org [85.214.250.239]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DBEE22528FC for ; Wed, 12 Mar 2025 14:41:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=85.214.250.239 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741790513; cv=none; b=AhsTublhcGVFonjeURRYmenslQIfHssVdhNgrutU8D33SkJoUClO1EtPMDrfJW7jmD/LTbS9FS617JnesrKPlaLunNgRzAuZp+cyezy2OSXQU9Ha1NMWsGDXp4gv3EtB9HJ5X0qBbjyR+ArAJ8FirC8oIXYGpL+M5zHl+v422oU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741790513; c=relaxed/simple; bh=0qIK11Nxc/qG99PcihtfUwWqc93REynnXKH4VFL31IE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LdGrjag70tctrQK+0G3yi4Ns+4l5w0zd1sDVvQkLiHaaJpiWJTiyWybuMX9fO99mVpzaQt5qDtoy3+BT+mTc693vvmX3ABEGWkfVAN6sf6l+4hfRwOVoI1ppXxkSaoPyCK+/u6zTlrhZuzs7khs2Hh5FiFNEhdgvbWp5OSoJv0E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=8bytes.org; spf=pass smtp.mailfrom=8bytes.org; dkim=pass (2048-bit key) header.d=8bytes.org header.i=@8bytes.org header.b=HoHVNj/I; arc=none smtp.client-ip=85.214.250.239 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=8bytes.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=8bytes.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=8bytes.org header.i=@8bytes.org header.b="HoHVNj/I" Received: from cap.home.8bytes.org (p4ffe03ae.dip0.t-ipconnect.de [79.254.3.174]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.8bytes.org (Postfix) with ESMTPSA id 7C8AB457E8; Wed, 12 Mar 2025 15:41:43 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=8bytes.org; s=default; t=1741790503; bh=0qIK11Nxc/qG99PcihtfUwWqc93REynnXKH4VFL31IE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HoHVNj/IbAvBuNXjpXmXmZXhmi/mV9g31NXzx+Q8ymiP69hnKc+IMTFmtlSR7OcaM ZtXOQpRSuosn2dXeWEjxB0NcIW4Nq6o/gEtvf2HlAYMUuy14ZbQn7M2q6Pma82s8ML 65/qsWECVTDUw8hFjewyv9iNMoAjH+dvO98mQOXxemny9oelR+0fTEqmYJzWNkky9J 8EGBIBN6nppdcsdXQqJW1PJqlwGM6riy9e+GvAg4VTtzDWTiarRmaWO+4meYLT73Tz Chd9fB+OaiKp99CKAMdYGZ2aKQmB+CLbtJI1pWlDV5Q24BD9vVkoKaRqq/hZb2gYpe CeFcDthvl4zSQ== From: Joerg Roedel To: x86@kernel.org Cc: hpa@zytor.com, Tom Lendacky , Nikunj A Dadhania , Larry.Dewey@amd.com, linux-kernel@vger.kernel.org, linux-coco@lists.linux.dev, Juergen Gross , kirill.shutemov@linux.intel.com, alexey.gladkov@intel.com, Joerg Roedel Subject: [PATCH 2/2] x86/sev: Make SEV_STATUS available via SYSFS Date: Wed, 12 Mar 2025 15:41:07 +0100 Message-ID: <20250312144107.108451-3-joro@8bytes.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250312144107.108451-1-joro@8bytes.org> References: <20250312144107.108451-1-joro@8bytes.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Joerg Roedel 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/hypervisor/sev/ directory to provide the value of the SEV_STATUS MSR to user-space. Signed-off-by: Joerg Roedel --- Documentation/ABI/testing/sysfs-hypervisor | 5 +++++ arch/x86/coco/sev/core.c | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-hypervisor b/Documentation/ABI= /testing/sysfs-hypervisor index aca8b02c878c..54c80899c19c 100644 --- a/Documentation/ABI/testing/sysfs-hypervisor +++ b/Documentation/ABI/testing/sysfs-hypervisor @@ -1,5 +1,6 @@ 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 Description: Secure Encrypted Virtualization (SEV) information @@ -8,3 +9,7 @@ Description: Secure Encrypted Virtualization (SEV) informat= ion =20 vmpl: Reports the Virtual Machine Privilege Level (VMPL) at which the SEV-SNP guest is running. + + sev_status: Reports the value of the SEV_STATUS MSR which + enumerates the enabled features of an SEV-SNP + environment. diff --git a/arch/x86/coco/sev/core.c b/arch/x86/coco/sev/core.c index 51a04a19449b..3e834ce9badc 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); } =20 +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 =3D __ATTR_RO(vmpl); +static struct kobj_attribute sev_status_attr =3D __ATTR_RO(sev_status); + =20 static struct attribute *vmpl_attrs[] =3D { &vmpl_attr.attr, + &sev_status_attr.attr, NULL }; =20 --=20 2.48.1