From patchwork Thu Oct 29 16:44:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 11866873 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 709F51130 for ; Thu, 29 Oct 2020 16:44:51 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 05A2D20838 for ; Thu, 29 Oct 2020 16:44:50 +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="hfspaErk" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 05A2D20838 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 097876B0062; Thu, 29 Oct 2020 12:44:50 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 045636B006C; Thu, 29 Oct 2020 12:44:50 -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 E50226B006E; Thu, 29 Oct 2020 12:44:49 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0249.hostedemail.com [216.40.44.249]) by kanga.kvack.org (Postfix) with ESMTP id B8CFE6B0062 for ; Thu, 29 Oct 2020 12:44:49 -0400 (EDT) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 60E6D180AD817 for ; Thu, 29 Oct 2020 16:44:49 +0000 (UTC) X-FDA: 77425537098.01.spy01_33118762728e Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin01.hostedemail.com (Postfix) with ESMTP id 3BB8B1004A756 for ; Thu, 29 Oct 2020 16:44:49 +0000 (UTC) X-Spam-Summary: 1,0,0,5ed0ab29c6f9a44f,d41d8cd98f00b204,songmuchun@bytedance.com,,RULES_HIT:41:355:379:541:800:960:973:988:989:1260:1311:1314:1345:1437:1515:1534:1541:1711:1730:1747:1777:1792:1801:2393:2559:2562:3138:3139:3140:3141:3142:3352:3865:3866:3867:3870:4321:4605:5007:6261:6653:6737:8784:10004:11026:11658:11914:12043:12048:12296:12297:12438:12517:12519:12555:12679:12895:13069:13161:13229:13311:13357:13894:14096:14181:14384:14394:14581:14721:21080:21444:21451:21627:21990:30054:30064,0,RBL:209.85.214.195:@bytedance.com:.lbl8.mailshell.net-66.100.201.201 62.2.0.100;04ygend938nfo4oh3mo8ofbmftso3ycj5u5ec97qtbub6443dngmebecb9ha8xn.7wqp8wsm5hdtfs4bw1gycdf4dwsegt9d47wobw99c6mfgwjck6zkzgbtb9mdrff.h-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:70,LUA_SUMMARY:none X-HE-Tag: spy01_33118762728e X-Filterd-Recvd-Size: 4285 Received: from mail-pl1-f195.google.com (mail-pl1-f195.google.com [209.85.214.195]) by imf27.hostedemail.com (Postfix) with ESMTP for ; Thu, 29 Oct 2020 16:44:48 +0000 (UTC) Received: by mail-pl1-f195.google.com with SMTP id x23so1572618plr.6 for ; Thu, 29 Oct 2020 09:44:48 -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:mime-version :content-transfer-encoding; bh=WMTjr2+W+gNVsgeHGd8A7YK4eqPL28HpThgEaSeH9eU=; b=hfspaErkNEk3rAQDqD3A0QgoFYIiQkGUXf8U4LtwDIZRnTaq5uY+72sOy4F8Tecu7/ S10JQrb+7JGVOXgAIaOvAXO67dScyeX13atrBB4zM+n0Vnq+wRAjitHeNE4ZuCqVjq/T y1K07iO66M5EAMlOc0n1HSwbJUn8tCD1O10RG0i3r2KoxYlwfxpn3eJjkJamTOQhXQdz WRu4N0U20Nh5rSCsry63lSKA1ytldBRzUIhbDSqHt73GjcTEdUL5KABUa1mss8WbXjsR IAJ/w6jdyyyMBerGnkWLXBgWJR/Zw+o2nEuA5MEUGTCnJccPYfUJRhZrugg2P3djBpW3 d5QQ== 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:mime-version :content-transfer-encoding; bh=WMTjr2+W+gNVsgeHGd8A7YK4eqPL28HpThgEaSeH9eU=; b=G6p3WJuce3E1B0k5761f4++Ot53eji7FMrIErFwmkKThHiQhExAn3qRS8OfbIw8Omj 0VYnS352ePaq49oNlTsireaaaVezyeMKYp4y7Fq0MKqNOuOpdMDE+BcQ2ZN6C4FFW9PZ eURA1sr6gcl5UJYHoIfxUb1fX1T+OfUTayuLnuiwZhutWs/MTIe6LmorbJAA29PpQeic AcFuqSsLXoBHYrZHqSZR64iJG9eP20DPKY6V3XSGK7Nh1IbV7UJ+VFtcw+2GNJsdI4Kk v3TxAJtr4/OD1lBwAi3iaFeahzmHKmbVhKmYITwsfc1uXSieSKWXTpDeRPROQ7gC/nxJ bFvQ== X-Gm-Message-State: AOAM533VOMt03wDfAbsP33W0YbtIv8cmdvXsAs0JC0BnPzRmw5T5SC8t wTVmSe2v04SAg0F48k0A4D4ARg== X-Google-Smtp-Source: ABdhPJwQrJmv/aoXAfRDFvHvxaf+pIXE+6B7vM/dhQRAubpFI5YbGj/chIP9FmZN25gkwUQQYOHgsQ== X-Received: by 2002:a17:902:b497:b029:d5:c01a:f06b with SMTP id y23-20020a170902b497b02900d5c01af06bmr5152085plr.13.1603989887265; Thu, 29 Oct 2020 09:44:47 -0700 (PDT) Received: from localhost.localdomain ([103.136.220.95]) by smtp.gmail.com with ESMTPSA id 197sm3429491pfa.170.2020.10.29.09.44.40 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Oct 2020 09:44:46 -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 v3] mm: memcg/slab: Fix return child memcg objcg for root memcg Date: Fri, 30 Oct 2020 00:44:29 +0800 Message-Id: <20201029164429.58703-1-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000683, 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 failed to get the reference on objcg of memcg A, 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 Acked-by: Roman Gushchin --- changelog in v3: 1. Fix commit grammar, thanks to Shakeel. changelog in v2: 1. Do not use a comparison with the root_mem_cgroup mm/memcontrol.c | 1 + 1 file changed, 1 insertion(+) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 1337775b04f3..8c8b4c3ed5a0 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -2961,6 +2961,7 @@ __always_inline struct obj_cgroup *get_obj_cgroup_from_current(void) objcg = rcu_dereference(memcg->objcg); if (objcg && obj_cgroup_tryget(objcg)) break; + objcg = NULL; } rcu_read_unlock();