summaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorJiufei Xue <jiufei.xue@linux.alibaba.com>2019-05-17 17:31:44 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2019-05-18 18:52:26 -0400
commitec084de929e419e51bcdafaafe567d9e7d0273b7 (patch)
tree8c9694cdd7e5e90ec859d746a42a43ca7d142d0d /fs
parent60fce36afa9c77c7ccbf980c4f670f3be3651fce (diff)
fs/writeback.c: use rcu_barrier() to wait for inflight wb switches going into workqueue when umount
synchronize_rcu() didn't wait for call_rcu() callbacks, so inode wb switch may not go to the workqueue after synchronize_rcu(). Thus previous scheduled switches was not finished even flushing the workqueue, which will cause a NULL pointer dereferenced followed below. VFS: Busy inodes after unmount of vdd. Self-destruct in 5 seconds. Have a nice day... BUG: unable to handle kernel NULL pointer dereference at 0000000000000278 evict+0xb3/0x180 iput+0x1b0/0x230 inode_switch_wbs_work_fn+0x3c0/0x6a0 worker_thread+0x4e/0x490 ? process_one_work+0x410/0x410 kthread+0xe6/0x100 ret_from_fork+0x39/0x50 Replace the synchronize_rcu() call with a rcu_barrier() to wait for all pending callbacks to finish. And inc isw_nr_in_flight after call_rcu() in inode_switch_wbs() to make more sense. Link: http://lkml.kernel.org/r/20190429024108.54150-1-jiufei.xue@linux.alibaba.com Signed-off-by: Jiufei Xue <jiufei.xue@linux.alibaba.com> Acked-by: Tejun Heo <tj@kernel.org> Suggested-by: Tejun Heo <tj@kernel.org> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs')
-rw-r--r--fs/fs-writeback.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c
index 36855c1f8daf..b16645b417d9 100644
--- a/fs/fs-writeback.c
+++ b/fs/fs-writeback.c
@@ -523,8 +523,6 @@ static void inode_switch_wbs(struct inode *inode, int new_wb_id)
523 523
524 isw->inode = inode; 524 isw->inode = inode;
525 525
526 atomic_inc(&isw_nr_in_flight);
527
528 /* 526 /*
529 * In addition to synchronizing among switchers, I_WB_SWITCH tells 527 * In addition to synchronizing among switchers, I_WB_SWITCH tells
530 * the RCU protected stat update paths to grab the i_page 528 * the RCU protected stat update paths to grab the i_page
@@ -532,6 +530,9 @@ static void inode_switch_wbs(struct inode *inode, int new_wb_id)
532 * Let's continue after I_WB_SWITCH is guaranteed to be visible. 530 * Let's continue after I_WB_SWITCH is guaranteed to be visible.
533 */ 531 */
534 call_rcu(&isw->rcu_head, inode_switch_wbs_rcu_fn); 532 call_rcu(&isw->rcu_head, inode_switch_wbs_rcu_fn);
533
534 atomic_inc(&isw_nr_in_flight);
535
535 goto out_unlock; 536 goto out_unlock;
536 537
537out_free: 538out_free:
@@ -901,7 +902,11 @@ restart:
901void cgroup_writeback_umount(void) 902void cgroup_writeback_umount(void)
902{ 903{
903 if (atomic_read(&isw_nr_in_flight)) { 904 if (atomic_read(&isw_nr_in_flight)) {
904 synchronize_rcu(); 905 /*
906 * Use rcu_barrier() to wait for all pending callbacks to
907 * ensure that all in-flight wb switches are in the workqueue.
908 */
909 rcu_barrier();
905 flush_workqueue(isw_wq); 910 flush_workqueue(isw_wq);
906 } 911 }
907} 912}