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=-15.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham 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 D693AC433B4 for ; Thu, 1 Apr 2021 03:38:37 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5ED6561041 for ; Thu, 1 Apr 2021 03:38:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5ED6561041 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id A10426B0080; Wed, 31 Mar 2021 23:38:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9C0706B0081; Wed, 31 Mar 2021 23:38:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 83A0D6B0082; Wed, 31 Mar 2021 23:38:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0192.hostedemail.com [216.40.44.192]) by kanga.kvack.org (Postfix) with ESMTP id 6AB2A6B0080 for ; Wed, 31 Mar 2021 23:38:36 -0400 (EDT) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 20212180AC155 for ; Thu, 1 Apr 2021 03:38:36 +0000 (UTC) X-FDA: 77982391032.23.62FE551 Received: from szxga06-in.huawei.com (szxga06-in.huawei.com [45.249.212.32]) by imf16.hostedemail.com (Postfix) with ESMTP id D117F80192D4 for ; Thu, 1 Apr 2021 03:38:34 +0000 (UTC) Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4F9pl36G4XzjXXJ; Thu, 1 Apr 2021 11:36:47 +0800 (CST) Received: from [10.174.179.86] (10.174.179.86) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.498.0; Thu, 1 Apr 2021 11:38:26 +0800 Subject: Re: [PATCH] mm: memcontrol: fix forget to obtain the ref to objcg in split_page_memcg To: Roman Gushchin , Muchun Song CC: , , , Christian Borntraeger , , , , , References: <20210401030141.37061-1-songmuchun@bytedance.com> <5c183fe6-637f-151c-67f0-fe19a0ce3356@huawei.com> From: Miaohe Lin Message-ID: <38903032-6075-954a-31e2-7ab609b4bb2e@huawei.com> Date: Thu, 1 Apr 2021 11:38:26 +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: 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 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: D117F80192D4 X-Stat-Signature: u3d9wcexnueay43a7w9s433y6s3s3744 Received-SPF: none (huawei.com>: No applicable sender policy available) receiver=imf16; identity=mailfrom; envelope-from=""; helo=szxga06-in.huawei.com; client-ip=45.249.212.32 X-HE-DKIM-Result: none/none X-HE-Tag: 1617248314-802476 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 2021/4/1 11:35, Roman Gushchin wrote: > On Thu, Apr 01, 2021 at 11:31:16AM +0800, Miaohe Lin wrote: >> 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? > > No, as the original patch hasn't been merged into the Linus's tree yet. > So the fix can be simply squashed. > > Btw, the fix looks good to me. > > Acked-by: Roman Gushchin > I see. Many thanks for explanation! The code looks good to me. Reviewed-by: Miaohe Lin >> >>> --- >>> 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 >>> >> > . >