Linux-Fsdevel Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Miklos Szeredi <miklos@szeredi.hu>
To: Vivek Goyal <vgoyal@redhat.com>
Cc: linux-fsdevel@vger.kernel.org,
	virtio-fs-list <virtio-fs@redhat.com>,
	ganesh.mahalingam@intel.com
Subject: Re: [PATCH] virtiofs: Enable SB_NOSEC flag to improve small write performance
Date: Fri, 17 Jul 2020 10:53:07 +0200	[thread overview]
Message-ID: <CAJfpegt-v6sjm2WyjXMWkObqLdL6TSAi=rjra4KK5sNy6hhhmA@mail.gmail.com> (raw)
In-Reply-To: <20200716181828.GE422759@redhat.com>

On Thu, Jul 16, 2020 at 8:18 PM Vivek Goyal <vgoyal@redhat.com> wrote:
>
> On Thu, Jul 16, 2020 at 10:40:33AM -0400, Vivek Goyal wrote:
> > Ganesh Mahalingam reported that virtiofs is slow with small direct random
> > writes when virtiofsd is run with cache=always.
> >
> > https://github.com/kata-containers/runtime/issues/2815
> >
> > Little debugging showed that that file_remove_privs() is called in cached
> > write path on every write. And everytime it calls
> > security_inode_need_killpriv() which results in call to
> > __vfs_getxattr(XATTR_NAME_CAPS). And this goes to file server to fetch
> > xattr. This extra round trip for every write slows down writes a lot.
> >
> > Normally to avoid paying this penalty on every write, vfs has the
> > notion of caching this information in inode (S_NOSEC). So vfs
> > sets S_NOSEC, if filesystem opted for it using super block flag
> > SB_NOSEC. And S_NOSEC is cleared when setuid/setgid bit is set or
> > when security xattr is set on inode so that next time a write
> > happens, we check inode again for clearing setuid/setgid bits as well
> > clear any security.capability xattr.
> >
> > This seems to work well for local file systems but for remote file
> > systems it is possible that VFS does not have full picture and a
> > different client sets setuid/setgid bit or security.capability xattr
> > on file and that means VFS information about S_NOSEC on another client
> > will be stale. So for remote filesystems SB_NOSEC was disabled by
> > default.
> >
> > commit 9e1f1de02c2275d7172e18dc4e7c2065777611bf
> > Author: Al Viro <viro@zeniv.linux.org.uk>
> > Date:   Fri Jun 3 18:24:58 2011 -0400
> >
> >     more conservative S_NOSEC handling
> >
> > That commit mentioned that these filesystems can still make use of
> > SB_NOSEC as long as they clear S_NOSEC when they are refreshing inode
> > attriutes from server.
> >
> > So this patch tries to enable SB_NOSEC on fuse (regular fuse as well
> > as virtiofs). And clear SB_NOSEC when we are refreshing inode attributes.
> >
> > We need to clear SB_NOSEC either when inode has setuid/setgid bit set
> > or security.capability xattr has been set. We have the first piece of
> > information available in FUSE_GETATTR response. But we don't know if
> > security.capability has been set on file or not. Question is, do we
> > really need to know about security.capability. file_remove_privs()
> > always removes security.capability if a file is being written to. That
> > means when server writes to file, security.capability should be removed
> > without guest having to tell anything to it.
>
>
> I am assuming that file server will clear security.capability on host
> upon WRITE. Is it a fair assumption for all filesystems passthrough
> virtiofsd might be running?

AFAICS this needs to be gated through handle_killpriv, and with that
it can become a generic fuse feature, not just virtiofs:

 * FUSE_HANDLE_KILLPRIV: fs handles killing suid/sgid/cap on write/chown/trunc

Even writeback_cache could be handled by this addition, since we call
fuse_update_attributes() before generic_file_write_iter() :

--- a/fs/fuse/dir.c
+++ b/fs/fuse/dir.c
@@ -985,6 +985,7 @@ static int fuse_update_get_attr(struct inode
*inode, struct file *file,

        if (sync) {
                forget_all_cached_acls(inode);
+               inode->i_flags &= ~S_NOSEC;
                err = fuse_do_getattr(inode, stat, file);
        } else if (stat) {
                generic_fillattr(inode, stat);


Thanks,
Miklos

  reply	other threads:[~2020-07-17  8:53 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-16 14:40 Vivek Goyal
2020-07-16 18:18 ` Vivek Goyal
2020-07-17  8:53   ` Miklos Szeredi [this message]
2020-07-20 15:41     ` Vivek Goyal
2020-07-21 12:33       ` Miklos Szeredi
2020-07-21 15:16         ` Vivek Goyal
2020-07-21 15:44           ` Miklos Szeredi
2020-07-21 15:55             ` Vivek Goyal
2020-07-21 18:16               ` Vivek Goyal
2020-07-21 19:53               ` Miklos Szeredi
2020-07-21 21:30                 ` Vivek Goyal
2020-07-22 10:00                   ` Miklos Szeredi

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='CAJfpegt-v6sjm2WyjXMWkObqLdL6TSAi=rjra4KK5sNy6hhhmA@mail.gmail.com' \
    --to=miklos@szeredi.hu \
    --cc=ganesh.mahalingam@intel.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=vgoyal@redhat.com \
    --cc=virtio-fs@redhat.com \
    --subject='Re: [PATCH] virtiofs: Enable SB_NOSEC flag to improve small write performance' \
    /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

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).