From: sashiko-bot@kernel.org
To: "Chengwen Feng" <fengchengwen@huawei.com>
Cc: linux-pci@vger.kernel.org
Subject: Re: [PATCH v6 2/6] PCI/TPH: Export pcie_tph_get_st_modes() for external use
Date: Wed, 06 May 2026 12:39:07 +0000 [thread overview]
Message-ID: <20260506123907.E2928C2BCB8@smtp.kernel.org> (raw)
In-Reply-To: <20260506094623.29327-3-fengchengwen@huawei.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] Missing error handling for pci_read_config_dword() in the newly exported pcie_tph_get_st_modes() leads to falsely reporting all TPH modes as supported when a device is disconnected.
- [Low] The !CONFIG_PCI_TPH stub for pcie_tph_get_st_table_loc() returns an inconsistent out-of-bounds value (0x7FF) instead of PCI_TPH_LOC_NONE.
--
commit d23fc69219a490dd1458be7c3d6f50ae929f70cd
Author: Chengwen Feng <fengchengwen@huawei.com>
PCI/TPH: Export pcie_tph_get_st_modes() for external use
This commit exports the pcie_tph_get_st_modes() helper so drivers like VFIO
can query supported PCIe TPH steering tag modes. It also adds stub functions
for when !CONFIG_PCI_TPH and tph_cap validation.
> diff --git a/drivers/pci/tph.c b/drivers/pci/tph.c
> index f17b74b5fb1e3..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)
> -static u8 get_st_modes(struct pci_dev *pdev)
> +/**
> + * pcie_tph_get_st_modes - Get supported Steering Tag modes
> + * @pdev: PCI device to query
> + *
> + * Return:
> + * Bitmask of supported ST modes (PCI_TPH_CAP_ST_NS, PCI_TPH_CAP_ST_IV,
> + * PCI_TPH_CAP_ST_DS)
> + */
> +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, ®);
If pci_read_config_dword() fails (e.g., when a device is disconnected), it
populates the output variable with an error response (~0 or 0xFFFFFFFF).
Since the return value is ignored here, will this masking operation:
> reg &= PCI_TPH_CAP_ST_NS | PCI_TPH_CAP_ST_IV | PCI_TPH_CAP_ST_DS;
evaluate to 0x07 and incorrectly report all three Steering Tag modes as
supported during a device disconnection?
>
> return reg;
> }
> +EXPORT_SYMBOL(pcie_tph_get_st_modes);
[ ... ]
> diff --git a/include/linux/pci-tph.h b/include/linux/pci-tph.h
> index be68cd17f2f83..586c75b19e019 100644
> --- a/include/linux/pci-tph.h
> +++ b/include/linux/pci-tph.h
[ ... ]
> @@ -41,6 +42,12 @@ static inline int pcie_tph_get_cpu_st(struct pci_dev *dev,
> static inline void pcie_disable_tph(struct pci_dev *pdev) { }
> static inline int pcie_enable_tph(struct pci_dev *pdev, int mode)
> { return -EINVAL; }
> +static inline u16 pcie_tph_get_st_table_size(struct pci_dev *pdev)
> +{ return 0; }
> +static inline u32 pcie_tph_get_st_table_loc(struct pci_dev *pdev)
> +{ return 0x7FF; /* Values that do not appear in normal case */ }
When TPH is enabled but a device lacks TPH capabilities, the live function
safely returns PCI_TPH_LOC_NONE.
Does returning 0x7FF in this stub introduce an inconsistency in the API that
forces callers to handle arbitrary magic numbers instead of relying on
PCI_TPH_LOC_NONE?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260506094623.29327-1-fengchengwen@huawei.com?part=2
next prev parent reply other threads:[~2026-05-06 12:39 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-06 9:46 [PATCH v6 0/6] vfio/pci: Add PCIe TPH support Chengwen Feng
2026-05-06 9:46 ` [PATCH v6 1/6] PCI/TPH: Fix pcie_tph_get_st_table_loc() field extraction Chengwen Feng
2026-05-06 15:54 ` Bjorn Helgaas
2026-05-06 9:46 ` [PATCH v6 2/6] PCI/TPH: Export pcie_tph_get_st_modes() for external use Chengwen Feng
2026-05-06 12:39 ` sashiko-bot [this message]
2026-05-06 9:46 ` [PATCH v6 3/6] vfio/pci: Add PCIe TPH interface with capability query Chengwen Feng
2026-05-06 18:48 ` sashiko-bot
2026-05-06 9:46 ` [PATCH v6 4/6] vfio/pci: Add PCIe TPH enable/disable support Chengwen Feng
2026-05-06 19:21 ` sashiko-bot
2026-05-06 9:46 ` [PATCH v6 5/6] vfio/pci: Add PCIe TPH GET_ST interface Chengwen Feng
2026-05-06 19:57 ` sashiko-bot
2026-05-06 9:46 ` [PATCH v6 6/6] vfio/pci: Add PCIe TPH SET_ST interface Chengwen Feng
2026-05-06 20:22 ` 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=20260506123907.E2928C2BCB8@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=fengchengwen@huawei.com \
--cc=linux-pci@vger.kernel.org \
--cc=sashiko@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