Skip to contentSkip to conversation

NLM: fix lockd hang when client blocking on released lock isn't responding

PATCH In review Jeff Layton 4 participants 14 messages Feb 6, 2008 – Mar 14, 2008 6 messages not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover NLM: fix lockd hang when client blocking on released lock isn't responding

This patchset fixes the problem that Bruce pointed out last week when we were discussing the lockd-kthread patches.

The main problem is described in patch #1 and that patch also fixes the DoS. The remaining patches clean up how GRANT_MSG callbacks handle an unresponsive client. The goal in those is to make sure that we don't end up with a ton of duplicate RPC's in queue and that we try to handle an invalidated block correctly.

Bruce, I'd like to see this fixed in 2.6.25 if at all possible.

Comments and suggestions are appreciated.

#1 lore raw

PATCH 1/4 NLM: set RPC_CLNT_CREATE_NOPING for NLM RPC clients

It's currently possible for an unresponsive NLM client to completely lock up a server's lockd. The scenario is something like this:

1) client1 (or a process on the server) takes a lock on a file
2) client2 tries to take a blocking lock on the same file and awaits the callback
3) client2 goes unresponsive (plug pulled, network partition, etc)
4) client1 releases the lock

...at that point the server's lockd will try to queue up a GRANT_MSG callback for client2, but first it requeues the block with a timeout of 30s. nlm_async_call will attempt to bind the RPC client to client2 and will call rpc_ping. rpc_ping entails a sync RPC call and if client2 is unresponsive it will take around 60s for that to time out. Once it times out, it's already time to retry the block and the whole process repeats.

Once in this situation, nlmsvc_retry_blocked will never return until the host starts responding again. lockd won't service new calls.

Fix this by skipping the RPC ping on NLM RPC clients. This makes nlm_async_call return quickly when called.

---
 fs/lockd/host.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
fs/lockd/host.c +1 -0
index ca6b16f..00063ee 100644
@@ -244,6 +244,7 @@ nlm_bind_host(struct nlm_host *host)
 			.version	= host->h_version,
 			.authflavor	= RPC_AUTH_UNIX,
 			.flags		= (RPC_CLNT_CREATE_HARDRTRY |
+					   RPC_CLNT_CREATE_NOPING |
 					   RPC_CLNT_CREATE_AUTOBIND),
 		};
 
Signature · 1 line
1.5.3.8
#2 lore raw

PATCH 2/4 NLM: have server-side RPC clients default to soft RPC tasks

Now that it no longer does an RPC ping, lockd always ends up queueing an RPC task for the GRANT_MSG callback. But, it also requeues the block for later attempts. Since these are hard RPC tasks, if the client we're calling back goes unresponsive the GRANT_MSG callbacks can stack up in the RPC queue.

Fix this by making server-side RPC clients default to soft RPC tasks. lockd requeues the block anyway, so this should be OK.

---
 fs/lockd/host.c |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)
fs/lockd/host.c +9 -2
index 00063ee..f1ef49f 100644
@@ -243,11 +243,18 @@ nlm_bind_host(struct nlm_host *host)
 			.program	= &nlm_program,
 			.version	= host->h_version,
 			.authflavor	= RPC_AUTH_UNIX,
-			.flags		= (RPC_CLNT_CREATE_HARDRTRY |
-					   RPC_CLNT_CREATE_NOPING |
+			.flags		= (RPC_CLNT_CREATE_NOPING |
 					   RPC_CLNT_CREATE_AUTOBIND),
 		};
 
+		/*
+		 * lockd retries server side blocks automatically so we want
+		 * those to be soft RPC calls. Client side calls need to be
+		 * hard RPC tasks.
+		 */
+		if (!host->h_server)
+			args.flags |= RPC_CLNT_CREATE_HARDRTRY;
+
 		clnt = rpc_create(&args);
 		if (!IS_ERR(clnt))
 			host->h_rpcclnt = clnt;
Signature · 1 line
1.5.3.8
#3 lore raw

PATCH 3/4 NLM: don't reattempt GRANT_MSG when there is already an RPC in flight

With the current scheme in nlmsvc_grant_blocked, we can end up with more than one GRANT_MSG callback for a block in flight. Right now, we requeue the block unconditionally so that a GRANT_MSG callback is done again in 30s. If the client is unresponsive, it can take more than 30s for the call already in flight to time out.

There's no benefit to having more than one GRANT_MSG RPC queued up at a time, so put it on the list with a timeout of NLM_NEVER before doing the RPC call. If the RPC call submission fails, we requeue it with a short timeout. If it works, then nlmsvc_grant_callback will end up requeueing it with a shorter timeout after it completes.

---
 fs/lockd/svclock.c |   17 +++++++++++++----
 1 files changed, 13 insertions(+), 4 deletions(-)
fs/lockd/svclock.c +13 -4
index 2f4d8fa..82db7b3 100644
@@ -763,11 +763,20 @@ callback:
 	dprintk("lockd: GRANTing blocked lock.\n");
 	block->b_granted = 1;
 
-	/* Schedule next grant callback in 30 seconds */
-	nlmsvc_insert_block(block, 30 * HZ);
+	/* keep block on the list, but don't reattempt until the RPC
+	 * completes or the submission fails
+	 */
+	nlmsvc_insert_block(block, NLM_NEVER);
 
-	/* Call the client */
-	nlm_async_call(block->b_call, NLMPROC_GRANTED_MSG, &nlmsvc_grant_ops);
+	/* Call the client -- use a soft RPC task since nlmsvc_retry_blocked
+	 * will queue up a new one if this one times out
+	 */
+	error = nlm_async_call(block->b_call, NLMPROC_GRANTED_MSG,
+				&nlmsvc_grant_ops);
+
+	/* RPC submission failed, wait a bit and retry */
+	if (error < 0)
+		nlmsvc_insert_block(block, 10 * HZ);
 }
 
 /*
Signature · 1 line
1.5.3.8
#4 lore raw

PATCH 4/4 NLM: don't requeue block if it was invalidated while GRANT_MSG was in flight

It's possible for lockd to catch a SIGKILL while a GRANT_MSG callback is in flight. If this happens we don't want lockd to insert the block back into the nlm_blocked list.

This helps that situation, but there's still a possible race. Fixing that will mean adding real locking for nlm_blocked.

---
 fs/lockd/svclock.c |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)
fs/lockd/svclock.c +11 -0
index 82db7b3..fe9bdb4 100644
@@ -795,6 +795,17 @@ static void nlmsvc_grant_callback(struct rpc_task *task, void *data)
 
 	dprintk("lockd: GRANT_MSG RPC callback\n");
 
+	/* if the block is not on a list at this point then it has
+	 * been invalidated. Don't try to requeue it.
+	 *
+	 * FIXME: it's possible that the block is removed from the list
+	 * after this check but before the nlmsvc_insert_block. In that
+	 * case it will be added back. Perhaps we need better locking
+	 * for nlm_blocked?
+	 */
+	if (list_empty(&block->b_list))
+		return;
+
 	/* Technically, we should down the file semaphore here. Since we
 	 * move the block towards the head of the queue only, no harm
 	 * can be done, though. */
Signature · 1 line
1.5.3.8
#5 lore raw

Re: [PATCH 4/4] NLM: don't requeue block if it was invalidated while GRANT_MSG was in flight

Quoted 28 lines · Jeff Layton

It's possible for lockd to catch a SIGKILL while a GRANT_MSG callback
is in flight. If this happens we don't want lockd to insert the block back into the nlm_blocked list.

This helps that situation, but there's still a possible race. Fixing that will mean adding real locking for nlm_blocked.

---

  fs/lockd/svclock.c |   11 +++++++++++
  1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/fs/lockd/svclock.c b/fs/lockd/svclock.c
index 82db7b3..fe9bdb4 100644
--- a/fs/lockd/svclock.c
+++ b/fs/lockd/svclock.c
@@ -795,6 +795,17 @@ static void nlmsvc_grant_callback(struct rpc_task *task, void *data)

        dprintk("lockd: GRANT_MSG RPC callback\n");

+ /* if the block is not on a list at this point then it has

 +        * been invalidated. Don't try to requeue it.
 +        *
 +        * FIXME: it's possible that the block is removed from the list
 +        * after this check but before the nlmsvc_insert_block. In that
 +        * case it will be added back. Perhaps we need better locking
 +        * for nlm_blocked?
 +        */
Quoted 7 lines

+ if (list_empty(&block->b_list))
+ return;
+
/* Technically, we should down the file semaphore here. Since we
* move the block towards the head of the queue only, no harm
* can be done, though. */

Hi Jeff,

Would the following patch take care of this race? Two questions I have:
1) Does my patch address your FIXME? I believe it should.
2) Can I get rid of the BKL in nlmsvc_grant_deferred() given this nlm_blocked serialization? It is unclear to me if nlmsvc_grant_deferred() is taking the BKL purely to protect nlm_blocked.

As an aside, I'm not convinced that the SIGKILL-only assertion you're making about the block not being on the list is valid considering it looks to me like there is a race in nlmsvc_lock().

The block isn't added to nlm_blocked until after there is an opening for the FS to callback via fl_grant(). Whereby causing nlmsvc_grant_callback() to not find the block on the list.

Mike

fs/lockd/svc.c +1 -0
index 1ed8bd4..7614499 100644
@@ -128,6 +128,7 @@ lockd(struct svc_rqst *rqstp)
 	/*
 	 * Let our maker know we're running.
 	 */
+	nlmsvc_init();
 	nlmsvc_pid = current->pid;
 	nlmsvc_serv = rqstp->rq_server;
 	complete(&lockd_start_done);
fs/lockd/svclock.c +34 -7

122 lines not on this page · raw message

include/linux/lockd/lockd.h +1 -0
index 4babb2a..667d791 100644
@@ -206,6 +206,7 @@ unsigned long	  nlmsvc_retry_blocked(void);
 void		  nlmsvc_traverse_blocks(struct nlm_host *, struct nlm_file *,
 					nlm_host_match_fn_t match);
 void		  nlmsvc_grant_reply(struct nlm_cookie *, __be32);
+void		  nlmsvc_init(void);
 
 /*
  * File handling for the server personality

A message that is not in the archive (sent off-list or not yet received): 170fa0d20803141255k41e8e2a3t6a53f4f812a15d7b-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#7 lore raw

Re: [PATCH 4/4] NLM: don't requeue block if it was invalidated while GRANT_MSG was in flight

Quoted 37 lines · On Fri, 14 Mar 2008 15:55:38 -0400 "Mike Snitzer" <[email protected]> wrote:
Quoted 28 lines · Jeff Layton

It's possible for lockd to catch a SIGKILL while a GRANT_MSG callback
is in flight. If this happens we don't want lockd to insert the block back into the nlm_blocked list.

This helps that situation, but there's still a possible race. Fixing that will mean adding real locking for nlm_blocked.

---

  fs/lockd/svclock.c |   11 +++++++++++
  1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/fs/lockd/svclock.c b/fs/lockd/svclock.c
index 82db7b3..fe9bdb4 100644
--- a/fs/lockd/svclock.c
+++ b/fs/lockd/svclock.c
@@ -795,6 +795,17 @@ static void nlmsvc_grant_callback(struct rpc_task *task, void *data)

        dprintk("lockd: GRANT_MSG RPC callback\n");

+ /* if the block is not on a list at this point then it has

 +        * been invalidated. Don't try to requeue it.
 +        *
 +        * FIXME: it's possible that the block is removed from the list
 +        * after this check but before the nlmsvc_insert_block. In that
 +        * case it will be added back. Perhaps we need better locking
 +        * for nlm_blocked?
 +        */
Quoted 7 lines

+ if (list_empty(&block->b_list))
+ return;
+
/* Technically, we should down the file semaphore here. Since we
* move the block towards the head of the queue only, no harm
* can be done, though. */

Quoted 4 lines

Hi Jeff,

Would the following patch take care of this race? Two questions I have:
1) Does my patch address your FIXME? I believe it should.

I don't think so. I think you'd have to have nlmsvc_grant_callback() take and hold your nlm_blocked_mutex over the whole function.

Quoted 5 lines

2) Can I get rid of the BKL in nlmsvc_grant_deferred() given this nlm_blocked serialization? It is unclear to me if nlmsvc_grant_deferred() is taking the BKL purely to protect nlm_blocked.

I'm not at all clear on why we have so much of this done under the BKL. I'm not sure that anyone does. If you could figure it out and document it, you'd be my hero. My understanding was that it had more to do with VFS locking, but I could certainly be wrong on this.

Now that you mention it though, it does look like we do rpc_call_done under the BKL. So you may be right that that's actually protecting nlm_blocked here. My FIXME may be bogus.

The main user of nlm_blocked is lockd itself. I don't think anything else generally touches that list. Since lockd is single-threaded by design, locking the list may be unnecessary. The exception is the grant callback here, which runs from rpciod. But if that's protected by the BKL, it may not be a problem.

Quoted 8 lines

As an aside, I'm not convinced that the SIGKILL-only assertion you're making about the block not being on the list is valid considering it looks to me like there is a race in nlmsvc_lock().

The block isn't added to nlm_blocked until after there is an opening for the FS to callback via fl_grant(). Whereby causing nlmsvc_grant_callback() to not find the block on the list.

I'm not sure I see this race. nlmsvc_grant_callback() won't get called until after nlmsvc_grant_blocked() has does the RPC call. That doesn't happen until the block has been added to the list. Can you elaborate on the race you're seeing?

Signature · 1 line
Jeff Layton <[email protected]>

A message that is not in the archive (sent off-list or not yet received): 20080314170120.790f99a9-RtJpwOs3+0O+kQycOl6kW4xkIHaj4LzF@public.gmane.org

#9 lore raw

Re: [PATCH 4/4] NLM: don't requeue block if it was invalidated while GRANT_MSG was in flight

Quoted 40 lines · Jeff Layton
Quoted 37 lines · On Fri, 14 Mar 2008 15:55:38 -0400 "Mike Snitzer" <[email protected]> wrote:
Quoted 35 lines · Jeff Layton

It's possible for lockd to catch a SIGKILL while a GRANT_MSG callback
is in flight. If this happens we don't want lockd to insert the block back into the nlm_blocked list.

This helps that situation, but there's still a possible race. Fixing that will mean adding real locking for nlm_blocked.

---

  fs/lockd/svclock.c |   11 +++++++++++
  1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/fs/lockd/svclock.c b/fs/lockd/svclock.c
index 82db7b3..fe9bdb4 100644
--- a/fs/lockd/svclock.c
+++ b/fs/lockd/svclock.c
@@ -795,6 +795,17 @@ static void nlmsvc_grant_callback(struct rpc_task *task, void *data)

        dprintk("lockd: GRANT_MSG RPC callback\n");

+ /* if the block is not on a list at this point then it has

 +        * been invalidated. Don't try to requeue it.
 +        *
 +        * FIXME: it's possible that the block is removed from the list
 +        * after this check but before the nlmsvc_insert_block. In that
 +        * case it will be added back. Perhaps we need better locking
 +        * for nlm_blocked?
 +        */

+ if (list_empty(&block->b_list))
+ return;
+
/* Technically, we should down the file semaphore here. Since we
* move the block towards the head of the queue only, no harm
* can be done, though. */

Quoted 8 lines
Quoted 4 lines

Hi Jeff,

Would the following patch take care of this race? Two questions I have:
1) Does my patch address your FIXME? I believe it should.

I don't think so. I think you'd have to have nlmsvc_grant_callback()
take and hold your nlm_blocked_mutex over the whole function.

OK.

Quoted 11 lines
Quoted 5 lines

2) Can I get rid of the BKL in nlmsvc_grant_deferred() given this nlm_blocked serialization? It is unclear to me if nlmsvc_grant_deferred() is taking the BKL purely to protect nlm_blocked.

I'm not at all clear on why we have so much of this done under the BKL.
I'm not sure that anyone does. If you could figure it out and document it, you'd be my hero. My understanding was that it had more to do with VFS locking, but I could certainly be wrong on this.

OK, yes.. I was hoping someone else could be my hero ;)

Quoted 9 lines

Now that you mention it though, it does look like we do rpc_call_done under the BKL. So you may be right that that's actually protecting nlm_blocked here. My FIXME may be bogus.

The main user of nlm_blocked is lockd itself. I don't think anything else generally touches that list. Since lockd is single-threaded by design, locking the list may be unnecessary. The exception is the grant callback here, which runs from rpciod. But if that's protected by the BKL, it may not be a problem.

Correct, nlm_blocked is local to svclock.c
I'm concerned precisely with the ->fl_grant callback and it's access of nlm_blocked.

Quoted 10 lines
Quoted 8 lines

As an aside, I'm not convinced that the SIGKILL-only assertion you're making about the block not being on the list is valid considering it looks to me like there is a race in nlmsvc_lock().

The block isn't added to nlm_blocked until after there is an opening for the FS to callback via fl_grant(). Whereby causing nlmsvc_grant_callback() to not find the block on the list.

Quoted 4 lines

I'm not sure I see this race. nlmsvc_grant_callback() won't get called
until after nlmsvc_grant_blocked() has does the RPC call. That doesn't happen until the block has been added to the list. Can you elaborate on the race you're seeing?

I'm sorry I meant nlmsvc_grant_deferred() (aka ->fl_grant) not nlmsvc_grant_blocked().

The race appears to be that the BKL is not always held on entry into nlmsvc_lock() and the call to vfs_lock_file() is made. If vfs_lock_file() returns -EINPROGRESS for a F_SETLK request the block will get added to nlm_blocked.

But there is a distinct possibility that ->fl_grant() can race against vfs_lock_file() returning and nlmsvc_lock() adding the block to nlm_blocked.

This would be a non-issue if both nlmsvc_lock() and nlmsvc_grant_deferred() are _always_ called with the BKL. But again, it seems nlmsvc_lock() didn't reliably have the BKL.

Mike

#10 lore raw

Re: [PATCH 4/4] NLM: don't requeue block if it was invalidated while GRANT_MSG was in flight

In reply to a message not in the archive
Quoted 37 lines · Mike Snitzer
Quoted 28 lines · Jeff Layton

It's possible for lockd to catch a SIGKILL while a GRANT_MSG callback
is in flight. If this happens we don't want lockd to insert the block back into the nlm_blocked list.

This helps that situation, but there's still a possible race. Fixing that will mean adding real locking for nlm_blocked.

---

  fs/lockd/svclock.c |   11 +++++++++++
  1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/fs/lockd/svclock.c b/fs/lockd/svclock.c
index 82db7b3..fe9bdb4 100644
--- a/fs/lockd/svclock.c
+++ b/fs/lockd/svclock.c
@@ -795,6 +795,17 @@ static void nlmsvc_grant_callback(struct rpc_task *task, void *data)

        dprintk("lockd: GRANT_MSG RPC callback\n");

+ /* if the block is not on a list at this point then it has

 +        * been invalidated. Don't try to requeue it.
 +        *
 +        * FIXME: it's possible that the block is removed from the list
 +        * after this check but before the nlmsvc_insert_block. In that
 +        * case it will be added back. Perhaps we need better locking
 +        * for nlm_blocked?
 +        */
Quoted 7 lines

+ if (list_empty(&block->b_list))
+ return;
+
/* Technically, we should down the file semaphore here. Since we
* move the block towards the head of the queue only, no harm
* can be done, though. */

Quoted 8 lines

Hi Jeff,

Would the following patch take care of this race? Two questions I have:
1) Does my patch address your FIXME? I believe it should.
2) Can I get rid of the BKL in nlmsvc_grant_deferred() given this nlm_blocked serialization? It is unclear to me if nlmsvc_grant_deferred() is taking the BKL purely to protect nlm_blocked.

Ugh... NACK!

We already have the file->f_mutex, so there should be no need to add a global semaphore on top of that.

Trond

A message that is not in the archive (sent off-list or not yet received): 1205529061.27906.86.camel-rJ7iovZKK19ZJLDQqaL3InhyD016LWXt@public.gmane.org

#12 lore raw

Re: [PATCH 4/4] NLM: don't requeue block if it was invalidated while GRANT_MSG was in flight

Quoted 49 lines · Trond Myklebust
Quoted 37 lines · Mike Snitzer
Quoted 28 lines · Jeff Layton

It's possible for lockd to catch a SIGKILL while a GRANT_MSG callback
is in flight. If this happens we don't want lockd to insert the block back into the nlm_blocked list.

This helps that situation, but there's still a possible race. Fixing that will mean adding real locking for nlm_blocked.

---

  fs/lockd/svclock.c |   11 +++++++++++
  1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/fs/lockd/svclock.c b/fs/lockd/svclock.c
index 82db7b3..fe9bdb4 100644
--- a/fs/lockd/svclock.c
+++ b/fs/lockd/svclock.c
@@ -795,6 +795,17 @@ static void nlmsvc_grant_callback(struct rpc_task *task, void *data)

        dprintk("lockd: GRANT_MSG RPC callback\n");

+ /* if the block is not on a list at this point then it has

 +        * been invalidated. Don't try to requeue it.
 +        *
 +        * FIXME: it's possible that the block is removed from the list
 +        * after this check but before the nlmsvc_insert_block. In that
 +        * case it will be added back. Perhaps we need better locking
 +        * for nlm_blocked?
 +        */
Quoted 7 lines

+ if (list_empty(&block->b_list))
+ return;
+
/* Technically, we should down the file semaphore here. Since we
* move the block towards the head of the queue only, no harm
* can be done, though. */

Quoted 8 lines

Hi Jeff,

Would the following patch take care of this race? Two questions I have:
1) Does my patch address your FIXME? I believe it should.
2) Can I get rid of the BKL in nlmsvc_grant_deferred() given this nlm_blocked serialization? It is unclear to me if nlmsvc_grant_deferred() is taking the BKL purely to protect nlm_blocked.

Quoted 4 lines

Ugh... NACK!

We already have the file->f_mutex, so there should be no need to add a global semaphore on top of that.

Um, nlm_blocked is global. file->f_mutex is local. What am I missing?

A message that is not in the archive (sent off-list or not yet received): 170fa0d20803141421s5c784d16ie1db8e1d57e4b428-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#14 lore raw

Re: [PATCH 4/4] NLM: don't requeue block if it was invalidated while GRANT_MSG was in flight

Quoted 50 lines · Mike Snitzer
Quoted 49 lines · Trond Myklebust
Quoted 45 lines · Mike Snitzer
Quoted 28 lines · Jeff Layton

It's possible for lockd to catch a SIGKILL while a GRANT_MSG callback
is in flight. If this happens we don't want lockd to insert the block back into the nlm_blocked list.

This helps that situation, but there's still a possible race. Fixing that will mean adding real locking for nlm_blocked.

---

  fs/lockd/svclock.c |   11 +++++++++++
  1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/fs/lockd/svclock.c b/fs/lockd/svclock.c
index 82db7b3..fe9bdb4 100644
--- a/fs/lockd/svclock.c
+++ b/fs/lockd/svclock.c
@@ -795,6 +795,17 @@ static void nlmsvc_grant_callback(struct rpc_task *task, void *data)

        dprintk("lockd: GRANT_MSG RPC callback\n");

+ /* if the block is not on a list at this point then it has

 +        * been invalidated. Don't try to requeue it.
 +        *
 +        * FIXME: it's possible that the block is removed from the list
 +        * after this check but before the nlmsvc_insert_block. In that
 +        * case it will be added back. Perhaps we need better locking
 +        * for nlm_blocked?
 +        */
Quoted 7 lines

+ if (list_empty(&block->b_list))
+ return;
+
/* Technically, we should down the file semaphore here. Since we
* move the block towards the head of the queue only, no harm
* can be done, though. */

Hi Jeff,

Would the following patch take care of this race? Two questions I have:
1) Does my patch address your FIXME? I believe it should.
2) Can I get rid of the BKL in nlmsvc_grant_deferred() given this nlm_blocked serialization? It is unclear to me if nlmsvc_grant_deferred() is taking the BKL purely to protect nlm_blocked.

Quoted 6 lines
Quoted 4 lines

Ugh... NACK!

We already have the file->f_mutex, so there should be no need to add a global semaphore on top of that.

Um, nlm_blocked is global. file->f_mutex is local. What am I missing?

The _race_ occurs when the block is temporarily removed and replaced on the list.

This should, AFAIK, only occur while holding the file->f_mutex. Similarly, the GRANTED code should be holding the same lock when looking up the block.

A message that is not in the archive (sent off-list or not yet received): 1205530164.27906.100.camel-rJ7iovZKK19ZJLDQqaL3InhyD016LWXt@public.gmane.org

#16 lore raw

Re: [PATCH 4/4] NLM: don't requeue block if it was invalidated while GRANT_MSG was in flight

Quoted 54 lines · On Fri, 14 Mar 2008 17:29:24 -0400 Trond Myklebust…
Quoted 52 lines · Mike Snitzer
Quoted 51 lines · Trond Myklebust
Quoted 37 lines · Mike Snitzer
Quoted 28 lines · Jeff Layton

It's possible for lockd to catch a SIGKILL while a GRANT_MSG callback
is in flight. If this happens we don't want lockd to insert the block back into the nlm_blocked list.

This helps that situation, but there's still a possible race. Fixing that will mean adding real locking for nlm_blocked.

---

  fs/lockd/svclock.c |   11 +++++++++++
  1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/fs/lockd/svclock.c b/fs/lockd/svclock.c
index 82db7b3..fe9bdb4 100644
--- a/fs/lockd/svclock.c
+++ b/fs/lockd/svclock.c
@@ -795,6 +795,17 @@ static void nlmsvc_grant_callback(struct rpc_task *task, void *data)

        dprintk("lockd: GRANT_MSG RPC callback\n");

+ /* if the block is not on a list at this point then it has

 +        * been invalidated. Don't try to requeue it.
 +        *
 +        * FIXME: it's possible that the block is removed from the list
 +        * after this check but before the nlmsvc_insert_block. In that
 +        * case it will be added back. Perhaps we need better locking
 +        * for nlm_blocked?
 +        */
Quoted 7 lines

+ if (list_empty(&block->b_list))
+ return;
+
/* Technically, we should down the file semaphore here. Since we
* move the block towards the head of the queue only, no harm
* can be done, though. */

Quoted 8 lines

Hi Jeff,

Would the following patch take care of this race? Two questions I have:
1) Does my patch address your FIXME? I believe it should.
2) Can I get rid of the BKL in nlmsvc_grant_deferred() given this nlm_blocked serialization? It is unclear to me if nlmsvc_grant_deferred() is taking the BKL purely to protect nlm_blocked.

Ugh... NACK!

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

We already have the file->f_mutex, so there should be no need to add a global semaphore on top of that.

Um, nlm_blocked is global. file->f_mutex is local. What am I missing?

The _race_ occurs when the block is temporarily removed and replaced on the list.

The race I had in mind was:

rpciod: nlmsvc_grant_callback checks to see if the block is on the list
lockd:  lockd() removes the block from the list after getting a SIGKILL
rpciod: nlmsvc_grant_callback requeues the block with a new timeout

...though now that I've looked, it seems like the BKL should prevent that particular race.

Quoted 4 lines

This should, AFAIK, only occur while holding the file->f_mutex. Similarly, the GRANTED code should be holding the same lock when looking up the block.

It's not though, is it? I don't think nlmsvc_grant_callback is run under the file->f_mutex (unless I'm missing something).

Signature · 1 line
Jeff Layton <[email protected]>

A message that is not in the archive (sent off-list or not yet received): 20080314173938.48c4f7cb-RtJpwOs3+0O+kQycOl6kW4xkIHaj4LzF@public.gmane.org

#18 lore raw

Re: [PATCH 4/4] NLM: don't requeue block if it was invalidated while GRANT_MSG was in flight

Quoted 8 lines · Jeff Layton

The race I had in mind was:

rpciod: nlmsvc_grant_callback checks to see if the block is on the list
lockd:  lockd() removes the block from the list after getting a SIGKILL
rpciod: nlmsvc_grant_callback requeues the block with a new timeout

...though now that I've looked, it seems like the BKL should prevent that particular race.

In any case, this can be fixed very simply: add a new flag B_INVALIDATED to nlm_block->b_flags which tells nlmsvc_grant_callback() that the block has been invalidated, and must not be requeued. Then remove the test for block->b_list...

In fact, it is quite arguable that we should probably have some form of locking scheme to prevent GRANTED and CANCEL requests from colliding. We might therefore also want to add a B_LOCKED flag, in order to tell incoming CANCEL requests that they should be deferred until the GRANTED call has completed. That would be a separate issue/patch, though.

Quoted 7 lines
Quoted 4 lines

This should, AFAIK, only occur while holding the file->f_mutex. Similarly, the GRANTED code should be holding the same lock when looking up the block.

It's not though, is it? I don't think nlmsvc_grant_callback is run under the file->f_mutex (unless I'm missing something).

Correct, but nlmsvc_grant_callback isn't actually trying to look up the block, so my argument is invalid.

Trond

#19 lore raw
In reply to Jeff Layton
Quoted 9 lines · Jeff Layton

This patchset fixes the problem that Bruce pointed out last week when we were discussing the lockd-kthread patches.

The main problem is described in patch #1 and that patch also fixes the DoS. The remaining patches clean up how GRANT_MSG callbacks handle an unresponsive client. The goal in those is to make sure that we don't end up with a ton of duplicate RPC's in queue and that we try to handle an invalidated block correctly.

Quoted 5 lines

Bruce, I'd like to see this fixed in 2.6.25 if at all possible.

Comments and suggestions are appreciated.

I gave them another quick skim, compiled, and did a connectathon run. (As always, I need better regression testing.) But I'll submit those tommorow assuming no one finds a problem.

--b.