[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20100930202429.42808a38@chocolatine.cbg.collabora.co.uk>
Date: Thu, 30 Sep 2010 20:24:29 +0100
From: Alban Crequy <alban.crequy@...labora.co.uk>
To: Eric Dumazet <eric.dumazet@...il.com>
Cc: "David S. Miller" <davem@...emloft.net>,
Stephen Hemminger <shemminger@...tta.com>,
Cyrill Gorcunov <gorcunov@...nvz.org>,
Alexey Dobriyan <adobriyan@...il.com>,
Lennart Poettering <lennart@...ttering.net>,
Kay Sievers <kay.sievers@...y.org>,
Ian Molton <ian.molton@...labora.co.uk>,
netdev@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH 4/5] AF_UNIX: find peers on multicast Unix stream
sockets
Le Fri, 24 Sep 2010 20:00:37 +0200,
Eric Dumazet <eric.dumazet@...il.com> a écrit :
> Le vendredi 24 septembre 2010 à 18:25 +0100, Alban Crequy a écrit :
>
> > @@ -1612,7 +1671,12 @@ static int unix_stream_sendmsg(struct kiocb
> > *kiocb, struct socket *sock, } else {
> > sunaddr = NULL;
> > err = -ENOTCONN;
> > - other = NULL; /* FIXME: get the list of other
> > connection */
> > + max_others = atomic_read(&unix_nr_multicast_socks);
> > + others = kzalloc((max_others + 1) * sizeof(void
> > *), GFP_KERNEL);
> > + unix_find_other(sock_net(sk), u->addr->name,
> > + u->addr->len, 0, u->addr->hash, 1, others,
> > max_others, &err);
> > + other = others[0];
> > + kfree(others);
> > if (!other)
> > goto out_err;
> > }
>
> Seriously, this block sizing against unix_nr_multicast_socks is not
> scalable. What happens if we have 1000 sockets ?
> kzalloc() to clear 8000 bytes ?
> Its also unsafe.
>
> (say you kzalloc() a buffer for 2 sockets, and another cpu inserts a
> new socket. unix_find_socket_byname() can overflow the buffer)
>
>
> You should use a list, and allocates elements in
> unix_find_socket_byname()
>
> struct item {
> struct item *next;
> struct sock *s;
> };
Thanks for your review.
I cannot allocate elements directly in unix_find_socket_byname()
iteration after iteration because the spinlock "unix_table_lock" is
held. If I release the spinlock to allocate, the number of sockets in
the table may change.
I changed the code to count the sockets with the lock held and then
allocate. In the unfortunate case where the allocation is not big
enough (if another process inserts a new socket), it just tries again.
The code is available here. Please pull from:
git://git.collabora.co.uk/git/user/alban/linux-2.6.35.y/.git unix-multicast2
It is still a work in progress. Missing pieces:
- The flow control does not work correctly: poll/select does not match
the reality
- Atomic delivery: if a process is killed or interrupted in the middle
of a delivery, only a subset of the recipients will get the message
- Some locking to provide the same delivery order to all the recipients
when several senders run concurrently.
Feedback welcome,
Alban Crequy
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Powered by blists - more mailing lists