cifs: clarify the meaning of tcpStatus == CifsGood
Subsystems (3)
PATCH 1/3 cifs: clarify the meaning of tcpStatus == CifsGood
When the TCP_Server_Info is first allocated and connected, tcpStatus == CifsGood means that the NEGOTIATE_PROTOCOL request has completed and the socket is ready for other calls. cifs_reconnect however sets tcpStatus to CifsGood as soon as the socket is reconnected and the optional RFC1001 session setup is done. We have no clear way to tell the difference between these two states, and we need to know this in order to know whether we can send an echo or not.
Resolve this by adding a new statusEnum value -- CifsNeedNegotiate. When the socket has been connected but has not yet had a NEGOTIATE_PROTOCOL request done, set it to this value. Once the NEGOTIATE is done, cifs_negotiate_protocol will set tcpStatus to CifsGood.
This also fixes and cleans the logic in cifs_reconnect and cifs_reconnect_tcon. The old code checked for specific states when what it really wants to know is whether the state has actually changed from CifsNeedReconnect.
--- fs/cifs/cifsglob.h | 3 ++- fs/cifs/cifssmb.c | 4 ++-- fs/cifs/connect.c | 8 ++++---- 3 files changed, 8 insertions(+), 7 deletions(-)
fs/cifs/cifsglob.h +2 -1
@@ -94,7 +94,8 @@ enum statusEnum { CifsNew =0 , CifsGood, CifsExiting, - CifsNeedReconnect + CifsNeedReconnect, + CifsNeedNegotiate }; enum securityEnum {
fs/cifs/cifssmb.c +2 -2
@@ -142,9 +142,9 @@ cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command)*/ while (server->tcpStatus == CifsNeedReconnect) {wait_event_interruptible_timeout (server->response_q, - (server->tcpStatus == CifsGood),10 *HZ ); + (server->tcpStatus != CifsNeedReconnect),10 *HZ ); -/* is TCP session is reestablished now ?*/ +/* are we still trying to reconnect? */ if (server->tcpStatus != CifsNeedReconnect)break ;
fs/cifs/connect.c +4 -4
@@ -203,8 +203,7 @@ cifs_reconnect(struct TCP_Server_Info *server) }spin_unlock (&GlobalMid_Lock); -while ((server->tcpStatus != CifsExiting) && - (server->tcpStatus != CifsGood)) { +while (server->tcpStatus == CifsNeedReconnect) {try_to_freeze ();/* we should try only the port we connected to before */
@@ -216,7 +215,7 @@ cifs_reconnect(struct TCP_Server_Info *server)atomic_inc (&tcpSesReconnectCount);spin_lock (&GlobalMid_Lock);if (server->tcpStatus != CifsExiting) - server->tcpStatus = CifsGood; + server->tcpStatus = CifsNeedNegotiate;spin_unlock (&GlobalMid_Lock); } }
@@ -425,7 +424,7 @@ cifs_demultiplex_thread(struct TCP_Server_Info *server) pdu_length =4 ;/* enough to get RFC1001 header */ incomplete_rcv: -if (echo_retries >0 && +if (echo_retries >0 && server->tcpStatus == CifsGood &&time_after (jiffies, server->lstrp + (echo_retries *SMB_ECHO_INTERVAL ))) { cERROR(1, "Server %s has not responded in %d seconds. "
@@ -1781,6 +1780,7 @@ cifs_get_tcp_session(struct smb_vol *volume_info)cERROR (1 ,"Error connecting to socket. Aborting operation" ); goto out_err_crypto_release; } + tcp_ses->tcpStatus = CifsNeedNegotiate;#ifdef CONFIG_CIFS_SMB2 if (volume_info->use_smb2)
Signature · 1 line
1.7.4
PATCH 2/3 cifs: fix broken BCC check in is_valid_oplock_break
In reply to a message not in the archiveThe BCC is still __le16 at this point, and in any case we need to use the get_bcc_le macro to make sure we don't hit alignment problems.
--- fs/cifs/misc.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
fs/cifs/misc.c +1 -1
@@ -521,7 +521,7 @@ is_valid_oplock_break(struct smb_hdr *buf, struct TCP_Server_Info *srv) (struct smb_com_transaction_change_notify_rsp *)buf;struct file_notify_information *pnotify;__u32 data_offset =0 ; -if (pSMBr->ByteCount >sizeof (struct file_notify_information )) { +if (get_bcc_le (buf) >sizeof (struct file_notify_information )) { data_offset =le32_to_cpu (pSMBr->DataOffset); pnotify = (struct file_notify_information *)
Signature · 1 line
1.7.4
PATCH 3/3 cifs: don't allow mmap'ed pages to be dirtied while under writeback
In reply to a message not in the archiveIf a process has a dirty page mapped into its page tables, then it has the ability to change it while the client is trying to write the data out to the server. If that happens after the signature has been calculated then that signature will then be wrong, and the server will likely reset the TCP connection.
This patch adds a page_mkwrite handler for CIFS that simply takes the page lock. Because the page lock is held over the life of writepage and writepages, this prevents the page from becoming writeable until the write call has completed.
With this, we can also remove the "sign_zero_copy" module option and always inline the pages when writing.
--- fs/cifs/cifsfs.c | 4 --- fs/cifs/cifsglob.h | 1 - fs/cifs/file.c | 62 ++++++++++++++++++++++++++-------------------------- 3 files changed, 31 insertions(+), 36 deletions(-)
fs/cifs/cifsfs.c +0 -4
@@ -81,10 +81,6 @@ module_param(echo_retries, ushort, 0644);MODULE_PARM_DESC (echo_retries,"Number of echo attempts before giving up and " "reconnecting server. Default: 5. 0 means " "never reconnect." ); -bool sign_zero_copy;/* globals init to false automatically */ -module_param (sign_zero_copy, bool,0644 ); -MODULE_PARM_DESC (sign_zero_copy,"Don't copy pages on write with signing " -"enabled. Default: N" );extern mempool_t *cifs_sm_req_poolp;extern mempool_t *cifs_req_poolp;extern mempool_t *cifs_mid_poolp;
fs/cifs/cifsglob.h +0 -1
@@ -858,7 +858,6 @@ GLOBAL_EXTERN unsigned int CIFSMaxBufSize; /* max size not including hdr */ GLOBAL_EXTERN unsigned int cifs_min_rcv; /* min size of big ntwrk buf pool */ GLOBAL_EXTERN unsigned int cifs_min_small; /* min size of small buf pool */ GLOBAL_EXTERN unsigned int cifs_max_pending; /* MAX requests at once to server*/ -GLOBAL_EXTERN bool sign_zero_copy; /* don't copy written pages with signing *//* reconnect after this many failed echo attempts */ GLOBAL_EXTERN unsigned short echo_retries;
fs/cifs/file.c +31 -31
98 lines not on this page · raw message
Signature · 1 line
1.7.4
Re: [PATCH 3/3] cifs: don't allow mmap'ed pages to be dirtied while under writeback
In reply to a message not in the archiveQuoted 14 lines · On Wed, 16 Mar 2011 15:15:31 -0400 Jeff Layton…
If a process has a dirty page mapped into its page tables, then it has the ability to change it while the client is trying to write the data out to the server. If that happens after the signature has been calculated then that signature will then be wrong, and the server will likely reset the TCP connection.
This patch adds a
page_mkwritehandler for CIFS that simply takes the page lock. Because the page lock is held over the life of writepage and writepages, this prevents the page from becoming writeable until the write call has completed.With this, we can also remove the "
sign_zero_copy" module option and always inline the pages when writing.
Quoted 7 lines
Signed-off-by Jeff Layton <[email protected]>--- fs/cifs/cifsfs.c | 4 --- fs/cifs/cifsglob.h | 1 - fs/cifs/file.c | 62 ++++++++++++++++++++++++++-------------------------- 3 files changed, 31 insertions(+), 36 deletions(-)
Steve, can you let me know where we are with this patch? It's not merged and you haven't commented on it.
Signature · 1 line
Jeff Layton <[email protected]>
Re: [PATCH 3/3] cifs: don't allow mmap'ed pages to be dirtied while under writeback
In reply to a message not in the archiveI like this patch very much, but had been waiting for any comments/ack/reviewed-by
one of those more familiar with this part of the mm layer.
Barring any objections, I plan to merge this (and the performance fix) after some additional review today or tomorrow.
Quoted 31 lines · Jeff Layton
Quoted 14 lines · On Wed, 16 Mar 2011 15:15:31 -0400 Jeff Layton…
If a process has a dirty page mapped into its page tables, then it has the ability to change it while the client is trying to write the data out to the server. If that happens after the signature has been calculated then that signature will then be wrong, and the server will likely reset the TCP connection.
This patch adds a
page_mkwritehandler for CIFS that simply takes the page lock. Because the page lock is held over the life of writepage and writepages, this prevents the page from becoming writeable until the write call has completed.With this, we can also remove the "
sign_zero_copy" module option and always inline the pages when writing.Quoted 7 lines
Signed-off-by Jeff Layton <[email protected]>---
fs/cifs/cifsfs.c | 4 ---
fs/cifs/cifsglob.h | 1 -
fs/cifs/file.c | 62 ++++++++++++++++++++++++++--------------------------3 files changed, 31 insertions(+), 36 deletions(-)Steve, can you let me know where we are with this patch? It's not merged and you haven't commented on it.
--
Jeff Layton <[email protected]>
Signature · 3 lines
Thanks, Steve
Re: [PATCH 3/3] cifs: don't allow mmap'ed pages to be dirtied while under writeback
In reply to a message not in the archive2011/3/16 Jeff Layton <[email protected]>:
Quoted 141 lines
If a process has a dirty page mapped into its page tables, then it has the ability to change it while the client is trying to write the data out to the server. If that happens after the signature has been calculated then that signature will then be wrong, and the server will likely reset the TCP connection.
This patch adds a
page_mkwritehandler for CIFS that simply takes the page lock. Because the page lock is held over the life of writepage and writepages, this prevents the page from becoming writeable until the write call has completed.With this, we can also remove the "
sign_zero_copy" module option and always inline the pages when writing.Signed-off-by Jeff Layton <[email protected]>---
fs/cifs/cifsfs.c | 4 ---
fs/cifs/cifsglob.h | 1 -
fs/cifs/file.c | 62 ++++++++++++++++++++++++++--------------------------3 files changed, 31 insertions(+), 36 deletions(-)fs/cifs/cifsfs.c +0
-0@@ -81,10 +81,6 @@ module_param(echo_retries, ushort, 0644);MODULE_PARM_DESC(echo_retries, "Number of echo attempts before giving up and " "reconnecting server. Default: 5. 0 means " "never reconnect.");
fs/cifs/cifsfs.c +0
-4-bool sign_zero_copy; /* globals init to false automatically */ -module_param (sign_zero_copy, bool,0644 ); -MODULE_PARM_DESC (sign_zero_copy,"Don't copy pages on write with signing " - "enabled. Default: N");extern
mempool_t*cifs_sm_req_poolp;
externmempool_t*cifs_req_poolp;
externmempool_t*cifs_mid_poolp;fs/cifs/cifsglob.h +0
-0@@ -858,7 +858,6 @@ GLOBAL_EXTERN unsigned int CIFSMaxBufSize; /* max size not including hdr */GLOBAL_EXTERN unsigned int
cifs_min_rcv; /* min size of big ntwrk buf pool */GLOBAL_EXTERNunsigned intcifs_min_small; /* min size of small buf pool */GLOBAL_EXTERNunsigned intcifs_max_pending; /* MAX requests at once to server*/ -GLOBAL_EXTERN boolsign_zero_copy; /* don't copy written pages with signing *//* reconnect after this many failed echo attempts */
GLOBAL_EXTERNunsigned shortecho_retries;fs/cifs/file.c +3
-0@@ -881,6 +881,9 @@ static ssize_t cifs_write(struct cifsFileInfo *open_file, total_written += bytes_written) { rc = -EAGAIN; while (rc == -EAGAIN) { + struct kvec iov[2]; + unsigned int len; + if (open_file->invalidHandle) { /* we could deadlock if we called
filemap_fdatawaitfrom here so tellfs/cifs/file.c +26
-31@@ -890,31 +893,14 @@ static ssize_t cifs_write(struct cifsFileInfo *open_file, if (rc != 0) break; } - if (sign_zero_copy || (pTcon->ses->server && - ((pTcon->ses->server->sec_mode & - (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) - == 0))) { - struct kvec iov[2]; - unsigned int len; - - len = min((size_t)cifs_sb->wsize, - write_size - total_written); - /* iov[0] is reserved for smb header */ - iov[1].iov_base = (char *)write_data + - total_written; - iov[1].iov_len = len; - rc = CIFSSMBWrite2(xid, pTcon, - open_file->netfid, len, - *poffset, &bytes_written, - iov, 1, 0); - } else - rc = CIFSSMBWrite(xid, pTcon, - open_file->netfid, - min_t(const int, cifs_sb->wsize, - write_size - total_written), - *poffset, &bytes_written, - write_data + total_written, - NULL, 0); + + len = min((size_t)cifs_sb->wsize, + write_size - total_written); + /* iov[0] is reserved for smb header */ + iov[1].iov_base = (char *)write_data + total_written; + iov[1].iov_len = len; + rc = CIFSSMBWrite2(xid, pTcon, open_file->netfid, len, + *poffset, &bytes_written, iov, 1, 0); } if (rc || (bytes_written == 0)) { if (total_written)@@ -1151,12 +1137,6 @@ static int cifs_writepages(struct address_space *mapping, } tcon = tlink_tcon(open_file->tlink); - if (!sign_zero_copy && tcon->ses->server->sec_mode & - (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) { - cifsFileInfo_put(open_file); - kfree(iov); - return generic_writepages(mapping, wbc); - } cifsFileInfo_put(open_file); xid = GetXid();@@ -1909,6 +1889,24 @@ static ssize_t cifs_read(struct file *file, char *read_data, size_t read_size, return total_read; } +/* +* If the page is mmap'ed into a process' page tables, then we need to make +* sure that it doesn't change while being written back. +*/ +static int +cifs_page_mkwrite (struct vm_area_struct *vma,struct vm_fault *vmf) +{ + struct page *page = vmf->page; + + lock_page(page); + return VM_FAULT_LOCKED; +} + +static struct vm_operations_struct cifs_file_vm_ops = { + .fault = filemap_fault, + .page_mkwrite = cifs_page_mkwrite, +}; + int cifs_file_strict_mmap(struct file *file, struct vm_area_struct *vma) { int rc, xid;
fs/cifs/file.c int cifs_file_strict_mmap(struct file *file, struct vm_area_struct *vma) · line 1921
Quoted 4 lines
fs/cifs/file.c +1
-0@@ -1920,6 +1918,7 @@ int cifs_file_strict_mmap(struct file *file, struct vm_area_struct *vma) cifs_invalidate_mapping(inode); rc = generic_file_mmap(file, vma); + vma->vm_ops = &cifs_file_vm_ops;
May be we should set this only if generic_file_mmap succeed and rc == 0?
Quoted 19 lines
fs/cifs/file.c +1
-1FreeXid(xid); return rc; }@@ -1936,6 +1935,7 @@ int cifs_file_mmap(struct file *file, struct vm_area_struct *vma) return rc; } rc = generic_file_mmap(file, vma); + vma->vm_ops = &cifs_file_vm_ops; FreeXid(xid); return rc; } --1.7.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
Signature · 2 lines
Best regards, Pavel Shilovsky.
Re: [PATCH 3/3] cifs: don't allow mmap'ed pages to be dirtied while under writeback
In reply to a message not in the archiveQuoted 11 lines · On Sun, 27 Mar 2011 23:13:45 +0400 Pavel Shilovsky…
fs/cifs/file.c int cifs_file_strict_mmap(struct file *file, struct vm_area_struct *vma) · line 1921
Quoted 8 lines
int
cifs_file_strict_mmap(struct file *file, struct vm_area_struct *vma){
int rc, xid;fs/cifs/file.c +1
-0@@ -1920,6 +1918,7 @@ int cifs_file_strict_mmap(struct file *file, struct vm_area_struct *vma) cifs_invalidate_mapping(inode); rc = generic_file_mmap(file, vma); + vma->vm_ops = &cifs_file_vm_ops;May be we should set this only if
generic_file_mmapsucceed and rc == 0?
I don't think it really matters but you're probably right that it won't hurt to do so. All of the existing callers of generic_file_mmap that set the vm_ops don't do it unless generic_file_mmap succeeds. I'll respin it...
Signature · 1 line
Jeff Layton <[email protected]>
PATCH 1/1 cifs: don't allow mmap'ed pages to be dirtied while under writeback (try #2)
In reply to a message not in the archiveIf a process has a dirty page mapped into its page tables, then it has the ability to change it while the client is trying to write the data out to the server. If that happens after the signature has been calculated then that signature will then be wrong, and the server will likely reset the TCP connection.
This patch adds a page_mkwrite handler for CIFS that simply takes the page lock. Because the page lock is held over the life of writepage and writepages, this prevents the page from becoming writeable until the write call has completed.
With this, we can also remove the "sign_zero_copy" module option and always inline the pages when writing.
--- fs/cifs/cifsfs.c | 4 --- fs/cifs/cifsglob.h | 1 - fs/cifs/file.c | 64 ++++++++++++++++++++++++++------------------------- 3 files changed, 33 insertions(+), 36 deletions(-)
fs/cifs/cifsfs.c +0 -4
@@ -81,10 +81,6 @@ module_param(echo_retries, ushort, 0644);MODULE_PARM_DESC (echo_retries,"Number of echo attempts before giving up and " "reconnecting server. Default: 5. 0 means " "never reconnect." ); -bool sign_zero_copy;/* globals init to false automatically */ -module_param (sign_zero_copy, bool,0644 ); -MODULE_PARM_DESC (sign_zero_copy,"Don't copy pages on write with signing " -"enabled. Default: N" );extern mempool_t *cifs_sm_req_poolp;extern mempool_t *cifs_req_poolp;extern mempool_t *cifs_mid_poolp;
fs/cifs/cifsglob.h +0 -1
@@ -907,7 +907,6 @@ GLOBAL_EXTERN unsigned int CIFSMaxBufSize; /* max size not including hdr */ GLOBAL_EXTERN unsigned int cifs_min_rcv; /* min size of big ntwrk buf pool */ GLOBAL_EXTERN unsigned int cifs_min_small; /* min size of small buf pool */ GLOBAL_EXTERN unsigned int cifs_max_pending; /* MAX requests at once to server*/ -GLOBAL_EXTERN bool sign_zero_copy; /* don't copy written pages with signing *//* reconnect after this many failed echo attempts */ GLOBAL_EXTERN unsigned short echo_retries;
fs/cifs/file.c +33 -31
100 lines not on this page · raw message
Signature · 1 line
1.7.4
Re: [PATCH] cifs: don't allow mmap'ed pages to be dirtied while under writeback (try #2)
In reply to a message not in the archiveQuoted 150 lines · On Mon, 28 Mar 2011 16:09:09 -0400 Jeff Layton…
If a process has a dirty page mapped into its page tables, then it has the ability to change it while the client is trying to write the data out to the server. If that happens after the signature has been calculated then that signature will then be wrong, and the server will likely reset the TCP connection.
This patch adds a
page_mkwritehandler for CIFS that simply takes the page lock. Because the page lock is held over the life of writepage and writepages, this prevents the page from becoming writeable until the write call has completed.With this, we can also remove the "
sign_zero_copy" module option and always inline the pages when writing.Signed-off-by Jeff Layton <[email protected]>--- fs/cifs/cifsfs.c | 4 --- fs/cifs/cifsglob.h | 1 - fs/cifs/file.c | 64 ++++++++++++++++++++++++++------------------------- 3 files changed, 33 insertions(+), 36 deletions(-)fs/cifs/cifsfs.c +0
-4@@ -81,10 +81,6 @@ module_param(echo_retries, ushort, 0644);MODULE_PARM_DESC (echo_retries,"Number of echo attempts before giving up and " "reconnecting server. Default: 5. 0 means " "never reconnect." ); -bool sign_zero_copy;/* globals init to false automatically */ -module_param (sign_zero_copy, bool,0644 ); -MODULE_PARM_DESC (sign_zero_copy,"Don't copy pages on write with signing " -"enabled. Default: N" );extern mempool_t *cifs_sm_req_poolp;extern mempool_t *cifs_req_poolp;extern mempool_t *cifs_mid_poolp;fs/cifs/cifsglob.h +0
-1@@ -907,7 +907,6 @@ GLOBAL_EXTERN unsigned int CIFSMaxBufSize; /* max size not including hdr */ GLOBAL_EXTERN unsigned int cifs_min_rcv; /* min size of big ntwrk buf pool */ GLOBAL_EXTERN unsigned int cifs_min_small; /* min size of small buf pool */ GLOBAL_EXTERN unsigned int cifs_max_pending; /* MAX requests at once to server*/ -GLOBAL_EXTERN bool sign_zero_copy; /* don't copy written pages with signing *//* reconnect after this many failed echo attempts */ GLOBAL_EXTERN unsigned short echo_retries;fs/cifs/file.c +31
-31@@ -881,6 +881,9 @@ static ssize_t cifs_write(struct cifsFileInfo *open_file, total_written += bytes_written) { rc = -EAGAIN ;while (rc == -EAGAIN ) { +struct kvec iov[2 ]; +unsigned int len; +if (open_file->invalidHandle) {/* we could deadlock if we called filemap_fdatawait from here so tell @@ -890,31 +893,14 @@ static ssize_t cifs_write(struct cifsFileInfo *open_file,if (rc !=0 )break ; } -if (sign_zero_copy || (pTcon->ses->server && - ((pTcon->ses->server->sec_mode & - (SECMODE_SIGN_REQUIRED |SECMODE_SIGN_ENABLED )) - ==0 ))) { -struct kvec iov[2 ]; -unsigned int len; - - len =min ((size_t )cifs_sb->wsize, - write_size - total_written); -/* iov[0] is reserved for smb header */ - iov[1 ].iov_base = (char *)write_data + - total_written; - iov[1 ].iov_len = len; - rc =CIFSSMBWrite2 (xid, pTcon, - open_file->netfid, len, - *poffset, &bytes_written, - iov,1 ,0 ); - }else - rc =CIFSSMBWrite (xid, pTcon, - open_file->netfid, - min_t(const int, cifs_sb->wsize, - write_size - total_written), - *poffset, &bytes_written, - write_data + total_written, -NULL ,0 ); + + len =min ((size_t )cifs_sb->wsize, + write_size - total_written); +/* iov[0] is reserved for smb header */ + iov[1 ].iov_base = (char *)write_data + total_written; + iov[1 ].iov_len = len; + rc =CIFSSMBWrite2 (xid, pTcon, open_file->netfid, len, + *poffset, &bytes_written, iov,1 ,0 ); }if (rc || (bytes_written ==0 )) {if (total_written)@@ -1151,12 +1137,6 @@ static int cifs_writepages(struct address_space *mapping, } tcon =tlink_tcon (open_file->tlink); -if (!sign_zero_copy && tcon->ses->server->sec_mode & - (SECMODE_SIGN_REQUIRED |SECMODE_SIGN_ENABLED )) { -cifsFileInfo_put (open_file); -kfree (iov); -return generic_writepages (mapping, wbc); - }cifsFileInfo_put (open_file); xid =GetXid ();@@ -1909,6 +1889,24 @@ static ssize_t cifs_read(struct file *file, char *read_data, size_t read_size,return total_read; } +/* +* If the page is mmap'ed into a process' page tables, then we need to make +* sure that it doesn't change while being written back. +*/ +static int +cifs_page_mkwrite (struct vm_area_struct *vma,struct vm_fault *vmf) +{ +struct page *page = vmf->page; + +lock_page (page); +return VM_FAULT_LOCKED ; +} + +static struct vm_operations_struct cifs_file_vm_ops = { + .fault = filemap_fault, + .page_mkwrite = cifs_page_mkwrite, +}; +int cifs_file_strict_mmap (struct file *file,struct vm_area_struct *vma) {int rc, xid;@@ -1920,6 +1918,8 @@ int cifs_file_strict_mmap(struct file *file, struct vm_area_struct *vma)cifs_invalidate_mapping (inode); rc =generic_file_mmap (file, vma); +if (rc ==0 ) + vma->vm_ops = &cifs_file_vm_ops;FreeXid (xid);return rc; }
fs/cifs/file.c int cifs_file_mmap(struct file *file, struct vm_area_struct *vma) · line 1943
Quoted 8 lines
fs/cifs/file.c +2
-0@@ -1936,6 +1936,8 @@ int cifs_file_mmap(struct file *file, struct vm_area_struct *vma)return rc; } rc =generic_file_mmap (file, vma); +if (rc ==0 ) + vma->vm_ops = &cifs_file_vm_ops;FreeXid (xid);return rc; }
Sorry that I didn't make it clear in the patch description. The only difference between this patch and the previous one is the check for rc == 0 before setting the vm_ops.
Signature · 1 line
Jeff Layton <[email protected]>
Re: [PATCH] cifs: don't allow mmap'ed pages to be dirtied while under writeback (try #2)
In reply to a message not in the archiveReviewed and merged into cifs-2.6.git
This looks like nice work.
Quoted 162 lines · Jeff Layton
If a process has a dirty page mapped into its page tables, then it has the ability to change it while the client is trying to write the data out to the server. If that happens after the signature has been calculated then that signature will then be wrong, and the server will likely reset the TCP connection.
This patch adds a
page_mkwritehandler for CIFS that simply takes the page lock. Because the page lock is held over the life of writepage and writepages, this prevents the page from becoming writeable until the write call has completed.With this, we can also remove the "
sign_zero_copy" module option and always inline the pages when writing.Signed-off-by Jeff Layton <[email protected]>---
fs/cifs/cifsfs.c | 4 ---
fs/cifs/cifsglob.h | 1 -
fs/cifs/file.c | 64 ++++++++++++++++++++++++++-------------------------3 files changed, 33 insertions(+), 36 deletions(-)fs/cifs/cifsfs.c +0
-0@@ -81,10 +81,6 @@ module_param(echo_retries, ushort, 0644);MODULE_PARM_DESC(echo_retries, "Number of echo attempts before giving up and " "reconnecting server. Default: 5. 0 means " "never reconnect.");
fs/cifs/cifsfs.c +0
-4-bool sign_zero_copy; /* globals init to false automatically */ -module_param (sign_zero_copy, bool,0644 ); -MODULE_PARM_DESC (sign_zero_copy,"Don't copy pages on write with signing " - "enabled. Default: N");extern
mempool_t*cifs_sm_req_poolp;
externmempool_t*cifs_req_poolp;
externmempool_t*cifs_mid_poolp;fs/cifs/cifsglob.h +0
-0@@ -907,7 +907,6 @@ GLOBAL_EXTERN unsigned int CIFSMaxBufSize; /* max size not including hdr */GLOBAL_EXTERN unsigned int
cifs_min_rcv; /* min size of big ntwrk buf pool */GLOBAL_EXTERNunsigned intcifs_min_small; /* min size of small buf pool */GLOBAL_EXTERNunsigned intcifs_max_pending; /* MAX requests at once to server*/ -GLOBAL_EXTERN boolsign_zero_copy; /* don't copy written pages with signing *//* reconnect after this many failed echo attempts */
GLOBAL_EXTERNunsigned shortecho_retries;fs/cifs/file.c +3
-0@@ -881,6 +881,9 @@ static ssize_t cifs_write(struct cifsFileInfo *open_file, total_written += bytes_written) { rc = -EAGAIN; while (rc == -EAGAIN) { + struct kvec iov[2]; + unsigned int len; + if (open_file->invalidHandle) { /* we could deadlock if we called
filemap_fdatawaitfrom here so tellfs/cifs/file.c +30
-32@@ -890,31 +893,14 @@ static ssize_t cifs_write(struct cifsFileInfo *open_file, if (rc != 0) break; } - if (sign_zero_copy || (pTcon->ses->server && - ((pTcon->ses->server->sec_mode & - (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) - == 0))) { - struct kvec iov[2]; - unsigned int len; - - len = min((size_t)cifs_sb->wsize, - write_size - total_written); - /* iov[0] is reserved for smb header */ - iov[1].iov_base = (char *)write_data + - total_written; - iov[1].iov_len = len; - rc = CIFSSMBWrite2(xid, pTcon, - open_file->netfid, len, - *poffset, &bytes_written, - iov, 1, 0); - } else - rc = CIFSSMBWrite(xid, pTcon, - open_file->netfid, - min_t(const int, cifs_sb->wsize, - write_size - total_written), - *poffset, &bytes_written, - write_data + total_written, - NULL, 0); + + len = min((size_t)cifs_sb->wsize, + write_size - total_written); + /* iov[0] is reserved for smb header */ + iov[1].iov_base = (char *)write_data + total_written; + iov[1].iov_len = len; + rc = CIFSSMBWrite2(xid, pTcon, open_file->netfid, len, + *poffset, &bytes_written, iov, 1, 0); } if (rc || (bytes_written == 0)) { if (total_written)@@ -1151,12 +1137,6 @@ static int cifs_writepages(struct address_space *mapping, } tcon = tlink_tcon(open_file->tlink); - if (!sign_zero_copy && tcon->ses->server->sec_mode & - (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) { - cifsFileInfo_put(open_file); - kfree(iov); - return generic_writepages(mapping, wbc); - } cifsFileInfo_put(open_file); xid = GetXid();@@ -1909,6 +1889,24 @@ static ssize_t cifs_read(struct file *file, char *read_data, size_t read_size, return total_read; } +/* +* If the page is mmap'ed into a process' page tables, then we need to make +* sure that it doesn't change while being written back. +*/ +static int +cifs_page_mkwrite (struct vm_area_struct *vma,struct vm_fault *vmf) +{ + struct page *page = vmf->page; + + lock_page(page); + return VM_FAULT_LOCKED; +} + +static struct vm_operations_struct cifs_file_vm_ops = { + .fault = filemap_fault, + .page_mkwrite = cifs_page_mkwrite, +}; + int cifs_file_strict_mmap(struct file *file, struct vm_area_struct *vma) { int rc, xid;@@ -1920,6 +1918,8 @@ int cifs_file_strict_mmap(struct file *file, struct vm_area_struct *vma) cifs_invalidate_mapping(inode); rc = generic_file_mmap(file, vma); + if (rc == 0) + vma->vm_ops = &cifs_file_vm_ops; FreeXid(xid); return rc; }@@ -1936,6 +1936,8 @@ int cifs_file_mmap(struct file *file, struct vm_area_struct *vma) return rc; } rc = generic_file_mmap(file, vma); + if (rc == 0) + vma->vm_ops = &cifs_file_vm_ops; FreeXid(xid); return rc; } --1.7.4
Signature · 3 lines
Thanks, Steve