Linux PCI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Leon Romanovsky" <leon@kernel.org>
Cc: linux-input@vger.kernel.org, linux-usb@vger.kernel.org,
	linux-pci@vger.kernel.org, linux-sound@vger.kernel.org,
	dmitry.torokhov@gmail.com
Subject: Re: [PATCH v3 26/31] PCI: Use device trust for platform restrictions
Date: Thu, 19 Nov 2026 19:29:45 +0000	[thread overview]
Message-ID: <sashiko-outbox-223912@kernel.org> (raw)
In-Reply-To: <20261118-device-trust-core-v3-26-d655875c4bfb@nvidia.com>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] PCI: broken adversarial trust inheritance in
  pci_set_default_trust_policy()
- [High] PCI: explicit default trust policy on removable devices
  resolves unrestricted
- [Medium] PCI: of_create_pci_dev() runs pci_ats_init() before
  device_trust_init()
--

commit ab3df18f298528c15fefd9b9d8d3f08b809b920f
Author: Leon Romanovsky <leon@kernel.org>

PCI: Use device trust for platform restrictions

This commit derives default PCI device trust policies from removable topology
and gates PCI ATS initialization and ACS Translation Blocking on the device
trust policy.

[ ... ]

> diff --git a/drivers/pci/ats.c b/drivers/pci/ats.c
> index 9cb23780093dd..c8c96acc26343 100644
> --- a/drivers/pci/ats.c
> +++ b/drivers/pci/ats.c
> @@ -21,7 +21,7 @@ void pci_ats_init(struct pci_dev *dev)
>  {
>  	int pos;
>  
> -	if (pci_ats_disabled())
> +	if (pci_ats_disabled() || pci_dev_default_is_restricted(dev))
>  		return;
>  
>  	pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ATS);
> @@ -40,7 +40,7 @@ void pci_ats_init(struct pci_dev *dev)
>   */
>  bool pci_ats_supported(struct pci_dev *dev)
>  {
> -	if (!dev->ats_cap || dev->untrusted)
> +	if (!dev->ats_cap)
>  		return false;

[Severity: Medium]
On PowerPC and SPARC, does pci_ats_init() run before dev->dev.trust_policy is
initialized when a PCI device is created via of_create_pci_dev()?

of_create_pci_dev() bypasses pci_setup_device() and calls pci_device_add()
directly, which runs pci_init_capabilities() -> pci_ats_init() and
pci_acs_init() before device_add() invokes device_trust_init().  Because
dev->dev.trust_policy is still DEVICE_TRUST_POLICY_DEFAULT at that point,
pci_dev_default_is_restricted() returns false, leaving dev->ats_cap populated
(and PCI_ACS_TB unset) even when boot trust parameters restrict the device.

[ ... ]

> diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
> index 9a178e0e5f7f4..9aa69d19ceab4 100644
> --- a/drivers/pci/probe.c
> +++ b/drivers/pci/probe.c
> @@ -1738,24 +1738,21 @@ static void set_pcie_cxl(struct pci_dev *dev)
>  
>  }
>  
> -static void set_pcie_untrusted(struct pci_dev *dev)
> +static void pci_set_default_trust_policy(struct pci_dev *dev)
>  {
>  	struct pci_dev *parent = pci_upstream_bridge(dev);
>  
>  	if (!parent)
>  		return;
> -	/*
> -	 * If the upstream bridge is untrusted we treat this device as
> -	 * untrusted as well.
> -	 */
> -	if (parent->untrusted) {
> -		dev->untrusted = true;
> +
> +	if (device_policy_is_adversarial(&parent->dev)) {
> +		dev->dev.trust_policy = DEVICE_TRUST_POLICY_ADVERSARY;
>  		return;
>  	}
>  
>  	if (arch_pci_dev_is_removable(dev)) {
> -		pci_dbg(dev, "marking as untrusted\n");
> -		dev->untrusted = true;
> +		pci_dbg(dev, "setting adversarial trust policy\n");
> +		dev->dev.trust_policy = DEVICE_TRUST_POLICY_ADVERSARY;
>  	}
>  }
>  
> @@ -2082,7 +2079,9 @@ int pci_setup_device(struct pci_dev *dev)
>  
>  	set_pcie_cxl(dev);
>  
> -	set_pcie_untrusted(dev);
> +	pci_set_default_trust_policy(dev);
> +	dev->untrusted = device_policy_is_adversarial(&dev->dev);
> +	device_trust_init(&dev->dev);

[Severity: High]
Does calling device_trust_init(&parent->dev) before enumerating child buses
prevent downstream devices from inheriting DEVICE_TRUST_POLICY_ADVERSARY and
dev->untrusted?

During top-down enumeration, pci_setup_device(parent) sets the removable
bridge's trust_policy to DEVICE_TRUST_POLICY_ADVERSARY and then immediately
calls device_trust_init(&parent->dev).  When device trust is active at boot
(for example with bare device_trust, where the default policy is blocked),
device_trust_init() overwrites parent->dev.trust_policy to
DEVICE_TRUST_POLICY_BLOCKED before child buses are scanned.

When pci_set_default_trust_policy() later runs on child devices,
device_policy_is_adversarial(&parent->dev) is false, and on x86
arch_pci_dev_is_removable() returns true only for the external switch
upstream port directly under an integrated USB4/Thunderbolt root port:

arch/x86/pci/acpi.c:arch_pci_dev_is_removable() {
	...
	/* Anything directly behind a "usb4-host-interface" is tunneled */
	if (pcie_has_usb4_host_interface(parent))
		return true;
	...
	if (pcie_switch_directly_under(root, pdev))
		return false;
	...
}

As a result, downstream switch ports and endpoints behind an external PCIe
switch stay at DEVICE_TRUST_POLICY_DEFAULT with dev->untrusted = false,
losing IOMMU DMA isolation, ATS disablement, and ACS Translation Blocking.

[ ... ]

> diff --git a/include/linux/pci.h b/include/linux/pci.h
> index aa3765a20a96c..d8edf8403a5ad 100644
> --- a/include/linux/pci.h
> +++ b/include/linux/pci.h
> @@ -616,6 +616,16 @@ static inline struct pci_dev *to_pci_dev(const struct device *dev)
>  {
>  	return container_of(dev, struct pci_dev, dev);
>  }
> +
> +static inline bool
> +pci_dev_default_is_restricted(const struct pci_dev *pdev)
> +{
> +	enum device_trust_policy policy = READ_ONCE(pdev->dev.trust_policy);
> +
> +	return policy == DEVICE_TRUST_POLICY_BLOCKED ||
> +	       policy == DEVICE_TRUST_POLICY_ADVERSARY;
> +}

[Severity: High]
Does setting an explicit "default" policy on a removable PCI device cause it
to be treated as unrestricted instead of adversarial?

pci_set_default_trust_policy() records a removable device's bus default by
writing DEVICE_TRUST_POLICY_ADVERSARY into dev->dev.trust_policy.  If a boot
rule such as device_trust=pci:<bdf>=default (or writing "default" to sysfs
trust_policy) matches the device, it overwrites dev->dev.trust_policy with
DEVICE_TRUST_POLICY_DEFAULT.

Because pci_dev_default_is_restricted() returns false for
DEVICE_TRUST_POLICY_DEFAULT and pci_bus_type does not implement
trust_resolve(), ATS is allowed, PCI_ACS_TB is skipped, and
__device_trust_prepare() resolves the removable device to
DEVICE_TRUST_UNRESTRICTED rather than DEVICE_TRUST_ADVERSARY.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261118-device-trust-core-v3-0-d655875c4bfb@nvidia.com?part=26

  reply	other threads:[~2026-11-19 19:29 UTC|newest]

Thread overview: 66+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18 19:26 [PATCH v3 00/31] driver core: Authorize device trust before driver binding Leon Romanovsky
2026-11-18 19:26 ` [PATCH v3 01/31] wifi: mac80211_hwsim: lock device for manual " Leon Romanovsky
2026-11-19 19:29   ` sashiko-bot
2026-11-18 19:26 ` [PATCH v3 02/31] Bluetooth: btusb: Fix MediaTek ISO claim locking Leon Romanovsky
2026-11-19 19:29   ` sashiko-bot
2026-11-18 19:26 ` [PATCH v3 03/31] USB: Lock interfaces during manual driver binding Leon Romanovsky
2026-11-19 19:29   ` sashiko-bot
2026-11-18 19:26 ` [PATCH v3 04/31] USB: serial: Register USB drivers with their owning module Leon Romanovsky
2026-11-19 19:29   ` sashiko-bot
2026-11-18 19:26 ` [PATCH v3 05/31] USB: Reject claims of DT-disabled interfaces Leon Romanovsky
2026-11-19 19:29   ` sashiko-bot
2026-11-18 19:26 ` [PATCH v3 06/31] USB: Release interface claims according to binding state Leon Romanovsky
2026-11-19 19:29   ` sashiko-bot
2026-11-18 19:26 ` [PATCH v3 07/31] USB: Reject claims after interface registration failure Leon Romanovsky
2026-11-19 19:29   ` sashiko-bot
2026-11-18 19:26 ` [PATCH v3 08/31] ALSA: usb-audio: Release interface claims when probe fails Leon Romanovsky
2026-11-19 19:29   ` sashiko-bot
2026-11-18 19:26 ` [PATCH v3 09/31] USB: Pin modules for unregistered interface claims Leon Romanovsky
2026-11-19 19:29   ` sashiko-bot
2026-11-18 19:26 ` [PATCH v3 10/31] USB: Add helpers to release unpublished " Leon Romanovsky
2026-11-19 19:29   ` sashiko-bot
2026-11-18 19:26 ` [PATCH v3 11/31] USB: Unwind interface claims after registration or binding failure Leon Romanovsky
2026-11-19 19:29   ` sashiko-bot
2026-11-18 19:26 ` [PATCH v3 12/31] PNP: Attach card devices through the driver core Leon Romanovsky
2026-11-19 19:29   ` sashiko-bot
2026-11-18 19:26 ` [PATCH v3 13/31] cdx: Propagate DMA configuration errors Leon Romanovsky
2026-11-19 19:29   ` sashiko-bot
2026-11-18 19:26 ` [PATCH v3 14/31] driver core: Report deferred probes through sysfs drivers_probe Leon Romanovsky
2026-11-19 19:29   ` sashiko-bot
2026-11-18 19:26 ` [PATCH v3 15/31] driver core: Add a compatibility API for manual driver attachment Leon Romanovsky
2026-11-19 19:29   ` sashiko-bot
2026-11-18 19:26 ` [PATCH v3 16/31] Input: gameport - use the compatibility driver attachment API Leon Romanovsky
2026-11-19 19:29   ` sashiko-bot
2026-11-18 19:26 ` [PATCH v3 17/31] Input: serio " Leon Romanovsky
2026-11-19 19:29   ` sashiko-bot
2026-11-18 19:26 ` [PATCH v3 18/31] net: phy: Use " Leon Romanovsky
2026-11-18 20:21   ` Andrew Lunn
2026-11-19  7:18     ` Leon Romanovsky
2026-11-19 13:30       ` Andrew Lunn
2026-11-19 19:29   ` sashiko-bot
2026-11-18 19:26 ` [PATCH v3 19/31] driver core: Introduce a generic device trust level Leon Romanovsky
2026-11-19 19:29   ` sashiko-bot
2026-11-18 19:26 ` [PATCH v3 20/31] driver core: Expose device trust authorization interfaces Leon Romanovsky
2026-11-19 19:29   ` sashiko-bot
2026-11-18 19:26 ` [PATCH v3 21/31] driver core: Accept device trust policy on the kernel command line Leon Romanovsky
2026-11-19 19:29   ` sashiko-bot
2026-11-18 19:26 ` [PATCH v3 22/31] driver core: Accept device trust policy by driver name Leon Romanovsky
2026-11-19 19:29   ` sashiko-bot
2026-11-18 19:26 ` [PATCH v3 23/31] driver core: Expose committed device trust level Leon Romanovsky
2026-11-19 19:29   ` sashiko-bot
2026-11-18 19:26 ` [PATCH v3 24/31] driver core: Cover trust authorization and binding with KUnit Leon Romanovsky
2026-11-19 19:29   ` sashiko-bot
2026-11-18 19:26 ` [PATCH v3 25/31] driver core: Document trust admission and initrd authorization Leon Romanovsky
2026-11-19 19:29   ` sashiko-bot
2026-11-18 19:26 ` [PATCH v3 26/31] PCI: Use device trust for platform restrictions Leon Romanovsky
2026-11-19 19:29   ` sashiko-bot [this message]
2026-11-18 19:26 ` [PATCH v3 27/31] iommu: Use device trust for DMA restrictions Leon Romanovsky
2026-11-19 19:29   ` sashiko-bot
2026-11-18 19:26 ` [PATCH v3 28/31] driver core: Allow driver attachment with the device lock held Leon Romanovsky
2026-11-19 19:29   ` sashiko-bot
2026-11-18 19:26 ` [PATCH v3 29/31] USB: Retain the result of configuration requests Leon Romanovsky
2026-11-19 19:29   ` sashiko-bot
2026-11-18 19:27 ` [PATCH v3 30/31] USB: Authorize interfaces through device trust Leon Romanovsky
2026-11-19 19:29   ` sashiko-bot
2026-11-18 19:27 ` [PATCH v3 31/31] USB: Authorize devices " Leon Romanovsky
2026-11-19 19:29   ` sashiko-bot

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=sashiko-outbox-223912@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=leon@kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=linux-usb@vger.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox