NTB: epf: propagate memory window command errors
PATCH 1/1 NTB: epf: propagate memory window command errors
ntb_epf_mw_set_trans() and ntb_epf_mw_clear_trans() discard the result of ntb_epf_send_command() and return success even when the endpoint reports a command failure or fails to respond. This prevents NTB clients from detecting a failed memory window operation.
Return the command status from both callbacks. Preserve the existing teardown error diagnostic.
--- drivers/ntb/hw/epf/ntb_hw_epf.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/ntb/hw/epf/ntb_hw_epf.c +3 -5
@@ -498,18 +498,16 @@ 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 (ndev,CMD_CONFIGURE_MW , idx); - -return 0 ; +return ntb_epf_send_command (ndev,CMD_CONFIGURE_MW , idx); }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" );
base-commit: d135ab453a7400a34930bdda1ef4bdc8acfac80e
Signature · 1 line
2.43.0
Quoted 19 lines · Avi Weiss
ntb_epf_mw_set_trans()andntb_epf_mw_clear_trans()discard the result ofntb_epf_send_command()and return success even when the endpoint reports a command failure or fails to respond. This prevents NTB clients from detecting a failed memory window operation.Return the command status from both callbacks. Preserve the existing teardown error diagnostic.
Fixes 812ce2f8d14e ("NTB: Add support for EPF PCI Non-Transparent Bridge")Signed-off-by Avi Weiss <[email protected]>--- drivers/ntb/hw/epf/ntb_hw_epf.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)drivers/ntb/hw/epf/ntb_hw_epf.c +0
-0
drivers/ntb/hw/epf/ntb_hw_epf.c static int ntb_epf_mw_set_trans(struct ntb_dev *ntb, int pidx, int idx, · line 501
Quoted 7 lines
drivers/ntb/hw/epf/ntb_hw_epf.c +1
-3@@ -498,18 +498,16 @@ 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 (ndev,CMD_CONFIGURE_MW , idx); - -return 0 ; +return ntb_epf_send_command (ndev,CMD_CONFIGURE_MW , idx);
I agree with propagating the error, but there's one thing I'm wondering:
On timeout, the endpoint (pci-epf-*ntb) may just be slow and complete CONFIGURE_MW later. E.g. tool_setup_mw() in ntb_tool frees the buffer when ntb_mw_set_trans() returns an error. Could this leave an MW pointing at freed memory?
Previously, it always returned 0, so tool_setup_mw() kept the buffer. I'm wondering if this change could introduce a subtle regression. To avoid that risk, how about keeping the existing timeout behavior?
ret = ntb_epf_send_command(ndev, CMD_CONFIGURE_MW, idx); return ret == -ETIMEDOUT ? 0 : ret;
I'd love to hear your thoughts, thanks!
Best regards,
Koichiro Den
Quoted 19 lines
drivers/ntb/hw/epf/ntb_hw_epf.c +2
-2}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" );base-commit:
d135ab453a7400a34930bdda1ef4bdc8acfac80eSignature · 1 line
2.43.0