Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Chengwen Feng" <fengchengwen@huawei.com>
Cc: linux-pci@vger.kernel.org, kvm@vger.kernel.org
Subject: Re: [PATCH v20 01/16] PCI/TPH: Add requester/completer type helpers
Date: Tue, 14 Jul 2026 10:54:08 +0000	[thread overview]
Message-ID: <20260714105409.50D741F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260714104325.54444-2-fengchengwen@huawei.com>

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

Pre-existing issues:
- [High] The internal get_rp_completer_type() function fails to fold the reserved 0b10 encoding into NONE, which can lead to writing a reserved value to the device's TPH Control Register and causes pcie_tph_enabled_req_type() to return an undocumented reserved value.
--

--- Patch [1]: [PATCH v20 01/16] PCI/TPH: Add requester/completer type helpers ---
commit f0ced626715c0e05a18f4a1a24c4e5840b72c4a0
Author: Zhiping Zhang <zhipingz@meta.com>

    PCI/TPH: Add requester/completer type helpers
    
    Add pcie_tph_enabled_req_type() so drivers can query the enabled TPH
    requester mode without reaching into pci_dev internals.
    
    Add pcie_tph_completer_type() so drivers that publish TPH metadata for
    a device acting as a completer can gate on the "TPH Completer
    Supported" field of Device Capabilities 2 (bits 13:12,
    PCI_EXP_DEVCAP2_TPH_COMP_MASK) rather than reusing requester-side
    state. Fold the reserved 0b10 encoding into NONE so callers only see
    the defined values.

> diff --git a/drivers/pci/tph.c b/drivers/pci/tph.c
> index 655ffd60e62f6..e7693fd9d6763 100644
> --- a/drivers/pci/tph.c
> +++ b/drivers/pci/tph.c
> @@ -173,6 +173,51 @@ u32 pcie_tph_get_st_table_loc(struct pci_dev *pdev)
>  }
>  EXPORT_SYMBOL(pcie_tph_get_st_table_loc);
>  
> +/**
> + * pcie_tph_enabled_req_type - Return the device's enabled TPH requester type
> + * @pdev: PCI device to query
> + *
> + * Return: PCI_TPH_REQ_DISABLE, PCI_TPH_REQ_TPH_ONLY or PCI_TPH_REQ_EXT_TPH.
> + */
> +u8 pcie_tph_enabled_req_type(struct pci_dev *pdev)
> +{
> +	return pdev->tph_req_type;
> +}
> +EXPORT_SYMBOL(pcie_tph_enabled_req_type);

[Severity: High]
This is a pre-existing issue, but does pdev->tph_req_type correctly avoid
returning the reserved 0b10 encoding?

While pcie_tph_completer_type() added in this patch explicitly folds the
reserved 0b10 encoding into NONE, the pre-existing internal
get_rp_completer_type() function in drivers/pci/tph.c directly returns
the field value without folding the reserved state:

drivers/pci/tph.c:get_rp_completer_type() {
    ...
    return FIELD_GET(PCI_EXP_DEVCAP2_TPH_COMP_MASK, reg);
}

If a Root Port returns the reserved value 2 (0b10), pcie_enable_tph() handles
it like this:

drivers/pci/tph.c:pcie_enable_tph() {
    ...
    if (pci_pcie_type(pdev) != PCI_EXP_TYPE_RC_END) {
        rp_req_type = get_rp_completer_type(pdev);

        /* Final req_type is the smallest value of two */
        pdev->tph_req_type = min(pdev->tph_req_type, rp_req_type);
    }
    ...
    FIELD_MODIFY(PCI_TPH_CTRL_REQ_EN_MASK, &reg, pdev->tph_req_type);
}

If the endpoint supports PCI_TPH_REQ_EXT_TPH (3), pdev->tph_req_type becomes
min(3, 2) = 2.

This bypassed value 2 is then written directly to the endpoint's TPH Requester
Enable field, which violates the PCIe specification and could cause undefined
hardware behavior. Furthermore, it causes this new pcie_tph_enabled_req_type()
function to leak this undocumented reserved value to external callers, which
contradicts the function documentation.

Should get_rp_completer_type() be updated to handle the reserved 0b10 encoding
in the same way as pcie_tph_completer_type()?

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

  reply	other threads:[~2026-07-14 10:54 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-14 10:43 [PATCH v20 00/16] vfio/pci: Add PCIe TPH support Chengwen Feng
2026-07-14 10:43 ` [PATCH v20 01/16] PCI/TPH: Add requester/completer type helpers Chengwen Feng
2026-07-14 10:54   ` sashiko-bot [this message]
2026-07-14 10:43 ` [PATCH v20 02/16] dma-buf: add optional get_pci_tph() callback Chengwen Feng
2026-07-14 10:50   ` sashiko-bot
2026-07-14 10:43 ` [PATCH v20 03/16] vfio/pci: implement get_pci_tph and DMA_BUF_TPH feature Chengwen Feng
2026-07-14 10:50   ` sashiko-bot
2026-07-14 10:43 ` [PATCH v20 04/16] PCI/TPH: Fix pcie_tph_get_st_table_loc() field extraction Chengwen Feng
2026-07-14 10:54   ` sashiko-bot
2026-07-14 10:43 ` [PATCH v20 05/16] PCI/TPH: Fix tph_enabled concurrent update race by bitfield packing Chengwen Feng
2026-07-14 11:00   ` sashiko-bot
2026-07-14 10:43 ` [PATCH v20 06/16] PCI/TPH: Cache negotiated max requester type at probe time Chengwen Feng
2026-07-14 10:57   ` sashiko-bot
2026-07-14 10:43 ` [PATCH v20 07/16] PCI/TPH: Refactor pcie_enable_tph and add requester variant Chengwen Feng
2026-07-14 10:58   ` sashiko-bot
2026-07-14 10:43 ` [PATCH v20 08/16] PCI/TPH: Refactor pcie_tph_get_cpu_st & " Chengwen Feng
2026-07-14 11:00   ` sashiko-bot
2026-07-14 10:43 ` [PATCH v20 09/16] PCI/TPH: Add macros to check standard and extended TPH support Chengwen Feng
2026-07-14 11:07   ` sashiko-bot
2026-07-14 10:43 ` [PATCH v20 10/16] PCI/TPH: Add pcie_tph_set_st_entries() batch ST entry programming helper Chengwen Feng
2026-07-14 11:11   ` sashiko-bot
2026-07-14 10:43 ` [PATCH v20 11/16] PCI/TPH: Add pci_tph_dsm_supported() helper to detect device TPH ST _DSM Chengwen Feng
2026-07-14 11:27   ` sashiko-bot
2026-07-14 10:43 ` [PATCH v20 12/16] vfio/pci: Add basic NO-ST TPH VFIO device feature support Chengwen Feng
2026-07-14 11:10   ` sashiko-bot
2026-07-14 10:43 ` [PATCH v20 13/16] vfio/pci: Add IV-ST TPH policy and VFIO TPH_ST batch programming support Chengwen Feng
2026-07-14 11:14   ` sashiko-bot
2026-07-14 10:43 ` [PATCH v20 14/16] vfio/pci: Add DS-ST TPH policy and extend TPH_RESOLVE capabilities Chengwen Feng
2026-07-14 11:12   ` sashiko-bot
2026-07-14 10:43 ` [PATCH v20 15/16] vfio/pci: Sync core PCI TPH software state across device lifecycle and resets Chengwen Feng
2026-07-14 11:28   ` sashiko-bot
2026-07-14 10:43 ` [PATCH v20 16/16] vfio/pci: Expose per-device TPH state via debugfs Chengwen Feng
2026-07-14 11:17   ` 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=20260714105409.50D741F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=fengchengwen@huawei.com \
    --cc=kvm@vger.kernel.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox