From: sashiko-bot@kernel.org
To: "Chengwen Feng" <fengchengwen@huawei.com>
Cc: kvm@vger.kernel.org, linux-pci@vger.kernel.org
Subject: Re: [PATCH v21 11/13] vfio/pci: Add DS-ST TPH policy and TPH_RESOLVE capability
Date: Wed, 18 Nov 2026 11:43:27 +0000 [thread overview]
Message-ID: <sashiko-outbox-220836@kernel.org> (raw)
In-Reply-To: <20261118091238.45992-12-fengchengwen@huawei.com>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] vfio/pci: vfio_pci_core_feature_tph_resolve() fails when
!has_arch_st
- [Medium] vfio/pci: vfio_tph_config_write() drops ST mode and active
req updates
- [Medium] vfio/pci: vfio_pci_tph_get_capability() skips
pcie_tph_dsm_supported()
--
commit 5b864ef3e267f2d34a7496c96455a9bee2cc860b
Author: Chengwen Feng <fengchengwen@huawei.com>
vfio/pci: Add DS-ST TPH policy and TPH_RESOLVE capability
This commit adds the DS-ST policy level to vfio-pci and introduces the
VFIO_DEVICE_FEATURE_TPH_RESOLVE ioctl feature for resolving CPU steering
tags on DS-ST capable devices.
> diff --git a/drivers/vfio/pci/vfio_pci_config.c b/drivers/vfio/pci/vfio_pci_config.c
> index 398f8db8b8ff0..8e47f84216b0d 100644
> --- a/drivers/vfio/pci/vfio_pci_config.c
> +++ b/drivers/vfio/pci/vfio_pci_config.c
> @@ -1218,7 +1218,7 @@ static int vfio_tph_config_write(struct vfio_pci_core_device *vdev, int pos,
> cap = vdev->tph_vcap;
> mode = FIELD_GET(PCI_TPH_CTRL_MODE_SEL_MASK, new_ctrl);
> req = FIELD_GET(PCI_TPH_CTRL_REQ_EN_MASK, new_ctrl);
> - if (mode > PCI_TPH_ST_IV_MODE || !(cap & (1u << mode)) ||
> + if (mode > PCI_TPH_ST_DS_MODE || !(cap & (1u << mode)) ||
> req == 0x2 /* reserved */ ||
> (req == PCI_TPH_REQ_EXT_TPH && !(cap & PCI_TPH_CAP_EXT_TPH)))
> goto out; /* Drop invalid or unsupported write value. */
[Severity: Medium]
Can vfio_tph_config_write() drop or overwrite ST Mode Select updates?
Right below this check, vfio_tph_config_write() still skips hardware
updates whenever req == org_req:
drivers/vfio/pci/vfio_pci_config.c:vfio_tph_config_write() {
...
vfio_user_config_read(pdev, start + PCI_TPH_CTRL, &ctrl_val, 4);
vfio_default_config_write(vdev, start + PCI_TPH_CTRL, 4, perm,
PCI_TPH_CTRL, ctrl_val);
...
org_req = FIELD_GET(PCI_TPH_CTRL_REQ_EN_MASK, org_ctrl);
if (req == org_req)
goto out; /* Only care about requester enable. */
if (req == PCI_TPH_REQ_TPH_ONLY || req == PCI_TPH_REQ_EXT_TPH)
pcie_enable_tph_ext(pdev, mode, req);
else if (req == PCI_TPH_REQ_DISABLE)
pcie_disable_tph(vdev->pdev);
...
}
If userspace writes PCI_TPH_ST_DS_MODE while the requester is disabled
(req == org_req == PCI_TPH_REQ_DISABLE) before enabling it in a second
write, the first write is not committed to hardware and the second write
clobbers vconfig[start + PCI_TPH_CTRL] from hardware (where mode is still
0), enabling the device in NO-ST mode.
Similarly, changing mode while TPH is already enabled is ignored because
req == org_req, disabling the requester via pcie_disable_tph() zeroes the
entire hardware PCI_TPH_CTRL register including ST Mode Select, and
switching req between PCI_TPH_REQ_TPH_ONLY and PCI_TPH_REQ_EXT_TPH while
enabled fails in pcie_enable_tph_ext() with -EBUSY because pdev->tph_enabled
is already set.
> diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c
> index 23ed8ea396575..049392831b35f 100644
> --- a/drivers/vfio/pci/vfio_pci_core.c
> +++ b/drivers/vfio/pci/vfio_pci_core.c
> @@ -1710,12 +1710,17 @@ static void vfio_pci_tph_dev_deinit(struct vfio_pci_core_device *vdev)
> static u32 vfio_pci_tph_get_capability(struct vfio_pci_core_device *vdev)
> {
> bool has_arch_st;
> + u32 cap = 0;
>
> has_arch_st = vfio_pci_tph_has_architected_st(vdev);
> - if (!has_arch_st)
> - return 0;
> + if (has_arch_st)
> + cap |= VFIO_DEVICE_TPH_CAP_PROG_ST_NONE |
> + VFIO_DEVICE_TPH_CAP_PROG_ST_CPU;
>
> - return VFIO_DEVICE_TPH_CAP_PROG_ST_NONE | VFIO_DEVICE_TPH_CAP_PROG_ST_CPU;
> + if (vdev->tph_vcap & PCI_TPH_CAP_ST_DS)
> + cap |= VFIO_DEVICE_TPH_CAP_RESOLVE_CPU_ST;
> +
> + return cap;
> }
[Severity: Medium]
Should vfio_pci_tph_get_capability() check pcie_tph_dsm_supported(vdev->pdev)
before advertising VFIO_DEVICE_TPH_CAP_PROG_ST_CPU and
VFIO_DEVICE_TPH_CAP_RESOLVE_CPU_ST?
Commit "PCI/TPH: Add pci_tph_dsm_supported() helper to detect device TPH
ST _DSM" earlier in this series added pcie_tph_dsm_supported() to check
whether the root port exposes the ACPI TPH _DSM method, but nothing calls
it. On systems without CONFIG_ACPI or without that _DSM on the root port,
VFIO_DEVICE_FEATURE_TPH GET advertises CPU steering tag support that will
always fail when invoked.
> @@ -1901,6 +1906,50 @@ static int vfio_pci_core_feature_tph_program(struct vfio_pci_core_device *vdev,
> return ret;
> }
>
> +static int vfio_pci_core_feature_tph_resolve(struct vfio_pci_core_device *vdev,
> + u32 flags,
> + struct vfio_device_feature_tph_resolve __user *arg,
> + size_t argsz)
> +{
> + struct vfio_device_feature_tph_resolve resolve;
> + u32 user_flags, src_mask;
> + bool extended;
> + u16 tag = 0;
> + int ret;
> +
> + if (!vdev->tph_opt_in || !(vdev->tph_vcap & PCI_TPH_CAP_ST_DS))
> + return -EOPNOTSUPP;
> +
> + ret = vfio_check_feature(flags, argsz, VFIO_DEVICE_FEATURE_GET,
> + sizeof(resolve));
> + if (ret != 1)
> + return ret;
> +
> + if (copy_from_user(&resolve, arg, sizeof(resolve)))
> + return -EFAULT;
> +
> + user_flags = resolve.flags;
> + extended = !!(user_flags & VFIO_DEVICE_TPH_EXTENDED);
> + if (extended && !pcie_ext_tph_supported(vdev->pdev))
> + return -EOPNOTSUPP;
> + user_flags &= ~VFIO_DEVICE_TPH_EXTENDED;
> +
> + src_mask = vfio_pci_tph_get_src_mask(vdev) & ~VFIO_DEVICE_TPH_SRC_NONE;
> + if (user_flags & ~src_mask || !is_power_of_2(user_flags))
> + return -EINVAL;
[Severity: High]
Does vfio_pci_core_feature_tph_resolve() always fail with -EINVAL on DS-ST
devices that do not also have an architected ST table?
vfio_pci_tph_get_src_mask() only checks VFIO_DEVICE_TPH_CAP_PROG_ST_CPU,
which is gated on vfio_pci_tph_has_architected_st(vdev), and ignores
VFIO_DEVICE_TPH_CAP_RESOLVE_CPU_ST:
drivers/vfio/pci/vfio_pci_core.c:vfio_pci_tph_get_src_mask() {
u32 flags = vfio_pci_tph_get_capability(vdev);
u32 src_mask = 0;
if (flags & VFIO_DEVICE_TPH_CAP_PROG_ST_NONE)
src_mask |= VFIO_DEVICE_TPH_SRC_NONE;
if (flags & VFIO_DEVICE_TPH_CAP_PROG_ST_CPU)
src_mask |= VFIO_DEVICE_TPH_SRC_CPU_VOLATILE |
VFIO_DEVICE_TPH_SRC_CPU_PERSISTENT;
return src_mask;
}
When a DS-ST device has PCI_TPH_LOC_NONE (storing steering tags in
device-specific MMIO or firmware rather than an architected ST table),
vfio_pci_tph_get_src_mask() returns 0, so src_mask is 0 and every
VFIO_DEVICE_FEATURE_TPH_RESOLVE call is rejected with -EINVAL.
Checking (flags & (VFIO_DEVICE_TPH_CAP_PROG_ST_CPU |
VFIO_DEVICE_TPH_CAP_RESOLVE_CPU_ST)) in vfio_pci_tph_get_src_mask() would
allow CPU source resolution when only VFIO_DEVICE_TPH_CAP_RESOLVE_CPU_ST
is supported.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261118091238.45992-1-fengchengwen@huawei.com?part=11
next prev parent reply other threads:[~2026-11-18 11:43 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 9:12 [PATCH v21 00/13] vfio/pci: Add PCIe TPH support Chengwen Feng
2026-11-18 9:12 ` [PATCH v21 01/13] PCI/TPH: Fix pcie_tph_get_st_table_loc() field extraction Chengwen Feng
2026-11-18 9:29 ` sashiko-bot
2026-11-18 9:12 ` [PATCH v21 02/13] PCI/TPH: Fix tph_enabled concurrent update race by bitfield packing Chengwen Feng
2026-11-18 9:38 ` sashiko-bot
2026-11-18 9:12 ` [PATCH v21 03/13] PCI/TPH: Cache negotiated max requester type at probe time Chengwen Feng
2026-11-18 9:12 ` [PATCH v21 04/13] PCI/TPH: Refactor pcie_enable_tph and add requester variant Chengwen Feng
2026-11-18 9:12 ` [PATCH v21 05/13] PCI/TPH: Refactor pcie_tph_get_cpu_st & " Chengwen Feng
2026-11-18 9:12 ` [PATCH v21 06/13] PCI/TPH: Add macros to check standard and extended TPH support Chengwen Feng
2026-11-18 10:06 ` sashiko-bot
2026-11-18 9:12 ` [PATCH v21 07/13] PCI/TPH: Add pcie_tph_set_st_entries() batch ST entry programming helper Chengwen Feng
2026-11-18 10:15 ` sashiko-bot
2026-11-18 9:12 ` [PATCH v21 08/13] PCI/TPH: Add pci_tph_dsm_supported() helper to detect device TPH ST _DSM Chengwen Feng
2026-11-18 10:29 ` sashiko-bot
2026-11-18 9:12 ` [PATCH v21 09/13] vfio/pci: Add basic NO-ST TPH VFIO device feature support Chengwen Feng
2026-11-18 10:51 ` sashiko-bot
2026-11-18 9:12 ` [PATCH v21 10/13] vfio/pci: Add IV-ST TPH policy and TPH_PROGRAM batch programming support Chengwen Feng
2026-11-18 11:21 ` sashiko-bot
2026-11-18 9:12 ` [PATCH v21 11/13] vfio/pci: Add DS-ST TPH policy and TPH_RESOLVE capability Chengwen Feng
2026-11-18 11:43 ` sashiko-bot [this message]
2026-11-18 9:12 ` [PATCH v21 12/13] vfio/pci: Reset PCIe TPH state on device open and close Chengwen Feng
2026-11-18 9:12 ` [PATCH v21 13/13] vfio/pci: Expose per-device TPH state via debugfs Chengwen Feng
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=sashiko-outbox-220836@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