From: Avi Weiss <thnkslprpt@gmail.com>
To: Jon Mason <jdmason@kudzu.us>
Cc: Dave Jiang <dave.jiang@intel.com>,
Allen Hubbe <allenbh@gmail.com>, Koichiro Den <den@valinux.co.jp>,
Frank Li <Frank.Li@nxp.com>,
ntb@lists.linux.dev, linux-kernel@vger.kernel.org,
Avi Weiss <thnkslprpt@gmail.com>
Subject: [PATCH v2 2/2] NTB: epf: propagate MW command errors while status is reliable
Date: Sun, 1 Nov 2026 15:57:06 +0200 [thread overview]
Message-ID: <62334fd3b8d69fdfdeed268d71f473df45f34556.1793540847.git.thnkslprpt@gmail.com> (raw)
In-Reply-To: <cover.1793540847.git.thnkslprpt@gmail.com>
ntb_epf_mw_set_trans() and ntb_epf_mw_clear_trans() discard command
errors even when the endpoint explicitly rejects a request.
A timed-out command may still complete on the endpoint. Propagating
that timeout can cause callers to free DMA buffers before the mapping
completes. A late completion may also be mistaken for the result of a
subsequent command.
Record the first command timeout and propagate MW command errors only
while completion status remains reliable. Preserve the original MW
success-return behavior after a timeout to avoid releasing buffers
based on ambiguous results.
Fixes: 812ce2f8d14e ("NTB: Add support for EPF PCI Non-Transparent Bridge")
Signed-off-by: Avi Weiss <thnkslprpt@gmail.com>
---
drivers/ntb/hw/epf/ntb_hw_epf.c | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/drivers/ntb/hw/epf/ntb_hw_epf.c b/drivers/ntb/hw/epf/ntb_hw_epf.c
index da7fbe1800656..455bcefc7c13e 100644
--- a/drivers/ntb/hw/epf/ntb_hw_epf.c
+++ b/drivers/ntb/hw/epf/ntb_hw_epf.c
@@ -102,6 +102,7 @@ struct ntb_epf_dev {
struct device *dev;
/* Mutex to protect providing commands to NTB EPF */
struct mutex cmd_lock;
+ bool cmd_status_unreliable;
const enum pci_barno *barno_map;
@@ -148,6 +149,7 @@ static int ntb_epf_send_command_locked(struct ntb_epf_dev *ndev, u32 command,
break;
if (WARN_ON(timedout)) {
+ ndev->cmd_status_unreliable = true;
ret = -ETIMEDOUT;
break;
}
@@ -156,6 +158,13 @@ static int ntb_epf_send_command_locked(struct ntb_epf_dev *ndev, u32 command,
}
writew(0, ndev->ctrl_reg + NTB_EPF_CMD_STATUS);
+ /*
+ * After a timeout, a status may refer to an earlier command.
+ * MW callers may free buffers on error, so retain old semantics.
+ */
+ if (ndev->cmd_status_unreliable &&
+ (command == CMD_CONFIGURE_MW || command == CMD_TEARDOWN_MW))
+ ret = 0;
return ret;
}
@@ -485,7 +494,7 @@ static int ntb_epf_mw_set_trans(struct ntb_dev *ntb, int pidx, int idx,
struct ntb_epf_dev *ndev = ntb_ndev(ntb);
struct device *dev = ndev->dev;
resource_size_t mw_size;
- int bar;
+ int bar, ret;
if (pidx != NTB_DEF_PEER_IDX) {
dev_err(dev, "Unsupported Peer ID %d\n", pidx);
@@ -509,19 +518,19 @@ static int ntb_epf_mw_set_trans(struct ntb_dev *ntb, int pidx, int idx,
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);
- ntb_epf_send_command_locked(ndev, CMD_CONFIGURE_MW, idx);
+ ret = ntb_epf_send_command_locked(ndev, CMD_CONFIGURE_MW, idx);
mutex_unlock(&ndev->cmd_lock);
- return 0;
+ return ret;
}
static int ntb_epf_mw_clear_trans(struct ntb_dev *ntb, int pidx, int idx)
{
struct ntb_epf_dev *ndev = ntb_ndev(ntb);
struct device *dev = ndev->dev;
- int ret = 0;
+ int ret;
- ntb_epf_send_command(ndev, CMD_TEARDOWN_MW, idx);
+ ret = ntb_epf_send_command(ndev, CMD_TEARDOWN_MW, idx);
if (ret)
dev_err(dev, "Failed to teardown memory window\n");
--
2.43.0
next prev parent reply other threads:[~2026-11-01 13:57 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-01 13:57 [PATCH v2 0/2] NTB: epf: serialize MW setup and report reliable errors Avi Weiss
2026-11-01 13:57 ` [PATCH v2 1/2] NTB: epf: serialize memory window parameter writes Avi Weiss
2026-11-01 15:53 ` Koichiro Den
2026-11-01 13:57 ` Avi Weiss [this message]
2026-11-01 15:56 ` [PATCH v2 2/2] NTB: epf: propagate MW command errors while status is reliable 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=62334fd3b8d69fdfdeed268d71f473df45f34556.1793540847.git.thnkslprpt@gmail.com \
--to=thnkslprpt@gmail.com \
--cc=Frank.Li@nxp.com \
--cc=allenbh@gmail.com \
--cc=dave.jiang@intel.com \
--cc=den@valinux.co.jp \
--cc=jdmason@kudzu.us \
--cc=linux-kernel@vger.kernel.org \
--cc=ntb@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
all inboxes | Powered by JetHome®