Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp2249534ybv; Fri, 14 Feb 2020 14:38:44 -0800 (PST) X-Google-Smtp-Source: APXvYqyDUfqgsLTv+JpJfnDCzR7lnx15XLzw6LayIhkcbeIKqe/Ab8i02CL6hBDELVtRTXb4a7zw X-Received: by 2002:a54:468a:: with SMTP id k10mr3515670oic.3.1581719924689; Fri, 14 Feb 2020 14:38:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581719924; cv=none; d=google.com; s=arc-20160816; b=ace3wBQ+83buzwB6TSBMGP38kLwGUIM0AUfYAVmkWETeQl2ZiJmzUdNNs+/MKuuBvU HlYJVKQ1lGzK+CKjPYUXqLEE55lzYJDs31TARJfyA5fcpBR08eHqCQY68gAbZOR20HfP +NT/0ncWLd+JN0XHk+lWxqjTaOUCPIiq66hgZTn+KFnH4R7iQAC4ojNDIXy8AWsqOHpb bWaoDFuRbN4gYObBSwZj3rvu5pNxo164fPy2bxk7Y3qJNYJWbIVph3UYZLKg1v0XssAp H559OoLIcpzsBO7Opv7rG2K/+A7xbS4KpfvLRhOVDrNt8kqVicDO4ojDFOwG1pVe7g8C DBDQ== 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=UhXhwNSRwdSyi+H9zMRuLq0WFPtWCQTooj0QtYbRLG8=; b=J+tMJ312TZFQTUlCpYl8s5nIiWRImg0QXQVAhb8eZZlhisA0tCgsFk0u8MyQQrp+U1 nkg5+1sjPpb/yABhiE7TfQWI/78KAVmaAo9d/XjOHU4/8Tlac170PmLCNnz1BjJ+XnmM 1i8h+3FWAIXZ2UonoL62jPylZEtJ7mWNzKLcwZ3LCX76hYQxP9Lvnr9HZRVi/qz5l/nV +kNb2zZ89hfp9Bdu+vDqdXyJrgevZckOK0kfrG98dtbV0uvO0c41nyBqMQsB2+gZvzdY 1Fet6z2qtonid+YNMlF/QR+7lsIJUA2qzPxhJZ80GCsKR8UK7jOhfd8OgE0+0cw/Nmz6 LX+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="LYB/2WoT"; 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 m4si3628932otn.281.2020.02.14.14.38.31; Fri, 14 Feb 2020 14:38:44 -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="LYB/2WoT"; 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 S1727620AbgBNWiW (ORCPT + 99 others); Fri, 14 Feb 2020 17:38:22 -0500 Received: from mail-yb1-f193.google.com ([209.85.219.193]:37374 "EHLO mail-yb1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727529AbgBNWiW (ORCPT ); Fri, 14 Feb 2020 17:38:22 -0500 Received: by mail-yb1-f193.google.com with SMTP id k69so5571766ybk.4 for ; Fri, 14 Feb 2020 14:38:20 -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=UhXhwNSRwdSyi+H9zMRuLq0WFPtWCQTooj0QtYbRLG8=; b=LYB/2WoTc0NUWQ7WAgvwRxpic7dTAP9/iI+IjkZnQRJx+5k39FyA4S4N3pmh8wcWqz AvLEKE2SjemIzT9ZtDMYJ5uqfQfwIBVHdbyFYDdMnzm8nm8qRGQ7OcBlUWfrU4zHwvZb PhUuwhIPS3pSexguM+13PMLeT8PeHqXx37bpMydKP8fZVFkdxVBVbBNTMz/IMIkXGKFs oE2s8v7rPEwjU9xEMptc3TmOHtHV/g5owFopfH0Fm7rh7Hr8J5cZw9cTWP5dmeyCnXNn rq3L8OW1us+mcfcgMy3ATrfW0PSGDZglwVRh7HmIoFZvLw78Vnokrdl77eiZ6m4SVJW0 eoXQ== 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=UhXhwNSRwdSyi+H9zMRuLq0WFPtWCQTooj0QtYbRLG8=; b=BF5vR4Z/3WbaLRJ8QzG9PP4YG2NoRVOko9TVeK1DPn9eJxNGMRfNUAfw5YKHKl6lNg GmlqbBO5b0bjZpBYZsPcKz2KPQDs5JQW05sk0vX/ws350nA3ZnBHCdhJurgK5FHfY5g5 3SLjE0m5AIUM7AOHDEAsgw1fJFmUDqQD03ES/xnAfvkBvk5nmnwgBw1Sfoa/PngzN/se VjOFmy05iUsTd8LpjPMdnILOwJ8C74cZB9uft7sRhR27sUx9rddVa48GDaYa6CrekTxT veT8gXFPpt09fscu6v0m+bDNuLxhUdwkwN2k38g69thYsmeM/zwtckj4RhHxMXPjb8jz uYpQ== X-Gm-Message-State: APjAAAVuX5Sa1ww1GahFih+ZDw0C/pu4CbPVIOFOFZtYrqgdcPSiuzAz 21eXMAzA9wMJXgRMHvdlgHn88DVy5PiTGgh9Pbu9/Q== X-Received: by 2002:a25:80c5:: with SMTP id c5mr4632219ybm.364.1581719899696; Fri, 14 Feb 2020 14:38:19 -0800 (PST) MIME-Version: 1.0 References: <20200214222415.181467-1-shakeelb@google.com> In-Reply-To: <20200214222415.181467-1-shakeelb@google.com> From: Eric Dumazet Date: Fri, 14 Feb 2020 14:38:08 -0800 Message-ID: Subject: Re: [PATCH v2] cgroup: memcg: net: do not associate sock with unrelated cgroup To: Shakeel Butt Cc: Johannes Weiner , Tejun Heo , Greg Thelen , Michal Hocko , Vladimir Davydov , Andrew Morton , cgroups@vger.kernel.org, linux-mm , Roman Gushchin , 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:24 PM 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. So, when will the association be done ? At accept() time ? Is it done already ? Thanks > > 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. */ > + 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; > } > > + /* 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) > -- > 2.25.0.265.gbab2e86ba0-goog >