Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3918580pxv; Mon, 28 Jun 2021 16:38:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzo4lG4Mi3c3ONN9os7uio7urV9SAPRF7OLbBI5XGs6Cm0A3OLPzIAf9MDB/77qPbmTJ+cS X-Received: by 2002:a5e:c601:: with SMTP id f1mr1448793iok.141.1624923533241; Mon, 28 Jun 2021 16:38:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624923533; cv=none; d=google.com; s=arc-20160816; b=fvRMKGw5WKa5JIrRvvgA7oOZqkWwghP9fxwOZVhmk0ggOH9Hv1Qr1JzgeGvg3mEBa5 sGTZfSm7X7RSrpv2gvQOzUhi/ndxQmS3wWWX28E6WK1QJLWHb51LNwJ5ZFB0ICPioM+/ PXg3celdPgp+FPIT8uEoU/w7oSgVWlmwAoiVVRaacWef/a3TpgjmXSu9t+4wcpNgn3C1 jPQE6OimxbYd4oxG91ClVIw6UvvB37fM6xFguWT7H1JCxOTRAdoG0tOxU/QPLrAbRNwS WxUEZmOwh3JXLTD8gjA5GvkoZDW+xobelEDhhQqyUQO7oZblH2QGInn+GF33SO9IgXhB aT3g== 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=sjzGZYePvIIaGO11WBPWnpQt5eSI/Ls63u3nQRytpxM=; b=p43F+tNdlotCO9boYC09GPaNVPSa2jS8n3UrQOFlMaoAmnRKXBN3tTl2BFXfQApg5C MQCDnSuJjr3v/ndXKMnQ7U83CF3piKn5Qqv2+t0Q+23J9ayVy3pAfJBhHLWRFZJD37ry CQI84EiW317q6cK8SBSg+UR3Txulifh1Q1G/x3qx1097vkx+5cYLAT2g6wZP7VYrTmrJ CuboSazzpDkcLxNEfd8Mo/Ja9uloSIkvXPyNsiFsBmiOTliGNTR4XsoggMMm6SIcbjGL h4fOYLIiMwKu+fGJMyPuX2YhoPmundH5DfUzdSdMJMWGn2UyNOVVd15FTK3ws0F2EqJ1 Sd5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=v5P5suiP; dkim=neutral (no key) header.i=@suse.cz header.b=D1mI1F4o; 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 x6si20125981ilv.59.2021.06.28.16.38.41; Mon, 28 Jun 2021 16:38:53 -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=v5P5suiP; dkim=neutral (no key) header.i=@suse.cz header.b=D1mI1F4o; 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 S234074AbhF1QfR (ORCPT + 99 others); Mon, 28 Jun 2021 12:35:17 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:45890 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233189AbhF1QfQ (ORCPT ); Mon, 28 Jun 2021 12:35:16 -0400 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 09051202E5; Mon, 28 Jun 2021 16:32:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1624897970; 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=sjzGZYePvIIaGO11WBPWnpQt5eSI/Ls63u3nQRytpxM=; b=v5P5suiPXZIsXITysRQW8T4KMY+HTzJY06wwv9ANmWT0+UoRk0KF2UcNSgGAcU8/xrnnyF kPpUVGYkpHSgNykI30VVBsAWWwV+JZ/NUZTUXx/jze71iGhD7eXPDiNlx2lkJ1KGufh45l F24EpgMLP+MgR+HzUjF07HT0FmnQU8U= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1624897970; 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=sjzGZYePvIIaGO11WBPWnpQt5eSI/Ls63u3nQRytpxM=; b=D1mI1F4oNy1ntZwMqfAaXFZh0By6E5mcAqJTJRlL2LDTIsrfdcrngZyYSiO77RRsiF88Od AeY1VaqSDh4oEuCA== Received: from quack2.suse.cz (unknown [10.100.224.230]) by relay2.suse.de (Postfix) with ESMTP id CE6C6A3B94; Mon, 28 Jun 2021 16:32:49 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 9B57A1E125C; Mon, 28 Jun 2021 18:32:49 +0200 (CEST) Date: Mon, 28 Jun 2021 18:32:49 +0200 From: Jan Kara To: Muchun Song Cc: Alexander Viro , Tejun Heo , axboe@fb.com, Matthew Wilcox , linux-fsdevel , LKML , Xiongchun duan , Michal Hocko Subject: Re: [PATCH v3] writeback: fix obtain a reference to a freeing memcg css Message-ID: <20210628163249.GC17026@quack2.suse.cz> References: <20210402091145.80635-1-songmuchun@bytedance.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi! On Thu 20-05-21 11:45:23, Muchun Song wrote: > It seems like this patch has not been added to the linux-next > tree. Can anyone help with this? Thanks. Muchun, did someone pickup this patch? I don't see it merged so unless somebody yells, I'll pick it up to my tree and send it to Linus for rc2. Honza > > On Fri, Apr 2, 2021 at 5:13 PM Muchun Song wrote: > > > > The caller of wb_get_create() should pin the memcg, because > > wb_get_create() relies on this guarantee. The rcu read lock > > only can guarantee that the memcg css returned by css_from_id() > > cannot be released, but the reference of the memcg can be zero. > > > > rcu_read_lock() > > memcg_css = css_from_id() > > wb_get_create(memcg_css) > > cgwb_create(memcg_css) > > // css_get can change the ref counter from 0 back to 1 > > css_get(memcg_css) > > rcu_read_unlock() > > > > Fix it by holding a reference to the css before calling > > wb_get_create(). This is not a problem I encountered in the > > real world. Just the result of a code review. > > > > Fixes: 682aa8e1a6a1 ("writeback: implement unlocked_inode_to_wb transaction and use it for stat updates") > > Signed-off-by: Muchun Song > > Acked-by: Michal Hocko > > --- > > Changelog in v3: > > 1. Do not change GFP_ATOMIC. > > 2. Update commit log. > > > > Thanks for Michal's review and suggestions. > > > > Changelog in v2: > > 1. Replace GFP_ATOMIC with GFP_NOIO suggested by Matthew. > > > > > > fs/fs-writeback.c | 9 +++++++-- > > 1 file changed, 7 insertions(+), 2 deletions(-) > > > > diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c > > index 3ac002561327..dedde99da40d 100644 > > --- a/fs/fs-writeback.c > > +++ b/fs/fs-writeback.c > > @@ -506,9 +506,14 @@ static void inode_switch_wbs(struct inode *inode, int new_wb_id) > > /* find and pin the new wb */ > > rcu_read_lock(); > > memcg_css = css_from_id(new_wb_id, &memory_cgrp_subsys); > > - if (memcg_css) > > - isw->new_wb = wb_get_create(bdi, memcg_css, GFP_ATOMIC); > > + if (memcg_css && !css_tryget(memcg_css)) > > + memcg_css = NULL; > > rcu_read_unlock(); > > + if (!memcg_css) > > + goto out_free; > > + > > + isw->new_wb = wb_get_create(bdi, memcg_css, GFP_ATOMIC); > > + css_put(memcg_css); > > if (!isw->new_wb) > > goto out_free; > > > > -- > > 2.11.0 > > -- Jan Kara SUSE Labs, CR