aboutsummaryrefslogtreecommitdiffstats
path: root/net/unix
diff options
context:
space:
mode:
authorIngo Molnar <mingo@elte.hu>2008-10-15 07:46:29 -0400
committerIngo Molnar <mingo@elte.hu>2008-10-15 07:46:29 -0400
commitb2aaf8f74cdc84a9182f6cabf198b7763bcb9d40 (patch)
tree53ccb1c2c14751fe69cf93102e76e97021f6df07 /net/unix
parent4f962d4d65923d7b722192e729840cfb79af0a5a (diff)
parent278429cff8809958d25415ba0ed32b59866ab1a8 (diff)
Merge branch 'linus' into stackprotector
Conflicts: arch/x86/kernel/Makefile include/asm-x86/pda.h
Diffstat (limited to 'net/unix')
-rw-r--r--net/unix/af_unix.c66
-rw-r--r--net/unix/garbage.c18
2 files changed, 39 insertions, 45 deletions
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index 657835f227d3..c647aab8d418 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -1,15 +1,13 @@
1/* 1/*
2 * NET4: Implementation of BSD Unix domain sockets. 2 * NET4: Implementation of BSD Unix domain sockets.
3 * 3 *
4 * Authors: Alan Cox, <alan.cox@linux.org> 4 * Authors: Alan Cox, <alan@lxorguk.ukuu.org.uk>
5 * 5 *
6 * This program is free software; you can redistribute it and/or 6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License 7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version. 9 * 2 of the License, or (at your option) any later version.
10 * 10 *
11 * Version: $Id: af_unix.c,v 1.133 2002/02/08 03:57:19 davem Exp $
12 *
13 * Fixes: 11 * Fixes:
14 * Linus Torvalds : Assorted bug cures. 12 * Linus Torvalds : Assorted bug cures.
15 * Niibe Yutaka : async I/O support. 13 * Niibe Yutaka : async I/O support.
@@ -229,7 +227,7 @@ static void __unix_remove_socket(struct sock *sk)
229 227
230static void __unix_insert_socket(struct hlist_head *list, struct sock *sk) 228static void __unix_insert_socket(struct hlist_head *list, struct sock *sk)
231{ 229{
232 BUG_TRAP(sk_unhashed(sk)); 230 WARN_ON(!sk_unhashed(sk));
233 sk_add_node(sk, list); 231 sk_add_node(sk, list);
234} 232}
235 233
@@ -352,9 +350,9 @@ static void unix_sock_destructor(struct sock *sk)
352 350
353 skb_queue_purge(&sk->sk_receive_queue); 351 skb_queue_purge(&sk->sk_receive_queue);
354 352
355 BUG_TRAP(!atomic_read(&sk->sk_wmem_alloc)); 353 WARN_ON(atomic_read(&sk->sk_wmem_alloc));
356 BUG_TRAP(sk_unhashed(sk)); 354 WARN_ON(!sk_unhashed(sk));
357 BUG_TRAP(!sk->sk_socket); 355 WARN_ON(sk->sk_socket);
358 if (!sock_flag(sk, SOCK_DEAD)) { 356 if (!sock_flag(sk, SOCK_DEAD)) {
359 printk("Attempt to release alive unix socket: %p\n", sk); 357 printk("Attempt to release alive unix socket: %p\n", sk);
360 return; 358 return;
@@ -487,8 +485,8 @@ static int unix_socketpair(struct socket *, struct socket *);
487static int unix_accept(struct socket *, struct socket *, int); 485static int unix_accept(struct socket *, struct socket *, int);
488static int unix_getname(struct socket *, struct sockaddr *, int *, int); 486static int unix_getname(struct socket *, struct sockaddr *, int *, int);
489static unsigned int unix_poll(struct file *, struct socket *, poll_table *); 487static unsigned int unix_poll(struct file *, struct socket *, poll_table *);
490static unsigned int unix_datagram_poll(struct file *, struct socket *, 488static unsigned int unix_dgram_poll(struct file *, struct socket *,
491 poll_table *); 489 poll_table *);
492static int unix_ioctl(struct socket *, unsigned int, unsigned long); 490static int unix_ioctl(struct socket *, unsigned int, unsigned long);
493static int unix_shutdown(struct socket *, int); 491static int unix_shutdown(struct socket *, int);
494static int unix_stream_sendmsg(struct kiocb *, struct socket *, 492static int unix_stream_sendmsg(struct kiocb *, struct socket *,
@@ -534,7 +532,7 @@ static const struct proto_ops unix_dgram_ops = {
534 .socketpair = unix_socketpair, 532 .socketpair = unix_socketpair,
535 .accept = sock_no_accept, 533 .accept = sock_no_accept,
536 .getname = unix_getname, 534 .getname = unix_getname,
537 .poll = unix_datagram_poll, 535 .poll = unix_dgram_poll,
538 .ioctl = unix_ioctl, 536 .ioctl = unix_ioctl,
539 .listen = sock_no_listen, 537 .listen = sock_no_listen,
540 .shutdown = unix_shutdown, 538 .shutdown = unix_shutdown,
@@ -555,7 +553,7 @@ static const struct proto_ops unix_seqpacket_ops = {
555 .socketpair = unix_socketpair, 553 .socketpair = unix_socketpair,
556 .accept = unix_accept, 554 .accept = unix_accept,
557 .getname = unix_getname, 555 .getname = unix_getname,
558 .poll = unix_datagram_poll, 556 .poll = unix_dgram_poll,
559 .ioctl = unix_ioctl, 557 .ioctl = unix_ioctl,
560 .listen = unix_listen, 558 .listen = unix_listen,
561 .shutdown = unix_shutdown, 559 .shutdown = unix_shutdown,
@@ -605,7 +603,7 @@ static struct sock * unix_create1(struct net *net, struct socket *sock)
605 u->dentry = NULL; 603 u->dentry = NULL;
606 u->mnt = NULL; 604 u->mnt = NULL;
607 spin_lock_init(&u->lock); 605 spin_lock_init(&u->lock);
608 atomic_set(&u->inflight, 0); 606 atomic_long_set(&u->inflight, 0);
609 INIT_LIST_HEAD(&u->link); 607 INIT_LIST_HEAD(&u->link);
610 mutex_init(&u->readlock); /* single task reading lock */ 608 mutex_init(&u->readlock); /* single task reading lock */
611 init_waitqueue_head(&u->peer_wait); 609 init_waitqueue_head(&u->peer_wait);
@@ -1994,29 +1992,13 @@ static unsigned int unix_poll(struct file * file, struct socket *sock, poll_tabl
1994 return mask; 1992 return mask;
1995} 1993}
1996 1994
1997static unsigned int unix_datagram_poll(struct file *file, struct socket *sock, 1995static unsigned int unix_dgram_poll(struct file *file, struct socket *sock,
1998 poll_table *wait) 1996 poll_table *wait)
1999{ 1997{
2000 struct sock *sk = sock->sk, *peer; 1998 struct sock *sk = sock->sk, *other;
2001 unsigned int mask; 1999 unsigned int mask, writable;
2002 2000
2003 poll_wait(file, sk->sk_sleep, wait); 2001 poll_wait(file, sk->sk_sleep, wait);
2004
2005 peer = unix_peer_get(sk);
2006 if (peer) {
2007 if (peer != sk) {
2008 /*
2009 * Writability of a connected socket additionally
2010 * depends on the state of the receive queue of the
2011 * peer.
2012 */
2013 poll_wait(file, &unix_sk(peer)->peer_wait, wait);
2014 } else {
2015 sock_put(peer);
2016 peer = NULL;
2017 }
2018 }
2019
2020 mask = 0; 2002 mask = 0;
2021 2003
2022 /* exceptional events? */ 2004 /* exceptional events? */
@@ -2042,14 +2024,26 @@ static unsigned int unix_datagram_poll(struct file *file, struct socket *sock,
2042 } 2024 }
2043 2025
2044 /* writable? */ 2026 /* writable? */
2045 if (unix_writable(sk) && !(peer && unix_recvq_full(peer))) 2027 writable = unix_writable(sk);
2028 if (writable) {
2029 other = unix_peer_get(sk);
2030 if (other) {
2031 if (unix_peer(other) != sk) {
2032 poll_wait(file, &unix_sk(other)->peer_wait,
2033 wait);
2034 if (unix_recvq_full(other))
2035 writable = 0;
2036 }
2037
2038 sock_put(other);
2039 }
2040 }
2041
2042 if (writable)
2046 mask |= POLLOUT | POLLWRNORM | POLLWRBAND; 2043 mask |= POLLOUT | POLLWRNORM | POLLWRBAND;
2047 else 2044 else
2048 set_bit(SOCK_ASYNC_NOSPACE, &sk->sk_socket->flags); 2045 set_bit(SOCK_ASYNC_NOSPACE, &sk->sk_socket->flags);
2049 2046
2050 if (peer)
2051 sock_put(peer);
2052
2053 return mask; 2047 return mask;
2054} 2048}
2055 2049
diff --git a/net/unix/garbage.c b/net/unix/garbage.c
index ebdff3d877a1..2a27b84f740b 100644
--- a/net/unix/garbage.c
+++ b/net/unix/garbage.c
@@ -127,7 +127,7 @@ void unix_inflight(struct file *fp)
127 if(s) { 127 if(s) {
128 struct unix_sock *u = unix_sk(s); 128 struct unix_sock *u = unix_sk(s);
129 spin_lock(&unix_gc_lock); 129 spin_lock(&unix_gc_lock);
130 if (atomic_inc_return(&u->inflight) == 1) { 130 if (atomic_long_inc_return(&u->inflight) == 1) {
131 BUG_ON(!list_empty(&u->link)); 131 BUG_ON(!list_empty(&u->link));
132 list_add_tail(&u->link, &gc_inflight_list); 132 list_add_tail(&u->link, &gc_inflight_list);
133 } else { 133 } else {
@@ -145,7 +145,7 @@ void unix_notinflight(struct file *fp)
145 struct unix_sock *u = unix_sk(s); 145 struct unix_sock *u = unix_sk(s);
146 spin_lock(&unix_gc_lock); 146 spin_lock(&unix_gc_lock);
147 BUG_ON(list_empty(&u->link)); 147 BUG_ON(list_empty(&u->link));
148 if (atomic_dec_and_test(&u->inflight)) 148 if (atomic_long_dec_and_test(&u->inflight))
149 list_del_init(&u->link); 149 list_del_init(&u->link);
150 unix_tot_inflight--; 150 unix_tot_inflight--;
151 spin_unlock(&unix_gc_lock); 151 spin_unlock(&unix_gc_lock);
@@ -237,17 +237,17 @@ static void scan_children(struct sock *x, void (*func)(struct unix_sock *),
237 237
238static void dec_inflight(struct unix_sock *usk) 238static void dec_inflight(struct unix_sock *usk)
239{ 239{
240 atomic_dec(&usk->inflight); 240 atomic_long_dec(&usk->inflight);
241} 241}
242 242
243static void inc_inflight(struct unix_sock *usk) 243static void inc_inflight(struct unix_sock *usk)
244{ 244{
245 atomic_inc(&usk->inflight); 245 atomic_long_inc(&usk->inflight);
246} 246}
247 247
248static void inc_inflight_move_tail(struct unix_sock *u) 248static void inc_inflight_move_tail(struct unix_sock *u)
249{ 249{
250 atomic_inc(&u->inflight); 250 atomic_long_inc(&u->inflight);
251 /* 251 /*
252 * If this is still a candidate, move it to the end of the 252 * If this is still a candidate, move it to the end of the
253 * list, so that it's checked even if it was already passed 253 * list, so that it's checked even if it was already passed
@@ -288,11 +288,11 @@ void unix_gc(void)
288 * before the detach without atomicity guarantees. 288 * before the detach without atomicity guarantees.
289 */ 289 */
290 list_for_each_entry_safe(u, next, &gc_inflight_list, link) { 290 list_for_each_entry_safe(u, next, &gc_inflight_list, link) {
291 int total_refs; 291 long total_refs;
292 int inflight_refs; 292 long inflight_refs;
293 293
294 total_refs = file_count(u->sk.sk_socket->file); 294 total_refs = file_count(u->sk.sk_socket->file);
295 inflight_refs = atomic_read(&u->inflight); 295 inflight_refs = atomic_long_read(&u->inflight);
296 296
297 BUG_ON(inflight_refs < 1); 297 BUG_ON(inflight_refs < 1);
298 BUG_ON(total_refs < inflight_refs); 298 BUG_ON(total_refs < inflight_refs);
@@ -324,7 +324,7 @@ void unix_gc(void)
324 /* Move cursor to after the current position. */ 324 /* Move cursor to after the current position. */
325 list_move(&cursor, &u->link); 325 list_move(&cursor, &u->link);
326 326
327 if (atomic_read(&u->inflight) > 0) { 327 if (atomic_long_read(&u->inflight) > 0) {
328 list_move_tail(&u->link, &gc_inflight_list); 328 list_move_tail(&u->link, &gc_inflight_list);
329 u->gc_candidate = 0; 329 u->gc_candidate = 0;
330 scan_children(&u->sk, inc_inflight_move_tail, NULL); 330 scan_children(&u->sk, inc_inflight_move_tail, NULL);