Skip to contentSkip to conversation

A patch for squashfs on s390

PATCH Pete Zaitcev 3 participants 3 messages Sep 3, 2006 – Sep 7, 2006

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Installation of RHEL 5 Beta 1 crashes on s390 when the block layer attempts to write out a dirty page into a mapping without a writeout method.

<1>Unable to handle kernel pointer dereference at virtual kernel address 0000000000000000
......
<4>Call Trace:
<4>([<00000000000d6924>] __mpage_writepage+0x2ac/0x720)
<4> [<00000000000d7d08>] mpage_writepages+0x3a4/0x540
<4> [<0000000000083f36>] do_writepages+0x5e/0x78
<4> [<00000000000d58e8>] __writeback_single_inode+0x1d0/0x3ac
<4> [<00000000000d5f72>] sync_sb_inodes+0x22a/0x310
<4> [<00000000000d6126>] sync_inodes_sb+0xce/0xe8
<4> [<00000000000d61cc>] __sync_inodes+0x8c/0xe8
<4> [<00000000000d625e>] sync_inodes+0x36/0x60
<4> [<00000000000aa2d4>] do_sync+0x3c/0xa4
<4> [<00000000000aa366>] sys_sync+0x2a/0x3c
<4> [<000000000001f6e8>] sysc_noemu+0x10/0x16

This happens when get_block is NULL. The situation arises when a page gets mistakenly marked as dirty.

Heiko @IBM debugged this and discovered that squashfs was the culprit. The code in question is squashfs_readpage():

	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 ?
					PAGE_CACHE_SIZE : bytes - byte_offset;
		if (i == page->index)  {
			........... do normal things
		} 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);
			page_cache_release(push_page);
		}
	}

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.

Here's a patch which I made out of Heiko's patch by transforming it:

fs/squashfs/inode.c +9 -2
@@ -1554,8 +1554,15 @@ static int squashfs_readpage(struct file
 			flush_dcache_page(page);
 			SetPageUptodate(page);
 			unlock_page(page);
-		} else if ((push_page =
-				grab_cache_page_nowait(page->mapping, i))) {
+		} else {
+			push_page = grab_cache_page_nowait(page->mapping, i);
+			if (!push_page)
+				continue;
+			if (PageUptodate(push_page)) {
+				unlock_page(push_page);
+				page_cache_release(push_page);
+				continue;
+			}
  			pageaddr = kmap_atomic(push_page, KM_USER0);
 
 			memcpy(pageaddr, data_ptr + byte_offset,

Any objections?

-- Pete

P.S. When is squashfs going to be upstream?

Signature · 1 line
VGER BF report: U 0.5
#1 lore raw
Quoted 8 lines · Pete Zaitcev

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.

Quoted 4 lines

Here's a patch which I made out of Heiko's patch by transforming it:

Any objections?

None from me.

Quoted 5 lines

-- Pete

P.S. When is squashfs going to be upstream?

I'd like Squashfs to be in the mainline kernel. As you may know, I submitted Squashfs in March 2005. I ended up with a lot of necessary improvements (larger than 4GB filesystems etc.), and spent over a year implementing them. These were released as Squashfs 3.0. I could re-submit Squashfs now, however, from my last failed attempt I know it could require a lot of effort to get it accepted, and I'm waiting until I have the necessary spare time. A rushed or poor re-submission is going to be worse than none at all, and I don't want to fail a second time...

Regards

Phillip

Signature · 1 line
VGER BF report: U 0.504827
#2 lore raw
Quoted 10 lines · Phillip Lougher
Quoted 8 lines · Pete Zaitcev

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.

Quoted 8 lines

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.

Quoted 3 lines

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

fs/squashfs/inode.c +0 -0
@@ -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