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=-0.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no 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 46554C4BA28 for ; Wed, 26 Feb 2020 19:07:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 267F42465D for ; Wed, 26 Feb 2020 19:07:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727250AbgBZTH4 (ORCPT ); Wed, 26 Feb 2020 14:07:56 -0500 Received: from shards.monkeyblade.net ([23.128.96.9]:60140 "EHLO shards.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727035AbgBZTHz (ORCPT ); Wed, 26 Feb 2020 14:07:55 -0500 Received: from localhost (unknown [IPv6:2601:601:9f00:477::3d5]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) (Authenticated sender: davem-davemloft) by shards.monkeyblade.net (Postfix) with ESMTPSA id 5044515AA1098; Wed, 26 Feb 2020 11:07:52 -0800 (PST) Date: Wed, 26 Feb 2020 11:07:49 -0800 (PST) Message-Id: <20200226.110749.77396284962321904.davem@davemloft.net> To: shakeelb@google.com Cc: edumazet@google.com, guro@fb.com, hannes@cmpxchg.org, tj@kernel.org, gthelen@google.com, mhocko@kernel.org, vdavydov.dev@gmail.com, akpm@linux-foundation.org, cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: Re: [PATCH v3] cgroup: memcg: net: do not associate sock with unrelated cgroup From: David Miller In-Reply-To: <20200221014604.126118-1-shakeelb@google.com> References: <20200221014604.126118-1-shakeelb@google.com> X-Mailer: Mew version 6.8 on Emacs 26.1 Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.5.12 (shards.monkeyblade.net [149.20.54.216]); Wed, 26 Feb 2020 11:07:52 -0800 (PST) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Shakeel Butt Date: Thu, 20 Feb 2020 17:46:04 -0800 > We are testing network memory accounting in our setup and noticed > inconsistent network memory usage and often unrelated cgroups network > usage correlates with testing workload. On further inspection, it > seems like mem_cgroup_sk_alloc() and cgroup_sk_alloc() are broken in > IRQ context specially for cgroup v1. > > mem_cgroup_sk_alloc() and cgroup_sk_alloc() can be called in IRQ context > and kind of assumes that this can only happen from sk_clone_lock() > and the source sock object has already associated cgroup. However in > cgroup v1, where network memory accounting is opt-in, the source sock > can be unassociated with any cgroup and the new cloned sock can get > associated with unrelated interrupted cgroup. > > Cgroup v2 can also suffer if the source sock object was created by > process in the root cgroup or if sk_alloc() is called in IRQ context. > The fix is to just do nothing in interrupt. > > WARNING: Please note that about half of the TCP sockets are allocated > from the IRQ context, so, memory used by such sockets will not be > accouted by the memcg. Then if we do this then we have to have some kind of subsequent change to attach these sockets to the correct cgroup, right?