Skip to contentSkip to conversation

IB/hfi1,qib,rdmavt: Fixes for 4.7 rc

PATCH In review Dennis Dalessandro 2 participants 12 messages Jun 9, 2016 – Jun 18, 2016 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover IB/hfi1,qib,rdmavt: Fixes for 4.7 rc

Doug, here are some fixes which we would like to land in 4.7 RC. These are bug fixes. Some more serious than others.

Patches apply on your k.o/for-4.7-rc tree.

Patches can also be viewed in my repo and have passed 0day builds:
https://github.com/ddalessa/kernel/tree/for-4.7

---

Brian Welty (2):
IB/rdmavt: Correct required callback functions for MODIFY_QP IB/rdmavt: Correct warning during QPN allocation

Ira Weiny (2):
IB/hfi1: Prevent context loss
IB/qib: Prevent context loss

Jubin John (2):
IB/hfi1: Fix credit return threshold adjustment IB/hfi1: Increase packet egress timeout

Sebastian Sanchez (2):
IB/hfi1: Remove FULL_MGMT_P_KEY from pkey table at link up IB/hfi1: Send a pkey change event on driver pkey update

Tadeusz Struk (2):
IB/hfi1: Fix potential NULL ptr dereference
IB/hfi1: Fix potential buffer overflow

 drivers/infiniband/hw/hfi1/chip.c        |   28 ++++++++++++++++++++--------
 drivers/infiniband/hw/hfi1/file_ops.c    |    3 +++
 drivers/infiniband/hw/hfi1/init.c        |    2 +-
 drivers/infiniband/hw/hfi1/mad.c         |   19 ++++++++++++-------
 drivers/infiniband/hw/hfi1/mad.h         |    2 ++
 drivers/infiniband/hw/hfi1/pio.c         |   26 +++++++++++++++++++++++---
 drivers/infiniband/hw/hfi1/qsfp.c        |    3 ++-
 drivers/infiniband/hw/qib/qib_file_ops.c |    5 +++++
 drivers/infiniband/sw/rdmavt/qp.c        |    4 ++--
 drivers/infiniband/sw/rdmavt/vt.c        |    4 +---
 10 files changed, 71 insertions(+), 25 deletions(-)
Signature · 5 lines
-Denny
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 20160609144644.12702.4832.stgit-9QXIwq+3FY+1XWohqUldA0EOCMrvLtNR@public.gmane.org

#2 lore raw

PATCH 1/10 IB/hfi1: Fix credit return threshold adjustment

From: Jubin John <[email protected]>

The credit return threshold adjustment on mtu change algorithm does not take into account all the kernel send contexts that are assigned per VL. Use the pio send context map to adjust the credit return thresholds for all the allocated and assigned kernel send contexts based on the MTU adjustment per VL.

The pio send context map can be changed dynamically based on the actual number of operational vls which is set by the fabric manager. When this happens update the credit return threshold values for all the remapped kernel send contexts.

---
 drivers/infiniband/hw/hfi1/chip.c |    7 +++++--
 drivers/infiniband/hw/hfi1/pio.c  |   24 ++++++++++++++++++++++--
 2 files changed, 27 insertions(+), 4 deletions(-)
drivers/infiniband/hw/hfi1/chip.c +5 -2
index 81619fb..c533d44 100644
@@ -9777,7 +9777,7 @@ static void set_send_length(struct hfi1_pportdata *ppd)
 	u64 len1 = 0, len2 = (((dd->vld[15].mtu + max_hb) >> 2)
 			      & SEND_LEN_CHECK1_LEN_VL15_MASK) <<
 		SEND_LEN_CHECK1_LEN_VL15_SHIFT;
-	int i;
+	int i, j;
 	u32 thres;
 
 	for (i = 0; i < ppd->vls_supported; i++) {
@@ -9801,7 +9801,10 @@ static void set_send_length(struct hfi1_pportdata *ppd)
 			    sc_mtu_to_threshold(dd->vld[i].sc,
 						dd->vld[i].mtu,
 						dd->rcd[0]->rcvhdrqentsize));
-		sc_set_cr_threshold(dd->vld[i].sc, thres);
+		for (j = 0; j < INIT_SC_PER_VL; j++)
+			sc_set_cr_threshold(
+					pio_select_send_context_vl(dd, j, i),
+					    thres);
 	}
 	thres = min(sc_percent_to_threshold(dd->vld[15].sc, 50),
 		    sc_mtu_to_threshold(dd->vld[15].sc,
drivers/infiniband/hw/hfi1/pio.c +22 -2
index d5edb1a..e0e1ff2 100644
@@ -1798,6 +1798,21 @@ static void pio_map_rcu_callback(struct rcu_head *list)
 }
 
 /*
+ * Set credit return threshold for the kernel send context
+ */
+static void set_threshold(struct hfi1_devdata *dd, int scontext, int i)
+{
+	u32 thres;
+
+	thres = min(sc_percent_to_threshold(dd->kernel_send_context[scontext],
+					    50),
+		    sc_mtu_to_threshold(dd->kernel_send_context[scontext],
+					dd->vld[i].mtu,
+					dd->rcd[0]->rcvhdrqentsize));
+	sc_set_cr_threshold(dd->kernel_send_context[scontext], thres);
+}
+
+/*
  * pio_map_init - called when #vls change
  * @dd: hfi1_devdata
  * @port: port number
@@ -1872,11 +1887,16 @@ int pio_map_init(struct hfi1_devdata *dd, u8 port, u8 num_vls, u8 *vl_scontexts)
 			if (!newmap->map[i])
 				goto bail;
 			newmap->map[i]->mask = (1 << ilog2(sz)) - 1;
-			/* assign send contexts */
+			/*
+			 * assign send contexts and
+			 * adjust credit return threshold
+			 */
 			for (j = 0; j < sz; j++) {
-				if (dd->kernel_send_context[scontext])
+				if (dd->kernel_send_context[scontext]) {
 					newmap->map[i]->ksc[j] =
 					dd->kernel_send_context[scontext];
+					set_threshold(dd, scontext, i);
+				}
 				if (++scontext >= first_scontext +
 						  vl_scontexts[i])
 					/* wrap back to first send context */

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#3 lore raw

PATCH 2/10 IB/rdmavt: Correct required callback functions for MODIFY_QP

In reply to a message not in the archive

From: Brian Welty <[email protected]>

Functions required for MODIFY_PORT were incorrectly being required for MODIFY_QP.

---
 drivers/infiniband/sw/rdmavt/vt.c |    4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)
drivers/infiniband/sw/rdmavt/vt.c +1 -3
index e1cc2cc..30c4fda 100644
@@ -501,9 +501,7 @@ static noinline int check_support(struct rvt_dev_info *rdi, int verb)
 			    !rdi->driver_f.quiesce_qp ||
 			    !rdi->driver_f.notify_error_qp ||
 			    !rdi->driver_f.mtu_from_qp ||
-			    !rdi->driver_f.mtu_to_path_mtu ||
-			    !rdi->driver_f.shut_down_port ||
-			    !rdi->driver_f.cap_mask_chg)
+			    !rdi->driver_f.mtu_to_path_mtu)
 				return -EINVAL;
 		break;
 

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw

PATCH 3/10 IB/rdmavt: Correct warning during QPN allocation

In reply to a message not in the archive

From: Brian Welty <[email protected]>

Correct calculation of the low order bits which should be unset based on use of qos_shift parameter when assigning QPN.

---
 drivers/infiniband/sw/rdmavt/qp.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/infiniband/sw/rdmavt/qp.c +2 -2
index 7de5134..c3e0d61 100644
@@ -369,8 +369,8 @@ static int alloc_qpn(struct rvt_dev_info *rdi, struct rvt_qpn_table *qpt,
 			/* wrap to first map page, invert bit 0 */
 			offset = qpt->incr | ((offset & 1) ^ 1);
 		}
-		/* there can be no bits at shift and below */
-		WARN_ON(offset & (rdi->dparms.qos_shift - 1));
+		/* there can be no set bits in low-order QoS bits */
+		WARN_ON(offset & (BIT(rdi->dparms.qos_shift) - 1));
 		qpn = mk_qpn(qpt, map, offset);
 	}
 

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#5 lore raw

PATCH 4/10 IB/hfi1: Increase packet egress timeout

In reply to a message not in the archive

From: Jubin John <[email protected]>

The current value of 500us for the packet egress timeout is too small which causes the host to declare failure on draining packets too early and unnecessarily bounces the link. Increase this to 50ms taking into account the switch packet discard timer default and the worst case per-VL package drainage rate.

---
 drivers/infiniband/hw/hfi1/pio.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/infiniband/hw/hfi1/pio.c +1 -1
index e0e1ff2..d402245 100644
@@ -995,7 +995,7 @@ static void sc_wait_for_packet_egress(struct send_context *sc, int pause)
 		/* counter is reset if occupancy count changes */
 		if (reg != reg_prev)
 			loop = 0;
-		if (loop > 500) {
+		if (loop > 50000) {
 			/* timed out - bounce the link */
 			dd_dev_err(dd,
 				   "%s: context %u(%u) timeout waiting for packets to egress, remaining count %u, bouncing link\n",

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#6 lore raw

PATCH 5/10 IB/hfi1: Prevent context loss

In reply to a message not in the archive

From: Ira Weiny <[email protected]>

If a context has already been assigned to an FD, prevent another assignment.

---
 drivers/infiniband/hw/hfi1/file_ops.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
drivers/infiniband/hw/hfi1/file_ops.c +3 -0
index 7a5b0e6..c702a00 100644
@@ -203,6 +203,9 @@ static long hfi1_file_ioctl(struct file *fp, unsigned int cmd,
 
 	switch (cmd) {
 	case HFI1_IOCTL_ASSIGN_CTXT:
+		if (uctxt)
+			return -EINVAL;
+
 		if (copy_from_user(&uinfo,
 				   (struct hfi1_user_info __user *)arg,
 				   sizeof(uinfo)))

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#7 lore raw

PATCH 6/10 IB/qib: Prevent context loss

In reply to a message not in the archive

From: Ira Weiny <[email protected]>

If a context has already been assigned to an FD, prevent another assignment.

---
 drivers/infiniband/hw/qib/qib_file_ops.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
drivers/infiniband/hw/qib/qib_file_ops.c +5 -0
index ff946d5..382466a 100644
@@ -2178,6 +2178,11 @@ static ssize_t qib_write(struct file *fp, const char __user *data,
 
 	switch (cmd.type) {
 	case QIB_CMD_ASSIGN_CTXT:
+		if (rcd) {
+			ret = -EINVAL;
+			goto bail;
+		}
+
 		ret = qib_assign_ctxt(fp, &cmd.cmd.user_info);
 		if (ret)
 			goto bail;

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#8 lore raw

PATCH 7/10 IB/hfi1: Fix potential NULL ptr dereference

In reply to a message not in the archive

From: Tadeusz Struk <[email protected]>

This fixes potential NULL ptr dereference because IS_ERR(dd) doesn't handle NULL. Fix the issue by initializing the pointer with a not NULL error code.

---
 drivers/infiniband/hw/hfi1/init.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/infiniband/hw/hfi1/init.c +1 -1
index 0d28a5a..eed971c 100644
@@ -1383,7 +1383,7 @@ static void postinit_cleanup(struct hfi1_devdata *dd)
 static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 {
 	int ret = 0, j, pidx, initfail;
-	struct hfi1_devdata *dd = NULL;
+	struct hfi1_devdata *dd = ERR_PTR(-EINVAL);
 	struct hfi1_pportdata *ppd;
 
 	/* First, lock the non-writable module parameters */

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#9 lore raw

PATCH 8/10 IB/hfi1: Fix potential buffer overflow

In reply to a message not in the archive

From: Tadeusz Struk <[email protected]>

This fixes potential buffer overflow because the sprintf function doesn't check buffer boundaries. Use snprintf instead.

---
 drivers/infiniband/hw/hfi1/qsfp.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
drivers/infiniband/hw/hfi1/qsfp.c +2 -1
index 2441669..9fb5616 100644
@@ -579,7 +579,8 @@ int qsfp_dump(struct hfi1_pportdata *ppd, char *buf, int len)
 
 	if (ppd->qsfp_info.cache_valid) {
 		if (QSFP_IS_CU(cache[QSFP_MOD_TECH_OFFS]))
-			sprintf(lenstr, "%dM ", cache[QSFP_MOD_LEN_OFFS]);
+			snprintf(lenstr, sizeof(lenstr), "%dM ",
+				 cache[QSFP_MOD_LEN_OFFS]);
 
 		power_byte = cache[QSFP_MOD_PWR_OFFS];
 		sofar += scnprintf(buf + sofar, len - sofar, "PWR:%.3sW\n",

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#10 lore raw

PATCH 9/10 IB/hfi1: Remove FULL_MGMT_P_KEY from pkey table at link up

In reply to a message not in the archive

From: Sebastian Sanchez <[email protected]>

FULL_MGMT_P_KEY doesn't get cleared from the pkey table at link bounce because the link down and link bounce code paths are different when moving a QSFP cable on a switch. This causes an HFI unit connected to a switch to try to be initialized to an FM node when the QSFP cable is moved from a MgmtAllowed=NO port to a MgmtAllowed=YES port and back to a MgmtAllowed=NO port. Remove FULL_MGMT_P_KEY from pkey table at link up.

---
 drivers/infiniband/hw/hfi1/chip.c |   19 +++++++++++++------
 1 files changed, 13 insertions(+), 6 deletions(-)
drivers/infiniband/hw/hfi1/chip.c +13 -6
index c533d44..3487fdf 100644
@@ -1037,7 +1037,7 @@ static void dc_shutdown(struct hfi1_devdata *);
 static void dc_start(struct hfi1_devdata *);
 static int qos_rmt_entries(struct hfi1_devdata *dd, unsigned int *mp,
 			   unsigned int *np);
-static void remove_full_mgmt_pkey(struct hfi1_pportdata *ppd);
+static void clear_full_mgmt_pkey(struct hfi1_pportdata *ppd);
 
 /*
  * Error interrupt table entry.  This is used as input to the interrupt
@@ -6962,8 +6962,6 @@ void handle_link_down(struct work_struct *work)
 	}
 
 	reset_neighbor_info(ppd);
-	if (ppd->mgmt_allowed)
-		remove_full_mgmt_pkey(ppd);
 
 	/* disable the port */
 	clear_rcvctrl(ppd->dd, RCV_CTRL_RCV_PORT_ENABLE_SMASK);
@@ -7072,10 +7070,12 @@ static void add_full_mgmt_pkey(struct hfi1_pportdata *ppd)
 	(void)hfi1_set_ib_cfg(ppd, HFI1_IB_CFG_PKEYS, 0);
 }
 
-static void remove_full_mgmt_pkey(struct hfi1_pportdata *ppd)
+static void clear_full_mgmt_pkey(struct hfi1_pportdata *ppd)
 {
-	ppd->pkeys[2] = 0;
-	(void)hfi1_set_ib_cfg(ppd, HFI1_IB_CFG_PKEYS, 0);
+	if (ppd->pkeys[2] != 0) {
+		ppd->pkeys[2] = 0;
+		(void)hfi1_set_ib_cfg(ppd, HFI1_IB_CFG_PKEYS, 0);
+	}
 }
 
 /*
@@ -9168,6 +9168,13 @@ int start_link(struct hfi1_pportdata *ppd)
 		return 0;
 	}
 
+	/*
+	 * FULL_MGMT_P_KEY is cleared from the pkey table, so that the
+	 * pkey table can be configured properly if the HFI unit is connected
+	 * to switch port with MgmtAllowed=NO
+	 */
+	clear_full_mgmt_pkey(ppd);
+
 	return set_link_state(ppd, HLS_DN_POLL);
 }
 

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#11 lore raw

PATCH 10/10 IB/hfi1: Send a pkey change event on driver pkey update

In reply to a message not in the archive

From: Sebastian Sanchez <[email protected]>

Swapping a cable from a "Mgmt Allowed=No" switch port to a "Mgmt Allowed=Yes" switch port doesn't send a pkey change notification. Therefore, the link doesn't become active as the oib_utils layer uses an old pkey table cache.

Fix by ensuring the pkey change notification is sent when the table is changed both explicitly by the FM and implicitly by the driver via a cable swap.

---
 drivers/infiniband/hw/hfi1/chip.c |    2 ++
 drivers/infiniband/hw/hfi1/mad.c  |   19 ++++++++++++-------
 drivers/infiniband/hw/hfi1/mad.h  |    2 ++
 3 files changed, 16 insertions(+), 7 deletions(-)
drivers/infiniband/hw/hfi1/chip.c +2 -0
index 3487fdf..f5de851 100644
@@ -7068,6 +7068,7 @@ static void add_full_mgmt_pkey(struct hfi1_pportdata *ppd)
 			    __func__, ppd->pkeys[2], FULL_MGMT_P_KEY);
 	ppd->pkeys[2] = FULL_MGMT_P_KEY;
 	(void)hfi1_set_ib_cfg(ppd, HFI1_IB_CFG_PKEYS, 0);
+	hfi1_event_pkey_change(ppd->dd, ppd->port);
 }
 
 static void clear_full_mgmt_pkey(struct hfi1_pportdata *ppd)
@@ -7075,6 +7076,7 @@ static void clear_full_mgmt_pkey(struct hfi1_pportdata *ppd)
 	if (ppd->pkeys[2] != 0) {
 		ppd->pkeys[2] = 0;
 		(void)hfi1_set_ib_cfg(ppd, HFI1_IB_CFG_PKEYS, 0);
+		hfi1_event_pkey_change(ppd->dd, ppd->port);
 	}
 }
 
drivers/infiniband/hw/hfi1/mad.c +12 -7
index 2190295..fca07a1 100644
@@ -78,6 +78,16 @@ static inline void clear_opa_smp_data(struct opa_smp *smp)
 	memset(data, 0, size);
 }
 
+void hfi1_event_pkey_change(struct hfi1_devdata *dd, u8 port)
+{
+	struct ib_event event;
+
+	event.event = IB_EVENT_PKEY_CHANGE;
+	event.device = &dd->verbs_dev.rdi.ibdev;
+	event.element.port_num = port;
+	ib_dispatch_event(&event);
+}
+
 static void send_trap(struct hfi1_ibport *ibp, void *data, unsigned len)
 {
 	struct ib_mad_send_buf *send_buf;
@@ -1418,15 +1428,10 @@ static int set_pkeys(struct hfi1_devdata *dd, u8 port, u16 *pkeys)
 	}
 
 	if (changed) {
-		struct ib_event event;
-
 		(void)hfi1_set_ib_cfg(ppd, HFI1_IB_CFG_PKEYS, 0);
-
-		event.event = IB_EVENT_PKEY_CHANGE;
-		event.device = &dd->verbs_dev.rdi.ibdev;
-		event.element.port_num = port;
-		ib_dispatch_event(&event);
+		hfi1_event_pkey_change(dd, port);
 	}
+
 	return 0;
 }
 
drivers/infiniband/hw/hfi1/mad.h +2 -0
index 55ee086..8b734aa 100644
@@ -434,4 +434,6 @@ struct sc2vlnt {
 		    COUNTER_MASK(1, 3) | \
 		    COUNTER_MASK(1, 4))
 
+void hfi1_event_pkey_change(struct hfi1_devdata *dd, u8 port);
+
 #endif				/* _HFI1_MAD_H */

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#12 lore raw
In reply to a message not in the archive
Quoted 31 lines · Dennis Dalessandro

Doug, here are some fixes which we would like to land in 4.7 RC. These are bug fixes. Some more serious than others.

Patches apply on your k.o/for-4.7-rc tree.

Patches can also be viewed in my repo and have passed 0day builds:
https://github.com/ddalessa/kernel/tree/for-4.7

---

Brian Welty (2):
IB/rdmavt: Correct required callback functions for MODIFY_QP IB/rdmavt: Correct warning during QPN allocation

Ira Weiny (2):
IB/hfi1: Prevent context loss
IB/qib: Prevent context loss

Jubin John (2):
IB/hfi1: Fix credit return threshold adjustment IB/hfi1: Increase packet egress timeout

Sebastian Sanchez (2):
IB/hfi1: Remove FULL_MGMT_P_KEY from pkey table at link up IB/hfi1: Send a pkey change event on driver pkey update

Tadeusz Struk (2):
IB/hfi1: Fix potential NULL ptr dereference
IB/hfi1: Fix potential buffer overflow

Quoted 12 lines
 drivers/infiniband/hw/hfi1/chip.c        |   28 ++++++++++++++++++++--------
 drivers/infiniband/hw/hfi1/file_ops.c    |    3 +++
 drivers/infiniband/hw/hfi1/init.c        |    2 +-
 drivers/infiniband/hw/hfi1/mad.c         |   19 ++++++++++++-------
 drivers/infiniband/hw/hfi1/mad.h         |    2 ++
 drivers/infiniband/hw/hfi1/pio.c         |   26 +++++++++++++++++++++++---
 drivers/infiniband/hw/hfi1/qsfp.c        |    3 ++-
 drivers/infiniband/hw/qib/qib_file_ops.c |    5 +++++
 drivers/infiniband/sw/rdmavt/qp.c        |    4 ++--
 drivers/infiniband/sw/rdmavt/vt.c        |    4 +---
 10 files changed, 71 insertions(+), 25 deletions(-)

Thanks, series applied.

Signature · 2 lines
Doug Ledford <[email protected]>
    GPG Key ID: 0E572FDD