| Seq | Timestamp | Type | Name | Duration |
|---|---|---|---|---|
| 0/0 | 2026/11/22 09:23 | flow | patch-triage |
32mArgs:null Results: {
"EnableConfigs": [
"PCIE_TPH",
"VFIO_PCI",
"VFIO",
"PCI",
"ACPI"
],
"FocusSymbols": [
"vfio_pci_core_feature_tph",
"vfio_pci_core_feature_tph_program",
"vfio_pci_core_feature_tph_resolve",
"vfio_tph_config_write",
"vfio_tph_config_read",
"vfio_pci_tph_cpuhp_offline",
"pcie_tph_set_st_entries",
"pcie_enable_tph_ext",
"pcie_tph_get_cpu_st_ext",
"pcie_tph_dsm_supported"
],
"KMSANReasoning": "The patch series adds PCIe TPH (TLP Processing Hints) support to VFIO-PCI and refactors helper functions in the PCI core TPH implementation.\n\nAnalysis of uninitialized memory risks:\n1. Structures copied to userspace:\n - `vfio_pci_core_feature_tph`: Copies `struct vfio_device_feature_tph` (4 bytes, single u32 `flags` field) to user space after assigning `flags`. There are no padding bytes or uninitialized fields.\n - `vfio_pci_core_feature_tph_resolve`: Copies `struct vfio_device_feature_tph_resolve` to user space. The structure layout is 12 bytes total (u32 flags, u32 src, u8 valid, u8 rsv, u16 st), matching 4-byte struct alignment with 0 padding bytes. The input fields `flags` and `src` are populated via `copy_from_user`, and all remaining output fields (`valid`, `rsv`, `st`) are explicitly assigned.\n - Config space reads via `vfio_tph_config_read`: Values are either synthesized (0 for out-of-range/table offsets) or read from device config space into pre-initialized stack buffers.\n\n2. Buffers and structures allocated in kernel space:\n - Dynamic allocations use zeroing allocators (`kcalloc` for `tags` and `vdev-\u003etph_st_cpu`, `kvzalloc` for the containing `vfio_pci_core_device`).\n - Local variables such as `reg` in `pcie_tph_get_st_table_loc` and `pci_tph_init` are explicitly initialized to 0.\n\nPotential issues introduced by this patch series (such as bounds checking on ST table sizes, array indexing, mutex locking with `tph_lock`, CPU hotplug state management, or PCI config register accesses) are fully covered by standard bug detectors (KASAN, LOCKDEP, UBSAN). There are no uninitialized memory reads or information leak risks that would warrant a dedicated KMSAN fuzzing session.",
"NeedsKMSAN": false,
"Reasoning": "The patch series implements support for PCIe TLP Processing Hints (TPH) in VFIO-PCI and refactors core PCIe TPH helper functions. Specifically, it adds user-facing ioctls (VFIO_DEVICE_FEATURE_TPH, VFIO_DEVICE_FEATURE_TPH_PROGRAM, VFIO_DEVICE_FEATURE_TPH_RESOLVE) for steering tag (ST) capability discovery, resolution, and batch table programming, virtualizes the PCIe TPH extended capability in VFIO config space reads/writes, integrates with the CPU hotplug subsystem to clear ST mappings when CPUs go offline, and introduces new locking and allocation paths. These changes touch reachable driver and PCI core code accepting user inputs and warrant fuzzing.",
"WorthFuzzing": true
} |
| 1/1 | 2026/11/22 09:23 | action | read-patch-diff |
0mArgs:null Results: {
"PatchDiff": "commit 03d5f979b30c8eee0af9b8cf1923dd0e2bffa4d0\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate: Sun Nov 22 09:23:03 2026 +0000\n\n syz-cluster: applied patch under review\n\ndiff --git a/drivers/pci/tph.c b/drivers/pci/tph.c\nindex 4d064b86befcc5..c3d940745fe4da 100644\n--- a/drivers/pci/tph.c\n+++ b/drivers/pci/tph.c\n@@ -167,11 +167,14 @@ static u8 get_st_modes(struct pci_dev *pdev)\n */\n u32 pcie_tph_get_st_table_loc(struct pci_dev *pdev)\n {\n-\tu32 reg;\n+\tu32 reg = 0;\n+\n+\tif (!pdev-\u003etph_cap)\n+\t\treturn PCI_TPH_LOC_NONE;\n \n \tpci_read_config_dword(pdev, pdev-\u003etph_cap + PCI_TPH_CAP, \u0026reg);\n \n-\treturn FIELD_GET(PCI_TPH_CAP_LOC_MASK, reg);\n+\treturn reg \u0026 PCI_TPH_CAP_LOC_MASK;\n }\n EXPORT_SYMBOL(pcie_tph_get_st_table_loc);\n \n@@ -186,9 +189,6 @@ u16 pcie_tph_get_st_table_size(struct pci_dev *pdev)\n \n \t/* Check ST table location first */\n \tloc = pcie_tph_get_st_table_loc(pdev);\n-\n-\t/* Convert loc to match with PCI_TPH_LOC_* defined in pci_regs.h */\n-\tloc = FIELD_PREP(PCI_TPH_CAP_LOC_MASK, loc);\n \tif (loc != PCI_TPH_LOC_CAP)\n \t\treturn 0;\n \n@@ -233,20 +233,22 @@ static int write_tag_to_st_table(struct pci_dev *pdev, int index, u16 tag)\n }\n \n /**\n- * pcie_tph_get_cpu_st() - Retrieve Steering Tag for a target memory associated\n- * with a specific CPU\n+ * pcie_tph_get_cpu_st_ext() - Retrieve Steering Tag for a target memory\n+ * associated with a specific CPU, with explicit requester type selection\n * @pdev: PCI device\n * @mem_type: target memory type (volatile or persistent RAM)\n+ * @req_type: TPH requester type to select ST namespace\n * @cpu: associated CPU id\n * @tag: Steering Tag to be returned\n *\n- * Return the Steering Tag for a target memory that is associated with a\n- * specific CPU as indicated by cpu.\n+ * Return the Steering Tag for a target memory associated with a specific CPU,\n+ * using the specified TPH requester type to select the correct ST namespace.\n+ * Validates requester type against hardware negotiated capability limits.\n *\n * Return: 0 if success, otherwise negative value (-errno)\n */\n-int pcie_tph_get_cpu_st(struct pci_dev *pdev, enum tph_mem_type mem_type,\n-\t\t\tunsigned int cpu, u16 *tag)\n+int pcie_tph_get_cpu_st_ext(struct pci_dev *pdev, enum tph_mem_type mem_type,\n+\t\t\t u8 req_type, unsigned int cpu, u16 *tag)\n {\n #ifdef CONFIG_ACPI\n \tstruct pci_dev *rp;\n@@ -255,6 +257,10 @@ int pcie_tph_get_cpu_st(struct pci_dev *pdev, enum tph_mem_type mem_type,\n \tu32 cpu_uid;\n \tint ret;\n \n+\tif (req_type == PCI_TPH_REQ_DISABLE || req_type == 2 ||\n+\t\treq_type \u003e pdev-\u003etph_max_type)\n+\t\treturn -EINVAL;\n+\n \tret = acpi_get_cpu_uid(cpu, \u0026cpu_uid);\n \tif (ret != 0)\n \t\treturn ret;\n@@ -270,35 +276,54 @@ int pcie_tph_get_cpu_st(struct pci_dev *pdev, enum tph_mem_type mem_type,\n \t\treturn -EINVAL;\n \t}\n \n-\t*tag = tph_extract_tag(mem_type, pdev-\u003etph_req_type, \u0026info);\n+\t*tag = tph_extract_tag(mem_type, req_type, \u0026info);\n \n-\tpci_dbg(pdev, \"get steering tag: mem_type=%s, cpu=%d, tag=%#04x\\n\",\n+\tpci_dbg(pdev, \"get steering tag: mem_type=%s, req_type=%u, cpu=%d, tag=%#04x\\n\",\n \t\t(mem_type == TPH_MEM_TYPE_VM) ? \"volatile\" : \"persistent\",\n-\t\tcpu, *tag);\n+\t\treq_type, cpu, *tag);\n \n \treturn 0;\n #else\n \treturn -ENODEV;\n #endif\n }\n-EXPORT_SYMBOL(pcie_tph_get_cpu_st);\n+EXPORT_SYMBOL(pcie_tph_get_cpu_st_ext);\n \n /**\n- * pcie_tph_set_st_entry() - Set Steering Tag in the ST table entry\n+ * pcie_tph_get_cpu_st() - Retrieve Steering Tag for a target memory associated\n+ * with a specific CPU\n * @pdev: PCI device\n- * @index: ST table entry index\n- * @tag: Steering Tag to be written\n+ * @mem_type: target memory type (volatile or persistent RAM)\n+ * @cpu: associated CPU id\n+ * @tag: Steering Tag to be returned\n *\n- * Figure out the proper location of ST table, either in the MSI-X table or\n- * in the TPH Extended Capability space, and write the Steering Tag into\n- * the ST entry pointed by index.\n+ * Return the Steering Tag for a target memory associated with a specific CPU,\n+ * using the default negotiated TPH requester type.\n *\n * Return: 0 if success, otherwise negative value (-errno)\n */\n-int pcie_tph_set_st_entry(struct pci_dev *pdev, unsigned int index, u16 tag)\n+int pcie_tph_get_cpu_st(struct pci_dev *pdev, enum tph_mem_type mem_type,\n+\t\t\tunsigned int cpu, u16 *tag)\n+{\n+\treturn pcie_tph_get_cpu_st_ext(pdev, mem_type, pdev-\u003etph_max_type,\n+\t\t\t\t cpu, tag);\n+}\n+EXPORT_SYMBOL(pcie_tph_get_cpu_st);\n+\n+/**\n+ * pcie_tph_set_st_entries - Batch set Steering Tag entries in the ST table\n+ * @pdev: PCI device\n+ * @start: starting ST table index\n+ * @count: number of contiguous entries to write\n+ * @tags: array of u16 tag values to program\n+ *\n+ * Return: number of successfully written entries (\u003e0), or negative errno\n+ */\n+int pcie_tph_set_st_entries(struct pci_dev *pdev, unsigned int start,\n+\t\t\t unsigned int count, const u16 *tags)\n {\n-\tu32 loc;\n \tint err = 0;\n+\tu32 loc, i;\n \n \tif (!pdev-\u003etph_cap)\n \t\treturn -EINVAL;\n@@ -306,9 +331,12 @@ int pcie_tph_set_st_entry(struct pci_dev *pdev, unsigned int index, u16 tag)\n \tif (!pdev-\u003etph_enabled)\n \t\treturn -EINVAL;\n \n+\tif (!count)\n+\t\treturn -EINVAL;\n+\n \t/* No need to write tag if device is in \"No ST Mode\" */\n \tif (pdev-\u003etph_mode == PCI_TPH_ST_NS_MODE)\n-\t\treturn 0;\n+\t\treturn count;\n \n \t/*\n \t * Disable TPH before updating ST to avoid potential instability as\n@@ -317,31 +345,47 @@ int pcie_tph_set_st_entry(struct pci_dev *pdev, unsigned int index, u16 tag)\n \tset_ctrl_reg_req_en(pdev, PCI_TPH_REQ_DISABLE);\n \n \tloc = pcie_tph_get_st_table_loc(pdev);\n-\t/* Convert loc to match with PCI_TPH_LOC_* */\n-\tloc = FIELD_PREP(PCI_TPH_CAP_LOC_MASK, loc);\n-\n-\tswitch (loc) {\n-\tcase PCI_TPH_LOC_MSIX:\n-\t\terr = pci_msix_write_tph_tag(pdev, index, tag);\n-\t\tbreak;\n-\tcase PCI_TPH_LOC_CAP:\n-\t\terr = write_tag_to_st_table(pdev, index, tag);\n-\t\tbreak;\n-\tdefault:\n-\t\terr = -EINVAL;\n-\t}\n-\n-\tif (err) {\n-\t\tpcie_disable_tph(pdev);\n-\t\treturn err;\n+\tfor (i = 0; i \u003c count; i++) {\n+\t\tswitch (loc) {\n+\t\tcase PCI_TPH_LOC_MSIX:\n+\t\t\terr = pci_msix_write_tph_tag(pdev, start + i, tags[i]);\n+\t\t\tbreak;\n+\t\tcase PCI_TPH_LOC_CAP:\n+\t\t\terr = write_tag_to_st_table(pdev, start + i, tags[i]);\n+\t\t\tbreak;\n+\t\tdefault:\n+\t\t\terr = -EINVAL;\n+\t\t}\n+\t\tif (err != 0) {\n+\t\t\tpci_err(pdev, \"failed to set steering tag: %s table, index=%u, tags=%u, ret=%d\\n\",\n+\t\t\t\t(loc == PCI_TPH_LOC_MSIX) ? \"MSI-X\" : \"ST\",\n+\t\t\t\tstart + i, tags[i], err);\n+\t\t\tpcie_disable_tph(pdev);\n+\t\t\treturn i \u003e 0 ? i : (err \u003e 0 ? -EINVAL : err);\n+\t\t}\n \t}\n \n \tset_ctrl_reg_req_en(pdev, pdev-\u003etph_req_type);\n \n-\tpci_dbg(pdev, \"set steering tag: %s table, index=%d, tag=%#04x\\n\",\n-\t\t(loc == PCI_TPH_LOC_MSIX) ? \"MSI-X\" : \"ST\", index, tag);\n+\tpci_dbg(pdev, \"batch set steering tag: %s table, start=%u, count=%u success!\\n\",\n+\t\t(loc == PCI_TPH_LOC_MSIX) ? \"MSI-X\" : \"ST\", start, count);\n \n-\treturn 0;\n+\treturn count;\n+}\n+EXPORT_SYMBOL(pcie_tph_set_st_entries);\n+\n+/**\n+ * pcie_tph_set_st_entry() - Set Steering Tag in the ST table entry\n+ * @pdev: PCI device\n+ * @index: ST table entry index\n+ * @tag: Steering Tag to be written\n+ *\n+ * Return: 0 if success, otherwise negative value (-errno)\n+ */\n+int pcie_tph_set_st_entry(struct pci_dev *pdev, unsigned int index, u16 tag)\n+{\n+\tint ret = pcie_tph_set_st_entries(pdev, index, 1, \u0026tag);\n+\treturn ret == 1 ? 0 : ret;\n }\n EXPORT_SYMBOL(pcie_tph_set_st_entry);\n \n@@ -368,26 +412,21 @@ void pcie_disable_tph(struct pci_dev *pdev)\n EXPORT_SYMBOL(pcie_disable_tph);\n \n /**\n- * pcie_enable_tph - Enable TPH support for device using a specific ST mode\n+ * pcie_enable_tph_ext - Enable TPH support with specific ST mode and\n+ * requester type\n * @pdev: PCI device\n- * @mode: ST mode to enable. Current supported modes include:\n+ * @mode: ST mode to enable: PCI_TPH_ST_(NS_MODE / IV_MODE / DS_MODE)\n+ * @req_type: Requester type to enable: PCI_TPH_REQ_(TPH_ONLY / EXT_TPH)\n *\n- * - PCI_TPH_ST_NS_MODE: NO ST Mode\n- * - PCI_TPH_ST_IV_MODE: Interrupt Vector Mode\n- * - PCI_TPH_ST_DS_MODE: Device Specific Mode\n- *\n- * Check whether the mode is actually supported by the device before enabling\n- * and return an error if not. Additionally determine what types of requests,\n- * TPH or extended TPH, can be issued by the device based on its TPH requester\n- * capability and the Root Port's completer capability.\n+ * Check whether the mode and requester type is actually supported by the\n+ * device before enabling and return an error if not.\n *\n * Return: 0 on success, otherwise negative value (-errno)\n */\n-int pcie_enable_tph(struct pci_dev *pdev, int mode)\n+int pcie_enable_tph_ext(struct pci_dev *pdev, u8 mode, u8 req_type)\n {\n \tu32 reg;\n \tu8 dev_modes;\n-\tu8 rp_req_type;\n \n \t/* Honor \"notph\" kernel parameter */\n \tif (pci_tph_disabled)\n@@ -399,6 +438,14 @@ int pcie_enable_tph(struct pci_dev *pdev, int mode)\n \tif (pdev-\u003etph_enabled)\n \t\treturn -EBUSY;\n \n+\tif (pdev-\u003etph_max_type == PCI_TPH_REQ_DISABLE)\n+\t\treturn -EINVAL;\n+\n+\t/* Sanitize and check TPH requester type compatibility */\n+\tif (req_type == PCI_TPH_REQ_DISABLE || req_type == 2 ||\n+\t\treq_type \u003e pdev-\u003etph_max_type)\n+\t\treturn -EINVAL;\n+\n \t/* Sanitize and check ST mode compatibility */\n \tmode \u0026= PCI_TPH_CTRL_MODE_SEL_MASK;\n \tdev_modes = get_st_modes(pdev);\n@@ -407,23 +454,7 @@ int pcie_enable_tph(struct pci_dev *pdev, int mode)\n \n \tpdev-\u003etph_mode = mode;\n \n-\t/* Get req_type supported by device and its Root Port */\n-\tpci_read_config_dword(pdev, pdev-\u003etph_cap + PCI_TPH_CAP, \u0026reg);\n-\tif (FIELD_GET(PCI_TPH_CAP_EXT_TPH, reg))\n-\t\tpdev-\u003etph_req_type = PCI_TPH_REQ_EXT_TPH;\n-\telse\n-\t\tpdev-\u003etph_req_type = PCI_TPH_REQ_TPH_ONLY;\n-\n-\t/* Check if the device is behind a Root Port */\n-\tif (pci_pcie_type(pdev) != PCI_EXP_TYPE_RC_END) {\n-\t\trp_req_type = get_rp_completer_type(pdev);\n-\n-\t\t/* Final req_type is the smallest value of two */\n-\t\tpdev-\u003etph_req_type = min(pdev-\u003etph_req_type, rp_req_type);\n-\t}\n-\n-\tif (pdev-\u003etph_req_type == PCI_TPH_REQ_DISABLE)\n-\t\treturn -EINVAL;\n+\tpdev-\u003etph_req_type = req_type;\n \n \t/* Write them into TPH control register */\n \tpci_read_config_dword(pdev, pdev-\u003etph_cap + PCI_TPH_CTRL, \u0026reg);\n@@ -437,6 +468,23 @@ int pcie_enable_tph(struct pci_dev *pdev, int mode)\n \n \treturn 0;\n }\n+EXPORT_SYMBOL(pcie_enable_tph_ext);\n+\n+/**\n+ * pcie_enable_tph - Enable TPH support for device using a specific ST mode\n+ * @pdev: PCI device\n+ * @mode: ST mode to enable: PCI_TPH_ST_(NS_MODE / IV_MODE / DS_MODE)\n+ *\n+ * Wrapper for pcie_enable_tph_ext(), automatically uses the pre-cached\n+ * tph_max_type value (negotiated maximum requester type between device and\n+ * root port).\n+ *\n+ * Return: 0 on success, otherwise negative value (-errno)\n+ */\n+int pcie_enable_tph(struct pci_dev *pdev, u8 mode)\n+{\n+\treturn pcie_enable_tph_ext(pdev, mode, pdev-\u003etph_max_type);\n+}\n EXPORT_SYMBOL(pcie_enable_tph);\n \n void pci_restore_tph_state(struct pci_dev *pdev)\n@@ -510,14 +558,60 @@ void pci_no_tph(void)\n \n void pci_tph_init(struct pci_dev *pdev)\n {\n+\tu8 tph_req_type, rp_req_type;\n \tint num_entries;\n \tu32 save_size;\n+\tu32 reg = 0;\n \n \tpdev-\u003etph_cap = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_TPH);\n \tif (!pdev-\u003etph_cap)\n \t\treturn;\n \n+\t/* Get req_type supported by device and its Root Port */\n+\tpci_read_config_dword(pdev, pdev-\u003etph_cap + PCI_TPH_CAP, \u0026reg);\n+\tif (FIELD_GET(PCI_TPH_CAP_EXT_TPH, reg))\n+\t\ttph_req_type = PCI_TPH_REQ_EXT_TPH;\n+\telse\n+\t\ttph_req_type = PCI_TPH_REQ_TPH_ONLY;\n+\n+\t/* Check if the device is behind a Root Port */\n+\tif (pci_pcie_type(pdev) != PCI_EXP_TYPE_RC_END) {\n+\t\trp_req_type = get_rp_completer_type(pdev);\n+\t\t/* Final req_type is the smallest value of two */\n+\t\ttph_req_type = min(tph_req_type, rp_req_type);\n+\t}\n+\n+\tpdev-\u003etph_max_type = tph_req_type;\n+\n \tnum_entries = pcie_tph_get_st_table_size(pdev);\n \tsave_size = sizeof(u32) + num_entries * sizeof(u16);\n \tpci_add_ext_cap_save_buffer(pdev, PCI_EXT_CAP_ID_TPH, save_size);\n }\n+\n+/**\n+ * pcie_tph_dsm_supported - Check if root port exposes TPH ST _DSM\n+ * @pdev: target PCI device\n+ *\n+ * Return true if root port of @pdev provides TPH ST DSM function,\n+ * false otherwise (ACPI disabled or DSM missing).\n+ */\n+bool pcie_tph_dsm_supported(struct pci_dev *pdev)\n+{\n+#ifdef CONFIG_ACPI\n+\tstruct pci_dev *rp = pcie_find_root_port(pdev);\n+\tacpi_handle handle;\n+\n+\tif (!rp || !rp-\u003ebus || !rp-\u003ebus-\u003ebridge)\n+\t\treturn false;\n+\n+\thandle = ACPI_HANDLE(rp-\u003ebus-\u003ebridge);\n+\tif (!handle)\n+\t\treturn false;\n+\n+\treturn acpi_check_dsm(handle, \u0026pci_acpi_dsm_guid, 7,\n+\t\t\t BIT(TPH_ST_DSM_FUNC_INDEX));\n+#else\n+\treturn false;\n+#endif\n+}\n+EXPORT_SYMBOL_GPL(pcie_tph_dsm_supported);\ndiff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c\nindex e7c012febe9124..0369069e7f6a27 100644\n--- a/drivers/vfio/pci/vfio_pci.c\n+++ b/drivers/vfio/pci/vfio_pci.c\n@@ -60,6 +60,29 @@ static bool disable_denylist;\n module_param(disable_denylist, bool, 0444);\n MODULE_PARM_DESC(disable_denylist, \"Disable use of device denylist. Disabling the denylist allows binding to devices with known errata that may lead to exploitable stability or security issues when accessed by untrusted users.\");\n \n+static unsigned int tph_policy;\n+static int tph_policy_set(const char *val, const struct kernel_param *kp)\n+{\n+\treturn param_set_uint_minmax(val, kp, VFIO_PCI_TPH_POLICY_NO_ST,\n+\t\t\t\t VFIO_PCI_TPH_POLICY_DS_ST);\n+}\n+static const struct kernel_param_ops tph_param_ops = {\n+\t.set = tph_policy_set,\n+\t.get = param_get_uint,\n+};\n+module_param_cb(tph_policy, \u0026tph_param_ops, \u0026tph_policy, 0644);\n+MODULE_PARM_DESC(tph_policy,\n+\t\"Global TPH policy level (0=default No-ST):\\n\"\n+\t\"0 = No-ST mode: ST programming unavailable\\n\"\n+\t\"1 = Add IV-ST mode: ST programming supports NONE/CPU sources\\n\"\n+\t\"2 = Add DS-ST mode: RESOLVE returns ST for CPU sources;\\n\"\n+\t\" ST programming supports NONE/CPU sources\\n\"\n+\t\" Note: In this 'Add DS-ST mode', device-specific ST tables are\\n\"\n+\t\" not preserved across PCI resets, userspace must re-establish\\n\"\n+\t\" ST state after reset. The kernel cannot validate these ST\\n\"\n+\t\" entries, so this mode is not recommended for general\\n\"\n+\t\" virtualization usecases.\");\n+\n static bool vfio_pci_dev_in_denylist(struct pci_dev *pdev)\n {\n \tswitch (pdev-\u003evendor) {\n@@ -142,6 +165,7 @@ static int vfio_pci_init_dev(struct vfio_device *core_vdev)\n #ifdef CONFIG_VFIO_PCI_VGA\n \tvdev-\u003edisable_vga = disable_vga;\n #endif\n+\tvdev-\u003etph_policy = tph_policy;\n \n \treturn vfio_pci_core_init_dev(core_vdev);\n }\ndiff --git a/drivers/vfio/pci/vfio_pci_config.c b/drivers/vfio/pci/vfio_pci_config.c\nindex 9914f3ac69aef9..8e47f84216b0dd 100644\n--- a/drivers/vfio/pci/vfio_pci_config.c\n+++ b/drivers/vfio/pci/vfio_pci_config.c\n@@ -20,8 +20,10 @@\n * must be negotiated with the underlying OS.\n */\n \n+#include \u003clinux/bitfield.h\u003e\n #include \u003clinux/fs.h\u003e\n #include \u003clinux/pci.h\u003e\n+#include \u003clinux/pci-tph.h\u003e\n #include \u003clinux/uaccess.h\u003e\n #include \u003clinux/vfio.h\u003e\n #include \u003clinux/slab.h\u003e\n@@ -1085,6 +1087,156 @@ static int __init init_pci_ext_cap_pwr_perm(struct perm_bits *perm)\n \treturn 0;\n }\n \n+static int vfio_find_cap_start(struct vfio_pci_core_device *vdev, int pos)\n+{\n+\tu8 cap;\n+\tint base = (pos \u003e= PCI_CFG_SPACE_SIZE) ? PCI_CFG_SPACE_SIZE :\n+\t\t\t\t\t\t PCI_STD_HEADER_SIZEOF;\n+\tcap = vdev-\u003epci_config_map[pos];\n+\n+\tif (cap == PCI_CAP_ID_BASIC)\n+\t\treturn 0;\n+\n+\t/* XXX Can we have to abutting capabilities of the same type? */\n+\twhile (pos - 1 \u003e= base \u0026\u0026 vdev-\u003epci_config_map[pos - 1] == cap)\n+\t\tpos--;\n+\n+\treturn pos;\n+}\n+\n+/* Permissions for TPH extended capability */\n+static int __init init_pci_ext_cap_tph_perm(struct perm_bits *perm)\n+{\n+\t/*\n+\t * We only virtualize the TPH header (excluding the ST table).\n+\t * For the ST table (if any), the read operation returns 0 by\n+\t * default, and the write operation is discarded by default.\n+\t */\n+\tif (alloc_perm_bits(perm, PCI_TPH_BASE_SIZEOF))\n+\t\treturn -ENOMEM;\n+\n+\tp_setd(perm, 0, ALL_VIRT, NO_WRITE);\n+\tp_setd(perm, PCI_TPH_CAP, ALL_VIRT, NO_WRITE);\n+\n+\tp_setd(perm, PCI_TPH_CTRL, ALL_VIRT,\n+\t PCI_TPH_CTRL_MODE_SEL_MASK | PCI_TPH_CTRL_REQ_EN_MASK);\n+\n+\treturn 0;\n+}\n+\n+static void vfio_tph_vcap_rewrite(struct vfio_pci_core_device *vdev, int pos)\n+{\n+\t__le32 *vptr = (__le32 *)\u0026vdev-\u003evconfig[pos + PCI_TPH_CAP];\n+\tstruct pci_dev *pdev = vdev-\u003epdev;\n+\tu32 val = le32_to_cpu(*vptr);\n+\n+\tif (!pcie_ext_tph_supported(pdev)) {\n+\t\t/* Remove extended TPH if root-port doesn't support */\n+\t\tval \u0026= ~PCI_TPH_CAP_EXT_TPH;\n+\t}\n+\n+\tif (vdev-\u003etph_policy == VFIO_PCI_TPH_POLICY_NO_ST) {\n+\t\t/*\n+\t\t * NO-ST policy: mask IV/DS mode, ST location and ST size fields.\n+\t\t * Userspace only sees NO-ST capability.\n+\t\t */\n+\t\tval \u0026= ~(PCI_TPH_CAP_ST_IV | PCI_TPH_CAP_ST_DS |\n+\t\t\t PCI_TPH_CAP_LOC_MASK | PCI_TPH_CAP_ST_MASK);\n+\t} else if (vdev-\u003etph_policy == VFIO_PCI_TPH_POLICY_IV_ST) {\n+\t\t/*\n+\t\t * Add IV policy: mask DS mode, drop ST location and size\n+\t\t * if device does not support IV mode.\n+\t\t */\n+\t\tval \u0026= ~PCI_TPH_CAP_ST_DS;\n+\t\tif (!(val \u0026 PCI_TPH_CAP_ST_IV))\n+\t\t\tval \u0026= ~(PCI_TPH_CAP_LOC_MASK | PCI_TPH_CAP_ST_MASK);\n+\t}\n+\n+\t*vptr = cpu_to_le32(val);\n+\n+\t/* Cache the final virtualized TPH capability value */\n+\tvdev-\u003etph_vcap = val;\n+}\n+\n+static int vfio_tph_config_read(struct vfio_pci_core_device *vdev, int pos,\n+\t\t\t\tint count, struct perm_bits *perm,\n+\t\t\t\tint offset, __le32 *val)\n+{\n+\tint ret;\n+\n+\tif (offset \u003e= PCI_TPH_BASE_SIZEOF) {\n+\t\t*val = cpu_to_le32(0);\n+\t\treturn count;\n+\t}\n+\n+\tif (offset \u003c PCI_TPH_CTRL)\n+\t\treturn vfio_default_config_read(vdev, pos, count, perm,\n+\t\t\t\t\t\toffset, val);\n+\n+\t/* Read the actual device value for CTRL register. */\n+\tret = vfio_user_config_read(vdev-\u003epdev, pos, val, count);\n+\treturn ret != 0 ? ret : count;\n+}\n+\n+static int vfio_tph_config_write(struct vfio_pci_core_device *vdev, int pos,\n+\t\t\t\t int count, struct perm_bits *perm,\n+\t\t\t\t int offset, __le32 val)\n+{\n+\tu16 start = vfio_find_cap_start(vdev, pos);\n+\tstruct pci_dev *pdev = vdev-\u003epdev;\n+\tu32 org_ctrl, new_ctrl, cap;\n+\tu8 mode, req, org_req;\n+\t__le32 ctrl_val = 0;\n+\tu16 cmd;\n+\tint ret;\n+\n+\tif (!vdev-\u003etph_opt_in || offset \u003e= PCI_TPH_BASE_SIZEOF ||\n+\t\toffset \u003c PCI_TPH_CTRL)\n+\t\treturn count;\n+\n+\tcmd = vfio_pci_memory_lock_and_enable(vdev);\n+\n+\t/*\n+\t * Synchronize the CTRL value of the hardware to the virt. Otherwise,\n+\t * the value will be inconsistent when the device is reset.\n+\t */\n+\tvfio_user_config_read(pdev, start + PCI_TPH_CTRL, \u0026ctrl_val, 4);\n+\tvfio_default_config_write(vdev, start + PCI_TPH_CTRL, 4, perm,\n+\t\t\t\t PCI_TPH_CTRL, ctrl_val);\n+\torg_ctrl = le32_to_cpu(ctrl_val);\n+\n+\t/* Do write operation to virt. */\n+\tret = vfio_default_config_write(vdev, pos, count, perm, offset, val);\n+\tif (ret != count)\n+\t\tgoto out;\n+\n+\t/* Reads the TPH_CTRL value after the write operation. */\n+\tnew_ctrl = le32_to_cpu(*(__le32 *)\u0026vdev-\u003evconfig[start + PCI_TPH_CTRL]);\n+\tif (new_ctrl == org_ctrl)\n+\t\tgoto out; /* Exit because there is no change. */\n+\n+\tcap = vdev-\u003etph_vcap;\n+\tmode = FIELD_GET(PCI_TPH_CTRL_MODE_SEL_MASK, new_ctrl);\n+\treq = FIELD_GET(PCI_TPH_CTRL_REQ_EN_MASK, new_ctrl);\n+\tif (mode \u003e PCI_TPH_ST_DS_MODE || !(cap \u0026 (1u \u003c\u003c mode)) ||\n+\t\treq == 0x2 /* reserved */ ||\n+\t\t(req == PCI_TPH_REQ_EXT_TPH \u0026\u0026 !(cap \u0026 PCI_TPH_CAP_EXT_TPH)))\n+\t\tgoto out; /* Drop invalid or unsupported write value. */\n+\n+\torg_req = FIELD_GET(PCI_TPH_CTRL_REQ_EN_MASK, org_ctrl);\n+\tif (req == org_req)\n+\t\tgoto out; /* Only care about requester enable. */\n+\n+\tif (req == PCI_TPH_REQ_TPH_ONLY || req == PCI_TPH_REQ_EXT_TPH)\n+\t\tpcie_enable_tph_ext(pdev, mode, req);\n+\telse if (req == PCI_TPH_REQ_DISABLE)\n+\t\tpcie_disable_tph(vdev-\u003epdev);\n+\n+out:\n+\tvfio_pci_memory_unlock_and_restore(vdev, cmd);\n+\treturn count;\n+}\n+\n /*\n * Initialize the shared permission tables\n */\n@@ -1100,6 +1252,7 @@ void vfio_pci_uninit_perm_bits(void)\n \n \tfree_perm_bits(\u0026ecap_perms[PCI_EXT_CAP_ID_ERR]);\n \tfree_perm_bits(\u0026ecap_perms[PCI_EXT_CAP_ID_PWR]);\n+\tfree_perm_bits(\u0026ecap_perms[PCI_EXT_CAP_ID_TPH]);\n }\n \n int __init vfio_pci_init_perm_bits(void)\n@@ -1120,6 +1273,9 @@ int __init vfio_pci_init_perm_bits(void)\n \t/* Extended capabilities */\n \tret |= init_pci_ext_cap_err_perm(\u0026ecap_perms[PCI_EXT_CAP_ID_ERR]);\n \tret |= init_pci_ext_cap_pwr_perm(\u0026ecap_perms[PCI_EXT_CAP_ID_PWR]);\n+\tret |= init_pci_ext_cap_tph_perm(\u0026ecap_perms[PCI_EXT_CAP_ID_TPH]);\n+\tecap_perms[PCI_EXT_CAP_ID_TPH].readfn = vfio_tph_config_read;\n+\tecap_perms[PCI_EXT_CAP_ID_TPH].writefn = vfio_tph_config_write;\n \tecap_perms[PCI_EXT_CAP_ID_VNDR].writefn = vfio_raw_config_write;\n \tecap_perms[PCI_EXT_CAP_ID_DVSEC].writefn = vfio_raw_config_write;\n \n@@ -1129,23 +1285,6 @@ int __init vfio_pci_init_perm_bits(void)\n \treturn ret;\n }\n \n-static int vfio_find_cap_start(struct vfio_pci_core_device *vdev, int pos)\n-{\n-\tu8 cap;\n-\tint base = (pos \u003e= PCI_CFG_SPACE_SIZE) ? PCI_CFG_SPACE_SIZE :\n-\t\t\t\t\t\t PCI_STD_HEADER_SIZEOF;\n-\tcap = vdev-\u003epci_config_map[pos];\n-\n-\tif (cap == PCI_CAP_ID_BASIC)\n-\t\treturn 0;\n-\n-\t/* XXX Can we have to abutting capabilities of the same type? */\n-\twhile (pos - 1 \u003e= base \u0026\u0026 vdev-\u003epci_config_map[pos - 1] == cap)\n-\t\tpos--;\n-\n-\treturn pos;\n-}\n-\n static int vfio_msi_config_read(struct vfio_pci_core_device *vdev, int pos,\n \t\t\t\tint count, struct perm_bits *perm,\n \t\t\t\tint offset, __le32 *val)\n@@ -1702,6 +1841,8 @@ static int vfio_ecap_init(struct vfio_pci_core_device *vdev)\n \t\tret = vfio_fill_vconfig_bytes(vdev, epos, len);\n \t\tif (ret)\n \t\t\treturn ret;\n+\t\tif (ecap == PCI_EXT_CAP_ID_TPH)\n+\t\t\tvfio_tph_vcap_rewrite(vdev, epos);\n \n \t\t/*\n \t\t * If we're just using this capability to anchor the list,\ndiff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c\nindex fcbb2da860e2ac..a9cdcb0f95a011 100644\n--- a/drivers/vfio/pci/vfio_pci_core.c\n+++ b/drivers/vfio/pci/vfio_pci_core.c\n@@ -11,6 +11,7 @@\n #define pr_fmt(fmt) KBUILD_MODNAME \": \" fmt\n \n #include \u003clinux/aperture.h\u003e\n+#include \u003clinux/cpuhotplug.h\u003e\n #include \u003clinux/debugfs.h\u003e\n #include \u003clinux/device.h\u003e\n #include \u003clinux/eventfd.h\u003e\n@@ -22,6 +23,7 @@\n #include \u003clinux/notifier.h\u003e\n #include \u003clinux/pagemap.h\u003e\n #include \u003clinux/pci.h\u003e\n+#include \u003clinux/pci-tph.h\u003e\n #include \u003clinux/pm_runtime.h\u003e\n #include \u003clinux/slab.h\u003e\n #include \u003clinux/types.h\u003e\n@@ -128,10 +130,20 @@ static int vfio_pci_core_debugfs_disable_idle_d3(struct seq_file *seq,\n \treturn 0;\n }\n \n+static int vfio_pci_core_debugfs_tph(struct seq_file *seq,\n+\t\t\t\t\t void *data)\n+{\n+\tstruct vfio_pci_core_device *vdev = vfio_pci_core_debugfs_private(seq);\n+\n+\tseq_printf(seq, \"policy=%u cap-virt=0x%x opt-in=%u\\n\",\n+\t\tvdev-\u003etph_policy, vdev-\u003etph_vcap, vdev-\u003etph_opt_in);\n+\treturn 0;\n+}\n+\n /*\n- * disable_idle_d3 and nointxmask are writable module parameters latched\n- * per device at init, so a device's effective value can differ from the\n- * current parameter setting. Expose the per-device (read-only) values\n+ * disable_idle_d3, nointxmask and tph_policy are writable module parameters\n+ * latched per device at init, so a device's effective value can differ from\n+ * the current parameter setting. Expose the per-device (read-only) values\n * here for visibility; read-only parameters can't drift and are omitted.\n */\n static void vfio_pci_core_debugfs_init(struct vfio_pci_core_device *vdev)\n@@ -147,6 +159,8 @@ static void vfio_pci_core_debugfs_init(struct vfio_pci_core_device *vdev)\n \t\t\t\t vfio_pci_core_debugfs_nointxmask);\n \tdebugfs_create_devm_seqfile(dev, \"disable_idle_d3\", pci_dir,\n \t\t\t\t vfio_pci_core_debugfs_disable_idle_d3);\n+\tdebugfs_create_devm_seqfile(dev, \"tph\", pci_dir,\n+\t\t\t\t vfio_pci_core_debugfs_tph);\n }\n #else\n static inline void vfio_pci_core_debugfs_init(struct vfio_pci_core_device *vdev)\n@@ -575,6 +589,9 @@ static void vfio_pci_core_map_bars(struct vfio_pci_core_device *vdev)\n \t}\n }\n \n+static int vfio_pci_tph_dev_init(struct vfio_pci_core_device *vdev);\n+static void vfio_pci_tph_dev_deinit(struct vfio_pci_core_device *vdev);\n+\n int vfio_pci_core_enable(struct vfio_pci_core_device *vdev)\n {\n \tstruct pci_dev *pdev = vdev-\u003epdev;\n@@ -601,6 +618,8 @@ int vfio_pci_core_enable(struct vfio_pci_core_device *vdev)\n \t\tgoto out_disable_device;\n \n \tvdev-\u003ereset_works = !ret;\n+\t/* Reset TPH state for new user session */\n+\tpcie_disable_tph(vdev-\u003epdev);\n \tpci_save_state(pdev);\n \tvdev-\u003epci_saved_state = pci_store_saved_state(pdev);\n \tif (!vdev-\u003epci_saved_state)\n@@ -629,6 +648,11 @@ int vfio_pci_core_enable(struct vfio_pci_core_device *vdev)\n \tif (ret)\n \t\tgoto out_free_zdev;\n \n+\t/* After identifying the capability, initialize TPH. */\n+\tret = vfio_pci_tph_dev_init(vdev);\n+\tif (ret != 0)\n+\t\tgoto out_free_config;\n+\n \tmsix_pos = pdev-\u003emsix_cap;\n \tif (msix_pos) {\n \t\tu16 flags;\n@@ -653,6 +677,8 @@ int vfio_pci_core_enable(struct vfio_pci_core_device *vdev)\n \n \treturn 0;\n \n+out_free_config:\n+\tvfio_config_free(vdev);\n out_free_zdev:\n \tvfio_pci_zdev_close_device(vdev);\n out_free_state:\n@@ -726,6 +752,8 @@ void vfio_pci_core_disable(struct vfio_pci_core_device *vdev)\n \tkfree(vdev-\u003eregion);\n \tvdev-\u003eregion = NULL; /* don't krealloc a freed pointer */\n \n+\tvfio_pci_tph_dev_deinit(vdev);\n+\n \tvfio_config_free(vdev);\n \n \tfor (i = 0; i \u003c PCI_STD_NUM_BARS; i++) {\n@@ -748,6 +776,9 @@ void vfio_pci_core_disable(struct vfio_pci_core_device *vdev)\n \n \tvfio_pci_zdev_close_device(vdev);\n \n+\t/* Reset TPH state on user session exit */\n+\tpcie_disable_tph(vdev-\u003epdev);\n+\n \t/*\n \t * If we have saved state, restore it. If we can reset the device,\n \t * even better. Resetting with current state seems better than\n@@ -1594,6 +1625,348 @@ static int vfio_pci_core_feature_token(struct vfio_pci_core_device *vdev,\n \treturn 0;\n }\n \n+static enum cpuhp_state vfio_tph_cpuhp_state;\n+static u32 vfio_pci_tph_get_st_table_size(struct vfio_pci_core_device *vdev);\n+\n+static int vfio_pci_tph_cpuhp_offline(unsigned int cpu, struct hlist_node *node)\n+{\n+\tstruct vfio_pci_core_device *vdev =\n+\t\thlist_entry(node, struct vfio_pci_core_device, tph_cpuhp_node);\n+\tu32 st_size = vfio_pci_tph_get_st_table_size(vdev);\n+\tint i;\n+\n+\tif (vdev-\u003etph_st_cpu == NULL)\n+\t\treturn 0;\n+\n+\tmutex_lock(\u0026vdev-\u003etph_lock);\n+\tfor (i = 0; i \u003c st_size; i++) {\n+\t\tif (vdev-\u003etph_st_cpu[i] != (s64)cpu)\n+\t\t\tcontinue;\n+\t\tpcie_tph_set_st_entry(vdev-\u003epdev, i, 0);\n+\t\tvdev-\u003etph_st_cpu[i] = -1;\n+\t}\n+\tmutex_unlock(\u0026vdev-\u003etph_lock);\n+\n+\treturn 0;\n+}\n+\n+static int vfio_pci_tph_cpuhp_init(void)\n+{\n+\tint ret;\n+\n+\tret = cpuhp_setup_state_multi(CPUHP_AP_ONLINE_DYN,\n+\t\t\t\t \"vfio/pci/tph:online\",\n+\t\t\t\t NULL,\n+\t\t\t\t vfio_pci_tph_cpuhp_offline);\n+\tif (ret \u003c 0)\n+\t\treturn ret;\n+\n+\tvfio_tph_cpuhp_state = ret;\n+\treturn 0;\n+}\n+\n+static void vfio_pci_tph_cpuhp_deinit(void)\n+{\n+\tcpuhp_remove_multi_state(vfio_tph_cpuhp_state);\n+}\n+\n+static bool vfio_pci_tph_has_architected_st(struct vfio_pci_core_device *vdev)\n+{\n+\tu32 loc = vdev-\u003etph_vcap \u0026 PCI_TPH_CAP_LOC_MASK;\n+\n+\treturn (loc == PCI_TPH_LOC_CAP || loc == PCI_TPH_LOC_MSIX) \u0026\u0026\n+\t\t(vfio_pci_tph_get_st_table_size(vdev) \u003e 0);\n+}\n+\n+static int vfio_pci_tph_dev_init(struct vfio_pci_core_device *vdev)\n+{\n+\tbool has_arch_st;\n+\tu32 st_size;\n+\tint i, ret;\n+\n+\tvdev-\u003etph_opt_in = 0;\n+\tvdev-\u003etph_st_cpu = NULL;\n+\n+\thas_arch_st = vfio_pci_tph_has_architected_st(vdev);\n+\tif (!has_arch_st)\n+\t\treturn 0;\n+\n+\tret = cpuhp_state_add_instance_nocalls(vfio_tph_cpuhp_state,\n+\t\t\t\t\t \u0026vdev-\u003etph_cpuhp_node);\n+\tif (ret != 0)\n+\t\treturn ret;\n+\n+\tst_size = vfio_pci_tph_get_st_table_size(vdev);\n+\tvdev-\u003etph_st_cpu = kcalloc(st_size, sizeof(*vdev-\u003etph_st_cpu),\n+\t\t\t\t GFP_KERNEL);\n+\tif (vdev-\u003etph_st_cpu == NULL) {\n+\t\tcpuhp_state_remove_instance_nocalls(vfio_tph_cpuhp_state,\n+\t\t\t\t\t\t \u0026vdev-\u003etph_cpuhp_node);\n+\t\treturn -ENOMEM;\n+\t}\n+\tfor (i = 0; i \u003c st_size; i++)\n+\t\tvdev-\u003etph_st_cpu[i] = -1;\n+\n+\treturn 0;\n+}\n+\n+static void vfio_pci_tph_dev_deinit(struct vfio_pci_core_device *vdev)\n+{\n+\tbool has_arch_st;\n+\n+\thas_arch_st = vfio_pci_tph_has_architected_st(vdev);\n+\tif (!has_arch_st)\n+\t\treturn;\n+\n+\tkfree(vdev-\u003etph_st_cpu);\n+\tvdev-\u003etph_st_cpu = NULL;\n+\tcpuhp_state_remove_instance_nocalls(vfio_tph_cpuhp_state,\n+\t\t\t\t\t \u0026vdev-\u003etph_cpuhp_node);\n+}\n+\n+static u32 vfio_pci_tph_get_capability(struct vfio_pci_core_device *vdev)\n+{\n+\tbool has_arch_st;\n+\tu32 cap = 0;\n+\n+\thas_arch_st = vfio_pci_tph_has_architected_st(vdev);\n+\tif (has_arch_st)\n+\t\tcap |= VFIO_DEVICE_TPH_CAP_PROG_ST_NONE |\n+\t\t VFIO_DEVICE_TPH_CAP_PROG_ST_CPU;\n+\n+\tif (vdev-\u003etph_vcap \u0026 PCI_TPH_CAP_ST_DS)\n+\t\tcap |= VFIO_DEVICE_TPH_CAP_RESOLVE_CPU_ST;\n+\n+\treturn cap;\n+}\n+\n+static int vfio_pci_core_feature_tph(struct vfio_pci_core_device *vdev,\n+\t\t\t\t u32 flags,\n+\t\t\t\t struct vfio_device_feature_tph __user *arg,\n+\t\t\t\t size_t argsz)\n+{\n+\tstruct vfio_device_feature_tph tph;\n+\tint ret;\n+\n+\tif (!pcie_std_tph_supported(vdev-\u003epdev))\n+\t\treturn -EOPNOTSUPP;\n+\n+\tret = vfio_check_feature(flags, argsz,\n+\t\t\tVFIO_DEVICE_FEATURE_GET | VFIO_DEVICE_FEATURE_SET,\n+\t\t\tsizeof(tph));\n+\tif (ret != 1)\n+\t\treturn ret;\n+\n+\tif (copy_from_user(\u0026tph, arg, sizeof(tph)))\n+\t\treturn -EFAULT;\n+\n+\tif (flags \u0026 VFIO_DEVICE_FEATURE_SET) {\n+\t\tif (tph.flags != 0)\n+\t\t\treturn -EINVAL;\n+\t\tvdev-\u003etph_opt_in = 1;\n+\t\treturn 0;\n+\t}\n+\n+\tif (!vdev-\u003etph_opt_in)\n+\t\treturn -EINVAL;\n+\n+\ttph.flags = vfio_pci_tph_get_capability(vdev);\n+\n+\treturn copy_to_user(arg, \u0026tph, sizeof(tph)) ? -EFAULT : 0;\n+}\n+\n+static u32 vfio_pci_tph_get_src_mask(struct vfio_pci_core_device *vdev)\n+{\n+\tu32 flags = vfio_pci_tph_get_capability(vdev);\n+\tu32 src_mask = 0;\n+\n+\tif (flags \u0026 VFIO_DEVICE_TPH_CAP_PROG_ST_NONE)\n+\t\tsrc_mask |= VFIO_DEVICE_TPH_SRC_NONE;\n+\tif (flags \u0026 VFIO_DEVICE_TPH_CAP_PROG_ST_CPU)\n+\t\tsrc_mask |= VFIO_DEVICE_TPH_SRC_CPU_VOLATILE |\n+\t\t\t VFIO_DEVICE_TPH_SRC_CPU_PERSISTENT;\n+\n+\treturn src_mask;\n+}\n+\n+static u32 vfio_pci_tph_get_st_table_size(struct vfio_pci_core_device *vdev)\n+{\n+\tstruct pci_dev *pdev = vdev-\u003epdev;\n+\tu32 loc = pcie_tph_get_st_table_loc(pdev);\n+\tint ret;\n+\n+\tif (loc == PCI_TPH_LOC_CAP) {\n+\t\treturn pcie_tph_get_st_table_size(pdev);\n+\t} else if (loc == PCI_TPH_LOC_MSIX) {\n+\t\tret = pci_msix_vec_count(pdev);\n+\t\tif (ret \u003c 0)\n+\t\t\treturn 0;\n+\t\treturn ret;\n+\t} else {\n+\t\treturn 0;\n+\t}\n+}\n+\n+static int vfio_pci_tph_resolve_st_tag(struct pci_dev *pdev, u32 src_bits,\n+\t\t\t\t u32 src_handle, bool extended, u16 *st)\n+{\n+\tu8 req_type = extended ? PCI_TPH_REQ_EXT_TPH : PCI_TPH_REQ_TPH_ONLY;\n+\tint ret = 0;\n+\n+\tif (src_bits \u0026 VFIO_DEVICE_TPH_SRC_NONE)\n+\t\t*st = 0;\n+\telse if (src_bits \u0026 VFIO_DEVICE_TPH_SRC_CPU_VOLATILE)\n+\t\tret = pcie_tph_get_cpu_st_ext(pdev, TPH_MEM_TYPE_VM,\n+\t\t\t\t\t req_type, src_handle, st);\n+\telse if (src_bits \u0026 VFIO_DEVICE_TPH_SRC_CPU_PERSISTENT)\n+\t\tret = pcie_tph_get_cpu_st_ext(pdev, TPH_MEM_TYPE_PM,\n+\t\t\t\t\t req_type, src_handle, st);\n+\telse\n+\t\tret = -EINVAL;\n+\n+\tif (ret != 0)\n+\t\t*st = 0;\n+\n+\treturn ret;\n+}\n+\n+static int vfio_pci_core_feature_tph_program(struct vfio_pci_core_device *vdev,\n+\t\t\tu32 flags,\n+\t\t\tstruct vfio_device_feature_tph_program __user *arg,\n+\t\t\tsize_t argsz)\n+{\n+\tstruct vfio_device_feature_tph_program program;\n+\tu32 user_flags, src_mask, st_size;\n+\tstruct pci_dev *pdev = vdev-\u003epdev;\n+\tbool extended, stop_on_zero;\n+\tu32 *src_handle = NULL;\n+\tint ret, i, k, written;\n+\tu16 *tags = NULL;\n+\tu16 cmd;\n+\n+\tif (!vdev-\u003etph_opt_in ||\n+\t\t!vfio_pci_tph_has_architected_st(vdev))\n+\t\treturn -EOPNOTSUPP;\n+\n+\tret = vfio_check_feature(flags, argsz, VFIO_DEVICE_FEATURE_SET,\n+\t\t\t\t sizeof(program));\n+\tif (ret != 1)\n+\t\treturn ret;\n+\n+\tif (copy_from_user(\u0026program, arg, sizeof(program)))\n+\t\treturn -EFAULT;\n+\n+\tuser_flags = program.flags;\n+\textended = !!(user_flags \u0026 VFIO_DEVICE_TPH_EXTENDED);\n+\tif (extended \u0026\u0026 !pcie_ext_tph_supported(vdev-\u003epdev))\n+\t\treturn -EOPNOTSUPP;\n+\tuser_flags \u0026= ~VFIO_DEVICE_TPH_EXTENDED;\n+\n+\tstop_on_zero = !!(user_flags \u0026 VFIO_DEVICE_TPH_REQUIRE_ST);\n+\tif (stop_on_zero \u0026\u0026 (user_flags \u0026 VFIO_DEVICE_TPH_SRC_NONE))\n+\t\treturn -EINVAL;\n+\tuser_flags \u0026= ~VFIO_DEVICE_TPH_REQUIRE_ST;\n+\n+\tsrc_mask = vfio_pci_tph_get_src_mask(vdev);\n+\tif (user_flags \u0026 ~src_mask || !is_power_of_2(user_flags))\n+\t\treturn -EINVAL;\n+\n+\tst_size = vfio_pci_tph_get_st_table_size(vdev);\n+\tif (program.start \u003e= st_size || program.count == 0 ||\n+\t\tprogram.count \u003e st_size - program.start)\n+\t\treturn -EINVAL;\n+\n+\tif (!(user_flags \u0026 VFIO_DEVICE_TPH_SRC_NONE)) {\n+\t\tsrc_handle = memdup_array_user(u64_to_user_ptr(program.srcs),\n+\t\t\t\t\t program.count, sizeof(u32));\n+\t\tif (IS_ERR(src_handle))\n+\t\t\treturn PTR_ERR(src_handle);\n+\t}\n+\ttags = kcalloc(program.count, sizeof(u16), GFP_KERNEL_ACCOUNT);\n+\tif (!tags) {\n+\t\tret = -ENOMEM;\n+\t\tgoto out;\n+\t}\n+\n+\tcpus_read_lock();\n+\n+\tfor (i = 0; i \u003c program.count; i++) {\n+\t\tret = vfio_pci_tph_resolve_st_tag(pdev, user_flags,\n+\t\t\t\t\t\tsrc_handle ? src_handle[i] : 0,\n+\t\t\t\t\t\textended, \u0026tags[i]);\n+\t\tif (ret || (stop_on_zero \u0026\u0026 tags[i] == 0))\n+\t\t\tbreak;\n+\t}\n+\n+\tif (i \u003e 0) {\n+\t\tmutex_lock(\u0026vdev-\u003etph_lock);\n+\n+\t\tcmd = vfio_pci_memory_lock_and_enable(vdev);\n+\t\tret = written = pcie_tph_set_st_entries(pdev, program.start, i,\n+\t\t\t\t\t\t\ttags);\n+\t\tvfio_pci_memory_unlock_and_restore(vdev, cmd);\n+\n+\t\tif (written \u003e 0) {\n+\t\t\tfor (k = 0; k \u003c written; k++)\n+\t\t\t\tvdev-\u003etph_st_cpu[program.start + k] =\n+\t\t\t\t\t(tags[k] == 0) ? -1 : src_handle[k];\n+\t\t}\n+\n+\t\tmutex_unlock(\u0026vdev-\u003etph_lock);\n+\t}\n+\n+\tcpus_read_unlock();\n+\n+out:\n+\tkfree(tags);\n+\tkfree(src_handle);\n+\treturn ret;\n+}\n+\n+static int vfio_pci_core_feature_tph_resolve(struct vfio_pci_core_device *vdev,\n+\t\t\tu32 flags,\n+\t\t\tstruct vfio_device_feature_tph_resolve __user *arg,\n+\t\t\tsize_t argsz)\n+{\n+\tstruct vfio_device_feature_tph_resolve resolve;\n+\tu32 user_flags, src_mask;\n+\tbool extended;\n+\tu16 tag = 0;\n+\tint ret;\n+\n+\tif (!vdev-\u003etph_opt_in || !(vdev-\u003etph_vcap \u0026 PCI_TPH_CAP_ST_DS))\n+\t\treturn -EOPNOTSUPP;\n+\n+\tret = vfio_check_feature(flags, argsz, VFIO_DEVICE_FEATURE_GET,\n+\t\t\t\t sizeof(resolve));\n+\tif (ret != 1)\n+\t\treturn ret;\n+\n+\tif (copy_from_user(\u0026resolve, arg, sizeof(resolve)))\n+\t\treturn -EFAULT;\n+\n+\tuser_flags = resolve.flags;\n+\textended = !!(user_flags \u0026 VFIO_DEVICE_TPH_EXTENDED);\n+\tif (extended \u0026\u0026 !pcie_ext_tph_supported(vdev-\u003epdev))\n+\t\treturn -EOPNOTSUPP;\n+\tuser_flags \u0026= ~VFIO_DEVICE_TPH_EXTENDED;\n+\n+\tsrc_mask = vfio_pci_tph_get_src_mask(vdev) \u0026 ~VFIO_DEVICE_TPH_SRC_NONE;\n+\tif (user_flags \u0026 ~src_mask || !is_power_of_2(user_flags))\n+\t\treturn -EINVAL;\n+\n+\tret = vfio_pci_tph_resolve_st_tag(vdev-\u003epdev, user_flags, resolve.src,\n+\t\t\t\t\t extended, \u0026tag);\n+\tif (ret != 0)\n+\t\treturn ret;\n+\n+\tresolve.valid = VFIO_DEVICE_TPH_VALID_ST;\n+\tresolve.rsv = 0;\n+\tresolve.st = tag;\n+\n+\treturn copy_to_user(arg, \u0026resolve, sizeof(resolve)) ? -EFAULT : 0;\n+}\n+\n int vfio_pci_core_ioctl_feature(struct vfio_device *device, u32 flags,\n \t\t\t\tvoid __user *arg, size_t argsz)\n {\n@@ -1614,6 +1987,14 @@ int vfio_pci_core_ioctl_feature(struct vfio_device *device, u32 flags,\n \t\treturn vfio_pci_core_feature_dma_buf(vdev, flags, arg, argsz);\n \tcase VFIO_DEVICE_FEATURE_ZPCI_ERROR:\n \t\treturn vfio_pci_zdev_feature_err(device, flags, arg, argsz);\n+\tcase VFIO_DEVICE_FEATURE_TPH:\n+\t\treturn vfio_pci_core_feature_tph(vdev, flags, arg, argsz);\n+\tcase VFIO_DEVICE_FEATURE_TPH_PROGRAM:\n+\t\treturn vfio_pci_core_feature_tph_program(vdev, flags,\n+\t\t\t\t\t\t\t arg, argsz);\n+\tcase VFIO_DEVICE_FEATURE_TPH_RESOLVE:\n+\t\treturn vfio_pci_core_feature_tph_resolve(vdev, flags,\n+\t\t\t\t\t\t\t arg, argsz);\n \tdefault:\n \t\treturn -ENOTTY;\n \t}\n@@ -2176,6 +2557,7 @@ int vfio_pci_core_init_dev(struct vfio_device *core_vdev)\n \tmutex_init(\u0026vdev-\u003eigate);\n \tspin_lock_init(\u0026vdev-\u003eirqlock);\n \tmutex_init(\u0026vdev-\u003eioeventfds_lock);\n+\tmutex_init(\u0026vdev-\u003etph_lock);\n \tINIT_LIST_HEAD(\u0026vdev-\u003edummy_resources_list);\n \tINIT_LIST_HEAD(\u0026vdev-\u003eioeventfds_list);\n \tINIT_LIST_HEAD(\u0026vdev-\u003esriov_pfs_item);\n@@ -2196,6 +2578,7 @@ void vfio_pci_core_release_dev(struct vfio_device *core_vdev)\n \t\tcontainer_of(core_vdev, struct vfio_pci_core_device, vdev);\n \n \tmutex_destroy(\u0026vdev-\u003eigate);\n+\tmutex_destroy(\u0026vdev-\u003etph_lock);\n \tmutex_destroy(\u0026vdev-\u003eioeventfds_lock);\n \tkfree(vdev-\u003eregion);\n \tkfree(vdev-\u003epm_save);\n@@ -2651,12 +3034,23 @@ static void vfio_pci_core_cleanup(void)\n {\n \tvfio_pci_uninit_perm_bits();\n \trcu_barrier();\n+\tvfio_pci_tph_cpuhp_deinit();\n }\n \n static int __init vfio_pci_core_init(void)\n {\n+\tint ret;\n+\n+\tret = vfio_pci_tph_cpuhp_init();\n+\tif (ret != 0)\n+\t\treturn ret;\n+\n \t/* Allocate shared config space permission data used by all devices */\n-\treturn vfio_pci_init_perm_bits();\n+\tret = vfio_pci_init_perm_bits();\n+\tif (ret != 0)\n+\t\tvfio_pci_tph_cpuhp_deinit();\n+\n+\treturn ret;\n }\n \n module_init(vfio_pci_core_init);\ndiff --git a/drivers/vfio/pci/vfio_pci_priv.h b/drivers/vfio/pci/vfio_pci_priv.h\nindex 4e7162234a2eba..967f706f509ef7 100644\n--- a/drivers/vfio/pci/vfio_pci_priv.h\n+++ b/drivers/vfio/pci/vfio_pci_priv.h\n@@ -11,6 +11,12 @@\n /* Cap maximum number of ioeventfds per device (arbitrary) */\n #define VFIO_PCI_IOEVENTFD_MAX\t\t1000\n \n+enum vfio_pci_tph_policy {\n+\tVFIO_PCI_TPH_POLICY_NO_ST = 0,\n+\tVFIO_PCI_TPH_POLICY_IV_ST,\n+\tVFIO_PCI_TPH_POLICY_DS_ST,\n+};\n+\n struct vfio_pci_ioeventfd {\n \tstruct list_head\tnext;\n \tstruct vfio_pci_core_device\t*vdev;\ndiff --git a/include/linux/pci-tph.h b/include/linux/pci-tph.h\nindex be68cd17f2f833..c19dbbb876200d 100644\n--- a/include/linux/pci-tph.h\n+++ b/include/linux/pci-tph.h\n@@ -9,6 +9,8 @@\n #ifndef LINUX_PCI_TPH_H\n #define LINUX_PCI_TPH_H\n \n+#include \u003clinux/pci.h\u003e\n+\n /*\n * According to the ECN for PCI Firmware Spec, Steering Tag can be different\n * depending on the memory type: Volatile Memory or Persistent Memory. When a\n@@ -21,26 +23,63 @@ enum tph_mem_type {\n };\n \n #ifdef CONFIG_PCIE_TPH\n+/**\n+ * pcie_std_tph_supported - check standard TPH requester support\n+ * @pdev: PCI device\n+ */\n+#define pcie_std_tph_supported(pdev) \\\n+\t((pdev)-\u003etph_max_type \u003e= PCI_TPH_REQ_TPH_ONLY)\n+/**\n+ * pcie_ext_tph_supported - check extended TPH requester support\n+ * @pdev: PCI device\n+ */\n+#define pcie_ext_tph_supported(pdev) \\\n+\t((pdev)-\u003etph_max_type == PCI_TPH_REQ_EXT_TPH)\n int pcie_tph_set_st_entry(struct pci_dev *pdev,\n \t\t\t unsigned int index, u16 tag);\n-int pcie_tph_get_cpu_st(struct pci_dev *dev,\n-\t\t\tenum tph_mem_type mem_type,\n+int pcie_tph_set_st_entries(struct pci_dev *pdev, unsigned int start,\n+\t\t\t unsigned int count, const u16 *tags);\n+int pcie_tph_get_cpu_st_ext(struct pci_dev *dev, enum tph_mem_type mem_type,\n+\t\t\t u8 req_type, unsigned int cpu, u16 *tag);\n+int pcie_tph_get_cpu_st(struct pci_dev *dev, enum tph_mem_type mem_type,\n \t\t\tunsigned int cpu, u16 *tag);\n void pcie_disable_tph(struct pci_dev *pdev);\n-int pcie_enable_tph(struct pci_dev *pdev, int mode);\n+int pcie_enable_tph_ext(struct pci_dev *pdev, u8 mode, u8 req_type);\n+int pcie_enable_tph(struct pci_dev *pdev, u8 mode);\n u16 pcie_tph_get_st_table_size(struct pci_dev *pdev);\n u32 pcie_tph_get_st_table_loc(struct pci_dev *pdev);\n+bool pcie_tph_dsm_supported(struct pci_dev *pdev);\n #else\n+#define pcie_std_tph_supported(pdev) false\n+#define pcie_ext_tph_supported(pdev) false\n static inline int pcie_tph_set_st_entry(struct pci_dev *pdev,\n \t\t\t\t\tunsigned int index, u16 tag)\n { return -EINVAL; }\n+static inline int pcie_tph_set_st_entries(struct pci_dev *pdev,\n+\t\t\t\t\t unsigned int start,\n+\t\t\t\t\t unsigned int count, const u16 *tags)\n+{ return -EINVAL; }\n+static inline int pcie_tph_get_cpu_st_ext(struct pci_dev *dev,\n+\t\t\t\t\t enum tph_mem_type mem_type,\n+\t\t\t\t\t u8 req_type, unsigned int cpu,\n+\t\t\t\t\t u16 *tag)\n+{ return -EINVAL; }\n static inline int pcie_tph_get_cpu_st(struct pci_dev *dev,\n \t\t\t\t enum tph_mem_type mem_type,\n \t\t\t\t unsigned int cpu, u16 *tag)\n { return -EINVAL; }\n static inline void pcie_disable_tph(struct pci_dev *pdev) { }\n-static inline int pcie_enable_tph(struct pci_dev *pdev, int mode)\n+static inline int pcie_enable_tph_ext(struct pci_dev *pdev, u8 mode,\n+\t\t\t\t u8 req_type)\n+{ return -EINVAL; }\n+static inline int pcie_enable_tph(struct pci_dev *pdev, u8 mode)\n { return -EINVAL; }\n+static inline u16 pcie_tph_get_st_table_size(struct pci_dev *pdev)\n+{ return 0; }\n+static inline u32 pcie_tph_get_st_table_loc(struct pci_dev *pdev)\n+{ return PCI_TPH_LOC_NONE; }\n+static inline bool pcie_tph_dsm_supported(struct pci_dev *pdev)\n+{ return false; }\n #endif\n \n #endif /* LINUX_PCI_TPH_H */\ndiff --git a/include/linux/pci.h b/include/linux/pci.h\nindex 6482549a841797..1dc3cb011dff63 100644\n--- a/include/linux/pci.h\n+++ b/include/linux/pci.h\n@@ -478,7 +478,6 @@ struct pci_dev {\n \tunsigned int\tats_enabled:1;\t\t/* Address Translation Svc */\n \tunsigned int\tpasid_enabled:1;\t/* Process Address Space ID */\n \tunsigned int\tpri_enabled:1;\t\t/* Page Request Interface */\n-\tunsigned int\ttph_enabled:1;\t\t/* TLP Processing Hints */\n \tunsigned int\tfm_enabled:1;\t\t/* Flit Mode (segment captured) */\n \tunsigned int\tis_managed:1;\t\t/* Managed via devres */\n \tunsigned int\tis_msi_managed:1;\t/* MSI release via devres installed */\n@@ -596,7 +595,10 @@ struct pci_dev {\n \tstruct gpio_desc *wake;\t\t/* WAKE# GPIO */\n \n #ifdef CONFIG_PCIE_TPH\n-\tu16\t\ttph_cap;\t/* TPH capability offset */\n+\tu16\t\ttph_cap:13;\t/* TPH capability offset */\n+\tu16\t\ttph_max_type:2; /* Negotiated max TPH requester type\n+\t\t\t\t\t between device and root port */\n+\tu16\t\ttph_enabled:1;\t/* Whether TPH is enabled */\n \tu8\t\ttph_mode;\t/* TPH mode */\n \tu8\t\ttph_req_type;\t/* TPH requester type */\n #endif\ndiff --git a/include/linux/vfio_pci_core.h b/include/linux/vfio_pci_core.h\nindex 2f3fa2787737a4..217f95aaa9db9b 100644\n--- a/include/linux/vfio_pci_core.h\n+++ b/include/linux/vfio_pci_core.h\n@@ -151,6 +151,12 @@ struct vfio_pci_core_device {\n \tstruct notifier_block\tnb;\n \tstruct rw_semaphore\tmemory_lock;\n \tstruct list_head\tdmabufs;\n+\tu8\t\t\ttph_policy;\n+\tu8\t\t\ttph_opt_in;\n+\tu32\t\t\ttph_vcap;\n+\ts64\t\t\t*tph_st_cpu;\n+\tstruct hlist_node\ttph_cpuhp_node;\n+\tstruct mutex\t\ttph_lock;\n };\n \n enum vfio_pci_io_width {\ndiff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h\nindex e41437fa17ad0e..1820bb20a460a5 100644\n--- a/include/uapi/linux/vfio.h\n+++ b/include/uapi/linux/vfio.h\n@@ -1555,6 +1555,135 @@ struct vfio_device_feature_zpci_err {\n \n #define VFIO_DEVICE_FEATURE_ZPCI_ERROR 13\n \n+/*\n+ * VFIO_DEVICE_FEATURE_TPH - Control and query VFIO TPH feature capabilities\n+ *\n+ * SET: Opt-in to enable the VFIO TPH feature for the device; flags must be\n+ * zero.\n+ * GET: Return VFIO-usable TPH capability bits in flags (see\n+ * VFIO_DEVICE_TPH_CAP_*). Returns an error if SET opt-in has not been\n+ * performed.\n+ *\n+ * Typical userspace sequence:\n+ * 1. Read virtualized PCI TPH capability via VFIO config space access to\n+ * discover underlying hardware PCI TPH support.\n+ * 2. Invoke SET to opt-in for VFIO TPH feature permission.\n+ * 3. Invoke GET to retrieve the set of TPH capabilities accessible via VFIO.\n+ * 4. Write the TPH control register through VFIO config space to activate\n+ * device TPH hardware.\n+ * 5. Program steering tag (ST) table entries by VFIO_DEVICE_FEATURE_TPH_PROGRAM\n+ * if the device has an architected ST table.\n+ * 6. Query the ST value for a given CPU ID via VFIO_DEVICE_FEATURE_TPH_RESOLVE\n+ * for DS-ST capable devices, userspace may then configure the ST through\n+ * device MMIO or firmware interfaces.\n+ */\n+#define VFIO_DEVICE_FEATURE_TPH\t\t\t14\n+\n+struct vfio_device_feature_tph {\n+\t__u32 flags;\n+};\n+\n+/*\n+ * Capability bits returned by VFIO_DEVICE_FEATURE_TPH GET\n+ */\n+\n+/*\n+ * Supports programming steering tag (ST) entries using the NONE source.\n+ * This source resolves to a zero ST value.\n+ */\n+#define VFIO_DEVICE_TPH_CAP_PROG_ST_NONE\t(1u \u003c\u003c 0)\n+/*\n+ * Supports programming steering tag (ST) entries using a CPU source handle,\n+ * for either volatile or persistent memory type.\n+ */\n+#define VFIO_DEVICE_TPH_CAP_PROG_ST_CPU\t\t(1u \u003c\u003c 1)\n+/*\n+ * Supports resolving a steering tag (ST) from a CPU source handle.\n+ */\n+#define VFIO_DEVICE_TPH_CAP_RESOLVE_CPU_ST\t(1u \u003c\u003c 2)\n+\n+/*\n+ * VFIO_DEVICE_FEATURE_TPH_PROGRAM - Batch program architected steering tag\n+ * (ST) table entries. This interface only operates on the architected ST\n+ * table described by the PCIe TPH ST Table Location field; it does not\n+ * manage device-specific (DS) ST storage or any vendor-private ST array.\n+ *\n+ * SET only\n+ *\n+ * Prerequisites before invoking this feature:\n+ * 1. Call VFIO_DEVICE_FEATURE_TPH with SET to enable vfio TPH permission;\n+ * 2. Write the TPH control register to activate device hardware TPH logic.\n+ *\n+ * @flags: IN - source type selector (see VFIO_DEVICE_TPH_SRC_*) and\n+ * steering tag namespace selector (see VFIO_DEVICE_TPH_EXTENDED) and\n+ * failure policy (see VFIO_DEVICE_TPH_REQUIRE_ST)\n+ * Note: only one source type is permitted; combining source type bits\n+ * is rejected.\n+ * @start: IN - first architected ST table index\n+ * @count: IN - number of contiguous entries to program\n+ * @srcs: IN - user pointer to array of source u32 handles (CPU ID for CPU\n+ * sources, ignored for SRC_NONE)\n+ *\n+ * Return value: \u003e=0 = number of entries successfully programmed;\n+ * \u003c0 = negative errno\n+ *\n+ * CPU offline note: When a CPU goes offline, the kernel automatically clears\n+ * all ST table entries mapped to that CPU, setting those ST values to zero.\n+ */\n+#define VFIO_DEVICE_FEATURE_TPH_PROGRAM\t\t15\n+\n+struct vfio_device_feature_tph_program {\n+\t__u32 flags;\n+\t__u16 start;\n+\t__u16 count;\n+\t__aligned_u64 srcs;\n+};\n+\n+/* Use extended 16-bit steering tag namespace */\n+#define VFIO_DEVICE_TPH_EXTENDED\t\t(1u \u003c\u003c 0)\n+/*\n+ * Stop the batch when an entry resolves to a zero steering tag.\n+ * Programming halts at that entry; the returned count\n+ * is the number of entries successfully programmed before the stop.\n+ */\n+#define VFIO_DEVICE_TPH_REQUIRE_ST\t\t(1u \u003c\u003c 1)\n+/* Source resolves to a zero steering tag (ST) */\n+#define VFIO_DEVICE_TPH_SRC_NONE\t\t(1u \u003c\u003c 2)\n+/* Source holds a volatile memory CPU ID */\n+#define VFIO_DEVICE_TPH_SRC_CPU_VOLATILE\t(1u \u003c\u003c 3)\n+/* Source holds a persistent memory CPU ID */\n+#define VFIO_DEVICE_TPH_SRC_CPU_PERSISTENT\t(1u \u003c\u003c 4)\n+\n+/*\n+ * VFIO_DEVICE_FEATURE_TPH_RESOLVE - Resolve TPH attributes from given source\n+ *\n+ * GET only\n+ *\n+ * Requires prior successful SET on VFIO_DEVICE_FEATURE_TPH, otherwise\n+ * this feature will return error.\n+ *\n+ * @flags: IN - source type selector (see VFIO_DEVICE_TPH_SRC_*)\n+ * and steering tag namespace selector (see VFIO_DEVICE_TPH_EXTENDED)\n+ * Note: only one source type is permitted (except SRC_NONE);\n+ * combining source type bits is rejected.\n+ * @src: IN - source identifier, e.g. CPU ID when SRC_CPU_VOLATILE is set\n+ * in flags\n+ * @valid: OUT - bitmap indicating valid output fields, see\n+ * VFIO_DEVICE_TPH_VALID_*\n+ * @rsv: OUT - Reserved for future extension, kernel returns zero\n+ * @st: OUT - TPH steering tag (valid when VALID_ST is set in valid)\n+ */\n+#define VFIO_DEVICE_FEATURE_TPH_RESOLVE\t\t16\n+\n+struct vfio_device_feature_tph_resolve {\n+\t__u32 flags;\n+\t__u32 src;\n+\t__u8 valid;\n+#define VFIO_DEVICE_TPH_VALID_ST (1u \u003c\u003c 0) /* st holds valid steering tag */\n+\t__u8 rsv;\n+\t__u16 st;\n+};\n+\n /* -------- API for Type1 VFIO IOMMU -------- */\n \n /**\n"
} |
| 2/1 | 2026/11/22 09:23 | agent | patch-evaluator |
22mModel:core Args: null Results: {
"EnableConfigs": [
"PCIE_TPH",
"VFIO_PCI",
"VFIO",
"PCI",
"ACPI"
],
"FocusSymbols": [
"vfio_pci_core_feature_tph",
"vfio_pci_core_feature_tph_program",
"vfio_pci_core_feature_tph_resolve",
"vfio_tph_config_write",
"vfio_tph_config_read",
"vfio_pci_tph_cpuhp_offline",
"pcie_tph_set_st_entries",
"pcie_enable_tph_ext",
"pcie_tph_get_cpu_st_ext",
"pcie_tph_dsm_supported"
],
"Reasoning": "The patch series implements support for PCIe TLP Processing Hints (TPH) in VFIO-PCI and refactors core PCIe TPH helper functions. Specifically, it adds user-facing ioctls (VFIO_DEVICE_FEATURE_TPH, VFIO_DEVICE_FEATURE_TPH_PROGRAM, VFIO_DEVICE_FEATURE_TPH_RESOLVE) for steering tag (ST) capability discovery, resolution, and batch table programming, virtualizes the PCIe TPH extended capability in VFIO config space reads/writes, integrates with the CPU hotplug subsystem to clear ST mappings when CPUs go offline, and introduces new locking and allocation paths. These changes touch reachable driver and PCI core code accepting user inputs and warrant fuzzing.",
"WorthFuzzing": true
}Instruction: You are an expert Linux kernel maintainer and security engineer.
Your job is to review a provided patch series and evaluate whether it warrants fuzzing with syzkaller.
IMPORTANT: The changes have ALREADY been applied and committed as the HEAD commit in
your workspace. Do NOT rely on internal assumptions. You must actively use your code access
tools to inspect the actual source code, callers, and surrounding context.
================================================================================
1. CORE TRIAGE PHILOSOPHY
================================================================================
The goal of patch fuzzing is to discover crashes, regressions, exposed latent bugs,
and newly triggered assertions introduced by the patch series.
- REACHABILITY IS THE PRIMARY GATE:
Fuzzing can only discover bugs in code that can actually execute in standard virtualized
environments (GCE or QEMU, utilizing software-emulated devices like USB gadgets, netdev, tun/tap).
If the modified code is structurally unreachable (see Section 2), it MUST NOT be fuzzed,
regardless of whether it adds assertions or complex logic.
- DO NOT BLINDLY TRUST "NO FUNCTIONAL CHANGE" (NFCI) OR "REFACTORING" CLAIMS:
Patch authors routinely label changes as "cleanups", "refactorings", or state
"No functional change intended". Do NOT take these claims at face value.
Code refactorings that rearrange logic, introduce helper functions, or alter state management
in core subsystems frequently introduce subtle semantic shifts or uncover latent kernel bugs.
If reachable executable code is modified or refactored, it MUST be fuzzed.
- NEW OR MODIFIED ASSERTIONS IN REACHABLE CODE MUST BE FUZZED:
When a patch introduces or modifies runtime checks or assertions (e.g., WARN_ON*, VM_WARN_ON*,
BUG_ON*, lockdep_assert*) in reachable code paths, it enforces new or stricter invariants.
Even if the author believes the invariant always holds, fuzzing is essential to verify whether
an unusual sequence of operations can violate it.
================================================================================
2. WHEN TO RETURN WorthFuzzing=false (NEGATIVE CRITERIA)
================================================================================
Return WorthFuzzing=false ONLY IF all modified code falls strictly into one or more of these categories:
- Non-kernel and non-executable changes:
* Modifications to Documentation/, comments, or spelling fixes.
* User-space directories, self-tests, samples, or scripts (e.g., tools/, samples/, scripts/, usr/)
that do not affect the compiled kernel image (vmlinux) or kernel modules.
* Purely decorative logging (e.g., message strings in pr_err, printk, dev_info) or tracepoints
that do not alter control flow or data structures.
* Build system or Kconfig changes that do not alter compiled C logic.
- Structurally unreachable hardware:
* Vendor-specific PCIe switches, SmartNICs, or GPU drivers (e.g., mlxsw, pds_core, qed,
ionic, amdgpu) requiring physical ASIC/PCIe cards not emulated in standard QEMU.
- Unreachable execution paths:
* Driver teardown callbacks (.remove, .shutdown, pci_unregister_driver) executed only during
physical PCI hot-unplug or manual sysfs driver unbinding.
* Code paths exclusive to architectures other than the target architecture.
================================================================================
3. WHEN TO RETURN WorthFuzzing=true (POSITIVE CRITERIA)
================================================================================
Return WorthFuzzing=true whenever the patch touches reachable executable code, including:
- Core Subsystems:
* Any logic modifications in memory management (mm/), synchronization/locking (kernel/locking/),
BPF, scheduler, core networking, VFS, or syscall handling.
- Refactorings and Code Cleanups:
* Any restructuring of reachable data structures, helper abstractions, or algorithm flows.
- Runtime Assertions and Defensive Checks:
* Any introduction or alteration of assertions (WARN_ON*, VM_WARN_ON*, BUG_ON*, etc.) in reachable paths.
- Reachable Drivers and Protocols:
* Drivers accessible via virtual buses (virtio, USB gadget, loopback, netlink, binder, sockets, etc.).
================================================================================
4. EXTRACTING FocusSymbols (PREVENTING DILUTION)
================================================================================
When WorthFuzzing=true, you must extract specific kernel functions into FocusSymbols to guide the fuzzer:
- AVOID UBIQUITOUS LIFECYCLE HOT-PATHS:
Do NOT list generic, ubiquitous functions called by almost every program in the corpus
(including, but not limited to: general memory allocators and deallocators, page fault
and trap handlers, or core synchronization primitives; this is not an exhaustive list).
Listing ubiquitous functions causes the fuzzer to classify thousands of unrelated tests as "focused",
which severely dilutes fuzzing effort away from the actual changes.
- TARGET SPECIFIC FEATURE LOGIC AND ENTRYPOINTS:
List functions that specifically implement the logic being added or altered, or direct API entrypoints
for the subsystem feature under review.
- HANDLING STATIC INLINE FUNCTIONS IN HEADERS (.h):
Compiler-inlined static functions (such as static inlines in mm/*.h or include/linux/*.h) lack
distinct symbol addresses in vmlinux and cannot be targeted directly by symbol coverage filters.
If the changes are primarily in static inline helpers, identify non-static, feature-specific caller
functions in .c files that exercise them (avoiding ubiquitous lifecycle wrappers).
================================================================================
5. IDENTIFYING EnableConfigs
================================================================================
Identify any specific CONFIG_ options required to properly compile and reach the modified code:
- Inspect Kconfig files and #ifdef guards; do not make assumptions.
- Check "depends on" lines in Kconfig to include any non-standard parent subsystem configs needed.
- Strip any 'CONFIG_' prefix (e.g., return "NET_IPV4" instead of "CONFIG_NET_IPV4").
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt: Target architecture: amd64
For your convenience, here is the diff of the changes:
commit 03d5f979b30c8eee0af9b8cf1923dd0e2bffa4d0
Author: syz-cluster <triage@syzkaller.com>
Date: Sun Nov 22 09:23:03 2026 +0000
syz-cluster: applied patch under review
diff --git a/drivers/pci/tph.c b/drivers/pci/tph.c
index 4d064b86befcc5..c3d940745fe4da 100644
--- a/drivers/pci/tph.c
+++ b/drivers/pci/tph.c
@@ -167,11 +167,14 @@ static u8 get_st_modes(struct pci_dev *pdev)
*/
u32 pcie_tph_get_st_table_loc(struct pci_dev *pdev)
{
- u32 reg;
+ u32 reg = 0;
+
+ if (!pdev->tph_cap)
+ return PCI_TPH_LOC_NONE;
pci_read_config_dword(pdev, pdev->tph_cap + PCI_TPH_CAP, ®);
- return FIELD_GET(PCI_TPH_CAP_LOC_MASK, reg);
+ return reg & PCI_TPH_CAP_LOC_MASK;
}
EXPORT_SYMBOL(pcie_tph_get_st_table_loc);
@@ -186,9 +189,6 @@ u16 pcie_tph_get_st_table_size(struct pci_dev *pdev)
/* Check ST table location first */
loc = pcie_tph_get_st_table_loc(pdev);
-
- /* Convert loc to match with PCI_TPH_LOC_* defined in pci_regs.h */
- loc = FIELD_PREP(PCI_TPH_CAP_LOC_MASK, loc);
if (loc != PCI_TPH_LOC_CAP)
return 0;
@@ -233,20 +233,22 @@ static int write_tag_to_st_table(struct pci_dev *pdev, int index, u16 tag)
}
/**
- * pcie_tph_get_cpu_st() - Retrieve Steering Tag for a target memory associated
- * with a specific CPU
+ * pcie_tph_get_cpu_st_ext() - Retrieve Steering Tag for a target memory
+ * associated with a specific CPU, with explicit requester type selection
* @pdev: PCI device
* @mem_type: target memory type (volatile or persistent RAM)
+ * @req_type: TPH requester type to select ST namespace
* @cpu: associated CPU id
* @tag: Steering Tag to be returned
*
- * Return the Steering Tag for a target memory that is associated with a
- * specific CPU as indicated by cpu.
+ * Return the Steering Tag for a target memory associated with a specific CPU,
+ * using the specified TPH requester type to select the correct ST namespace.
+ * Validates requester type against hardware negotiated capability limits.
*
* Return: 0 if success, otherwise negative value (-errno)
*/
-int pcie_tph_get_cpu_st(struct pci_dev *pdev, enum tph_mem_type mem_type,
- unsigned int cpu, u16 *tag)
+int pcie_tph_get_cpu_st_ext(struct pci_dev *pdev, enum tph_mem_type mem_type,
+ u8 req_type, unsigned int cpu, u16 *tag)
{
#ifdef CONFIG_ACPI
struct pci_dev *rp;
@@ -255,6 +257,10 @@ int pcie_tph_get_cpu_st(struct pci_dev *pdev, enum tph_mem_type mem_type,
u32 cpu_uid;
int ret;
+ if (req_type == PCI_TPH_REQ_DISABLE || req_type == 2 ||
+ req_type > pdev->tph_max_type)
+ return -EINVAL;
+
ret = acpi_get_cpu_uid(cpu, &cpu_uid);
if (ret != 0)
return ret;
@@ -270,35 +276,54 @@ int pcie_tph_get_cpu_st(struct pci_dev *pdev, enum tph_mem_type mem_type,
return -EINVAL;
}
- *tag = tph_extract_tag(mem_type, pdev->tph_req_type, &info);
+ *tag = tph_extract_tag(mem_type, req_type, &info);
- pci_dbg(pdev, "get steering tag: mem_type=%s, cpu=%d, tag=%#04x\n",
+ pci_dbg(pdev, "get steering tag: mem_type=%s, req_type=%u, cpu=%d, tag=%#04x\n",
(mem_type == TPH_MEM_TYPE_VM) ? "volatile" : "persistent",
- cpu, *tag);
+ req_type, cpu, *tag);
return 0;
#else
return -ENODEV;
#endif
}
-EXPORT_SYMBOL(pcie_tph_get_cpu_st);
+EXPORT_SYMBOL(pcie_tph_get_cpu_st_ext);
/**
- * pcie_tph_set_st_entry() - Set Steering Tag in the ST table entry
+ * pcie_tph_get_cpu_st() - Retrieve Steering Tag for a target memory associated
+ * with a specific CPU
* @pdev: PCI device
- * @index: ST table entry index
- * @tag: Steering Tag to be written
+ * @mem_type: target memory type (volatile or persistent RAM)
+ * @cpu: associated CPU id
+ * @tag: Steering Tag to be returned
*
- * Figure out the proper location of ST table, either in the MSI-X table or
- * in the TPH Extended Capability space, and write the Steering Tag into
- * the ST entry pointed by index.
+ * Return the Steering Tag for a target memory associated with a specific CPU,
+ * using the default negotiated TPH requester type.
*
* Return: 0 if success, otherwise negative value (-errno)
*/
-int pcie_tph_set_st_entry(struct pci_dev *pdev, unsigned int index, u16 tag)
+int pcie_tph_get_cpu_st(struct pci_dev *pdev, enum tph_mem_type mem_type,
+ unsigned int cpu, u16 *tag)
+{
+ return pcie_tph_get_cpu_st_ext(pdev, mem_type, pdev->tph_max_type,
+ cpu, tag);
+}
+EXPORT_SYMBOL(pcie_tph_get_cpu_st);
+
+/**
+ * pcie_tph_set_st_entries - Batch set Steering Tag entries in the ST table
+ * @pdev: PCI device
+ * @start: starting ST table index
+ * @count: number of contiguous entries to write
+ * @tags: array of u16 tag values to program
+ *
+ * Return: number of successfully written entries (>0), or negative errno
+ */
+int pcie_tph_set_st_entries(struct pci_dev *pdev, unsigned int start,
+ unsigned int count, const u16 *tags)
{
- u32 loc;
int err = 0;
+ u32 loc, i;
if (!pdev->tph_cap)
return -EINVAL;
@@ -306,9 +331,12 @@ int pcie_tph_set_st_entry(struct pci_dev *pdev, unsigned int index, u16 tag)
if (!pdev->tph_enabled)
return -EINVAL;
+ if (!count)
+ return -EINVAL;
+
/* No need to write tag if device is in "No ST Mode" */
if (pdev->tph_mode == PCI_TPH_ST_NS_MODE)
- return 0;
+ return count;
/*
* Disable TPH before updating ST to avoid potential instability as
@@ -317,31 +345,47 @@ int pcie_tph_set_st_entry(struct pci_dev *pdev, unsigned int index, u16 tag)
set_ctrl_reg_req_en(pdev, PCI_TPH_REQ_DISABLE);
loc = pcie_tph_get_st_table_loc(pdev);
- /* Convert loc to match with PCI_TPH_LOC_* */
- loc = FIELD_PREP(PCI_TPH_CAP_LOC_MASK, loc);
-
- switch (loc) {
- case PCI_TPH_LOC_MSIX:
- err = pci_msix_write_tph_tag(pdev, index, tag);
- break;
- case PCI_TPH_LOC_CAP:
- err = write_tag_to_st_table(pdev, index, tag);
- break;
- default:
- err = -EINVAL;
- }
-
- if (err) {
- pcie_disable_tph(pdev);
- return err;
+ for (i = 0; i < count; i++) {
+ switch (loc) {
+ case PCI_TPH_LOC_MSIX:
+ err = pci_msix_write_tph_tag(pdev, start + i, tags[i]);
+ break;
+ case PCI_TPH_LOC_CAP:
+ err = write_tag_to_st_table(pdev, start + i, tags[i]);
+ break;
+ default:
+ err = -EINVAL;
+ }
+ if (err != 0) {
+ pci_err(pdev, "failed to set steering tag: %s table, index=%u, tags=%u, ret=%d\n",
+ (loc == PCI_TPH_LOC_MSIX) ? "MSI-X" : "ST",
+ start + i, tags[i], err);
+ pcie_disable_tph(pdev);
+ return i > 0 ? i : (err > 0 ? -EINVAL : err);
+ }
}
set_ctrl_reg_req_en(pdev, pdev->tph_req_type);
- pci_dbg(pdev, "set steering tag: %s table, index=%d, tag=%#04x\n",
- (loc == PCI_TPH_LOC_MSIX) ? "MSI-X" : "ST", index, tag);
+ pci_dbg(pdev, "batch set steering tag: %s table, start=%u, count=%u success!\n",
+ (loc == PCI_TPH_LOC_MSIX) ? "MSI-X" : "ST", start, count);
- return 0;
+ return count;
+}
+EXPORT_SYMBOL(pcie_tph_set_st_entries);
+
+/**
+ * pcie_tph_set_st_entry() - Set Steering Tag in the ST table entry
+ * @pdev: PCI device
+ * @index: ST table entry index
+ * @tag: Steering Tag to be written
+ *
+ * Return: 0 if success, otherwise negative value (-errno)
+ */
+int pcie_tph_set_st_entry(struct pci_dev *pdev, unsigned int index, u16 tag)
+{
+ int ret = pcie_tph_set_st_entries(pdev, index, 1, &tag);
+ return ret == 1 ? 0 : ret;
}
EXPORT_SYMBOL(pcie_tph_set_st_entry);
@@ -368,26 +412,21 @@ void pcie_disable_tph(struct pci_dev *pdev)
EXPORT_SYMBOL(pcie_disable_tph);
/**
- * pcie_enable_tph - Enable TPH support for device using a specific ST mode
+ * pcie_enable_tph_ext - Enable TPH support with specific ST mode and
+ * requester type
* @pdev: PCI device
- * @mode: ST mode to enable. Current supported modes include:
+ * @mode: ST mode to enable: PCI_TPH_ST_(NS_MODE / IV_MODE / DS_MODE)
+ * @req_type: Requester type to enable: PCI_TPH_REQ_(TPH_ONLY / EXT_TPH)
*
- * - PCI_TPH_ST_NS_MODE: NO ST Mode
- * - PCI_TPH_ST_IV_MODE: Interrupt Vector Mode
- * - PCI_TPH_ST_DS_MODE: Device Specific Mode
- *
- * Check whether the mode is actually supported by the device before enabling
- * and return an error if not. Additionally determine what types of requests,
- * TPH or extended TPH, can be issued by the device based on its TPH requester
- * capability and the Root Port's completer capability.
+ * Check whether the mode and requester type is actually supported by the
+ * device before enabling and return an error if not.
*
* Return: 0 on success, otherwise negative value (-errno)
*/
-int pcie_enable_tph(struct pci_dev *pdev, int mode)
+int pcie_enable_tph_ext(struct pci_dev *pdev, u8 mode, u8 req_type)
{
u32 reg;
u8 dev_modes;
- u8 rp_req_type;
/* Honor "notph" kernel parameter */
if (pci_tph_disabled)
@@ -399,6 +438,14 @@ int pcie_enable_tph(struct pci_dev *pdev, int mode)
if (pdev->tph_enabled)
return -EBUSY;
+ if (pdev->tph_max_type == PCI_TPH_REQ_DISABLE)
+ return -EINVAL;
+
+ /* Sanitize and check TPH requester type compatibility */
+ if (req_type == PCI_TPH_REQ_DISABLE || req_type == 2 ||
+ req_type > pdev->tph_max_type)
+ return -EINVAL;
+
/* Sanitize and check ST mode compatibility */
mode &= PCI_TPH_CTRL_MODE_SEL_MASK;
dev_modes = get_st_modes(pdev);
@@ -407,23 +454,7 @@ int pcie_enable_tph(struct pci_dev *pdev, int mode)
pdev->tph_mode = mode;
- /* Get req_type supported by device and its Root Port */
- pci_read_config_dword(pdev, pdev->tph_cap + PCI_TPH_CAP, ®);
- if (FIELD_GET(PCI_TPH_CAP_EXT_TPH, reg))
- pdev->tph_req_type = PCI_TPH_REQ_EXT_TPH;
- else
- pdev->tph_req_type = PCI_TPH_REQ_TPH_ONLY;
-
- /* Check if the device is behind a Root Port */
- if (pci_pcie_type(pdev) != PCI_EXP_TYPE_RC_END) {
- rp_req_type = get_rp_completer_type(pdev);
-
- /* Final req_type is the smallest value of two */
- pdev->tph_req_type = min(pdev->tph_req_type, rp_req_type);
- }
-
- if (pdev->tph_req_type == PCI_TPH_REQ_DISABLE)
- return -EINVAL;
+ pdev->tph_req_type = req_type;
/* Write them into TPH control register */
pci_read_config_dword(pdev, pdev->tph_cap + PCI_TPH_CTRL, ®);
@@ -437,6 +468,23 @@ int pcie_enable_tph(struct pci_dev *pdev, int mode)
return 0;
}
+EXPORT_SYMBOL(pcie_enable_tph_ext);
+
+/**
+ * pcie_enable_tph - Enable TPH support for device using a specific ST mode
+ * @pdev: PCI device
+ * @mode: ST mode to enable: PCI_TPH_ST_(NS_MODE / IV_MODE / DS_MODE)
+ *
+ * Wrapper for pcie_enable_tph_ext(), automatically uses the pre-cached
+ * tph_max_type value (negotiated maximum requester type between device and
+ * root port).
+ *
+ * Return: 0 on success, otherwise negative value (-errno)
+ */
+int pcie_enable_tph(struct pci_dev *pdev, u8 mode)
+{
+ return pcie_enable_tph_ext(pdev, mode, pdev->tph_max_type);
+}
EXPORT_SYMBOL(pcie_enable_tph);
void pci_restore_tph_state(struct pci_dev *pdev)
@@ -510,14 +558,60 @@ void pci_no_tph(void)
void pci_tph_init(struct pci_dev *pdev)
{
+ u8 tph_req_type, rp_req_type;
int num_entries;
u32 save_size;
+ u32 reg = 0;
pdev->tph_cap = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_TPH);
if (!pdev->tph_cap)
return;
+ /* Get req_type supported by device and its Root Port */
+ pci_read_config_dword(pdev, pdev->tph_cap + PCI_TPH_CAP, ®);
+ if (FIELD_GET(PCI_TPH_CAP_EXT_TPH, reg))
+ tph_req_type = PCI_TPH_REQ_EXT_TPH;
+ else
+ tph_req_type = PCI_TPH_REQ_TPH_ONLY;
+
+ /* Check if the device is behind a Root Port */
+ if (pci_pcie_type(pdev) != PCI_EXP_TYPE_RC_END) {
+ rp_req_type = get_rp_completer_type(pdev);
+ /* Final req_type is the smallest value of two */
+ tph_req_type = min(tph_req_type, rp_req_type);
+ }
+
+ pdev->tph_max_type = tph_req_type;
+
num_entries = pcie_tph_get_st_table_size(pdev);
save_size = sizeof(u32) + num_entries * sizeof(u16);
pci_add_ext_cap_save_buffer(pdev, PCI_EXT_CAP_ID_TPH, save_size);
}
+
+/**
+ * pcie_tph_dsm_supported - Check if root port exposes TPH ST _DSM
+ * @pdev: target PCI device
+ *
+ * Return true if root port of @pdev provides TPH ST DSM function,
+ * false otherwise (ACPI disabled or DSM missing).
+ */
+bool pcie_tph_dsm_supported(struct pci_dev *pdev)
+{
+#ifdef CONFIG_ACPI
+ struct pci_dev *rp = pcie_find_root_port(pdev);
+ acpi_handle handle;
+
+ if (!rp || !rp->bus || !rp->bus->bridge)
+ return false;
+
+ handle = ACPI_HANDLE(rp->bus->bridge);
+ if (!handle)
+ return false;
+
+ return acpi_check_dsm(handle, &pci_acpi_dsm_guid, 7,
+ BIT(TPH_ST_DSM_FUNC_INDEX));
+#else
+ return false;
+#endif
+}
+EXPORT_SYMBOL_GPL(pcie_tph_dsm_supported);
diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c
index e7c012febe9124..0369069e7f6a27 100644
--- a/drivers/vfio/pci/vfio_pci.c
+++ b/drivers/vfio/pci/vfio_pci.c
@@ -60,6 +60,29 @@ static bool disable_denylist;
module_param(disable_denylist, bool, 0444);
MODULE_PARM_DESC(disable_denylist, "Disable use of device denylist. Disabling the denylist allows binding to devices with known errata that may lead to exploitable stability or security issues when accessed by untrusted users.");
+static unsigned int tph_policy;
+static int tph_policy_set(const char *val, const struct kernel_param *kp)
+{
+ return param_set_uint_minmax(val, kp, VFIO_PCI_TPH_POLICY_NO_ST,
+ VFIO_PCI_TPH_POLICY_DS_ST);
+}
+static const struct kernel_param_ops tph_param_ops = {
+ .set = tph_policy_set,
+ .get = param_get_uint,
+};
+module_param_cb(tph_policy, &tph_param_ops, &tph_policy, 0644);
+MODULE_PARM_DESC(tph_policy,
+ "Global TPH policy level (0=default No-ST):\n"
+ "0 = No-ST mode: ST programming unavailable\n"
+ "1 = Add IV-ST mode: ST programming supports NONE/CPU sources\n"
+ "2 = Add DS-ST mode: RESOLVE returns ST for CPU sources;\n"
+ " ST programming supports NONE/CPU sources\n"
+ " Note: In this 'Add DS-ST mode', device-specific ST tables are\n"
+ " not preserved across PCI resets, userspace must re-establish\n"
+ " ST state after reset. The kernel cannot validate these ST\n"
+ " entries, so this mode is not recommended for general\n"
+ " virtualization usecases.");
+
static bool vfio_pci_dev_in_denylist(struct pci_dev *pdev)
{
switch (pdev->vendor) {
@@ -142,6 +165,7 @@ static int vfio_pci_init_dev(struct vfio_device *core_vdev)
#ifdef CONFIG_VFIO_PCI_VGA
vdev->disable_vga = disable_vga;
#endif
+ vdev->tph_policy = tph_policy;
return vfio_pci_core_init_dev(core_vdev);
}
diff --git a/drivers/vfio/pci/vfio_pci_config.c b/drivers/vfio/pci/vfio_pci_config.c
index 9914f3ac69aef9..8e47f84216b0dd 100644
--- a/drivers/vfio/pci/vfio_pci_config.c
+++ b/drivers/vfio/pci/vfio_pci_config.c
@@ -20,8 +20,10 @@
* must be negotiated with the underlying OS.
*/
+#include <linux/bitfield.h>
#include <linux/fs.h>
#include <linux/pci.h>
+#include <linux/pci-tph.h>
#include <linux/uaccess.h>
#include <linux/vfio.h>
#include <linux/slab.h>
@@ -1085,6 +1087,156 @@ static int __init init_pci_ext_cap_pwr_perm(struct perm_bits *perm)
return 0;
}
+static int vfio_find_cap_start(struct vfio_pci_core_device *vdev, int pos)
+{
+ u8 cap;
+ int base = (pos >= PCI_CFG_SPACE_SIZE) ? PCI_CFG_SPACE_SIZE :
+ PCI_STD_HEADER_SIZEOF;
+ cap = vdev->pci_config_map[pos];
+
+ if (cap == PCI_CAP_ID_BASIC)
+ return 0;
+
+ /* XXX Can we have to abutting capabilities of the same type? */
+ while (pos - 1 >= base && vdev->pci_config_map[pos - 1] == cap)
+ pos--;
+
+ return pos;
+}
+
+/* Permissions for TPH extended capability */
+static int __init init_pci_ext_cap_tph_perm(struct perm_bits *perm)
+{
+ /*
+ * We only virtualize the TPH header (excluding the ST table).
+ * For the ST table (if any), the read operation returns 0 by
+ * default, and the write operation is discarded by default.
+ */
+ if (alloc_perm_bits(perm, PCI_TPH_BASE_SIZEOF))
+ return -ENOMEM;
+
+ p_setd(perm, 0, ALL_VIRT, NO_WRITE);
+ p_setd(perm, PCI_TPH_CAP, ALL_VIRT, NO_WRITE);
+
+ p_setd(perm, PCI_TPH_CTRL, ALL_VIRT,
+ PCI_TPH_CTRL_MODE_SEL_MASK | PCI_TPH_CTRL_REQ_EN_MASK);
+
+ return 0;
+}
+
+static void vfio_tph_vcap_rewrite(struct vfio_pci_core_device *vdev, int pos)
+{
+ __le32 *vptr = (__le32 *)&vdev->vconfig[pos + PCI_TPH_CAP];
+ struct pci_dev *pdev = vdev->pdev;
+ u32 val = le32_to_cpu(*vptr);
+
+ if (!pcie_ext_tph_supported(pdev)) {
+ /* Remove extended TPH if root-port doesn't support */
+ val &= ~PCI_TPH_CAP_EXT_TPH;
+ }
+
+ if (vdev->tph_policy == VFIO_PCI_TPH_POLICY_NO_ST) {
+ /*
+ * NO-ST policy: mask IV/DS mode, ST location and ST size fields.
+ * Userspace only sees NO-ST capability.
+ */
+ val &= ~(PCI_TPH_CAP_ST_IV | PCI_TPH_CAP_ST_DS |
+ PCI_TPH_CAP_LOC_MASK | PCI_TPH_CAP_ST_MASK);
+ } else if (vdev->tph_policy == VFIO_PCI_TPH_POLICY_IV_ST) {
+ /*
+ * Add IV policy: mask DS mode, drop ST location and size
+ * if device does not support IV mode.
+ */
+ val &= ~PCI_TPH_CAP_ST_DS;
+ if (!(val & PCI_TPH_CAP_ST_IV))
+ val &= ~(PCI_TPH_CAP_LOC_MASK | PCI_TPH_CAP_ST_MASK);
+ }
+
+ *vptr = cpu_to_le32(val);
+
+ /* Cache the final virtualized TPH capability value */
+ vdev->tph_vcap = val;
+}
+
+static int vfio_tph_config_read(struct vfio_pci_core_device *vdev, int pos,
+ int count, struct perm_bits *perm,
+ int offset, __le32 *val)
+{
+ int ret;
+
+ if (offset >= PCI_TPH_BASE_SIZEOF) {
+ *val = cpu_to_le32(0);
+ return count;
+ }
+
+ if (offset < PCI_TPH_CTRL)
+ return vfio_default_config_read(vdev, pos, count, perm,
+ offset, val);
+
+ /* Read the actual device value for CTRL register. */
+ ret = vfio_user_config_read(vdev->pdev, pos, val, count);
+ return ret != 0 ? ret : count;
+}
+
+static int vfio_tph_config_write(struct vfio_pci_core_device *vdev, int pos,
+ int count, struct perm_bits *perm,
+ int offset, __le32 val)
+{
+ u16 start = vfio_find_cap_start(vdev, pos);
+ struct pci_dev *pdev = vdev->pdev;
+ u32 org_ctrl, new_ctrl, cap;
+ u8 mode, req, org_req;
+ __le32 ctrl_val = 0;
+ u16 cmd;
+ int ret;
+
+ if (!vdev->tph_opt_in || offset >= PCI_TPH_BASE_SIZEOF ||
+ offset < PCI_TPH_CTRL)
+ return count;
+
+ cmd = vfio_pci_memory_lock_and_enable(vdev);
+
+ /*
+ * Synchronize the CTRL value of the hardware to the virt. Otherwise,
+ * the value will be inconsistent when the device is reset.
+ */
+ 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_ctrl = le32_to_cpu(ctrl_val);
+
+ /* Do write operation to virt. */
+ ret = vfio_default_config_write(vdev, pos, count, perm, offset, val);
+ if (ret != count)
+ goto out;
+
+ /* Reads the TPH_CTRL value after the write operation. */
+ new_ctrl = le32_to_cpu(*(__le32 *)&vdev->vconfig[start + PCI_TPH_CTRL]);
+ if (new_ctrl == org_ctrl)
+ goto out; /* Exit because there is no change. */
+
+ 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_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. */
+
+ 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);
+
+out:
+ vfio_pci_memory_unlock_and_restore(vdev, cmd);
+ return count;
+}
+
/*
* Initialize the shared permission tables
*/
@@ -1100,6 +1252,7 @@ void vfio_pci_uninit_perm_bits(void)
free_perm_bits(&ecap_perms[PCI_EXT_CAP_ID_ERR]);
free_perm_bits(&ecap_perms[PCI_EXT_CAP_ID_PWR]);
+ free_perm_bits(&ecap_perms[PCI_EXT_CAP_ID_TPH]);
}
int __init vfio_pci_init_perm_bits(void)
@@ -1120,6 +1273,9 @@ int __init vfio_pci_init_perm_bits(void)
/* Extended capabilities */
ret |= init_pci_ext_cap_err_perm(&ecap_perms[PCI_EXT_CAP_ID_ERR]);
ret |= init_pci_ext_cap_pwr_perm(&ecap_perms[PCI_EXT_CAP_ID_PWR]);
+ ret |= init_pci_ext_cap_tph_perm(&ecap_perms[PCI_EXT_CAP_ID_TPH]);
+ ecap_perms[PCI_EXT_CAP_ID_TPH].readfn = vfio_tph_config_read;
+ ecap_perms[PCI_EXT_CAP_ID_TPH].writefn = vfio_tph_config_write;
ecap_perms[PCI_EXT_CAP_ID_VNDR].writefn = vfio_raw_config_write;
ecap_perms[PCI_EXT_CAP_ID_DVSEC].writefn = vfio_raw_config_write;
@@ -1129,23 +1285,6 @@ int __init vfio_pci_init_perm_bits(void)
return ret;
}
-static int vfio_find_cap_start(struct vfio_pci_core_device *vdev, int pos)
-{
- u8 cap;
- int base = (pos >= PCI_CFG_SPACE_SIZE) ? PCI_CFG_SPACE_SIZE :
- PCI_STD_HEADER_SIZEOF;
- cap = vdev->pci_config_map[pos];
-
- if (cap == PCI_CAP_ID_BASIC)
- return 0;
-
- /* XXX Can we have to abutting capabilities of the same type? */
- while (pos - 1 >= base && vdev->pci_config_map[pos - 1] == cap)
- pos--;
-
- return pos;
-}
-
static int vfio_msi_config_read(struct vfio_pci_core_device *vdev, int pos,
int count, struct perm_bits *perm,
int offset, __le32 *val)
@@ -1702,6 +1841,8 @@ static int vfio_ecap_init(struct vfio_pci_core_device *vdev)
ret = vfio_fill_vconfig_bytes(vdev, epos, len);
if (ret)
return ret;
+ if (ecap == PCI_EXT_CAP_ID_TPH)
+ vfio_tph_vcap_rewrite(vdev, epos);
/*
* If we're just using this capability to anchor the list,
diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c
index fcbb2da860e2ac..a9cdcb0f95a011 100644
--- a/drivers/vfio/pci/vfio_pci_core.c
+++ b/drivers/vfio/pci/vfio_pci_core.c
@@ -11,6 +11,7 @@
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/aperture.h>
+#include <linux/cpuhotplug.h>
#include <linux/debugfs.h>
#include <linux/device.h>
#include <linux/eventfd.h>
@@ -22,6 +23,7 @@
#include <linux/notifier.h>
#include <linux/pagemap.h>
#include <linux/pci.h>
+#include <linux/pci-tph.h>
#include <linux/pm_runtime.h>
#include <linux/slab.h>
#include <linux/types.h>
@@ -128,10 +130,20 @@ static int vfio_pci_core_debugfs_disable_idle_d3(struct seq_file *seq,
return 0;
}
+static int vfio_pci_core_debugfs_tph(struct seq_file *seq,
+ void *data)
+{
+ struct vfio_pci_core_device *vdev = vfio_pci_core_debugfs_private(seq);
+
+ seq_printf(seq, "policy=%u cap-virt=0x%x opt-in=%u\n",
+ vdev->tph_policy, vdev->tph_vcap, vdev->tph_opt_in);
+ return 0;
+}
+
/*
- * disable_idle_d3 and nointxmask are writable module parameters latched
- * per device at init, so a device's effective value can differ from the
- * current parameter setting. Expose the per-device (read-only) values
+ * disable_idle_d3, nointxmask and tph_policy are writable module parameters
+ * latched per device at init, so a device's effective value can differ from
+ * the current parameter setting. Expose the per-device (read-only) values
* here for visibility; read-only parameters can't drift and are omitted.
*/
static void vfio_pci_core_debugfs_init(struct vfio_pci_core_device *vdev)
@@ -147,6 +159,8 @@ static void vfio_pci_core_debugfs_init(struct vfio_pci_core_device *vdev)
vfio_pci_core_debugfs_nointxmask);
debugfs_create_devm_seqfile(dev, "disable_idle_d3", pci_dir,
vfio_pci_core_debugfs_disable_idle_d3);
+ debugfs_create_devm_seqfile(dev, "tph", pci_dir,
+ vfio_pci_core_debugfs_tph);
}
#else
static inline void vfio_pci_core_debugfs_init(struct vfio_pci_core_device *vdev)
@@ -575,6 +589,9 @@ static void vfio_pci_core_map_bars(struct vfio_pci_core_device *vdev)
}
}
+static int vfio_pci_tph_dev_init(struct vfio_pci_core_device *vdev);
+static void vfio_pci_tph_dev_deinit(struct vfio_pci_core_device *vdev);
+
int vfio_pci_core_enable(struct vfio_pci_core_device *vdev)
{
struct pci_dev *pdev = vdev->pdev;
@@ -601,6 +618,8 @@ int vfio_pci_core_enable(struct vfio_pci_core_device *vdev)
goto out_disable_device;
vdev->reset_works = !ret;
+ /* Reset TPH state for new user session */
+ pcie_disable_tph(vdev->pdev);
pci_save_state(pdev);
vdev->pci_saved_state = pci_store_saved_state(pdev);
if (!vdev->pci_saved_state)
@@ -629,6 +648,11 @@ int vfio_pci_core_enable(struct vfio_pci_core_device *vdev)
if (ret)
goto out_free_zdev;
+ /* After identifying the capability, initialize TPH. */
+ ret = vfio_pci_tph_dev_init(vdev);
+ if (ret != 0)
+ goto out_free_config;
+
msix_pos = pdev->msix_cap;
if (msix_pos) {
u16 flags;
@@ -653,6 +677,8 @@ int vfio_pci_core_enable(struct vfio_pci_core_device *vdev)
return 0;
+out_free_config:
+ vfio_config_free(vdev);
out_free_zdev:
vfio_pci_zdev_close_device(vdev);
out_free_state:
@@ -726,6 +752,8 @@ void vfio_pci_core_disable(struct vfio_pci_core_device *vdev)
kfree(vdev->region);
vdev->region = NULL; /* don't krealloc a freed pointer */
+ vfio_pci_tph_dev_deinit(vdev);
+
vfio_config_free(vdev);
for (i = 0; i < PCI_STD_NUM_BARS; i++) {
@@ -748,6 +776,9 @@ void vfio_pci_core_disable(struct vfio_pci_core_device *vdev)
vfio_pci_zdev_close_device(vdev);
+ /* Reset TPH state on user session exit */
+ pcie_disable_tph(vdev->pdev);
+
/*
* If we have saved state, restore it. If we can reset the device,
* even better. Resetting with current state seems better than
@@ -1594,6 +1625,348 @@ static int vfio_pci_core_feature_token(struct vfio_pci_core_device *vdev,
return 0;
}
+static enum cpuhp_state vfio_tph_cpuhp_state;
+static u32 vfio_pci_tph_get_st_table_size(struct vfio_pci_core_device *vdev);
+
+static int vfio_pci_tph_cpuhp_offline(unsigned int cpu, struct hlist_node *node)
+{
+ struct vfio_pci_core_device *vdev =
+ hlist_entry(node, struct vfio_pci_core_device, tph_cpuhp_node);
+ u32 st_size = vfio_pci_tph_get_st_table_size(vdev);
+ int i;
+
+ if (vdev->tph_st_cpu == NULL)
+ return 0;
+
+ mutex_lock(&vdev->tph_lock);
+ for (i = 0; i < st_size; i++) {
+ if (vdev->tph_st_cpu[i] != (s64)cpu)
+ continue;
+ pcie_tph_set_st_entry(vdev->pdev, i, 0);
+ vdev->tph_st_cpu[i] = -1;
+ }
+ mutex_unlock(&vdev->tph_lock);
+
+ return 0;
+}
+
+static int vfio_pci_tph_cpuhp_init(void)
+{
+ int ret;
+
+ ret = cpuhp_setup_state_multi(CPUHP_AP_ONLINE_DYN,
+ "vfio/pci/tph:online",
+ NULL,
+ vfio_pci_tph_cpuhp_offline);
+ if (ret < 0)
+ return ret;
+
+ vfio_tph_cpuhp_state = ret;
+ return 0;
+}
+
+static void vfio_pci_tph_cpuhp_deinit(void)
+{
+ cpuhp_remove_multi_state(vfio_tph_cpuhp_state);
+}
+
+static bool vfio_pci_tph_has_architected_st(struct vfio_pci_core_device *vdev)
+{
+ u32 loc = vdev->tph_vcap & PCI_TPH_CAP_LOC_MASK;
+
+ return (loc == PCI_TPH_LOC_CAP || loc == PCI_TPH_LOC_MSIX) &&
+ (vfio_pci_tph_get_st_table_size(vdev) > 0);
+}
+
+static int vfio_pci_tph_dev_init(struct vfio_pci_core_device *vdev)
+{
+ bool has_arch_st;
+ u32 st_size;
+ int i, ret;
+
+ vdev->tph_opt_in = 0;
+ vdev->tph_st_cpu = NULL;
+
+ has_arch_st = vfio_pci_tph_has_architected_st(vdev);
+ if (!has_arch_st)
+ return 0;
+
+ ret = cpuhp_state_add_instance_nocalls(vfio_tph_cpuhp_state,
+ &vdev->tph_cpuhp_node);
+ if (ret != 0)
+ return ret;
+
+ st_size = vfio_pci_tph_get_st_table_size(vdev);
+ vdev->tph_st_cpu = kcalloc(st_size, sizeof(*vdev->tph_st_cpu),
+ GFP_KERNEL);
+ if (vdev->tph_st_cpu == NULL) {
+ cpuhp_state_remove_instance_nocalls(vfio_tph_cpuhp_state,
+ &vdev->tph_cpuhp_node);
+ return -ENOMEM;
+ }
+ for (i = 0; i < st_size; i++)
+ vdev->tph_st_cpu[i] = -1;
+
+ return 0;
+}
+
+static void vfio_pci_tph_dev_deinit(struct vfio_pci_core_device *vdev)
+{
+ bool has_arch_st;
+
+ has_arch_st = vfio_pci_tph_has_architected_st(vdev);
+ if (!has_arch_st)
+ return;
+
+ kfree(vdev->tph_st_cpu);
+ vdev->tph_st_cpu = NULL;
+ cpuhp_state_remove_instance_nocalls(vfio_tph_cpuhp_state,
+ &vdev->tph_cpuhp_node);
+}
+
+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)
+ cap |= 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;
+}
+
+static int vfio_pci_core_feature_tph(struct vfio_pci_core_device *vdev,
+ u32 flags,
+ struct vfio_device_feature_tph __user *arg,
+ size_t argsz)
+{
+ struct vfio_device_feature_tph tph;
+ int ret;
+
+ if (!pcie_std_tph_supported(vdev->pdev))
+ return -EOPNOTSUPP;
+
+ ret = vfio_check_feature(flags, argsz,
+ VFIO_DEVICE_FEATURE_GET | VFIO_DEVICE_FEATURE_SET,
+ sizeof(tph));
+ if (ret != 1)
+ return ret;
+
+ if (copy_from_user(&tph, arg, sizeof(tph)))
+ return -EFAULT;
+
+ if (flags & VFIO_DEVICE_FEATURE_SET) {
+ if (tph.flags != 0)
+ return -EINVAL;
+ vdev->tph_opt_in = 1;
+ return 0;
+ }
+
+ if (!vdev->tph_opt_in)
+ return -EINVAL;
+
+ tph.flags = vfio_pci_tph_get_capability(vdev);
+
+ return copy_to_user(arg, &tph, sizeof(tph)) ? -EFAULT : 0;
+}
+
+static u32 vfio_pci_tph_get_src_mask(struct vfio_pci_core_device *vdev)
+{
+ 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;
+}
+
+static u32 vfio_pci_tph_get_st_table_size(struct vfio_pci_core_device *vdev)
+{
+ struct pci_dev *pdev = vdev->pdev;
+ u32 loc = pcie_tph_get_st_table_loc(pdev);
+ int ret;
+
+ if (loc == PCI_TPH_LOC_CAP) {
+ return pcie_tph_get_st_table_size(pdev);
+ } else if (loc == PCI_TPH_LOC_MSIX) {
+ ret = pci_msix_vec_count(pdev);
+ if (ret < 0)
+ return 0;
+ return ret;
+ } else {
+ return 0;
+ }
+}
+
+static int vfio_pci_tph_resolve_st_tag(struct pci_dev *pdev, u32 src_bits,
+ u32 src_handle, bool extended, u16 *st)
+{
+ u8 req_type = extended ? PCI_TPH_REQ_EXT_TPH : PCI_TPH_REQ_TPH_ONLY;
+ int ret = 0;
+
+ if (src_bits & VFIO_DEVICE_TPH_SRC_NONE)
+ *st = 0;
+ else if (src_bits & VFIO_DEVICE_TPH_SRC_CPU_VOLATILE)
+ ret = pcie_tph_get_cpu_st_ext(pdev, TPH_MEM_TYPE_VM,
+ req_type, src_handle, st);
+ else if (src_bits & VFIO_DEVICE_TPH_SRC_CPU_PERSISTENT)
+ ret = pcie_tph_get_cpu_st_ext(pdev, TPH_MEM_TYPE_PM,
+ req_type, src_handle, st);
+ else
+ ret = -EINVAL;
+
+ if (ret != 0)
+ *st = 0;
+
+ return ret;
+}
+
+static int vfio_pci_core_feature_tph_program(struct vfio_pci_core_device *vdev,
+ u32 flags,
+ struct vfio_device_feature_tph_program __user *arg,
+ size_t argsz)
+{
+ struct vfio_device_feature_tph_program program;
+ u32 user_flags, src_mask, st_size;
+ struct pci_dev *pdev = vdev->pdev;
+ bool extended, stop_on_zero;
+ u32 *src_handle = NULL;
+ int ret, i, k, written;
+ u16 *tags = NULL;
+ u16 cmd;
+
+ if (!vdev->tph_opt_in ||
+ !vfio_pci_tph_has_architected_st(vdev))
+ return -EOPNOTSUPP;
+
+ ret = vfio_check_feature(flags, argsz, VFIO_DEVICE_FEATURE_SET,
+ sizeof(program));
+ if (ret != 1)
+ return ret;
+
+ if (copy_from_user(&program, arg, sizeof(program)))
+ return -EFAULT;
+
+ user_flags = program.flags;
+ extended = !!(user_flags & VFIO_DEVICE_TPH_EXTENDED);
+ if (extended && !pcie_ext_tph_supported(vdev->pdev))
+ return -EOPNOTSUPP;
+ user_flags &= ~VFIO_DEVICE_TPH_EXTENDED;
+
+ stop_on_zero = !!(user_flags & VFIO_DEVICE_TPH_REQUIRE_ST);
+ if (stop_on_zero && (user_flags & VFIO_DEVICE_TPH_SRC_NONE))
+ return -EINVAL;
+ user_flags &= ~VFIO_DEVICE_TPH_REQUIRE_ST;
+
+ src_mask = vfio_pci_tph_get_src_mask(vdev);
+ if (user_flags & ~src_mask || !is_power_of_2(user_flags))
+ return -EINVAL;
+
+ st_size = vfio_pci_tph_get_st_table_size(vdev);
+ if (program.start >= st_size || program.count == 0 ||
+ program.count > st_size - program.start)
+ return -EINVAL;
+
+ if (!(user_flags & VFIO_DEVICE_TPH_SRC_NONE)) {
+ src_handle = memdup_array_user(u64_to_user_ptr(program.srcs),
+ program.count, sizeof(u32));
+ if (IS_ERR(src_handle))
+ return PTR_ERR(src_handle);
+ }
+ tags = kcalloc(program.count, sizeof(u16), GFP_KERNEL_ACCOUNT);
+ if (!tags) {
+ ret = -ENOMEM;
+ goto out;
+ }
+
+ cpus_read_lock();
+
+ for (i = 0; i < program.count; i++) {
+ ret = vfio_pci_tph_resolve_st_tag(pdev, user_flags,
+ src_handle ? src_handle[i] : 0,
+ extended, &tags[i]);
+ if (ret || (stop_on_zero && tags[i] == 0))
+ break;
+ }
+
+ if (i > 0) {
+ mutex_lock(&vdev->tph_lock);
+
+ cmd = vfio_pci_memory_lock_and_enable(vdev);
+ ret = written = pcie_tph_set_st_entries(pdev, program.start, i,
+ tags);
+ vfio_pci_memory_unlock_and_restore(vdev, cmd);
+
+ if (written > 0) {
+ for (k = 0; k < written; k++)
+ vdev->tph_st_cpu[program.start + k] =
+ (tags[k] == 0) ? -1 : src_handle[k];
+ }
+
+ mutex_unlock(&vdev->tph_lock);
+ }
+
+ cpus_read_unlock();
+
+out:
+ kfree(tags);
+ kfree(src_handle);
+ 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;
+
+ ret = vfio_pci_tph_resolve_st_tag(vdev->pdev, user_flags, resolve.src,
+ extended, &tag);
+ if (ret != 0)
+ return ret;
+
+ resolve.valid = VFIO_DEVICE_TPH_VALID_ST;
+ resolve.rsv = 0;
+ resolve.st = tag;
+
+ 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)
{
@@ -1614,6 +1987,14 @@ 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_ZPCI_ERROR:
return vfio_pci_zdev_feature_err(device, flags, arg, argsz);
+ case VFIO_DEVICE_FEATURE_TPH:
+ return vfio_pci_core_feature_tph(vdev, flags, arg, argsz);
+ case VFIO_DEVICE_FEATURE_TPH_PROGRAM:
+ return vfio_pci_core_feature_tph_program(vdev, flags,
+ arg, argsz);
+ case VFIO_DEVICE_FEATURE_TPH_RESOLVE:
+ return vfio_pci_core_feature_tph_resolve(vdev, flags,
+ arg, argsz);
default:
return -ENOTTY;
}
@@ -2176,6 +2557,7 @@ int vfio_pci_core_init_dev(struct vfio_device *core_vdev)
mutex_init(&vdev->igate);
spin_lock_init(&vdev->irqlock);
mutex_init(&vdev->ioeventfds_lock);
+ mutex_init(&vdev->tph_lock);
INIT_LIST_HEAD(&vdev->dummy_resources_list);
INIT_LIST_HEAD(&vdev->ioeventfds_list);
INIT_LIST_HEAD(&vdev->sriov_pfs_item);
@@ -2196,6 +2578,7 @@ void vfio_pci_core_release_dev(struct vfio_device *core_vdev)
container_of(core_vdev, struct vfio_pci_core_device, vdev);
mutex_destroy(&vdev->igate);
+ mutex_destroy(&vdev->tph_lock);
mutex_destroy(&vdev->ioeventfds_lock);
kfree(vdev->region);
kfree(vdev->pm_save);
@@ -2651,12 +3034,23 @@ static void vfio_pci_core_cleanup(void)
{
vfio_pci_uninit_perm_bits();
rcu_barrier();
+ vfio_pci_tph_cpuhp_deinit();
}
static int __init vfio_pci_core_init(void)
{
+ int ret;
+
+ ret = vfio_pci_tph_cpuhp_init();
+ if (ret != 0)
+ return ret;
+
/* Allocate shared config space permission data used by all devices */
- return vfio_pci_init_perm_bits();
+ ret = vfio_pci_init_perm_bits();
+ if (ret != 0)
+ vfio_pci_tph_cpuhp_deinit();
+
+ return ret;
}
module_init(vfio_pci_core_init);
diff --git a/drivers/vfio/pci/vfio_pci_priv.h b/drivers/vfio/pci/vfio_pci_priv.h
index 4e7162234a2eba..967f706f509ef7 100644
--- a/drivers/vfio/pci/vfio_pci_priv.h
+++ b/drivers/vfio/pci/vfio_pci_priv.h
@@ -11,6 +11,12 @@
/* Cap maximum number of ioeventfds per device (arbitrary) */
#define VFIO_PCI_IOEVENTFD_MAX 1000
+enum vfio_pci_tph_policy {
+ VFIO_PCI_TPH_POLICY_NO_ST = 0,
+ VFIO_PCI_TPH_POLICY_IV_ST,
+ VFIO_PCI_TPH_POLICY_DS_ST,
+};
+
struct vfio_pci_ioeventfd {
struct list_head next;
struct vfio_pci_core_device *vdev;
diff --git a/include/linux/pci-tph.h b/include/linux/pci-tph.h
index be68cd17f2f833..c19dbbb876200d 100644
--- a/include/linux/pci-tph.h
+++ b/include/linux/pci-tph.h
@@ -9,6 +9,8 @@
#ifndef LINUX_PCI_TPH_H
#define LINUX_PCI_TPH_H
+#include <linux/pci.h>
+
/*
* According to the ECN for PCI Firmware Spec, Steering Tag can be different
* depending on the memory type: Volatile Memory or Persistent Memory. When a
@@ -21,26 +23,63 @@ enum tph_mem_type {
};
#ifdef CONFIG_PCIE_TPH
+/**
+ * pcie_std_tph_supported - check standard TPH requester support
+ * @pdev: PCI device
+ */
+#define pcie_std_tph_supported(pdev) \
+ ((pdev)->tph_max_type >= PCI_TPH_REQ_TPH_ONLY)
+/**
+ * pcie_ext_tph_supported - check extended TPH requester support
+ * @pdev: PCI device
+ */
+#define pcie_ext_tph_supported(pdev) \
+ ((pdev)->tph_max_type == PCI_TPH_REQ_EXT_TPH)
int pcie_tph_set_st_entry(struct pci_dev *pdev,
unsigned int index, u16 tag);
-int pcie_tph_get_cpu_st(struct pci_dev *dev,
- enum tph_mem_type mem_type,
+int pcie_tph_set_st_entries(struct pci_dev *pdev, unsigned int start,
+ unsigned int count, const u16 *tags);
+int pcie_tph_get_cpu_st_ext(struct pci_dev *dev, enum tph_mem_type mem_type,
+ u8 req_type, unsigned int cpu, u16 *tag);
+int pcie_tph_get_cpu_st(struct pci_dev *dev, enum tph_mem_type mem_type,
unsigned int cpu, u16 *tag);
void pcie_disable_tph(struct pci_dev *pdev);
-int pcie_enable_tph(struct pci_dev *pdev, int mode);
+int pcie_enable_tph_ext(struct pci_dev *pdev, u8 mode, u8 req_type);
+int pcie_enable_tph(struct pci_dev *pdev, u8 mode);
u16 pcie_tph_get_st_table_size(struct pci_dev *pdev);
u32 pcie_tph_get_st_table_loc(struct pci_dev *pdev);
+bool pcie_tph_dsm_supported(struct pci_dev *pdev);
#else
+#define pcie_std_tph_supported(pdev) false
+#define pcie_ext_tph_supported(pdev) false
static inline int pcie_tph_set_st_entry(struct pci_dev *pdev,
unsigned int index, u16 tag)
{ return -EINVAL; }
+static inline int pcie_tph_set_st_entries(struct pci_dev *pdev,
+ unsigned int start,
+ unsigned int count, const u16 *tags)
+{ return -EINVAL; }
+static inline int pcie_tph_get_cpu_st_ext(struct pci_dev *dev,
+ enum tph_mem_type mem_type,
+ u8 req_type, unsigned int cpu,
+ u16 *tag)
+{ return -EINVAL; }
static inline int pcie_tph_get_cpu_st(struct pci_dev *dev,
enum tph_mem_type mem_type,
unsigned int cpu, u16 *tag)
{ return -EINVAL; }
static inline void pcie_disable_tph(struct pci_dev *pdev) { }
-static inline int pcie_enable_tph(struct pci_dev *pdev, int mode)
+static inline int pcie_enable_tph_ext(struct pci_dev *pdev, u8 mode,
+ u8 req_type)
+{ return -EINVAL; }
+static inline int pcie_enable_tph(struct pci_dev *pdev, u8 mode)
{ return -EINVAL; }
+static inline u16 pcie_tph_get_st_table_size(struct pci_dev *pdev)
+{ return 0; }
+static inline u32 pcie_tph_get_st_table_loc(struct pci_dev *pdev)
+{ return PCI_TPH_LOC_NONE; }
+static inline bool pcie_tph_dsm_supported(struct pci_dev *pdev)
+{ return false; }
#endif
#endif /* LINUX_PCI_TPH_H */
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 6482549a841797..1dc3cb011dff63 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -478,7 +478,6 @@ struct pci_dev {
unsigned int ats_enabled:1; /* Address Translation Svc */
unsigned int pasid_enabled:1; /* Process Address Space ID */
unsigned int pri_enabled:1; /* Page Request Interface */
- unsigned int tph_enabled:1; /* TLP Processing Hints */
unsigned int fm_enabled:1; /* Flit Mode (segment captured) */
unsigned int is_managed:1; /* Managed via devres */
unsigned int is_msi_managed:1; /* MSI release via devres installed */
@@ -596,7 +595,10 @@ struct pci_dev {
struct gpio_desc *wake; /* WAKE# GPIO */
#ifdef CONFIG_PCIE_TPH
- u16 tph_cap; /* TPH capability offset */
+ u16 tph_cap:13; /* TPH capability offset */
+ u16 tph_max_type:2; /* Negotiated max TPH requester type
+ between device and root port */
+ u16 tph_enabled:1; /* Whether TPH is enabled */
u8 tph_mode; /* TPH mode */
u8 tph_req_type; /* TPH requester type */
#endif
diff --git a/include/linux/vfio_pci_core.h b/include/linux/vfio_pci_core.h
index 2f3fa2787737a4..217f95aaa9db9b 100644
--- a/include/linux/vfio_pci_core.h
+++ b/include/linux/vfio_pci_core.h
@@ -151,6 +151,12 @@ struct vfio_pci_core_device {
struct notifier_block nb;
struct rw_semaphore memory_lock;
struct list_head dmabufs;
+ u8 tph_policy;
+ u8 tph_opt_in;
+ u32 tph_vcap;
+ s64 *tph_st_cpu;
+ struct hlist_node tph_cpuhp_node;
+ struct mutex tph_lock;
};
enum vfio_pci_io_width {
diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h
index e41437fa17ad0e..1820bb20a460a5 100644
--- a/include/uapi/linux/vfio.h
+++ b/include/uapi/linux/vfio.h
@@ -1555,6 +1555,135 @@ struct vfio_device_feature_zpci_err {
#define VFIO_DEVICE_FEATURE_ZPCI_ERROR 13
+/*
+ * VFIO_DEVICE_FEATURE_TPH - Control and query VFIO TPH feature capabilities
+ *
+ * SET: Opt-in to enable the VFIO TPH feature for the device; flags must be
+ * zero.
+ * GET: Return VFIO-usable TPH capability bits in flags (see
+ * VFIO_DEVICE_TPH_CAP_*). Returns an error if SET opt-in has not been
+ * performed.
+ *
+ * Typical userspace sequence:
+ * 1. Read virtualized PCI TPH capability via VFIO config space access to
+ * discover underlying hardware PCI TPH support.
+ * 2. Invoke SET to opt-in for VFIO TPH feature permission.
+ * 3. Invoke GET to retrieve the set of TPH capabilities accessible via VFIO.
+ * 4. Write the TPH control register through VFIO config space to activate
+ * device TPH hardware.
+ * 5. Program steering tag (ST) table entries by VFIO_DEVICE_FEATURE_TPH_PROGRAM
+ * if the device has an 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.
+ */
+#define VFIO_DEVICE_FEATURE_TPH 14
+
+struct vfio_device_feature_tph {
+ __u32 flags;
+};
+
+/*
+ * Capability bits returned by VFIO_DEVICE_FEATURE_TPH GET
+ */
+
+/*
+ * Supports programming steering tag (ST) entries using the NONE source.
+ * This source resolves to a zero ST value.
+ */
+#define VFIO_DEVICE_TPH_CAP_PROG_ST_NONE (1u << 0)
+/*
+ * Supports programming steering tag (ST) entries using a CPU source handle,
+ * for either volatile or persistent memory type.
+ */
+#define VFIO_DEVICE_TPH_CAP_PROG_ST_CPU (1u << 1)
+/*
+ * Supports resolving a steering tag (ST) from a CPU source handle.
+ */
+#define VFIO_DEVICE_TPH_CAP_RESOLVE_CPU_ST (1u << 2)
+
+/*
+ * VFIO_DEVICE_FEATURE_TPH_PROGRAM - Batch program architected steering tag
+ * (ST) table entries. This interface only operates on the architected ST
+ * table described by the PCIe TPH ST Table Location field; it does not
+ * manage device-specific (DS) ST storage or any vendor-private ST array.
+ *
+ * SET only
+ *
+ * Prerequisites before invoking this feature:
+ * 1. Call VFIO_DEVICE_FEATURE_TPH with SET to enable vfio TPH permission;
+ * 2. Write the TPH control register to activate device hardware TPH logic.
+ *
+ * @flags: IN - source type selector (see VFIO_DEVICE_TPH_SRC_*) and
+ * steering tag namespace selector (see VFIO_DEVICE_TPH_EXTENDED) and
+ * failure policy (see VFIO_DEVICE_TPH_REQUIRE_ST)
+ * Note: only one source type is permitted; combining source type bits
+ * is rejected.
+ * @start: IN - first architected ST table index
+ * @count: IN - number of contiguous entries to program
+ * @srcs: IN - user pointer to array of source u32 handles (CPU ID for CPU
+ * sources, ignored for SRC_NONE)
+ *
+ * Return value: >=0 = number of entries successfully programmed;
+ * <0 = negative errno
+ *
+ * CPU offline note: When a CPU goes offline, the kernel automatically clears
+ * all ST table entries mapped to that CPU, setting those ST values to zero.
+ */
+#define VFIO_DEVICE_FEATURE_TPH_PROGRAM 15
+
+struct vfio_device_feature_tph_program {
+ __u32 flags;
+ __u16 start;
+ __u16 count;
+ __aligned_u64 srcs;
+};
+
+/* Use extended 16-bit steering tag namespace */
+#define VFIO_DEVICE_TPH_EXTENDED (1u << 0)
+/*
+ * Stop the batch when an entry resolves to a zero steering tag.
+ * Programming halts at that entry; the returned count
+ * is the number of entries successfully programmed before the stop.
+ */
+#define VFIO_DEVICE_TPH_REQUIRE_ST (1u << 1)
+/* Source resolves to a zero steering tag (ST) */
+#define VFIO_DEVICE_TPH_SRC_NONE (1u << 2)
+/* Source holds a volatile memory CPU ID */
+#define VFIO_DEVICE_TPH_SRC_CPU_VOLATILE (1u << 3)
+/* Source holds a persistent memory CPU ID */
+#define VFIO_DEVICE_TPH_SRC_CPU_PERSISTENT (1u << 4)
+
+/*
+ * VFIO_DEVICE_FEATURE_TPH_RESOLVE - Resolve TPH attributes from given source
+ *
+ * GET only
+ *
+ * Requires prior successful SET on VFIO_DEVICE_FEATURE_TPH, otherwise
+ * this feature will return error.
+ *
+ * @flags: IN - source type selector (see VFIO_DEVICE_TPH_SRC_*)
+ * and steering tag namespace selector (see VFIO_DEVICE_TPH_EXTENDED)
+ * Note: only one source type is permitted (except SRC_NONE);
+ * combining source type bits is rejected.
+ * @src: IN - source identifier, e.g. CPU ID when SRC_CPU_VOLATILE is set
+ * in flags
+ * @valid: OUT - bitmap indicating valid output fields, see
+ * VFIO_DEVICE_TPH_VALID_*
+ * @rsv: OUT - Reserved for future extension, kernel returns zero
+ * @st: OUT - TPH steering tag (valid when VALID_ST is set in valid)
+ */
+#define VFIO_DEVICE_FEATURE_TPH_RESOLVE 16
+
+struct vfio_device_feature_tph_resolve {
+ __u32 flags;
+ __u32 src;
+ __u8 valid;
+#define VFIO_DEVICE_TPH_VALID_ST (1u << 0) /* st holds valid steering tag */
+ __u8 rsv;
+ __u16 st;
+};
+
/* -------- API for Type1 VFIO IOMMU -------- */
/**
|
| 3/2 | 2026/11/22 09:23 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 22625 output: 20 thoughts: 849 Thoughts: **Analyzing the Patch for Fuzzing Potential** Okay, let's break this down. My initial assessment is: can this patch be fruitfully fuzzed with syzkaller? First, I need to understand *what* it does. I see it's touching quite a few files related to PCI TPH (TLP Processing Hints) and VFIO-PCI. Seems like a deeper dive is necessary to ascertain the potential attack surface. Specifically, I see changes in `drivers/pci/tph.c` with helper functions for TPH, `drivers/vfio/pci/vfio_pci.c` adding a module parameter, then `drivers/vfio/pci/vfio_pci_config.c` adding virtualization for TPH extended capabilities, and `drivers/vfio/pci/vfio_pci_core.c` with debugfs entries, initialization/de-initialization routines, CPU hotplug integration and new ioctl features. Several header files are also involved. Now, the crucial question: can VFIO-PCI or PCI TPH, or their interaction, actually be reached in a syzkaller fuzzing setup? This is the core issue. Let's examine the syzkaller capabilities, virtual devices, and VFIO reachability. I need to figure out what devices are accessible within a standard syzkaller QEMU or GCE environment. Does syzkaller even *have* access to a PCI device bound to vfio-pci? Wait, in standard syzkaller QEMU/GCE environments, QEMU has PCI devices like virtio-pci, e1000, etc. But, are *any* of those devices bound to `vfio-pci` by default? Can the user bind a device to vfio-pci within syzkaller's environment? Does syzkaller have fake/sample vfio devices? Or vfio-pci itself? I need to check the syzlang descriptions or documentation to see how syzkaller *actually* uses vfio. Is there any mechanism for syzkaller to bind a device to vfio-pci via sysfs? I need to know what syzkaller is doing with `/dev/vfio/*`. This will give me some information. Ultimately, I'll need to search through the kernel's VFIO configuration and usage to understand how things are connected and to evaluate whether this patch introduces any vulnerabilities that are relevant for fuzzing. |
| 4/2 | 2026/11/22 09:23 | tool | grepper |
0mArgs:{
"Expression": "CONFIG_VFIO_PCI"
}Results: {
"Output": "arch/arm64/configs/defconfig=1428=CONFIG_VFIO=y\narch/arm64/configs/defconfig:1429:CONFIG_VFIO_PCI=y\narch/arm64/configs/defconfig-1430-CONFIG_VIRTIO_PCI=y\n--\narch/loongarch/configs/loongson32_defconfig=901=CONFIG_VFIO=m\narch/loongarch/configs/loongson32_defconfig:902:CONFIG_VFIO_PCI=m\narch/loongarch/configs/loongson32_defconfig-903-CONFIG_VIRTIO_PCI=y\n--\narch/loongarch/configs/loongson64_defconfig=930=CONFIG_VFIO=m\narch/loongarch/configs/loongson64_defconfig:931:CONFIG_VFIO_PCI=m\narch/loongarch/configs/loongson64_defconfig-932-CONFIG_VIRTIO_PCI=y\n--\narch/s390/configs/debug_defconfig=650=CONFIG_VFIO=m\narch/s390/configs/debug_defconfig:651:CONFIG_VFIO_PCI=m\narch/s390/configs/debug_defconfig-652-CONFIG_MLX5_VFIO_PCI=m\n--\narch/s390/configs/defconfig=640=CONFIG_VFIO=m\narch/s390/configs/defconfig:641:CONFIG_VFIO_PCI=m\narch/s390/configs/defconfig-642-CONFIG_MLX5_VFIO_PCI=m\n--\narch/s390/kvm/s390/Makefile=11=kvm-y += $(gmap-y)\narch/s390/kvm/s390/Makefile-12-\narch/s390/kvm/s390/Makefile:13:kvm-$(CONFIG_VFIO_PCI_ZDEV_KVM) += pci.o\narch/s390/kvm/s390/Makefile-14-obj-$(CONFIG_KVM) += kvm.o\n--\narch/s390/kvm/s390/interrupt.c=3741=static void gib_alert_irq_handler(struct airq_struct *airq,\n--\narch/s390/kvm/s390/interrupt.c-3748-\tif ((info-\u003eforward || info-\u003eerror) \u0026\u0026\narch/s390/kvm/s390/interrupt.c:3749:\t IS_ENABLED(CONFIG_VFIO_PCI_ZDEV_KVM)) {\narch/s390/kvm/s390/interrupt.c-3750-\t\taen_process_gait(info-\u003eisc);\n--\narch/s390/kvm/s390/pci.h=48=static inline struct kvm *kvm_s390_pci_si_to_kvm(struct zpci_aift *aift,\n--\narch/s390/kvm/s390/pci.h-50-{\narch/s390/kvm/s390/pci.h:51:\tif (!IS_ENABLED(CONFIG_VFIO_PCI_ZDEV_KVM) || !aift-\u003ekzdev ||\narch/s390/kvm/s390/pci.h-52-\t !aift-\u003ekzdev[si])\n--\narch/s390/kvm/s390/pci.h=68=static inline bool kvm_s390_pci_interp_allowed(void)\n--\narch/s390/kvm/s390/pci.h-82-\tdefault:\narch/s390/kvm/s390/pci.h:83:\t\treturn (IS_ENABLED(CONFIG_VFIO_PCI_ZDEV_KVM) \u0026\u0026\narch/s390/kvm/s390/pci.h-84-\t\t\tsclp.has_zpci_lsi \u0026\u0026 sclp.has_aeni \u0026\u0026 sclp.has_aisi \u0026\u0026\n--\narch/s390/kvm/s390/s390.c=496=static int __init __kvm_s390_init(void)\n--\narch/s390/kvm/s390/s390.c-520-\narch/s390/kvm/s390/s390.c:521:\tif (IS_ENABLED(CONFIG_VFIO_PCI_ZDEV_KVM)) {\narch/s390/kvm/s390/s390.c-522-\t\trc = kvm_s390_pci_init();\n--\narch/s390/kvm/s390/s390.c-538-err_gib:\narch/s390/kvm/s390/s390.c:539:\tif (IS_ENABLED(CONFIG_VFIO_PCI_ZDEV_KVM))\narch/s390/kvm/s390/s390.c-540-\t\tkvm_s390_pci_exit();\n--\narch/s390/kvm/s390/s390.c=550=static void __kvm_s390_exit(void)\n--\narch/s390/kvm/s390/s390.c-555-\tkvm_s390_gib_destroy();\narch/s390/kvm/s390/s390.c:556:\tif (IS_ENABLED(CONFIG_VFIO_PCI_ZDEV_KVM))\narch/s390/kvm/s390/s390.c-557-\t\tkvm_s390_pci_exit();\n--\narch/s390/kvm/s390/s390.c=2900=int kvm_arch_vm_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg)\n--\narch/s390/kvm/s390/s390.c-3063-\t\tr = -EINVAL;\narch/s390/kvm/s390/s390.c:3064:\t\tif (!IS_ENABLED(CONFIG_VFIO_PCI_ZDEV_KVM))\narch/s390/kvm/s390/s390.c-3065-\t\t\tbreak;\n--\narch/s390/kvm/s390/s390.c=3232=void kvm_arch_free_vm(struct kvm *kvm)\narch/s390/kvm/s390/s390.c-3233-{\narch/s390/kvm/s390/s390.c:3234:\tif (IS_ENABLED(CONFIG_VFIO_PCI_ZDEV_KVM))\narch/s390/kvm/s390/s390.c-3235-\t\tkvm_s390_pci_clear_list(kvm);\n--\narch/s390/kvm/s390/s390.c=3240=int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)\n--\narch/s390/kvm/s390/s390.c-3316-\narch/s390/kvm/s390/s390.c:3317:\tif (IS_ENABLED(CONFIG_VFIO_PCI_ZDEV_KVM)) {\narch/s390/kvm/s390/s390.c-3318-\t\tmutex_lock(\u0026kvm-\u003elock);\n--\ndrivers/iommu/iommufd/pages.c=1468=sym_vfio_pci_dma_buf_iommufd_map(struct dma_buf_attachment *attachment,\n--\ndrivers/iommu/iommufd/pages.c-1477-\ndrivers/iommu/iommufd/pages.c:1478:\tif (!IS_ENABLED(CONFIG_VFIO_PCI_DMABUF))\ndrivers/iommu/iommufd/pages.c-1479-\t\treturn -EOPNOTSUPP;\n--\ndrivers/vfio/Makefile=13=obj-$(CONFIG_VFIO_IOMMU_SPAPR_TCE) += vfio_iommu_spapr_tce.o\ndrivers/vfio/Makefile:14:obj-$(CONFIG_VFIO_PCI_CORE) += pci/\ndrivers/vfio/Makefile-15-obj-$(CONFIG_VFIO_PLATFORM_BASE) += platform/\n--\ndrivers/vfio/pci/Makefile=3=vfio-pci-core-y := vfio_pci_core.o vfio_pci_intrs.o vfio_pci_rdwr.o vfio_pci_config.o\ndrivers/vfio/pci/Makefile:4:vfio-pci-core-$(CONFIG_VFIO_PCI_ZDEV_KVM) += vfio_pci_zdev.o\ndrivers/vfio/pci/Makefile:5:vfio-pci-core-$(CONFIG_VFIO_PCI_DMABUF) += vfio_pci_dmabuf.o\ndrivers/vfio/pci/Makefile:6:obj-$(CONFIG_VFIO_PCI_CORE) += vfio-pci-core.o\ndrivers/vfio/pci/Makefile-7-\ndrivers/vfio/pci/Makefile=8=vfio-pci-y := vfio_pci.o\ndrivers/vfio/pci/Makefile:9:vfio-pci-$(CONFIG_VFIO_PCI_IGD) += vfio_pci_igd.o\ndrivers/vfio/pci/Makefile:10:obj-$(CONFIG_VFIO_PCI) += vfio-pci.o\ndrivers/vfio/pci/Makefile-11-\n--\ndrivers/vfio/pci/vfio_pci.c=39=MODULE_PARM_DESC(nointxmask,\n--\ndrivers/vfio/pci/vfio_pci.c-41-\ndrivers/vfio/pci/vfio_pci.c:42:#ifdef CONFIG_VFIO_PCI_VGA\ndrivers/vfio/pci/vfio_pci.c-43-static bool disable_vga;\n--\ndrivers/vfio/pci/vfio_pci.c=151=static int vfio_pci_init_dev(struct vfio_device *core_vdev)\n--\ndrivers/vfio/pci/vfio_pci.c-164-\tvdev-\u003edisable_idle_d3 = disable_idle_d3;\ndrivers/vfio/pci/vfio_pci.c:165:#ifdef CONFIG_VFIO_PCI_VGA\ndrivers/vfio/pci/vfio_pci.c-166-\tvdev-\u003edisable_vga = disable_vga;\n--\ndrivers/vfio/pci/vfio_pci_config.c=1891=int vfio_config_init(struct vfio_pci_core_device *vdev)\n--\ndrivers/vfio/pci/vfio_pci_config.c-1973-\ndrivers/vfio/pci/vfio_pci_config.c:1974:\tif (!IS_ENABLED(CONFIG_VFIO_PCI_INTX) || vdev-\u003enointx ||\ndrivers/vfio/pci/vfio_pci_config.c-1975-\t !vdev-\u003epdev-\u003eirq || vdev-\u003epdev-\u003eirq == IRQ_NOTCONNECTED)\n--\ndrivers/vfio/pci/vfio_pci_core.c=96=static inline bool vfio_vga_disabled(struct vfio_pci_core_device *vdev)\ndrivers/vfio/pci/vfio_pci_core.c-97-{\ndrivers/vfio/pci/vfio_pci_core.c:98:#ifdef CONFIG_VFIO_PCI_VGA\ndrivers/vfio/pci/vfio_pci_core.c-99-\treturn vdev-\u003edisable_vga;\n--\ndrivers/vfio/pci/vfio_pci_priv.h=50=ssize_t vfio_pci_bar_rw(struct vfio_pci_core_device *vdev, char __user *buf,\n--\ndrivers/vfio/pci/vfio_pci_priv.h-52-\ndrivers/vfio/pci/vfio_pci_priv.h:53:#ifdef CONFIG_VFIO_PCI_VGA\ndrivers/vfio/pci/vfio_pci_priv.h-54-ssize_t vfio_pci_vga_rw(struct vfio_pci_core_device *vdev, char __user *buf,\n--\ndrivers/vfio/pci/vfio_pci_priv.h=79=void vfio_pci_memory_unlock_and_restore(struct vfio_pci_core_device *vdev,\n--\ndrivers/vfio/pci/vfio_pci_priv.h-81-\ndrivers/vfio/pci/vfio_pci_priv.h:82:#ifdef CONFIG_VFIO_PCI_IGD\ndrivers/vfio/pci/vfio_pci_priv.h-83-bool vfio_pci_is_intel_display(struct pci_dev *pdev);\n--\ndrivers/vfio/pci/vfio_pci_priv.h=91=static inline int vfio_pci_igd_init(struct vfio_pci_core_device *vdev)\n--\ndrivers/vfio/pci/vfio_pci_priv.h-96-\ndrivers/vfio/pci/vfio_pci_priv.h:97:#ifdef CONFIG_VFIO_PCI_ZDEV_KVM\ndrivers/vfio/pci/vfio_pci_priv.h-98-int vfio_pci_info_zdev_add_caps(struct vfio_pci_core_device *vdev,\n--\ndrivers/vfio/pci/vfio_pci_priv.h=127=static inline bool vfio_pci_is_vga(struct pci_dev *pdev)\n--\ndrivers/vfio/pci/vfio_pci_priv.h-131-\ndrivers/vfio/pci/vfio_pci_priv.h:132:#ifdef CONFIG_VFIO_PCI_DMABUF\ndrivers/vfio/pci/vfio_pci_priv.h-133-int vfio_pci_core_feature_dma_buf(struct vfio_pci_core_device *vdev, u32 flags,\n--\ndrivers/vfio/pci/vfio_pci_rdwr.c=201=ssize_t vfio_pci_bar_rw(struct vfio_pci_core_device *vdev, char __user *buf,\n--\ndrivers/vfio/pci/vfio_pci_rdwr.c-280-\ndrivers/vfio/pci/vfio_pci_rdwr.c:281:#ifdef CONFIG_VFIO_PCI_VGA\ndrivers/vfio/pci/vfio_pci_rdwr.c-282-ssize_t vfio_pci_vga_rw(struct vfio_pci_core_device *vdev, char __user *buf,\n--\ninclude/linux/sched/user.h=14=struct user_struct {\n--\ninclude/linux/sched/user.h-26-#if defined(CONFIG_NET) || defined(CONFIG_IO_URING) || \\\ninclude/linux/sched/user.h:27:\tdefined(CONFIG_VFIO_PCI_ZDEV_KVM) || IS_ENABLED(CONFIG_IOMMUFD) || \\\ninclude/linux/sched/user.h-28-\tdefined(CONFIG_SECRETMEM)\n--\ninclude/linux/vfio_pci_core.h=62=struct vfio_pci_device_ops {\n--\ninclude/linux/vfio_pci_core.h-70-\ninclude/linux/vfio_pci_core.h:71:#if IS_ENABLED(CONFIG_VFIO_PCI_DMABUF)\ninclude/linux/vfio_pci_core.h-72-int vfio_pci_core_fill_phys_vec(struct phys_vec *phys_vec,\n"
} |
| 5/2 | 2026/11/22 09:23 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 28291 output: 20 thoughts: 27 Thoughts: Okay, here's my attempt at summarizing those thoughts, tailored for an expert audience and in the first person: **Investigating Kconfig Dependencies** Alright, let's dive in. I'm curious about the Kconfig dependencies surrounding `CONFIG_PCIE_TPH` and `CONFIG_VFIO_PCI`. My goal here is to get a clearer understanding of how these options are linked within the kernel configuration system. I want to see which other options, potentially obscure or not immediately obvious, might enable, disable, or otherwise influence the behavior of these two. This is particularly relevant when debugging hardware or investigating driver behavior, as these options often have implicit dependencies that can trip you up. A comprehensive review of the dependencies can give insight into system behavior. |
| 6/2 | 2026/11/22 09:24 | tool | grepper |
0mArgs:{
"Expression": "config PCIE_TPH"
}Results: {
"Output": "drivers/pci/Kconfig=185=config PCI_PASID\n--\ndrivers/pci/Kconfig-196-\ndrivers/pci/Kconfig:197:config PCIE_TPH\ndrivers/pci/Kconfig-198-\tbool \"TLP Processing Hints\"\n"
} |
| 7/2 | 2026/11/22 09:24 | llm | patch-evaluator |
1mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 28580 output: 35 thoughts: 20 Thoughts: Here's a first-person summary, tailored for an expert audience, based on the provided starting point: **Diving into PCI Configuration** Okay, time to get my hands dirty. Let's see... I'm going to jump into the `drivers/pci/Kconfig` file, specifically around line 197. I suspect we're getting into the nitty-gritty of configuring some PCI-related options. This is probably where the core feature enabling/disabling choices are made. I'm hoping to find something specific that resonates with my current issue, maybe a setting related to a particular PCI device class, or perhaps something concerning DMA configuration. Let's see what gems are hidden in this section of the Kconfig file. I'm going to start looking for a specific config option I'm familiar with, to see how it ties into the overall structure. |
| 8/2 | 2026/11/22 09:25 | tool | read-file |
0mArgs:{
"File": "drivers/pci/Kconfig",
"FirstLine": 195,
"LineCount": 25
}Results: {
"Contents": " 195:\t\t If unsure, say N.\n 196:\t\n 197:\tconfig PCIE_TPH\n 198:\t\tbool \"TLP Processing Hints\"\n 199:\t\thelp\n 200:\t\t This option adds support for PCIe TLP Processing Hints (TPH).\n 201:\t\t TPH allows endpoint devices to provide optimization hints, such as\n 202:\t\t desired caching behavior, for requests that target memory space.\n 203:\t\t These hints, called Steering Tags, can empower the system hardware\n 204:\t\t to optimize the utilization of platform resources.\n 205:\t\n 206:\tconfig PCI_P2PDMA\n 207:\t\tbool \"PCI peer-to-peer transfer support\"\n 208:\t\tdepends on ZONE_DEVICE\n 209:\t\t#\n 210:\t\t# The need for the scatterlist DMA bus address flag means PCI P2PDMA\n 211:\t\t# requires 64bit\n 212:\t\t#\n 213:\t\tdepends on 64BIT\n 214:\t\tselect GENERIC_ALLOCATOR\n 215:\t\tselect NEED_SG_DMA_FLAGS\n 216:\t\thelp\n 217:\t\t Enables drivers to do PCI peer-to-peer transactions to and from\n 218:\t\t BARs that are exposed in other devices that are the part of\n 219:\t\t the hierarchy where peer-to-peer DMA is guaranteed by the PCI\n"
} |
| 9/2 | 2026/11/22 09:25 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 29207 output: 19 thoughts: 17 Thoughts: Okay, let's dive into this. Here's my take on those thoughts, as if they're my own: **Kconfig Dive: VFIO Driver Configuration** Right, let's get down to brass tacks and check out `drivers/vfio/pci/Kconfig`. I need to understand how the VFIO PCI driver's configuration options are structured and what dependencies it has. This is crucial for customizing the kernel for specific hardware setups and use cases. I need to know: Are there any new options since the last time I looked? Are there any changes in defaults that I need to be aware of? Are there new dependencies on other kernel features or drivers? This file is the key to understanding how to enable, disable, and tailor the VFIO PCI functionality to a particular platform or application. Time to dig in and see what's changed. |
| 10/2 | 2026/11/22 09:26 | tool | grepper |
0mArgs:{
"Expression": "config VFIO_PCI"
}Results: {
"Output": "drivers/vfio/pci/Kconfig=2=menu \"VFIO support for PCI devices\"\n--\ndrivers/vfio/pci/Kconfig-4-\ndrivers/vfio/pci/Kconfig:5:config VFIO_PCI_CORE\ndrivers/vfio/pci/Kconfig-6-\ttristate\n--\ndrivers/vfio/pci/Kconfig-9-\ndrivers/vfio/pci/Kconfig:10:config VFIO_PCI_INTX\ndrivers/vfio/pci/Kconfig-11-\tdef_bool y if !S390\n--\ndrivers/vfio/pci/Kconfig-13-\ndrivers/vfio/pci/Kconfig:14:config VFIO_PCI\ndrivers/vfio/pci/Kconfig-15-\ttristate \"Generic VFIO support for any PCI device\"\n--\ndrivers/vfio/pci/Kconfig=23=if VFIO_PCI\ndrivers/vfio/pci/Kconfig:24:config VFIO_PCI_VGA\ndrivers/vfio/pci/Kconfig-25-\tbool \"Generic VFIO PCI support for VGA devices\"\n--\ndrivers/vfio/pci/Kconfig-33-\ndrivers/vfio/pci/Kconfig:34:config VFIO_PCI_IGD\ndrivers/vfio/pci/Kconfig-35-\tbool \"Generic VFIO PCI extensions for Intel graphics (GVT-d)\"\n--\ndrivers/vfio/pci/Kconfig=45=endif\ndrivers/vfio/pci/Kconfig-46-\ndrivers/vfio/pci/Kconfig:47:config VFIO_PCI_ZDEV_KVM\ndrivers/vfio/pci/Kconfig-48-\tbool \"VFIO PCI extensions for s390x KVM passthrough\"\n--\ndrivers/vfio/pci/Kconfig-57-\ndrivers/vfio/pci/Kconfig:58:config VFIO_PCI_DMABUF\ndrivers/vfio/pci/Kconfig-59-\tdef_bool y if VFIO_PCI_CORE \u0026\u0026 PCI_P2PDMA \u0026\u0026 DMA_SHARED_BUFFER\n"
} |
| 11/2 | 2026/11/22 09:26 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 29963 output: 37 thoughts: 24 Thoughts: Here's a summary of my thought process, as requested: **Diving into the VFIO PCI Configuration** Okay, let's get down to brass tacks. I need to understand the configuration options for VFIO-PCI. My immediate focus is on the `drivers/vfio/pci/Kconfig` file. Specifically, I'm zeroing in on lines 14 through 25. That section likely defines the core configuration knobs related to the PCI part of the VFIO subsystem, such as device assignment, interrupt handling, or maybe even direct access capabilities. Understanding those configuration options is crucial for making informed decisions on how to deploy or debug a VFIO setup. I anticipate this will reveal the underlying features available to my user. |
| 12/2 | 2026/11/22 09:27 | tool | read-file |
0mArgs:{
"File": "drivers/vfio/pci/Kconfig",
"FirstLine": 14,
"LineCount": 20
}Results: {
"Contents": " 14:\tconfig VFIO_PCI\n 15:\t\ttristate \"Generic VFIO support for any PCI device\"\n 16:\t\tselect VFIO_PCI_CORE\n 17:\t\thelp\n 18:\t\t Support for the generic PCI VFIO bus driver which can connect any\n 19:\t\t PCI device to the VFIO framework.\n 20:\t\n 21:\t\t If you don't know what to do here, say N.\n 22:\t\n 23:\tif VFIO_PCI\n 24:\tconfig VFIO_PCI_VGA\n 25:\t\tbool \"Generic VFIO PCI support for VGA devices\"\n 26:\t\tdepends on X86 \u0026\u0026 VGA_ARB\n 27:\t\thelp\n 28:\t\t Support for VGA extension to VFIO PCI. This exposes an additional\n 29:\t\t region on VGA devices for accessing legacy VGA addresses used by\n 30:\t\t BIOS and generic video drivers.\n 31:\t\n 32:\t\t If you don't know what to do here, say N.\n 33:\t\n"
} |
| 13/2 | 2026/11/22 09:27 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 30461 output: 29 thoughts: 47 Thoughts: Okay, let's dive into this. Here's how I'd approach this task, as if these were my internal thoughts: **Analyzing TPH and VFIO PCI Call Relationships** Right, so I need to get a clear picture of how the PCI Translation Process Header (TPH) functions interact with VFIO PCI. My immediate goal is to understand the calling hierarchy. I want to know, specifically, where the `pcie_enable_tph`, `pci_tph_init`, and other related TPH functions are actually invoked within the kernel tree. That will give me insight into which parts of the kernel are responsible for enabling, initializing, and using TPH. I need to trace the call paths to see how it works. |
| 14/2 | 2026/11/22 09:27 | tool | grepper |
0mArgs:{
"Expression": "pcie_enable_tph|pci_tph_init"
}Results: {
"Output": "Documentation/PCI/tph.rst=48=To enable TPH for a device, use the following function::\nDocumentation/PCI/tph.rst-49-\nDocumentation/PCI/tph.rst:50: int pcie_enable_tph(struct pci_dev *pdev, int mode);\nDocumentation/PCI/tph.rst-51-\n--\nDocumentation/PCI/tph.rst=53=Current supported modes include:\n--\nDocumentation/PCI/tph.rst-58-\nDocumentation/PCI/tph.rst:59:`pcie_enable_tph()` checks whether the requested mode is actually\nDocumentation/PCI/tph.rst-60-supported by the device before enabling. The device driver can figure out\nDocumentation/PCI/tph.rst=61=which TPH mode is supported and can be properly enabled based on the\nDocumentation/PCI/tph.rst:62:return value of `pcie_enable_tph()`.\nDocumentation/PCI/tph.rst-63-\n--\ndrivers/net/ethernet/broadcom/bnxt/bnxt.c=11990=static int bnxt_request_irq(struct bnxt *bp)\n--\ndrivers/net/ethernet/broadcom/bnxt/bnxt.c-12008-\tif (BNXT_SUPPORTS_QUEUE_API(bp)) {\ndrivers/net/ethernet/broadcom/bnxt/bnxt.c:12009:\t\trc = pcie_enable_tph(bp-\u003epdev, PCI_TPH_ST_IV_MODE);\ndrivers/net/ethernet/broadcom/bnxt/bnxt.c-12010-\t\tif (!rc)\n--\ndrivers/net/ethernet/mellanox/mlx5/core/lib/st.c=25=struct mlx5_st *mlx5_st_create(struct mlx5_core_dev *dev)\n--\ndrivers/net/ethernet/mellanox/mlx5/core/lib/st.c-57-\t/* The OS doesn't support ST */\ndrivers/net/ethernet/mellanox/mlx5/core/lib/st.c:58:\tret = pcie_enable_tph(pdev, PCI_TPH_ST_DS_MODE);\ndrivers/net/ethernet/mellanox/mlx5/core/lib/st.c-59-\tif (ret)\n--\ndrivers/pci/pci.h=1071=void pci_no_tph(void);\ndrivers/pci/pci.h:1072:void pci_tph_init(struct pci_dev *dev);\ndrivers/pci/pci.h-1073-#else\n--\ndrivers/pci/pci.h=1076=static inline void pci_no_tph(void) { }\ndrivers/pci/pci.h:1077:static inline void pci_tph_init(struct pci_dev *dev) { }\ndrivers/pci/pci.h-1078-#endif\n--\ndrivers/pci/probe.c=2665=static void pci_init_capabilities(struct pci_dev *dev)\n--\ndrivers/pci/probe.c-2687-\tpci_doe_init(dev);\t\t/* Data Object Exchange */\ndrivers/pci/probe.c:2688:\tpci_tph_init(dev);\t\t/* TLP Processing Hints */\ndrivers/pci/probe.c-2689-\tpci_rebar_init(dev);\t\t/* Resizable BAR */\n--\ndrivers/pci/tph.c=412=EXPORT_SYMBOL(pcie_disable_tph);\n--\ndrivers/pci/tph.c-414-/**\ndrivers/pci/tph.c:415: * pcie_enable_tph_ext - Enable TPH support with specific ST mode and\ndrivers/pci/tph.c-416- * requester type\n--\ndrivers/pci/tph.c-425- */\ndrivers/pci/tph.c:426:int pcie_enable_tph_ext(struct pci_dev *pdev, u8 mode, u8 req_type)\ndrivers/pci/tph.c-427-{\n--\ndrivers/pci/tph.c-470-}\ndrivers/pci/tph.c:471:EXPORT_SYMBOL(pcie_enable_tph_ext);\ndrivers/pci/tph.c-472-\ndrivers/pci/tph.c-473-/**\ndrivers/pci/tph.c:474: * pcie_enable_tph - Enable TPH support for device using a specific ST mode\ndrivers/pci/tph.c-475- * @pdev: PCI device\n--\ndrivers/pci/tph.c-477- *\ndrivers/pci/tph.c:478: * Wrapper for pcie_enable_tph_ext(), automatically uses the pre-cached\ndrivers/pci/tph.c-479- * tph_max_type value (negotiated maximum requester type between device and\n--\ndrivers/pci/tph.c-483- */\ndrivers/pci/tph.c:484:int pcie_enable_tph(struct pci_dev *pdev, u8 mode)\ndrivers/pci/tph.c-485-{\ndrivers/pci/tph.c:486:\treturn pcie_enable_tph_ext(pdev, mode, pdev-\u003etph_max_type);\ndrivers/pci/tph.c-487-}\ndrivers/pci/tph.c:488:EXPORT_SYMBOL(pcie_enable_tph);\ndrivers/pci/tph.c-489-\n--\ndrivers/pci/tph.c=552=void pci_no_tph(void)\n--\ndrivers/pci/tph.c-558-\ndrivers/pci/tph.c:559:void pci_tph_init(struct pci_dev *pdev)\ndrivers/pci/tph.c-560-{\n--\ndrivers/vfio/pci/vfio_pci_config.c=1181=static int vfio_tph_config_write(struct vfio_pci_core_device *vdev, int pos,\n--\ndrivers/vfio/pci/vfio_pci_config.c-1230-\tif (req == PCI_TPH_REQ_TPH_ONLY || req == PCI_TPH_REQ_EXT_TPH)\ndrivers/vfio/pci/vfio_pci_config.c:1231:\t\tpcie_enable_tph_ext(pdev, mode, req);\ndrivers/vfio/pci/vfio_pci_config.c-1232-\telse if (req == PCI_TPH_REQ_DISABLE)\n--\ninclude/linux/pci-tph.h=46=void pcie_disable_tph(struct pci_dev *pdev);\ninclude/linux/pci-tph.h:47:int pcie_enable_tph_ext(struct pci_dev *pdev, u8 mode, u8 req_type);\ninclude/linux/pci-tph.h:48:int pcie_enable_tph(struct pci_dev *pdev, u8 mode);\ninclude/linux/pci-tph.h-49-u16 pcie_tph_get_st_table_size(struct pci_dev *pdev);\n--\ninclude/linux/pci-tph.h=71=static inline void pcie_disable_tph(struct pci_dev *pdev) { }\ninclude/linux/pci-tph.h:72:static inline int pcie_enable_tph_ext(struct pci_dev *pdev, u8 mode,\ninclude/linux/pci-tph.h-73-\t\t\t\t u8 req_type)\ninclude/linux/pci-tph.h-74-{ return -EINVAL; }\ninclude/linux/pci-tph.h:75:static inline int pcie_enable_tph(struct pci_dev *pdev, u8 mode)\ninclude/linux/pci-tph.h-76-{ return -EINVAL; }\n"
} |
| 15/2 | 2026/11/22 09:27 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 32790 output: 37 thoughts: 67 Thoughts: Okay, let's dive into this. I need to understand how TPH (Transaction Pending Handling) is being initialized for PCI devices. My initial hunch, given my experience, is that the initialization should be happening during device enumeration, probably within the probe sequence. So, the key function to trace is `pci_tph_init`. I immediately recall that `pci_init_capabilities` is the likely candidate to call `pci_tph_init(dev)`. This seems logical, as `pci_init_capabilities` is where various device capabilities are typically set up. I'll need to confirm that relationship. To locate the crucial code, I'll go straight to `drivers/pci/probe.c`. I'm going to look around line 2688, knowing that probe-related initialization often sits within a single block of code, I anticipate the code I need will be nearby. I'll focus my attention there and see what `pci_init_capabilities` actually does with `pci_tph_init`. |
| 16/2 | 2026/11/22 09:28 | tool | read-file |
0mArgs:{
"File": "drivers/pci/probe.c",
"FirstLine": 2680,
"LineCount": 20
}Results: {
"Contents": "2680:\t\tpci_pri_init(dev);\t\t/* Page Request Interface */\n2681:\t\tpci_pasid_init(dev);\t\t/* Process Address Space ID */\n2682:\t\tpci_acs_init(dev);\t\t/* Access Control Services */\n2683:\t\tpci_ptm_init(dev);\t\t/* Precision Time Measurement */\n2684:\t\tpci_aer_init(dev);\t\t/* Advanced Error Reporting */\n2685:\t\tpci_dpc_init(dev);\t\t/* Downstream Port Containment */\n2686:\t\tpci_rcec_init(dev);\t\t/* Root Complex Event Collector */\n2687:\t\tpci_doe_init(dev);\t\t/* Data Object Exchange */\n2688:\t\tpci_tph_init(dev);\t\t/* TLP Processing Hints */\n2689:\t\tpci_rebar_init(dev);\t\t/* Resizable BAR */\n2690:\t\tpci_dev3_init(dev);\t\t/* Device 3 capabilities */\n2691:\t\tpci_ide_init(dev);\t\t/* Link Integrity and Data Encryption */\n2692:\t\n2693:\t\tpcie_report_downtraining(dev);\n2694:\t\tpci_init_reset_methods(dev);\n2695:\t}\n2696:\t\n2697:\t/*\n2698:\t * This is the equivalent of pci_host_bridge_msi_domain() that acts on\n2699:\t * devices. Firmware interfaces that can select the MSI domain on a\n"
} |
| 17/2 | 2026/11/22 09:28 | llm | patch-evaluator |
1mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 33526 output: 23 thoughts: 1609 Thoughts: **TPH Initialization and VFIO Exploration** Okay, first things first, `pci_tph_init(dev)` is called during the PCI device probe. I need to understand what this function does. Diving into `drivers/pci/tph.c`, I see it's responsible for initializing TPH capabilities. It checks for the TPH Extended Capability, reads configuration registers to determine the supported request type (`PCI_TPH_REQ_EXT_TPH` or `PCI_TPH_REQ_TPH_ONLY`), and considers the root port's capabilities, selecting the minimum supported type. Importantly, it allocates space using `pci_add_ext_cap_save_buffer`. Now, I need to understand this in the context of VFIO, as that's my area of interest. I'm trying to figure out if VFIO functionality related to this can be triggered or fuzzed. I know that according to the instructions I need to avoid syzkaller's syzlang descriptions. I need to figure out how VFIO ioctls are used. So, can VFIO-PCI even be used in standard virtualized environments like QEMU? Can a user space process open `/dev/vfio/vfio` or specific VFIO devices? I know a device needs to be bound to `vfio-pci`. Let's refresh my memory on the binding process: it involves writing the device vendor and device ID to `/sys/bus/pci/drivers/vfio-pci/new_id`, or unbinding and rebinding a PCI device to the VFIO-PCI driver via `/sys/bus/pci/devices/0000:00:xx.x/driver/unbind` and then `/sys/bus/pci/drivers/vfio-pci/bind`. The important point is whether a root user (which syzkaller runs as, or a root user in a user namespace?) has the capability to do this within the fuzzing environment. I believe syzkaller has access to sysfs, which means it should be possible. Now, let's look at `VFIO_DEVICE_FEATURE` ioctls specifically. Examining `drivers/vfio/pci/vfio_pci_core.c`, I see `vfio_pci_core_ioctl_feature` handles this, and this function has different cases: `VFIO_DEVICE_FEATURE_TPH`, `VFIO_DEVICE_FEATURE_TPH_PROGRAM`, and `VFIO_DEVICE_FEATURE_TPH_RESOLVE`. This looks like a good place to start, as this exposes TPH functionality directly through VFIO. Furthermore, let's see about CPU hotplug callbacks: `vfio_pci_tph_cpuhp_offline` and `vfio_pci_tph_cpuhp_init`. I see that `vfio_pci_tph_cpuhp_init` is called in `vfio_pci_core_init()`, which means it's called during module initialization of `vfio-pci`. During initialization, `vfio_pci_tph_cpuhp_init()` registers `vfio_pci_tph_cpuhp_offline` with CPU hotplug! When a CPU is offlined, which syzkaller does frequently, `vfio_pci_tph_cpuhp_offline` is called. Also, `vfio_pci_core_enable` adds the instance `cpuhp_state_add_instance_nocalls()` and allocates `vdev->tph_st_cpu`! This is interesting! When is `vfio_pci_core_enable` called? I need to know. Let's find out! |
| 18/2 | 2026/11/22 09:29 | tool | grepper |
0mArgs:{
"Expression": "vfio_pci_core_enable"
}Results: {
"Output": "drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c=1507=static int hisi_acc_vfio_pci_open_device(struct vfio_device *core_vdev)\n--\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c-1512-\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c:1513:\tret = vfio_pci_core_enable(vdev);\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c-1514-\tif (ret)\n--\ndrivers/vfio/pci/ism/main.c=53=static int ism_vfio_pci_open_device(struct vfio_device *core_vdev)\n--\ndrivers/vfio/pci/ism/main.c-62-\ndrivers/vfio/pci/ism/main.c:63:\tret = vfio_pci_core_enable(vdev);\ndrivers/vfio/pci/ism/main.c-64-\tif (ret)\n--\ndrivers/vfio/pci/mlx5/main.c=1323=static int mlx5vf_pci_open_device(struct vfio_device *core_vdev)\n--\ndrivers/vfio/pci/mlx5/main.c-1329-\ndrivers/vfio/pci/mlx5/main.c:1330:\tret = vfio_pci_core_enable(vdev);\ndrivers/vfio/pci/mlx5/main.c-1331-\tif (ret)\n--\ndrivers/vfio/pci/nvgrace-gpu/main.c=177=static int nvgrace_gpu_open_device(struct vfio_device *core_vdev)\n--\ndrivers/vfio/pci/nvgrace-gpu/main.c-186-\ndrivers/vfio/pci/nvgrace-gpu/main.c:187:\tret = vfio_pci_core_enable(vdev);\ndrivers/vfio/pci/nvgrace-gpu/main.c-188-\tif (ret)\n--\ndrivers/vfio/pci/nvgrace-gpu/main.c-195-\t * GPU readiness is checked by reading the BAR0 registers.\ndrivers/vfio/pci/nvgrace-gpu/main.c:196:\t * The BAR map was just set up by vfio_pci_core_enable(), so\ndrivers/vfio/pci/nvgrace-gpu/main.c-197-\t * bail early if that wasn't successful:\n--\ndrivers/vfio/pci/nvgrace-gpu/main.c=1087=static int nvgrace_gpu_core_open_device(struct vfio_device *core_vdev)\n--\ndrivers/vfio/pci/nvgrace-gpu/main.c-1092-\ndrivers/vfio/pci/nvgrace-gpu/main.c:1093:\tret = vfio_pci_core_enable(vdev);\ndrivers/vfio/pci/nvgrace-gpu/main.c-1094-\tif (ret)\n--\ndrivers/vfio/pci/pds/vfio_dev.c=156=static int pds_vfio_open_device(struct vfio_device *vdev)\n--\ndrivers/vfio/pci/pds/vfio_dev.c-162-\ndrivers/vfio/pci/pds/vfio_dev.c:163:\terr = vfio_pci_core_enable(\u0026pds_vfio-\u003evfio_coredev);\ndrivers/vfio/pci/pds/vfio_dev.c-164-\tif (err)\n--\ndrivers/vfio/pci/qat/main.c=61=static int qat_vf_pci_open_device(struct vfio_device *core_vdev)\n--\ndrivers/vfio/pci/qat/main.c-68-\ndrivers/vfio/pci/qat/main.c:69:\tret = vfio_pci_core_enable(vdev);\ndrivers/vfio/pci/qat/main.c-70-\tif (ret)\n--\ndrivers/vfio/pci/vfio_pci.c=126=static int vfio_pci_open_device(struct vfio_device *core_vdev)\n--\ndrivers/vfio/pci/vfio_pci.c-132-\ndrivers/vfio/pci/vfio_pci.c:133:\tret = vfio_pci_core_enable(vdev);\ndrivers/vfio/pci/vfio_pci.c-134-\tif (ret)\n--\ndrivers/vfio/pci/vfio_pci_core.c=593=static void vfio_pci_tph_dev_deinit(struct vfio_pci_core_device *vdev);\ndrivers/vfio/pci/vfio_pci_core.c-594-\ndrivers/vfio/pci/vfio_pci_core.c:595:int vfio_pci_core_enable(struct vfio_pci_core_device *vdev)\ndrivers/vfio/pci/vfio_pci_core.c-596-{\n--\ndrivers/vfio/pci/vfio_pci_core.c-693-}\ndrivers/vfio/pci/vfio_pci_core.c:694:EXPORT_SYMBOL_GPL(vfio_pci_core_enable);\ndrivers/vfio/pci/vfio_pci_core.c-695-\n--\ndrivers/vfio/pci/virtio/main.c=24=static int virtiovf_pci_open_device(struct vfio_device *core_vdev)\n--\ndrivers/vfio/pci/virtio/main.c-30-\ndrivers/vfio/pci/virtio/main.c:31:\tret = vfio_pci_core_enable(vdev);\ndrivers/vfio/pci/virtio/main.c-32-\tif (ret)\n--\ndrivers/vfio/pci/xe/main.c=149=static int xe_vfio_pci_open_device(struct vfio_device *core_vdev)\n--\ndrivers/vfio/pci/xe/main.c-155-\ndrivers/vfio/pci/xe/main.c:156:\tret = vfio_pci_core_enable(vdev);\ndrivers/vfio/pci/xe/main.c-157-\tif (ret)\n--\ninclude/linux/vfio_pci_core.h=198=int vfio_pci_core_match_token_uuid(struct vfio_device *core_vdev,\ninclude/linux/vfio_pci_core.h-199-\t\t\t\t const uuid_t *uuid);\ninclude/linux/vfio_pci_core.h:200:int vfio_pci_core_enable(struct vfio_pci_core_device *vdev);\ninclude/linux/vfio_pci_core.h-201-void vfio_pci_core_disable(struct vfio_pci_core_device *vdev);\n--\ninclude/linux/vfio_pci_core.h=236=static inline bool is_aligned_for_order(struct vm_area_struct *vma,\n--\ninclude/linux/vfio_pci_core.h-248- * BAR isn't valid, its resource wasn't acquired, or its iomap\ninclude/linux/vfio_pci_core.h:249: * failed. This shall only be used after vfio_pci_core_enable()\ninclude/linux/vfio_pci_core.h-250- * has set up the BAR maps and before vfio_pci_core_disable()\n"
} |
| 19/2 | 2026/11/22 09:29 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 38024 output: 37 thoughts: 3178 Thoughts: **Analyzing the VFIO-PCI and TPH Patch for Fuzzing Potential** Okay, here's the breakdown of my thought process. I'm starting by tracing how `vfio_pci_open_device()` leads to `vfio_pci_core_enable`, and from there, wondering how virtio or other QEMU devices might connect to VFIO-PCI or `virtiovf_pci`. My focus is on what happens when a `VFIO_GROUP_GET_DEVICE_FD` or `VFIO_DEVICE_BIND_IOMMUFD` call comes in on a VFIO-PCI device. I see the open calls `vfio_pci_core_enable`, and that ioctls are possible like `VFIO_DEVICE_FEATURE`, reading/writing to config space (through `vfio_tph_config_read`, `vfio_tph_config_write`). Now, I'm diving into the fuzzing criteria to see if this patch is worth testing. I'm re-reading sections 2 and 3 of the instructions, focusing on the negative and positive criteria. Basically, I have to figure out if the changes are *reachable* executable code. I'm taking a close look at the modules changed: `drivers/pci/tph.c`, `drivers/vfio/pci/vfio_pci_config.c`, and `drivers/vfio/pci/vfio_pci_core.c`. I'm going through each change, checking if they could be hit. Specifically, I am thinking about how these functions are being used: - `pcie_tph_*` calls in `drivers/pci/tph.c` - `tph_policy` module parameters in `drivers/vfio/pci/vfio_pci.c` - Functions in `drivers/vfio/pci/vfio_pci_config.c` like `vfio_find_cap_start`, `vfio_tph_*` calls - Functions in `drivers/vfio/pci/vfio_pci_core.c` like `vfio_pci_core_*`, `vfio_pci_tph_*` My central question is whether VFIO-PCI is reachable, and whether PCI TPH itself is relevant. I'm asking myself, are PCI devices configured with TPH enabled, or is VFIO open for fuzzing or TPH emulation. I am looking at `vfio_pci_core_enable` to see what is happening. The key call is `vfio_pci_tph_dev_init`. And that eventually calls `pcie_std_tph_supported()`. `pcie_std_tph_supported` requires `pdev->tph_cap` to be present, meaning that we need a PCIe device that supports TPH. Now I have to go through and figure out what devices in QEMU have PCIe TPH capability. Specifically, is `PCI_EXT_CAP_ID_TPH` (0x17) present in any virtual device? Now I am going back to section 2. I have to see if any of these patches fall under any of the exceptions: non-kernel changes, unreachable hardware or unreachable paths. Is `drivers/vfio/pci/` or `drivers/pci/tph.c` a vendor-specific driver? NO! So I need to return `WorthFuzzing=true`. Now I need to prove that some of the modified code is executable. `pci_tph_init` is called during boot for every PCI device, so it is reachable. All QEMU VM's boot with PCI devices. The `vfio_pci_core_init` function gets called during module load. That is how the CPU hotplug gets initialized (`vfio_pci_tph_cpuhp_init`). This also initializes the `ecap_perms[PCI_EXT_CAP_ID_TPH]` variable. Now I just need to determine if syzkaller can interact with VFIO and `vfio_pci` devices and search the kernel for relevant test devices. |
| 20/2 | 2026/11/22 09:30 | tool | grepper |
0mArgs:{
"Expression": "MODULE_DEVICE_TABLE\\(pci",
"PathPrefixes": [
"drivers/vfio/pci/"
]
}Results: {
"Output": "drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c=1720=static const struct pci_device_id hisi_acc_vfio_pci_table[] = {\n--\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c-1726-\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c:1727:MODULE_DEVICE_TABLE(pci, hisi_acc_vfio_pci_table);\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c-1728-\n--\ndrivers/vfio/pci/ism/main.c=386=static const struct pci_device_id ism_device_table[] = {\n--\ndrivers/vfio/pci/ism/main.c-390-};\ndrivers/vfio/pci/ism/main.c:391:MODULE_DEVICE_TABLE(pci, ism_device_table);\ndrivers/vfio/pci/ism/main.c-392-\n--\ndrivers/vfio/pci/mlx5/main.c=1437=static const struct pci_device_id mlx5vf_pci_table[] = {\n--\ndrivers/vfio/pci/mlx5/main.c-1441-\ndrivers/vfio/pci/mlx5/main.c:1442:MODULE_DEVICE_TABLE(pci, mlx5vf_pci_table);\ndrivers/vfio/pci/mlx5/main.c-1443-\n--\ndrivers/vfio/pci/nvgrace-gpu/main.c=1397=static const struct pci_device_id nvgrace_gpu_vfio_pci_table[] = {\n--\ndrivers/vfio/pci/nvgrace-gpu/main.c-1410-\ndrivers/vfio/pci/nvgrace-gpu/main.c:1411:MODULE_DEVICE_TABLE(pci, nvgrace_gpu_vfio_pci_table);\ndrivers/vfio/pci/nvgrace-gpu/main.c-1412-\n--\ndrivers/vfio/pci/pds/pci_drv.c=162=static const struct pci_device_id pds_vfio_pci_table[] = {\n--\ndrivers/vfio/pci/pds/pci_drv.c-165-};\ndrivers/vfio/pci/pds/pci_drv.c:166:MODULE_DEVICE_TABLE(pci, pds_vfio_pci_table);\ndrivers/vfio/pci/pds/pci_drv.c-167-\n--\ndrivers/vfio/pci/qat/main.c=675=static const struct pci_device_id qat_vf_vfio_pci_table[] = {\n--\ndrivers/vfio/pci/qat/main.c-685-};\ndrivers/vfio/pci/qat/main.c:686:MODULE_DEVICE_TABLE(pci, qat_vf_vfio_pci_table);\ndrivers/vfio/pci/qat/main.c-687-\n--\ndrivers/vfio/pci/vfio_pci.c=243=static const struct pci_device_id vfio_pci_table[] = {\n--\ndrivers/vfio/pci/vfio_pci.c-247-\ndrivers/vfio/pci/vfio_pci.c:248:MODULE_DEVICE_TABLE(pci, vfio_pci_table);\ndrivers/vfio/pci/vfio_pci.c-249-\n--\ndrivers/vfio/pci/virtio/main.c=198=static const struct pci_device_id virtiovf_pci_table[] = {\n--\ndrivers/vfio/pci/virtio/main.c-204-\ndrivers/vfio/pci/virtio/main.c:205:MODULE_DEVICE_TABLE(pci, virtiovf_pci_table);\ndrivers/vfio/pci/virtio/main.c-206-\n--\ndrivers/vfio/pci/xe/main.c=579=static const struct pci_device_id xe_vfio_pci_table[] = {\n--\ndrivers/vfio/pci/xe/main.c-587-};\ndrivers/vfio/pci/xe/main.c:588:MODULE_DEVICE_TABLE(pci, xe_vfio_pci_table);\ndrivers/vfio/pci/xe/main.c-589-\n"
} |
| 21/2 | 2026/11/22 09:30 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 43358 output: 43 thoughts: 48 Thoughts: Here's my analysis of the provided snippet, framed as my own thought process: **Diving into the VFIO-PCI Driver** Okay, let's get down to brass tacks. I need to understand this VFIO-PCI driver better, specifically the area around line 243 in `drivers/vfio/pci/vfio_pci.c`. My immediate goal here is to understand the context and functionality in this particular section of code. I'll need to carefully examine what's happening around that specific line to grasp the overall behavior and how it interacts with the rest of the driver. I expect to be looking at data structures and function calls in this region. |
| 22/2 | 2026/11/22 09:30 | tool | read-file |
0mArgs:{
"File": "drivers/vfio/pci/vfio_pci.c",
"FirstLine": 235,
"LineCount": 35
}Results: {
"Contents": " 235:\t\tstruct vfio_pci_core_device *vdev = dev_get_drvdata(\u0026pdev-\u003edev);\n 236:\t\n 237:\t\tif (!enable_sriov)\n 238:\t\t\treturn -ENOENT;\n 239:\t\n 240:\t\treturn vfio_pci_core_sriov_configure(vdev, nr_virtfn);\n 241:\t}\n 242:\t\n 243:\tstatic const struct pci_device_id vfio_pci_table[] = {\n 244:\t\t{ PCI_DRIVER_OVERRIDE_DEVICE_VFIO(PCI_ANY_ID, PCI_ANY_ID) }, /* match all by default */\n 245:\t\t{}\n 246:\t};\n 247:\t\n 248:\tMODULE_DEVICE_TABLE(pci, vfio_pci_table);\n 249:\t\n 250:\tstatic int __maybe_unused vfio_pci_pm_suspend(struct device *dev)\n 251:\t{\n 252:\t\tstruct vfio_pci_core_device *vdev = dev_get_drvdata(dev);\n 253:\t\n 254:\t\treturn vfio_pci_core_runtime_suspend(vdev);\n 255:\t}\n 256:\t\n 257:\tstatic int __maybe_unused vfio_pci_pm_resume(struct device *dev)\n 258:\t{\n 259:\t\tstruct vfio_pci_core_device *vdev = dev_get_drvdata(dev);\n 260:\t\n 261:\t\treturn vfio_pci_core_runtime_resume(vdev);\n 262:\t}\n 263:\t\n 264:\tstatic const struct dev_pm_ops vfio_pci_pm_ops = {\n 265:\t\tSET_RUNTIME_PM_OPS(vfio_pci_pm_suspend, vfio_pci_pm_resume, NULL)\n 266:\t};\n 267:\t\n 268:\tstatic pci_ers_result_t vfio_pci_aer_err_detected(struct pci_dev *pdev,\n 269:\t\t\t\t\t\t pci_channel_state_t state)\n"
} |
| 23/2 | 2026/11/22 09:30 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 44205 output: 42 thoughts: 87 Thoughts: Here's my summary, as I see it: **VFIO PCI Device Identification** Okay, so I'm digging into how VFIO handles PCI device overrides. First, I need to remind myself how these overrides are defined, so I'll quickly look at `vfio_pci_table` in the kernel code. Ah, right, it's defined with `PCI_DRIVER_OVERRIDE_DEVICE_VFIO(PCI_ANY_ID, PCI_ANY_ID)`. That means it applies generically to any device, which makes sense. Now, I need to get into the details of where this all hangs together, so I should look at `drivers/vfio/pci/virtio/main.c`. Specifically, I recall the crucial logic related to device assignment is around line 198, so I'll zero in on that section to understand how VFIO interacts with virtio devices and how it's able to manage this override. I need to refresh my understanding of the exact code path. |
| 24/2 | 2026/11/22 09:30 | tool | read-file |
0mArgs:{
"File": "drivers/vfio/pci/virtio/main.c",
"FirstLine": 195,
"LineCount": 25
}Results: {
"Contents": " 195:\t\tvfio_put_device(\u0026virtvdev-\u003ecore_device.vdev);\n 196:\t}\n 197:\t\n 198:\tstatic const struct pci_device_id virtiovf_pci_table[] = {\n 199:\t\t/* Only virtio-net and virtio-block are supported/tested so far */\n 200:\t\t{ PCI_DRIVER_OVERRIDE_DEVICE_VFIO(PCI_VENDOR_ID_REDHAT_QUMRANET, 0x1041) },\n 201:\t\t{ PCI_DRIVER_OVERRIDE_DEVICE_VFIO(PCI_VENDOR_ID_REDHAT_QUMRANET, 0x1042) },\n 202:\t\t{}\n 203:\t};\n 204:\t\n 205:\tMODULE_DEVICE_TABLE(pci, virtiovf_pci_table);\n 206:\t\n 207:\tstatic void virtiovf_pci_aer_reset_done(struct pci_dev *pdev)\n 208:\t{\n 209:\t#ifdef CONFIG_VIRTIO_VFIO_PCI_ADMIN_LEGACY\n 210:\t\tvirtiovf_legacy_io_reset_done(pdev);\n 211:\t#endif\n 212:\t\tvirtiovf_migration_reset_done(pdev);\n 213:\t}\n 214:\t\n 215:\tstatic const struct pci_error_handlers virtiovf_err_handlers = {\n 216:\t\t.reset_done = virtiovf_pci_aer_reset_done,\n 217:\t\t.error_detected = virtiovf_aer_err_detected,\n 218:\t};\n 219:\t\n"
} |
| 25/2 | 2026/11/22 09:30 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 45017 output: 32 thoughts: 328 Thoughts: **VFIO Device Feature Handling: A Quick Refresher** Okay, let's dive back into the `VFIO_DEVICE_FEATURE` handling within `vfio_pci_core_ioctl_feature`. I need to solidify my understanding of what's happening when this IOCTL is invoked. My thought process is now on the case statement: I see three primary sub-cases within the `VFIO_DEVICE_FEATURE` handler: `VFIO_DEVICE_FEATURE_TPH`, `VFIO_DEVICE_FEATURE_TPH_PROGRAM`, and `VFIO_DEVICE_FEATURE_TPH_RESOLVE`. Each of these seems related to Translation Lookaside Buffer (TLB) and Page Table Handling (TPH), which I should already know, but want to confirm. But, before I get too deep, how does userspace even *get* to this `VFIO_DEVICE_FEATURE` point? Right, it's the standard flow: user space either opens `/dev/vfio/vfio`, `/dev/vfio/devices/...`, or, using `iommufd`, gets a device file descriptor. Then the IOCTL call with `VFIO_DEVICE_FEATURE` and the relevant arguments is made. I'm visualizing the code flow now... Now, a quick question: Does syzkaller actually *test* this feature? I should check the syzkaller definitions and samples to see if it's exercising the `ioctl(device_fd, VFIO_DEVICE_FEATURE, ...)` path. Need to confirm that this is a tested and stable interface. To do this, I will need to look into `drivers/vfio/vfio_main.c` or, more specifically, `drivers/vfio/pci/vfio_pci_core.c` and confirm. |
| 26/2 | 2026/11/22 09:30 | tool | grepper |
0mArgs:{
"Expression": "VFIO_DEVICE_FEATURE",
"PathPrefixes": [
"drivers/vfio/"
]
}Results: {
"Output": "\nFull output is too long, showing 200 out of 205 lines.\nUse more precise expression or PathPrefixes if possible.\n\nNumber of matching lines per file (6 files in total):\ndrivers/vfio/cdx/main.c:5\ndrivers/vfio/pci/mlx5/main.c:1\ndrivers/vfio/pci/vfio_pci_core.c:18\ndrivers/vfio/pci/vfio_pci_dmabuf.c:1\ndrivers/vfio/pci/vfio_pci_zdev.c:1\ndrivers/vfio/vfio_main.c:24\n\ndrivers/vfio/cdx/main.c=84=static int vfio_cdx_bm_ctrl(struct vfio_device *core_vdev, u32 flags,\n--\ndrivers/vfio/cdx/main.c-97-\ndrivers/vfio/cdx/main.c:98:\tret = vfio_check_feature(flags, argsz, VFIO_DEVICE_FEATURE_SET,\ndrivers/vfio/cdx/main.c-99-\t\t\t\t sizeof(ops));\n--\ndrivers/vfio/cdx/main.c-106-\tswitch (ops.op) {\ndrivers/vfio/cdx/main.c:107:\tcase VFIO_DEVICE_FEATURE_CLEAR_MASTER:\ndrivers/vfio/cdx/main.c-108-\t\treturn cdx_clear_master(cdx_dev);\ndrivers/vfio/cdx/main.c:109:\tcase VFIO_DEVICE_FEATURE_SET_MASTER:\ndrivers/vfio/cdx/main.c-110-\t\treturn cdx_set_master(cdx_dev);\n--\ndrivers/vfio/cdx/main.c=116=static int vfio_cdx_ioctl_feature(struct vfio_device *device, u32 flags,\n--\ndrivers/vfio/cdx/main.c-118-{\ndrivers/vfio/cdx/main.c:119:\tswitch (flags \u0026 VFIO_DEVICE_FEATURE_MASK) {\ndrivers/vfio/cdx/main.c:120:\tcase VFIO_DEVICE_FEATURE_BUS_MASTER:\ndrivers/vfio/cdx/main.c-121-\t\treturn vfio_cdx_bm_ctrl(device, flags, arg, argsz);\n--\ndrivers/vfio/pci/mlx5/main.c=459=static long mlx5vf_precopy_ioctl(struct file *filp, unsigned int cmd,\n--\ndrivers/vfio/pci/mlx5/main.c-509-\t/*\ndrivers/vfio/pci/mlx5/main.c:510:\t * opt-in for VFIO_DEVICE_FEATURE_MIG_PRECOPY_INFOv2 serves\ndrivers/vfio/pci/mlx5/main.c-511-\t * as opt-in for VFIO_PRECOPY_INFO_REINIT as well\n--\ndrivers/vfio/pci/vfio_pci_core.c=410=static int vfio_pci_core_pm_entry(struct vfio_pci_core_device *vdev, u32 flags,\n--\ndrivers/vfio/pci/vfio_pci_core.c-414-\ndrivers/vfio/pci/vfio_pci_core.c:415:\tret = vfio_check_feature(flags, argsz, VFIO_DEVICE_FEATURE_SET, 0);\ndrivers/vfio/pci/vfio_pci_core.c-416-\tif (ret != 1)\n--\ndrivers/vfio/pci/vfio_pci_core.c=428=static int vfio_pci_core_pm_entry_with_wakeup(\n--\ndrivers/vfio/pci/vfio_pci_core.c-436-\ndrivers/vfio/pci/vfio_pci_core.c:437:\tret = vfio_check_feature(flags, argsz, VFIO_DEVICE_FEATURE_SET,\ndrivers/vfio/pci/vfio_pci_core.c-438-\t\t\t\t sizeof(entry));\n--\ndrivers/vfio/pci/vfio_pci_core.c=485=static int vfio_pci_core_pm_exit(struct vfio_pci_core_device *vdev, u32 flags,\n--\ndrivers/vfio/pci/vfio_pci_core.c-489-\ndrivers/vfio/pci/vfio_pci_core.c:490:\tret = vfio_check_feature(flags, argsz, VFIO_DEVICE_FEATURE_SET, 0);\ndrivers/vfio/pci/vfio_pci_core.c-491-\tif (ret != 1)\n--\ndrivers/vfio/pci/vfio_pci_core.c=1601=static int vfio_pci_core_feature_token(struct vfio_pci_core_device *vdev,\n--\ndrivers/vfio/pci/vfio_pci_core.c-1613-\t */\ndrivers/vfio/pci/vfio_pci_core.c:1614:\tret = vfio_check_feature(flags, argsz, VFIO_DEVICE_FEATURE_SET,\ndrivers/vfio/pci/vfio_pci_core.c-1615-\t\t\t\t sizeof(uuid));\n--\ndrivers/vfio/pci/vfio_pci_core.c=1743=static int vfio_pci_core_feature_tph(struct vfio_pci_core_device *vdev,\n--\ndrivers/vfio/pci/vfio_pci_core.c-1754-\tret = vfio_check_feature(flags, argsz,\ndrivers/vfio/pci/vfio_pci_core.c:1755:\t\t\tVFIO_DEVICE_FEATURE_GET | VFIO_DEVICE_FEATURE_SET,\ndrivers/vfio/pci/vfio_pci_core.c-1756-\t\t\tsizeof(tph));\n--\ndrivers/vfio/pci/vfio_pci_core.c-1762-\ndrivers/vfio/pci/vfio_pci_core.c:1763:\tif (flags \u0026 VFIO_DEVICE_FEATURE_SET) {\ndrivers/vfio/pci/vfio_pci_core.c-1764-\t\tif (tph.flags != 0)\n--\ndrivers/vfio/pci/vfio_pci_core.c=1833=static int vfio_pci_core_feature_tph_program(struct vfio_pci_core_device *vdev,\n--\ndrivers/vfio/pci/vfio_pci_core.c-1850-\ndrivers/vfio/pci/vfio_pci_core.c:1851:\tret = vfio_check_feature(flags, argsz, VFIO_DEVICE_FEATURE_SET,\ndrivers/vfio/pci/vfio_pci_core.c-1852-\t\t\t\t sizeof(program));\n--\ndrivers/vfio/pci/vfio_pci_core.c=1926=static int vfio_pci_core_feature_tph_resolve(struct vfio_pci_core_device *vdev,\n--\ndrivers/vfio/pci/vfio_pci_core.c-1939-\ndrivers/vfio/pci/vfio_pci_core.c:1940:\tret = vfio_check_feature(flags, argsz, VFIO_DEVICE_FEATURE_GET,\ndrivers/vfio/pci/vfio_pci_core.c-1941-\t\t\t\t sizeof(resolve));\n--\ndrivers/vfio/pci/vfio_pci_core.c=1970=int vfio_pci_core_ioctl_feature(struct vfio_device *device, u32 flags,\n--\ndrivers/vfio/pci/vfio_pci_core.c-1975-\ndrivers/vfio/pci/vfio_pci_core.c:1976:\tswitch (flags \u0026 VFIO_DEVICE_FEATURE_MASK) {\ndrivers/vfio/pci/vfio_pci_core.c:1977:\tcase VFIO_DEVICE_FEATURE_LOW_POWER_ENTRY:\ndrivers/vfio/pci/vfio_pci_core.c-1978-\t\treturn vfio_pci_core_pm_entry(vdev, flags, arg, argsz);\ndrivers/vfio/pci/vfio_pci_core.c:1979:\tcase VFIO_DEVICE_FEATURE_LOW_POWER_ENTRY_WITH_WAKEUP:\ndrivers/vfio/pci/vfio_pci_core.c-1980-\t\treturn vfio_pci_core_pm_entry_with_wakeup(vdev, flags,\ndrivers/vfio/pci/vfio_pci_core.c-1981-\t\t\t\t\t\t\t arg, argsz);\ndrivers/vfio/pci/vfio_pci_core.c:1982:\tcase VFIO_DEVICE_FEATURE_LOW_POWER_EXIT:\ndrivers/vfio/pci/vfio_pci_core.c-1983-\t\treturn vfio_pci_core_pm_exit(vdev, flags, arg, argsz);\ndrivers/vfio/pci/vfio_pci_core.c:1984:\tcase VFIO_DEVICE_FEATURE_PCI_VF_TOKEN:\ndrivers/vfio/pci/vfio_pci_core.c-1985-\t\treturn vfio_pci_core_feature_token(vdev, flags, arg, argsz);\ndrivers/vfio/pci/vfio_pci_core.c:1986:\tcase VFIO_DEVICE_FEATURE_DMA_BUF:\ndrivers/vfio/pci/vfio_pci_core.c-1987-\t\treturn vfio_pci_core_feature_dma_buf(vdev, flags, arg, argsz);\ndrivers/vfio/pci/vfio_pci_core.c:1988:\tcase VFIO_DEVICE_FEATURE_ZPCI_ERROR:\ndrivers/vfio/pci/vfio_pci_core.c-1989-\t\treturn vfio_pci_zdev_feature_err(device, flags, arg, argsz);\ndrivers/vfio/pci/vfio_pci_core.c:1990:\tcase VFIO_DEVICE_FEATURE_TPH:\ndrivers/vfio/pci/vfio_pci_core.c-1991-\t\treturn vfio_pci_core_feature_tph(vdev, flags, arg, argsz);\ndrivers/vfio/pci/vfio_pci_core.c:1992:\tcase VFIO_DEVICE_FEATURE_TPH_PROGRAM:\ndrivers/vfio/pci/vfio_pci_core.c-1993-\t\treturn vfio_pci_core_feature_tph_program(vdev, flags,\ndrivers/vfio/pci/vfio_pci_core.c-1994-\t\t\t\t\t\t\t arg, argsz);\ndrivers/vfio/pci/vfio_pci_core.c:1995:\tcase VFIO_DEVICE_FEATURE_TPH_RESOLVE:\ndrivers/vfio/pci/vfio_pci_core.c-1996-\t\treturn vfio_pci_core_feature_tph_resolve(vdev, flags,\n--\ndrivers/vfio/pci/vfio_pci_dmabuf.c=221=int vfio_pci_core_feature_dma_buf(struct vfio_pci_core_device *vdev, u32 flags,\n--\ndrivers/vfio/pci/vfio_pci_dmabuf.c-234-\ndrivers/vfio/pci/vfio_pci_dmabuf.c:235:\tret = vfio_check_feature(flags, argsz, VFIO_DEVICE_FEATURE_GET,\ndrivers/vfio/pci/vfio_pci_dmabuf.c-236-\t\t\t\t sizeof(get_dma_buf));\n--\ndrivers/vfio/pci/vfio_pci_zdev.c=145=int vfio_pci_zdev_feature_err(struct vfio_device *device, u32 flags,\n--\ndrivers/vfio/pci/vfio_pci_zdev.c-158-\ndrivers/vfio/pci/vfio_pci_zdev.c:159:\tret = vfio_check_feature(flags, argsz, VFIO_DEVICE_FEATURE_GET,\ndrivers/vfio/pci/vfio_pci_zdev.c-160-\t\t\t\t sizeof(err));\n--\ndrivers/vfio/vfio_main.c=895=vfio_ioctl_device_feature_mig_device_state(struct vfio_device *device,\n--\ndrivers/vfio/vfio_main.c-908-\tret = vfio_check_feature(flags, argsz,\ndrivers/vfio/vfio_main.c:909:\t\t\t\t VFIO_DEVICE_FEATURE_SET |\ndrivers/vfio/vfio_main.c:910:\t\t\t\t VFIO_DEVICE_FEATURE_GET,\ndrivers/vfio/vfio_main.c-911-\t\t\t\t sizeof(mig));\n--\ndrivers/vfio/vfio_main.c-917-\ndrivers/vfio/vfio_main.c:918:\tif (flags \u0026 VFIO_DEVICE_FEATURE_GET) {\ndrivers/vfio/vfio_main.c-919-\t\tenum vfio_device_mig_state curr_state;\n--\ndrivers/vfio/vfio_main.c-928-\ndrivers/vfio/vfio_main.c:929:\t/* Handle the VFIO_DEVICE_FEATURE_SET */\ndrivers/vfio/vfio_main.c-930-\tfilp = device-\u003emig_ops-\u003emigration_set_state(device, mig.device_state);\n--\ndrivers/vfio/vfio_main.c=945=vfio_ioctl_device_feature_migration_data_size(struct vfio_device *device,\n--\ndrivers/vfio/vfio_main.c-955-\ndrivers/vfio/vfio_main.c:956:\tret = vfio_check_feature(flags, argsz, VFIO_DEVICE_FEATURE_GET,\ndrivers/vfio/vfio_main.c-957-\t\t\t\t sizeof(data_size));\n--\ndrivers/vfio/vfio_main.c=973=vfio_ioctl_device_feature_migration_precopy_info_v2(struct vfio_device *device,\n--\ndrivers/vfio/vfio_main.c-980-\ndrivers/vfio/vfio_main.c:981:\tret = vfio_check_feature(flags, argsz, VFIO_DEVICE_FEATURE_SET, 0);\ndrivers/vfio/vfio_main.c-982-\tif (ret != 1)\n--\ndrivers/vfio/vfio_main.c=989=static int vfio_ioctl_device_feature_migration(struct vfio_device *device,\n--\ndrivers/vfio/vfio_main.c-1000-\ndrivers/vfio/vfio_main.c:1001:\tret = vfio_check_feature(flags, argsz, VFIO_DEVICE_FEATURE_GET,\ndrivers/vfio/vfio_main.c-1002-\t\t\t\t sizeof(mig));\n--\ndrivers/vfio/vfio_main.c=1072=vfio_ioctl_device_feature_logging_start(struct vfio_device *device,\n--\ndrivers/vfio/vfio_main.c-1091-\tret = vfio_check_feature(flags, argsz,\ndrivers/vfio/vfio_main.c:1092:\t\t\t\t VFIO_DEVICE_FEATURE_SET,\ndrivers/vfio/vfio_main.c-1093-\t\t\t\t sizeof(control));\n--\ndrivers/vfio/vfio_main.c=1156=vfio_ioctl_device_feature_logging_stop(struct vfio_device *device,\n--\ndrivers/vfio/vfio_main.c-1165-\tret = vfio_check_feature(flags, argsz,\ndrivers/vfio/vfio_main.c:1166:\t\t\t\t VFIO_DEVICE_FEATURE_SET, 0);\ndrivers/vfio/vfio_main.c-1167-\tif (ret != 1)\n--\ndrivers/vfio/vfio_main.c=1183=vfio_ioctl_device_feature_logging_report(struct vfio_device *device,\n--\ndrivers/vfio/vfio_main.c-1198-\tret = vfio_check_feature(flags, argsz,\ndrivers/vfio/vfio_main.c:1199:\t\t\t\t VFIO_DEVICE_FEATURE_GET,\ndrivers/vfio/vfio_main.c-1200-\t\t\t\t sizeof(report));\n--\ndrivers/vfio/vfio_main.c=1227=static int vfio_ioctl_device_feature(struct vfio_device *device,\n--\ndrivers/vfio/vfio_main.c-1240-\tif (feature.flags \u0026\ndrivers/vfio/vfio_main.c:1241:\t ~(VFIO_DEVICE_FEATURE_MASK | VFIO_DEVICE_FEATURE_SET |\ndrivers/vfio/vfio_main.c:1242:\t VFIO_DEVICE_FEATURE_GET | VFIO_DEVICE_FEATURE_PROBE))\ndrivers/vfio/vfio_main.c-1243-\t\treturn -EINVAL;\n--\ndrivers/vfio/vfio_main.c-1245-\t/* GET \u0026 SET are mutually exclusive except with PROBE */\ndrivers/vfio/vfio_main.c:1246:\tif (!(feature.flags \u0026 VFIO_DEVICE_FEATURE_PROBE) \u0026\u0026\ndrivers/vfio/vfio_main.c:1247:\t (feature.flags \u0026 VFIO_DEVICE_FEATURE_SET) \u0026\u0026\ndrivers/vfio/vfio_main.c:1248:\t (feature.flags \u0026 VFIO_DEVICE_FEATURE_GET))\ndrivers/vfio/vfio_main.c-1249-\t\treturn -EINVAL;\ndrivers/vfio/vfio_main.c-1250-\ndrivers/vfio/vfio_main.c:1251:\tswitch (feature.flags \u0026 VFIO_DEVICE_FEATURE_MASK) {\ndrivers/vfio/vfio_main.c:1252:\tcase VFIO_DEVICE_FEATURE_MIGRATION:\ndrivers/vfio/vfio_main.c-1253-\t\treturn vfio_ioctl_device_feature_migration(\n--\ndrivers/vfio/vfio_main.c-1255-\t\t\tfeature.argsz - minsz);\ndrivers/vfio/vfio_main.c:1256:\tcase VFIO_DEVICE_FEATURE_MIG_DEVICE_STATE:\ndrivers/vfio/vfio_main.c-1257-\t\treturn vfio_ioctl_device_feature_mig_device_state(\n--\ndrivers/vfio/vfio_main.c-1259-\t\t\tfeature.argsz - minsz);\ndrivers/vfio/vfio_main.c:1260:\tcase VFIO_DEVICE_FEATURE_DMA_LOGGING_START:\ndrivers/vfio/vfio_main.c-1261-\t\treturn vfio_ioctl_device_feature_logging_start(\n--\ndrivers/vfio/vfio_main.c-1263-\t\t\tfeature.argsz - minsz);\ndrivers/vfio/vfio_main.c:1264:\tcase VFIO_DEVICE_FEATURE_DMA_LOGGING_STOP:\ndrivers/vfio/vfio_main.c-1265-\t\treturn vfio_ioctl_device_feature_logging_stop(\n--\ndrivers/vfio/vfio_main.c-1267-\t\t\tfeature.argsz - minsz);\ndrivers/vfio/vfio_main.c:1268:\tcase VFIO_DEVICE_FEATURE_DMA_LOGGING_REPORT:\ndrivers/vfio/vfio_main.c-1269-\t\treturn vfio_ioctl_device_feature_logging_report(\n--\ndrivers/vfio/vfio_main.c-1271-\t\t\tfeature.argsz - minsz);\ndrivers/vfio/vfio_main.c:1272:\tcase VFIO_DEVICE_FEATURE_MIG_DATA_SIZE:\ndrivers/vfio/vfio_main.c-1273-\t\treturn vfio_ioctl_device_feature_migration_data_size(\n--\ndrivers/vfio/vfio_main.c-1275-\t\t\tfeature.argsz - minsz);\ndrivers/vfio/vfio_main.c:1276:\tcase VFIO_DEVICE_FEATURE_MIG_PRECOPY_INFOv2:\ndrivers/vfio/vfio_main.c-1277-\t\treturn vfio_ioctl_device_feature_migration_precopy_info_v2(\n--\n\n"
} |
| 27/2 | 2026/11/22 09:30 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 51155 output: 40 thoughts: 28 Thoughts: Okay, here's the summary, written as requested: **Peering into vfio_main.c - A Familiar Haunt** Alright, let's dive in. My focus narrows down to `drivers/vfio/vfio_main.c`, specifically around line 1280. I've been here countless times before, navigating the labyrinthine logic of the VFIO core. I know that region well. I'm probably looking at something related to device initialization, resource allocation, or maybe even error handling during a specific operation. Based on the context, I suspect it is related to a device's life cycle. I'm going in with a strong hypothesis, based on prior experience with this codebase, that I can quickly determine the section's purpose. Let's see if the code confirms my initial hunch. It's time to get a closer look. |
| 28/2 | 2026/11/22 09:31 | tool | read-file |
0mArgs:{
"File": "drivers/vfio/vfio_main.c",
"FirstLine": 1270,
"LineCount": 30
}Results: {
"Contents": "1270:\t\t\t\tdevice, feature.flags, arg-\u003edata,\n1271:\t\t\t\tfeature.argsz - minsz);\n1272:\t\tcase VFIO_DEVICE_FEATURE_MIG_DATA_SIZE:\n1273:\t\t\treturn vfio_ioctl_device_feature_migration_data_size(\n1274:\t\t\t\tdevice, feature.flags, arg-\u003edata,\n1275:\t\t\t\tfeature.argsz - minsz);\n1276:\t\tcase VFIO_DEVICE_FEATURE_MIG_PRECOPY_INFOv2:\n1277:\t\t\treturn vfio_ioctl_device_feature_migration_precopy_info_v2(\n1278:\t\t\t\tdevice, feature.flags, feature.argsz - minsz);\n1279:\t\tdefault:\n1280:\t\t\tif (unlikely(!device-\u003eops-\u003edevice_feature))\n1281:\t\t\t\treturn -ENOTTY;\n1282:\t\t\treturn device-\u003eops-\u003edevice_feature(device, feature.flags,\n1283:\t\t\t\t\t\t\t arg-\u003edata,\n1284:\t\t\t\t\t\t\t feature.argsz - minsz);\n1285:\t\t}\n1286:\t}\n1287:\t\n1288:\tstatic long vfio_get_region_info(struct vfio_device *device,\n1289:\t\t\t\t\t struct vfio_region_info __user *arg)\n1290:\t{\n1291:\t\tunsigned long minsz = offsetofend(struct vfio_region_info, offset);\n1292:\t\tstruct vfio_region_info info = {};\n1293:\t\tstruct vfio_info_cap caps = {};\n1294:\t\tint ret;\n1295:\t\n1296:\t\tif (unlikely(!device-\u003eops-\u003eget_region_info_caps))\n1297:\t\t\treturn -EINVAL;\n1298:\t\n1299:\t\tif (copy_from_user(\u0026info, arg, minsz))\n"
} |
| 29/2 | 2026/11/22 09:31 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 51914 output: 30 thoughts: 40 Thoughts: Here's my analysis of the provided snippet, as though it were my train of thought: **Diving into the VFIO PCI Structure** Okay, so I'm looking at this `device->ops->device_feature` pointer. The key thing here is that it's pointing right to `vfio_pci_core_ioctl_feature`. That's a good starting point. This means the feature handling for this specific VFIO PCI device is going to be handled by that function, which I already have a handle on. Now, to make sure I'm following the correct execution path, I'm going to quickly refresh my understanding by checking the `vfio_pci_ops` structure itself. I need to make sure this is what I expect. I'll probably cross reference this with my notes on other `vfio_pci` calls to fully contextualize the `ioctl` call path that would trigger this function. Understanding this context will allow me to assess the overall implementation and any potential edge cases with the `device_feature` handling. |
| 30/2 | 2026/11/22 09:31 | tool | grepper |
0mArgs:{
"Expression": "\\.device_feature",
"PathPrefixes": [
"drivers/vfio/"
]
}Results: {
"Output": "drivers/vfio/cdx/main.c=298=static const struct vfio_device_ops vfio_cdx_ops = {\n--\ndrivers/vfio/cdx/main.c-305-\t.get_region_info_caps = vfio_cdx_ioctl_get_region_info,\ndrivers/vfio/cdx/main.c:306:\t.device_feature = vfio_cdx_ioctl_feature,\ndrivers/vfio/cdx/main.c-307-\t.mmap\t\t= vfio_cdx_mmap,\n--\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c=1574=static const struct vfio_device_ops hisi_acc_vfio_pci_migrn_ops = {\n--\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c-1581-\t.get_region_info_caps = hisi_acc_vfio_ioctl_get_region,\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c:1582:\t.device_feature = vfio_pci_core_ioctl_feature,\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c-1583-\t.read = hisi_acc_vfio_pci_read,\n--\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c=1595=static const struct vfio_device_ops hisi_acc_vfio_pci_ops = {\n--\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c-1602-\t.get_region_info_caps = vfio_pci_ioctl_get_region_info,\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c:1603:\t.device_feature = vfio_pci_core_ioctl_feature,\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c-1604-\t.read = vfio_pci_core_read,\n--\ndrivers/vfio/pci/ism/main.c=338=static const struct vfio_device_ops ism_pci_ops = {\n--\ndrivers/vfio/pci/ism/main.c-345-\t.get_region_info_caps = ism_vfio_pci_ioctl_get_region_info,\ndrivers/vfio/pci/ism/main.c:346:\t.device_feature = vfio_pci_core_ioctl_feature,\ndrivers/vfio/pci/ism/main.c-347-\t.read = ism_vfio_pci_read,\n--\ndrivers/vfio/pci/mlx5/main.c=1386=static const struct vfio_device_ops mlx5vf_pci_ops = {\n--\ndrivers/vfio/pci/mlx5/main.c-1393-\t.get_region_info_caps = vfio_pci_ioctl_get_region_info,\ndrivers/vfio/pci/mlx5/main.c:1394:\t.device_feature = vfio_pci_core_ioctl_feature,\ndrivers/vfio/pci/mlx5/main.c-1395-\t.read = vfio_pci_core_read,\n--\ndrivers/vfio/pci/nvgrace-gpu/main.c=1066=static const struct vfio_device_ops nvgrace_gpu_pci_ops = {\n--\ndrivers/vfio/pci/nvgrace-gpu/main.c-1073-\t.get_region_info_caps = nvgrace_gpu_ioctl_get_region_info,\ndrivers/vfio/pci/nvgrace-gpu/main.c:1074:\t.device_feature\t= vfio_pci_core_ioctl_feature,\ndrivers/vfio/pci/nvgrace-gpu/main.c-1075-\t.read\t\t= nvgrace_gpu_read,\n--\ndrivers/vfio/pci/nvgrace-gpu/main.c=1106=static const struct vfio_device_ops nvgrace_gpu_pci_core_ops = {\n--\ndrivers/vfio/pci/nvgrace-gpu/main.c-1113-\t.get_region_info_caps = vfio_pci_ioctl_get_region_info,\ndrivers/vfio/pci/nvgrace-gpu/main.c:1114:\t.device_feature\t= vfio_pci_core_ioctl_feature,\ndrivers/vfio/pci/nvgrace-gpu/main.c-1115-\t.read\t\t= vfio_pci_core_read,\n--\ndrivers/vfio/pci/pds/vfio_dev.c=188=static const struct vfio_device_ops pds_vfio_ops = {\n--\ndrivers/vfio/pci/pds/vfio_dev.c-195-\t.get_region_info_caps = vfio_pci_ioctl_get_region_info,\ndrivers/vfio/pci/pds/vfio_dev.c:196:\t.device_feature = vfio_pci_core_ioctl_feature,\ndrivers/vfio/pci/pds/vfio_dev.c-197-\t.read = vfio_pci_core_read,\n--\ndrivers/vfio/pci/vfio_pci.c=173=static const struct vfio_device_ops vfio_pci_ops = {\n--\ndrivers/vfio/pci/vfio_pci.c-180-\t.get_region_info_caps = vfio_pci_ioctl_get_region_info,\ndrivers/vfio/pci/vfio_pci.c:181:\t.device_feature = vfio_pci_core_ioctl_feature,\ndrivers/vfio/pci/vfio_pci.c-182-\t.read\t\t= vfio_pci_core_read,\n--\ndrivers/vfio/pci/virtio/main.c=87=static const struct vfio_device_ops virtiovf_vfio_pci_lm_ops = {\n--\ndrivers/vfio/pci/virtio/main.c-94-\t.get_region_info_caps = vfio_pci_ioctl_get_region_info,\ndrivers/vfio/pci/virtio/main.c:95:\t.device_feature = vfio_pci_core_ioctl_feature,\ndrivers/vfio/pci/virtio/main.c-96-\t.read = vfio_pci_core_read,\n--\ndrivers/vfio/pci/virtio/main.c=109=static const struct vfio_device_ops virtiovf_vfio_pci_tran_lm_ops = {\n--\ndrivers/vfio/pci/virtio/main.c-116-\t.get_region_info_caps = virtiovf_pci_ioctl_get_region_info,\ndrivers/vfio/pci/virtio/main.c:117:\t.device_feature = vfio_pci_core_ioctl_feature,\ndrivers/vfio/pci/virtio/main.c-118-\t.read = virtiovf_pci_core_read,\n--\ndrivers/vfio/pci/virtio/main.c=131=static const struct vfio_device_ops virtiovf_vfio_pci_ops = {\n--\ndrivers/vfio/pci/virtio/main.c-138-\t.get_region_info_caps = vfio_pci_ioctl_get_region_info,\ndrivers/vfio/pci/virtio/main.c:139:\t.device_feature = vfio_pci_core_ioctl_feature,\ndrivers/vfio/pci/virtio/main.c-140-\t.read = vfio_pci_core_read,\n--\ndrivers/vfio/pci/xe/main.c=525=static const struct vfio_device_ops xe_vfio_pci_ops = {\n--\ndrivers/vfio/pci/xe/main.c-532-\t.get_region_info_caps = vfio_pci_ioctl_get_region_info,\ndrivers/vfio/pci/xe/main.c:533:\t.device_feature = vfio_pci_core_ioctl_feature,\ndrivers/vfio/pci/xe/main.c-534-\t.read = vfio_pci_core_read,\n"
} |
| 31/2 | 2026/11/22 09:31 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 54432 output: 23 thoughts: 2929 Thoughts: **TPH and VFIO PCI Reachability Analysis** Okay, so I'm looking at this patch and the associated code changes, specifically the interaction between TPH (Translation Process Hardware) and VFIO-PCI. My initial observation is that both `vfio_pci_ops` and `virtiovf_vfio_pci_ops` use the same `.device_feature` (`vfio_pci_core_ioctl_feature`), which suggests a shared foundation for feature handling. The core of this patch seems to be extending virtualization capabilities for the TPH extended capability within the VFIO-PCI context. Now, let's break down the changes: 1. **`drivers/pci/tph.c`**: There are modifications to `pcie_tph_get_st_table_loc`, `pcie_tph_get_st_table_size`, and a new function `pcie_tph_get_cpu_st_ext`. There's also some interesting logic for enabling, setting, and disabling TPH, along with batch setting of steering tags using `pcie_tph_set_st_entries` in the ST table. `pci_tph_init` calculates `pdev->tph_max_type`, which is important for the TPH. `pcie_tph_dsm_supported` checks for ACPI DSM support, I'll need to keep that in mind. 2. **`drivers/vfio/pci/vfio_pci_config.c`**: This is where the magic happens. The patch adds virtualization for `PCI_EXT_CAP_ID_TPH` through functions like `init_pci_ext_cap_tph_perm`, `vfio_tph_config_read`, `vfio_tph_config_write`, and `vfio_tph_vcap_rewrite`. The key takeaway is that these functions intercept and virtualize read/write operations to the TPH extended capability when a VFIO-PCI user is interacting with the PCI config space. `vfio_tph_config_write` appears to validate mode and request type, and calls `pcie_enable_tph_ext` and `pcie_disable_tph`. 3. **`drivers/vfio/pci/vfio_pci_core.c`**: CPU hotplug support is added using the `cpuhp` framework, and a per-device initialization in `vfio_pci_core_enable`. The most interesting parts are the IOCTL handlers for `VFIO_DEVICE_FEATURE`, in particular `VFIO_DEVICE_FEATURE_TPH`, `VFIO_DEVICE_FEATURE_TPH_PROGRAM`, and `VFIO_DEVICE_FEATURE_TPH_RESOLVE`. `VFIO_DEVICE_FEATURE_TPH_PROGRAM` is particularly intricate, involving user-space data copying (`copy_from_user`), validation, tag resolution (`vfio_pci_tph_resolve_st_tag`), and the use of locks and memory locking (`vfio_pci_memory_lock_and_enable`). This all seems designed to allow a user-space process to program the TPH steering table for a virtualized device. Now, the critical question: **is this reachable by fuzzers?** The rules state that structurally unreachable code should not be fuzzed. But is this code unreachable? I know syzkaller *can* fuzz VFIO. Syzkaller includes VFIO descriptions, which suggests that VFIO PCI is a target. The typical VFIO setup involves the creation of a VFIO container, group, and device file descriptors, which can be done with `ioctl(container_fd, VFIO_SET_IOMMU, ...)` and `ioctl(group_fd, VFIO_GROUP_GET_DEVICE_FD, ...)`. What about syzkaller's QEMU images? The real test here is: Does syzkaller bind a device to vfio-pci, and is it possible for syzkaller to bind a device and exercise the code? Syzkaller doesn't run shell scripts, but it can open files, so that may be the access vector. Specifically, since `vfio_pci_core_init` is executed at boot or module load, and `pci_tph_init` is called for *every* PCI device during enumeration, these code paths are highly likely to be reached. Moreover, since `VFIO_DEVICE_FEATURE_TPH`, `VFIO_DEVICE_FEATURE_TPH_PROGRAM`, and `VFIO_DEVICE_FEATURE_TPH_RESOLVE` are IOCTLs on the vfio-pci device, and vfio is available |
| 32/2 | 2026/11/22 09:32 | tool | grepper |
0mArgs:{
"Expression": "config VIRTIO_VFIO_PCI"
}Results: {
"Output": "drivers/vfio/pci/virtio/Kconfig-1-# SPDX-License-Identifier: GPL-2.0-only\ndrivers/vfio/pci/virtio/Kconfig:2:config VIRTIO_VFIO_PCI\ndrivers/vfio/pci/virtio/Kconfig-3-\ttristate \"VFIO support for VIRTIO PCI VF devices\"\n--\ndrivers/vfio/pci/virtio/Kconfig-18-\ndrivers/vfio/pci/virtio/Kconfig:19:config VIRTIO_VFIO_PCI_ADMIN_LEGACY\ndrivers/vfio/pci/virtio/Kconfig-20-\tbool \"Legacy I/O support for VIRTIO NET PCI VF devices\"\n"
} |
| 33/2 | 2026/11/22 09:32 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 58597 output: 39 thoughts: 37 Thoughts: Okay, here's my interpretation of that thought process, tailored for an expert audience, and written in the first person: **Analyzing the VFIO Virtio Kconfig** Alright, let's dive in. The suggestion is to take a look at `drivers/vfio/pci/virtio/Kconfig`. Right. Naturally, my first thought is to understand the configuration options for VFIO's virtio support. This likely means examining the dependencies, default settings, and any conditional compilation logic defined within that Kconfig file. I need to quickly grasp how the virtio-specific features are integrated within the VFIO framework. I'll be looking for things like: * **Feature Flags:** What knobs are exposed for enabling/disabling specific virtio device features within the VFIO context? Are there options for IOMMU handling, DMA remapping, or other virtio-specific enhancements? * **Dependencies:** What are the prerequisites? Does virtio VFIO rely on specific kernel versions, other VFIO components, or certain hardware capabilities? Understanding the dependency tree is critical for proper configuration and troubleshooting. * **Defaults and Help Text:** What are the default settings and accompanying help text? This is often the most efficient way to understand the intended use cases and potential implications of each option. * **Conditional Logic:** Are there any *if* statements or *select* options within the Kconfig? I'll need to identify any scenarios where certain virtio features are only enabled under specific hardware or kernel configurations. * **Integration Points:** How does the virtio Kconfig link into the broader VFIO architecture? Are there any specific Kconfig options that control aspects of the VFIO core that have a direct impact on the virtio devices? * **Device Types:** I'm interested in the supported Virtio device types, from network to block to serial. * **Resource Mapping:** How is resource mapping handled for different Virtio devices within the VFIO environment? This is important for understanding how guest OSes will see and access the hardware. In short, my goal is to build a mental map of how VFIO's virtio support is structured, configured, and how the various components interact. Armed with this knowledge, I should be able to make informed decisions about how to best configure and utilize virtio devices within a VFIO environment, and quickly assess any configuration-related problems. Let's see what's in there... |
| 34/2 | 2026/11/22 09:33 | tool | read-file |
0mArgs:{
"File": "drivers/vfio/pci/virtio/Kconfig",
"FirstLine": 1,
"LineCount": 25
}Results: {
"Contents": " 1:\t# SPDX-License-Identifier: GPL-2.0-only\n 2:\tconfig VIRTIO_VFIO_PCI\n 3:\t\ttristate \"VFIO support for VIRTIO PCI VF devices\"\n 4:\t\tdepends on VIRTIO_PCI\n 5:\t\tselect VFIO_PCI_CORE\n 6:\t\thelp\n 7:\t\t This provides migration support for VIRTIO NET and BLOCK PCI VF\n 8:\t\t devices using the VFIO framework. Migration support requires the\n 9:\t\t SR-IOV PF device to support specific VIRTIO extensions,\n 10:\t\t otherwise this driver provides no additional functionality\n 11:\t\t beyond vfio-pci.\n 12:\t\n 13:\t\t Migration support in this driver relies on dirty page tracking\n 14:\t\t provided by the IOMMU hardware and exposed through IOMMUFD, any\n 15:\t\t other use cases are dis-recommended.\n 16:\t\n 17:\t\t If you don't know what to do here, say N.\n 18:\t\n 19:\tconfig VIRTIO_VFIO_PCI_ADMIN_LEGACY\n 20:\t\tbool \"Legacy I/O support for VIRTIO NET PCI VF devices\"\n 21:\t\tdepends on VIRTIO_VFIO_PCI \u0026\u0026 VIRTIO_PCI_ADMIN_LEGACY\n 22:\t\tdefault y\n 23:\t\thelp\n 24:\t\t This extends the virtio-vfio-pci driver to support legacy I/O\n 25:\t\t access, allowing use of legacy virtio drivers with VIRTIO NET\n"
} |
| 35/2 | 2026/11/22 09:33 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 59591 output: 24 thoughts: 193 Thoughts: Here's my thought process, as it stands: **Examining Virtualization Dependencies and TPH Support** Okay, so `VIRTIO_VFIO_PCI` is built on top of `VIRTIO_PCI` and selects `VFIO_PCI_CORE`. And, confirming that, `VFIO_PCI` also selects `VFIO_PCI_CORE`. Now, that all seems logical. However, I want to drill down and see if this affects something I'm interested in and I need to do a bit more digging. Hold on a second, I need to check something related to this architecture... can any real-world device that QEMU emulates even present the `PCI_EXT_CAP_ID_TPH` capability? I need to verify what QEMU can actually do. Hmm, does QEMU even support the TPH extended capability on *any* emulated device, regardless? That's the real question here. Right, time to consult the kernel. Let me check what devices within the kernel itself actually support TPH. Or, even more broadly, if *any* emulated device is exposing this capability through the kernel. This is a critical point that needs confirmation. Okay, let's step back, what is `PCI_EXT_CAP_ID_TPH` again? Let me find where it's defined... Ah, right, it's defined in `include/uapi/linux/pci_regs.h`. That makes sense. Now I need to know where it's actually *used* within the kernel codebase. I need to trace its usage. |
| 36/2 | 2026/11/22 09:33 | tool | grepper |
0mArgs:{
"Expression": "PCI_EXT_CAP_ID_TPH"
}Results: {
"Output": "drivers/infiniband/hw/hfi1/pcie.c=280=int restore_pci_variables(struct hfi1_devdata *dd)\n--\ndrivers/infiniband/hw/hfi1/pcie.c-320-\ndrivers/infiniband/hw/hfi1/pcie.c:321:\tif (pci_find_ext_capability(dd-\u003epcidev, PCI_EXT_CAP_ID_TPH)) {\ndrivers/infiniband/hw/hfi1/pcie.c-322-\t\tret = pci_write_config_dword(dd-\u003epcidev, PCIE_CFG_TPH2,\n--\ndrivers/infiniband/hw/hfi1/pcie.c=339=int save_pci_variables(struct hfi1_devdata *dd)\n--\ndrivers/infiniband/hw/hfi1/pcie.c-379-\ndrivers/infiniband/hw/hfi1/pcie.c:380:\tif (pci_find_ext_capability(dd-\u003epcidev, PCI_EXT_CAP_ID_TPH)) {\ndrivers/infiniband/hw/hfi1/pcie.c-381-\t\tret = pci_read_config_dword(dd-\u003epcidev, PCIE_CFG_TPH2,\n--\ndrivers/pci/tph.c=490=void pci_restore_tph_state(struct pci_dev *pdev)\n--\ndrivers/pci/tph.c-502-\ndrivers/pci/tph.c:503:\tsave_state = pci_find_saved_ext_cap(pdev, PCI_EXT_CAP_ID_TPH);\ndrivers/pci/tph.c-504-\tif (!save_state)\n--\ndrivers/pci/tph.c=520=void pci_save_tph_state(struct pci_dev *pdev)\n--\ndrivers/pci/tph.c-532-\ndrivers/pci/tph.c:533:\tsave_state = pci_find_saved_ext_cap(pdev, PCI_EXT_CAP_ID_TPH);\ndrivers/pci/tph.c-534-\tif (!save_state)\n--\ndrivers/pci/tph.c=559=void pci_tph_init(struct pci_dev *pdev)\n--\ndrivers/pci/tph.c-565-\ndrivers/pci/tph.c:566:\tpdev-\u003etph_cap = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_TPH);\ndrivers/pci/tph.c-567-\tif (!pdev-\u003etph_cap)\n--\ndrivers/pci/tph.c-587-\tsave_size = sizeof(u32) + num_entries * sizeof(u16);\ndrivers/pci/tph.c:588:\tpci_add_ext_cap_save_buffer(pdev, PCI_EXT_CAP_ID_TPH, save_size);\ndrivers/pci/tph.c-589-}\n--\ndrivers/vfio/pci/vfio_pci_config.c=73=static const u16 pci_ext_cap_length[PCI_EXT_CAP_ID_MAX + 1] = {\n--\ndrivers/vfio/pci/vfio_pci_config.c-95-\t[PCI_EXT_CAP_ID_DPA]\t=\t0xFF,\ndrivers/vfio/pci/vfio_pci_config.c:96:\t[PCI_EXT_CAP_ID_TPH]\t=\t0xFF,\ndrivers/vfio/pci/vfio_pci_config.c-97-\t[PCI_EXT_CAP_ID_LTR]\t=\tPCI_EXT_CAP_LTR_SIZEOF,\n--\ndrivers/vfio/pci/vfio_pci_config.c=1243=void vfio_pci_uninit_perm_bits(void)\n--\ndrivers/vfio/pci/vfio_pci_config.c-1254-\tfree_perm_bits(\u0026ecap_perms[PCI_EXT_CAP_ID_PWR]);\ndrivers/vfio/pci/vfio_pci_config.c:1255:\tfree_perm_bits(\u0026ecap_perms[PCI_EXT_CAP_ID_TPH]);\ndrivers/vfio/pci/vfio_pci_config.c-1256-}\n--\ndrivers/vfio/pci/vfio_pci_config.c=1258=int __init vfio_pci_init_perm_bits(void)\n--\ndrivers/vfio/pci/vfio_pci_config.c-1275-\tret |= init_pci_ext_cap_pwr_perm(\u0026ecap_perms[PCI_EXT_CAP_ID_PWR]);\ndrivers/vfio/pci/vfio_pci_config.c:1276:\tret |= init_pci_ext_cap_tph_perm(\u0026ecap_perms[PCI_EXT_CAP_ID_TPH]);\ndrivers/vfio/pci/vfio_pci_config.c:1277:\tecap_perms[PCI_EXT_CAP_ID_TPH].readfn = vfio_tph_config_read;\ndrivers/vfio/pci/vfio_pci_config.c:1278:\tecap_perms[PCI_EXT_CAP_ID_TPH].writefn = vfio_tph_config_write;\ndrivers/vfio/pci/vfio_pci_config.c-1279-\tecap_perms[PCI_EXT_CAP_ID_VNDR].writefn = vfio_raw_config_write;\n--\ndrivers/vfio/pci/vfio_pci_config.c=1538=static int vfio_ext_cap_len(struct vfio_pci_core_device *vdev, u16 ecap, u16 epos)\n--\ndrivers/vfio/pci/vfio_pci_config.c-1591-\t\treturn PCI_DPA_BASE_SIZEOF + byte + 1;\ndrivers/vfio/pci/vfio_pci_config.c:1592:\tcase PCI_EXT_CAP_ID_TPH:\ndrivers/vfio/pci/vfio_pci_config.c-1593-\t\tret = pci_read_config_dword(pdev, epos + PCI_TPH_CAP, \u0026dword);\n--\ndrivers/vfio/pci/vfio_pci_config.c=1769=static int vfio_ecap_init(struct vfio_pci_core_device *vdev)\n--\ndrivers/vfio/pci/vfio_pci_config.c-1843-\t\t\treturn ret;\ndrivers/vfio/pci/vfio_pci_config.c:1844:\t\tif (ecap == PCI_EXT_CAP_ID_TPH)\ndrivers/vfio/pci/vfio_pci_config.c-1845-\t\t\tvfio_tph_vcap_rewrite(vdev, epos);\n--\ninclude/uapi/linux/pci_regs.h-747-#define PCI_EXT_CAP_ID_DPA\t0x16\t/* Dynamic Power Allocation */\ninclude/uapi/linux/pci_regs.h:748:#define PCI_EXT_CAP_ID_TPH\t0x17\t/* TPH Requester */\ninclude/uapi/linux/pci_regs.h-749-#define PCI_EXT_CAP_ID_LTR\t0x18\t/* Latency Tolerance Reporting */\n"
} |
| 37/2 | 2026/11/22 09:33 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 62120 output: 46 thoughts: 107 Thoughts: Here's my analysis of the provided code snippet, summarized from my perspective as an expert in this field: **Diving into VFIO PCI Configuration** Okay, let's dissect this. My focus is immediately drawn to `drivers/vfio/pci/vfio_pci_config.c`. Specifically, I'm zeroing in on the `vfio_ext_cap_len` function. That function is crucial for determining the length of extended capability structures within the PCI configuration space, a function I have no doubt I am already quite familiar with. I see a `case` statement specifically addressing `PCI_EXT_CAP_ID_TPH`. That's Target-Based Process Handling, a key component in efficient DMA operations. My expert understanding of this already tells me that the code is likely looking to understand how the device manages its translation of physical addresses. I see a `pci_read_config_dword` call, which immediately tells me this function is reading a double word value from the PCI configuration space. It's reading from the extended capability's offset (`epos`) plus `PCI_TPH_CAP`. This is the offset to the TPH Capability register itself within the Extended Capability data structure. I'm going to jump straight to line 1592 of `vfio_ext_cap_len` right now and get a better look at what's going on! I want to understand what the code does next, based on that read value! |
| 38/2 | 2026/11/22 09:34 | tool | read-file |
0mArgs:{
"File": "drivers/vfio/pci/vfio_pci_config.c",
"FirstLine": 1590,
"LineCount": 25
}Results: {
"Contents": "1590:\t\t\tbyte \u0026= PCI_DPA_CAP_SUBSTATE_MASK;\n1591:\t\t\treturn PCI_DPA_BASE_SIZEOF + byte + 1;\n1592:\t\tcase PCI_EXT_CAP_ID_TPH:\n1593:\t\t\tret = pci_read_config_dword(pdev, epos + PCI_TPH_CAP, \u0026dword);\n1594:\t\t\tif (ret)\n1595:\t\t\t\treturn pcibios_err_to_errno(ret);\n1596:\t\n1597:\t\t\tif ((dword \u0026 PCI_TPH_CAP_LOC_MASK) == PCI_TPH_LOC_CAP) {\n1598:\t\t\t\tint sts;\n1599:\t\n1600:\t\t\t\tsts = dword \u0026 PCI_TPH_CAP_ST_MASK;\n1601:\t\t\t\tsts \u003e\u003e= PCI_TPH_CAP_ST_SHIFT;\n1602:\t\t\t\treturn PCI_TPH_BASE_SIZEOF + (sts * 2) + 2;\n1603:\t\t\t}\n1604:\t\t\treturn PCI_TPH_BASE_SIZEOF;\n1605:\t\tcase PCI_EXT_CAP_ID_DVSEC:\n1606:\t\t\tret = pci_read_config_dword(pdev, epos + PCI_DVSEC_HEADER1, \u0026dword);\n1607:\t\t\tif (ret)\n1608:\t\t\t\treturn pcibios_err_to_errno(ret);\n1609:\t\t\treturn PCI_DVSEC_HEADER1_LEN(dword);\n1610:\t\tdefault:\n1611:\t\t\tpci_warn(pdev, \"%s: unknown length for PCI ecap %#x@%#x\\n\",\n1612:\t\t\t\t __func__, ecap, epos);\n1613:\t\t}\n1614:\t\n"
} |
| 39/2 | 2026/11/22 09:34 | llm | patch-evaluator |
1mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 63061 output: 33 thoughts: 3211 Thoughts: **TPH Capability Analysis in QEMU/VFIO for Fuzzing** Okay, let's break this down. My initial question is whether or not any devices emulated in QEMU, particularly those exposed to syzkaller, have the TLP Processing Hints (TPH) capability. Specifically, does QEMU implement TPH on *any* emulated PCIe device? My mind immediately jumps to devices that might have PCIe capability: virtio, e1000e, igb, etc. But I have a nagging feeling that the default QEMU setup might *not* expose TPH on any of these. If no emulated device supports TPH, then fuzzing any TPH related code would be futile. I need to confirm that. Let's circle back to the instructions. The negative criteria for `WorthFuzzing=false` focuses on structurally unreachable hardware. But VFIO and the PCI core *aren't* vendor-specific hardware; they are *core* kernel components. They are definitely *not* structurally unreachable. So that's a positive for fuzzing. Now, does syzkaller actually *reach* VFIO functionality? Can a syzkaller VM even create `/dev/vfio/*`? The key is the ability to bind devices to `vfio-pci`. Does syzkaller generate the necessary sysfs writes to bind a device? I need to verify syzkaller's behavior here. Since syzkaller runs with root permissions, sysfs writes are possible. I need to dig into the kernel code to understand what happens. `vfio_pci_core_init` is called on module load/boot. Crucially, I see `vfio_pci_tph_cpuhp_init()`, which sets up CPU hotplug callbacks for TPH. Debugfs is also initialized. I also see that `vfio_pci_init_perm_bits()` calls `init_pci_ext_cap_tph_perm`, which initializes the read/write functions for TPH config space. And from `drivers/pci/probe.c`: `pci_tph_init` is called at boot for *every* PCI device. This implies TPH handling is *always* potentially active. Now, let's examine the new ioctls: `VFIO_DEVICE_FEATURE_TPH`, `VFIO_DEVICE_FEATURE_TPH_PROGRAM`, and `VFIO_DEVICE_FEATURE_TPH_RESOLVE`. These are triggered when a VFIO device is opened. `vfio_pci_open_device` calls `vfio_pci_tph_dev_init`. I see it checks for `has_arch_st` and if present, sets up CPU hotplug callbacks (again!) and allocates a state table. `vfio_pci_core_disable` disables TPH on device close. I also see ioctl handlers: `vfio_pci_core_feature_tph`, `vfio_pci_core_feature_tph_program`, and `vfio_pci_core_feature_tph_resolve`. Crucially, the code checks `pcie_std_tph_supported(vdev->pdev)`. If `PCI_EXT_CAP_ID_TPH` isn't present, the ioctls return `-EOPNOTSUPP`. This is the crucial point! The device *must* have the TPH capability for any of the TPH-related ioctls to do anything. So, the biggest question now is: **can ANY emulated device in QEMU *actually* have the `PCI_EXT_CAP_ID_TPH` capability?** I need to definitively determine if it's possible for syzkaller to create a VFIO device with TPH support. Let's examine the devices QEMU provides: e1000e, igb, and virtio. E1000e and igb predated TPH. Virtio doesn't have TPH. NVME doesn't have TPH. A QEMU pcie-root-port does not provide TPH. Is there *any* way to get a virtual device, or QEMU itself to *declare* TPH? Is there a command line flag to emulate TPH? Or are we stuck looking at VFIO on real hardware? I must investigate `samples/vfio-mdev` to check if there are any mdev or virtual devices in Linux that use vfio-pci and might have TPH support. The answer to this determines the next path forward. |
| 40/2 | 2026/11/22 09:35 | tool | grepper |
0mArgs:{
"Expression": "PCI_EXT_CAP_ID_TPH",
"PathPrefixes": [
"drivers/"
]
}Results: {
"Output": "drivers/infiniband/hw/hfi1/pcie.c=280=int restore_pci_variables(struct hfi1_devdata *dd)\n--\ndrivers/infiniband/hw/hfi1/pcie.c-320-\ndrivers/infiniband/hw/hfi1/pcie.c:321:\tif (pci_find_ext_capability(dd-\u003epcidev, PCI_EXT_CAP_ID_TPH)) {\ndrivers/infiniband/hw/hfi1/pcie.c-322-\t\tret = pci_write_config_dword(dd-\u003epcidev, PCIE_CFG_TPH2,\n--\ndrivers/infiniband/hw/hfi1/pcie.c=339=int save_pci_variables(struct hfi1_devdata *dd)\n--\ndrivers/infiniband/hw/hfi1/pcie.c-379-\ndrivers/infiniband/hw/hfi1/pcie.c:380:\tif (pci_find_ext_capability(dd-\u003epcidev, PCI_EXT_CAP_ID_TPH)) {\ndrivers/infiniband/hw/hfi1/pcie.c-381-\t\tret = pci_read_config_dword(dd-\u003epcidev, PCIE_CFG_TPH2,\n--\ndrivers/pci/tph.c=490=void pci_restore_tph_state(struct pci_dev *pdev)\n--\ndrivers/pci/tph.c-502-\ndrivers/pci/tph.c:503:\tsave_state = pci_find_saved_ext_cap(pdev, PCI_EXT_CAP_ID_TPH);\ndrivers/pci/tph.c-504-\tif (!save_state)\n--\ndrivers/pci/tph.c=520=void pci_save_tph_state(struct pci_dev *pdev)\n--\ndrivers/pci/tph.c-532-\ndrivers/pci/tph.c:533:\tsave_state = pci_find_saved_ext_cap(pdev, PCI_EXT_CAP_ID_TPH);\ndrivers/pci/tph.c-534-\tif (!save_state)\n--\ndrivers/pci/tph.c=559=void pci_tph_init(struct pci_dev *pdev)\n--\ndrivers/pci/tph.c-565-\ndrivers/pci/tph.c:566:\tpdev-\u003etph_cap = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_TPH);\ndrivers/pci/tph.c-567-\tif (!pdev-\u003etph_cap)\n--\ndrivers/pci/tph.c-587-\tsave_size = sizeof(u32) + num_entries * sizeof(u16);\ndrivers/pci/tph.c:588:\tpci_add_ext_cap_save_buffer(pdev, PCI_EXT_CAP_ID_TPH, save_size);\ndrivers/pci/tph.c-589-}\n--\ndrivers/vfio/pci/vfio_pci_config.c=73=static const u16 pci_ext_cap_length[PCI_EXT_CAP_ID_MAX + 1] = {\n--\ndrivers/vfio/pci/vfio_pci_config.c-95-\t[PCI_EXT_CAP_ID_DPA]\t=\t0xFF,\ndrivers/vfio/pci/vfio_pci_config.c:96:\t[PCI_EXT_CAP_ID_TPH]\t=\t0xFF,\ndrivers/vfio/pci/vfio_pci_config.c-97-\t[PCI_EXT_CAP_ID_LTR]\t=\tPCI_EXT_CAP_LTR_SIZEOF,\n--\ndrivers/vfio/pci/vfio_pci_config.c=1243=void vfio_pci_uninit_perm_bits(void)\n--\ndrivers/vfio/pci/vfio_pci_config.c-1254-\tfree_perm_bits(\u0026ecap_perms[PCI_EXT_CAP_ID_PWR]);\ndrivers/vfio/pci/vfio_pci_config.c:1255:\tfree_perm_bits(\u0026ecap_perms[PCI_EXT_CAP_ID_TPH]);\ndrivers/vfio/pci/vfio_pci_config.c-1256-}\n--\ndrivers/vfio/pci/vfio_pci_config.c=1258=int __init vfio_pci_init_perm_bits(void)\n--\ndrivers/vfio/pci/vfio_pci_config.c-1275-\tret |= init_pci_ext_cap_pwr_perm(\u0026ecap_perms[PCI_EXT_CAP_ID_PWR]);\ndrivers/vfio/pci/vfio_pci_config.c:1276:\tret |= init_pci_ext_cap_tph_perm(\u0026ecap_perms[PCI_EXT_CAP_ID_TPH]);\ndrivers/vfio/pci/vfio_pci_config.c:1277:\tecap_perms[PCI_EXT_CAP_ID_TPH].readfn = vfio_tph_config_read;\ndrivers/vfio/pci/vfio_pci_config.c:1278:\tecap_perms[PCI_EXT_CAP_ID_TPH].writefn = vfio_tph_config_write;\ndrivers/vfio/pci/vfio_pci_config.c-1279-\tecap_perms[PCI_EXT_CAP_ID_VNDR].writefn = vfio_raw_config_write;\n--\ndrivers/vfio/pci/vfio_pci_config.c=1538=static int vfio_ext_cap_len(struct vfio_pci_core_device *vdev, u16 ecap, u16 epos)\n--\ndrivers/vfio/pci/vfio_pci_config.c-1591-\t\treturn PCI_DPA_BASE_SIZEOF + byte + 1;\ndrivers/vfio/pci/vfio_pci_config.c:1592:\tcase PCI_EXT_CAP_ID_TPH:\ndrivers/vfio/pci/vfio_pci_config.c-1593-\t\tret = pci_read_config_dword(pdev, epos + PCI_TPH_CAP, \u0026dword);\n--\ndrivers/vfio/pci/vfio_pci_config.c=1769=static int vfio_ecap_init(struct vfio_pci_core_device *vdev)\n--\ndrivers/vfio/pci/vfio_pci_config.c-1843-\t\t\treturn ret;\ndrivers/vfio/pci/vfio_pci_config.c:1844:\t\tif (ecap == PCI_EXT_CAP_ID_TPH)\ndrivers/vfio/pci/vfio_pci_config.c-1845-\t\t\tvfio_tph_vcap_rewrite(vdev, epos);\n"
} |
| 41/2 | 2026/11/22 09:35 | llm | patch-evaluator |
1mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 69164 output: 23 thoughts: 2865 Thoughts: **TPH in VFIO and Syzkaller Reachability Analysis** Okay, let's break this down. My initial thought process is centered around understanding the execution path and reachability of TPH (TLP Processing Hints) functionality within the context of VFIO (Virtual Function I/O) and syzkaller, specifically for fuzzing purposes. First, I looked at specific functions like `pcie_tph_get_st_table_loc`, `pcie_enable_tph`, `pcie_tph_set_st_entries`, etc. The immediate question is, where are these functions called, and what hardware is needed to execute them? I quickly recognized that drivers like `bnxt` (Broadcom) and `mlx5` (Mellanox) – these are SmartNIC drivers – are involved in enabling TPH, and are typically present in hardware. Also `vfio_tph_config_write` in `vfio_pci_config.c`, `vfio_pci_core_feature_tph_program`, etc. are called. The key realization here is that TPH is a PCIe 3.0+ feature, typically associated with high-speed PCIe devices like those SmartNICs or CXL devices, and these devices need to have the TPH capability defined in their PCI config space. QEMU, the virtual machine I'm interested in for syzkaller, *does not* emulate this. Devices like e1000, rtl8139, virtio – none of them support `PCI_EXT_CAP_ID_TPH`. So, the next question is, can syzkaller somehow *create* a virtual device with TPH capability? The answer is no; syzkaller relies on what QEMU *emulates*. QEMU doesn't emulate the feature, so syzkaller can't create it. Next, I looked at how TPH might be initialized, specifically, the execution of `pci_tph_init`. Here's what I found. When the kernel is booting in QEMU, `pci_tph_init` is called, but `pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_TPH)` *always* returns 0 because standard QEMU devices don't have it. `pci_tph_init` returns immediately. No TPH initialization code in the patch executes. Similarly, the setup in `vfio_pci_core_init` doesn't execute anything with the same reason. Now, during fuzzing, the question became: Can syzkaller call `VFIO_DEVICE_FEATURE_TPH`? If I had a vfio-pci device, `pcie_std_tph_supported(vdev->pdev)` is `FALSE` and `-EOPNOTSUPP` is returned. Similarly, `vfio_pci_core_feature_tph_program` and `vfio_pci_core_feature_tph_resolve` both immediately return `-EOPNOTSUPP`. The TPH configuration read/write via extended capabilities is also never hit because no extended capability with ID `PCI_EXT_CAP_ID_TPH` is defined! The CPU hotplug functionality via `vfio_pci_tph_cpuhp_offline` also does not execute, since `vfio_pci_tph_has_architected_st(vdev)` is always false. Given all of this, the key question becomes, is this code reachable during fuzzing? The guidelines specifically state that "Structurally unreachable hardware" is a reason to return `WorthFuzzing=false`. The code requires physical PCIe cards or SmartNICs (which are *not* emulated). So, the question is, *why* was this code added? What patch is this? I need to review the commit log or description of the patch to fully understand its intention and whether it could have intended consequences if it *were* reachable. However, given that it's *not* reachable, it should be marked as "Not Worth Fuzzing" because it falls under the negative criteria of "structurally unreachable hardware". |
| 42/2 | 2026/11/22 09:36 | tool | grepper |
0mArgs:{
"Expression": "VFIO_DEVICE_FEATURE_TPH"
}Results: {
"Output": "drivers/vfio/pci/vfio_pci_core.c=1970=int vfio_pci_core_ioctl_feature(struct vfio_device *device, u32 flags,\n--\ndrivers/vfio/pci/vfio_pci_core.c-1989-\t\treturn vfio_pci_zdev_feature_err(device, flags, arg, argsz);\ndrivers/vfio/pci/vfio_pci_core.c:1990:\tcase VFIO_DEVICE_FEATURE_TPH:\ndrivers/vfio/pci/vfio_pci_core.c-1991-\t\treturn vfio_pci_core_feature_tph(vdev, flags, arg, argsz);\ndrivers/vfio/pci/vfio_pci_core.c:1992:\tcase VFIO_DEVICE_FEATURE_TPH_PROGRAM:\ndrivers/vfio/pci/vfio_pci_core.c-1993-\t\treturn vfio_pci_core_feature_tph_program(vdev, flags,\ndrivers/vfio/pci/vfio_pci_core.c-1994-\t\t\t\t\t\t\t arg, argsz);\ndrivers/vfio/pci/vfio_pci_core.c:1995:\tcase VFIO_DEVICE_FEATURE_TPH_RESOLVE:\ndrivers/vfio/pci/vfio_pci_core.c-1996-\t\treturn vfio_pci_core_feature_tph_resolve(vdev, flags,\n--\ninclude/uapi/linux/vfio.h=1552=struct vfio_device_feature_zpci_err {\n--\ninclude/uapi/linux/vfio.h-1558-/*\ninclude/uapi/linux/vfio.h:1559: * VFIO_DEVICE_FEATURE_TPH - Control and query VFIO TPH feature capabilities\ninclude/uapi/linux/vfio.h-1560- *\n--\ninclude/uapi/linux/vfio.h-1573- * device TPH hardware.\ninclude/uapi/linux/vfio.h:1574: * 5. Program steering tag (ST) table entries by VFIO_DEVICE_FEATURE_TPH_PROGRAM\ninclude/uapi/linux/vfio.h-1575- * if the device has an architected ST table.\ninclude/uapi/linux/vfio.h:1576: * 6. Query the ST value for a given CPU ID via VFIO_DEVICE_FEATURE_TPH_RESOLVE\ninclude/uapi/linux/vfio.h-1577- * for DS-ST capable devices, userspace may then configure the ST through\n--\ninclude/uapi/linux/vfio.h-1579- */\ninclude/uapi/linux/vfio.h:1580:#define VFIO_DEVICE_FEATURE_TPH\t\t\t14\ninclude/uapi/linux/vfio.h-1581-\ninclude/uapi/linux/vfio.h=1582=struct vfio_device_feature_tph {\n--\ninclude/uapi/linux/vfio.h-1586-/*\ninclude/uapi/linux/vfio.h:1587: * Capability bits returned by VFIO_DEVICE_FEATURE_TPH GET\ninclude/uapi/linux/vfio.h-1588- */\n--\ninclude/uapi/linux/vfio.h-1605-/*\ninclude/uapi/linux/vfio.h:1606: * VFIO_DEVICE_FEATURE_TPH_PROGRAM - Batch program architected steering tag\ninclude/uapi/linux/vfio.h-1607- * (ST) table entries. This interface only operates on the architected ST\n--\ninclude/uapi/linux/vfio.h-1613- * Prerequisites before invoking this feature:\ninclude/uapi/linux/vfio.h:1614: * 1. Call VFIO_DEVICE_FEATURE_TPH with SET to enable vfio TPH permission;\ninclude/uapi/linux/vfio.h-1615- * 2. Write the TPH control register to activate device hardware TPH logic.\n--\ninclude/uapi/linux/vfio.h-1632- */\ninclude/uapi/linux/vfio.h:1633:#define VFIO_DEVICE_FEATURE_TPH_PROGRAM\t\t15\ninclude/uapi/linux/vfio.h-1634-\ninclude/uapi/linux/vfio.h=1635=struct vfio_device_feature_tph_program {\n--\ninclude/uapi/linux/vfio.h-1657-/*\ninclude/uapi/linux/vfio.h:1658: * VFIO_DEVICE_FEATURE_TPH_RESOLVE - Resolve TPH attributes from given source\ninclude/uapi/linux/vfio.h-1659- *\n--\ninclude/uapi/linux/vfio.h-1661- *\ninclude/uapi/linux/vfio.h:1662: * Requires prior successful SET on VFIO_DEVICE_FEATURE_TPH, otherwise\ninclude/uapi/linux/vfio.h-1663- * this feature will return error.\n--\ninclude/uapi/linux/vfio.h-1675- */\ninclude/uapi/linux/vfio.h:1676:#define VFIO_DEVICE_FEATURE_TPH_RESOLVE\t\t16\ninclude/uapi/linux/vfio.h-1677-\n"
} |
| 43/2 | 2026/11/22 09:36 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 74348 output: 30 thoughts: 89 Thoughts: Here's my thought process, as it stands: **Exploring Virtual PCIe Device Support for TPH** Okay, hold on a second... Could *any* of the virtual devices or PCI test devices out there actually support TPH? That's the key question. I need to figure out if there's an existing virtual PCIe test device in the Linux kernel that could potentially handle this. Let's see... Maybe something like `pci-pf-stub`, or perhaps `pci-endpoint`, or even `ivshmem`? Worth exploring those possibilities. Alright, time to dive into the kernel source code. I'll start by checking the usual suspects – specifically, the `drivers/pci/endpoint/` directory. That seems like the most logical place to begin, focusing on anything related to endpoints and test setups. Then, just in case something's tucked away elsewhere, I'll broaden the search to `drivers/misc/` and `drivers/vfio/`. Hopefully, there's a good starting point in one of those areas. |
| 44/2 | 2026/11/22 09:37 | tool | grepper |
0mArgs:{
"Expression": "tph",
"PathPrefixes": [
"drivers/pci/endpoint/"
]
}Results: {
"Output": "no matches"
} |
| 45/2 | 2026/11/22 09:37 | llm | patch-evaluator |
1mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 74704 output: 24 thoughts: 17 Thoughts: Here's my thought process, as requested: **Checking for TPH Interactions in Drivers/** Okay, so I need to figure out if there's any code within the `drivers/` directory that's either generating or actively consuming "TPH." This sounds like a specific concept within this codebase, and understanding its usage is critical. My initial step will be to leverage the tools and techniques I'm used to. I’ll start with a straightforward search, probably using `grep` or whatever search utility is most appropriate for this environment, looking for instances where "TPH" is explicitly mentioned. That's the baseline, the obvious stuff. But I can't just rely on literal string matches. I need to think about variations, potential naming conventions the original developers might have used. I'll need to consider how TPH might be represented indirectly. Are there any functions related to TPH, or perhaps variables named in a way that implies TPH usage but don't explicitly say it? I need to think like the code's original author might have, to anticipate their choices. Beyond the text, I need to look for patterns. If TPH is a type of data structure, I should see that it's constructed, passed, or manipulated. I'll also be mindful of potential dependencies. Are there any other modules that seem to be involved with TPH? Are there any data structures or functions within `drivers/` which are likely to *interact* with TPH, even if they don't explicitly mention it? This means diving a bit deeper, starting to understand data flows and dependencies within the `drivers/` directory. I will also need to review the build configuration if possible. The `Makefile` and other build configuration files could contain clues about TPH, and how it is compiled, used, or linked. I'll search for any references in the build system. It looks like the goal is to determine if `drivers/` depends on or provides functionality related to TPH. Once I've found a good starting set of results, I'll need to examine the relevant code more closely to gain a deeper understanding of the relationships. I'll be looking for both direct uses of TPH, and indirect implications that modules within `drivers/` support or consume TPH. This will require some code reading. |
| 46/2 | 2026/11/22 09:38 | tool | grepper |
0mArgs:{
"Expression": "PCI_EXT_CAP_ID_TPH"
}Results: {
"Output": "drivers/infiniband/hw/hfi1/pcie.c=280=int restore_pci_variables(struct hfi1_devdata *dd)\n--\ndrivers/infiniband/hw/hfi1/pcie.c-320-\ndrivers/infiniband/hw/hfi1/pcie.c:321:\tif (pci_find_ext_capability(dd-\u003epcidev, PCI_EXT_CAP_ID_TPH)) {\ndrivers/infiniband/hw/hfi1/pcie.c-322-\t\tret = pci_write_config_dword(dd-\u003epcidev, PCIE_CFG_TPH2,\n--\ndrivers/infiniband/hw/hfi1/pcie.c=339=int save_pci_variables(struct hfi1_devdata *dd)\n--\ndrivers/infiniband/hw/hfi1/pcie.c-379-\ndrivers/infiniband/hw/hfi1/pcie.c:380:\tif (pci_find_ext_capability(dd-\u003epcidev, PCI_EXT_CAP_ID_TPH)) {\ndrivers/infiniband/hw/hfi1/pcie.c-381-\t\tret = pci_read_config_dword(dd-\u003epcidev, PCIE_CFG_TPH2,\n--\ndrivers/pci/tph.c=490=void pci_restore_tph_state(struct pci_dev *pdev)\n--\ndrivers/pci/tph.c-502-\ndrivers/pci/tph.c:503:\tsave_state = pci_find_saved_ext_cap(pdev, PCI_EXT_CAP_ID_TPH);\ndrivers/pci/tph.c-504-\tif (!save_state)\n--\ndrivers/pci/tph.c=520=void pci_save_tph_state(struct pci_dev *pdev)\n--\ndrivers/pci/tph.c-532-\ndrivers/pci/tph.c:533:\tsave_state = pci_find_saved_ext_cap(pdev, PCI_EXT_CAP_ID_TPH);\ndrivers/pci/tph.c-534-\tif (!save_state)\n--\ndrivers/pci/tph.c=559=void pci_tph_init(struct pci_dev *pdev)\n--\ndrivers/pci/tph.c-565-\ndrivers/pci/tph.c:566:\tpdev-\u003etph_cap = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_TPH);\ndrivers/pci/tph.c-567-\tif (!pdev-\u003etph_cap)\n--\ndrivers/pci/tph.c-587-\tsave_size = sizeof(u32) + num_entries * sizeof(u16);\ndrivers/pci/tph.c:588:\tpci_add_ext_cap_save_buffer(pdev, PCI_EXT_CAP_ID_TPH, save_size);\ndrivers/pci/tph.c-589-}\n--\ndrivers/vfio/pci/vfio_pci_config.c=73=static const u16 pci_ext_cap_length[PCI_EXT_CAP_ID_MAX + 1] = {\n--\ndrivers/vfio/pci/vfio_pci_config.c-95-\t[PCI_EXT_CAP_ID_DPA]\t=\t0xFF,\ndrivers/vfio/pci/vfio_pci_config.c:96:\t[PCI_EXT_CAP_ID_TPH]\t=\t0xFF,\ndrivers/vfio/pci/vfio_pci_config.c-97-\t[PCI_EXT_CAP_ID_LTR]\t=\tPCI_EXT_CAP_LTR_SIZEOF,\n--\ndrivers/vfio/pci/vfio_pci_config.c=1243=void vfio_pci_uninit_perm_bits(void)\n--\ndrivers/vfio/pci/vfio_pci_config.c-1254-\tfree_perm_bits(\u0026ecap_perms[PCI_EXT_CAP_ID_PWR]);\ndrivers/vfio/pci/vfio_pci_config.c:1255:\tfree_perm_bits(\u0026ecap_perms[PCI_EXT_CAP_ID_TPH]);\ndrivers/vfio/pci/vfio_pci_config.c-1256-}\n--\ndrivers/vfio/pci/vfio_pci_config.c=1258=int __init vfio_pci_init_perm_bits(void)\n--\ndrivers/vfio/pci/vfio_pci_config.c-1275-\tret |= init_pci_ext_cap_pwr_perm(\u0026ecap_perms[PCI_EXT_CAP_ID_PWR]);\ndrivers/vfio/pci/vfio_pci_config.c:1276:\tret |= init_pci_ext_cap_tph_perm(\u0026ecap_perms[PCI_EXT_CAP_ID_TPH]);\ndrivers/vfio/pci/vfio_pci_config.c:1277:\tecap_perms[PCI_EXT_CAP_ID_TPH].readfn = vfio_tph_config_read;\ndrivers/vfio/pci/vfio_pci_config.c:1278:\tecap_perms[PCI_EXT_CAP_ID_TPH].writefn = vfio_tph_config_write;\ndrivers/vfio/pci/vfio_pci_config.c-1279-\tecap_perms[PCI_EXT_CAP_ID_VNDR].writefn = vfio_raw_config_write;\n--\ndrivers/vfio/pci/vfio_pci_config.c=1538=static int vfio_ext_cap_len(struct vfio_pci_core_device *vdev, u16 ecap, u16 epos)\n--\ndrivers/vfio/pci/vfio_pci_config.c-1591-\t\treturn PCI_DPA_BASE_SIZEOF + byte + 1;\ndrivers/vfio/pci/vfio_pci_config.c:1592:\tcase PCI_EXT_CAP_ID_TPH:\ndrivers/vfio/pci/vfio_pci_config.c-1593-\t\tret = pci_read_config_dword(pdev, epos + PCI_TPH_CAP, \u0026dword);\n--\ndrivers/vfio/pci/vfio_pci_config.c=1769=static int vfio_ecap_init(struct vfio_pci_core_device *vdev)\n--\ndrivers/vfio/pci/vfio_pci_config.c-1843-\t\t\treturn ret;\ndrivers/vfio/pci/vfio_pci_config.c:1844:\t\tif (ecap == PCI_EXT_CAP_ID_TPH)\ndrivers/vfio/pci/vfio_pci_config.c-1845-\t\t\tvfio_tph_vcap_rewrite(vdev, epos);\n--\ninclude/uapi/linux/pci_regs.h-747-#define PCI_EXT_CAP_ID_DPA\t0x16\t/* Dynamic Power Allocation */\ninclude/uapi/linux/pci_regs.h:748:#define PCI_EXT_CAP_ID_TPH\t0x17\t/* TPH Requester */\ninclude/uapi/linux/pci_regs.h-749-#define PCI_EXT_CAP_ID_LTR\t0x18\t/* Latency Tolerance Reporting */\n"
} |
| 47/2 | 2026/11/22 09:38 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 77201 output: 20 thoughts: 1254 Thoughts: **Analyzing the Fuzzing Suitability of a PCIe TPH Patch** Okay, let's break this down. First, I noticed that the PCIe Transaction Processing Hints (TPH) feature is only used by a couple of very specific and expensive hardware drivers: Omni-Path and ConnectX. Crucially, I see that QEMU, the standard emulator, *doesn't* support TPH at all, and neither do typical virtualized environments like GCE, which use virtio or gVNIC. That's the initial red flag. My immediate thought is: is this "structurally unreachable hardware"? Is the code *actually* going to be executed in a standard fuzzing environment? Section 1 stresses that fuzzing needs executable code in QEMU or similar environments. If it's unreachable, we shouldn't fuzz it, even if it has assertions or complex logic. Now, let's dig into Section 2, the "NEGATIVE CRITERIA." We're looking for reasons to *not* fuzz. The section says to return `WorthFuzzing=false` if *all* modified code falls into certain categories: non-executable changes, structurally unreachable hardware, or unreachable execution paths. Looking at the patch, we're modifying `drivers/pci/tph.c`, `drivers/vfio/pci/vfio_pci.c`, `vfio_pci_config.c`, `vfio_pci_core.c`, and relevant headers. I'm wondering if this counts as "Vendor-specific PCIe switches, SmartNICs, or GPU drivers... requiring physical ASIC/PCIe cards not emulated in standard QEMU". No, it doesn't appear to be vendor-specific; it's in core PCI and VFIO, so that's a point in favor of fuzzing. I'm thinking, does it fall under: "Drivers accessible via virtual buses (virtio, USB gadget, loopback, netlink, binder, sockets, etc.)"? Or maybe: "Core Subsystems"? No to both. But the crux is: what syscalls are we touching? This patch adds new IOCTLs to `VFIO_DEVICE_FEATURE`: `VFIO_DEVICE_FEATURE_TPH`, `VFIO_DEVICE_FEATURE_TPH_PROGRAM`, and `VFIO_DEVICE_FEATURE_TPH_RESOLVE`. My key question now is, can syzkaller *actually* execute `vfio_pci_core_ioctl_feature`? Can syzkaller even have a VFIO device opened? That's the critical question! If syzkaller can have an open VFIO PCI device, this opens the door to fuzzing, but if not, this code is structurally unreachable, and not worth fuzzing. I need to investigate whether syzkaller supports VFIO. I need to see if syzkaller is running in environments with VFIO devices, and how syzkaller *gets* a VFIO device. Is there a `/dev/vfio/*` device available in syzkaller? I need to check the kernel sources too, to see if there are any emulated or virtual VFIO devices. |
| 48/2 | 2026/11/22 09:39 | tool | grepper |
0mArgs:{
"Expression": "vfio_alloc_device"
}Results: {
"Output": "Documentation/driver-api/vfio.rst=475=The driver should embed the vfio_device in its own structure and use\nDocumentation/driver-api/vfio.rst:476:vfio_alloc_device() to allocate the structure, and can register\nDocumentation/driver-api/vfio.rst-477-@init/@release callbacks to manage any private state wrapping the\nDocumentation/driver-api/vfio.rst=478=vfio_device::\nDocumentation/driver-api/vfio.rst-479-\nDocumentation/driver-api/vfio.rst:480:\tvfio_alloc_device(dev_struct, member, dev, ops);\nDocumentation/driver-api/vfio.rst-481-\tvoid vfio_put_device(struct vfio_device *device);\n--\ndrivers/gpu/drm/i915/gvt/kvmgt.c=1457=static int intel_vgpu_probe(struct mdev_device *mdev)\n--\ndrivers/gpu/drm/i915/gvt/kvmgt.c-1461-\ndrivers/gpu/drm/i915/gvt/kvmgt.c:1462:\tvgpu = vfio_alloc_device(intel_vgpu, vfio_device, \u0026mdev-\u003edev,\ndrivers/gpu/drm/i915/gvt/kvmgt.c-1463-\t\t\t\t \u0026intel_vgpu_dev_ops);\n--\ndrivers/s390/cio/vfio_ccw_ops.c=99=static int vfio_ccw_mdev_probe(struct mdev_device *mdev)\n--\ndrivers/s390/cio/vfio_ccw_ops.c-105-\ndrivers/s390/cio/vfio_ccw_ops.c:106:\tprivate = vfio_alloc_device(vfio_ccw_private, vdev, \u0026mdev-\u003edev,\ndrivers/s390/cio/vfio_ccw_ops.c-107-\t\t\t\t \u0026vfio_ccw_dev_ops);\n--\ndrivers/s390/crypto/vfio_ap_ops.c=797=static int vfio_ap_mdev_probe(struct mdev_device *mdev)\n--\ndrivers/s390/crypto/vfio_ap_ops.c-801-\ndrivers/s390/crypto/vfio_ap_ops.c:802:\tmatrix_mdev = vfio_alloc_device(ap_matrix_mdev, vdev, \u0026mdev-\u003edev,\ndrivers/s390/crypto/vfio_ap_ops.c-803-\t\t\t\t\t\u0026vfio_ap_matrix_dev_ops);\n--\ndrivers/vfio/cdx/main.c=313=static int vfio_cdx_probe(struct cdx_device *cdx_dev)\n--\ndrivers/vfio/cdx/main.c-318-\ndrivers/vfio/cdx/main.c:319:\tvdev = vfio_alloc_device(vfio_cdx_device, vdev, dev,\ndrivers/vfio/cdx/main.c-320-\t\t\t\t \u0026vfio_cdx_ops);\n--\ndrivers/vfio/fsl-mc/vfio_fsl_mc.c=529=static int vfio_fsl_mc_probe(struct fsl_mc_device *mc_dev)\n--\ndrivers/vfio/fsl-mc/vfio_fsl_mc.c-534-\ndrivers/vfio/fsl-mc/vfio_fsl_mc.c:535:\tvdev = vfio_alloc_device(vfio_fsl_mc_device, vdev, dev,\ndrivers/vfio/fsl-mc/vfio_fsl_mc.c-536-\t\t\t\t \u0026vfio_fsl_mc_ops);\n--\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c=1672=static int hisi_acc_vfio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)\n--\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c-1690-\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c:1691:\thisi_acc_vdev = vfio_alloc_device(hisi_acc_vf_core_device,\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c-1692-\t\t\t\t\t core_device.vdev, \u0026pdev-\u003edev, ops);\n--\ndrivers/vfio/pci/ism/main.c=358=static int ism_vfio_pci_probe(struct pci_dev *pdev,\n--\ndrivers/vfio/pci/ism/main.c-363-\ndrivers/vfio/pci/ism/main.c:364:\tivpcd = vfio_alloc_device(ism_vfio_pci_core_device, core_device.vdev,\ndrivers/vfio/pci/ism/main.c-365-\t\t\t\t \u0026pdev-\u003edev, \u0026ism_pci_ops);\n--\ndrivers/vfio/pci/mlx5/main.c=1407=static int mlx5vf_pci_probe(struct pci_dev *pdev,\n--\ndrivers/vfio/pci/mlx5/main.c-1412-\ndrivers/vfio/pci/mlx5/main.c:1413:\tmvdev = vfio_alloc_device(mlx5vf_pci_core_device, core_device.vdev,\ndrivers/vfio/pci/mlx5/main.c-1414-\t\t\t\t \u0026pdev-\u003edev, \u0026mlx5vf_pci_ops);\n--\ndrivers/vfio/pci/nvgrace-gpu/main.c=1336=static int nvgrace_gpu_probe(struct pci_dev *pdev,\n--\ndrivers/vfio/pci/nvgrace-gpu/main.c-1347-\ndrivers/vfio/pci/nvgrace-gpu/main.c:1348:\tnvdev = vfio_alloc_device(nvgrace_gpu_pci_core_device, core_device.vdev,\ndrivers/vfio/pci/nvgrace-gpu/main.c-1349-\t\t\t\t \u0026pdev-\u003edev, ops);\n--\ndrivers/vfio/pci/pds/pci_drv.c=113=static int pds_vfio_pci_probe(struct pci_dev *pdev,\n--\ndrivers/vfio/pci/pds/pci_drv.c-118-\ndrivers/vfio/pci/pds/pci_drv.c:119:\tpds_vfio = vfio_alloc_device(pds_vfio_pci_device, vfio_coredev.vdev,\ndrivers/vfio/pci/pds/pci_drv.c-120-\t\t\t\t \u0026pdev-\u003edev, pds_vfio_ops_info());\n--\ndrivers/vfio/pci/qat/main.c=645=qat_vf_vfio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)\n--\ndrivers/vfio/pci/qat/main.c-650-\ndrivers/vfio/pci/qat/main.c:651:\tqat_vdev = vfio_alloc_device(qat_vf_core_device, core_device.vdev, dev, \u0026qat_vf_pci_ops);\ndrivers/vfio/pci/qat/main.c-652-\tif (IS_ERR(qat_vdev))\n--\ndrivers/vfio/pci/vfio_pci.c=200=static int vfio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)\n--\ndrivers/vfio/pci/vfio_pci.c-207-\ndrivers/vfio/pci/vfio_pci.c:208:\tvdev = vfio_alloc_device(vfio_pci_core_device, vdev, \u0026pdev-\u003edev,\ndrivers/vfio/pci/vfio_pci.c-209-\t\t\t\t \u0026vfio_pci_ops);\n--\ndrivers/vfio/pci/virtio/main.c=152=static int virtiovf_pci_probe(struct pci_dev *pdev,\n--\ndrivers/vfio/pci/virtio/main.c-171-\ndrivers/vfio/pci/virtio/main.c:172:\tvirtvdev = vfio_alloc_device(virtiovf_pci_core_device, core_device.vdev,\ndrivers/vfio/pci/virtio/main.c-173-\t\t\t\t \u0026pdev-\u003edev, ops);\n--\ndrivers/vfio/pci/xe/main.c=546=static int xe_vfio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)\n--\ndrivers/vfio/pci/xe/main.c-550-\ndrivers/vfio/pci/xe/main.c:551:\txe_vdev = vfio_alloc_device(xe_vfio_pci_core_device, core_device.vdev, \u0026pdev-\u003edev,\ndrivers/vfio/pci/xe/main.c-552-\t\t\t\t \u0026xe_vfio_pci_ops);\n--\ndrivers/vfio/platform/vfio_amba.c=68=static int vfio_amba_probe(struct amba_device *adev, const struct amba_id *id)\n--\ndrivers/vfio/platform/vfio_amba.c-74-\ndrivers/vfio/platform/vfio_amba.c:75:\tvdev = vfio_alloc_device(vfio_platform_device, vdev, \u0026adev-\u003edev,\ndrivers/vfio/platform/vfio_amba.c-76-\t\t\t\t \u0026vfio_amba_ops);\n--\ndrivers/vfio/platform/vfio_platform.c=57=static int vfio_platform_probe(struct platform_device *pdev)\n--\ndrivers/vfio/platform/vfio_platform.c-61-\ndrivers/vfio/platform/vfio_platform.c:62:\tvdev = vfio_alloc_device(vfio_platform_device, vdev, \u0026pdev-\u003edev,\ndrivers/vfio/platform/vfio_platform.c-63-\t\t\t\t \u0026vfio_platform_ops);\n--\ndrivers/vfio/vfio_main.c=212=static int vfio_init_device(struct vfio_device *device, struct device *dev,\n--\ndrivers/vfio/vfio_main.c-218- *\ndrivers/vfio/vfio_main.c:219: * Drivers should use the wrapper vfio_alloc_device() for allocation.\ndrivers/vfio/vfio_main.c-220- * @size is the size of the structure to be allocated, including any\n--\ndrivers/vfio/vfio_main.c-226- */\ndrivers/vfio/vfio_main.c:227:struct vfio_device *_vfio_alloc_device(size_t size, struct device *dev,\ndrivers/vfio/vfio_main.c-228-\t\t\t\t const struct vfio_device_ops *ops)\n--\ndrivers/vfio/vfio_main.c-248-}\ndrivers/vfio/vfio_main.c:249:EXPORT_SYMBOL_GPL(_vfio_alloc_device);\ndrivers/vfio/vfio_main.c-250-\n--\ninclude/linux/vfio.h=301=vfio_check_precopy_ioctl(struct vfio_device *vdev, unsigned int cmd,\n--\ninclude/linux/vfio.h-324-\ninclude/linux/vfio.h:325:struct vfio_device *_vfio_alloc_device(size_t size, struct device *dev,\ninclude/linux/vfio.h-326-\t\t\t\t const struct vfio_device_ops *ops);\ninclude/linux/vfio.h:327:#define vfio_alloc_device(dev_struct, member, dev, ops)\t\t\t\t\\\ninclude/linux/vfio.h:328:\tcontainer_of(_vfio_alloc_device(sizeof(struct dev_struct) +\t\t\\\ninclude/linux/vfio.h-329-\t\t\t\t\tBUILD_BUG_ON_ZERO(offsetof(\t\t\\\n--\nsamples/vfio-mdev/mbochs.c=566=static int mbochs_probe(struct mdev_device *mdev)\n--\nsamples/vfio-mdev/mbochs.c-570-\nsamples/vfio-mdev/mbochs.c:571:\tmdev_state = vfio_alloc_device(mdev_state, vdev, \u0026mdev-\u003edev,\nsamples/vfio-mdev/mbochs.c-572-\t\t\t\t \u0026mbochs_dev_ops);\n--\nsamples/vfio-mdev/mdpy.c=261=static int mdpy_probe(struct mdev_device *mdev)\n--\nsamples/vfio-mdev/mdpy.c-265-\nsamples/vfio-mdev/mdpy.c:266:\tmdev_state = vfio_alloc_device(mdev_state, vdev, \u0026mdev-\u003edev,\nsamples/vfio-mdev/mdpy.c-267-\t\t\t\t \u0026mdpy_dev_ops);\n--\nsamples/vfio-mdev/mtty.c=1358=static int mtty_probe(struct mdev_device *mdev)\n--\nsamples/vfio-mdev/mtty.c-1362-\nsamples/vfio-mdev/mtty.c:1363:\tmdev_state = vfio_alloc_device(mdev_state, vdev, \u0026mdev-\u003edev,\nsamples/vfio-mdev/mtty.c-1364-\t\t\t\t \u0026mtty_dev_ops);\n"
} |
| 49/2 | 2026/11/22 09:39 | llm | patch-evaluator |
1mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 82762 output: 27 thoughts: 4472 Thoughts: **Analyzing the TPH Patch for Fuzzing Potential** Okay, so I'm diving into this patch series, trying to figure out if it's worth the effort to fuzz it. My initial thought process involves tracing the execution paths and considering the conditions under which the modified code is reached. I'm focusing on the `virtiovf_pci_probe` and `vfio_pci_probe` functions as entry points, since they handle the PCI device setup within the vfio framework. The primary question I'm asking is: when are the core functions like `vfio_pci_core_enable`, `vfio_pci_core_disable`, and the ioctl handlers for TPH features actually invoked? I've established that these functions are called when a PCI device is bound to `vfio-pci`. `vfio_alloc_device` creates the vfio device with the `vfio_pci_ops` (or `virtiovf_vfio_pci_ops`). The functions `vfio_pci_tph_dev_init` and `vfio_pci_tph_dev_deinit` are executed during the device enable and disable sequences, respectively. Furthermore, the `VFIO_DEVICE_FEATURE_TPH`, `VFIO_DEVICE_FEATURE_TPH_PROGRAM`, and `VFIO_DEVICE_FEATURE_TPH_RESOLVE` ioctls all funnel into the TPH-related core feature handlers within the VFIO driver. Now, here's where it gets interesting. Even if a device *is* bound to `vfio-pci`, does it *actually* have the TPH capability (`PCI_EXT_CAP_ID_TPH`)? If not, a lot of the code paths seem to be bypassed. Specifically, functions like `vfio_pci_tph_dev_init` returns early, and the feature ioctls return `-EOPNOTSUPP`. The config space read/write callbacks for the TPH capability are never registered in the first place, if the device does not have `PCI_EXT_CAP_ID_TPH`. My immediate reaction was that the patch might be mostly a no-op for most devices. But the crucial question is whether that bypass means the modified code is *unreachable*, and therefore uninteresting for fuzzing. The patch *does* modify `pcie_disable_tph`, which is called regardless of TPH capability presence, and `pci_tph_init` which is called during device initialization. The modifications to `pcie_disable_tph`, `pci_tph_init` may still be reachable. To be sure, I've reread the fuzzing guidance, specifically the criteria for returning `WorthFuzzing=false`. I've concluded that the modified code *doesn't* strictly fall into the categories of "non-kernel and non-executable changes," "structurally unreachable hardware," or "unreachable execution paths" as defined in the guidance. VFIO is not a vendor-specific driver requiring special hardware. The code touches reachable VFIO code. Therefore, by a process of elimination and a close reading of the fuzzing guidance, I'm leaning toward the belief that `WorthFuzzing=true`. The next stage of analysis will determine whether or not syzkaller is able to trigger these VFIO code paths. |
| 50/2 | 2026/11/22 09:40 | tool | grepper |
0mArgs:{
"Expression": "syzkaller.*vfio|vfio.*syzkaller"
}Results: {
"Output": "no matches"
} |
| 51/2 | 2026/11/22 09:40 | llm | patch-evaluator |
1mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 88008 output: 30 thoughts: 2506 Thoughts: **VFIO TPH Feature Analysis for Syzkaller Integration** Alright, let's break this down. My initial thought is to see if syzkaller has found any VFIO bugs, and it clearly has, hitting several areas. Now, this patch touches VFIO, a core virtualization component. Looking at the "WorthFuzzing=true" criteria, this patch definitely hits the mark. It modifies reachable code, specifically within the VFIO PCI driver, which supports virtual buses like virtio. This patch introduces new ioctl commands, module parameters, debugfs entries, CPU hotplug notifier state, and PCI core TPH functions. It's extensive. So, "WorthFuzzing=true" is a solid yes. Now, the important part: Identifying the "FocusSymbols". I need to avoid ubiquitous functions, so I want the specific entry points or logic tied to this TPH (Targeted Physical Hardware) feature. I'm focusing on the added/modified functions: In `drivers/pci/tph.c`, I see a bunch of new TPH functions, these are specific to TPH and not generic. In `drivers/vfio/pci/vfio_pci.c`, I see `tph_policy_set`. Then, inside `drivers/vfio/pci/vfio_pci_config.c`, I have static functions that rewrite vcap, read and write config. Inside `drivers/vfio/pci/vfio_pci_core.c`, I find the main entry point: `vfio_pci_core_ioctl_feature`. Also a few static functions that are related to this feature: `vfio_pci_core_feature_tph`, `vfio_pci_core_feature_tph_program`, `vfio_pci_core_feature_tph_resolve`, `vfio_pci_tph_cpuhp_offline`, `vfio_pci_tph_dev_init` and `vfio_pci_tph_resolve_st_tag`. Okay, taking into account the criteria, I'm going to choose: * `vfio_pci_core_feature_tph` * `vfio_pci_core_feature_tph_program` * `vfio_pci_core_feature_tph_resolve` * `vfio_tph_config_write` * `vfio_tph_config_read` * `pcie_tph_set_st_entries` * `pcie_enable_tph_ext` * `pcie_tph_get_cpu_st_ext` * `vfio_pci_tph_cpuhp_offline` Now, let's verify these symbols exist. They are all specific to the VFIO TPH feature. Now, for `EnableConfigs` I need to review the Kconfigs and Makefiles to understand which config options activate this code. I need to make sure I identify and set the relevant configurations so Syzkaller can properly enable and test this new functionality. |
| 52/2 | 2026/11/22 09:41 | tool | grepper |
0mArgs:{
"Expression": "tph\\.o",
"PathPrefixes": [
"drivers/pci/"
]
}Results: {
"Output": "drivers/pci/Makefile=41=obj-$(CONFIG_PCI_NPEM)\t\t+= npem.o\ndrivers/pci/Makefile:42:obj-$(CONFIG_PCIE_TPH)\t\t+= tph.o\ndrivers/pci/Makefile-43-obj-$(CONFIG_CARDBUS)\t\t+= setup-cardbus.o\n"
} |
| 53/2 | 2026/11/22 09:41 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 91328 output: 35 thoughts: 134 Thoughts: **Investigating the `PCIE_TPH` Configuration Option** Okay, so I'm looking at `drivers/pci/Makefile`, and I see the line `obj-$(CONFIG_PCIE_TPH) += tph.o`. Right, so we definitely require the `PCIE_TPH` config option to be enabled for the `tph.o` object to be built. Makes perfect sense. Now, I need to understand this `PCIE_TPH` option better. Time to check `drivers/pci/Kconfig`. Let me jump over to that file. Ah, line 197, I see: `config PCIE_TPH bool "TLP Processing Hints"`. Good, it's a boolean option, and the description is "TLP Processing Hints". Now, the important question is: are there any dependencies for this? I need to know what other configuration options might influence whether this is even exposed to the user, or if it has any hardware dependencies that need to be met. Let me quickly scan the surrounding lines, say 190-205 in the Kconfig file, to see if there are any `depends on` clauses. I need to understand its context. |
| 54/2 | 2026/11/22 09:42 | tool | read-file |
0mArgs:{
"File": "drivers/pci/Kconfig",
"FirstLine": 190,
"LineCount": 17
}Results: {
"Contents": " 190:\t\t to access more than one IO address space at the same time. To make\n 191:\t\t use of this feature an IOMMU is required which also supports PASIDs.\n 192:\t\t Select this option if you have such an IOMMU and want to compile the\n 193:\t\t driver for it into your kernel.\n 194:\t\n 195:\t\t If unsure, say N.\n 196:\t\n 197:\tconfig PCIE_TPH\n 198:\t\tbool \"TLP Processing Hints\"\n 199:\t\thelp\n 200:\t\t This option adds support for PCIe TLP Processing Hints (TPH).\n 201:\t\t TPH allows endpoint devices to provide optimization hints, such as\n 202:\t\t desired caching behavior, for requests that target memory space.\n 203:\t\t These hints, called Steering Tags, can empower the system hardware\n 204:\t\t to optimize the utilization of platform resources.\n 205:\t\n 206:\tconfig PCI_P2PDMA\n"
} |
| 55/2 | 2026/11/22 09:42 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 92042 output: 33 thoughts: 61 Thoughts: Okay, let's break this down. **Analyzing the PCIE_TPH Kconfig Entry** My initial thought is to examine the `PCIE_TPH` Kconfig option. The key here is to determine its dependencies, or lack thereof, beyond its placement within the `drivers/pci/Kconfig` file. I need to understand if it's conditioned by any higher-level features within the PCI subsystem. Therefore, I'm specifically looking for an `if PCI` statement or potentially a `menu "PCI support"` block that encapsulates `PCIE_TPH` within the `drivers/pci/Kconfig` file. The presence of either of these would directly affect when `PCIE_TPH` is even considered for configuration, and thus are relevant for determining its ultimate behavior and usability. I have to start with the obvious. |
| 56/2 | 2026/11/22 09:42 | tool | read-file |
0mArgs:{
"File": "drivers/pci/Kconfig",
"FirstLine": 1,
"LineCount": 40
}Results: {
"Contents": " 1:\t# SPDX-License-Identifier: GPL-2.0\n 2:\t#\n 3:\t# PCI configuration\n 4:\t#\n 5:\t\n 6:\t# select this to offer the PCI prompt\n 7:\tconfig HAVE_PCI\n 8:\t\tbool\n 9:\t\n 10:\t# select this to unconditionally force on PCI support\n 11:\tconfig FORCE_PCI\n 12:\t\tbool\n 13:\t\tselect HAVE_PCI\n 14:\t\tselect PCI\n 15:\t\n 16:\t# select this to provide a generic PCI iomap,\n 17:\t# without PCI itself having to be defined\n 18:\tconfig GENERIC_PCI_IOMAP\n 19:\t\tbool\n 20:\t\n 21:\tmenuconfig PCI\n 22:\t\tbool \"PCI support\"\n 23:\t\tdepends on HAVE_PCI\n 24:\t\tdepends on MMU\n 25:\t\thelp\n 26:\t\t This option enables support for the PCI local bus, including\n 27:\t\t support for PCI-X and the foundations for PCI Express support.\n 28:\t\t Say 'Y' here unless you know what you are doing.\n 29:\t\n 30:\tif PCI\n 31:\t\n 32:\tconfig PCI_DOMAINS\n 33:\t\tbool\n 34:\t\n 35:\tconfig PCI_DOMAINS_GENERIC\n 36:\t\tbool\n 37:\t\tselect PCI_DOMAINS\n 38:\t\n 39:\tconfig PCI_SYSCALL\n 40:\t\tbool\n"
} |
| 57/2 | 2026/11/22 09:42 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 92731 output: 33 thoughts: 307 Thoughts: **Analyzing VFIO-PCI Module Dependencies** Okay, so I'm looking at line 197 and seeing it's conditional on `PCI`, meaning `PCI` and `PCIE_TPH` are relevant. Now I need to figure out what modules are built based on which configurations. My next step is to examine the `drivers/vfio/pci/Makefile`. Let's see... I can see that `vfio-pci-core-y` includes the core files, then we have conditionals for `CONFIG_VFIO_PCI_ZDEV_KVM` and `CONFIG_VFIO_PCI_DMABUF` adding additional object files. Importantly, `obj-$(CONFIG_VFIO_PCI_CORE) += vfio-pci-core.o` tells me when that core module is built. Then I see `vfio-pci-y := vfio_pci.o` which defines the base, plus a conditional for `CONFIG_VFIO_PCI_IGD`. Finally, `obj-$(CONFIG_VFIO_PCI) += vfio-pci.o` handles when the `vfio-pci` module is built. Now, I'm heading over to `drivers/vfio/Makefile` to see how the PCI components are integrated at the parent directory level. Ah, right here, `obj-$(CONFIG_VFIO_PCI_CORE) += pci/`, this confirms that the `pci` directory is included if the core is enabled. I also need to check the Kconfig file for relevant configuration options. So, let's see what's in `drivers/vfio/Kconfig`. |
| 58/2 | 2026/11/22 09:43 | tool | read-file |
0mArgs:{
"File": "drivers/vfio/Kconfig",
"FirstLine": 1,
"LineCount": 50
}Results: {
"Contents": " 1:\t# SPDX-License-Identifier: GPL-2.0-only\n 2:\tmenuconfig VFIO\n 3:\t\ttristate \"VFIO Non-Privileged userspace driver framework\"\n 4:\t\tselect IOMMU_API\n 5:\t\tdepends on IOMMUFD || !IOMMUFD\n 6:\t\tselect INTERVAL_TREE\n 7:\t\tselect VFIO_GROUP if SPAPR_TCE_IOMMU || IOMMUFD=n\n 8:\t\tselect VFIO_DEVICE_CDEV if !VFIO_GROUP\n 9:\t\tselect VFIO_CONTAINER if IOMMUFD=n\n 10:\t\thelp\n 11:\t\t VFIO provides a framework for secure userspace device drivers.\n 12:\t\t See Documentation/driver-api/vfio.rst for more details.\n 13:\t\n 14:\t\t If you don't know what to do here, say N.\n 15:\t\n 16:\tif VFIO\n 17:\tconfig VFIO_DEVICE_CDEV\n 18:\t\tbool \"Support for the VFIO cdev /dev/vfio/devices/vfioX\"\n 19:\t\tdepends on IOMMUFD \u0026\u0026 !SPAPR_TCE_IOMMU\n 20:\t\tdefault !VFIO_GROUP\n 21:\t\thelp\n 22:\t\t The VFIO device cdev is another way for userspace to get device\n 23:\t\t access. Userspace gets device fd by opening device cdev under\n 24:\t\t /dev/vfio/devices/vfioX, and then bind the device fd with an iommufd\n 25:\t\t to set up secure DMA context for device access.\n 26:\t\n 27:\t\t If you don't know what to do here, say N.\n 28:\t\n 29:\tconfig VFIO_GROUP\n 30:\t\tbool \"Support for the VFIO group /dev/vfio/$group_id\"\n 31:\t\tdefault y\n 32:\t\thelp\n 33:\t\t VFIO group support provides the traditional model for accessing\n 34:\t\t devices through VFIO and is used by the majority of userspace\n 35:\t\t applications and drivers making use of VFIO.\n 36:\t\n 37:\t\t If you don't know what to do here, say Y.\n 38:\t\n 39:\tconfig VFIO_CONTAINER\n 40:\t\tbool \"Support for the VFIO container /dev/vfio/vfio\"\n 41:\t\tselect VFIO_IOMMU_TYPE1 if MMU \u0026\u0026 (X86 || S390 || ARM || ARM64)\n 42:\t\tdepends on VFIO_GROUP\n 43:\t\tdefault y\n 44:\t\thelp\n 45:\t\t The VFIO container is the classic interface to VFIO for establishing\n 46:\t\t IOMMU mappings. If N is selected here then IOMMUFD must be used to\n 47:\t\t manage the mappings.\n 48:\t\n 49:\t\t Unless testing IOMMUFD say Y here.\n 50:\t\n"
} |
| 59/2 | 2026/11/22 09:43 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 94211 output: 34 thoughts: 21 Thoughts: Here's my take on the line range you specified: **Analyzing vfio Kconfig (Lines 50-70)** Alright, let's dive into lines 50-70 of `drivers/vfio/Kconfig`. I'm expecting to see configuration options related to specific VFIO features or perhaps device types. Given the context, this is likely where we'll find the granularity of what a developer can enable or disable for the VFIO subsystem. I want to quickly identify any new options or changes since the last time I reviewed this section, and whether they align with the latest discussions on performance or security improvements. I'm also looking for dependencies, default values, and help text – that's crucial for understanding the intent and implications of each configuration setting. Any interaction between this config section and the rest of the VFIO subsystem, or other kernel modules, is also of interest to me. My main objective is to identify any potential risks, opportunities, or areas that could impact the stability or performance of VFIO deployments. |
| 60/2 | 2026/11/22 09:43 | tool | read-file |
0mArgs:{
"File": "drivers/vfio/Kconfig",
"FirstLine": 50,
"LineCount": 25
}Results: {
"Contents": " 50:\t\n 51:\tif VFIO_CONTAINER\n 52:\tconfig VFIO_IOMMU_TYPE1\n 53:\t\ttristate\n 54:\t\tdefault n\n 55:\t\n 56:\tconfig VFIO_IOMMU_SPAPR_TCE\n 57:\t\ttristate\n 58:\t\tdepends on SPAPR_TCE_IOMMU\n 59:\t\tdefault VFIO\n 60:\tendif\n 61:\t\n 62:\tconfig VFIO_NOIOMMU\n 63:\t\tbool \"VFIO No-IOMMU support\"\n 64:\t\tdepends on VFIO_GROUP || (VFIO_DEVICE_CDEV \u0026\u0026 !GENERIC_ATOMIC64)\n 65:\t\tdepends on !VFIO_GROUP || VFIO_CONTAINER || IOMMUFD_VFIO_CONTAINER\n 66:\t\tselect IOMMUFD_NOIOMMU if VFIO_DEVICE_CDEV \u0026\u0026 !GENERIC_ATOMIC64\n 67:\t\thelp\n 68:\t\t VFIO is built on the ability to isolate devices using the IOMMU.\n 69:\t\t Only with an IOMMU can userspace access to DMA capable devices be\n 70:\t\t considered secure. VFIO No-IOMMU mode enables IOMMU groups for\n 71:\t\t devices without IOMMU backing for the purpose of re-using the VFIO\n 72:\t\t infrastructure in a non-secure mode. Use of this mode will result\n 73:\t\t in an unsupportable kernel and will therefore taint the kernel.\n 74:\t\t Device assignment to virtual machines is also not possible with\n"
} |
| 61/2 | 2026/11/22 09:43 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 94904 output: 34 thoughts: 22 Thoughts: Here's my summary, as if I were thinking these thoughts: **Examining VFIO's Configuration Options** Alright, let's dive in. I need to refresh my memory on the specifics of how VFIO is configured within the kernel. Time to zero in on lines 75 through 100 of the `drivers/vfio/Kconfig` file. I'm hoping to quickly identify the relevant configuration options within that range, and what dependencies or defaults they might have. I want to check for any new additions or changes to core settings and their implications for user space. I need to quickly recall the implications of any `select` statements and tristate options within that section, and how they relate to the bigger VFIO picture. It's time to refresh and update! |
| 62/2 | 2026/11/22 09:44 | tool | read-file |
0mArgs:{
"File": "drivers/vfio/Kconfig",
"FirstLine": 75,
"LineCount": 25
}Results: {
"Contents": " 75:\t\t this mode since there is no IOMMU to provide DMA translation.\n 76:\t\n 77:\t\t If you don't know what to do here, say N.\n 78:\t\n 79:\tconfig VFIO_VIRQFD\n 80:\t\tbool\n 81:\t\tselect EVENTFD\n 82:\t\tdefault n\n 83:\t\n 84:\tconfig VFIO_DEBUGFS\n 85:\t\tbool \"Export VFIO internals in DebugFS\"\n 86:\t\tdepends on DEBUG_FS\n 87:\t\thelp\n 88:\t\t Allows exposure of VFIO device internals. This option enables\n 89:\t\t the use of debugfs by VFIO drivers as required. The device can\n 90:\t\t cause the VFIO code create a top-level debug/vfio directory\n 91:\t\t during initialization, and then populate a subdirectory with\n 92:\t\t entries as required.\n 93:\t\n 94:\tsource \"drivers/vfio/pci/Kconfig\"\n 95:\tsource \"drivers/vfio/platform/Kconfig\"\n 96:\tsource \"drivers/vfio/mdev/Kconfig\"\n 97:\tsource \"drivers/vfio/fsl-mc/Kconfig\"\n 98:\tsource \"drivers/vfio/cdx/Kconfig\"\n 99:\tendif\n"
} |
| 63/2 | 2026/11/22 09:44 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 95479 output: 353 thoughts: 1291 Thoughts: **Fuzzing Verdict: PCIe TPH and VFIO TPH Support** Okay, let's break this down. First, I need to confirm the necessary configurations. I've re-examined `drivers/vfio/pci/Kconfig` and confirmed that `VFIO_PCI` selects `VFIO_PCI_CORE`. I've also noted that `ACPI` is utilized in `drivers/pci/tph.c` and is conditional in `pcie_tph_dsm_supported`, enabling ACPI Steering Tag resolution paths. `VFIO_DEBUGFS` enables the debugfs `tph` file. Further, I know that `CPU_HOTPLUG` is needed for CPU hotplug features. So, the key configs I need to ensure are enabled are: `PCIE_TPH`, `VFIO_PCI`, `VFIO_PCI_CORE` (selected by `VFIO_PCI`), `VFIO` (parent of `VFIO_PCI`), `PCI`, `ACPI`, and `VFIO_DEBUGFS`. Looking at the diff, `CONFIG_PCIE_TPH` builds `tph.o`, `CONFIG_VFIO_PCI` builds `vfio_pci.o`, `CONFIG_VFIO_PCI_CORE` builds `vfio_pci_config.o`, and `CONFIG_VFIO_PCI_CORE` also builds `vfio_pci_core.o`. The debugfs support is conditional on `CONFIG_VFIO_DEBUGFS`. The key symbols in focus are: `vfio_pci_core_feature_tph`, `vfio_pci_core_feature_tph_program`, `vfio_pci_core_feature_tph_resolve`, `vfio_tph_config_write`, `vfio_tph_config_read`, `vfio_pci_tph_cpuhp_offline`, `pcie_tph_set_st_entries`, `pcie_enable_tph_ext`, `pcie_tph_get_cpu_st_ext`, and `pcie_tph_dsm_supported`. None of these are common infrastructure elements, confirming their specific relevance to TPH and VFIO. Given all of this, the final check confirms that `WorthFuzzing` is `true`. The `FocusSymbols` are as listed above. The `EnableConfigs` are: `PCIE_TPH`, `VFIO_PCI`, `VFIO`, `PCI`, and `ACPI`. The reasoning is clear: this patch introduces VFIO user-space interfaces for PCIe TPH. It includes new IOCTL features, virtualized TPH extended capability config space read/write, and CPU hotplug integration, along with refactoring existing PCIe TPH helpers. This warrants fuzzing because of the user-controllable input via new ioctls, complex state handling involving memory allocation, locking, array indexing, and CPU hotplug notifications. Therefore, this is a clear candidate for fuzzing. Time to call `set-results`. |
| 64/2 | 2026/11/22 09:45 | tool | set-results |
0mArgs:{
"EnableConfigs": [
"PCIE_TPH",
"VFIO_PCI",
"VFIO",
"PCI",
"ACPI"
],
"FocusSymbols": [
"vfio_pci_core_feature_tph",
"vfio_pci_core_feature_tph_program",
"vfio_pci_core_feature_tph_resolve",
"vfio_tph_config_write",
"vfio_tph_config_read",
"vfio_pci_tph_cpuhp_offline",
"pcie_tph_set_st_entries",
"pcie_enable_tph_ext",
"pcie_tph_get_cpu_st_ext",
"pcie_tph_dsm_supported"
],
"Reasoning": "The patch series implements support for PCIe TLP Processing Hints (TPH) in VFIO-PCI and refactors core PCIe TPH helper functions. Specifically, it adds user-facing ioctls (VFIO_DEVICE_FEATURE_TPH, VFIO_DEVICE_FEATURE_TPH_PROGRAM, VFIO_DEVICE_FEATURE_TPH_RESOLVE) for steering tag (ST) capability discovery, resolution, and batch table programming, virtualizes the PCIe TPH extended capability in VFIO config space reads/writes, integrates with the CPU hotplug subsystem to clear ST mappings when CPUs go offline, and introduces new locking and allocation paths. These changes touch reachable driver and PCI core code accepting user inputs and warrant fuzzing.",
"WorthFuzzing": true
}Results: {
"EnableConfigs": [
"PCIE_TPH",
"VFIO_PCI",
"VFIO",
"PCI",
"ACPI"
],
"FocusSymbols": [
"vfio_pci_core_feature_tph",
"vfio_pci_core_feature_tph_program",
"vfio_pci_core_feature_tph_resolve",
"vfio_tph_config_write",
"vfio_tph_config_read",
"vfio_pci_tph_cpuhp_offline",
"pcie_tph_set_st_entries",
"pcie_enable_tph_ext",
"pcie_tph_get_cpu_st_ext",
"pcie_tph_dsm_supported"
],
"Reasoning": "The patch series implements support for PCIe TLP Processing Hints (TPH) in VFIO-PCI and refactors core PCIe TPH helper functions. Specifically, it adds user-facing ioctls (VFIO_DEVICE_FEATURE_TPH, VFIO_DEVICE_FEATURE_TPH_PROGRAM, VFIO_DEVICE_FEATURE_TPH_RESOLVE) for steering tag (ST) capability discovery, resolution, and batch table programming, virtualizes the PCIe TPH extended capability in VFIO config space reads/writes, integrates with the CPU hotplug subsystem to clear ST mappings when CPUs go offline, and introduces new locking and allocation paths. These changes touch reachable driver and PCI core code accepting user inputs and warrant fuzzing.",
"WorthFuzzing": true
} |
| 65/1 | 2026/11/22 09:45 | action | If |
10mArgs:{
"WorthFuzzing": true
}Results: null |
| 66/2 | 2026/11/22 09:45 | agent | kmsan-evaluator |
10mModel:core Args: null Results: {
"KMSANReasoning": "The patch series adds PCIe TPH (TLP Processing Hints) support to VFIO-PCI and refactors helper functions in the PCI core TPH implementation.\n\nAnalysis of uninitialized memory risks:\n1. Structures copied to userspace:\n - `vfio_pci_core_feature_tph`: Copies `struct vfio_device_feature_tph` (4 bytes, single u32 `flags` field) to user space after assigning `flags`. There are no padding bytes or uninitialized fields.\n - `vfio_pci_core_feature_tph_resolve`: Copies `struct vfio_device_feature_tph_resolve` to user space. The structure layout is 12 bytes total (u32 flags, u32 src, u8 valid, u8 rsv, u16 st), matching 4-byte struct alignment with 0 padding bytes. The input fields `flags` and `src` are populated via `copy_from_user`, and all remaining output fields (`valid`, `rsv`, `st`) are explicitly assigned.\n - Config space reads via `vfio_tph_config_read`: Values are either synthesized (0 for out-of-range/table offsets) or read from device config space into pre-initialized stack buffers.\n\n2. Buffers and structures allocated in kernel space:\n - Dynamic allocations use zeroing allocators (`kcalloc` for `tags` and `vdev-\u003etph_st_cpu`, `kvzalloc` for the containing `vfio_pci_core_device`).\n - Local variables such as `reg` in `pcie_tph_get_st_table_loc` and `pci_tph_init` are explicitly initialized to 0.\n\nPotential issues introduced by this patch series (such as bounds checking on ST table sizes, array indexing, mutex locking with `tph_lock`, CPU hotplug state management, or PCI config register accesses) are fully covered by standard bug detectors (KASAN, LOCKDEP, UBSAN). There are no uninitialized memory reads or information leak risks that would warrant a dedicated KMSAN fuzzing session.",
"NeedsKMSAN": false
}Instruction: You are an expert Linux kernel security engineer specializing in kernel memory
error detectors (KASAN and KMSAN). Your job is to review the provided patch series and
determine if the code changes justify spawning a dedicated KMSAN (KernelMemorySanitizer)
fuzzing session in addition to standard KASAN fuzzing.
CRITICAL DISTINCTION BETWEEN KASAN AND KMSAN:
- Standard KASAN kernel builds (upstream-apparmor-kasan.config) already enable
a comprehensive suite of debugging tools and sanitizers, including KASAN
(out-of-bounds accesses, use-after-free, double free, invalid free), LOCKDEP
(locking bugs and deadlocks), UB-sanitizers, and memory corruption checks.
- KMSAN (KernelMemorySanitizer) detects reads of UNINITIALIZED memory (stack, heap,
or page allocations) and kernel-to-user memory info-leaks.
Rule: THERE IS NO SENSE IN RUNNING A KMSAN SESSION IF A BUG CAN BE CAUGHT BY KASAN,
LOCKDEP, OR OTHER STANDARD BUG DETECTORS.
A dedicated KMSAN fuzzing session incurs significant resource costs. You must ONLY
set NeedsKMSAN=true if the code changes introduce or expose UNINITIALIZED MEMORY risks
that are detected ONLY by KMSAN.
Look holistically at the patch series and surrounding code. Even if no direct
uninitialized field accesses or new buffer allocations are added in the diff itself,
a patch may alter control flow, bounds checking, or data length calculations in ways
that change how the rest of the code operates on existing buffers (e.g. allowing
uninitialized stack/heap memory to be read, copied to user space, or used in control
flow). Do not hesitate to use your code access tools to inspect the surrounding code,
called functions, and callers.
Set NeedsKMSAN=true ONLY IF the patch introduces or modifies:
1. Kernel structures sent to user space (via copy_to_user, put_user, netlink skb
attributes, ioctl output arguments, socket options, or BPF buffers) where fields
or structure padding might not be fully initialized/zeroed.
2. Conditional logic or branching that depends on potentially uninitialized variables
or struct fields.
3. Allocation or initialization of complex data structures where uninitialized fields
could be read later in reachable code paths.
4. Bounds checks, lengths, or logic in a way that allows surrounding code to access
uninitialized bytes of existing buffers.
Set NeedsKMSAN=false IF:
- The code changes primarily risk out-of-bounds access, array overflows, NULL pointer
dereferences, locking deadlocks, or use-after-free bugs (these are already caught
by KASAN, LOCKDEP, or standard bug detectors).
- All stack/heap structures touched or introduced by the patch are fully zeroed
or initialized (e.g. using = {0}, memset, kzalloc) before being read or copied.
- The patch does not introduce any risk of uninitialized memory usage or info-leaks.
Use your code access tools to inspect the surrounding code if necessary, then provide
detailed KMSANReasoning contrasting KASAN vs KMSAN applicability for this patch.
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt: Target architecture: amd64
For your convenience, here is the diff of the changes:
commit 03d5f979b30c8eee0af9b8cf1923dd0e2bffa4d0
Author: syz-cluster <triage@syzkaller.com>
Date: Sun Nov 22 09:23:03 2026 +0000
syz-cluster: applied patch under review
diff --git a/drivers/pci/tph.c b/drivers/pci/tph.c
index 4d064b86befcc5..c3d940745fe4da 100644
--- a/drivers/pci/tph.c
+++ b/drivers/pci/tph.c
@@ -167,11 +167,14 @@ static u8 get_st_modes(struct pci_dev *pdev)
*/
u32 pcie_tph_get_st_table_loc(struct pci_dev *pdev)
{
- u32 reg;
+ u32 reg = 0;
+
+ if (!pdev->tph_cap)
+ return PCI_TPH_LOC_NONE;
pci_read_config_dword(pdev, pdev->tph_cap + PCI_TPH_CAP, ®);
- return FIELD_GET(PCI_TPH_CAP_LOC_MASK, reg);
+ return reg & PCI_TPH_CAP_LOC_MASK;
}
EXPORT_SYMBOL(pcie_tph_get_st_table_loc);
@@ -186,9 +189,6 @@ u16 pcie_tph_get_st_table_size(struct pci_dev *pdev)
/* Check ST table location first */
loc = pcie_tph_get_st_table_loc(pdev);
-
- /* Convert loc to match with PCI_TPH_LOC_* defined in pci_regs.h */
- loc = FIELD_PREP(PCI_TPH_CAP_LOC_MASK, loc);
if (loc != PCI_TPH_LOC_CAP)
return 0;
@@ -233,20 +233,22 @@ static int write_tag_to_st_table(struct pci_dev *pdev, int index, u16 tag)
}
/**
- * pcie_tph_get_cpu_st() - Retrieve Steering Tag for a target memory associated
- * with a specific CPU
+ * pcie_tph_get_cpu_st_ext() - Retrieve Steering Tag for a target memory
+ * associated with a specific CPU, with explicit requester type selection
* @pdev: PCI device
* @mem_type: target memory type (volatile or persistent RAM)
+ * @req_type: TPH requester type to select ST namespace
* @cpu: associated CPU id
* @tag: Steering Tag to be returned
*
- * Return the Steering Tag for a target memory that is associated with a
- * specific CPU as indicated by cpu.
+ * Return the Steering Tag for a target memory associated with a specific CPU,
+ * using the specified TPH requester type to select the correct ST namespace.
+ * Validates requester type against hardware negotiated capability limits.
*
* Return: 0 if success, otherwise negative value (-errno)
*/
-int pcie_tph_get_cpu_st(struct pci_dev *pdev, enum tph_mem_type mem_type,
- unsigned int cpu, u16 *tag)
+int pcie_tph_get_cpu_st_ext(struct pci_dev *pdev, enum tph_mem_type mem_type,
+ u8 req_type, unsigned int cpu, u16 *tag)
{
#ifdef CONFIG_ACPI
struct pci_dev *rp;
@@ -255,6 +257,10 @@ int pcie_tph_get_cpu_st(struct pci_dev *pdev, enum tph_mem_type mem_type,
u32 cpu_uid;
int ret;
+ if (req_type == PCI_TPH_REQ_DISABLE || req_type == 2 ||
+ req_type > pdev->tph_max_type)
+ return -EINVAL;
+
ret = acpi_get_cpu_uid(cpu, &cpu_uid);
if (ret != 0)
return ret;
@@ -270,35 +276,54 @@ int pcie_tph_get_cpu_st(struct pci_dev *pdev, enum tph_mem_type mem_type,
return -EINVAL;
}
- *tag = tph_extract_tag(mem_type, pdev->tph_req_type, &info);
+ *tag = tph_extract_tag(mem_type, req_type, &info);
- pci_dbg(pdev, "get steering tag: mem_type=%s, cpu=%d, tag=%#04x\n",
+ pci_dbg(pdev, "get steering tag: mem_type=%s, req_type=%u, cpu=%d, tag=%#04x\n",
(mem_type == TPH_MEM_TYPE_VM) ? "volatile" : "persistent",
- cpu, *tag);
+ req_type, cpu, *tag);
return 0;
#else
return -ENODEV;
#endif
}
-EXPORT_SYMBOL(pcie_tph_get_cpu_st);
+EXPORT_SYMBOL(pcie_tph_get_cpu_st_ext);
/**
- * pcie_tph_set_st_entry() - Set Steering Tag in the ST table entry
+ * pcie_tph_get_cpu_st() - Retrieve Steering Tag for a target memory associated
+ * with a specific CPU
* @pdev: PCI device
- * @index: ST table entry index
- * @tag: Steering Tag to be written
+ * @mem_type: target memory type (volatile or persistent RAM)
+ * @cpu: associated CPU id
+ * @tag: Steering Tag to be returned
*
- * Figure out the proper location of ST table, either in the MSI-X table or
- * in the TPH Extended Capability space, and write the Steering Tag into
- * the ST entry pointed by index.
+ * Return the Steering Tag for a target memory associated with a specific CPU,
+ * using the default negotiated TPH requester type.
*
* Return: 0 if success, otherwise negative value (-errno)
*/
-int pcie_tph_set_st_entry(struct pci_dev *pdev, unsigned int index, u16 tag)
+int pcie_tph_get_cpu_st(struct pci_dev *pdev, enum tph_mem_type mem_type,
+ unsigned int cpu, u16 *tag)
+{
+ return pcie_tph_get_cpu_st_ext(pdev, mem_type, pdev->tph_max_type,
+ cpu, tag);
+}
+EXPORT_SYMBOL(pcie_tph_get_cpu_st);
+
+/**
+ * pcie_tph_set_st_entries - Batch set Steering Tag entries in the ST table
+ * @pdev: PCI device
+ * @start: starting ST table index
+ * @count: number of contiguous entries to write
+ * @tags: array of u16 tag values to program
+ *
+ * Return: number of successfully written entries (>0), or negative errno
+ */
+int pcie_tph_set_st_entries(struct pci_dev *pdev, unsigned int start,
+ unsigned int count, const u16 *tags)
{
- u32 loc;
int err = 0;
+ u32 loc, i;
if (!pdev->tph_cap)
return -EINVAL;
@@ -306,9 +331,12 @@ int pcie_tph_set_st_entry(struct pci_dev *pdev, unsigned int index, u16 tag)
if (!pdev->tph_enabled)
return -EINVAL;
+ if (!count)
+ return -EINVAL;
+
/* No need to write tag if device is in "No ST Mode" */
if (pdev->tph_mode == PCI_TPH_ST_NS_MODE)
- return 0;
+ return count;
/*
* Disable TPH before updating ST to avoid potential instability as
@@ -317,31 +345,47 @@ int pcie_tph_set_st_entry(struct pci_dev *pdev, unsigned int index, u16 tag)
set_ctrl_reg_req_en(pdev, PCI_TPH_REQ_DISABLE);
loc = pcie_tph_get_st_table_loc(pdev);
- /* Convert loc to match with PCI_TPH_LOC_* */
- loc = FIELD_PREP(PCI_TPH_CAP_LOC_MASK, loc);
-
- switch (loc) {
- case PCI_TPH_LOC_MSIX:
- err = pci_msix_write_tph_tag(pdev, index, tag);
- break;
- case PCI_TPH_LOC_CAP:
- err = write_tag_to_st_table(pdev, index, tag);
- break;
- default:
- err = -EINVAL;
- }
-
- if (err) {
- pcie_disable_tph(pdev);
- return err;
+ for (i = 0; i < count; i++) {
+ switch (loc) {
+ case PCI_TPH_LOC_MSIX:
+ err = pci_msix_write_tph_tag(pdev, start + i, tags[i]);
+ break;
+ case PCI_TPH_LOC_CAP:
+ err = write_tag_to_st_table(pdev, start + i, tags[i]);
+ break;
+ default:
+ err = -EINVAL;
+ }
+ if (err != 0) {
+ pci_err(pdev, "failed to set steering tag: %s table, index=%u, tags=%u, ret=%d\n",
+ (loc == PCI_TPH_LOC_MSIX) ? "MSI-X" : "ST",
+ start + i, tags[i], err);
+ pcie_disable_tph(pdev);
+ return i > 0 ? i : (err > 0 ? -EINVAL : err);
+ }
}
set_ctrl_reg_req_en(pdev, pdev->tph_req_type);
- pci_dbg(pdev, "set steering tag: %s table, index=%d, tag=%#04x\n",
- (loc == PCI_TPH_LOC_MSIX) ? "MSI-X" : "ST", index, tag);
+ pci_dbg(pdev, "batch set steering tag: %s table, start=%u, count=%u success!\n",
+ (loc == PCI_TPH_LOC_MSIX) ? "MSI-X" : "ST", start, count);
- return 0;
+ return count;
+}
+EXPORT_SYMBOL(pcie_tph_set_st_entries);
+
+/**
+ * pcie_tph_set_st_entry() - Set Steering Tag in the ST table entry
+ * @pdev: PCI device
+ * @index: ST table entry index
+ * @tag: Steering Tag to be written
+ *
+ * Return: 0 if success, otherwise negative value (-errno)
+ */
+int pcie_tph_set_st_entry(struct pci_dev *pdev, unsigned int index, u16 tag)
+{
+ int ret = pcie_tph_set_st_entries(pdev, index, 1, &tag);
+ return ret == 1 ? 0 : ret;
}
EXPORT_SYMBOL(pcie_tph_set_st_entry);
@@ -368,26 +412,21 @@ void pcie_disable_tph(struct pci_dev *pdev)
EXPORT_SYMBOL(pcie_disable_tph);
/**
- * pcie_enable_tph - Enable TPH support for device using a specific ST mode
+ * pcie_enable_tph_ext - Enable TPH support with specific ST mode and
+ * requester type
* @pdev: PCI device
- * @mode: ST mode to enable. Current supported modes include:
+ * @mode: ST mode to enable: PCI_TPH_ST_(NS_MODE / IV_MODE / DS_MODE)
+ * @req_type: Requester type to enable: PCI_TPH_REQ_(TPH_ONLY / EXT_TPH)
*
- * - PCI_TPH_ST_NS_MODE: NO ST Mode
- * - PCI_TPH_ST_IV_MODE: Interrupt Vector Mode
- * - PCI_TPH_ST_DS_MODE: Device Specific Mode
- *
- * Check whether the mode is actually supported by the device before enabling
- * and return an error if not. Additionally determine what types of requests,
- * TPH or extended TPH, can be issued by the device based on its TPH requester
- * capability and the Root Port's completer capability.
+ * Check whether the mode and requester type is actually supported by the
+ * device before enabling and return an error if not.
*
* Return: 0 on success, otherwise negative value (-errno)
*/
-int pcie_enable_tph(struct pci_dev *pdev, int mode)
+int pcie_enable_tph_ext(struct pci_dev *pdev, u8 mode, u8 req_type)
{
u32 reg;
u8 dev_modes;
- u8 rp_req_type;
/* Honor "notph" kernel parameter */
if (pci_tph_disabled)
@@ -399,6 +438,14 @@ int pcie_enable_tph(struct pci_dev *pdev, int mode)
if (pdev->tph_enabled)
return -EBUSY;
+ if (pdev->tph_max_type == PCI_TPH_REQ_DISABLE)
+ return -EINVAL;
+
+ /* Sanitize and check TPH requester type compatibility */
+ if (req_type == PCI_TPH_REQ_DISABLE || req_type == 2 ||
+ req_type > pdev->tph_max_type)
+ return -EINVAL;
+
/* Sanitize and check ST mode compatibility */
mode &= PCI_TPH_CTRL_MODE_SEL_MASK;
dev_modes = get_st_modes(pdev);
@@ -407,23 +454,7 @@ int pcie_enable_tph(struct pci_dev *pdev, int mode)
pdev->tph_mode = mode;
- /* Get req_type supported by device and its Root Port */
- pci_read_config_dword(pdev, pdev->tph_cap + PCI_TPH_CAP, ®);
- if (FIELD_GET(PCI_TPH_CAP_EXT_TPH, reg))
- pdev->tph_req_type = PCI_TPH_REQ_EXT_TPH;
- else
- pdev->tph_req_type = PCI_TPH_REQ_TPH_ONLY;
-
- /* Check if the device is behind a Root Port */
- if (pci_pcie_type(pdev) != PCI_EXP_TYPE_RC_END) {
- rp_req_type = get_rp_completer_type(pdev);
-
- /* Final req_type is the smallest value of two */
- pdev->tph_req_type = min(pdev->tph_req_type, rp_req_type);
- }
-
- if (pdev->tph_req_type == PCI_TPH_REQ_DISABLE)
- return -EINVAL;
+ pdev->tph_req_type = req_type;
/* Write them into TPH control register */
pci_read_config_dword(pdev, pdev->tph_cap + PCI_TPH_CTRL, ®);
@@ -437,6 +468,23 @@ int pcie_enable_tph(struct pci_dev *pdev, int mode)
return 0;
}
+EXPORT_SYMBOL(pcie_enable_tph_ext);
+
+/**
+ * pcie_enable_tph - Enable TPH support for device using a specific ST mode
+ * @pdev: PCI device
+ * @mode: ST mode to enable: PCI_TPH_ST_(NS_MODE / IV_MODE / DS_MODE)
+ *
+ * Wrapper for pcie_enable_tph_ext(), automatically uses the pre-cached
+ * tph_max_type value (negotiated maximum requester type between device and
+ * root port).
+ *
+ * Return: 0 on success, otherwise negative value (-errno)
+ */
+int pcie_enable_tph(struct pci_dev *pdev, u8 mode)
+{
+ return pcie_enable_tph_ext(pdev, mode, pdev->tph_max_type);
+}
EXPORT_SYMBOL(pcie_enable_tph);
void pci_restore_tph_state(struct pci_dev *pdev)
@@ -510,14 +558,60 @@ void pci_no_tph(void)
void pci_tph_init(struct pci_dev *pdev)
{
+ u8 tph_req_type, rp_req_type;
int num_entries;
u32 save_size;
+ u32 reg = 0;
pdev->tph_cap = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_TPH);
if (!pdev->tph_cap)
return;
+ /* Get req_type supported by device and its Root Port */
+ pci_read_config_dword(pdev, pdev->tph_cap + PCI_TPH_CAP, ®);
+ if (FIELD_GET(PCI_TPH_CAP_EXT_TPH, reg))
+ tph_req_type = PCI_TPH_REQ_EXT_TPH;
+ else
+ tph_req_type = PCI_TPH_REQ_TPH_ONLY;
+
+ /* Check if the device is behind a Root Port */
+ if (pci_pcie_type(pdev) != PCI_EXP_TYPE_RC_END) {
+ rp_req_type = get_rp_completer_type(pdev);
+ /* Final req_type is the smallest value of two */
+ tph_req_type = min(tph_req_type, rp_req_type);
+ }
+
+ pdev->tph_max_type = tph_req_type;
+
num_entries = pcie_tph_get_st_table_size(pdev);
save_size = sizeof(u32) + num_entries * sizeof(u16);
pci_add_ext_cap_save_buffer(pdev, PCI_EXT_CAP_ID_TPH, save_size);
}
+
+/**
+ * pcie_tph_dsm_supported - Check if root port exposes TPH ST _DSM
+ * @pdev: target PCI device
+ *
+ * Return true if root port of @pdev provides TPH ST DSM function,
+ * false otherwise (ACPI disabled or DSM missing).
+ */
+bool pcie_tph_dsm_supported(struct pci_dev *pdev)
+{
+#ifdef CONFIG_ACPI
+ struct pci_dev *rp = pcie_find_root_port(pdev);
+ acpi_handle handle;
+
+ if (!rp || !rp->bus || !rp->bus->bridge)
+ return false;
+
+ handle = ACPI_HANDLE(rp->bus->bridge);
+ if (!handle)
+ return false;
+
+ return acpi_check_dsm(handle, &pci_acpi_dsm_guid, 7,
+ BIT(TPH_ST_DSM_FUNC_INDEX));
+#else
+ return false;
+#endif
+}
+EXPORT_SYMBOL_GPL(pcie_tph_dsm_supported);
diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c
index e7c012febe9124..0369069e7f6a27 100644
--- a/drivers/vfio/pci/vfio_pci.c
+++ b/drivers/vfio/pci/vfio_pci.c
@@ -60,6 +60,29 @@ static bool disable_denylist;
module_param(disable_denylist, bool, 0444);
MODULE_PARM_DESC(disable_denylist, "Disable use of device denylist. Disabling the denylist allows binding to devices with known errata that may lead to exploitable stability or security issues when accessed by untrusted users.");
+static unsigned int tph_policy;
+static int tph_policy_set(const char *val, const struct kernel_param *kp)
+{
+ return param_set_uint_minmax(val, kp, VFIO_PCI_TPH_POLICY_NO_ST,
+ VFIO_PCI_TPH_POLICY_DS_ST);
+}
+static const struct kernel_param_ops tph_param_ops = {
+ .set = tph_policy_set,
+ .get = param_get_uint,
+};
+module_param_cb(tph_policy, &tph_param_ops, &tph_policy, 0644);
+MODULE_PARM_DESC(tph_policy,
+ "Global TPH policy level (0=default No-ST):\n"
+ "0 = No-ST mode: ST programming unavailable\n"
+ "1 = Add IV-ST mode: ST programming supports NONE/CPU sources\n"
+ "2 = Add DS-ST mode: RESOLVE returns ST for CPU sources;\n"
+ " ST programming supports NONE/CPU sources\n"
+ " Note: In this 'Add DS-ST mode', device-specific ST tables are\n"
+ " not preserved across PCI resets, userspace must re-establish\n"
+ " ST state after reset. The kernel cannot validate these ST\n"
+ " entries, so this mode is not recommended for general\n"
+ " virtualization usecases.");
+
static bool vfio_pci_dev_in_denylist(struct pci_dev *pdev)
{
switch (pdev->vendor) {
@@ -142,6 +165,7 @@ static int vfio_pci_init_dev(struct vfio_device *core_vdev)
#ifdef CONFIG_VFIO_PCI_VGA
vdev->disable_vga = disable_vga;
#endif
+ vdev->tph_policy = tph_policy;
return vfio_pci_core_init_dev(core_vdev);
}
diff --git a/drivers/vfio/pci/vfio_pci_config.c b/drivers/vfio/pci/vfio_pci_config.c
index 9914f3ac69aef9..8e47f84216b0dd 100644
--- a/drivers/vfio/pci/vfio_pci_config.c
+++ b/drivers/vfio/pci/vfio_pci_config.c
@@ -20,8 +20,10 @@
* must be negotiated with the underlying OS.
*/
+#include <linux/bitfield.h>
#include <linux/fs.h>
#include <linux/pci.h>
+#include <linux/pci-tph.h>
#include <linux/uaccess.h>
#include <linux/vfio.h>
#include <linux/slab.h>
@@ -1085,6 +1087,156 @@ static int __init init_pci_ext_cap_pwr_perm(struct perm_bits *perm)
return 0;
}
+static int vfio_find_cap_start(struct vfio_pci_core_device *vdev, int pos)
+{
+ u8 cap;
+ int base = (pos >= PCI_CFG_SPACE_SIZE) ? PCI_CFG_SPACE_SIZE :
+ PCI_STD_HEADER_SIZEOF;
+ cap = vdev->pci_config_map[pos];
+
+ if (cap == PCI_CAP_ID_BASIC)
+ return 0;
+
+ /* XXX Can we have to abutting capabilities of the same type? */
+ while (pos - 1 >= base && vdev->pci_config_map[pos - 1] == cap)
+ pos--;
+
+ return pos;
+}
+
+/* Permissions for TPH extended capability */
+static int __init init_pci_ext_cap_tph_perm(struct perm_bits *perm)
+{
+ /*
+ * We only virtualize the TPH header (excluding the ST table).
+ * For the ST table (if any), the read operation returns 0 by
+ * default, and the write operation is discarded by default.
+ */
+ if (alloc_perm_bits(perm, PCI_TPH_BASE_SIZEOF))
+ return -ENOMEM;
+
+ p_setd(perm, 0, ALL_VIRT, NO_WRITE);
+ p_setd(perm, PCI_TPH_CAP, ALL_VIRT, NO_WRITE);
+
+ p_setd(perm, PCI_TPH_CTRL, ALL_VIRT,
+ PCI_TPH_CTRL_MODE_SEL_MASK | PCI_TPH_CTRL_REQ_EN_MASK);
+
+ return 0;
+}
+
+static void vfio_tph_vcap_rewrite(struct vfio_pci_core_device *vdev, int pos)
+{
+ __le32 *vptr = (__le32 *)&vdev->vconfig[pos + PCI_TPH_CAP];
+ struct pci_dev *pdev = vdev->pdev;
+ u32 val = le32_to_cpu(*vptr);
+
+ if (!pcie_ext_tph_supported(pdev)) {
+ /* Remove extended TPH if root-port doesn't support */
+ val &= ~PCI_TPH_CAP_EXT_TPH;
+ }
+
+ if (vdev->tph_policy == VFIO_PCI_TPH_POLICY_NO_ST) {
+ /*
+ * NO-ST policy: mask IV/DS mode, ST location and ST size fields.
+ * Userspace only sees NO-ST capability.
+ */
+ val &= ~(PCI_TPH_CAP_ST_IV | PCI_TPH_CAP_ST_DS |
+ PCI_TPH_CAP_LOC_MASK | PCI_TPH_CAP_ST_MASK);
+ } else if (vdev->tph_policy == VFIO_PCI_TPH_POLICY_IV_ST) {
+ /*
+ * Add IV policy: mask DS mode, drop ST location and size
+ * if device does not support IV mode.
+ */
+ val &= ~PCI_TPH_CAP_ST_DS;
+ if (!(val & PCI_TPH_CAP_ST_IV))
+ val &= ~(PCI_TPH_CAP_LOC_MASK | PCI_TPH_CAP_ST_MASK);
+ }
+
+ *vptr = cpu_to_le32(val);
+
+ /* Cache the final virtualized TPH capability value */
+ vdev->tph_vcap = val;
+}
+
+static int vfio_tph_config_read(struct vfio_pci_core_device *vdev, int pos,
+ int count, struct perm_bits *perm,
+ int offset, __le32 *val)
+{
+ int ret;
+
+ if (offset >= PCI_TPH_BASE_SIZEOF) {
+ *val = cpu_to_le32(0);
+ return count;
+ }
+
+ if (offset < PCI_TPH_CTRL)
+ return vfio_default_config_read(vdev, pos, count, perm,
+ offset, val);
+
+ /* Read the actual device value for CTRL register. */
+ ret = vfio_user_config_read(vdev->pdev, pos, val, count);
+ return ret != 0 ? ret : count;
+}
+
+static int vfio_tph_config_write(struct vfio_pci_core_device *vdev, int pos,
+ int count, struct perm_bits *perm,
+ int offset, __le32 val)
+{
+ u16 start = vfio_find_cap_start(vdev, pos);
+ struct pci_dev *pdev = vdev->pdev;
+ u32 org_ctrl, new_ctrl, cap;
+ u8 mode, req, org_req;
+ __le32 ctrl_val = 0;
+ u16 cmd;
+ int ret;
+
+ if (!vdev->tph_opt_in || offset >= PCI_TPH_BASE_SIZEOF ||
+ offset < PCI_TPH_CTRL)
+ return count;
+
+ cmd = vfio_pci_memory_lock_and_enable(vdev);
+
+ /*
+ * Synchronize the CTRL value of the hardware to the virt. Otherwise,
+ * the value will be inconsistent when the device is reset.
+ */
+ 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_ctrl = le32_to_cpu(ctrl_val);
+
+ /* Do write operation to virt. */
+ ret = vfio_default_config_write(vdev, pos, count, perm, offset, val);
+ if (ret != count)
+ goto out;
+
+ /* Reads the TPH_CTRL value after the write operation. */
+ new_ctrl = le32_to_cpu(*(__le32 *)&vdev->vconfig[start + PCI_TPH_CTRL]);
+ if (new_ctrl == org_ctrl)
+ goto out; /* Exit because there is no change. */
+
+ 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_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. */
+
+ 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);
+
+out:
+ vfio_pci_memory_unlock_and_restore(vdev, cmd);
+ return count;
+}
+
/*
* Initialize the shared permission tables
*/
@@ -1100,6 +1252,7 @@ void vfio_pci_uninit_perm_bits(void)
free_perm_bits(&ecap_perms[PCI_EXT_CAP_ID_ERR]);
free_perm_bits(&ecap_perms[PCI_EXT_CAP_ID_PWR]);
+ free_perm_bits(&ecap_perms[PCI_EXT_CAP_ID_TPH]);
}
int __init vfio_pci_init_perm_bits(void)
@@ -1120,6 +1273,9 @@ int __init vfio_pci_init_perm_bits(void)
/* Extended capabilities */
ret |= init_pci_ext_cap_err_perm(&ecap_perms[PCI_EXT_CAP_ID_ERR]);
ret |= init_pci_ext_cap_pwr_perm(&ecap_perms[PCI_EXT_CAP_ID_PWR]);
+ ret |= init_pci_ext_cap_tph_perm(&ecap_perms[PCI_EXT_CAP_ID_TPH]);
+ ecap_perms[PCI_EXT_CAP_ID_TPH].readfn = vfio_tph_config_read;
+ ecap_perms[PCI_EXT_CAP_ID_TPH].writefn = vfio_tph_config_write;
ecap_perms[PCI_EXT_CAP_ID_VNDR].writefn = vfio_raw_config_write;
ecap_perms[PCI_EXT_CAP_ID_DVSEC].writefn = vfio_raw_config_write;
@@ -1129,23 +1285,6 @@ int __init vfio_pci_init_perm_bits(void)
return ret;
}
-static int vfio_find_cap_start(struct vfio_pci_core_device *vdev, int pos)
-{
- u8 cap;
- int base = (pos >= PCI_CFG_SPACE_SIZE) ? PCI_CFG_SPACE_SIZE :
- PCI_STD_HEADER_SIZEOF;
- cap = vdev->pci_config_map[pos];
-
- if (cap == PCI_CAP_ID_BASIC)
- return 0;
-
- /* XXX Can we have to abutting capabilities of the same type? */
- while (pos - 1 >= base && vdev->pci_config_map[pos - 1] == cap)
- pos--;
-
- return pos;
-}
-
static int vfio_msi_config_read(struct vfio_pci_core_device *vdev, int pos,
int count, struct perm_bits *perm,
int offset, __le32 *val)
@@ -1702,6 +1841,8 @@ static int vfio_ecap_init(struct vfio_pci_core_device *vdev)
ret = vfio_fill_vconfig_bytes(vdev, epos, len);
if (ret)
return ret;
+ if (ecap == PCI_EXT_CAP_ID_TPH)
+ vfio_tph_vcap_rewrite(vdev, epos);
/*
* If we're just using this capability to anchor the list,
diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c
index fcbb2da860e2ac..a9cdcb0f95a011 100644
--- a/drivers/vfio/pci/vfio_pci_core.c
+++ b/drivers/vfio/pci/vfio_pci_core.c
@@ -11,6 +11,7 @@
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/aperture.h>
+#include <linux/cpuhotplug.h>
#include <linux/debugfs.h>
#include <linux/device.h>
#include <linux/eventfd.h>
@@ -22,6 +23,7 @@
#include <linux/notifier.h>
#include <linux/pagemap.h>
#include <linux/pci.h>
+#include <linux/pci-tph.h>
#include <linux/pm_runtime.h>
#include <linux/slab.h>
#include <linux/types.h>
@@ -128,10 +130,20 @@ static int vfio_pci_core_debugfs_disable_idle_d3(struct seq_file *seq,
return 0;
}
+static int vfio_pci_core_debugfs_tph(struct seq_file *seq,
+ void *data)
+{
+ struct vfio_pci_core_device *vdev = vfio_pci_core_debugfs_private(seq);
+
+ seq_printf(seq, "policy=%u cap-virt=0x%x opt-in=%u\n",
+ vdev->tph_policy, vdev->tph_vcap, vdev->tph_opt_in);
+ return 0;
+}
+
/*
- * disable_idle_d3 and nointxmask are writable module parameters latched
- * per device at init, so a device's effective value can differ from the
- * current parameter setting. Expose the per-device (read-only) values
+ * disable_idle_d3, nointxmask and tph_policy are writable module parameters
+ * latched per device at init, so a device's effective value can differ from
+ * the current parameter setting. Expose the per-device (read-only) values
* here for visibility; read-only parameters can't drift and are omitted.
*/
static void vfio_pci_core_debugfs_init(struct vfio_pci_core_device *vdev)
@@ -147,6 +159,8 @@ static void vfio_pci_core_debugfs_init(struct vfio_pci_core_device *vdev)
vfio_pci_core_debugfs_nointxmask);
debugfs_create_devm_seqfile(dev, "disable_idle_d3", pci_dir,
vfio_pci_core_debugfs_disable_idle_d3);
+ debugfs_create_devm_seqfile(dev, "tph", pci_dir,
+ vfio_pci_core_debugfs_tph);
}
#else
static inline void vfio_pci_core_debugfs_init(struct vfio_pci_core_device *vdev)
@@ -575,6 +589,9 @@ static void vfio_pci_core_map_bars(struct vfio_pci_core_device *vdev)
}
}
+static int vfio_pci_tph_dev_init(struct vfio_pci_core_device *vdev);
+static void vfio_pci_tph_dev_deinit(struct vfio_pci_core_device *vdev);
+
int vfio_pci_core_enable(struct vfio_pci_core_device *vdev)
{
struct pci_dev *pdev = vdev->pdev;
@@ -601,6 +618,8 @@ int vfio_pci_core_enable(struct vfio_pci_core_device *vdev)
goto out_disable_device;
vdev->reset_works = !ret;
+ /* Reset TPH state for new user session */
+ pcie_disable_tph(vdev->pdev);
pci_save_state(pdev);
vdev->pci_saved_state = pci_store_saved_state(pdev);
if (!vdev->pci_saved_state)
@@ -629,6 +648,11 @@ int vfio_pci_core_enable(struct vfio_pci_core_device *vdev)
if (ret)
goto out_free_zdev;
+ /* After identifying the capability, initialize TPH. */
+ ret = vfio_pci_tph_dev_init(vdev);
+ if (ret != 0)
+ goto out_free_config;
+
msix_pos = pdev->msix_cap;
if (msix_pos) {
u16 flags;
@@ -653,6 +677,8 @@ int vfio_pci_core_enable(struct vfio_pci_core_device *vdev)
return 0;
+out_free_config:
+ vfio_config_free(vdev);
out_free_zdev:
vfio_pci_zdev_close_device(vdev);
out_free_state:
@@ -726,6 +752,8 @@ void vfio_pci_core_disable(struct vfio_pci_core_device *vdev)
kfree(vdev->region);
vdev->region = NULL; /* don't krealloc a freed pointer */
+ vfio_pci_tph_dev_deinit(vdev);
+
vfio_config_free(vdev);
for (i = 0; i < PCI_STD_NUM_BARS; i++) {
@@ -748,6 +776,9 @@ void vfio_pci_core_disable(struct vfio_pci_core_device *vdev)
vfio_pci_zdev_close_device(vdev);
+ /* Reset TPH state on user session exit */
+ pcie_disable_tph(vdev->pdev);
+
/*
* If we have saved state, restore it. If we can reset the device,
* even better. Resetting with current state seems better than
@@ -1594,6 +1625,348 @@ static int vfio_pci_core_feature_token(struct vfio_pci_core_device *vdev,
return 0;
}
+static enum cpuhp_state vfio_tph_cpuhp_state;
+static u32 vfio_pci_tph_get_st_table_size(struct vfio_pci_core_device *vdev);
+
+static int vfio_pci_tph_cpuhp_offline(unsigned int cpu, struct hlist_node *node)
+{
+ struct vfio_pci_core_device *vdev =
+ hlist_entry(node, struct vfio_pci_core_device, tph_cpuhp_node);
+ u32 st_size = vfio_pci_tph_get_st_table_size(vdev);
+ int i;
+
+ if (vdev->tph_st_cpu == NULL)
+ return 0;
+
+ mutex_lock(&vdev->tph_lock);
+ for (i = 0; i < st_size; i++) {
+ if (vdev->tph_st_cpu[i] != (s64)cpu)
+ continue;
+ pcie_tph_set_st_entry(vdev->pdev, i, 0);
+ vdev->tph_st_cpu[i] = -1;
+ }
+ mutex_unlock(&vdev->tph_lock);
+
+ return 0;
+}
+
+static int vfio_pci_tph_cpuhp_init(void)
+{
+ int ret;
+
+ ret = cpuhp_setup_state_multi(CPUHP_AP_ONLINE_DYN,
+ "vfio/pci/tph:online",
+ NULL,
+ vfio_pci_tph_cpuhp_offline);
+ if (ret < 0)
+ return ret;
+
+ vfio_tph_cpuhp_state = ret;
+ return 0;
+}
+
+static void vfio_pci_tph_cpuhp_deinit(void)
+{
+ cpuhp_remove_multi_state(vfio_tph_cpuhp_state);
+}
+
+static bool vfio_pci_tph_has_architected_st(struct vfio_pci_core_device *vdev)
+{
+ u32 loc = vdev->tph_vcap & PCI_TPH_CAP_LOC_MASK;
+
+ return (loc == PCI_TPH_LOC_CAP || loc == PCI_TPH_LOC_MSIX) &&
+ (vfio_pci_tph_get_st_table_size(vdev) > 0);
+}
+
+static int vfio_pci_tph_dev_init(struct vfio_pci_core_device *vdev)
+{
+ bool has_arch_st;
+ u32 st_size;
+ int i, ret;
+
+ vdev->tph_opt_in = 0;
+ vdev->tph_st_cpu = NULL;
+
+ has_arch_st = vfio_pci_tph_has_architected_st(vdev);
+ if (!has_arch_st)
+ return 0;
+
+ ret = cpuhp_state_add_instance_nocalls(vfio_tph_cpuhp_state,
+ &vdev->tph_cpuhp_node);
+ if (ret != 0)
+ return ret;
+
+ st_size = vfio_pci_tph_get_st_table_size(vdev);
+ vdev->tph_st_cpu = kcalloc(st_size, sizeof(*vdev->tph_st_cpu),
+ GFP_KERNEL);
+ if (vdev->tph_st_cpu == NULL) {
+ cpuhp_state_remove_instance_nocalls(vfio_tph_cpuhp_state,
+ &vdev->tph_cpuhp_node);
+ return -ENOMEM;
+ }
+ for (i = 0; i < st_size; i++)
+ vdev->tph_st_cpu[i] = -1;
+
+ return 0;
+}
+
+static void vfio_pci_tph_dev_deinit(struct vfio_pci_core_device *vdev)
+{
+ bool has_arch_st;
+
+ has_arch_st = vfio_pci_tph_has_architected_st(vdev);
+ if (!has_arch_st)
+ return;
+
+ kfree(vdev->tph_st_cpu);
+ vdev->tph_st_cpu = NULL;
+ cpuhp_state_remove_instance_nocalls(vfio_tph_cpuhp_state,
+ &vdev->tph_cpuhp_node);
+}
+
+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)
+ cap |= 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;
+}
+
+static int vfio_pci_core_feature_tph(struct vfio_pci_core_device *vdev,
+ u32 flags,
+ struct vfio_device_feature_tph __user *arg,
+ size_t argsz)
+{
+ struct vfio_device_feature_tph tph;
+ int ret;
+
+ if (!pcie_std_tph_supported(vdev->pdev))
+ return -EOPNOTSUPP;
+
+ ret = vfio_check_feature(flags, argsz,
+ VFIO_DEVICE_FEATURE_GET | VFIO_DEVICE_FEATURE_SET,
+ sizeof(tph));
+ if (ret != 1)
+ return ret;
+
+ if (copy_from_user(&tph, arg, sizeof(tph)))
+ return -EFAULT;
+
+ if (flags & VFIO_DEVICE_FEATURE_SET) {
+ if (tph.flags != 0)
+ return -EINVAL;
+ vdev->tph_opt_in = 1;
+ return 0;
+ }
+
+ if (!vdev->tph_opt_in)
+ return -EINVAL;
+
+ tph.flags = vfio_pci_tph_get_capability(vdev);
+
+ return copy_to_user(arg, &tph, sizeof(tph)) ? -EFAULT : 0;
+}
+
+static u32 vfio_pci_tph_get_src_mask(struct vfio_pci_core_device *vdev)
+{
+ 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;
+}
+
+static u32 vfio_pci_tph_get_st_table_size(struct vfio_pci_core_device *vdev)
+{
+ struct pci_dev *pdev = vdev->pdev;
+ u32 loc = pcie_tph_get_st_table_loc(pdev);
+ int ret;
+
+ if (loc == PCI_TPH_LOC_CAP) {
+ return pcie_tph_get_st_table_size(pdev);
+ } else if (loc == PCI_TPH_LOC_MSIX) {
+ ret = pci_msix_vec_count(pdev);
+ if (ret < 0)
+ return 0;
+ return ret;
+ } else {
+ return 0;
+ }
+}
+
+static int vfio_pci_tph_resolve_st_tag(struct pci_dev *pdev, u32 src_bits,
+ u32 src_handle, bool extended, u16 *st)
+{
+ u8 req_type = extended ? PCI_TPH_REQ_EXT_TPH : PCI_TPH_REQ_TPH_ONLY;
+ int ret = 0;
+
+ if (src_bits & VFIO_DEVICE_TPH_SRC_NONE)
+ *st = 0;
+ else if (src_bits & VFIO_DEVICE_TPH_SRC_CPU_VOLATILE)
+ ret = pcie_tph_get_cpu_st_ext(pdev, TPH_MEM_TYPE_VM,
+ req_type, src_handle, st);
+ else if (src_bits & VFIO_DEVICE_TPH_SRC_CPU_PERSISTENT)
+ ret = pcie_tph_get_cpu_st_ext(pdev, TPH_MEM_TYPE_PM,
+ req_type, src_handle, st);
+ else
+ ret = -EINVAL;
+
+ if (ret != 0)
+ *st = 0;
+
+ return ret;
+}
+
+static int vfio_pci_core_feature_tph_program(struct vfio_pci_core_device *vdev,
+ u32 flags,
+ struct vfio_device_feature_tph_program __user *arg,
+ size_t argsz)
+{
+ struct vfio_device_feature_tph_program program;
+ u32 user_flags, src_mask, st_size;
+ struct pci_dev *pdev = vdev->pdev;
+ bool extended, stop_on_zero;
+ u32 *src_handle = NULL;
+ int ret, i, k, written;
+ u16 *tags = NULL;
+ u16 cmd;
+
+ if (!vdev->tph_opt_in ||
+ !vfio_pci_tph_has_architected_st(vdev))
+ return -EOPNOTSUPP;
+
+ ret = vfio_check_feature(flags, argsz, VFIO_DEVICE_FEATURE_SET,
+ sizeof(program));
+ if (ret != 1)
+ return ret;
+
+ if (copy_from_user(&program, arg, sizeof(program)))
+ return -EFAULT;
+
+ user_flags = program.flags;
+ extended = !!(user_flags & VFIO_DEVICE_TPH_EXTENDED);
+ if (extended && !pcie_ext_tph_supported(vdev->pdev))
+ return -EOPNOTSUPP;
+ user_flags &= ~VFIO_DEVICE_TPH_EXTENDED;
+
+ stop_on_zero = !!(user_flags & VFIO_DEVICE_TPH_REQUIRE_ST);
+ if (stop_on_zero && (user_flags & VFIO_DEVICE_TPH_SRC_NONE))
+ return -EINVAL;
+ user_flags &= ~VFIO_DEVICE_TPH_REQUIRE_ST;
+
+ src_mask = vfio_pci_tph_get_src_mask(vdev);
+ if (user_flags & ~src_mask || !is_power_of_2(user_flags))
+ return -EINVAL;
+
+ st_size = vfio_pci_tph_get_st_table_size(vdev);
+ if (program.start >= st_size || program.count == 0 ||
+ program.count > st_size - program.start)
+ return -EINVAL;
+
+ if (!(user_flags & VFIO_DEVICE_TPH_SRC_NONE)) {
+ src_handle = memdup_array_user(u64_to_user_ptr(program.srcs),
+ program.count, sizeof(u32));
+ if (IS_ERR(src_handle))
+ return PTR_ERR(src_handle);
+ }
+ tags = kcalloc(program.count, sizeof(u16), GFP_KERNEL_ACCOUNT);
+ if (!tags) {
+ ret = -ENOMEM;
+ goto out;
+ }
+
+ cpus_read_lock();
+
+ for (i = 0; i < program.count; i++) {
+ ret = vfio_pci_tph_resolve_st_tag(pdev, user_flags,
+ src_handle ? src_handle[i] : 0,
+ extended, &tags[i]);
+ if (ret || (stop_on_zero && tags[i] == 0))
+ break;
+ }
+
+ if (i > 0) {
+ mutex_lock(&vdev->tph_lock);
+
+ cmd = vfio_pci_memory_lock_and_enable(vdev);
+ ret = written = pcie_tph_set_st_entries(pdev, program.start, i,
+ tags);
+ vfio_pci_memory_unlock_and_restore(vdev, cmd);
+
+ if (written > 0) {
+ for (k = 0; k < written; k++)
+ vdev->tph_st_cpu[program.start + k] =
+ (tags[k] == 0) ? -1 : src_handle[k];
+ }
+
+ mutex_unlock(&vdev->tph_lock);
+ }
+
+ cpus_read_unlock();
+
+out:
+ kfree(tags);
+ kfree(src_handle);
+ 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;
+
+ ret = vfio_pci_tph_resolve_st_tag(vdev->pdev, user_flags, resolve.src,
+ extended, &tag);
+ if (ret != 0)
+ return ret;
+
+ resolve.valid = VFIO_DEVICE_TPH_VALID_ST;
+ resolve.rsv = 0;
+ resolve.st = tag;
+
+ 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)
{
@@ -1614,6 +1987,14 @@ 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_ZPCI_ERROR:
return vfio_pci_zdev_feature_err(device, flags, arg, argsz);
+ case VFIO_DEVICE_FEATURE_TPH:
+ return vfio_pci_core_feature_tph(vdev, flags, arg, argsz);
+ case VFIO_DEVICE_FEATURE_TPH_PROGRAM:
+ return vfio_pci_core_feature_tph_program(vdev, flags,
+ arg, argsz);
+ case VFIO_DEVICE_FEATURE_TPH_RESOLVE:
+ return vfio_pci_core_feature_tph_resolve(vdev, flags,
+ arg, argsz);
default:
return -ENOTTY;
}
@@ -2176,6 +2557,7 @@ int vfio_pci_core_init_dev(struct vfio_device *core_vdev)
mutex_init(&vdev->igate);
spin_lock_init(&vdev->irqlock);
mutex_init(&vdev->ioeventfds_lock);
+ mutex_init(&vdev->tph_lock);
INIT_LIST_HEAD(&vdev->dummy_resources_list);
INIT_LIST_HEAD(&vdev->ioeventfds_list);
INIT_LIST_HEAD(&vdev->sriov_pfs_item);
@@ -2196,6 +2578,7 @@ void vfio_pci_core_release_dev(struct vfio_device *core_vdev)
container_of(core_vdev, struct vfio_pci_core_device, vdev);
mutex_destroy(&vdev->igate);
+ mutex_destroy(&vdev->tph_lock);
mutex_destroy(&vdev->ioeventfds_lock);
kfree(vdev->region);
kfree(vdev->pm_save);
@@ -2651,12 +3034,23 @@ static void vfio_pci_core_cleanup(void)
{
vfio_pci_uninit_perm_bits();
rcu_barrier();
+ vfio_pci_tph_cpuhp_deinit();
}
static int __init vfio_pci_core_init(void)
{
+ int ret;
+
+ ret = vfio_pci_tph_cpuhp_init();
+ if (ret != 0)
+ return ret;
+
/* Allocate shared config space permission data used by all devices */
- return vfio_pci_init_perm_bits();
+ ret = vfio_pci_init_perm_bits();
+ if (ret != 0)
+ vfio_pci_tph_cpuhp_deinit();
+
+ return ret;
}
module_init(vfio_pci_core_init);
diff --git a/drivers/vfio/pci/vfio_pci_priv.h b/drivers/vfio/pci/vfio_pci_priv.h
index 4e7162234a2eba..967f706f509ef7 100644
--- a/drivers/vfio/pci/vfio_pci_priv.h
+++ b/drivers/vfio/pci/vfio_pci_priv.h
@@ -11,6 +11,12 @@
/* Cap maximum number of ioeventfds per device (arbitrary) */
#define VFIO_PCI_IOEVENTFD_MAX 1000
+enum vfio_pci_tph_policy {
+ VFIO_PCI_TPH_POLICY_NO_ST = 0,
+ VFIO_PCI_TPH_POLICY_IV_ST,
+ VFIO_PCI_TPH_POLICY_DS_ST,
+};
+
struct vfio_pci_ioeventfd {
struct list_head next;
struct vfio_pci_core_device *vdev;
diff --git a/include/linux/pci-tph.h b/include/linux/pci-tph.h
index be68cd17f2f833..c19dbbb876200d 100644
--- a/include/linux/pci-tph.h
+++ b/include/linux/pci-tph.h
@@ -9,6 +9,8 @@
#ifndef LINUX_PCI_TPH_H
#define LINUX_PCI_TPH_H
+#include <linux/pci.h>
+
/*
* According to the ECN for PCI Firmware Spec, Steering Tag can be different
* depending on the memory type: Volatile Memory or Persistent Memory. When a
@@ -21,26 +23,63 @@ enum tph_mem_type {
};
#ifdef CONFIG_PCIE_TPH
+/**
+ * pcie_std_tph_supported - check standard TPH requester support
+ * @pdev: PCI device
+ */
+#define pcie_std_tph_supported(pdev) \
+ ((pdev)->tph_max_type >= PCI_TPH_REQ_TPH_ONLY)
+/**
+ * pcie_ext_tph_supported - check extended TPH requester support
+ * @pdev: PCI device
+ */
+#define pcie_ext_tph_supported(pdev) \
+ ((pdev)->tph_max_type == PCI_TPH_REQ_EXT_TPH)
int pcie_tph_set_st_entry(struct pci_dev *pdev,
unsigned int index, u16 tag);
-int pcie_tph_get_cpu_st(struct pci_dev *dev,
- enum tph_mem_type mem_type,
+int pcie_tph_set_st_entries(struct pci_dev *pdev, unsigned int start,
+ unsigned int count, const u16 *tags);
+int pcie_tph_get_cpu_st_ext(struct pci_dev *dev, enum tph_mem_type mem_type,
+ u8 req_type, unsigned int cpu, u16 *tag);
+int pcie_tph_get_cpu_st(struct pci_dev *dev, enum tph_mem_type mem_type,
unsigned int cpu, u16 *tag);
void pcie_disable_tph(struct pci_dev *pdev);
-int pcie_enable_tph(struct pci_dev *pdev, int mode);
+int pcie_enable_tph_ext(struct pci_dev *pdev, u8 mode, u8 req_type);
+int pcie_enable_tph(struct pci_dev *pdev, u8 mode);
u16 pcie_tph_get_st_table_size(struct pci_dev *pdev);
u32 pcie_tph_get_st_table_loc(struct pci_dev *pdev);
+bool pcie_tph_dsm_supported(struct pci_dev *pdev);
#else
+#define pcie_std_tph_supported(pdev) false
+#define pcie_ext_tph_supported(pdev) false
static inline int pcie_tph_set_st_entry(struct pci_dev *pdev,
unsigned int index, u16 tag)
{ return -EINVAL; }
+static inline int pcie_tph_set_st_entries(struct pci_dev *pdev,
+ unsigned int start,
+ unsigned int count, const u16 *tags)
+{ return -EINVAL; }
+static inline int pcie_tph_get_cpu_st_ext(struct pci_dev *dev,
+ enum tph_mem_type mem_type,
+ u8 req_type, unsigned int cpu,
+ u16 *tag)
+{ return -EINVAL; }
static inline int pcie_tph_get_cpu_st(struct pci_dev *dev,
enum tph_mem_type mem_type,
unsigned int cpu, u16 *tag)
{ return -EINVAL; }
static inline void pcie_disable_tph(struct pci_dev *pdev) { }
-static inline int pcie_enable_tph(struct pci_dev *pdev, int mode)
+static inline int pcie_enable_tph_ext(struct pci_dev *pdev, u8 mode,
+ u8 req_type)
+{ return -EINVAL; }
+static inline int pcie_enable_tph(struct pci_dev *pdev, u8 mode)
{ return -EINVAL; }
+static inline u16 pcie_tph_get_st_table_size(struct pci_dev *pdev)
+{ return 0; }
+static inline u32 pcie_tph_get_st_table_loc(struct pci_dev *pdev)
+{ return PCI_TPH_LOC_NONE; }
+static inline bool pcie_tph_dsm_supported(struct pci_dev *pdev)
+{ return false; }
#endif
#endif /* LINUX_PCI_TPH_H */
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 6482549a841797..1dc3cb011dff63 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -478,7 +478,6 @@ struct pci_dev {
unsigned int ats_enabled:1; /* Address Translation Svc */
unsigned int pasid_enabled:1; /* Process Address Space ID */
unsigned int pri_enabled:1; /* Page Request Interface */
- unsigned int tph_enabled:1; /* TLP Processing Hints */
unsigned int fm_enabled:1; /* Flit Mode (segment captured) */
unsigned int is_managed:1; /* Managed via devres */
unsigned int is_msi_managed:1; /* MSI release via devres installed */
@@ -596,7 +595,10 @@ struct pci_dev {
struct gpio_desc *wake; /* WAKE# GPIO */
#ifdef CONFIG_PCIE_TPH
- u16 tph_cap; /* TPH capability offset */
+ u16 tph_cap:13; /* TPH capability offset */
+ u16 tph_max_type:2; /* Negotiated max TPH requester type
+ between device and root port */
+ u16 tph_enabled:1; /* Whether TPH is enabled */
u8 tph_mode; /* TPH mode */
u8 tph_req_type; /* TPH requester type */
#endif
diff --git a/include/linux/vfio_pci_core.h b/include/linux/vfio_pci_core.h
index 2f3fa2787737a4..217f95aaa9db9b 100644
--- a/include/linux/vfio_pci_core.h
+++ b/include/linux/vfio_pci_core.h
@@ -151,6 +151,12 @@ struct vfio_pci_core_device {
struct notifier_block nb;
struct rw_semaphore memory_lock;
struct list_head dmabufs;
+ u8 tph_policy;
+ u8 tph_opt_in;
+ u32 tph_vcap;
+ s64 *tph_st_cpu;
+ struct hlist_node tph_cpuhp_node;
+ struct mutex tph_lock;
};
enum vfio_pci_io_width {
diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h
index e41437fa17ad0e..1820bb20a460a5 100644
--- a/include/uapi/linux/vfio.h
+++ b/include/uapi/linux/vfio.h
@@ -1555,6 +1555,135 @@ struct vfio_device_feature_zpci_err {
#define VFIO_DEVICE_FEATURE_ZPCI_ERROR 13
+/*
+ * VFIO_DEVICE_FEATURE_TPH - Control and query VFIO TPH feature capabilities
+ *
+ * SET: Opt-in to enable the VFIO TPH feature for the device; flags must be
+ * zero.
+ * GET: Return VFIO-usable TPH capability bits in flags (see
+ * VFIO_DEVICE_TPH_CAP_*). Returns an error if SET opt-in has not been
+ * performed.
+ *
+ * Typical userspace sequence:
+ * 1. Read virtualized PCI TPH capability via VFIO config space access to
+ * discover underlying hardware PCI TPH support.
+ * 2. Invoke SET to opt-in for VFIO TPH feature permission.
+ * 3. Invoke GET to retrieve the set of TPH capabilities accessible via VFIO.
+ * 4. Write the TPH control register through VFIO config space to activate
+ * device TPH hardware.
+ * 5. Program steering tag (ST) table entries by VFIO_DEVICE_FEATURE_TPH_PROGRAM
+ * if the device has an 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.
+ */
+#define VFIO_DEVICE_FEATURE_TPH 14
+
+struct vfio_device_feature_tph {
+ __u32 flags;
+};
+
+/*
+ * Capability bits returned by VFIO_DEVICE_FEATURE_TPH GET
+ */
+
+/*
+ * Supports programming steering tag (ST) entries using the NONE source.
+ * This source resolves to a zero ST value.
+ */
+#define VFIO_DEVICE_TPH_CAP_PROG_ST_NONE (1u << 0)
+/*
+ * Supports programming steering tag (ST) entries using a CPU source handle,
+ * for either volatile or persistent memory type.
+ */
+#define VFIO_DEVICE_TPH_CAP_PROG_ST_CPU (1u << 1)
+/*
+ * Supports resolving a steering tag (ST) from a CPU source handle.
+ */
+#define VFIO_DEVICE_TPH_CAP_RESOLVE_CPU_ST (1u << 2)
+
+/*
+ * VFIO_DEVICE_FEATURE_TPH_PROGRAM - Batch program architected steering tag
+ * (ST) table entries. This interface only operates on the architected ST
+ * table described by the PCIe TPH ST Table Location field; it does not
+ * manage device-specific (DS) ST storage or any vendor-private ST array.
+ *
+ * SET only
+ *
+ * Prerequisites before invoking this feature:
+ * 1. Call VFIO_DEVICE_FEATURE_TPH with SET to enable vfio TPH permission;
+ * 2. Write the TPH control register to activate device hardware TPH logic.
+ *
+ * @flags: IN - source type selector (see VFIO_DEVICE_TPH_SRC_*) and
+ * steering tag namespace selector (see VFIO_DEVICE_TPH_EXTENDED) and
+ * failure policy (see VFIO_DEVICE_TPH_REQUIRE_ST)
+ * Note: only one source type is permitted; combining source type bits
+ * is rejected.
+ * @start: IN - first architected ST table index
+ * @count: IN - number of contiguous entries to program
+ * @srcs: IN - user pointer to array of source u32 handles (CPU ID for CPU
+ * sources, ignored for SRC_NONE)
+ *
+ * Return value: >=0 = number of entries successfully programmed;
+ * <0 = negative errno
+ *
+ * CPU offline note: When a CPU goes offline, the kernel automatically clears
+ * all ST table entries mapped to that CPU, setting those ST values to zero.
+ */
+#define VFIO_DEVICE_FEATURE_TPH_PROGRAM 15
+
+struct vfio_device_feature_tph_program {
+ __u32 flags;
+ __u16 start;
+ __u16 count;
+ __aligned_u64 srcs;
+};
+
+/* Use extended 16-bit steering tag namespace */
+#define VFIO_DEVICE_TPH_EXTENDED (1u << 0)
+/*
+ * Stop the batch when an entry resolves to a zero steering tag.
+ * Programming halts at that entry; the returned count
+ * is the number of entries successfully programmed before the stop.
+ */
+#define VFIO_DEVICE_TPH_REQUIRE_ST (1u << 1)
+/* Source resolves to a zero steering tag (ST) */
+#define VFIO_DEVICE_TPH_SRC_NONE (1u << 2)
+/* Source holds a volatile memory CPU ID */
+#define VFIO_DEVICE_TPH_SRC_CPU_VOLATILE (1u << 3)
+/* Source holds a persistent memory CPU ID */
+#define VFIO_DEVICE_TPH_SRC_CPU_PERSISTENT (1u << 4)
+
+/*
+ * VFIO_DEVICE_FEATURE_TPH_RESOLVE - Resolve TPH attributes from given source
+ *
+ * GET only
+ *
+ * Requires prior successful SET on VFIO_DEVICE_FEATURE_TPH, otherwise
+ * this feature will return error.
+ *
+ * @flags: IN - source type selector (see VFIO_DEVICE_TPH_SRC_*)
+ * and steering tag namespace selector (see VFIO_DEVICE_TPH_EXTENDED)
+ * Note: only one source type is permitted (except SRC_NONE);
+ * combining source type bits is rejected.
+ * @src: IN - source identifier, e.g. CPU ID when SRC_CPU_VOLATILE is set
+ * in flags
+ * @valid: OUT - bitmap indicating valid output fields, see
+ * VFIO_DEVICE_TPH_VALID_*
+ * @rsv: OUT - Reserved for future extension, kernel returns zero
+ * @st: OUT - TPH steering tag (valid when VALID_ST is set in valid)
+ */
+#define VFIO_DEVICE_FEATURE_TPH_RESOLVE 16
+
+struct vfio_device_feature_tph_resolve {
+ __u32 flags;
+ __u32 src;
+ __u8 valid;
+#define VFIO_DEVICE_TPH_VALID_ST (1u << 0) /* st holds valid steering tag */
+ __u8 rsv;
+ __u16 st;
+};
+
/* -------- API for Type1 VFIO IOMMU -------- */
/**
|
| 67/3 | 2026/11/22 09:45 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 21837 output: 37 thoughts: 2089 Thoughts: **Analyzing the VFIO PCI TPH Patch for KMSAN Needs**
Okay, let's break this down systematically. My primary concern here is identifying potential uninitialized memory reads that could lead to information leaks, which is precisely what KMSAN is designed to detect. I need to carefully scrutinize any data structures that are either copied from user space *or* copied to user space, paying close attention to initialization and potential padding within those structures.
First, I examined the `vfio_pci_core_feature_tph` function. It involves a `vfio_device_feature_tph` structure:
struct vfio_device_feature_tph {
__u32 flags;
};
This looks straightforward. It's just a single 32-bit field. The code initializes `tph.flags` with a value. The data is transferred via `copy_to_user`, after it has been initialized. There's no padding, no complex initialization logic. Based on my expert knowledge, this doesn't seem to present a KMSAN risk.
Next, I delved into `vfio_pci_core_feature_tph_resolve`. This one has a more complex structure, `vfio_device_feature_tph_resolve`:
struct vfio_device_feature_tph_resolve {
__u32 flags;
__u32 src;
__u8 valid;
__u8 rsv;
__u16 st;
};
I checked the struct's size. It's 4 (flags) + 4 (src) + 1 (valid) + 1 (rsv) + 2 (st) = 12 bytes. Since this struct has `__u32` which has an alignment of 4, the struct is also aligned to 4 bytes. Total size of 12 bytes is divisible by 4. Thus the structure has no padding and it is efficiently packed.
In the function, the struct members `flags` and `src` come from user space via `copy_from_user`. The other fields (`valid`, `rsv`, `st`) are *explicitly* initialized within the function before the `copy_to_user`. Thus no uninitialized bytes are copied to user space. There are no uninitialized reads. It's safe.
Finally, I considered `vfio_tph_config_read`. This involves reading config space, which is potentially interesting. It uses `vfio_user_config_read`, which I'd need to look into more to be sure. But given my understanding of the VFIO PCI model, this involves reading data from PCI config space. This data is typically initialized by the hardware or driver. To be certain about this I would have to look into `vfio_user_config_read`. For now, I'm going to set it aside.
**Conclusion:** Based on this initial analysis of `vfio_pci_core_feature_tph` and `vfio_pci_core_feature_tph_resolve`, I'm not seeing any immediate KMSAN concerns. My initial thought is *no*, I do *not* need to set `NeedsKMSAN=true` for these parts of the patch. The structures that are copied to user space are either fully initialized or are directly populated from user-provided data. I'd still like to check how `vfio_user_config_read` is implemented. I need to be absolutely certain before signing off on this.
|
| 68/3 | 2026/11/22 09:46 | tool | grepper |
0mArgs:{
"Expression": "vfio_.*_config_read",
"PathPrefixes": [
"drivers/vfio/pci/"
]
}Results: {
"Output": "drivers/vfio/pci/vfio_pci_config.c=111=struct perm_bits {\n--\ndrivers/vfio/pci/vfio_pci_config.c-124-\ndrivers/vfio/pci/vfio_pci_config.c:125:static int vfio_user_config_read(struct pci_dev *pdev, int offset,\ndrivers/vfio/pci/vfio_pci_config.c-126-\t\t\t\t __le32 *val, int count)\n--\ndrivers/vfio/pci/vfio_pci_config.c=156=static int vfio_user_config_write(struct pci_dev *pdev, int offset,\n--\ndrivers/vfio/pci/vfio_pci_config.c-176-\ndrivers/vfio/pci/vfio_pci_config.c:177:static int vfio_default_config_read(struct vfio_pci_core_device *vdev, int pos,\ndrivers/vfio/pci/vfio_pci_config.c-178-\t\t\t\t int count, struct perm_bits *perm,\n--\ndrivers/vfio/pci/vfio_pci_config.c-192-\ndrivers/vfio/pci/vfio_pci_config.c:193:\t\tret = vfio_user_config_read(pdev, pos, \u0026phys_val, count);\ndrivers/vfio/pci/vfio_pci_config.c-194-\t\tif (ret)\n--\ndrivers/vfio/pci/vfio_pci_config.c=203=static int vfio_default_config_write(struct vfio_pci_core_device *vdev, int pos,\n--\ndrivers/vfio/pci/vfio_pci_config.c-233-\ndrivers/vfio/pci/vfio_pci_config.c:234:\t\tret = vfio_user_config_read(pdev, pos, \u0026phys_val, count);\ndrivers/vfio/pci/vfio_pci_config.c-235-\t\tif (ret)\n--\ndrivers/vfio/pci/vfio_pci_config.c-249-/* Allow direct read from hardware, except for capability next pointer */\ndrivers/vfio/pci/vfio_pci_config.c:250:static int vfio_direct_config_read(struct vfio_pci_core_device *vdev, int pos,\ndrivers/vfio/pci/vfio_pci_config.c-251-\t\t\t\t int count, struct perm_bits *perm,\n--\ndrivers/vfio/pci/vfio_pci_config.c-255-\ndrivers/vfio/pci/vfio_pci_config.c:256:\tret = vfio_user_config_read(vdev-\u003epdev, pos, val, count);\ndrivers/vfio/pci/vfio_pci_config.c-257-\tif (ret)\n--\ndrivers/vfio/pci/vfio_pci_config.c=275=static int vfio_raw_config_write(struct vfio_pci_core_device *vdev, int pos,\n--\ndrivers/vfio/pci/vfio_pci_config.c-287-\ndrivers/vfio/pci/vfio_pci_config.c:288:static int vfio_raw_config_read(struct vfio_pci_core_device *vdev, int pos,\ndrivers/vfio/pci/vfio_pci_config.c-289-\t\t\t\tint count, struct perm_bits *perm,\n--\ndrivers/vfio/pci/vfio_pci_config.c-293-\ndrivers/vfio/pci/vfio_pci_config.c:294:\tret = vfio_user_config_read(vdev-\u003epdev, pos, val, count);\ndrivers/vfio/pci/vfio_pci_config.c-295-\tif (ret)\n--\ndrivers/vfio/pci/vfio_pci_config.c=302=static int vfio_virt_config_write(struct vfio_pci_core_device *vdev, int pos,\n--\ndrivers/vfio/pci/vfio_pci_config.c-309-\ndrivers/vfio/pci/vfio_pci_config.c:310:static int vfio_virt_config_read(struct vfio_pci_core_device *vdev, int pos,\ndrivers/vfio/pci/vfio_pci_config.c-311-\t\t\t\t int count, struct perm_bits *perm,\n--\ndrivers/vfio/pci/vfio_pci_config.c=318=static struct perm_bits direct_ro_perms = {\ndrivers/vfio/pci/vfio_pci_config.c:319:\t.readfn = vfio_direct_config_read,\ndrivers/vfio/pci/vfio_pci_config.c-320-};\n--\ndrivers/vfio/pci/vfio_pci_config.c=323=static struct perm_bits cap_perms[PCI_CAP_ID_MAX + 1] = {\ndrivers/vfio/pci/vfio_pci_config.c:324:\t[0 ... PCI_CAP_ID_MAX] = { .readfn = vfio_direct_config_read }\ndrivers/vfio/pci/vfio_pci_config.c-325-};\ndrivers/vfio/pci/vfio_pci_config.c=326=static struct perm_bits ecap_perms[PCI_EXT_CAP_ID_MAX + 1] = {\ndrivers/vfio/pci/vfio_pci_config.c:327:\t[0 ... PCI_EXT_CAP_ID_MAX] = { .readfn = vfio_direct_config_read }\ndrivers/vfio/pci/vfio_pci_config.c-328-};\n--\ndrivers/vfio/pci/vfio_pci_config.c=335=static struct perm_bits unassigned_perms = {\ndrivers/vfio/pci/vfio_pci_config.c:336:\t.readfn = vfio_raw_config_read,\ndrivers/vfio/pci/vfio_pci_config.c-337-\t.writefn = vfio_raw_config_write\n--\ndrivers/vfio/pci/vfio_pci_config.c=340=static struct perm_bits virt_perms = {\ndrivers/vfio/pci/vfio_pci_config.c:341:\t.readfn = vfio_virt_config_read,\ndrivers/vfio/pci/vfio_pci_config.c-342-\t.writefn = vfio_virt_config_write\n--\ndrivers/vfio/pci/vfio_pci_config.c=353=static int alloc_perm_bits(struct perm_bits *perm, int size)\n--\ndrivers/vfio/pci/vfio_pci_config.c-375-\ndrivers/vfio/pci/vfio_pci_config.c:376:\tperm-\u003ereadfn = vfio_default_config_read;\ndrivers/vfio/pci/vfio_pci_config.c-377-\tperm-\u003ewritefn = vfio_default_config_write;\n--\ndrivers/vfio/pci/vfio_pci_config.c=474=static void vfio_bar_fixup(struct vfio_pci_core_device *vdev)\n--\ndrivers/vfio/pci/vfio_pci_config.c-527-\ndrivers/vfio/pci/vfio_pci_config.c:528:static int vfio_basic_config_read(struct vfio_pci_core_device *vdev, int pos,\ndrivers/vfio/pci/vfio_pci_config.c-529-\t\t\t\t int count, struct perm_bits *perm,\n--\ndrivers/vfio/pci/vfio_pci_config.c-534-\ndrivers/vfio/pci/vfio_pci_config.c:535:\tcount = vfio_default_config_read(vdev, pos, count, perm, offset, val);\ndrivers/vfio/pci/vfio_pci_config.c-536-\n--\ndrivers/vfio/pci/vfio_pci_config.c=663=static int __init init_pci_cap_basic_perm(struct perm_bits *perm)\n--\ndrivers/vfio/pci/vfio_pci_config.c-667-\ndrivers/vfio/pci/vfio_pci_config.c:668:\tperm-\u003ereadfn = vfio_basic_config_read;\ndrivers/vfio/pci/vfio_pci_config.c-669-\tperm-\u003ewritefn = vfio_basic_config_write;\n--\ndrivers/vfio/pci/vfio_pci_config.c=1127=static void vfio_tph_vcap_rewrite(struct vfio_pci_core_device *vdev, int pos)\n--\ndrivers/vfio/pci/vfio_pci_config.c-1160-\ndrivers/vfio/pci/vfio_pci_config.c:1161:static int vfio_tph_config_read(struct vfio_pci_core_device *vdev, int pos,\ndrivers/vfio/pci/vfio_pci_config.c-1162-\t\t\t\tint count, struct perm_bits *perm,\n--\ndrivers/vfio/pci/vfio_pci_config.c-1172-\tif (offset \u003c PCI_TPH_CTRL)\ndrivers/vfio/pci/vfio_pci_config.c:1173:\t\treturn vfio_default_config_read(vdev, pos, count, perm,\ndrivers/vfio/pci/vfio_pci_config.c-1174-\t\t\t\t\t\toffset, val);\n--\ndrivers/vfio/pci/vfio_pci_config.c-1176-\t/* Read the actual device value for CTRL register. */\ndrivers/vfio/pci/vfio_pci_config.c:1177:\tret = vfio_user_config_read(vdev-\u003epdev, pos, val, count);\ndrivers/vfio/pci/vfio_pci_config.c-1178-\treturn ret != 0 ? ret : count;\n--\ndrivers/vfio/pci/vfio_pci_config.c=1181=static int vfio_tph_config_write(struct vfio_pci_core_device *vdev, int pos,\n--\ndrivers/vfio/pci/vfio_pci_config.c-1202-\t */\ndrivers/vfio/pci/vfio_pci_config.c:1203:\tvfio_user_config_read(pdev, start + PCI_TPH_CTRL, \u0026ctrl_val, 4);\ndrivers/vfio/pci/vfio_pci_config.c-1204-\tvfio_default_config_write(vdev, start + PCI_TPH_CTRL, 4, perm,\n--\ndrivers/vfio/pci/vfio_pci_config.c=1258=int __init vfio_pci_init_perm_bits(void)\n--\ndrivers/vfio/pci/vfio_pci_config.c-1276-\tret |= init_pci_ext_cap_tph_perm(\u0026ecap_perms[PCI_EXT_CAP_ID_TPH]);\ndrivers/vfio/pci/vfio_pci_config.c:1277:\tecap_perms[PCI_EXT_CAP_ID_TPH].readfn = vfio_tph_config_read;\ndrivers/vfio/pci/vfio_pci_config.c-1278-\tecap_perms[PCI_EXT_CAP_ID_TPH].writefn = vfio_tph_config_write;\n--\ndrivers/vfio/pci/vfio_pci_config.c-1287-\ndrivers/vfio/pci/vfio_pci_config.c:1288:static int vfio_msi_config_read(struct vfio_pci_core_device *vdev, int pos,\ndrivers/vfio/pci/vfio_pci_config.c-1289-\t\t\t\tint count, struct perm_bits *perm,\n--\ndrivers/vfio/pci/vfio_pci_config.c-1304-\ndrivers/vfio/pci/vfio_pci_config.c:1305:\treturn vfio_default_config_read(vdev, pos, count, perm, offset, val);\ndrivers/vfio/pci/vfio_pci_config.c-1306-}\n--\ndrivers/vfio/pci/vfio_pci_config.c=1354=static int init_pci_cap_msi_perm(struct perm_bits *perm, int len, u16 flags)\n--\ndrivers/vfio/pci/vfio_pci_config.c-1358-\ndrivers/vfio/pci/vfio_pci_config.c:1359:\tperm-\u003ereadfn = vfio_msi_config_read;\ndrivers/vfio/pci/vfio_pci_config.c-1360-\tperm-\u003ewritefn = vfio_msi_config_write;\n"
} |
| 69/3 | 2026/11/22 09:46 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 28225 output: 31 thoughts: 53 Thoughts: Okay, let's dive into this. Here's what I'm thinking: **Examining the Data Flow in vfio_pci_config_rw** Right, I need to get a clear picture of how `vfio_pci_config_rw` functions, specifically how it interacts with the `readfn` callback and, crucially, how the `*val` pointer is being managed. That's the core of understanding how data is handled during read and write operations. The likely place to find the answers is, as usual, in `drivers/vfio/pci/vfio_pci_config.c`. Time to get my hands dirty. I'll need to trace the calls and follow the data. Let's see what's what. |
| 70/3 | 2026/11/22 09:46 | tool | grepper |
0mArgs:{
"Expression": "readfn",
"PathPrefixes": [
"drivers/vfio/pci/"
]
}Results: {
"Output": "drivers/vfio/pci/vfio_pci_config.c=111=struct perm_bits {\n--\ndrivers/vfio/pci/vfio_pci_config.c-113-\tu8\t*write;\t\t/* writeable bits */\ndrivers/vfio/pci/vfio_pci_config.c:114:\tint\t(*readfn)(struct vfio_pci_core_device *vdev, int pos, int count,\ndrivers/vfio/pci/vfio_pci_config.c-115-\t\t\t struct perm_bits *perm, int offset, __le32 *val);\n--\ndrivers/vfio/pci/vfio_pci_config.c=318=static struct perm_bits direct_ro_perms = {\ndrivers/vfio/pci/vfio_pci_config.c:319:\t.readfn = vfio_direct_config_read,\ndrivers/vfio/pci/vfio_pci_config.c-320-};\n--\ndrivers/vfio/pci/vfio_pci_config.c=323=static struct perm_bits cap_perms[PCI_CAP_ID_MAX + 1] = {\ndrivers/vfio/pci/vfio_pci_config.c:324:\t[0 ... PCI_CAP_ID_MAX] = { .readfn = vfio_direct_config_read }\ndrivers/vfio/pci/vfio_pci_config.c-325-};\ndrivers/vfio/pci/vfio_pci_config.c=326=static struct perm_bits ecap_perms[PCI_EXT_CAP_ID_MAX + 1] = {\ndrivers/vfio/pci/vfio_pci_config.c:327:\t[0 ... PCI_EXT_CAP_ID_MAX] = { .readfn = vfio_direct_config_read }\ndrivers/vfio/pci/vfio_pci_config.c-328-};\n--\ndrivers/vfio/pci/vfio_pci_config.c=335=static struct perm_bits unassigned_perms = {\ndrivers/vfio/pci/vfio_pci_config.c:336:\t.readfn = vfio_raw_config_read,\ndrivers/vfio/pci/vfio_pci_config.c-337-\t.writefn = vfio_raw_config_write\n--\ndrivers/vfio/pci/vfio_pci_config.c=340=static struct perm_bits virt_perms = {\ndrivers/vfio/pci/vfio_pci_config.c:341:\t.readfn = vfio_virt_config_read,\ndrivers/vfio/pci/vfio_pci_config.c-342-\t.writefn = vfio_virt_config_write\n--\ndrivers/vfio/pci/vfio_pci_config.c=353=static int alloc_perm_bits(struct perm_bits *perm, int size)\n--\ndrivers/vfio/pci/vfio_pci_config.c-375-\ndrivers/vfio/pci/vfio_pci_config.c:376:\tperm-\u003ereadfn = vfio_default_config_read;\ndrivers/vfio/pci/vfio_pci_config.c-377-\tperm-\u003ewritefn = vfio_default_config_write;\n--\ndrivers/vfio/pci/vfio_pci_config.c=663=static int __init init_pci_cap_basic_perm(struct perm_bits *perm)\n--\ndrivers/vfio/pci/vfio_pci_config.c-667-\ndrivers/vfio/pci/vfio_pci_config.c:668:\tperm-\u003ereadfn = vfio_basic_config_read;\ndrivers/vfio/pci/vfio_pci_config.c-669-\tperm-\u003ewritefn = vfio_basic_config_write;\n--\ndrivers/vfio/pci/vfio_pci_config.c=1258=int __init vfio_pci_init_perm_bits(void)\n--\ndrivers/vfio/pci/vfio_pci_config.c-1276-\tret |= init_pci_ext_cap_tph_perm(\u0026ecap_perms[PCI_EXT_CAP_ID_TPH]);\ndrivers/vfio/pci/vfio_pci_config.c:1277:\tecap_perms[PCI_EXT_CAP_ID_TPH].readfn = vfio_tph_config_read;\ndrivers/vfio/pci/vfio_pci_config.c-1278-\tecap_perms[PCI_EXT_CAP_ID_TPH].writefn = vfio_tph_config_write;\n--\ndrivers/vfio/pci/vfio_pci_config.c=1354=static int init_pci_cap_msi_perm(struct perm_bits *perm, int len, u16 flags)\n--\ndrivers/vfio/pci/vfio_pci_config.c-1358-\ndrivers/vfio/pci/vfio_pci_config.c:1359:\tperm-\u003ereadfn = vfio_msi_config_read;\ndrivers/vfio/pci/vfio_pci_config.c-1360-\tperm-\u003ewritefn = vfio_msi_config_write;\n--\ndrivers/vfio/pci/vfio_pci_config.c=1769=static int vfio_ecap_init(struct vfio_pci_core_device *vdev)\n--\ndrivers/vfio/pci/vfio_pci_config.c-1818-\t\t\t * Otherwise, fill in a placeholder, the direct\ndrivers/vfio/pci/vfio_pci_config.c:1819:\t\t\t * readfn will virtualize this automatically\ndrivers/vfio/pci/vfio_pci_config.c-1820-\t\t\t */\n--\ndrivers/vfio/pci/vfio_pci_config.c=2025=ssize_t vfio_pci_config_rw_single(struct vfio_pci_core_device *vdev,\n--\ndrivers/vfio/pci/vfio_pci_config.c-2102-\t} else {\ndrivers/vfio/pci/vfio_pci_config.c:2103:\t\tif (perm-\u003ereadfn) {\ndrivers/vfio/pci/vfio_pci_config.c:2104:\t\t\tret = perm-\u003ereadfn(vdev, *ppos, count,\ndrivers/vfio/pci/vfio_pci_config.c-2105-\t\t\t\t\t perm, offset, \u0026val);\n"
} |
| 71/3 | 2026/11/22 09:46 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 30207 output: 46 thoughts: 25 Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience, and written as if they were my own: **Diving into `vfio_pci_config_rw_single`** Alright, let's zero in on `vfio_pci_config_rw_single`. Specifically, I want to take a closer look at that function around line 2100 in the code. I'm guessing that's where the core logic for the single register read/write operations is located, and that's probably the most critical place to confirm it's acting as it should. We know that's a common area for potential errors, especially with the complexities of DMA and device access in VFIO, so it warrants a thorough inspection. There might be some subtle timing issues or address translation quirks there that need to be ironed out. Knowing the complexities, it is likely the most sensible place to start looking. |
| 72/3 | 2026/11/22 09:47 | tool | read-file |
0mArgs:{
"File": "drivers/vfio/pci/vfio_pci_config.c",
"FirstLine": 2095,
"LineCount": 40
}Results: {
"Contents": "2095:\t\t\tif (!perm-\u003ewritefn)\n2096:\t\t\t\treturn ret;\n2097:\t\n2098:\t\t\tif (copy_from_user(\u0026val, buf, count))\n2099:\t\t\t\treturn -EFAULT;\n2100:\t\n2101:\t\t\tret = perm-\u003ewritefn(vdev, *ppos, count, perm, offset, val);\n2102:\t\t} else {\n2103:\t\t\tif (perm-\u003ereadfn) {\n2104:\t\t\t\tret = perm-\u003ereadfn(vdev, *ppos, count,\n2105:\t\t\t\t\t\t perm, offset, \u0026val);\n2106:\t\t\t\tif (ret \u003c 0)\n2107:\t\t\t\t\treturn ret;\n2108:\t\t\t}\n2109:\t\n2110:\t\t\tif (copy_to_user(buf, \u0026val, count))\n2111:\t\t\t\treturn -EFAULT;\n2112:\t\t}\n2113:\t\n2114:\t\treturn ret;\n2115:\t}\n2116:\tEXPORT_SYMBOL_GPL(vfio_pci_config_rw_single);\n2117:\t\n2118:\tssize_t vfio_pci_config_rw(struct vfio_pci_core_device *vdev, char __user *buf,\n2119:\t\t\t\t size_t count, loff_t *ppos, bool iswrite)\n2120:\t{\n2121:\t\tsize_t done = 0;\n2122:\t\tint ret = 0;\n2123:\t\tloff_t pos = *ppos;\n2124:\t\n2125:\t\tpos \u0026= VFIO_PCI_OFFSET_MASK;\n2126:\t\n2127:\t\twhile (count) {\n2128:\t\t\tret = vfio_pci_config_rw_single(vdev, buf, count, \u0026pos, iswrite);\n2129:\t\t\tif (ret \u003c 0)\n2130:\t\t\t\treturn ret;\n2131:\t\n2132:\t\t\tcount -= ret;\n2133:\t\t\tdone += ret;\n2134:\t\t\tbuf += ret;\n"
} |
| 73/3 | 2026/11/22 09:47 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 31052 output: 46 thoughts: 66 Thoughts: Here's my take on the thought process, as requested: **Diving into `vfio_pci_config_rw_single` Initialization** Alright, let's take a closer look at `vfio_pci_config_rw_single`. My immediate concern, as always when dealing with memory operations, is initialization. Specifically, I need to verify that `__le32 val` is properly initialized before any read or write operations. Leaving variables uninitialized in this context is just asking for trouble, potential garbage data, and unpredictable behavior, especially in a driver. I need to be absolutely certain that this isn't the case here, given that we are dealing with PCI configuration space and I don't need any unexpected consequences to pop up. So, I'll go ahead and skim from lines 2050 to 2095 in the code. I'll be looking specifically for where `val` is defined and if a value is assigned to `val`. I'll scan that section for possible bugs that involve the variable `val`. I'll also try to follow the data path and determine if `val` is later written to or read from, and I'll need to know whether any prior values are considered. |
| 74/3 | 2026/11/22 09:47 | tool | read-file |
0mArgs:{
"File": "drivers/vfio/pci/vfio_pci_config.c",
"FirstLine": 2050,
"LineCount": 45
}Results: {
"Contents": "2050:\t\t\tcount = 1;\n2051:\t\n2052:\t\tret = count;\n2053:\t\n2054:\t\tcap_id = vdev-\u003epci_config_map[*ppos];\n2055:\t\n2056:\t\tif (cap_id == PCI_CAP_ID_INVALID) {\n2057:\t\t\tperm = \u0026unassigned_perms;\n2058:\t\t\tcap_start = *ppos;\n2059:\t\t} else if (cap_id == PCI_CAP_ID_INVALID_VIRT) {\n2060:\t\t\tperm = \u0026virt_perms;\n2061:\t\t\tcap_start = *ppos;\n2062:\t\t} else {\n2063:\t\t\tif (*ppos \u003e= PCI_CFG_SPACE_SIZE) {\n2064:\t\t\t\t/*\n2065:\t\t\t\t * We can get a cap_id that exceeds PCI_EXT_CAP_ID_MAX\n2066:\t\t\t\t * if we're hiding an unknown capability at the start\n2067:\t\t\t\t * of the extended capability list. Use default, ro\n2068:\t\t\t\t * access, which will virtualize the id and next values.\n2069:\t\t\t\t */\n2070:\t\t\t\tif (cap_id \u003e PCI_EXT_CAP_ID_MAX)\n2071:\t\t\t\t\tperm = \u0026direct_ro_perms;\n2072:\t\t\t\telse\n2073:\t\t\t\t\tperm = \u0026ecap_perms[cap_id];\n2074:\t\n2075:\t\t\t\tcap_start = vfio_find_cap_start(vdev, *ppos);\n2076:\t\t\t} else {\n2077:\t\t\t\tWARN_ON(cap_id \u003e PCI_CAP_ID_MAX);\n2078:\t\n2079:\t\t\t\tperm = \u0026cap_perms[cap_id];\n2080:\t\n2081:\t\t\t\tif (cap_id == PCI_CAP_ID_MSI)\n2082:\t\t\t\t\tperm = vdev-\u003emsi_perm;\n2083:\t\n2084:\t\t\t\tif (cap_id \u003e PCI_CAP_ID_BASIC)\n2085:\t\t\t\t\tcap_start = vfio_find_cap_start(vdev, *ppos);\n2086:\t\t\t}\n2087:\t\t}\n2088:\t\n2089:\t\tWARN_ON(!cap_start \u0026\u0026 cap_id != PCI_CAP_ID_BASIC);\n2090:\t\tWARN_ON(cap_start \u003e *ppos);\n2091:\t\n2092:\t\toffset = *ppos - cap_start;\n2093:\t\n2094:\t\tif (iswrite) {\n"
} |
| 75/3 | 2026/11/22 09:47 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 32121 output: 46 thoughts: 22 Thoughts: Here's my take on the thought process, as requested: **Diving into the `val` Declaration** Alright, let's zero in. My immediate thought is to pinpoint the exact location where this `val` is declared. Lines 2025 through 2050 are the target – that's where the declaration should be. I'll need to rapidly scan that block to understand the context. I'm looking for the scope, any associated modifiers (like `private`, `public`, `static`, etc.), the data type, and the initial value, of course. I'll also be watching out for any potential interactions within that declaration block, like other variables being initialized or any conditional logic that might be involved. This is the foundation I need to begin building my understanding of how this `val` behaves. I'm expecting to find a clear and concise definition, but I'm prepared for a bit of detective work if the code isn't perfectly straightforward. Let's see what we uncover in that range... |
| 76/3 | 2026/11/22 09:48 | tool | read-file |
0mArgs:{
"File": "drivers/vfio/pci/vfio_pci_config.c",
"FirstLine": 2025,
"LineCount": 25
}Results: {
"Contents": "2025:\tssize_t vfio_pci_config_rw_single(struct vfio_pci_core_device *vdev,\n2026:\t\t\t\t\t char __user *buf, size_t count, loff_t *ppos,\n2027:\t\t\t\t\t bool iswrite)\n2028:\t{\n2029:\t\tstruct pci_dev *pdev = vdev-\u003epdev;\n2030:\t\tstruct perm_bits *perm;\n2031:\t\t__le32 val = 0;\n2032:\t\tint cap_start = 0, offset;\n2033:\t\tu8 cap_id;\n2034:\t\tssize_t ret;\n2035:\t\n2036:\t\tif (*ppos \u003c 0 || *ppos \u003e= pdev-\u003ecfg_size ||\n2037:\t\t *ppos + count \u003e pdev-\u003ecfg_size)\n2038:\t\t\treturn -EFAULT;\n2039:\t\n2040:\t\t/*\n2041:\t\t * Chop accesses into aligned chunks containing no more than a\n2042:\t\t * single capability. Caller increments to the next chunk.\n2043:\t\t */\n2044:\t\tcount = min(count, vfio_pci_cap_remaining_dword(vdev, *ppos));\n2045:\t\tif (count \u003e= 4 \u0026\u0026 !(*ppos % 4))\n2046:\t\t\tcount = 4;\n2047:\t\telse if (count \u003e= 2 \u0026\u0026 !(*ppos % 2))\n2048:\t\t\tcount = 2;\n2049:\t\telse\n"
} |
| 77/3 | 2026/11/22 09:48 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 32834 output: 32 thoughts: 3437 Thoughts: **TPH Code Analysis: Initialization and Potential Issues** Okay, let's break this down. We're looking at TPH (TLP Processing Hints) initialization and usage within the VFIO driver. The core concern is data integrity and preventing uninitialized values. First, within the `vfio_pci_config_rw_single` function, `val` is initialized. This is a basic read/write process. Let's trace it down. Within `vfio_tph_config_read` the code checks an `offset` and utilizes `vfio_default_config_read` if less than `PCI_TPH_CTRL`. Otherwise, it utilizes `vfio_user_config_read`. In `vfio_user_config_read`, `tmp_val` is being written to `*val`. It appears to be reading the device's configuration and translating it. In `pcie_tph_get_st_table_loc`, `reg` is initialized to 0. It reads a configuration value, which should be initialized by `pci_alloc_dev` to all zeros. Now, let's get into the heart of the TPH setup. `pcie_tph_get_cpu_st_ext` and `vfio_pci_tph_resolve_st_tag` play a crucial role. We see `pcie_tph_get_cpu_st_ext` initializing `cpu_uid`. And, `vfio_pci_tph_resolve_st_tag` will assign `*st = 0` on failure, but `tag` is initialized. In the `vfio_pci_core_feature_tph_resolve` function, the `tag` value is initialized to 0. `vfio_pci_tph_resolve_st_tag` returns 0. `vfio_pci_core_feature_tph_program` comes into play next. The `tags` array is allocated with `kcalloc`, meaning it's zero-initialized. The loop iterates based on `program.count`. Inside the loop, `vfio_pci_tph_resolve_st_tag` is called again. The critical part is that we handle the `stop_on_zero` flag. The loop breaks if `ret` is non-zero or if the `tags` array is `0`. Then there's `vdev->tph_st_cpu` within `vfio_pci_core_device`. This is a table to store the TPH status. This is allocated with `kcalloc` so it's initialized to 0. Afterwards, the table is initialized to -1. Now, the potential vulnerability. We must consider the `src_handle` parameter. If `user_flags & VFIO_DEVICE_TPH_SRC_NONE` is true, then `src_handle` is NULL. This is crucial. If `src_bits & VFIO_DEVICE_TPH_SRC_NONE` then `*st = 0`, thus `tags[k] = 0`. So, the ternary operator `(tags[k] == 0) ? -1 : src_handle[k]` will assign `-1`, so no dereferencing occurs. So, the issue of potentially uninitialized `tags` is solved because `tags` is zeroed by allocation, and the loop properly utilizes the return values from the `pci` functions to terminate early. In examining `struct pci_dev`, bitfields are allocated with `kzalloc`. This guarantees all fields are initialized to 0 at device creation. We're safe here. In addition, the initialization of the `tph_cap` field ensures that if the TPH capability is not found, related values remain initialized to 0. Finally, if `CONFIG_PCIE_TPH` is disabled, the code path is bypassed. In summary, the code appears to be sound. Every variable is correctly initialized. The potential for uninitialized values or null pointer dereferences is handled. |
| 78/3 | 2026/11/22 09:48 | tool | grepper |
0mArgs:{
"Expression": "tph_extract_tag",
"PathPrefixes": [
"drivers/pci/"
]
}Results: {
"Output": "drivers/pci/tph.c=38=union st_info {\n--\ndrivers/pci/tph.c-55-\ndrivers/pci/tph.c:56:static u16 tph_extract_tag(enum tph_mem_type mem_type, u8 req_type,\ndrivers/pci/tph.c-57-\t\t\t union st_info *info)\n--\ndrivers/pci/tph.c=250=int pcie_tph_get_cpu_st_ext(struct pci_dev *pdev, enum tph_mem_type mem_type,\n--\ndrivers/pci/tph.c-278-\ndrivers/pci/tph.c:279:\t*tag = tph_extract_tag(mem_type, req_type, \u0026info);\ndrivers/pci/tph.c-280-\n"
} |
| 79/3 | 2026/11/22 09:48 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 37419 output: 36 thoughts: 23 Thoughts: Okay, let's dive into this. Here's my take on those lines of code: **Analyzing the PCI TPH Code (drivers/pci/tph.c lines 40-75)** Alright, so I'm looking at `drivers/pci/tph.c`, specifically lines 40 through 75. My initial scan suggests this is likely related to handling Transaction Pending Handling (TPH) within the PCI subsystem, likely for IOMMU or similar advanced features. My expert eye immediately seeks key data structures and function calls to understand the flow and logic. I'm guessing this section contains the core routines for setting, clearing, and perhaps interpreting TPH-related bits or registers. I’m expecting to see definitions related to the TPH capabilities structure, maybe some helper functions to determine support, and probably some register access logic. Specifically, I'm thinking I'll find code that checks for the presence of the TPH capability in the device configuration space. I'm interested in seeing how it handles different TPH types if they exist, and how it handles potential error conditions or unsupported configurations. The intent is to fully grok the mechanism PCI uses to pass transaction pending data to an IOMMU, if indeed this is the implementation. I'm also curious about the locking mechanisms used here. Concurrency within the PCI subsystem can be tricky, so I'll be looking for any mutexes or spinlocks that protect the TPH-related data structures or register accesses, especially if there's any interrupt-driven interaction. Let me see... I'm looking for the state transitions in the TPH operations, and how they relate to the PCI transaction. From previous PCI experience, I'm expecting some kind of interrupt handling or polling mechanism to coordinate operations. Ok, time to dive in and get specific. |
| 80/3 | 2026/11/22 09:48 | tool | read-file |
0mArgs:{
"File": "drivers/pci/tph.c",
"FirstLine": 40,
"LineCount": 35
}Results: {
"Contents": " 40:\t\t\tu64 vm_st_valid : 1;\n 41:\t\t\tu64 vm_xst_valid : 1;\n 42:\t\t\tu64 vm_ph_ignore : 1;\n 43:\t\t\tu64 rsvd1 : 5;\n 44:\t\t\tu64 vm_st : 8;\n 45:\t\t\tu64 vm_xst : 16;\n 46:\t\t\tu64 pm_st_valid : 1;\n 47:\t\t\tu64 pm_xst_valid : 1;\n 48:\t\t\tu64 pm_ph_ignore : 1;\n 49:\t\t\tu64 rsvd2 : 5;\n 50:\t\t\tu64 pm_st : 8;\n 51:\t\t\tu64 pm_xst : 16;\n 52:\t\t};\n 53:\t\tu64 value;\n 54:\t};\n 55:\t\n 56:\tstatic u16 tph_extract_tag(enum tph_mem_type mem_type, u8 req_type,\n 57:\t\t\t\t union st_info *info)\n 58:\t{\n 59:\t\tswitch (req_type) {\n 60:\t\tcase PCI_TPH_REQ_TPH_ONLY: /* 8-bit tag */\n 61:\t\t\tswitch (mem_type) {\n 62:\t\t\tcase TPH_MEM_TYPE_VM:\n 63:\t\t\t\tif (info-\u003evm_st_valid)\n 64:\t\t\t\t\treturn info-\u003evm_st;\n 65:\t\t\t\tbreak;\n 66:\t\t\tcase TPH_MEM_TYPE_PM:\n 67:\t\t\t\tif (info-\u003epm_st_valid)\n 68:\t\t\t\t\treturn info-\u003epm_st;\n 69:\t\t\t\tbreak;\n 70:\t\t\t}\n 71:\t\t\tbreak;\n 72:\t\tcase PCI_TPH_REQ_EXT_TPH: /* 16-bit tag */\n 73:\t\t\tswitch (mem_type) {\n 74:\t\t\tcase TPH_MEM_TYPE_VM:\n"
} |
| 81/3 | 2026/11/22 09:48 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 38404 output: 37 thoughts: 37 Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience: **Analyzing `pcie_tph_get_cpu_st_ext` in `drivers/pci/tph.c`** Alright, let's dive into this. I'm focusing on `pcie_tph_get_cpu_st_ext`, specifically around line 250 in the `drivers/pci/tph.c` file. My immediate thought is, what are we trying to achieve here with the retrieval of the CPU-specific stimulus type extended information? This likely relates to how we're handling Transaction Processing Hints (TPH) within the PCI Express framework. We need to dissect how the code interacts with the underlying hardware, and how it handles potential edge cases or error conditions during the information retrieval. Is it related to handling a specific type of TPH or is it more general? I'll be keeping an eye out for how this function integrates with the wider system. Any interaction with the MMIO is of interest. Also, if there is a problem with retrieving the information, how the function reports it - is there a check for valid input values? What is the function's return value and what does it indicate about the state of the extended information? I anticipate potentially encountering considerations such as cache coherency or interrupt handling, depending on how this data is being accessed and used by other parts of the system. I will look for any potential performance bottlenecks or locking mechanisms used, and if there is a risk of data corruption or race conditions. |
| 82/3 | 2026/11/22 09:49 | tool | read-file |
0mArgs:{
"File": "drivers/pci/tph.c",
"FirstLine": 250,
"LineCount": 45
}Results: {
"Contents": " 250:\tint pcie_tph_get_cpu_st_ext(struct pci_dev *pdev, enum tph_mem_type mem_type,\n 251:\t\t\t\t u8 req_type, unsigned int cpu, u16 *tag)\n 252:\t{\n 253:\t#ifdef CONFIG_ACPI\n 254:\t\tstruct pci_dev *rp;\n 255:\t\tacpi_handle rp_acpi_handle;\n 256:\t\tunion st_info info;\n 257:\t\tu32 cpu_uid;\n 258:\t\tint ret;\n 259:\t\n 260:\t\tif (req_type == PCI_TPH_REQ_DISABLE || req_type == 2 ||\n 261:\t\t\treq_type \u003e pdev-\u003etph_max_type)\n 262:\t\t\treturn -EINVAL;\n 263:\t\n 264:\t\tret = acpi_get_cpu_uid(cpu, \u0026cpu_uid);\n 265:\t\tif (ret != 0)\n 266:\t\t\treturn ret;\n 267:\t\n 268:\t\trp = pcie_find_root_port(pdev);\n 269:\t\tif (!rp || !rp-\u003ebus || !rp-\u003ebus-\u003ebridge)\n 270:\t\t\treturn -ENODEV;\n 271:\t\n 272:\t\trp_acpi_handle = ACPI_HANDLE(rp-\u003ebus-\u003ebridge);\n 273:\t\n 274:\t\tif (tph_invoke_dsm(rp_acpi_handle, cpu_uid, \u0026info) != AE_OK) {\n 275:\t\t\t*tag = 0;\n 276:\t\t\treturn -EINVAL;\n 277:\t\t}\n 278:\t\n 279:\t\t*tag = tph_extract_tag(mem_type, req_type, \u0026info);\n 280:\t\n 281:\t\tpci_dbg(pdev, \"get steering tag: mem_type=%s, req_type=%u, cpu=%d, tag=%#04x\\n\",\n 282:\t\t\t(mem_type == TPH_MEM_TYPE_VM) ? \"volatile\" : \"persistent\",\n 283:\t\t\treq_type, cpu, *tag);\n 284:\t\n 285:\t\treturn 0;\n 286:\t#else\n 287:\t\treturn -ENODEV;\n 288:\t#endif\n 289:\t}\n 290:\tEXPORT_SYMBOL(pcie_tph_get_cpu_st_ext);\n 291:\t\n 292:\t/**\n 293:\t * pcie_tph_get_cpu_st() - Retrieve Steering Tag for a target memory associated\n 294:\t * with a specific CPU\n"
} |
| 83/3 | 2026/11/22 09:49 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 39542 output: 33 thoughts: 23 Thoughts: Here's my take on those thoughts, keeping in mind my expertise in this area: **Checking Initialization Before the Big Call** Okay, so before I even *think* about calling `tph_invoke_dsm`, my gut instinct is to make absolutely certain that the `info` structure has been properly initialized. Experience has taught me that overlooking this seemingly simple detail can lead to the most frustrating and difficult-to-debug issues. We're talking about a critical function call here, and I've seen enough "mysterious" behavior arise from uninitialized variables to know that a quick sanity check is always worthwhile. It's just good defensive programming practice, really. This is a crucial area and it's always better to make sure. I'm going to quickly verify that `info` is good to go – it only takes a moment, and it could save me hours down the line. |
| 84/3 | 2026/11/22 09:49 | tool | grepper |
0mArgs:{
"Expression": "tph_invoke_dsm",
"PathPrefixes": [
"drivers/pci/"
]
}Results: {
"Output": "drivers/pci/tph.c=56=static u16 tph_extract_tag(enum tph_mem_type mem_type, u8 req_type,\n--\ndrivers/pci/tph.c-91-#define TPH_ST_DSM_FUNC_INDEX\t0xF\ndrivers/pci/tph.c:92:static acpi_status tph_invoke_dsm(acpi_handle handle, u32 cpu_uid,\ndrivers/pci/tph.c-93-\t\t\t\t union st_info *st_out)\n--\ndrivers/pci/tph.c=250=int pcie_tph_get_cpu_st_ext(struct pci_dev *pdev, enum tph_mem_type mem_type,\n--\ndrivers/pci/tph.c-273-\ndrivers/pci/tph.c:274:\tif (tph_invoke_dsm(rp_acpi_handle, cpu_uid, \u0026info) != AE_OK) {\ndrivers/pci/tph.c-275-\t\t*tag = 0;\n"
} |
| 85/3 | 2026/11/22 09:49 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 40072 output: 36 thoughts: 30 Thoughts: Okay, here's my interpretation of that thought process, assuming I'm already quite familiar with PCI and driver interactions: **Analyzing the `tph_invoke_dsm` Function** Alright, my internal radar is pinging. The direction is clear: line 92 in `drivers/pci/tph.c`, specifically the function `tph_invoke_dsm`. The immediate implication is that we're dealing with something related to TPH – Transaction Processing Hints. Given the context, I'd wager we're looking at the core function responsible for, well, *invoking* a DSM (Device Specific Method) related to TPH. That line number suggests it's likely a relatively central or critical piece of the puzzle. I'm expecting to see the core logic for how the driver interacts with the firmware/BIOS to set up, query, or manage TPH-related features for a given PCI device. This could involve reading capabilities, potentially issuing ACPI calls, handling error conditions, or managing data structures related to the transaction hint setup. My expertise on this topic is high, so I'm already anticipating some of the common pitfalls and complexities involved in this kind of low-level interaction. Time to dig in and see if my assumptions hold true. |
| 86/3 | 2026/11/22 09:49 | tool | read-file |
0mArgs:{
"File": "drivers/pci/tph.c",
"FirstLine": 92,
"LineCount": 40
}Results: {
"Contents": " 92:\tstatic acpi_status tph_invoke_dsm(acpi_handle handle, u32 cpu_uid,\n 93:\t\t\t\t\t union st_info *st_out)\n 94:\t{\n 95:\t\tunion acpi_object arg3[3], in_obj, *out_obj;\n 96:\t\n 97:\t\tif (!acpi_check_dsm(handle, \u0026pci_acpi_dsm_guid, 7,\n 98:\t\t\t\t BIT(TPH_ST_DSM_FUNC_INDEX)))\n 99:\t\t\treturn AE_ERROR;\n 100:\t\n 101:\t\t/* DWORD: feature ID (0 for processor cache ST query) */\n 102:\t\targ3[0].integer.type = ACPI_TYPE_INTEGER;\n 103:\t\targ3[0].integer.value = 0;\n 104:\t\n 105:\t\t/* DWORD: target UID */\n 106:\t\targ3[1].integer.type = ACPI_TYPE_INTEGER;\n 107:\t\targ3[1].integer.value = cpu_uid;\n 108:\t\n 109:\t\t/* QWORD: properties, all 0's */\n 110:\t\targ3[2].integer.type = ACPI_TYPE_INTEGER;\n 111:\t\targ3[2].integer.value = 0;\n 112:\t\n 113:\t\tin_obj.type = ACPI_TYPE_PACKAGE;\n 114:\t\tin_obj.package.count = ARRAY_SIZE(arg3);\n 115:\t\tin_obj.package.elements = arg3;\n 116:\t\n 117:\t\tout_obj = acpi_evaluate_dsm(handle, \u0026pci_acpi_dsm_guid, 7,\n 118:\t\t\t\t\t TPH_ST_DSM_FUNC_INDEX, \u0026in_obj);\n 119:\t\tif (!out_obj)\n 120:\t\t\treturn AE_ERROR;\n 121:\t\n 122:\t\tif (out_obj-\u003etype != ACPI_TYPE_BUFFER ||\n 123:\t\t out_obj-\u003ebuffer.length \u003c sizeof(st_out-\u003evalue) ||\n 124:\t\t !out_obj-\u003ebuffer.pointer) {\n 125:\t\t\tACPI_FREE(out_obj);\n 126:\t\t\treturn AE_ERROR;\n 127:\t\t}\n 128:\t\n 129:\t\tmemcpy(\u0026st_out-\u003evalue, out_obj-\u003ebuffer.pointer, sizeof(st_out-\u003evalue));\n 130:\t\n 131:\t\tACPI_FREE(out_obj);\n"
} |
| 87/3 | 2026/11/22 09:49 | llm | kmsan-evaluator |
1mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 41097 output: 41 thoughts: 2027 Thoughts: **Analysis of VFIO TPH Programming and Resolution** Okay, let's break this down systematically. First, `memcpy` is being used, copying the size of `st_out->value` – the `info` structure is fully populated, so that's fine. Now, focusing on `vfio_pci_core_feature_tph_program`: I'm zeroing in on this conditional block within the function, particularly the interplay between `user_flags`, `src_handle`, and the `tags` array. Specifically, the `VFIO_DEVICE_TPH_SRC_NONE` flag warrants immediate attention because if it's set, `src_handle` is NULL. My critical question is: can `tags[k]` ever be non-zero when `VFIO_DEVICE_TPH_SRC_NONE` is active? My prior understanding is that it can't, because of the `vfio_pci_tph_resolve_st_tag` function, which explicitly sets `*st = 0` when `src_bits & VFIO_DEVICE_TPH_SRC_NONE`. Therefore, if the user specifies that there is no source handle, the tag should ALWAYS be zero. But, I am double-checking that this will happen, to make sure I am not mistaken. Okay, if `tags[k]` *is* zero, then `vdev->tph_st_cpu[program.start + k] = -1;`. That's intended behavior. But what about the case when `src_handle` isn't NULL and we access `src_handle[k]`? I am satisfied that `src_handle` is allocated using `memdup_array_user`, and as such, `src_handle[k]` is within bounds. Also, the `memdup_array_user` check guarantees it copies from userspace. If there's an issue with user memory, the function returns early. Therefore, it should be safe. Next, I'm analyzing the return value of `vfio_pci_core_feature_tph_program`. The function either returns the number of entries successfully programmed (which should be positive), or a negative errno. This isn't copying anything to userspace; the return value is simply passed back through the ioctl system call. The comment confirms the return value semantics. Now, let's move to `vfio_pci_core_feature_tph_resolve`. I can see there are assignments to `resolve.valid`, `resolve.rsv`, and `resolve.st`, with the intention to copy the populated `resolve` struct to userspace with `copy_to_user`. I'll analyze the structure. `struct vfio_device_feature_tph_resolve` has a size of 12 bytes: `flags` (4 bytes), `src` (4 bytes), `valid` (1 byte), `rsv` (1 byte), and `st` (2 bytes). There are no padding bytes, because the struct members occupy contiguous memory, as I have calculated. Because `resolve` is fully initialized, the `copy_to_user` should be safe, because all bytes are initialized with values. Next, on to `vfio_device_feature_tph`: This is straightforward. It's a 4-byte struct containing `flags`, which is fully initialized before the copy to user. Finally, regarding debugfs, all the relevant fields in `vfio_pci_core_device` are initialized: `tph_policy` is assigned in `vfio_pci_init_dev`, and I have verified this. My next step is to examine how `tph_vcap` gets initialized. I will ensure that this always is initialized or that a check is put in place, to ensure no uninitialized bytes get read. I see it's initialized in `vfio_tph_vcap_rewrite`. But, what if the device doesn't have TPH capabilities? `vfio_tph_vcap_rewrite` is not called, and thus `vdev->tph_vcap` might be uninitialized. Therefore, I need to check where `struct vfio_pci_core_device` is allocated and review all places where `tph_vcap` is read, to handle this scenario. |
| 88/3 | 2026/11/22 09:50 | tool | grepper |
0mArgs:{
"Expression": "kzalloc.*vfio_pci_core_device",
"PathPrefixes": [
"drivers/vfio/pci/"
]
}Results: {
"Output": "no matches"
} |
| 89/3 | 2026/11/22 09:50 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 44118 output: 38 thoughts: 20 Thoughts: Here's my thought process, summarized as you requested: **Digging into vfio_pci_core_device Allocation** Okay, so I need to understand how and where `struct vfio_pci_core_device` is allocated. That's the key to understanding the lifecycle and potential issues related to this structure. I'm going to start with a targeted search for the allocation site. I'll need to use my typical methods to identify the allocation points. From there, I can trace back where this `struct` is declared to give it a better understanding. This will give me an understanding of the relationship between this structure, vfio, and pci. |
| 90/3 | 2026/11/22 09:51 | tool | grepper |
0mArgs:{
"Expression": "vfio_pci_core_device",
"PathPrefixes": [
"drivers/vfio/pci/"
]
}Results: {
"Output": "\nFull output is too long, showing 200 out of 1363 lines.\nUse more precise expression or PathPrefixes if possible.\n\nNumber of matching lines per file (21 files in total):\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c:9\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.h:1\ndrivers/vfio/pci/ism/main.c:23\ndrivers/vfio/pci/mlx5/cmd.h:1\ndrivers/vfio/pci/mlx5/main.c:1\ndrivers/vfio/pci/nvgrace-gpu/main.c:12\ndrivers/vfio/pci/pds/vfio_dev.h:1\ndrivers/vfio/pci/qat/main.c:2\ndrivers/vfio/pci/vfio_pci.c:11\ndrivers/vfio/pci/vfio_pci_config.c:39\ndrivers/vfio/pci/vfio_pci_core.c:103\ndrivers/vfio/pci/vfio_pci_dmabuf.c:5\ndrivers/vfio/pci/vfio_pci_igd.c:7\ndrivers/vfio/pci/vfio_pci_intrs.c:31\ndrivers/vfio/pci/vfio_pci_priv.h:31\ndrivers/vfio/pci/vfio_pci_rdwr.c:8\ndrivers/vfio/pci/vfio_pci_zdev.c:5\ndrivers/vfio/pci/virtio/common.h:1\ndrivers/vfio/pci/virtio/legacy_io.c:2\ndrivers/vfio/pci/virtio/main.c:1\ndrivers/vfio/pci/xe/main.c:32\n\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c=1192=static int hisi_acc_vf_qm_init(struct hisi_acc_vf_core_device *hisi_acc_vdev)\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c-1193-{\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c:1194:\tstruct vfio_pci_core_device *vdev = \u0026hisi_acc_vdev-\u003ecore_device;\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c-1195-\tstruct hisi_qm *vf_qm = \u0026hisi_acc_vdev-\u003evf_qm;\n--\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c=1241=static struct hisi_qm *hisi_acc_get_pf_qm(struct pci_dev *pdev)\n--\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c-1270-\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c:1271:static size_t hisi_acc_get_resource_len(struct vfio_pci_core_device *vdev,\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c-1272-\t\t\t\t\tunsigned int index)\n--\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c=1293=static int hisi_acc_pci_rw_access_check(struct vfio_device *core_vdev,\n--\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c-1297-\tunsigned int index = VFIO_PCI_OFFSET_TO_INDEX(*ppos);\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c:1298:\tstruct vfio_pci_core_device *vdev =\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c:1299:\t\tcontainer_of(core_vdev, struct vfio_pci_core_device, vdev);\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c-1300-\n--\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c=1316=static int hisi_acc_vfio_pci_mmap(struct vfio_device *core_vdev,\n--\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c-1318-{\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c:1319:\tstruct vfio_pci_core_device *vdev =\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c:1320:\t\tcontainer_of(core_vdev, struct vfio_pci_core_device, vdev);\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c-1321-\tunsigned int index;\n--\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c=1369=static int hisi_acc_vfio_ioctl_get_region(struct vfio_device *core_vdev,\n--\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c-1372-{\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c:1373:\tstruct vfio_pci_core_device *vdev =\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c:1374:\t\tcontainer_of(core_vdev, struct vfio_pci_core_device, vdev);\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c-1375-\n--\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c=1507=static int hisi_acc_vfio_pci_open_device(struct vfio_device *core_vdev)\n--\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c-1509-\tstruct hisi_acc_vf_core_device *hisi_acc_vdev = hisi_acc_get_vf_dev(core_vdev);\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c:1510:\tstruct vfio_pci_core_device *vdev = \u0026hisi_acc_vdev-\u003ecore_device;\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c-1511-\tint ret;\n--\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.h=129=struct hisi_acc_vf_core_device {\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.h:130:\tstruct vfio_pci_core_device core_device;\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.h-131-\tu8 match_done;\n--\ndrivers/vfio/pci/ism/main.c=43=ISM_READ(8);\ndrivers/vfio/pci/ism/main.c-44-\ndrivers/vfio/pci/ism/main.c:45:struct ism_vfio_pci_core_device {\ndrivers/vfio/pci/ism/main.c:46:\tstruct vfio_pci_core_device core_device;\ndrivers/vfio/pci/ism/main.c-47-\tstruct kmem_cache *store_block_cache;\n--\ndrivers/vfio/pci/ism/main.c-49-\ndrivers/vfio/pci/ism/main.c:50:VFIO_PCI_CORE_DEFINE_CALLBACKS(ism_vfio, struct ism_vfio_pci_core_device,\ndrivers/vfio/pci/ism/main.c-51-\t\t\t core_device)\n--\ndrivers/vfio/pci/ism/main.c=53=static int ism_vfio_pci_open_device(struct vfio_device *core_vdev)\ndrivers/vfio/pci/ism/main.c-54-{\ndrivers/vfio/pci/ism/main.c:55:\tstruct ism_vfio_pci_core_device *ivpcd;\ndrivers/vfio/pci/ism/main.c:56:\tstruct vfio_pci_core_device *vdev;\ndrivers/vfio/pci/ism/main.c-57-\tint ret;\ndrivers/vfio/pci/ism/main.c-58-\ndrivers/vfio/pci/ism/main.c:59:\tivpcd = container_of(core_vdev, struct ism_vfio_pci_core_device,\ndrivers/vfio/pci/ism/main.c-60-\t\t\t core_device.vdev);\n--\ndrivers/vfio/pci/ism/main.c-79- */\ndrivers/vfio/pci/ism/main.c:80:static ssize_t ism_vfio_pci_do_io_r(struct vfio_pci_core_device *vdev,\ndrivers/vfio/pci/ism/main.c-81-\t\t\t\t char __user *buf, loff_t off, size_t count,\n--\ndrivers/vfio/pci/ism/main.c-124- */\ndrivers/vfio/pci/ism/main.c:125:static ssize_t ism_vfio_pci_do_io_w(struct vfio_pci_core_device *vdev,\ndrivers/vfio/pci/ism/main.c-126-\t\t\t\t char __user *buf, loff_t off, size_t count,\n--\ndrivers/vfio/pci/ism/main.c-129-\tstruct zpci_dev *zdev = to_zpci(vdev-\u003epdev);\ndrivers/vfio/pci/ism/main.c:130:\tstruct ism_vfio_pci_core_device *ivpcd;\ndrivers/vfio/pci/ism/main.c-131-\tssize_t ret;\n--\ndrivers/vfio/pci/ism/main.c-139-\ndrivers/vfio/pci/ism/main.c:140:\tivpcd = container_of(vdev, struct ism_vfio_pci_core_device,\ndrivers/vfio/pci/ism/main.c-141-\t\t\t core_device);\n--\ndrivers/vfio/pci/ism/main.c-162-\ndrivers/vfio/pci/ism/main.c:163:static ssize_t ism_vfio_pci_bar_rw(struct vfio_pci_core_device *vdev,\ndrivers/vfio/pci/ism/main.c-164-\t\t\t\t char __user *buf, size_t count, loff_t *ppos,\n--\ndrivers/vfio/pci/ism/main.c-192-\ndrivers/vfio/pci/ism/main.c:193:static ssize_t ism_vfio_pci_config_rw(struct vfio_pci_core_device *vdev,\ndrivers/vfio/pci/ism/main.c-194-\t\t\t\t char __user *buf, size_t count,\n--\ndrivers/vfio/pci/ism/main.c=223=static ssize_t ism_vfio_pci_rw(struct vfio_device *core_vdev, char __user *buf,\n--\ndrivers/vfio/pci/ism/main.c-226-\tunsigned int index = ISM_VFIO_PCI_OFFSET_TO_INDEX(*ppos);\ndrivers/vfio/pci/ism/main.c:227:\tstruct vfio_pci_core_device *vdev;\ndrivers/vfio/pci/ism/main.c-228-\tint ret;\ndrivers/vfio/pci/ism/main.c-229-\ndrivers/vfio/pci/ism/main.c:230:\tvdev = container_of(core_vdev, struct vfio_pci_core_device, vdev);\ndrivers/vfio/pci/ism/main.c-231-\n--\ndrivers/vfio/pci/ism/main.c=265=static int ism_vfio_pci_ioctl_get_region_info(struct vfio_device *core_vdev,\n--\ndrivers/vfio/pci/ism/main.c-268-{\ndrivers/vfio/pci/ism/main.c:269:\tstruct vfio_pci_core_device *vdev =\ndrivers/vfio/pci/ism/main.c:270:\t\tcontainer_of(core_vdev, struct vfio_pci_core_device, vdev);\ndrivers/vfio/pci/ism/main.c-271-\tstruct pci_dev *pdev = vdev-\u003epdev;\n--\ndrivers/vfio/pci/ism/main.c=299=static int ism_vfio_pci_init_dev(struct vfio_device *core_vdev)\n--\ndrivers/vfio/pci/ism/main.c-301-\tstruct zpci_dev *zdev = to_zpci(to_pci_dev(core_vdev-\u003edev));\ndrivers/vfio/pci/ism/main.c:302:\tstruct ism_vfio_pci_core_device *ivpcd;\ndrivers/vfio/pci/ism/main.c-303-\tchar cache_name[20];\n--\ndrivers/vfio/pci/ism/main.c-305-\ndrivers/vfio/pci/ism/main.c:306:\tivpcd = container_of(core_vdev, struct ism_vfio_pci_core_device,\ndrivers/vfio/pci/ism/main.c-307-\t\t\t core_device.vdev);\n--\ndrivers/vfio/pci/ism/main.c=329=static void ism_vfio_pci_release_dev(struct vfio_device *core_vdev)\ndrivers/vfio/pci/ism/main.c-330-{\ndrivers/vfio/pci/ism/main.c:331:\tstruct ism_vfio_pci_core_device *ivpcd = container_of(\ndrivers/vfio/pci/ism/main.c:332:\t\tcore_vdev, struct ism_vfio_pci_core_device, core_device.vdev);\ndrivers/vfio/pci/ism/main.c-333-\n--\ndrivers/vfio/pci/ism/main.c=358=static int ism_vfio_pci_probe(struct pci_dev *pdev,\n--\ndrivers/vfio/pci/ism/main.c-360-{\ndrivers/vfio/pci/ism/main.c:361:\tstruct ism_vfio_pci_core_device *ivpcd;\ndrivers/vfio/pci/ism/main.c-362-\tint ret;\ndrivers/vfio/pci/ism/main.c-363-\ndrivers/vfio/pci/ism/main.c:364:\tivpcd = vfio_alloc_device(ism_vfio_pci_core_device, core_device.vdev,\ndrivers/vfio/pci/ism/main.c-365-\t\t\t\t \u0026pdev-\u003edev, \u0026ism_pci_ops);\n--\ndrivers/vfio/pci/ism/main.c=378=static void ism_vfio_pci_remove(struct pci_dev *pdev)\ndrivers/vfio/pci/ism/main.c-379-{\ndrivers/vfio/pci/ism/main.c:380:\tstruct ism_vfio_pci_core_device *ivpcd = pci_get_drvdata(pdev);\ndrivers/vfio/pci/ism/main.c-381-\n--\ndrivers/vfio/pci/mlx5/cmd.h=172=struct mlx5vf_pci_core_device {\ndrivers/vfio/pci/mlx5/cmd.h:173:\tstruct vfio_pci_core_device core_device;\ndrivers/vfio/pci/mlx5/cmd.h-174-\tint vf_id;\n--\ndrivers/vfio/pci/mlx5/main.c=1323=static int mlx5vf_pci_open_device(struct vfio_device *core_vdev)\n--\ndrivers/vfio/pci/mlx5/main.c-1326-\t\tcore_vdev, struct mlx5vf_pci_core_device, core_device.vdev);\ndrivers/vfio/pci/mlx5/main.c:1327:\tstruct vfio_pci_core_device *vdev = \u0026mvdev-\u003ecore_device;\ndrivers/vfio/pci/mlx5/main.c-1328-\tint ret;\n--\ndrivers/vfio/pci/nvgrace-gpu/main.c=60=struct nvgrace_gpu_pci_core_device {\ndrivers/vfio/pci/nvgrace-gpu/main.c:61:\tstruct vfio_pci_core_device core_device;\ndrivers/vfio/pci/nvgrace-gpu/main.c-62-\t/* Cached and usable memory for the VM. */\n--\ndrivers/vfio/pci/nvgrace-gpu/main.c=177=static int nvgrace_gpu_open_device(struct vfio_device *core_vdev)\ndrivers/vfio/pci/nvgrace-gpu/main.c-178-{\ndrivers/vfio/pci/nvgrace-gpu/main.c:179:\tstruct vfio_pci_core_device *vdev =\ndrivers/vfio/pci/nvgrace-gpu/main.c:180:\t\tcontainer_of(core_vdev, struct vfio_pci_core_device, vdev);\ndrivers/vfio/pci/nvgrace-gpu/main.c-181-\tstruct nvgrace_gpu_pci_core_device *nvdev =\n--\ndrivers/vfio/pci/nvgrace-gpu/main.c=359=nvgrace_gpu_check_device_ready(struct nvgrace_gpu_pci_core_device *nvdev)\ndrivers/vfio/pci/nvgrace-gpu/main.c-360-{\ndrivers/vfio/pci/nvgrace-gpu/main.c:361:\tstruct vfio_pci_core_device *vdev = \u0026nvdev-\u003ecore_device;\ndrivers/vfio/pci/nvgrace-gpu/main.c-362-\tint ret;\n--\ndrivers/vfio/pci/nvgrace-gpu/main.c=393=static vm_fault_t nvgrace_gpu_vfio_pci_huge_fault(struct vm_fault *vmf,\n--\ndrivers/vfio/pci/nvgrace-gpu/main.c-397-\tstruct nvgrace_gpu_pci_core_device *nvdev = vma-\u003evm_private_data;\ndrivers/vfio/pci/nvgrace-gpu/main.c:398:\tstruct vfio_pci_core_device *vdev = \u0026nvdev-\u003ecore_device;\ndrivers/vfio/pci/nvgrace-gpu/main.c-399-\tunsigned int index =\n--\ndrivers/vfio/pci/nvgrace-gpu/main.c=806=nvgrace_gpu_read_mem(struct nvgrace_gpu_pci_core_device *nvdev,\n--\ndrivers/vfio/pci/nvgrace-gpu/main.c-808-{\ndrivers/vfio/pci/nvgrace-gpu/main.c:809:\tstruct vfio_pci_core_device *vdev = \u0026nvdev-\u003ecore_device;\ndrivers/vfio/pci/nvgrace-gpu/main.c-810-\tu64 offset = *ppos \u0026 VFIO_PCI_OFFSET_MASK;\n--\ndrivers/vfio/pci/nvgrace-gpu/main.c=868=nvgrace_gpu_read(struct vfio_device *core_vdev,\n--\ndrivers/vfio/pci/nvgrace-gpu/main.c-874-\t\t\t core_device.vdev);\ndrivers/vfio/pci/nvgrace-gpu/main.c:875:\tstruct vfio_pci_core_device *vdev = \u0026nvdev-\u003ecore_device;\ndrivers/vfio/pci/nvgrace-gpu/main.c-876-\tint ret;\n--\ndrivers/vfio/pci/nvgrace-gpu/main.c=943=nvgrace_gpu_write_mem(struct nvgrace_gpu_pci_core_device *nvdev,\n--\ndrivers/vfio/pci/nvgrace-gpu/main.c-945-{\ndrivers/vfio/pci/nvgrace-gpu/main.c:946:\tstruct vfio_pci_core_device *vdev = \u0026nvdev-\u003ecore_device;\ndrivers/vfio/pci/nvgrace-gpu/main.c-947-\tunsigned int index = VFIO_PCI_OFFSET_TO_INDEX(*ppos);\n--\ndrivers/vfio/pci/nvgrace-gpu/main.c=998=nvgrace_gpu_write(struct vfio_device *core_vdev,\n--\ndrivers/vfio/pci/nvgrace-gpu/main.c-1003-\t\t\t core_device.vdev);\ndrivers/vfio/pci/nvgrace-gpu/main.c:1004:\tstruct vfio_pci_core_device *vdev = \u0026nvdev-\u003ecore_device;\ndrivers/vfio/pci/nvgrace-gpu/main.c-1005-\tunsigned int index = VFIO_PCI_OFFSET_TO_INDEX(*ppos);\n--\ndrivers/vfio/pci/nvgrace-gpu/main.c-1021-\ndrivers/vfio/pci/nvgrace-gpu/main.c:1022:static int nvgrace_get_dmabuf_phys(struct vfio_pci_core_device *core_vdev,\ndrivers/vfio/pci/nvgrace-gpu/main.c-1023-\t\t\t\t struct p2pdma_provider **provider,\n--\ndrivers/vfio/pci/nvgrace-gpu/main.c=1087=static int nvgrace_gpu_core_open_device(struct vfio_device *core_vdev)\ndrivers/vfio/pci/nvgrace-gpu/main.c-1088-{\ndrivers/vfio/pci/nvgrace-gpu/main.c:1089:\tstruct vfio_pci_core_device *vdev =\ndrivers/vfio/pci/nvgrace-gpu/main.c:1090:\t\tcontainer_of(core_vdev, struct vfio_pci_core_device, vdev);\ndrivers/vfio/pci/nvgrace-gpu/main.c-1091-\tint ret;\n--\ndrivers/vfio/pci/pds/vfio_dev.h=13=struct pds_vfio_pci_device {\ndrivers/vfio/pci/pds/vfio_dev.h:14:\tstruct vfio_pci_core_device vfio_coredev;\ndrivers/vfio/pci/pds/vfio_dev.h-15-\n--\n\n"
} |
| 91/3 | 2026/11/22 09:51 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 50468 output: 37 thoughts: 30 Thoughts: Okay, here's my take on those thoughts, framed as an expert's internal monologue: **Investigating `vfio_alloc_device`'s Memory Allocation** Right, let's dig into this `vfio_alloc_device` function. I know it's responsible for, well, allocating VFIO devices – which means memory allocation is critical here. The code mentions `kzalloc` internally. That immediately piques my interest. `kzalloc`, of course, is a kernel function for allocating zeroed memory. It’s the go-to for many structures to ensure clean state initialization. My initial thought is to verify how `vfio_alloc_device` leverages `kzalloc`. What size is being allocated? Is the zeroing necessary? Is it used appropriately for the objects created, or are we paying a performance penalty by needlessly zeroing large structures that get overwritten later? Are there opportunities to optimize or use a more specific allocator if appropriate? I need to look closely at the usage pattern to be sure the memory allocation is correct and efficient. I need to check for any potential issues with error handling, like ensuring that a NULL return from `kzalloc` is handled gracefully. Let's see if we can find any subtle memory leaks, double frees, or other problems that might be missed on a cursory glance. Okay, time to dive into the code... |
| 92/3 | 2026/11/22 09:52 | tool | grepper |
0mArgs:{
"Expression": "#define vfio_alloc_device",
"PathPrefixes": [
"include/linux/vfio.h"
]
}Results: {
"Output": "include/linux/vfio.h=325=struct vfio_device *_vfio_alloc_device(size_t size, struct device *dev,\ninclude/linux/vfio.h-326-\t\t\t\t const struct vfio_device_ops *ops);\ninclude/linux/vfio.h:327:#define vfio_alloc_device(dev_struct, member, dev, ops)\t\t\t\t\\\ninclude/linux/vfio.h-328-\tcontainer_of(_vfio_alloc_device(sizeof(struct dev_struct) +\t\t\\\n"
} |
| 93/3 | 2026/11/22 09:52 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 50969 output: 33 thoughts: 27 Thoughts: Okay, here's the summary, framed as your thought process: **Diving into VFIO Device Allocation** Alright, let's get down to brass tacks. I need to understand how these VFIO devices are being allocated. Specifically, I should zero in on the `_vfio_alloc_device` function. I know that's the likely entry point for device assignment, and it's located right where I expect it – in `drivers/vfio/vfio_main.c`. That's the core of the VFIO driver, so I'm hoping to find the control flow and resource management logic there. Time to see what magic happens inside. I anticipate I'll find how the kernel interacts with the device, and potentially where I can hook into the logic. |
| 94/3 | 2026/11/22 09:53 | tool | grepper |
0mArgs:{
"Expression": "_vfio_alloc_device",
"PathPrefixes": [
"drivers/vfio/"
]
}Results: {
"Output": "drivers/vfio/vfio_main.c=212=static int vfio_init_device(struct vfio_device *device, struct device *dev,\n--\ndrivers/vfio/vfio_main.c-226- */\ndrivers/vfio/vfio_main.c:227:struct vfio_device *_vfio_alloc_device(size_t size, struct device *dev,\ndrivers/vfio/vfio_main.c-228-\t\t\t\t const struct vfio_device_ops *ops)\n--\ndrivers/vfio/vfio_main.c-248-}\ndrivers/vfio/vfio_main.c:249:EXPORT_SYMBOL_GPL(_vfio_alloc_device);\ndrivers/vfio/vfio_main.c-250-\n"
} |
| 95/3 | 2026/11/22 09:53 | llm | kmsan-evaluator |
1mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 51404 output: 39 thoughts: 23 Thoughts: Okay, let's dive into this. I'm going to pull up `drivers/vfio/vfio_main.c` and specifically focus on line 227. I know that's probably where the heart of the matter lies, or at least a critical point within this specific file. I need to understand what's happening at that particular line to fully grasp the code's behavior. I can already start to form some expectations based on the filename, so I'll be very quick with this analysis. |
| 96/3 | 2026/11/22 09:54 | tool | read-file |
0mArgs:{
"File": "drivers/vfio/vfio_main.c",
"FirstLine": 227,
"LineCount": 15
}Results: {
"Contents": " 227:\tstruct vfio_device *_vfio_alloc_device(size_t size, struct device *dev,\n 228:\t\t\t\t\t const struct vfio_device_ops *ops)\n 229:\t{\n 230:\t\tstruct vfio_device *device;\n 231:\t\tint ret;\n 232:\t\n 233:\t\tif (WARN_ON(size \u003c sizeof(struct vfio_device)))\n 234:\t\t\treturn ERR_PTR(-EINVAL);\n 235:\t\n 236:\t\tdevice = kvzalloc(size, GFP_KERNEL);\n 237:\t\tif (!device)\n 238:\t\t\treturn ERR_PTR(-ENOMEM);\n 239:\t\n 240:\t\tret = vfio_init_device(device, dev, ops);\n 241:\t\tif (ret)\n"
} |
| 97/3 | 2026/11/22 09:54 | llm | kmsan-evaluator |
1mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 51809 output: 494 thoughts: 1154 Thoughts: **KMSAN Assessment: No Uninitialized Memory Risks Introduced** Okay, let's break this down. My primary concern here is the introduction or exposure of uninitialized memory vulnerabilities. I've gone through the patch methodically, using a checklist to guide my review. First, I always look for data structures sent to userspace. I've re-verified that all structures passed to userspace, specifically `vfio_device_feature_tph_t` and `vfio_device_feature_tph_resolve`, are properly initialized before being copied. No risks there: padding is handled, and all fields are explicitly assigned. Next, I examined conditional logic that might depend on uninitialized variables. I've thoroughly checked every variable declared and used in the diff, including `pcie_tph_get_st_table_loc`, `pcie_tph_set_st_entries`, `pcie_enable_tph_ext`, `pci_tph_init`, `vfio_tph_config_write`, `vfio_pci_tph_resolve_st_tag`, and `vfio_pci_core_feature_tph_program`. I verified that all variables are initialized before use, especially the initialization of `reg` to 0 where it was previously uninitialized. The loop counters `i` are initialized and controlled. No uninitialized memory is being used for branching decisions. Then, I focused on data structure allocation and initialization. I specifically looked for situations where uninitialized fields in complex structures could be read later. I've confirmed that the primary device structure, `struct vfio_pci_core_device`, is zeroed during allocation using `kvzalloc`. Further allocations such as `kcalloc` are used to allocate memory and the code then iterates through the allocated memory and explicitly sets each element to a known value. Finally, I checked for bounds checks or logic that might allow access to uninitialized portions of buffers. The code in `pcie_tph_set_st_entries` correctly uses the `count` provided by the TPH mode. And in `vfio_pci_core_feature_tph_program`, there's a bounds check `if (program.start >= st_size || program.count == 0 || program.count > st_size - program.start) return -EINVAL;` before reading or writing data. I can confirm that `st_size` is based on the allocated table size and I see no way for a user to access uninitialized memory through this mechanism. Given the careful initialization of all memory regions through explicit assignment, `kcalloc`, or `kvzalloc`, I'm confident there are no uninitialized memory risks introduced by this patch. Regarding the question of running a KMSAN session, that's not needed. KASAN and LOCKDEP will catch concurrency, deadlocks, and standard errors, like array indexing issues, mutex locking issues, and cpuhp callbacks. Since I've rigorously established that no uninitialized memory is read or leaked by this patch, KMSAN wouldn't offer any significant advantage here, and `NeedsKMSAN` can be set to false. |
| 98/3 | 2026/11/22 09:55 | tool | set-results |
0mArgs:{
"KMSANReasoning": "The patch series adds PCIe TPH (TLP Processing Hints) support to VFIO-PCI and refactors helper functions in the PCI core TPH implementation.\n\nAnalysis of uninitialized memory risks:\n1. Structures copied to userspace:\n - `vfio_pci_core_feature_tph`: Copies `struct vfio_device_feature_tph` (4 bytes, single u32 `flags` field) to user space after assigning `flags`. There are no padding bytes or uninitialized fields.\n - `vfio_pci_core_feature_tph_resolve`: Copies `struct vfio_device_feature_tph_resolve` to user space. The structure layout is 12 bytes total (u32 flags, u32 src, u8 valid, u8 rsv, u16 st), matching 4-byte struct alignment with 0 padding bytes. The input fields `flags` and `src` are populated via `copy_from_user`, and all remaining output fields (`valid`, `rsv`, `st`) are explicitly assigned.\n - Config space reads via `vfio_tph_config_read`: Values are either synthesized (0 for out-of-range/table offsets) or read from device config space into pre-initialized stack buffers.\n\n2. Buffers and structures allocated in kernel space:\n - Dynamic allocations use zeroing allocators (`kcalloc` for `tags` and `vdev-\u003etph_st_cpu`, `kvzalloc` for the containing `vfio_pci_core_device`).\n - Local variables such as `reg` in `pcie_tph_get_st_table_loc` and `pci_tph_init` are explicitly initialized to 0.\n\nPotential issues introduced by this patch series (such as bounds checking on ST table sizes, array indexing, mutex locking with `tph_lock`, CPU hotplug state management, or PCI config register accesses) are fully covered by standard bug detectors (KASAN, LOCKDEP, UBSAN). There are no uninitialized memory reads or information leak risks that would warrant a dedicated KMSAN fuzzing session.",
"NeedsKMSAN": false
}Results: {
"KMSANReasoning": "The patch series adds PCIe TPH (TLP Processing Hints) support to VFIO-PCI and refactors helper functions in the PCI core TPH implementation.\n\nAnalysis of uninitialized memory risks:\n1. Structures copied to userspace:\n - `vfio_pci_core_feature_tph`: Copies `struct vfio_device_feature_tph` (4 bytes, single u32 `flags` field) to user space after assigning `flags`. There are no padding bytes or uninitialized fields.\n - `vfio_pci_core_feature_tph_resolve`: Copies `struct vfio_device_feature_tph_resolve` to user space. The structure layout is 12 bytes total (u32 flags, u32 src, u8 valid, u8 rsv, u16 st), matching 4-byte struct alignment with 0 padding bytes. The input fields `flags` and `src` are populated via `copy_from_user`, and all remaining output fields (`valid`, `rsv`, `st`) are explicitly assigned.\n - Config space reads via `vfio_tph_config_read`: Values are either synthesized (0 for out-of-range/table offsets) or read from device config space into pre-initialized stack buffers.\n\n2. Buffers and structures allocated in kernel space:\n - Dynamic allocations use zeroing allocators (`kcalloc` for `tags` and `vdev-\u003etph_st_cpu`, `kvzalloc` for the containing `vfio_pci_core_device`).\n - Local variables such as `reg` in `pcie_tph_get_st_table_loc` and `pci_tph_init` are explicitly initialized to 0.\n\nPotential issues introduced by this patch series (such as bounds checking on ST table sizes, array indexing, mutex locking with `tph_lock`, CPU hotplug state management, or PCI config register accesses) are fully covered by standard bug detectors (KASAN, LOCKDEP, UBSAN). There are no uninitialized memory reads or information leak risks that would warrant a dedicated KMSAN fuzzing session.",
"NeedsKMSAN": false
} |
| Total Calls | Total Tokens | Avg Tokens | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|
| Total Calls | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|