All of lore.kernel.org
 help / color / mirror / Atom feed
From: "J. Bruce Fields" <bfields@fieldses.org>
To: "George G. Davis" <gdavis@mvista.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [RFC][PATCH] Fix hang in posix_locks_deadlock()
Date: Fri, 26 Oct 2007 13:07:50 -0400	[thread overview]
Message-ID: <20071026170750.GC13033@fieldses.org> (raw)
In-Reply-To: <20071018185759.GU3785@mvista.com>

On Thu, Oct 18, 2007 at 02:57:59PM -0400, George G. Davis wrote:
> On Wed, Oct 17, 2007 at 02:51:57PM -0400, George G. Davis wrote:
> > ---
> > Not sure if this is the correct fix but it does resolve the hangs we're
> > observing in posix_locks_deadlock().
> 
> Please disregard the previous patch, it's not quite right - causes occasional
> segfaults and clearly did not retain the posix_same_owner() checks implemented
> in the original code.  Here's a new version which I believe retains the
> intent of the original code:
> 
> diff --git a/fs/locks.c b/fs/locks.c
> index 7f9a3ea..e012b27 100644
> --- a/fs/locks.c
> +++ b/fs/locks.c
> @@ -702,14 +702,12 @@ static int posix_locks_deadlock(struct file_lock *caller_fl,
>  {
>  	struct file_lock *fl;
>  
> -next_task:
>  	if (posix_same_owner(caller_fl, block_fl))
>  		return 1;
>  	list_for_each_entry(fl, &blocked_list, fl_link) {
>  		if (posix_same_owner(fl, block_fl)) {
> -			fl = fl->fl_next;
> -			block_fl = fl;
> -			goto next_task;
> +			if (posix_same_owner(caller_fl, fl))
> +				return 1;
>  		}
>  	}
>  	return 0;

It may take multiple steps to identify a deadlock.  With the above
you'll miss deadlocks like

	process 1 is requesting a lock held by process 2
	process 2 is blocking on a lock held by process 3
	process 3 is blocking on a lock held by process 1.

Could you give more details about how you're causing
posix_locks_deadlock to hang?  Is there a simple test-case you can post?

--b.

> 
> 
> I'm not sure about those "fl = fl->fl_next; block_fl = fl;" statements,
> first, the order of those statements seems reversed to me.  Otherwise,
> I think the intent was to advance the "fl" for loop variable to the next
> entry in the list but it doesn't work out that way at all - the for
> loop restarts from the beginning - this is where we get into an
> infinite loop condition.  Whether the test case I posted before is
> valid or not, I reckon it shouldn't be possible for non-root Joe user
> to contrive a test case which can hang the system as we're observing
> with that test case.  The above patch fixes the hang.
> 
> Comments greatly appreciated...
> 
> -- 
> Regards,
> George
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/

  reply	other threads:[~2007-10-26 17:07 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-17 18:51 [RFC][PATCH] Fix hang in posix_locks_deadlock() George G. Davis
2007-10-17 23:41 ` George G. Davis
2007-10-18 18:57 ` George G. Davis
2007-10-26 17:07   ` J. Bruce Fields [this message]
2007-10-26 22:47     ` J. Bruce Fields
2007-10-28 17:31       ` [PATCH] locks: fix possible infinite loop in posix deadlock detection J. Bruce Fields
2007-10-28 17:43         ` [RFC, PATCH] locks: remove " J. Bruce Fields
2007-10-28 18:27           ` Matthew Wilcox
2007-10-28 18:40             ` Alan Cox
2007-10-28 20:11               ` Matthew Wilcox
2007-10-28 21:38                 ` Alan Cox
2007-10-28 21:45                   ` Jiri Kosina
2007-10-28 23:38                   ` Matthew Wilcox
2007-10-28 23:44                     ` Alan Cox
2007-10-28 21:50                 ` Trond Myklebust
2007-10-28 22:41                   ` Matthew Wilcox
2007-10-28 22:48                     ` Alan Cox
2007-10-28 22:55                       ` Matthew Wilcox
2007-10-28 23:38                         ` Alan Cox
2007-10-29  2:29                           ` J. Bruce Fields
2007-10-29  8:08                             ` Alan Cox
2007-10-29  9:15                             ` Jiri Kosina
2007-10-30 15:35                               ` J. Bruce Fields
2007-10-28 22:55                     ` Jiri Kosina
2007-10-28 23:31                       ` Matthew Wilcox
2007-10-29  9:11                         ` Jiri Kosina
2007-10-29  2:10                     ` J. Bruce Fields
2007-10-29  3:26                     ` Trond Myklebust
2007-10-29  1:13               ` J. Bruce Fields
2007-10-29  8:06           ` Alan Cox
2007-10-30 15:51             ` J. Bruce Fields
2007-10-30 15:20         ` [PATCH, RESEND] locks: fix possible infinite loop in " J. Bruce Fields
2007-10-30 15:35           ` Alan Cox
2007-10-28 17:47       ` [RFC][PATCH] Fix hang in posix_locks_deadlock() J. Bruce Fields
2007-11-02 15:05     ` George G. Davis

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=20071026170750.GC13033@fieldses.org \
    --to=bfields@fieldses.org \
    --cc=gdavis@mvista.com \
    --cc=linux-kernel@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.