All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Monakhov <dmonakhov@openvz.org>
To: Theodore Ts'o <tytso@mit.edu>,
	Ext4 Developers List <linux-ext4@vger.kernel.org>
Cc: Theodore Ts'o <tytso@mit.edu>,
	linux-fsdevel@vger.kernel.org, Al Viro <viro@ZenIV.linux.org.uk>
Subject: Re: [PATCH] fs: take i_mutex in __page_symlink()
Date: Tue, 02 Apr 2013 12:19:42 +0400	[thread overview]
Message-ID: <87a9phs5sx.fsf@openvz.org> (raw)
In-Reply-To: <1364829822-18989-1-git-send-email-tytso@mit.edu>

[-- Attachment #1: Type: text/plain, Size: 1953 bytes --]

On Mon,  1 Apr 2013 11:23:42 -0400, Theodore Ts'o <tytso@mit.edu> wrote:
> In Documentation/filesystems/Locking, it's documented that
> write_begin() is guaranteed to be called with i_mutex locked.  The
> function __page_symlink() was not taking i_mutex before calling
> pagecache_write_begin(), which will eventually result in the file
> system's write_begin()'s function getting called.
> 
> Other callers of pagecache_write_begin such as in fs/splice.c, call
> pagecache_write_begin() with i_mutex locked, so fix __page_symlink()
> to be consistent.
> 
> This was discovered by the addition of a new ext4 debugging assertion
> which checked to make sure i_mutex was locked before calling
> ext4_truncate().
> 
> Reported-by: Zheng Liu <gnehzuil.liu@gmail.com>
> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
> Cc: linux-fsdevel@vger.kernel.org
> Cc: Al Viro <viro@ZenIV.linux.org.uk>
> ---
> 
> Note: I plan to carry the following patch in the ext4 tree, unless
> someone objects or Al insists on carrying this in the vfs git tree.
> 
>  fs/namei.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/fs/namei.c b/fs/namei.c
> index 57ae9c8..548e57b 100644
> --- a/fs/namei.c
> +++ b/fs/namei.c
> @@ -4035,8 +4035,10 @@ int __page_symlink(struct inode *inode, const char *symname, int len, int nofs)
>  		flags |= AOP_FLAG_NOFS;
>  
>  retry:
> +	mutex_lock(&inode->i_mutex);
>  	err = pagecache_write_begin(NULL, mapping, 0, len-1,
>  				flags, &page, &fsdata);
> +	mutex_unlock(&inode->i_mutex);
Noo. Please do no do that. i_mutex should being hold from write_begin() to
write_end() because:
1) both functions contains one logical block (critical section)
2) write_end() may update i_size
3) write_end() may call truncate

And since we know that we want to lock i_mutex here only for
convention purposes (no one can access this inode yet) let's do that
correct. Original Zheng's patch was much better.
I have following patch in my queue:

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-patch-ext4_symlink.patch.patch --]
[-- Type: text/x-patch, Size: 887 bytes --]

>From c147d9ae5f9511f722a97179cd9f661e7e10417e Mon Sep 17 00:00:00 2001
From: Dmitry Monakhov <dmonakhov@openvz.org>
Date: Sun, 31 Mar 2013 17:35:38 +0400
Subject: [PATCH] patch ext4_symlink.patch


Signed-off-by: Dmitry Monakhov <dmonakhov@openvz.org>
---
 fs/namei.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/fs/namei.c b/fs/namei.c
index 57ae9c8..9dcdb27 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -4034,6 +4034,7 @@ int __page_symlink(struct inode *inode, const char *symname, int len, int nofs)
 	if (nofs)
 		flags |= AOP_FLAG_NOFS;
 
+	mutex_lock(&inode->i_mutex);
 retry:
 	err = pagecache_write_begin(NULL, mapping, 0, len-1,
 				flags, &page, &fsdata);
@@ -4052,8 +4053,10 @@ retry:
 		goto retry;
 
 	mark_inode_dirty(inode);
+	mutex_unlock(&inode->i_mutex);
 	return 0;
 fail:
+	mutex_unlock(&inode->i_mutex);
 	return err;
 }
 
-- 
1.7.1


[-- Attachment #3: Type: text/plain, Size: 270 bytes --]


>  	if (err)
>  		goto fail;
>  
> -- 
> 1.7.12.rc0.22.gcdd159b
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2013-04-02  8:19 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-27 13:19 [PATCH] ext4: take i_mutex in ext4_symlink to eliminate a warning from ext4_truncate Zheng Liu
2013-03-27 13:41 ` Theodore Ts'o
2013-03-27 14:02   ` Zheng Liu
2013-03-27 13:51     ` Theodore Ts'o
2013-03-27 15:07       ` Zheng Liu
2013-03-27 15:19         ` Zheng Liu
2013-03-27 15:12           ` Theodore Ts'o
2013-03-27 15:35             ` Zheng Liu
2013-03-28 14:06               ` Theodore Ts'o
2013-04-01 15:23                 ` [PATCH] fs: take i_mutex in __page_symlink() Theodore Ts'o
2013-04-01 16:35                   ` Al Viro
2013-04-01 17:38                     ` Theodore Ts'o
2013-04-02  8:19                   ` Dmitry Monakhov [this message]
2013-03-27 14:04     ` [PATCH] ext4: take i_mutex in ext4_symlink to eliminate a warning from ext4_truncate Zheng Liu

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=87a9phs5sx.fsf@openvz.org \
    --to=dmonakhov@openvz.org \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=tytso@mit.edu \
    --cc=viro@ZenIV.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.