* Re: [PATCH] btrfs: zoned: move log tree node allocation out of log_root_tree->log_mutex
@ 2021-03-24 20:10 kernel test robot
0 siblings, 0 replies; 5+ messages in thread
From: kernel test robot @ 2021-03-24 20:10 UTC (permalink / raw)
To: kbuild
[-- Attachment #1: Type: text/plain, Size: 26400 bytes --]
CC: kbuild-all(a)lists.01.org
In-Reply-To: <984c070461f31182e87d1b4f27c4565088a31b40.1616595693.git.naohiro.aota@wdc.com>
References: <984c070461f31182e87d1b4f27c4565088a31b40.1616595693.git.naohiro.aota@wdc.com>
TO: Naohiro Aota <naohiro.aota@wdc.com>
TO: linux-btrfs(a)vger.kernel.org
TO: dsterba(a)suse.com
CC: Naohiro Aota <naohiro.aota@wdc.com>
CC: Filipe Manana <fdmanana@suse.com>
CC: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Hi Naohiro,
I love your patch! Perhaps something to improve:
[auto build test WARNING on kdave/for-next]
[also build test WARNING on v5.12-rc4 next-20210324]
[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]
url: https://github.com/0day-ci/linux/commits/Naohiro-Aota/btrfs-zoned-move-log-tree-node-allocation-out-of-log_root_tree-log_mutex/20210324-222641
base: https://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux.git for-next
:::::: branch date: 6 hours ago
:::::: commit date: 6 hours ago
config: x86_64-allyesconfig (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Julia Lawall <julia.lawall@lip6.fr>
cocci warnings: (new ones prefixed by >>)
>> fs/btrfs/tree-log.c:3344:1-7: preceding lock on line 3169
vim +3344 fs/btrfs/tree-log.c
8b050d350c7846 Miao Xie 2014-02-20 3042
e02119d5a7b439 Chris Mason 2008-09-05 3043 /*
e02119d5a7b439 Chris Mason 2008-09-05 3044 * btrfs_sync_log does sends a given tree log down to the disk and
e02119d5a7b439 Chris Mason 2008-09-05 3045 * updates the super blocks to record it. When this call is done,
12fcfd22fe5bf4 Chris Mason 2009-03-24 3046 * you know that any inodes previously logged are safely on disk only
12fcfd22fe5bf4 Chris Mason 2009-03-24 3047 * if it returns 0.
12fcfd22fe5bf4 Chris Mason 2009-03-24 3048 *
12fcfd22fe5bf4 Chris Mason 2009-03-24 3049 * Any other return value means you need to call btrfs_commit_transaction.
12fcfd22fe5bf4 Chris Mason 2009-03-24 3050 * Some of the edge cases for fsyncing directories that have had unlinks
12fcfd22fe5bf4 Chris Mason 2009-03-24 3051 * or renames done in the past mean that sometimes the only safe
12fcfd22fe5bf4 Chris Mason 2009-03-24 3052 * fsync is to commit the whole FS. When btrfs_sync_log returns -EAGAIN,
12fcfd22fe5bf4 Chris Mason 2009-03-24 3053 * that has happened.
e02119d5a7b439 Chris Mason 2008-09-05 3054 */
e02119d5a7b439 Chris Mason 2008-09-05 3055 int btrfs_sync_log(struct btrfs_trans_handle *trans,
8b050d350c7846 Miao Xie 2014-02-20 3056 struct btrfs_root *root, struct btrfs_log_ctx *ctx)
e02119d5a7b439 Chris Mason 2008-09-05 3057 {
7237f1833601dc Yan Zheng 2009-01-21 3058 int index1;
7237f1833601dc Yan Zheng 2009-01-21 3059 int index2;
8cef4e160d7492 Yan, Zheng 2009-11-12 3060 int mark;
e02119d5a7b439 Chris Mason 2008-09-05 3061 int ret;
0b246afa62b0cf Jeff Mahoney 2016-06-22 3062 struct btrfs_fs_info *fs_info = root->fs_info;
e02119d5a7b439 Chris Mason 2008-09-05 3063 struct btrfs_root *log = root->log_root;
0b246afa62b0cf Jeff Mahoney 2016-06-22 3064 struct btrfs_root *log_root_tree = fs_info->log_root_tree;
4203e968947071 Josef Bacik 2019-09-30 3065 struct btrfs_root_item new_root_item;
bb14a59b619d3a Miao Xie 2014-02-20 3066 int log_transid = 0;
8b050d350c7846 Miao Xie 2014-02-20 3067 struct btrfs_log_ctx root_log_ctx;
c6adc9cc082e3c Miao Xie 2013-05-28 3068 struct blk_plug plug;
47876f7ceffa0e Filipe Manana 2020-11-25 3069 u64 log_root_start;
47876f7ceffa0e Filipe Manana 2020-11-25 3070 u64 log_root_level;
e02119d5a7b439 Chris Mason 2008-09-05 3071
7237f1833601dc Yan Zheng 2009-01-21 3072 mutex_lock(&root->log_mutex);
d1433debe7f434 Miao Xie 2014-02-20 3073 log_transid = ctx->log_transid;
d1433debe7f434 Miao Xie 2014-02-20 3074 if (root->log_transid_committed >= log_transid) {
d1433debe7f434 Miao Xie 2014-02-20 3075 mutex_unlock(&root->log_mutex);
d1433debe7f434 Miao Xie 2014-02-20 3076 return ctx->log_ret;
d1433debe7f434 Miao Xie 2014-02-20 3077 }
d1433debe7f434 Miao Xie 2014-02-20 3078
d1433debe7f434 Miao Xie 2014-02-20 3079 index1 = log_transid % 2;
7237f1833601dc Yan Zheng 2009-01-21 3080 if (atomic_read(&root->log_commit[index1])) {
60d53eb3107c8e Zhaolei 2015-08-17 3081 wait_log_commit(root, log_transid);
7237f1833601dc Yan Zheng 2009-01-21 3082 mutex_unlock(&root->log_mutex);
8b050d350c7846 Miao Xie 2014-02-20 3083 return ctx->log_ret;
e02119d5a7b439 Chris Mason 2008-09-05 3084 }
d1433debe7f434 Miao Xie 2014-02-20 3085 ASSERT(log_transid == root->log_transid);
7237f1833601dc Yan Zheng 2009-01-21 3086 atomic_set(&root->log_commit[index1], 1);
7237f1833601dc Yan Zheng 2009-01-21 3087
7237f1833601dc Yan Zheng 2009-01-21 3088 /* wait for previous tree log sync to complete */
7237f1833601dc Yan Zheng 2009-01-21 3089 if (atomic_read(&root->log_commit[(index1 + 1) % 2]))
60d53eb3107c8e Zhaolei 2015-08-17 3090 wait_log_commit(root, log_transid - 1);
48cab2e0714913 Miao Xie 2014-02-20 3091
86df7eb921a009 Yan, Zheng 2009-10-14 3092 while (1) {
2ecb79239bcd04 Miao Xie 2012-09-06 3093 int batch = atomic_read(&root->log_batch);
cd354ad613a393 Chris Mason 2011-10-20 3094 /* when we're on an ssd, just kick the log commit out */
0b246afa62b0cf Jeff Mahoney 2016-06-22 3095 if (!btrfs_test_opt(fs_info, SSD) &&
27cdeb7096b86f Miao Xie 2014-04-02 3096 test_bit(BTRFS_ROOT_MULTI_LOG_TASKS, &root->state)) {
7237f1833601dc Yan Zheng 2009-01-21 3097 mutex_unlock(&root->log_mutex);
e02119d5a7b439 Chris Mason 2008-09-05 3098 schedule_timeout_uninterruptible(1);
7237f1833601dc Yan Zheng 2009-01-21 3099 mutex_lock(&root->log_mutex);
86df7eb921a009 Yan, Zheng 2009-10-14 3100 }
60d53eb3107c8e Zhaolei 2015-08-17 3101 wait_for_writer(root);
2ecb79239bcd04 Miao Xie 2012-09-06 3102 if (batch == atomic_read(&root->log_batch))
e02119d5a7b439 Chris Mason 2008-09-05 3103 break;
e02119d5a7b439 Chris Mason 2008-09-05 3104 }
e02119d5a7b439 Chris Mason 2008-09-05 3105
12fcfd22fe5bf4 Chris Mason 2009-03-24 3106 /* bail out if we need to do a full commit */
4884b8e8ebf54e David Sterba 2019-03-20 3107 if (btrfs_need_log_full_commit(trans)) {
12fcfd22fe5bf4 Chris Mason 2009-03-24 3108 ret = -EAGAIN;
12fcfd22fe5bf4 Chris Mason 2009-03-24 3109 mutex_unlock(&root->log_mutex);
12fcfd22fe5bf4 Chris Mason 2009-03-24 3110 goto out;
12fcfd22fe5bf4 Chris Mason 2009-03-24 3111 }
12fcfd22fe5bf4 Chris Mason 2009-03-24 3112
8cef4e160d7492 Yan, Zheng 2009-11-12 3113 if (log_transid % 2 == 0)
8cef4e160d7492 Yan, Zheng 2009-11-12 3114 mark = EXTENT_DIRTY;
8cef4e160d7492 Yan, Zheng 2009-11-12 3115 else
8cef4e160d7492 Yan, Zheng 2009-11-12 3116 mark = EXTENT_NEW;
8cef4e160d7492 Yan, Zheng 2009-11-12 3117
690587d109ffe1 Chris Mason 2009-10-13 3118 /* we start IO on all the marked extents here, but we don't actually
690587d109ffe1 Chris Mason 2009-10-13 3119 * wait for them until later.
690587d109ffe1 Chris Mason 2009-10-13 3120 */
c6adc9cc082e3c Miao Xie 2013-05-28 3121 blk_start_plug(&plug);
2ff7e61e0d30ff Jeff Mahoney 2016-06-22 3122 ret = btrfs_write_marked_extents(fs_info, &log->dirty_log_pages, mark);
b528f467132713 Naohiro Aota 2021-02-05 3123 /*
b528f467132713 Naohiro Aota 2021-02-05 3124 * -EAGAIN happens when someone, e.g., a concurrent transaction
b528f467132713 Naohiro Aota 2021-02-05 3125 * commit, writes a dirty extent in this tree-log commit. This
b528f467132713 Naohiro Aota 2021-02-05 3126 * concurrent write will create a hole writing out the extents,
b528f467132713 Naohiro Aota 2021-02-05 3127 * and we cannot proceed on a zoned filesystem, requiring
b528f467132713 Naohiro Aota 2021-02-05 3128 * sequential writing. While we can bail out to a full commit
b528f467132713 Naohiro Aota 2021-02-05 3129 * here, but we can continue hoping the concurrent writing fills
b528f467132713 Naohiro Aota 2021-02-05 3130 * the hole.
b528f467132713 Naohiro Aota 2021-02-05 3131 */
b528f467132713 Naohiro Aota 2021-02-05 3132 if (ret == -EAGAIN && btrfs_is_zoned(fs_info))
b528f467132713 Naohiro Aota 2021-02-05 3133 ret = 0;
79787eaab46121 Jeff Mahoney 2012-03-12 3134 if (ret) {
c6adc9cc082e3c Miao Xie 2013-05-28 3135 blk_finish_plug(&plug);
66642832f06a43 Jeff Mahoney 2016-06-10 3136 btrfs_abort_transaction(trans, ret);
907877664e2d85 David Sterba 2019-03-20 3137 btrfs_set_log_full_commit(trans);
79787eaab46121 Jeff Mahoney 2012-03-12 3138 mutex_unlock(&root->log_mutex);
79787eaab46121 Jeff Mahoney 2012-03-12 3139 goto out;
79787eaab46121 Jeff Mahoney 2012-03-12 3140 }
7237f1833601dc Yan Zheng 2009-01-21 3141
4203e968947071 Josef Bacik 2019-09-30 3142 /*
4203e968947071 Josef Bacik 2019-09-30 3143 * We _must_ update under the root->log_mutex in order to make sure we
4203e968947071 Josef Bacik 2019-09-30 3144 * have a consistent view of the log root we are trying to commit at
4203e968947071 Josef Bacik 2019-09-30 3145 * this moment.
4203e968947071 Josef Bacik 2019-09-30 3146 *
4203e968947071 Josef Bacik 2019-09-30 3147 * We _must_ copy this into a local copy, because we are not holding the
4203e968947071 Josef Bacik 2019-09-30 3148 * log_root_tree->log_mutex yet. This is important because when we
4203e968947071 Josef Bacik 2019-09-30 3149 * commit the log_root_tree we must have a consistent view of the
4203e968947071 Josef Bacik 2019-09-30 3150 * log_root_tree when we update the super block to point at the
4203e968947071 Josef Bacik 2019-09-30 3151 * log_root_tree bytenr. If we update the log_root_tree here we'll race
4203e968947071 Josef Bacik 2019-09-30 3152 * with the commit and possibly point at the new block which we may not
4203e968947071 Josef Bacik 2019-09-30 3153 * have written out.
4203e968947071 Josef Bacik 2019-09-30 3154 */
5d4f98a28c7d33 Yan Zheng 2009-06-10 3155 btrfs_set_root_node(&log->root_item, log->node);
4203e968947071 Josef Bacik 2019-09-30 3156 memcpy(&new_root_item, &log->root_item, sizeof(new_root_item));
7237f1833601dc Yan Zheng 2009-01-21 3157
7237f1833601dc Yan Zheng 2009-01-21 3158 root->log_transid++;
7237f1833601dc Yan Zheng 2009-01-21 3159 log->log_transid = root->log_transid;
ff782e0a131c7f Josef Bacik 2009-10-08 3160 root->log_start_pid = 0;
7237f1833601dc Yan Zheng 2009-01-21 3161 /*
8cef4e160d7492 Yan, Zheng 2009-11-12 3162 * IO has been started, blocks of the log tree have WRITTEN flag set
8cef4e160d7492 Yan, Zheng 2009-11-12 3163 * in their headers. new modifications of the log will be written to
8cef4e160d7492 Yan, Zheng 2009-11-12 3164 * new positions. so it's safe to allow log writers to go in.
7237f1833601dc Yan Zheng 2009-01-21 3165 */
7237f1833601dc Yan Zheng 2009-01-21 3166 mutex_unlock(&root->log_mutex);
7237f1833601dc Yan Zheng 2009-01-21 3167
3ddebf27fcd3a9 Naohiro Aota 2021-02-04 3168 if (btrfs_is_zoned(fs_info)) {
c3b49b44155f93 Naohiro Aota 2021-03-24 @3169 mutex_lock(&fs_info->tree_root->log_mutex);
3ddebf27fcd3a9 Naohiro Aota 2021-02-04 3170 if (!log_root_tree->node) {
3ddebf27fcd3a9 Naohiro Aota 2021-02-04 3171 ret = btrfs_alloc_log_tree_node(trans, log_root_tree);
3ddebf27fcd3a9 Naohiro Aota 2021-02-04 3172 if (ret) {
c3b49b44155f93 Naohiro Aota 2021-03-24 3173 mutex_unlock(&fs_info->tree_log_mutex);
3ddebf27fcd3a9 Naohiro Aota 2021-02-04 3174 goto out;
3ddebf27fcd3a9 Naohiro Aota 2021-02-04 3175 }
3ddebf27fcd3a9 Naohiro Aota 2021-02-04 3176 }
c3b49b44155f93 Naohiro Aota 2021-03-24 3177 mutex_unlock(&fs_info->tree_root->log_mutex);
3ddebf27fcd3a9 Naohiro Aota 2021-02-04 3178 }
3ddebf27fcd3a9 Naohiro Aota 2021-02-04 3179
c3b49b44155f93 Naohiro Aota 2021-03-24 3180 btrfs_init_log_ctx(&root_log_ctx, NULL);
c3b49b44155f93 Naohiro Aota 2021-03-24 3181
c3b49b44155f93 Naohiro Aota 2021-03-24 3182 mutex_lock(&log_root_tree->log_mutex);
c3b49b44155f93 Naohiro Aota 2021-03-24 3183
e3d3b415761016 Filipe Manana 2021-03-11 3184 index2 = log_root_tree->log_transid % 2;
e3d3b415761016 Filipe Manana 2021-03-11 3185 list_add_tail(&root_log_ctx.list, &log_root_tree->log_ctxs[index2]);
e3d3b415761016 Filipe Manana 2021-03-11 3186 root_log_ctx.log_transid = log_root_tree->log_transid;
e3d3b415761016 Filipe Manana 2021-03-11 3187
4203e968947071 Josef Bacik 2019-09-30 3188 /*
4203e968947071 Josef Bacik 2019-09-30 3189 * Now we are safe to update the log_root_tree because we're under the
4203e968947071 Josef Bacik 2019-09-30 3190 * log_mutex, and we're a current writer so we're holding the commit
4203e968947071 Josef Bacik 2019-09-30 3191 * open until we drop the log_mutex.
4203e968947071 Josef Bacik 2019-09-30 3192 */
4203e968947071 Josef Bacik 2019-09-30 3193 ret = update_log_root(trans, log, &new_root_item);
4a500fd178c89b Yan, Zheng 2010-05-16 3194 if (ret) {
d1433debe7f434 Miao Xie 2014-02-20 3195 if (!list_empty(&root_log_ctx.list))
d1433debe7f434 Miao Xie 2014-02-20 3196 list_del_init(&root_log_ctx.list);
d1433debe7f434 Miao Xie 2014-02-20 3197
c6adc9cc082e3c Miao Xie 2013-05-28 3198 blk_finish_plug(&plug);
907877664e2d85 David Sterba 2019-03-20 3199 btrfs_set_log_full_commit(trans);
995946dd296177 Miao Xie 2014-04-02 3200
79787eaab46121 Jeff Mahoney 2012-03-12 3201 if (ret != -ENOSPC) {
66642832f06a43 Jeff Mahoney 2016-06-10 3202 btrfs_abort_transaction(trans, ret);
79787eaab46121 Jeff Mahoney 2012-03-12 3203 mutex_unlock(&log_root_tree->log_mutex);
79787eaab46121 Jeff Mahoney 2012-03-12 3204 goto out;
79787eaab46121 Jeff Mahoney 2012-03-12 3205 }
bf89d38febaadd Jeff Mahoney 2016-09-09 3206 btrfs_wait_tree_log_extents(log, mark);
4a500fd178c89b Yan, Zheng 2010-05-16 3207 mutex_unlock(&log_root_tree->log_mutex);
4a500fd178c89b Yan, Zheng 2010-05-16 3208 ret = -EAGAIN;
4a500fd178c89b Yan, Zheng 2010-05-16 3209 goto out;
4a500fd178c89b Yan, Zheng 2010-05-16 3210 }
4a500fd178c89b Yan, Zheng 2010-05-16 3211
d1433debe7f434 Miao Xie 2014-02-20 3212 if (log_root_tree->log_transid_committed >= root_log_ctx.log_transid) {
3da5ab56482f32 Forrest Liu 2015-01-30 3213 blk_finish_plug(&plug);
cbd60aa7cd17d8 Chris Mason 2016-09-06 3214 list_del_init(&root_log_ctx.list);
d1433debe7f434 Miao Xie 2014-02-20 3215 mutex_unlock(&log_root_tree->log_mutex);
d1433debe7f434 Miao Xie 2014-02-20 3216 ret = root_log_ctx.log_ret;
d1433debe7f434 Miao Xie 2014-02-20 3217 goto out;
d1433debe7f434 Miao Xie 2014-02-20 3218 }
8b050d350c7846 Miao Xie 2014-02-20 3219
d1433debe7f434 Miao Xie 2014-02-20 3220 index2 = root_log_ctx.log_transid % 2;
7237f1833601dc Yan Zheng 2009-01-21 3221 if (atomic_read(&log_root_tree->log_commit[index2])) {
c6adc9cc082e3c Miao Xie 2013-05-28 3222 blk_finish_plug(&plug);
bf89d38febaadd Jeff Mahoney 2016-09-09 3223 ret = btrfs_wait_tree_log_extents(log, mark);
60d53eb3107c8e Zhaolei 2015-08-17 3224 wait_log_commit(log_root_tree,
d1433debe7f434 Miao Xie 2014-02-20 3225 root_log_ctx.log_transid);
7237f1833601dc Yan Zheng 2009-01-21 3226 mutex_unlock(&log_root_tree->log_mutex);
5ab5e44a36164f Filipe Manana 2014-11-13 3227 if (!ret)
8b050d350c7846 Miao Xie 2014-02-20 3228 ret = root_log_ctx.log_ret;
7237f1833601dc Yan Zheng 2009-01-21 3229 goto out;
7237f1833601dc Yan Zheng 2009-01-21 3230 }
d1433debe7f434 Miao Xie 2014-02-20 3231 ASSERT(root_log_ctx.log_transid == log_root_tree->log_transid);
7237f1833601dc Yan Zheng 2009-01-21 3232 atomic_set(&log_root_tree->log_commit[index2], 1);
7237f1833601dc Yan Zheng 2009-01-21 3233
12fcfd22fe5bf4 Chris Mason 2009-03-24 3234 if (atomic_read(&log_root_tree->log_commit[(index2 + 1) % 2])) {
60d53eb3107c8e Zhaolei 2015-08-17 3235 wait_log_commit(log_root_tree,
d1433debe7f434 Miao Xie 2014-02-20 3236 root_log_ctx.log_transid - 1);
12fcfd22fe5bf4 Chris Mason 2009-03-24 3237 }
7237f1833601dc Yan Zheng 2009-01-21 3238
12fcfd22fe5bf4 Chris Mason 2009-03-24 3239 /*
12fcfd22fe5bf4 Chris Mason 2009-03-24 3240 * now that we've moved on to the tree of log tree roots,
12fcfd22fe5bf4 Chris Mason 2009-03-24 3241 * check the full commit flag again
12fcfd22fe5bf4 Chris Mason 2009-03-24 3242 */
4884b8e8ebf54e David Sterba 2019-03-20 3243 if (btrfs_need_log_full_commit(trans)) {
c6adc9cc082e3c Miao Xie 2013-05-28 3244 blk_finish_plug(&plug);
bf89d38febaadd Jeff Mahoney 2016-09-09 3245 btrfs_wait_tree_log_extents(log, mark);
12fcfd22fe5bf4 Chris Mason 2009-03-24 3246 mutex_unlock(&log_root_tree->log_mutex);
12fcfd22fe5bf4 Chris Mason 2009-03-24 3247 ret = -EAGAIN;
12fcfd22fe5bf4 Chris Mason 2009-03-24 3248 goto out_wake_log_root;
12fcfd22fe5bf4 Chris Mason 2009-03-24 3249 }
7237f1833601dc Yan Zheng 2009-01-21 3250
2ff7e61e0d30ff Jeff Mahoney 2016-06-22 3251 ret = btrfs_write_marked_extents(fs_info,
8cef4e160d7492 Yan, Zheng 2009-11-12 3252 &log_root_tree->dirty_log_pages,
8cef4e160d7492 Yan, Zheng 2009-11-12 3253 EXTENT_DIRTY | EXTENT_NEW);
c6adc9cc082e3c Miao Xie 2013-05-28 3254 blk_finish_plug(&plug);
b528f467132713 Naohiro Aota 2021-02-05 3255 /*
b528f467132713 Naohiro Aota 2021-02-05 3256 * As described above, -EAGAIN indicates a hole in the extents. We
b528f467132713 Naohiro Aota 2021-02-05 3257 * cannot wait for these write outs since the waiting cause a
b528f467132713 Naohiro Aota 2021-02-05 3258 * deadlock. Bail out to the full commit instead.
b528f467132713 Naohiro Aota 2021-02-05 3259 */
b528f467132713 Naohiro Aota 2021-02-05 3260 if (ret == -EAGAIN && btrfs_is_zoned(fs_info)) {
b528f467132713 Naohiro Aota 2021-02-05 3261 btrfs_set_log_full_commit(trans);
b528f467132713 Naohiro Aota 2021-02-05 3262 btrfs_wait_tree_log_extents(log, mark);
b528f467132713 Naohiro Aota 2021-02-05 3263 mutex_unlock(&log_root_tree->log_mutex);
b528f467132713 Naohiro Aota 2021-02-05 3264 goto out_wake_log_root;
b528f467132713 Naohiro Aota 2021-02-05 3265 } else if (ret) {
907877664e2d85 David Sterba 2019-03-20 3266 btrfs_set_log_full_commit(trans);
66642832f06a43 Jeff Mahoney 2016-06-10 3267 btrfs_abort_transaction(trans, ret);
79787eaab46121 Jeff Mahoney 2012-03-12 3268 mutex_unlock(&log_root_tree->log_mutex);
79787eaab46121 Jeff Mahoney 2012-03-12 3269 goto out_wake_log_root;
79787eaab46121 Jeff Mahoney 2012-03-12 3270 }
bf89d38febaadd Jeff Mahoney 2016-09-09 3271 ret = btrfs_wait_tree_log_extents(log, mark);
5ab5e44a36164f Filipe Manana 2014-11-13 3272 if (!ret)
bf89d38febaadd Jeff Mahoney 2016-09-09 3273 ret = btrfs_wait_tree_log_extents(log_root_tree,
c6adc9cc082e3c Miao Xie 2013-05-28 3274 EXTENT_NEW | EXTENT_DIRTY);
5ab5e44a36164f Filipe Manana 2014-11-13 3275 if (ret) {
907877664e2d85 David Sterba 2019-03-20 3276 btrfs_set_log_full_commit(trans);
5ab5e44a36164f Filipe Manana 2014-11-13 3277 mutex_unlock(&log_root_tree->log_mutex);
5ab5e44a36164f Filipe Manana 2014-11-13 3278 goto out_wake_log_root;
5ab5e44a36164f Filipe Manana 2014-11-13 3279 }
e02119d5a7b439 Chris Mason 2008-09-05 3280
47876f7ceffa0e Filipe Manana 2020-11-25 3281 log_root_start = log_root_tree->node->start;
47876f7ceffa0e Filipe Manana 2020-11-25 3282 log_root_level = btrfs_header_level(log_root_tree->node);
7237f1833601dc Yan Zheng 2009-01-21 3283 log_root_tree->log_transid++;
7237f1833601dc Yan Zheng 2009-01-21 3284 mutex_unlock(&log_root_tree->log_mutex);
7237f1833601dc Yan Zheng 2009-01-21 3285
7237f1833601dc Yan Zheng 2009-01-21 3286 /*
47876f7ceffa0e Filipe Manana 2020-11-25 3287 * Here we are guaranteed that nobody is going to write the superblock
47876f7ceffa0e Filipe Manana 2020-11-25 3288 * for the current transaction before us and that neither we do write
47876f7ceffa0e Filipe Manana 2020-11-25 3289 * our superblock before the previous transaction finishes its commit
47876f7ceffa0e Filipe Manana 2020-11-25 3290 * and writes its superblock, because:
47876f7ceffa0e Filipe Manana 2020-11-25 3291 *
47876f7ceffa0e Filipe Manana 2020-11-25 3292 * 1) We are holding a handle on the current transaction, so no body
47876f7ceffa0e Filipe Manana 2020-11-25 3293 * can commit it until we release the handle;
47876f7ceffa0e Filipe Manana 2020-11-25 3294 *
47876f7ceffa0e Filipe Manana 2020-11-25 3295 * 2) Before writing our superblock we acquire the tree_log_mutex, so
47876f7ceffa0e Filipe Manana 2020-11-25 3296 * if the previous transaction is still committing, and hasn't yet
47876f7ceffa0e Filipe Manana 2020-11-25 3297 * written its superblock, we wait for it to do it, because a
47876f7ceffa0e Filipe Manana 2020-11-25 3298 * transaction commit acquires the tree_log_mutex when the commit
47876f7ceffa0e Filipe Manana 2020-11-25 3299 * begins and releases it only after writing its superblock.
7237f1833601dc Yan Zheng 2009-01-21 3300 */
47876f7ceffa0e Filipe Manana 2020-11-25 3301 mutex_lock(&fs_info->tree_log_mutex);
47876f7ceffa0e Filipe Manana 2020-11-25 3302 btrfs_set_super_log_root(fs_info->super_for_commit, log_root_start);
47876f7ceffa0e Filipe Manana 2020-11-25 3303 btrfs_set_super_log_root_level(fs_info->super_for_commit, log_root_level);
eece6a9cf69140 David Sterba 2017-02-10 3304 ret = write_all_supers(fs_info, 1);
47876f7ceffa0e Filipe Manana 2020-11-25 3305 mutex_unlock(&fs_info->tree_log_mutex);
5af3e8cce8b7ba Stefan Behrens 2012-08-01 3306 if (ret) {
907877664e2d85 David Sterba 2019-03-20 3307 btrfs_set_log_full_commit(trans);
66642832f06a43 Jeff Mahoney 2016-06-10 3308 btrfs_abort_transaction(trans, ret);
5af3e8cce8b7ba Stefan Behrens 2012-08-01 3309 goto out_wake_log_root;
5af3e8cce8b7ba Stefan Behrens 2012-08-01 3310 }
7237f1833601dc Yan Zheng 2009-01-21 3311
257c62e1bce03e Chris Mason 2009-10-13 3312 mutex_lock(&root->log_mutex);
257c62e1bce03e Chris Mason 2009-10-13 3313 if (root->last_log_commit < log_transid)
257c62e1bce03e Chris Mason 2009-10-13 3314 root->last_log_commit = log_transid;
257c62e1bce03e Chris Mason 2009-10-13 3315 mutex_unlock(&root->log_mutex);
257c62e1bce03e Chris Mason 2009-10-13 3316
12fcfd22fe5bf4 Chris Mason 2009-03-24 3317 out_wake_log_root:
570dd45042a7c8 Chris Mason 2016-10-27 3318 mutex_lock(&log_root_tree->log_mutex);
8b050d350c7846 Miao Xie 2014-02-20 3319 btrfs_remove_all_log_ctxs(log_root_tree, index2, ret);
8b050d350c7846 Miao Xie 2014-02-20 3320
d1433debe7f434 Miao Xie 2014-02-20 3321 log_root_tree->log_transid_committed++;
7237f1833601dc Yan Zheng 2009-01-21 3322 atomic_set(&log_root_tree->log_commit[index2], 0);
d1433debe7f434 Miao Xie 2014-02-20 3323 mutex_unlock(&log_root_tree->log_mutex);
d1433debe7f434 Miao Xie 2014-02-20 3324
33a9eca7e4a4c2 David Sterba 2015-10-10 3325 /*
093258e6ebaf17 David Sterba 2018-02-26 3326 * The barrier before waitqueue_active (in cond_wake_up) is needed so
093258e6ebaf17 David Sterba 2018-02-26 3327 * all the updates above are seen by the woken threads. It might not be
093258e6ebaf17 David Sterba 2018-02-26 3328 * necessary, but proving that seems to be hard.
33a9eca7e4a4c2 David Sterba 2015-10-10 3329 */
093258e6ebaf17 David Sterba 2018-02-26 3330 cond_wake_up(&log_root_tree->log_commit_wait[index2]);
e02119d5a7b439 Chris Mason 2008-09-05 3331 out:
d1433debe7f434 Miao Xie 2014-02-20 3332 mutex_lock(&root->log_mutex);
570dd45042a7c8 Chris Mason 2016-10-27 3333 btrfs_remove_all_log_ctxs(root, index1, ret);
d1433debe7f434 Miao Xie 2014-02-20 3334 root->log_transid_committed++;
7237f1833601dc Yan Zheng 2009-01-21 3335 atomic_set(&root->log_commit[index1], 0);
d1433debe7f434 Miao Xie 2014-02-20 3336 mutex_unlock(&root->log_mutex);
8b050d350c7846 Miao Xie 2014-02-20 3337
33a9eca7e4a4c2 David Sterba 2015-10-10 3338 /*
093258e6ebaf17 David Sterba 2018-02-26 3339 * The barrier before waitqueue_active (in cond_wake_up) is needed so
093258e6ebaf17 David Sterba 2018-02-26 3340 * all the updates above are seen by the woken threads. It might not be
093258e6ebaf17 David Sterba 2018-02-26 3341 * necessary, but proving that seems to be hard.
33a9eca7e4a4c2 David Sterba 2015-10-10 3342 */
093258e6ebaf17 David Sterba 2018-02-26 3343 cond_wake_up(&root->log_commit_wait[index1]);
b31eabd86eb68d Chris Mason 2011-01-31 @3344 return ret;
e02119d5a7b439 Chris Mason 2008-09-05 3345 }
e02119d5a7b439 Chris Mason 2008-09-05 3346
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 65448 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] btrfs: zoned: move log tree node allocation out of log_root_tree->log_mutex
2021-03-24 14:23 Naohiro Aota
2021-03-24 14:31 ` Filipe Manana
2021-03-29 8:04 ` Johannes Thumshirn
@ 2021-03-29 18:29 ` David Sterba
2 siblings, 0 replies; 5+ messages in thread
From: David Sterba @ 2021-03-29 18:29 UTC (permalink / raw)
To: Naohiro Aota; +Cc: linux-btrfs, dsterba, Filipe Manana, Johannes Thumshirn
On Wed, Mar 24, 2021 at 11:23:11PM +0900, Naohiro Aota wrote:
> Commit 6e37d2459941 ("btrfs: zoned: fix deadlock on log sync") pointed out
> a deadlock warning and removed
> mutex_{lock,unlock}(&fs_info->tree_root->log_mutex). While it looks like it
> always cause a deadlock, we didn't see actual deadlock in fstests runs. The
> reason is log_root_tree->log_mutex != fs_info->tree_root->log_mutex, not
> taking the same lock. So, the warning was actually a false-positive.
>
> Since btrfs_alloc_log_tree_node() is protected only by
> fs_info->tree_root->log_mutex, we can (and should) move the code out of the
> lock scope of log_root_tree->log_mutex and silence the warning.
>
> Cc: Filipe Manana <fdmanana@suse.com>
> Cc: Johannes Thumshirn <johannes.thumshirn@wdc.com>
> Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
Added to misc-next, thanks.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] btrfs: zoned: move log tree node allocation out of log_root_tree->log_mutex
2021-03-24 14:23 Naohiro Aota
2021-03-24 14:31 ` Filipe Manana
@ 2021-03-29 8:04 ` Johannes Thumshirn
2021-03-29 18:29 ` David Sterba
2 siblings, 0 replies; 5+ messages in thread
From: Johannes Thumshirn @ 2021-03-29 8:04 UTC (permalink / raw)
To: Naohiro Aota, linux-btrfs, dsterba; +Cc: Filipe Manana
Looks good,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] btrfs: zoned: move log tree node allocation out of log_root_tree->log_mutex
2021-03-24 14:23 Naohiro Aota
@ 2021-03-24 14:31 ` Filipe Manana
2021-03-29 8:04 ` Johannes Thumshirn
2021-03-29 18:29 ` David Sterba
2 siblings, 0 replies; 5+ messages in thread
From: Filipe Manana @ 2021-03-24 14:31 UTC (permalink / raw)
To: Naohiro Aota; +Cc: linux-btrfs, David Sterba, Filipe Manana, Johannes Thumshirn
On Wed, Mar 24, 2021 at 2:26 PM Naohiro Aota <naohiro.aota@wdc.com> wrote:
>
> Commit 6e37d2459941 ("btrfs: zoned: fix deadlock on log sync") pointed out
> a deadlock warning and removed
> mutex_{lock,unlock}(&fs_info->tree_root->log_mutex). While it looks like it
> always cause a deadlock, we didn't see actual deadlock in fstests runs. The
> reason is log_root_tree->log_mutex != fs_info->tree_root->log_mutex, not
> taking the same lock. So, the warning was actually a false-positive.
>
> Since btrfs_alloc_log_tree_node() is protected only by
> fs_info->tree_root->log_mutex, we can (and should) move the code out of the
> lock scope of log_root_tree->log_mutex and silence the warning.
>
> Cc: Filipe Manana <fdmanana@suse.com>
> Cc: Johannes Thumshirn <johannes.thumshirn@wdc.com>
> Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
Reviewed-by: Filipe Manana <fdmanana@suse.com>
Looks good, thanks.
> ---
> fs/btrfs/tree-log.c | 12 +++++++-----
> 1 file changed, 7 insertions(+), 5 deletions(-)
>
> diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
> index 92a368627791..72c4b66ed516 100644
> --- a/fs/btrfs/tree-log.c
> +++ b/fs/btrfs/tree-log.c
> @@ -3165,20 +3165,22 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
> */
> mutex_unlock(&root->log_mutex);
>
> - btrfs_init_log_ctx(&root_log_ctx, NULL);
> -
> - mutex_lock(&log_root_tree->log_mutex);
> -
> if (btrfs_is_zoned(fs_info)) {
> + mutex_lock(&fs_info->tree_root->log_mutex);
> if (!log_root_tree->node) {
> ret = btrfs_alloc_log_tree_node(trans, log_root_tree);
> if (ret) {
> - mutex_unlock(&log_root_tree->log_mutex);
> + mutex_unlock(&fs_info->tree_log_mutex);
> goto out;
> }
> }
> + mutex_unlock(&fs_info->tree_root->log_mutex);
> }
>
> + btrfs_init_log_ctx(&root_log_ctx, NULL);
> +
> + mutex_lock(&log_root_tree->log_mutex);
> +
> index2 = log_root_tree->log_transid % 2;
> list_add_tail(&root_log_ctx.list, &log_root_tree->log_ctxs[index2]);
> root_log_ctx.log_transid = log_root_tree->log_transid;
> --
> 2.31.0
>
--
Filipe David Manana,
“Whether you think you can, or you think you can't — you're right.”
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] btrfs: zoned: move log tree node allocation out of log_root_tree->log_mutex
@ 2021-03-24 14:23 Naohiro Aota
2021-03-24 14:31 ` Filipe Manana
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Naohiro Aota @ 2021-03-24 14:23 UTC (permalink / raw)
To: linux-btrfs, dsterba; +Cc: Naohiro Aota, Filipe Manana, Johannes Thumshirn
Commit 6e37d2459941 ("btrfs: zoned: fix deadlock on log sync") pointed out
a deadlock warning and removed
mutex_{lock,unlock}(&fs_info->tree_root->log_mutex). While it looks like it
always cause a deadlock, we didn't see actual deadlock in fstests runs. The
reason is log_root_tree->log_mutex != fs_info->tree_root->log_mutex, not
taking the same lock. So, the warning was actually a false-positive.
Since btrfs_alloc_log_tree_node() is protected only by
fs_info->tree_root->log_mutex, we can (and should) move the code out of the
lock scope of log_root_tree->log_mutex and silence the warning.
Cc: Filipe Manana <fdmanana@suse.com>
Cc: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
---
fs/btrfs/tree-log.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
index 92a368627791..72c4b66ed516 100644
--- a/fs/btrfs/tree-log.c
+++ b/fs/btrfs/tree-log.c
@@ -3165,20 +3165,22 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
*/
mutex_unlock(&root->log_mutex);
- btrfs_init_log_ctx(&root_log_ctx, NULL);
-
- mutex_lock(&log_root_tree->log_mutex);
-
if (btrfs_is_zoned(fs_info)) {
+ mutex_lock(&fs_info->tree_root->log_mutex);
if (!log_root_tree->node) {
ret = btrfs_alloc_log_tree_node(trans, log_root_tree);
if (ret) {
- mutex_unlock(&log_root_tree->log_mutex);
+ mutex_unlock(&fs_info->tree_log_mutex);
goto out;
}
}
+ mutex_unlock(&fs_info->tree_root->log_mutex);
}
+ btrfs_init_log_ctx(&root_log_ctx, NULL);
+
+ mutex_lock(&log_root_tree->log_mutex);
+
index2 = log_root_tree->log_transid % 2;
list_add_tail(&root_log_ctx.list, &log_root_tree->log_ctxs[index2]);
root_log_ctx.log_transid = log_root_tree->log_transid;
--
2.31.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-03-29 18:32 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-24 20:10 [PATCH] btrfs: zoned: move log tree node allocation out of log_root_tree->log_mutex kernel test robot
-- strict thread matches above, loose matches on Subject: below --
2021-03-24 14:23 Naohiro Aota
2021-03-24 14:31 ` Filipe Manana
2021-03-29 8:04 ` Johannes Thumshirn
2021-03-29 18:29 ` David Sterba
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.