Skip to contentSkip to conversation

be2iscsi: Fix for premature buffer free

PATCH In review Jayamohan Kallickal 3 participants 4 messages Jun 30, 2010 – Jul 5, 2010

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

PATCH 7/12 be2iscsi: Fix for premature buffer free

This patch fixes a bug where the buffer was being freed as soon as submission to HW
is done.

---
 drivers/scsi/be2iscsi/be_iscsi.c |   24 ++++++++++++++++++--
 drivers/scsi/be2iscsi/be_main.c  |   43 +++++++++++++++++++++++++++++++++---
 drivers/scsi/be2iscsi/be_mgmt.c  |   44 ++++++++++++++++++-------------------
 drivers/scsi/be2iscsi/be_mgmt.h  |   10 +++++---
 4 files changed, 87 insertions(+), 34 deletions(-)
drivers/scsi/be2iscsi/be_iscsi.c +21 -3
index 49e3718..7acf351 100644
@@ -488,6 +488,7 @@ static int beiscsi_open_conn(struct iscsi_endpoint *ep,
 	struct be_mcc_wrb *wrb;
 	struct tcp_connect_and_offload_out *ptcpcnct_out;
 	unsigned short status, extd_status;
+	struct be_dma_mem nonemb_cmd;
 	unsigned int tag, wrb_num;
 	int ret = -1;
 
@@ -508,7 +509,20 @@ static int beiscsi_open_conn(struct iscsi_endpoint *ep,
 	}
 
 	beiscsi_ep->cid_vld = 0;
-	tag = mgmt_open_connection(phba, dst_addr, beiscsi_ep);
+
+	nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
+				sizeof(struct tcp_connect_and_offload_in),
+				&nonemb_cmd.dma);
+	if (nonemb_cmd.va == NULL) {
+		SE_DEBUG(DBG_LVL_1,
+			 "Failed to allocate memory for mgmt_open_connection"
+			 "\n");
+		goto free_ep;
+	}
+	nonemb_cmd.size = sizeof(struct tcp_connect_and_offload_in);
+	memset(nonemb_cmd.va, 0, nonemb_cmd.size);
+	tag = mgmt_open_connection(phba, dst_addr, beiscsi_ep, &nonemb_cmd);
+
 	if (!tag) {
 		SE_DEBUG(DBG_LVL_1,
 			 "mgmt_open_connection Failed for cid=%d\n",
@@ -525,6 +539,8 @@ static int beiscsi_open_conn(struct iscsi_endpoint *ep,
 				    " status = %d extd_status = %d\n",
 				    status, extd_status);
 		free_mcc_tag(&phba->ctrl, tag);
+		pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
+			    nonemb_cmd.va, nonemb_cmd.dma);
 		goto free_ep;
 	} else {
 		wrb = queue_get_wrb(mccq, wrb_num);
@@ -536,6 +552,8 @@ static int beiscsi_open_conn(struct iscsi_endpoint *ep,
 		beiscsi_ep->cid_vld = 1;
 		SE_DEBUG(DBG_LVL_8, "mgmt_open_connection Success\n");
 	}
+	pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
+			    nonemb_cmd.va, nonemb_cmd.dma);
 	return 0;
 
 free_ep:
@@ -587,12 +605,12 @@ beiscsi_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,
 	if (beiscsi_open_conn(ep, NULL, dst_addr, non_blocking)) {
 		SE_DEBUG(DBG_LVL_1, "Failed in beiscsi_open_conn\n");
 		ret = -ENOMEM;
-		goto free_ep;
+		goto dstry_ep;
 	}
 
 	return ep;
 
-free_ep:
+dstry_ep:
 	iscsi_destroy_endpoint(ep);
 	return ERR_PTR(ret);
 }
drivers/scsi/be2iscsi/be_main.c +39 -4

87 lines not on this page · raw message

drivers/scsi/be2iscsi/be_mgmt.c +21 -23

98 lines not on this page · raw message

drivers/scsi/be2iscsi/be_mgmt.h +6 -4
index 3d316b8..a1ae347 100644
@@ -87,15 +87,17 @@ struct mcc_wrb {
 };
 
 unsigned char mgmt_epfw_cleanup(struct beiscsi_hba *phba, unsigned short chute);
-int mgmt_open_connection(struct beiscsi_hba *phba, struct sockaddr *dst_addr,
-			 struct beiscsi_endpoint *beiscsi_ep);
-
+int mgmt_open_connection(struct beiscsi_hba *phba,
+			 struct sockaddr *dst_addr,
+			 struct beiscsi_endpoint *beiscsi_ep,
+			 struct be_dma_mem *nonemb_cmd);
 unsigned char mgmt_upload_connection(struct beiscsi_hba *phba,
 				     unsigned short cid,
 				     unsigned int upload_flag);
 unsigned char mgmt_invalidate_icds(struct beiscsi_hba *phba,
 				struct invalidate_command_table *inv_tbl,
-				unsigned int num_invalidate, unsigned int cid);
+				unsigned int num_invalidate, unsigned int cid,
+				struct be_dma_mem *nonemb_cmd);
 
 struct iscsi_invalidate_connection_params_in {
 	struct be_cmd_req_hdr hdr;
Signature · 1 line
1.6.5.2
#1 lore raw
Quoted 32 lines · Jayamohan Kallickal

This patch fixes a bug where the buffer was being freed as soon as submission to HW
is done.

---
  drivers/scsi/be2iscsi/be_iscsi.c |   24 ++++++++++++++++++--
  drivers/scsi/be2iscsi/be_main.c  |   43 +++++++++++++++++++++++++++++++++---
  drivers/scsi/be2iscsi/be_mgmt.c  |   44 ++++++++++++++++++-------------------
  drivers/scsi/be2iscsi/be_mgmt.h  |   10 +++++---
  4 files changed, 87 insertions(+), 34 deletions(-)
drivers/scsi/be2iscsi/be_iscsi.c +5 -1
index 49e3718..7acf351 100644
@@ -488,6 +488,7 @@ static int beiscsi_open_conn(struct iscsi_endpoint *ep,
  	struct be_mcc_wrb *wrb;
  	struct tcp_connect_and_offload_out *ptcpcnct_out;
  	unsigned short status, extd_status;
+	struct be_dma_mem nonemb_cmd;
  	unsigned int tag, wrb_num;
  	int ret = -1;
 
@@ -508,7 +509,20 @@ static int beiscsi_open_conn(struct iscsi_endpoint *ep,
  	}
 
  	beiscsi_ep->cid_vld = 0;
-	tag = mgmt_open_connection(phba, dst_addr, beiscsi_ep);
+
+	nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
+				sizeof(struct tcp_connect_and_offload_in),
+				&nonemb_cmd.dma);

drivers/scsi/be2iscsi/be_iscsi.c static int beiscsi_open_conn(struct iscsi_endpoint *ep, · line 525

Quoted 10 lines
drivers/scsi/be2iscsi/be_iscsi.c +10 -0
+	if (nonemb_cmd.va == NULL) {
+		SE_DEBUG(DBG_LVL_1,
+			 "Failed to allocate memory for mgmt_open_connection"
+			 "\n");
+		goto free_ep;
+	}
+	nonemb_cmd.size = sizeof(struct tcp_connect_and_offload_in);
+	memset(nonemb_cmd.va, 0, nonemb_cmd.size);
+	tag = mgmt_open_connection(phba, dst_addr, beiscsi_ep,&nonemb_cmd);
+

Don't need extra newline.

Quoted 51 lines
drivers/scsi/be2iscsi/be_iscsi.c +6 -2
  	if (!tag) {
  		SE_DEBUG(DBG_LVL_1,
  			 "mgmt_open_connection Failed for cid=%d\n",
@@ -525,6 +539,8 @@ static int beiscsi_open_conn(struct iscsi_endpoint *ep,
  				    " status = %d extd_status = %d\n",
  				    status, extd_status);
  		free_mcc_tag(&phba->ctrl, tag);
+		pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
+			    nonemb_cmd.va, nonemb_cmd.dma);
  		goto free_ep;
  	} else {
  		wrb = queue_get_wrb(mccq, wrb_num);
@@ -536,6 +552,8 @@ static int beiscsi_open_conn(struct iscsi_endpoint *ep,
  		beiscsi_ep->cid_vld = 1;
  		SE_DEBUG(DBG_LVL_8, "mgmt_open_connection Success\n");
  	}
+	pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
+			    nonemb_cmd.va, nonemb_cmd.dma);
  	return 0;
 
  free_ep:
@@ -587,12 +605,12 @@ beiscsi_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,
  	if (beiscsi_open_conn(ep, NULL, dst_addr, non_blocking)) {
  		SE_DEBUG(DBG_LVL_1, "Failed in beiscsi_open_conn\n");
  		ret = -ENOMEM;
-		goto free_ep;
+		goto dstry_ep;
  	}
 
  	return ep;
 
-free_ep:
+dstry_ep:
  	iscsi_destroy_endpoint(ep);
  	return ERR_PTR(ret);
  }
drivers/scsi/be2iscsi/be_main.c +1 -0
index 8f3e4b9..b17897b 100644
@@ -71,6 +71,7 @@ static int beiscsi_eh_abort(struct scsi_cmnd *sc)
  	struct beiscsi_hba *phba;
  	struct iscsi_session *session;
  	struct invalidate_command_table *inv_tbl;
+	struct be_dma_mem nonemb_cmd;
  	unsigned int cid, tag, num_invalidate;
 
  	cls_session = starget_to_session(scsi_target(sc->device));
@@ -101,18 +102,35 @@ static int beiscsi_eh_abort(struct scsi_cmnd *sc)
  	inv_tbl->cid = cid;
  	inv_tbl->icd = aborted_io_task->psgl_handle->sgl_index;

drivers/scsi/be2iscsi/be_main.c static int beiscsi_eh_abort(struct scsi_cmnd *sc) · line 112

Quoted 10 lines
drivers/scsi/be2iscsi/be_main.c +8 -1
  	num_invalidate = 1;
-	tag = mgmt_invalidate_icds(phba, inv_tbl, num_invalidate, cid);
+	nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
+				sizeof(struct invalidate_commands_params_in),
+				&nonemb_cmd.dma);
+	if (nonemb_cmd.va == NULL) {
+		SE_DEBUG(DBG_LVL_1,
+			 "Failed to allocate memory for"
+			 "mgmt_invalidate_icds\n");
+		return -1;

This should be return FAILED.

drivers/scsi/be2iscsi/be_main.c static int beiscsi_eh_abort(struct scsi_cmnd *sc) · line 122

Quoted 10 lines
drivers/scsi/be2iscsi/be_main.c +6 -0
+	}
+	nonemb_cmd.size = sizeof(struct invalidate_commands_params_in);
+
+	tag = mgmt_invalidate_icds(phba, inv_tbl, num_invalidate,
+				   cid,&nonemb_cmd);
  	if (!tag) {
  		shost_printk(KERN_WARNING, phba->shost,
  			     "mgmt_invalidate_icds could not be"
  			     " submitted\n");
+		if (nonemb_cmd.va)

I do not think you need the test. Shouldn't this always be set, or what other path could free it?

Quoted 26 lines
drivers/scsi/be2iscsi/be_main.c +6 -1
+			pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
+				    nonemb_cmd.va, nonemb_cmd.dma);
+
  		return FAILED;
  	} else {
  		wait_event_interruptible(phba->ctrl.mcc_wait[tag],
  					 phba->ctrl.mcc_numtag[tag]);
  		free_mcc_tag(&phba->ctrl, tag);
  	}
-
+	pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
+				    nonemb_cmd.va, nonemb_cmd.dma);
  	return iscsi_eh_abort(sc);
  }
 
@@ -126,6 +144,7 @@ static int beiscsi_eh_device_reset(struct scsi_cmnd *sc)
  	struct iscsi_session *session;
  	struct iscsi_cls_session *cls_session;
  	struct invalidate_command_table *inv_tbl;
+	struct be_dma_mem nonemb_cmd;
  	unsigned int cid, tag, i, num_invalidate;
  	int rc = FAILED;
 
@@ -160,18 +179,34 @@ static int beiscsi_eh_device_reset(struct scsi_cmnd *sc)
  	spin_unlock_bh(&session->lock);
  	inv_tbl = phba->inv_tbl;

drivers/scsi/be2iscsi/be_main.c static int beiscsi_eh_device_reset(struct scsi_cmnd *sc) · line 189

Quoted 10 lines
drivers/scsi/be2iscsi/be_main.c +8 -1
 
-	tag = mgmt_invalidate_icds(phba, inv_tbl, num_invalidate, cid);
+	nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
+				sizeof(struct invalidate_commands_params_in),
+				&nonemb_cmd.dma);
+	if (nonemb_cmd.va == NULL) {
+		SE_DEBUG(DBG_LVL_1,
+			 "Failed to allocate memory for"
+			 "mgmt_invalidate_icds\n");
+		return -1;

return FAILED.

#2 lore raw
Quoted 8 lines · Mike Christie
Quoted 6 lines · Jayamohan Kallickal
drivers/scsi/be2iscsi/be_main.c +0 -0
@@ -160,18 +179,34 @@ static int beiscsi_eh_device_reset(struct scsi_cmnd
 *sc)
 
  	spin_unlock_bh(&session->lock);
  	inv_tbl = phba->inv_tbl;
 
Quoted 11 lines

drivers/scsi/be2iscsi/be_main.c static int beiscsi_eh_abort(struct scsi_cmnd *sc) · line 112

Quoted 9 lines
drivers/scsi/be2iscsi/be_main.c +8 -1
-	tag = mgmt_invalidate_icds(phba, inv_tbl, num_invalidate, cid);
+	nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
+				sizeof(struct invalidate_commands_params_in),
+				&nonemb_cmd.dma);
+	if (nonemb_cmd.va == NULL) {
+		SE_DEBUG(DBG_LVL_1,
+			 "Failed to allocate memory for"
+			 "mgmt_invalidate_icds\n");
+		return -1;

return FAILED.

Why not ENOMEM? That would come into my mind when an allocations fails.

Eike

#3 lore raw
Quoted 21 lines · Rolf Eike Beer
Quoted 8 lines · Mike Christie
Quoted 6 lines · Jayamohan Kallickal
drivers/scsi/be2iscsi/be_main.c +0 -0
@@ -160,18 +179,34 @@ static int beiscsi_eh_device_reset(struct scsi_cmnd
 *sc)
 
   	spin_unlock_bh(&session->lock);
   	inv_tbl = phba->inv_tbl;
 
Quoted 11 lines

drivers/scsi/be2iscsi/be_main.c static int beiscsi_eh_abort(struct scsi_cmnd *sc) · line 112

Quoted 9 lines
drivers/scsi/be2iscsi/be_main.c +8 -1
-	tag = mgmt_invalidate_icds(phba, inv_tbl, num_invalidate, cid);
+	nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
+				sizeof(struct invalidate_commands_params_in),
+				&nonemb_cmd.dma);
+	if (nonemb_cmd.va == NULL) {
+		SE_DEBUG(DBG_LVL_1,
+			 "Failed to allocate memory for"
+			 "mgmt_invalidate_icds\n");
+		return -1;

return FAILED.

Quoted 2 lines

Why not ENOMEM? That would come into my mind when an allocations fails.

Because that function is called by the scsi layer's error handling code and it uses SUCCESS and FAILED for return values.