From: fengchengwen <fengchengwen@huawei.com>
To: <alex@shazbot.org>
Cc: <wathsala.vithanage@arm.com>, <wei.huang2@amd.com>,
<zhipingz@meta.com>, <wangzhou1@hisilicon.com>,
<wangyushan12@huawei.com>, <liuyonglong@huawei.com>,
<kvm@vger.kernel.org>, <linux-pci@vger.kernel.org>,
<jgg@ziepe.ca>, <helgaas@kernel.org>
Subject: Re: [PATCH v22 00/13] vfio/pci: Add PCIe TPH support
Date: Mon, 23 Nov 2026 10:52:52 +0800 [thread overview]
Message-ID: <62dc52aa-eccb-4604-a0e1-5748a47c29c7@huawei.com> (raw)
In-Reply-To: <20261123023628.7728-1-fengchengwen@huawei.com>
Hi Alex,
This v22 adapts the VFIO feature enum numbers to match the latest linux-next
and addresses Sashiko review comments on v21.
I previously invited Wathsala (ARM) and Wei Huang (AMD) to review the series,
particularly the TPH uAPI ownership and CPU offline lifecycle model. They are
copied here for this v22 update.
I'd appreciate your review when you have bandwidth.
Thanks,
Chengwen
On 11/23/2026 10:36 AM, Chengwen Feng wrote:
> This patchset enables userspace-configurable PCIe TPH support for VFIO in
> the **device-to-host (D2H)** scenario, bringing performance benefits for
> userspace workloads such as DPDK and SPDK.
>
> The patchset is split into two logical parts:
> 1. The first eight patches fix and refactor core PCI/TPH kernel code to
> export the required helper interfaces.
> 2. The second five patches implement the corresponding VFIO TPH
> virtualization and uAPI step by step.
>
>
> Since TLP TPH ST values are not validated by the IOMMU like TLP address
> fields, there exists risk of cross-tenant cache interference if untrusted
> VM can program arbitrary ST tags. We introduce two-level security
> gating:
>
> The first is the VFIO-PCI module parameter tph_policy, defined as:
> Global TPH policy level (0 = default No-ST):
> 0 = No-ST mode: ST programming unavailable
> 1 = Add IV-ST mode: ST programming supports NONE / CPU sources
> 2 = Add DS-ST mode: RESOLVE returns ST for CPU sources;
> ST programming supports NONE / CPU sources
> Note: In this 'Add DS-ST mode', device-specific ST tables are not
> preserved across PCI resets, userspace must re-establish ST
> state after reset. The kernel cannot validate these ST
> entries, so this mode is not recommended for general
> virtualization usecases.
>
> Note: IV-ST mode is considered safe for VM use because the ST table is
> programmed exclusively via the kernel VFIO uAPI. VM cannot directly
> write the architected ST table in MSI-X or config space. The hypervisor
> (e.g. QEMU) will verify ST, and also when a target CPU transitions from
> online to offline, the kernel automatically (add in this patchset) clears
> all ST table entries mapped to that CPU, setting those ST values to zero.
>
> The second gate is per-device opt-in. TPH programming is only permitted
> after userspace successfully opt-in via the VFIO TPH feature.
>
>
> Three VFIO device features are introduced in this series:
> 1. VFIO_DEVICE_FEATURE_TPH: control and query VFIO TPH feature
> capabilities.
> 2. VFIO_DEVICE_FEATURE_TPH_PROGRAM: batch program architected steering tag
> table entries.
> 3. VFIO_DEVICE_FEATURE_TPH_RESOLVE: resolve TPH attributes for a given CPU
> source.
>
> The intended userspace programming model is:
> 1. Read the virtualized PCI TPH capability via VFIO config space access to
> discover underlying hardware TPH support.
> 2. Invoke VFIO_DEVICE_FEATURE_TPH SET to opt-in and obtain TPH permission.
> 3. Invoke VFIO_DEVICE_FEATURE_TPH GET to retrieve available TPH
> capabilities; GET returns an error if opt-in has not been performed.
> 4. Write the TPH control register through VFIO config space to activate
> hardware TPH.
> 5. Program architected ST table entries via
> VFIO_DEVICE_FEATURE_TPH_PROGRAM if the device exposes architected ST
> table.
> 6. Query the ST value for a given CPU ID via
> VFIO_DEVICE_FEATURE_TPH_RESOLVE for DS-ST capable devices, userspace
> may then configure the ST through device MMIO or firmware interfaces.
>
>
> Key implementation details for capability virtualization:
> 1. The TPH capability register is virtualized according to the active
> tph_policy:
> a. No-ST policy: IV/DS mode bits, ST location and ST size fields are
> masked. Only NO-ST capability is visible to userspace.
> b. IV-ST policy: DS mode bits are masked. Userspace sees NO-ST and
> IV-ST capabilities (if hardware supports IV-ST).
> c. DS-ST policy: capability register is passed through unmodified.
> 2. Capability bits returned by VFIO_DEVICE_FEATURE_TPH GET follow these
> rules:
> a. If virtualized TPH exposes architected ST table:
> VFIO_DEVICE_TPH_CAP_PROG_ST_NONE and VFIO_DEVICE_TPH_CAP_PROG_ST_CPU
> are reported. These indicate userspace may use TPH_PROGRAM to update
> ST.
> b. If virtualized TPH supports DS mode:
> VFIO_DEVICE_TPH_CAP_RESOLVE_CPU_ST is reported. This indicates
> userspace can resolve CPU-ID associated ST values via TPH_RESOLVE.
>
>
> Future P2P / DMABUF extension:
> The uAPI is designed to easy extend to support device-to-device (P2P) and
> DMABUF-backed scenarios on top of Zhiping's P2P TPH patchset:
> 1. Return VFIO_DEVICE_TPH_CAP_RESOLVE_DMABUF_PH in all tph_policy in
> VFIO_DEVICE_FEATURE_TPH GET, so that userspace could resolve DMABUF's
> TPH PH info
> 2. Return VFIO_DEVICE_TPH_CAP_PROG_ST_DMABUF if virtualized TPH has the
> architect ST, so that userspace could program ST entries which
> associated to DMABUFs' fd
> 3. Return VFIO_DEVICE_TPH_CAP_RESOLVE_DMABUF_ST if virtualized TPH
> supports DS mode, so that userspace could retrieve ST value which
> associated to DMABUF's fd
>
> ---
> v22:
> - Rebase latest linux-next to resolve uAPI conflict
> - Reorder patch sequence: move core tph disable fixes ahead of vfio patches
> - Fix Sashiko comments:
> - Fix TPH config write path: disable existing TPH before re-enable to
> keep state coherent
> - Fix cpuhp race/UAF: reorder TPH teardown before cpuhp removal
> - Add cpu_online() check in ST resolve routine
> - Gate IV/DS capability exposure on TPH _DSM presence; hide IV/DS when
> DSM unavailable
> - Fix kernel-doc and redundant check in pcie_tph_dsm_supported() helper
> v21:
> - Focus only device-to-host (D2H) scenario
> - Implement steering-tag to cpuid map to tracking cpu offline
> - Refactor the implementation
> v20:
> - Address almost all comments from Alex about v19, not within Alex's
> scope:
> - Drop LITERAL policy support
> - uAPI changes: cap have been split into fine-grained
> - TPH config access: still based on perm mechanism, but restrict the
> readable and writable length
> - Debugfs add more fields
> v19:
> - Address all comments from Alex
> - Drop CPU-to-ST translation of PCI/TPH
> - Re-implement vfio part, please refer:
> https://lore.kernel.org/linux-pci/20260626092232.53ed3a7c@shazbot.org/
> - Add expose tph_policy via debugfs
>
> Chengwen Feng (13):
> PCI/TPH: Fix pcie_tph_get_st_table_loc() field extraction
> PCI/TPH: Fix tph_enabled concurrent update race by bitfield packing
> PCI/TPH: Cache negotiated max requester type at probe time
> PCI/TPH: Refactor pcie_enable_tph and add requester variant
> PCI/TPH: Refactor pcie_tph_get_cpu_st & add requester variant
> PCI/TPH: Add helpers to check standard and extended TPH support
> PCI/TPH: Add pcie_tph_set_st_entries() batch ST entry programming
> helper
> PCI/TPH: Add pcie_tph_dsm_supported() helper to detect device TPH ST
> _DSM
> vfio/pci: Reset PCIe TPH state on device open and close
> vfio/pci: Add basic NO-ST TPH VFIO device feature support
> vfio/pci: Add IV-ST TPH policy and TPH_PROGRAM batch programming
> support
> vfio/pci: Add DS-ST TPH policy and TPH_RESOLVE capability
> vfio/pci: Expose per-device TPH state via debugfs
>
> drivers/pci/tph.c | 240 ++++++++++++-----
> drivers/vfio/pci/vfio_pci.c | 24 ++
> drivers/vfio/pci/vfio_pci_config.c | 188 +++++++++++--
> drivers/vfio/pci/vfio_pci_core.c | 412 ++++++++++++++++++++++++++++-
> drivers/vfio/pci/vfio_pci_priv.h | 6 +
> include/linux/pci-tph.h | 55 +++-
> include/linux/pci.h | 6 +-
> include/linux/vfio_pci_core.h | 7 +
> include/uapi/linux/vfio.h | 129 +++++++++
> 9 files changed, 967 insertions(+), 100 deletions(-)
>
next prev parent reply other threads:[~2026-11-23 2:53 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 2:36 [PATCH v22 00/13] vfio/pci: Add PCIe TPH support Chengwen Feng
2026-11-23 2:36 ` [PATCH v22 01/13] PCI/TPH: Fix pcie_tph_get_st_table_loc() field extraction Chengwen Feng
2026-11-23 2:36 ` [PATCH v22 02/13] PCI/TPH: Fix tph_enabled concurrent update race by bitfield packing Chengwen Feng
2026-11-23 2:36 ` [PATCH v22 03/13] PCI/TPH: Cache negotiated max requester type at probe time Chengwen Feng
2026-11-23 2:36 ` [PATCH v22 04/13] PCI/TPH: Refactor pcie_enable_tph and add requester variant Chengwen Feng
2026-11-23 2:36 ` [PATCH v22 05/13] PCI/TPH: Refactor pcie_tph_get_cpu_st & " Chengwen Feng
2026-11-23 2:36 ` [PATCH v22 06/13] PCI/TPH: Add helpers to check standard and extended TPH support Chengwen Feng
2026-11-23 2:47 ` sashiko-bot
2026-11-23 2:36 ` [PATCH v22 07/13] PCI/TPH: Add pcie_tph_set_st_entries() batch ST entry programming helper Chengwen Feng
2026-11-23 2:48 ` sashiko-bot
2026-11-23 2:36 ` [PATCH v22 08/13] PCI/TPH: Add pcie_tph_dsm_supported() helper to detect device TPH ST _DSM Chengwen Feng
2026-11-23 2:36 ` [PATCH v22 09/13] vfio/pci: Reset PCIe TPH state on device open and close Chengwen Feng
2026-11-23 2:36 ` [PATCH v22 10/13] vfio/pci: Add basic NO-ST TPH VFIO device feature support Chengwen Feng
2026-11-23 2:36 ` [PATCH v22 11/13] vfio/pci: Add IV-ST TPH policy and TPH_PROGRAM batch programming support Chengwen Feng
2026-11-23 2:58 ` sashiko-bot
2026-11-23 2:36 ` [PATCH v22 12/13] vfio/pci: Add DS-ST TPH policy and TPH_RESOLVE capability Chengwen Feng
2026-11-23 2:50 ` sashiko-bot
2026-11-23 2:36 ` [PATCH v22 13/13] vfio/pci: Expose per-device TPH state via debugfs Chengwen Feng
2026-11-23 2:52 ` fengchengwen [this message]
2026-11-23 2:58 ` [PATCH v22 00/13] vfio/pci: Add PCIe TPH support 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=62dc52aa-eccb-4604-a0e1-5748a47c29c7@huawei.com \
--to=fengchengwen@huawei.com \
--cc=alex@shazbot.org \
--cc=helgaas@kernel.org \
--cc=jgg@ziepe.ca \
--cc=kvm@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=liuyonglong@huawei.com \
--cc=wangyushan12@huawei.com \
--cc=wangzhou1@hisilicon.com \
--cc=wathsala.vithanage@arm.com \
--cc=wei.huang2@amd.com \
--cc=zhipingz@meta.com \
/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