GFS2: Fix panic in glock memory shrinker
To: [email protected]
Subject: GFS2: Fix panic in glock memory shrinker
It is possible for gfs2_shrink_glock_memory() to check a glock for demotion
that's in the process of being freed by gfs2_glock_put(). In this case, gfs2_shrink_glock_memory() will acquire a new reference to this glock, and
then try to free the glock itself when it drops the refernce. To solve this, gfs2_shrink_glock_memory() just needs to check if the glock is in the process of being freed, and if so skip it without ever unlocking the lru_lock.
--- fs/gfs2/glock.c | 4 ++++ 1 file changed, 4 insertions(+)
fs/gfs2/glock.c +4 -0
@@ -1314,6 +1314,10 @@ static int gfs2_shrink_glock_memory(intlist_del_init (&gl->gl_lru);atomic_dec (&lru_count); +/* Check if glock is about to be freed */ +if (atomic_read (&gl->gl_ref) ==0 ) +continue ; +/* Test for being demotable */ if (!test_and_set_bit (GLF_LOCK , &gl->gl_flags)) {gfs2_glock_hold (gl);
----- "Benjamin Marzinski" <[email protected]> wrote:
| To: cluster-devel at redhat.com | Subject: GFS2: Fix panic in glock memory shrinker | | It is possible for gfs2_shrink_glock_memory() to check a glock for | demotion | that's in the process of being freed by gfs2_glock_put(). In this | case, | gfs2_shrink_glock_memory() will acquire a new reference to this | glock, | and | then try to free the glock itself when it drops the refernce. To | solve | this, gfs2_shrink_glock_memory() just needs to check if the glock is | in | the process of being freed, and if so skip it without ever unlocking | the | lru_lock. | | Signed-off-by: Benjamin Marzinski <[email protected]> | --- | fs/gfs2/glock.c | 4 ++++ | 1 file changed, 4 insertions(+) | | Index: kernel-upstream/fs/gfs2/glock.c | =================================================================== | --- kernel-upstream.orig/fs/gfs2/glock.c | +++ kernel-upstream/fs/gfs2/glock.c | @@ -1314,6 +1314,10 @@ static int gfs2_shrink_glock_memory(int | list_del_init(&gl->gl_lru); | atomic_dec(&lru_count); | | + /* Check if glock is about to be freed */ | + if (atomic_read(&gl->gl_ref) == 0) | + continue; | + | /* Test for being demotable */ | if (!test_and_set_bit(GLF_LOCK, &gl->gl_flags)) { | gfs2_glock_hold(gl);
Hi,
ACKed by Bob Peterson <[email protected]>
Regards,
Bob Peterson
Red Hat File Systems
Hi,
Now in the -nmw git tree. Thanks,
Steve.
Quoted 34 lines · Benjamin Marzinski
To: cluster-devel at redhat.com
Subject: GFS2: Fix panic in glock memory shrinkerIt is possible for
gfs2_shrink_glock_memory()to check a glock for demotion
that's in the process of being freed bygfs2_glock_put(). In this case,gfs2_shrink_glock_memory()will acquire a new reference to this glock, and
then try to free the glock itself when it drops the refernce. To solve this,gfs2_shrink_glock_memory()just needs to check if the glock is in the process of being freed, and if so skip it without ever unlocking thelru_lock.Signed-off-by Benjamin Marzinski <[email protected]>--- fs/gfs2/glock.c | 4 ++++ 1 file changed, 4 insertions(+)Index:
kernel-upstream/fs/gfs2/glock.c
===================================================================fs/gfs2/glock.c +4
-0@@ -1314,6 +1314,10 @@ static int gfs2_shrink_glock_memory(intlist_del_init (&gl->gl_lru);atomic_dec (&lru_count); +/* Check if glock is about to be freed */ +if (atomic_read (&gl->gl_ref) ==0 ) +continue ; +/* Test for being demotable */ if (!test_and_set_bit (GLF_LOCK , &gl->gl_flags)) {gfs2_glock_hold (gl);