GFS2: Fix potential race in glock code

Previous thread: pcmcia/staging: update comedi drivers by Linux Kernel Mailing List on Saturday, December 5, 2009 - 10:59 am. (1 message)

Next thread: LSM: Move security_path_chmod()/security_path_chown() to after mutex_lock(). by Linux Kernel Mailing List on Saturday, December 5, 2009 - 10:59 am. (1 message)
From: Linux Kernel Mailing List
Date: Saturday, December 5, 2009 - 10:59 am

Gitweb:     http://git.kernel.org/linus/7e71c55ee73988d0cb61045660b899eaac23bf8f
Commit:     7e71c55ee73988d0cb61045660b899eaac23bf8f
Parent:     22763c5cf3690a681551162c15d34d935308c8d7
Author:     Steven Whitehouse <swhiteho@redhat.com>
AuthorDate: Tue Sep 22 10:56:16 2009 +0100
Committer:  Steven Whitehouse <swhiteho@redhat.com>
CommitDate: Thu Dec 3 11:42:25 2009 +0000

    GFS2: Fix potential race in glock code
    
    We need to be careful of the ordering between clearing the
    GLF_LOCK bit and scheduling the workqueue.
    
    Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
---
 fs/gfs2/glock.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c
index 8b674b1..a3f90ad 100644
--- a/fs/gfs2/glock.c
+++ b/fs/gfs2/glock.c
@@ -672,12 +672,17 @@ out:
 	return;
 
 out_sched:
+	clear_bit(GLF_LOCK, &gl->gl_flags);
+	smp_mb__after_clear_bit();
 	gfs2_glock_hold(gl);
 	if (queue_delayed_work(glock_workqueue, &gl->gl_work, 0) == 0)
 		gfs2_glock_put_nolock(gl);
+	return;
+
 out_unlock:
 	clear_bit(GLF_LOCK, &gl->gl_flags);
-	goto out;
+	smp_mb__after_clear_bit();
+	return;
 }
 
 static void delete_work_func(struct work_struct *work)
@@ -1375,10 +1380,11 @@ static int gfs2_shrink_glock_memory(int nr, gfp_t gfp_mask)
 				handle_callback(gl, LM_ST_UNLOCKED, 0);
 				nr--;
 			}
+			clear_bit(GLF_LOCK, &gl->gl_flags);
+			smp_mb__after_clear_bit();
 			if (queue_delayed_work(glock_workqueue, &gl->gl_work, 0) == 0)
 				gfs2_glock_put_nolock(gl);
 			spin_unlock(&gl->gl_spin);
-			clear_bit(GLF_LOCK, &gl->gl_flags);
 			spin_lock(&lru_lock);
 			continue;
 		}
--

Previous thread: pcmcia/staging: update comedi drivers by Linux Kernel Mailing List on Saturday, December 5, 2009 - 10:59 am. (1 message)

Next thread: LSM: Move security_path_chmod()/security_path_chown() to after mutex_lock(). by Linux Kernel Mailing List on Saturday, December 5, 2009 - 10:59 am. (1 message)