Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp2253786ybv; Fri, 14 Feb 2020 14:45:57 -0800 (PST) X-Google-Smtp-Source: APXvYqwKL33A6gi4QcVgL9O3INcfwIvgHFGUff20GLGTOYsd3myjUy4fWtzWBcNvN+7XC90vhBAz X-Received: by 2002:aca:ab53:: with SMTP id u80mr3347043oie.94.1581720357350; Fri, 14 Feb 2020 14:45:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581720357; cv=none; d=google.com; s=arc-20160816; b=Imo2NxIVExR8rYGkdPNfXeSkf6uJ/Q8qhesB9niwSKzfM3L0v1/hE1VmXNrmAYLPMv IAGjN/Lme6PXCtzh1SzUzf7GfqgLvobJjG+Kg5zA88PKt3HAFdIkKt2L7tJ43wXSBvIs F8pUi3upgjdzwaHxgEgeVUKDT92VqrGjhiALb34dxeDUl0Tb2M7qjzQeO475gCt/0JLX 4LJL3S3FKakPnnFmcmRDrunjsggp898NgJvoEdaajnEmGUin2CDsL/d/Q7J9ZGZzVDtx MAXMTALTmOm656tgrA3fQDGcw8pmERGAb8lyMr85kM3x/oxuIZB/EYPbjUXJ+LEOtUu/ /s0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=BieUm8+5YIDYgpe+FhMyY8gKnYdFr8G076ODKkZnCSI=; b=0BV4We5P6rywPeijmXV4EKrEPQYy4vQVWmujFty8+L7AC3dp8hTptrAna/Je1zLa1Z TpYJH9s7zrIYUHSwyEC3I13P6FAoTqvjKm982zSdAiV1ItUroYsXSj7P3r05ehagFBsp 5d2CZbQEO4deieRv+HXCKFCLN+0UferWjAtdW4BJETnzNFJbpHD1T4f2ZsmkSUp8kSAy fwBOMmF5Przg/LOuhCTPjr5czQJegKnC7/qLW28b4dDhXctQggmjwneKY7XbUmz0MoUb TzYCAfe6bx0GwvHRs8YqIRwlMwptPllehoV+sM7YtwoHNQ0P2NSrfMraXDkSrlFsZGPb MkNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=L3eP57FH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r21si3412358otd.135.2020.02.14.14.45.45; Fri, 14 Feb 2020 14:45:57 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=L3eP57FH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727799AbgBNWok (ORCPT + 99 others); Fri, 14 Feb 2020 17:44:40 -0500 Received: from mail-ot1-f66.google.com ([209.85.210.66]:43370 "EHLO mail-ot1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727528AbgBNWok (ORCPT ); Fri, 14 Feb 2020 17:44:40 -0500 Received: by mail-ot1-f66.google.com with SMTP id p8so10652116oth.10 for ; Fri, 14 Feb 2020 14:44:39 -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=tFh/UI+i6Ukj9BOZLiWSZ6a+Djgk0TM83M67sh+qsN9MNfa1JQLXFSIez7/PQMeDCa EtYolCYXhmE5wramwwGBjkbURaZ2AtN/ohq7JmyVC3rXZbSUQ8bR/voX3g5CdPTAQnTt HsUGrxu9UqMz8IvnTCURd+rxDD48hdLhByQpasD/jJE69g5Ioo3HjO00cVHWyN6eeShf wOhv8VmtGMdFvg+CdOLKobsj9xRKWj71qcisG4CyBpwM6NAY96Xvcj6Xvisv8cvuo3hj I2b03nTFU8hO7vw415aN/TRqVwJMQAoSgapserScOmT2v255RDZrHEGbpRrpk74vAtMs /dfg== X-Gm-Message-State: APjAAAUCyA7upjvY52jlx2CWUr+woQVErTvz4lOxsgQzeJRlGFxgZgiP ttSrq9IM08wxi8XGhTHAnT+lHWyA9fD5PhJPRdekSg== 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" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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