Blame SOURCES/open-iscsi-2.0.876-54-iscsiuio-Add-inter-host-mutex-while-doing-xmit.patch

36622c
From d469a2e15e8558cf8ba34db376b4b777177a016b Mon Sep 17 00:00:00 2001
36622c
From: Chris Leech <cleech@redhat.com>
36622c
Date: Fri, 22 Jun 2018 12:30:09 -0700
36622c
Subject: [PATCH 1/1] iscsiuio: Add inter-host mutex while doing xmit
36622c
36622c
Bugzilla: ZZZ
36622c
Upstream Status:
36622c
Build Info: XXX
36622c
Tested:
36622c
36622c
commit 9501dcaf5be474b4cb882a5e00f875f8c57e0e8e
36622c
Author: Manish Rangankar <manish.rangankar@cavium.com>
36622c
Date:   Wed Jun 20 02:33:36 2018 -0400
36622c
36622c
    iscsiuio: Add inter-host mutex while doing xmit
36622c
36622c
    This avoids the netlink buffer corruption when more than one host
36622c
    try to xmit packet at the same time.
36622c
36622c
    Signed-off-by: Manish Rangankar <manish.rangankar@cavium.com>
36622c
---
36622c
 iscsiuio/src/unix/libs/cnic.c |  2 ++
36622c
 iscsiuio/src/unix/libs/qedi.c | 38 +++++++++++++++++++++++++++++++++-----
36622c
 iscsiuio/src/unix/nic.c       | 15 ++++++++++++---
36622c
 iscsiuio/src/unix/nic_utils.c |  4 ++++
36622c
 4 files changed, 51 insertions(+), 8 deletions(-)
36622c
36622c
diff --git a/iscsiuio/src/unix/libs/cnic.c b/iscsiuio/src/unix/libs/cnic.c
36622c
index 32166edf243f..b953278e5eab 100644
36622c
--- a/iscsiuio/src/unix/libs/cnic.c
36622c
+++ b/iscsiuio/src/unix/libs/cnic.c
36622c
@@ -106,6 +106,8 @@ static int cnic_arp_send(nic_t *nic, nic_interface_t *nic_iface, int fd,
36622c
 	static const uint8_t multicast_mac[] = {
36622c
 				0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
36622c
 
36622c
+	LOG_DEBUG(PFX "%s: host:%d - try getting xmit mutex cnic arp send",
36622c
+		  nic->log_name, nic->host_no);
36622c
 	rc = pthread_mutex_trylock(&nic->xmit_mutex);
36622c
 	if (rc != 0) {
36622c
 		LOG_DEBUG(PFX "%s: could not get xmit_mutex", nic->log_name);
36622c
diff --git a/iscsiuio/src/unix/libs/qedi.c b/iscsiuio/src/unix/libs/qedi.c
36622c
index 5bb0682c8bed..32cab48fed17 100644
36622c
--- a/iscsiuio/src/unix/libs/qedi.c
36622c
+++ b/iscsiuio/src/unix/libs/qedi.c
36622c
@@ -74,6 +74,8 @@
36622c
 
36622c
 extern int nl_sock;
36622c
 
36622c
+static pthread_mutex_t host_mutex = PTHREAD_MUTEX_INITIALIZER;
36622c
+
36622c
 /*  Foward struct declarations */
36622c
 struct nic_ops qedi_op;
36622c
 
36622c
@@ -812,15 +814,26 @@ static void qedi_prepare_xmit_packet(nic_t *nic,
36622c
 	struct uip_vlan_eth_hdr *eth_vlan = (struct uip_vlan_eth_hdr *)pkt->buf;
36622c
 	struct uip_eth_hdr *eth = (struct uip_eth_hdr *)bp->tx_pkt;
36622c
 
36622c
+	LOG_DEBUG(PFX "%s: pkt->buf_size=%d tpid=0x%x", nic->log_name,
36622c
+		  pkt->buf_size, eth_vlan->tpid);
36622c
+	
36622c
 	if (eth_vlan->tpid == htons(UIP_ETHTYPE_8021Q)) {
36622c
 		memcpy(bp->tx_pkt, pkt->buf, sizeof(struct uip_eth_hdr));
36622c
 		eth->type = eth_vlan->type;
36622c
 		pkt->buf_size -= (sizeof(struct uip_vlan_eth_hdr) -
36622c
 				  sizeof(struct uip_eth_hdr));
36622c
+
36622c
+	LOG_DEBUG(PFX "%s: pkt->buf_size=%d type=0x%x", nic->log_name,
36622c
+		  pkt->buf_size, eth->type);
36622c
+	LOG_DEBUG(PFX "%s: pkt->buf_size - eth_hdr_size = %d", nic->log_name,
36622c
+		  pkt->buf_size - sizeof(struct uip_eth_hdr));
36622c
+
36622c
 		memcpy(bp->tx_pkt + sizeof(struct uip_eth_hdr),
36622c
 		       pkt->buf + sizeof(struct uip_vlan_eth_hdr),
36622c
 		       pkt->buf_size - sizeof(struct uip_eth_hdr));
36622c
 	} else {
36622c
+		LOG_DEBUG(PFX "%s: NO VLAN pkt->buf_size=%d", nic->log_name,
36622c
+			  pkt->buf_size);
36622c
 		memcpy(bp->tx_pkt, pkt->buf, pkt->buf_size);
36622c
 	}
36622c
 
36622c
@@ -876,11 +889,18 @@ void qedi_start_xmit(nic_t *nic, size_t len, u16_t vlan_id)
36622c
 	path_data->handle = QEDI_PATH_HANDLE;
36622c
 	path_data->vlan_id = vlan_id;
36622c
 	uctrl->host_tx_pkt_len = len;
36622c
+	LOG_DEBUG(PFX "%s: host_no:%d vlan_id=%d, tx_pkt_len=%d",
36622c
+		  nic->log_name, ev->u.set_path.host_no, path_data->vlan_id, uctrl->host_tx_pkt_len);
36622c
 
36622c
+	LOG_DEBUG(PFX "%s: ACQUIRE HOST MUTEX", nic->log_name);
36622c
+	pthread_mutex_lock(&host_mutex);
36622c
 	rc = __kipc_call(nl_sock, ev, buflen);
36622c
 	if (rc > 0) {
36622c
 		bp->tx_prod++;
36622c
 		uctrl->host_tx_prod++;
36622c
+		LOG_DEBUG(PFX "%s: bp->tx_prod: %d, uctrl->host_tx_prod=%d",
36622c
+			  nic->log_name, bp->tx_prod, uctrl->host_tx_prod);
36622c
+
36622c
 		msync(uctrl, sizeof(struct qedi_uio_ctrl), MS_SYNC);
36622c
 		LOG_PACKET(PFX "%s: sent %d bytes using bp->tx_prod: %d",
36622c
 			   nic->log_name, len, bp->tx_prod);
36622c
@@ -888,6 +908,8 @@ void qedi_start_xmit(nic_t *nic, size_t len, u16_t vlan_id)
36622c
 		LOG_ERR(PFX "Pkt transmission failed: %d", rc);
36622c
 	}
36622c
 
36622c
+	LOG_DEBUG(PFX "%s: RELEASE HOST MUTEX", nic->log_name);
36622c
+	pthread_mutex_unlock(&host_mutex);
36622c
 	free(ubuf);
36622c
 }
36622c
 
36622c
@@ -923,14 +945,18 @@ int qedi_write(nic_t *nic, nic_interface_t *nic_iface, packet_t *pkt)
36622c
 		struct timespec sleep_req = {.tv_sec = 0, .tv_nsec = 5000000 },
36622c
 		    sleep_rem;
36622c
 
36622c
+		LOG_DEBUG(PFX "%s: host:%d - calling clear_tx_intr from qedi_write",
36622c
+			  nic->log_name, nic->host_no);
36622c
 		if (qedi_clear_tx_intr(nic) == 0)
36622c
 			break;
36622c
 
36622c
 		nanosleep(&sleep_req, &sleep_rem);
36622c
 	}
36622c
 
36622c
+	LOG_DEBUG(PFX "%s: host:%d - try getting xmit mutex",
36622c
+		   nic->log_name, nic->host_no);
36622c
 	if (pthread_mutex_trylock(&nic->xmit_mutex) != 0) {
36622c
-		LOG_PACKET(PFX "%s: Dropped previous transmitted packet",
36622c
+		LOG_DEBUG(PFX "%s: Dropped previous transmitted packet",
36622c
 			   nic->log_name);
36622c
 		return -EINVAL;
36622c
 	}
36622c
@@ -944,7 +970,7 @@ int qedi_write(nic_t *nic, nic_interface_t *nic_iface, packet_t *pkt)
36622c
 	nic->stats.tx.packets++;
36622c
 	nic->stats.tx.bytes += uip->uip_len;
36622c
 
36622c
-	LOG_PACKET(PFX "%s: transmitted %d bytes dev->tx_cons: %d, dev->tx_prod: %d, dev->tx_bd_prod:%d",
36622c
+	LOG_DEBUG(PFX "%s: transmitted %d bytes dev->tx_cons: %d, dev->tx_prod: %d, dev->tx_bd_prod:%d",
36622c
 		   nic->log_name, pkt->buf_size,
36622c
 		   bp->tx_cons, bp->tx_prod, bp->tx_bd_prod);
36622c
 
36622c
@@ -1071,7 +1097,7 @@ static int qedi_clear_tx_intr(nic_t *nic)
36622c
 		return -EINVAL;
36622c
 	}
36622c
 
36622c
-	LOG_PACKET(PFX "%s: clearing tx interrupt [%d %d]",
36622c
+	LOG_DEBUG(PFX "%s: clearing tx interrupt [%d %d]",
36622c
 		   nic->log_name, bp->tx_cons, hw_cons);
36622c
 	bp->tx_cons = hw_cons;
36622c
 
36622c
@@ -1083,7 +1109,7 @@ static int qedi_clear_tx_intr(nic_t *nic)
36622c
 		packet_t *pkt;
36622c
 		int i;
36622c
 
36622c
-		LOG_PACKET(PFX "%s: sending queued tx packet", nic->log_name);
36622c
+		LOG_DEBUG(PFX "%s: sending queued tx packet", nic->log_name);
36622c
 		pkt = nic_dequeue_tx_packet(nic);
36622c
 
36622c
 		/* Got a TX packet buffer of the TX queue and put it onto
36622c
@@ -1096,7 +1122,7 @@ static int qedi_clear_tx_intr(nic_t *nic)
36622c
 					(pkt->nic_iface->vlan_priority << 12) |
36622c
 					pkt->nic_iface->vlan_id);
36622c
 
36622c
-			LOG_PACKET(PFX "%s: transmitted queued packet %d bytes, dev->tx_cons: %d, dev->tx_prod: %d, dev->tx_bd_prod:%d",
36622c
+			LOG_DEBUG(PFX "%s: transmitted queued packet %d bytes, dev->tx_cons: %d, dev->tx_prod: %d, dev->tx_bd_prod:%d",
36622c
 				   nic->log_name, pkt->buf_size,
36622c
 				   bp->tx_cons, bp->tx_prod, bp->tx_bd_prod);
36622c
 
36622c
@@ -1124,6 +1150,8 @@ static int qedi_clear_tx_intr(nic_t *nic)
36622c
 		}
36622c
 	}
36622c
 
36622c
+	LOG_DEBUG(PFX "%s: host:%d - releasing xmit mutex",
36622c
+		   nic->log_name, nic->host_no);
36622c
 	pthread_mutex_unlock(&nic->xmit_mutex);
36622c
 
36622c
 	return 0;
36622c
diff --git a/iscsiuio/src/unix/nic.c b/iscsiuio/src/unix/nic.c
36622c
index a5f714a91923..dfc2ad0a7a7b 100644
36622c
--- a/iscsiuio/src/unix/nic.c
36622c
+++ b/iscsiuio/src/unix/nic.c
36622c
@@ -799,6 +799,8 @@ int nic_process_intr(nic_t *nic, int discard_check)
36622c
 
36622c
 		nic->intr_count = count;
36622c
 
36622c
+		LOG_DEBUG(PFX "%s: host:%d - calling clear_tx_intr from process_intr",
36622c
+			   nic->log_name, nic->host_no);
36622c
 		(*nic->ops->clear_tx_intr) (nic);
36622c
 		ret = 1;
36622c
 	}
36622c
@@ -1036,9 +1038,11 @@ int process_packets(nic_t *nic,
36622c
 		case UIP_ETHTYPE_IPv4:
36622c
 		case UIP_ETHTYPE_ARP:
36622c
 			af_type = AF_INET;
36622c
+			LOG_DEBUG(PFX "%s: ARP or IPv4 vlan:0x%x ethertype:0x%x",
36622c
+				   nic->log_name, vlan_id, type);
36622c
 			break;
36622c
 		default:
36622c
-			LOG_PACKET(PFX "%s: Ignoring vlan:0x%x ethertype:0x%x",
36622c
+			LOG_DEBUG(PFX "%s: Ignoring vlan:0x%x ethertype:0x%x",
36622c
 				   nic->log_name, vlan_id, type);
36622c
 			goto done;
36622c
 		}
36622c
@@ -1064,7 +1068,7 @@ int process_packets(nic_t *nic,
36622c
 		if (nic_iface == NULL) {
36622c
 			/* Matching nic_iface not found */
36622c
 			pthread_mutex_unlock(&nic->nic_mutex);
36622c
-			LOG_PACKET(PFX "%s: Couldn't find interface for "
36622c
+			LOG_DEBUG(PFX "%s: Couldn't find interface for "
36622c
 				   "VLAN: %d af_type %d",
36622c
 				nic->log_name, vlan_id, af_type);
36622c
 			rc = EINVAL;  /* Return the +error code */
36622c
@@ -1118,6 +1122,8 @@ nic_iface_present:
36622c
 				prepare_ipv4_packet(nic, nic_iface,
36622c
 						    ustack, pkt);
36622c
 
36622c
+				LOG_DEBUG(PFX "%s: write called after arp_ipin, uip_len=%d",
36622c
+					  nic->log_name, ustack->uip_len);
36622c
 				(*nic->ops->write) (nic, nic_iface, pkt);
36622c
 			}
36622c
 
36622c
@@ -1129,8 +1135,11 @@ nic_iface_present:
36622c
 			 * in data that should be sent out on the
36622c
 			 * network, the global variable uip_len
36622c
 			 * is set to a value > 0. */
36622c
-			if (pkt->buf_size > 0)
36622c
+			if (pkt->buf_size > 0) {
36622c
+				LOG_DEBUG(PFX "%s: write called after arp_arpin, bufsize=%d",
36622c
+					   nic->log_name, pkt->buf_size);
36622c
 				(*nic->ops->write) (nic, nic_iface, pkt);
36622c
+			}
36622c
 			break;
36622c
 		}
36622c
 		ustack->uip_len = 0;
36622c
diff --git a/iscsiuio/src/unix/nic_utils.c b/iscsiuio/src/unix/nic_utils.c
36622c
index 6e580f862eea..988905bca2a9 100644
36622c
--- a/iscsiuio/src/unix/nic_utils.c
36622c
+++ b/iscsiuio/src/unix/nic_utils.c
36622c
@@ -1435,6 +1435,10 @@ nic_interface_t *nic_find_nic_iface(nic_t *nic,
36622c
 	nic_interface_t *current_vlan = NULL;
36622c
 
36622c
 	while (current != NULL) {
36622c
+		LOG_DEBUG(PFX "%s: incoming protocol: %d, vlan_id:%d iface_num: %d, request_type: %d",
36622c
+			  nic->log_name, protocol, vlan_id, iface_num,  request_type);
36622c
+		LOG_DEBUG(PFX "%s: host:%d iface_num: 0x%x VLAN: %d protocol: %d",
36622c
+			  nic->log_name, nic->host_no, current->iface_num, current->vlan_id, current->protocol);
36622c
 		if (current->protocol != protocol)
36622c
 			goto next;
36622c
 
36622c
-- 
36622c
2.14.4
36622c