From: sashiko-bot@kernel.org
To: "Chengwen Feng" <fengchengwen@huawei.com>
Cc: kvm@vger.kernel.org, linux-pci@vger.kernel.org
Subject: Re: [PATCH v12 6/6] vfio/pci: Add PCIe TPH control register virtualization
Date: Tue, 26 May 2026 06:56:51 +0000 [thread overview]
Message-ID: <20260526065651.9B13D1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260526040830.52854-7-fengchengwen@huawei.com>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] The TPH configuration write handler silently drops valid byte-level writes, blocks ST Table config-space writes, and bypasses virtual configuration space updates.
- [High] TPH state is lost and becomes unrecoverable after a device reset due to missing state synchronization.
- [High] `vfio_pci_tph_config_write` performs MMIO accesses without holding `vdev->memory_lock`, racing with concurrent device resets.
--
commit e0337d4fe2416ad1997b3bae043a087facf49ef3
Author: Chengwen Feng <fengchengwen@huawei.com>
vfio/pci: Add PCIe TPH control register virtualization
Implement virtualized handling for PCIe TPH capability control register
writes. Validate and mediate user write requests to accept only valid TPH
mode configurations. Synchronize shadow steering tag table to hardware when
TPH gets enabled successfully.
> diff --git a/drivers/vfio/pci/vfio_pci_config.c b/drivers/vfio/pci/vfio_pci_config.c
> index a10ed733f0e3a..188845f81626d 100644
> --- a/drivers/vfio/pci/vfio_pci_config.c
> +++ b/drivers/vfio/pci/vfio_pci_config.c
[ ... ]
> @@ -313,6 +317,39 @@ static int vfio_virt_config_read(struct vfio_pci_core_device *vdev, int pos,
> return count;
> }
>
> +static int vfio_pci_tph_config_write(struct vfio_pci_core_device *vdev, int pos,
> + int count, struct perm_bits *perm,
> + int offset, __le32 val)
> +{
> + struct pci_dev *pdev = vdev->pdev;
> + u32 data = le32_to_cpu(val);
> + u8 mode, req_en;
> + int i, ret;
> +
> + if (!enable_unsafe_tph)
> + return count;
> +
> + if (offset != PCI_TPH_CTRL || count < 2)
> + return count;
[Severity: High]
Does this silently drop valid 1-byte writes to the control register, or
writes to the upper bytes of the register (e.g. offset 0x09)? This might
break guests that perform byte-wise accesses.
Also, could this drop guest writes to the ST Table if it resides in the
capability space (offset >= 0x0C)?
Additionally, since this function returns without ever updating
vdev->vconfig via vfio_default_config_write() or similar, does this bypass
virtual configuration space updates entirely?
> +
> + guard(mutex)(&vdev->tph_lock);
> +
> + mode = FIELD_GET(PCI_TPH_CTRL_MODE_SEL_MASK, data);
> + req_en = FIELD_GET(PCI_TPH_CTRL_REQ_EN_MASK, data);
> + if (req_en) {
> + ret = pcie_enable_tph(pdev, mode);
[Severity: High]
If pcie_enable_tph() succeeds, it updates the hardware register and sets
pdev->tph_enabled = 1. However, since pci_save_state() is not called here,
if a device reset occurs (e.g. via VFIO_DEVICE_RESET), the PCI core
restores the stale saved state where TPH is disabled, clearing the hardware
register.
Since pdev->tph_enabled remains 1 in software, wouldn't subsequent attempts
by the guest to re-enable TPH cause pcie_enable_tph() to immediately return
-EBUSY, permanently blocking the guest from using TPH after a reset?
> + if (ret == 0 && vdev->tph_st_shadow) {
> + for (i = 0; i < vdev->tph_st_entries; i++)
> + pcie_tph_set_st_entry(pdev, i,
> + vdev->tph_st_shadow[i]);
[Severity: High]
If the hardware ST table resides in the MSI-X table, pcie_tph_set_st_entry()
may perform MMIO writes. Since this is executed holding only
vdev->tph_lock, could this race with a concurrent device reset (which
acquires down_write(&vdev->memory_lock) to block MMIO accesses and disables
memory decode)?
Without holding down_read(&vdev->memory_lock) here, could these MMIO writes
interleave with the physical reset or occur while memory decode is disabled,
causing Master Aborts?
> + }
> + } else {
> + pcie_disable_tph(vdev->pdev);
> + }
> +
> + return count;
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260526040830.52854-1-fengchengwen@huawei.com?part=6
prev parent reply other threads:[~2026-05-26 6:56 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-26 4:08 [PATCH v12 0/6] vfio/pci: Add PCIe TPH support Chengwen Feng
2026-05-26 4:08 ` [PATCH v12 1/6] PCI/TPH: Fix pcie_tph_get_st_table_loc() field extraction Chengwen Feng
2026-05-26 4:31 ` sashiko-bot
2026-05-26 4:08 ` [PATCH v12 2/6] PCI/TPH: Export pcie_tph_get_st_modes() for external use Chengwen Feng
2026-05-26 4:51 ` sashiko-bot
2026-05-26 4:08 ` [PATCH v12 3/6] PCI/TPH: Add pcie_tph_enabled_mode() helper Chengwen Feng
2026-05-26 4:08 ` [PATCH v12 4/6] PCI/TPH: Move tph_req_type initialization into pci_tph_init Chengwen Feng
2026-05-26 5:35 ` sashiko-bot
2026-05-26 22:42 ` Alex Williamson
2026-05-26 4:08 ` [PATCH v12 5/6] vfio/pci: Add VFIO_DEVICE_FEATURE_TPH_ST for PCIe TPH steering tag management Chengwen Feng
2026-05-26 6:09 ` sashiko-bot
2026-05-26 22:42 ` Alex Williamson
2026-05-27 9:54 ` fengchengwen
2026-05-26 4:08 ` [PATCH v12 6/6] vfio/pci: Add PCIe TPH control register virtualization Chengwen Feng
2026-05-26 6:56 ` sashiko-bot [this message]
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=20260526065651.9B13D1F000E9@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