Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3917911pxj; Tue, 8 Jun 2021 01:46:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyv765lZoQl60N/7u/G1NWm1TZ9bP0H+o9CIJ3nONGg/M/LLeNBmaDC92q9B0gfzfrU7qK/ X-Received: by 2002:a50:cc0b:: with SMTP id m11mr23959691edi.297.1623141968671; Tue, 08 Jun 2021 01:46:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623141968; cv=none; d=google.com; s=arc-20160816; b=zw4o5Xo6wL5lCItQEDaz6eymBRLnIvXX90VpTIXEHYWJOfb8zkUxflBYx6Ii7p+TSi X7T9OXOZkqbwn6xyfs68xP3Kw70s6Rf+uk/J/o0tc3DCiGS1vMpvy4353K3+A5FkyFTj UNjNkDY1ZMLBiBZaaHJVgk5ySGFPMzJMc41ofTH5KlkNEjwSbOlnrZEUxGo9/NqUW/L1 D9tnDe5mK8JuKslkkohzkUJCfmNzUwggeCgXYvitZxTgyXHJtxncN9x7xik/Mupdwn5+ PyYvOit+CeGE7EhuBKfNCutwfxHRr8oinOlixWcaTZXYo8VJtjLSz1JK/327icF+q56P qtJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature:dkim-signature; bh=iISBLZW6vnOrxf1PW5nBJaiWFRRWjobdH4Xa3xTC/lU=; b=UXzAVGr4cRKoNJehS0XDIvYLMDcl5z8CgINcMcCOLpdODOzwfmfmQWxS4lhrbrJIKo R8/v0aUCsRQlL9iEdGsZdYwkJzkKomMDwH/8buqQUs80uQUloOKkaSMdeGL4sGVm7Td8 Myi1f4T/r+zCFTIm2AN/eU7RZUKORPr4m+Qg8BUvGp/7hFSSnoYuaitxsx41Dc6MiRdv Jhgr7jzZ+JjqQ3XKsBCpoccrE+dT95K/NrAo+NlxvF1n745BH246S7M3zI9RIFd0pUB8 cGHvx3W6Hp8WFQVmeG4tFp4xYEt4pnskHG/tcZTaj4eLwPNOfw3nZcwcxWTFMcA0/9fS PdaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=njPEmPPp; dkim=neutral (no key) header.i=@suse.cz header.b=WZxVu+kn; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a92si16579547edf.232.2021.06.08.01.45.45; Tue, 08 Jun 2021 01:46:08 -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=@suse.cz header.s=susede2_rsa header.b=njPEmPPp; dkim=neutral (no key) header.i=@suse.cz header.b=WZxVu+kn; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231205AbhFHIpm (ORCPT + 99 others); Tue, 8 Jun 2021 04:45:42 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:50342 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230280AbhFHIpm (ORCPT ); Tue, 8 Jun 2021 04:45:42 -0400 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id DCEF11FD2A; Tue, 8 Jun 2021 08:43:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1623141828; h=from:from:reply-to: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=iISBLZW6vnOrxf1PW5nBJaiWFRRWjobdH4Xa3xTC/lU=; b=njPEmPPpqnXg+tK+t2CDK3LGjIjtcmBh4GjeomQYXxUy4wdWJIv5Qfh3tYvVx3Ji5/9kO1 QyjjZEfBuDOcJoAU1stmecuDDIuh4TJjuDElafj2O8/cIeoJSYIjozJzVJ9hj7ekFDz1VO EJ39+iqOxFuiRomisRKW5s6b6jEbKjY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1623141828; h=from:from:reply-to: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=iISBLZW6vnOrxf1PW5nBJaiWFRRWjobdH4Xa3xTC/lU=; b=WZxVu+knMuzzI4pcbDtECurFxUjtzwLXtn+LHGOZ/eE7TJvRoflemPzoPTgweVLDUQPNMX Inv4z139hONYZOCQ== Received: from quack2.suse.cz (unknown [10.100.200.198]) by relay2.suse.de (Postfix) with ESMTP id BC035A3B87; Tue, 8 Jun 2021 08:43:48 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 83E781F2C94; Tue, 8 Jun 2021 10:43:48 +0200 (CEST) Date: Tue, 8 Jun 2021 10:43:48 +0200 From: Jan Kara To: Roman Gushchin Cc: Jan Kara , Tejun Heo , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Viro , Dennis Zhou , Dave Chinner , cgroups@vger.kernel.org Subject: Re: [PATCH v8 2/8] writeback, cgroup: add smp_mb() to cgroup_writeback_umount() Message-ID: <20210608084348.GA5562@quack2.suse.cz> References: <20210608013123.1088882-1-guro@fb.com> <20210608013123.1088882-3-guro@fb.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210608013123.1088882-3-guro@fb.com> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon 07-06-21 18:31:17, Roman Gushchin wrote: > 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 Looks good. Feel free to add: Reviewed-by: Jan Kara Honza > --- > fs/fs-writeback.c | 6 ++++++ > 1 file changed, 6 insertions(+) > > diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c > index bd99890599e0..3564efcc4b78 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_id, 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 > -- > 2.31.1 > -- Jan Kara SUSE Labs, CR