Linux PCI Non-Transparent Bridge framework and drivers
 help / color / mirror / Atom feed
* [PATCH 0/2] NTB: Fix/improve memory window index validation
@ 2015-08-31 13:30 Allen Hubbe
  2015-08-31 13:30 ` [PATCH 1/2] NTB: Improve index handling in B2B MW workaround Allen Hubbe
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Allen Hubbe @ 2015-08-31 13:30 UTC (permalink / raw)
  To: linux-ntb; +Cc: Jon Mason, Dave Jiang, Allen Hubbe

Fix a range check on validating a memory window index, and make validation more
strict for using memory window as a hardware errata workaround.

Allen Hubbe (2):
  NTB: Improve index handling in B2B MW workaround
  NTB: Fix range check on memory window index

 drivers/ntb/hw/intel/ntb_hw_intel.c | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

-- 
2.5.0.rc1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] NTB: Improve index handling in B2B MW workaround
  2015-08-31 13:30 [PATCH 0/2] NTB: Fix/improve memory window index validation Allen Hubbe
@ 2015-08-31 13:30 ` Allen Hubbe
  2015-08-31 13:31 ` [PATCH 2/2] NTB: Fix range check on memory window index Allen Hubbe
  2015-09-07 19:41 ` [PATCH 0/2] NTB: Fix/improve memory window index validation Jon Mason
  2 siblings, 0 replies; 4+ messages in thread
From: Allen Hubbe @ 2015-08-31 13:30 UTC (permalink / raw)
  To: linux-ntb; +Cc: Jon Mason, Dave Jiang, Allen Hubbe

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>
---
 drivers/ntb/hw/intel/ntb_hw_intel.c | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/drivers/ntb/hw/intel/ntb_hw_intel.c b/drivers/ntb/hw/intel/ntb_hw_intel.c
index c2bc56b67e63..fc6af2da8df0 100644
--- a/drivers/ntb/hw/intel/ntb_hw_intel.c
+++ b/drivers/ntb/hw/intel/ntb_hw_intel.c
@@ -575,10 +575,13 @@ static ssize_t ndev_debugfs_read(struct file *filp, char __user *ubuf,
 			 "Connection Topology -\t%s\n",
 			 ntb_topo_string(ndev->ntb.topo));
 
-	off += scnprintf(buf + off, buf_size - off,
-			 "B2B Offset -\t\t%#lx\n", ndev->b2b_off);
-	off += scnprintf(buf + off, buf_size - off,
-			 "B2B MW Idx -\t\t%d\n", ndev->b2b_idx);
+	if (ndev->b2b_idx != UINT_MAX) {
+		off += scnprintf(buf + off, buf_size - off,
+				 "B2B MW Idx -\t\t%u\n", ndev->b2b_idx);
+		off += scnprintf(buf + off, buf_size - off,
+				 "B2B Offset -\t\t%#lx\n", ndev->b2b_off);
+	}
+
 	off += scnprintf(buf + off, buf_size - off,
 			 "BAR4 Split -\t\t%s\n",
 			 ndev->bar4_split ? "yes" : "no");
@@ -1487,7 +1490,7 @@ static int xeon_setup_b2b_mw(struct intel_ntb_dev *ndev,
 	pdev = ndev_pdev(ndev);
 	mmio = ndev->self_mmio;
 
-	if (ndev->b2b_idx >= ndev->mw_count) {
+	if (ndev->b2b_idx == UINT_MAX) {
 		dev_dbg(ndev_dev(ndev), "not using b2b mw\n");
 		b2b_bar = 0;
 		ndev->b2b_off = 0;
@@ -1779,6 +1782,13 @@ static int xeon_init_ntb(struct intel_ntb_dev *ndev)
 			else
 				ndev->b2b_idx = b2b_mw_idx;
 
+			if (ndev->b2b_idx >= ndev->mw_count) {
+				dev_dbg(ndev_dev(ndev),
+					"b2b_mw_idx %d invalid for mw_count %u\n",
+					b2b_mw_idx, ndev->mw_count);
+				return -EINVAL;
+			}
+
 			dev_dbg(ndev_dev(ndev),
 				"setting up b2b mw idx %d means %d\n",
 				b2b_mw_idx, ndev->b2b_idx);
@@ -2008,7 +2018,7 @@ static inline void ndev_init_struct(struct intel_ntb_dev *ndev,
 	ndev->ntb.ops = &intel_ntb_ops;
 
 	ndev->b2b_off = 0;
-	ndev->b2b_idx = INT_MAX;
+	ndev->b2b_idx = UINT_MAX;
 
 	ndev->bar4_split = 0;
 
-- 
2.5.0.rc1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] NTB: Fix range check on memory window index
  2015-08-31 13:30 [PATCH 0/2] NTB: Fix/improve memory window index validation Allen Hubbe
  2015-08-31 13:30 ` [PATCH 1/2] NTB: Improve index handling in B2B MW workaround Allen Hubbe
@ 2015-08-31 13:31 ` Allen Hubbe
  2015-09-07 19:41 ` [PATCH 0/2] NTB: Fix/improve memory window index validation Jon Mason
  2 siblings, 0 replies; 4+ messages in thread
From: Allen Hubbe @ 2015-08-31 13:31 UTC (permalink / raw)
  To: linux-ntb; +Cc: Jon Mason, Dave Jiang, Allen Hubbe

The range check must exclude the upper bound.

Signed-off-by: Allen Hubbe <Allen.Hubbe@emc.com>
---
 drivers/ntb/hw/intel/ntb_hw_intel.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/ntb/hw/intel/ntb_hw_intel.c b/drivers/ntb/hw/intel/ntb_hw_intel.c
index fc6af2da8df0..865a3e3cc581 100644
--- a/drivers/ntb/hw/intel/ntb_hw_intel.c
+++ b/drivers/ntb/hw/intel/ntb_hw_intel.c
@@ -240,7 +240,7 @@ static inline int ndev_ignore_unsafe(struct intel_ntb_dev *ndev,
 
 static int ndev_mw_to_bar(struct intel_ntb_dev *ndev, int idx)
 {
-	if (idx < 0 || idx > ndev->mw_count)
+	if (idx < 0 || idx >= ndev->mw_count)
 		return -EINVAL;
 	return ndev->reg->mw_bar[idx];
 }
-- 
2.5.0.rc1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/2] NTB: Fix/improve memory window index validation
  2015-08-31 13:30 [PATCH 0/2] NTB: Fix/improve memory window index validation Allen Hubbe
  2015-08-31 13:30 ` [PATCH 1/2] NTB: Improve index handling in B2B MW workaround Allen Hubbe
  2015-08-31 13:31 ` [PATCH 2/2] NTB: Fix range check on memory window index Allen Hubbe
@ 2015-09-07 19:41 ` Jon Mason
  2 siblings, 0 replies; 4+ messages in thread
From: Jon Mason @ 2015-09-07 19:41 UTC (permalink / raw)
  To: Allen Hubbe; +Cc: linux-ntb, Dave Jiang

On Mon, Aug 31, 2015 at 9:30 AM, Allen Hubbe <Allen.Hubbe@emc.com> wrote:
> Fix a range check on validating a memory window index, and make validation more
> strict for using memory window as a hardware errata workaround.
>
> Allen Hubbe (2):
>   NTB: Improve index handling in B2B MW workaround
>   NTB: Fix range check on memory window index

Both of these look fine to me.  Applying to my tree for 4.3.

Thanks,
Jon

>  drivers/ntb/hw/intel/ntb_hw_intel.c | 24 +++++++++++++++++-------
>  1 file changed, 17 insertions(+), 7 deletions(-)
>
> --
> 2.5.0.rc1
>
> --
> You received this message because you are subscribed to the Google Groups "linux-ntb" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to linux-ntb+unsubscribe@googlegroups.com.
> To post to this group, send email to linux-ntb@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/linux-ntb/cover.1441027457.git.Allen.Hubbe%40emc.com.
> For more options, visit https://groups.google.com/d/optout.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-09-07 19:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-31 13:30 [PATCH 0/2] NTB: Fix/improve memory window index validation Allen Hubbe
2015-08-31 13:30 ` [PATCH 1/2] NTB: Improve index handling in B2B MW workaround Allen Hubbe
2015-08-31 13:31 ` [PATCH 2/2] NTB: Fix range check on memory window index Allen Hubbe
2015-09-07 19:41 ` [PATCH 0/2] NTB: Fix/improve memory window index validation Jon Mason

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox