All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Koichiro Den" <den@valinux.co.jp>
Cc: linux-pci@vger.kernel.org, ntb@lists.linux.dev
Subject: Re: [PATCH v2 5/5] NTB: ntb_hw_epf: Discover vNTB-embedded DMA
Date: Fri, 28 Aug 2026 17:24:31 +0000	[thread overview]
Message-ID: <20260828172432.016061F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260828170932.2735807-6-den@valinux.co.jp>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] Unaligned MMIO offset provided by untrusted device causes alignment fault and kernel panic.
- [Medium] Unsupported DMA extensions or insufficient IRQs cause the core NTB device probe to fail entirely, rather than gracefully falling back to a non-DMA mode.
- [Low] The macro or enum value DW_EDMA_CHIP_PARTIAL is not declared in the kernel tree.
--

commit 47ea035773d643574d3bec0ab584f66f7879214f
Author: Koichiro Den <den@valinux.co.jp>

NTB: ntb_hw_epf: Discover vNTB-embedded DMA

This commit allows a vNTB PCI function to expose endpoint-local DMA channels
to its host. It decodes the extension, registers advertised channels, and
dispatches on the advertised DMA type.

Link: https://lore.kernel.org/r/20260312165005.1148676-1-den@valinux.co.jp/
Link: https://lore.kernel.org/r/20260813063757.3131865-9-den@valinux.co.jp/

> diff --git a/drivers/ntb/hw/epf/ntb_hw_epf.c b/drivers/ntb/hw/epf/ntb_hw_epf.c
> --- a/drivers/ntb/hw/epf/ntb_hw_epf.c
> +++ b/drivers/ntb/hw/epf/ntb_hw_epf.c
[ ... ]
> +static bool ntb_epf_dma_region_parse(struct ntb_epf_dev *ndev, u32 base,
> +				     bool optional,
> +				     struct ntb_epf_dma_region *region)
> +{
> +	resource_size_t bar_len;
> +	u32 bar, offset, size;
> +
> +	bar = readl(ndev->ctrl_reg + NTB_EPF_DMA_REGION_BAR(base));
> +	offset = readl(ndev->ctrl_reg + NTB_EPF_DMA_REGION_OFFSET(base));

[Severity: High]
Is offset validated for alignment here? Since this is read directly from
the untrusted device configuration space, a malicious or buggy endpoint could
provide an unaligned offset.

[ ... ]
> +static int ntb_epf_dw_edma_map_region(struct pci_dev *pdev,
> +				      struct ntb_epf_dma_region *region)
> +{
> +	region->vaddr = pci_iomap_range(pdev, region->bar, region->offset,
> +					region->size);

[Severity: High]
If the region->offset provided by the endpoint is unaligned, does mapping
it via pci_iomap_range() yield an unaligned virtual address?

The dw_edma driver subsequently uses 32-bit accessors (readl) on this
mapping, which can cause an alignment fault (synchronous external abort) and
kernel panic.

[ ... ]
> +static int ntb_epf_dw_edma_init(struct ntb_epf_dev *ndev)
> +{
[ ... ]
> +	chip->dev = ndev->dev;
> +	chip->ops = &ntb_epf_dw_edma_ops;
> +	chip->flags = DW_EDMA_CHIP_PARTIAL;

[Severity: Low]
Does this code build? It looks like DW_EDMA_CHIP_PARTIAL is not declared
in the kernel tree. This might be a leftover from an unmerged or modified
prerequisite patch series.

[ ... ]
> +static int ntb_epf_dma_parse(struct ntb_epf_dev *ndev)
> +{
[ ... ]
> +	switch (type) {
> +	case NTB_EPF_DMA_TYPE_DW_EDMA:
> +		ret = ntb_epf_dw_edma_parse(ndev, length);
> +		break;
> +	default:
> +		return -EOPNOTSUPP;
> +	}

[Severity: Medium]
If the endpoint exposes a newer or unrecognized DMA type, this returns
-EOPNOTSUPP and causes the core NTB device probe to fail entirely.

Would it be better to gracefully fall back to a non-DMA mode so core NTB
functionality (doorbells, memory windows) remains available?

[ ... ]
>  	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: Medium]
This now strictly requires dma_irqs to be available. If a constrained host
platform lacks enough MSI/MSI-X vectors to satisfy the msi_min + dma_irqs
requirement, pci_alloc_irq_vectors() will fail.

Can we allow the initialization to proceed without DMA support in this
scenario instead of aborting the whole probe?

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

      reply	other threads:[~2026-08-28 17:24 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-28 17:09 [PATCH v2 0/5] PCI: endpoint: Remote DMA support via vNTB Koichiro Den
2026-08-28 17:09 ` [PATCH v2 1/5] PCI: endpoint: Add DMA auxiliary resource metadata Koichiro Den
2026-08-28 17:15   ` sashiko-bot
2026-08-28 18:48   ` Frank Li
2026-08-28 17:09 ` [PATCH v2 2/5] PCI: dwc: Expose endpoint DMA resources Koichiro Den
2026-08-28 17:16   ` sashiko-bot
2026-08-28 18:59   ` Frank Li
2026-08-28 17:09 ` [PATCH v2 3/5] PCI: endpoint: pci-epf-vntb: Move epf_ntb_is_bar_used() up Koichiro Den
2026-08-28 17:14   ` sashiko-bot
2026-08-28 18:59   ` Frank Li
2026-08-28 17:09 ` [PATCH v2 4/5] PCI: endpoint: pci-epf-vntb: Export endpoint DMA channels Koichiro Den
2026-08-28 17:24   ` sashiko-bot
2026-08-28 17:09 ` [PATCH v2 5/5] NTB: ntb_hw_epf: Discover vNTB-embedded DMA Koichiro Den
2026-08-28 17:24   ` sashiko-bot [this message]

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=20260828172432.016061F000E9@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.