All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC v2 0/4] overlayfs: Optimize override/revert creds
@ 2024-01-25 23:57 Vinicius Costa Gomes
  2024-01-25 23:57 ` [RFC v2 1/4] cleanup: Fix discarded const warning when defining guards Vinicius Costa Gomes
                   ` (4 more replies)
  0 siblings, 5 replies; 15+ messages in thread
From: Vinicius Costa Gomes @ 2024-01-25 23:57 UTC (permalink / raw)
  To: brauner, amir73il, hu1.chen
  Cc: miklos, malini.bhandaru, tim.c.chen, mikko.ylinen, lizhen.you,
	linux-unionfs, linux-kernel, Vinicius Costa Gomes

Hi,

It was noticed that some workloads suffer from contention on
increasing/decrementing the ->usage counter in their credentials,
those refcount operations are associated with overriding/reverting the
current task credentials. (the linked thread adds more context)

In some specialized cases, overlayfs is one of them, the credentials
in question have a longer lifetime than the override/revert "critical
section". In the overlayfs case, the credentials are created when the
fs is mounted and destroyed when it's unmounted. In this case of long
lived credentials, the usage counter doesn't need to be
incremented/decremented.

Add a lighter version of credentials override/revert to be used in
these specialized cases. To make sure that the override/revert calls
are paired, add a cleanup guard macro. This was suggested here:

https://lore.kernel.org/all/20231219-marken-pochen-26d888fb9bb9@brauner/

With a small number of tweaks:
 - Used inline functions instead of macros;
 - A small change to store the credentials into the passed argument,
   the guard is now defined as (note the added '_T ='):
   
      DEFINE_GUARD(cred, const struct cred *, _T = override_creds_light(_T),
                  revert_creds_light(_T));

 - Allow "const" arguments to be used with these kind of guards;

Some comments:
 - If patch 1/4 is not a good idea (adding the cast), the alternative
   I can see is using some kind of container for the credentials;
 - The only user for the backing file ops is overlayfs, so these
   changes make sense, but may not make sense in the most general
   case;

For the numbers, some from 'perf c2c', before this series:
(edited to fit)

#
#        ----- HITM -----                                        Shared                          
#   Num  RmtHitm  LclHitm                      Symbol            Object         Source:Line  Node
# .....  .......  .......  ..........................  ................  ..................  ....
#
  -------------------------
      0      412     1028  
  -------------------------
          41.50%   42.22%  [k] revert_creds            [kernel.vmlinux]  atomic64_64.h:39     0  1
          15.05%   10.60%  [k] override_creds          [kernel.vmlinux]  atomic64_64.h:25     0  1
           0.73%    0.58%  [k] init_file               [kernel.vmlinux]  atomic64_64.h:25     0  1
           0.24%    0.10%  [k] revert_creds            [kernel.vmlinux]  cred.h:266           0  1
          32.28%   37.16%  [k] generic_permission      [kernel.vmlinux]  mnt_idmapping.h:81   0  1
           9.47%    8.75%  [k] generic_permission      [kernel.vmlinux]  mnt_idmapping.h:81   0  1
           0.49%    0.58%  [k] inode_owner_or_capable  [kernel.vmlinux]  mnt_idmapping.h:81   0  1
           0.24%    0.00%  [k] generic_permission      [kernel.vmlinux]  namei.c:354          0

  -------------------------
      1       50      103  
  -------------------------
         100.00%  100.00%  [k] update_cfs_group  [kernel.vmlinux]  atomic64_64.h:15   0  1

  -------------------------
      2       50       98  
  -------------------------
          96.00%   96.94%  [k] update_cfs_group  [kernel.vmlinux]  atomic64_64.h:15   0  1
           2.00%    1.02%  [k] update_load_avg   [kernel.vmlinux]  atomic64_64.h:25   0  1
           0.00%    2.04%  [k] update_load_avg   [kernel.vmlinux]  fair.c:4118        0
           2.00%    0.00%  [k] update_cfs_group  [kernel.vmlinux]  fair.c:3932        0  1

after this series:

#
#        ----- HITM -----                                   Shared                        
#   Num  RmtHitm  LclHitm                 Symbol            Object       Source:Line  Node
# .....  .......  .......   ....................  ................  ................  ....
#
  -------------------------
      0       54       88  
  -------------------------
         100.00%  100.00%   [k] update_cfs_group  [kernel.vmlinux]  atomic64_64.h:15   0  1

  -------------------------
      1       48       83  
  -------------------------
          97.92%   97.59%   [k] update_cfs_group  [kernel.vmlinux]  atomic64_64.h:15   0  1
           2.08%    1.20%   [k] update_load_avg   [kernel.vmlinux]  atomic64_64.h:25   0  1
           0.00%    1.20%   [k] update_load_avg   [kernel.vmlinux]  fair.c:4118        0  1

  -------------------------
      2       28       44  
  -------------------------
          85.71%   79.55%   [k] generic_permission      [kernel.vmlinux]  mnt_idmapping.h:81   0  1
          14.29%   20.45%   [k] generic_permission      [kernel.vmlinux]  mnt_idmapping.h:81   0  1


The contention is practically gone.

Link: https://lore.kernel.org/all/20231018074553.41333-1-hu1.chen@intel.com/

Vinicius Costa Gomes (4):
  cleanup: Fix discarded const warning when defining guards
  cred: Add a light version of override/revert_creds()
  overlayfs: Optimize credentials usage
  fs: Optimize credentials reference count for backing file ops

 fs/backing-file.c       | 124 +++++++++++++++++++---------------------
 fs/overlayfs/copy_up.c  |   4 +-
 fs/overlayfs/dir.c      |  22 +++----
 fs/overlayfs/file.c     |  70 ++++++++++++-----------
 fs/overlayfs/inode.c    |  60 ++++++++++---------
 fs/overlayfs/namei.c    |  21 ++++---
 fs/overlayfs/readdir.c  |  18 +++---
 fs/overlayfs/util.c     |  23 ++++----
 fs/overlayfs/xattrs.c   |  34 +++++------
 include/linux/cleanup.h |   2 +-
 include/linux/cred.h    |  21 +++++++
 kernel/cred.c           |   6 +-
 12 files changed, 215 insertions(+), 190 deletions(-)

-- 
2.43.0


^ permalink raw reply	[flat|nested] 15+ messages in thread
* Re: [RFC v2 4/4] fs: Optimize credentials reference count for backing file ops
@ 2024-01-28 12:27 kernel test robot
  0 siblings, 0 replies; 15+ messages in thread
From: kernel test robot @ 2024-01-28 12:27 UTC (permalink / raw)
  To: oe-kbuild; +Cc: lkp, Dan Carpenter

BCC: lkp@intel.com
CC: oe-kbuild-all@lists.linux.dev
In-Reply-To: <20240125235723.39507-5-vinicius.gomes@intel.com>
References: <20240125235723.39507-5-vinicius.gomes@intel.com>
TO: Vinicius Costa Gomes <vinicius.gomes@intel.com>

Hi Vinicius,

[This is a private test report for your RFC patch.]
kernel test robot noticed the following build warnings:

[auto build test WARNING on brauner-vfs/vfs.all]
[also build test WARNING on linus/master v6.8-rc1 next-20240125]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Vinicius-Costa-Gomes/cleanup-Fix-discarded-const-warning-when-defining-guards/20240126-080128
base:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git vfs.all
patch link:    https://lore.kernel.org/r/20240125235723.39507-5-vinicius.gomes%40intel.com
patch subject: [RFC v2 4/4] fs: Optimize credentials reference count for backing file ops
:::::: branch date: 3 days ago
:::::: commit date: 3 days ago
config: i386-randconfig-141-20240128 (https://download.01.org/0day-ci/archive/20240128/202401282026.OY6K7pyk-lkp@intel.com/config)
compiler: clang version 17.0.6 (https://github.com/llvm/llvm-project 6009708b4367171ccdbf4b5905cb6a803753fe18)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Reported-by: Dan Carpenter <error27@gmail.com>
| Closes: https://lore.kernel.org/r/202401282026.OY6K7pyk-lkp@intel.com/

smatch warnings:
fs/backing-file.c:181 backing_file_read_iter() error: uninitialized symbol 'ret'.
fs/backing-file.c:265 backing_file_splice_read() error: uninitialized symbol 'ret'.
fs/backing-file.c:318 backing_file_mmap() error: uninitialized symbol 'ret'.

vim +/ret +181 fs/backing-file.c

a6293b3e285cd0 Amir Goldstein       2023-11-22  136  
a6293b3e285cd0 Amir Goldstein       2023-11-22  137  
a6293b3e285cd0 Amir Goldstein       2023-11-22  138  ssize_t backing_file_read_iter(struct file *file, struct iov_iter *iter,
a6293b3e285cd0 Amir Goldstein       2023-11-22  139  			       struct kiocb *iocb, int flags,
a6293b3e285cd0 Amir Goldstein       2023-11-22  140  			       struct backing_file_ctx *ctx)
a6293b3e285cd0 Amir Goldstein       2023-11-22  141  {
a6293b3e285cd0 Amir Goldstein       2023-11-22  142  	struct backing_aio *aio = NULL;
3da9951cd3bbfa Vinicius Costa Gomes 2024-01-25  143  	const struct cred *old_cred = ctx->cred;
a6293b3e285cd0 Amir Goldstein       2023-11-22  144  	ssize_t ret;
a6293b3e285cd0 Amir Goldstein       2023-11-22  145  
a6293b3e285cd0 Amir Goldstein       2023-11-22  146  	if (WARN_ON_ONCE(!(file->f_mode & FMODE_BACKING)))
a6293b3e285cd0 Amir Goldstein       2023-11-22  147  		return -EIO;
a6293b3e285cd0 Amir Goldstein       2023-11-22  148  
a6293b3e285cd0 Amir Goldstein       2023-11-22  149  	if (!iov_iter_count(iter))
a6293b3e285cd0 Amir Goldstein       2023-11-22  150  		return 0;
a6293b3e285cd0 Amir Goldstein       2023-11-22  151  
a6293b3e285cd0 Amir Goldstein       2023-11-22  152  	if (iocb->ki_flags & IOCB_DIRECT &&
a6293b3e285cd0 Amir Goldstein       2023-11-22  153  	    !(file->f_mode & FMODE_CAN_ODIRECT))
a6293b3e285cd0 Amir Goldstein       2023-11-22  154  		return -EINVAL;
a6293b3e285cd0 Amir Goldstein       2023-11-22  155  
3da9951cd3bbfa Vinicius Costa Gomes 2024-01-25  156  	scoped_guard(cred, old_cred) {
a6293b3e285cd0 Amir Goldstein       2023-11-22  157  		if (is_sync_kiocb(iocb)) {
a6293b3e285cd0 Amir Goldstein       2023-11-22  158  			rwf_t rwf = iocb_to_rw_flags(flags);
a6293b3e285cd0 Amir Goldstein       2023-11-22  159  
a6293b3e285cd0 Amir Goldstein       2023-11-22  160  			ret = vfs_iter_read(file, iter, &iocb->ki_pos, rwf);
a6293b3e285cd0 Amir Goldstein       2023-11-22  161  		} else {
a6293b3e285cd0 Amir Goldstein       2023-11-22  162  			ret = -ENOMEM;
a6293b3e285cd0 Amir Goldstein       2023-11-22  163  			aio = kmem_cache_zalloc(backing_aio_cachep, GFP_KERNEL);
a6293b3e285cd0 Amir Goldstein       2023-11-22  164  			if (!aio)
a6293b3e285cd0 Amir Goldstein       2023-11-22  165  				goto out;
a6293b3e285cd0 Amir Goldstein       2023-11-22  166  
a6293b3e285cd0 Amir Goldstein       2023-11-22  167  			aio->orig_iocb = iocb;
a6293b3e285cd0 Amir Goldstein       2023-11-22  168  			kiocb_clone(&aio->iocb, iocb, get_file(file));
a6293b3e285cd0 Amir Goldstein       2023-11-22  169  			aio->iocb.ki_complete = backing_aio_rw_complete;
a6293b3e285cd0 Amir Goldstein       2023-11-22  170  			refcount_set(&aio->ref, 2);
a6293b3e285cd0 Amir Goldstein       2023-11-22  171  			ret = vfs_iocb_iter_read(file, &aio->iocb, iter);
a6293b3e285cd0 Amir Goldstein       2023-11-22  172  			backing_aio_put(aio);
a6293b3e285cd0 Amir Goldstein       2023-11-22  173  			if (ret != -EIOCBQUEUED)
a6293b3e285cd0 Amir Goldstein       2023-11-22  174  				backing_aio_cleanup(aio, ret);
a6293b3e285cd0 Amir Goldstein       2023-11-22  175  		}
3da9951cd3bbfa Vinicius Costa Gomes 2024-01-25  176  	}
a6293b3e285cd0 Amir Goldstein       2023-11-22  177  out:
a6293b3e285cd0 Amir Goldstein       2023-11-22  178  	if (ctx->accessed)
a6293b3e285cd0 Amir Goldstein       2023-11-22  179  		ctx->accessed(ctx->user_file);
a6293b3e285cd0 Amir Goldstein       2023-11-22  180  
a6293b3e285cd0 Amir Goldstein       2023-11-22 @181  	return ret;
a6293b3e285cd0 Amir Goldstein       2023-11-22  182  }
a6293b3e285cd0 Amir Goldstein       2023-11-22  183  EXPORT_SYMBOL_GPL(backing_file_read_iter);
a6293b3e285cd0 Amir Goldstein       2023-11-22  184  
a6293b3e285cd0 Amir Goldstein       2023-11-22  185  ssize_t backing_file_write_iter(struct file *file, struct iov_iter *iter,
a6293b3e285cd0 Amir Goldstein       2023-11-22  186  				struct kiocb *iocb, int flags,
a6293b3e285cd0 Amir Goldstein       2023-11-22  187  				struct backing_file_ctx *ctx)
a6293b3e285cd0 Amir Goldstein       2023-11-22  188  {
3da9951cd3bbfa Vinicius Costa Gomes 2024-01-25  189  	const struct cred *old_cred = ctx->cred;
a6293b3e285cd0 Amir Goldstein       2023-11-22  190  	ssize_t ret;
a6293b3e285cd0 Amir Goldstein       2023-11-22  191  
a6293b3e285cd0 Amir Goldstein       2023-11-22  192  	if (WARN_ON_ONCE(!(file->f_mode & FMODE_BACKING)))
a6293b3e285cd0 Amir Goldstein       2023-11-22  193  		return -EIO;
a6293b3e285cd0 Amir Goldstein       2023-11-22  194  
a6293b3e285cd0 Amir Goldstein       2023-11-22  195  	if (!iov_iter_count(iter))
a6293b3e285cd0 Amir Goldstein       2023-11-22  196  		return 0;
a6293b3e285cd0 Amir Goldstein       2023-11-22  197  
a6293b3e285cd0 Amir Goldstein       2023-11-22  198  	ret = file_remove_privs(ctx->user_file);
a6293b3e285cd0 Amir Goldstein       2023-11-22  199  	if (ret)
a6293b3e285cd0 Amir Goldstein       2023-11-22  200  		return ret;
a6293b3e285cd0 Amir Goldstein       2023-11-22  201  
a6293b3e285cd0 Amir Goldstein       2023-11-22  202  	if (iocb->ki_flags & IOCB_DIRECT &&
a6293b3e285cd0 Amir Goldstein       2023-11-22  203  	    !(file->f_mode & FMODE_CAN_ODIRECT))
a6293b3e285cd0 Amir Goldstein       2023-11-22  204  		return -EINVAL;
a6293b3e285cd0 Amir Goldstein       2023-11-22  205  
a6293b3e285cd0 Amir Goldstein       2023-11-22  206  	/*
a6293b3e285cd0 Amir Goldstein       2023-11-22  207  	 * Stacked filesystems don't support deferred completions, don't copy
a6293b3e285cd0 Amir Goldstein       2023-11-22  208  	 * this property in case it is set by the issuer.
a6293b3e285cd0 Amir Goldstein       2023-11-22  209  	 */
a6293b3e285cd0 Amir Goldstein       2023-11-22  210  	flags &= ~IOCB_DIO_CALLER_COMP;
a6293b3e285cd0 Amir Goldstein       2023-11-22  211  
3da9951cd3bbfa Vinicius Costa Gomes 2024-01-25  212  	scoped_guard(cred, old_cred) {
a6293b3e285cd0 Amir Goldstein       2023-11-22  213  		if (is_sync_kiocb(iocb)) {
a6293b3e285cd0 Amir Goldstein       2023-11-22  214  			rwf_t rwf = iocb_to_rw_flags(flags);
a6293b3e285cd0 Amir Goldstein       2023-11-22  215  
a6293b3e285cd0 Amir Goldstein       2023-11-22  216  			ret = vfs_iter_write(file, iter, &iocb->ki_pos, rwf);
a6293b3e285cd0 Amir Goldstein       2023-11-22  217  			if (ctx->end_write)
a6293b3e285cd0 Amir Goldstein       2023-11-22  218  				ctx->end_write(ctx->user_file);
a6293b3e285cd0 Amir Goldstein       2023-11-22  219  		} else {
a6293b3e285cd0 Amir Goldstein       2023-11-22  220  			struct backing_aio *aio;
a6293b3e285cd0 Amir Goldstein       2023-11-22  221  
a6293b3e285cd0 Amir Goldstein       2023-11-22  222  			ret = backing_aio_init_wq(iocb);
a6293b3e285cd0 Amir Goldstein       2023-11-22  223  			if (ret)
3da9951cd3bbfa Vinicius Costa Gomes 2024-01-25  224  				return ret;
a6293b3e285cd0 Amir Goldstein       2023-11-22  225  
a6293b3e285cd0 Amir Goldstein       2023-11-22  226  			ret = -ENOMEM;
a6293b3e285cd0 Amir Goldstein       2023-11-22  227  			aio = kmem_cache_zalloc(backing_aio_cachep, GFP_KERNEL);
a6293b3e285cd0 Amir Goldstein       2023-11-22  228  			if (!aio)
3da9951cd3bbfa Vinicius Costa Gomes 2024-01-25  229  				return ret;
a6293b3e285cd0 Amir Goldstein       2023-11-22  230  
a6293b3e285cd0 Amir Goldstein       2023-11-22  231  			aio->orig_iocb = iocb;
a6293b3e285cd0 Amir Goldstein       2023-11-22  232  			aio->end_write = ctx->end_write;
a6293b3e285cd0 Amir Goldstein       2023-11-22  233  			kiocb_clone(&aio->iocb, iocb, get_file(file));
a6293b3e285cd0 Amir Goldstein       2023-11-22  234  			aio->iocb.ki_flags = flags;
a6293b3e285cd0 Amir Goldstein       2023-11-22  235  			aio->iocb.ki_complete = backing_aio_queue_completion;
a6293b3e285cd0 Amir Goldstein       2023-11-22  236  			refcount_set(&aio->ref, 2);
a6293b3e285cd0 Amir Goldstein       2023-11-22  237  			ret = vfs_iocb_iter_write(file, &aio->iocb, iter);
a6293b3e285cd0 Amir Goldstein       2023-11-22  238  			backing_aio_put(aio);
a6293b3e285cd0 Amir Goldstein       2023-11-22  239  			if (ret != -EIOCBQUEUED)
a6293b3e285cd0 Amir Goldstein       2023-11-22  240  				backing_aio_cleanup(aio, ret);
a6293b3e285cd0 Amir Goldstein       2023-11-22  241  		}
3da9951cd3bbfa Vinicius Costa Gomes 2024-01-25  242  	}
a6293b3e285cd0 Amir Goldstein       2023-11-22  243  	return ret;
a6293b3e285cd0 Amir Goldstein       2023-11-22  244  }
a6293b3e285cd0 Amir Goldstein       2023-11-22  245  EXPORT_SYMBOL_GPL(backing_file_write_iter);
a6293b3e285cd0 Amir Goldstein       2023-11-22  246  
9b7e9e2f5d5c3d Amir Goldstein       2023-10-13  247  ssize_t backing_file_splice_read(struct file *in, loff_t *ppos,
9b7e9e2f5d5c3d Amir Goldstein       2023-10-13  248  				 struct pipe_inode_info *pipe, size_t len,
9b7e9e2f5d5c3d Amir Goldstein       2023-10-13  249  				 unsigned int flags,
9b7e9e2f5d5c3d Amir Goldstein       2023-10-13  250  				 struct backing_file_ctx *ctx)
9b7e9e2f5d5c3d Amir Goldstein       2023-10-13  251  {
3da9951cd3bbfa Vinicius Costa Gomes 2024-01-25  252  	const struct cred *old_cred = ctx->cred;
9b7e9e2f5d5c3d Amir Goldstein       2023-10-13  253  	ssize_t ret;
9b7e9e2f5d5c3d Amir Goldstein       2023-10-13  254  
9b7e9e2f5d5c3d Amir Goldstein       2023-10-13  255  	if (WARN_ON_ONCE(!(in->f_mode & FMODE_BACKING)))
9b7e9e2f5d5c3d Amir Goldstein       2023-10-13  256  		return -EIO;
9b7e9e2f5d5c3d Amir Goldstein       2023-10-13  257  
3da9951cd3bbfa Vinicius Costa Gomes 2024-01-25  258  	scoped_guard(cred, old_cred) {
9b7e9e2f5d5c3d Amir Goldstein       2023-10-13  259  		ret = vfs_splice_read(in, ppos, pipe, len, flags);
3da9951cd3bbfa Vinicius Costa Gomes 2024-01-25  260  	}
9b7e9e2f5d5c3d Amir Goldstein       2023-10-13  261  
9b7e9e2f5d5c3d Amir Goldstein       2023-10-13  262  	if (ctx->accessed)
9b7e9e2f5d5c3d Amir Goldstein       2023-10-13  263  		ctx->accessed(ctx->user_file);
9b7e9e2f5d5c3d Amir Goldstein       2023-10-13  264  
9b7e9e2f5d5c3d Amir Goldstein       2023-10-13 @265  	return ret;
9b7e9e2f5d5c3d Amir Goldstein       2023-10-13  266  }
9b7e9e2f5d5c3d Amir Goldstein       2023-10-13  267  EXPORT_SYMBOL_GPL(backing_file_splice_read);
9b7e9e2f5d5c3d Amir Goldstein       2023-10-13  268  
9b7e9e2f5d5c3d Amir Goldstein       2023-10-13  269  ssize_t backing_file_splice_write(struct pipe_inode_info *pipe,
9b7e9e2f5d5c3d Amir Goldstein       2023-10-13  270  				  struct file *out, loff_t *ppos, size_t len,
9b7e9e2f5d5c3d Amir Goldstein       2023-10-13  271  				  unsigned int flags,
9b7e9e2f5d5c3d Amir Goldstein       2023-10-13  272  				  struct backing_file_ctx *ctx)
9b7e9e2f5d5c3d Amir Goldstein       2023-10-13  273  {
3da9951cd3bbfa Vinicius Costa Gomes 2024-01-25  274  	const struct cred *old_cred = ctx->cred;
9b7e9e2f5d5c3d Amir Goldstein       2023-10-13  275  	ssize_t ret;
9b7e9e2f5d5c3d Amir Goldstein       2023-10-13  276  
9b7e9e2f5d5c3d Amir Goldstein       2023-10-13  277  	if (WARN_ON_ONCE(!(out->f_mode & FMODE_BACKING)))
9b7e9e2f5d5c3d Amir Goldstein       2023-10-13  278  		return -EIO;
9b7e9e2f5d5c3d Amir Goldstein       2023-10-13  279  
9b7e9e2f5d5c3d Amir Goldstein       2023-10-13  280  	ret = file_remove_privs(ctx->user_file);
9b7e9e2f5d5c3d Amir Goldstein       2023-10-13  281  	if (ret)
9b7e9e2f5d5c3d Amir Goldstein       2023-10-13  282  		return ret;
9b7e9e2f5d5c3d Amir Goldstein       2023-10-13  283  
3da9951cd3bbfa Vinicius Costa Gomes 2024-01-25  284  	scoped_guard(cred, old_cred) {
9b7e9e2f5d5c3d Amir Goldstein       2023-10-13  285  		file_start_write(out);
9b7e9e2f5d5c3d Amir Goldstein       2023-10-13  286  		ret = iter_file_splice_write(pipe, out, ppos, len, flags);
9b7e9e2f5d5c3d Amir Goldstein       2023-10-13  287  		file_end_write(out);
3da9951cd3bbfa Vinicius Costa Gomes 2024-01-25  288  	}
9b7e9e2f5d5c3d Amir Goldstein       2023-10-13  289  	if (ctx->end_write)
9b7e9e2f5d5c3d Amir Goldstein       2023-10-13  290  		ctx->end_write(ctx->user_file);
9b7e9e2f5d5c3d Amir Goldstein       2023-10-13  291  
9b7e9e2f5d5c3d Amir Goldstein       2023-10-13  292  	return ret;
9b7e9e2f5d5c3d Amir Goldstein       2023-10-13  293  }
9b7e9e2f5d5c3d Amir Goldstein       2023-10-13  294  EXPORT_SYMBOL_GPL(backing_file_splice_write);
9b7e9e2f5d5c3d Amir Goldstein       2023-10-13  295  
f567377e406c03 Amir Goldstein       2023-10-13  296  int backing_file_mmap(struct file *file, struct vm_area_struct *vma,
f567377e406c03 Amir Goldstein       2023-10-13  297  		      struct backing_file_ctx *ctx)
f567377e406c03 Amir Goldstein       2023-10-13  298  {
3da9951cd3bbfa Vinicius Costa Gomes 2024-01-25  299  	const struct cred *old_cred = ctx->cred;
f567377e406c03 Amir Goldstein       2023-10-13  300  	int ret;
f567377e406c03 Amir Goldstein       2023-10-13  301  
f567377e406c03 Amir Goldstein       2023-10-13  302  	if (WARN_ON_ONCE(!(file->f_mode & FMODE_BACKING)) ||
f567377e406c03 Amir Goldstein       2023-10-13  303  	    WARN_ON_ONCE(ctx->user_file != vma->vm_file))
f567377e406c03 Amir Goldstein       2023-10-13  304  		return -EIO;
f567377e406c03 Amir Goldstein       2023-10-13  305  
f567377e406c03 Amir Goldstein       2023-10-13  306  	if (!file->f_op->mmap)
f567377e406c03 Amir Goldstein       2023-10-13  307  		return -ENODEV;
f567377e406c03 Amir Goldstein       2023-10-13  308  
f567377e406c03 Amir Goldstein       2023-10-13  309  	vma_set_file(vma, file);
f567377e406c03 Amir Goldstein       2023-10-13  310  
3da9951cd3bbfa Vinicius Costa Gomes 2024-01-25  311  	scoped_guard(cred, old_cred) {
f567377e406c03 Amir Goldstein       2023-10-13  312  		ret = call_mmap(vma->vm_file, vma);
3da9951cd3bbfa Vinicius Costa Gomes 2024-01-25  313  	}
f567377e406c03 Amir Goldstein       2023-10-13  314  
f567377e406c03 Amir Goldstein       2023-10-13  315  	if (ctx->accessed)
f567377e406c03 Amir Goldstein       2023-10-13  316  		ctx->accessed(ctx->user_file);
f567377e406c03 Amir Goldstein       2023-10-13  317  
f567377e406c03 Amir Goldstein       2023-10-13 @318  	return ret;
f567377e406c03 Amir Goldstein       2023-10-13  319  }
f567377e406c03 Amir Goldstein       2023-10-13  320  EXPORT_SYMBOL_GPL(backing_file_mmap);
f567377e406c03 Amir Goldstein       2023-10-13  321  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2024-01-28 12:28 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-25 23:57 [RFC v2 0/4] overlayfs: Optimize override/revert creds Vinicius Costa Gomes
2024-01-25 23:57 ` [RFC v2 1/4] cleanup: Fix discarded const warning when defining guards Vinicius Costa Gomes
2024-01-26 14:46   ` Amir Goldstein
2024-01-25 23:57 ` [RFC v2 2/4] cred: Add a light version of override/revert_creds() Vinicius Costa Gomes
2024-01-26 14:34   ` Amir Goldstein
2024-01-27  0:16     ` Vinicius Costa Gomes
2024-01-25 23:57 ` [RFC v2 3/4] overlayfs: Optimize credentials usage Vinicius Costa Gomes
2024-01-26 17:22   ` Amir Goldstein
2024-01-27  0:34     ` Vinicius Costa Gomes
2024-01-25 23:57 ` [RFC v2 4/4] fs: Optimize credentials reference count for backing file ops Vinicius Costa Gomes
2024-01-26 14:50   ` Amir Goldstein
2024-01-27  0:25     ` Vinicius Costa Gomes
2024-01-26 11:40 ` [RFC v2 0/4] overlayfs: Optimize override/revert creds Amir Goldstein
2024-01-27  0:02   ` Vinicius Costa Gomes
  -- strict thread matches above, loose matches on Subject: below --
2024-01-28 12:27 [RFC v2 4/4] fs: Optimize credentials reference count for backing file ops kernel test robot

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.