Linux PCI subsystem development
 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 07/11] NTB: epf: Implement MW group translation callbacks
Date: Mon, 03 Aug 2026 18:29:18 +0000	[thread overview]
Message-ID: <20260803182919.673B91F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260803180439.1963864-8-den@valinux.co.jp>

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

New issues:
- [High] Unprotected concurrent modification of shared hardware control registers before acquiring cmd_lock.

Pre-existing issues:
- [High] The return values of `ntb_epf_send_command` are silently ignored in legacy MW operations.
--

--- Patch [7]: [PATCH 07/11] NTB: epf: Implement MW group translation callbacks ---
commit 1b85afed97e44da7b70fd9dff32c501ab6f91e2d
Author: Koichiro Den <den@valinux.co.jp>

NTB: epf: Implement MW group translation callbacks

This commit connects the NTB group callbacks to the version 1 group commands
so ntb_hw_epf can program packed MWs. Singleton MWs keep using the legacy
commands.

> diff --git a/drivers/ntb/hw/epf/ntb_hw_epf.c b/drivers/ntb/hw/epf/ntb_hw_epf.c
> index 46f37c2dea7b2..8b00550eea04d 100644
> --- a/drivers/ntb/hw/epf/ntb_hw_epf.c
> +++ b/drivers/ntb/hw/epf/ntb_hw_epf.c
> @@ -509,6 +511,43 @@ static int ntb_epf_db_set_mask(struct ntb_dev *ntb, u64 db_bits)
>  	return 0;
>  }
>  
> +static int
> +ntb_epf_mw_set_trans_group(struct ntb_dev *ntb, int pidx, int widx,
> +			   dma_addr_t addr, resource_size_t size)
> +{
[ ... ]
> +	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);

[Severity: High]
Can concurrent writes to these registers corrupt the hardware state?

Looking at ntb_epf_mw_set_trans_group(), the parameter registers are modified
outside the protection of ndev->cmd_lock, which is only acquired later inside
ntb_epf_send_command().

If a user or client driver concurrently configures different memory windows,
would the register writes interleave, potentially granting the peer device
DMA access to unintended memory regions?

This identical pattern also exists in ntb_epf_mw_set_trans().

> +
> +	return ntb_epf_send_command(ndev, CMD_CONFIGURE_MW_GROUP, widx);
> +}
[ ... ]
> @@ -648,6 +687,8 @@ static const struct ntb_dev_ops ntb_epf_ops = {
>  	.db_vector_mask		= ntb_epf_db_vector_mask,
>  	.db_set_mask		= ntb_epf_db_set_mask,
>  	.mw_get_trans_group	= ntb_epf_mw_get_trans_group,
> +	.mw_set_trans_group	= ntb_epf_mw_set_trans_group,
> +	.mw_clear_trans_group	= ntb_epf_mw_clear_trans_group,
>  	.mw_set_trans		= ntb_epf_mw_set_trans,
>  	.mw_clear_trans		= ntb_epf_mw_clear_trans,

[Severity: High]
This is a pre-existing issue, but do the legacy transaction functions mask
hardware failures?

Looking at ntb_epf_mw_clear_trans() in drivers/ntb/hw/epf/ntb_hw_epf.c:

	ntb_epf_send_command(ndev, CMD_TEARDOWN_MW, idx);
	if (ret)
		dev_err(dev, "Failed to teardown memory window\n");

The return value of ntb_epf_send_command() isn't captured, so ret remains
zero and the error check becomes dead code.

Could this hide a teardown failure, causing the local host to free memory
while the peer host retains active DMA access to it?

Similarly, ntb_epf_mw_set_trans() discards the return value of
ntb_epf_send_command() and unconditionally returns 0.

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

  reply	other threads:[~2026-08-03 18:29 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-03 18:04 [PATCH 00/11] PCI/NTB: endpoint: packed vNTB memory windows Koichiro Den
2026-08-03 18:04 ` [PATCH 01/11] NTB: Add atomic MW translation group operations Koichiro Den
2026-08-03 18:10   ` sashiko-bot
2026-08-03 18:04 ` [PATCH 02/11] NTB: epf: Parse a versioned packed MW layout Koichiro Den
2026-08-03 18:23   ` sashiko-bot
2026-08-03 18:04 ` [PATCH 03/11] PCI: endpoint: pci-epf-vntb: Add packed MW layout handling Koichiro Den
2026-08-03 18:25   ` sashiko-bot
2026-08-03 18:04 ` [PATCH 04/11] PCI: endpoint: pci-epf-vntb: Implement MW group translation callbacks Koichiro Den
2026-08-03 18:25   ` sashiko-bot
2026-08-04  1:41     ` Koichiro Den
2026-08-03 18:04 ` [PATCH 05/11] PCI: endpoint: pci-epf-vntb: Allocate packed outbound MW space Koichiro Den
2026-08-03 18:32   ` sashiko-bot
2026-08-03 18:04 ` [PATCH 06/11] PCI: endpoint: pci-epf-vntb: Add outbound MW group commands Koichiro Den
2026-08-03 18:28   ` sashiko-bot
2026-08-03 18:04 ` [PATCH 07/11] NTB: epf: Implement MW group translation callbacks Koichiro Den
2026-08-03 18:29   ` sashiko-bot [this message]
2026-08-03 18:04 ` [PATCH 08/11] NTB: perf: Reject grouped memory windows Koichiro Den
2026-08-03 18:25   ` sashiko-bot
2026-08-03 18:04 ` [PATCH 09/11] NTB/msi: Require a singleton memory window Koichiro Den
2026-08-03 18:23   ` sashiko-bot
2026-08-03 18:04 ` [PATCH 10/11] NTB: ntb_transport: Use atomic MW translation groups Koichiro Den
2026-08-03 18:40   ` sashiko-bot
2026-08-03 18:04 ` [PATCH 11/11] PCI: endpoint: pci-epf-vntb: Expose packed MWs through configfs Koichiro Den
2026-08-03 18:40   ` sashiko-bot
2026-08-03 23:00 ` [PATCH 00/11] PCI/NTB: endpoint: packed vNTB memory windows Randy Dunlap
2026-08-04  0:55   ` 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=20260803182919.673B91F000E9@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