Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Krishna Chaitanya Chundru" <krishna.chundru@oss.qualcomm.com>
Cc: linux-pci@vger.kernel.org, devicetree@vger.kernel.org,
	linux-phy@lists.infradead.org, robh@kernel.org,
	conor+dt@kernel.org, vkoul@kernel.org, neil.armstrong@linaro.org,
	olteanv@gmail.com
Subject: Re: [PATCH 03/11] PCI: epf-mhi: Add MSI-X support
Date: Sun, 22 Nov 2026 03:15:11 +0000	[thread overview]
Message-ID: <sashiko-outbox-227666@kernel.org> (raw)
In-Reply-To: <20261122-nord_ep-v1-3-6d8839ffa9aa@oss.qualcomm.com>

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@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

  reply	other threads:[~2026-11-22  3:15 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-22  2:56 [PATCH 00/11] PCI: qcom-ep: Add Nord PCIe Endpoint controller support Krishna Chaitanya Chundru
2026-11-22  2:56 ` [PATCH 01/11] PCI: epf-mhi: Pass the actual number of MSI vectors to pci_epc_set_msi() Krishna Chaitanya Chundru
2026-11-22  3:03   ` sashiko-bot
2026-11-22  2:56 ` [PATCH 02/11] PCI: qcom-ep: Add MSI-X support Krishna Chaitanya Chundru
2026-11-22  3:08   ` sashiko-bot
2026-11-22  2:56 ` [PATCH 03/11] PCI: epf-mhi: " Krishna Chaitanya Chundru
2026-11-22  3:15   ` sashiko-bot [this message]
2026-11-22  2:56 ` [PATCH 04/11] PCI: dwc: Preserve glue-provided eDMA HDMA channel separation Krishna Chaitanya Chundru
2026-11-22  2:56 ` [PATCH 05/11] phy: qcom: qmp-pcie: Add PCIe endpoint mode support Krishna Chaitanya Chundru
2026-11-22  2:56 ` [PATCH 06/11] phy: qcom: qmp-pcie: Add Nord endpoint mode init sequences Krishna Chaitanya Chundru
2026-11-22  2:56 ` [PATCH 07/11] dt-bindings: PCI: qcom-ep: Add Nord PCIe Endpoint Krishna Chaitanya Chundru
2026-11-22  2:56 ` [PATCH 08/11] PCI: qcom-ep: Add Nord PCIe Endpoint controller support Krishna Chaitanya Chundru
2026-11-22  3:08   ` sashiko-bot
2026-11-22  2:56 ` [PATCH 09/11] PCI: epf-mhi: Add Nord endpoint support Krishna Chaitanya Chundru
2026-11-22  2:56 ` [PATCH 10/11] bus: mhi: host: pci_generic: Add support for Qualcomm Nord Krishna Chaitanya Chundru
2026-11-22  3:19   ` sashiko-bot
2026-11-22  2:56 ` [PATCH 11/11] arm64: dts: qcom: nord: Add PCIe endpoint nodes Krishna Chaitanya Chundru
2026-11-22  3:17   ` 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=sashiko-outbox-227666@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=krishna.chundru@oss.qualcomm.com \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux-phy@lists.infradead.org \
    --cc=neil.armstrong@linaro.org \
    --cc=olteanv@gmail.com \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=vkoul@kernel.org \
    /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