Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4496637pxj; Tue, 8 Jun 2021 16:07:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz+HxZz5zzHagHccTVExvnBLiSntf5ytVJYysE0Cicg+VQHzOnVHfqI72x/cCZ4CfxGl0E1 X-Received: by 2002:a17:906:2b04:: with SMTP id a4mr12215799ejg.6.1623193655382; Tue, 08 Jun 2021 16:07:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623193655; cv=none; d=google.com; s=arc-20160816; b=Z9c0wihn3u9hR1xP+y1KaKJbudZMsDv4/Y1QrnDWvBUQOe8dcqSbJVIb+9bjCZLOOW v2hE9RlFGqtowQm3S6a/VtGmizQLbc76PLO4F2Q1xYdmpvVzpQ07+wi+PypWT0BN93qc doVo7ja6Ri2HQesf/sGrxPzr7cqT6+jeNTbZMF1Sw6tlUbSNiLsiIj4OkJL55+qFFu00 8Cb7gP2Md5Nt2IHe3eMlg4Ui5aj+MWjqtPgjao+HTDKKZdNjBTrak3Sw0PptklA1rCCl 9JMtQwPyLvcjdzps4tIY76DRNIEflk5KzHQcgSurR3fOylM9EjBGi7FwMKNSaTNMjlij 4srA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=mfav6jzNKGWoxXgqLsimDL5+HxKJWmRmET2uHflSm9w=; b=m+PRkeQUGFkYvdAkB0o/Rr00Ty7KEl11C3BIr0av8Au8sK6NfFwlKHqwwXbwY99rDq 0QraYdeZjJ1R+YwJVgMOUwz1tFeN8/W6R4HVfBOPDgUUqAuj/SQJDWxp8mMXg1nu8o6U mrznifLpx+HqGp7vM1fUH4nsL4TB6Ps8tG8mPv4DehLp1KnvfLuaJn00FTehYX+3i+dB V1clb4QxbyGE2OwRSi5HegbJ2UnxVVruzq2/CqQTCSD4OhXpN8nhWfqysRpus4EKts+z 5Fkh/FaQClw3qZ4ScLEg/eBEhGGYLL2h/K5lgtT+LcJ+0i9Fy8XOPBMv3WEQT3DspSbo YMBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=OjqfaN2O; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=fb.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y15si844997eju.51.2021.06.08.16.07.11; Tue, 08 Jun 2021 16:07:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=OjqfaN2O; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=fb.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235152AbhFHXGr (ORCPT + 99 others); Tue, 8 Jun 2021 19:06:47 -0400 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:4582 "EHLO mx0b-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235121AbhFHXGq (ORCPT ); Tue, 8 Jun 2021 19:06:46 -0400 Received: from pps.filterd (m0109331.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 158Mvmt0015244 for ; Tue, 8 Jun 2021 16:04:53 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=facebook; bh=mfav6jzNKGWoxXgqLsimDL5+HxKJWmRmET2uHflSm9w=; b=OjqfaN2Os6DxSL7HmOn4jDtij1QwyZYPxFDhWgbljrVVB85ZPP7F2i1BRuaLZ7Rrp80u F9+mfkNCMARlB+MSC3rh4vz7UjDseYvOEtUZKn8LwPjakhCg/wlUY8oB9jdWmd3tnEb2 i0qc72fz4JnRtBJRCP8a4Pp2Nog77WtweDM= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com with ESMTP id 391rhyrkvd-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 08 Jun 2021 16:04:53 -0700 Received: from intmgw003.48.prn1.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:82::f) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Tue, 8 Jun 2021 16:04:51 -0700 Received: by devvm3388.prn0.facebook.com (Postfix, from userid 111017) id 3519582542C9; Tue, 8 Jun 2021 16:02:28 -0700 (PDT) From: Roman Gushchin To: Andrew Morton , Tejun Heo CC: , , , Alexander Viro , Jan Kara , Dennis Zhou , Dave Chinner , , Roman Gushchin Subject: [PATCH v9 2/8] writeback, cgroup: add smp_mb() to cgroup_writeback_umount() Date: Tue, 8 Jun 2021 16:02:19 -0700 Message-ID: <20210608230225.2078447-3-guro@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210608230225.2078447-1-guro@fb.com> References: <20210608230225.2078447-1-guro@fb.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-FB-Internal: Safe Content-Type: text/plain X-Proofpoint-GUID: VI-F90Boxhr1bWQRsSwYyoGho9mSYr1i X-Proofpoint-ORIG-GUID: VI-F90Boxhr1bWQRsSwYyoGho9mSYr1i X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.761 definitions=2021-06-08_17:2021-06-04,2021-06-08 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 mlxlogscore=726 priorityscore=1501 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 adultscore=0 phishscore=0 mlxscore=0 malwarescore=0 impostorscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2106080145 X-FB-Internal: deliver Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org A full memory barrier is required between clearing SB_ACTIVE flag in generic_shutdown_super() and checking isw_nr_in_flight in cgroup_writeback_umount(), otherwise a new switch operation might be scheduled after atomic_read(&isw_nr_in_flight) returned 0. This would result in a non-flushed isw_wq, and a potential crash. 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 | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c index 7d2891d7ac12..b6fc13a4962d 100644 --- a/fs/fs-writeback.c +++ b/fs/fs-writeback.c @@ -1000,6 +1000,12 @@ int cgroup_writeback_by_id(u64 bdi_id, int memcg_i= d, unsigned long nr, */ void cgroup_writeback_umount(void) { + /* + * SB_ACTIVE should be reliably cleared before checking + * isw_nr_in_flight, see generic_shutdown_super(). + */ + smp_mb(); + if (atomic_read(&isw_nr_in_flight)) { /* * Use rcu_barrier() to wait for all pending callbacks to --=20 2.31.1