From: James Simmons Date: Sat, 22 Feb 2025 15:10:24 +0000 (-0500) Subject: LU-18743 llite: inode_to_wb() needs locking X-Git-Tag: 2.16.53~77 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=5fb5cccd934acba8fdeb0eeb75004fb727875240;p=fs%2Flustre-release.git LU-18743 llite: inode_to_wb() needs locking 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 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/58161 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Patrick Farrell Reviewed-by: Qian Yingjin Reviewed-by: Oleg Drokin --- diff --git a/lustre/llite/rw.c b/lustre/llite/rw.c index 0f1221d..fc528ad 100644 --- a/lustre/llite/rw.c +++ b/lustre/llite/rw.c @@ -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