1. 21 9月, 2010 1 次提交
  2. 26 8月, 2010 2 次提交
    • K
      tcp: select(writefds) don't hang up when a peer close connection · d84ba638
      KOSAKI Motohiro 提交于
      This issue come from ruby language community. Below test program
      hang up when only run on Linux.
      
      	% uname -mrsv
      	Linux 2.6.26-2-486 #1 Sat Dec 26 08:37:39 UTC 2009 i686
      	% ruby -rsocket -ve '
      	BasicSocket.do_not_reverse_lookup = true
      	serv = TCPServer.open("127.0.0.1", 0)
      	s1 = TCPSocket.open("127.0.0.1", serv.addr[1])
      	s2 = serv.accept
      	s2.close
      	s1.write("a") rescue p $!
      	s1.write("a") rescue p $!
      	Thread.new {
      	  s1.write("a")
      	}.join'
      	ruby 1.9.3dev (2010-07-06 trunk 28554) [i686-linux]
      	#<Errno::EPIPE: Broken pipe>
      	[Hang Here]
      
      FreeBSD, Solaris, Mac doesn't. because Ruby's write() method call
      select() internally. and tcp_poll has a bug.
      
      SUS defined 'ready for writing' of select() as following.
      
      |  A descriptor shall be considered ready for writing when a call to an output
      |  function with O_NONBLOCK clear would not block, whether or not the function
      |  would transfer data successfully.
      
      That said, EPIPE situation is clearly one of 'ready for writing'.
      
      We don't have read-side issue because tcp_poll() already has read side
      shutdown care.
      
      |        if (sk->sk_shutdown & RCV_SHUTDOWN)
      |                mask |= POLLIN | POLLRDNORM | POLLRDHUP;
      
      So, Let's insert same logic in write side.
      
      - reference url
        http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/31065
        http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/31068Signed-off-by: NKOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      d84ba638
    • E
      tcp: fix three tcp sysctls tuning · c5ed63d6
      Eric Dumazet 提交于
      As discovered by Anton Blanchard, current code to autotune 
      tcp_death_row.sysctl_max_tw_buckets, sysctl_tcp_max_orphans and
      sysctl_max_syn_backlog makes little sense.
      
      The bigger a page is, the less tcp_max_orphans is : 4096 on a 512GB
      machine in Anton's case.
      
      (tcp_hashinfo.bhash_size * sizeof(struct inet_bind_hashbucket))
      is much bigger if spinlock debugging is on. Its wrong to select bigger
      limits in this case (where kernel structures are also bigger)
      
      bhash_size max is 65536, and we get this value even for small machines. 
      
      A better ground is to use size of ehash table, this also makes code
      shorter and more obvious.
      
      Based on a patch from Anton, and another from David.
      Reported-and-tested-by: NAnton Blanchard <anton@samba.org>
      Signed-off-by: NEric Dumazet <eric.dumazet@gmail.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      c5ed63d6
  3. 25 8月, 2010 1 次提交
  4. 03 8月, 2010 1 次提交
  5. 31 7月, 2010 1 次提交
  6. 15 7月, 2010 1 次提交
  7. 13 7月, 2010 2 次提交
  8. 29 6月, 2010 1 次提交
  9. 25 6月, 2010 1 次提交
    • K
      tcp: do not send reset to already closed sockets · 565b7b2d
      Konstantin Khorenko 提交于
      i've found that tcp_close() can be called for an already closed
      socket, but still sends reset in this case (tcp_send_active_reset())
      which seems to be incorrect.  Moreover, a packet with reset is sent
      with different source port as original port number has been already
      cleared on socket.  Besides that incrementing stat counter for
      LINUX_MIB_TCPABORTONCLOSE also does not look correct in this case.
      
      Initially this issue was found on 2.6.18-x RHEL5 kernel, but the same
      seems to be true for the current mainstream kernel (checked on
      2.6.35-rc3).  Please, correct me if i missed something.
      
      How that happens:
      
      1) the server receives a packet for socket in TCP_CLOSE_WAIT state
         that triggers a tcp_reset():
      
      Call Trace:
       <IRQ>  [<ffffffff8025b9b9>] tcp_reset+0x12f/0x1e8
       [<ffffffff80046125>] tcp_rcv_state_process+0x1c0/0xa08
       [<ffffffff8003eb22>] tcp_v4_do_rcv+0x310/0x37a
       [<ffffffff80028bea>] tcp_v4_rcv+0x74d/0xb43
       [<ffffffff8024ef4c>] ip_local_deliver_finish+0x0/0x259
       [<ffffffff80037131>] ip_local_deliver+0x200/0x2f4
       [<ffffffff8003843c>] ip_rcv+0x64c/0x69f
       [<ffffffff80021d89>] netif_receive_skb+0x4c4/0x4fa
       [<ffffffff80032eca>] process_backlog+0x90/0xec
       [<ffffffff8000cc50>] net_rx_action+0xbb/0x1f1
       [<ffffffff80012d3a>] __do_softirq+0xf5/0x1ce
       [<ffffffff8001147a>] handle_IRQ_event+0x56/0xb0
       [<ffffffff8006334c>] call_softirq+0x1c/0x28
       [<ffffffff80070476>] do_softirq+0x2c/0x85
       [<ffffffff80070441>] do_IRQ+0x149/0x152
       [<ffffffff80062665>] ret_from_intr+0x0/0xa
       <EOI>  [<ffffffff80008a2e>] __handle_mm_fault+0x6cd/0x1303
       [<ffffffff80008903>] __handle_mm_fault+0x5a2/0x1303
       [<ffffffff80033a9d>] cache_free_debugcheck+0x21f/0x22e
       [<ffffffff8006a263>] do_page_fault+0x49a/0x7dc
       [<ffffffff80066487>] thread_return+0x89/0x174
       [<ffffffff800c5aee>] audit_syscall_exit+0x341/0x35c
       [<ffffffff80062e39>] error_exit+0x0/0x84
      
      tcp_rcv_state_process()
      ...  // (sk_state == TCP_CLOSE_WAIT here)
      ...
              /* step 2: check RST bit */
              if(th->rst) {
                      tcp_reset(sk);
                      goto discard;
              }
      ...
      ---------------------------------
      tcp_rcv_state_process
       tcp_reset
        tcp_done
         tcp_set_state(sk, TCP_CLOSE);
           inet_put_port
            __inet_put_port
             inet_sk(sk)->num = 0;
      
         sk->sk_shutdown = SHUTDOWN_MASK;
      
      2) After that the process (socket owner) tries to write something to
         that socket and "inet_autobind" sets a _new_ (which differs from
         the original!) port number for the socket:
      
       Call Trace:
        [<ffffffff80255a12>] inet_bind_hash+0x33/0x5f
        [<ffffffff80257180>] inet_csk_get_port+0x216/0x268
        [<ffffffff8026bcc9>] inet_autobind+0x22/0x8f
        [<ffffffff80049140>] inet_sendmsg+0x27/0x57
        [<ffffffff8003a9d9>] do_sock_write+0xae/0xea
        [<ffffffff80226ac7>] sock_writev+0xdc/0xf6
        [<ffffffff800680c7>] _spin_lock_irqsave+0x9/0xe
        [<ffffffff8001fb49>] __pollwait+0x0/0xdd
        [<ffffffff8008d533>] default_wake_function+0x0/0xe
        [<ffffffff800a4f10>] autoremove_wake_function+0x0/0x2e
        [<ffffffff800f0b49>] do_readv_writev+0x163/0x274
        [<ffffffff80066538>] thread_return+0x13a/0x174
        [<ffffffff800145d8>] tcp_poll+0x0/0x1c9
        [<ffffffff800c56d3>] audit_syscall_entry+0x180/0x1b3
        [<ffffffff800f0dd0>] sys_writev+0x49/0xe4
        [<ffffffff800622dd>] tracesys+0xd5/0xe0
      
      3) sendmsg fails at last with -EPIPE (=> 'write' returns -EPIPE in userspace):
      
      F: tcp_sendmsg1 -EPIPE: sk=ffff81000bda00d0, sport=49847, old_state=7, new_state=7, sk_err=0, sk_shutdown=3
      
      Call Trace:
       [<ffffffff80027557>] tcp_sendmsg+0xcb/0xe87
       [<ffffffff80033300>] release_sock+0x10/0xae
       [<ffffffff8016f20f>] vgacon_cursor+0x0/0x1a7
       [<ffffffff8026bd32>] inet_autobind+0x8b/0x8f
       [<ffffffff8003a9d9>] do_sock_write+0xae/0xea
       [<ffffffff80226ac7>] sock_writev+0xdc/0xf6
       [<ffffffff800680c7>] _spin_lock_irqsave+0x9/0xe
       [<ffffffff8001fb49>] __pollwait+0x0/0xdd
       [<ffffffff8008d533>] default_wake_function+0x0/0xe
       [<ffffffff800a4f10>] autoremove_wake_function+0x0/0x2e
       [<ffffffff800f0b49>] do_readv_writev+0x163/0x274
       [<ffffffff80066538>] thread_return+0x13a/0x174
       [<ffffffff800145d8>] tcp_poll+0x0/0x1c9
       [<ffffffff800c56d3>] audit_syscall_entry+0x180/0x1b3
       [<ffffffff800f0dd0>] sys_writev+0x49/0xe4
       [<ffffffff800622dd>] tracesys+0xd5/0xe0
      
      tcp_sendmsg()
      ...
              /* Wait for a connection to finish. */
              if ((1 << sk->sk_state) & ~(TCPF_ESTABLISHED | TCPF_CLOSE_WAIT)) {
                      int old_state = sk->sk_state;
                      if ((err = sk_stream_wait_connect(sk, &timeo)) != 0) {
      if (f_d && (err == -EPIPE)) {
              printk("F: tcp_sendmsg1 -EPIPE: sk=%p, sport=%u, old_state=%d, new_state=%d, "
                      "sk_err=%d, sk_shutdown=%d\n",
                      sk, ntohs(inet_sk(sk)->sport), old_state, sk->sk_state,
                      sk->sk_err, sk->sk_shutdown);
              dump_stack();
      }
                              goto out_err;
                      }
              }
      ...
      
      4) Then the process (socket owner) understands that it's time to close
         that socket and does that (and thus triggers sending reset packet):
      
      Call Trace:
      ...
       [<ffffffff80032077>] dev_queue_xmit+0x343/0x3d6
       [<ffffffff80034698>] ip_output+0x351/0x384
       [<ffffffff80251ae9>] dst_output+0x0/0xe
       [<ffffffff80036ec6>] ip_queue_xmit+0x567/0x5d2
       [<ffffffff80095700>] vprintk+0x21/0x33
       [<ffffffff800070f0>] check_poison_obj+0x2e/0x206
       [<ffffffff80013587>] poison_obj+0x36/0x45
       [<ffffffff8025dea6>] tcp_send_active_reset+0x15/0x14d
       [<ffffffff80023481>] dbg_redzone1+0x1c/0x25
       [<ffffffff8025dea6>] tcp_send_active_reset+0x15/0x14d
       [<ffffffff8000ca94>] cache_alloc_debugcheck_after+0x189/0x1c8
       [<ffffffff80023405>] tcp_transmit_skb+0x764/0x786
       [<ffffffff8025df8a>] tcp_send_active_reset+0xf9/0x14d
       [<ffffffff80258ff1>] tcp_close+0x39a/0x960
       [<ffffffff8026be12>] inet_release+0x69/0x80
       [<ffffffff80059b31>] sock_release+0x4f/0xcf
       [<ffffffff80059d4c>] sock_close+0x2c/0x30
       [<ffffffff800133c9>] __fput+0xac/0x197
       [<ffffffff800252bc>] filp_close+0x59/0x61
       [<ffffffff8001eff6>] sys_close+0x85/0xc7
       [<ffffffff800622dd>] tracesys+0xd5/0xe0
      
      So, in brief:
      
      * a received packet for socket in TCP_CLOSE_WAIT state triggers
        tcp_reset() which clears inet_sk(sk)->num and put socket into
        TCP_CLOSE state
      
      * an attempt to write to that socket forces inet_autobind() to get a
        new port (but the write itself fails with -EPIPE)
      
      * tcp_close() called for socket in TCP_CLOSE state sends an active
        reset via socket with newly allocated port
      
      This adds an additional check in tcp_close() for already closed
      sockets. We do not want to send anything to closed sockets.
      Signed-off-by: NKonstantin Khorenko <khorenko@openvz.org>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      565b7b2d
  10. 16 6月, 2010 1 次提交
    • C
      tcp: unify tcp flag macros · a3433f35
      Changli Gao 提交于
      unify tcp flag macros: TCPHDR_FIN, TCPHDR_SYN, TCPHDR_RST, TCPHDR_PSH,
      TCPHDR_ACK, TCPHDR_URG, TCPHDR_ECE and TCPHDR_CWR. TCBCB_FLAG_* are replaced
      with the corresponding TCPHDR_*.
      Signed-off-by: NChangli Gao <xiaosuo@gmail.com>
      ----
       include/net/tcp.h                      |   24 ++++++-------
       net/ipv4/tcp.c                         |    8 ++--
       net/ipv4/tcp_input.c                   |    2 -
       net/ipv4/tcp_output.c                  |   59 ++++++++++++++++-----------------
       net/netfilter/nf_conntrack_proto_tcp.c |   32 ++++++-----------
       net/netfilter/xt_TCPMSS.c              |    4 --
       6 files changed, 58 insertions(+), 71 deletions(-)
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      a3433f35
  11. 31 5月, 2010 1 次提交
  12. 18 5月, 2010 1 次提交
  13. 16 5月, 2010 1 次提交
  14. 28 4月, 2010 1 次提交
  15. 21 4月, 2010 2 次提交
  16. 31 3月, 2010 1 次提交
  17. 30 3月, 2010 1 次提交
    • T
      include cleanup: Update gfp.h and slab.h includes to prepare for breaking... · 5a0e3ad6
      Tejun Heo 提交于
      include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
      
      percpu.h is included by sched.h and module.h and thus ends up being
      included when building most .c files.  percpu.h includes slab.h which
      in turn includes gfp.h making everything defined by the two files
      universally available and complicating inclusion dependencies.
      
      percpu.h -> slab.h dependency is about to be removed.  Prepare for
      this change by updating users of gfp and slab facilities include those
      headers directly instead of assuming availability.  As this conversion
      needs to touch large number of source files, the following script is
      used as the basis of conversion.
      
        http://userweb.kernel.org/~tj/misc/slabh-sweep.py
      
      The script does the followings.
      
      * Scan files for gfp and slab usages and update includes such that
        only the necessary includes are there.  ie. if only gfp is used,
        gfp.h, if slab is used, slab.h.
      
      * When the script inserts a new include, it looks at the include
        blocks and try to put the new include such that its order conforms
        to its surrounding.  It's put in the include block which contains
        core kernel includes, in the same order that the rest are ordered -
        alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
        doesn't seem to be any matching order.
      
      * If the script can't find a place to put a new include (mostly
        because the file doesn't have fitting include block), it prints out
        an error message indicating which .h file needs to be added to the
        file.
      
      The conversion was done in the following steps.
      
      1. The initial automatic conversion of all .c files updated slightly
         over 4000 files, deleting around 700 includes and adding ~480 gfp.h
         and ~3000 slab.h inclusions.  The script emitted errors for ~400
         files.
      
      2. Each error was manually checked.  Some didn't need the inclusion,
         some needed manual addition while adding it to implementation .h or
         embedding .c file was more appropriate for others.  This step added
         inclusions to around 150 files.
      
      3. The script was run again and the output was compared to the edits
         from #2 to make sure no file was left behind.
      
      4. Several build tests were done and a couple of problems were fixed.
         e.g. lib/decompress_*.c used malloc/free() wrappers around slab
         APIs requiring slab.h to be added manually.
      
      5. The script was run on all .h files but without automatically
         editing them as sprinkling gfp.h and slab.h inclusions around .h
         files could easily lead to inclusion dependency hell.  Most gfp.h
         inclusion directives were ignored as stuff from gfp.h was usually
         wildly available and often used in preprocessor macros.  Each
         slab.h inclusion directive was examined and added manually as
         necessary.
      
      6. percpu.h was updated not to include slab.h.
      
      7. Build test were done on the following configurations and failures
         were fixed.  CONFIG_GCOV_KERNEL was turned off for all tests (as my
         distributed build env didn't work with gcov compiles) and a few
         more options had to be turned off depending on archs to make things
         build (like ipr on powerpc/64 which failed due to missing writeq).
      
         * x86 and x86_64 UP and SMP allmodconfig and a custom test config.
         * powerpc and powerpc64 SMP allmodconfig
         * sparc and sparc64 SMP allmodconfig
         * ia64 SMP allmodconfig
         * s390 SMP allmodconfig
         * alpha SMP allmodconfig
         * um on x86_64 SMP allmodconfig
      
      8. percpu.h modifications were reverted so that it could be applied as
         a separate patch and serve as bisection point.
      
      Given the fact that I had only a couple of failures from tests on step
      6, I'm fairly confident about the coverage of this conversion patch.
      If there is a breakage, it's likely to be something in one of the arch
      headers which should be easily discoverable easily on most builds of
      the specific arch.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Guess-its-ok-by: NChristoph Lameter <cl@linux-foundation.org>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
      5a0e3ad6
  18. 21 3月, 2010 1 次提交
    • S
      NET_DMA: free skbs periodically · 73852e81
      Steven J. Magnani 提交于
      Under NET_DMA, data transfer can grind to a halt when userland issues a
      large read on a socket with a high RCVLOWAT (i.e., 512 KB for both).
      This appears to be because the NET_DMA design queues up lots of memcpy
      operations, but doesn't issue or wait for them (and thus free the
      associated skbs) until it is time for tcp_recvmesg() to return.
      The socket hangs when its TCP window goes to zero before enough data is
      available to satisfy the read.
      
      Periodically issue asynchronous memcpy operations, and free skbs for ones
      that have completed, to prevent sockets from going into zero-window mode.
      Signed-off-by: NSteven J. Magnani <steve@digidescorp.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      73852e81
  19. 19 3月, 2010 1 次提交
  20. 19 2月, 2010 2 次提交
    • A
      net: TCP thin dupack · 7e380175
      Andreas Petlund 提交于
      This patch enables fast retransmissions after one dupACK for
      TCP if the stream is identified as thin. This will reduce
      latencies for thin streams that are not able to trigger fast
      retransmissions due to high packet interarrival time. This
      mechanism is only active if enabled by iocontrol or syscontrol
      and the stream is identified as thin.
      Signed-off-by: NAndreas Petlund <apetlund@simula.no>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      7e380175
    • A
      net: TCP thin linear timeouts · 36e31b0a
      Andreas Petlund 提交于
      This patch will make TCP use only linear timeouts if the
      stream is thin. This will help to avoid the very high latencies
      that thin stream suffer because of exponential backoff. This
      mechanism is only active if enabled by iocontrol or syscontrol
      and the stream is identified as thin. A maximum of 6 linear
      timeouts is tried before exponential backoff is resumed.
      Signed-off-by: NAndreas Petlund <apetlund@simula.no>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      36e31b0a
  21. 17 2月, 2010 1 次提交
    • T
      percpu: add __percpu sparse annotations to net · 7d720c3e
      Tejun Heo 提交于
      Add __percpu sparse annotations to net.
      
      These annotations are to make sparse consider percpu variables to be
      in a different address space and warn if accessed without going
      through percpu accessors.  This patch doesn't affect normal builds.
      
      The macro and type tricks around snmp stats make things a bit
      interesting.  DEFINE/DECLARE_SNMP_STAT() macros mark the target field
      as __percpu and SNMP_UPD_PO_STATS() macro is updated accordingly.  All
      snmp_mib_*() users which used to cast the argument to (void **) are
      updated to cast it to (void __percpu **).
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Acked-by: NDavid S. Miller <davem@davemloft.net>
      Cc: Patrick McHardy <kaber@trash.net>
      Cc: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
      Cc: Vlad Yasevich <vladislav.yasevich@hp.com>
      Cc: netdev@vger.kernel.org
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      7d720c3e
  22. 24 12月, 2009 2 次提交
  23. 09 12月, 2009 1 次提交
  24. 03 12月, 2009 2 次提交
    • W
      TCPCT part 1e: implement socket option TCP_COOKIE_TRANSACTIONS · e56fb50f
      William Allen Simpson 提交于
      Provide per socket control of the TCP cookie option and SYN/SYNACK data.
      
      This is a straightforward re-implementation of an earlier (year-old)
      patch that no longer applies cleanly, with permission of the original
      author (Adam Langley):
      
          http://thread.gmane.org/gmane.linux.network/102586
      
      The principle difference is using a TCP option to carry the cookie nonce,
      instead of a user configured offset in the data.
      
      Allocations have been rearranged to avoid requiring GFP_ATOMIC.
      
      Requires:
         net: TCP_MSS_DEFAULT, TCP_MSS_DESIRED
         TCPCT part 1c: sysctl_tcp_cookie_size, socket option TCP_COOKIE_TRANSACTIONS
         TCPCT part 1d: define TCP cookie option, extend existing struct's
      
      Signed-off-by: William.Allen.Simpson@gmail.com
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      e56fb50f
    • W
      TCPCT part 1b: generate Responder Cookie secret · da5c78c8
      William Allen Simpson 提交于
      Define (missing) hash message size for SHA1.
      
      Define hashing size constants specific to TCP cookies.
      
      Add new function: tcp_cookie_generator().
      
      Maintain global secret values for tcp_cookie_generator().
      
      This is a significantly revised implementation of earlier (15-year-old)
      Photuris [RFC-2522] code for the KA9Q cooperative multitasking platform.
      
      Linux RCU technique appears to be well-suited to this application, though
      neither of the circular queue items are freed.
      
      These functions will also be used in subsequent patches that implement
      additional features.
      
      Signed-off-by: William.Allen.Simpson@gmail.com
      Acked-by: NEric Dumazet <eric.dumazet@gmail.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      da5c78c8
  25. 01 12月, 2009 1 次提交
  26. 14 11月, 2009 1 次提交
  27. 23 10月, 2009 1 次提交
  28. 20 10月, 2009 2 次提交
  29. 19 10月, 2009 1 次提交
    • E
      inet: rename some inet_sock fields · c720c7e8
      Eric Dumazet 提交于
      In order to have better cache layouts of struct sock (separate zones
      for rx/tx paths), we need this preliminary patch.
      
      Goal is to transfert fields used at lookup time in the first
      read-mostly cache line (inside struct sock_common) and move sk_refcnt
      to a separate cache line (only written by rx path)
      
      This patch adds inet_ prefix to daddr, rcv_saddr, dport, num, saddr,
      sport and id fields. This allows a future patch to define these
      fields as macros, like sk_refcnt, without name clashes.
      Signed-off-by: NEric Dumazet <eric.dumazet@gmail.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      c720c7e8
  30. 13 10月, 2009 1 次提交
  31. 03 10月, 2009 1 次提交
  32. 02 10月, 2009 1 次提交
  33. 01 10月, 2009 1 次提交