Linux PCI Non-Transparent Bridge framework and drivers
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Koichiro Den" <den@valinux.co.jp>
Cc: ntb@lists.linux.dev, linux-pci@vger.kernel.org
Subject: Re: [PATCH v3 6/7] NTB: ntb_hw_epf: Discover vNTB-embedded DMA
Date: Mon, 31 Aug 2026 21:20:43 +0000	[thread overview]
Message-ID: <20260831212043.E1C5B1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260831182657.329614-7-den@valinux.co.jp>

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:

New issues:
- [High] Probe fails entirely if the endpoint advertises an unsupported DMA type or if dw-edma host support is missing.
- [High] Strictly demanding `dma_irqs` extra MSI/MSI-X vectors breaks probe on IRQ-constrained systems.

Pre-existing issues:
- [Critical] Dynamic reading of the SPAD offset without validation allows a malicious endpoint to cause arbitrary host MMIO read/write.
- [High] Pre-existing race condition in `ntb_epf_mw_set_trans` where multiple concurrent calls can interleave writes to shared memory window configuration registers.
--

commit 9b8b5f4c03fc934132c68dec22efe8a4ca1332ef
Author: Koichiro Den <den@valinux.co.jp>

NTB: ntb_hw_epf: Discover vNTB-embedded DMA

A vNTB PCI function can now expose endpoint-local DMA channels to its
host. This patch decodes the extension and registers the advertised
channels before the NTB device.

> diff --git a/drivers/ntb/hw/epf/ntb_hw_epf.c b/drivers/ntb/hw/epf/ntb_hw_epf.c
> index c47607d4f8a7f..16cde97d4bde2 100644
> --- a/drivers/ntb/hw/epf/ntb_hw_epf.c
> +++ b/drivers/ntb/hw/epf/ntb_hw_epf.c

[ ... ]

> @@ -373,15 +681,19 @@ static int ntb_epf_init_isr(struct ntb_epf_dev *ndev, int msi_min, int msi_max)
>  {
>  	struct pci_dev *pdev = ndev->ntb.pdev;
>  	struct device *dev = ndev->dev;
> +	unsigned int dma_irqs = ndev->dma.nr_irqs;
> +	unsigned int ntb_irqs;
>  	u32 argument = MSIX_ENABLE;
>  	int irq;
>  	int ret;
>  	int i;
>  
> -	irq = pci_alloc_irq_vectors(pdev, msi_min, msi_max, PCI_IRQ_MSIX);
> +	irq = pci_alloc_irq_vectors(pdev, msi_min + dma_irqs,
> +				    msi_max + dma_irqs, PCI_IRQ_MSIX);

[Severity: High]
Will strictly demanding the extra dma_irqs break probe on IRQ-constrained
host systems?

If the host platform can only supply fewer vectors than the minimum
requested here (which can inflate up to 10 if the endpoint advertises 8
DW eDMA channels), pci_alloc_irq_vectors() will return a negative error
code.

Should the driver request only the minimum required for basic NTB
operation, and selectively allocate or disable DMA channels based on the
number of vectors actually granted?

[ ... ]

> @@ -486,7 +799,7 @@ static int ntb_epf_mw_set_trans(struct ntb_dev *ntb, int pidx, int idx,
>  	if (bar < 0)
>  		return bar;
>  
> -	mw_size = pci_resource_len(ntb->pdev, bar);
> +	mw_size = ntb_epf_mw_size(ndev, idx, bar);
>  
>  	if (size > mw_size) {
>  		dev_err(dev, "Size:%pa is greater than the MW size %pa\n",

[Severity: High]
This is a pre-existing issue, but can concurrent calls to
ntb_epf_mw_set_trans() corrupt the memory window configurations?

The function writes to a shared set of registers across memory windows
right after this block:

writel(lower_32_bits(addr), ndev->ctrl_reg + NTB_EPF_LOWER_ADDR);
writel(upper_32_bits(addr), ndev->ctrl_reg + NTB_EPF_UPPER_ADDR);
writel(lower_32_bits(size), ndev->ctrl_reg + NTB_EPF_LOWER_SIZE);
writel(upper_32_bits(size), ndev->ctrl_reg + NTB_EPF_UPPER_SIZE);

It then calls ntb_epf_send_command(), which is where ndev->cmd_lock is
finally acquired. If multiple threads configure different memory windows
concurrently, can their writes interleave and send a corrupted mixture of
addresses and sizes?

[ ... ]

> @@ -785,6 +1114,12 @@ static int ntb_epf_pci_probe(struct pci_dev *pdev,
>  		goto err_init_dev;
>  	}
>  
> +	ret = ntb_epf_dma_init(ndev);
> +	if (ret) {
> +		dev_err(dev, "Failed to initialize endpoint DMA\n");
> +		goto err_dma_init;
> +	}

[Severity: High]
If the endpoint advertises an unsupported DMA type, or if the host kernel
is compiled without CONFIG_DW_EDMA, ntb_epf_dma_init() will fail. Does
this mean the entire NTB device initialization will completely abort here?

Since the DMA extension is optional, would it be better to log a warning
and fall back to the existing non-DMA path instead of completely rejecting
the device?


While reviewing this file, I also noticed a pre-existing issue in
ntb_epf_spad_read() and ntb_epf_spad_write() which are not modified by
this patch:

[Severity: Critical]
This isn't a bug introduced by this patch, but is it safe to use the SPAD
offset directly from hardware for an IOMEM read or write without
validation?

In ntb_epf_spad_read(), the offset is read dynamically:

offset = readl(ndev->ctrl_reg + NTB_EPF_SPAD_OFFSET);
offset += (idx << 2);
return readl(ndev->ctrl_reg + offset);

Since the PCIe endpoint controls its configuration space, a malicious or
compromised endpoint could modify NTB_EPF_SPAD_OFFSET to an arbitrarily
large 32-bit value. Does this allow the endpoint to trigger an
unvalidated out-of-bounds MMIO read or write on the host?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260831182657.329614-1-den@valinux.co.jp?part=6

  reply	other threads:[~2026-08-31 21:20 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-31 18:26 [PATCH v3 0/7] PCI: endpoint: Remote DMA support via vNTB Koichiro Den
2026-08-31 18:26 ` [PATCH v3 1/7] PCI: endpoint: Add DMA auxiliary resource metadata Koichiro Den
2026-08-31 20:22   ` sashiko-bot
2026-08-31 18:26 ` [PATCH v3 2/7] PCI: dwc: Expose endpoint DMA resources Koichiro Den
2026-08-31 20:34   ` sashiko-bot
2026-08-31 18:26 ` [PATCH v3 3/7] PCI: endpoint: pci-epf-vntb: Move epf_ntb_is_bar_used() up Koichiro Den
2026-08-31 20:35   ` sashiko-bot
2026-08-31 18:26 ` [PATCH v3 4/7] PCI: endpoint: pci-epf-vntb: Export endpoint DMA channels Koichiro Den
2026-08-31 20:52   ` sashiko-bot
2026-09-03 21:20   ` Frank Li
2026-09-04  1:34     ` Koichiro Den
2026-08-31 18:26 ` [PATCH v3 5/7] PCI: endpoint: pci-epf-vntb: Allow DMA and MW to share a BAR Koichiro Den
2026-08-31 21:05   ` sashiko-bot
2026-09-02  2:40     ` Koichiro Den
2026-08-31 18:26 ` [PATCH v3 6/7] NTB: ntb_hw_epf: Discover vNTB-embedded DMA Koichiro Den
2026-08-31 21:20   ` sashiko-bot [this message]
2026-08-31 18:26 ` [PATCH v3 7/7] Documentation: PCI: endpoint: Document vNTB DMA export Koichiro Den
2026-08-31 21:21   ` sashiko-bot
2026-09-03 11:43 ` [PATCH v3 0/7] PCI: endpoint: Remote DMA support via vNTB Manivannan Sadhasivam
2026-09-03 15:13   ` Koichiro Den

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=20260831212043.E1C5B1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=den@valinux.co.jp \
    --cc=linux-pci@vger.kernel.org \
    --cc=ntb@lists.linux.dev \
    --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