1. 05 11月, 2012 2 次提交
  2. 22 8月, 2012 7 次提交
  3. 21 8月, 2012 2 次提交
    • J
      svcrpc: fix svc_xprt_enqueue/svc_recv busy-looping · d10f27a7
      J. Bruce Fields 提交于
      The rpc server tries to ensure that there will be room to send a reply
      before it receives a request.
      
      It does this by tracking, in xpt_reserved, an upper bound on the total
      size of the replies that is has already committed to for the socket.
      
      Currently it is adding in the estimate for a new reply *before* it
      checks whether there is space available.  If it finds that there is not
      space, it then subtracts the estimate back out.
      
      This may lead the subsequent svc_xprt_enqueue to decide that there is
      space after all.
      
      The results is a svc_recv() that will repeatedly return -EAGAIN, causing
      server threads to loop without doing any actual work.
      
      Cc: stable@vger.kernel.org
      Reported-by: NMichael Tokarev <mjt@tls.msk.ru>
      Tested-by: NMichael Tokarev <mjt@tls.msk.ru>
      Signed-off-by: NJ. Bruce Fields <bfields@redhat.com>
      d10f27a7
    • J
      svcrpc: sends on closed socket should stop immediately · f06f00a2
      J. Bruce Fields 提交于
      svc_tcp_sendto sets XPT_CLOSE if we fail to transmit the entire reply.
      However, the XPT_CLOSE won't be acted on immediately.  Meanwhile other
      threads could send further replies before the socket is really shut
      down.  This can manifest as data corruption: for example, if a truncated
      read reply is followed by another rpc reply, that second reply will look
      to the client like further read data.
      
      Symptoms were data corruption preceded by svc_tcp_sendto logging
      something like
      
      	kernel: rpc-srv/tcp: nfsd: sent only 963696 when sending 1048708 bytes - shutting down socket
      
      Cc: stable@vger.kernel.org
      Reported-by: NMalahal Naineni <malahal@us.ibm.com>
      Tested-by: NMalahal Naineni <malahal@us.ibm.com>
      Signed-off-by: NJ. Bruce Fields <bfields@redhat.com>
      f06f00a2
  4. 01 6月, 2012 2 次提交
  5. 16 5月, 2012 1 次提交
  6. 15 2月, 2012 3 次提交
  7. 01 2月, 2012 1 次提交
  8. 12 12月, 2011 1 次提交
  9. 07 12月, 2011 4 次提交
    • S
      SUNRPC: create svc_xprt in proper network namespace · bd4620dd
      Stanislav Kinsbursky 提交于
      This patch makes svc_xprt inherit network namespace link from its socket.
      Signed-off-by: NStanislav Kinsbursky <skinsbursky@parallels.com>
      Signed-off-by: NJ. Bruce Fields <bfields@redhat.com>
      bd4620dd
    • J
      svcrpc: avoid memory-corruption on pool shutdown · b4f36f88
      J. Bruce Fields 提交于
      Socket callbacks use svc_xprt_enqueue() to add an xprt to a
      pool->sp_sockets list.  In normal operation a server thread will later
      come along and take the xprt off that list.  On shutdown, after all the
      threads have exited, we instead manually walk the sv_tempsocks and
      sv_permsocks lists to find all the xprt's and delete them.
      
      So the sp_sockets lists don't really matter any more.  As a result,
      we've mostly just ignored them and hoped they would go away.
      
      Which has gotten us into trouble; witness for example ebc63e53
      "svcrpc: fix list-corrupting race on nfsd shutdown", the result of Ben
      Greear noticing that a still-running svc_xprt_enqueue() could re-add an
      xprt to an sp_sockets list just before it was deleted.  The fix was to
      remove it from the list at the end of svc_delete_xprt().  But that only
      made corruption less likely--I can see nothing that prevents a
      svc_xprt_enqueue() from adding another xprt to the list at the same
      moment that we're removing this xprt from the list.  In fact, despite
      the earlier xpo_detach(), I don't even see what guarantees that
      svc_xprt_enqueue() couldn't still be running on this xprt.
      
      So, instead, note that svc_xprt_enqueue() essentially does:
      	lock sp_lock
      		if XPT_BUSY unset
      			add to sp_sockets
      	unlock sp_lock
      
      So, if we do:
      
      	set XPT_BUSY on every xprt.
      	Empty every sp_sockets list, under the sp_socks locks.
      
      Then we're left knowing that the sp_sockets lists are all empty and will
      stay that way, since any svc_xprt_enqueue() will check XPT_BUSY under
      the sp_lock and see it set.
      
      And *then* we can continue deleting the xprt's.
      
      (Thanks to Jeff Layton for being correctly suspicious of this code....)
      
      Cc: Ben Greear <greearb@candelatech.com>
      Cc: Jeff Layton <jlayton@redhat.com>
      Cc: stable@kernel.org
      Signed-off-by: NJ. Bruce Fields <bfields@redhat.com>
      b4f36f88
    • J
      svcrpc: destroy server sockets all at once · 2fefb8a0
      J. Bruce Fields 提交于
      There's no reason I can see that we need to call sv_shutdown between
      closing the two lists of sockets.
      
      Cc: stable@kernel.org
      Signed-off-by: NJ. Bruce Fields <bfields@redhat.com>
      2fefb8a0
    • J
      svcrpc: make svc_delete_xprt static · 7710ec36
      J. Bruce Fields 提交于
      Signed-off-by: NJ. Bruce Fields <bfields@redhat.com>
      7710ec36
  10. 01 11月, 2011 1 次提交
  11. 14 9月, 2011 1 次提交
  12. 16 7月, 2011 1 次提交
    • J
      svcrpc: fix list-corrupting race on nfsd shutdown · ebc63e53
      J. Bruce Fields 提交于
      After commit 3262c816 "[PATCH] knfsd:
      split svc_serv into pools", svc_delete_xprt (then svc_delete_socket) no
      longer removed its xpt_ready (then sk_ready) field from whatever list it
      was on, noting that there was no point since the whole list was about to
      be destroyed anyway.
      
      That was mostly true, but forgot that a few svc_xprt_enqueue()'s might
      still be hanging around playing with the about-to-be-destroyed list, and
      could get themselves into trouble writing to freed memory if we left
      this xprt on the list after freeing it.
      
      (This is actually functionally identical to a patch made first by Ben
      Greear, but with more comments.)
      
      Cc: stable@kernel.org
      Cc: gnb@fmeh.org
      Reported-by: NBen Greear <greearb@candelatech.com>
      Tested-by: NBen Greear <greearb@candelatech.com>
      Signed-off-by: NJ. Bruce Fields <bfields@redhat.com>
      ebc63e53
  13. 12 1月, 2011 1 次提交
    • J
      rpc: keep backchannel xprt as long as server connection · 99de8ea9
      J. Bruce Fields 提交于
      Multiple backchannels can share the same tcp connection; from rfc 5661 section
      2.10.3.1:
      
      	A connection's association with a session is not exclusive.  A
      	connection associated with the channel(s) of one session may be
      	simultaneously associated with the channel(s) of other sessions
      	including sessions associated with other client IDs.
      
      However, multiple backchannels share a connection, they must all share
      the same xid stream (hence the same rpc_xprt); the only way we have to
      match replies with calls at the rpc layer is using the xid.
      
      So, keep the rpc_xprt around as long as the connection lasts, in case
      we're asked to use the connection as a backchannel again.
      
      Requests to create new backchannel clients over a given server
      connection should results in creating new clients that reuse the
      existing rpc_xprt.
      
      But to start, just reject attempts to associate multiple rpc_xprt's with
      the same underlying bc_xprt.
      Signed-off-by: NJ. Bruce Fields <bfields@redhat.com>
      99de8ea9
  14. 05 1月, 2011 1 次提交
    • J
      svcrpc: simpler request dropping · 9e701c61
      J. Bruce Fields 提交于
      Currently we use -EAGAIN returns to determine when to drop a deferred
      request.  On its own, that is error-prone, as it makes us treat -EAGAIN
      returns from other functions specially to prevent inadvertent dropping.
      
      So, use a flag on the request instead.
      
      Returning an error on request deferral is still required, to prevent
      further processing, but we no longer need worry that an error return on
      its own could result in a drop.
      Signed-off-by: NJ. Bruce Fields <bfields@redhat.com>
      9e701c61
  15. 18 12月, 2010 1 次提交
    • N
      sunrpc: remove xpt_pool · 7c96aef7
      NeilBrown 提交于
      The xpt_pool field is only used for reporting BUGs.
      And it isn't used correctly.
      
      In particular, when it is cleared in svc_xprt_received before
      XPT_BUSY is cleared, there is no guarantee that either the
      compiler or the CPU might not re-order to two assignments, just
      setting xpt_pool to NULL after XPT_BUSY is cleared.
      
      If a different cpu were running svc_xprt_enqueue at this moment,
      it might see XPT_BUSY clear and then xpt_pool non-NULL, and
      so BUG.
      
      This could be fixed by calling
        smp_mb__before_clear_bit()
      before the clear_bit.  However as xpt_pool isn't really used,
      it seems safest to simply remove xpt_pool.
      
      Another alternate would be to change the clear_bit to
      clear_bit_unlock, and the test_and_set_bit to test_and_set_bit_lock.
      Signed-off-by: NNeilBrown <neilb@suse.de>
      Signed-off-by: NJ. Bruce Fields <bfields@redhat.com>
      7c96aef7
  16. 08 12月, 2010 1 次提交
    • N
      sunrpc: prevent use-after-free on clearing XPT_BUSY · ed2849d3
      NeilBrown 提交于
      When an xprt is created, it has a refcount of 1, and XPT_BUSY is set.
      The refcount is *not* owned by the thread that created the xprt
      (as is clear from the fact that creators never put the reference).
      Rather, it is owned by the absence of XPT_DEAD.  Once XPT_DEAD is set,
      (And XPT_BUSY is clear) that initial reference is dropped and the xprt
      can be freed.
      
      So when a creator clears XPT_BUSY it is dropping its only reference and
      so must not touch the xprt again.
      
      However svc_recv, after calling ->xpo_accept (and so getting an XPT_BUSY
      reference on a new xprt), calls svc_xprt_recieved.  This clears
      XPT_BUSY and then svc_xprt_enqueue - this last without owning a reference.
      This is dangerous and has been seen to leave svc_xprt_enqueue working
      with an xprt containing garbage.
      
      So we need to hold an extra counted reference over that call to
      svc_xprt_received.
      
      For safety, any time we clear XPT_BUSY and then use the xprt again, we
      first get a reference, and the put it again afterwards.
      
      Note that svc_close_all does not need this extra protection as there are
      no threads running, and the final free can only be called asynchronously
      from such a thread.
      Signed-off-by: NNeilBrown <neilb@suse.de>
      Cc: stable@kernel.org
      Signed-off-by: NJ. Bruce Fields <bfields@redhat.com>
      ed2849d3
  17. 20 11月, 2010 5 次提交
    • J
      svcrpc: fix wspace-checking race · 9c335c0b
      J. Bruce Fields 提交于
      We call svc_xprt_enqueue() after something happens which we think may
      require handling from a server thread.  To avoid such events being lost,
      svc_xprt_enqueue() must guarantee that there will be a svc_serv() call
      from a server thread following any such event.  It does that by either
      waking up a server thread itself, or checking that XPT_BUSY is set (in
      which case somebody else is doing it).
      
      But the check of XPT_BUSY could occur just as someone finishes
      processing some other event, and just before they clear XPT_BUSY.
      
      Therefore it's important not to clear XPT_BUSY without subsequently
      doing another svc_export_enqueue() to check whether the xprt should be
      requeued.
      
      The xpo_wspace() check in svc_xprt_enqueue() breaks this rule, allowing
      an event to be missed in situations like:
      
      	data arrives
      	call svc_tcp_data_ready():
      	call svc_xprt_enqueue():
      	set BUSY
      	find no write space
      				svc_reserve():
      				free up write space
      				call svc_enqueue():
      				test BUSY
      	clear BUSY
      
      So, instead, check wspace in the same places that the state flags are
      checked: before taking BUSY, and in svc_receive().
      Signed-off-by: NJ. Bruce Fields <bfields@redhat.com>
      9c335c0b
    • J
      svcrpc: svc_close_xprt comment · b1763316
      J. Bruce Fields 提交于
      Neil Brown had to explain to me why we do this here; record the answer
      for posterity.
      Signed-off-by: NJ. Bruce Fields <bfields@redhat.com>
      b1763316
    • J
      svcrpc: simplify svc_close_all · f8c0d226
      J. Bruce Fields 提交于
      There's no need to be fooling with XPT_BUSY now that all the threads
      are gone.
      
      The list_del_init() here could execute at the same time as the
      svc_xprt_enqueue()'s list_add_tail(), with undefined results.  We don't
      really care at this point, but it might result in a spurious
      list-corruption warning or something.
      
      And svc_close() isn't adding any value; just call svc_delete_xprt()
      directly.
      Signed-off-by: NJ. Bruce Fields <bfields@redhat.com>
      f8c0d226
    • J
      nfsd4: centralize more calls to svc_xprt_received · ca7896cd
      J. Bruce Fields 提交于
      Follow up on b48fa6b9 by moving all the
      svc_xprt_received() calls for the main xprt to one place.  The clearing
      of XPT_BUSY here is critical to the correctness of the server, so I'd
      prefer it to be obvious where we do it.
      
      The only substantive result is moving svc_xprt_received() after
      svc_receive_deferred().  Other than a (likely insignificant) delay
      waking up the next thread, that should be harmless.
      
      Also reshuffle the exit code a little to skip a few other steps that we
      don't care about the in the svc_delete_xprt() case.
      Signed-off-by: NJ. Bruce Fields <bfields@redhat.com>
      ca7896cd
    • J
      svcrpc: don't set then immediately clear XPT_DEFERRED · 62bac4af
      J. Bruce Fields 提交于
      There's no harm to doing this, since the only caller will immediately
      call svc_enqueue() afterwards, ensuring we don't miss the remaining
      deferred requests just because XPT_DEFERRED was briefly cleared.
      
      But why not just do this the simple way?
      Signed-off-by: NJ. Bruce Fields <bfields@redhat.com>
      62bac4af
  18. 18 11月, 2010 1 次提交
  19. 26 10月, 2010 3 次提交
  20. 19 10月, 2010 1 次提交