* [BUG] Bug in netprio_cgroup and netcls_cgroup ? @ 2013-01-21 6:08 Li Zefan [not found] ` <50FCDB5C.4050608-hv44wF8Li93QT0dZR+AlfA@public.gmane.org> 0 siblings, 1 reply; 12+ messages in thread From: Li Zefan @ 2013-01-21 6:08 UTC (permalink / raw) To: John Fastabend, Neil Horman, Daniel Wagner Cc: LKML, netdev-u79uwXL29TY76Z2rM5mHXA, Cgroups I'm not a network developer, so correct me if I'm wrong. Since commit 406a3c638ce8b17d9704052c07955490f732c2b8 ("net: netprio_cgroup: rework update socket logic"), sock->sk->sk_cgrp_prioidx is set when the socket is created, and won't be updated unless the task is moved to another cgroup. Now the problem is, a socket can be _shared_ by multiple processes (fork, SCM_RIGHT). If we place those processes in different cgroups, and each cgroup has different configs, but all of the processes will send data via this socket with the same network priority. Similar with cls cgroup. ^ permalink raw reply [flat|nested] 12+ messages in thread
[parent not found: <50FCDB5C.4050608-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>]
* Re: [BUG] Bug in netprio_cgroup and netcls_cgroup ? [not found] ` <50FCDB5C.4050608-hv44wF8Li93QT0dZR+AlfA@public.gmane.org> @ 2013-01-21 8:50 ` Daniel Wagner [not found] ` <50FD0144.1000401-kQCPcA+X3s7YtjvyW6yDsg@public.gmane.org> 0 siblings, 1 reply; 12+ messages in thread From: Daniel Wagner @ 2013-01-21 8:50 UTC (permalink / raw) To: Li Zefan Cc: John Fastabend, Neil Horman, Daniel Wagner, LKML, netdev-u79uwXL29TY76Z2rM5mHXA, Cgroups Hi Li, On 21.01.2013 07:08, Li Zefan wrote: > I'm not a network developer, so correct me if I'm wrong. > > Since commit 7955490f732c2b8 > ("net: netprio_cgroup: rework update socket logic"), sock->sk->sk_cgrp_prioidx > is set when the socket is created, and won't be updated unless the task is > moved to another cgroup. > > Now the problem is, a socket can be _shared_ by multiple processes (fork, SCM_RIGHT). > If we place those processes in different cgroups, and each cgroup has > different configs, but all of the processes will send data via this socket > with the same network priority. Wouldn't that be addressed by 48a87cc26c13b68f6cce4e9d769fcb17a6b3e4b8 net: netprio: fd passed in SCM_RIGHTS datagram not set correctly A socket fd passed in a SCM_RIGHTS datagram was not getting updated with the new tasks cgrp prioidx. This leaves IO on the socket tagged with the old tasks priority. To fix this add a check in the scm recvmsg path to update the sock cgrp prioidx with the new tasks value. As I read this this should work for net_prio. > Similar with cls cgroup. but not for cls_cgroup because I forgot to apply that fix as well. Just a sec, about to send a patch for this. Thanks for looking into this! cheers, daniel ^ permalink raw reply [flat|nested] 12+ messages in thread
[parent not found: <50FD0144.1000401-kQCPcA+X3s7YtjvyW6yDsg@public.gmane.org>]
* Re: [BUG] Bug in netprio_cgroup and netcls_cgroup ? [not found] ` <50FD0144.1000401-kQCPcA+X3s7YtjvyW6yDsg@public.gmane.org> @ 2013-01-21 9:01 ` Li Zefan [not found] ` <50FD0402.6060400-hv44wF8Li93QT0dZR+AlfA@public.gmane.org> 0 siblings, 1 reply; 12+ messages in thread From: Li Zefan @ 2013-01-21 9:01 UTC (permalink / raw) To: Daniel Wagner Cc: John Fastabend, Neil Horman, Daniel Wagner, LKML, netdev-u79uwXL29TY76Z2rM5mHXA, Cgroups On 2013/1/21 16:50, Daniel Wagner wrote: > Hi Li, > > On 21.01.2013 07:08, Li Zefan wrote: >> I'm not a network developer, so correct me if I'm wrong. >> >> Since commit 7955490f732c2b8 >> ("net: netprio_cgroup: rework update socket logic"), sock->sk->sk_cgrp_prioidx >> is set when the socket is created, and won't be updated unless the task is >> moved to another cgroup. >> >> Now the problem is, a socket can be _shared_ by multiple processes (fork, SCM_RIGHT). >> If we place those processes in different cgroups, and each cgroup has >> different configs, but all of the processes will send data via this socket >> with the same network priority. > > Wouldn't that be addressed by 48a87cc26c13b68f6cce4e9d769fcb17a6b3e4b8 > > net: netprio: fd passed in SCM_RIGHTS datagram not set correctly > > A socket fd passed in a SCM_RIGHTS datagram was not getting > updated with the new tasks cgrp prioidx. This leaves IO on > the socket tagged with the old tasks priority. > > To fix this add a check in the scm recvmsg path to update the > sock cgrp prioidx with the new tasks value. > > As I read this this should work for net_prio. > But after process A passed the socket fd to B, both A and B can use the same socket to send data, right? Then if A and B were placed in different cgroups with differnt configs, A's config won't take effect anymore. Am I missing something? ^ permalink raw reply [flat|nested] 12+ messages in thread
[parent not found: <50FD0402.6060400-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>]
* Re: [BUG] Bug in netprio_cgroup and netcls_cgroup ? [not found] ` <50FD0402.6060400-hv44wF8Li93QT0dZR+AlfA@public.gmane.org> @ 2013-01-21 9:21 ` John Fastabend [not found] ` <50FD0893.1050805-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 2013-01-21 9:27 ` Daniel Wagner 1 sibling, 1 reply; 12+ messages in thread From: John Fastabend @ 2013-01-21 9:21 UTC (permalink / raw) To: Li Zefan Cc: Daniel Wagner, John Fastabend, Neil Horman, Daniel Wagner, LKML, netdev-u79uwXL29TY76Z2rM5mHXA, Cgroups On 01/21/2013 01:01 AM, Li Zefan wrote: > On 2013/1/21 16:50, Daniel Wagner wrote: >> Hi Li, >> >> On 21.01.2013 07:08, Li Zefan wrote: >>> I'm not a network developer, so correct me if I'm wrong. >>> >>> Since commit 7955490f732c2b8 >>> ("net: netprio_cgroup: rework update socket logic"), sock->sk->sk_cgrp_prioidx >>> is set when the socket is created, and won't be updated unless the task is >>> moved to another cgroup. >>> >>> Now the problem is, a socket can be _shared_ by multiple processes (fork, SCM_RIGHT). >>> If we place those processes in different cgroups, and each cgroup has >>> different configs, but all of the processes will send data via this socket >>> with the same network priority. >> >> Wouldn't that be addressed by 48a87cc26c13b68f6cce4e9d769fcb17a6b3e4b8 >> >> net: netprio: fd passed in SCM_RIGHTS datagram not set correctly >> >> A socket fd passed in a SCM_RIGHTS datagram was not getting >> updated with the new tasks cgrp prioidx. This leaves IO on >> the socket tagged with the old tasks priority. >> >> To fix this add a check in the scm recvmsg path to update the >> sock cgrp prioidx with the new tasks value. >> >> As I read this this should work for net_prio. >> > > But after process A passed the socket fd to B, both A and B can use the > same socket to send data, right? Then if A and B were placed in different > cgroups with differnt configs, A's config won't take effect anymore. > > Am I missing something? > > Hi Zefan, Neil and I discusses this here, http://patchwork.ozlabs.org/patch/172343/ look towards the bottom of the thread. Quoted here. >> I like the idea, but IIRC last time we tried this I think it caused problems >> with processes that shared sockets. That is to say, if you have a parent and >> child process that dup an socket descriptior, and put them in separate cgroups, >> you get unpredictable results, as the socket gets assigned a priority based on >> the last processed that moved cgroups. >> >> Neil >> > > Shared sockets creates strange behavior as it exists today. If a dup > of the socket fd is created the private data is still shared right. So > in this case the sk_cgrp_prioidx value is going to get updated by both > threads and then it is a race to see what it happens to be set to in > the xmit path. > > With this patch at least the behavior is deterministic. Without it > I can create the above scenario but have no way to determine what the > skb priority will actually be set to. > Its unfortunate but I'm not sure how to fix it off hand with the shared value in the socket. .John -- John Fastabend Intel Corporation ^ permalink raw reply [flat|nested] 12+ messages in thread
[parent not found: <50FD0893.1050805-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>]
* Re: [BUG] Bug in netprio_cgroup and netcls_cgroup ? [not found] ` <50FD0893.1050805-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> @ 2013-01-21 9:52 ` Li Zefan 0 siblings, 0 replies; 12+ messages in thread From: Li Zefan @ 2013-01-21 9:52 UTC (permalink / raw) To: John Fastabend Cc: Daniel Wagner, John Fastabend, Neil Horman, Daniel Wagner, LKML, netdev-u79uwXL29TY76Z2rM5mHXA, Cgroups On 2013/1/21 17:21, John Fastabend wrote: > On 01/21/2013 01:01 AM, Li Zefan wrote: >> On 2013/1/21 16:50, Daniel Wagner wrote: >>> Hi Li, >>> >>> On 21.01.2013 07:08, Li Zefan wrote: >>>> I'm not a network developer, so correct me if I'm wrong. >>>> >>>> Since commit 7955490f732c2b8 >>>> ("net: netprio_cgroup: rework update socket logic"), sock->sk->sk_cgrp_prioidx >>>> is set when the socket is created, and won't be updated unless the task is >>>> moved to another cgroup. >>>> >>>> Now the problem is, a socket can be _shared_ by multiple processes (fork, SCM_RIGHT). >>>> If we place those processes in different cgroups, and each cgroup has >>>> different configs, but all of the processes will send data via this socket >>>> with the same network priority. >>> >>> Wouldn't that be addressed by 48a87cc26c13b68f6cce4e9d769fcb17a6b3e4b8 >>> >>> net: netprio: fd passed in SCM_RIGHTS datagram not set correctly >>> >>> A socket fd passed in a SCM_RIGHTS datagram was not getting >>> updated with the new tasks cgrp prioidx. This leaves IO on >>> the socket tagged with the old tasks priority. >>> >>> To fix this add a check in the scm recvmsg path to update the >>> sock cgrp prioidx with the new tasks value. >>> >>> As I read this this should work for net_prio. >>> >> >> But after process A passed the socket fd to B, both A and B can use the >> same socket to send data, right? Then if A and B were placed in different >> cgroups with differnt configs, A's config won't take effect anymore. >> >> Am I missing something? >> >> > > Hi Zefan, > > Neil and I discusses this here, http://patchwork.ozlabs.org/patch/172343/ > look towards the bottom of the thread. Quoted here. > So this is a known issue. Why not document this behavior in Documentation/cgroups/netprio.txt? ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [BUG] Bug in netprio_cgroup and netcls_cgroup ? [not found] ` <50FD0402.6060400-hv44wF8Li93QT0dZR+AlfA@public.gmane.org> 2013-01-21 9:21 ` John Fastabend @ 2013-01-21 9:27 ` Daniel Wagner 2013-01-21 9:57 ` Li Zefan 1 sibling, 1 reply; 12+ messages in thread From: Daniel Wagner @ 2013-01-21 9:27 UTC (permalink / raw) To: Li Zefan Cc: John Fastabend, Neil Horman, Daniel Wagner, LKML, netdev-u79uwXL29TY76Z2rM5mHXA, Cgroups On 21.01.2013 10:01, Li Zefan wrote: > On 2013/1/21 16:50, Daniel Wagner wrote: >> Hi Li, >> >> On 21.01.2013 07:08, Li Zefan wrote: >>> I'm not a network developer, so correct me if I'm wrong. >>> >>> Since commit 7955490f732c2b8 >>> ("net: netprio_cgroup: rework update socket logic"), sock->sk->sk_cgrp_prioidx >>> is set when the socket is created, and won't be updated unless the task is >>> moved to another cgroup. >>> >>> Now the problem is, a socket can be _shared_ by multiple processes (fork, SCM_RIGHT). >>> If we place those processes in different cgroups, and each cgroup has >>> different configs, but all of the processes will send data via this socket >>> with the same network priority. >> >> Wouldn't that be addressed by 48a87cc26c13b68f6cce4e9d769fcb17a6b3e4b8 >> >> net: netprio: fd passed in SCM_RIGHTS datagram not set correctly >> >> A socket fd passed in a SCM_RIGHTS datagram was not getting >> updated with the new tasks cgrp prioidx. This leaves IO on >> the socket tagged with the old tasks priority. >> >> To fix this add a check in the scm recvmsg path to update the >> sock cgrp prioidx with the new tasks value. >> >> As I read this this should work for net_prio. >> > > But after process A passed the socket fd to B, both A and B can use the > same socket to send data, right? Then if A and B were placed in different > cgroups with differnt configs, A's config won't take effect anymore. > > Am I missing something? I don't know. I guess at one point the socket resources are shared and then one configuration is taking preference. As you can see I am far away of being an expert in this field. Hopefully someone who understands this bits can chip in. BTW, isn't this a similar to what should happen with the block io cgroup? What is the behavior with a fd writing to a file in the scenario you describe above? ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [BUG] Bug in netprio_cgroup and netcls_cgroup ? 2013-01-21 9:27 ` Daniel Wagner @ 2013-01-21 9:57 ` Li Zefan 2013-01-21 17:18 ` John Fastabend 0 siblings, 1 reply; 12+ messages in thread From: Li Zefan @ 2013-01-21 9:57 UTC (permalink / raw) To: Daniel Wagner Cc: John Fastabend, Neil Horman, Daniel Wagner, LKML, netdev, Cgroups On 2013/1/21 17:27, Daniel Wagner wrote: > On 21.01.2013 10:01, Li Zefan wrote: >> On 2013/1/21 16:50, Daniel Wagner wrote: >>> Hi Li, >>> >>> On 21.01.2013 07:08, Li Zefan wrote: >>>> I'm not a network developer, so correct me if I'm wrong. >>>> >>>> Since commit 7955490f732c2b8 >>>> ("net: netprio_cgroup: rework update socket logic"), sock->sk->sk_cgrp_prioidx >>>> is set when the socket is created, and won't be updated unless the task is >>>> moved to another cgroup. >>>> >>>> Now the problem is, a socket can be _shared_ by multiple processes (fork, SCM_RIGHT). >>>> If we place those processes in different cgroups, and each cgroup has >>>> different configs, but all of the processes will send data via this socket >>>> with the same network priority. >>> >>> Wouldn't that be addressed by 48a87cc26c13b68f6cce4e9d769fcb17a6b3e4b8 >>> >>> net: netprio: fd passed in SCM_RIGHTS datagram not set correctly >>> >>> A socket fd passed in a SCM_RIGHTS datagram was not getting >>> updated with the new tasks cgrp prioidx. This leaves IO on >>> the socket tagged with the old tasks priority. >>> >>> To fix this add a check in the scm recvmsg path to update the >>> sock cgrp prioidx with the new tasks value. >>> >>> As I read this this should work for net_prio. >>> >> >> But after process A passed the socket fd to B, both A and B can use the >> same socket to send data, right? Then if A and B were placed in different >> cgroups with differnt configs, A's config won't take effect anymore. >> >> Am I missing something? > > I don't know. I guess at one point the socket resources are shared and then > one configuration is taking preference. As you can see I am far away of > being > an expert in this field. Hopefully someone who understands this bits > can chip in. > > BTW, isn't this a similar to what should happen with the block io cgroup? > What is the behavior with a fd writing to a file in the scenario you > describe above? > It forbids task moving in this case: /* * We cannot support shared io contexts, as we have no mean to support * two tasks with the same ioc in two different groups without major rework * of the main cic data structures. For now we allow a task to change * its cgroup only if it's the only owner of its ioc. */ static int blkcg_can_attach(struct cgroup *cgrp, struct cgroup_taskset *tset) ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [BUG] Bug in netprio_cgroup and netcls_cgroup ? 2013-01-21 9:57 ` Li Zefan @ 2013-01-21 17:18 ` John Fastabend [not found] ` <50FD786E.4050108-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 0 siblings, 1 reply; 12+ messages in thread From: John Fastabend @ 2013-01-21 17:18 UTC (permalink / raw) To: Li Zefan Cc: Daniel Wagner, John Fastabend, Neil Horman, Daniel Wagner, LKML, netdev, Cgroups On 01/21/2013 01:57 AM, Li Zefan wrote: > On 2013/1/21 17:27, Daniel Wagner wrote: >> On 21.01.2013 10:01, Li Zefan wrote: >>> On 2013/1/21 16:50, Daniel Wagner wrote: >>>> Hi Li, >>>> >>>> On 21.01.2013 07:08, Li Zefan wrote: >>>>> I'm not a network developer, so correct me if I'm wrong. >>>>> >>>>> Since commit 7955490f732c2b8 >>>>> ("net: netprio_cgroup: rework update socket logic"), sock->sk->sk_cgrp_prioidx >>>>> is set when the socket is created, and won't be updated unless the task is >>>>> moved to another cgroup. >>>>> >>>>> Now the problem is, a socket can be _shared_ by multiple processes (fork, SCM_RIGHT). >>>>> If we place those processes in different cgroups, and each cgroup has >>>>> different configs, but all of the processes will send data via this socket >>>>> with the same network priority. >>>> >>>> Wouldn't that be addressed by 48a87cc26c13b68f6cce4e9d769fcb17a6b3e4b8 >>>> >>>> net: netprio: fd passed in SCM_RIGHTS datagram not set correctly >>>> >>>> A socket fd passed in a SCM_RIGHTS datagram was not getting >>>> updated with the new tasks cgrp prioidx. This leaves IO on >>>> the socket tagged with the old tasks priority. >>>> >>>> To fix this add a check in the scm recvmsg path to update the >>>> sock cgrp prioidx with the new tasks value. >>>> >>>> As I read this this should work for net_prio. >>>> >>> >>> But after process A passed the socket fd to B, both A and B can use the >>> same socket to send data, right? Then if A and B were placed in different >>> cgroups with differnt configs, A's config won't take effect anymore. >>> >>> Am I missing something? >> >> I don't know. I guess at one point the socket resources are shared and then >> one configuration is taking preference. As you can see I am far away of >> being >> an expert in this field. Hopefully someone who understands this bits >> can chip in. >> >> BTW, isn't this a similar to what should happen with the block io cgroup? >> What is the behavior with a fd writing to a file in the scenario you >> describe above? >> > > It forbids task moving in this case: > > /* > * We cannot support shared io contexts, as we have no mean to support > * two tasks with the same ioc in two different groups without major rework > * of the main cic data structures. For now we allow a task to change > * its cgroup only if it's the only owner of its ioc. > */ > static int blkcg_can_attach(struct cgroup *cgrp, struct cgroup_taskset *tset) > OK, I guess we should do something similar in the netprio, netcls cgroups and yes document it as you noted in your last comment. Thanks, John -- John Fastabend Intel Corporation ^ permalink raw reply [flat|nested] 12+ messages in thread
[parent not found: <50FD786E.4050108-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>]
* Re: [BUG] Bug in netprio_cgroup and netcls_cgroup ? [not found] ` <50FD786E.4050108-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> @ 2013-01-22 10:09 ` Daniel Wagner 2013-01-23 0:02 ` John Fastabend 2013-01-25 8:39 ` Li Zefan 0 siblings, 2 replies; 12+ messages in thread From: Daniel Wagner @ 2013-01-22 10:09 UTC (permalink / raw) To: John Fastabend Cc: Li Zefan, John Fastabend, Neil Horman, Daniel Wagner, LKML, netdev-u79uwXL29TY76Z2rM5mHXA, Cgroups On Mon, Jan 21, 2013 at 09:18:38AM -0800, John Fastabend wrote: > On 01/21/2013 01:57 AM, Li Zefan wrote: > > On 2013/1/21 17:27, Daniel Wagner wrote: > >> On 21.01.2013 10:01, Li Zefan wrote: > >>> On 2013/1/21 16:50, Daniel Wagner wrote: > >>>> Hi Li, > >>>> > >>>> On 21.01.2013 07:08, Li Zefan wrote: > >>>>> I'm not a network developer, so correct me if I'm wrong. > >>>>> > >>>>> Since commit 7955490f732c2b8 > >>>>> ("net: netprio_cgroup: rework update socket logic"), sock->sk->sk_cgrp_prioidx > >>>>> is set when the socket is created, and won't be updated unless the task is > >>>>> moved to another cgroup. > >>>>> > >>>>> Now the problem is, a socket can be _shared_ by multiple processes (fork, SCM_RIGHT). > >>>>> If we place those processes in different cgroups, and each cgroup has > >>>>> different configs, but all of the processes will send data via this socket > >>>>> with the same network priority. > >>>> > >>>> Wouldn't that be addressed by 48a87cc26c13b68f6cce4e9d769fcb17a6b3e4b8 > >>>> > >>>> net: netprio: fd passed in SCM_RIGHTS datagram not set correctly > >>>> > >>>> A socket fd passed in a SCM_RIGHTS datagram was not getting > >>>> updated with the new tasks cgrp prioidx. This leaves IO on > >>>> the socket tagged with the old tasks priority. > >>>> > >>>> To fix this add a check in the scm recvmsg path to update the > >>>> sock cgrp prioidx with the new tasks value. > >>>> > >>>> As I read this this should work for net_prio. > >>>> > >>> > >>> But after process A passed the socket fd to B, both A and B can use the > >>> same socket to send data, right? Then if A and B were placed in different > >>> cgroups with differnt configs, A's config won't take effect anymore. > >>> > >>> Am I missing something? > >> > >> I don't know. I guess at one point the socket resources are shared and then > >> one configuration is taking preference. As you can see I am far away of > >> being > >> an expert in this field. Hopefully someone who understands this bits > >> can chip in. > >> > >> BTW, isn't this a similar to what should happen with the block io cgroup? > >> What is the behavior with a fd writing to a file in the scenario you > >> describe above? > >> > > > > It forbids task moving in this case: > > > > /* > > * We cannot support shared io contexts, as we have no mean to support > > * two tasks with the same ioc in two different groups without major rework > > * of the main cic data structures. For now we allow a task to change > > * its cgroup only if it's the only owner of its ioc. > > */ > > static int blkcg_can_attach(struct cgroup *cgrp, struct cgroup_taskset *tset) > > > > OK, I guess we should do something similar in the netprio, netcls > cgroups and > yes document it as you noted in your last comment. Here is my attempt to add such a check. I really don't know if this is the correct way to do so. To test this I have written a test program, which seems to test the right thing. Please have a look and let me know if it is correct: http://www.monom.org/misc/scm_rights.c And here a dirty first version of the patch: >From 49a78d907eaf31c16673025e7e3b4844e419e416 Mon Sep 17 00:00:00 2001 From: Daniel Wagner <daniel.wagner-98C5kh4wR6ohFhg+JK9F0w@public.gmane.org> Date: Tue, 22 Jan 2013 11:08:22 +0100 Subject: [PATCH] net: net_prio: Block attach if a socket is shared --- net/core/netprio_cgroup.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/net/core/netprio_cgroup.c b/net/core/netprio_cgroup.c index 847c02b..de4e6c5 100644 --- a/net/core/netprio_cgroup.c +++ b/net/core/netprio_cgroup.c @@ -274,9 +274,39 @@ static struct cftype ss_files[] = { { } /* terminate */ }; +static int check_cnt(const void *v, struct file *file, unsigned n) +{ + unsigned *flag = (unsigned *)v; + int err; + + struct socket *sock = sock_from_file(file, &err); + if (sock && file_count(file) > 1) + *flag = 1; + + return 0; +} + +static int cgrp_can_attach(struct cgroup *cgrp, struct cgroup_taskset *tset) +{ + struct task_struct *p; + unsigned flag = 0; + + cgroup_taskset_for_each(p, cgrp, tset) { + task_lock(p); + iterate_fd(p->files, 0, check_cnt, &flag); + task_unlock(p); + } + + if (flag != 0) + return -EINVAL; + + return 0; +} + struct cgroup_subsys net_prio_subsys = { .name = "net_prio", .create = cgrp_create, + .can_attach = cgrp_can_attach, .destroy = cgrp_destroy, .attach = net_prio_attach, .subsys_id = net_prio_subsys_id, -- 1.8.0.rc0 ^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [BUG] Bug in netprio_cgroup and netcls_cgroup ? 2013-01-22 10:09 ` Daniel Wagner @ 2013-01-23 0:02 ` John Fastabend [not found] ` <50FF287C.70906-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 2013-01-25 8:39 ` Li Zefan 1 sibling, 1 reply; 12+ messages in thread From: John Fastabend @ 2013-01-23 0:02 UTC (permalink / raw) To: Daniel Wagner Cc: Li Zefan, John Fastabend, Neil Horman, Daniel Wagner, LKML, netdev, Cgroups [...] >> >> OK, I guess we should do something similar in the netprio, netcls >> cgroups and >> yes document it as you noted in your last comment. > > Here is my attempt to add such a check. I really don't know if this is the > correct way to do so. To test this I have written a test program, which > seems to test the right thing. Please have a look and let me know if > it is correct: http://www.monom.org/misc/scm_rights.c > > And here a dirty first version of the patch: > > > From 49a78d907eaf31c16673025e7e3b4844e419e416 Mon Sep 17 00:00:00 2001 > From: Daniel Wagner <daniel.wagner@bmw-carit.de> > Date: Tue, 22 Jan 2013 11:08:22 +0100 > Subject: [PATCH] net: net_prio: Block attach if a socket is shared > > --- > net/core/netprio_cgroup.c | 30 ++++++++++++++++++++++++++++++ > 1 file changed, 30 insertions(+) > > diff --git a/net/core/netprio_cgroup.c b/net/core/netprio_cgroup.c > index 847c02b..de4e6c5 100644 > --- a/net/core/netprio_cgroup.c > +++ b/net/core/netprio_cgroup.c > @@ -274,9 +274,39 @@ static struct cftype ss_files[] = { > { } /* terminate */ > }; > > +static int check_cnt(const void *v, struct file *file, unsigned n) > +{ > + unsigned *flag = (unsigned *)v; > + int err; > + > + struct socket *sock = sock_from_file(file, &err); > + if (sock && file_count(file) > 1) > + *flag = 1; > + I think this check will catch a lot of cases that are not necessarily sharing a socket across tasks though. For example iscsid passes a file descriptor to the kernel which does a sockfd_lookup() incrementing f_count. Similarly look at dup/clone/etc. In many of these cases I believe it should be OK to move the task around when the sockets are not shared between multiple tasks. .John -- John Fastabend Intel Corporation ^ permalink raw reply [flat|nested] 12+ messages in thread
[parent not found: <50FF287C.70906-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>]
* Re: [BUG] Bug in netprio_cgroup and netcls_cgroup ? [not found] ` <50FF287C.70906-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> @ 2013-01-23 9:24 ` Daniel Wagner 0 siblings, 0 replies; 12+ messages in thread From: Daniel Wagner @ 2013-01-23 9:24 UTC (permalink / raw) To: John Fastabend Cc: Li Zefan, John Fastabend, Neil Horman, Daniel Wagner, LKML, netdev-u79uwXL29TY76Z2rM5mHXA, Cgroups On 23.01.2013 01:02, John Fastabend wrote: > [...] > >>> >>> OK, I guess we should do something similar in the netprio, netcls >>> cgroups and >>> yes document it as you noted in your last comment. >> >> Here is my attempt to add such a check. I really don't know if this is >> the >> correct way to do so. To test this I have written a test program, which >> seems to test the right thing. Please have a look and let me know if >> it is correct: http://www.monom.org/misc/scm_rights.c >> >> And here a dirty first version of the patch: >> >> >> From 49a78d907eaf31c16673025e7e3b4844e419e416 Mon Sep 17 00:00:00 2001 >> From: Daniel Wagner <daniel.wagner-98C5kh4wR6ohFhg+JK9F0w@public.gmane.org> >> Date: Tue, 22 Jan 2013 11:08:22 +0100 >> Subject: [PATCH] net: net_prio: Block attach if a socket is shared >> >> --- >> net/core/netprio_cgroup.c | 30 ++++++++++++++++++++++++++++++ >> 1 file changed, 30 insertions(+) >> >> diff --git a/net/core/netprio_cgroup.c b/net/core/netprio_cgroup.c >> index 847c02b..de4e6c5 100644 >> --- a/net/core/netprio_cgroup.c >> +++ b/net/core/netprio_cgroup.c >> @@ -274,9 +274,39 @@ static struct cftype ss_files[] = { >> { } /* terminate */ >> }; >> >> +static int check_cnt(const void *v, struct file *file, unsigned n) >> +{ >> + unsigned *flag = (unsigned *)v; >> + int err; >> + >> + struct socket *sock = sock_from_file(file, &err); >> + if (sock && file_count(file) > 1) >> + *flag = 1; >> + > > I think this check will catch a lot of cases that are not necessarily > sharing a socket across tasks though. For example iscsid passes a file > descriptor to the kernel which does a sockfd_lookup() incrementing > f_count. Similarly look at dup/clone/etc. Yep, I expected that this patch was too simple. > In many of these cases I believe it should be OK to move the task > around when the sockets are not shared between multiple tasks. Do you know of a different way to identify the shared sockets? thanks, daniel ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [BUG] Bug in netprio_cgroup and netcls_cgroup ? 2013-01-22 10:09 ` Daniel Wagner 2013-01-23 0:02 ` John Fastabend @ 2013-01-25 8:39 ` Li Zefan 1 sibling, 0 replies; 12+ messages in thread From: Li Zefan @ 2013-01-25 8:39 UTC (permalink / raw) To: Daniel Wagner Cc: John Fastabend, John Fastabend, Neil Horman, Daniel Wagner, LKML, netdev, Cgroups >>>> BTW, isn't this a similar to what should happen with the block io cgroup? >>>> What is the behavior with a fd writing to a file in the scenario you >>>> describe above? >>>> >>> >>> It forbids task moving in this case: >>> >>> /* >>> * We cannot support shared io contexts, as we have no mean to support >>> * two tasks with the same ioc in two different groups without major rework >>> * of the main cic data structures. For now we allow a task to change >>> * its cgroup only if it's the only owner of its ioc. >>> */ >>> static int blkcg_can_attach(struct cgroup *cgrp, struct cgroup_taskset *tset) >>> >> >> OK, I guess we should do something similar in the netprio, netcls >> cgroups and >> yes document it as you noted in your last comment. > > Here is my attempt to add such a check. I really don't know if this is the > correct way to do so. To test this I have written a test program, which > seems to test the right thing. Please have a look and let me know if > it is correct: http://www.monom.org/misc/scm_rights.c > > And here a dirty first version of the patch: > Adding new can_attach() is discouraged. It's considered bad, because if cgroup is mounted with multi subsystems binded, and if one of them can forbid task moving for some reason, this will add burden on users to use cgroup properly. ^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2013-01-25 8:39 UTC | newest] Thread overview: 12+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2013-01-21 6:08 [BUG] Bug in netprio_cgroup and netcls_cgroup ? Li Zefan [not found] ` <50FCDB5C.4050608-hv44wF8Li93QT0dZR+AlfA@public.gmane.org> 2013-01-21 8:50 ` Daniel Wagner [not found] ` <50FD0144.1000401-kQCPcA+X3s7YtjvyW6yDsg@public.gmane.org> 2013-01-21 9:01 ` Li Zefan [not found] ` <50FD0402.6060400-hv44wF8Li93QT0dZR+AlfA@public.gmane.org> 2013-01-21 9:21 ` John Fastabend [not found] ` <50FD0893.1050805-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 2013-01-21 9:52 ` Li Zefan 2013-01-21 9:27 ` Daniel Wagner 2013-01-21 9:57 ` Li Zefan 2013-01-21 17:18 ` John Fastabend [not found] ` <50FD786E.4050108-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 2013-01-22 10:09 ` Daniel Wagner 2013-01-23 0:02 ` John Fastabend [not found] ` <50FF287C.70906-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 2013-01-23 9:24 ` Daniel Wagner 2013-01-25 8:39 ` Li Zefan
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).