linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Artem B. Bityuckiy" <dedekind@infradead.org>
To: linux-kernel@vger.kernel.org
Cc: David Woodhouse <dwmw2@infradead.org>,
	linux-mtd@lists.infradead.org, viro@math.psu.edu,
	linux-fsdevel@vger.kernel.org
Subject: [PATCH] VFS bugfix: two read_inode() calles without clear_inode() call between
Date: Tue, 19 Apr 2005 16:38:44 +0400	[thread overview]
Message-ID: <1113914324.2125.61.camel@sauron.oktetlabs.ru> (raw)

Hello,

here is a patch to fix the problem discussed at the "[PATC] small VFS
change for JFFS2" thread in LKML (http://lkml.org/lkml/2005/4/18/77).

The problem description:
~~~~~~~~~~~~~~~~~~~~~~

prune_icache() removes inodes from the inode hash (inode->i_hash) and
drops the node_lock spinlock. If at that moment iget() is called, we end
up with the situation when VFS calls ->read_inode() twice for the same
inode without calling ->clear_inode() between. This happens despite of
the I_FREEING inode state because the inode is already removed from the
hash by the time find_inode_fast() is invoked.

The fix is: do not remove the inode from the hash too early.

The following patch fixes the problem. It was tested with JFFS2 (only)
and works perfectly.

Comments?



Signed-off-by: Artem B. Bityuckiy <dedekind@infradead.org>


diff -auNrp linux-2.6.11.5/fs/inode.c linux-2.6.11.5_fixed/fs/inode.c
--- linux-2.6.11.5/fs/inode.c   2005-03-19 09:35:04.000000000 +0300
+++ linux-2.6.11.5_fixed/fs/inode.c     2005-04-18 17:54:16.000000000
+0400
@@ -284,6 +284,12 @@ static void dispose_list(struct list_hea
                if (inode->i_data.nrpages)
                        truncate_inode_pages(&inode->i_data, 0);
                clear_inode(inode);
+
+               spin_lock(&inode_lock);
+               hlist_del_init(&inode->i_hash);
+               list_del_init(&inode->i_sb_list);
+               spin_unlock(&inode_lock);
+
                destroy_inode(inode);
                nr_disposed++;
        }
@@ -319,8 +325,6 @@ static int invalidate_list(struct list_h
                inode = list_entry(tmp, struct inode, i_sb_list);
                invalidate_inode_buffers(inode);
                if (!atomic_read(&inode->i_count)) {
-                       hlist_del_init(&inode->i_hash);
-                       list_del(&inode->i_sb_list);
                        list_move(&inode->i_list, dispose);
                        inode->i_state |= I_FREEING;
                        count++;
@@ -455,8 +459,6 @@ static void prune_icache(int nr_to_scan)
                        if (!can_unuse(inode))
                                continue;
                }
-               hlist_del_init(&inode->i_hash);
-               list_del_init(&inode->i_sb_list);
                list_move(&inode->i_list, &freeable);
                inode->i_state |= I_FREEING;
                nr_pruned++;

-- 
Best Regards,
Artem B. Bityuckiy,
St.-Petersburg, Russia.


             reply	other threads:[~2005-04-19 12:38 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-04-19 12:38 Artem B. Bityuckiy [this message]
  -- strict thread matches above, loose matches on Subject: below --
2005-04-27 13:15 [PATCH] VFS bugfix: two read_inode() calles without clear_inode() call between Artem B. Bityuckiy
2005-04-27 13:42 ` Jan Harkes
2005-04-27 14:22 ` Miklos Szeredi
2005-04-27 15:57 ` Miklos Szeredi
2005-04-27 16:19   ` Artem B. Bityuckiy
     [not found]     ` <E1DQqZu-0002Rf-00@dorka.pomaz.szeredi.hu>
2005-04-28  7:32       ` Artem B. Bityuckiy
2005-04-28  7:34         ` Andrew Morton
2005-05-04 12:17           ` Artem B. Bityuckiy
2005-05-04 20:04             ` Andrew Morton
2005-05-04 21:35               ` David Woodhouse
2005-05-04 21:58                 ` Andrew Morton
2005-05-05  9:10                   ` David Woodhouse
2005-05-05 16:18                     ` Miklos Szeredi
2005-05-06 11:08                       ` David Woodhouse
2005-04-28  7:41         ` Miklos Szeredi
2005-04-28  7:47           ` Artem B. Bityuckiy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1113914324.2125.61.camel@sauron.oktetlabs.ru \
    --to=dedekind@infradead.org \
    --cc=dwmw2@infradead.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=viro@math.psu.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).