All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: alistair23@gmail.com
Cc: linux-cxl@vger.kernel.org, ojeda@kernel.org, linux-pci@vger.kernel.org
Subject: Re: [PATCH v3 11/21] PCI/TSM: Support connecting to PCIe CMA devices
Date: Tue, 01 Sep 2026 01:25:45 +0000	[thread overview]
Message-ID: <20260901012546.071881F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260901010347.2614656-12-alistair.francis@wdc.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

New issues:
- [High] Unconditional overwrite of `pdev->tsm` in `probe_fn()` causes memory leak and state corruption for independent sibling CMA hosts.
- [High] Expanding `is_pci_tsm_host()` to return true for dependent functions with CMA breaks DSM resolution, causing type confusion and preventing context cleanup.

Pre-existing issues:
- [High] AB-BA lock inversion between `pci_bus_sem` and `tsm_host->lock` in `__pci_tsm_disconnect` for upstream switch ports.
--

commit 1f366330a43aef4dbb8b7e338fe088b357fa13a0
Author: Alistair Francis <alistair.francis@wdc.com>

PCI/TSM: Support connecting to PCIe CMA devices

This patch adds support for connecting to PCIe CMA devices by modifying
is_pci_tsm_host() to allow CMA capable devices. It caches the CMA support
in struct pci_dev to avoid repeated mailbox lookups.

> diff --git a/drivers/pci/tsm.c b/drivers/pci/tsm.c
> index 10c9c6696624d..440f818ac5699 100644
> --- a/drivers/pci/tsm.c
> +++ b/drivers/pci/tsm.c

[ ... ]

> @@ -456,7 +475,7 @@ static void __pci_tsm_disconnect(struct pci_dev *pdev)
>  	 * teardown
>  	 */
>  	guard(mutex)(&tsm_host->lock);
> -	pci_tsm_walk_fns_reverse(pdev, remove_fn, NULL);
> +	pci_tsm_walk_fns_reverse(pdev, remove_fn, pdev);

[Severity: High]
This is a pre-existing issue, but does __pci_tsm_disconnect() create an
AB-BA lock inversion between pci_bus_sem and tsm_host->lock?

First, pci_tsm_unbind_all() calls pci_tsm_walk_fns_reverse(). For upstream
switch ports, this invokes pci_walk_bus_reverse(), acquiring pci_bus_sem
for read. Inside the walk, the callback __pci_tsm_unbind() acquires
tsm_host->lock, establishing a pci_bus_sem -> tsm_host->lock ordering.

Immediately after, __pci_tsm_disconnect() explicitly acquires tsm_host->lock
via guard(mutex), and then calls pci_tsm_walk_fns_reverse() (which invokes
pci_walk_bus_reverse()), attempting to acquire pci_bus_sem for read.

This reverses the acquisition order to tsm_host->lock -> pci_bus_sem, which
could lead to a deadlock when racing with bus modifications.

>  	ops->disconnect(pdev);
>  }

> diff --git a/include/linux/pci-tsm.h b/include/linux/pci-tsm.h
> index 950e2c36a4cae..f504fa6803157 100644
> --- a/include/linux/pci-tsm.h
> +++ b/include/linux/pci-tsm.h

[ ... ]

> @@ -142,6 +143,15 @@ static inline bool is_pci_tsm_host(struct pci_dev *pdev)
>  	if (pdev->is_virtfn)
>  		return false;
>  
> +	/*
> +	 * Report capable if CMA is supported, which can be supported on any PCIe
> +	 * device.
> +	 */
> +#ifdef CONFIG_PCI_DOE
> +	if (pdev->doe_cma)
> +		return true;
> +#endif
> +

[Severity: High]
Does expanding is_pci_tsm_host() to return true for dependent functions with
CMA introduce a memory leak and state corruption?

If userspace connects a dependent function (like PF1) as a CMA host first,
pci_tsm_connect() allocates PF1->tsm. If userspace subsequently connects a
TEE host (DSM) on the same device (e.g. PF0), pci_tsm_connect(PF0) walks
dependent functions and calls probe_fn(PF1, PF0).

In drivers/pci/tsm.c:probe_fn(), it unconditionally overwrites pdev->tsm:

	pdev->tsm = ops->probe(dsm_dev->tsm->tsm_dev, pdev);

Could this overwrite the existing CMA TSM context without checking or freeing
it, leaking the memory and corrupting the state?

[Severity: High]
Additionally, does returning true for dependent functions with CMA break
DSM resolution in find_dsm_dev()?

When the parent TEE DSM (PF0) calls probe_fn(PF1), the allocation path
calls find_dsm_dev(PF1). Since is_pci_tsm_host(PF1) now evaluates to true,
find_dsm_dev() incorrectly returns PF1 instead of the actual DSM (PF0).

This causes PF1 to self-identify as its own host, meaning
PF1->tsm->dsm_dev == PF1.

Later, when the parent DSM (PF0) is disconnected, remove_fn() has:

	if (!pdev->tsm || pdev->tsm->dsm_dev != host)
		return 0;

This will skip PF1 because its dsm_dev no longer matches the host, causing
the TEE context to leak. Furthermore, upon device removal,
__pci_tsm_destroy(PF1) would incorrectly treat PF1 as a host and execute the
host-only teardown path (pci_tsm_disconnect), causing type confusion.

>  	/*
>  	 * Allow for a Device Security Manager (DSM) associated with function0
>  	 * of an Endpoint to coordinate TDISP requests for other functions

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260901010347.2614656-1-alistair.francis@wdc.com?part=11

  reply	other threads:[~2026-09-01  1:25 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-01  1:03 [PATCH v3 00/21] lib: Rust implementation of SPDM alistair23
2026-09-01  1:03 ` [PATCH v3 01/21] rust: transmute: add `cast_slice[_mut]` functions alistair23
2026-09-01  1:11   ` sashiko-bot
2026-09-01  1:03 ` [PATCH v3 02/21] rust: create basic untrusted data API alistair23
2026-09-01  1:19   ` sashiko-bot
2026-09-01  1:03 ` [PATCH v3 03/21] rust: validate: add `Validate` trait alistair23
2026-09-01  1:16   ` sashiko-bot
2026-09-01  1:03 ` [PATCH v3 04/21] X.509: Make certificate parser public alistair23
2026-09-01  1:12   ` sashiko-bot
2026-09-01  1:03 ` [PATCH v3 05/21] X.509: Parse Subject Alternative Name in certificates alistair23
2026-09-01  1:12   ` sashiko-bot
2026-09-01  1:03 ` [PATCH v3 06/21] X.509: Move certificate length retrieval into new helper alistair23
2026-09-01  1:10   ` sashiko-bot
2026-09-01  1:03 ` [PATCH v3 07/21] rust: add bindings for hash.h alistair23
2026-09-01  1:10   ` sashiko-bot
2026-09-01  1:03 ` [PATCH v3 08/21] rust: error: impl From<FromBytesWithNulError> for Kernel Error alistair23
2026-09-01  1:10   ` sashiko-bot
2026-09-01  1:03 ` [PATCH v3 09/21] lib: rspdm: Initial commit of Rust SPDM alistair23
2026-09-01  1:17   ` sashiko-bot
2026-09-08 22:57   ` Jonathan Cameron
2026-09-01  1:03 ` [PATCH v3 10/21] PCI/TSM: Rename pf0 to host alistair23
2026-09-01  1:16   ` sashiko-bot
2026-09-08 23:01   ` Jonathan Cameron
2026-09-11  5:00     ` Alistair
2026-09-01  1:03 ` [PATCH v3 11/21] PCI/TSM: Support connecting to PCIe CMA devices alistair23
2026-09-01  1:25   ` sashiko-bot [this message]
2026-09-01  1:03 ` [PATCH v3 12/21] PCI/CMA: Add a PCI TSM CMA driver using SPDM alistair23
2026-09-01  1:20   ` sashiko-bot
2026-09-08 23:21   ` Jonathan Cameron
2026-09-01  1:03 ` [PATCH v3 13/21] PCI/CMA: Validate Subject Alternative Name in certificates alistair23
2026-09-01  1:15   ` sashiko-bot
2026-09-01  1:03 ` [PATCH v3 14/21] lib: rspdm: Support SPDM get_version alistair23
2026-09-01  1:17   ` sashiko-bot
2026-09-08 23:40   ` Jonathan Cameron
2026-09-01  1:03 ` [PATCH v3 15/21] lib: rspdm: Support SPDM get_capabilities alistair23
2026-09-01  1:15   ` sashiko-bot
2026-09-08 23:47   ` Jonathan Cameron
2026-09-01  1:03 ` [PATCH v3 16/21] lib: rspdm: Support SPDM negotiate_algorithms alistair23
2026-09-01  1:30   ` sashiko-bot
2026-09-04  5:01   ` Aksh Garg
2026-09-09  0:17   ` Jonathan Cameron
2026-09-11  4:53     ` Alistair
2026-09-01  1:03 ` [PATCH v3 17/21] lib: rspdm: Support SPDM get_digests alistair23
2026-09-01  1:20   ` sashiko-bot
2026-09-09  0:36     ` Jonathan Cameron
2026-09-09  0:31   ` Jonathan Cameron
2026-09-01  1:03 ` [PATCH v3 18/21] lib: rspdm: Support SPDM get_certificate alistair23
2026-09-01  1:21   ` sashiko-bot
2026-09-01  1:03 ` [PATCH v3 19/21] lib: rspdm: Support SPDM certificate validation alistair23
2026-09-01  1:22   ` sashiko-bot
2026-09-09  0:46   ` Jonathan Cameron
2026-09-01  1:03 ` [PATCH v3 20/21] rust: allow extracting the buffer from a CString alistair23
2026-09-01  1:19   ` sashiko-bot
2026-09-01  1:03 ` [PATCH v3 21/21] lib: rspdm: Support SPDM challenge alistair23
2026-09-01  1:31   ` sashiko-bot
2026-09-09  1:37   ` Jonathan Cameron
2026-09-11  3:46     ` Alistair

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=20260901012546.071881F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=alistair23@gmail.com \
    --cc=linux-cxl@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=ojeda@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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.