Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1149486pxk; Fri, 18 Sep 2020 05:15:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyJrY8npd2ZU9duV+KICHT83DVjl1iwJafnBqHB4CnTQhV96F9KQ01RkHCrJyJFiz+ShpTR X-Received: by 2002:a17:906:3791:: with SMTP id n17mr34984779ejc.216.1600431332063; Fri, 18 Sep 2020 05:15:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600431332; cv=none; d=google.com; s=arc-20160816; b=XKuWt2fwCmFGEatZLhkitsTHTkKfLCS7ypyeNKFkXsJ6F3F6U1N0DmkYQ27xGU1xGn lfgcPxE2mIXbyDDfSCBUGuC1G+67fe7DEVxT3ss1Om0FDxRBLg2berGeSfFwOKAUt3rQ ZAO2hSp9IIZXoRQP7o0/5hh4BXHGEYpsIz6gPhtsRSZY16AMC6PNokWYtut0p4KIf+bo NKPMNlR3NsW+/0ZLe95wpGHFsBmmi1+Lz8be4wZLhxAVAQjmA47lk3tnqSBPddbcFIIv wwqFo4+fv0412J4bl2oTTQVKi03BiKEX+U/6VXkYVaUEGvcJjmtSX6bOeYBSD+T2yoON VX5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=LwJh2Jg+llItfiPMDTwpwTSCiYeiFLD+g/KxngTUH6c=; b=pRoneVrIA7JiSyuc3fRCF4JDIhsLt9UF9mrYaR5LzmpNlHT7evepfE1OaMHh2VO4nn kxCwSmJbwRwK9qN0KYjt8Q1qIvKDVb4lv0+5aEj6UKPYSGSjPemIyx7RZoM8xu9c0xil yhkJF90w2oDMau+Dqn/mPP+rINVfY3ysYVHjE6uCKKqwrA1BY7X9qpO0QypkR86U542U 6xIAP6KTDsQX5k8PuT05xB3d2j69bSwKJgV1mmSgLfhpCXKE4Y6yPi5/dNCLsttqdtcS T3Znn65LdR2ol8Sj6r4AL9hpoNyrJPg/9GE7X018fIbPlP8Q1jyYovM8ODwIydAIE3kD 1CKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@tessares-net.20150623.gappssmtp.com header.s=20150623 header.b=oVYgTbto; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gv24si2026815ejb.258.2020.09.18.05.15.08; Fri, 18 Sep 2020 05:15:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@tessares-net.20150623.gappssmtp.com header.s=20150623 header.b=oVYgTbto; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726687AbgIRMMo (ORCPT + 99 others); Fri, 18 Sep 2020 08:12:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725900AbgIRMMk (ORCPT ); Fri, 18 Sep 2020 08:12:40 -0400 Received: from mail-ej1-x642.google.com (mail-ej1-x642.google.com [IPv6:2a00:1450:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E50BC061756 for ; Fri, 18 Sep 2020 05:12:40 -0700 (PDT) Received: by mail-ej1-x642.google.com with SMTP id z23so7722539ejr.13 for ; Fri, 18 Sep 2020 05:12:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tessares-net.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LwJh2Jg+llItfiPMDTwpwTSCiYeiFLD+g/KxngTUH6c=; b=oVYgTbtocYLwTQ1yDb79D0yPhf6zQUR/yDffS2xPh2VZAMUm+h9otvXx+Qz3g1VutF uYV1VSEospDv5SxawHAukf9jwaZWhX5AsRc9SiXfuaf/dqhr/XOGK8LSOhXV9u1HwCM9 HpZO+So0GJCh1GXsLz1CINYFnd6HCHcVCaz8v/JdqMV8Rc3rF/MoRk5SPBpZq4UBp84z vyWOb/tlbC5hT3nvNLsI33uipWVEAH/07E5sFXPpy7C1KkgyQEkWb3Sly9MP6wTfK1eU yNcLP/hncGwkNh9YxByvD59pl/F4s/R0amoOTK8ZpGJGaJK5ohOb3qHjAHwufNqJgeRc fBWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LwJh2Jg+llItfiPMDTwpwTSCiYeiFLD+g/KxngTUH6c=; b=PKG9kJyEKV8YEuJtUyFUzOWWppOx8Y2moocheGLtF0tocTK1wqwlXesW6p0KdLbw/8 D4nQX0Unc75pzq6XMhXU/gwPthyoZYIhM+5Y1iJmiNlLC0yJEYA1txoiQWHgouvtlYfG AvJKn0m/EuTBcsLMjMoFNZOIWnwpfM8lUW6Z+Qt5Uku5q+plkUKWYjg8RU1UCn/lCJFw CkwYx/fvIo1ZyGkOZ3ppgVe/Ca1cOgADRKr075OOgx2ZosM3FSzchMzy5HtNRDL40JAm oaIIIQ50iqSWlsbll/m0ZbrWFIQNfREW+DBeVtH5ENIZDfcd9ykQ1yJY3HNxcIO0SyhH El9Q== X-Gm-Message-State: AOAM530GRj9ycnrr21T4VRS8+bWIfFSPjpm/eEiY/6s+fZFb8CgD+QCu d/vU9CWM0+hPX9fdbfuzl1tWmQ== X-Received: by 2002:a17:906:cb92:: with SMTP id mf18mr37269577ejb.485.1600431158958; Fri, 18 Sep 2020 05:12:38 -0700 (PDT) Received: from localhost.localdomain ([87.66.33.240]) by smtp.gmail.com with ESMTPSA id h64sm2084555edd.50.2020.09.18.05.12.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Sep 2020 05:12:38 -0700 (PDT) From: Nicolas Rybowski To: Mat Martineau , Matthieu Baerts , "David S. Miller" , Jakub Kicinski , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , Andrii Nakryiko , John Fastabend , KP Singh Cc: Nicolas Rybowski , Paolo Abeni , netdev@vger.kernel.org, mptcp@lists.01.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH bpf-next v3 2/5] mptcp: attach subflow socket to parent cgroup Date: Fri, 18 Sep 2020 14:10:41 +0200 Message-Id: <20200918121046.190240-2-nicolas.rybowski@tessares.net> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200918121046.190240-1-nicolas.rybowski@tessares.net> References: <20200918121046.190240-1-nicolas.rybowski@tessares.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It has been observed that the kernel sockets created for the subflows (except the first one) are not in the same cgroup as their parents. That's because the additional subflows are created by kernel workers. This is a problem with eBPF programs attached to the parent's cgroup won't be executed for the children. But also with any other features of CGroup linked to a sk. This patch fixes this behaviour. As the subflow sockets are created by the kernel, we can't use 'mem_cgroup_sk_alloc' because of the current context being the one of the kworker. This is why we have to do low level memcg manipulation, if required. Suggested-by: Matthieu Baerts Suggested-by: Paolo Abeni Acked-by: Matthieu Baerts Reviewed-by: Mat Martineau Acked-by: Song Liu Signed-off-by: Nicolas Rybowski --- net/mptcp/subflow.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c index e8cac2655c82..535a3f9f8cfc 100644 --- a/net/mptcp/subflow.c +++ b/net/mptcp/subflow.c @@ -1130,6 +1130,30 @@ int __mptcp_subflow_connect(struct sock *sk, int ifindex, return err; } +static void mptcp_attach_cgroup(struct sock *parent, struct sock *child) +{ +#ifdef CONFIG_SOCK_CGROUP_DATA + struct sock_cgroup_data *parent_skcd = &parent->sk_cgrp_data, + *child_skcd = &child->sk_cgrp_data; + + /* only the additional subflows created by kworkers have to be modified */ + if (cgroup_id(sock_cgroup_ptr(parent_skcd)) != + cgroup_id(sock_cgroup_ptr(child_skcd))) { +#ifdef CONFIG_MEMCG + struct mem_cgroup *memcg = parent->sk_memcg; + + mem_cgroup_sk_free(child); + if (memcg && css_tryget(&memcg->css)) + child->sk_memcg = memcg; +#endif /* CONFIG_MEMCG */ + + cgroup_sk_free(child_skcd); + *child_skcd = *parent_skcd; + cgroup_sk_clone(child_skcd); + } +#endif /* CONFIG_SOCK_CGROUP_DATA */ +} + int mptcp_subflow_create_socket(struct sock *sk, struct socket **new_sock) { struct mptcp_subflow_context *subflow; @@ -1150,6 +1174,9 @@ int mptcp_subflow_create_socket(struct sock *sk, struct socket **new_sock) lock_sock(sf->sk); + /* the newly created socket has to be in the same cgroup as its parent */ + mptcp_attach_cgroup(sk, sf->sk); + /* kernel sockets do not by default acquire net ref, but TCP timer * needs it. */ -- 2.28.0