From patchwork Fri Feb 14 07:12:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shakeel Butt X-Patchwork-Id: 11381783 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 0F83713A4 for ; Fri, 14 Feb 2020 07:13:02 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id BE02F2082F for ; Fri, 14 Feb 2020 07:13:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="X/KjJzEF" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BE02F2082F Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id F05E66B05FE; Fri, 14 Feb 2020 02:13:00 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E8E4F6B05FF; Fri, 14 Feb 2020 02:13:00 -0500 (EST) 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 D561C6B0600; Fri, 14 Feb 2020 02:13:00 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0091.hostedemail.com [216.40.44.91]) by kanga.kvack.org (Postfix) with ESMTP id B92BA6B05FE for ; Fri, 14 Feb 2020 02:13:00 -0500 (EST) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 410794DB7 for ; Fri, 14 Feb 2020 07:13:00 +0000 (UTC) X-FDA: 76487865720.24.line87_3746c3b0e6360 X-Spam-Summary: 2,0,0,7a31fd867bb40b19,d41d8cd98f00b204,3ekhgxggkcb0la3d77e49hh9e7.5hfebgnq-ffdo35d.hk9@flex--shakeelb.bounces.google.com,,RULES_HIT:41:152:355:379:541:800:960:973:988:989:1260:1277:1313:1314:1345:1437:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2393:2559:2562:2904:3138:3139:3140:3141:3142:3152:3353:3865:3866:3867:3868:3870:3871:3872:3874:4321:5007:6261:6653:7807:9969:10004:10400:11026:11658:11914:12043:12297:12438:12555:12679:12895:12986:13069:13161:13229:13311:13357:14096:14097:14181:14394:14659:14721:21067:21080:21433:21444:21450:21451:21627:21740:21990:30054:30056,0,RBL:209.85.214.202:@flex--shakeelb.bounces.google.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.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:23,LUA_SUMMARY:none X-HE-Tag: line87_3746c3b0e6360 X-Filterd-Recvd-Size: 4186 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) by imf19.hostedemail.com (Postfix) with ESMTP for ; Fri, 14 Feb 2020 07:12:59 +0000 (UTC) Received: by mail-pl1-f202.google.com with SMTP id q24so4726787pls.6 for ; Thu, 13 Feb 2020 23:12:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=GUW2iSWVcQnIpjOPNE/ThNp+Hs+3dImvwMIhxUppeuc=; b=X/KjJzEFSqSYWdSfML7JzS6n8HILLSQQiXHtsSRI37f+n9WVM5YZMoHTy7mrHn4gGG hiPLZs7adC6g14eb5Li+tsysiLOlk8Tm2QXpXorPLvcipOR2ey7hQGzHi/U4dnqIMYqe znIerMU7p8tjZjFbH0Zc0oTlRND+PiTNe3d94aV6gKKoRrlRGnwcmXmydkAf852PDJcU wDUPiEnhJ7CO/mAQ39rQ+aGDyE0+Nwcqt9EtBy2NyB7VfJIBImkoe3Xcq668JvykU6aJ QuJrqgKAcgR/YnrcmcwLhj9TFG9UrPEwL70sB3KLjiV9T3OsyGpnREhIXRMROfT7Q7A3 yvEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=GUW2iSWVcQnIpjOPNE/ThNp+Hs+3dImvwMIhxUppeuc=; b=VznJW8q7pZGU2FEID7q9UuM+9clcn+j65tE0QFENuxODquP4iJsaO5wFq94i6ei/C0 JGm9wGKdaplqK4i2Eh/YC36aY/ae3IRH1G5SCUCGpnQndRW+D9K8OLW/se0I9lGZ2QYr GL66KEJtUsIQPPeJyRo49Ti6xYijAPp4g2KmwB90YiMPLM/zZ6/qRPeqvzkhbHJ+QWLE ksur0MS+y3x1e3IlcSEwdnLYmv6AFQHPTDK32Qc2vaJEs8Kx0txFw5Y1HoXkiT7lK1XO hcon4ojVcEnwYARntxiw4v+OcMSzoYrx17WNpDzN0TJtvUxobhnY9KNTftCeX2nMXlGy 8aRA== X-Gm-Message-State: APjAAAUjFEX660xmbDThnkb2z/h7pEr8pqPrlFDw/9r/Hm0BF2JVWqOX OVslmb+Evnykakd6UUM9EixXqPKOPLjXyw== X-Google-Smtp-Source: APXvYqwI3Y/jbP9VtSLYI93+92eWNZSPA3hRBkyh1+IdbC3I0JAFFYLTnNgS9Bb7M2Rhd12CMf5e5s0E8x8kmQ== X-Received: by 2002:a63:451b:: with SMTP id s27mr1904601pga.233.1581664378417; Thu, 13 Feb 2020 23:12:58 -0800 (PST) Date: Thu, 13 Feb 2020 23:12:33 -0800 Message-Id: <20200214071233.100682-1-shakeelb@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog Subject: [PATCH] memcg: net: do not associate sock with unrelated memcg From: Shakeel Butt To: Johannes Weiner , Eric Dumazet Cc: Greg Thelen , Michal Hocko , Vladimir Davydov , Andrew Morton , cgroups@vger.kernel.org, linux-mm@kvack.org, Roman Gushchin , linux-kernel@vger.kernel.org, Shakeel Butt 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: We are testing network memory accounting in our setup and noticed inconsistent network memory usage and often unrelated memcgs network usage correlates with testing workload. On further inspection, it seems like mem_cgroup_sk_alloc() is broken in irq context specially for cgroup v1. mem_cgroup_sk_alloc() can be called in irq context and kind of assumes that it can only happen from sk_clone_lock() and the source sock object has already associated memcg. However in cgroup v1, where network memory accounting is opt-in, the source sock can be not associated with any memcg and the new cloned sock can get associated with unrelated interrupted memcg. Cgroup v2 can also suffer if the source sock object was created by process in the root memcg or if sk_alloc() is called in irq context. The fix is to just do nothing in interrupt. Fixes: 2d7580738345 ("mm: memcontrol: consolidate cgroup socket tracking") Signed-off-by: Shakeel Butt --- mm/memcontrol.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 63bb6a2aab81..f500da82bfe8 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -6697,6 +6697,10 @@ void mem_cgroup_sk_alloc(struct sock *sk) return; } + /* Do not associate the sock with unrelated interrupted task's memcg. */ + if (in_interrupt()) + return; + rcu_read_lock(); memcg = mem_cgroup_from_task(current); if (memcg == root_mem_cgroup)