Linux Confidential Computing Development
 help / color / mirror / Atom feed
From: Dan Williams <dan.j.williams@intel.com>
To: Alexey Gladkov <legion@kernel.org>, <x86@kernel.org>
Cc: "Alexey Gladkov (Intel)" <legion@kernel.org>,
	<linux-kernel@vger.kernel.org>, <linux-coco@lists.linux.dev>,
	Alexey Gladkov <alexey.gladkov@intel.com>,
	"H . Peter Anvin" <hpa@zytor.com>, Joerg Roedel <jroedel@suse.de>,
	Juergen Gross <jgross@suse.com>,
	"Kirill A . Shutemov" <kirill.shutemov@linux.intel.com>,
	<Larry.Dewey@amd.com>, Nikunj A Dadhania <nikunj@amd.com>,
	Tom Lendacky <thomas.lendacky@amd.com>
Subject: Re: [RFC PATCH v1 1/3] x86/tdx: Make TDX metadata available via SYSFS
Date: Fri, 14 Mar 2025 16:42:31 -0700	[thread overview]
Message-ID: <67d4bee77313a_12e31294c7@dwillia2-xfh.jf.intel.com.notmuch> (raw)
In-Reply-To: <ddbf49381eb5d1779e218e022ffc144db5da003e.1741952958.git.legion@kernel.org>

Alexey Gladkov wrote:
> From: "Alexey Gladkov (Intel)" <legion@kernel.org>
> 
> Expose the TDX module information to userspace. The version information
> is valuable for debugging, as knowing the exact module version can help
> reproduce TDX-related issues.
> 
> Signed-off-by: Alexey Gladkov (Intel) <legion@kernel.org>
> ---
>  arch/x86/Kconfig                  |  1 +
>  arch/x86/include/asm/shared/tdx.h |  2 +
>  arch/x86/include/asm/tdx.h        | 12 +++++
>  arch/x86/virt/vmx/tdx/tdx.c       | 74 +++++++++++++++++++++++++++++++
>  4 files changed, 89 insertions(+)
> 
> diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
> index be2c311f5118..516f3539d0c7 100644
> --- a/arch/x86/Kconfig
> +++ b/arch/x86/Kconfig
> @@ -1986,6 +1986,7 @@ config INTEL_TDX_HOST
>  	depends on CONTIG_ALLOC
>  	depends on !KEXEC_CORE
>  	depends on X86_MCE
> +	select SYS_HYPERVISOR
>  	help
>  	  Intel Trust Domain Extensions (TDX) protects guest VMs from malicious
>  	  host and certain physical attacks.  This option enables necessary TDX
> diff --git a/arch/x86/include/asm/shared/tdx.h b/arch/x86/include/asm/shared/tdx.h
> index 606d93a1cbac..92ee9dfb21e7 100644
> --- a/arch/x86/include/asm/shared/tdx.h
> +++ b/arch/x86/include/asm/shared/tdx.h
> @@ -18,6 +18,8 @@
>  #define TDG_MEM_PAGE_ACCEPT		6
>  #define TDG_VM_RD			7
>  #define TDG_VM_WR			8
> +/* TDG_SYS_RD is available since TDX module version 1.5 and later. */
> +#define TDG_SYS_RD			11
>  
>  /* TDX attributes */
>  #define TDX_ATTR_DEBUG_BIT		0
> diff --git a/arch/x86/include/asm/tdx.h b/arch/x86/include/asm/tdx.h
> index e6b003fe7f5e..95d748bc8464 100644
> --- a/arch/x86/include/asm/tdx.h
> +++ b/arch/x86/include/asm/tdx.h
> @@ -31,6 +31,18 @@
>  #define TDX_SUCCESS		0ULL
>  #define TDX_RND_NO_ENTROPY	0x8000020300000000ULL
>  
> +/*
> + * TDX metadata base field id, used by TDCALL TDG.SYS.RD
> + * See TDX ABI Spec Global Metadata Fields
> + */
> +#define TDX_SYS_MINOR_FID		0x0800000100000003ULL
> +#define TDX_SYS_MAJOR_FID		0x0800000100000004ULL
> +#define TDX_SYS_UPDATE_FID		0x0800000100000005ULL
> +#define TDX_SYS_INTERNAL_FID		0x0800000100000006ULL
> +#define TDX_SYS_BUILD_DATE_FID		0x8800000200000001ULL
> +#define TDX_SYS_BUILD_NUM_FID		0x8800000100000002ULL
> +#define TDX_SYS_FEATURES0_FID		0x0A00000300000008ULL
> +
>  #ifndef __ASSEMBLY__
>  
>  #include <uapi/asm/mce.h>
> diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c
> index f5e2a937c1e7..89378e2a1f66 100644
> --- a/arch/x86/virt/vmx/tdx/tdx.c
> +++ b/arch/x86/virt/vmx/tdx/tdx.c
> @@ -1869,3 +1869,77 @@ u64 tdh_phymem_page_wbinvd_hkid(u64 hkid, struct page *page)
>  	return seamcall(TDH_PHYMEM_PAGE_WBINVD, &args);
>  }
>  EXPORT_SYMBOL_GPL(tdh_phymem_page_wbinvd_hkid);
> +
> +#ifdef CONFIG_SYSFS
> +#define TDX_SYSFS_ATTR(_field, _name, fmt)				\
> +static ssize_t _name ## _show(						\
> +	struct kobject *kobj, struct kobj_attribute *attr, char *buf)	\
> +{									\
> +	u64 value = 0;							\
> +	read_sys_metadata_field(_field, &value);			\
> +	return sprintf(buf, fmt, value);				\
> +}									\
> +static struct kobj_attribute _name ## _attr = __ATTR_RO(_name)
> +
> +TDX_SYSFS_ATTR(TDX_SYS_MINOR_FID, minor, "%lld\n");
> +TDX_SYSFS_ATTR(TDX_SYS_MAJOR_FID, major, "%lld\n");
> +TDX_SYSFS_ATTR(TDX_SYS_UPDATE_FID, update, "%lld\n");
> +TDX_SYSFS_ATTR(TDX_SYS_BUILD_NUM_FID, build_num, "%lld\n");
> +TDX_SYSFS_ATTR(TDX_SYS_BUILD_DATE_FID, build_date, "%lld\n");
> +TDX_SYSFS_ATTR(TDX_SYS_FEATURES0_FID, features0, "%llx\n");
> +
> +static struct attribute *version_attrs[] = {
> +	&minor_attr.attr,
> +	&major_attr.attr,
> +	&update_attr.attr,
> +	NULL,
> +};
> +
> +static const struct attribute_group version_attr_group = {
> +	.name = "version",
> +	.attrs = version_attrs,
> +};
> +
> +static struct attribute *properties_attrs[] = {
> +	&build_num_attr.attr,
> +	&build_date_attr.attr,
> +	&features0_attr.attr,
> +	NULL,
> +};
> +
> +static const struct attribute_group properties_attr_group = {
> +	.name = "properties",
> +	.attrs = properties_attrs,
> +};
> +
> +__init static int tdh_sysfs_init(void)
> +{
> +	struct kobject *tdx_kobj;
> +	int ret;
> +
> +	if (!hypervisor_kobj)
> +		return -ENOMEM;
> +
> +	tdx_kobj = kobject_create_and_add("tdx", hypervisor_kobj);

So this "/sys/hypervisor" proposal is clearly unaware of some other
discussions that have been happening around sysfs ABI for TEE Security
Managers like the PSP or TDX Module [1]. That PCI/TSM series discusses
the motivation for a bus/class + device model, not just raw hand-crafted
kobjects.

My other concern for hand-crafted kobjects is that it also destroys the
relationship with other existing objects. A /sys/hypervisor/$technology
is awkward when ABI like Documentation/ABI/testing/sysfs-driver-ccp
already exists.

So, no, I am not on board with this proposal. There are already patches
in flight to have TDX create a 'struct device' object that plays a
similar role as the PSP device object. For any potential common
attributes across vendors the proposal is that be handled via a typical
sysfs class device construction that links back to the $technology
device. That "tsm" class device is present in the PCI/TSM series [1].

[1]: http://lore.kernel.org/174107245357.1288555.10863541957822891561.stgit@dwillia2-xfh.jf.intel.com

  reply	other threads:[~2025-03-14 23:42 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-14 11:56 [RFC PATCH v1 0/3] Export TDX module information via SYSFS Alexey Gladkov
2025-03-14 11:56 ` [RFC PATCH v1 1/3] x86/tdx: Make TDX metadata available " Alexey Gladkov
2025-03-14 23:42   ` Dan Williams [this message]
2025-03-17  9:38     ` Kirill A . Shutemov
2025-03-18  1:35       ` Dan Williams
2025-03-18  9:30         ` Kirill A . Shutemov
2025-03-19 16:58           ` Dan Williams
2025-03-14 11:56 ` [RFC PATCH v1 2/3] x86/tdx: Make TDX metadata available on guest " Alexey Gladkov
2025-03-14 11:56 ` [RFC PATCH v1 3/3] docs: ABI: testing: Add documentation about TDX Alexey Gladkov

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=67d4bee77313a_12e31294c7@dwillia2-xfh.jf.intel.com.notmuch \
    --to=dan.j.williams@intel.com \
    --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=legion@kernel.org \
    --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