Skip to contentSkip to conversation

locks: reinstate locks_delete_block optimization

PATCH New Jeff Layton 1 participant 1 message Mar 18, 2020

Subsystems (4)
lore
Share & tools
lore

Jeff Layton

author maintainer
#0 lore raw

PATCH 1/1 locks: reinstate locks_delete_block optimization

From: Linus Torvalds <[email protected]>

There is measurable performance impact in some synthetic tests due to commit 6d390e4b5d48 (locks: fix a potential use-after-free problem when wakeup a waiter). Fix the race condition instead by clearing the fl_blocker pointer after the wake_up, using explicit acquire/release semantics.

This does mean that we can no longer use the clearing of fl_blocker as the wait condition, so switch the waiters over to checking whether the fl_blocked_member list_head is empty.

Fixes 6d390e4b5d48 (locks: fix a potential use-after-free problem when wakeup a waiter)
---
 fs/cifs/file.c |  3 ++-
 fs/locks.c     | 54 ++++++++++++++++++++++++++++++++++++++++++++------
 2 files changed, 50 insertions(+), 7 deletions(-)

Hi Linus,

Sending this individually since it's just a single patch. If you'd prefer a pull request, let me know.

-- Jeff

fs/cifs/file.c +2 -1
index 3b942ecdd4be..8f9d849a0012 100644
@@ -1169,7 +1169,8 @@ cifs_posix_lock_set(struct file *file, struct file_lock *flock)
 	rc = posix_lock_file(file, flock, NULL);
 	up_write(&cinode->lock_sem);
 	if (rc == FILE_LOCK_DEFERRED) {
-		rc = wait_event_interruptible(flock->fl_wait, !flock->fl_blocker);
+		rc = wait_event_interruptible(flock->fl_wait,
+					list_empty(&flock->fl_blocked_member));
 		if (!rc)
 			goto try_again;
 		locks_delete_block(flock);
fs/locks.c +48 -6

107 lines not on this page · raw message

Signature · 1 line
2.24.1