All of lore.kernel.org
 help / color / mirror / Atom feed
From: kernel test robot <lkp@intel.com>
To: oe-kbuild@lists.linux.dev
Cc: lkp@intel.com, Dan Carpenter <error27@gmail.com>
Subject: [linux-next:master 7224/7423] fs/btrfs/extent_io.c:1125 can_skip_one_ordered_range() error: 'folio' dereferencing possible ERR_PTR()
Date: Tue, 4 Mar 2025 02:05:40 +0800	[thread overview]
Message-ID: <202503040153.la3WrwKZ-lkp@intel.com> (raw)

BCC: lkp@intel.com
CC: oe-kbuild-all@lists.linux.dev
TO: Christian Brauner <brauner@kernel.org>

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master
head:   cd3215bbcb9d4321def93fea6cfad4d5b42b9d1d
commit: 343a7c425f5ffba8fa977602f33d5a90a771e099 [7224/7423] Merge branch 'vfs.all' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
:::::: branch date: 10 hours ago
:::::: commit date: 4 days ago
config: x86_64-randconfig-161-20250303 (https://download.01.org/0day-ci/archive/20250304/202503040153.la3WrwKZ-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.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/202503040153.la3WrwKZ-lkp@intel.com/

smatch warnings:
fs/btrfs/extent_io.c:1125 can_skip_one_ordered_range() error: 'folio' dereferencing possible ERR_PTR()

vim +/folio +1125 fs/btrfs/extent_io.c

d1310b2e0cd98e Chris Mason 2008-01-24  1074  
f47168d051203f Qu Wenruo   2025-02-12  1075  /*
f47168d051203f Qu Wenruo   2025-02-12  1076   * Check if we can skip waiting the @ordered extent covering the block
f47168d051203f Qu Wenruo   2025-02-12  1077   * at file pos @cur.
f47168d051203f Qu Wenruo   2025-02-12  1078   *
f47168d051203f Qu Wenruo   2025-02-12  1079   * Return true if we can skip to @next_ret. The caller needs to check
f47168d051203f Qu Wenruo   2025-02-12  1080   * the @next_ret value to make sure if covers the full range, before
f47168d051203f Qu Wenruo   2025-02-12  1081   * skipping the OE.
f47168d051203f Qu Wenruo   2025-02-12  1082   *
f47168d051203f Qu Wenruo   2025-02-12  1083   * Return false if we must wait for the ordered extent.
f47168d051203f Qu Wenruo   2025-02-12  1084   *
f47168d051203f Qu Wenruo   2025-02-12  1085   * @cur:	The start file offset that we have locked folio for read.
f47168d051203f Qu Wenruo   2025-02-12  1086   * @next_ret:	If we return true, this indiciates the next check start
f47168d051203f Qu Wenruo   2025-02-12  1087   *		range.
f47168d051203f Qu Wenruo   2025-02-12  1088   */
f47168d051203f Qu Wenruo   2025-02-12  1089  static bool can_skip_one_ordered_range(struct btrfs_inode *binode,
f47168d051203f Qu Wenruo   2025-02-12  1090  				       struct btrfs_ordered_extent *ordered,
f47168d051203f Qu Wenruo   2025-02-12  1091  				       u64 cur, u64 *next_ret)
f47168d051203f Qu Wenruo   2025-02-12  1092  {
f47168d051203f Qu Wenruo   2025-02-12  1093  	const struct btrfs_fs_info *fs_info = binode->root->fs_info;
f47168d051203f Qu Wenruo   2025-02-12  1094  	struct folio *folio;
f47168d051203f Qu Wenruo   2025-02-12  1095  	const u32 blocksize = fs_info->sectorsize;
f47168d051203f Qu Wenruo   2025-02-12  1096  	u64 range_len;
f47168d051203f Qu Wenruo   2025-02-12  1097  	bool ret;
f47168d051203f Qu Wenruo   2025-02-12  1098  
f47168d051203f Qu Wenruo   2025-02-12  1099  	folio = filemap_get_folio(binode->vfs_inode.i_mapping,
f47168d051203f Qu Wenruo   2025-02-12  1100  				  cur >> PAGE_SHIFT);
f47168d051203f Qu Wenruo   2025-02-12  1101  
f47168d051203f Qu Wenruo   2025-02-12  1102  	/*
f47168d051203f Qu Wenruo   2025-02-12  1103  	 * We should have locked the folio(s) for range [start, end], thus
f47168d051203f Qu Wenruo   2025-02-12  1104  	 * there must be a folio and it must be locked.
f47168d051203f Qu Wenruo   2025-02-12  1105  	 */
f47168d051203f Qu Wenruo   2025-02-12  1106  	ASSERT(!IS_ERR(folio));
f47168d051203f Qu Wenruo   2025-02-12  1107  	ASSERT(folio_test_locked(folio));
f47168d051203f Qu Wenruo   2025-02-12  1108  
f47168d051203f Qu Wenruo   2025-02-12  1109  	/*
f47168d051203f Qu Wenruo   2025-02-12  1110  	 * We several cases for the folio and OE combination:
f47168d051203f Qu Wenruo   2025-02-12  1111  	 *
f47168d051203f Qu Wenruo   2025-02-12  1112  	 * 0) Folio has no private flag
f47168d051203f Qu Wenruo   2025-02-12  1113  	 *    The OE has all its IO done but not yet finished, and folio got
f47168d051203f Qu Wenruo   2025-02-12  1114  	 *    invalidated. Or direct IO.
f47168d051203f Qu Wenruo   2025-02-12  1115  	 *
f47168d051203f Qu Wenruo   2025-02-12  1116  	 * Have to wait for the OE to finish, as it may contain the
f47168d051203f Qu Wenruo   2025-02-12  1117  	 * to-be-inserted data checksum.
f47168d051203f Qu Wenruo   2025-02-12  1118  	 * Without the data checksum inserted into csum tree, read
f47168d051203f Qu Wenruo   2025-02-12  1119  	 * will just fail with missing csum.
f47168d051203f Qu Wenruo   2025-02-12  1120  	 */
f47168d051203f Qu Wenruo   2025-02-12  1121  	if (!folio_test_private(folio)) {
f47168d051203f Qu Wenruo   2025-02-12  1122  		ret = false;
f47168d051203f Qu Wenruo   2025-02-12  1123  		goto out;
f47168d051203f Qu Wenruo   2025-02-12  1124  	}
f47168d051203f Qu Wenruo   2025-02-12 @1125  	range_len = min(folio_pos(folio) + folio_size(folio),
f47168d051203f Qu Wenruo   2025-02-12  1126  			ordered->file_offset + ordered->num_bytes) - cur;
f47168d051203f Qu Wenruo   2025-02-12  1127  
f47168d051203f Qu Wenruo   2025-02-12  1128  	/*
f47168d051203f Qu Wenruo   2025-02-12  1129  	 * 1) The first block is DIRTY.
f47168d051203f Qu Wenruo   2025-02-12  1130  	 *
f47168d051203f Qu Wenruo   2025-02-12  1131  	 * This means the OE is created by some folio before us, but writeback
f47168d051203f Qu Wenruo   2025-02-12  1132  	 * has not started.
f47168d051203f Qu Wenruo   2025-02-12  1133  	 * We can and must skip the whole OE, because it will never start until
f47168d051203f Qu Wenruo   2025-02-12  1134  	 * we finished our folio read and unlocked the folio.
f47168d051203f Qu Wenruo   2025-02-12  1135  	 */
f47168d051203f Qu Wenruo   2025-02-12  1136  	if (btrfs_folio_test_dirty(fs_info, folio, cur, blocksize)) {
f47168d051203f Qu Wenruo   2025-02-12  1137  		ret = true;
f47168d051203f Qu Wenruo   2025-02-12  1138  		/*
f47168d051203f Qu Wenruo   2025-02-12  1139  		 * At least inside the folio, all the remaining blocks should
f47168d051203f Qu Wenruo   2025-02-12  1140  		 * also be dirty.
f47168d051203f Qu Wenruo   2025-02-12  1141  		 */
f47168d051203f Qu Wenruo   2025-02-12  1142  		ASSERT(btrfs_folio_test_dirty(fs_info, folio, cur, range_len));
f47168d051203f Qu Wenruo   2025-02-12  1143  		*next_ret = ordered->file_offset + ordered->num_bytes;
f47168d051203f Qu Wenruo   2025-02-12  1144  		goto out;
f47168d051203f Qu Wenruo   2025-02-12  1145  	}
f47168d051203f Qu Wenruo   2025-02-12  1146  
f47168d051203f Qu Wenruo   2025-02-12  1147  	/*
f47168d051203f Qu Wenruo   2025-02-12  1148  	 * 2) The first block is uptodate.
f47168d051203f Qu Wenruo   2025-02-12  1149  	 *
f47168d051203f Qu Wenruo   2025-02-12  1150  	 * At least the first block can be skipped, but we are still
f47168d051203f Qu Wenruo   2025-02-12  1151  	 * not full sure. E.g. if the OE has some other folios in
f47168d051203f Qu Wenruo   2025-02-12  1152  	 * the range that can not be skipped.
f47168d051203f Qu Wenruo   2025-02-12  1153  	 * So we return true and update @next_ret to the OE/folio boundary.
f47168d051203f Qu Wenruo   2025-02-12  1154  	 */
f47168d051203f Qu Wenruo   2025-02-12  1155  	if (btrfs_folio_test_uptodate(fs_info, folio, cur, blocksize)) {
f47168d051203f Qu Wenruo   2025-02-12  1156  		u64 range_len = min(folio_pos(folio) + folio_size(folio),
f47168d051203f Qu Wenruo   2025-02-12  1157  				    ordered->file_offset + ordered->num_bytes) - cur;
f47168d051203f Qu Wenruo   2025-02-12  1158  
f47168d051203f Qu Wenruo   2025-02-12  1159  		/*
f47168d051203f Qu Wenruo   2025-02-12  1160  		 * The whole range to the OE end or folio boundary should also
f47168d051203f Qu Wenruo   2025-02-12  1161  		 * be uptodate.
f47168d051203f Qu Wenruo   2025-02-12  1162  		 */
f47168d051203f Qu Wenruo   2025-02-12  1163  		ASSERT(btrfs_folio_test_uptodate(fs_info, folio, cur, range_len));
f47168d051203f Qu Wenruo   2025-02-12  1164  		ret = true;
f47168d051203f Qu Wenruo   2025-02-12  1165  		*next_ret = cur + range_len;
f47168d051203f Qu Wenruo   2025-02-12  1166  		goto out;
f47168d051203f Qu Wenruo   2025-02-12  1167  	}
f47168d051203f Qu Wenruo   2025-02-12  1168  
f47168d051203f Qu Wenruo   2025-02-12  1169  	/*
f47168d051203f Qu Wenruo   2025-02-12  1170  	 * 3) The first block is not uptodate.
f47168d051203f Qu Wenruo   2025-02-12  1171  	 *
f47168d051203f Qu Wenruo   2025-02-12  1172  	 * This means the folio is invalidated after the OE finished, or direct IO.
f47168d051203f Qu Wenruo   2025-02-12  1173  	 * Very much the same as case 1), just with private flag set.
f47168d051203f Qu Wenruo   2025-02-12  1174  	 */
f47168d051203f Qu Wenruo   2025-02-12  1175  	ret = false;
f47168d051203f Qu Wenruo   2025-02-12  1176  out:
f47168d051203f Qu Wenruo   2025-02-12  1177  	folio_put(folio);
f47168d051203f Qu Wenruo   2025-02-12  1178  	return ret;
f47168d051203f Qu Wenruo   2025-02-12  1179  }
f47168d051203f Qu Wenruo   2025-02-12  1180  

:::::: The code at line 1125 was first introduced by commit
:::::: f47168d051203f5f9020ee51ef8c90db89008fe0 btrfs: introduce a read path dedicated extent lock helper

:::::: TO: Qu Wenruo <wqu@suse.com>
:::::: CC: David Sterba <dsterba@suse.com>

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

                 reply	other threads:[~2025-03-03 18:05 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=202503040153.la3WrwKZ-lkp@intel.com \
    --to=lkp@intel.com \
    --cc=error27@gmail.com \
    --cc=oe-kbuild@lists.linux.dev \
    /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 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.