NFS: Fix O_DIRECT locking issues
authorTrond Myklebust <trond.myklebust@hammerspace.com>
Mon, 4 Sep 2023 16:34:38 +0000 (12:34 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 6 Oct 2023 12:56:30 +0000 (14:56 +0200)
[ Upstream commit 7c6339322ce0c6128acbe36aacc1eeb986dd7bf1 ]

The dreq fields are protected by the dreq->lock.

Fixes: 954998b60caa ("NFS: Fix error handling for O_DIRECT write scheduling")
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/nfs/direct.c

index d71762f32b6c483ed142c53c0654276a1ffa15de..449d248fc1ec77d3980a2eb05395f1004cdd732e 100644 (file)
@@ -555,7 +555,7 @@ static void nfs_direct_write_reschedule(struct nfs_direct_req *dreq)
                /* Bump the transmission count */
                req->wb_nio++;
                if (!nfs_pageio_add_request(&desc, req)) {
-                       spin_lock(&cinfo.inode->i_lock);
+                       spin_lock(&dreq->lock);
                        if (dreq->error < 0) {
                                desc.pg_error = dreq->error;
                        } else if (desc.pg_error != -EAGAIN) {
@@ -565,7 +565,7 @@ static void nfs_direct_write_reschedule(struct nfs_direct_req *dreq)
                                dreq->error = desc.pg_error;
                        } else
                                dreq->flags = NFS_ODIRECT_RESCHED_WRITES;
-                       spin_unlock(&cinfo.inode->i_lock);
+                       spin_unlock(&dreq->lock);
                        break;
                }
                nfs_release_request(req);
@@ -875,9 +875,9 @@ static ssize_t nfs_direct_write_schedule_iovec(struct nfs_direct_req *dreq,
 
                        /* If the error is soft, defer remaining requests */
                        nfs_init_cinfo_from_dreq(&cinfo, dreq);
-                       spin_lock(&cinfo.inode->i_lock);
+                       spin_lock(&dreq->lock);
                        dreq->flags = NFS_ODIRECT_RESCHED_WRITES;
-                       spin_unlock(&cinfo.inode->i_lock);
+                       spin_unlock(&dreq->lock);
                        nfs_unlock_request(req);
                        nfs_mark_request_commit(req, NULL, &cinfo, 0);
                        desc.pg_error = 0;