Skip to contentSkip to conversation

vfs: Fix vmtruncate() regression

PATCH In review OGAWA Hirofumi 4 participants 8 messages Jan 11, 2010 – Jan 19, 2010

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

PATCH 1/1 vfs: Fix vmtruncate() regression

Hi,

Could you review this one?

If __block_prepare_write() was failed in block_write_begin(), the allocated blocks can be outside of ->i_size.

But new truncate_pagecache() in vmtuncate() does nothing if new < old. It means the above usage is not working anymore.

So, this patch fixes it by removing "new < old" check. It would need more cleanup/change. But, now -rc and truncate working is in progress, so, this tried to fix it minimum change.

---

 mm/truncate.c |   28 +++++++++++++---------------
 1 file changed, 13 insertions(+), 15 deletions(-)
mm/truncate.c renamed from mm/truncate.c~truncate_pagecache-fix +13 -15
diff -puN mm/truncate.c~truncate_pagecache-fix mm/truncate.c
@@ -522,22 +522,20 @@ EXPORT_SYMBOL_GPL(invalidate_inode_pages
  */
 void truncate_pagecache(struct inode *inode, loff_t old, loff_t new)
 {
-	if (new < old) {
-		struct address_space *mapping = inode->i_mapping;
+	struct address_space *mapping = inode->i_mapping;
 
-		/*
-		 * unmap_mapping_range is called twice, first simply for
-		 * efficiency so that truncate_inode_pages does fewer
-		 * single-page unmaps.  However after this first call, and
-		 * before truncate_inode_pages finishes, it is possible for
-		 * private pages to be COWed, which remain after
-		 * truncate_inode_pages finishes, hence the second
-		 * unmap_mapping_range call must be made for correctness.
-		 */
-		unmap_mapping_range(mapping, new + PAGE_SIZE - 1, 0, 1);
-		truncate_inode_pages(mapping, new);
-		unmap_mapping_range(mapping, new + PAGE_SIZE - 1, 0, 1);
-	}
+	/*
+	 * unmap_mapping_range is called twice, first simply for
+	 * efficiency so that truncate_inode_pages does fewer
+	 * single-page unmaps.  However after this first call, and
+	 * before truncate_inode_pages finishes, it is possible for
+	 * private pages to be COWed, which remain after
+	 * truncate_inode_pages finishes, hence the second
+	 * unmap_mapping_range call must be made for correctness.
+	 */
+	unmap_mapping_range(mapping, new + PAGE_SIZE - 1, 0, 1);
+	truncate_inode_pages(mapping, new);
+	unmap_mapping_range(mapping, new + PAGE_SIZE - 1, 0, 1);
 }
 EXPORT_SYMBOL(truncate_pagecache);
 

_

Signature · 1 line
OGAWA Hirofumi <[email protected]>
Acked-by on v1 1/1
#1 lore raw
Quoted 12 lines · OGAWA Hirofumi

Hi,

Could you review this one?

If __block_prepare_write() was failed in block_write_begin(), the allocated blocks can be outside of ->i_size.

But new truncate_pagecache() in vmtuncate() does nothing if new < old. It means the above usage is not working anymore.

Quoted 6 lines

So, this patch fixes it by removing "new < old" check. It would need more cleanup/change. But, now -rc and truncate working is in progress, so, this tried to fix it minimum change.

Hmm, truncate_pagecache() is for truncating the mm/vm part of the pagecache. vmtruncate should still call inode->i_op->truncate() to trim blocks if required.

However I'd say we do still need to ensure do_invalidatepage is called for the page, for private metadata. So yes I think your patch looks good.

Please apply to mainline and 2.6.32.

Quoted 48 lines

---

 mm/truncate.c |   28 +++++++++++++---------------
 1 file changed, 13 insertions(+), 15 deletions(-)

diff -puN mm/truncate.c~truncate_pagecache-fix mm/truncate.c

mm/truncate.c renamed from mm/truncate.c~truncate_pagecache-fix +13 -15
@@ -522,22 +522,20 @@ EXPORT_SYMBOL_GPL(invalidate_inode_pages
  */
 void truncate_pagecache(struct inode *inode, loff_t old, loff_t new)
 {
-	if (new < old) {
-		struct address_space *mapping = inode->i_mapping;
+	struct address_space *mapping = inode->i_mapping;
 
-		/*
-		 * unmap_mapping_range is called twice, first simply for
-		 * efficiency so that truncate_inode_pages does fewer
-		 * single-page unmaps.  However after this first call, and
-		 * before truncate_inode_pages finishes, it is possible for
-		 * private pages to be COWed, which remain after
-		 * truncate_inode_pages finishes, hence the second
-		 * unmap_mapping_range call must be made for correctness.
-		 */
-		unmap_mapping_range(mapping, new + PAGE_SIZE - 1, 0, 1);
-		truncate_inode_pages(mapping, new);
-		unmap_mapping_range(mapping, new + PAGE_SIZE - 1, 0, 1);
-	}
+	/*
+	 * unmap_mapping_range is called twice, first simply for
+	 * efficiency so that truncate_inode_pages does fewer
+	 * single-page unmaps.  However after this first call, and
+	 * before truncate_inode_pages finishes, it is possible for
+	 * private pages to be COWed, which remain after
+	 * truncate_inode_pages finishes, hence the second
+	 * unmap_mapping_range call must be made for correctness.
+	 */
+	unmap_mapping_range(mapping, new + PAGE_SIZE - 1, 0, 1);
+	truncate_inode_pages(mapping, new);
+	unmap_mapping_range(mapping, new + PAGE_SIZE - 1, 0, 1);
 }
 EXPORT_SYMBOL(truncate_pagecache);
 

_

Signature · 1 line
OGAWA Hirofumi <[email protected]>
#2 lore raw
Quoted 13 lines · Nick Piggin
Quoted 6 lines

If __block_prepare_write() was failed in block_write_begin(), the allocated blocks can be outside of ->i_size.

But new truncate_pagecache() in vmtuncate() does nothing if new < old. It means the above usage is not working anymore.

Quoted 6 lines

So, this patch fixes it by removing "new < old" check. It would need more cleanup/change. But, now -rc and truncate working is in progress, so, this tried to fix it minimum change.

Quoted 7 lines

Hmm, truncate_pagecache() is for truncating the mm/vm part of the pagecache. vmtruncate should still call inode->i_op->truncate() to trim blocks if required.

However I'd say we do still need to ensure do_invalidatepage is called for the page, for private metadata. So yes I think your patch looks good.

Thanks for reviewing. Yes, and it also needs to be called to ensure that have the same state on-disk and page/bh state. [BTW, this became the cause of fatfs corruption.]

Thanks.

Signature · 1 line
OGAWA Hirofumi <[email protected]>
#3 lore raw

PATCH 1/1 vfs: Fix vmtruncate() regression

If __block_prepare_write() was failed in block_write_begin(), the allocated blocks can be outside of ->i_size.

But new truncate_pagecache() in vmtuncate() does nothing if new < old. It means the above usage is not working anymore.

So, this patch fixes it by removing "new < old" check. It would need more cleanup/change. But, now -rc and truncate working is in progress, so, this tried to fix it minimum change.

---

 mm/truncate.c |   28 +++++++++++++---------------
 1 file changed, 13 insertions(+), 15 deletions(-)
mm/truncate.c renamed from mm/truncate.c~truncate_pagecache-fix +13 -15
diff -puN mm/truncate.c~truncate_pagecache-fix mm/truncate.c
@@ -522,22 +522,20 @@ EXPORT_SYMBOL_GPL(invalidate_inode_pages
  */
 void truncate_pagecache(struct inode *inode, loff_t old, loff_t new)
 {
-	if (new < old) {
-		struct address_space *mapping = inode->i_mapping;
+	struct address_space *mapping = inode->i_mapping;
 
-		/*
-		 * unmap_mapping_range is called twice, first simply for
-		 * efficiency so that truncate_inode_pages does fewer
-		 * single-page unmaps.  However after this first call, and
-		 * before truncate_inode_pages finishes, it is possible for
-		 * private pages to be COWed, which remain after
-		 * truncate_inode_pages finishes, hence the second
-		 * unmap_mapping_range call must be made for correctness.
-		 */
-		unmap_mapping_range(mapping, new + PAGE_SIZE - 1, 0, 1);
-		truncate_inode_pages(mapping, new);
-		unmap_mapping_range(mapping, new + PAGE_SIZE - 1, 0, 1);
-	}
+	/*
+	 * unmap_mapping_range is called twice, first simply for
+	 * efficiency so that truncate_inode_pages does fewer
+	 * single-page unmaps.  However after this first call, and
+	 * before truncate_inode_pages finishes, it is possible for
+	 * private pages to be COWed, which remain after
+	 * truncate_inode_pages finishes, hence the second
+	 * unmap_mapping_range call must be made for correctness.
+	 */
+	unmap_mapping_range(mapping, new + PAGE_SIZE - 1, 0, 1);
+	truncate_inode_pages(mapping, new);
+	unmap_mapping_range(mapping, new + PAGE_SIZE - 1, 0, 1);
 }
 EXPORT_SYMBOL(truncate_pagecache);
 

_

maintainer
#4 lore raw
Quoted 46 lines · On Wed, 13 Jan 2010 21:14:09 +0900 OGAWA Hirofumi…

If __block_prepare_write() was failed in block_write_begin(), the allocated blocks can be outside of ->i_size.

But new truncate_pagecache() in vmtuncate() does nothing if new < old. It means the above usage is not working anymore.

So, this patch fixes it by removing "new < old" check. It would need more cleanup/change. But, now -rc and truncate working is in progress, so, this tried to fix it minimum change.

---

 mm/truncate.c |   28 +++++++++++++---------------
 1 file changed, 13 insertions(+), 15 deletions(-)

diff -puN mm/truncate.c~truncate_pagecache-fix mm/truncate.c

mm/truncate.c renamed from mm/truncate.c~truncate_pagecache-fix +5 -15
@@ -522,22 +522,20 @@ EXPORT_SYMBOL_GPL(invalidate_inode_pages
  */
 void truncate_pagecache(struct inode *inode, loff_t old, loff_t new)
 {
-	if (new < old) {
-		struct address_space *mapping = inode->i_mapping;
+	struct address_space *mapping = inode->i_mapping;
 
-		/*
-		 * unmap_mapping_range is called twice, first simply for
-		 * efficiency so that truncate_inode_pages does fewer
-		 * single-page unmaps.  However after this first call, and
-		 * before truncate_inode_pages finishes, it is possible for
-		 * private pages to be COWed, which remain after
-		 * truncate_inode_pages finishes, hence the second
-		 * unmap_mapping_range call must be made for correctness.
-		 */
-		unmap_mapping_range(mapping, new + PAGE_SIZE - 1, 0, 1);
-		truncate_inode_pages(mapping, new);
-		unmap_mapping_range(mapping, new + PAGE_SIZE - 1, 0, 1);
-	}
+	/*
+	 * unmap_mapping_range is called twice, first simply for
+	 * efficiency so that truncate_inode_pages does fewer
+	 * single-page unmaps.  However after this first call, and

mm/truncate.c EXPORT_SYMBOL_GPL(invalidate_inode_pages · line 540

Quoted 10 lines
mm/truncate.c renamed from mm/truncate.c~truncate_pagecache-fix +8 -0
+	 * before truncate_inode_pages finishes, it is possible for
+	 * private pages to be COWed, which remain after
+	 * truncate_inode_pages finishes, hence the second
+	 * unmap_mapping_range call must be made for correctness.
+	 */
+	unmap_mapping_range(mapping, new + PAGE_SIZE - 1, 0, 1);
+	truncate_inode_pages(mapping, new);
+	unmap_mapping_range(mapping, new + PAGE_SIZE - 1, 0, 1);
 }
 EXPORT_SYMBOL(truncate_pagecache);

The fix was applied to 2.6.33-rcX (cedabed49b39b4319bccc059a63344b6232b619c), appears to be needed in 2.6.32.x but no cc:stable's are present?

#5 lore raw
Quoted 55 lines · Andrew Morton
Quoted 52 lines · On Wed, 13 Jan 2010 21:14:09 +0900 OGAWA Hirofumi…

If __block_prepare_write() was failed in block_write_begin(), the allocated blocks can be outside of ->i_size.

But new truncate_pagecache() in vmtuncate() does nothing if new < old. It means the above usage is not working anymore.

So, this patch fixes it by removing "new < old" check. It would need more cleanup/change. But, now -rc and truncate working is in progress, so, this tried to fix it minimum change.

---

 mm/truncate.c |   28 +++++++++++++---------------
 1 file changed, 13 insertions(+), 15 deletions(-)

diff -puN mm/truncate.c~truncate_pagecache-fix mm/truncate.c

mm/truncate.c renamed from mm/truncate.c~truncate_pagecache-fix +11 -15
@@ -522,22 +522,20 @@ EXPORT_SYMBOL_GPL(invalidate_inode_pages
  */
 void truncate_pagecache(struct inode *inode, loff_t old, loff_t new)
 {
-	if (new < old) {
-		struct address_space *mapping = inode->i_mapping;
+	struct address_space *mapping = inode->i_mapping;
 
-		/*
-		 * unmap_mapping_range is called twice, first simply for
-		 * efficiency so that truncate_inode_pages does fewer
-		 * single-page unmaps.  However after this first call, and
-		 * before truncate_inode_pages finishes, it is possible for
-		 * private pages to be COWed, which remain after
-		 * truncate_inode_pages finishes, hence the second
-		 * unmap_mapping_range call must be made for correctness.
-		 */
-		unmap_mapping_range(mapping, new + PAGE_SIZE - 1, 0, 1);
-		truncate_inode_pages(mapping, new);
-		unmap_mapping_range(mapping, new + PAGE_SIZE - 1, 0, 1);
-	}
+	/*
+	 * unmap_mapping_range is called twice, first simply for
+	 * efficiency so that truncate_inode_pages does fewer
+	 * single-page unmaps.  However after this first call, and
+	 * before truncate_inode_pages finishes, it is possible for
+	 * private pages to be COWed, which remain after
+	 * truncate_inode_pages finishes, hence the second
+	 * unmap_mapping_range call must be made for correctness.
+	 */
+	unmap_mapping_range(mapping, new + PAGE_SIZE - 1, 0, 1);
Quoted 8 lines

mm/truncate.c EXPORT_SYMBOL_GPL(invalidate_inode_pages · line 540

Quoted 4 lines
mm/truncate.c renamed from mm/truncate.c~truncate_pagecache-fix +2 -0
+	truncate_inode_pages(mapping, new);
+	unmap_mapping_range(mapping, new + PAGE_SIZE - 1, 0, 1);
 }
 EXPORT_SYMBOL(truncate_pagecache);

The fix was applied to 2.6.33-rcX (cedabed49b39b4319bccc059a63344b6232b619c), appears to be needed in 2.6.32.x but no cc:stable's are present?

Ah, yes. I forgot to add "Cc: stable". Please apply this to 2.6.32.x.

Signature · 1 line
OGAWA Hirofumi <[email protected]>
#6 lore raw
Quoted 66 lines · OGAWA Hirofumi
Quoted 55 lines · Andrew Morton
Quoted 52 lines · On Wed, 13 Jan 2010 21:14:09 +0900 OGAWA Hirofumi…

If __block_prepare_write() was failed in block_write_begin(), the allocated blocks can be outside of ->i_size.

But new truncate_pagecache() in vmtuncate() does nothing if new < old. It means the above usage is not working anymore.

So, this patch fixes it by removing "new < old" check. It would need more cleanup/change. But, now -rc and truncate working is in progress, so, this tried to fix it minimum change.

---

 mm/truncate.c |   28 +++++++++++++---------------
 1 file changed, 13 insertions(+), 15 deletions(-)

diff -puN mm/truncate.c~truncate_pagecache-fix mm/truncate.c

mm/truncate.c renamed from mm/truncate.c~truncate_pagecache-fix +11 -15
@@ -522,22 +522,20 @@ EXPORT_SYMBOL_GPL(invalidate_inode_pages
  */
 void truncate_pagecache(struct inode *inode, loff_t old, loff_t new)
 {
-	if (new < old) {
-		struct address_space *mapping = inode->i_mapping;
+	struct address_space *mapping = inode->i_mapping;
 
-		/*
-		 * unmap_mapping_range is called twice, first simply for
-		 * efficiency so that truncate_inode_pages does fewer
-		 * single-page unmaps.  However after this first call, and
-		 * before truncate_inode_pages finishes, it is possible for
-		 * private pages to be COWed, which remain after
-		 * truncate_inode_pages finishes, hence the second
-		 * unmap_mapping_range call must be made for correctness.
-		 */
-		unmap_mapping_range(mapping, new + PAGE_SIZE - 1, 0, 1);
-		truncate_inode_pages(mapping, new);
-		unmap_mapping_range(mapping, new + PAGE_SIZE - 1, 0, 1);
-	}
+	/*
+	 * unmap_mapping_range is called twice, first simply for
+	 * efficiency so that truncate_inode_pages does fewer
+	 * single-page unmaps.  However after this first call, and
+	 * before truncate_inode_pages finishes, it is possible for
+	 * private pages to be COWed, which remain after
+	 * truncate_inode_pages finishes, hence the second
+	 * unmap_mapping_range call must be made for correctness.
+	 */
+	unmap_mapping_range(mapping, new + PAGE_SIZE - 1, 0, 1);
Quoted 8 lines

mm/truncate.c EXPORT_SYMBOL_GPL(invalidate_inode_pages · line 540

Quoted 4 lines
mm/truncate.c renamed from mm/truncate.c~truncate_pagecache-fix +2 -0
+	truncate_inode_pages(mapping, new);
+	unmap_mapping_range(mapping, new + PAGE_SIZE - 1, 0, 1);
 }
 EXPORT_SYMBOL(truncate_pagecache);

The fix was applied to 2.6.33-rcX (cedabed49b39b4319bccc059a63344b6232b619c), appears to be needed in 2.6.32.x but no cc:stable's are present?

Quoted 1 line

Ah, yes. I forgot to add "Cc: stable". Please apply this to 2.6.32.x.

Thanks guys, it's quite important so please apply to stable 2.6.32 and consider it as a high priority to release.

#7 lore raw
Quoted 67 lines · Nick Piggin
Quoted 66 lines · OGAWA Hirofumi
Quoted 63 lines · Andrew Morton
Quoted 46 lines · On Wed, 13 Jan 2010 21:14:09 +0900 OGAWA Hirofumi…

If __block_prepare_write() was failed in block_write_begin(), the allocated blocks can be outside of ->i_size.

But new truncate_pagecache() in vmtuncate() does nothing if new < old. It means the above usage is not working anymore.

So, this patch fixes it by removing "new < old" check. It would need more cleanup/change. But, now -rc and truncate working is in progress, so, this tried to fix it minimum change.

---

 mm/truncate.c |   28 +++++++++++++---------------
 1 file changed, 13 insertions(+), 15 deletions(-)

diff -puN mm/truncate.c~truncate_pagecache-fix mm/truncate.c

mm/truncate.c renamed from mm/truncate.c~truncate_pagecache-fix +5 -15
@@ -522,22 +522,20 @@ EXPORT_SYMBOL_GPL(invalidate_inode_pages
  */
 void truncate_pagecache(struct inode *inode, loff_t old, loff_t new)
 {
-	if (new < old) {
-		struct address_space *mapping = inode->i_mapping;
+	struct address_space *mapping = inode->i_mapping;
 
-		/*
-		 * unmap_mapping_range is called twice, first simply for
-		 * efficiency so that truncate_inode_pages does fewer
-		 * single-page unmaps.  However after this first call, and
-		 * before truncate_inode_pages finishes, it is possible for
-		 * private pages to be COWed, which remain after
-		 * truncate_inode_pages finishes, hence the second
-		 * unmap_mapping_range call must be made for correctness.
-		 */
-		unmap_mapping_range(mapping, new + PAGE_SIZE - 1, 0, 1);
-		truncate_inode_pages(mapping, new);
-		unmap_mapping_range(mapping, new + PAGE_SIZE - 1, 0, 1);
-	}
+	/*
+	 * unmap_mapping_range is called twice, first simply for
+	 * efficiency so that truncate_inode_pages does fewer
+	 * single-page unmaps.  However after this first call, and

mm/truncate.c EXPORT_SYMBOL_GPL(invalidate_inode_pages · line 540

Quoted 10 lines
mm/truncate.c renamed from mm/truncate.c~truncate_pagecache-fix +8 -0
+	 * before truncate_inode_pages finishes, it is possible for
+	 * private pages to be COWed, which remain after
+	 * truncate_inode_pages finishes, hence the second
+	 * unmap_mapping_range call must be made for correctness.
+	 */
+	unmap_mapping_range(mapping, new + PAGE_SIZE - 1, 0, 1);
+	truncate_inode_pages(mapping, new);
+	unmap_mapping_range(mapping, new + PAGE_SIZE - 1, 0, 1);
 }
 EXPORT_SYMBOL(truncate_pagecache);

The fix was applied to 2.6.33-rcX (cedabed49b39b4319bccc059a63344b6232b619c), appears to be needed in 2.6.32.x but no cc:stable's are present?

Quoted 4 lines
Quoted 1 line

Ah, yes. I forgot to add "Cc: stable". Please apply this to 2.6.32.x.

Thanks guys, it's quite important so please apply to stable 2.6.32 and consider it as a high priority to release.

Now queued up for the next .32 -stable release.

greg k-h