[PATCH 03/11] PCI: epf-mhi: Add MSI-X support

sashiko-bot at kernel.org sashiko-bot at kernel.org
Sat Nov 21 19:15:11 PST 2026


Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] PCI: epf-mhi: msix_bar and epf_bar collide on BAR_0 in
  pci_epf_mhi_epc_init()
- [Medium] PCI: epf-mhi: stale msix_phys retained across unbind in
  pci_epf_mhi_bind()
- [Medium] PCI: epf-mhi: unguarded pci_epc_get_msix() in
  pci_epf_mhi_raise_irq()
--

commit ff5df916c7bb4879ef75224bb4a16f16be1ead17
Author: Anvita T <anvita.t at oss.qualcomm.com>

PCI: epf-mhi: Add MSI-X support

This commit adds MSI-X support to the MHI PCI endpoint function driver by
configuring BAR_0 from an optional "msix" platform memory resource and
selecting PCI_IRQ_MSIX when MSI-X is enabled.

> diff --git a/drivers/pci/endpoint/functions/pci-epf-mhi.c b/drivers/pci/endpoint/functions/pci-epf-mhi.c
> index 52cfffcfd5ca0..a8765beffe060 100644
> --- a/drivers/pci/endpoint/functions/pci-epf-mhi.c
> +++ b/drivers/pci/endpoint/functions/pci-epf-mhi.c
[ ... ]
> @@ -230,12 +232,16 @@ static void pci_epf_mhi_raise_irq(struct mhi_ep_cntrl *mhi_cntrl, u32 vector)
>  	struct pci_epf_mhi *epf_mhi = to_epf_mhi(mhi_cntrl);
>  	struct pci_epf *epf = epf_mhi->epf;
>  	struct pci_epc *epc = epf->epc;
> +	unsigned int type = PCI_IRQ_MSI;
> +
> +	if (pci_epc_get_msix(epc, epf->func_no, epf->vfunc_no) > 0)
> +		type = PCI_IRQ_MSIX;
>  
>  	/*
>  	 * MHI supplies 0 based MSI vectors but the API expects the vector
>  	 * number to start from 1, so we need to increment the vector by 1.
>  	 */
> -	pci_epc_raise_irq(epc, epf->func_no, epf->vfunc_no, PCI_IRQ_MSI,
> +	pci_epc_raise_irq(epc, epf->func_no, epf->vfunc_no, type,
>  			  vector + 1);
>  }

[Severity: Medium]
Should pci_epf_mhi_raise_irq() check epf_mhi->epc_features->msix_capable
before calling pci_epc_get_msix()?

Without that check, every MHI interrupt acquires epc->lock an extra time
(contending with pci_epc_map_addr() and pci_epc_unmap_addr() in the data
path) and calls epc->ops->get_msix(), which on DesignWare controllers
walks ep->func_list and reads PCI_MSIX_FLAGS over DBI MMIO even when
msix_capable is false.

> @@ -714,11 +720,40 @@ static int pci_epf_mhi_epc_init(struct pci_epf *epf)
>  {
>  	struct pci_epf_mhi *epf_mhi = epf_get_drvdata(epf);
>  	const struct pci_epf_mhi_ep_info *info = epf_mhi->info;
> +	struct pci_epf_bar *msix_bar = &epf->bar[BAR_0];
>  	struct pci_epf_bar *epf_bar = &epf->bar[info->bar_num];
>  	struct pci_epc *epc = epf->epc;
>  	struct device *dev = &epf->dev;
>  	int ret;
>  
> +	epf_mhi->epc_features = pci_epc_get_features(epc, epf->func_no, epf->vfunc_no);
> +	if (!epf_mhi->epc_features)
> +		return -ENODATA;
> +
> +	if (epf_mhi->epc_features->msix_capable) {
> +		if (!epf_mhi->msix_phys) {
> +			dev_err(dev, "MSI-X BAR address not configured in DT\n");
> +			return -EINVAL;
> +		}
> +
> +		msix_bar->phys_addr = epf_mhi->msix_phys;
> +		msix_bar->size = epf_mhi->msix_size;
> +		msix_bar->barno = BAR_0;
> +		msix_bar->flags = info->epf_flags;
> +		ret = pci_epc_set_bar(epc, epf->func_no, epf->vfunc_no, msix_bar);
> +		if (ret) {
> +			dev_err(dev, "Failed to set MSI-X BAR: %d\n", ret);
> +			return ret;
> +		}
> +
> +		ret = pci_epc_set_msix(epc, epf->func_no, epf->vfunc_no,
> +				       info->msi_count, BAR_0, 0);
> +		if (ret) {
> +			dev_err(dev, "Failed to set MSI-X configuration: %d\n", ret);
> +			return ret;
> +		}
> +	}
> +
>  	epf_bar->phys_addr = epf_mhi->mmio_phys;
>  	epf_bar->size = epf_mhi->mmio_size;
>  	epf_bar->barno = info->bar_num;

[Severity: High]
Does msix_bar collide with epf_bar on BAR_0 when info->bar_num is BAR_0?

All existing pci_epf_mhi_ep_info configurations (sdx55_info, sm8450_info,
and sa8775p_info) set .bar_num = BAR_0.  When bound to an MSI-X capable
controller, msix_bar and epf_bar point to the same epf->bar[BAR_0] entry:
pci_epf_mhi_epc_init() sets BAR_0 for MSI-X and points the MSI-X table at
BAR_0, then overwrites epf->bar[BAR_0] in place with mmio_phys and
mmio_size and calls pci_epc_set_bar() on BAR_0 a second time.

Because epf->bar[BAR_0] is mutated in place before the second call,
dw_pcie_ep_set_bar() compares the overwritten size against itself, tears
down the MSI-X inbound iATU mapping on BAR_0, skips updating the BAR mask
register (leaving BAR_0 sized to msix_size), and remaps BAR_0 to
mmio_phys while PCI_MSIX_TABLE still points at BAR_0.  In addition,
pci_epf_mhi_epc_deinit() and pci_epf_mhi_unbind() call
pci_epc_clear_bar() twice on &epf->bar[BAR_0].

[ ... ]
> @@ -880,6 +914,13 @@ static int pci_epf_mhi_bind(struct pci_epf *epf)
>  	if (!epf_mhi->mmio)
>  		return -ENOMEM;
>  
> +	/* MSI-X BAR address is optional; only present on EPCs that support MSI-X */
> +	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "msix");
> +	if (res) {
> +		epf_mhi->msix_phys = res->start;
> +		epf_mhi->msix_size = resource_size(res);
> +	}
> +
>  	ret = platform_get_irq_byname(pdev, "doorbell");
>  	if (ret < 0) {
>  		iounmap(epf_mhi->mmio);

[Severity: Medium]
Can epf_mhi->msix_phys and epf_mhi->msix_size retain stale values across
an unbind and rebind?

struct pci_epf_mhi is allocated in pci_epf_mhi_probe() and reused across
binds, and neither pci_epf_mhi_unbind() nor the !res path here clears
msix_phys or msix_size.  If the function is unbound from an EPC with an
"msix" resource and rebound to an MSI-X capable EPC where "msix" is
missing, pci_epf_mhi_epc_init() will see the previous controller's
non-zero msix_phys and program BAR_0 with the stale physical address.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261122-nord_ep-v1-0-6d8839ffa9aa@oss.qualcomm.com?part=3



More information about the linux-phy mailing list