From: Chengwen Feng <fengchengwen@huawei.com>
To: <alex@shazbot.org>, <jgg@ziepe.ca>
Cc: <wathsala.vithanage@arm.com>, <helgaas@kernel.org>,
<wangzhou1@hisilicon.com>, <wangyushan12@huawei.com>,
<liuyonglong@huawei.com>, <kvm@vger.kernel.org>,
<linux-pci@vger.kernel.org>
Subject: [PATCH v5 6/6] vfio/pci: Add PCIe TPH SET_ST interface
Date: Mon, 27 Apr 2026 16:58:43 +0800 [thread overview]
Message-ID: <20260427085843.42460-7-fengchengwen@huawei.com> (raw)
In-Reply-To: <20260427085843.42460-1-fengchengwen@huawei.com>
Add VFIO_PCI_TPH_SET_ST operation to support batch programming of steering
tag entries. If any entry fails, roll back successfully programmed entries
to 0 to prevent inconsistent device state.
Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
---
drivers/vfio/pci/vfio_pci_core.c | 69 ++++++++++++++++++++++++++++++++
1 file changed, 69 insertions(+)
diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c
index 74596ef278b5..ce62d7026b27 100644
--- a/drivers/vfio/pci/vfio_pci_core.c
+++ b/drivers/vfio/pci/vfio_pci_core.c
@@ -1586,6 +1586,73 @@ static int vfio_pci_tph_get_st(struct vfio_pci_core_device *vdev,
return err;
}
+static int vfio_pci_tph_set_st(struct vfio_pci_core_device *vdev,
+ struct vfio_device_pci_tph_op *op,
+ void __user *uarg)
+{
+ struct pci_dev *pdev = vdev->pdev;
+ struct vfio_pci_tph_entry *ents;
+ struct vfio_pci_tph_st st;
+ enum tph_mem_type mtype;
+ int i = 0, j, err, size;
+ u32 tab_loc;
+ u16 st_val;
+
+ tab_loc = pcie_tph_get_st_table_loc(pdev);
+ if (tab_loc != PCI_TPH_LOC_CAP && tab_loc != PCI_TPH_LOC_MSIX)
+ return -EOPNOTSUPP;
+
+ if (copy_from_user(&st, uarg, sizeof(st)))
+ return -EFAULT;
+
+ if (!st.count || st.count > VFIO_PCI_TPH_MAX_ENTRIES)
+ return -EINVAL;
+
+ size = st.count * sizeof(*ents);
+ ents = kvmalloc(size, GFP_KERNEL);
+ if (!ents)
+ return -ENOMEM;
+
+ if (copy_from_user(ents, uarg + sizeof(st), size)) {
+ err = -EFAULT;
+ goto out;
+ }
+
+ for (; i < st.count; i++) {
+ if (ents[i].cpu == U32_MAX) {
+ err = pcie_tph_set_st_entry(pdev, ents[i].index, 0);
+ if (err)
+ goto out;
+ continue;
+ }
+
+ 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, &st_val);
+ if (err)
+ goto out;
+ err = pcie_tph_set_st_entry(pdev, ents[i].index, st_val);
+ if (err)
+ goto out;
+ }
+
+out:
+ if (err) {
+ /* Roll back previously programmed entries to 0 */
+ for (j = 0; j < i; j++)
+ pcie_tph_set_st_entry(pdev, ents[j].index, 0);
+ }
+ kvfree(ents);
+ return err;
+}
+
static int vfio_pci_ioctl_tph(struct vfio_pci_core_device *vdev,
void __user *uarg)
{
@@ -1608,6 +1675,8 @@ static int vfio_pci_ioctl_tph(struct vfio_pci_core_device *vdev,
return vfio_pci_tph_disable(vdev);
case VFIO_PCI_TPH_GET_ST:
return vfio_pci_tph_get_st(vdev, &op, uarg + minsz);
+ case VFIO_PCI_TPH_SET_ST:
+ return vfio_pci_tph_set_st(vdev, &op, uarg + minsz);
default:
/* Other ops are not implemented yet */
return -EINVAL;
--
2.17.1
prev parent reply other threads:[~2026-04-27 8:58 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-27 8:58 [PATCH v5 0/6] vfio/pci: Add PCIe TPH support Chengwen Feng
2026-04-27 8:58 ` [PATCH v5 1/6] PCI/TPH: Fix pcie_tph_get_st_table_loc() field extraction Chengwen Feng
2026-04-27 22:25 ` Bjorn Helgaas
2026-05-04 23:11 ` Alex Williamson
2026-04-27 8:58 ` [PATCH v5 2/6] PCI/TPH: Export pcie_tph_get_st_modes() for external use Chengwen Feng
2026-04-27 8:58 ` [PATCH v5 3/6] vfio/pci: Add PCIe TPH interface with capability query Chengwen Feng
2026-04-27 8:58 ` [PATCH v5 4/6] vfio/pci: Add PCIe TPH enable/disable support Chengwen Feng
2026-04-27 8:58 ` [PATCH v5 5/6] vfio/pci: Add PCIe TPH GET_ST interface Chengwen Feng
2026-04-27 8:58 ` Chengwen Feng [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=20260427085843.42460-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 \
/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