From: fengchengwen <fengchengwen@huawei.com>
To: Alex Williamson <alex@shazbot.org>
Cc: <jgg@ziepe.ca>, <helgaas@kernel.org>,
<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>
Subject: Re: [PATCH v19 15/18] vfio/pci: Implement TPH_RESOLVE feature for DMABUF and CPU source resolving
Date: Thu, 9 Jul 2026 20:20:38 +0800 [thread overview]
Message-ID: <dad40817-9c87-494c-86b2-e0e2b75e60e7@huawei.com> (raw)
In-Reply-To: <20260708173106.21d26a9a@shazbot.org>
On 7/9/2026 7:31 AM, Alex Williamson wrote:
> On Thu, 2 Jul 2026 20:42:21 +0800
> Chengwen Feng <fengchengwen@huawei.com> wrote:
>
>> Add vfio_pci_core_feature_tph_resolve() to implement the
>> VFIO_DEVICE_FEATURE_TPH_RESOLVE GET-only uAPI.
>>
>> Resolve PH/ST values from two supported sources:
>> - DMABUF fd: retrieve stored TPH metadata via dmabuf helper
>> - CPU ID: fetch ST tag from platform via PCIe TPH core helper
>>
>> Gate supported source types dynamically according to the tph_policy level:
>> No-ST/IV modes only permit DMABUF resolution, while DS+ modes additionally
>> allow CPU volatile/persistent sources.
>
> RESOLVE is not an oracle, it's not only the sources that can be
> resolved, but whether the user has a means to use the value. RESOLVE
> should not return a LITERAL unless the device supports DS mode or
> supports IV mode AND we're in POLICY_LITERAL. Thanks,
Got it. My current RESOLVE logic only filters allowed sources by policy,
but does not check whether the device can actually use the resolved ST.
I will fix it: ST will only be reported when the hardware supports IV/DS
ST table capability, even under LITERAL policy.
Thanks
>
> Alex
>
>
>> Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
>> ---
>> drivers/vfio/pci/vfio_pci_core.c | 75 ++++++++++++++++++++++++++++++++
>> 1 file changed, 75 insertions(+)
>>
>> diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c
>> index 14944d3ea86e..ed6bbffa8b26 100644
>> --- a/drivers/vfio/pci/vfio_pci_core.c
>> +++ b/drivers/vfio/pci/vfio_pci_core.c
>> @@ -1641,6 +1641,78 @@ static int vfio_pci_core_feature_tph(struct vfio_pci_core_device *vdev,
>> return copy_to_user(arg, &tph, sizeof(tph)) ? -EFAULT : 0;
>> }
>>
>> +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)
>> +{
>> + const u32 permit_src_mask[] = {
>> + [VFIO_PCI_TPH_POLICY_NO_ST] = VFIO_DEVICE_TPH_SRC_DMABUF,
>> + [VFIO_PCI_TPH_POLICY_IV_ST] = VFIO_DEVICE_TPH_SRC_DMABUF,
>> + [VFIO_PCI_TPH_POLICY_DS_ST ... VFIO_PCI_TPH_POLICY_LITERAL] =
>> + VFIO_DEVICE_TPH_SRC_DMABUF |
>> + VFIO_DEVICE_TPH_SRC_CPU_VOLATILE |
>> + VFIO_DEVICE_TPH_SRC_CPU_PERSISTENT,
>> + };
>> + u32 permit_flags = permit_src_mask[vdev->tph_policy] |
>> + VFIO_DEVICE_TPH_EXTENDED;
>> + struct vfio_device_feature_tph_resolve resolve = {0};
>> + enum tph_mem_type mtype;
>> + bool extended;
>> + u32 src_bits;
>> + u16 tag = 0;
>> + u8 ph = 0;
>> + int ret;
>> +
>> + if (!vdev->tph_permit)
>> + return -EOPNOTSUPP;
>> +
>> + ret = vfio_check_feature(flags, argsz, VFIO_DEVICE_FEATURE_GET,
>> + sizeof(resolve));
>> + if (ret <= 0)
>> + return ret;
>> +
>> + if (copy_from_user(&resolve, arg, sizeof(resolve)))
>> + return -EFAULT;
>> +
>> + src_bits = resolve.flags & VFIO_DEVICE_TPH_SRC_MASK;
>> + if (!(resolve.flags & permit_flags) || !is_power_of_2(src_bits))
>> + return -EINVAL;
>> + extended = !!(resolve.flags & VFIO_DEVICE_TPH_EXTENDED);
>> + if (extended && !pcie_tph_supported(vdev->pdev, true))
>> + return -EINVAL;
>> +
>> + resolve.valid = 0;
>> + resolve.ph = 0;
>> + resolve.st = 0;
>> +
>> + if (src_bits & VFIO_DEVICE_TPH_SRC_DMABUF) {
>> + ret = vfio_pci_dma_buf_get_tph_by_fd(resolve.src, extended,
>> + &tag, &ph);
>> + if (ret)
>> + return ret;
>> + resolve.ph = ph;
>> + resolve.valid = VFIO_DEVICE_TPH_VALID_PH;
>> + if (vdev->tph_policy >= VFIO_PCI_TPH_POLICY_DS_ST) {
>> + resolve.st = tag;
>> + resolve.valid |= VFIO_DEVICE_TPH_VALID_ST;
>> + }
>> + goto out;
>> + }
>> +
>> + mtype = (src_bits & VFIO_DEVICE_TPH_SRC_CPU_VOLATILE) ?
>> + TPH_MEM_TYPE_VM : TPH_MEM_TYPE_PM;
>> + ret = pcie_tph_get_cpu_st_explicit(vdev->pdev, mtype, extended,
>> + resolve.src, &tag);
>> + if (ret)
>> + return ret;
>> + resolve.valid = VFIO_DEVICE_TPH_VALID_ST;
>> + resolve.st = tag;
>> +
>> +out:
>> + return copy_to_user(arg, &resolve, sizeof(resolve)) ? -EFAULT : 0;
>> +}
>> +
>> int vfio_pci_core_ioctl_feature(struct vfio_device *device, u32 flags,
>> void __user *arg, size_t argsz)
>> {
>> @@ -1661,6 +1733,9 @@ int vfio_pci_core_ioctl_feature(struct vfio_device *device, u32 flags,
>> return vfio_pci_core_feature_dma_buf(vdev, flags, arg, argsz);
>> case VFIO_DEVICE_FEATURE_TPH:
>> return vfio_pci_core_feature_tph(vdev, flags, arg, argsz);
>> + case VFIO_DEVICE_FEATURE_TPH_RESOLVE:
>> + return vfio_pci_core_feature_tph_resolve(vdev, flags,
>> + arg, argsz);
>> default:
>> return -ENOTTY;
>> }
>
next prev parent reply other threads:[~2026-07-09 12:20 UTC|newest]
Thread overview: 71+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-02 12:42 [PATCH v19 00/18] vfio/pci: Add PCIe TPH support Chengwen Feng
2026-07-02 12:42 ` [PATCH v19 01/18] PCI/TPH: Fix pcie_tph_get_st_table_loc() field extraction Chengwen Feng
2026-07-02 12:51 ` sashiko-bot
2026-07-02 12:42 ` [PATCH v19 02/18] PCI/TPH: Fix tph_enabled concurrent update race by bitfield packing Chengwen Feng
2026-07-02 12:51 ` sashiko-bot
2026-07-02 12:42 ` [PATCH v19 03/18] PCI/TPH: Cache TPH requester capability at probe time Chengwen Feng
2026-07-02 12:55 ` sashiko-bot
2026-07-02 12:42 ` [PATCH v19 04/18] PCI/TPH: Refactor pcie_enable_tph & add explicit requester variant Chengwen Feng
2026-07-02 12:50 ` sashiko-bot
2026-07-08 23:33 ` Alex Williamson
2026-07-09 9:22 ` fengchengwen
2026-07-02 12:42 ` [PATCH v19 05/18] PCI/TPH: Refactor pcie_tph_get_cpu_st & add explicit variant Chengwen Feng
2026-07-02 12:56 ` sashiko-bot
2026-07-02 12:42 ` [PATCH v19 06/18] PCI/TPH: Expose the enabled TPH requester type Chengwen Feng
2026-07-02 12:49 ` sashiko-bot
2026-07-08 23:33 ` Alex Williamson
2026-07-09 9:30 ` fengchengwen
2026-07-02 12:42 ` [PATCH v19 07/18] PCI/TPH: Add pcie_tph_supported() helper to check TPH capability attributes Chengwen Feng
2026-07-02 12:53 ` sashiko-bot
2026-07-03 0:39 ` fengchengwen
2026-07-08 23:32 ` Alex Williamson
2026-07-09 9:36 ` fengchengwen
2026-07-02 12:42 ` [PATCH v19 08/18] PCI/TPH: Add pci_tph_dsm_supported() helper to detect device TPH ST _DSM Chengwen Feng
2026-07-02 12:55 ` sashiko-bot
2026-07-02 12:42 ` [PATCH v19 09/18] vfio/pci: Hide TPH capability when TPH is unsupported Chengwen Feng
2026-07-02 13:00 ` sashiko-bot
2026-07-03 0:36 ` fengchengwen
2026-07-08 23:32 ` Alex Williamson
2026-07-09 11:00 ` fengchengwen
2026-07-02 12:42 ` [PATCH v19 10/18] vfio/pci: Introduce tph policy parameter for staged TPH feature enablement Chengwen Feng
2026-07-02 12:50 ` sashiko-bot
2026-07-08 23:31 ` Alex Williamson
2026-07-09 11:29 ` fengchengwen
2026-07-02 12:42 ` [PATCH v19 11/18] vfio/pci: Virtualize PCIe TPH capability registers Chengwen Feng
2026-07-02 13:04 ` sashiko-bot
2026-07-03 0:51 ` fengchengwen
2026-07-08 23:31 ` Alex Williamson
2026-07-09 11:40 ` fengchengwen
2026-07-02 12:42 ` [PATCH v19 12/18] vfio/pci: Add dmabuf TPH metadata storage and fd query helper Chengwen Feng
2026-07-02 12:56 ` sashiko-bot
2026-07-03 0:53 ` fengchengwen
2026-07-08 23:31 ` Alex Williamson
2026-07-09 11:49 ` fengchengwen
2026-07-09 18:50 ` Alex Williamson
2026-07-02 12:42 ` [PATCH v19 13/18] vfio/pci: Introduce VFIO_DEVICE_FEATURE_TPH family uapi for PCI TPH control Chengwen Feng
2026-07-02 13:01 ` sashiko-bot
2026-07-03 0:57 ` fengchengwen
2026-07-08 23:31 ` Alex Williamson
2026-07-09 11:56 ` fengchengwen
2026-07-02 12:42 ` [PATCH v19 14/18] vfio/pci: Implement VFIO_DEVICE_FEATURE_TPH and valid TPH config write support Chengwen Feng
2026-07-02 13:04 ` sashiko-bot
2026-07-03 1:16 ` fengchengwen
2026-07-08 23:30 ` Alex Williamson
2026-07-09 12:16 ` fengchengwen
2026-07-02 12:42 ` [PATCH v19 15/18] vfio/pci: Implement TPH_RESOLVE feature for DMABUF and CPU source resolving Chengwen Feng
2026-07-02 13:00 ` sashiko-bot
2026-07-03 1:26 ` fengchengwen
2026-07-08 23:31 ` Alex Williamson
2026-07-09 12:20 ` fengchengwen [this message]
2026-07-02 12:42 ` [PATCH v19 16/18] vfio/pci: Implement TPH_ST feature for batch ST table programming Chengwen Feng
2026-07-02 13:04 ` sashiko-bot
2026-07-03 1:42 ` fengchengwen
2026-07-08 23:29 ` Alex Williamson
2026-07-09 12:36 ` fengchengwen
2026-07-09 13:49 ` Alex Williamson
2026-07-02 12:42 ` [PATCH v19 17/18] vfio/pci: Reset hardware TPH state on device enable/disable Chengwen Feng
2026-07-02 13:00 ` sashiko-bot
2026-07-08 23:29 ` Alex Williamson
2026-07-09 12:39 ` fengchengwen
2026-07-02 12:42 ` [PATCH v19 18/18] vfio/pci: Expose tph_policy via debugfs Chengwen Feng
2026-07-02 12:59 ` 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=dad40817-9c87-494c-86b2-e0e2b75e60e7@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