From: David Woodhouse <dwmw2@infradead.org>
To: Dave Kleikamp <shaggy@linux.vnet.ibm.com>
Cc: Roberts Nathan-mcg31137 <Nathan.Roberts@motorola.com>,
linux-mtd@lists.infradead.org, ye janboe <janboe.ye@gmail.com>
Subject: Re: JFFS2 deadlock with alloc_sem
Date: Tue, 31 Jul 2007 13:40:27 +0100 [thread overview]
Message-ID: <1185885627.3083.113.camel@pmac.infradead.org> (raw)
In-Reply-To: <1185883827.3083.109.camel@pmac.infradead.org>
On Tue, 2007-07-31 at 13:10 +0100, David Woodhouse wrote:
> If that's the explanation, then the patch which Nathan tried (dropping
> f->sem before jffs2_gc_fetch_page(), followed by your cleanups¹) ought
> to have fixed the problem. And I'd be happier with that version rather
> than introducing a new read_cache_page_async_trylock() solely for
> JFFS2.
This is the tidied-up version of that patch...
diff --git a/fs/jffs2/README.Locking b/fs/jffs2/README.Locking
index d14d5a4..5836de7 100644
--- a/fs/jffs2/README.Locking
+++ b/fs/jffs2/README.Locking
@@ -69,6 +69,8 @@ Ordering constraints:
any f->sem held.
2. Never attempt to lock two file semaphores in one thread.
No ordering rules have been made for doing so.
+(Linux) 3. f->sem must always be locked _after_ the page lock of
+ any page cache page belonging to the file in question.
erase_completion_lock spinlock
diff --git a/fs/jffs2/file.c b/fs/jffs2/file.c
index c253019..4c09531 100644
--- a/fs/jffs2/file.c
+++ b/fs/jffs2/file.c
@@ -69,7 +69,7 @@ const struct address_space_operations jffs2_file_address_operations =
.commit_write = jffs2_commit_write
};
-static int jffs2_do_readpage_nolock (struct inode *inode, struct page *pg)
+static int jffs2_do_readpage(struct inode *inode, struct page *pg)
{
struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode);
struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb);
@@ -83,8 +83,11 @@ static int jffs2_do_readpage_nolock (struct inode *inode, struct page *pg)
pg_buf = kmap(pg);
/* FIXME: Can kmap fail? */
+ down(&f->sem);
+
ret = jffs2_read_inode_range(c, f, pg_buf, pg->index << PAGE_CACHE_SHIFT, PAGE_CACHE_SIZE);
+ up(&f->sem);
if (ret) {
ClearPageUptodate(pg);
SetPageError(pg);
@@ -102,21 +105,14 @@ static int jffs2_do_readpage_nolock (struct inode *inode, struct page *pg)
int jffs2_do_readpage_unlock(struct inode *inode, struct page *pg)
{
- int ret = jffs2_do_readpage_nolock(inode, pg);
+ int ret = jffs2_do_readpage(inode, pg);
unlock_page(pg);
return ret;
}
-
-static int jffs2_readpage (struct file *filp, struct page *pg)
+static int jffs2_readpage(struct file *filp, struct page *pg)
{
- struct jffs2_inode_info *f = JFFS2_INODE_INFO(pg->mapping->host);
- int ret;
-
- down(&f->sem);
- ret = jffs2_do_readpage_unlock(pg->mapping->host, pg);
- up(&f->sem);
- return ret;
+ return jffs2_do_readpage_unlock(pg->mapping->host, pg);
}
static int jffs2_prepare_write (struct file *filp, struct page *pg,
@@ -194,11 +190,9 @@ static int jffs2_prepare_write (struct file *filp, struct page *pg,
}
/* Read in the page if it wasn't already present, unless it's a whole page */
- if (!PageUptodate(pg) && (start || end < PAGE_CACHE_SIZE)) {
- down(&f->sem);
- ret = jffs2_do_readpage_nolock(inode, pg);
- up(&f->sem);
- }
+ if (!PageUptodate(pg) && (start || end < PAGE_CACHE_SIZE))
+ ret = jffs2_do_readpage(inode, pg);
+
D1(printk(KERN_DEBUG "end prepare_write(). pg->flags %lx\n", pg->flags));
return ret;
}
diff --git a/fs/jffs2/fs.c b/fs/jffs2/fs.c
diff --git a/fs/jffs2/gc.c b/fs/jffs2/gc.c
index eded819..51cb3d1 100644
--- a/fs/jffs2/gc.c
+++ b/fs/jffs2/gc.c
@@ -1218,7 +1218,9 @@ static int jffs2_garbage_collect_dnode(struct jffs2_sb_info *c, struct jffs2_era
* page OK. We'll actually write it out again in commit_write, which is a little
* suboptimal, but at least we're correct.
*/
+ up(&f->sem);
pg_ptr = jffs2_gc_fetch_page(c, f, start, &pg);
+ down(&f->sem);
if (IS_ERR(pg_ptr)) {
printk(KERN_WARNING "read_cache_page() returned error: %ld\n", PTR_ERR(pg_ptr));
diff --git a/fs/jffs2/os-linux.h b/fs/jffs2/os-linux.h
--
dwmw2
next prev parent reply other threads:[~2007-07-31 12:40 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <af3ea28a0707262032h7ee22775t6ef54e364a9cd704@mail.gmail.com>
2007-07-27 3:38 ` JFFS2 deadlock with alloc_sem ye janboe
2007-07-27 13:42 ` Dave Kleikamp
2007-07-27 16:35 ` ye janboe
2007-07-27 17:38 ` Dave Kleikamp
2007-07-30 12:45 ` David Woodhouse
2007-07-30 16:45 ` Dave Kleikamp
2007-07-31 12:10 ` David Woodhouse
2007-07-31 12:40 ` David Woodhouse [this message]
2007-07-31 13:23 ` Dave Kleikamp
2007-07-31 15:23 ` David Woodhouse
2007-07-31 15:36 ` Dave Kleikamp
2007-07-31 16:23 ` David Woodhouse
2007-08-02 4:11 ` ye janboe
2007-06-08 19:26 Dave Kleikamp
2007-06-11 12:14 ` David Woodhouse
2007-06-12 1:45 ` Roberts Nathan-mcg31137
2007-06-19 16:11 ` Dave Kleikamp
2007-06-19 19:42 ` Dave Kleikamp
-- strict thread matches above, loose matches on Subject: below --
2007-04-30 19:41 Roberts Nathan-mcg31137
2007-05-05 8:23 ` David Woodhouse
2007-06-02 17:42 ` David Woodhouse
2007-06-05 14:21 ` Roberts Nathan-mcg31137
2007-06-07 14:29 ` Josh Boyer
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=1185885627.3083.113.camel@pmac.infradead.org \
--to=dwmw2@infradead.org \
--cc=Nathan.Roberts@motorola.com \
--cc=janboe.ye@gmail.com \
--cc=linux-mtd@lists.infradead.org \
--cc=shaggy@linux.vnet.ibm.com \
/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).