[PATCH v0 0/4] Rework net_cls update socket logic

STALE5105d

4 messages, 3 authors, 2012-10-17 · open the first message on its own page

[PATCH v0 0/4] Rework net_cls update socket logic

From: Daniel Wagner <hidden>
Date: 2012-10-17 13:04:42

From: Daniel Wagner <redacted>

Hi,

This series updates net_cls to use the same socket update logic as
net_prio. With this change sock_update_classid() is not called from
recvmsg, sendmsg and friends anymore. This seems to be a good idea.

Credit goes to John Fastabend for this work.

The patches are against net-next.

cheers,
daniel

Cc:  Li Zefan <redacted>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Eric Dumazet <redacted>
Cc: Glauber Costa <redacted>
Cc: Jamal Hadi Salim <jhs@mojatatu.com>
Cc: Joe Perches <joe@perches.com>
Cc: John Fastabend <redacted>
Cc: Li Zefan <redacted>
Cc: Neil Horman <nhorman@tuxdriver.com>
Cc: Stanislav Kinsbursky <redacted>
Cc: Tejun Heo <tj@kernel.org>
Cc: <redacted>
Cc: <redacted>

Daniel Wagner (4):
  cgroup: net_prio: Mark local used function static
  cgroup: net_cls: Fix local variable type decleration
  cgroup: net_cls: Pass in task to sock_update_classid()
  cgroup: net_cls: Rework update socket logic

 drivers/net/tun.c         |  3 ---
 include/net/cls_cgroup.h  |  4 ++--
 net/core/netprio_cgroup.c |  2 +-
 net/core/sock.c           |  6 +++---
 net/sched/cls_cgroup.c    | 38 ++++++++++++++++++++++++++++++++++++++
 net/socket.c              |  8 --------
 6 files changed, 44 insertions(+), 17 deletions(-)

-- 
1.7.11.4

[PATCH v0 3/4] cgroup: net_cls: Pass in task to sock_update_classid()

From: Daniel Wagner <hidden>
Date: 2012-10-17 13:04:44

From: Daniel Wagner <redacted>

sock_update_classid() assumes that the update operation always are
applied on the current task. sock_update_classid() needs to know on
which tasks to work on in order to be able to migrate task between
cgroups using the struct cgroup_subsys attach() callback.

Signed-off-by: Daniel Wagner <redacted>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Eric Dumazet <redacted>
Cc: Glauber Costa <redacted>
Cc: Joe Perches <joe@perches.com>
Cc: Neil Horman <nhorman@tuxdriver.com>
Cc: Stanislav Kinsbursky <redacted>
Cc: Tejun Heo <tj@kernel.org>
Cc: <redacted>
Cc: <redacted>
---
 drivers/net/tun.c        | 2 +-
 include/net/cls_cgroup.h | 2 +-
 net/core/sock.c          | 6 +++---
 net/socket.c             | 8 ++++----
 4 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index 0873cdc..e4858b2 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -587,7 +587,7 @@ static struct sk_buff *tun_alloc_skb(struct tun_struct *tun,
 	struct sk_buff *skb;
 	int err;
 
-	sock_update_classid(sk);
+	sock_update_classid(sk, current);
 
 	/* Under a page?  Don't bother with paged skb. */
 	if (prepad + len < PAGE_SIZE || !linear)
diff --git a/include/net/cls_cgroup.h b/include/net/cls_cgroup.h
index 0fee061..571de6e 100644
--- a/include/net/cls_cgroup.h
+++ b/include/net/cls_cgroup.h
@@ -24,7 +24,7 @@ struct cgroup_cls_state
 	u32 classid;
 };
 
-extern void sock_update_classid(struct sock *sk);
+extern void sock_update_classid(struct sock *sk, struct task_struct *task);
 
 #if IS_BUILTIN(CONFIG_NET_CLS_CGROUP)
 static inline u32 task_cls_classid(struct task_struct *p)
diff --git a/net/core/sock.c b/net/core/sock.c
index 8a146cf..68c2f3b 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -1214,12 +1214,12 @@ static void sk_prot_free(struct proto *prot, struct sock *sk)
 
 #ifdef CONFIG_CGROUPS
 #if IS_ENABLED(CONFIG_NET_CLS_CGROUP)
-void sock_update_classid(struct sock *sk)
+void sock_update_classid(struct sock *sk, struct task_struct *task)
 {
 	u32 classid;
 
 	rcu_read_lock();  /* doing current task, which cannot vanish. */
-	classid = task_cls_classid(current);
+	classid = task_cls_classid(task);
 	rcu_read_unlock();
 	if (classid != sk->sk_classid)
 		sk->sk_classid = classid;
@@ -1263,7 +1263,7 @@ struct sock *sk_alloc(struct net *net, int family, gfp_t priority,
 		sock_net_set(sk, get_net(net));
 		atomic_set(&sk->sk_wmem_alloc, 1);
 
-		sock_update_classid(sk);
+		sock_update_classid(sk, current);
 		sock_update_netprioidx(sk, current);
 	}
 
diff --git a/net/socket.c b/net/socket.c
index 80dc7e8..b38aff9 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -625,7 +625,7 @@ static inline int __sock_sendmsg_nosec(struct kiocb *iocb, struct socket *sock,
 {
 	struct sock_iocb *si = kiocb_to_siocb(iocb);
 
-	sock_update_classid(sock->sk);
+	sock_update_classid(sock->sk, current);
 
 	si->sock = sock;
 	si->scm = NULL;
@@ -789,7 +789,7 @@ static inline int __sock_recvmsg_nosec(struct kiocb *iocb, struct socket *sock,
 {
 	struct sock_iocb *si = kiocb_to_siocb(iocb);
 
-	sock_update_classid(sock->sk);
+	sock_update_classid(sock->sk, current);
 
 	si->sock = sock;
 	si->scm = NULL;
@@ -901,7 +901,7 @@ static ssize_t sock_splice_read(struct file *file, loff_t *ppos,
 	if (unlikely(!sock->ops->splice_read))
 		return -EINVAL;
 
-	sock_update_classid(sock->sk);
+	sock_update_classid(sock->sk, current);
 
 	return sock->ops->splice_read(sock, ppos, pipe, len, flags);
 }
@@ -3421,7 +3421,7 @@ EXPORT_SYMBOL(kernel_setsockopt);
 int kernel_sendpage(struct socket *sock, struct page *page, int offset,
 		    size_t size, int flags)
 {
-	sock_update_classid(sock->sk);
+	sock_update_classid(sock->sk, current);
 
 	if (sock->ops->sendpage)
 		return sock->ops->sendpage(sock, page, offset, size, flags);
-- 
1.7.11.4

Re: [PATCH v0 3/4] cgroup: net_cls: Pass in task to sock_update_classid()

From: Eric Dumazet <hidden>
Date: 2012-10-17 13:37:27

On Wed, 2012-10-17 at 15:04 +0200, Daniel Wagner wrote:
From: Daniel Wagner <redacted>

sock_update_classid() assumes that the update operation always are
applied on the current task. sock_update_classid() needs to know on
which tasks to work on in order to be able to migrate task between
cgroups using the struct cgroup_subsys attach() callback.
...
quoted hunk
 
-extern void sock_update_classid(struct sock *sk);
+extern void sock_update_classid(struct sock *sk, struct task_struct *task);
 
 #if IS_BUILTIN(CONFIG_NET_CLS_CGROUP)
 static inline u32 task_cls_classid(struct task_struct *p)
diff --git a/net/core/sock.c b/net/core/sock.c
index 8a146cf..68c2f3b 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -1214,12 +1214,12 @@ static void sk_prot_free(struct proto *prot, struct sock *sk)
 
 #ifdef CONFIG_CGROUPS
 #if IS_ENABLED(CONFIG_NET_CLS_CGROUP)
-void sock_update_classid(struct sock *sk)
+void sock_update_classid(struct sock *sk, struct task_struct *task)
 {
 	u32 classid;
 
 	rcu_read_lock();  /* doing current task, which cannot vanish. */
-	classid = task_cls_classid(current);
+	classid = task_cls_classid(task);
 	rcu_read_unlock();

Comment is now misleading (since task might not be current) and
rcu_read_lock()/rcu_read_unlock() protects nothing here, but avoid a
lockdep splat...

Hey task_cls_classid() has its own rcu protection since commit
3fb5a991916091a908d (cls_cgroup: Fix rcu lockdep warning)

So we can safely revert Paul commit (1144182a8757f2a1)
(We no longer need rcu_read_lock/unlock here)

(BTW net-next is not opened yet, its content outdated, although I like
your patch series !)

Re: [PATCH v0 3/4] cgroup: net_cls: Pass in task to sock_update_classid()

From: Daniel Wagner <hidden>
Date: 2012-10-17 15:54:40

On 17.10.2012 15:37, Eric Dumazet wrote:
On Wed, 2012-10-17 at 15:04 +0200, Daniel Wagner wrote:
quoted
From: Daniel Wagner <redacted>

sock_update_classid() assumes that the update operation always are
applied on the current task. sock_update_classid() needs to know on
which tasks to work on in order to be able to migrate task between
cgroups using the struct cgroup_subsys attach() callback.
...
quoted

-extern void sock_update_classid(struct sock *sk);
+extern void sock_update_classid(struct sock *sk, struct task_struct *task);

  #if IS_BUILTIN(CONFIG_NET_CLS_CGROUP)
  static inline u32 task_cls_classid(struct task_struct *p)
diff --git a/net/core/sock.c b/net/core/sock.c
index 8a146cf..68c2f3b 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -1214,12 +1214,12 @@ static void sk_prot_free(struct proto *prot, struct sock *sk)

  #ifdef CONFIG_CGROUPS
  #if IS_ENABLED(CONFIG_NET_CLS_CGROUP)
-void sock_update_classid(struct sock *sk)
+void sock_update_classid(struct sock *sk, struct task_struct *task)
  {
  	u32 classid;

  	rcu_read_lock();  /* doing current task, which cannot vanish. */
-	classid = task_cls_classid(current);
+	classid = task_cls_classid(task);
  	rcu_read_unlock();

Comment is now misleading (since task might not be current) and
rcu_read_lock()/rcu_read_unlock() protects nothing here, but avoid a
lockdep splat...

Hey task_cls_classid() has its own rcu protection since commit
3fb5a991916091a908d (cls_cgroup: Fix rcu lockdep warning)

So we can safely revert Paul commit (1144182a8757f2a1)
(We no longer need rcu_read_lock/unlock here)
Good point. Will update the series accordingly.
(BTW net-next is not opened yet, its content outdated, although I like
your patch series !)
I still have not figured all details on the patch submission procedure. Sorry about that. The time to send patches for net-next will be annonced by David, is this correct?
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help