Blob Blame History Raw
From: ZhangXiaoxu <zhangxiaoxu5@huawei.com>
Date: Thu, 26 Sep 2019 14:29:38 +0800
Subject: [PATCH] nfs: Fix nfsi->nrequests count error on
 nfs_inode_remove_request
Git-commit: 33ea5aaa87cdae0f9af4d6b7ee4f650a1a36fd1d
Patch-mainline: v5.4
References: git-fixes

When xfstests testing, there are some WARNING as below:

Warning: CPU: 0 PID: 6235 at fs/nfs/inode.c:122 nfs_clear_inode+0x9c/0xd8
Modules linked in:
Cpu: 0 PID: 6235 Comm: umount.nfs
Hardware name: linux,dummy-virt (DT)
Pstate: 60000005 (nZCv daif -PAN -UAO)
pc : nfs_clear_inode+0x9c/0xd8
lr : nfs_evict_inode+0x60/0x78
sp : fffffc000f68fc00
X29: fffffc000f68fc00 x28: fffffe00c53155c0
X27: fffffe00c5315000 x26: fffffc0009a63748
X25: fffffc000f68fd18 x24: fffffc000bfaaf40
X23: fffffc000936d3c0 x22: fffffe00c4ff5e20
X21: fffffc000bfaaf40 x20: fffffe00c4ff5d10
X19: fffffc000c056000 x18: 000000000000003c
X17: 0000000000000000 x16: 0000000000000000
X15: 0000000000000040 x14: 0000000000000228
X13: fffffc000c3a2000 x12: 0000000000000045
X11: 0000000000000000 x10: 0000000000000000
x9 : 0000000000000000 x8 : 0000000000000000
x7 : 0000000000000000 x6 : fffffc00084b027c
x5 : fffffc0009a64000 x4 : fffffe00c0e77400
x3 : fffffc000c0563a8 x2 : fffffffffffffffb
x1 : 000000000000764e x0 : 0000000000000001
Call trace:
 nfs_clear_inode+0x9c/0xd8
 nfs_evict_inode+0x60/0x78
 evict+0x108/0x380
 dispose_list+0x70/0xa0
 evict_inodes+0x194/0x210
 generic_shutdown_super+0xb0/0x220
 nfs_kill_super+0x40/0x88
 deactivate_locked_super+0xb4/0x120
 deactivate_super+0x144/0x160
 cleanup_mnt+0x98/0x148
 __cleanup_mnt+0x38/0x50
 task_work_run+0x114/0x160
 do_notify_resume+0x2f8/0x308
 work_pending+0x8/0x14

The nrequest should be increased/decreased only if PG_INODE_REF flag
was setted.

But in the nfs_inode_remove_request function, it maybe decrease when
no PG_INODE_REF flag, this maybe lead nrequests count error.

Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: ZhangXiaoxu <zhangxiaoxu5@huawei.com>
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
Acked-by: NeilBrown <neilb@suse.com>

---
 fs/nfs/write.c |   10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

--- a/fs/nfs/write.c
+++ b/fs/nfs/write.c
@@ -820,16 +820,16 @@ static void nfs_inode_remove_request(str
 			ClearPagePrivate(head->wb_page);
 			clear_bit(PG_MAPPED, &head->wb_flags);
 		}
-		nfsi->nrequests--;
-		spin_unlock(&inode->i_lock);
 	} else {
 		spin_lock(&inode->i_lock);
-		nfsi->nrequests--;
-		spin_unlock(&inode->i_lock);
 	}
 
-	if (test_and_clear_bit(PG_INODE_REF, &req->wb_flags))
+	if (test_and_clear_bit(PG_INODE_REF, &req->wb_flags)) {
+		nfsi->nrequests--;
+		spin_unlock(&inode->i_lock);
 		nfs_release_request(req);
+	} else
+		spin_unlock(&inode->i_lock);
 }
 
 static void