Skip to contentSkip to conversation

fix hangs in posix_locks_deadlock().

PATCH In review Trond Myklebust 5 participants 5 messages Sep 20, 2004 – Sep 26, 2004

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

PATCH 1/1 fix hangs in posix_locks_deadlock().

"blocked_list" may contain both leases and flock locks in addition to posix locks.

---
 locks.c |    7 +++----
 1 files changed, 3 insertions(+), 4 deletions(-)
fs/locks.c +3 -4
Index: linux-2.6.9-rc2-up/fs/locks.c
===================================================================
@@ -634,14 +634,13 @@
 int posix_locks_deadlock(struct file_lock *caller_fl,
 				struct file_lock *block_fl)
 {
-	struct list_head *tmp;
+	struct file_lock *fl;
 
 next_task:
 	if (posix_same_owner(caller_fl, block_fl))
 		return 1;
-	list_for_each(tmp, &blocked_list) {
-		struct file_lock *fl = list_entry(tmp, struct file_lock, fl_link);
-		if (posix_same_owner(fl, block_fl)) {
+	list_for_each_entry(fl, &blocked_list, fl_link) {
+		if (IS_POSIX(fl) && posix_same_owner(fl, block_fl)) {
 			fl = fl->fl_next;
 			block_fl = fl;
 			goto next_task;
#1 lore raw
Quoted 2 lines · Trond Myklebust

"blocked_list" may contain both leases and flock locks in addition to posix locks.

It shouldn't. Take this patch instead.

Index: linux-2.6/fs/locks.c
===================================================================
RCS file: /var/cvs/linux-2.6/fs/locks.c,v
retrieving revision 1.13

fs/locks.c +2 -1
diff -u -p -r1.13 locks.c
@@ -463,7 +463,8 @@ static void locks_insert_block(struct fi
 	}
 	list_add_tail(&waiter->fl_block, &blocker->fl_block);
 	waiter->fl_next = blocker;
-	list_add(&waiter->fl_link, &blocked_list);
+	if (IS_POSIX(blocker))
+		list_add(&waiter->fl_link, &blocked_list);
 }
 
 /* Wake up processes blocked waiting for blocker.
Signature · 6 lines
"Next the statesmen will invent cheap lies, putting the blame upon 
the nation that is attacked, and every man will be glad of those
conscience-soothing falsities, and will diligently study them, and refuse
to examine any refutations of them; and thus he will by and by convince 
himself that the war is just, and will thank God for the better sleep 
he enjoys after this process of grotesque self-deception." -- Mark Twain
#2 lore raw
Quoted 2 lines · Matthew Wilcox

It shouldn't. Take this patch instead.

Trond, could you please review/test/confirm?

Matthew: changelog entry, please. Always...

#3 lore raw
In reply to Matthew Wilcox
Quoted 6 lines · Matthew Wilcox
Quoted 2 lines · Trond Myklebust

"blocked_list" may contain both leases and flock locks in addition to posix locks.

It shouldn't. Take this patch instead.

This is a different thing, btw.

Willy, when you do

	if (IS_POSIX(blocker))
		list_add(&waiter->fl_link, &blocked_list);

note how the _blocker_ may be a POSIX lock, but the _blockee_ is not necessarily. So this ends up being very different from what Trond was testing - he's testing whether the _blockee_ is a POSIX file lock in posix_locks_deadlocks(), and ignoring non-posix locks.

Now, I think Trond's patch makes more sense, since if the blockee isn't a POSIX lock, then the "posix_same_owner()" test doesn't make any sense that I can tell. In contrast, your patch will still allow non-POSIX locks onto the blocked list, leaving Trond's observation true.

Maybe you meant

if (IS_POSIX(waiter))

but on the whole I'd really like to get some clarification for what the semantics are actually supposed to be. I'm inclined to apply Trond's patch if only because it looks more sensible, but I'd rather see an _explanation_ of the fighting patches, ok?

Linus

#4 lore raw
Quoted 9 lines · Linus Torvalds

This is a different thing, btw.

Willy, when you do

	if (IS_POSIX(blocker))
		list_add(&waiter->fl_link, &blocked_list);

note how the _blocker_ may be a POSIX lock, but the _blockee_ is not necessarily.

Oh, but it is, because POSIX locks and BSD locks don't block each other.

Quoted 4 lines

but on the whole I'd really like to get some clarification for what the semantics are actually supposed to be. I'm inclined to apply Trond's patch if only because it looks more sensible, but I'd rather see an _explanation_ of the fighting patches, ok?

Only POSIX locks check for deadlock. This is because BSD locks can't be atomically changed -- you have to release the lock you currently have before upgrading it.

As I've noted before (but never posted a patch), we should probably stop checking for deadlock. POSIX says it's optional for an implementation to check for deadlock, and since the change to match on tgid, we can report a deadlock when none exists.

Sorry for the delay in replying; Debian's mailserver got backlogged and only just handed me this mail.

Signature · 6 lines
"Next the statesmen will invent cheap lies, putting the blame upon 
the nation that is attacked, and every man will be glad of those
conscience-soothing falsities, and will diligently study them, and refuse
to examine any refutations of them; and thus he will by and by convince 
himself that the war is just, and will thank God for the better sleep 
he enjoys after this process of grotesque self-deception." -- Mark Twain