From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 52EE5C48BCF for ; Wed, 9 Jun 2021 03:33:06 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id ED8CA613BC for ; Wed, 9 Jun 2021 03:33:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org ED8CA613BC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 0E5F06B0036; Tue, 8 Jun 2021 23:33:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 096896B006E; Tue, 8 Jun 2021 23:33:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E5D7A6B0070; Tue, 8 Jun 2021 23:33:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0063.hostedemail.com [216.40.44.63]) by kanga.kvack.org (Postfix) with ESMTP id AFCC36B0036 for ; Tue, 8 Jun 2021 23:33:04 -0400 (EDT) Received: from smtpin34.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 49F672816 for ; Wed, 9 Jun 2021 03:33:04 +0000 (UTC) X-FDA: 78232764288.34.FD2BA5B Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf02.hostedemail.com (Postfix) with ESMTP id F416841AD7B6 for ; Wed, 9 Jun 2021 03:33:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623209583; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=umLfKhpHP+RuI0WJ/3k+B1+HOsxB0tKVXkMkbJg5ENY=; b=DpILld8NKvQC+qGUCctqtqXyj/77L3ys8MOQhePWWFw3wFdQtvORWKPcwhe5cD4K4KKUMN G98vURzqFsHLVOcjrhGV6g0sgJoYF3hQSuV9lFLslpaWDQtsliQesGcNIeK2qw3OJly3z8 wVYpV7nv3u9tkYP8afOvdhscr08NDbY= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-262-ygZ5VinmNvipqjSqZSKDzQ-1; Tue, 08 Jun 2021 23:33:00 -0400 X-MC-Unique: ygZ5VinmNvipqjSqZSKDzQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 943FA107ACCA; Wed, 9 Jun 2021 03:32:58 +0000 (UTC) Received: from T590 (ovpn-12-143.pek2.redhat.com [10.72.12.143]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0C77F5C1BB; Wed, 9 Jun 2021 03:32:48 +0000 (UTC) Date: Wed, 9 Jun 2021 11:32:44 +0800 From: Ming Lei To: Roman Gushchin Cc: Andrew Morton , Tejun Heo , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Viro , Jan Kara , Dennis Zhou , Dave Chinner , cgroups@vger.kernel.org, Jan Kara Subject: Re: [PATCH v9 3/8] writeback, cgroup: increment isw_nr_in_flight before grabbing an inode Message-ID: References: <20210608230225.2078447-1-guro@fb.com> <20210608230225.2078447-4-guro@fb.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210608230225.2078447-4-guro@fb.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=DpILld8N; spf=none (imf02.hostedemail.com: domain of ming.lei@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: F416841AD7B6 X-Stat-Signature: 5p7nfs63pz41cd9gpnnqizajpktjj3cz X-HE-Tag: 1623209581-640673 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue, Jun 08, 2021 at 04:02:20PM -0700, Roman Gushchin wrote: > isw_nr_in_flight is used do determine whether the inode switch queue > should be flushed from the umount path. Currently it's increased > after grabbing an inode and even scheduling the switch work. It means > the umount path can be walked past cleanup_offline_cgwb() with active > inode references, which can result in a "Busy inodes after unmount." > message and use-after-free issues (with inode->i_sb which gets freed). > > Fix it by incrementing isw_nr_in_flight before doing anything with > the inode and decrementing in the case when switching wasn't scheduled. > > The problem hasn't yet been seen in the real life and was discovered > by Jan Kara by looking into the code. > > Suggested-by: Jan Kara > Signed-off-by: Roman Gushchin > Reviewed-by: Jan Kara > --- > fs/fs-writeback.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c > index b6fc13a4962d..4413e005c28c 100644 > --- a/fs/fs-writeback.c > +++ b/fs/fs-writeback.c > @@ -505,6 +505,8 @@ static void inode_switch_wbs(struct inode *inode, int new_wb_id) > if (!isw) > return; > > + atomic_inc(&isw_nr_in_flight); smp_mb() may be required for ordering the WRITE in 'atomic_inc(&isw_nr_in_flight)' and the following READ on 'inode->i_sb->s_flags & SB_ACTIVE'. Otherwise, cgroup_writeback_umount() may observe zero of 'isw_nr_in_flight' because of re-order of the two OPs, then miss the flush_workqueue(). Also this barrier should serve as pair of the one added in cgroup_writeback_umount(), so maybe this patch should be merged with 2/8. Thanks, Ming