From patchwork Tue Oct 27 08:02:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 11859627 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E018661C for ; Tue, 27 Oct 2020 08:03:24 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 651382224E for ; Tue, 27 Oct 2020 08:03:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=bytedance-com.20150623.gappssmtp.com header.i=@bytedance-com.20150623.gappssmtp.com header.b="J7QFPcYy" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 651382224E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 937F46B0062; Tue, 27 Oct 2020 04:03:23 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 90E016B006C; Tue, 27 Oct 2020 04:03:23 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 826466B006E; Tue, 27 Oct 2020 04:03:23 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0063.hostedemail.com [216.40.44.63]) by kanga.kvack.org (Postfix) with ESMTP id 50E056B0062 for ; Tue, 27 Oct 2020 04:03:23 -0400 (EDT) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 02D318249980 for ; Tue, 27 Oct 2020 08:03:23 +0000 (UTC) X-FDA: 77416965486.29.cover01_5c16def2727a Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin29.hostedemail.com (Postfix) with ESMTP id D105A18086CBE for ; Tue, 27 Oct 2020 08:03:22 +0000 (UTC) X-Spam-Summary: 1,0,0,89e4cc378fb4f12c,d41d8cd98f00b204,songmuchun@bytedance.com,,RULES_HIT:41:355:379:541:800:960:973:988:989:1260:1311:1314:1345:1359:1437:1515:1534:1541:1711:1730:1747:1777:1792:1801:2393:2559:2562:3138:3139:3140:3141:3142:3352:3865:3866:4321:4605:5007:6261:6653:6737:8784:10004:11026:11658:11914:12043:12048:12296:12297:12438:12517:12519:12555:12679:12895:13069:13311:13357:13894:14096:14181:14384:14394:14581:14721:21080:21444:21451:21627:21990:30054,0,RBL:209.85.216.65:@bytedance.com:.lbl8.mailshell.net-62.2.0.100 66.100.201.201;04y85rwstxb3we13ebhhjcyuyufcuopwbg5awkp1hsnmwf74asjbiswhfc84wmw.1uek4kqn63oyoznccppn57w1n7ppkqcx1rukw9k4xefwp1n5rgjab885x3ur6m6.6-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: cover01_5c16def2727a X-Filterd-Recvd-Size: 4505 Received: from mail-pj1-f65.google.com (mail-pj1-f65.google.com [209.85.216.65]) by imf49.hostedemail.com (Postfix) with ESMTP for ; Tue, 27 Oct 2020 08:03:22 +0000 (UTC) Received: by mail-pj1-f65.google.com with SMTP id l2so343784pjt.5 for ; Tue, 27 Oct 2020 01:03:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pkKyxTwl8ekG841RoN58bB0vzsrEHZTiUbsxmBIxH0Y=; b=J7QFPcYyl+Rudib/U00XRzim7IuwfNQtPAZP0xb+Mv5iSY4+XHq5yo6c5JpkrTzH+x zMqLgUYoRMW6RLuijAzEUXPiwdUAv0OlP018X16jtfAE4iCBozAlIGusVJ379BvQF4ex euMiQdjzZbooFeBqwPBtKiAAMXvQMYa2laliQtiAMGa7S2aFAmb0VdDszsuq2FBeQIrn 6sGs6A7g90DTQsM0B1cOt3EBBB544p5q7HmT5QI3C7xvTdM987JLsiQjWQblfV4fCci2 1R7xoknLsUCfNO9cESLng0m+PikAlEnM8DcLgi/D28YoWPYN5FGqJexP7SZNeepLSpx9 bcRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pkKyxTwl8ekG841RoN58bB0vzsrEHZTiUbsxmBIxH0Y=; b=TYXsVOD1G5yW/CRdjPOha/s+JmN+T43RmowD1KGIFGXHHodx78Hjjfwd+ZZtqXqMCt oP7goadIi5Lioiv/HC1pzgjh5Q4VE5YYq+/w0z0MU4uEO9zRhUqV+SzAzhNaRkfsafQX 4jBntk2A0buDAtjkVvoRCFDR7D9Jls+I2xP0ZunyyN9lUe2xe7LlEeiGRITM97+66y3x KqeSpNnz7xgQz26qlqbFNHJVIvA5ccnvCPFAvfi9QaZpJYsbMiydRcdXtB4p+s4JAwkp csj5dPAPWlD4hc63GznsrWM5Uw0u2vVqnKDAjPryBqGQUAe7j6jHE9IpPFOSHHGHwjIH gf2A== X-Gm-Message-State: AOAM530sRpQj7keqUSrX5KlIE/6sjcy0qO6wRUwOdr5DR3eSy7+Lv31n GPu/p9ziqfZXYyDsZQgOMLOF5Q== X-Google-Smtp-Source: ABdhPJykmbE8wdjYC2X2wAsrBvfaEdwwrwqA0TK0rjcGxYjqEk01eqrw7luf4X70zO+qxkB7CaqFXg== X-Received: by 2002:a17:902:468:b029:d5:ad3c:cf52 with SMTP id 95-20020a1709020468b02900d5ad3ccf52mr1397871ple.7.1603785801285; Tue, 27 Oct 2020 01:03:21 -0700 (PDT) Received: from Smcdef-MBP.local.net ([103.136.220.89]) by smtp.gmail.com with ESMTPSA id p8sm1039580pgs.34.2020.10.27.01.03.14 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Oct 2020 01:03:20 -0700 (PDT) From: Muchun Song To: hannes@cmpxchg.org, mhocko@kernel.org, vdavydov.dev@gmail.com, akpm@linux-foundation.org, shakeelb@google.com, guro@fb.com, iamjoonsoo.kim@lge.com, laoar.shao@gmail.com, chris@chrisdown.name, christian.brauner@ubuntu.com, peterz@infradead.org, mingo@kernel.org, keescook@chromium.org, tglx@linutronix.de, esyr@redhat.com, surenb@google.com, areber@redhat.com, elver@google.com Cc: linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org, Muchun Song Subject: [PATCH 1/5] mm: memcg/slab: Fix return child memcg objcg for root memcg Date: Tue, 27 Oct 2020 16:02:52 +0800 Message-Id: <20201027080256.76497-2-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) In-Reply-To: <20201027080256.76497-1-songmuchun@bytedance.com> References: <20201027080256.76497-1-songmuchun@bytedance.com> MIME-Version: 1.0 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: Consider the following memcg hierarchy. root / \ A B If we get the objcg of memcg A failed, the get_obj_cgroup_from_current can return the wrong objcg for the root memcg. Fixes: bf4f059954dc ("mm: memcg/slab: obj_cgroup API") Signed-off-by: Muchun Song --- mm/memcontrol.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 1337775b04f3..fcbd79c5023e 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -2945,7 +2945,7 @@ struct mem_cgroup *mem_cgroup_from_obj(void *p) __always_inline struct obj_cgroup *get_obj_cgroup_from_current(void) { - struct obj_cgroup *objcg = NULL; + struct obj_cgroup *objcg; struct mem_cgroup *memcg; if (memcg_kmem_bypass()) @@ -2964,6 +2964,9 @@ __always_inline struct obj_cgroup *get_obj_cgroup_from_current(void) } rcu_read_unlock(); + if (memcg == root_mem_cgroup) + return NULL; + return objcg; }