All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH 1/2] alloc_tag: avoid current->alloc_tag manipulations when profiling is disabled
@ 2024-12-27 11:47 kernel test robot
  0 siblings, 0 replies; 8+ messages in thread
From: kernel test robot @ 2024-12-27 11:47 UTC (permalink / raw)
  To: oe-kbuild; +Cc: lkp, Dan Carpenter

BCC: lkp@intel.com
CC: oe-kbuild-all@lists.linux.dev
In-Reply-To: <20241226211639.1357704-1-surenb@google.com>
References: <20241226211639.1357704-1-surenb@google.com>
TO: Suren Baghdasaryan <surenb@google.com>

Hi Suren,

kernel test robot noticed the following build warnings:

[auto build test WARNING on 431614f1580a03c1a653340c55ea76bd12a9403f]

url:    https://github.com/intel-lab-lkp/linux/commits/Suren-Baghdasaryan/alloc_tag-skip-pgalloc_tag_swap-if-profiling-is-disabled/20241227-051744
base:   431614f1580a03c1a653340c55ea76bd12a9403f
patch link:    https://lore.kernel.org/r/20241226211639.1357704-1-surenb%40google.com
patch subject: [PATCH 1/2] alloc_tag: avoid current->alloc_tag manipulations when profiling is disabled
:::::: branch date: 14 hours ago
:::::: commit date: 14 hours ago
config: arc-randconfig-r073-20241227 (https://download.01.org/0day-ci/archive/20241227/202412271903.leG6fSFl-lkp@intel.com/config)
compiler: arc-elf-gcc (GCC) 13.2.0

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/202412271903.leG6fSFl-lkp@intel.com/

New smatch warnings:
fs/overlayfs/namei.c:658 ovl_verify_index() warn: passing zero to 'PTR_ERR'

Old smatch warnings:
fs/overlayfs/namei.c:44 ovl_check_redirect() warn: passing zero to 'PTR_ERR'
fs/overlayfs/namei.c:479 ovl_check_origin() warn: passing zero to 'PTR_ERR'
fs/overlayfs/namei.c:581 ovl_index_upper() warn: passing zero to 'ERR_CAST'

vim +/PTR_ERR +658 fs/overlayfs/namei.c

e8f9e5b780b040 Amir Goldstein   2018-01-11  598  
415543d5c64fe4 Amir Goldstein   2017-06-21  599  /*
415543d5c64fe4 Amir Goldstein   2017-06-21  600   * Verify that an index entry name matches the origin file handle stored in
415543d5c64fe4 Amir Goldstein   2017-06-21  601   * OVL_XATTR_ORIGIN and that origin file handle can be decoded to lower path.
415543d5c64fe4 Amir Goldstein   2017-06-21  602   * Return 0 on match, -ESTALE on mismatch or stale origin, < 0 on error.
415543d5c64fe4 Amir Goldstein   2017-06-21  603   */
1eff1a1deec727 Amir Goldstein   2017-12-12  604  int ovl_verify_index(struct ovl_fs *ofs, struct dentry *index)
415543d5c64fe4 Amir Goldstein   2017-06-21  605  {
415543d5c64fe4 Amir Goldstein   2017-06-21  606  	struct ovl_fh *fh = NULL;
415543d5c64fe4 Amir Goldstein   2017-06-21  607  	size_t len;
b93436320c1e90 Chandan Rajendra 2017-07-24  608  	struct ovl_path origin = { };
b93436320c1e90 Chandan Rajendra 2017-07-24  609  	struct ovl_path *stack = &origin;
e8f9e5b780b040 Amir Goldstein   2018-01-11  610  	struct dentry *upper = NULL;
415543d5c64fe4 Amir Goldstein   2017-06-21  611  	int err;
415543d5c64fe4 Amir Goldstein   2017-06-21  612  
415543d5c64fe4 Amir Goldstein   2017-06-21  613  	if (!d_inode(index))
415543d5c64fe4 Amir Goldstein   2017-06-21  614  		return 0;
415543d5c64fe4 Amir Goldstein   2017-06-21  615  
fa0096e3bad69e Amir Goldstein   2017-10-24  616  	err = -EINVAL;
cbe7fba8edfc8c Amir Goldstein   2019-11-15  617  	if (index->d_name.len < sizeof(struct ovl_fb)*2)
415543d5c64fe4 Amir Goldstein   2017-06-21  618  		goto fail;
415543d5c64fe4 Amir Goldstein   2017-06-21  619  
415543d5c64fe4 Amir Goldstein   2017-06-21  620  	err = -ENOMEM;
415543d5c64fe4 Amir Goldstein   2017-06-21  621  	len = index->d_name.len / 2;
cbe7fba8edfc8c Amir Goldstein   2019-11-15  622  	fh = kzalloc(len + OVL_FH_WIRE_OFFSET, GFP_KERNEL);
415543d5c64fe4 Amir Goldstein   2017-06-21  623  	if (!fh)
415543d5c64fe4 Amir Goldstein   2017-06-21  624  		goto fail;
415543d5c64fe4 Amir Goldstein   2017-06-21  625  
415543d5c64fe4 Amir Goldstein   2017-06-21  626  	err = -EINVAL;
cbe7fba8edfc8c Amir Goldstein   2019-11-15  627  	if (hex2bin(fh->buf, index->d_name.name, len))
2e1a532883cf77 Amir Goldstein   2017-10-24  628  		goto fail;
2e1a532883cf77 Amir Goldstein   2017-10-24  629  
cbe7fba8edfc8c Amir Goldstein   2019-11-15  630  	err = ovl_check_fb_len(&fh->fb, len);
2e1a532883cf77 Amir Goldstein   2017-10-24  631  	if (err)
415543d5c64fe4 Amir Goldstein   2017-06-21  632  		goto fail;
415543d5c64fe4 Amir Goldstein   2017-06-21  633  
7db25d36d9253c Amir Goldstein   2018-01-11  634  	/*
7db25d36d9253c Amir Goldstein   2018-01-11  635  	 * Whiteout index entries are used as an indication that an exported
7db25d36d9253c Amir Goldstein   2018-01-11  636  	 * overlay file handle should be treated as stale (i.e. after unlink
7db25d36d9253c Amir Goldstein   2018-01-11  637  	 * of the overlay inode). These entries contain no origin xattr.
7db25d36d9253c Amir Goldstein   2018-01-11  638  	 */
7db25d36d9253c Amir Goldstein   2018-01-11  639  	if (ovl_is_whiteout(index))
7db25d36d9253c Amir Goldstein   2018-01-11  640  		goto out;
7db25d36d9253c Amir Goldstein   2018-01-11  641  
e8f9e5b780b040 Amir Goldstein   2018-01-11  642  	/*
e8f9e5b780b040 Amir Goldstein   2018-01-11  643  	 * Verifying directory index entries are not stale is expensive, so
e8f9e5b780b040 Amir Goldstein   2018-01-11  644  	 * only verify stale dir index if NFS export is enabled.
e8f9e5b780b040 Amir Goldstein   2018-01-11  645  	 */
e8f9e5b780b040 Amir Goldstein   2018-01-11  646  	if (d_is_dir(index) && !ofs->config.nfs_export)
e8f9e5b780b040 Amir Goldstein   2018-01-11  647  		goto out;
e8f9e5b780b040 Amir Goldstein   2018-01-11  648  
e8f9e5b780b040 Amir Goldstein   2018-01-11  649  	/*
e8f9e5b780b040 Amir Goldstein   2018-01-11  650  	 * Directory index entries should have 'upper' xattr pointing to the
e8f9e5b780b040 Amir Goldstein   2018-01-11  651  	 * real upper dir. Non-dir index entries are hardlinks to the upper
e8f9e5b780b040 Amir Goldstein   2018-01-11  652  	 * real inode. For non-dir index, we can read the copy up origin xattr
e8f9e5b780b040 Amir Goldstein   2018-01-11  653  	 * directly from the index dentry, but for dir index we first need to
e8f9e5b780b040 Amir Goldstein   2018-01-11  654  	 * decode the upper directory.
e8f9e5b780b040 Amir Goldstein   2018-01-11  655  	 */
8ea2876577b578 Amir Goldstein   2022-10-04  656  	upper = ovl_index_upper(ofs, index, false);
e8f9e5b780b040 Amir Goldstein   2018-01-11  657  	if (IS_ERR_OR_NULL(upper)) {
e8f9e5b780b040 Amir Goldstein   2018-01-11 @658  		err = PTR_ERR(upper);
24f0b17203691d Amir Goldstein   2018-01-11  659  		/*
24f0b17203691d Amir Goldstein   2018-01-11  660  		 * Directory index entries with no 'upper' xattr need to be
24f0b17203691d Amir Goldstein   2018-01-11  661  		 * removed. When dir index entry has a stale 'upper' xattr,
24f0b17203691d Amir Goldstein   2018-01-11  662  		 * we assume that upper dir was removed and we treat the dir
24f0b17203691d Amir Goldstein   2018-01-11  663  		 * index as orphan entry that needs to be whited out.
24f0b17203691d Amir Goldstein   2018-01-11  664  		 */
24f0b17203691d Amir Goldstein   2018-01-11  665  		if (err == -ESTALE)
24f0b17203691d Amir Goldstein   2018-01-11  666  			goto orphan;
24f0b17203691d Amir Goldstein   2018-01-11  667  		else if (!err)
e8f9e5b780b040 Amir Goldstein   2018-01-11  668  			err = -ESTALE;
e8f9e5b780b040 Amir Goldstein   2018-01-11  669  		goto fail;
e8f9e5b780b040 Amir Goldstein   2018-01-11  670  	}
e8f9e5b780b040 Amir Goldstein   2018-01-11  671  
610afc0bd40882 Miklos Szeredi   2020-09-02  672  	err = ovl_verify_fh(ofs, upper, OVL_XATTR_ORIGIN, fh);
e8f9e5b780b040 Amir Goldstein   2018-01-11  673  	dput(upper);
415543d5c64fe4 Amir Goldstein   2017-06-21  674  	if (err)
415543d5c64fe4 Amir Goldstein   2017-06-21  675  		goto fail;
415543d5c64fe4 Amir Goldstein   2017-06-21  676  
e8f9e5b780b040 Amir Goldstein   2018-01-11  677  	/* Check if non-dir index is orphan and don't warn before cleaning it */
e8f9e5b780b040 Amir Goldstein   2018-01-11  678  	if (!d_is_dir(index) && d_inode(index)->i_nlink == 1) {
8a22efa15b46d5 Amir Goldstein   2018-03-09  679  		err = ovl_check_origin_fh(ofs, fh, false, index, &stack);
415543d5c64fe4 Amir Goldstein   2017-06-21  680  		if (err)
415543d5c64fe4 Amir Goldstein   2017-06-21  681  			goto fail;
415543d5c64fe4 Amir Goldstein   2017-06-21  682  
610afc0bd40882 Miklos Szeredi   2020-09-02  683  		if (ovl_get_nlink(ofs, origin.dentry, index, 0) == 0)
24f0b17203691d Amir Goldstein   2018-01-11  684  			goto orphan;
e8f9e5b780b040 Amir Goldstein   2018-01-11  685  	}
caf70cb2ba5dff Amir Goldstein   2017-06-21  686  
415543d5c64fe4 Amir Goldstein   2017-06-21  687  out:
e8f9e5b780b040 Amir Goldstein   2018-01-11  688  	dput(origin.dentry);
415543d5c64fe4 Amir Goldstein   2017-06-21  689  	kfree(fh);
415543d5c64fe4 Amir Goldstein   2017-06-21  690  	return err;
415543d5c64fe4 Amir Goldstein   2017-06-21  691  
415543d5c64fe4 Amir Goldstein   2017-06-21  692  fail:
1bd0a3aea4357e lijiazi          2019-12-16  693  	pr_warn_ratelimited("failed to verify index (%pd2, ftype=%x, err=%i)\n",
61b674710cd9af Amir Goldstein   2017-07-18  694  			    index, d_inode(index)->i_mode & S_IFMT, err);
415543d5c64fe4 Amir Goldstein   2017-06-21  695  	goto out;
24f0b17203691d Amir Goldstein   2018-01-11  696  
24f0b17203691d Amir Goldstein   2018-01-11  697  orphan:
1bd0a3aea4357e lijiazi          2019-12-16  698  	pr_warn_ratelimited("orphan index entry (%pd2, ftype=%x, nlink=%u)\n",
24f0b17203691d Amir Goldstein   2018-01-11  699  			    index, d_inode(index)->i_mode & S_IFMT,
24f0b17203691d Amir Goldstein   2018-01-11  700  			    d_inode(index)->i_nlink);
24f0b17203691d Amir Goldstein   2018-01-11  701  	err = -ENOENT;
24f0b17203691d Amir Goldstein   2018-01-11  702  	goto out;
415543d5c64fe4 Amir Goldstein   2017-06-21  703  }
415543d5c64fe4 Amir Goldstein   2017-06-21  704  

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

^ permalink raw reply	[flat|nested] 8+ messages in thread
* [PATCH 1/2] alloc_tag: avoid current->alloc_tag manipulations when profiling is disabled
@ 2024-12-26 21:16 Suren Baghdasaryan
  2024-12-27  0:43 ` Kent Overstreet
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Suren Baghdasaryan @ 2024-12-26 21:16 UTC (permalink / raw)
  To: akpm
  Cc: kent.overstreet, yuzhao, 00107082, quic_zhenhuah, linux-mm,
	linux-kernel, Suren Baghdasaryan, stable

When memory allocation profiling is disabled there is no need to update
current->alloc_tag and these manipulations add unnecessary overhead. Fix
the overhead by skipping these extra updates.

Fixes: b951aaff5035 ("mm: enable page allocation tagging")
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Cc: stable@vger.kernel.org
---
 include/linux/alloc_tag.h | 11 ++++++++---
 lib/alloc_tag.c           |  2 ++
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/include/linux/alloc_tag.h b/include/linux/alloc_tag.h
index 0bbbe537c5f9..a946e0203e6d 100644
--- a/include/linux/alloc_tag.h
+++ b/include/linux/alloc_tag.h
@@ -224,9 +224,14 @@ static inline void alloc_tag_sub(union codetag_ref *ref, size_t bytes) {}
 
 #define alloc_hooks_tag(_tag, _do_alloc)				\
 ({									\
-	struct alloc_tag * __maybe_unused _old = alloc_tag_save(_tag);	\
-	typeof(_do_alloc) _res = _do_alloc;				\
-	alloc_tag_restore(_tag, _old);					\
+	typeof(_do_alloc) _res;						\
+	if (mem_alloc_profiling_enabled()) {				\
+		struct alloc_tag * __maybe_unused _old;			\
+		_old = alloc_tag_save(_tag);				\
+		_res = _do_alloc;					\
+		alloc_tag_restore(_tag, _old);				\
+	} else								\
+		_res = _do_alloc;					\
 	_res;								\
 })
 
diff --git a/lib/alloc_tag.c b/lib/alloc_tag.c
index 7dcebf118a3e..4c373f444eb1 100644
--- a/lib/alloc_tag.c
+++ b/lib/alloc_tag.c
@@ -29,6 +29,8 @@ EXPORT_SYMBOL(_shared_alloc_tag);
 
 DEFINE_STATIC_KEY_MAYBE(CONFIG_MEM_ALLOC_PROFILING_ENABLED_BY_DEFAULT,
 			mem_alloc_profiling_key);
+EXPORT_SYMBOL(mem_alloc_profiling_key);
+
 DEFINE_STATIC_KEY_FALSE(mem_profiling_compressed);
 
 struct alloc_tag_kernel_section kernel_tags = { NULL, 0 };

base-commit: 431614f1580a03c1a653340c55ea76bd12a9403f
-- 
2.47.1.613.gc27f4b7a9f-goog


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

end of thread, other threads:[~2024-12-27 14:40 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-27 11:47 [PATCH 1/2] alloc_tag: avoid current->alloc_tag manipulations when profiling is disabled kernel test robot
  -- strict thread matches above, loose matches on Subject: below --
2024-12-26 21:16 Suren Baghdasaryan
2024-12-27  0:43 ` Kent Overstreet
2024-12-27  1:07   ` Suren Baghdasaryan
2024-12-27  1:09     ` Suren Baghdasaryan
2024-12-27  1:46       ` Suren Baghdasaryan
2024-12-27 14:17 ` kernel test robot
2024-12-27 14:39 ` 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.