From: sashiko-bot@kernel.org
To: "Chengwen Feng" <fengchengwen@huawei.com>
Cc: linux-pci@vger.kernel.org
Subject: Re: [PATCH v11 2/5] PCI/TPH: Export pcie_tph_get_st_modes() for external use
Date: Mon, 18 May 2026 07:57:31 +0000 [thread overview]
Message-ID: <20260518075731.EAAFFC2BCC6@smtp.kernel.org> (raw)
In-Reply-To: <20260518071701.25177-3-fengchengwen@huawei.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Unchecked return value of pci_read_config_dword() leads to reporting false capabilities and bypassing safety checks on disconnected devices.
--
commit 7d284f4750da4fed3caa1876a0ac6b5f46c96ad9
Author: Chengwen Feng <fengchengwen@huawei.com>
PCI/TPH: Export pcie_tph_get_st_modes() for external use
Export the helper to retrieve supported PCIe TPH steering tag modes so that
drivers like VFIO can query and expose device capabilities to userspace.
Add stub functions for when CONFIG_PCIE_TPH is disabled, and add validation
to prevent invalid configuration space access.
> diff --git a/drivers/pci/tph.c b/drivers/pci/tph.c
> index 877cf556242b4..ba31b010f67ad 100644
> --- a/drivers/pci/tph.c
> +++ b/drivers/pci/tph.c
[ ... ]
> @@ -145,15 +145,27 @@ static void set_ctrl_reg_req_en(struct pci_dev *pdev, u8 req_type)
[ ... ]
> +u8 pcie_tph_get_st_modes(struct pci_dev *pdev)
> {
> u32 reg;
>
> + if (!pdev->tph_cap)
> + return 0;
> +
> pci_read_config_dword(pdev, pdev->tph_cap + PCI_TPH_CAP, ®);
> reg &= PCI_TPH_CAP_ST_NS | PCI_TPH_CAP_ST_IV | PCI_TPH_CAP_ST_DS;
>
> return reg;
> }
> +EXPORT_SYMBOL(pcie_tph_get_st_modes);
Is it possible for pci_read_config_dword() to fail here?
If the device is disconnected or the read fails, reg could be set to
0xFFFFFFFF (PCI_ERROR_RESPONSE). It might also be left uninitialized if the
host controller fails the read without updating the variable.
Because the return value of pci_read_config_dword() is not checked, a value
of 0xFFFFFFFF in reg would cause this function to return 0x7 after masking.
With this function now being exported to external drivers like VFIO, could
this result in falsely exposing all ST modes as supported to userspace
instead of returning 0 on failure?
> @@ -168,6 +180,9 @@ u32 pcie_tph_get_st_table_loc(struct pci_dev *pdev)
> {
> u32 reg;
>
> + if (!pdev->tph_cap)
> + return PCI_TPH_LOC_NONE;
> +
> pci_read_config_dword(pdev, pdev->tph_cap + PCI_TPH_CAP, ®);
>
> return reg & PCI_TPH_CAP_LOC_MASK;
> }
Similarly, if pci_read_config_dword() fails here and sets reg to 0xFFFFFFFF,
this will return PCI_TPH_CAP_LOC_MASK (a reserved location) rather than
PCI_TPH_LOC_NONE.
Could this incorrect return value bypass safety checks that expect
PCI_TPH_LOC_NONE for invalid devices, or cause pcie_enable_tph() to
improperly enable TPH when hardware access has failed?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260518071701.25177-1-fengchengwen@huawei.com?part=2
next prev parent reply other threads:[~2026-05-18 7:57 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-18 7:16 [PATCH v11 0/5] vfio/pci: Add PCIe TPH support Chengwen Feng
2026-05-18 7:16 ` [PATCH v11 1/5] PCI/TPH: Fix pcie_tph_get_st_table_loc() field extraction Chengwen Feng
2026-05-18 7:16 ` [PATCH v11 2/5] PCI/TPH: Export pcie_tph_get_st_modes() for external use Chengwen Feng
2026-05-18 7:57 ` sashiko-bot [this message]
2026-05-22 4:10 ` Alex Williamson
2026-05-18 7:16 ` [PATCH v11 3/5] PCI/TPH: Add pcie_tph_enabled_mode() helper Chengwen Feng
2026-05-18 8:14 ` sashiko-bot
2026-05-22 4:10 ` Alex Williamson
2026-05-22 9:18 ` fengchengwen
2026-05-22 14:00 ` Alex Williamson
2026-05-18 7:17 ` [PATCH v11 4/5] vfio/pci: Add PCIe TPH configuration space virtualization Chengwen Feng
2026-05-18 8:48 ` sashiko-bot
2026-05-22 4:10 ` Alex Williamson
2026-05-22 9:39 ` fengchengwen
2026-05-22 14:09 ` Alex Williamson
2026-05-18 7:17 ` [PATCH v11 5/5] vfio/pci: Add VFIO_DEVICE_FEATURE_TPH_ST for TPH ST entry management Chengwen Feng
2026-05-18 9:22 ` sashiko-bot
2026-05-22 4:10 ` Alex Williamson
2026-05-22 10:04 ` fengchengwen
2026-05-22 14:27 ` Alex Williamson
2026-05-26 6:29 ` fengchengwen
2026-05-22 1:31 ` [PATCH v11 0/5] vfio/pci: Add PCIe TPH support fengchengwen
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=20260518075731.EAAFFC2BCC6@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=fengchengwen@huawei.com \
--cc=linux-pci@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 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.