Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp4034918pxv; Mon, 28 Jun 2021 20:07:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw6p1VJI13gRcVDT7S89pbyYnUZF7aq6KWYPSaW2zUopIDIdnHmDLaKr5IFsS0AI3sxRK6s X-Received: by 2002:a05:6602:2f05:: with SMTP id q5mr2155467iow.192.1624936049420; Mon, 28 Jun 2021 20:07:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624936049; cv=none; d=google.com; s=arc-20160816; b=JUhd1lxutBbXnfm+nahV1RZeQBSxxmYcNNCsO+vWytAbZzFcUX2UTToFtbbBKXYVF2 gTVcaVQA+fmedFxuxupi1kIBFPJPer4VhslovP+fxLOCmgP0jX2FX8X/vyBfeGLPQZ3l 2/YHMi/JuZUBCXp8cVLxdVuoEzVIkBWbD/K0XBkLbT6AmD+6MlDEbu2e/U4jnFavPlfh Os0G4vdsTa5wi9usXA0X49VMfN3QTGsRD2llV0//QAf+euLRuWcUA2dYsI8G9kp6lLK3 4XbSfLYDN48UTI25ykiF5lREgCXxxg1XGbkTOKE2HxivmJdpYBqIkhCM55a6VaC18zAh KYnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=LDErPNTHeqAsnL4tn8YCrZnI3XrNMmZNrANksxZDwvQ=; b=TxJeU06OZQdPNbtHptRlnc+Lki3R3BkG8N4CEU9Nc3efaF9fi1f6b0mBrK62ztWxy7 D1WFdXQ47KOZQrUwDQBZ9MnUwtdSu402QzM8w70Y0dDQmKzIsPSanxzlkuWMy5yQgVw8 PDiXxDZUu823vWPveDW2BAa3jIBiVnBIJL0f9/D/KRGZ3BnD9sLeOv0PUuDV+jERLTnJ MOI6q6VU9B1Xl91o5KQe7DCXlSiYSqysSVEV1Sj7bz5rKm13z9Mb/hqT4/0oDrIbLQh8 bdNn8Q+GfeWoz28Daie26xXYDxc8x7VE1piaqHkuH3W0/ywF5RJuO1Wnl7aWW/aPLcSV jS5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=ZIqb2ZZZ; 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=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q9si3041167ild.5.2021.06.28.20.07.17; Mon, 28 Jun 2021 20:07:29 -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=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=ZIqb2ZZZ; 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=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231717AbhF2DJR (ORCPT + 99 others); Mon, 28 Jun 2021 23:09:17 -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-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