From: "Phillip Lougher" Subject: Re: Re: A patch for squashfs on s390 Date: Thu, 7 Sep 2006 02:19:00 +0100 Message-ID: References: <20060902204753.84b354a2.zaitcev@redhat.com> <44FB7949.4010306@lougher.demon.co.uk> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_57609_3390730.1157591940543" Cc: phillip@lougher.org.uk, linux-fsdevel@vger.kernel.org Return-path: Received: from nz-out-0102.google.com ([64.233.162.206]:41402 "EHLO nz-out-0102.google.com") by vger.kernel.org with ESMTP id S964883AbWIGBTB (ORCPT ); Wed, 6 Sep 2006 21:19:01 -0400 Received: by nz-out-0102.google.com with SMTP id n1so17577nzf for ; Wed, 06 Sep 2006 18:19:00 -0700 (PDT) To: "Phillip Lougher" , "Pete Zaitcev" , heiko.carstens@de.ibm.com In-Reply-To: <44FB7949.4010306@lougher.demon.co.uk> Sender: linux-fsdevel-owner@vger.kernel.org List-Id: linux-fsdevel.vger.kernel.org ------=_Part_57609_3390730.1157591940543 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 9/4/06, Phillip Lougher wrote: > Pete Zaitcev wrote: > > > > At some situations, this can get called twice on the same page. > > When this happens first, the page is filled normally, and SetPageUptodate > > clears dirty bit. Notice though, SetPageUptodate is different on s390 > > from all other architectures, because the dirty bit belongs to a page, > > and not to a page table entry there. So, on second pass, SetPageUptodate > > sees the page already up to date and does not clear the dirty bit. > > This creates a dirty page which eventually oopses us. > > Makes sense. I hit the "same page read more than once at the same time" > race condition a couple of years ago, and solved it using > grab_cache_page_nowait. Unfortunately I didn't know about the s390, > however, I probably should always have had a PageUptodate check anyway. > > > > > Here's a patch which I made out of Heiko's patch by transforming it: > > Hi Heiko, Pete, I've had a second look at the patch. The patch is fixing the one branch of the if, but it isn't fixing the other branch. That is when process A enters read_page to read page n, and process B simultaneously enters read_page to read page n +1, the patch fixes the case where process A pushes page n +1 a second time (second branch of the if, i != page->index). The other case can happen, process A pushes pages n and n+1 first, which means process B pushes page n + 1 a second time (first branch of the if, i == page->index). This case isn't fixed. In fact when fragment pages are not being read, this is the case that will always occur because process A grabs the read_page_mutex lock. This is the case I experienced a couple of years ago. Process A enters read_page, and grabs the lock. Process B enters and waits on the lock. Process A then reads page n, and pushes page n +1 (and others) into the page cache. Process B only proceeds once the lock is released, by which time the page which it has entered read_page to read (n + 1), has already been read. This is a updated patch which deals with both cases. I've also attached it because I don't know if Gmail mangles inline patches. BTW Zisofs uses grab_cache_page_nowait and will suffer from this problem. NTFS which also uses grab_cache_page_nowait does have a PageUptodate check. Regards Phillip diff --new-file -urp linux-2.6.17/fs/squashfs/inode.c linux-2.6.17-patched/fs/squashfs/inode.c --- linux-2.6.17/fs/squashfs/inode.c 2006-09-07 00:54:33.000000000 +0100 +++ linux-2.6.17-patched/fs/squashfs/inode.c 2006-09-07 01:08:49.000000000 +0100 @@ -1547,36 +1547,31 @@ static int squashfs_readpage(struct file for (i = start_index; i <= end_index && byte_offset < bytes; i++, byte_offset += PAGE_CACHE_SIZE) { struct page *push_page; - int available_bytes = (bytes - byte_offset) > PAGE_CACHE_SIZE ? + int avail = (bytes - byte_offset) > PAGE_CACHE_SIZE ? PAGE_CACHE_SIZE : bytes - byte_offset; TRACE("bytes %d, i %d, byte_offset %d, available_bytes %d\n", - bytes, i, byte_offset, available_bytes); + bytes, i, byte_offset, avail); - if (i == page->index) { - pageaddr = kmap_atomic(page, KM_USER0); - memcpy(pageaddr, data_ptr + byte_offset, - available_bytes); - memset(pageaddr + available_bytes, 0, - PAGE_CACHE_SIZE - available_bytes); - kunmap_atomic(pageaddr, KM_USER0); - flush_dcache_page(page); - SetPageUptodate(page); - unlock_page(page); - } else if ((push_page = - grab_cache_page_nowait(page->mapping, i))) { - pageaddr = kmap_atomic(push_page, KM_USER0); - - memcpy(pageaddr, data_ptr + byte_offset, - available_bytes); - memset(pageaddr + available_bytes, 0, - PAGE_CACHE_SIZE - available_bytes); - kunmap_atomic(pageaddr, KM_USER0); - flush_dcache_page(push_page); - SetPageUptodate(push_page); - unlock_page(push_page); + push_page = (i == page->index) ? page : + grab_cache_page_nowait(page->mapping, i); + + if (!push_page) + continue; + + if (PageUptodate(push_page)) + goto skip_page; + + pageaddr = kmap_atomic(push_page, KM_USER0); + memcpy(pageaddr, data_ptr + byte_offset, avail); + memset(pageaddr + avail, 0, PAGE_CACHE_SIZE - avail); + kunmap_atomic(pageaddr, KM_USER0); + flush_dcache_page(push_page); + SetPageUptodate(push_page); +skip_page: + unlock_page(push_page); + if(i != page->index) page_cache_release(push_page); - } } if (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK ------=_Part_57609_3390730.1157591940543 Content-Type: application/octet-stream; name=s390_patch Content-Transfer-Encoding: base64 X-Attachment-Id: f_114x72y Content-Disposition: attachment; filename="s390_patch" ZGlmZiAtLW5ldy1maWxlIC11cnAgbGludXgtMi42LjE3L2ZzL3NxdWFzaGZzL2lub2RlLmMgbGlu dXgtMi42LjE3LXBhdGNoZWQvZnMvc3F1YXNoZnMvaW5vZGUuYwotLS0gbGludXgtMi42LjE3L2Zz L3NxdWFzaGZzL2lub2RlLmMJMjAwNi0wOS0wNyAwMDo1NDozMy4wMDAwMDAwMDAgKzAxMDAKKysr IGxpbnV4LTIuNi4xNy1wYXRjaGVkL2ZzL3NxdWFzaGZzL2lub2RlLmMJMjAwNi0wOS0wNyAwMTow ODo0OS4wMDAwMDAwMDAgKzAxMDAKQEAgLTE1NDcsMzYgKzE1NDcsMzEgQEAgc3RhdGljIGludCBz cXVhc2hmc19yZWFkcGFnZShzdHJ1Y3QgZmlsZQogCWZvciAoaSA9IHN0YXJ0X2luZGV4OyBpIDw9 IGVuZF9pbmRleCAmJiBieXRlX29mZnNldCA8IGJ5dGVzOwogCQkJCQlpKyssIGJ5dGVfb2Zmc2V0 ICs9IFBBR0VfQ0FDSEVfU0laRSkgewogCQlzdHJ1Y3QgcGFnZSAqcHVzaF9wYWdlOwotCQlpbnQg YXZha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