Linux PCI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Chengwen Feng" <fengchengwen@huawei.com>
Cc: linux-pci@vger.kernel.org
Subject: Re: [PATCH v7 2/6] PCI/TPH: Export pcie_tph_get_st_modes() for external use
Date: Thu, 07 May 2026 22:19:02 +0000	[thread overview]
Message-ID: <20260507221903.77885C2BCF7@smtp.kernel.org> (raw)
In-Reply-To: <20260507130956.34441-3-fengchengwen@huawei.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] The `pcie_tph_get_st_modes()` and `pcie_tph_get_st_table_loc()` functions ignore the return value of `pci_read_config_dword()`, leading to fabricated capabilities being exposed to userspace.
- [Low] The commit message incorrectly refers to the configuration option as `!CONFIG_PCI_TPH` instead of `!CONFIG_PCIE_TPH`.
--

commit 4a10965994892856e6b789d0c75e23d0e2e09be7
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 and expose device capabilities to userspace. It also adds stub
functions and tph_cap validation to prevent invalid configuration access.

> Add stub functions for pcie_tph_get_st_table_size() and
> pcie_tph_get_st_table_loc() when !CONFIG_PCI_TPH.

This isn't a bug, but there is a typo in the configuration option name.
The actual kernel configuration option for PCIe TLP Processing Hints is
CONFIG_PCIE_TPH rather than CONFIG_PCI_TPH.

> 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
[ ... ]
> -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, &reg);

Should we check the return value of pci_read_config_dword() here?

If the device is disconnected or unresponsive, pci_read_config_dword()
returns an error and populates the variable with the standard PCI error
response 0xFFFFFFFF.

When the mask (PCI_TPH_CAP_ST_NS | PCI_TPH_CAP_ST_IV | PCI_TPH_CAP_ST_DS)
is applied to 0xFFFFFFFF, it results in 7. This falsely indicates that all
Steering Tag modes are supported.

Since this function is now exported for external subsystems like VFIO, does
this risk exposing fabricated hardware capabilities to userspace when a
device becomes unresponsive?

>  	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);
[ ... ]
>  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, &reg);

Similarly, does this need error checking for the config read?

Applying the PCI_TPH_CAP_LOC_MASK (3 << 9) to 0xFFFFFFFF results in 0x600,
which is an invalid, undefined location enum.

>  
>  	return reg & PCI_TPH_CAP_LOC_MASK;
>  }

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260507130956.34441-1-fengchengwen@huawei.com?part=2

  reply	other threads:[~2026-05-07 22:19 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-07 13:09 [PATCH v7 0/6] vfio/pci: Add PCIe TPH support Chengwen Feng
2026-05-07 13:09 ` [PATCH v7 1/6] PCI/TPH: Fix pcie_tph_get_st_table_loc() field extraction Chengwen Feng
2026-05-07 13:09 ` [PATCH v7 2/6] PCI/TPH: Export pcie_tph_get_st_modes() for external use Chengwen Feng
2026-05-07 22:19   ` sashiko-bot [this message]
2026-05-07 13:09 ` [PATCH v7 3/6] vfio/pci: Add PCIe TPH interface with capability query Chengwen Feng
2026-05-07 23:20   ` sashiko-bot
2026-05-07 13:09 ` [PATCH v7 4/6] vfio/pci: Add PCIe TPH enable/disable support Chengwen Feng
2026-05-07 23:49   ` sashiko-bot
2026-05-07 13:09 ` [PATCH v7 5/6] vfio/pci: Add PCIe TPH GET_ST interface Chengwen Feng
2026-05-08  0:18   ` sashiko-bot
2026-05-07 13:09 ` [PATCH v7 6/6] vfio/pci: Add PCIe TPH SET_ST interface Chengwen Feng
2026-05-08  0:52   ` 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=20260507221903.77885C2BCF7@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