Skip to content

Commit 2aa2a77

Browse files
Allen Hubbejonmason
authored andcommitted
NTB: Improve index handling in B2B MW workaround
Check that b2b_mw_idx is in range of the number of memory windows when initializing the device. The workaround is considered to be in effect only if the device b2b_idx is exactly UINT_MAX, instead of any index past the last memory window. Only print B2B MW workaround information in debugfs if the workaround is in effect. Signed-off-by: Allen Hubbe <Allen.Hubbe@emc.com> Signed-off-by: Jon Mason <jdmason@kudzu.us>
1 parent 86663c9 commit 2aa2a77

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

drivers/ntb/hw/intel/ntb_hw_intel.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -575,10 +575,13 @@ static ssize_t ndev_debugfs_read(struct file *filp, char __user *ubuf,
575575
"Connection Topology -\t%s\n",
576576
ntb_topo_string(ndev->ntb.topo));
577577

578-
off += scnprintf(buf + off, buf_size - off,
579-
"B2B Offset -\t\t%#lx\n", ndev->b2b_off);
580-
off += scnprintf(buf + off, buf_size - off,
581-
"B2B MW Idx -\t\t%d\n", ndev->b2b_idx);
578+
if (ndev->b2b_idx != UINT_MAX) {
579+
off += scnprintf(buf + off, buf_size - off,
580+
"B2B MW Idx -\t\t%u\n", ndev->b2b_idx);
581+
off += scnprintf(buf + off, buf_size - off,
582+
"B2B Offset -\t\t%#lx\n", ndev->b2b_off);
583+
}
584+
582585
off += scnprintf(buf + off, buf_size - off,
583586
"BAR4 Split -\t\t%s\n",
584587
ndev->bar4_split ? "yes" : "no");
@@ -1487,7 +1490,7 @@ static int xeon_setup_b2b_mw(struct intel_ntb_dev *ndev,
14871490
pdev = ndev_pdev(ndev);
14881491
mmio = ndev->self_mmio;
14891492

1490-
if (ndev->b2b_idx >= ndev->mw_count) {
1493+
if (ndev->b2b_idx == UINT_MAX) {
14911494
dev_dbg(ndev_dev(ndev), "not using b2b mw\n");
14921495
b2b_bar = 0;
14931496
ndev->b2b_off = 0;
@@ -1779,6 +1782,13 @@ static int xeon_init_ntb(struct intel_ntb_dev *ndev)
17791782
else
17801783
ndev->b2b_idx = b2b_mw_idx;
17811784

1785+
if (ndev->b2b_idx >= ndev->mw_count) {
1786+
dev_dbg(ndev_dev(ndev),
1787+
"b2b_mw_idx %d invalid for mw_count %u\n",
1788+
b2b_mw_idx, ndev->mw_count);
1789+
return -EINVAL;
1790+
}
1791+
17821792
dev_dbg(ndev_dev(ndev),
17831793
"setting up b2b mw idx %d means %d\n",
17841794
b2b_mw_idx, ndev->b2b_idx);
@@ -2008,7 +2018,7 @@ static inline void ndev_init_struct(struct intel_ntb_dev *ndev,
20082018
ndev->ntb.ops = &intel_ntb_ops;
20092019

20102020
ndev->b2b_off = 0;
2011-
ndev->b2b_idx = INT_MAX;
2021+
ndev->b2b_idx = UINT_MAX;
20122022

20132023
ndev->bar4_split = 0;
20142024

0 commit comments

Comments
 (0)