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=-13.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 9D9A9C11F66 for ; Tue, 29 Jun 2021 03:06:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7890861CA5 for ; Tue, 29 Jun 2021 03:06:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231682AbhF2DJS (ORCPT ); Mon, 28 Jun 2021 23:09:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231219AbhF2DJQ (ORCPT ); Mon, 28 Jun 2021 23:09:16 -0400 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E9F38C061760 for ; Mon, 28 Jun 2021 20:06:49 -0700 (PDT) Received: by mail-pj1-x1035.google.com with SMTP id pf4-20020a17090b1d84b029016f6699c3f2so953216pjb.0 for ; Mon, 28 Jun 2021 20:06:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=LDErPNTHeqAsnL4tn8YCrZnI3XrNMmZNrANksxZDwvQ=; b=ZIqb2ZZZTUFurFu4691iz5Ngf0kUICuOc8bjbHPTf+JEnONt8e6UboHwC8bfH7qOdi Xeol6nlo0CCEsy8YSYxrCScYIscTyIqviA62dp6T3xHnczCKUNDgIJCVLbWznaQ10Qr/ 277H2OOtSDyc/Ui/d/wdowOSrZSztbwMlHuCythTWaL7+ZIOQ0oxshAS6Jhl70284IVO mAVx0jpKt/fGLN5yn0yV30CyJX0OeN+F46brDgxqfuiRGTx+H/oqNkj1xoaZrTT4bK7e nMj7J7cFQDHbAT7cuMcTK7LCxnC9dGea/8cySFdN4tVnomzJl1Y90SbBfNcTnGXR05OR bgcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=LDErPNTHeqAsnL4tn8YCrZnI3XrNMmZNrANksxZDwvQ=; b=NDR2sMbNS8FBMcbi5FcVA9gtaTN6rUTIsRhLnayHchNMbIVtvlYeojKaYLMY7e16jx DJYbS/sLBHQ9xs537qXc3zImySfZxHnmjcaO43s19pPBURwpRM8boYrHvn2wqKFYyr9Z DeAMh2NmcoWUyhVYPDYhz97TQyGUdFeySYYx8l9ifQIYYW30m8IZaAx9NQjg+2Fl2ok9 5q3xNFlRIsz8lnQCaSlY8APk68CQEsIBXRfX+ft7KICRidfazOKRLWc2BcaCTWchVofY VEdY7bukSFQX2aPhxfpZ4Id0/ScYBsxCaWtRoLcBuvv4VVtlyQ/d9JkpzGj53AFjvNfi ZlWw== X-Gm-Message-State: AOAM530fdbkEVe/06ZJTfqCZ+e0X4NeyevLWwBu1HS6IfD4Q7SPCOMcs ZaP5abBYwQp43HlX+cD+SCTz9DmeiWUwy46bffPzdg== X-Google-Smtp-Source: ABdhPJzcqOKzhEJFQaQ4CzTFveIdQfXJ3YjRzdswQWJsJWDGHo1cgxl+JlkQuVhlyzYnsAXE3RSINrhxwHn0eNO4A7Q= X-Received: by 2002:a17:90a:14a4:: with SMTP id k33mr29255817pja.13.1624936008065; Mon, 28 Jun 2021 20:06:48 -0700 (PDT) MIME-Version: 1.0 References: <20210402091145.80635-1-songmuchun@bytedance.com> <20210628163249.GC17026@quack2.suse.cz> In-Reply-To: <20210628163249.GC17026@quack2.suse.cz> From: Muchun Song Date: Tue, 29 Jun 2021 11:06:10 +0800 Message-ID: Subject: Re: [External] Re: [PATCH v3] writeback: fix obtain a reference to a freeing memcg css To: Jan Kara Cc: Alexander Viro , Tejun Heo , axboe@fb.com, Matthew Wilcox , linux-fsdevel , LKML , Xiongchun duan , Michal Hocko Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 29, 2021 at 12:32 AM Jan Kara wrote: > > 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. > Hi, > Muchun, did someone pickup this patch? I don't see it merged so unless No, not yet. > somebody yells, I'll pick it up to my tree and send it to Linus for rc2. I'll be happy if you do that. Thanks. > > 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