From: Andrew Morton <akpm@osdl.org>
To: Olaf Hering <olh@suse.de>
Cc: linux-kernel@vger.kernel.org, viro@ftp.linux.org.uk
Subject: Re: [PATCH] cramfs corruption after BLKFLSBUF on loop device
Date: Thu, 1 Jun 2006 12:12:00 -0700 [thread overview]
Message-ID: <20060601121200.457c0335.akpm@osdl.org> (raw)
In-Reply-To: <20060601184938.GA31376@suse.de>
On Thu, 1 Jun 2006 20:49:38 +0200
Olaf Hering <olh@suse.de> wrote:
>
> This script will cause cramfs decompression errors, on SMP at least:
>
> #!/bin/bash
> while :;do blockdev --flushbufs /dev/loop0;done </dev/null &>/dev/null&
> while :;do ps faxs </dev/null &>/dev/null&done </dev/null &>/dev/null&
> while :;do dmesg </dev/null &>/dev/null&done </dev/null &>/dev/null&
> while :;do find /mounts/instsys -type f -print0|xargs -0 cat &>/dev/null;done
>
> (The used executables come from the symlinked /mounts/instsys directory)
>
> ...
> Error -3 while decompressing!
> c0000000009592a2(2649)->c0000000edf87000(4096)
> Error -3 while decompressing!
> c000000000959298(2520)->c0000000edbc7000(4096)
> Error -3 while decompressing!
> c000000000959c70(2489)->c0000000f1482000(4096)
> Error -3 while decompressing!
> c00000000095a629(2355)->c0000000edaff000(4096)
> Error -3 while decompressing!
> ...
>
> Its a long standing bug, introduced in 2.6.2.
>
> cramfs_read() clears parts of the src buffer because the page is not uptodate.
> invalidate_bdev() called from block_ioctl(BLKFLSBUF) will set ClearPageUptodate()
> after cramfs_read() got the page from read_cache_page()
> If PageUptodate() fails, read the page again before using it.
> There is still a small window were the page may not be uptodate before copying
> its contents away.
>
> evms_access does the BLKFLSBUF ioctl (lots of them) on the loop device. This will
> corrupt the SuSE installation image on SMP kernels, leading to random segfaults.
>
OK, invalidate_inode_pages().
> +
> for (i = 0; i < BLKS_PER_BUF; i++) {
> - struct page *page = pages[i];
> - if (page) {
> - memcpy(data, kmap(page), PAGE_CACHE_SIZE);
> - kunmap(page);
> - page_cache_release(page);
> - } else
> - memset(data, 0, PAGE_CACHE_SIZE);
> + if (blocknr + i < devsize) {
> + page = NULL;
> + for (readagain = 0; readagain < 5; readagain++) {
> + page = read_cache_page(mapping, blocknr + i,
> + (filler_t *)mapping->a_ops->readpage,
> + NULL);
> + /* synchronous error? */
> + if (IS_ERR(page)) {
> + page = NULL;
> + break;
> + }
> + wait_on_page_locked(page);
> + if (PageUptodate(page))
> + break;
> + /* asynchronous error */
> + /* maybe BLKFLSBUF flushed the page */
> + page_cache_release(page);
> + page = NULL;
> + }
> + if (page) {
> + memcpy(data, kmap(page), PAGE_CACHE_SIZE);
> + kunmap(page);
> + page_cache_release(page);
> + } else
> + memset(data, 0, PAGE_CACHE_SIZE);
> + if (readagain)
> + printk(KERN_DEBUG "cramfs_read got %s Uptodate page after %d attempt(s)\n",
> + page ? "an" : "no", readagain);
> + }
This code absolutely needs a comment telling the poor reader what it's in
there for.
It's still racy. Do the memcpy while the page is locked:
retry:
read_cache_page()
lock_page()
if (!PageUptodate()) {
if (readagain-- != 0)
goto retry;
give_up();
}
memcpy();
unlock_page();
Also, let's use kmap_atomic() while we're in there.
Of course, this will all just fail less often than it presently does. We'd
be better off taking a lock if poss to keep the ioctl away. I'd have
thought that it'd be appropriate to take i_mutex while running
invalidate_inode_pages().
next prev parent reply other threads:[~2006-06-01 19:07 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-05-29 21:40 Olaf Hering
2006-05-30 13:19 ` Olaf Hering
2006-05-30 18:24 ` Olaf Hering
2006-06-01 18:49 ` [PATCH] " Olaf Hering
2006-06-01 19:12 ` Andrew Morton [this message]
2006-06-01 19:15 ` Andrew Morton
2006-06-01 20:10 ` Olaf Hering
2006-06-01 21:24 ` Andrew Morton
2006-06-01 21:41 ` Olaf Hering
2006-06-01 21:57 ` Andrew Morton
2006-06-02 8:43 ` Olaf Hering
2006-06-02 9:11 ` Andrew Morton
2006-06-02 19:14 ` Olaf Hering
2006-06-02 19:41 ` Andrew Morton
2006-06-02 21:06 ` Olaf Hering
2006-06-02 19:37 ` Olaf Hering
2006-06-02 19:46 ` Andrew Morton
2006-06-03 13:13 ` Olaf Hering
2006-06-01 20:17 ` Chris Mason
2006-06-01 20:20 ` Olaf Hering
2006-06-01 20:29 ` Chris Mason
2006-09-20 13:20 ` Olaf Hering
2006-09-20 18:47 ` Andrew Morton
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=20060601121200.457c0335.akpm@osdl.org \
--to=akpm@osdl.org \
--cc=linux-kernel@vger.kernel.org \
--cc=olh@suse.de \
--cc=viro@ftp.linux.org.uk \
/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
all inboxes | Powered by JetHome®