From: Jeff Layton <jlayton@redhat.com>
To: Trond Myklebust <trond.myklebust@primarydata.com>
Cc: linux-nfs@vger.kernel.org
Subject: Re: [PATCH] NFS: Fix races in nfs_revalidate_mapping
Date: Tue, 28 Jan 2014 10:10:37 -0500 [thread overview]
Message-ID: <20140128101037.35e04fb7@tlielax.poochiereds.net> (raw)
In-Reply-To: <1390920550-5543-1-git-send-email-trond.myklebust@primarydata.com>
On Tue, 28 Jan 2014 09:49:10 -0500
Trond Myklebust <trond.myklebust@primarydata.com> wrote:
> Commit d529ef83c355f97027ff85298a9709fe06216a66 (NFS: fix the handling
> of NFS_INO_INVALID_DATA flag in nfs_revalidate_mapping) introduces
> a potential race, since it doesn't test the value of nfsi->cache_validity
> and set the bitlock in nfsi->flags atomically.
>
> Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
> Cc: Jeff Layton <jlayton@redhat.com>
> ---
> fs/nfs/inode.c | 22 ++++++++++------------
> 1 file changed, 10 insertions(+), 12 deletions(-)
>
> diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
> index 0a972ee9ccc1..8a5bcb6040ac 100644
> --- a/fs/nfs/inode.c
> +++ b/fs/nfs/inode.c
> @@ -1038,24 +1038,22 @@ int nfs_revalidate_mapping(struct inode *inode, struct address_space *mapping)
> nfs_wait_bit_killable, TASK_KILLABLE);
> if (ret)
> goto out;
> - if (!(nfsi->cache_validity & NFS_INO_INVALID_DATA))
> + spin_lock(&inode->i_lock);
> + if (!(nfsi->cache_validity & NFS_INO_INVALID_DATA)) {
> + spin_unlock(&inode->i_lock);
> goto out;
> + }
> if (!test_and_set_bit_lock(NFS_INO_INVALIDATING, bitlock))
> break;
> - }
> -
I don't think that patch will help.
Consider the case where we have two tasks that enter
nfs_revalidate_mapping simultaneously. NFS_INO_INVALIDATING is
initially clear and NFS_INO_INVALID_DATA is set:
Task 1 Task2
---------------------------------------------------------------------
wait_on_bit(NFS_INO_INVALIDATING) wait_on_bit(NFS_INO_INVALIDATING)
gets i_lock spins on i_lock
checks NFS_INO_INVALID_DATA
sets NFS_INO_INVALIDATING
clears NFS_INO_INVALID_DATA
drops i_lock gets i_lock, finds that NFS_INO_INVALID_DATA
is clear, and exits the function
calls nfs_invalidate_mapping
...so task2 just returned from nfs_revalidate_mapping before the pages
got invalidated.
> - spin_lock(&inode->i_lock);
> - if (nfsi->cache_validity & NFS_INO_INVALID_DATA) {
> - nfsi->cache_validity &= ~NFS_INO_INVALID_DATA;
> - spin_unlock(&inode->i_lock);
> - trace_nfs_invalidate_mapping_enter(inode);
> - ret = nfs_invalidate_mapping(inode, mapping);
> - trace_nfs_invalidate_mapping_exit(inode, ret);
> - } else {
> - /* something raced in and cleared the flag */
> spin_unlock(&inode->i_lock);
> }
>
> + nfsi->cache_validity &= ~NFS_INO_INVALID_DATA;
> + spin_unlock(&inode->i_lock);
> + trace_nfs_invalidate_mapping_enter(inode);
> + ret = nfs_invalidate_mapping(inode, mapping);
> + trace_nfs_invalidate_mapping_exit(inode, ret);
> +
> clear_bit_unlock(NFS_INO_INVALIDATING, bitlock);
> smp_mb__after_clear_bit();
> wake_up_bit(bitlock, NFS_INO_INVALIDATING);
--
Jeff Layton <jlayton@redhat.com>
next prev parent reply other threads:[~2014-01-28 15:10 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-27 18:46 [PATCH] NFS: fix the handling of NFS_INO_INVALID_DATA flag in nfs_revalidate_mapping Jeff Layton
2014-01-28 13:38 ` Jeff Layton
2014-01-28 13:50 ` Trond Myklebust
2014-01-28 14:18 ` Jeff Layton
2014-01-28 14:49 ` [PATCH] NFS: Fix races " Trond Myklebust
2014-01-28 15:10 ` Jeff Layton [this message]
2014-01-28 15:41 ` [PATCH v2] " Trond Myklebust
2014-01-28 15:50 ` [PATCH v3] " Trond Myklebust
2014-01-28 16:05 ` Jeff Layton
2014-01-28 17:24 ` Trond Myklebust
2014-01-28 18:47 ` Jeff Layton
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=20140128101037.35e04fb7@tlielax.poochiereds.net \
--to=jlayton@redhat.com \
--cc=linux-nfs@vger.kernel.org \
--cc=trond.myklebust@primarydata.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox