Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp2256586ybv; Fri, 14 Feb 2020 14:50:44 -0800 (PST) X-Google-Smtp-Source: APXvYqzU/ZrwNQXAK7NfD91tiMKFLujpKE7uuITIKmTBhN7rwRXmYVXxEP9XTjk5ebX4AC4Z28uW X-Received: by 2002:a05:6830:1d93:: with SMTP id y19mr4164352oti.350.1581720644361; Fri, 14 Feb 2020 14:50:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581720644; cv=none; d=google.com; s=arc-20160816; b=S1fO2XiZGvslSotx10Wc859Yi3Nq12yS7mT82vfTW7biecYRBVZR+fZv60c2nMU8FO Q1AeSe3Moyc/rPfCnlT6venPwJIZr/C03jHnctsKVUOT6hS/vO7dBcY/u3XP4KKxF0sn +OpQfU4TTAKr2k8FmAeiNzcYAShhqE+colGVPD9YodvyLrOhcwHenti5Ttq+ga6nT0V7 0zIncbXjY59AyRJ+CuZmA9IQ7i972i2tY8xoW9+BAGnRTUCVjs/Fyf7uZR14aFaiF3Gy 4MTA57f28Qaog81yBw3gsAtIY8jRDRbaIz85I1Uj9IrXEUKaLwCixJWV0X7dMKzZZDDA hb7Q== 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=TgoIP7Jshrn2duDl/cLkfq4CVlTeMc4BWp5pc4aKy4o=; b=OChCEWXv1B9aQldusB1acoBWZ42qmpryy8L3YclpHsyC9UQaNZYYq5lmiuzOW7r/Sa 19XZYxt7lGH2Hb442W6GFfIX8sngMgqgec21OiWPDl0k2e4qW0EluFA8ek5wePuJnmmH rXm63IwmWDg4X+qBdax7adM7GEI2RQtEaSQPRcMyBvPRKfmbQzdrXq9tHMp4qZ7/PZEo 8BVjOn4DxLxUNF3mhtGQF9LuVYLz4YhjIGzcCYg4ay7WETRRCGn96WMt2/BVwBIVe6oA THjzvDr4i6XEryHIny/ajLyXZLCBFDWgNV7H5fhZtRA2pMqehRxnTJq5NrxePH8s6lYY 21OQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=MhgOWYPo; 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 w202si3584463oif.121.2020.02.14.14.50.32; Fri, 14 Feb 2020 14:50: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=MhgOWYPo; 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 S1727857AbgBNWs6 (ORCPT + 99 others); Fri, 14 Feb 2020 17:48:58 -0500 Received: from mail-oi1-f196.google.com ([209.85.167.196]:33950 "EHLO mail-oi1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727815AbgBNWs6 (ORCPT ); Fri, 14 Feb 2020 17:48:58 -0500 Received: by mail-oi1-f196.google.com with SMTP id l136so10996214oig.1 for ; Fri, 14 Feb 2020 14:48:57 -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=TgoIP7Jshrn2duDl/cLkfq4CVlTeMc4BWp5pc4aKy4o=; b=MhgOWYPob9S6aZV6qa2b7vLLaVDvt275tODnygTV/CKd8wZi8f724KWNlUCRxs5mjH DCM690tw83yBr2LORN0E+j9ll5bD4HHOlWoWsl86QrhEuZIsmxOjBealBDm00d5vtezR vUaYfoe/EyPW0Yufblun637lPw3LqF5RI0rMvLWN47ZAf9ujyHXOjVyP4Qfo2c271JS9 7rUY48zxABcoVUIkQPtg+0T4o5KmUJuvDUzJxKTBOgxeCBg2ZxJDuziggGbCQ9scH07Z 1lMwyvU0Aa05SCjGeSZN7Mw6D5wbI4rvxo452JwFeUFIe8Ry6FtSz9LrvBReh5+rLGI4 jBsA== 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=TgoIP7Jshrn2duDl/cLkfq4CVlTeMc4BWp5pc4aKy4o=; b=BaKis2DIkBctyJceopeUAfbHFG35wTYYtLIKqEa1hN1KivJbIIdIOO509OWmXAv2L1 dLUjIhzbwOSOjL61jjpi8cXnYf7cAti8zuyOTEeOeM/oAWX90treY7TdiNJxqQLnWcqs 1i/lGJmlLQfwy9TJ0XKN7RYCMQz/vXxyaepM6sx0WA6UFu245c3JfN3C1kL/aZkIzEAx F6/t1djMcDhmIg1CnGl9ZWoL/7ISSSiDeLQEPvQUGMAND4WHuINFwXtuwvqMx5geEw0z DIqTaMGNwUbkF94xslqX2b65mwV8WHuEyKBBEwIqgvkMAyW0vYpAxNA2lbxnrCvulUyP xcrw== X-Gm-Message-State: APjAAAXii0z3qf2s6gbNJm1nZDbIFkcifSZv4AGRdSVRB5lBk9mMw90T F3KHCAtluixhAceFx6sj+c51RKCgYSltbzHA554pgA== X-Received: by 2002:aca:6542:: with SMTP id j2mr3470435oiw.69.1581720536963; Fri, 14 Feb 2020 14:48:56 -0800 (PST) MIME-Version: 1.0 References: <20200214222415.181467-1-shakeelb@google.com> In-Reply-To: From: Shakeel Butt Date: Fri, 14 Feb 2020 14:48:46 -0800 Message-ID: Subject: Re: [PATCH v2] cgroup: memcg: net: do not associate sock with unrelated cgroup To: Eric Dumazet Cc: Johannes Weiner , Tejun Heo , Greg Thelen , Michal Hocko , Vladimir Davydov , Andrew Morton , Cgroups , 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:38 PM Eric Dumazet wrote: > > 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 ? > I think in the current code if the association is skipped at allocation time then the sock will remain unassociated for its lifetime. Maybe we can add the association in the later stages but it seems like it is not a simple task i.e. edbe69ef2c90f ("Revert "defer call to mem_cgroup_sk_alloc()""). Shakeel