Skip to contentSkip to conversation

NFS: Don't hold the group lock when calling nfs_release_request()

PATCH New Trond Myklebust 1 participant 2 messages Sep 10, 2017

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

PATCH 1/2 NFS: Don't hold the group lock when calling nfs_release_request()

That can deadlock if this is the last reference since nfs_page_group_destroy() calls nfs_page_group_sync_on_bit(). Note that even if the page was removed from the subpage list, the req->wb_head could still be pointing to the old head.

---
 fs/nfs/write.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfs/write.c +1 -1
index 121218d4e5ed..36d34a4c86bd 100644
@@ -532,9 +532,9 @@ nfs_lock_and_join_requests(struct page *page)
 		} else if (WARN_ON_ONCE(subreq->wb_offset < head->wb_offset ||
 			    ((subreq->wb_offset + subreq->wb_bytes) >
 			     (head->wb_offset + total_bytes)))) {
+			nfs_page_group_unlock(head);
 			nfs_unroll_locks(inode, head, subreq);
 			nfs_unlock_and_release_request(subreq);
-			nfs_page_group_unlock(head);
 			nfs_unlock_and_release_request(head);
 			return ERR_PTR(-EIO);
 		}
Signature · 1 line
2.13.5
#1 lore raw

PATCH 2/2 NFS: Count the bytes of skipped subrequests in nfs_lock_and_join_requests()

If we skip a subrequest due to a zero refcount, we should still count the byte range that it covered so that we accurately reconstruct the original request size.

---
 fs/nfs/write.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
fs/nfs/write.c +5 -1
index 36d34a4c86bd..f68083db63c8 100644
@@ -504,8 +504,12 @@ nfs_lock_and_join_requests(struct page *page)
 	for (subreq = head->wb_this_page; subreq != head;
 			subreq = subreq->wb_this_page) {
 
-		if (!kref_get_unless_zero(&subreq->wb_kref))
+		if (!kref_get_unless_zero(&subreq->wb_kref)) {
+			if (subreq->wb_offset == head->wb_offset + total_bytes)
+				total_bytes += subreq->wb_bytes;
 			continue;
+		}
+
 		while (!nfs_lock_request(subreq)) {
 			/*
 			 * Unlock page to allow nfs_page_group_sync_on_bit()
Signature · 1 line
2.13.5