Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Chengwen Feng" <fengchengwen@huawei.com>
Cc: kvm@vger.kernel.org, linux-pci@vger.kernel.org
Subject: Re: [PATCH RESEND v18 04/12] PCI/TPH: Refactor pcie_enable_tph & add explicit requester variant
Date: Tue, 23 Jun 2026 09:04:48 +0000	[thread overview]
Message-ID: <20260623090449.AAA661F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260623085048.51139-5-fengchengwen@huawei.com>

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

Pre-existing issues:
- [High] Concurrent execution of `pcie_tph_set_st_entry` can violate the PCIe spec and corrupt hardware state by modifying the ST table while TPH is globally enabled.
--

commit e3b30f139c34eadf8039e394826ffa947655fe86
Author: Chengwen Feng <fengchengwen@huawei.com>

PCI/TPH: Refactor pcie_enable_tph & add explicit requester variant

This commit refactors the pcie_enable_tph implementation by extracting the
core logic into a static internal enable_tph helper that accepts an explicit
requester type. It preserves the original pcie_enable_tph behavior as an
auto-detecting wrapper and adds a new pcie_enable_tph_explicit function
for explicit standard or extended TPH selection.

> diff --git a/drivers/pci/tph.c b/drivers/pci/tph.c
> index 4097787ea98a1..c22eb7f4b0bd7 100644
> --- a/drivers/pci/tph.c
> +++ b/drivers/pci/tph.c

[ ... ]

> @@ -400,10 +384,11 @@ int pcie_enable_tph(struct pci_dev *pdev, int mode)
>  	if (!((1 << mode) & dev_modes))
>  		return -EINVAL;
>  
> -	pdev->tph_mode = mode;
> +	if (req_type == PCI_TPH_REQ_EXT_TPH && !pdev->tph_ext_support)
> +		return -EINVAL;
>  
> -	pdev->tph_req_type = pdev->tph_ext_support ? PCI_TPH_REQ_EXT_TPH :
> -						     PCI_TPH_REQ_TPH_ONLY;
> +	pdev->tph_mode = mode;
> +	pdev->tph_req_type = req_type;
>  
>  	/* Write them into TPH control register */
>  	pci_read_config_dword(pdev, pdev->tph_cap + PCI_TPH_CTRL, &reg);

[Severity: High]
This is a pre-existing issue, but does the TPH subsystem lack necessary
locking around the TPH Control Register and ST table updates?

If multiple MSI-X vectors' SMP affinities are updated simultaneously by a
user or irqbalance, concurrent calls to pcie_tph_set_st_entry could happen.
Since pcie_tph_set_st_entry temporarily disables TPH system-wide:

pcie_tph_set_st_entry()
    set_ctrl_reg_req_en(pdev, PCI_TPH_REQ_DISABLE);
    ... 
    loc = pcie_tph_get_st_table_loc(pdev);
    ... write to ST table ...
    ...
    set_ctrl_reg_req_en(pdev, pdev->tph_req_type);

Would CPU2 re-enable TPH while CPU1 is still writing to the ST table,
violating the PCIe r6.2 sec 6.17.3 specification which cautions against
updating the ST table while TPH is enabled?

Additionally, set_ctrl_reg_req_en performs an unprotected read-modify-write:

set_ctrl_reg_req_en()
    pci_read_config_dword(pdev, pdev->tph_cap + PCI_TPH_CTRL, &reg);
    FIELD_MODIFY(PCI_TPH_CTRL_REQ_EN_MASK, &reg, req_type);
    pci_write_config_dword(pdev, pdev->tph_cap + PCI_TPH_CTRL, reg);

Could concurrent IRQ notifiers cause a data race here, corrupting the TPH
control register state?

>  	FIELD_MODIFY(PCI_TPH_CTRL_MODE_SEL_MASK, &reg, pdev->tph_mode);
>  	FIELD_MODIFY(PCI_TPH_CTRL_REQ_EN_MASK, &reg, pdev->tph_req_type);
>  
>  	pci_write_config_dword(pdev, pdev->tph_cap + PCI_TPH_CTRL, reg);
>

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

  reply	other threads:[~2026-06-23  9:04 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-23  8:50 [PATCH RESEND v18 00/12] vfio/pci: Add PCIe TPH support Chengwen Feng
2026-06-23  8:50 ` [PATCH RESEND v18 01/12] PCI/TPH: Fix pcie_tph_get_st_table_loc() field extraction Chengwen Feng
2026-06-23  8:59   ` sashiko-bot
2026-06-23  8:50 ` [PATCH RESEND v18 02/12] PCI/TPH: Fix tph_enabled concurrent update race by bitfield packing Chengwen Feng
2026-06-23  9:00   ` sashiko-bot
2026-06-23  8:50 ` [PATCH RESEND v18 03/12] PCI/TPH: Cache TPH requester capability at probe time Chengwen Feng
2026-06-23  9:00   ` sashiko-bot
2026-06-23  8:50 ` [PATCH RESEND v18 04/12] PCI/TPH: Refactor pcie_enable_tph & add explicit requester variant Chengwen Feng
2026-06-23  9:04   ` sashiko-bot [this message]
2026-06-23  8:50 ` [PATCH RESEND v18 05/12] PCI/TPH: Refactor pcie_tph_get_cpu_st & add explicit variant Chengwen Feng
2026-06-23  9:02   ` sashiko-bot
2026-06-23  8:50 ` [PATCH RESEND v18 06/12] PCI/TPH: Expose the enabled TPH requester type Chengwen Feng
2026-06-23  8:57   ` sashiko-bot
2026-06-23  8:50 ` [PATCH RESEND v18 07/12] PCI/TPH: Add pcie_tph_supported() helper to check TPH capability attributes Chengwen Feng
2026-06-23  9:07   ` sashiko-bot
2026-06-23  8:50 ` [PATCH RESEND v18 08/12] PCI/TPH: Add sysfs binary file to export CPU to steering-tag mapping Chengwen Feng
2026-06-23  9:02   ` sashiko-bot
2026-06-23  8:50 ` [PATCH RESEND v18 09/12] vfio/pci: Hide TPH capability when TPH is unsupported Chengwen Feng
2026-06-23  9:07   ` sashiko-bot
2026-06-23  8:50 ` [PATCH RESEND v18 10/12] vfio/pci: Add TPH_ENABLE feature skeleton and unsafe module parameter Chengwen Feng
2026-06-23  9:03   ` sashiko-bot
2026-06-23  8:50 ` [PATCH RESEND v18 11/12] vfio/pci: Add TPH_ST_CONFIG for PCIe TPH ST configuration Chengwen Feng
2026-06-23  9:11   ` sashiko-bot
2026-06-23  8:50 ` [PATCH RESEND v18 12/12] vfio/pci: Virtualize PCIe TPH capability registers Chengwen Feng
2026-06-23  9:13   ` 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=20260623090449.AAA661F000E9@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