Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp238305yba; Mon, 20 May 2019 07:57:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqwahsJfbpH8twjrg5pDwcSroi/NoObAa+5RxR+NisqPVxDLF0KB/HsuaVnQmRr3tpINZ9tg X-Received: by 2002:a05:6a00:43:: with SMTP id i3mr2468144pfk.113.1558364232756; Mon, 20 May 2019 07:57:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558364232; cv=none; d=google.com; s=arc-20160816; b=ZY27txULk4fnO8T82wnlylY5JTxglxPyJjMYSBJi7t9tKxDqlCiLPGU4KBOp1zIfLh cwLTIzrX/K2QB0pyx6P1lh50yfFMdLT8r31VObAHAPQrlo7PLRKdHlZY73mTU+WhPgJc 1rFv9osvdzNhQDdXOprRB8G3fVYc6uBaponTGyLJTOoUvH9DeWXOQwmCj/ac7UZ5kzP3 3sWxZctYQKxBDE2jdJ8uWJiayVWHGbtyhZ/omkKwbZLZIhs6gGLD7auvWZscP2WHtn7V HA6JCXBRXrDRB6YgXDh4xzqHWLFquQ7wwN0+gutrQDvTcjYA/8ewqYiyjW3YLCLbVZZM /KQQ== 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=cYG2F9BDQRcL+XOxsobzmurH+ETys7MQYMW2c1HV7r4=; b=S68pY+aybB8El88qS8J6+j1eIz499ZEkHwTkDcFSzIxkdANG5H2qlzzgoDIG64LWvF tVYDhVacU6rYAcbA/afYc9B7SfIJYEtY3qLHZxXn2OxxnDAuDvkY/2neomULN5yXedlv /bPSj7nA3wEO6KNwVZZDC9G0JC4dY9HYx+7gDiGcsKZzVMQclQCoS3dfoZV/SOjWxhRW jvd9n/iE/Io4A2oCRUUdQthpzDuBWLxkbtyzodfQmiTivoRCYHJqUp0KGcepaAp1WFeB y4Hsq1Fl9UUCi+CMKhMamvZqT72RBm28qAl9Uzo4R0LnXvBGq6mahXxOZBtg7SmxJdBJ 3IBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=C16rJGHB; 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 e37si19438018plb.10.2019.05.20.07.56.57; Mon, 20 May 2019 07:57:12 -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=C16rJGHB; 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 S2387614AbfETMRl (ORCPT + 99 others); Mon, 20 May 2019 08:17:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:58694 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733157AbfETMRj (ORCPT ); Mon, 20 May 2019 08:17:39 -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 01D3220656; Mon, 20 May 2019 12:17:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558354658; bh=QzXMABAp5useRBARdCL6vnv7ldSqL36jJR/3j27x2Ok=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=C16rJGHBeDCzCIuoFSSxkMmV8Z4POrB7gt3pGgrCI5rqjhz5+1zGG2jhkBX47x4lH ItzHlClDO4nfeE2AmvAAoE6GbaTTro5st3XbNQGfGd9ygUKFt2eFYsX5v+6Dc59Xo4 +QfnALuWnAigjv/c1HeJhCYExCP/dSrkWpsuDJxo= 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 4.9 40/44] fs/writeback.c: use rcu_barrier() to wait for inflight wb switches going into workqueue when umount Date: Mon, 20 May 2019 14:14:29 +0200 Message-Id: <20190520115235.677932792@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190520115230.720347034@linuxfoundation.org> References: <20190520115230.720347034@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 @@ -530,8 +530,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 mapping's @@ -539,6 +537,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: @@ -908,7 +909,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); } }