Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp89750yba; Mon, 20 May 2019 05:31:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqwgHI53XjBngpXGiEqCMG6yRxdItqipYXogtgbPoYNGNEnXhVBIkbhG1G+YKirye0TsQ2lU X-Received: by 2002:a65:6497:: with SMTP id e23mr60958919pgv.388.1558355517492; Mon, 20 May 2019 05:31:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558355517; cv=none; d=google.com; s=arc-20160816; b=r8eQdVY61C7xUkeiwEqM3YWbBBBLjekjZFXmcdjrZR9G0SZTRr8XbaNFTxAFYCWqCe imL3Lxm1HdVlGuG3ox7yAD4JhSLczYORwz+2F98kUdnhP/8hQmMWE7LaXpezCnhgnm9V jhP+Y7sUskhpEIg1Y7WHcie05hUmaL9Fnbd1LgH3krjVnn5EdhQf0NsqXvuylCzm5EFD b3S05kfDevQDefpve5zZUlw17QEItqpxnw/ZlRXBO939LLg3bsP9kOXfBiThQpQalh34 fY/DP6N8Xn8N3/1KCC6poMo6yOdIcLOjs9qtA6QuiAwbdkIcivaOLxmpvmNtv4p5Obzs v91g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=+O7mioUlWYxwbOM+KmurVsYRFf576+31f6z26sPGVTg=; b=xEncFUqKJGLUi4aNc4mIr7/cFen2fNPG/QEhr+HGwTHFZoMu9L26uUQLKd0PBtFMoo z1LnfocRczvxnc2CJaFGKv7Noyh9wbMpIlny/4G6KMMglFsuF1UG8+ZQxSEG14MM0iXY 4bgssrTw8aTxH9MsTbu9iLpETs+z0khFPxG7hC3RY7rOTWOdL92ZVbbn+BGlgzuPvweC BllCJKhcwT1T3xzSXB73du24kHrdDYrlVkZL2+KhzMavyrcSEyP+TTsSf4sL+mLBpR/U uM3AR+2ls2R8+gEhikH4t3QLS5yCJWuC7/8Lv6poL4/2yE1qT7koeskTUlLC+Z0FeFWF xxbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vTI65A+C; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g1si4009391pgq.350.2019.05.20.05.31.42; Mon, 20 May 2019 05:31:57 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vTI65A+C; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390006AbfETM34 (ORCPT + 99 others); Mon, 20 May 2019 08:29:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:46062 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389975AbfETM3z (ORCPT ); Mon, 20 May 2019 08:29:55 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9679920645; Mon, 20 May 2019 12:29:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558355394; bh=onfGMYicXDP3MCBWfPIOJpbs01/cprEgL1AT+ll7nso=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vTI65A+CHpCnNq6O7dwPIFcsf0GrYQlyGCx62rIknslYdlSJBu2OhulVAZyOpJa+n zh/71XCFRpTZhpPaFrbOATkwGLauu2c39/NlHy5iuSv0wRw+r68xL7TO9HMy0ualZ+ nR4jmQDiefD9eEx+7Z75Ho41GxyJbLSoco1cYClw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jiufei Xue , Tejun Heo , Andrew Morton , Linus Torvalds Subject: [PATCH 5.0 100/123] fs/writeback.c: use rcu_barrier() to wait for inflight wb switches going into workqueue when umount Date: Mon, 20 May 2019 14:14:40 +0200 Message-Id: <20190520115251.686329530@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190520115245.439864225@linuxfoundation.org> References: <20190520115245.439864225@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jiufei Xue commit ec084de929e419e51bcdafaafe567d9e7d0273b7 upstream. 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 Acked-by: Tejun Heo Suggested-by: Tejun Heo Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- fs/fs-writeback.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) --- a/fs/fs-writeback.c +++ b/fs/fs-writeback.c @@ -523,8 +523,6 @@ static void inode_switch_wbs(struct inod isw->inode = inode; - atomic_inc(&isw_nr_in_flight); - /* * In addition to synchronizing among switchers, I_WB_SWITCH tells * the RCU protected stat update paths to grab the i_page @@ -532,6 +530,9 @@ static void inode_switch_wbs(struct inod * Let's continue after I_WB_SWITCH is guaranteed to be visible. */ call_rcu(&isw->rcu_head, inode_switch_wbs_rcu_fn); + + atomic_inc(&isw_nr_in_flight); + goto out_unlock; out_free: @@ -901,7 +902,11 @@ restart: void cgroup_writeback_umount(void) { if (atomic_read(&isw_nr_in_flight)) { - synchronize_rcu(); + /* + * Use rcu_barrier() to wait for all pending callbacks to + * ensure that all in-flight wb switches are in the workqueue. + */ + rcu_barrier(); flush_workqueue(isw_wq); } }