| Seq | Timestamp | Type | Name | Duration |
|---|---|---|---|---|
| 0/0 | 2026/10/11 07:56 | flow | patch-triage |
0mArgs:null Results: {
"EnableConfigs": null,
"FocusSymbols": [],
"KMSANReasoning": "",
"NeedsKMSAN": false,
"Reasoning": "The patch introduces a VFIO PCI variant driver (qcom-vfio-pci), helper function pci_find_free_ext_cap_offset(), and MSI/reset handling adjustments in the Qualcomm ath11k and ath12k PCI drivers. All modified code specifically targets physical Qualcomm WiFi PCIe hardware (ath11k and ath12k chipsets) for device operation and host-to-VM passthrough. Standard virtualized fuzzing environments (QEMU/GCE) lack emulation for these Qualcomm PCIe devices, making the code structurally unreachable.",
"WorthFuzzing": false
} |
| 1/1 | 2026/10/11 07:56 | action | read-patch-diff |
0mArgs:null Results: {
"PatchDiff": "commit 643a03b7a3fd62832c4426cfdc4830c0c5b9182b\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate: Sun Oct 11 07:56:07 2026 +0000\n\n syz-cluster: applied patch under review\n\ndiff --git a/drivers/net/wireless/ath/ath11k/pci.c b/drivers/net/wireless/ath/ath11k/pci.c\nindex a163168f36176..35883abdf12e0 100644\n--- a/drivers/net/wireless/ath/ath11k/pci.c\n+++ b/drivers/net/wireless/ath/ath11k/pci.c\n@@ -10,6 +10,7 @@\n #include \u003clinux/of.h\u003e\n #include \u003clinux/time.h\u003e\n #include \u003clinux/vmalloc.h\u003e\n+#include \u003clinux/qcom_vfio.h\u003e\n \n #include \"pci.h\"\n #include \"core.h\"\n@@ -190,8 +191,10 @@ static void ath11k_pci_restore_window(struct ath11k_base *ab)\n \tspin_unlock_bh(\u0026ab_pci-\u003ewindow_lock);\n }\n \n-static void ath11k_pci_soc_global_reset(struct ath11k_base *ab)\n+static int ath11k_pci_soc_global_reset(struct ath11k_base *ab)\n {\n+\tbool link_recovered = false;\n+\tint retries = 250;\n \tu32 val, delay;\n \n \tval = ath11k_pcic_read32(ab, PCIE_SOC_GLOBAL_RESET);\n@@ -215,14 +218,28 @@ static void ath11k_pci_soc_global_reset(struct ath11k_base *ab)\n \n \tmdelay(delay);\n \n-\tval = ath11k_pcic_read32(ab, PCIE_SOC_GLOBAL_RESET);\n-\tif (val == 0xffffffff)\n-\t\tath11k_warn(ab, \"link down error during global reset\\n\");\n+\t/* Wait for PCIe link to recover, especially important in VM environments\n+\t * where timing can vary significantly from bare metal.\n+\t */\n+\twhile (retries-- \u003e 0) {\n+\t\tval = ath11k_pcic_read32(ab, PCIE_SOC_GLOBAL_RESET);\n+\t\tif (val != 0xffffffff) {\n+\t\t\tlink_recovered = true;\n+\t\t\tbreak;\n+\t\t}\n+\t\tmdelay(20);\n+\t}\n+\tif (!link_recovered) {\n+\t\tath11k_err(ab, \"PCIe link failed to recover - device may need power cycle\\n\");\n+\t\treturn -ETIMEDOUT;\n+\t}\n \n \t/* Restore window register as its content is cleared during\n \t * hardware global reset, such that it aligns with host cache.\n \t */\n \tath11k_pci_restore_window(ab);\n+\n+\treturn 0;\n }\n \n static void ath11k_pci_clear_dbg_registers(struct ath11k_base *ab)\n@@ -377,8 +394,10 @@ static void ath11k_pci_force_wake(struct ath11k_base *ab)\n \tmdelay(5);\n }\n \n-static void ath11k_pci_sw_reset(struct ath11k_base *ab, bool power_on)\n+static int ath11k_pci_sw_reset(struct ath11k_base *ab, bool power_on)\n {\n+\tint ret;\n+\n \tmdelay(100);\n \n \tif (power_on) {\n@@ -391,8 +410,12 @@ static void ath11k_pci_sw_reset(struct ath11k_base *ab, bool power_on)\n \n \tath11k_mhi_clear_vector(ab);\n \tath11k_pci_clear_dbg_registers(ab);\n-\tath11k_pci_soc_global_reset(ab);\n+\tret = ath11k_pci_soc_global_reset(ab);\n+\tif (ret)\n+\t\treturn ret;\n \tath11k_mhi_set_mhictrl_reset(ab);\n+\n+\treturn 0;\n }\n \n static void ath11k_pci_init_qmi_ce_config(struct ath11k_base *ab)\n@@ -440,8 +463,11 @@ static int ath11k_pci_alloc_msi(struct ath11k_pci *ab_pci)\n \tstruct ath11k_base *ab = ab_pci-\u003eab;\n \tconst struct ath11k_msi_config *msi_config = ab-\u003epci.msi.config;\n \tstruct pci_dev *pci_dev = ab_pci-\u003epdev;\n+\tu32 msi_addr_lo = 0, msi_addr_hi = 0;\n \tstruct msi_desc *msi_desc;\n+\tu16 msi_data = 0;\n \tint num_vectors;\n+\tint msi_offset;\n \tint ret;\n \n \tnum_vectors = pci_alloc_irq_vectors(pci_dev,\n@@ -465,6 +491,36 @@ static int ath11k_pci_alloc_msi(struct ath11k_pci *ab_pci)\n \t}\n \tath11k_info(ab, \"MSI vectors: %d\\n\", num_vectors);\n \n+\t/*\n+\t * Try to get host MSI address from VFIO cache.\n+\t * When running on a VM, the ath11k firmware requires physical host\n+\t * MSI addresses and cannot handle guest IOVA addresses.\n+\t * qcom-vfio-pci writes host MSI values to extended config space with\n+\t * a magic signature \"QMSI\" for discovery. Search for it.\n+\t */\n+\tmsi_offset = qcom_vfio_find_msi_cache(pci_dev);\n+\tif (msi_offset) {\n+\t\tpci_read_config_dword(pci_dev,\n+\t\t\t\t msi_offset + QCOM_VFIO_MSI_ADDR_LO_OFFSET,\n+\t\t\t\t \u0026msi_addr_lo);\n+\t\tpci_read_config_dword(pci_dev,\n+\t\t\t\t msi_offset + QCOM_VFIO_MSI_ADDR_HI_OFFSET,\n+\t\t\t\t \u0026msi_addr_hi);\n+\t\tpci_read_config_word(pci_dev,\n+\t\t\t\t msi_offset + QCOM_VFIO_MSI_DATA_OFFSET,\n+\t\t\t\t \u0026msi_data);\n+\n+\t\tif (msi_addr_lo \u0026\u0026 msi_addr_lo != 0xFFFFFFFF) {\n+\t\t\tab-\u003epci.msi.addr_lo = msi_addr_lo;\n+\t\t\tab-\u003epci.msi.addr_hi = msi_addr_hi;\n+\t\t\tab-\u003epci.msi.ep_base_data = msi_data;\n+\t\t\tab_pci-\u003evfio_msi_cached = true;\n+\t\t\tath11k_info(ab, \"VFIO MSI cache at offset 0x%x: addr_lo=0x%x addr_hi=0x%x data=%d\\n\",\n+\t\t\t\t msi_offset, msi_addr_lo, msi_addr_hi, msi_data);\n+\t\t\treturn 0;\n+\t\t}\n+\t}\n+\n \tath11k_pci_msi_disable(ab_pci);\n \n \tmsi_desc = irq_get_msi_desc(ab_pci-\u003epdev-\u003eirq);\n@@ -506,6 +562,9 @@ static int ath11k_pci_config_msi_data(struct ath11k_pci *ab_pci)\n {\n \tstruct msi_desc *msi_desc;\n \n+\tif (ab_pci-\u003evfio_msi_cached)\n+\t\treturn 0;\n+\n \tmsi_desc = irq_get_msi_desc(ab_pci-\u003epdev-\u003eirq);\n \tif (!msi_desc) {\n \t\tath11k_err(ab_pci-\u003eab, \"msi_desc is NULL!\\n\");\n@@ -822,7 +881,9 @@ static int ath11k_pci_power_up(struct ath11k_base *ab)\n \n \tab_pci-\u003eregister_window = 0;\n \tclear_bit(ATH11K_FLAG_DEVICE_INIT_DONE, \u0026ab-\u003edev_flags);\n-\tath11k_pci_sw_reset(ab_pci-\u003eab, true);\n+\tret = ath11k_pci_sw_reset(ab_pci-\u003eab, true);\n+\tif (ret)\n+\t\treturn ret;\n \n \t/* Disable ASPM during firmware download due to problems switching\n \t * to AMSS state.\ndiff --git a/drivers/net/wireless/ath/ath11k/pci.h b/drivers/net/wireless/ath/ath11k/pci.h\nindex 1e3005a4b64c6..5229c9db59d7f 100644\n--- a/drivers/net/wireless/ath/ath11k/pci.h\n+++ b/drivers/net/wireless/ath/ath11k/pci.h\n@@ -74,6 +74,8 @@ struct ath11k_pci {\n \tunsigned long flags;\n \tu16 link_ctl;\n \tu64 dma_mask;\n+\n+\tbool vfio_msi_cached;\n };\n \n static inline struct ath11k_pci *ath11k_pci_priv(struct ath11k_base *ab)\ndiff --git a/drivers/net/wireless/ath/ath12k/pci.c b/drivers/net/wireless/ath/ath12k/pci.c\nindex 12bbb75570f1f..8e92213fd3fce 100644\n--- a/drivers/net/wireless/ath/ath12k/pci.c\n+++ b/drivers/net/wireless/ath/ath12k/pci.c\n@@ -8,6 +8,7 @@\n #include \u003clinux/interrupt.h\u003e\n #include \u003clinux/msi.h\u003e\n #include \u003clinux/pci.h\u003e\n+#include \u003clinux/qcom_vfio.h\u003e\n #include \u003clinux/time.h\u003e\n #include \u003clinux/vmalloc.h\u003e\n \n@@ -181,8 +182,10 @@ static void ath12k_pci_restore_window(struct ath12k_base *ab)\n \tspin_unlock_bh(\u0026ab_pci-\u003ewindow_lock);\n }\n \n-static void ath12k_pci_soc_global_reset(struct ath12k_base *ab)\n+static int ath12k_pci_soc_global_reset(struct ath12k_base *ab)\n {\n+\tbool link_recovered = false;\n+\tint retries = 250;\n \tu32 val, delay;\n \n \tval = ath12k_pci_read32(ab, PCIE_SOC_GLOBAL_RESET);\n@@ -206,14 +209,28 @@ static void ath12k_pci_soc_global_reset(struct ath12k_base *ab)\n \n \tmdelay(delay);\n \n-\tval = ath12k_pci_read32(ab, PCIE_SOC_GLOBAL_RESET);\n-\tif (val == 0xffffffff)\n-\t\tath12k_warn(ab, \"link down error during global reset\\n\");\n+\t/* Wait for PCIe link to recover, especially important in VM environments\n+\t * where timing can vary significantly from bare metal.\n+\t */\n+\twhile (retries-- \u003e 0) {\n+\t\tval = ath12k_pci_read32(ab, PCIE_SOC_GLOBAL_RESET);\n+\t\tif (val != 0xffffffff) {\n+\t\t\tlink_recovered = true;\n+\t\t\tbreak;\n+\t\t}\n+\t\tmdelay(20);\n+\t}\n+\tif (!link_recovered) {\n+\t\tath12k_err(ab, \"PCIe link failed to recover - device may need power cycle\\n\");\n+\t\treturn -ETIMEDOUT;\n+\t}\n \n \t/* Restore window register as its content is cleared during\n \t * hardware global reset, such that it aligns with host cache.\n \t */\n \tath12k_pci_restore_window(ab);\n+\n+\treturn 0;\n }\n \n static void ath12k_pci_clear_dbg_registers(struct ath12k_base *ab)\n@@ -299,8 +316,10 @@ static void ath12k_pci_force_wake(struct ath12k_base *ab)\n \tmdelay(5);\n }\n \n-static void ath12k_pci_sw_reset(struct ath12k_base *ab, bool power_on)\n+static int ath12k_pci_sw_reset(struct ath12k_base *ab, bool power_on)\n {\n+\tint ret;\n+\n \tif (power_on) {\n \t\tath12k_pci_enable_ltssm(ab);\n \t\tath12k_pci_clear_all_intrs(ab);\n@@ -309,8 +328,12 @@ static void ath12k_pci_sw_reset(struct ath12k_base *ab, bool power_on)\n \n \tath12k_mhi_clear_vector(ab);\n \tath12k_pci_clear_dbg_registers(ab);\n-\tath12k_pci_soc_global_reset(ab);\n+\tret = ath12k_pci_soc_global_reset(ab);\n+\tif (ret)\n+\t\treturn ret;\n \tath12k_mhi_set_mhictrl_reset(ab);\n+\n+\treturn 0;\n }\n \n static void ath12k_pci_free_ce_irq(struct ath12k_base *ab, int num_ce)\n@@ -760,8 +783,11 @@ static int ath12k_pci_msi_alloc(struct ath12k_pci *ab_pci)\n {\n \tstruct ath12k_base *ab = ab_pci-\u003eab;\n \tconst struct ath12k_msi_config *msi_config = ab_pci-\u003emsi_config;\n+\tu32 msi_addr_lo = 0, msi_addr_hi = 0;\n \tstruct msi_desc *msi_desc;\n+\tu16 msi_data = 0;\n \tint num_vectors;\n+\tint msi_offset;\n \tint ret;\n \n \tnum_vectors = pci_alloc_irq_vectors(ab_pci-\u003epdev,\n@@ -789,6 +815,39 @@ static int ath12k_pci_msi_alloc(struct ath12k_pci *ab_pci)\n \n \tath12k_info(ab, \"MSI vectors: %d\\n\", num_vectors);\n \n+\t/*\n+\t * Try to get host MSI address from VFIO cache.\n+\t * When running on a VM, the ath12k firmware requires physical host\n+\t * MSI addresses and cannot handle guest IOVA addresses.\n+\t * qcom-vfio-pci writes host MSI values to extended config space with\n+\t * a magic signature \"QMSI\" for discovery. Search for it.\n+\t */\n+\tmsi_offset = qcom_vfio_find_msi_cache(ab_pci-\u003epdev);\n+\tif (msi_offset) {\n+\t\tpci_read_config_dword(ab_pci-\u003epdev,\n+\t\t\t\t msi_offset + QCOM_VFIO_MSI_ADDR_LO_OFFSET,\n+\t\t\t\t \u0026msi_addr_lo);\n+\t\tpci_read_config_dword(ab_pci-\u003epdev,\n+\t\t\t\t msi_offset + QCOM_VFIO_MSI_ADDR_HI_OFFSET,\n+\t\t\t\t \u0026msi_addr_hi);\n+\t\tpci_read_config_word(ab_pci-\u003epdev,\n+\t\t\t\t msi_offset + QCOM_VFIO_MSI_DATA_OFFSET,\n+\t\t\t\t \u0026msi_data);\n+\n+\t\tif (msi_addr_lo \u0026\u0026 msi_addr_lo != 0xFFFFFFFF) {\n+\t\t\tab_pci-\u003emsi_addr_hi = msi_addr_hi;\n+\t\t\tab_pci-\u003emsi_addr_lo = msi_addr_lo;\n+\t\t\tab_pci-\u003emsi_ep_base_data = msi_data;\n+\t\t\tab_pci-\u003emsi_addr_cached = true;\n+\n+\t\t\tath12k_info(ab,\n+\t\t\t\t \"using host MSI from VFIO at offset 0x%x: addr_lo=0x%x addr_hi=0x%x data=%d\\n\",\n+\t\t\t\t msi_offset, msi_addr_lo, msi_addr_hi, msi_data);\n+\t\t\treturn 0;\n+\t\t}\n+\t}\n+\tab_pci-\u003emsi_addr_cached = false;\n+\n \tath12k_pci_msi_disable(ab_pci);\n \n \tmsi_desc = irq_get_msi_desc(ab_pci-\u003epdev-\u003eirq);\n@@ -822,6 +881,9 @@ static int ath12k_pci_config_msi_data(struct ath12k_pci *ab_pci)\n {\n \tstruct msi_desc *msi_desc;\n \n+\tif (ab_pci-\u003emsi_addr_cached)\n+\t\treturn 0;\n+\n \tmsi_desc = irq_get_msi_desc(ab_pci-\u003epdev-\u003eirq);\n \tif (!msi_desc) {\n \t\tath12k_err(ab_pci-\u003eab, \"msi_desc is NULL!\\n\");\n@@ -1060,6 +1122,12 @@ void ath12k_pci_get_msi_address(struct ath12k_base *ab, u32 *msi_addr_lo,\n \tstruct ath12k_pci *ab_pci = ath12k_pci_priv(ab);\n \tstruct pci_dev *pci_dev = to_pci_dev(ab-\u003edev);\n \n+\tif (ab_pci-\u003emsi_addr_cached) {\n+\t\t*msi_addr_hi = ab_pci-\u003emsi_addr_hi;\n+\t\t*msi_addr_lo = ab_pci-\u003emsi_addr_lo;\n+\t\treturn;\n+\t}\n+\n \tpci_read_config_dword(pci_dev, pci_dev-\u003emsi_cap + PCI_MSI_ADDRESS_LO,\n \t\t\t msi_addr_lo);\n \n@@ -1452,7 +1520,9 @@ int ath12k_pci_power_up(struct ath12k_base *ab)\n \n \tab_pci-\u003eregister_window = 0;\n \tclear_bit(ATH12K_PCI_FLAG_INIT_DONE, \u0026ab_pci-\u003eflags);\n-\tath12k_pci_sw_reset(ab_pci-\u003eab, true);\n+\tret = ath12k_pci_sw_reset(ab_pci-\u003eab, true);\n+\tif (ret)\n+\t\treturn ret;\n \n \t/* Disable ASPM during firmware download due to problems switching\n \t * to AMSS state.\ndiff --git a/drivers/net/wireless/ath/ath12k/pci.h b/drivers/net/wireless/ath/ath12k/pci.h\nindex 0e0e2020c6ae5..ee3696d40dfb6 100644\n--- a/drivers/net/wireless/ath/ath12k/pci.h\n+++ b/drivers/net/wireless/ath/ath12k/pci.h\n@@ -129,6 +129,12 @@ struct ath12k_pci {\n \t/* enum ath12k_pci_flags */\n \tunsigned long flags;\n \tu16 link_ctl;\n+\n+\t/* Cached host MSI address for firmware configuration in VMs */\n+\tu32 msi_addr_hi;\n+\tu32 msi_addr_lo;\n+\tbool msi_addr_cached;\n+\n \tunsigned long irq_flags;\n \tconst struct ath12k_pci_ops *pci_ops;\n \tu32 qmi_instance;\ndiff --git a/drivers/pci/pci.c b/drivers/pci/pci.c\nindex 8cc6a89130b53..ae234c9a2a29b 100644\n--- a/drivers/pci/pci.c\n+++ b/drivers/pci/pci.c\n@@ -544,6 +544,78 @@ u16 pci_find_ext_capability(struct pci_dev *dev, int cap)\n }\n EXPORT_SYMBOL_GPL(pci_find_ext_capability);\n \n+/**\n+ * pci_find_free_ext_cap_offset - Find free space in extended config\n+ * @dev: PCI device to query\n+ * @size: Minimum size needed (in bytes)\n+ *\n+ * Scans the extended capability chain and then searches for a contiguous\n+ * region of zeroed space of at least @size bytes in the extended\n+ * configuration space (0x100-0xFFF). This can be used by drivers that\n+ * need to use unused extended config space for device-specific purposes\n+ * (e.g., VFIO quirks for VM passthrough).\n+ *\n+ * Returns the offset to free space, or 0 if no suitable gap found.\n+ */\n+int pci_find_free_ext_cap_offset(struct pci_dev *dev, size_t size)\n+{\n+\tint ttl = (PCI_CFG_SPACE_EXP_SIZE - PCI_CFG_SPACE_SIZE) / 8;\n+\tint pos = PCI_CFG_SPACE_SIZE;\n+\tint start = 0, run = 0;\n+\tint highest_pos = 0;\n+\tu32 header;\n+\tint offset;\n+\n+\tif (!pci_is_pcie(dev) || dev-\u003ecfg_size \u003c= PCI_CFG_SPACE_SIZE)\n+\t\treturn 0;\n+\n+\tif (size == 0 || size \u003e PCI_CFG_SPACE_EXP_SIZE - PCI_CFG_SPACE_SIZE)\n+\t\treturn 0;\n+\n+\tif (pci_read_config_dword(dev, pos, \u0026header))\n+\t\treturn 0;\n+\tif (header == 0 || header == 0xffffffff)\n+\t\treturn 0;\n+\n+\twhile (ttl-- \u003e 0) {\n+\t\tif (pos \u003e highest_pos)\n+\t\t\thighest_pos = pos;\n+\n+\t\tpos = PCI_EXT_CAP_NEXT(header);\n+\t\tif (!pos || pos \u003c PCI_CFG_SPACE_SIZE)\n+\t\t\tbreak;\n+\n+\t\tif (pci_read_config_dword(dev, pos, \u0026header))\n+\t\t\tbreak;\n+\t\tif (header == 0 || header == 0xffffffff)\n+\t\t\tbreak;\n+\t}\n+\n+\tif (!highest_pos)\n+\t\treturn 0;\n+\n+\tfor (offset = highest_pos; offset \u003c= (int)PCI_CFG_SPACE_EXP_SIZE - 4;\n+\t offset += 4) {\n+\t\tu32 val;\n+\n+\t\tif (pci_read_config_dword(dev, offset, \u0026val))\n+\t\t\tbreak;\n+\n+\t\tif (val == 0) {\n+\t\t\tif (run == 0)\n+\t\t\t\tstart = offset;\n+\t\t\trun += 4;\n+\t\t\tif (run \u003e= (int)size)\n+\t\t\t\treturn start;\n+\t\t} else {\n+\t\t\trun = 0;\n+\t\t}\n+\t}\n+\n+\treturn 0;\n+}\n+EXPORT_SYMBOL_GPL(pci_find_free_ext_cap_offset);\n+\n /**\n * pci_get_dsn - Read and return the 8-byte Device Serial Number\n * @dev: PCI device to query\ndiff --git a/drivers/vfio/pci/Kconfig b/drivers/vfio/pci/Kconfig\nindex 296bf01e185ec..237a29443bf58 100644\n--- a/drivers/vfio/pci/Kconfig\n+++ b/drivers/vfio/pci/Kconfig\n@@ -72,6 +72,8 @@ source \"drivers/vfio/pci/nvgrace-gpu/Kconfig\"\n \n source \"drivers/vfio/pci/qat/Kconfig\"\n \n+source \"drivers/vfio/pci/qcom/Kconfig\"\n+\n source \"drivers/vfio/pci/xe/Kconfig\"\n \n endmenu\ndiff --git a/drivers/vfio/pci/Makefile b/drivers/vfio/pci/Makefile\nindex 6138f1bf241df..63db19102850d 100644\n--- a/drivers/vfio/pci/Makefile\n+++ b/drivers/vfio/pci/Makefile\n@@ -23,4 +23,6 @@ obj-$(CONFIG_NVGRACE_GPU_VFIO_PCI) += nvgrace-gpu/\n \n obj-$(CONFIG_QAT_VFIO_PCI) += qat/\n \n+obj-$(CONFIG_QCOM_VFIO_PCI) += qcom/\n+\n obj-$(CONFIG_XE_VFIO_PCI) += xe/\ndiff --git a/drivers/vfio/pci/qcom/Kconfig b/drivers/vfio/pci/qcom/Kconfig\nnew file mode 100644\nindex 0000000000000..e284b91cabf0d\n--- /dev/null\n+++ b/drivers/vfio/pci/qcom/Kconfig\n@@ -0,0 +1,22 @@\n+# SPDX-License-Identifier: GPL-2.0-only\n+config QCOM_VFIO_PCI\n+\ttristate \"VFIO support for Qualcomm PCI devices\"\n+\tdepends on PCI\n+\tselect VFIO_PCI_CORE\n+\thelp\n+\t This provides VFIO support for Qualcomm PCI devices with device-specific\n+\t quirks. Currently supports:\n+\t - Qualcomm ath11k WiFi (Device ID 0x1103)\n+\t - Qualcomm ath12k WiFi (Device ID 0x1107)\n+\n+\t These devices require special handling for MSI address/data passthrough\n+\t when used with VFIO. The firmware expects physical host MSI addresses\n+\t rather than guest IOVA addresses.\n+\n+\t The VM must have IOMMU interrupt remapping and caching mode enabled.\n+\t For example, with libvirt/QEMU on Intel, add to the domain XML:\n+\t \u003ciommu model=\"intel\"\u003e\n+\t \u003cdriver intremap=\"on\" caching_mode=\"on\"/\u003e\n+\t \u003c/iommu\u003e\n+\n+\t If you don't know what to do here, say N.\ndiff --git a/drivers/vfio/pci/qcom/Makefile b/drivers/vfio/pci/qcom/Makefile\nnew file mode 100644\nindex 0000000000000..dc48d87d1ef61\n--- /dev/null\n+++ b/drivers/vfio/pci/qcom/Makefile\n@@ -0,0 +1,3 @@\n+# SPDX-License-Identifier: GPL-2.0-only\n+obj-$(CONFIG_QCOM_VFIO_PCI) += qcom-vfio-pci.o\n+qcom-vfio-pci-y := main.o msi_quirk.o\ndiff --git a/drivers/vfio/pci/qcom/main.c b/drivers/vfio/pci/qcom/main.c\nnew file mode 100644\nindex 0000000000000..8773661d29a10\n--- /dev/null\n+++ b/drivers/vfio/pci/qcom/main.c\n@@ -0,0 +1,285 @@\n+// SPDX-License-Identifier: GPL-2.0-only\n+// SPDX-FileCopyrightText: Copyright Red Hat\n+\n+#include \u003clinux/device.h\u003e\n+#include \u003clinux/module.h\u003e\n+#include \u003clinux/pci.h\u003e\n+#include \u003clinux/stddef.h\u003e\n+#include \u003clinux/string.h\u003e\n+#include \u003clinux/types.h\u003e\n+#include \u003clinux/uaccess.h\u003e\n+#include \u003clinux/vfio.h\u003e\n+#include \u003clinux/vfio_pci_core.h\u003e\n+#include \u003cuapi/linux/vfio.h\u003e\n+\n+#include \"qcom_vfio_pci.h\"\n+\n+static struct qcom_vfio_pci_device *to_qcom_vdev(struct vfio_pci_core_device *vdev)\n+{\n+\treturn container_of(vdev, struct qcom_vfio_pci_device, vdev);\n+}\n+\n+/*\n+ * Intercept config space read operations to return cached host MSI values.\n+ * Call core VFIO if not intercepted.\n+ */\n+static ssize_t qcom_vfio_pci_read(struct vfio_device *core_vdev, char __user *buf,\n+\t\t\t\t size_t count, loff_t *ppos)\n+{\n+\tstruct vfio_pci_core_device *vdev =\n+\t\tcontainer_of(core_vdev, struct vfio_pci_core_device, vdev);\n+\tstruct qcom_vfio_pci_device *qdev = to_qcom_vdev(vdev);\n+\tunsigned int index = VFIO_PCI_OFFSET_TO_INDEX(*ppos);\n+\tloff_t offset = *ppos \u0026 VFIO_PCI_OFFSET_MASK;\n+\tssize_t ret;\n+\n+\tif (index == VFIO_PCI_CONFIG_REGION_INDEX) {\n+\t\tret = qcom_vfio_pci_config_rw(qdev, buf, count, offset, false);\n+\t\tif (ret != -ENOTTY) {\n+\t\t\tif (ret \u003e 0)\n+\t\t\t\t*ppos += ret;\n+\t\t\treturn ret;\n+\t\t}\n+\t}\n+\n+\treturn vfio_pci_core_read(core_vdev, buf, count, ppos);\n+}\n+\n+static int qcom_vfio_pci_init_dev(struct vfio_device *core_vdev)\n+{\n+\tstruct qcom_vfio_pci_device *qdev =\n+\t\tcontainer_of(core_vdev, struct qcom_vfio_pci_device, vdev.vdev);\n+\tstruct pci_dev *pdev = to_pci_dev(core_vdev-\u003edev);\n+\tint ret;\n+\n+\tret = vfio_pci_core_init_dev(core_vdev);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tqdev-\u003emsi_offset = qcom_vfio_find_msi_offset(pdev);\n+\tif (!qdev-\u003emsi_offset) {\n+\t\tpci_err(pdev, \"No free space in extended config for MSI quirk\\n\");\n+\t\tpci_err(pdev, \"qcom-vfio-pci cannot function without MSI passthrough, failing probe\\n\");\n+\t\tvfio_pci_core_release_dev(core_vdev);\n+\t\treturn -ENODEV;\n+\t}\n+\tpci_info(pdev, \"MSI passthrough quirk using offset 0x%x\\n\", qdev-\u003emsi_offset);\n+\n+\tqdev-\u003emsi_cached = false;\n+\tqdev-\u003emsi_addr_lo = 0;\n+\tqdev-\u003emsi_addr_hi = 0;\n+\tqdev-\u003emsi_data = 0;\n+\n+\treturn 0;\n+}\n+\n+static const struct vfio_pci_device_ops qcom_vfio_pci_device_ops = {\n+\t/* No device-specific operations needed */\n+};\n+\n+static int qcom_vfio_pci_open_device(struct vfio_device *core_vdev)\n+{\n+\tstruct qcom_vfio_pci_device *qdev =\n+\t\tcontainer_of(core_vdev, struct qcom_vfio_pci_device, vdev.vdev);\n+\tstruct vfio_pci_core_device *vdev = \u0026qdev-\u003evdev;\n+\tint ret;\n+\n+\tret = vfio_pci_core_enable(vdev);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tvfio_pci_core_finish_enable(vdev);\n+\treturn 0;\n+}\n+\n+static void qcom_vfio_pci_close_device(struct vfio_device *core_vdev)\n+{\n+\tstruct qcom_vfio_pci_device *qdev =\n+\t\tcontainer_of(core_vdev, struct qcom_vfio_pci_device, vdev.vdev);\n+\n+\tqdev-\u003emsi_cached = false;\n+\tqdev-\u003emsi_addr_lo = 0;\n+\tqdev-\u003emsi_addr_hi = 0;\n+\tqdev-\u003emsi_data = 0;\n+\n+\tvfio_pci_core_close_device(core_vdev);\n+}\n+\n+/*\n+ * Wrap ioctl to intercept MSI allocation and cache host MSI values.\n+ * This is called after QEMU allocates MSI via VFIO_DEVICE_SET_IRQS.\n+ */\n+static long qcom_vfio_pci_ioctl(struct vfio_device *core_vdev,\n+\t\t\t\tunsigned int cmd, unsigned long arg)\n+{\n+\tstruct vfio_pci_core_device *vdev =\n+\t\tcontainer_of(core_vdev, struct vfio_pci_core_device, vdev);\n+\tstruct qcom_vfio_pci_device *qdev = to_qcom_vdev(vdev);\n+\tbool is_msi_trigger = false;\n+\tstruct vfio_irq_set hdr;\n+\tlong ret;\n+\n+\t/*\n+\t * Pre-fetch SET_IRQS header to avoid TOCTOU from\n+\t * re-reading userspace after the core ioctl completes.\n+\t */\n+\tif (cmd == VFIO_DEVICE_SET_IRQS) {\n+\t\tunsigned long minsz = offsetofend(struct vfio_irq_set, count);\n+\n+\t\tif (!copy_from_user(\u0026hdr, (void __user *)arg, minsz)) {\n+\t\t\tis_msi_trigger = (hdr.index == VFIO_PCI_MSI_IRQ_INDEX \u0026\u0026\n+\t\t\t\t\t (hdr.flags \u0026 VFIO_IRQ_SET_ACTION_TRIGGER));\n+\t\t\tif (is_msi_trigger)\n+\t\t\t\tpci_dbg(qdev-\u003evdev.pdev,\n+\t\t\t\t\t\"SET_IRQS: idx=%u flags=0x%x start=%u count=%u\\n\",\n+\t\t\t\t\thdr.index, hdr.flags, hdr.start, hdr.count);\n+\t\t}\n+\t}\n+\n+\tret = vfio_pci_core_ioctl(core_vdev, cmd, arg);\n+\n+\tif (ret == 0 \u0026\u0026 is_msi_trigger \u0026\u0026 !qdev-\u003emsi_cached)\n+\t\tqcom_cache_and_write_msi(qdev);\n+\n+\treturn ret;\n+}\n+\n+static const struct vfio_device_ops qcom_vfio_pci_ops = {\n+\t.name\t\t= \"qcom-vfio-pci\",\n+\t.init\t\t= qcom_vfio_pci_init_dev,\n+\t.release\t= vfio_pci_core_release_dev,\n+\t.open_device\t= qcom_vfio_pci_open_device,\n+\t.close_device\t= qcom_vfio_pci_close_device,\n+\t.ioctl\t\t= qcom_vfio_pci_ioctl,\n+\t.get_region_info_caps = vfio_pci_ioctl_get_region_info,\n+\t.device_feature\t= vfio_pci_core_ioctl_feature,\n+\t.read\t\t= qcom_vfio_pci_read,\n+\t.write\t\t= vfio_pci_core_write,\n+\t.mmap\t\t= vfio_pci_core_mmap,\n+\t.request\t= vfio_pci_core_request,\n+\t.match\t\t= vfio_pci_core_match,\n+\t.match_token_uuid = vfio_pci_core_match_token_uuid,\n+\t.bind_iommufd\t= vfio_iommufd_physical_bind,\n+\t.unbind_iommufd\t= vfio_iommufd_physical_unbind,\n+\t.attach_ioas\t= vfio_iommufd_physical_attach_ioas,\n+\t.detach_ioas\t= vfio_iommufd_physical_detach_ioas,\n+};\n+\n+static int qcom_vfio_pci_probe(struct pci_dev *pdev,\n+\t\t\t const struct pci_device_id *id)\n+{\n+\tstruct qcom_vfio_pci_device *qdev;\n+\tint ret;\n+\n+\tqdev = vfio_alloc_device(qcom_vfio_pci_device, vdev.vdev,\n+\t\t\t\t \u0026pdev-\u003edev, \u0026qcom_vfio_pci_ops);\n+\tif (IS_ERR(qdev))\n+\t\treturn PTR_ERR(qdev);\n+\n+\tdev_set_drvdata(\u0026pdev-\u003edev, \u0026qdev-\u003evdev);\n+\tqdev-\u003evdev.pci_ops = \u0026qcom_vfio_pci_device_ops;\n+\tret = vfio_pci_core_register_device(\u0026qdev-\u003evdev);\n+\tif (ret)\n+\t\tgoto out_put_vdev;\n+\n+\treturn 0;\n+\n+out_put_vdev:\n+\tvfio_put_device(\u0026qdev-\u003evdev.vdev);\n+\treturn ret;\n+}\n+\n+static void qcom_vfio_pci_remove(struct pci_dev *pdev)\n+{\n+\tstruct vfio_pci_core_device *vdev = dev_get_drvdata(\u0026pdev-\u003edev);\n+\tstruct qcom_vfio_pci_device *qdev = to_qcom_vdev(vdev);\n+\n+\tvfio_pci_core_unregister_device(\u0026qdev-\u003evdev);\n+\tvfio_put_device(\u0026qdev-\u003evdev.vdev);\n+}\n+\n+static const struct pci_device_id qcom_vfio_pci_table[] = {\n+\t/* Qualcomm ath11k WiFi */\n+\t{ PCI_DRIVER_OVERRIDE_DEVICE_VFIO(PCI_VENDOR_ID_QCOM, 0x1103) },\n+\t/* Qualcomm ath12k WiFi */\n+\t{ PCI_DRIVER_OVERRIDE_DEVICE_VFIO(PCI_VENDOR_ID_QCOM, 0x1107) },\n+\t{ }\n+};\n+\n+MODULE_DEVICE_TABLE(pci, qcom_vfio_pci_table);\n+\n+static struct pci_driver qcom_vfio_pci_driver = {\n+\t.name\t\t\t= \"qcom-vfio-pci\",\n+\t.id_table\t\t= qcom_vfio_pci_table,\n+\t.probe\t\t\t= qcom_vfio_pci_probe,\n+\t.remove\t\t\t= qcom_vfio_pci_remove,\n+\t.driver_managed_dma\t= true,\n+};\n+\n+static char ids[1024] __initdata;\n+module_param_string(ids, ids, sizeof(ids), 0);\n+MODULE_PARM_DESC(ids, \"Initial PCI IDs to add to the driver, format is \\\"vendor:device[:subvendor[:subdevice[:class[:class_mask]]]]\\\" and multiple comma separated entries can be specified\");\n+\n+static void __init qcom_vfio_pci_fill_ids(void)\n+{\n+\tchar *p, *id;\n+\tint rc;\n+\n+\tif (ids[0] == '\\0')\n+\t\treturn;\n+\n+\tp = ids;\n+\twhile ((id = strsep(\u0026p, \",\"))) {\n+\t\tunsigned int vendor, device, subvendor = PCI_ANY_ID,\n+\t\t\tsubdevice = PCI_ANY_ID, class = 0, class_mask = 0;\n+\t\tint fields;\n+\n+\t\tif (!strlen(id))\n+\t\t\tcontinue;\n+\n+\t\tfields = sscanf(id, \"%x:%x:%x:%x:%x:%x\",\n+\t\t\t\t\u0026vendor, \u0026device, \u0026subvendor, \u0026subdevice,\n+\t\t\t\t\u0026class, \u0026class_mask);\n+\n+\t\tif (fields \u003c 2) {\n+\t\t\tpr_warn(\"qcom-vfio-pci: invalid id string \\\"%s\\\"\\n\", id);\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\trc = pci_add_dynid(\u0026qcom_vfio_pci_driver, vendor, device,\n+\t\t\t\t subvendor, subdevice, class, class_mask, 0);\n+\t\tif (rc)\n+\t\t\tpr_warn(\"qcom-vfio-pci: failed to add dynamic id [%04x:%04x[%04x:%04x]] class %#08x/%08x (%d)\\n\",\n+\t\t\t\tvendor, device, subvendor, subdevice,\n+\t\t\t\tclass, class_mask, rc);\n+\t\telse\n+\t\t\tpr_info(\"qcom-vfio-pci: add [%04x:%04x[%04x:%04x]] class %#08x/%08x\\n\",\n+\t\t\t\tvendor, device, subvendor, subdevice,\n+\t\t\t\tclass, class_mask);\n+\t}\n+}\n+\n+static int __init qcom_vfio_pci_init(void)\n+{\n+\tint ret;\n+\n+\tret = pci_register_driver(\u0026qcom_vfio_pci_driver);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tqcom_vfio_pci_fill_ids();\n+\n+\treturn 0;\n+}\n+\n+static void __exit qcom_vfio_pci_exit(void)\n+{\n+\tpci_unregister_driver(\u0026qcom_vfio_pci_driver);\n+}\n+\n+module_init(qcom_vfio_pci_init);\n+module_exit(qcom_vfio_pci_exit);\n+\n+MODULE_LICENSE(\"GPL\");\n+MODULE_AUTHOR(\"Jose Ignacio Tornos Martinez \u003cjtornosm@redhat.com\u003e\");\n+MODULE_DESCRIPTION(\"Qualcomm VFIO PCI - Device-Specific VFIO PCI driver for Qualcomm devices\");\ndiff --git a/drivers/vfio/pci/qcom/msi_quirk.c b/drivers/vfio/pci/qcom/msi_quirk.c\nnew file mode 100644\nindex 0000000000000..b717aff37ffc8\n--- /dev/null\n+++ b/drivers/vfio/pci/qcom/msi_quirk.c\n@@ -0,0 +1,163 @@\n+// SPDX-License-Identifier: GPL-2.0-only\n+// SPDX-FileCopyrightText: Copyright Red Hat\n+\n+#include \u003clinux/kernel.h\u003e\n+#include \u003clinux/msi.h\u003e\n+#include \u003clinux/pci.h\u003e\n+#include \u003clinux/uaccess.h\u003e\n+#include \u003clinux/vfio_pci_core.h\u003e\n+\n+#include \"qcom_vfio_pci.h\"\n+\n+/**\n+ * qcom_cache_and_write_msi - Cache host MSI address and data\n+ * @qdev: Qualcomm VFIO device\n+ *\n+ * Called after QEMU allocates MSI via SET_IRQS ioctl to cache the physical\n+ * host MSI addresses that will be returned to the VM driver.\n+ */\n+void qcom_cache_and_write_msi(struct qcom_vfio_pci_device *qdev)\n+{\n+\tstruct pci_dev *pdev = qdev-\u003evdev.pdev;\n+\tstruct device *dev = \u0026pdev-\u003edev;\n+\tstruct msi_desc *desc;\n+\tu32 addr_lo, addr_hi;\n+\tu16 data;\n+\n+\tif (qdev-\u003emsi_cached)\n+\t\treturn;\n+\n+\tif (!qdev-\u003emsi_offset)\n+\t\treturn;\n+\n+\t__msi_lock_descs(dev);\n+\tdesc = msi_first_desc(dev, MSI_DESC_ASSOCIATED);\n+\tif (!desc) {\n+\t\t__msi_unlock_descs(dev);\n+\t\tpci_warn(pdev, \"MSI descriptor not found\\n\");\n+\t\treturn;\n+\t}\n+\n+\taddr_lo = desc-\u003emsg.address_lo;\n+\taddr_hi = desc-\u003emsg.address_hi;\n+\tdata = desc-\u003emsg.data;\n+\t__msi_unlock_descs(dev);\n+\n+\tpci_dbg(pdev, \"MSI descriptor - addr_lo=0x%x addr_hi=0x%x data=0x%x\\n\",\n+\t\t addr_lo, addr_hi, data);\n+\n+\t/*\n+\t * Validate: address must be valid. Data can be 0 with interrupt remapping.\n+\t * When Intel VT-d interrupt remapping is enabled, the MSI data field\n+\t * contains an index into the interrupt remapping table, which can be 0.\n+\t * We cache it anyway since that's what the VM driver will program.\n+\t */\n+\tif (!addr_lo) {\n+\t\tpci_warn(pdev, \"MSI address invalid, skipping cache\\n\");\n+\t\treturn;\n+\t}\n+\tqdev-\u003emsi_addr_lo = addr_lo;\n+\tqdev-\u003emsi_addr_hi = addr_hi;\n+\tqdev-\u003emsi_data = data;\n+\tqdev-\u003emsi_cached = true;\n+\n+\tpci_write_config_dword(pdev, qdev-\u003emsi_offset + QCOM_VFIO_MSI_MAGIC_OFFSET,\n+\t\t\t QCOM_VFIO_MSI_MAGIC);\n+\tpci_write_config_dword(pdev, qdev-\u003emsi_offset + QCOM_VFIO_MSI_ADDR_LO_OFFSET,\n+\t\t\t qdev-\u003emsi_addr_lo);\n+\tpci_write_config_dword(pdev, qdev-\u003emsi_offset + QCOM_VFIO_MSI_ADDR_HI_OFFSET,\n+\t\t\t qdev-\u003emsi_addr_hi);\n+\tpci_write_config_word(pdev, qdev-\u003emsi_offset + QCOM_VFIO_MSI_DATA_OFFSET,\n+\t\t\t qdev-\u003emsi_data);\n+\n+\tpci_info(pdev, \"Qualcomm WiFi MSI cached at offset 0x%x - addr_lo=0x%x addr_hi=0x%x data=0x%x (magic=QMSI)\\n\",\n+\t\t qdev-\u003emsi_offset, qdev-\u003emsi_addr_lo, qdev-\u003emsi_addr_hi, qdev-\u003emsi_data);\n+}\n+\n+/**\n+ * qcom_intercept_msi_read - Intercept MSI config reads and return cached values\n+ * @qdev: Qualcomm VFIO device\n+ * @pos: Config space offset\n+ * @buf: User buffer\n+ * @count: Read size\n+ *\n+ * Returns: Number of bytes read, or negative error\n+ */\n+static ssize_t qcom_intercept_msi_read(struct qcom_vfio_pci_device *qdev,\n+\t\t\t\t loff_t pos, char __user *buf, size_t count)\n+{\n+\tu32 tmp_val = 0;\n+\tint msi_magic, msi_addr_lo, msi_addr_hi, msi_data;\n+\n+\tif (!qdev-\u003emsi_offset)\n+\t\treturn -ENOTTY;\n+\n+\tmsi_magic = qdev-\u003emsi_offset + QCOM_VFIO_MSI_MAGIC_OFFSET;\n+\tmsi_addr_lo = qdev-\u003emsi_offset + QCOM_VFIO_MSI_ADDR_LO_OFFSET;\n+\tmsi_addr_hi = qdev-\u003emsi_offset + QCOM_VFIO_MSI_ADDR_HI_OFFSET;\n+\tmsi_data = qdev-\u003emsi_offset + QCOM_VFIO_MSI_DATA_OFFSET;\n+\n+\tif (pos == msi_magic \u0026\u0026 count == sizeof(u32)) {\n+\t\tif (qdev-\u003emsi_cached) {\n+\t\t\ttmp_val = QCOM_VFIO_MSI_MAGIC;\n+\t\t\tpci_dbg(qdev-\u003evdev.pdev, \"Intercepting MAGIC read at 0x%llx, returning 0x%x (QMSI)\\n\",\n+\t\t\t\t pos, tmp_val);\n+\t\t} else {\n+\t\t\treturn -ENOTTY;\n+\t\t}\n+\t} else if (qdev-\u003emsi_cached) {\n+\t\tif (pos == msi_addr_lo \u0026\u0026 count == sizeof(u32)) {\n+\t\t\ttmp_val = qdev-\u003emsi_addr_lo;\n+\t\t\tpci_dbg(qdev-\u003evdev.pdev, \"Intercepting ADDR_LO read at 0x%llx, returning 0x%x\\n\",\n+\t\t\t\t pos, tmp_val);\n+\t\t} else if (pos == msi_addr_hi \u0026\u0026 count == sizeof(u32)) {\n+\t\t\ttmp_val = qdev-\u003emsi_addr_hi;\n+\t\t\tpci_dbg(qdev-\u003evdev.pdev, \"Intercepting ADDR_HI read at 0x%llx, returning 0x%x\\n\",\n+\t\t\t\t pos, tmp_val);\n+\t\t} else if (pos == msi_data \u0026\u0026 count == sizeof(u16)) {\n+\t\t\ttmp_val = qdev-\u003emsi_data;\n+\t\t\tpci_dbg(qdev-\u003evdev.pdev, \"Intercepting MSI_DATA read at 0x%llx, returning 0x%x\\n\",\n+\t\t\t\t pos, tmp_val);\n+\t\t} else {\n+\t\t\treturn -ENOTTY;\n+\t\t}\n+\t} else {\n+\t\treturn -ENOTTY;\n+\t}\n+\n+\tif (copy_to_user(buf, \u0026tmp_val, count))\n+\t\treturn -EFAULT;\n+\n+\treturn count;\n+}\n+\n+/**\n+ * qcom_vfio_pci_config_rw - Config space read/write with MSI interception\n+ * @qdev: Qualcomm VFIO device\n+ * @buf: User buffer\n+ * @count: Size\n+ * @offset: Config space offset (0-0xFFF)\n+ * @iswrite: true for write, false for read\n+ *\n+ * Returns: Number of bytes transferred, or -ENOTTY if not intercepted\n+ */\n+ssize_t qcom_vfio_pci_config_rw(struct qcom_vfio_pci_device *qdev,\n+\t\t\t\tchar __user *buf, size_t count,\n+\t\t\t\tloff_t offset, bool iswrite)\n+{\n+\tint msi_range_start, msi_range_end;\n+\n+\tif (iswrite)\n+\t\treturn -ENOTTY;\n+\n+\tif (!qdev-\u003emsi_offset)\n+\t\treturn -ENOTTY;\n+\n+\tmsi_range_start = qdev-\u003emsi_offset;\n+\tmsi_range_end = qdev-\u003emsi_offset + QCOM_VFIO_MSI_SPACE_SIZE;\n+\n+\tif (offset \u003e= msi_range_start \u0026\u0026 offset \u003c msi_range_end)\n+\t\treturn qcom_intercept_msi_read(qdev, offset, buf, count);\n+\n+\treturn -ENOTTY;\n+}\ndiff --git a/drivers/vfio/pci/qcom/qcom_vfio_pci.h b/drivers/vfio/pci/qcom/qcom_vfio_pci.h\nnew file mode 100644\nindex 0000000000000..50c70375ad5f6\n--- /dev/null\n+++ b/drivers/vfio/pci/qcom/qcom_vfio_pci.h\n@@ -0,0 +1,36 @@\n+/* SPDX-License-Identifier: GPL-2.0-only */\n+/* SPDX-FileCopyrightText: Copyright Red Hat */\n+\n+#ifndef _QCOM_VFIO_PCI_H_\n+#define _QCOM_VFIO_PCI_H_\n+\n+#include \u003clinux/vfio_pci_core.h\u003e\n+#include \u003clinux/qcom_vfio.h\u003e\n+\n+/**\n+ * struct qcom_vfio_pci_device - Qualcomm VFIO PCI device with quirks\n+ * @vdev: Core VFIO PCI device\n+ * @msi_offset: Base offset in extended config for MSI passthrough (0 if disabled)\n+ * @msi_cached: Whether host MSI address/data has been cached\n+ * @msi_addr_lo: Cached host MSI address (low 32 bits)\n+ * @msi_addr_hi: Cached host MSI address (high 32 bits)\n+ * @msi_data: Cached host MSI data value\n+ */\n+struct qcom_vfio_pci_device {\n+\tstruct vfio_pci_core_device vdev;\n+\n+\t/* MSI quirk state */\n+\tint msi_offset;\n+\tbool msi_cached;\n+\tu32 msi_addr_lo;\n+\tu32 msi_addr_hi;\n+\tu16 msi_data;\n+};\n+\n+/* MSI quirk functions */\n+ssize_t qcom_vfio_pci_config_rw(struct qcom_vfio_pci_device *qdev,\n+\t\t\t\tchar __user *buf, size_t count,\n+\t\t\t\tloff_t offset, bool iswrite);\n+void qcom_cache_and_write_msi(struct qcom_vfio_pci_device *qdev);\n+\n+#endif /* _QCOM_VFIO_PCI_H_ */\ndiff --git a/include/linux/pci.h b/include/linux/pci.h\nindex d31a8d107b1ef..c63de78bfd66f 100644\n--- a/include/linux/pci.h\n+++ b/include/linux/pci.h\n@@ -1299,6 +1299,7 @@ u8 pci_find_ht_capability(struct pci_dev *dev, int ht_cap);\n u8 pci_find_next_ht_capability(struct pci_dev *dev, u8 pos, int ht_cap);\n u16 pci_find_ext_capability(struct pci_dev *dev, int cap);\n u16 pci_find_next_ext_capability(struct pci_dev *dev, u16 pos, int cap);\n+int pci_find_free_ext_cap_offset(struct pci_dev *dev, size_t size);\n struct pci_bus *pci_find_next_bus(const struct pci_bus *from);\n u16 pci_find_vsec_capability(struct pci_dev *dev, u16 vendor, int cap);\n u16 pci_find_dvsec_capability(struct pci_dev *dev, u16 vendor, u16 dvsec);\n@@ -2199,6 +2200,8 @@ static inline u8 pci_find_next_capability(struct pci_dev *dev, u8 post, int cap)\n { return 0; }\n static inline u16 pci_find_ext_capability(struct pci_dev *dev, int cap)\n { return 0; }\n+static inline int pci_find_free_ext_cap_offset(struct pci_dev *dev, size_t size)\n+{ return 0; }\n \n static inline u64 pci_get_dsn(struct pci_dev *dev)\n { return 0; }\ndiff --git a/include/linux/qcom_vfio.h b/include/linux/qcom_vfio.h\nnew file mode 100644\nindex 0000000000000..7553bc382c8e4\n--- /dev/null\n+++ b/include/linux/qcom_vfio.h\n@@ -0,0 +1,90 @@\n+/* SPDX-License-Identifier: GPL-2.0-only */\n+/* SPDX-FileCopyrightText: Copyright Red Hat */\n+\n+#ifndef _QCOM_VFIO_H_\n+#define _QCOM_VFIO_H_\n+\n+#include \u003clinux/pci.h\u003e\n+\n+/*\n+ * MSI Address Passthrough Quirk\n+ *\n+ * Qualcomm device firmware requires physical host MSI addresses rather than\n+ * guest IOVA addresses. The qcom-vfio-pci variant driver caches host MSI\n+ * values in extended PCI config space with a magic signature for VM\n+ * discovery.\n+ *\n+ * Protocol:\n+ * 1. Host: qcom-vfio-pci finds free space in extended config (0x100-0xFFF)\n+ * 2. Host: Writes magic signature \"QMSI\" (0x49534D51) followed by MSI data\n+ * 3. VM: Device driver searches for \"QMSI\" signature to locate cached MSI\n+ * 4. VM: Reads MSI values and programs device firmware\n+ *\n+ * This avoids offset mismatch when QEMU filters certain capabilities, causing\n+ * host and VM to see different extended capability chains.\n+ *\n+ * Layout in extended config space:\n+ * +0x00: Magic signature \"QMSI\" (0x49534D51)\n+ * +0x04: MSI address low 32 bits\n+ * +0x08: MSI address high 32 bits\n+ * +0x0C: MSI data (16 bits)\n+ *\n+ * Used by Qualcomm ath11k/ath12k WiFi devices. Supported PCI IDs\n+ * are listed in the qcom-vfio-pci variant driver.\n+ */\n+\n+/* Magic signature \"QMSI\" to identify cached MSI data */\n+#define QCOM_VFIO_MSI_MAGIC\t\t0x49534D51\n+\n+/* Space needed for magic + MSI passthrough data */\n+#define QCOM_VFIO_MSI_SPACE_SIZE\t16\n+\n+/* Relative offsets from base discovered by qcom_vfio_find_msi_offset() */\n+#define QCOM_VFIO_MSI_MAGIC_OFFSET\t0x00\t/* Magic signature \"QMSI\" */\n+#define QCOM_VFIO_MSI_ADDR_LO_OFFSET\t0x04\t/* Host MSI address low 32 bits */\n+#define QCOM_VFIO_MSI_ADDR_HI_OFFSET\t0x08\t/* Host MSI address high 32 bits */\n+#define QCOM_VFIO_MSI_DATA_OFFSET\t0x0C\t/* Host MSI data (16 bits) */\n+\n+/**\n+ * qcom_vfio_find_msi_offset - Find free space for host to cache MSI\n+ * @pdev: PCI device\n+ *\n+ * Host-side function: Finds free space in extended config to write MSI cache.\n+ * Uses PCI core utility to scan capability chain.\n+ *\n+ * Returns: Offset in extended config space (\u003e= 0x100), or 0 if no space found\n+ */\n+static inline int qcom_vfio_find_msi_offset(struct pci_dev *pdev)\n+{\n+\treturn pci_find_free_ext_cap_offset(pdev, QCOM_VFIO_MSI_SPACE_SIZE);\n+}\n+\n+/**\n+ * qcom_vfio_find_msi_cache - Locate cached MSI data by magic signature\n+ * @pdev: PCI device\n+ *\n+ * VM-side function: Searches extended config space for \"QMSI\" magic signature\n+ * to locate host-cached MSI values. This avoids offset mismatch when QEMU\n+ * filters certain capabilities. Config reads go through QEMU's VFIO\n+ * virtualization, so no hardware side-effects or URs will occur.\n+ *\n+ * Returns: Offset of MSI data (after magic), or 0 if not found\n+ */\n+static inline int qcom_vfio_find_msi_cache(struct pci_dev *pdev)\n+{\n+\tu32 magic;\n+\tint offset;\n+\n+\tfor (offset = PCI_CFG_SPACE_SIZE;\n+\t offset \u003c= PCI_CFG_SPACE_EXP_SIZE - QCOM_VFIO_MSI_SPACE_SIZE;\n+\t offset += 4) {\n+\t\tif (pci_read_config_dword(pdev, offset, \u0026magic))\n+\t\t\tcontinue;\n+\t\tif (magic == QCOM_VFIO_MSI_MAGIC)\n+\t\t\treturn offset;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+#endif /* _QCOM_VFIO_H_ */\n"
} |
| 2/1 | 2026/10/11 07:56 | agent | patch-evaluator |
0mModel:core Args: null Results: {
"EnableConfigs": null,
"FocusSymbols": [],
"Reasoning": "The patch introduces a VFIO PCI variant driver (qcom-vfio-pci), helper function pci_find_free_ext_cap_offset(), and MSI/reset handling adjustments in the Qualcomm ath11k and ath12k PCI drivers. All modified code specifically targets physical Qualcomm WiFi PCIe hardware (ath11k and ath12k chipsets) for device operation and host-to-VM passthrough. Standard virtualized fuzzing environments (QEMU/GCE) lack emulation for these Qualcomm PCIe devices, making the code structurally unreachable.",
"WorthFuzzing": false
}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 643a03b7a3fd62832c4426cfdc4830c0c5b9182b
Author: syz-cluster <triage@syzkaller.com>
Date: Sun Oct 11 07:56:07 2026 +0000
syz-cluster: applied patch under review
diff --git a/drivers/net/wireless/ath/ath11k/pci.c b/drivers/net/wireless/ath/ath11k/pci.c
index a163168f36176..35883abdf12e0 100644
--- a/drivers/net/wireless/ath/ath11k/pci.c
+++ b/drivers/net/wireless/ath/ath11k/pci.c
@@ -10,6 +10,7 @@
#include <linux/of.h>
#include <linux/time.h>
#include <linux/vmalloc.h>
+#include <linux/qcom_vfio.h>
#include "pci.h"
#include "core.h"
@@ -190,8 +191,10 @@ static void ath11k_pci_restore_window(struct ath11k_base *ab)
spin_unlock_bh(&ab_pci->window_lock);
}
-static void ath11k_pci_soc_global_reset(struct ath11k_base *ab)
+static int ath11k_pci_soc_global_reset(struct ath11k_base *ab)
{
+ bool link_recovered = false;
+ int retries = 250;
u32 val, delay;
val = ath11k_pcic_read32(ab, PCIE_SOC_GLOBAL_RESET);
@@ -215,14 +218,28 @@ static void ath11k_pci_soc_global_reset(struct ath11k_base *ab)
mdelay(delay);
- val = ath11k_pcic_read32(ab, PCIE_SOC_GLOBAL_RESET);
- if (val == 0xffffffff)
- ath11k_warn(ab, "link down error during global reset\n");
+ /* Wait for PCIe link to recover, especially important in VM environments
+ * where timing can vary significantly from bare metal.
+ */
+ while (retries-- > 0) {
+ val = ath11k_pcic_read32(ab, PCIE_SOC_GLOBAL_RESET);
+ if (val != 0xffffffff) {
+ link_recovered = true;
+ break;
+ }
+ mdelay(20);
+ }
+ if (!link_recovered) {
+ ath11k_err(ab, "PCIe link failed to recover - device may need power cycle\n");
+ return -ETIMEDOUT;
+ }
/* Restore window register as its content is cleared during
* hardware global reset, such that it aligns with host cache.
*/
ath11k_pci_restore_window(ab);
+
+ return 0;
}
static void ath11k_pci_clear_dbg_registers(struct ath11k_base *ab)
@@ -377,8 +394,10 @@ static void ath11k_pci_force_wake(struct ath11k_base *ab)
mdelay(5);
}
-static void ath11k_pci_sw_reset(struct ath11k_base *ab, bool power_on)
+static int ath11k_pci_sw_reset(struct ath11k_base *ab, bool power_on)
{
+ int ret;
+
mdelay(100);
if (power_on) {
@@ -391,8 +410,12 @@ static void ath11k_pci_sw_reset(struct ath11k_base *ab, bool power_on)
ath11k_mhi_clear_vector(ab);
ath11k_pci_clear_dbg_registers(ab);
- ath11k_pci_soc_global_reset(ab);
+ ret = ath11k_pci_soc_global_reset(ab);
+ if (ret)
+ return ret;
ath11k_mhi_set_mhictrl_reset(ab);
+
+ return 0;
}
static void ath11k_pci_init_qmi_ce_config(struct ath11k_base *ab)
@@ -440,8 +463,11 @@ static int ath11k_pci_alloc_msi(struct ath11k_pci *ab_pci)
struct ath11k_base *ab = ab_pci->ab;
const struct ath11k_msi_config *msi_config = ab->pci.msi.config;
struct pci_dev *pci_dev = ab_pci->pdev;
+ u32 msi_addr_lo = 0, msi_addr_hi = 0;
struct msi_desc *msi_desc;
+ u16 msi_data = 0;
int num_vectors;
+ int msi_offset;
int ret;
num_vectors = pci_alloc_irq_vectors(pci_dev,
@@ -465,6 +491,36 @@ static int ath11k_pci_alloc_msi(struct ath11k_pci *ab_pci)
}
ath11k_info(ab, "MSI vectors: %d\n", num_vectors);
+ /*
+ * Try to get host MSI address from VFIO cache.
+ * When running on a VM, the ath11k firmware requires physical host
+ * MSI addresses and cannot handle guest IOVA addresses.
+ * qcom-vfio-pci writes host MSI values to extended config space with
+ * a magic signature "QMSI" for discovery. Search for it.
+ */
+ msi_offset = qcom_vfio_find_msi_cache(pci_dev);
+ if (msi_offset) {
+ pci_read_config_dword(pci_dev,
+ msi_offset + QCOM_VFIO_MSI_ADDR_LO_OFFSET,
+ &msi_addr_lo);
+ pci_read_config_dword(pci_dev,
+ msi_offset + QCOM_VFIO_MSI_ADDR_HI_OFFSET,
+ &msi_addr_hi);
+ pci_read_config_word(pci_dev,
+ msi_offset + QCOM_VFIO_MSI_DATA_OFFSET,
+ &msi_data);
+
+ if (msi_addr_lo && msi_addr_lo != 0xFFFFFFFF) {
+ ab->pci.msi.addr_lo = msi_addr_lo;
+ ab->pci.msi.addr_hi = msi_addr_hi;
+ ab->pci.msi.ep_base_data = msi_data;
+ ab_pci->vfio_msi_cached = true;
+ ath11k_info(ab, "VFIO MSI cache at offset 0x%x: addr_lo=0x%x addr_hi=0x%x data=%d\n",
+ msi_offset, msi_addr_lo, msi_addr_hi, msi_data);
+ return 0;
+ }
+ }
+
ath11k_pci_msi_disable(ab_pci);
msi_desc = irq_get_msi_desc(ab_pci->pdev->irq);
@@ -506,6 +562,9 @@ static int ath11k_pci_config_msi_data(struct ath11k_pci *ab_pci)
{
struct msi_desc *msi_desc;
+ if (ab_pci->vfio_msi_cached)
+ return 0;
+
msi_desc = irq_get_msi_desc(ab_pci->pdev->irq);
if (!msi_desc) {
ath11k_err(ab_pci->ab, "msi_desc is NULL!\n");
@@ -822,7 +881,9 @@ static int ath11k_pci_power_up(struct ath11k_base *ab)
ab_pci->register_window = 0;
clear_bit(ATH11K_FLAG_DEVICE_INIT_DONE, &ab->dev_flags);
- ath11k_pci_sw_reset(ab_pci->ab, true);
+ ret = ath11k_pci_sw_reset(ab_pci->ab, true);
+ if (ret)
+ return ret;
/* Disable ASPM during firmware download due to problems switching
* to AMSS state.
diff --git a/drivers/net/wireless/ath/ath11k/pci.h b/drivers/net/wireless/ath/ath11k/pci.h
index 1e3005a4b64c6..5229c9db59d7f 100644
--- a/drivers/net/wireless/ath/ath11k/pci.h
+++ b/drivers/net/wireless/ath/ath11k/pci.h
@@ -74,6 +74,8 @@ struct ath11k_pci {
unsigned long flags;
u16 link_ctl;
u64 dma_mask;
+
+ bool vfio_msi_cached;
};
static inline struct ath11k_pci *ath11k_pci_priv(struct ath11k_base *ab)
diff --git a/drivers/net/wireless/ath/ath12k/pci.c b/drivers/net/wireless/ath/ath12k/pci.c
index 12bbb75570f1f..8e92213fd3fce 100644
--- a/drivers/net/wireless/ath/ath12k/pci.c
+++ b/drivers/net/wireless/ath/ath12k/pci.c
@@ -8,6 +8,7 @@
#include <linux/interrupt.h>
#include <linux/msi.h>
#include <linux/pci.h>
+#include <linux/qcom_vfio.h>
#include <linux/time.h>
#include <linux/vmalloc.h>
@@ -181,8 +182,10 @@ static void ath12k_pci_restore_window(struct ath12k_base *ab)
spin_unlock_bh(&ab_pci->window_lock);
}
-static void ath12k_pci_soc_global_reset(struct ath12k_base *ab)
+static int ath12k_pci_soc_global_reset(struct ath12k_base *ab)
{
+ bool link_recovered = false;
+ int retries = 250;
u32 val, delay;
val = ath12k_pci_read32(ab, PCIE_SOC_GLOBAL_RESET);
@@ -206,14 +209,28 @@ static void ath12k_pci_soc_global_reset(struct ath12k_base *ab)
mdelay(delay);
- val = ath12k_pci_read32(ab, PCIE_SOC_GLOBAL_RESET);
- if (val == 0xffffffff)
- ath12k_warn(ab, "link down error during global reset\n");
+ /* Wait for PCIe link to recover, especially important in VM environments
+ * where timing can vary significantly from bare metal.
+ */
+ while (retries-- > 0) {
+ val = ath12k_pci_read32(ab, PCIE_SOC_GLOBAL_RESET);
+ if (val != 0xffffffff) {
+ link_recovered = true;
+ break;
+ }
+ mdelay(20);
+ }
+ if (!link_recovered) {
+ ath12k_err(ab, "PCIe link failed to recover - device may need power cycle\n");
+ return -ETIMEDOUT;
+ }
/* Restore window register as its content is cleared during
* hardware global reset, such that it aligns with host cache.
*/
ath12k_pci_restore_window(ab);
+
+ return 0;
}
static void ath12k_pci_clear_dbg_registers(struct ath12k_base *ab)
@@ -299,8 +316,10 @@ static void ath12k_pci_force_wake(struct ath12k_base *ab)
mdelay(5);
}
-static void ath12k_pci_sw_reset(struct ath12k_base *ab, bool power_on)
+static int ath12k_pci_sw_reset(struct ath12k_base *ab, bool power_on)
{
+ int ret;
+
if (power_on) {
ath12k_pci_enable_ltssm(ab);
ath12k_pci_clear_all_intrs(ab);
@@ -309,8 +328,12 @@ static void ath12k_pci_sw_reset(struct ath12k_base *ab, bool power_on)
ath12k_mhi_clear_vector(ab);
ath12k_pci_clear_dbg_registers(ab);
- ath12k_pci_soc_global_reset(ab);
+ ret = ath12k_pci_soc_global_reset(ab);
+ if (ret)
+ return ret;
ath12k_mhi_set_mhictrl_reset(ab);
+
+ return 0;
}
static void ath12k_pci_free_ce_irq(struct ath12k_base *ab, int num_ce)
@@ -760,8 +783,11 @@ static int ath12k_pci_msi_alloc(struct ath12k_pci *ab_pci)
{
struct ath12k_base *ab = ab_pci->ab;
const struct ath12k_msi_config *msi_config = ab_pci->msi_config;
+ u32 msi_addr_lo = 0, msi_addr_hi = 0;
struct msi_desc *msi_desc;
+ u16 msi_data = 0;
int num_vectors;
+ int msi_offset;
int ret;
num_vectors = pci_alloc_irq_vectors(ab_pci->pdev,
@@ -789,6 +815,39 @@ static int ath12k_pci_msi_alloc(struct ath12k_pci *ab_pci)
ath12k_info(ab, "MSI vectors: %d\n", num_vectors);
+ /*
+ * Try to get host MSI address from VFIO cache.
+ * When running on a VM, the ath12k firmware requires physical host
+ * MSI addresses and cannot handle guest IOVA addresses.
+ * qcom-vfio-pci writes host MSI values to extended config space with
+ * a magic signature "QMSI" for discovery. Search for it.
+ */
+ msi_offset = qcom_vfio_find_msi_cache(ab_pci->pdev);
+ if (msi_offset) {
+ pci_read_config_dword(ab_pci->pdev,
+ msi_offset + QCOM_VFIO_MSI_ADDR_LO_OFFSET,
+ &msi_addr_lo);
+ pci_read_config_dword(ab_pci->pdev,
+ msi_offset + QCOM_VFIO_MSI_ADDR_HI_OFFSET,
+ &msi_addr_hi);
+ pci_read_config_word(ab_pci->pdev,
+ msi_offset + QCOM_VFIO_MSI_DATA_OFFSET,
+ &msi_data);
+
+ if (msi_addr_lo && msi_addr_lo != 0xFFFFFFFF) {
+ ab_pci->msi_addr_hi = msi_addr_hi;
+ ab_pci->msi_addr_lo = msi_addr_lo;
+ ab_pci->msi_ep_base_data = msi_data;
+ ab_pci->msi_addr_cached = true;
+
+ ath12k_info(ab,
+ "using host MSI from VFIO at offset 0x%x: addr_lo=0x%x addr_hi=0x%x data=%d\n",
+ msi_offset, msi_addr_lo, msi_addr_hi, msi_data);
+ return 0;
+ }
+ }
+ ab_pci->msi_addr_cached = false;
+
ath12k_pci_msi_disable(ab_pci);
msi_desc = irq_get_msi_desc(ab_pci->pdev->irq);
@@ -822,6 +881,9 @@ static int ath12k_pci_config_msi_data(struct ath12k_pci *ab_pci)
{
struct msi_desc *msi_desc;
+ if (ab_pci->msi_addr_cached)
+ return 0;
+
msi_desc = irq_get_msi_desc(ab_pci->pdev->irq);
if (!msi_desc) {
ath12k_err(ab_pci->ab, "msi_desc is NULL!\n");
@@ -1060,6 +1122,12 @@ void ath12k_pci_get_msi_address(struct ath12k_base *ab, u32 *msi_addr_lo,
struct ath12k_pci *ab_pci = ath12k_pci_priv(ab);
struct pci_dev *pci_dev = to_pci_dev(ab->dev);
+ if (ab_pci->msi_addr_cached) {
+ *msi_addr_hi = ab_pci->msi_addr_hi;
+ *msi_addr_lo = ab_pci->msi_addr_lo;
+ return;
+ }
+
pci_read_config_dword(pci_dev, pci_dev->msi_cap + PCI_MSI_ADDRESS_LO,
msi_addr_lo);
@@ -1452,7 +1520,9 @@ int ath12k_pci_power_up(struct ath12k_base *ab)
ab_pci->register_window = 0;
clear_bit(ATH12K_PCI_FLAG_INIT_DONE, &ab_pci->flags);
- ath12k_pci_sw_reset(ab_pci->ab, true);
+ ret = ath12k_pci_sw_reset(ab_pci->ab, true);
+ if (ret)
+ return ret;
/* Disable ASPM during firmware download due to problems switching
* to AMSS state.
diff --git a/drivers/net/wireless/ath/ath12k/pci.h b/drivers/net/wireless/ath/ath12k/pci.h
index 0e0e2020c6ae5..ee3696d40dfb6 100644
--- a/drivers/net/wireless/ath/ath12k/pci.h
+++ b/drivers/net/wireless/ath/ath12k/pci.h
@@ -129,6 +129,12 @@ struct ath12k_pci {
/* enum ath12k_pci_flags */
unsigned long flags;
u16 link_ctl;
+
+ /* Cached host MSI address for firmware configuration in VMs */
+ u32 msi_addr_hi;
+ u32 msi_addr_lo;
+ bool msi_addr_cached;
+
unsigned long irq_flags;
const struct ath12k_pci_ops *pci_ops;
u32 qmi_instance;
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 8cc6a89130b53..ae234c9a2a29b 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -544,6 +544,78 @@ u16 pci_find_ext_capability(struct pci_dev *dev, int cap)
}
EXPORT_SYMBOL_GPL(pci_find_ext_capability);
+/**
+ * pci_find_free_ext_cap_offset - Find free space in extended config
+ * @dev: PCI device to query
+ * @size: Minimum size needed (in bytes)
+ *
+ * Scans the extended capability chain and then searches for a contiguous
+ * region of zeroed space of at least @size bytes in the extended
+ * configuration space (0x100-0xFFF). This can be used by drivers that
+ * need to use unused extended config space for device-specific purposes
+ * (e.g., VFIO quirks for VM passthrough).
+ *
+ * Returns the offset to free space, or 0 if no suitable gap found.
+ */
+int pci_find_free_ext_cap_offset(struct pci_dev *dev, size_t size)
+{
+ int ttl = (PCI_CFG_SPACE_EXP_SIZE - PCI_CFG_SPACE_SIZE) / 8;
+ int pos = PCI_CFG_SPACE_SIZE;
+ int start = 0, run = 0;
+ int highest_pos = 0;
+ u32 header;
+ int offset;
+
+ if (!pci_is_pcie(dev) || dev->cfg_size <= PCI_CFG_SPACE_SIZE)
+ return 0;
+
+ if (size == 0 || size > PCI_CFG_SPACE_EXP_SIZE - PCI_CFG_SPACE_SIZE)
+ return 0;
+
+ if (pci_read_config_dword(dev, pos, &header))
+ return 0;
+ if (header == 0 || header == 0xffffffff)
+ return 0;
+
+ while (ttl-- > 0) {
+ if (pos > highest_pos)
+ highest_pos = pos;
+
+ pos = PCI_EXT_CAP_NEXT(header);
+ if (!pos || pos < PCI_CFG_SPACE_SIZE)
+ break;
+
+ if (pci_read_config_dword(dev, pos, &header))
+ break;
+ if (header == 0 || header == 0xffffffff)
+ break;
+ }
+
+ if (!highest_pos)
+ return 0;
+
+ for (offset = highest_pos; offset <= (int)PCI_CFG_SPACE_EXP_SIZE - 4;
+ offset += 4) {
+ u32 val;
+
+ if (pci_read_config_dword(dev, offset, &val))
+ break;
+
+ if (val == 0) {
+ if (run == 0)
+ start = offset;
+ run += 4;
+ if (run >= (int)size)
+ return start;
+ } else {
+ run = 0;
+ }
+ }
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(pci_find_free_ext_cap_offset);
+
/**
* pci_get_dsn - Read and return the 8-byte Device Serial Number
* @dev: PCI device to query
diff --git a/drivers/vfio/pci/Kconfig b/drivers/vfio/pci/Kconfig
index 296bf01e185ec..237a29443bf58 100644
--- a/drivers/vfio/pci/Kconfig
+++ b/drivers/vfio/pci/Kconfig
@@ -72,6 +72,8 @@ source "drivers/vfio/pci/nvgrace-gpu/Kconfig"
source "drivers/vfio/pci/qat/Kconfig"
+source "drivers/vfio/pci/qcom/Kconfig"
+
source "drivers/vfio/pci/xe/Kconfig"
endmenu
diff --git a/drivers/vfio/pci/Makefile b/drivers/vfio/pci/Makefile
index 6138f1bf241df..63db19102850d 100644
--- a/drivers/vfio/pci/Makefile
+++ b/drivers/vfio/pci/Makefile
@@ -23,4 +23,6 @@ obj-$(CONFIG_NVGRACE_GPU_VFIO_PCI) += nvgrace-gpu/
obj-$(CONFIG_QAT_VFIO_PCI) += qat/
+obj-$(CONFIG_QCOM_VFIO_PCI) += qcom/
+
obj-$(CONFIG_XE_VFIO_PCI) += xe/
diff --git a/drivers/vfio/pci/qcom/Kconfig b/drivers/vfio/pci/qcom/Kconfig
new file mode 100644
index 0000000000000..e284b91cabf0d
--- /dev/null
+++ b/drivers/vfio/pci/qcom/Kconfig
@@ -0,0 +1,22 @@
+# SPDX-License-Identifier: GPL-2.0-only
+config QCOM_VFIO_PCI
+ tristate "VFIO support for Qualcomm PCI devices"
+ depends on PCI
+ select VFIO_PCI_CORE
+ help
+ This provides VFIO support for Qualcomm PCI devices with device-specific
+ quirks. Currently supports:
+ - Qualcomm ath11k WiFi (Device ID 0x1103)
+ - Qualcomm ath12k WiFi (Device ID 0x1107)
+
+ These devices require special handling for MSI address/data passthrough
+ when used with VFIO. The firmware expects physical host MSI addresses
+ rather than guest IOVA addresses.
+
+ The VM must have IOMMU interrupt remapping and caching mode enabled.
+ For example, with libvirt/QEMU on Intel, add to the domain XML:
+ <iommu model="intel">
+ <driver intremap="on" caching_mode="on"/>
+ </iommu>
+
+ If you don't know what to do here, say N.
diff --git a/drivers/vfio/pci/qcom/Makefile b/drivers/vfio/pci/qcom/Makefile
new file mode 100644
index 0000000000000..dc48d87d1ef61
--- /dev/null
+++ b/drivers/vfio/pci/qcom/Makefile
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0-only
+obj-$(CONFIG_QCOM_VFIO_PCI) += qcom-vfio-pci.o
+qcom-vfio-pci-y := main.o msi_quirk.o
diff --git a/drivers/vfio/pci/qcom/main.c b/drivers/vfio/pci/qcom/main.c
new file mode 100644
index 0000000000000..8773661d29a10
--- /dev/null
+++ b/drivers/vfio/pci/qcom/main.c
@@ -0,0 +1,285 @@
+// SPDX-License-Identifier: GPL-2.0-only
+// SPDX-FileCopyrightText: Copyright Red Hat
+
+#include <linux/device.h>
+#include <linux/module.h>
+#include <linux/pci.h>
+#include <linux/stddef.h>
+#include <linux/string.h>
+#include <linux/types.h>
+#include <linux/uaccess.h>
+#include <linux/vfio.h>
+#include <linux/vfio_pci_core.h>
+#include <uapi/linux/vfio.h>
+
+#include "qcom_vfio_pci.h"
+
+static struct qcom_vfio_pci_device *to_qcom_vdev(struct vfio_pci_core_device *vdev)
+{
+ return container_of(vdev, struct qcom_vfio_pci_device, vdev);
+}
+
+/*
+ * Intercept config space read operations to return cached host MSI values.
+ * Call core VFIO if not intercepted.
+ */
+static ssize_t qcom_vfio_pci_read(struct vfio_device *core_vdev, char __user *buf,
+ size_t count, loff_t *ppos)
+{
+ struct vfio_pci_core_device *vdev =
+ container_of(core_vdev, struct vfio_pci_core_device, vdev);
+ struct qcom_vfio_pci_device *qdev = to_qcom_vdev(vdev);
+ unsigned int index = VFIO_PCI_OFFSET_TO_INDEX(*ppos);
+ loff_t offset = *ppos & VFIO_PCI_OFFSET_MASK;
+ ssize_t ret;
+
+ if (index == VFIO_PCI_CONFIG_REGION_INDEX) {
+ ret = qcom_vfio_pci_config_rw(qdev, buf, count, offset, false);
+ if (ret != -ENOTTY) {
+ if (ret > 0)
+ *ppos += ret;
+ return ret;
+ }
+ }
+
+ return vfio_pci_core_read(core_vdev, buf, count, ppos);
+}
+
+static int qcom_vfio_pci_init_dev(struct vfio_device *core_vdev)
+{
+ struct qcom_vfio_pci_device *qdev =
+ container_of(core_vdev, struct qcom_vfio_pci_device, vdev.vdev);
+ struct pci_dev *pdev = to_pci_dev(core_vdev->dev);
+ int ret;
+
+ ret = vfio_pci_core_init_dev(core_vdev);
+ if (ret)
+ return ret;
+
+ qdev->msi_offset = qcom_vfio_find_msi_offset(pdev);
+ if (!qdev->msi_offset) {
+ pci_err(pdev, "No free space in extended config for MSI quirk\n");
+ pci_err(pdev, "qcom-vfio-pci cannot function without MSI passthrough, failing probe\n");
+ vfio_pci_core_release_dev(core_vdev);
+ return -ENODEV;
+ }
+ pci_info(pdev, "MSI passthrough quirk using offset 0x%x\n", qdev->msi_offset);
+
+ qdev->msi_cached = false;
+ qdev->msi_addr_lo = 0;
+ qdev->msi_addr_hi = 0;
+ qdev->msi_data = 0;
+
+ return 0;
+}
+
+static const struct vfio_pci_device_ops qcom_vfio_pci_device_ops = {
+ /* No device-specific operations needed */
+};
+
+static int qcom_vfio_pci_open_device(struct vfio_device *core_vdev)
+{
+ struct qcom_vfio_pci_device *qdev =
+ container_of(core_vdev, struct qcom_vfio_pci_device, vdev.vdev);
+ struct vfio_pci_core_device *vdev = &qdev->vdev;
+ int ret;
+
+ ret = vfio_pci_core_enable(vdev);
+ if (ret)
+ return ret;
+
+ vfio_pci_core_finish_enable(vdev);
+ return 0;
+}
+
+static void qcom_vfio_pci_close_device(struct vfio_device *core_vdev)
+{
+ struct qcom_vfio_pci_device *qdev =
+ container_of(core_vdev, struct qcom_vfio_pci_device, vdev.vdev);
+
+ qdev->msi_cached = false;
+ qdev->msi_addr_lo = 0;
+ qdev->msi_addr_hi = 0;
+ qdev->msi_data = 0;
+
+ vfio_pci_core_close_device(core_vdev);
+}
+
+/*
+ * Wrap ioctl to intercept MSI allocation and cache host MSI values.
+ * This is called after QEMU allocates MSI via VFIO_DEVICE_SET_IRQS.
+ */
+static long qcom_vfio_pci_ioctl(struct vfio_device *core_vdev,
+ unsigned int cmd, unsigned long arg)
+{
+ struct vfio_pci_core_device *vdev =
+ container_of(core_vdev, struct vfio_pci_core_device, vdev);
+ struct qcom_vfio_pci_device *qdev = to_qcom_vdev(vdev);
+ bool is_msi_trigger = false;
+ struct vfio_irq_set hdr;
+ long ret;
+
+ /*
+ * Pre-fetch SET_IRQS header to avoid TOCTOU from
+ * re-reading userspace after the core ioctl completes.
+ */
+ if (cmd == VFIO_DEVICE_SET_IRQS) {
+ unsigned long minsz = offsetofend(struct vfio_irq_set, count);
+
+ if (!copy_from_user(&hdr, (void __user *)arg, minsz)) {
+ is_msi_trigger = (hdr.index == VFIO_PCI_MSI_IRQ_INDEX &&
+ (hdr.flags & VFIO_IRQ_SET_ACTION_TRIGGER));
+ if (is_msi_trigger)
+ pci_dbg(qdev->vdev.pdev,
+ "SET_IRQS: idx=%u flags=0x%x start=%u count=%u\n",
+ hdr.index, hdr.flags, hdr.start, hdr.count);
+ }
+ }
+
+ ret = vfio_pci_core_ioctl(core_vdev, cmd, arg);
+
+ if (ret == 0 && is_msi_trigger && !qdev->msi_cached)
+ qcom_cache_and_write_msi(qdev);
+
+ return ret;
+}
+
+static const struct vfio_device_ops qcom_vfio_pci_ops = {
+ .name = "qcom-vfio-pci",
+ .init = qcom_vfio_pci_init_dev,
+ .release = vfio_pci_core_release_dev,
+ .open_device = qcom_vfio_pci_open_device,
+ .close_device = qcom_vfio_pci_close_device,
+ .ioctl = qcom_vfio_pci_ioctl,
+ .get_region_info_caps = vfio_pci_ioctl_get_region_info,
+ .device_feature = vfio_pci_core_ioctl_feature,
+ .read = qcom_vfio_pci_read,
+ .write = vfio_pci_core_write,
+ .mmap = vfio_pci_core_mmap,
+ .request = vfio_pci_core_request,
+ .match = vfio_pci_core_match,
+ .match_token_uuid = vfio_pci_core_match_token_uuid,
+ .bind_iommufd = vfio_iommufd_physical_bind,
+ .unbind_iommufd = vfio_iommufd_physical_unbind,
+ .attach_ioas = vfio_iommufd_physical_attach_ioas,
+ .detach_ioas = vfio_iommufd_physical_detach_ioas,
+};
+
+static int qcom_vfio_pci_probe(struct pci_dev *pdev,
+ const struct pci_device_id *id)
+{
+ struct qcom_vfio_pci_device *qdev;
+ int ret;
+
+ qdev = vfio_alloc_device(qcom_vfio_pci_device, vdev.vdev,
+ &pdev->dev, &qcom_vfio_pci_ops);
+ if (IS_ERR(qdev))
+ return PTR_ERR(qdev);
+
+ dev_set_drvdata(&pdev->dev, &qdev->vdev);
+ qdev->vdev.pci_ops = &qcom_vfio_pci_device_ops;
+ ret = vfio_pci_core_register_device(&qdev->vdev);
+ if (ret)
+ goto out_put_vdev;
+
+ return 0;
+
+out_put_vdev:
+ vfio_put_device(&qdev->vdev.vdev);
+ return ret;
+}
+
+static void qcom_vfio_pci_remove(struct pci_dev *pdev)
+{
+ struct vfio_pci_core_device *vdev = dev_get_drvdata(&pdev->dev);
+ struct qcom_vfio_pci_device *qdev = to_qcom_vdev(vdev);
+
+ vfio_pci_core_unregister_device(&qdev->vdev);
+ vfio_put_device(&qdev->vdev.vdev);
+}
+
+static const struct pci_device_id qcom_vfio_pci_table[] = {
+ /* Qualcomm ath11k WiFi */
+ { PCI_DRIVER_OVERRIDE_DEVICE_VFIO(PCI_VENDOR_ID_QCOM, 0x1103) },
+ /* Qualcomm ath12k WiFi */
+ { PCI_DRIVER_OVERRIDE_DEVICE_VFIO(PCI_VENDOR_ID_QCOM, 0x1107) },
+ { }
+};
+
+MODULE_DEVICE_TABLE(pci, qcom_vfio_pci_table);
+
+static struct pci_driver qcom_vfio_pci_driver = {
+ .name = "qcom-vfio-pci",
+ .id_table = qcom_vfio_pci_table,
+ .probe = qcom_vfio_pci_probe,
+ .remove = qcom_vfio_pci_remove,
+ .driver_managed_dma = true,
+};
+
+static char ids[1024] __initdata;
+module_param_string(ids, ids, sizeof(ids), 0);
+MODULE_PARM_DESC(ids, "Initial PCI IDs to add to the driver, format is \"vendor:device[:subvendor[:subdevice[:class[:class_mask]]]]\" and multiple comma separated entries can be specified");
+
+static void __init qcom_vfio_pci_fill_ids(void)
+{
+ char *p, *id;
+ int rc;
+
+ if (ids[0] == '\0')
+ return;
+
+ p = ids;
+ while ((id = strsep(&p, ","))) {
+ unsigned int vendor, device, subvendor = PCI_ANY_ID,
+ subdevice = PCI_ANY_ID, class = 0, class_mask = 0;
+ int fields;
+
+ if (!strlen(id))
+ continue;
+
+ fields = sscanf(id, "%x:%x:%x:%x:%x:%x",
+ &vendor, &device, &subvendor, &subdevice,
+ &class, &class_mask);
+
+ if (fields < 2) {
+ pr_warn("qcom-vfio-pci: invalid id string \"%s\"\n", id);
+ continue;
+ }
+
+ rc = pci_add_dynid(&qcom_vfio_pci_driver, vendor, device,
+ subvendor, subdevice, class, class_mask, 0);
+ if (rc)
+ pr_warn("qcom-vfio-pci: failed to add dynamic id [%04x:%04x[%04x:%04x]] class %#08x/%08x (%d)\n",
+ vendor, device, subvendor, subdevice,
+ class, class_mask, rc);
+ else
+ pr_info("qcom-vfio-pci: add [%04x:%04x[%04x:%04x]] class %#08x/%08x\n",
+ vendor, device, subvendor, subdevice,
+ class, class_mask);
+ }
+}
+
+static int __init qcom_vfio_pci_init(void)
+{
+ int ret;
+
+ ret = pci_register_driver(&qcom_vfio_pci_driver);
+ if (ret)
+ return ret;
+
+ qcom_vfio_pci_fill_ids();
+
+ return 0;
+}
+
+static void __exit qcom_vfio_pci_exit(void)
+{
+ pci_unregister_driver(&qcom_vfio_pci_driver);
+}
+
+module_init(qcom_vfio_pci_init);
+module_exit(qcom_vfio_pci_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Jose Ignacio Tornos Martinez <jtornosm@redhat.com>");
+MODULE_DESCRIPTION("Qualcomm VFIO PCI - Device-Specific VFIO PCI driver for Qualcomm devices");
diff --git a/drivers/vfio/pci/qcom/msi_quirk.c b/drivers/vfio/pci/qcom/msi_quirk.c
new file mode 100644
index 0000000000000..b717aff37ffc8
--- /dev/null
+++ b/drivers/vfio/pci/qcom/msi_quirk.c
@@ -0,0 +1,163 @@
+// SPDX-License-Identifier: GPL-2.0-only
+// SPDX-FileCopyrightText: Copyright Red Hat
+
+#include <linux/kernel.h>
+#include <linux/msi.h>
+#include <linux/pci.h>
+#include <linux/uaccess.h>
+#include <linux/vfio_pci_core.h>
+
+#include "qcom_vfio_pci.h"
+
+/**
+ * qcom_cache_and_write_msi - Cache host MSI address and data
+ * @qdev: Qualcomm VFIO device
+ *
+ * Called after QEMU allocates MSI via SET_IRQS ioctl to cache the physical
+ * host MSI addresses that will be returned to the VM driver.
+ */
+void qcom_cache_and_write_msi(struct qcom_vfio_pci_device *qdev)
+{
+ struct pci_dev *pdev = qdev->vdev.pdev;
+ struct device *dev = &pdev->dev;
+ struct msi_desc *desc;
+ u32 addr_lo, addr_hi;
+ u16 data;
+
+ if (qdev->msi_cached)
+ return;
+
+ if (!qdev->msi_offset)
+ return;
+
+ __msi_lock_descs(dev);
+ desc = msi_first_desc(dev, MSI_DESC_ASSOCIATED);
+ if (!desc) {
+ __msi_unlock_descs(dev);
+ pci_warn(pdev, "MSI descriptor not found\n");
+ return;
+ }
+
+ addr_lo = desc->msg.address_lo;
+ addr_hi = desc->msg.address_hi;
+ data = desc->msg.data;
+ __msi_unlock_descs(dev);
+
+ pci_dbg(pdev, "MSI descriptor - addr_lo=0x%x addr_hi=0x%x data=0x%x\n",
+ addr_lo, addr_hi, data);
+
+ /*
+ * Validate: address must be valid. Data can be 0 with interrupt remapping.
+ * When Intel VT-d interrupt remapping is enabled, the MSI data field
+ * contains an index into the interrupt remapping table, which can be 0.
+ * We cache it anyway since that's what the VM driver will program.
+ */
+ if (!addr_lo) {
+ pci_warn(pdev, "MSI address invalid, skipping cache\n");
+ return;
+ }
+ qdev->msi_addr_lo = addr_lo;
+ qdev->msi_addr_hi = addr_hi;
+ qdev->msi_data = data;
+ qdev->msi_cached = true;
+
+ pci_write_config_dword(pdev, qdev->msi_offset + QCOM_VFIO_MSI_MAGIC_OFFSET,
+ QCOM_VFIO_MSI_MAGIC);
+ pci_write_config_dword(pdev, qdev->msi_offset + QCOM_VFIO_MSI_ADDR_LO_OFFSET,
+ qdev->msi_addr_lo);
+ pci_write_config_dword(pdev, qdev->msi_offset + QCOM_VFIO_MSI_ADDR_HI_OFFSET,
+ qdev->msi_addr_hi);
+ pci_write_config_word(pdev, qdev->msi_offset + QCOM_VFIO_MSI_DATA_OFFSET,
+ qdev->msi_data);
+
+ pci_info(pdev, "Qualcomm WiFi MSI cached at offset 0x%x - addr_lo=0x%x addr_hi=0x%x data=0x%x (magic=QMSI)\n",
+ qdev->msi_offset, qdev->msi_addr_lo, qdev->msi_addr_hi, qdev->msi_data);
+}
+
+/**
+ * qcom_intercept_msi_read - Intercept MSI config reads and return cached values
+ * @qdev: Qualcomm VFIO device
+ * @pos: Config space offset
+ * @buf: User buffer
+ * @count: Read size
+ *
+ * Returns: Number of bytes read, or negative error
+ */
+static ssize_t qcom_intercept_msi_read(struct qcom_vfio_pci_device *qdev,
+ loff_t pos, char __user *buf, size_t count)
+{
+ u32 tmp_val = 0;
+ int msi_magic, msi_addr_lo, msi_addr_hi, msi_data;
+
+ if (!qdev->msi_offset)
+ return -ENOTTY;
+
+ msi_magic = qdev->msi_offset + QCOM_VFIO_MSI_MAGIC_OFFSET;
+ msi_addr_lo = qdev->msi_offset + QCOM_VFIO_MSI_ADDR_LO_OFFSET;
+ msi_addr_hi = qdev->msi_offset + QCOM_VFIO_MSI_ADDR_HI_OFFSET;
+ msi_data = qdev->msi_offset + QCOM_VFIO_MSI_DATA_OFFSET;
+
+ if (pos == msi_magic && count == sizeof(u32)) {
+ if (qdev->msi_cached) {
+ tmp_val = QCOM_VFIO_MSI_MAGIC;
+ pci_dbg(qdev->vdev.pdev, "Intercepting MAGIC read at 0x%llx, returning 0x%x (QMSI)\n",
+ pos, tmp_val);
+ } else {
+ return -ENOTTY;
+ }
+ } else if (qdev->msi_cached) {
+ if (pos == msi_addr_lo && count == sizeof(u32)) {
+ tmp_val = qdev->msi_addr_lo;
+ pci_dbg(qdev->vdev.pdev, "Intercepting ADDR_LO read at 0x%llx, returning 0x%x\n",
+ pos, tmp_val);
+ } else if (pos == msi_addr_hi && count == sizeof(u32)) {
+ tmp_val = qdev->msi_addr_hi;
+ pci_dbg(qdev->vdev.pdev, "Intercepting ADDR_HI read at 0x%llx, returning 0x%x\n",
+ pos, tmp_val);
+ } else if (pos == msi_data && count == sizeof(u16)) {
+ tmp_val = qdev->msi_data;
+ pci_dbg(qdev->vdev.pdev, "Intercepting MSI_DATA read at 0x%llx, returning 0x%x\n",
+ pos, tmp_val);
+ } else {
+ return -ENOTTY;
+ }
+ } else {
+ return -ENOTTY;
+ }
+
+ if (copy_to_user(buf, &tmp_val, count))
+ return -EFAULT;
+
+ return count;
+}
+
+/**
+ * qcom_vfio_pci_config_rw - Config space read/write with MSI interception
+ * @qdev: Qualcomm VFIO device
+ * @buf: User buffer
+ * @count: Size
+ * @offset: Config space offset (0-0xFFF)
+ * @iswrite: true for write, false for read
+ *
+ * Returns: Number of bytes transferred, or -ENOTTY if not intercepted
+ */
+ssize_t qcom_vfio_pci_config_rw(struct qcom_vfio_pci_device *qdev,
+ char __user *buf, size_t count,
+ loff_t offset, bool iswrite)
+{
+ int msi_range_start, msi_range_end;
+
+ if (iswrite)
+ return -ENOTTY;
+
+ if (!qdev->msi_offset)
+ return -ENOTTY;
+
+ msi_range_start = qdev->msi_offset;
+ msi_range_end = qdev->msi_offset + QCOM_VFIO_MSI_SPACE_SIZE;
+
+ if (offset >= msi_range_start && offset < msi_range_end)
+ return qcom_intercept_msi_read(qdev, offset, buf, count);
+
+ return -ENOTTY;
+}
diff --git a/drivers/vfio/pci/qcom/qcom_vfio_pci.h b/drivers/vfio/pci/qcom/qcom_vfio_pci.h
new file mode 100644
index 0000000000000..50c70375ad5f6
--- /dev/null
+++ b/drivers/vfio/pci/qcom/qcom_vfio_pci.h
@@ -0,0 +1,36 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* SPDX-FileCopyrightText: Copyright Red Hat */
+
+#ifndef _QCOM_VFIO_PCI_H_
+#define _QCOM_VFIO_PCI_H_
+
+#include <linux/vfio_pci_core.h>
+#include <linux/qcom_vfio.h>
+
+/**
+ * struct qcom_vfio_pci_device - Qualcomm VFIO PCI device with quirks
+ * @vdev: Core VFIO PCI device
+ * @msi_offset: Base offset in extended config for MSI passthrough (0 if disabled)
+ * @msi_cached: Whether host MSI address/data has been cached
+ * @msi_addr_lo: Cached host MSI address (low 32 bits)
+ * @msi_addr_hi: Cached host MSI address (high 32 bits)
+ * @msi_data: Cached host MSI data value
+ */
+struct qcom_vfio_pci_device {
+ struct vfio_pci_core_device vdev;
+
+ /* MSI quirk state */
+ int msi_offset;
+ bool msi_cached;
+ u32 msi_addr_lo;
+ u32 msi_addr_hi;
+ u16 msi_data;
+};
+
+/* MSI quirk functions */
+ssize_t qcom_vfio_pci_config_rw(struct qcom_vfio_pci_device *qdev,
+ char __user *buf, size_t count,
+ loff_t offset, bool iswrite);
+void qcom_cache_and_write_msi(struct qcom_vfio_pci_device *qdev);
+
+#endif /* _QCOM_VFIO_PCI_H_ */
diff --git a/include/linux/pci.h b/include/linux/pci.h
index d31a8d107b1ef..c63de78bfd66f 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -1299,6 +1299,7 @@ u8 pci_find_ht_capability(struct pci_dev *dev, int ht_cap);
u8 pci_find_next_ht_capability(struct pci_dev *dev, u8 pos, int ht_cap);
u16 pci_find_ext_capability(struct pci_dev *dev, int cap);
u16 pci_find_next_ext_capability(struct pci_dev *dev, u16 pos, int cap);
+int pci_find_free_ext_cap_offset(struct pci_dev *dev, size_t size);
struct pci_bus *pci_find_next_bus(const struct pci_bus *from);
u16 pci_find_vsec_capability(struct pci_dev *dev, u16 vendor, int cap);
u16 pci_find_dvsec_capability(struct pci_dev *dev, u16 vendor, u16 dvsec);
@@ -2199,6 +2200,8 @@ static inline u8 pci_find_next_capability(struct pci_dev *dev, u8 post, int cap)
{ return 0; }
static inline u16 pci_find_ext_capability(struct pci_dev *dev, int cap)
{ return 0; }
+static inline int pci_find_free_ext_cap_offset(struct pci_dev *dev, size_t size)
+{ return 0; }
static inline u64 pci_get_dsn(struct pci_dev *dev)
{ return 0; }
diff --git a/include/linux/qcom_vfio.h b/include/linux/qcom_vfio.h
new file mode 100644
index 0000000000000..7553bc382c8e4
--- /dev/null
+++ b/include/linux/qcom_vfio.h
@@ -0,0 +1,90 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* SPDX-FileCopyrightText: Copyright Red Hat */
+
+#ifndef _QCOM_VFIO_H_
+#define _QCOM_VFIO_H_
+
+#include <linux/pci.h>
+
+/*
+ * MSI Address Passthrough Quirk
+ *
+ * Qualcomm device firmware requires physical host MSI addresses rather than
+ * guest IOVA addresses. The qcom-vfio-pci variant driver caches host MSI
+ * values in extended PCI config space with a magic signature for VM
+ * discovery.
+ *
+ * Protocol:
+ * 1. Host: qcom-vfio-pci finds free space in extended config (0x100-0xFFF)
+ * 2. Host: Writes magic signature "QMSI" (0x49534D51) followed by MSI data
+ * 3. VM: Device driver searches for "QMSI" signature to locate cached MSI
+ * 4. VM: Reads MSI values and programs device firmware
+ *
+ * This avoids offset mismatch when QEMU filters certain capabilities, causing
+ * host and VM to see different extended capability chains.
+ *
+ * Layout in extended config space:
+ * +0x00: Magic signature "QMSI" (0x49534D51)
+ * +0x04: MSI address low 32 bits
+ * +0x08: MSI address high 32 bits
+ * +0x0C: MSI data (16 bits)
+ *
+ * Used by Qualcomm ath11k/ath12k WiFi devices. Supported PCI IDs
+ * are listed in the qcom-vfio-pci variant driver.
+ */
+
+/* Magic signature "QMSI" to identify cached MSI data */
+#define QCOM_VFIO_MSI_MAGIC 0x49534D51
+
+/* Space needed for magic + MSI passthrough data */
+#define QCOM_VFIO_MSI_SPACE_SIZE 16
+
+/* Relative offsets from base discovered by qcom_vfio_find_msi_offset() */
+#define QCOM_VFIO_MSI_MAGIC_OFFSET 0x00 /* Magic signature "QMSI" */
+#define QCOM_VFIO_MSI_ADDR_LO_OFFSET 0x04 /* Host MSI address low 32 bits */
+#define QCOM_VFIO_MSI_ADDR_HI_OFFSET 0x08 /* Host MSI address high 32 bits */
+#define QCOM_VFIO_MSI_DATA_OFFSET 0x0C /* Host MSI data (16 bits) */
+
+/**
+ * qcom_vfio_find_msi_offset - Find free space for host to cache MSI
+ * @pdev: PCI device
+ *
+ * Host-side function: Finds free space in extended config to write MSI cache.
+ * Uses PCI core utility to scan capability chain.
+ *
+ * Returns: Offset in extended config space (>= 0x100), or 0 if no space found
+ */
+static inline int qcom_vfio_find_msi_offset(struct pci_dev *pdev)
+{
+ return pci_find_free_ext_cap_offset(pdev, QCOM_VFIO_MSI_SPACE_SIZE);
+}
+
+/**
+ * qcom_vfio_find_msi_cache - Locate cached MSI data by magic signature
+ * @pdev: PCI device
+ *
+ * VM-side function: Searches extended config space for "QMSI" magic signature
+ * to locate host-cached MSI values. This avoids offset mismatch when QEMU
+ * filters certain capabilities. Config reads go through QEMU's VFIO
+ * virtualization, so no hardware side-effects or URs will occur.
+ *
+ * Returns: Offset of MSI data (after magic), or 0 if not found
+ */
+static inline int qcom_vfio_find_msi_cache(struct pci_dev *pdev)
+{
+ u32 magic;
+ int offset;
+
+ for (offset = PCI_CFG_SPACE_SIZE;
+ offset <= PCI_CFG_SPACE_EXP_SIZE - QCOM_VFIO_MSI_SPACE_SIZE;
+ offset += 4) {
+ if (pci_read_config_dword(pdev, offset, &magic))
+ continue;
+ if (magic == QCOM_VFIO_MSI_MAGIC)
+ return offset;
+ }
+
+ return 0;
+}
+
+#endif /* _QCOM_VFIO_H_ */
|
| 3/2 | 2026/10/11 07:56 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 18394 output: 26 thoughts: 1280 Thoughts: **Analyzing the Patch for Fuzzing Potential** Okay, let's break this patch down and figure out if it's even *worth* considering for fuzzing. We need to determine if it's reachable in a standard QEMU environment and, if so, what kind of configuration and target symbols we should focus on. First, I've got to understand the scope of the changes. The patch touches a bunch of files related to Qualcomm WiFi drivers: `ath11k` and `ath12k` PCI drivers, the PCI core, and VFIO. It looks like we've got some return type changes for error handling in the `ath11k` and `ath12k` drivers. Also some interesting changes around MSI (Message Signaled Interrupts) cacheing, with `qcom_vfio_find_msi_cache`. The core PCI code gets a new function `pci_find_free_ext_cap_offset`. And, crucially, there's a new `qcom-vfio-pci` driver, which includes a bunch of functions like read, init, open/close, ioctl, probe, and remove, as well as functions for cacheing and writing MSIs. Now, here's where things get tricky. I need to make sure this code is actually *reachable* in a typical fuzzing setup. I have to apply my knowledge of what is structurally unreachable, per the instructions. Is this `ath11k` / `ath12k` hardware *physical*? Specifically, can these Qualcomm WiFi devices be emulated in standard QEMU? Based on the instructions, anything requiring physical hardware, like specialized PCIe switches, SmartNICs, or GPU drivers that *aren't* emulated in standard QEMU, is a no-go. The critical question here is whether the `qcom-vfio-pci` driver is reachable in QEMU. It's a VFIO driver, but is it tied to the physical hardware somehow? The table shows that it targets Qualcomm WiFi devices (0x1103, 0x1107). Can this device be emulated in standard QEMU? **No.** QEMU doesn't emulate the Qualcomm `ath11k` or `ath12k` PCIe devices! The patch includes the introduction of `pci_find_free_ext_cap_offset`. I need to figure out where that's called because the core PCI code is often reachable. Therefore, the `qcom-vfio-pci` driver is not reachable. This whole patch is probably not worth the effort because it requires specific hardware that isn't emulated. |
| 4/2 | 2026/10/11 07:56 | tool | grepper |
0mArgs:{
"Expression": "pci_find_free_ext_cap_offset"
}Results: {
"Output": "drivers/pci/pci.c=545=EXPORT_SYMBOL_GPL(pci_find_ext_capability);\n--\ndrivers/pci/pci.c-547-/**\ndrivers/pci/pci.c:548: * pci_find_free_ext_cap_offset - Find free space in extended config\ndrivers/pci/pci.c-549- * @dev: PCI device to query\n--\ndrivers/pci/pci.c-559- */\ndrivers/pci/pci.c:560:int pci_find_free_ext_cap_offset(struct pci_dev *dev, size_t size)\ndrivers/pci/pci.c-561-{\n--\ndrivers/pci/pci.c-616-}\ndrivers/pci/pci.c:617:EXPORT_SYMBOL_GPL(pci_find_free_ext_cap_offset);\ndrivers/pci/pci.c-618-\n--\ninclude/linux/pci.h=1301=u16 pci_find_next_ext_capability(struct pci_dev *dev, u16 pos, int cap);\ninclude/linux/pci.h:1302:int pci_find_free_ext_cap_offset(struct pci_dev *dev, size_t size);\ninclude/linux/pci.h-1303-struct pci_bus *pci_find_next_bus(const struct pci_bus *from);\n--\ninclude/linux/pci.h=2201=static inline u16 pci_find_ext_capability(struct pci_dev *dev, int cap)\ninclude/linux/pci.h-2202-{ return 0; }\ninclude/linux/pci.h:2203:static inline int pci_find_free_ext_cap_offset(struct pci_dev *dev, size_t size)\ninclude/linux/pci.h-2204-{ return 0; }\n--\ninclude/linux/qcom_vfio.h=57=static inline int qcom_vfio_find_msi_offset(struct pci_dev *pdev)\ninclude/linux/qcom_vfio.h-58-{\ninclude/linux/qcom_vfio.h:59:\treturn pci_find_free_ext_cap_offset(pdev, QCOM_VFIO_MSI_SPACE_SIZE);\ninclude/linux/qcom_vfio.h-60-}\n"
} |
| 5/2 | 2026/10/11 07:56 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 20912 output: 149 thoughts: 3132 Thoughts: **Analysis of Reachability for Fuzzing** Okay, so here's the deal. I'm looking at this patch and my initial thought is, "Wait a minute, is this even something syzkaller *can* reach?" The code changes involve `pci_find_free_ext_cap_offset` which seems pretty isolated and is called by `qcom_vfio_find_msi_offset`, which in turn is only called by code specific to `qcom-vfio-pci`. And further digging shows that `qcom-vfio-pci` only interfaces with the `ath11k` and `ath12k` drivers. My brain immediately goes, "Qualcomm WiFi...PCIe...aha!" This isn't just generic PCIe stuff. The `ath11k` and `ath12k` are specifically Qualcomm wireless PCIe chipsets (0x1103 and 0x1107). They are *physical* devices. The patch is clearly addressing specific quirks or configurations related to *those* physical cards. Now I'm thinking about the syzkaller setup. Can syzkaller reach these devices? Does it emulate them? No! Standard QEMU doesn't emulate these types of cards, it's just got the basics like virtio. Then I quickly remember the negative criteria for `WorthFuzzing`. The instructions are clear: if the code relies on "structurally unreachable hardware...requiring physical ASIC/PCIe cards not emulated in standard QEMU," then we should return `WorthFuzzing=false`. This seems to fit *perfectly*. `qcom-vfio-pci` is there to pass through those physical cards to a VM. It needs the physical card on the host, and the VM needs either VFIO (passed through) or the standard driver (if running natively). It can't run without that physical hardware. And the `ath11k` and `ath12k` drivers clearly depend on the presence of that same hardware to probe and function. I try to shake loose any possible edge cases: does `syzkaller` ever create devices, could there be a weird `new_id` binding in sysfs that would make it work? It doesn't. No sysfs binding, nothing. I check Section 1 of the instructions... "reachability is the primary gate," and, again, section 2. I check Section 3, looking for virtio or other virtual buses, but that's not what is happening here. `ath11k` and `ath12k` are not `mac80211_hwsim` either. No, they are independent hardware drivers, which register mac80211 hw devices when physical hardware is probed. So, the conclusion is easy, the only part that is modified is `qcom-vfio-pci` and those are specific to Qualcomm WiFi PCIe cards. There is no other path, nothing in core PCIe or virtual that is going to call this function. Ultimately, all these changes, including the helper function in `pci.c`, are *entirely* reliant on the presence of these very specific, physical Qualcomm WiFi PCIe cards, and the standard syzkaller setup *cannot* reach that hardware. The patch modifies drivers that probe those, reset, and configure them. Everything falls squarely under the "structurally unreachable hardware" negative criteria. Thus, WorthFuzzing=false. Let's make that call. |
| 6/2 | 2026/10/11 07:56 | tool | set-results |
0mArgs:{
"EnableConfigs": [],
"FocusSymbols": [],
"Reasoning": "The patch introduces a VFIO PCI variant driver (qcom-vfio-pci), helper function pci_find_free_ext_cap_offset(), and MSI/reset handling adjustments in the Qualcomm ath11k and ath12k PCI drivers. All modified code specifically targets physical Qualcomm WiFi PCIe hardware (ath11k and ath12k chipsets) for device operation and host-to-VM passthrough. Standard virtualized fuzzing environments (QEMU/GCE) lack emulation for these Qualcomm PCIe devices, making the code structurally unreachable.",
"WorthFuzzing": false
}Results: {
"EnableConfigs": null,
"FocusSymbols": [],
"Reasoning": "The patch introduces a VFIO PCI variant driver (qcom-vfio-pci), helper function pci_find_free_ext_cap_offset(), and MSI/reset handling adjustments in the Qualcomm ath11k and ath12k PCI drivers. All modified code specifically targets physical Qualcomm WiFi PCIe hardware (ath11k and ath12k chipsets) for device operation and host-to-VM passthrough. Standard virtualized fuzzing environments (QEMU/GCE) lack emulation for these Qualcomm PCIe devices, making the code structurally unreachable.",
"WorthFuzzing": false
} |
| 7/1 | 2026/10/11 07:56 | action | If |
0mArgs:{
"WorthFuzzing": false
}Results: null |
| Total Calls | Total Tokens | Avg Tokens | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|
| Total Calls | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|