Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp171644pxf; Wed, 31 Mar 2021 20:38:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyaDu+qH5+8rWoHsHL4whX53T7uc74ju+w05t9cm1yjbT3Gp077j0dZnSMohlyUOi53eF8g X-Received: by 2002:a05:6402:22b5:: with SMTP id cx21mr7544008edb.27.1617248316259; Wed, 31 Mar 2021 20:38:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617248316; cv=none; d=google.com; s=arc-20160816; b=X4Ir0Nx1WrwWj6OZDfQdHM7fFuqBmYr0ZiFURmoUaqUUXSu8sOLod+D9U8NZdVqy15 Ttm/QloB24X5dYOxYZRarfE69V6jCGySmeHmFDCUhBbgTPpqNH7PMnOaJcDv2YN6hVKa 4bkYER4qqPL0/2Pjj8gVV5UJnUYvBoD878fzW9IekeCg6193b0uOSedR3w11K9ynb+j0 /IJcX7ncX1bDI4Bh1bJvgbcc4G21ISUwJo1dqJCqbrhn9biLzEFbXOQrCY+8FMJMHnPL ardknzrqRZqtdGiM/0emxrjxXXLvBjNn4cEv+RE0IBgJmC8O4c8/FnH1GoODbsn8T8Fm XTzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=ECVgxDZ/uMaZneKae5K1vzxVp/7zAVJIgrlRZrFbxtQ=; b=Wg/APqMXn125xt6GcOA+YDgTwm6VkFn9avPW8lHfHVK5QT/RNOhZtWzxRcj12yxXjr 1AzYFrs2T3p+gB+lZOfVXlNbR8IEdwcyXpn5uNyVzetWzuW1f9Je1AQXvHEX+3zUG0wp NGyuBxV6fXNLLrlnj1ibWVQcihuGOBaLBvAoMh/4lUiXnuRm/LsCroue2c5i49Xcrztz un5xBtZuNIsZQ4Tv95iNWtnCmtFnjhxFTP3b41X4Uhonz0V0RssheC3SLeZvmsX0U9Kt mZfP6RajEGGROAxkeNtfXhL2bbBFvAHptFvvi8R1QFtzEB4TVqsNIHi3Kg5T8gTLCaU7 xYHg== ARC-Authentication-Results: i=1; mx.google.com; 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=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gs37si3304718ejc.198.2021.03.31.20.38.14; Wed, 31 Mar 2021 20:38:36 -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; 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=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233509AbhDADbt (ORCPT + 99 others); Wed, 31 Mar 2021 23:31:49 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:14660 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233461AbhDADbY (ORCPT ); Wed, 31 Mar 2021 23:31:24 -0400 Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4F9pYk5srxznWxq; Thu, 1 Apr 2021 11:28:42 +0800 (CST) Received: from [10.174.179.86] (10.174.179.86) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.498.0; Thu, 1 Apr 2021 11:31:16 +0800 Subject: Re: [PATCH] mm: memcontrol: fix forget to obtain the ref to objcg in split_page_memcg To: Muchun Song CC: , , , Christian Borntraeger , , , , , , References: <20210401030141.37061-1-songmuchun@bytedance.com> From: Miaohe Lin Message-ID: <5c183fe6-637f-151c-67f0-fe19a0ce3356@huawei.com> Date: Thu, 1 Apr 2021 11:31:16 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: <20210401030141.37061-1-songmuchun@bytedance.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.179.86] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021/4/1 11:01, Muchun Song wrote: > Christian Borntraeger reported a warning about "percpu ref > (obj_cgroup_release) <= 0 (-1) after switching to atomic". > Because we forgot to obtain the reference to the objcg and > wrongly obtain the reference of memcg. > > Reported-by: Christian Borntraeger > Signed-off-by: Muchun Song Thanks for the patch. Is a Fixes tag needed? > --- > include/linux/memcontrol.h | 6 ++++++ > mm/memcontrol.c | 6 +++++- > 2 files changed, 11 insertions(+), 1 deletion(-) > > diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h > index 0e8907957227..c960fd49c3e8 100644 > --- a/include/linux/memcontrol.h > +++ b/include/linux/memcontrol.h > @@ -804,6 +804,12 @@ static inline void obj_cgroup_get(struct obj_cgroup *objcg) > percpu_ref_get(&objcg->refcnt); > } > > +static inline void obj_cgroup_get_many(struct obj_cgroup *objcg, > + unsigned long nr) > +{ > + percpu_ref_get_many(&objcg->refcnt, nr); > +} > + > static inline void obj_cgroup_put(struct obj_cgroup *objcg) > { > percpu_ref_put(&objcg->refcnt); > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > index c0b83a396299..64ada9e650a5 100644 > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > @@ -3133,7 +3133,11 @@ void split_page_memcg(struct page *head, unsigned int nr) > > for (i = 1; i < nr; i++) > head[i].memcg_data = head->memcg_data; > - css_get_many(&memcg->css, nr - 1); > + > + if (PageMemcgKmem(head)) > + obj_cgroup_get_many(__page_objcg(head), nr - 1); > + else > + css_get_many(&memcg->css, nr - 1); > } > > #ifdef CONFIG_MEMCG_SWAP >