From: Chengwen Feng <fengchengwen@huawei.com>
To: <alex@shazbot.org>, <jgg@ziepe.ca>
Cc: <wathsala.vithanage@arm.com>, <helgaas@kernel.org>,
<wei.huang2@amd.com>, <wangzhou1@hisilicon.com>,
<wangyushan12@huawei.com>, <liuyonglong@huawei.com>,
<kvm@vger.kernel.org>, <linux-pci@vger.kernel.org>
Subject: [PATCH v8 6/7] vfio/pci: Add PCIe TPH GET_ST interface
Date: Fri, 8 May 2026 14:40:52 +0800 [thread overview]
Message-ID: <20260508064053.37529-7-fengchengwen@huawei.com> (raw)
In-Reply-To: <20260508064053.37529-1-fengchengwen@huawei.com>
Add support to batch get CPU steering tags for device-specific TPH mode.
This interface requires enabling the 'enable_unsafe_tph_ds_mode' module
parameter.
Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
---
drivers/vfio/pci/vfio_pci_core.c | 76 ++++++++++++++++++++++++++++++++
1 file changed, 76 insertions(+)
diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c
index bfc7e87d190f..7ec2dd32f106 100644
--- a/drivers/vfio/pci/vfio_pci_core.c
+++ b/drivers/vfio/pci/vfio_pci_core.c
@@ -1532,6 +1532,80 @@ static int vfio_pci_tph_disable(struct vfio_pci_core_device *vdev)
return 0;
}
+static int vfio_pci_tph_get_st(struct vfio_pci_core_device *vdev,
+ struct vfio_device_pci_tph_op *op,
+ void __user *uarg)
+{
+ struct pci_dev *pdev = vdev->pdev;
+ u8 mode = pcie_tph_get_st_modes(pdev);
+ struct vfio_pci_tph_entry *ents;
+ struct vfio_pci_tph_st st;
+ enum tph_mem_type mtype;
+ size_t size, ents_off;
+ int i, err;
+
+ if (!enable_unsafe_tph_ds_mode || !(mode & PCI_TPH_CAP_ST_DS))
+ return -EOPNOTSUPP;
+
+ if (op->argsz < offsetofend(struct vfio_device_pci_tph_op, st))
+ return -EINVAL;
+
+ if (copy_from_user(&st, uarg, sizeof(st)))
+ return -EFAULT;
+
+ /* Check reserved fields are zero */
+ if (memchr_inv(&st.reserved, 0, sizeof(st.reserved)))
+ return -EINVAL;
+
+ if (!st.count || st.count > VFIO_PCI_TPH_MAX_ENTRIES)
+ return -EINVAL;
+
+ size = st.count * sizeof(*ents);
+ if (op->argsz < offsetofend(struct vfio_device_pci_tph_op, st) + size)
+ return -EINVAL;
+
+ ents = kvmalloc(size, GFP_KERNEL);
+ if (!ents)
+ return -ENOMEM;
+
+ ents_off = offsetof(struct vfio_pci_tph_st, ents);
+ if (copy_from_user(ents, uarg + ents_off, size)) {
+ err = -EFAULT;
+ goto out;
+ }
+
+ for (i = 0; i < st.count; i++) {
+ /* Check reserved fields and index are zero */
+ if (memchr_inv(&ents[i].reserved0, 0, sizeof(ents[i].reserved0)) ||
+ memchr_inv(&ents[i].reserved1, 0, sizeof(ents[i].reserved1)) ||
+ ents[i].index != 0) {
+ err = -EINVAL;
+ goto out;
+ }
+
+ if (ents[i].mem_type == VFIO_PCI_TPH_MEM_TYPE_VM) {
+ mtype = TPH_MEM_TYPE_VM;
+ } else if (ents[i].mem_type == VFIO_PCI_TPH_MEM_TYPE_PM) {
+ mtype = TPH_MEM_TYPE_PM;
+ } else {
+ err = -EINVAL;
+ goto out;
+ }
+
+ err = pcie_tph_get_cpu_st(pdev, mtype, ents[i].cpu,
+ &ents[i].st);
+ if (err)
+ goto out;
+ }
+
+ if (copy_to_user(uarg + ents_off, ents, size))
+ err = -EFAULT;
+
+out:
+ kvfree(ents);
+ return err;
+}
+
static int vfio_pci_ioctl_tph(struct vfio_pci_core_device *vdev,
void __user *uarg)
{
@@ -1550,6 +1624,8 @@ static int vfio_pci_ioctl_tph(struct vfio_pci_core_device *vdev,
return vfio_pci_tph_enable(vdev, &op, uarg + minsz);
case VFIO_PCI_TPH_DISABLE:
return vfio_pci_tph_disable(vdev);
+ case VFIO_PCI_TPH_GET_ST:
+ return vfio_pci_tph_get_st(vdev, &op, uarg + minsz);
default:
/* Other ops are not implemented yet */
return -EINVAL;
--
2.17.1
next prev parent reply other threads:[~2026-05-08 6:41 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-08 6:40 [PATCH v8 0/7] vfio/pci: Add PCIe TPH support Chengwen Feng
2026-05-08 6:40 ` [PATCH v8 1/7] PCI/TPH: Fix pcie_tph_get_st_table_loc() field extraction Chengwen Feng
2026-05-08 6:40 ` [PATCH v8 2/7] PCI/TPH: Export pcie_tph_get_st_modes() for external use Chengwen Feng
2026-05-08 19:02 ` sashiko-bot
2026-05-08 6:40 ` [PATCH v8 3/7] PCI/TPH: Fix pcie_tph_get_st_table_size() for MSI-X table location Chengwen Feng
2026-05-08 19:31 ` sashiko-bot
2026-05-08 6:40 ` [PATCH v8 4/7] vfio/pci: Add PCIe TPH interface with capability query Chengwen Feng
2026-05-08 20:03 ` sashiko-bot
2026-05-08 22:40 ` Alex Williamson
2026-05-09 3:28 ` fengchengwen
2026-05-11 4:36 ` Alex Williamson
2026-05-08 6:40 ` [PATCH v8 5/7] vfio/pci: Add PCIe TPH enable/disable support Chengwen Feng
2026-05-08 20:46 ` sashiko-bot
2026-05-08 6:40 ` Chengwen Feng [this message]
2026-05-08 6:40 ` [PATCH v8 7/7] vfio/pci: Add PCIe TPH SET_ST interface Chengwen Feng
2026-05-08 21:49 ` 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=20260508064053.37529-7-fengchengwen@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 \
/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