Skip to contentSkip to conversation

GFS2: Use local iopen glock holder in gfs2_evict_inode

PATCH Superseded Bob Peterson 2 participants 2 messages Jun 14, 2016 1 message not in the archive GFS2 file system

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/1 GFS2: Use local iopen glock holder in gfs2_evict_inode

Hi,

Before this patch, function gfs2_evict_inode unlocked the iopen glock (from SH), waited for completion, then locked it again in EXclusive mode. That's all well and good except that other processes (not in gfs2_evict_inode) can try to do lookups, and function gfs2_inode_lookup tries to lock the iopen glock in SH again. This second lookup can and does wipe out the holder's pid with getpid(). The first putpid (from glock_holder_uninit) will be successful, but the second one will crash the kernel with:

BUG: unable to handle kernel paging request

This patch introduces a holder variable, io_gh, local to function gfs2_evict_inode, which will keep its own getpid() and subsequent putpid() from interfering with one another. So simultaneous inode lookups won't change the value out from under gfs2_evict_inode.

---

fs/gfs2/super.c +10 -9
index 9b2ff353..6dc5f2ac 100644
@@ -1518,7 +1518,7 @@ static void gfs2_evict_inode(struct inode *inode)
 	struct super_block *sb = inode->i_sb;
 	struct gfs2_sbd *sdp = sb->s_fs_info;
 	struct gfs2_inode *ip = GFS2_I(inode);
-	struct gfs2_holder gh;
+	struct gfs2_holder gh, io_gh;
 	struct address_space *metamapping;
 	int error;
 
@@ -1527,6 +1527,7 @@ static void gfs2_evict_inode(struct inode *inode)
 		return;
 	}
 
+	memset(&io_gh, 0, sizeof(io_gh));
 	if (inode->i_nlink || (sb->s_flags & MS_RDONLY))
 		goto out;
 
@@ -1555,9 +1556,9 @@ static void gfs2_evict_inode(struct inode *inode)
 	    test_bit(HIF_HOLDER, &ip->i_iopen_gh.gh_iflags)) {
 		ip->i_iopen_gh.gh_flags |= GL_NOCACHE;
 		gfs2_glock_dq_wait(&ip->i_iopen_gh);
-		gfs2_holder_reinit(LM_ST_EXCLUSIVE, LM_FLAG_TRY_1CB | GL_NOCACHE,
-				   &ip->i_iopen_gh);
-		error = gfs2_glock_nq(&ip->i_iopen_gh);
+		error = gfs2_glock_nq_init(ip->i_iopen_gh.gh_gl,
+					   LM_ST_EXCLUSIVE, LM_FLAG_TRY_1CB |
+					   GL_NOCACHE, &io_gh);
 		if (error)
 			goto out_truncate;
 	}
@@ -1610,12 +1611,12 @@ out_unlock:
 	if (gfs2_rs_active(&ip->i_res))
 		gfs2_rs_deltree(&ip->i_res);
 
-	if (ip->i_iopen_gh.gh_gl) {
-		if (test_bit(HIF_HOLDER, &ip->i_iopen_gh.gh_iflags)) {
-			ip->i_iopen_gh.gh_flags |= GL_NOCACHE;
-			gfs2_glock_dq_wait(&ip->i_iopen_gh);
+	if (io_gh.gh_gl) {
+		if (test_bit(HIF_HOLDER, &io_gh.gh_iflags)) {
+			io_gh.gh_flags |= GL_NOCACHE;
+			gfs2_glock_dq_wait(&io_gh);
 		}
-		gfs2_holder_uninit(&ip->i_iopen_gh);
+		gfs2_holder_uninit(&io_gh);
 	}
 	gfs2_glock_dq_uninit(&gh);
 	if (error && error != GLR_TRYFAILED && error != -EROFS)
#2 lore raw

PATCH 1/1 GFS2: Use local iopen glock holder in gfs2_evict_inode

Quoted 61 lines · Bob Peterson

Hi,

Before this patch, function gfs2_evict_inode unlocked the iopen glock (from SH), waited for completion, then locked it again in EXclusive mode. That's all well and good except that other processes (not in gfs2_evict_inode) can try to do lookups, and function gfs2_inode_lookup tries to lock the iopen glock in SH again. This second lookup can and does wipe out the holder's pid with getpid(). The first putpid (from glock_holder_uninit) will be successful, but the second one will crash the kernel with:

BUG: unable to handle kernel paging request

This patch introduces a holder variable, io_gh, local to function gfs2_evict_inode, which will keep its own getpid() and subsequent putpid() from interfering with one another. So simultaneous inode lookups won't change the value out from under gfs2_evict_inode.

---

fs/gfs2/super.c +5 -8
index 9b2ff353..6dc5f2ac 100644
@@ -1518,7 +1518,7 @@ static void gfs2_evict_inode(struct inode *inode)
        struct super_block *sb = inode->i_sb;
        struct gfs2_sbd *sdp = sb->s_fs_info;
        struct gfs2_inode *ip = GFS2_I(inode);
-       struct gfs2_holder gh;
+       struct gfs2_holder gh, io_gh;
        struct address_space *metamapping;
        int error;
 
@@ -1527,6 +1527,7 @@ static void gfs2_evict_inode(struct inode *inode)
                return;
        }
 
+       memset(&io_gh, 0, sizeof(io_gh));
        if (inode->i_nlink || (sb->s_flags & MS_RDONLY))
                goto out;
 
@@ -1555,9 +1556,9 @@ static void gfs2_evict_inode(struct inode *inode)
            test_bit(HIF_HOLDER, &ip->i_iopen_gh.gh_iflags)) {
                ip->i_iopen_gh.gh_flags |= GL_NOCACHE;
                gfs2_glock_dq_wait(&ip->i_iopen_gh);
-               gfs2_holder_reinit(LM_ST_EXCLUSIVE, LM_FLAG_TRY_1CB | GL_NOCACHE,
-                                  &ip->i_iopen_gh);
-               error = gfs2_glock_nq(&ip->i_iopen_gh);
+               error = gfs2_glock_nq_init(ip->i_iopen_gh.gh_gl,
+                                          LM_ST_EXCLUSIVE, LM_FLAG_TRY_1CB |
+                                          GL_NOCACHE, &io_gh);
                if (error)
                        goto out_truncate;
        }
@@ -1610,12 +1611,12 @@ out_unlock:
        if (gfs2_rs_active(&ip->i_res))
                gfs2_rs_deltree(&ip->i_res);
 
-       if (ip->i_iopen_gh.gh_gl) {
-               if (test_bit(HIF_HOLDER, &ip->i_iopen_gh.gh_iflags)) {
-                       ip->i_iopen_gh.gh_flags |= GL_NOCACHE;
-                       gfs2_glock_dq_wait(&ip->i_iopen_gh);

fs/gfs2/super.c out_unlock: · line 1622

Quoted 10 lines
fs/gfs2/super.c +5 -1
+       if (io_gh.gh_gl) {
+               if (test_bit(HIF_HOLDER, &io_gh.gh_iflags)) {
+                       io_gh.gh_flags |= GL_NOCACHE;
+                       gfs2_glock_dq_wait(&io_gh);
                }
-               gfs2_holder_uninit(&ip->i_iopen_gh);
+               gfs2_holder_uninit(&io_gh);
        }
        gfs2_glock_dq_uninit(&gh);
        if (error && error != GLR_TRYFAILED && error != -EROFS)