Skip to contentSkip to conversation

cifs: Do not modify mid entry after submitting I/O in cifs_call_async

PATCH Superseded Long Li 2 participants 2 messages Jun 28, 2017

Subsystems (2)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Long Li

author
#0 lore raw

PATCH v3 1/1 cifs: Do not modify mid entry after submitting I/O in cifs_call_async

From: Long Li <[email protected]>

In cifs_call_async, server may respond as soon as I/O is submitted. Because mid entry is freed on the return path, it should not be modified after I/O is submitted.

cifs_save_when_sent modifies the sent timestamp in mid entry, and should not be called after I/O. Call it before I/O.

---
 fs/cifs/transport.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
fs/cifs/transport.c +4 -2
index 47a125e..f49b73f 100644
@@ -536,11 +536,13 @@ cifs_call_async(struct TCP_Server_Info *server, struct smb_rqst *rqst,
 	list_add_tail(&mid->qhead, &server->pending_mid_q);
 	spin_unlock(&GlobalMid_Lock);
 
-
+	/* Need to store the time in mid before calling I/O. For call_async,
+	 * I/O response can come back and free the mid entry on another thread.
+	 */
+	cifs_save_when_sent(mid);
 	cifs_in_send_inc(server);
 	rc = smb_send_rqst(server, rqst, flags);
 	cifs_in_send_dec(server);
-	cifs_save_when_sent(mid);
 
 	if (rc < 0) {
 		server->sequence_number -= 2;
Signature · 1 line
2.7.4
Reviewed-by on v3 1/1
#1 lore raw

2017-06-28 15:02 GMT-07:00 Long Li <longli-Lp/[email protected]>:

Quoted 37 lines

From: Long Li <[email protected]>

In cifs_call_async, server may respond as soon as I/O is submitted. Because mid entry is freed on the return path, it should not be modified after I/O is submitted.

cifs_save_when_sent modifies the sent timestamp in mid entry, and should not be called after I/O. Call it before I/O.

---
 fs/cifs/transport.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
fs/cifs/transport.c +4 -3
index 47a125e..f49b73f 100644
@@ -536,11 +536,13 @@ cifs_call_async(struct TCP_Server_Info *server, struct smb_rqst *rqst,
        list_add_tail(&mid->qhead, &server->pending_mid_q);
        spin_unlock(&GlobalMid_Lock);
 
-
+       /* Need to store the time in mid before calling I/O. For call_async,
+        * I/O response can come back and free the mid entry on another thread.
+        */
+       cifs_save_when_sent(mid);
        cifs_in_send_inc(server);
        rc = smb_send_rqst(server, rqst, flags);
        cifs_in_send_dec(server);
-       cifs_save_when_sent(mid);
 
        if (rc < 0) {
                server->sequence_number -= 2;
--

2.7.4

Quoted 4 lines

--
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

Thanks! Please fix the comment style to

/*
* ....
*/

Other than that -

--
Best regards,
Pavel Shilovsky