From: Vivek Goyal <vgoyal@redhat.com>
To: Amir Goldstein <amir73il@gmail.com>
Cc: overlayfs <linux-unionfs@vger.kernel.org>,
Miklos Szeredi <miklos@szeredi.hu>
Subject: Re: [PATCH 10/11] ovl: Introduce read/write barriers around metacopy flag update
Date: Wed, 18 Oct 2017 11:32:36 -0400 [thread overview]
Message-ID: <20171018153236.GI3445@redhat.com> (raw)
In-Reply-To: <CAOQ4uxipEM_yjVBYyL48OhUYs2qL6Cw+rA82+mTwRAoTS=Wk5w@mail.gmail.com>
On Wed, Oct 18, 2017 at 08:19:50AM +0300, Amir Goldstein wrote:
> On Wed, Oct 18, 2017 at 12:05 AM, Vivek Goyal <vgoyal@redhat.com> wrote:
> > If a file is copied up metadata only and later when same file is opened
> > for WRITE, then data copy up takes place. We copy up data, remove METACOPY
> > xattr and then clear the METACOPY flag from ovl_entry->flags. While all
> > these operations happen with oi->lock held, read side of oi->flags is
> > lockless. That is another thread on another cpu can check if METACOPY
> > flag is clear or not.
> >
> > So this gives us an ordering requirement w.r.t METACOPY flag. That is, if
> > another cpu sees METACOPY flag clear, then it should be guaranteed that
> > effects of data copy up and remove xattr operations are also visible.
> >
> > For example.
> >
> > CPU1 CPU2
> > ovl_copy_up_flags() acquire(oi->lock)
> > ovl_dentry_needs_data_copy_up() ovl_copy_up_data()
>
> The relevant lockless execution path of CPU1 is
> ovl_d_real -> ovl_test_flag(OVL_METACOPY) -> return real
> when real is upper, upper needs to be with correct data
>
That path is relevant for ordering requirements w.r.t oi->__upperdentry
and next patch does put an smp_rmb() there to cover it.
> The execution path you describe here is going to test the flag
> under overlay inode lock again in ovl_copy_up_one() so it is irrelevant
> to the barriers patch
It will go into ovl_copy_up_one() only if this cpu saw OVL_METACOPY=1. But
what about the case where OVL_METACOPY is being cleared on CPU2, and
it became visible on CPU1. That means cpu1 will assume file copy up is
complete and it will continue and never both to take oi->lock.
>
>
> > ovl_test_flag(OVL_METACOPY) vfs_removexattr()
> > ovl_clear_metacopy_flag()
> > release(oi->lock)
> >
> > Say CPU2 is copying up data and in the end clears metacopy flag. But if
> > CPU1 perceives the effects of clearing of metacopy flag but not effects of
> > preceeding operations, that would be a problem.
> >
> > Hence this patch introduces smp_wmb() on metacopy flag clear operation
> > and smp_rmb() on metacopy flag test operation.
> >
> > May be some other lock or barrier is already covering it. But I am not sure
> > what that is and is it obvious enough that we will not break it in future.
> >
> > So hence trying to be safe here and introducing barriers explicitly for
> > metacopy bit.
> >
> > Signed-off-by: Vivek Goyal <vgoyal@redhat.com>
> > ---
> > fs/overlayfs/copy_up.c | 6 ++++++
> > fs/overlayfs/util.c | 12 ++++++++++--
> > 2 files changed, 16 insertions(+), 2 deletions(-)
> >
> > diff --git a/fs/overlayfs/copy_up.c b/fs/overlayfs/copy_up.c
> > index 99b7be4ff4fc..200ee3b7d397 100644
> > --- a/fs/overlayfs/copy_up.c
> > +++ b/fs/overlayfs/copy_up.c
> > @@ -466,6 +466,12 @@ static int ovl_copy_up_meta_inode_data(struct ovl_copy_up_ctx *c)
> > if (err)
> > return err;
> >
> > + /*
> > + * Pairs with smp_rmb() after test_bit(OVL_METACOPY). Make sure
>
> This comment is meant to refer the reader to the code that this pairs with
> i.e. pairs with smp_rmb() in ovl_d_real() ..
This pairs with smp_rmb() in ovl_dentry_needs_data_copy_up(). Next patch
has smp_rmb() in ovl_d_real() and I will explain that more.
>
> > + * if OVL_METACOPY flag reset is visible, then all the write
> > + * operations before it are visible as well
> > + */
> > + smp_wmb();
> > ovl_clear_flag(OVL_METACOPY, d_inode(c->dentry));
> > return err;
> > }
> > diff --git a/fs/overlayfs/util.c b/fs/overlayfs/util.c
> > index 91c542d1a39d..6bca9a960c6d 100644
> > --- a/fs/overlayfs/util.c
> > +++ b/fs/overlayfs/util.c
> > @@ -228,6 +228,8 @@ void ovl_dentry_set_upper_alias(struct dentry *dentry)
> > }
> >
> > bool ovl_dentry_needs_data_copy_up(struct dentry *dentry, int flags) {
> > + bool metacopy;
> > +
> > if (!S_ISREG(d_inode(dentry)->i_mode))
> > return false;
> >
> > @@ -237,9 +239,15 @@ bool ovl_dentry_needs_data_copy_up(struct dentry *dentry, int flags) {
> > if (!(OPEN_FMODE(flags) & FMODE_WRITE))
> > return false;
> >
> > - if (!ovl_test_flag(OVL_METACOPY, d_inode(dentry)))
> > + metacopy = ovl_test_flag(OVL_METACOPY, d_inode(dentry));
> > + /*
> > + * Pairs with smp_wmb() while clearing OVL_METACOPY. Make sure if
>
> This comment is meant to refer the reader to the code that this pairs with
> i.e. pairs with smp_wmb() in ovl_copy_up_meta_inode_data() ..
Will do. I guess I will retain this which explains what's the intent
and also add funciton name where OVL_METACOPY is being cleared.
>
> > + * clearing of OVL_METACOPY is visible, then effects of writes
> > + * before that are visible too.
> > + */
> > + smp_rmb();
>
> Please move this rmb to ovl_d_real() after re-testing flag,
> which is the only place that matters for inode data access.
But we are testing it atleast at two places.
(ovl_dentry_needs_data_copy_up()).
First call is in.
ovl_d_real()
ovl_open_need_copy_up()
ovl_dentry_needs_data_copy_up()
And second call is in ovl_copy_up_flags() further down.
ovl_d_real()
ovl_open_need_copy_up()
ovl_dentry_needs_data_copy_up() <---- First Call
ovl_copy_up_flags()
ovl_dentry_needs_data_copy_up() <--- Second Call
Given we are checking/loading oi->flags at both the places, IIUC, we
need smp_rmb() at both the places. And if that's the case, its better
to keep it inside ovl_dentry_needs_data_copy_up() instead of open
coding it in ovl_open_need_copy_up() and ovl_copy_up_flags().
Thanks
Vivek
>
> > + if (!metacopy)
> > return false;
> > -
> > return true;
> > }
> >
> > --
> > 2.13.5
> >
next prev parent reply other threads:[~2017-10-18 15:32 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-17 21:05 [RFC PATCH 00/11][V4] overlayfs: Delayed copy up of data Vivek Goyal
2017-10-17 21:05 ` [PATCH 01/11] ovl: Create origin xattr on copy up for all files Vivek Goyal
2017-10-18 4:09 ` Amir Goldstein
2017-10-18 12:55 ` Vivek Goyal
2017-10-18 13:56 ` Amir Goldstein
2017-10-17 21:05 ` [PATCH 02/11] ovl: ovl_check_setxattr() get rid of redundant -EOPNOTSUPP check Vivek Goyal
2017-10-18 4:11 ` Amir Goldstein
2017-10-17 21:05 ` [PATCH 03/11] ovl: During copy up, first copy up metadata and then data Vivek Goyal
2017-10-18 4:13 ` Amir Goldstein
2017-10-18 4:39 ` Amir Goldstein
2017-10-17 21:05 ` [PATCH 04/11] ovl: Provide a mount option metacopy=on/off for metadata copyup Vivek Goyal
2017-10-18 4:31 ` Amir Goldstein
2017-10-18 13:03 ` Vivek Goyal
2017-10-18 14:09 ` Amir Goldstein
2017-10-18 14:26 ` Vivek Goyal
2017-10-18 14:38 ` Amir Goldstein
2017-10-18 14:10 ` Vivek Goyal
2017-10-18 14:26 ` Amir Goldstein
2017-10-17 21:05 ` [PATCH 05/11] ovl: Copy up only metadata during copy up where it makes sense Vivek Goyal
2017-10-18 4:46 ` Amir Goldstein
2017-10-17 21:05 ` [PATCH 06/11] ovl: Set xattr OVL_XATTR_METACOPY on upper file Vivek Goyal
2017-10-18 4:57 ` Amir Goldstein
2017-10-18 13:30 ` Vivek Goyal
2017-10-17 21:05 ` [PATCH 07/11] ovl: Fix ovl_getattr() to get number of blocks from lower Vivek Goyal
2017-10-18 5:01 ` Amir Goldstein
2017-10-18 13:39 ` Vivek Goyal
2017-10-17 21:05 ` [PATCH 08/11] ovl: Set OVL_METACOPY flag during ovl_lookup() Vivek Goyal
2017-10-18 5:06 ` Amir Goldstein
2017-10-18 13:53 ` Vivek Goyal
2017-10-17 21:05 ` [PATCH 09/11] ovl: Return lower dentry if only metadata copy up took place Vivek Goyal
2017-10-18 5:07 ` Amir Goldstein
2017-10-17 21:05 ` [PATCH 10/11] ovl: Introduce read/write barriers around metacopy flag update Vivek Goyal
2017-10-18 5:19 ` Amir Goldstein
2017-10-18 15:32 ` Vivek Goyal [this message]
2017-10-18 16:05 ` Amir Goldstein
2017-10-17 21:05 ` [PATCH 11/11] ovl: Put barriers to order oi->__upperdentry and OVL_METACOPY update Vivek Goyal
2017-10-18 5:40 ` Amir Goldstein
2017-10-19 13:00 ` Vivek Goyal
2017-10-19 13:21 ` Amir Goldstein
2017-10-19 14:58 ` Vivek Goyal
2017-10-19 15:08 ` Amir Goldstein
2017-10-19 15:22 ` Vivek Goyal
2017-10-19 15:39 ` Amir Goldstein
2017-10-19 15:59 ` Vivek Goyal
2017-10-19 16:33 ` Amir Goldstein
2017-10-19 20:33 ` Vivek Goyal
2017-10-20 4:09 ` Amir Goldstein
2017-10-20 15:41 ` Vivek Goyal
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=20171018153236.GI3445@redhat.com \
--to=vgoyal@redhat.com \
--cc=amir73il@gmail.com \
--cc=linux-unionfs@vger.kernel.org \
--cc=miklos@szeredi.hu \
/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;
as well as URLs for NNTP newsgroup(s).