:::::: :::::: Manual check reason: "low confidence static check warning: fs/xfs/xfs_log_cil.c:1334:2: warning: Value stored to 'ticket' is never read [clang-analyzer-deadcode.DeadStores]" :::::: BCC: lkp@intel.com CC: llvm@lists.linux.dev CC: oe-kbuild-all@lists.linux.dev CC: linux-kernel@vger.kernel.org TO: Dave Chinner CC: "Darrick J. Wong" tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master head: b229b6ca5abbd63ff40c1396095b1b36b18139c3 commit: d9f68777b2515452828d97b521ff8e3517b42eb1 xfs: xlog_sync() manually adjusts grant head space date: 4 months ago :::::: branch date: 8 hours ago :::::: commit date: 4 months ago config: riscv-randconfig-c006-20221023 compiler: clang version 16.0.0 (https://github.com/llvm/llvm-project 791a7ae1ba3efd6bca96338e10ffde557ba83920) reproduce (this is a W=1 build): wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # install riscv cross compiling tool for clang build # apt-get install binutils-riscv-linux-gnu # https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=d9f68777b2515452828d97b521ff8e3517b42eb1 git remote add linus https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git git fetch --no-tags linus master git checkout d9f68777b2515452828d97b521ff8e3517b42eb1 # save the config file COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=riscv clang-analyzer If you fix the issue, kindly add following tag where applicable | Reported-by: kernel test robot clang_analyzer warnings: (new ones prefixed by >>) 64 warnings generated. block/blk-sysfs.c:32:9: warning: Call to function 'sprintf' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'sprintf_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling] return sprintf(page, "%lu\n", var); ^~~~~~~ block/blk-sysfs.c:32:9: note: Call to function 'sprintf' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'sprintf_s' in case of C11 return sprintf(page, "%lu\n", var); ^~~~~~~ block/blk-sysfs.c:177:9: warning: Call to function 'sprintf' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'sprintf_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling] return sprintf(page, "%llu\n", ^~~~~~~ block/blk-sysfs.c:177:9: note: Call to function 'sprintf' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'sprintf_s' in case of C11 return sprintf(page, "%llu\n", ^~~~~~~ block/blk-sysfs.c:183:9: warning: Call to function 'sprintf' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'sprintf_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling] return sprintf(page, "%llu\n", ^~~~~~~ block/blk-sysfs.c:183:9: note: Call to function 'sprintf' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'sprintf_s' in case of C11 return sprintf(page, "%llu\n", ^~~~~~~ block/blk-sysfs.c:222:9: warning: Call to function 'sprintf' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'sprintf_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling] return sprintf(page, "%llu\n", ^~~~~~~ block/blk-sysfs.c:222:9: note: Call to function 'sprintf' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'sprintf_s' in case of C11 return sprintf(page, "%llu\n", ^~~~~~~ block/blk-sysfs.c:236:9: warning: Call to function 'sprintf' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'sprintf_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling] return sprintf(page, "%llu\n", max_sectors << SECTOR_SHIFT); ^~~~~~~ block/blk-sysfs.c:236:9: note: Call to function 'sprintf' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'sprintf_s' in case of C11 return sprintf(page, "%llu\n", max_sectors << SECTOR_SHIFT); ^~~~~~~ block/blk-sysfs.c:313:10: warning: Call to function 'sprintf' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'sprintf_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling] return sprintf(page, "host-aware\n"); ^~~~~~~ block/blk-sysfs.c:313:10: note: Call to function 'sprintf' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'sprintf_s' in case of C11 return sprintf(page, "host-aware\n"); ^~~~~~~ block/blk-sysfs.c:315:10: warning: Call to function 'sprintf' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'sprintf_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling] return sprintf(page, "host-managed\n"); ^~~~~~~ block/blk-sysfs.c:315:10: note: Call to function 'sprintf' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'sprintf_s' in case of C11 return sprintf(page, "host-managed\n"); ^~~~~~~ block/blk-sysfs.c:317:10: warning: Call to function 'sprintf' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'sprintf_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling] return sprintf(page, "none\n"); ^~~~~~~ block/blk-sysfs.c:317:10: note: Call to function 'sprintf' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'sprintf_s' in case of C11 return sprintf(page, "none\n"); ^~~~~~~ block/blk-sysfs.c:403:9: warning: Call to function 'sprintf' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'sprintf_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling] return sprintf(page, "%d\n", val); ^~~~~~~ block/blk-sysfs.c:403:9: note: Call to function 'sprintf' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'sprintf_s' in case of C11 return sprintf(page, "%d\n", val); ^~~~~~~ block/blk-sysfs.c:445:9: warning: Call to function 'sprintf' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'sprintf_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling] return sprintf(page, "%u\n", jiffies_to_msecs(q->rq_timeout)); ^~~~~~~ block/blk-sysfs.c:445:9: note: Call to function 'sprintf' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'sprintf_s' in case of C11 return sprintf(page, "%u\n", jiffies_to_msecs(q->rq_timeout)); ^~~~~~~ block/blk-sysfs.c:468:9: warning: Call to function 'sprintf' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'sprintf_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling] return sprintf(page, "%llu\n", div_u64(wbt_get_min_lat(q), 1000)); ^~~~~~~ block/blk-sysfs.c:468:9: note: Call to function 'sprintf' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'sprintf_s' in case of C11 return sprintf(page, "%llu\n", div_u64(wbt_get_min_lat(q), 1000)); ^~~~~~~ block/blk-sysfs.c:518:10: warning: Call to function 'sprintf' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'sprintf_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling] return sprintf(page, "write back\n"); ^~~~~~~ block/blk-sysfs.c:518:10: note: Call to function 'sprintf' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'sprintf_s' in case of C11 return sprintf(page, "write back\n"); ^~~~~~~ block/blk-sysfs.c:520:9: warning: Call to function 'sprintf' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'sprintf_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling] return sprintf(page, "write through\n"); ^~~~~~~ block/blk-sysfs.c:520:9: note: Call to function 'sprintf' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'sprintf_s' in case of C11 return sprintf(page, "write through\n"); ^~~~~~~ block/blk-sysfs.c:547:9: warning: Call to function 'sprintf' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'sprintf_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling] return sprintf(page, "%u\n", test_bit(QUEUE_FLAG_FUA, &q->queue_flags)); ^~~~~~~ block/blk-sysfs.c:547:9: note: Call to function 'sprintf' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'sprintf_s' in case of C11 return sprintf(page, "%u\n", test_bit(QUEUE_FLAG_FUA, &q->queue_flags)); ^~~~~~~ Suppressed 50 warnings (50 in non-user code). Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well. 55 warnings generated. fs/xfs/xfs_log_cil.c:340:4: warning: Call to function 'memset' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'memset_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling] memset(lv, 0, xlog_cil_iovec_space(niovecs)); ^~~~~~ fs/xfs/xfs_log_cil.c:340:4: note: Call to function 'memset' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'memset_s' in case of C11 memset(lv, 0, xlog_cil_iovec_space(niovecs)); ^~~~~~ fs/xfs/xfs_log_cil.c:1048:2: warning: Call to function 'memset' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'memset_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling] memset(hdr, 0, sizeof(*hdr)); ^~~~~~ fs/xfs/xfs_log_cil.c:1048:2: note: Call to function 'memset' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'memset_s' in case of C11 memset(hdr, 0, sizeof(*hdr)); ^~~~~~ >> fs/xfs/xfs_log_cil.c:1334:2: warning: Value stored to 'ticket' is never read [clang-analyzer-deadcode.DeadStores] ticket = ctx->ticket; ^ ~~~~~~~~~~~ fs/xfs/xfs_log_cil.c:1334:2: note: Value stored to 'ticket' is never read ticket = ctx->ticket; ^ ~~~~~~~~~~~ Suppressed 52 warnings (52 in non-user code). Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well. 54 warnings generated. fs/xfs/xfs_bmap_item.c:593:2: warning: Call to function 'memcpy' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'memcpy_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling] memcpy(buip->bui_format.bui_extents, extp, count * sizeof(*extp)); ^~~~~~ fs/xfs/xfs_bmap_item.c:593:2: note: Call to function 'memcpy' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'memcpy_s' in case of C11 memcpy(buip->bui_format.bui_extents, extp, count * sizeof(*extp)); ^~~~~~ fs/xfs/xfs_bmap_item.c:628:3: warning: Call to function 'memcpy' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'memcpy_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling] memcpy(dst_bui_fmt, src_bui_fmt, len); ^~~~~~ fs/xfs/xfs_bmap_item.c:628:3: note: Call to function 'memcpy' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'memcpy_s' in case of C11 memcpy(dst_bui_fmt, src_bui_fmt, len); ^~~~~~ Suppressed 52 warnings (52 in non-user code). Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well. 31 warnings generated. Suppressed 31 warnings (31 in non-user code). Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well. 39 warnings generated. drivers/clk/clk-axi-clkgen.c:197:2: warning: Call to function 'memset' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'memset_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling] memset(params, 0x0, sizeof(*params)); ^~~~~~ drivers/clk/clk-axi-clkgen.c:197:2: note: Call to function 'memset' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'memset_s' in case of C11 memset(params, 0x0, sizeof(*params)); ^~~~~~ drivers/clk/clk-axi-clkgen.c:413:11: warning: The left operand of '&' is a garbage value [clang-analyzer-core.UndefinedBinaryOperatorResult] if (val2 & MMCM_CLKOUT_NOCOUNT) ^ drivers/clk/clk-axi-clkgen.c:441:9: note: Calling 'axi_clkgen_get_div' dout = axi_clkgen_get_div(axi_clkgen, MMCM_REG_CLKOUT0_1, ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ drivers/clk/clk-axi-clkgen.c:409:21: note: 'val2' declared without an initial value unsigned int val1, val2; ^~~~ drivers/clk/clk-axi-clkgen.c:412:2: note: Calling 'axi_clkgen_mmcm_read' axi_clkgen_mmcm_read(axi_clkgen, reg2, &val2); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ drivers/clk/clk-axi-clkgen.c:265:6: note: Assuming 'ret' is < 0 if (ret < 0) ^~~~~~~ drivers/clk/clk-axi-clkgen.c:265:2: note: Taking true branch if (ret < 0) ^ drivers/clk/clk-axi-clkgen.c:266:3: note: Returning without writing to '*val' return ret; ^ drivers/clk/clk-axi-clkgen.c:412:2: note: Returning from 'axi_clkgen_mmcm_read' axi_clkgen_mmcm_read(axi_clkgen, reg2, &val2); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ drivers/clk/clk-axi-clkgen.c:413:11: note: The left operand of '&' is a garbage value if (val2 & MMCM_CLKOUT_NOCOUNT) ~~~~ ^ drivers/clk/clk-axi-clkgen.c:418:14: warning: The left operand of '&' is a garbage value [clang-analyzer-core.UndefinedBinaryOperatorResult] div = (val1 & 0x3f) + ((val1 >> 6) & 0x3f); ^ drivers/clk/clk-axi-clkgen.c:441:9: note: Calling 'axi_clkgen_get_div' dout = axi_clkgen_get_div(axi_clkgen, MMCM_REG_CLKOUT0_1, ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ drivers/clk/clk-axi-clkgen.c:409:15: note: 'val1' declared without an initial value unsigned int val1, val2; ^~~~ drivers/clk/clk-axi-clkgen.c:413:6: note: Assuming the condition is false if (val2 & MMCM_CLKOUT_NOCOUNT) ^~~~~~~~~~~~~~~~~~~~~~~~~~ drivers/clk/clk-axi-clkgen.c:413:2: note: Taking false branch if (val2 & MMCM_CLKOUT_NOCOUNT) ^ drivers/clk/clk-axi-clkgen.c:416:2: note: Calling 'axi_clkgen_mmcm_read' axi_clkgen_mmcm_read(axi_clkgen, reg1, &val1); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ drivers/clk/clk-axi-clkgen.c:265:6: note: Assuming 'ret' is < 0 if (ret < 0) ^~~~~~~ drivers/clk/clk-axi-clkgen.c:265:2: note: Taking true branch if (ret < 0) ^ drivers/clk/clk-axi-clkgen.c:266:3: note: Returning without writing to '*val' return ret; ^ drivers/clk/clk-axi-clkgen.c:416:2: note: Returning from 'axi_clkgen_mmcm_read' axi_clkgen_mmcm_read(axi_clkgen, reg1, &val1); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ drivers/clk/clk-axi-clkgen.c:418:14: note: The left operand of '&' is a garbage value div = (val1 & 0x3f) + ((val1 >> 6) & 0x3f); ~~~~ ^ drivers/clk/clk-axi-clkgen.c:447:10: warning: The left operand of '&' is a garbage value [clang-analyzer-core.UndefinedBinaryOperatorResult] if (val & MMCM_CLK_DIV_NOCOUNT) ~~~ ^ drivers/clk/clk-axi-clkgen.c:439:2: note: 'val' declared without an initial value unsigned int val; ^~~~~~~~~~~~~~~~ drivers/clk/clk-axi-clkgen.c:446:2: note: Calling 'axi_clkgen_mmcm_read' axi_clkgen_mmcm_read(axi_clkgen, MMCM_REG_CLK_DIV, &val); vim +/ticket +1334 fs/xfs/xfs_log_cil.c 0d227466be8433 Dave Chinner 2022-05-04 1160 71e330b593905e Dave Chinner 2010-05-21 1161 /* c7cc296ddd1f6d Christoph Hellwig 2020-03-20 1162 * Push the Committed Item List to the log. c7cc296ddd1f6d Christoph Hellwig 2020-03-20 1163 * c7cc296ddd1f6d Christoph Hellwig 2020-03-20 1164 * If the current sequence is the same as xc_push_seq we need to do a flush. If c7cc296ddd1f6d Christoph Hellwig 2020-03-20 1165 * xc_push_seq is less than the current sequence, then it has already been a44f13edf0ebb4 Dave Chinner 2010-08-24 1166 * flushed and we don't need to do anything - the caller will wait for it to a44f13edf0ebb4 Dave Chinner 2010-08-24 1167 * complete if necessary. a44f13edf0ebb4 Dave Chinner 2010-08-24 1168 * c7cc296ddd1f6d Christoph Hellwig 2020-03-20 1169 * xc_push_seq is checked unlocked against the sequence number for a match. c7cc296ddd1f6d Christoph Hellwig 2020-03-20 1170 * Hence we can allow log forces to run racily and not issue pushes for the c7cc296ddd1f6d Christoph Hellwig 2020-03-20 1171 * same sequence twice. If we get a race between multiple pushes for the same c7cc296ddd1f6d Christoph Hellwig 2020-03-20 1172 * sequence they will block on the first one and then abort, hence avoiding c7cc296ddd1f6d Christoph Hellwig 2020-03-20 1173 * needless pushes. c7cc296ddd1f6d Christoph Hellwig 2020-03-20 1174 */ c7cc296ddd1f6d Christoph Hellwig 2020-03-20 1175 static void c7cc296ddd1f6d Christoph Hellwig 2020-03-20 1176 xlog_cil_push_work( c7cc296ddd1f6d Christoph Hellwig 2020-03-20 1177 struct work_struct *work) 71e330b593905e Dave Chinner 2010-05-21 1178 { 39823d0fac9416 Dave Chinner 2021-08-10 1179 struct xfs_cil_ctx *ctx = 39823d0fac9416 Dave Chinner 2021-08-10 1180 container_of(work, struct xfs_cil_ctx, push_work); 39823d0fac9416 Dave Chinner 2021-08-10 1181 struct xfs_cil *cil = ctx->cil; c7cc296ddd1f6d Christoph Hellwig 2020-03-20 1182 struct xlog *log = cil->xc_log; 71e330b593905e Dave Chinner 2010-05-21 1183 struct xfs_cil_ctx *new_ctx; d80fc2914f9125 Dave Chinner 2022-04-21 1184 int num_iovecs = 0; d80fc2914f9125 Dave Chinner 2022-04-21 1185 int num_bytes = 0; 71e330b593905e Dave Chinner 2010-05-21 1186 int error = 0; 735fbf67df56f4 Dave Chinner 2022-04-21 1187 struct xlog_cil_trans_hdr thdr; 169248536a2b28 Dave Chinner 2022-07-07 1188 struct xfs_log_vec lvhdr = {}; 0dc8f7f139f07a Dave Chinner 2021-07-27 1189 xfs_csn_t push_seq; 0020a190cf3eac Dave Chinner 2021-08-10 1190 bool push_commit_stable; 0d227466be8433 Dave Chinner 2022-05-04 1191 LIST_HEAD (whiteouts); d9f68777b25154 Dave Chinner 2022-07-07 1192 struct xlog_ticket *ticket; 71e330b593905e Dave Chinner 2010-05-21 1193 39823d0fac9416 Dave Chinner 2021-08-10 1194 new_ctx = xlog_cil_ctx_alloc(); 71e330b593905e Dave Chinner 2010-05-21 1195 new_ctx->ticket = xlog_cil_ticket_alloc(log); 71e330b593905e Dave Chinner 2010-05-21 1196 71e330b593905e Dave Chinner 2010-05-21 1197 down_write(&cil->xc_ctx_lock); 71e330b593905e Dave Chinner 2010-05-21 1198 4bb928cdb900d0 Dave Chinner 2013-08-12 1199 spin_lock(&cil->xc_push_lock); 4c2d542f2e7865 Dave Chinner 2012-04-23 1200 push_seq = cil->xc_push_seq; 4c2d542f2e7865 Dave Chinner 2012-04-23 1201 ASSERT(push_seq <= ctx->sequence); 0020a190cf3eac Dave Chinner 2021-08-10 1202 push_commit_stable = cil->xc_push_commit_stable; 0020a190cf3eac Dave Chinner 2021-08-10 1203 cil->xc_push_commit_stable = false; 71e330b593905e Dave Chinner 2010-05-21 1204 0e7ab7efe77451 Dave Chinner 2020-03-24 1205 /* 19f4e7cc819771 Dave Chinner 2021-06-18 1206 * As we are about to switch to a new, empty CIL context, we no longer 19f4e7cc819771 Dave Chinner 2021-06-18 1207 * need to throttle tasks on CIL space overruns. Wake any waiters that 19f4e7cc819771 Dave Chinner 2021-06-18 1208 * the hard push throttle may have caught so they can start committing 19f4e7cc819771 Dave Chinner 2021-06-18 1209 * to the new context. The ctx->xc_push_lock provides the serialisation 19f4e7cc819771 Dave Chinner 2021-06-18 1210 * necessary for safely using the lockless waitqueue_active() check in 19f4e7cc819771 Dave Chinner 2021-06-18 1211 * this context. 19f4e7cc819771 Dave Chinner 2021-06-18 1212 */ 19f4e7cc819771 Dave Chinner 2021-06-18 1213 if (waitqueue_active(&cil->xc_push_wait)) c7f87f3984cfa1 Dave Chinner 2020-06-16 1214 wake_up_all(&cil->xc_push_wait); 0e7ab7efe77451 Dave Chinner 2020-03-24 1215 7c8ade21212008 Dave Chinner 2022-07-07 1216 xlog_cil_push_pcp_aggregate(cil, ctx); 7c8ade21212008 Dave Chinner 2022-07-07 1217 4c2d542f2e7865 Dave Chinner 2012-04-23 1218 /* 4c2d542f2e7865 Dave Chinner 2012-04-23 1219 * Check if we've anything to push. If there is nothing, then we don't 4c2d542f2e7865 Dave Chinner 2012-04-23 1220 * move on to a new sequence number and so we have to be able to push 4c2d542f2e7865 Dave Chinner 2012-04-23 1221 * this sequence again later. 4c2d542f2e7865 Dave Chinner 2012-04-23 1222 */ 88591e7f06a42b Dave Chinner 2022-07-02 1223 if (test_bit(XLOG_CIL_EMPTY, &cil->xc_flags)) { 4c2d542f2e7865 Dave Chinner 2012-04-23 1224 cil->xc_push_seq = 0; 4bb928cdb900d0 Dave Chinner 2013-08-12 1225 spin_unlock(&cil->xc_push_lock); a44f13edf0ebb4 Dave Chinner 2010-08-24 1226 goto out_skip; 4c2d542f2e7865 Dave Chinner 2012-04-23 1227 } 4c2d542f2e7865 Dave Chinner 2012-04-23 1228 a44f13edf0ebb4 Dave Chinner 2010-08-24 1229 cf085a1b5d2214 Joe Perches 2019-11-07 1230 /* check for a previously pushed sequence */ 39823d0fac9416 Dave Chinner 2021-08-10 1231 if (push_seq < ctx->sequence) { 8af3dcd3c89aef Dave Chinner 2014-09-23 1232 spin_unlock(&cil->xc_push_lock); df806158b0f6eb Dave Chinner 2010-05-17 1233 goto out_skip; 8af3dcd3c89aef Dave Chinner 2014-09-23 1234 } 8af3dcd3c89aef Dave Chinner 2014-09-23 1235 8af3dcd3c89aef Dave Chinner 2014-09-23 1236 /* 8af3dcd3c89aef Dave Chinner 2014-09-23 1237 * We are now going to push this context, so add it to the committing 8af3dcd3c89aef Dave Chinner 2014-09-23 1238 * list before we do anything else. This ensures that anyone waiting on 8af3dcd3c89aef Dave Chinner 2014-09-23 1239 * this push can easily detect the difference between a "push in 8af3dcd3c89aef Dave Chinner 2014-09-23 1240 * progress" and "CIL is empty, nothing to do". 8af3dcd3c89aef Dave Chinner 2014-09-23 1241 * 8af3dcd3c89aef Dave Chinner 2014-09-23 1242 * IOWs, a wait loop can now check for: 8af3dcd3c89aef Dave Chinner 2014-09-23 1243 * the current sequence not being found on the committing list; 8af3dcd3c89aef Dave Chinner 2014-09-23 1244 * an empty CIL; and 8af3dcd3c89aef Dave Chinner 2014-09-23 1245 * an unchanged sequence number 8af3dcd3c89aef Dave Chinner 2014-09-23 1246 * to detect a push that had nothing to do and therefore does not need 8af3dcd3c89aef Dave Chinner 2014-09-23 1247 * waiting on. If the CIL is not empty, we get put on the committing 8af3dcd3c89aef Dave Chinner 2014-09-23 1248 * list before emptying the CIL and bumping the sequence number. Hence 8af3dcd3c89aef Dave Chinner 2014-09-23 1249 * an empty CIL and an unchanged sequence number means we jumped out 8af3dcd3c89aef Dave Chinner 2014-09-23 1250 * above after doing nothing. 8af3dcd3c89aef Dave Chinner 2014-09-23 1251 * 8af3dcd3c89aef Dave Chinner 2014-09-23 1252 * Hence the waiter will either find the commit sequence on the 8af3dcd3c89aef Dave Chinner 2014-09-23 1253 * committing list or the sequence number will be unchanged and the CIL 8af3dcd3c89aef Dave Chinner 2014-09-23 1254 * still dirty. In that latter case, the push has not yet started, and 8af3dcd3c89aef Dave Chinner 2014-09-23 1255 * so the waiter will have to continue trying to check the CIL 8af3dcd3c89aef Dave Chinner 2014-09-23 1256 * committing list until it is found. In extreme cases of delay, the 8af3dcd3c89aef Dave Chinner 2014-09-23 1257 * sequence may fully commit between the attempts the wait makes to wait 8af3dcd3c89aef Dave Chinner 2014-09-23 1258 * on the commit sequence. 8af3dcd3c89aef Dave Chinner 2014-09-23 1259 */ 8af3dcd3c89aef Dave Chinner 2014-09-23 1260 list_add(&ctx->committing, &cil->xc_committing); 8af3dcd3c89aef Dave Chinner 2014-09-23 1261 spin_unlock(&cil->xc_push_lock); df806158b0f6eb Dave Chinner 2010-05-17 1262 c0fb4765c5086c Dave Chinner 2022-07-07 1263 xlog_cil_build_lv_chain(ctx, &whiteouts, &num_iovecs, &num_bytes); 71e330b593905e Dave Chinner 2010-05-21 1264 71e330b593905e Dave Chinner 2010-05-21 1265 /* 39823d0fac9416 Dave Chinner 2021-08-10 1266 * Switch the contexts so we can drop the context lock and move out 71e330b593905e Dave Chinner 2010-05-21 1267 * of a shared context. We can't just go straight to the commit record, 71e330b593905e Dave Chinner 2010-05-21 1268 * though - we need to synchronise with previous and future commits so 71e330b593905e Dave Chinner 2010-05-21 1269 * that the commit records are correctly ordered in the log to ensure 71e330b593905e Dave Chinner 2010-05-21 1270 * that we process items during log IO completion in the correct order. 71e330b593905e Dave Chinner 2010-05-21 1271 * 71e330b593905e Dave Chinner 2010-05-21 1272 * For example, if we get an EFI in one checkpoint and the EFD in the 71e330b593905e Dave Chinner 2010-05-21 1273 * next (e.g. due to log forces), we do not want the checkpoint with 71e330b593905e Dave Chinner 2010-05-21 1274 * the EFD to be committed before the checkpoint with the EFI. Hence 71e330b593905e Dave Chinner 2010-05-21 1275 * we must strictly order the commit records of the checkpoints so 71e330b593905e Dave Chinner 2010-05-21 1276 * that: a) the checkpoint callbacks are attached to the iclogs in the 71e330b593905e Dave Chinner 2010-05-21 1277 * correct order; and b) the checkpoints are replayed in correct order 71e330b593905e Dave Chinner 2010-05-21 1278 * in log recovery. 71e330b593905e Dave Chinner 2010-05-21 1279 * 71e330b593905e Dave Chinner 2010-05-21 1280 * Hence we need to add this context to the committing context list so 71e330b593905e Dave Chinner 2010-05-21 1281 * that higher sequences will wait for us to write out a commit record 71e330b593905e Dave Chinner 2010-05-21 1282 * before they do. f876e44603ad09 Dave Chinner 2014-02-27 1283 * 5f9b4b0de8dc2f Dave Chinner 2021-06-18 1284 * xfs_log_force_seq requires us to mirror the new sequence into the cil f876e44603ad09 Dave Chinner 2014-02-27 1285 * structure atomically with the addition of this sequence to the f876e44603ad09 Dave Chinner 2014-02-27 1286 * committing list. This also ensures that we can do unlocked checks f876e44603ad09 Dave Chinner 2014-02-27 1287 * against the current sequence in log forces without risking f876e44603ad09 Dave Chinner 2014-02-27 1288 * deferencing a freed context pointer. 71e330b593905e Dave Chinner 2010-05-21 1289 */ 4bb928cdb900d0 Dave Chinner 2013-08-12 1290 spin_lock(&cil->xc_push_lock); 39823d0fac9416 Dave Chinner 2021-08-10 1291 xlog_cil_ctx_switch(cil, new_ctx); 4bb928cdb900d0 Dave Chinner 2013-08-12 1292 spin_unlock(&cil->xc_push_lock); 71e330b593905e Dave Chinner 2010-05-21 1293 up_write(&cil->xc_ctx_lock); 71e330b593905e Dave Chinner 2010-05-21 1294 4eb56069cb2835 Dave Chinner 2022-07-07 1295 /* 4eb56069cb2835 Dave Chinner 2022-07-07 1296 * Sort the log vector chain before we add the transaction headers. 4eb56069cb2835 Dave Chinner 2022-07-07 1297 * This ensures we always have the transaction headers at the start 4eb56069cb2835 Dave Chinner 2022-07-07 1298 * of the chain. 4eb56069cb2835 Dave Chinner 2022-07-07 1299 */ 4eb56069cb2835 Dave Chinner 2022-07-07 1300 list_sort(NULL, &ctx->lv_chain, xlog_cil_order_cmp); 4eb56069cb2835 Dave Chinner 2022-07-07 1301 71e330b593905e Dave Chinner 2010-05-21 1302 /* 71e330b593905e Dave Chinner 2010-05-21 1303 * Build a checkpoint transaction header and write it to the log to 71e330b593905e Dave Chinner 2010-05-21 1304 * begin the transaction. We need to account for the space used by the 71e330b593905e Dave Chinner 2010-05-21 1305 * transaction header here as it is not accounted for in xlog_write(). 169248536a2b28 Dave Chinner 2022-07-07 1306 * Add the lvhdr to the head of the lv chain we pass to xlog_write() so 169248536a2b28 Dave Chinner 2022-07-07 1307 * it gets written into the iclog first. 71e330b593905e Dave Chinner 2010-05-21 1308 */ 735fbf67df56f4 Dave Chinner 2022-04-21 1309 xlog_cil_build_trans_hdr(ctx, &thdr, &lvhdr, num_iovecs); d80fc2914f9125 Dave Chinner 2022-04-21 1310 num_bytes += lvhdr.lv_bytes; 169248536a2b28 Dave Chinner 2022-07-07 1311 list_add(&lvhdr.lv_list, &ctx->lv_chain); 71e330b593905e Dave Chinner 2010-05-21 1312 169248536a2b28 Dave Chinner 2022-07-07 1313 /* 169248536a2b28 Dave Chinner 2022-07-07 1314 * Take the lvhdr back off the lv_chain immediately after calling 169248536a2b28 Dave Chinner 2022-07-07 1315 * xlog_cil_write_chain() as it should not be passed to log IO 169248536a2b28 Dave Chinner 2022-07-07 1316 * completion. 169248536a2b28 Dave Chinner 2022-07-07 1317 */ 169248536a2b28 Dave Chinner 2022-07-07 1318 error = xlog_cil_write_chain(ctx, num_bytes); 169248536a2b28 Dave Chinner 2022-07-07 1319 list_del(&lvhdr.lv_list); bf034bc827807a Dave Chinner 2021-08-10 1320 if (error) ac983517ec5941 Dave Chinner 2014-05-07 1321 goto out_abort_free_ticket; 71e330b593905e Dave Chinner 2010-05-21 1322 caa80090d17c89 Dave Chinner 2021-08-10 1323 error = xlog_cil_write_commit_record(ctx); dd401770b0ff68 Dave Chinner 2020-03-25 1324 if (error) dd401770b0ff68 Dave Chinner 2020-03-25 1325 goto out_abort_free_ticket; dd401770b0ff68 Dave Chinner 2020-03-25 1326 d9f68777b25154 Dave Chinner 2022-07-07 1327 /* d9f68777b25154 Dave Chinner 2022-07-07 1328 * Grab the ticket from the ctx so we can ungrant it after releasing the d9f68777b25154 Dave Chinner 2022-07-07 1329 * commit_iclog. The ctx may be freed by the time we return from d9f68777b25154 Dave Chinner 2022-07-07 1330 * releasing the commit_iclog (i.e. checkpoint has been completed and d9f68777b25154 Dave Chinner 2022-07-07 1331 * callback run) so we can't reference the ctx after the call to d9f68777b25154 Dave Chinner 2022-07-07 1332 * xlog_state_release_iclog(). d9f68777b25154 Dave Chinner 2022-07-07 1333 */ d9f68777b25154 Dave Chinner 2022-07-07 @1334 ticket = ctx->ticket; 71e330b593905e Dave Chinner 2010-05-21 1335 a79b28c284fd91 Dave Chinner 2021-06-18 1336 /* 1effb72a8179a0 Dave Chinner 2021-06-25 1337 * If the checkpoint spans multiple iclogs, wait for all previous iclogs 1effb72a8179a0 Dave Chinner 2021-06-25 1338 * to complete before we submit the commit_iclog. We can't use state 1effb72a8179a0 Dave Chinner 2021-06-25 1339 * checks for this - ACTIVE can be either a past completed iclog or a 1effb72a8179a0 Dave Chinner 2021-06-25 1340 * future iclog being filled, while WANT_SYNC through SYNC_DONE can be a 1effb72a8179a0 Dave Chinner 2021-06-25 1341 * past or future iclog awaiting IO or ordered IO completion to be run. 1effb72a8179a0 Dave Chinner 2021-06-25 1342 * In the latter case, if it's a future iclog and we wait on it, the we 1effb72a8179a0 Dave Chinner 2021-06-25 1343 * will hang because it won't get processed through to ic_force_wait 1effb72a8179a0 Dave Chinner 2021-06-25 1344 * wakeup until this commit_iclog is written to disk. Hence we use the 1effb72a8179a0 Dave Chinner 2021-06-25 1345 * iclog header lsn and compare it to the commit lsn to determine if we 1effb72a8179a0 Dave Chinner 2021-06-25 1346 * need to wait on iclogs or not. a79b28c284fd91 Dave Chinner 2021-06-18 1347 */ caa80090d17c89 Dave Chinner 2021-08-10 1348 spin_lock(&log->l_icloglock); c45aba40cf5b29 Dave Chinner 2021-08-10 1349 if (ctx->start_lsn != ctx->commit_lsn) { 1effb72a8179a0 Dave Chinner 2021-06-25 1350 xfs_lsn_t plsn; 1effb72a8179a0 Dave Chinner 2021-06-25 1351 caa80090d17c89 Dave Chinner 2021-08-10 1352 plsn = be64_to_cpu(ctx->commit_iclog->ic_prev->ic_header.h_lsn); c45aba40cf5b29 Dave Chinner 2021-08-10 1353 if (plsn && XFS_LSN_CMP(plsn, ctx->commit_lsn) < 0) { 1effb72a8179a0 Dave Chinner 2021-06-25 1354 /* 1effb72a8179a0 Dave Chinner 2021-06-25 1355 * Waiting on ic_force_wait orders the completion of 1effb72a8179a0 Dave Chinner 2021-06-25 1356 * iclogs older than ic_prev. Hence we only need to wait 1effb72a8179a0 Dave Chinner 2021-06-25 1357 * on the most recent older iclog here. 1effb72a8179a0 Dave Chinner 2021-06-25 1358 */ caa80090d17c89 Dave Chinner 2021-08-10 1359 xlog_wait_on_iclog(ctx->commit_iclog->ic_prev); eef983ffeae7a1 Dave Chinner 2021-06-18 1360 spin_lock(&log->l_icloglock); 1effb72a8179a0 Dave Chinner 2021-06-25 1361 } 1effb72a8179a0 Dave Chinner 2021-06-25 1362 1effb72a8179a0 Dave Chinner 2021-06-25 1363 /* 1effb72a8179a0 Dave Chinner 2021-06-25 1364 * We need to issue a pre-flush so that the ordering for this 1effb72a8179a0 Dave Chinner 2021-06-25 1365 * checkpoint is correctly preserved down to stable storage. 1effb72a8179a0 Dave Chinner 2021-06-25 1366 */ caa80090d17c89 Dave Chinner 2021-08-10 1367 ctx->commit_iclog->ic_flags |= XLOG_ICL_NEED_FLUSH; a79b28c284fd91 Dave Chinner 2021-06-18 1368 } a79b28c284fd91 Dave Chinner 2021-06-18 1369 eef983ffeae7a1 Dave Chinner 2021-06-18 1370 /* eef983ffeae7a1 Dave Chinner 2021-06-18 1371 * The commit iclog must be written to stable storage to guarantee eef983ffeae7a1 Dave Chinner 2021-06-18 1372 * journal IO vs metadata writeback IO is correctly ordered on stable eef983ffeae7a1 Dave Chinner 2021-06-18 1373 * storage. 0020a190cf3eac Dave Chinner 2021-08-10 1374 * 0020a190cf3eac Dave Chinner 2021-08-10 1375 * If the push caller needs the commit to be immediately stable and the 0020a190cf3eac Dave Chinner 2021-08-10 1376 * commit_iclog is not yet marked as XLOG_STATE_WANT_SYNC to indicate it 0020a190cf3eac Dave Chinner 2021-08-10 1377 * will be written when released, switch it's state to WANT_SYNC right 0020a190cf3eac Dave Chinner 2021-08-10 1378 * now. eef983ffeae7a1 Dave Chinner 2021-06-18 1379 */ caa80090d17c89 Dave Chinner 2021-08-10 1380 ctx->commit_iclog->ic_flags |= XLOG_ICL_NEED_FUA; 0020a190cf3eac Dave Chinner 2021-08-10 1381 if (push_commit_stable && 0020a190cf3eac Dave Chinner 2021-08-10 1382 ctx->commit_iclog->ic_state == XLOG_STATE_ACTIVE) 0020a190cf3eac Dave Chinner 2021-08-10 1383 xlog_state_switch_iclogs(log, ctx->commit_iclog, 0); d9f68777b25154 Dave Chinner 2022-07-07 1384 ticket = ctx->ticket; d9f68777b25154 Dave Chinner 2022-07-07 1385 xlog_state_release_iclog(log, ctx->commit_iclog, ticket); 502a01fac09834 Dave Chinner 2021-08-10 1386 502a01fac09834 Dave Chinner 2021-08-10 1387 /* Not safe to reference ctx now! */ 502a01fac09834 Dave Chinner 2021-08-10 1388 eef983ffeae7a1 Dave Chinner 2021-06-18 1389 spin_unlock(&log->l_icloglock); 0d227466be8433 Dave Chinner 2022-05-04 1390 xlog_cil_cleanup_whiteouts(&whiteouts); d9f68777b25154 Dave Chinner 2022-07-07 1391 xfs_log_ticket_ungrant(log, ticket); c7cc296ddd1f6d Christoph Hellwig 2020-03-20 1392 return; 71e330b593905e Dave Chinner 2010-05-21 1393 71e330b593905e Dave Chinner 2010-05-21 1394 out_skip: 71e330b593905e Dave Chinner 2010-05-21 1395 up_write(&cil->xc_ctx_lock); 71e330b593905e Dave Chinner 2010-05-21 1396 xfs_log_ticket_put(new_ctx->ticket); 71e330b593905e Dave Chinner 2010-05-21 1397 kmem_free(new_ctx); c7cc296ddd1f6d Christoph Hellwig 2020-03-20 1398 return; 71e330b593905e Dave Chinner 2010-05-21 1399 7db37c5e6575b2 Dave Chinner 2011-01-27 1400 out_abort_free_ticket: 2039a272300b94 Dave Chinner 2021-08-10 1401 ASSERT(xlog_is_shutdown(log)); 0d227466be8433 Dave Chinner 2022-05-04 1402 xlog_cil_cleanup_whiteouts(&whiteouts); caa80090d17c89 Dave Chinner 2021-08-10 1403 if (!ctx->commit_iclog) { d9f68777b25154 Dave Chinner 2022-07-07 1404 xfs_log_ticket_ungrant(log, ctx->ticket); 12e6a0f449d585 Christoph Hellwig 2020-03-20 1405 xlog_cil_committed(ctx); caa80090d17c89 Dave Chinner 2021-08-10 1406 return; caa80090d17c89 Dave Chinner 2021-08-10 1407 } caa80090d17c89 Dave Chinner 2021-08-10 1408 spin_lock(&log->l_icloglock); d9f68777b25154 Dave Chinner 2022-07-07 1409 ticket = ctx->ticket; d9f68777b25154 Dave Chinner 2022-07-07 1410 xlog_state_release_iclog(log, ctx->commit_iclog, ticket); caa80090d17c89 Dave Chinner 2021-08-10 1411 /* Not safe to reference ctx now! */ caa80090d17c89 Dave Chinner 2021-08-10 1412 spin_unlock(&log->l_icloglock); d9f68777b25154 Dave Chinner 2022-07-07 1413 xfs_log_ticket_ungrant(log, ticket); 4c2d542f2e7865 Dave Chinner 2012-04-23 1414 } 4c2d542f2e7865 Dave Chinner 2012-04-23 1415 -- 0-DAY CI Kernel Test Service https://01.org/lkp