Skip to contentSkip to conversation

net: Add l3mdev cgroup

RFC PATCH In review David Ahern 5 participants 10 messages Jan 4, 2016 – Jan 19, 2016 5 messages not in the archive

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 net: Add l3mdev cgroup

Add cgroup to assoicate tasks with L3 networking domains. AF_INET{6} sockets opened by tasks associated with an l3mdev cgroup are bound to the associated master device when the socket is created. This allows a user to run a command (and its children) within an L3 networking context.

The master-device for an l3mdev cgroup must be an L3 master device (e.g., VRF), and it must be set before attaching tasks to the cgroup. Once set the master-device can not change. Nested l3mdev cgroups are not supported. The root (aka default) l3mdev cgroup can not be bound to a master device.

Example:
ip link add vrf-red type vrf table vrf-red
ip link set dev vrf-red up
ip link set dev eth1 master vrf-red

cgcreate -g l3mdev:vrf-red
cgset -r l3mdev.master-device=vrf-red vrf-red
cgexec -g l3mdev:vrf-red bash

At this point the current shell and its child processes are attached to the vrf-red L3 domain. Any AF_INET and AF_INET6 sockets opened by the tasks are bound to the vrf-red device.

TO-DO:
- how to auto-create the cgroup when a VRF device is created and auto-deleted when a VRF device is destroyed

---
 include/linux/cgroup_subsys.h |   3 +
 include/net/l3mdev_cgroup.h   |  27 ++++++
 net/core/sock.c               |   2 +
 net/l3mdev/Kconfig            |  12 +++
 net/l3mdev/Makefile           |   1 +
 net/l3mdev/l3mdev_cgroup.c    | 195 ++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 240 insertions(+)
 create mode 100644 include/net/l3mdev_cgroup.h
 create mode 100644 net/l3mdev/l3mdev_cgroup.c
include/linux/cgroup_subsys.h +3 -0
index 1a96fdaa33d5..507df40f11de 100644
@@ -58,6 +58,9 @@ SUBSYS(net_prio)
 SUBSYS(hugetlb)
 #endif
 
+#if IS_ENABLED(CONFIG_NET_L3_MASTER_DEV)
+SUBSYS(l3mdev)
+#endif
 /*
  * Subsystems that implement the can_fork() family of callbacks.
  */
include/net/l3mdev_cgroup.h new file +27 -0
new file mode 100644
index 000000000000..c20fbb0a7f46
@@ -0,0 +1,27 @@
+/*
+ * l3mdev_cgroup.h		Control Group for L3 Master Device
+ *
+ * Copyright (c) 2015 Cumulus Networks. All rights reserved.
+ * Copyright (c) 2015 David Ahern <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#ifndef _L3MDEV_CGROUP_H
+#define _L3MDEV_CGROUP_H
+
+#if IS_ENABLED(CONFIG_CGROUP_L3MDEV)
+
+void sock_update_l3mdev(struct sock *sk);
+
+#else /* !CONFIG_CGROUP_L3MDEV */
+
+static inline void sock_update_l3mdev(struct sock *sk)
+{
+}
+
+#endif /* CONFIG_CGROUP_L3MDEV */
+#endif /* _L3MDEV_CGROUP_H */
net/core/sock.c +2 -0
index 565bab7baca9..19ce06674dd9 100644
@@ -131,6 +131,7 @@
 #include <linux/ipsec.h>
 #include <net/cls_cgroup.h>
 #include <net/netprio_cgroup.h>
+#include <net/l3mdev_cgroup.h>
 #include <linux/sock_diag.h>
 
 #include <linux/filter.h>
@@ -1424,6 +1425,7 @@ struct sock *sk_alloc(struct net *net, int family, gfp_t priority,
 
 		sock_update_classid(&sk->sk_cgrp_data);
 		sock_update_netprioidx(&sk->sk_cgrp_data);
+		sock_update_l3mdev(sk);
 	}
 
 	return sk;
net/l3mdev/Kconfig +12 -0
index 5d47325037bc..3142d810e222 100644
@@ -8,3 +8,15 @@ config NET_L3_MASTER_DEV
 	---help---
 	  This module provides glue between core networking code and device
 	  drivers to support L3 master devices like VRF.
+
+config CGROUP_L3MDEV
+	bool "L3 Master Device cgroup"
+	depends on CGROUPS
+	depends on NET_L3_MASTER_DEV
+	---help---
+	  Cgroup subsystem for assigning processes to an L3 domain.
+	  When a process is assigned to an l3mdev domain all AF_INET and
+	  AF_INET6 sockets opened by the process are bound to the L3 master
+	  device.
+
+
net/l3mdev/Makefile +1 -0
index 84a53a6f609a..ae74ebad8db7 100644
@@ -3,3 +3,4 @@
 #
 
 obj-$(CONFIG_NET_L3_MASTER_DEV) += l3mdev.o
+obj-$(CONFIG_CGROUP_L3MDEV) += l3mdev_cgroup.o
net/l3mdev/l3mdev_cgroup.c new file +195 -0

195 lines not on this page · raw message

Signature · 1 line
1.9.1
#2 lore raw
In reply to a message not in the archive

Hello, David.

Quoted 11 lines · David Ahern

Add cgroup to assoicate tasks with L3 networking domains. AF_INET{6} sockets opened by tasks associated with an l3mdev cgroup are bound to the associated master device when the socket is created. This allows a user to run a command (and its children) within an L3 networking context.

The master-device for an l3mdev cgroup must be an L3 master device (e.g., VRF), and it must be set before attaching tasks to the cgroup. Once set the master-device can not change. Nested l3mdev cgroups are not supported. The root (aka default) l3mdev cgroup can not be bound to a master device.

Quoted 8 lines

Example:
ip link add vrf-red type vrf table vrf-red
ip link set dev vrf-red up
ip link set dev eth1 master vrf-red

cgcreate -g l3mdev:vrf-red
cgset -r l3mdev.master-device=vrf-red vrf-red
cgexec -g l3mdev:vrf-red bash

Please don't create any new controller whose sole purpose is identifying group membership. Please take a look at how libxt_cgroup handles identification w/o creating a new controller.

http://lkml.kernel.org/g/1449527935-27056-1-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org

Thanks.

Signature · 1 line
tejun
#3 lore raw

Hi Tejun:

Quoted 6 lines · Tejun Heo

Please don't create any new controller whose sole purpose is identifying group membership. Please take a look at how libxt_cgroup handles identification w/o creating a new controller.

http://lkml.kernel.org/g/[email protected]

This controller applies a cgroup specific setting to tasks associated with an instance (similar to cpuset restricting tasks to specifics CPUs), so it is more than just identifying membership.

I looked at the commits referenced above and net/netfilter/xt_cgroup.c code in particular and I don't see how it applies to this use case. Can you elaborate?

Thanks,
David

#5 lore raw
In reply to a message not in the archive

Hello, David.

Quoted 11 lines · David Ahern
Quoted 6 lines · Tejun Heo

Please don't create any new controller whose sole purpose is identifying group membership. Please take a look at how libxt_cgroup handles identification w/o creating a new controller.

http://lkml.kernel.org/g/1449527935-27056-1-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org

This controller applies a cgroup specific setting to tasks associated with an instance (similar to cpuset restricting tasks to specifics CPUs), so it is more than just identifying membership.

Any identification can be mapped back and forth to setting configs to a set of tasks. That doesn't change the fact that all the controller is doing is identifying cgroup membership and the proposed controller shares exatly the same problems as netprio or netcls controllers.

Quoted 3 lines

I looked at the commits referenced above and net/netfilter/xt_cgroup.c code in particular and I don't see how it applies to this use case. Can you elaborate?

Match cgroup membership in whatever subsystem that cares about it and apply the policy there.

Thanks.

Signature · 1 line
tejun
#7 lore raw
In reply to a message not in the archive
Quoted 20 lines · Tejun Heo

Hello, David.

Quoted 11 lines · David Ahern
Quoted 6 lines · Tejun Heo

Please don't create any new controller whose sole purpose is identifying group membership. Please take a look at how libxt_cgroup handles identification w/o creating a new controller.

http://lkml.kernel.org/g/1449527935-27056-1-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org

This controller applies a cgroup specific setting to tasks associated with an instance (similar to cpuset restricting tasks to specifics CPUs), so it is more than just identifying membership.

Any identification can be mapped back and forth to setting configs to a set of tasks. That doesn't change the fact that all the controller is doing is identifying cgroup membership and the proposed controller shares exatly the same problems as netprio or netcls controllers.

Quoted 7 lines
Quoted 3 lines

I looked at the commits referenced above and net/netfilter/xt_cgroup.c code in particular and I don't see how it applies to this use case. Can you elaborate?

Match cgroup membership in whatever subsystem that cares about it and apply the policy there.

None of the existing subsystems are relevant for configuring an L3 networking domain, and it does not make sense to tie net_cls and net_prio to an L3 domain.

maintainer
#8 lore raw

Hello, David.

Quoted 3 lines · David Ahern

None of the existing subsystems are relevant for configuring an L3 networking domain, and it does not make sense to tie net_cls and net_prio to an L3 domain.

I don't have an answer for that but cgroup isn't a place to put such stray configurations either. Please figure out where the configuration belongs first. What you're proposing really isn't a resource controller. There's no resource being distributed hierarchically. It's just dumping configuration which hasn't found its proper place into cgroup.

Thanks.

Signature · 1 line
tejun
#9 lore raw
Quoted 6 lines · Tejun Heo

I don't have an answer for that but cgroup isn't a place to put such stray configurations either. Please figure out where the configuration belongs first. What you're proposing really isn't a resource controller. There's no resource being distributed hierarchically. It's just dumping configuration which hasn't found its proper place into cgroup.

cgroups have very nice properties that I want to leverage such as parent-child inheritance and easy tracking which subsystem instance a task belongs. This provides a great kernel foundation for building easy to use management tools.

The documentation for cgroups does not restrict a controller to physical resources but rather "it may be anything that wants to act on a group of processes." That is exactly what I am doing here - I have a network config that is applied to a group of processes similar to net_cls and net_prio (but as I stated before those are orthogonal, independent settings from the L3 domain).

#11 lore raw
In reply to a message not in the archive

Hello,

Quoted 11 lines · David Ahern

cgroups have very nice properties that I want to leverage such as parent-child inheritance and easy tracking which subsystem instance a task belongs. This provides a great kernel foundation for building easy to use management tools.

The documentation for cgroups does not restrict a controller to physical resources but rather "it may be anything that wants to act on a group of processes." That is exactly what I am doing here - I have a network config that is applied to a group of processes similar to net_cls and net_prio (but as I stated before those are orthogonal, independent settings from the L3 domain).

Please read the new version of cgroup documentation.

https://git.kernel.org/cgit/linux/kernel/git/tj/cgroup.git/tree/Documentation/cgroup.txt?h=for-4.5

cgroup has experienced a lot of problems doing its main job - hierarchical resource control - from trying to support random things which want to group threads. As shown with xt_cgroup, such identifying usages can be implemented in a way where the subsystem matches the membership rather than cgroup taking in configurations which belong to the subsystem, so please investigate that direction.

Thanks.

Signature · 1 line
tejun
#13 lore raw
In reply to a message not in the archive
Quoted 19 lines · On Mon, 4 Jan 2016 15:05:18 -0500 Tejun Heo…

Hello,

Quoted 11 lines · David Ahern

cgroups have very nice properties that I want to leverage such as parent-child inheritance and easy tracking which subsystem instance a task belongs. This provides a great kernel foundation for building easy to use management tools.

The documentation for cgroups does not restrict a controller to physical resources but rather "it may be anything that wants to act on a group of processes." That is exactly what I am doing here - I have a network config that is applied to a group of processes similar to net_cls and net_prio (but as I stated before those are orthogonal, independent settings from the L3 domain).

Please read the new version of cgroup documentation.

https://git.kernel.org/cgit/linux/kernel/git/tj/cgroup.git/tree/Documentation/cgroup.txt?h=for-4.5

Quoted 9 lines

cgroup has experienced a lot of problems doing its main job - hierarchical resource control - from trying to support random things which want to group threads. As shown with xt_cgroup, such identifying usages can be implemented in a way where the subsystem matches the membership rather than cgroup taking in configurations which belong to the subsystem, so please investigate that direction.

Thanks.

Policy like this belongs in userspace not kernel.

#14 lore raw
Quoted 29 lines · Stephen Hemminger
Quoted 26 lines · On Mon, 4 Jan 2016 15:05:18 -0500 Tejun Heo <[email protected]> wrote:

Hello,

Quoted 11 lines · David Ahern

cgroups have very nice properties that I want to leverage such as parent-child inheritance and easy tracking which subsystem instance a task belongs. This provides a great kernel foundation for building easy to use management tools.

The documentation for cgroups does not restrict a controller to physical resources but rather "it may be anything that wants to act on a group of processes." That is exactly what I am doing here - I have a network config that is applied to a group of processes similar to net_cls and net_prio (but as I stated before those are orthogonal, independent settings from the L3 domain).

Please read the new version of cgroup documentation.

https://git.kernel.org/cgit/linux/kernel/git/tj/cgroup.git/tree/Documentation/cgroup.txt?h=for-4.5

cgroup has experienced a lot of problems doing its main job - hierarchical resource control - from trying to support random things which want to group threads. As shown with xt_cgroup, such identifying usages can be implemented in a way where the subsystem matches the membership rather than cgroup taking in configurations which belong to the subsystem, so please investigate that direction.

Quoted 5 lines
Quoted 2 lines

Thanks.

Policy like this belongs in userspace not kernel.

This is the infrastructure that allows userspace to implement a policy - the policy being binding tasks and their children to an L3 domain.