Whamcloud - gitweb
LU-18743 llite: inode_to_wb() needs locking 61/58161/3
authorJames Simmons <jsimmons@infradead.org>
Sat, 22 Feb 2025 15:10:24 +0000 (10:10 -0500)
committerOleg Drokin <green@whamcloud.com>
Thu, 6 Mar 2025 08:05:12 +0000 (08:05 +0000)
When running a kernel with lockdep turned on testing shows the
following error:

WARNING: CPU: 1 PID: 37 at include/linux/backing-dev.h:291 ll_writepages+0x3dd/0x400 [lustre]
Workqueue: writeback wb_workfn (flush-lustre-ffff8f09f4)
RIP: 0010:ll_writepages+0x3dd/0x400 [lustre]
Call Trace: [ 1267.032775] ? show_regs.cold.9+0x22/0x2f
 ? __warn+0xc8/0x150 [ 1267.043623] ? ll_writepages+0x3dd/0x400 [lustre]

This due to inode_to_wb() being called without a lock. We can
pick from 3 types of locks but I went with the inode i_lock.

Change-Id: I7427041d6df102161c06cfbb05b7e26428675225
Signed-off-by: James Simmons <jsimmons@infradead.org>
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/58161
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Patrick Farrell <pfarrell@whamcloud.com>
Reviewed-by: Qian Yingjin <qian@ddn.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/llite/rw.c

index 0f1221d..fc528ad 100644 (file)
@@ -1609,11 +1609,13 @@ int ll_writepages(struct address_space *mapping, struct writeback_control *wbc)
                 * The system is under memory pressure and it is now reclaiming
                 * cache pages.
                 */
+               spin_lock(&inode->i_lock);
                wb = inode_to_wb(inode);
                if (wbc->for_background ||
                    (wb->start_all_reason == WB_REASON_VMSCAN &&
                     test_bit(WB_start_all, &wb->state)))
                        mode = CL_FSYNC_RECLAIM;
+               spin_unlock(&inode->i_lock);
 #else
                /*
                 * We have no idea about writeback reason for memory reclaim