Skip to contentSkip to conversation

Initialise mid_q_entry before putting it on the pending queue

PATCH Superseded Sachin Prabhu 3 participants 4 messages Jul 10, 2012 – Jul 11, 2012 2 messages not in the archive

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Initialise mid_q_entry before putting it on the pending queue

A user reported a crash in cifs_demultiplex_thread() caused by an incorrectly set mid_q_entry->callback() function. It appears that the callback assignment made in cifs_call_async() was not flushed back to memory suggesting that a memory barrier was required here. Changing the code to make sure that the mid_q_entry structure was completely initialised before it was added to the pending queue fixes the problem.

---
 fs/cifs/transport.c |   20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
fs/cifs/transport.c +10 -10
index 3097ee5..c5faf02 100644
@@ -365,14 +365,10 @@ cifs_setup_async_request(struct TCP_Server_Info *server, struct kvec *iov,
 	if (mid == NULL)
 		return -ENOMEM;
 
-	/* put it on the pending_mid_q */
-	spin_lock(&GlobalMid_Lock);
-	list_add_tail(&mid->qhead, &server->pending_mid_q);
-	spin_unlock(&GlobalMid_Lock);
-
 	rc = cifs_sign_smb2(iov, nvec, server, &mid->sequence_number);
 	if (rc)
-		delete_mid(mid);
+		DeleteMidQEntry(mid);
+
 	*ret_mid = mid;
 	return rc;
 }
@@ -407,17 +403,21 @@ cifs_call_async(struct TCP_Server_Info *server, struct kvec *iov,
 	mid->callback_data = cbdata;
 	mid->mid_state = MID_REQUEST_SUBMITTED;
 
+	/* put it on the pending_mid_q */
+	spin_lock(&GlobalMid_Lock);
+	list_add_tail(&mid->qhead, &server->pending_mid_q);
+	spin_unlock(&GlobalMid_Lock);
+
+
 	cifs_in_send_inc(server);
 	rc = smb_sendv(server, iov, nvec);
 	cifs_in_send_dec(server);
 	cifs_save_when_sent(mid);
 	mutex_unlock(&server->srv_mutex);
 
-	if (rc)
-		goto out_err;
+	if (rc == 0)
+		return 0;
 
-	return rc;
-out_err:
 	delete_mid(mid);
 	add_credits(server, 1);
 	wake_up(&server->request_q);
Signature · 1 line
1.7.10.4
Reviewed-by
#2 lore raw
In reply to a message not in the archive
Quoted 49 lines · On Tue, 10 Jul 2012 19:58:40 +0100 Sachin Prabhu…

A user reported a crash in cifs_demultiplex_thread() caused by an incorrectly set mid_q_entry->callback() function. It appears that the callback assignment made in cifs_call_async() was not flushed back to memory suggesting that a memory barrier was required here. Changing the code to make sure that the mid_q_entry structure was completely initialised before it was added to the pending queue fixes the problem.

---
 fs/cifs/transport.c |   20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
fs/cifs/transport.c +8 -6
index 3097ee5..c5faf02 100644
@@ -365,14 +365,10 @@ cifs_setup_async_request(struct TCP_Server_Info *server, struct kvec *iov,
 	if (mid == NULL)
 		return -ENOMEM;
 
-	/* put it on the pending_mid_q */
-	spin_lock(&GlobalMid_Lock);
-	list_add_tail(&mid->qhead, &server->pending_mid_q);
-	spin_unlock(&GlobalMid_Lock);
-
 	rc = cifs_sign_smb2(iov, nvec, server, &mid->sequence_number);
 	if (rc)
-		delete_mid(mid);
+		DeleteMidQEntry(mid);
+
 	*ret_mid = mid;
 	return rc;
 }
@@ -407,17 +403,21 @@ cifs_call_async(struct TCP_Server_Info *server, struct kvec *iov,
 	mid->callback_data = cbdata;
 	mid->mid_state = MID_REQUEST_SUBMITTED;
 
+	/* put it on the pending_mid_q */
+	spin_lock(&GlobalMid_Lock);
+	list_add_tail(&mid->qhead, &server->pending_mid_q);
+	spin_unlock(&GlobalMid_Lock);
+
+
 	cifs_in_send_inc(server);
 	rc = smb_sendv(server, iov, nvec);
 	cifs_in_send_dec(server);
 	cifs_save_when_sent(mid);
 	mutex_unlock(&server->srv_mutex);
 

fs/cifs/transport.c cifs_call_async(struct TCP_Server_Info *server, struct kvec *iov, · line 423

Quoted 10 lines
fs/cifs/transport.c +2 -4
-	if (rc)
-		goto out_err;
+	if (rc == 0)
+		return 0;
 
-	return rc;
-out_err:
 	delete_mid(mid);
 	add_credits(server, 1);
 	wake_up(&server->request_q);

Looks correct.

#3 lore raw
In reply to a message not in the archive
Quoted 21 lines · Sachin Prabhu

A user reported a crash in cifs_demultiplex_thread() caused by an incorrectly set mid_q_entry->callback() function. It appears that the callback assignment made in cifs_call_async() was not flushed back to memory suggesting that a memory barrier was required here. Changing the code to make sure that the mid_q_entry structure was completely initialised before it was added to the pending queue fixes the problem.

---
 fs/cifs/transport.c |   20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
fs/cifs/transport.c +0 -1
index 3097ee5..c5faf02 100644
@@ -365,14 +365,10 @@ cifs_setup_async_request(struct TCP_Server_Info *server, struct kvec *iov,
        if (mid == NULL)
                return -ENOMEM;
 
-       /* put it on the pending_mid_q */

fs/cifs/transport.c cifs_setup_async_request(struct TCP_Server_Info *server, struct kvec *iov, · line 372

Quoted 10 lines
fs/cifs/transport.c +2 -5
-       spin_lock(&GlobalMid_Lock);
-       list_add_tail(&mid->qhead, &server->pending_mid_q);
-       spin_unlock(&GlobalMid_Lock);
-
        rc = cifs_sign_smb2(iov, nvec, server, &mid->sequence_number);
        if (rc)
-               delete_mid(mid);
+               DeleteMidQEntry(mid);
+
        *ret_mid = mid;

Looks correct. But just a thought, why bother assigning ret_mid a Deleted mid if rc is not null?

Quoted 31 lines
fs/cifs/transport.c +8 -5
        return rc;
 }
@@ -407,17 +403,21 @@ cifs_call_async(struct TCP_Server_Info *server, struct kvec *iov,
        mid->callback_data = cbdata;
        mid->mid_state = MID_REQUEST_SUBMITTED;
 
+       /* put it on the pending_mid_q */
+       spin_lock(&GlobalMid_Lock);
+       list_add_tail(&mid->qhead, &server->pending_mid_q);
+       spin_unlock(&GlobalMid_Lock);
+
+
        cifs_in_send_inc(server);
        rc = smb_sendv(server, iov, nvec);
        cifs_in_send_dec(server);
        cifs_save_when_sent(mid);
        mutex_unlock(&server->srv_mutex);
 
-       if (rc)
-               goto out_err;
+       if (rc == 0)
+               return 0;
 
-       return rc;
-out_err:
        delete_mid(mid);
        add_credits(server, 1);
        wake_up(&server->request_q);
--

1.7.10.4

#5 lore raw
In reply to a message not in the archive
Quoted 21 lines · Shirish Pargaonkar
Quoted 20 lines · Sachin Prabhu

A user reported a crash in cifs_demultiplex_thread() caused by an incorrectly set mid_q_entry->callback() function. It appears that the callback assignment made in cifs_call_async() was not flushed back to memory suggesting that a memory barrier was required here. Changing the code to make sure that the mid_q_entry structure was completely initialised before it was added to the pending queue fixes the problem.

---
 fs/cifs/transport.c |   20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
fs/cifs/transport.c +0 -0
index 3097ee5..c5faf02 100644
@@ -365,14 +365,10 @@ cifs_setup_async_request(struct TCP_Server_Info *server, struct kvec *iov,
        if (mid == NULL)
                return -ENOMEM;
 
Quoted 14 lines

fs/cifs/transport.c cifs_setup_async_request(struct TCP_Server_Info *server, struct kvec *iov, · line 372

Quoted 11 lines
fs/cifs/transport.c +2 -6
-       /* put it on the pending_mid_q */
-       spin_lock(&GlobalMid_Lock);
-       list_add_tail(&mid->qhead, &server->pending_mid_q);
-       spin_unlock(&GlobalMid_Lock);
-
        rc = cifs_sign_smb2(iov, nvec, server, &mid->sequence_number);
        if (rc)
-               delete_mid(mid);
+               DeleteMidQEntry(mid);
+
        *ret_mid = mid;

Looks correct. But just a thought, why bother assigning ret_mid a Deleted mid if rc is not null?

I did notice this line which was already set to do this when I wrote the patch. Since it did not result in any error, I left it alone. I will create another patch which cleans this bit of the code.

Sachin Prabhu

Quoted 36 lines
Quoted 30 lines
fs/cifs/transport.c +8 -5
        return rc;
 }
@@ -407,17 +403,21 @@ cifs_call_async(struct TCP_Server_Info *server, struct kvec *iov,
        mid->callback_data = cbdata;
        mid->mid_state = MID_REQUEST_SUBMITTED;
 
+       /* put it on the pending_mid_q */
+       spin_lock(&GlobalMid_Lock);
+       list_add_tail(&mid->qhead, &server->pending_mid_q);
+       spin_unlock(&GlobalMid_Lock);
+
+
        cifs_in_send_inc(server);
        rc = smb_sendv(server, iov, nvec);
        cifs_in_send_dec(server);
        cifs_save_when_sent(mid);
        mutex_unlock(&server->srv_mutex);
 
-       if (rc)
-               goto out_err;
+       if (rc == 0)
+               return 0;
 
-       return rc;
-out_err:
        delete_mid(mid);
        add_credits(server, 1);
        wake_up(&server->request_q);
--
Quoted 2 lines

1.7.10.4

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