[PATCH v2 5/7] ath11k: Use VFIO MSI cache when available

From: Jose Ignacio Tornos Martinez

Date: Sun Oct 11 2026 - 03:49:21 EST


The Qualcomm ath11k firmware requires physical host MSI addresses for
interrupt configuration but cannot handle IOVA-based MSI addressing in
virtualized environments.

When the device is passed through to a VM via VFIO:
- The guest kernel allocates MSI vectors and sees IOVA addresses
- The ath11k firmware expects physical host MSI addresses
- Providing IOVA to the firmware causes interrupt delivery to fail
- Result: device is non-functional in VMs

The qcom-vfio-pci variant driver (introduced in earlier patches) solves
this by caching the physical host MSI values and exposing them through
PCI extended config space with a "QMSI" magic signature for discovery.

Search for the QMSI magic signature in extended config space. If found,
the device is running on a VM and we can read the cached host MSI values
from that location. If the VFIO cache is not present (i.e. on baremetal),
fall back to standard PCI MSI configuration.

This change is transparent, arch independent and requires no user
configuration when used with the qcom-vfio-pci driver.

Signed-off-by: Jose Ignacio Tornos Martinez <jtornosm@xxxxxxxxxx>
---
v2: Address Sashiko comments:
- Add vfio_msi_cached flag to ath11k_pci struct to track when VFIO
cached values are in use
- Guard config_msi_data() to skip overwrite when VFIO cached values
are already set, preventing guest virtual MSI data from overwriting
host physical values
v1: https://lore.kernel.org/all/20260930140833.576941-6-jtornosm@xxxxxxxxxx/

drivers/net/wireless/ath/ath11k/pci.c | 37 +++++++++++++++++++++++++++
drivers/net/wireless/ath/ath11k/pci.h | 2 ++
2 files changed, 39 insertions(+)

diff --git a/drivers/net/wireless/ath/ath11k/pci.c b/drivers/net/wireless/ath/ath11k/pci.c
index c372676b097f..b5e4a3f21d89 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"
@@ -463,8 +464,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,
@@ -488,6 +492,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);
@@ -527,7 +561,10 @@ static void ath11k_pci_free_msi(struct ath11k_pci *ab_pci)
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");
diff --git a/drivers/net/wireless/ath/ath11k/pci.h b/drivers/net/wireless/ath/ath11k/pci.h
index 9a17fbc1e5d2..4c8b6d3f7a21 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)
--
2.55.0