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: Sun, 28 Oct 2007 13:47:09 -0400 [thread overview]
Message-ID: <20071028174709.GC16905@fieldses.org> (raw)
In-Reply-To: <20071026224707.GO13033@fieldses.org>
On Fri, Oct 26, 2007 at 06:47:08PM -0400, J. Bruce Fields wrote:
> Hm. After another look: assume we have four tasks, t1, t2, t3, and t4.
> Assume t1 and t2 share the same current->files (so they're the same
> "owner" for the purpose of posix_same_owner()). Assume:
>
> t1 is waiting on a conflicting lock held by t3.
> t2 is waiting on a conflicting lock held by t4.
>
> Now suppose t4 requests a lock that conflicts with a lock held by t1 and
> t2. The list_for_each_entry() above will search for a task with t1 or
> t2 as owner, which is waiting on a lock. If it finds t1 first, the loop
> won't be noticed, so t4 will be put to sleep. Now we have a loop; t3
> can release its lock (it no longer matters), and we'll have
>
> t2 waiting on a conflicting lock held by t4, and
> t4 waiting on a conflicting lock held by t2.
>
> If a new task t5 then requests a lock conflicting with the one held by
> t2, then the above function will go into an infinite loop. I think.
>
> Consider the directed graph with each vertex representing the set of all
> tasks sharing the same file table, and each edge representing the
> relationship "a task at this vertex is waiting on a lock held by a task
> on another vertex". The existance of multiple tasks with the same file
> table means that we can no longer assume that each vertex has outdegree
> at most one, so we have to switch to an algorithm that works on an
> arbitrary directed graph. That sounds painful.
>
> Am I right about that, and about the example above? It'd be interesting
> to code it up just to make sure.
>
> If so, one can imagine various bandaids, but maybe we should just rip
> out the deadlock detection completely.... It's hard to imagine it being
> really useful anyway.
OK, well I cooked up a similar example, which was kind of fun, and
verified that I can indeed lock up the kernel this way.
The only way this can happen, though, is if you already have deadlocked
threads--that is to say, two threads that are each waiting on posix file
locks held by the other. (Or a similar cycle of length more than 2.) So
hopefully your application is doing some other kind of deadlock
detection (e.g. by killing threads that block for too long); otherwise
it already has a bug.
--b.
next prev parent reply other threads:[~2007-10-28 17:47 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
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 ` J. Bruce Fields [this message]
2007-11-02 15:05 ` [RFC][PATCH] Fix hang in posix_locks_deadlock() 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=20071028174709.GC16905@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox