Linux PCI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jose Ignacio Tornos Martinez" <jtornosm@redhat.com>
Cc: linux-pci@vger.kernel.org, kvm@vger.kernel.org
Subject: Re: [PATCH 2/7] vfio: Add qcom_vfio.h header for MSI cache protocol
Date: Wed, 30 Sep 2026 14:31:48 +0000	[thread overview]
Message-ID: <20260930143149.0F62D1F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260930140833.576941-3-jtornosm@redhat.com>

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [Critical] vfio: protocol abuses hardware config space risking data corruption
- [High] vfio: blind config space scan causes URs and read side-effects
- [High] vfio: false positive MSI discovery from arbitrary config data
- [Medium] vfio: incomplete MSI cache search bounds silently fails
--

commit e548d5bbb36a1137ddec4454b7d63b995f23989e
Author: Jose Ignacio Tornos Martinez <jtornosm@redhat.com>

vfio: Add qcom_vfio.h header for MSI cache protocol

Add shared header defining the communication protocol between
qcom-vfio-pci variant driver and Qualcomm device drivers (ath11k,
ath12k) for passing physical host MSI addresses to VMs.

Qualcomm device firmware requires physical host MSI addresses rather
than guest IOVA addresses. The qcom-vfio-pci driver caches host MSI
values in extended PCI config space with a magic signature "QMSI" for
VM discovery.

> diff --git a/include/linux/qcom_vfio.h b/include/linux/qcom_vfio.h
> new file mode 100644
> index 0000000000000..2ed1ea0c1a604
> --- /dev/null
> +++ b/include/linux/qcom_vfio.h
[ ... ]
> +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);
> +}

[Severity: Critical]
Does using pci_find_free_ext_cap_offset() here risk corrupting active
hardware capabilities?

pci_find_free_ext_cap_offset() relies on a heuristic that assumes the last
extended capability is exactly 64 bytes:

drivers/pci/pci.c:pci_find_free_ext_cap_offset() {
    ...
    free_offset = last_cap_start + 64;
    free_offset = ALIGN(free_offset, 4);
    ...
}

If the final capability is larger (such as AER, DPC, or VSEC), this
allocation would return an offset inside the active capability. Will the
host driver physically writing MSI data to this offset silently corrupt the
device's hardware capability state?

> +
> +/**
> + * 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.
> + *
> + * 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 = 0x100; offset <= 0xf00; offset += 4) {

[Severity: Medium]
Will this loop prematurely terminate and fail to find the MSI cache if the
offset is allocated above 0xf00?

The host driver uses pci_find_free_ext_cap_offset(), which can legitimately
return an offset up to 0xff0 in the 4096-byte PCIe extended config space.
If the cache block is placed between 0xf04 and 0xff0, the guest driver
would silently fail to discover the magic signature.

> +		if (pci_read_config_dword(pdev, offset, &magic))
> +			continue;

[Severity: High]
Does blindly reading every DWORD in the extended config space risk bus
errors and unintended hardware side effects?

Iterating through the configuration space without walking the PCIe
capability linked list means reading active capability registers
arbitrarily. This can trigger unintended read side-effects, such as
clearing Read-to-Clear (RC) status bits.

Furthermore, reading unmapped PCIe configuration space can generate
Unsupported Request (UR) bus errors. On some systems, URs escalate to
Advanced Error Reporting (AER) faults or system hangs.

> +		if (magic == QCOM_VFIO_MSI_MAGIC)
> +			return offset;

[Severity: High]
Could this lead to false positive MSI discoveries if active registers or
payloads contain this value?

Since the loop scans the entire config space instead of parsing
vendor-specific capabilities, a legitimate device register, statistics
counter, or VSEC payload might naturally contain the 32-bit value
0x49534D51 (QMSI).

If falsely identified, the guest driver would interpret the subsequent 12
bytes as physical MSI addresses and mistakenly program invalid addresses
into the device firmware.

> +	}
> +
> +	return 0;
> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260930140833.576941-1-jtornosm@redhat.com?part=2

  reply	other threads:[~2026-09-30 14:31 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-30 14:08 [PATCH 0/7] Enable Qualcomm WiFi PCIe passthrough to VMs Jose Ignacio Tornos Martinez
2026-09-30 14:08 ` [PATCH 1/7] PCI: Add pci_find_free_ext_cap_offset() helper Jose Ignacio Tornos Martinez
2026-09-30 14:21   ` sashiko-bot
2026-09-30 14:08 ` [PATCH 2/7] vfio: Add qcom_vfio.h header for MSI cache protocol Jose Ignacio Tornos Martinez
2026-09-30 14:31   ` sashiko-bot [this message]
2026-09-30 14:08 ` [PATCH 3/7] vfio/pci: Add qcom-vfio-pci variant driver Jose Ignacio Tornos Martinez
2026-09-30 14:45   ` sashiko-bot
2026-09-30 15:12   ` Jason Gunthorpe
2026-10-01  7:19     ` Jose Ignacio Tornos Martinez
2026-10-02 17:10       ` Jason Gunthorpe
2026-10-05 11:01         ` Jose Ignacio Tornos Martinez
2026-09-30 14:08 ` [PATCH 4/7] ath11k: add PCIe link recovery retry Jose Ignacio Tornos Martinez
2026-09-30 14:56   ` sashiko-bot
2026-09-30 14:08 ` [PATCH 5/7] ath11k: Use VFIO MSI cache when available Jose Ignacio Tornos Martinez
2026-09-30 15:08   ` sashiko-bot
2026-09-30 14:08 ` [PATCH 6/7] ath12k: add PCIe link recovery retry Jose Ignacio Tornos Martinez
2026-09-30 15:17   ` sashiko-bot
2026-09-30 14:08 ` [PATCH 7/7] ath12k: Use VFIO MSI cache when available Jose Ignacio Tornos Martinez
2026-09-30 15:29   ` sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260930143149.0F62D1F00893@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=jtornosm@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox