Skip to contentSkip to conversation

mm: Improve comment before pagecache_isize_extended()

PATCH In review Jan Kara 2 participants 5 messages Nov 4, 2014

Subsystems (3)
lore
Share & tools
lore

Jan Kara

author maintainer
#0 lore raw

PATCH 1/1 mm: Improve comment before pagecache_isize_extended()

Not all filesystems are using i_mutex for serialization - reflect that in the comment. Also expand the reasoning a bit. It is complex enough that it deserves more details.

---
 mm/truncate.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

BTW Dave has queued patch which removes the WARN_ON(!mutex_locked(inode->i_mutex)) from the function. That should go to Linus ASAP.

mm/truncate.c +7 -4
index 261eaf6e5a19..b248c0c8dcd1 100644
@@ -743,10 +743,13 @@ EXPORT_SYMBOL(truncate_setsize);
  * changed.
  *
  * The function must be called after i_size is updated so that page fault
- * coming after we unlock the page will already see the new i_size.
- * The function must be called while we still hold i_mutex - this not only
- * makes sure i_size is stable but also that userspace cannot observe new
- * i_size value before we are prepared to store mmap writes at new inode size.
+ * coming after we unlock the page will already see the new i_size.  The caller
+ * must make sure (generally by holding i_mutex but e.g. XFS uses its private
+ * lock) i_size cannot change from the new value while we are called. It must
+ * also make sure userspace cannot observe new i_size value before we are
+ * prepared to store mmap writes upto new inode size (otherwise userspace could
+ * think it stored data via mmap within i_size but they would get zeroed due to
+ * writeback & reclaim because they have no backing blocks).
  */
 void pagecache_isize_extended(struct inode *inode, loff_t from, loff_t to)
 {
Signature · 7 lines
1.8.1.4

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#1 lore raw
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 04.11.14 at 12:43, <"[email protected]".non-mime.internet> wrote:
mm/truncate.c +0 -4
@@ -743,10 +743,13 @@ EXPORT_SYMBOL(truncate_setsize);
  * changed.
  *
  * The function must be called after i_size is updated so that page fault
- * coming after we unlock the page will already see the new i_size.
- * The function must be called while we still hold i_mutex - this not only
- * makes sure i_size is stable but also that userspace cannot observe new
- * i_size value before we are prepared to store mmap writes at new inode size.

mm/truncate.c EXPORT_SYMBOL(truncate_setsize); · line 755

Quoted 10 lines
mm/truncate.c +7 -0
+ * coming after we unlock the page will already see the new i_size.  The caller
+ * must make sure (generally by holding i_mutex but e.g. XFS uses its private
+ * lock) i_size cannot change from the new value while we are called. It must
+ * also make sure userspace cannot observe new i_size value before we are
+ * prepared to store mmap writes upto new inode size (otherwise userspace could
+ * think it stored data via mmap within i_size but they would get zeroed due to
+ * writeback & reclaim because they have no backing blocks).
  */
 void pagecache_isize_extended(struct inode *inode, loff_t from, loff_t to)
 {

May I suggest that the comment preceding truncate_setsize() also be updated/removed?

Jan

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

author maintainer
#2 lore raw
Quoted 16 lines · Jan Beulich
Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 04.11.14 at 12:43, <"[email protected]".non-mime.internet> wrote:
mm/truncate.c +5 -4
@@ -743,10 +743,13 @@ EXPORT_SYMBOL(truncate_setsize);
  * changed.
  *
  * The function must be called after i_size is updated so that page fault
- * coming after we unlock the page will already see the new i_size.
- * The function must be called while we still hold i_mutex - this not only
- * makes sure i_size is stable but also that userspace cannot observe new
- * i_size value before we are prepared to store mmap writes at new inode size.
+ * coming after we unlock the page will already see the new i_size.  The caller
+ * must make sure (generally by holding i_mutex but e.g. XFS uses its private
+ * lock) i_size cannot change from the new value while we are called. It must
+ * also make sure userspace cannot observe new i_size value before we are
+ * prepared to store mmap writes upto new inode size (otherwise userspace could
Quoted 8 lines

mm/truncate.c EXPORT_SYMBOL(truncate_setsize); · line 755

Quoted 5 lines
mm/truncate.c +2 -0
+ * think it stored data via mmap within i_size but they would get zeroed due to
+ * writeback & reclaim because they have no backing blocks).
  */
 void pagecache_isize_extended(struct inode *inode, loff_t from, loff_t to)
 {

May I suggest that the comment preceding truncate_setsize() also be updated/removed?

But that comment is actually still true AFAICT because VFS takes i_mutex
before calling into ->setattr(). So we hold i_mutex in truncate_setsize() even for XFS.

Honza

Signature · 8 lines
Jan Kara <[email protected]>
SUSE Labs, CR

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#3 lore raw
Quoted 30 lines
Quoted 1 line
Quoted 1 line · On 04.11.14 at 16:33, <[email protected]> wrote:
Quoted 11 lines · Jan Beulich

mm/truncate.c EXPORT_SYMBOL(truncate_setsize); · line 749

Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 04.11.14 at 12:43, <"[email protected]".non-mime.internet> wrote:
mm/truncate.c +0 -4
@@ -743,10 +743,13 @@ EXPORT_SYMBOL(truncate_setsize);
  * changed.
  *
  * The function must be called after i_size is updated so that page fault
- * coming after we unlock the page will already see the new i_size.
- * The function must be called while we still hold i_mutex - this not only
- * makes sure i_size is stable but also that userspace cannot observe new
- * i_size value before we are prepared to store mmap writes at new inode 

size.

Quoted 1 line

mm/truncate.c EXPORT_SYMBOL(truncate_setsize); · line 746

Quoted 1 line
mm/truncate.c +1 -0
+ * coming after we unlock the page will already see the new i_size.  The 

caller

Quoted 1 line

mm/truncate.c EXPORT_SYMBOL(truncate_setsize); · line 747

Quoted 1 line
mm/truncate.c +1 -0
+ * must make sure (generally by holding i_mutex but e.g. XFS uses its 

private

Quoted 1 line

mm/truncate.c EXPORT_SYMBOL(truncate_setsize); · line 748

Quoted 1 line
mm/truncate.c +1 -0
+ * lock) i_size cannot change from the new value while we are called. It 

must

Quoted 2 lines

mm/truncate.c EXPORT_SYMBOL(truncate_setsize); · line 750

Quoted 2 lines
mm/truncate.c +2 -0
+ * also make sure userspace cannot observe new i_size value before we are
+ * prepared to store mmap writes upto new inode size (otherwise userspace 

could

Quoted 1 line

mm/truncate.c EXPORT_SYMBOL(truncate_setsize); · line 751

Quoted 1 line
mm/truncate.c +1 -0
+ * think it stored data via mmap within i_size but they would get zeroed 

due to

Quoted 5 lines
Quoted 4 lines
mm/truncate.c +1 -0
+ * writeback & reclaim because they have no backing blocks).
  */
 void pagecache_isize_extended(struct inode *inode, loff_t from, loff_t to)
 {
Quoted 5 lines
Quoted 2 lines

May I suggest that the comment preceding truncate_setsize() also be updated/removed?

But that comment is actually still true AFAICT because VFS takes i_mutex
before calling into ->setattr(). So we hold i_mutex in truncate_setsize() even for XFS.

I doubt that, especially in the light of the WARN_ON() that prompted all this:

[<ffffffff810053fa>] dump_trace+0x7a/0x350
[<ffffffff810050de>] show_stack_log_lvl+0xee/0x150
[<ffffffff810064fc>] show_stack+0x1c/0x50
[<ffffffff8138e4e3>] dump_stack+0x68/0x7d
[<ffffffff81042c82>] warn_slowpath_common+0x82/0xb0
[<ffffffff810d3831>] pagecache_isize_extended+0x121/0x130
[<ffffffff810d4689>] truncate_setsize+0x29/0x50
[<ffffffffa056705f>] xfs_setattr_size+0x12f/0x440 [xfs]
[<ffffffffa055cbf7>] xfs_file_fallocate+0x297/0x310 [xfs]
[<ffffffff81111b59>] do_fallocate+0x169/0x190
[<ffffffff8111206e>] SyS_fallocate+0x4e/0x90
[<ffffffff81392712>] system_call_fastpath+0x12/0x17

[<00007f0e6bdddf45>] 0x7f0e6bdddf45

I.e. truncate_setsize() is being called here without the mutex held (or else the WARN_ON() wouldn't have got triggered in the first place).

Jan

author maintainer
#4 lore raw
Quoted 51 lines · Jan Beulich
Quoted 30 lines
Quoted 1 line
Quoted 1 line · On 04.11.14 at 16:33, <[email protected]> wrote:
Quoted 11 lines · Jan Beulich

mm/truncate.c EXPORT_SYMBOL(truncate_setsize); · line 749

Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 04.11.14 at 12:43, <"[email protected]".non-mime.internet> wrote:
mm/truncate.c +0 -4
@@ -743,10 +743,13 @@ EXPORT_SYMBOL(truncate_setsize);
  * changed.
  *
  * The function must be called after i_size is updated so that page fault
- * coming after we unlock the page will already see the new i_size.
- * The function must be called while we still hold i_mutex - this not only
- * makes sure i_size is stable but also that userspace cannot observe new
- * i_size value before we are prepared to store mmap writes at new inode 

size.

Quoted 1 line

mm/truncate.c EXPORT_SYMBOL(truncate_setsize); · line 746

Quoted 1 line
mm/truncate.c +1 -0
+ * coming after we unlock the page will already see the new i_size.  The 

caller

Quoted 1 line

mm/truncate.c EXPORT_SYMBOL(truncate_setsize); · line 747

Quoted 1 line
mm/truncate.c +1 -0
+ * must make sure (generally by holding i_mutex but e.g. XFS uses its 

private

Quoted 1 line

mm/truncate.c EXPORT_SYMBOL(truncate_setsize); · line 748

Quoted 1 line
mm/truncate.c +1 -0
+ * lock) i_size cannot change from the new value while we are called. It 

must

Quoted 2 lines

mm/truncate.c EXPORT_SYMBOL(truncate_setsize); · line 750

Quoted 2 lines
mm/truncate.c +2 -0
+ * also make sure userspace cannot observe new i_size value before we are
+ * prepared to store mmap writes upto new inode size (otherwise userspace 

could

Quoted 1 line

mm/truncate.c EXPORT_SYMBOL(truncate_setsize); · line 751

Quoted 1 line
mm/truncate.c +1 -0
+ * think it stored data via mmap within i_size but they would get zeroed 

due to

Quoted 5 lines
Quoted 4 lines
mm/truncate.c +1 -0
+ * writeback & reclaim because they have no backing blocks).
  */
 void pagecache_isize_extended(struct inode *inode, loff_t from, loff_t to)
 {
Quoted 5 lines
Quoted 2 lines

May I suggest that the comment preceding truncate_setsize() also be updated/removed?

But that comment is actually still true AFAICT because VFS takes i_mutex
before calling into ->setattr(). So we hold i_mutex in truncate_setsize() even for XFS.

I doubt that, especially in the light of the WARN_ON() that prompted all this:

[<ffffffff810053fa>] dump_trace+0x7a/0x350
[<ffffffff810050de>] show_stack_log_lvl+0xee/0x150
[<ffffffff810064fc>] show_stack+0x1c/0x50
[<ffffffff8138e4e3>] dump_stack+0x68/0x7d
[<ffffffff81042c82>] warn_slowpath_common+0x82/0xb0
[<ffffffff810d3831>] pagecache_isize_extended+0x121/0x130
[<ffffffff810d4689>] truncate_setsize+0x29/0x50
[<ffffffffa056705f>] xfs_setattr_size+0x12f/0x440 [xfs]
[<ffffffffa055cbf7>] xfs_file_fallocate+0x297/0x310 [xfs]
[<ffffffff81111b59>] do_fallocate+0x169/0x190
[<ffffffff8111206e>] SyS_fallocate+0x4e/0x90
[<ffffffff81392712>] system_call_fastpath+0x12/0x17
Quoted 5 lines

[<00007f0e6bdddf45>] 0x7f0e6bdddf45

I.e. truncate_setsize() is being called here without the mutex held (or else the WARN_ON() wouldn't have got triggered in the first place).

Ah, OK, I was thinking about standard truncate path and didn't notice
that xfs_setattr_size() can get called also from the fallocate code. I'll fix that comment as well.

Honza

Signature · 8 lines
Jan Kara <[email protected]>
SUSE Labs, CR

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>