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=-14.4 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable 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 1CAA4C3F68F for ; Fri, 14 Feb 2020 22:44:42 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D3A512081E for ; Fri, 14 Feb 2020 22:44:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="L3eP57FH" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D3A512081E 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 69EFB6B06B5; Fri, 14 Feb 2020 17:44:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 64FB66B06B7; Fri, 14 Feb 2020 17:44:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 566346B06B8; Fri, 14 Feb 2020 17:44:41 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0210.hostedemail.com [216.40.44.210]) by kanga.kvack.org (Postfix) with ESMTP id 3FBA96B06B5 for ; Fri, 14 Feb 2020 17:44:41 -0500 (EST) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id C5F61181AEF1E for ; Fri, 14 Feb 2020 22:44:40 +0000 (UTC) X-FDA: 76490213520.15.boy45_28cd317abed32 X-HE-Tag: boy45_28cd317abed32 X-Filterd-Recvd-Size: 5641 Received: from mail-ot1-f65.google.com (mail-ot1-f65.google.com [209.85.210.65]) by imf06.hostedemail.com (Postfix) with ESMTP for ; Fri, 14 Feb 2020 22:44:40 +0000 (UTC) Received: by mail-ot1-f65.google.com with SMTP id i6so10690672otr.7 for ; Fri, 14 Feb 2020 14:44:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=BieUm8+5YIDYgpe+FhMyY8gKnYdFr8G076ODKkZnCSI=; b=L3eP57FHmgpwX0BXPjR4dUwWPeYx6VHKH+dC4bF26fzsa3xP9s0imlWA+E6uN0S05K 6yf51tiwkAerV/SJR1fGiA7Wr7WLGZ+zBOxXt4Qenpn5rfbjKgPm/mIibXFJTTd1Tp8t Bq0p5XsdziD0E4io0BuEe8rJgP3xOcdLDCN8eS8l52k8BwSaxsGA+Wt0tRIEeIquIIJ2 auK+UxC6K6JqgIfyOGPbbekMOBylIsf5X7uNHK4QhAbHdShRHe/5UFvUjzVGbTfgjopB SV18xbWZSDFVHxHJtWH3a/dtf1SPGdnTpCqTw50f6gi648Gtjpk6CtDMj2n25/NpIiJR DBRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=BieUm8+5YIDYgpe+FhMyY8gKnYdFr8G076ODKkZnCSI=; b=V3KhQy+g5oejONOlKSuw1EUlSMufEgzbQwumS8jjAW7dPAvACH0k6vP5eZxfzMxS8A fdljlka4b4XIERTSfAj5nLiSkQ83oB6vWwBhnMlUNfP/F74OFeUUBkDVbKKkyhc3Ap6j JLUgKQvVqfHNZKWlOkYluqw/DA0HYDQaW4KMzejqJZOuByLJcUAyabtV5ZiwIrATJ9jE itE5xyTp1nJNE9xNDBVTUk0a1V1qPiH4S/o1vl3sKf5Qt/HVSbpwQXXZyUihpBWqojre cwMToCKAK7fhV50ZPGbbI5lszaWU93dFHuzVOm49fjH5oB6Lp8yO2PyTsiukOVmvqTAv TbvA== X-Gm-Message-State: APjAAAWEHy4QJKHjAZndqvqInp8ihI4Fkl47zD5Ed7giqh8RXFA0CJIW RWZ1Fz7lO83wJ82CBL8VXc/HRGBQi0I84M59cv3aMA== X-Google-Smtp-Source: APXvYqwtMloELc8yyjiKROZUWk9iBobR5zrhOA3kDqcmzqBo65VARWEAjndXv65IUMTNhasNaouQOIRld/mI5menbbA= X-Received: by 2002:a05:6830:1e2b:: with SMTP id t11mr4117327otr.81.1581720279231; Fri, 14 Feb 2020 14:44:39 -0800 (PST) MIME-Version: 1.0 References: <20200214222415.181467-1-shakeelb@google.com> <20200214223303.GA60585@carbon.dhcp.thefacebook.com> In-Reply-To: <20200214223303.GA60585@carbon.dhcp.thefacebook.com> From: Shakeel Butt Date: Fri, 14 Feb 2020 14:44:28 -0800 Message-ID: Subject: Re: [PATCH v2] cgroup: memcg: net: do not associate sock with unrelated cgroup To: Roman Gushchin Cc: Johannes Weiner , Eric Dumazet , Tejun Heo , Greg Thelen , Michal Hocko , Vladimir Davydov , Andrew Morton , Cgroups , Linux MM , LKML Content-Type: text/plain; charset="UTF-8" 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: On Fri, Feb 14, 2020 at 2:33 PM Roman Gushchin wrote: > > On Fri, Feb 14, 2020 at 02:24:15PM -0800, Shakeel Butt wrote: > > 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. > > > > Fixes: 2d7580738345 ("mm: memcontrol: consolidate cgroup socket tracking") > > Fixes: d979a39d7242 ("cgroup: duplicate cgroup reference when cloning sockets") > > Signed-off-by: Shakeel Butt > > --- > > > > Changes since v1: > > - Fix cgroup_sk_alloc() too. > > > > kernel/cgroup/cgroup.c | 4 ++++ > > mm/memcontrol.c | 4 ++++ > > 2 files changed, 8 insertions(+) > > > > diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c > > index 9a8a5ded3c48..46e5f5518fba 100644 > > --- a/kernel/cgroup/cgroup.c > > +++ b/kernel/cgroup/cgroup.c > > @@ -6449,6 +6449,10 @@ void cgroup_sk_alloc(struct sock_cgroup_data *skcd) > > return; > > } > > > > + /* Do not associate the sock with unrelated interrupted task's memcg. */ > ^^^^^ > cgroup? > > + if (in_interrupt()) > > + return; > > + > > rcu_read_lock(); > > > > while (true) { > > 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; > > } > > Can you, please, include the stacktrace into the commit log? > Except a minor typo (see above), > Reviewed-by: Roman Gushchin > > A really good catch. > Thanks, I will add the stack trace and fix the typo. Shakeel