All of lore.kernel.org
 help / color / mirror / Atom feed
From: Baolu Lu <baolu.lu@linux.intel.com>
To: Chao Gao <chao.gao@intel.com>
Cc: baolu.lu@linux.intel.com, iommu@lists.linux.dev, x86@kernel.org,
	linux-coco@lists.linux.dev, kvm@vger.kernel.org,
	Jason Gunthorpe <jgg@ziepe.ca>, Kevin Tian <kevin.tian@intel.com>,
	Kiryl Shutsemau <kas@kernel.org>,
	Rick Edgecombe <rick.p.edgecombe@intel.com>,
	yilun.xu@linux.intel.com, xiaoyao.li@intel.com,
	Binbin Wu <binbin.wu@linux.intel.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 7/9] coco/tdx-host: Add skeleton to support PCI link encryption
Date: Mon, 23 Nov 2026 11:30:12 +0800	[thread overview]
Message-ID: <d9f3eecf-5655-4779-9e8a-b3ff4cbdb667@linux.intel.com> (raw)
In-Reply-To: <av1QxRYY9sXtC--P@intel.com>

On 11/18/2026 3:16 PM, Chao Gao wrote:
> On Thu, Nov 12, 2026 at 12:30:52PM +0800, Lu Baolu wrote:
>> Register a Link TSM instance to support host side TSM operations for
>> TDISP, when the TDX Connect support bit is set by TDX Module in
>> tdx_feature0.
> 
> s/TDX Module/TDX module for the whole patch. Existing code and docs mostly
> use "TDX module".
> 
> Also s/tdx_feature0/tdx_features0.

Updated. Thanks!

>>
>> This is the main purpose of an independent tdx-host module out of TDX
>> core. Recall that a TEE Security Manager (TSM) is a platform agent that
>> speaks the TEE Device Interface Security Protocol (TDISP) to PCIe
>> devices and manages private memory resources for the platform. An
>> independent tdx-host module allows for device-security enumeration and
>> initialization flows to be deferred from other TDX Module initialization
>> requirements. Crucially, when / if TDX Module init moves earlier in x86
>> initialization flow this driver is still guaranteed to run after IOMMU
>> and PCI init (i.e. subsys_initcall() vs device_initcall()).
> 
> This changelog is outdated. TDX module initialization has already moved
> earlier in x86 initialization.

Updated. Thanks!

> 
>>
>> The ability to unload the module, or unbind the driver is also useful
>> for debug and coarse grained transitioning between PCI TSM operation and
>> PCI CMA operation (native kernel PCI device authentication).
>>
>> For now only check for TDX Connect support in the TDX Module and
>> register the Link TSM. The TSM support is basic boilerplate with
>> operation flows to be added later.
>>
>> Based on work by Yilun and Dan.
>>
>> Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
>> ---
>> drivers/virt/coco/tdx-host/Kconfig    |   2 +
>> arch/x86/include/asm/tdx.h            |   8 ++
>> drivers/virt/coco/tdx-host/tdx-host.c | 118 +++++++++++++++++++++++++-
>> 3 files changed, 127 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/virt/coco/tdx-host/Kconfig b/drivers/virt/coco/tdx-host/Kconfig
>> index 57d0c01a4357..f8c8cc29d46c 100644
>> --- a/drivers/virt/coco/tdx-host/Kconfig
>> +++ b/drivers/virt/coco/tdx-host/Kconfig
>> @@ -1,6 +1,8 @@
>> config TDX_HOST_SERVICES
>> 	tristate
>> 	depends on INTEL_TDX_HOST
>> +	depends on PCI
>> 	select FW_LOADER
>> 	select FW_UPLOAD
>> +	select PCI_TSM
>> 	default m
>> diff --git a/arch/x86/include/asm/tdx.h b/arch/x86/include/asm/tdx.h
>> index 0ed0062c9b0a..fc284a555984 100644
>> --- a/arch/x86/include/asm/tdx.h
>> +++ b/arch/x86/include/asm/tdx.h
>> @@ -142,6 +142,14 @@ int tdx_topup_pamt_cache(struct tdx_pamt_cache *cache, unsigned long npages);
>> int tdx_pamt_get(kvm_pfn_t pfn, struct tdx_pamt_cache *cache);
>> void tdx_pamt_put(kvm_pfn_t pfn);
>>
>> +static inline bool tdx_supports_tdisp(const struct tdx_sys_info *sysinfo)
>> +{
>> +	if (!(sysinfo->features.tdx_features0 & TDX_FEATURES0_TDXCONNECT))
>> +		return false;
>> +
>> +	return false; /* To be enabled when kernel is ready */
>> +}
> 
> Patch 2 open-codes the same TDX_FEATURES0_TDXCONNECT check. Can this
> helper be moved to patch 2 and used there?

These checks serve different purposes: the metadata patch checks whether
the TDX module supports TDX Connect; tdx_supports_tdisp() decides
whether the kernel is ready to register the link tsm. The latter may
include additional checks, such as quirks, so I would like to keep the
helper for the tsm registration.

> 
>> +
>> int tdx_guest_keyid_alloc(void);
>> u32 tdx_get_nr_guest_keyids(void);
>> void tdx_guest_keyid_free(unsigned int keyid);
>> diff --git a/drivers/virt/coco/tdx-host/tdx-host.c b/drivers/virt/coco/tdx-host/tdx-host.c
>> index e8ed8dfa526e..0908aaaa28ac 100644
>> --- a/drivers/virt/coco/tdx-host/tdx-host.c
>> +++ b/drivers/virt/coco/tdx-host/tdx-host.c
>> @@ -9,10 +9,14 @@
>> #include <linux/firmware.h>
>> #include <linux/module.h>
>> #include <linux/sysfs.h>
>> +#include <linux/pci.h>
>> +#include <linux/pci-tsm.h>
>> +#include <linux/tsm.h>
>>
>> #include <asm/cpu_device_id.h>
>> #include <asm/seamldr.h>
>> #include <asm/tdx.h>
>> +#include <asm/tdx_global_metadata.h>
>>
>> static const struct x86_cpu_id tdx_host_ids[] = {
>> 	X86_MATCH_FEATURE(X86_FEATURE_TDX_HOST_PLATFORM, NULL),
>> @@ -20,6 +24,112 @@ static const struct x86_cpu_id tdx_host_ids[] = {
>> };
>> MODULE_DEVICE_TABLE(x86cpu, tdx_host_ids);
>>
>> +struct tdx_tsm_link {
>> +	struct pci_tsm_pf0 pci;
>> +};
>> +
>> +static struct tdx_tsm_link *to_tdx_tsm_link(struct pci_tsm *tsm)
>> +{
>> +	return container_of(tsm, struct tdx_tsm_link, pci.base_tsm);
>> +}
>> +
>> +static int tdx_tsm_link_connect(struct pci_dev *pdev)
>> +{
>> +	return -ENXIO;
>> +}
>> +
>> +static void tdx_tsm_link_disconnect(struct pci_dev *pdev)
>> +{
>> +}
>> +
>> +static struct pci_tsm *tdx_tsm_link_pf0_probe(struct tsm_dev *tsm_dev,
>> +					      struct pci_dev *pdev)
>> +{
>> +	int rc;
>> +
>> +	struct tdx_tsm_link *tlink __free(kfree) = kzalloc_obj(*tlink);
> 
> tdx-host goes through the tip tree. It looks like Dave prefers plain
> error handling over __free() [*]. I think we should drop __free() for
> tdx-host code. Same for tdx_tsm_link_fn_probe() below.
> 
> *: https://lore.kernel.org/kvm/691e16318f5ea_1eb85100ce@dwillia2-mobl4.notmuch/

Okay, so I will update it like this:

diff --git a/drivers/virt/coco/tdx-host/main.c 
b/drivers/virt/coco/tdx-host/main.c
index a815dbe5127a..af887c49a027 100644
--- a/drivers/virt/coco/tdx-host/main.c
+++ b/drivers/virt/coco/tdx-host/main.c
@@ -56,17 +56,22 @@ static void tdx_tsm_link_disconnect(struct pci_dev 
*pdev)
  static struct pci_tsm *tdx_tsm_link_pf0_probe(struct tsm_dev *tsm_dev,
  					      struct pci_dev *pdev)
  {
+	struct tdx_tsm_link *tlink;
  	int rc;

-	struct tdx_tsm_link *tlink __free(kfree) = kzalloc_obj(*tlink);
+	tlink = kzalloc_obj(*tlink);
  	if (!tlink)
  		return NULL;

  	rc = pci_tsm_pf0_constructor(pdev, &tlink->pci, tsm_dev);
  	if (rc)
-		return NULL;
+		goto err_free;

-	return &no_free_ptr(tlink)->pci.base_tsm;
+	return &tlink->pci.base_tsm;
+
+err_free:
+	kfree(tlink);
+	return NULL;
  }

  static void tdx_tsm_link_pf0_remove(struct pci_tsm *tsm)
@@ -80,17 +85,22 @@ static void tdx_tsm_link_pf0_remove(struct pci_tsm *tsm)
  static struct pci_tsm *tdx_tsm_link_fn_probe(struct tsm_dev *tsm_dev,
  					     struct pci_dev *pdev)
  {
+	struct pci_tsm *pci_tsm;
  	int rc;

-	struct pci_tsm *pci_tsm __free(kfree) = kzalloc_obj(*pci_tsm);
+	pci_tsm = kzalloc_obj(*pci_tsm);
  	if (!pci_tsm)
  		return NULL;

  	rc = pci_tsm_link_constructor(pdev, pci_tsm, tsm_dev);
  	if (rc)
-		return NULL;
+		goto err_free;

-	return no_free_ptr(pci_tsm);
+	return pci_tsm;
+
+err_free:
+	kfree(pci_tsm);
+	return NULL;
  }

  static struct pci_tsm *tdx_tsm_link_probe(struct tsm_dev *tsm_dev,
-- 
2.43.0


>> +	if (!tlink)
>> +		return NULL;
>> +
>> +	rc = pci_tsm_pf0_constructor(pdev, &tlink->pci, tsm_dev);
>> +	if (rc)
>> +		return NULL;
>> +
>> +	return &no_free_ptr(tlink)->pci.base_tsm;
>> +}
>> +
>> +static void tdx_tsm_link_pf0_remove(struct pci_tsm *tsm)
>> +{
>> +	struct tdx_tsm_link *tlink = to_tdx_tsm_link(tsm);
>> +
>> +	pci_tsm_pf0_destructor(&tlink->pci);
>> +	kfree(tlink);
>> +}
>> +
>> +static struct pci_tsm *tdx_tsm_link_fn_probe(struct tsm_dev *tsm_dev,
>> +					     struct pci_dev *pdev)
>> +{
>> +	int rc;
>> +
>> +	struct pci_tsm *pci_tsm __free(kfree) = kzalloc_obj(*pci_tsm);
>> +	if (!pci_tsm)
>> +		return NULL;
>> +
>> +	rc = pci_tsm_link_constructor(pdev, pci_tsm, tsm_dev);
>> +	if (rc)
>> +		return NULL;
>> +
>> +	return no_free_ptr(pci_tsm);
>> +}

Thanks,
baolu

  reply	other threads:[~2026-11-23  3:30 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-12  4:30 [PATCH v3 0/9] coco/tdx-host: Introduce trusted DMA initialization support Lu Baolu
2026-11-12  4:30 ` [PATCH v3 1/9] x86/virt/tdx: Add SEAMCALL wrappers for IOMMU setup/clear Lu Baolu
2026-11-18 11:02   ` Binbin Wu
2026-11-23  4:03     ` Baolu Lu
2026-11-23  9:55   ` Xu Yilun
2026-11-24  5:46     ` Baolu Lu
2026-11-24  8:07   ` Tian, Kevin
2026-11-25  2:47     ` Baolu Lu
2026-11-25  3:08       ` Tian, Kevin
2026-11-25  4:26         ` Baolu Lu
2026-11-12  4:30 ` [PATCH v3 2/9] x86/virt/tdx: Read global metadata for trusted IOMMU Lu Baolu
2026-11-18 13:39   ` Binbin Wu
2026-11-23  4:09     ` Baolu Lu
2026-11-24  8:13       ` Tian, Kevin
2026-11-25  2:57         ` Baolu Lu
2026-11-12  4:30 ` [PATCH v3 3/9] x86/virt/tdx: Export Dynamic PAMT helpers to tdx-host Lu Baolu
2026-11-23 10:25   ` Xu Yilun
2026-11-23 16:28     ` Edgecombe, Rick P
2026-11-24  6:07       ` Baolu Lu
2026-11-12  4:30 ` [PATCH v3 4/9] iommu/vt-d: Add interface for tdx-host when enabling trusted DMA Lu Baolu
2026-11-23 15:08   ` Xu Yilun
2026-11-24  7:47     ` Baolu Lu
2026-11-25  3:32       ` Tian, Kevin
2026-11-25  3:29   ` Tian, Kevin
2026-11-25 23:33     ` Baolu Lu
     [not found]     ` <9a92bb91-3dac-4fc5-8f38-130b7442bdcc@linux.intel.com>
2026-11-27  7:59       ` Tian, Kevin
2026-12-02  0:22         ` Baolu Lu
2026-12-02  3:02           ` Tian, Kevin
2026-11-12  4:30 ` [PATCH v3 5/9] iommu/vt-d: Block GCMD and ECMD while acquired by the TDX module Lu Baolu
2026-11-25  3:49   ` Tian, Kevin
2026-11-26  2:10     ` Baolu Lu
2026-12-02  4:57       ` Tian, Kevin
2026-11-12  4:30 ` [PATCH v3 6/9] iommu/vt-d: Refuse system suspend " Lu Baolu
2026-11-25  4:01   ` Tian, Kevin
2026-11-25  6:27     ` Baolu Lu
2026-11-12  4:30 ` [PATCH v3 7/9] coco/tdx-host: Add skeleton to support PCI link encryption Lu Baolu
2026-11-18  7:16   ` Chao Gao
2026-11-23  3:30     ` Baolu Lu [this message]
2026-11-23 15:26       ` Xu Yilun
2026-11-25  2:24         ` Baolu Lu
2026-11-19  2:52   ` Binbin Wu
2026-11-23  4:18     ` Baolu Lu
2026-11-23 15:43       ` Xu Yilun
2026-11-12  4:30 ` [PATCH v3 8/9] coco/tdx-host: Rename tdx-host.c to main.c Lu Baolu
2026-11-12  4:30 ` [PATCH v3 9/9] coco/tdx-host: Enable trusted DMA on IOMMUs on device connect Lu Baolu
2026-11-18  8:11   ` Chao Gao
2026-11-23  4:51     ` Baolu Lu
2026-11-27  9:57   ` Xu Yilun
2026-12-02  0:55     ` Baolu Lu

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=d9f3eecf-5655-4779-9e8a-b3ff4cbdb667@linux.intel.com \
    --to=baolu.lu@linux.intel.com \
    --cc=binbin.wu@linux.intel.com \
    --cc=chao.gao@intel.com \
    --cc=iommu@lists.linux.dev \
    --cc=jgg@ziepe.ca \
    --cc=kas@kernel.org \
    --cc=kevin.tian@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-coco@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rick.p.edgecombe@intel.com \
    --cc=x86@kernel.org \
    --cc=xiaoyao.li@intel.com \
    --cc=yilun.xu@linux.intel.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.