Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp172171pxf; Wed, 31 Mar 2021 20:39:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwRpm54alsGJeTXtXVb2qLWP3Owi04/21X3Icafi0etf2ddoz6rYtM2LLrpeZtLqOkenSMM X-Received: by 2002:a17:906:2818:: with SMTP id r24mr7006903ejc.502.1617248394873; Wed, 31 Mar 2021 20:39:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617248394; cv=none; d=google.com; s=arc-20160816; b=1LtYMTbXraeRRDbaUNvX/G5LUIOxch11tHbGsDsKGzPSFFdTwHJPADx/WqZ2wsWTKC DMUfx35LjowSDLQQuE4Xuld1vuV48+TSENF3DH6y4/QnpwxDIEdlDHU57vPx/7paKFg5 Q4JnszXL7f4M+zwWONHiBj77MD95TUMTV+PhyJc/uT/EXoI3oAY10XVpJ6eceFHB1FPA af9/030hT15/aiRjzUHjrqAdaiuSOv5Br57LBoBEo8hbTt9sREHty2Ls++ef/1cJaLyP BTwln9oSrTGUNaTHzNT9/rbXPN4n6T3muFp6uCIrbPmMGy0VManxUNFk/EF9HGC5C2GV lx4g== 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=6ABh7G3aqyjWpj4HPQxV4ijNfSktfKzBbc7sWrcEyjY=; b=lWMUPlSSMvoNmRhAG0xUepl2b3i+B/Js3yWud5Xw7HmcY+624cJ83fGxtKtGtCQ/Mb 3SMn8VFpbVIAmXu4dDvHR1mpTQjwPe5sEmAwZAXr+D2NYyvqB/0TPlsRpENFOCI3tobm acNPTVvVSLAMnH6s93irKqNHO+yDMgfrTAcWidDKUvaGFio70z153X3nno8REBR+HV21 y02N47Q8HeKL99j4O0x4uvUlgLfWh7OikJfntKkEI47FRfKhOl6R6B+Vp+0c5Sd7jQeH 6tWUTl5Ivc7LjVEn/D3jMX7tBpL414RN4HkXDARjnm0uB1OVQIgcnMGQnfqK8xef1WOq emVg== 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 m19si3609674edd.384.2021.03.31.20.39.32; Wed, 31 Mar 2021 20:39:54 -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 S232491AbhDADie (ORCPT + 99 others); Wed, 31 Mar 2021 23:38:34 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:15424 "EHLO szxga06-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230291AbhDADid (ORCPT ); Wed, 31 Mar 2021 23:38:33 -0400 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 >>> >> > . >