public inbox for linux-nfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Tom Tucker <tom@opengridcomputing.com>
To: Trond Myklebust <trond.myklebust@fys.uio.no>
Cc: "J. Bruce Fields" <bfields@fieldses.org>, linux-nfs@vger.kernel.org
Subject: Re: [PATCH 3/3] SUNRPC: svc_xprt_enqueue should not refuse to enqueue 'XPT_DEAD' transports
Date: Mon, 05 Jan 2009 14:41:54 -0600	[thread overview]
Message-ID: <49627092.3090405@opengridcomputing.com> (raw)
In-Reply-To: <1231185115.7127.28.camel-rJ7iovZKK19ZJLDQqaL3InhyD016LWXt@public.gmane.org>

Trond Myklebust wrote:
> On Mon, 2009-01-05 at 13:33 -0600, Tom Tucker wrote:
>> Trond Myklebust wrote:
>>> On Mon, 2009-01-05 at 11:04 -0600, Tom Tucker wrote:
>>>> Trond Myklebust wrote:
>>>>> On Sun, 2009-01-04 at 14:12 -0500, Trond Myklebust wrote:
>>>> [...snip...]
>>>>
>>>>>> I see nothing that stops svc_delete_xprt() from setting XPT_DEAD after
>>>>>> the above test in svc_revisit(), and before the test inside
>>>>>> svc_xprt_enqueue(). What's preventing a race there?
>>>>> I suppose one way to fix it would be to hold the xprt->xpt_lock across
>>>>> the above test, and to make sure that you set XPT_DEFERRED while holding
>>>>> the lock, and _before_ you test for XPT_DEAD. That way, you guarantee
>>>>> that the svc_deferred_dequeue() loop in svc_delete_xprt() will pick up
>>>>> anything that races with the setting of XPT_DEAD.
>>>>>
>>>>> Trond
>>>> I think this patch fixes this. Thanks again,
>>>>
>>>> From: Tom Tucker <tom@opengridcomputing.com>
>>>> Date: Mon, 5 Jan 2009 10:56:03 -0600
>>>> Subject: [PATCH] svc: Clean up deferred requests on transport destruction
>>>>
>>>> A race between svc_revisit and svc_delete_xprt can result in
>>>> deferred requests holding references on a transport that can never be
>>>> recovered because dead transports are not enqueued for subsequent
>>>> processing.
>>>>
>>>> Check for XPT_DEAD in revisit to clean up completing deferrals on a dead
>>>> transport and sweep a transport's deferred queue to do the same for queued
>>>> but unprocessed deferrals.
>>>>
>>>> Signed-off-by: Tom Tucker <tom@opengridcomputing.com>
>>>>
>>>> ---
>>>>   net/sunrpc/svc_xprt.c |   29 ++++++++++++++++++++++-------
>>>>   1 files changed, 22 insertions(+), 7 deletions(-)
>>>>
>>>> diff --git a/net/sunrpc/svc_xprt.c b/net/sunrpc/svc_xprt.c
>>>> index bf5b5cd..375a695 100644
>>>> --- a/net/sunrpc/svc_xprt.c
>>>> +++ b/net/sunrpc/svc_xprt.c
>>>> @@ -837,6 +837,15 @@ static void svc_age_temp_xprts(unsigned long closure)
>>>>   void svc_delete_xprt(struct svc_xprt *xprt)
>>>>   {
>>>>          struct svc_serv *serv = xprt->xpt_server;
>>>> +       struct svc_deferred_req *dr;
>>>> +
>>>> +       /* Only do this once */
>>>> +       spin_lock(&xprt->xpt_lock);
>>>> +       if (test_and_set_bit(XPT_DEAD, &xprt->xpt_flags)) {
>>>> +               spin_unlock(&xprt->xpt_lock);
>>>> +               return;
>>>> +       }
>>>> +       spin_unlock(&xprt->xpt_lock);
>>> You shouldn't need to take the spinlock here if you just move the line
>>> 	set_bit(XPT_DEFERRED, &xprt->xpt_flags);
>>> in svc_revisit(). See below...
>>>
>> I'm confused...sorry.
>>
>> This lock in intended to avoid the following race:
>>
>> 				revisit:
>> 					- test_bit == 0
>> svc_delete_xprt:
>> 	- test_and_set_bit == 0
>> 	- iterates over deferred queue,
>> 	  but there's nothing in it yet
>> 	  to clean up.
>>
>> 					- Adds deferred request to transport's
>> 					  deferred list.
>> 					- enqueue fails because XPT_DEAD is set
>>
>> Now we've got a dangling reference.
>>
>> The lock forces the delete to wait until the revisit had
>> added the deferral to the transport list.
>>
>>
>>>>          dprintk("svc: svc_delete_xprt(%p)\n", xprt);
>>>>          xprt->xpt_ops->xpo_detach(xprt);
>>>> @@ -851,12 +860,16 @@ void svc_delete_xprt(struct svc_xprt *xprt)
>>>>           * while still attached to a queue, the queue itself
>>>>           * is about to be destroyed (in svc_destroy).
>>>>           */
>>>> -       if (!test_and_set_bit(XPT_DEAD, &xprt->xpt_flags)) {
>>>> -               BUG_ON(atomic_read(&xprt->xpt_ref.refcount) < 2);
>>>> -               if (test_bit(XPT_TEMP, &xprt->xpt_flags))
>>>> -                       serv->sv_tmpcnt--;
>>>> +       if (test_bit(XPT_TEMP, &xprt->xpt_flags))
>>>> +               serv->sv_tmpcnt--;
>>>> +
>>>> +       for (dr = svc_deferred_dequeue(xprt); dr;
>>>> +            dr = svc_deferred_dequeue(xprt)) {
>>>>                  svc_xprt_put(xprt);
>>>> +               kfree(dr);
>>>>          }
>>>> +
>>>> +       svc_xprt_put(xprt);
>>>>          spin_unlock_bh(&serv->sv_lock);
>>>>   }
>>>>
>>>> @@ -902,17 +915,19 @@ static void svc_revisit(struct cache_deferred_req *dreq, int too_many)
>>>>                  container_of(dreq, struct svc_deferred_req, handle);
>>>>          struct svc_xprt *xprt = dr->xprt;
>>>>
>>>> -       if (too_many) {
>>>> +       spin_lock(&xprt->xpt_lock);
>>>  +        set_bit(XPT_DEFERRED, &xprt->xpt_flags);
>>>
>> Given the above, how does this avoid the race?
> 
> By setting XPT_DEFERRED, you will force svc_deferred_dequeue to wait for
> the xprt->xpt_lock, which you are already holding. At that point, it
> would be OK for the test of XPT_DEAD to race, since you are still
> holding the xpt_lock, so the loop over svc_deferred_dequeue() will catch
> it...
> 

Trond, this version removes the extra unnecessary spin locks.

If it's ok, do you want me to resend to Bruce, or
do you want to couple it with your other patch?

Thanks,
Tom

A race between svc_revisit and svc_delete_xprt can result in
deferred requests holding references on a transport that can never be
recovered because dead transports are not enqueued for subsequent
processing.

Check for XPT_DEAD in revisit to clean up completing deferrals on a dead
transport and sweep a transport's deferred queue to do the same for queued
but unprocessed deferrals.

Signed-off-by: Tom Tucker <tom@opengridcomputing.com>

---
  net/sunrpc/svc_xprt.c |   25 ++++++++++++++++++-------
  1 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/net/sunrpc/svc_xprt.c b/net/sunrpc/svc_xprt.c
index bf5b5cd..6bdbb79 100644
--- a/net/sunrpc/svc_xprt.c
+++ b/net/sunrpc/svc_xprt.c
@@ -837,6 +837,11 @@ static void svc_age_temp_xprts(unsigned long closure)
  void svc_delete_xprt(struct svc_xprt *xprt)
  {
  	struct svc_serv	*serv = xprt->xpt_server;
+	struct svc_deferred_req *dr;
+
+	/* Only do this once */
+	if (test_and_set_bit(XPT_DEAD, &xprt->xpt_flags))
+		return;

  	dprintk("svc: svc_delete_xprt(%p)\n", xprt);
  	xprt->xpt_ops->xpo_detach(xprt);
@@ -851,12 +856,16 @@ void svc_delete_xprt(struct svc_xprt *xprt)
  	 * while still attached to a queue, the queue itself
  	 * is about to be destroyed (in svc_destroy).
  	 */
-	if (!test_and_set_bit(XPT_DEAD, &xprt->xpt_flags)) {
-		BUG_ON(atomic_read(&xprt->xpt_ref.refcount) < 2);
-		if (test_bit(XPT_TEMP, &xprt->xpt_flags))
-			serv->sv_tmpcnt--;
+	if (test_bit(XPT_TEMP, &xprt->xpt_flags))
+		serv->sv_tmpcnt--;
+
+	for (dr = svc_deferred_dequeue(xprt); dr;
+	     dr = svc_deferred_dequeue(xprt)) {
  		svc_xprt_put(xprt);
+		kfree(dr);
  	}
+
+	svc_xprt_put(xprt);
  	spin_unlock_bh(&serv->sv_lock);
  }

@@ -902,17 +911,19 @@ static void svc_revisit(struct cache_deferred_req *dreq, int too_many)
  		container_of(dreq, struct svc_deferred_req, handle);
  	struct svc_xprt *xprt = dr->xprt;

-	if (too_many) {
+	spin_lock(&xprt->xpt_lock);
+	set_bit(XPT_DEFERRED, &xprt->xpt_flags);
+	if (too_many || test_bit(XPT_DEAD, &xprt->xpt_flags)) {
+		spin_unlock(&xprt->xpt_lock);
+		dprintk("revisit cancelled\n");
  		svc_xprt_put(xprt);
  		kfree(dr);
  		return;
  	}
  	dprintk("revisit queued\n");
  	dr->xprt = NULL;
-	spin_lock(&xprt->xpt_lock);
  	list_add(&dr->handle.recent, &xprt->xpt_deferred);
  	spin_unlock(&xprt->xpt_lock);
-	set_bit(XPT_DEFERRED, &xprt->xpt_flags);
  	svc_xprt_enqueue(xprt);
  	svc_xprt_put(xprt);
  }


> Cheers
>   Trond
> 
> 


  parent reply	other threads:[~2009-01-05 20:41 UTC|newest]

Thread overview: 79+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20081017123207.GA14979@rabbit.intern.cm-ag>
     [not found] ` <1224484046.23068.14.camel@localhost.localdomain>
     [not found]   ` <1225539927.2221.3.camel@localhost.localdomain>
     [not found]     ` <1225546878.4390.3.camel@heimdal.trondhjem.org>
2008-11-25  7:09       ` [PATCH] NFS regression in 2.6.26?, "task blocked for more than 120 seconds" Ian Campbell
     [not found]         ` <1227596962.16868.22.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2008-11-25 13:28           ` Trond Myklebust
     [not found]             ` <1227619696.7057.19.camel-rJ7iovZKK19ZJLDQqaL3InhyD016LWXt@public.gmane.org>
2008-11-25 13:38               ` Ian Campbell
     [not found]                 ` <1227620339.9425.99.camel-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
2008-11-25 13:57                   ` Trond Myklebust
     [not found]                     ` <1227621434.7057.33.camel-rJ7iovZKK19ZJLDQqaL3InhyD016LWXt@public.gmane.org>
2008-11-25 14:04                       ` Ian Campbell
     [not found]                         ` <1227621877.9425.102.camel-o4Be2W7LfRlXesXXhkcM7miJhflN2719@public.gmane.org>
2008-11-26 22:12                           ` Ian Campbell
     [not found]                             ` <1227737539.31008.2.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2008-12-01  0:17                               ` [PATCH 0/3] " Trond Myklebust
2008-12-01  0:19                                 ` [PATCH 2/3] SUNRPC: We only need to call svc_delete_xprt() once Trond Myklebust
     [not found]                                 ` <1228090631.7112.11.camel-rJ7iovZKK19ZJLDQqaL3InhyD016LWXt@public.gmane.org>
2008-12-01  0:18                                   ` [PATCH 1/3] SUNRPC: Ensure the server closes sockets in a timely fashion Trond Myklebust
     [not found]                                     ` <1228090719.7112.13.camel-rJ7iovZKK19ZJLDQqaL3InhyD016LWXt@public.gmane.org>
2008-12-17 15:27                                       ` Tom Tucker
2008-12-17 18:08                                         ` Trond Myklebust
     [not found]                                           ` <1229537296.7257.37.camel-rJ7iovZKK19ZJLDQqaL3InhyD016LWXt@public.gmane.org>
2008-12-17 18:59                                             ` Tom Tucker
2008-12-01  0:20                                   ` [PATCH 3/3] SUNRPC: svc_xprt_enqueue should not refuse to enqueue 'XPT_DEAD' transports Trond Myklebust
2008-12-17 15:35                                     ` Tom Tucker
2008-12-17 19:07                                       ` Trond Myklebust
     [not found]                                         ` <1229540877.7257.97.camel-rJ7iovZKK19ZJLDQqaL3InhyD016LWXt@public.gmane.org>
2008-12-23 14:49                                           ` Tom Tucker
2008-12-23 23:39                                             ` Tom Tucker
2009-01-02 21:44                                           ` Tom Tucker
2009-01-04 19:12                                             ` Trond Myklebust
     [not found]                                               ` <1231096358.7363.6.camel-rJ7iovZKK19ZJLDQqaL3InhyD016LWXt@public.gmane.org>
2009-01-04 19:25                                                 ` Trond Myklebust
2009-01-05  3:33                                                 ` Tom Tucker
     [not found]                                               ` <1231097131.7 363.11.camel@heimdal.trondhjem.org>
     [not found]                                                 ` <1231097131.7363.11.camel-rJ7iovZKK19ZJLDQqaL3InhyD016LWXt@public.gmane.org>
2009-01-05  3:33                                                   ` Tom Tucker
2009-01-05 17:04                                                   ` Tom Tucker
2009-01-05 17:13                                                     ` Trond Myklebust
     [not found]                                                       ` <1231175613.7127.6.camel-rJ7iovZKK19ZJLDQqaL3InhyD016LWXt@public.gmane.org>
2009-01-05 19:33                                                         ` Tom Tucker
2009-01-05 19:51                                                           ` Trond Myklebust
     [not found]                                                             ` <1231185115.7127.28.camel-rJ7iovZKK19ZJLDQqaL3InhyD016LWXt@public.gmane.org>
2009-01-05 20:13                                                               ` Tom Tucker
2009-01-05 20:41                                                               ` Tom Tucker [this message]
2009-01-05 20:48                                                                 ` Trond Myklebust
     [not found]                                                                   ` <1231188518.7127.30.camel-rJ7iovZKK19ZJLDQqaL3InhyD016LWXt@public.gmane.org>
2009-01-05 21:10                                                                     ` Tom Tucker
2008-12-01  0:29                                   ` [PATCH 0/3] NFS regression in 2.6.26?, "task blocked for more than 120 seconds" Trond Myklebust
     [not found]                                     ` <1228091380.7112.17.camel-rJ7iovZKK19ZJLDQqaL3InhyD016LWXt@public.gmane.org>
2008-12-02 15:22                                       ` Kasparek Tomas
2008-12-02 15:37                                         ` Trond Myklebust
     [not found]                                           ` <1228232222.3090.5.camel-rJ7iovZKK19ZJLDQqaL3InhyD016LWXt@public.gmane.org>
2008-12-02 16:26                                             ` Kasparek Tomas
2008-12-02 18:10                                               ` Trond Myklebust
     [not found]                                                 ` <1228241407.3090.7.camel-rJ7iovZKK19ZJLDQqaL3InhyD016LWXt@public.gmane.org>
2008-12-04 10:23                                                   ` Kasparek Tomas
     [not found]                                                     ` <1229284201.6463.98.camel@heimdal.trondhjem.org>
     [not found]                                                       ` <1229284201.6463.98.camel-rJ7iovZKK19ZJLDQqaL3InhyD016LWXt@public.gmane.org>
2008-12-16 12:05                                                         ` Kasparek Tomas
2008-12-16 12:10                                                           ` Kasparek Tomas
2008-12-16 12:59                                                             ` Trond Myklebust
2008-12-23 22:34                                                           ` Trond Myklebust
     [not found]                                                             ` <1230071647.17701.27.camel-rJ7iovZKK19ZJLDQqaL3InhyD016LWXt@public.gmane.org>
2009-01-05 12:18                                                               ` Kasparek Tomas
2009-01-09 14:56                                                               ` Kasparek Tomas
2009-01-09 17:59                                                                 ` Trond Myklebust
     [not found]                                                                   ` <1231523966.7179.67.camel-rJ7iovZKK19ZJLDQqaL3InhyD016LWXt@public.gmane.org>
2009-01-10 10:24                                                                     ` Kasparek Tomas
2009-01-10 16:00                                                                       ` Trond Myklebust
     [not found]                                                                         ` <20090112090404.GL47559@fit.vutbr.cz>
     [not found]                                                                           ` <1231782009.7322.12.camel@heimdal.trondhjem.org>
     [not found]                                                                             ` <1231809446.7322.17.camel@heimdal.trondhjem.org>
     [not found]                                                                               ` <1231809446.7322.17.camel-rJ7iovZKK19ZJLDQqaL3InhyD016LWXt@public.gmane.org>
2009-01-13 15:22                                                                                 ` Kasparek Tomas
2009-01-16 10:48                                                                                   ` Kasparek Tomas
2009-01-18 13:08                                                                                     ` Kasparek Tomas
2009-01-20 15:03                                                                                       ` Kasparek Tomas
2009-01-20 15:32                                                                                         ` Trond Myklebust
     [not found]                                                                                           ` <1232465547.7055.3.camel-rJ7iovZKK19ZJLDQqaL3InhyD016LWXt@public.gmane.org>
2009-01-28  8:18                                                                                             ` Kasparek Tomas
2009-02-06  6:35                                                                                               ` Kasparek Tomas
2009-02-10  7:55                                                                                                 ` Kasparek Tomas
2009-03-03 12:08                                                                                           ` Kasparek Tomas
2009-03-03 14:16                                                                                             ` Trond Myklebust
     [not found]                                                                                               ` <1236089767.9631.4.camel-rJ7iovZKK19ZJLDQqaL3InhyD016LWXt@public.gmane.org>
2009-03-25  8:46                                                                                                 ` Kasparek Tomas
2009-04-18  5:17                                                                                                 ` Kasparek Tomas
2009-04-22 17:27                                                                                                   ` NFS client packet storm on 2.6.27.x Kasparek Tomas
2009-04-29 12:12                                                                                                     ` Steve Dickson
     [not found]                                                                                                       ` <49F84436.5090007-AfCzQyP5zfLQT0dZR+AlfA@public.gmane.org>
2009-04-29 14:57                                                                                                         ` Kasparek Tomas
2009-06-25  5:55                                                                                                     ` Kasparek Tomas
2009-07-13 11:12                                                                                                       ` Kasparek Tomas
2009-07-13 17:20                                                                                                         ` [stable] " Greg KH
2009-07-13 17:40                                                                                                           ` Trond Myklebust
     [not found]                                                                                                             ` <1247506817.14524.25.camel-rJ7iovZKK19ZJLDQqaL3InhyD016LWXt@public.gmane.org>
2009-07-24  8:54                                                                                                               ` Kasparek Tomas
2009-07-28 18:31                                                                                                               ` Greg KH
2008-12-01 22:09                                   ` [PATCH 0/3] NFS regression in 2.6.26?, "task blocked for more than 120 seconds" Ian Campbell
     [not found]                                     ` <1228169383.20370.3.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2008-12-06 12:16                                       ` Ian Campbell
     [not found]                                         ` <1228565812.10856.30.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2008-12-14 18:24                                           ` Ian Campbell
     [not found]                                             ` <1229279045.3721.1.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2008-12-16 17:55                                               ` J. Bruce Fields
2008-12-16 18:39                                                 ` Ian Campbell
     [not found]                                                   ` <1229452775.3721.25.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2009-01-07 22:21                                                     ` J. Bruce Fields
2009-01-08 18:20                                                       ` J. Bruce Fields
2009-01-08 21:22                                                         ` Ian Campbell
     [not found]                                                           ` <1231449753.21688.12.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2009-01-08 21:26                                                             ` J. Bruce Fields
2009-01-12  9:46                                                               ` Ian Campbell
2009-01-22  8:27                                                               ` Ian Campbell
     [not found]                                                                 ` <1232612860.29604.57.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2009-01-22 16:44                                                                   ` J. Bruce Fields
2008-11-26  9:16                 ` [PATCH] NFS regression in 2.6.26?, Tomas Kasparek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=49627092.3090405@opengridcomputing.com \
    --to=tom@opengridcomputing.com \
    --cc=bfields@fieldses.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=trond.myklebust@fys.uio.no \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox