<feed xmlns='http://www.w3.org/2005/Atom'>
<title>linux-toradex.git/fs/btrfs, branch v4.3.2</title>
<subtitle>Linux kernel for Apalis and Colibri modules</subtitle>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/'/>
<entry>
<title>Merge branch 'for-linus-4.3' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs</title>
<updated>2015-10-23T22:17:58+00:00</updated>
<author>
<name>Linus Torvalds</name>
<email>torvalds@linux-foundation.org</email>
</author>
<published>2015-10-23T22:17:58+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=37902bc190f1396a8c232783b29ddfcaa4026028'/>
<id>37902bc190f1396a8c232783b29ddfcaa4026028</id>
<content type='text'>
Pull btrfs fixes from Chris Mason:
 "I have two more small fixes this week:

  Qu's fix avoids unneeded COW during fallocate, and Christian found a
  memory leak in the error handling of an earlier fix"

* 'for-linus-4.3' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs:
  btrfs: fix possible leak in btrfs_ioctl_balance()
  btrfs: Avoid truncate tailing page if fallocate range doesn't exceed inode size
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Pull btrfs fixes from Chris Mason:
 "I have two more small fixes this week:

  Qu's fix avoids unneeded COW during fallocate, and Christian found a
  memory leak in the error handling of an earlier fix"

* 'for-linus-4.3' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs:
  btrfs: fix possible leak in btrfs_ioctl_balance()
  btrfs: Avoid truncate tailing page if fallocate range doesn't exceed inode size
</pre>
</div>
</content>
</entry>
<entry>
<title>btrfs: fix possible leak in btrfs_ioctl_balance()</title>
<updated>2015-10-22T01:10:02+00:00</updated>
<author>
<name>Christian Engelmayer</name>
<email>cengelma@gmx.at</email>
</author>
<published>2015-10-20T22:50:06+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=0f89abf56abbd0e1c6e3cef9813e6d9f05383c1e'/>
<id>0f89abf56abbd0e1c6e3cef9813e6d9f05383c1e</id>
<content type='text'>
Commit 8eb934591f8b ("btrfs: check unsupported filters in balance
arguments") adds a jump to exit label out_bargs in case the argument
check fails. At this point in addition to the bargs memory, the
memory for struct btrfs_balance_control has already been allocated.
Ownership of bctl is passed to btrfs_balance() in the good case,
thus the memory is not freed due to the introduced jump. Make sure
that the memory gets freed in any case as necessary. Detected by
Coverity CID 1328378.

Signed-off-by: Christian Engelmayer &lt;cengelma@gmx.at&gt;
Reviewed-by: David Sterba &lt;dsterba@suse.com&gt;
Signed-off-by: Chris Mason &lt;clm@fb.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Commit 8eb934591f8b ("btrfs: check unsupported filters in balance
arguments") adds a jump to exit label out_bargs in case the argument
check fails. At this point in addition to the bargs memory, the
memory for struct btrfs_balance_control has already been allocated.
Ownership of bctl is passed to btrfs_balance() in the good case,
thus the memory is not freed due to the introduced jump. Make sure
that the memory gets freed in any case as necessary. Detected by
Coverity CID 1328378.

Signed-off-by: Christian Engelmayer &lt;cengelma@gmx.at&gt;
Reviewed-by: David Sterba &lt;dsterba@suse.com&gt;
Signed-off-by: Chris Mason &lt;clm@fb.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>btrfs: Avoid truncate tailing page if fallocate range doesn't exceed inode size</title>
<updated>2015-10-21T02:07:29+00:00</updated>
<author>
<name>Qu Wenruo</name>
<email>quwenruo@cn.fujitsu.com</email>
</author>
<published>2015-10-14T07:26:13+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=0f6925fa2907df58496cabc33fa4677c635e2223'/>
<id>0f6925fa2907df58496cabc33fa4677c635e2223</id>
<content type='text'>
Current code will always truncate tailing page if its alloc_start is
smaller than inode size.

For example, the file extent layout is like:
0	4K	8K	16K	32K
|&lt;-----Extent A----------------&gt;|
|&lt;--Inode size: 18K----------&gt;|

But if calling fallocate even for range [0,4K), it will cause btrfs to
re-truncate the range [16,32K), causing COW and a new extent.

0	4K	8K	16K	32K
|///////|	&lt;- Fallocate call range
|&lt;-----Extent A--------&gt;|&lt;--B--&gt;|

The cause is quite easy, just a careless btrfs_truncate_inode() in a
else branch without extra judgment.
Fix it by add judgment on whether the fallocate range is beyond isize.

Signed-off-by: Qu Wenruo &lt;quwenruo@cn.fujitsu.com&gt;
Signed-off-by: Chris Mason &lt;clm@fb.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Current code will always truncate tailing page if its alloc_start is
smaller than inode size.

For example, the file extent layout is like:
0	4K	8K	16K	32K
|&lt;-----Extent A----------------&gt;|
|&lt;--Inode size: 18K----------&gt;|

But if calling fallocate even for range [0,4K), it will cause btrfs to
re-truncate the range [16,32K), causing COW and a new extent.

0	4K	8K	16K	32K
|///////|	&lt;- Fallocate call range
|&lt;-----Extent A--------&gt;|&lt;--B--&gt;|

The cause is quite easy, just a careless btrfs_truncate_inode() in a
else branch without extra judgment.
Fix it by add judgment on whether the fallocate range is beyond isize.

Signed-off-by: Qu Wenruo &lt;quwenruo@cn.fujitsu.com&gt;
Signed-off-by: Chris Mason &lt;clm@fb.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>Merge branch 'for-linus-4.3' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs</title>
<updated>2015-10-16T19:55:34+00:00</updated>
<author>
<name>Linus Torvalds</name>
<email>torvalds@linux-foundation.org</email>
</author>
<published>2015-10-16T19:55:34+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=6aa8ca4df0c1e2095c3f9f6fc28d85a991787879'/>
<id>6aa8ca4df0c1e2095c3f9f6fc28d85a991787879</id>
<content type='text'>
Pull btrfs fixes from Chris Mason:
 "I have two more bug fixes for btrfs.

  My commit fixes a bug we hit last week at FB, a combination of lots of
  hard links and an admin command to resolve inode numbers.

  Dave is adding checks to make sure balance on current kernels ignores
  filters it doesn't understand.  The penalty for being wrong is just
  doing more work (not crashing etc), but it's a good fix"

* 'for-linus-4.3' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs:
  btrfs: fix use after free iterating extrefs
  btrfs: check unsupported filters in balance arguments
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Pull btrfs fixes from Chris Mason:
 "I have two more bug fixes for btrfs.

  My commit fixes a bug we hit last week at FB, a combination of lots of
  hard links and an admin command to resolve inode numbers.

  Dave is adding checks to make sure balance on current kernels ignores
  filters it doesn't understand.  The penalty for being wrong is just
  doing more work (not crashing etc), but it's a good fix"

* 'for-linus-4.3' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs:
  btrfs: fix use after free iterating extrefs
  btrfs: check unsupported filters in balance arguments
</pre>
</div>
</content>
</entry>
<entry>
<title>btrfs: fix use after free iterating extrefs</title>
<updated>2015-10-14T01:54:44+00:00</updated>
<author>
<name>Chris Mason</name>
<email>clm@fb.com</email>
</author>
<published>2015-10-13T18:06:48+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=dc6c5fb3b514221f2e9d21ee626a9d95d3418dff'/>
<id>dc6c5fb3b514221f2e9d21ee626a9d95d3418dff</id>
<content type='text'>
The code for btrfs inode-resolve has never worked properly for
files with enough hard links to trigger extrefs.  It was trying to
get the leaf out of a path after freeing the path:

	btrfs_release_path(path);
	leaf = path-&gt;nodes[0];
	item_size = btrfs_item_size_nr(leaf, slot);

The fix here is to use the extent buffer we cloned just a little higher
up to avoid deadlocks caused by using the leaf in the path.

Signed-off-by: Chris Mason &lt;clm@fb.com&gt;
cc: stable@vger.kernel.org # v3.7+
cc: Mark Fasheh &lt;mfasheh@suse.de&gt;
Reviewed-by: Filipe Manana &lt;fdmanana@suse.com&gt;
Reviewed-by: Mark Fasheh &lt;mfasheh@suse.de&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
The code for btrfs inode-resolve has never worked properly for
files with enough hard links to trigger extrefs.  It was trying to
get the leaf out of a path after freeing the path:

	btrfs_release_path(path);
	leaf = path-&gt;nodes[0];
	item_size = btrfs_item_size_nr(leaf, slot);

The fix here is to use the extent buffer we cloned just a little higher
up to avoid deadlocks caused by using the leaf in the path.

Signed-off-by: Chris Mason &lt;clm@fb.com&gt;
cc: stable@vger.kernel.org # v3.7+
cc: Mark Fasheh &lt;mfasheh@suse.de&gt;
Reviewed-by: Filipe Manana &lt;fdmanana@suse.com&gt;
Reviewed-by: Mark Fasheh &lt;mfasheh@suse.de&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>btrfs: check unsupported filters in balance arguments</title>
<updated>2015-10-14T01:53:03+00:00</updated>
<author>
<name>David Sterba</name>
<email>dsterba@suse.com</email>
</author>
<published>2015-10-12T14:55:54+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=8eb934591f8bf584969454a658f629cd06e59f3a'/>
<id>8eb934591f8bf584969454a658f629cd06e59f3a</id>
<content type='text'>
We don't verify that all the balance filter arguments supplemented by
the flags are actually known to the kernel. Thus we let it silently pass
and do nothing.

At the moment this means only the 'limit' filter, but we're going to add
a few more soon so it's better to have that fixed. Also in older stable
kernels so that it works with newer userspace tools.

Cc: stable@vger.kernel.org # 3.16+
Signed-off-by: David Sterba &lt;dsterba@suse.com&gt;
Signed-off-by: Chris Mason &lt;clm@fb.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
We don't verify that all the balance filter arguments supplemented by
the flags are actually known to the kernel. Thus we let it silently pass
and do nothing.

At the moment this means only the 'limit' filter, but we're going to add
a few more soon so it's better to have that fixed. Also in older stable
kernels so that it works with newer userspace tools.

Cc: stable@vger.kernel.org # 3.16+
Signed-off-by: David Sterba &lt;dsterba@suse.com&gt;
Signed-off-by: Chris Mason &lt;clm@fb.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>Merge branch 'for-linus-4.3' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs</title>
<updated>2015-10-09T23:39:35+00:00</updated>
<author>
<name>Linus Torvalds</name>
<email>torvalds@linux-foundation.org</email>
</author>
<published>2015-10-09T23:39:35+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=175d58cfed70f132b8d4df39e19267ad6094bd16'/>
<id>175d58cfed70f132b8d4df39e19267ad6094bd16</id>
<content type='text'>
Pull btrfs fixes from Chris Mason:
 "These are small and assorted.  Neil's is the oldest, I dropped the
  ball thinking he was going to send it in"

* 'for-linus-4.3' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs:
  Btrfs: support NFSv2 export
  Btrfs: open_ctree: Fix possible memory leak
  Btrfs: fix deadlock when finalizing block group creation
  Btrfs: update fix for read corruption of compressed and shared extents
  Btrfs: send, fix corner case for reference overwrite detection
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Pull btrfs fixes from Chris Mason:
 "These are small and assorted.  Neil's is the oldest, I dropped the
  ball thinking he was going to send it in"

* 'for-linus-4.3' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs:
  Btrfs: support NFSv2 export
  Btrfs: open_ctree: Fix possible memory leak
  Btrfs: fix deadlock when finalizing block group creation
  Btrfs: update fix for read corruption of compressed and shared extents
  Btrfs: send, fix corner case for reference overwrite detection
</pre>
</div>
</content>
</entry>
<entry>
<title>BTRFS: support NFSv2 export</title>
<updated>2015-10-06T13:55:23+00:00</updated>
<author>
<name>NeilBrown</name>
<email>neilb@suse.de</email>
</author>
<published>2015-05-08T00:16:23+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=7d35199e15b82a4d1a20049153b03e6258ce79f7'/>
<id>7d35199e15b82a4d1a20049153b03e6258ce79f7</id>
<content type='text'>
The "fh_len" passed to -&gt;fh_to_* is not guaranteed to be that same as
that returned by encode_fh - it may be larger.

With NFSv2, the filehandle is fixed length, so it may appear longer
than expected and be zero-padded.

So we must test that fh_len is at least some value, not exactly equal
to it.

Signed-off-by: NeilBrown &lt;neilb@suse.de&gt;
Acked-by: David Sterba &lt;dsterba@suse.cz&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
The "fh_len" passed to -&gt;fh_to_* is not guaranteed to be that same as
that returned by encode_fh - it may be larger.

With NFSv2, the filehandle is fixed length, so it may appear longer
than expected and be zero-padded.

So we must test that fh_len is at least some value, not exactly equal
to it.

Signed-off-by: NeilBrown &lt;neilb@suse.de&gt;
Acked-by: David Sterba &lt;dsterba@suse.cz&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>Btrfs: open_ctree: Fix possible memory leak</title>
<updated>2015-10-06T13:55:22+00:00</updated>
<author>
<name>chandan</name>
<email>chandan@linux.vnet.ibm.com</email>
</author>
<published>2015-10-05T16:44:25+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=e5fffbac4a49270e4976d71a0e054c0cf3ef4f8e'/>
<id>e5fffbac4a49270e4976d71a0e054c0cf3ef4f8e</id>
<content type='text'>
After reading one of chunk or tree root tree's root node from disk, if the
root node does not have EXTENT_BUFFER_UPTODATE flag set, we fail to release
the memory used by the root node. Fix this.

Signed-off-by: Chandan Rajendra &lt;chandan@linux.vnet.ibm.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
After reading one of chunk or tree root tree's root node from disk, if the
root node does not have EXTENT_BUFFER_UPTODATE flag set, we fail to release
the memory used by the root node. Fix this.

Signed-off-by: Chandan Rajendra &lt;chandan@linux.vnet.ibm.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>Btrfs: fix deadlock when finalizing block group creation</title>
<updated>2015-10-05T23:56:38+00:00</updated>
<author>
<name>Filipe Manana</name>
<email>fdmanana@suse.com</email>
</author>
<published>2015-10-03T12:13:13+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=d9a0540a79f87456907f2ce031f058cf745c5bff'/>
<id>d9a0540a79f87456907f2ce031f058cf745c5bff</id>
<content type='text'>
Josef ran into a deadlock while a transaction handle was finalizing the
creation of its block groups, which produced the following trace:

  [260445.593112] fio             D ffff88022a9df468     0  8924   4518 0x00000084
  [260445.593119]  ffff88022a9df468 ffffffff81c134c0 ffff880429693c00 ffff88022a9df488
  [260445.593126]  ffff88022a9e0000 ffff8803490d7b00 ffff8803490d7b18 ffff88022a9df4b0
  [260445.593132]  ffff8803490d7af8 ffff88022a9df488 ffffffff8175a437 ffff8803490d7b00
  [260445.593137] Call Trace:
  [260445.593145]  [&lt;ffffffff8175a437&gt;] schedule+0x37/0x80
  [260445.593189]  [&lt;ffffffffa0850f37&gt;] btrfs_tree_lock+0xa7/0x1f0 [btrfs]
  [260445.593197]  [&lt;ffffffff810db7c0&gt;] ? prepare_to_wait_event+0xf0/0xf0
  [260445.593225]  [&lt;ffffffffa07eac44&gt;] btrfs_lock_root_node+0x34/0x50 [btrfs]
  [260445.593253]  [&lt;ffffffffa07eff6b&gt;] btrfs_search_slot+0x88b/0xa00 [btrfs]
  [260445.593295]  [&lt;ffffffffa08389df&gt;] ? free_extent_buffer+0x4f/0x90 [btrfs]
  [260445.593324]  [&lt;ffffffffa07f1a06&gt;] btrfs_insert_empty_items+0x66/0xc0 [btrfs]
  [260445.593351]  [&lt;ffffffffa07ea94a&gt;] ? btrfs_alloc_path+0x1a/0x20 [btrfs]
  [260445.593394]  [&lt;ffffffffa08403b9&gt;] btrfs_finish_chunk_alloc+0x1c9/0x570 [btrfs]
  [260445.593427]  [&lt;ffffffffa08002ab&gt;] btrfs_create_pending_block_groups+0x11b/0x200 [btrfs]
  [260445.593459]  [&lt;ffffffffa0800964&gt;] do_chunk_alloc+0x2a4/0x2e0 [btrfs]
  [260445.593491]  [&lt;ffffffffa0803815&gt;] find_free_extent+0xa55/0xd90 [btrfs]
  [260445.593524]  [&lt;ffffffffa0803c22&gt;] btrfs_reserve_extent+0xd2/0x220 [btrfs]
  [260445.593532]  [&lt;ffffffff8119fe5d&gt;] ? account_page_dirtied+0xdd/0x170
  [260445.593564]  [&lt;ffffffffa0803e78&gt;] btrfs_alloc_tree_block+0x108/0x4a0 [btrfs]
  [260445.593597]  [&lt;ffffffffa080c9de&gt;] ? btree_set_page_dirty+0xe/0x10 [btrfs]
  [260445.593626]  [&lt;ffffffffa07eb5cd&gt;] __btrfs_cow_block+0x12d/0x5b0 [btrfs]
  [260445.593654]  [&lt;ffffffffa07ebbff&gt;] btrfs_cow_block+0x11f/0x1c0 [btrfs]
  [260445.593682]  [&lt;ffffffffa07ef8c7&gt;] btrfs_search_slot+0x1e7/0xa00 [btrfs]
  [260445.593724]  [&lt;ffffffffa08389df&gt;] ? free_extent_buffer+0x4f/0x90 [btrfs]
  [260445.593752]  [&lt;ffffffffa07f1a06&gt;] btrfs_insert_empty_items+0x66/0xc0 [btrfs]
  [260445.593830]  [&lt;ffffffffa07ea94a&gt;] ? btrfs_alloc_path+0x1a/0x20 [btrfs]
  [260445.593905]  [&lt;ffffffffa08403b9&gt;] btrfs_finish_chunk_alloc+0x1c9/0x570 [btrfs]
  [260445.593946]  [&lt;ffffffffa08002ab&gt;] btrfs_create_pending_block_groups+0x11b/0x200 [btrfs]
  [260445.593990]  [&lt;ffffffffa0815798&gt;] btrfs_commit_transaction+0xa8/0xb40 [btrfs]
  [260445.594042]  [&lt;ffffffffa085abcd&gt;] ? btrfs_log_dentry_safe+0x6d/0x80 [btrfs]
  [260445.594089]  [&lt;ffffffffa082bc84&gt;] btrfs_sync_file+0x294/0x350 [btrfs]
  [260445.594115]  [&lt;ffffffff8123e29b&gt;] vfs_fsync_range+0x3b/0xa0
  [260445.594133]  [&lt;ffffffff81023891&gt;] ? syscall_trace_enter_phase1+0x131/0x180
  [260445.594149]  [&lt;ffffffff8123e35d&gt;] do_fsync+0x3d/0x70
  [260445.594169]  [&lt;ffffffff81023bb8&gt;] ? syscall_trace_leave+0xb8/0x110
  [260445.594187]  [&lt;ffffffff8123e600&gt;] SyS_fsync+0x10/0x20
  [260445.594204]  [&lt;ffffffff8175de6e&gt;] entry_SYSCALL_64_fastpath+0x12/0x71

This happened because the same transaction handle created a large number
of block groups and while finalizing their creation (inserting new items
and updating existing items in the chunk and device trees) a new metadata
extent had to be allocated and no free space was found in the current
metadata block groups, which made find_free_extent() attempt to allocate
a new block group via do_chunk_alloc(). However at do_chunk_alloc() we
ended up allocating a new system chunk too and exceeded the threshold
of 2Mb of reserved chunk bytes, which makes do_chunk_alloc() enter the
final part of block group creation again (at
btrfs_create_pending_block_groups()) and attempt to lock again the root
of the chunk tree when it's already write locked by the same task.

Similarly we can deadlock on extent tree nodes/leafs if while we are
running delayed references we end up creating a new metadata block group
in order to allocate a new node/leaf for the extent tree (as part of
a CoW operation or growing the tree), as btrfs_create_pending_block_groups
inserts items into the extent tree as well. In this case we get the
following trace:

  [14242.773581] fio             D ffff880428ca3418     0  3615   3100 0x00000084
  [14242.773588]  ffff880428ca3418 ffff88042d66b000 ffff88042a03c800 ffff880428ca3438
  [14242.773594]  ffff880428ca4000 ffff8803e4b20190 ffff8803e4b201a8 ffff880428ca3460
  [14242.773600]  ffff8803e4b20188 ffff880428ca3438 ffffffff8175a437 ffff8803e4b20190
  [14242.773606] Call Trace:
  [14242.773613]  [&lt;ffffffff8175a437&gt;] schedule+0x37/0x80
  [14242.773656]  [&lt;ffffffffa057ff07&gt;] btrfs_tree_lock+0xa7/0x1f0 [btrfs]
  [14242.773664]  [&lt;ffffffff810db7c0&gt;] ? prepare_to_wait_event+0xf0/0xf0
  [14242.773692]  [&lt;ffffffffa0519c44&gt;] btrfs_lock_root_node+0x34/0x50 [btrfs]
  [14242.773720]  [&lt;ffffffffa051ef6b&gt;] btrfs_search_slot+0x88b/0xa00 [btrfs]
  [14242.773750]  [&lt;ffffffffa0520a06&gt;] btrfs_insert_empty_items+0x66/0xc0 [btrfs]
  [14242.773758]  [&lt;ffffffff811ef4a2&gt;] ? kmem_cache_alloc+0x1d2/0x200
  [14242.773786]  [&lt;ffffffffa0520ad1&gt;] btrfs_insert_item+0x71/0xf0 [btrfs]
  [14242.773818]  [&lt;ffffffffa052f292&gt;] btrfs_create_pending_block_groups+0x102/0x200 [btrfs]
  [14242.773850]  [&lt;ffffffffa052f96e&gt;] do_chunk_alloc+0x2ae/0x2f0 [btrfs]
  [14242.773934]  [&lt;ffffffffa0532825&gt;] find_free_extent+0xa55/0xd90 [btrfs]
  [14242.773998]  [&lt;ffffffffa0532c22&gt;] btrfs_reserve_extent+0xc2/0x1d0 [btrfs]
  [14242.774041]  [&lt;ffffffffa0532e38&gt;] btrfs_alloc_tree_block+0x108/0x4a0 [btrfs]
  [14242.774078]  [&lt;ffffffffa051a5cd&gt;] __btrfs_cow_block+0x12d/0x5b0 [btrfs]
  [14242.774118]  [&lt;ffffffffa051abff&gt;] btrfs_cow_block+0x11f/0x1c0 [btrfs]
  [14242.774155]  [&lt;ffffffffa051e8c7&gt;] btrfs_search_slot+0x1e7/0xa00 [btrfs]
  [14242.774194]  [&lt;ffffffffa0528021&gt;] ? __btrfs_free_extent.isra.70+0x2e1/0xcb0 [btrfs]
  [14242.774235]  [&lt;ffffffffa0520a06&gt;] btrfs_insert_empty_items+0x66/0xc0 [btrfs]
  [14242.774274]  [&lt;ffffffffa051994a&gt;] ? btrfs_alloc_path+0x1a/0x20 [btrfs]
  [14242.774318]  [&lt;ffffffffa052c433&gt;] __btrfs_run_delayed_refs+0xbb3/0x1020 [btrfs]
  [14242.774358]  [&lt;ffffffffa052f404&gt;] btrfs_run_delayed_refs.part.78+0x74/0x280 [btrfs]
  [14242.774391]  [&lt;ffffffffa052f627&gt;] btrfs_run_delayed_refs+0x17/0x20 [btrfs]
  [14242.774432]  [&lt;ffffffffa05be236&gt;] commit_cowonly_roots+0x8d/0x2bd [btrfs]
  [14242.774474]  [&lt;ffffffffa059d07f&gt;] ? __btrfs_run_delayed_items+0x1cf/0x210 [btrfs]
  [14242.774516]  [&lt;ffffffffa05adac3&gt;] ? btrfs_qgroup_account_extents+0x83/0x130 [btrfs]
  [14242.774558]  [&lt;ffffffffa0544c40&gt;] btrfs_commit_transaction+0x590/0xb40 [btrfs]
  [14242.774599]  [&lt;ffffffffa0589b9d&gt;] ? btrfs_log_dentry_safe+0x6d/0x80 [btrfs]
  [14242.774642]  [&lt;ffffffffa055ac54&gt;] btrfs_sync_file+0x294/0x350 [btrfs]
  [14242.774650]  [&lt;ffffffff8123e29b&gt;] vfs_fsync_range+0x3b/0xa0
  [14242.774657]  [&lt;ffffffff81023891&gt;] ? syscall_trace_enter_phase1+0x131/0x180
  [14242.774663]  [&lt;ffffffff8123e35d&gt;] do_fsync+0x3d/0x70
  [14242.774669]  [&lt;ffffffff81023bb8&gt;] ? syscall_trace_leave+0xb8/0x110
  [14242.774675]  [&lt;ffffffff8123e600&gt;] SyS_fsync+0x10/0x20
  [14242.774681]  [&lt;ffffffff8175de6e&gt;] entry_SYSCALL_64_fastpath+0x12/0x71

Fix this by never recursing into the finalization phase of block group
creation and making sure we never trigger the finalization of block group
creation while running delayed references.

Reported-by: Josef Bacik &lt;jbacik@fb.com&gt;
Fixes: 00d80e342c0f ("Btrfs: fix quick exhaustion of the system array in the superblock")
Signed-off-by: Filipe Manana &lt;fdmanana@suse.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Josef ran into a deadlock while a transaction handle was finalizing the
creation of its block groups, which produced the following trace:

  [260445.593112] fio             D ffff88022a9df468     0  8924   4518 0x00000084
  [260445.593119]  ffff88022a9df468 ffffffff81c134c0 ffff880429693c00 ffff88022a9df488
  [260445.593126]  ffff88022a9e0000 ffff8803490d7b00 ffff8803490d7b18 ffff88022a9df4b0
  [260445.593132]  ffff8803490d7af8 ffff88022a9df488 ffffffff8175a437 ffff8803490d7b00
  [260445.593137] Call Trace:
  [260445.593145]  [&lt;ffffffff8175a437&gt;] schedule+0x37/0x80
  [260445.593189]  [&lt;ffffffffa0850f37&gt;] btrfs_tree_lock+0xa7/0x1f0 [btrfs]
  [260445.593197]  [&lt;ffffffff810db7c0&gt;] ? prepare_to_wait_event+0xf0/0xf0
  [260445.593225]  [&lt;ffffffffa07eac44&gt;] btrfs_lock_root_node+0x34/0x50 [btrfs]
  [260445.593253]  [&lt;ffffffffa07eff6b&gt;] btrfs_search_slot+0x88b/0xa00 [btrfs]
  [260445.593295]  [&lt;ffffffffa08389df&gt;] ? free_extent_buffer+0x4f/0x90 [btrfs]
  [260445.593324]  [&lt;ffffffffa07f1a06&gt;] btrfs_insert_empty_items+0x66/0xc0 [btrfs]
  [260445.593351]  [&lt;ffffffffa07ea94a&gt;] ? btrfs_alloc_path+0x1a/0x20 [btrfs]
  [260445.593394]  [&lt;ffffffffa08403b9&gt;] btrfs_finish_chunk_alloc+0x1c9/0x570 [btrfs]
  [260445.593427]  [&lt;ffffffffa08002ab&gt;] btrfs_create_pending_block_groups+0x11b/0x200 [btrfs]
  [260445.593459]  [&lt;ffffffffa0800964&gt;] do_chunk_alloc+0x2a4/0x2e0 [btrfs]
  [260445.593491]  [&lt;ffffffffa0803815&gt;] find_free_extent+0xa55/0xd90 [btrfs]
  [260445.593524]  [&lt;ffffffffa0803c22&gt;] btrfs_reserve_extent+0xd2/0x220 [btrfs]
  [260445.593532]  [&lt;ffffffff8119fe5d&gt;] ? account_page_dirtied+0xdd/0x170
  [260445.593564]  [&lt;ffffffffa0803e78&gt;] btrfs_alloc_tree_block+0x108/0x4a0 [btrfs]
  [260445.593597]  [&lt;ffffffffa080c9de&gt;] ? btree_set_page_dirty+0xe/0x10 [btrfs]
  [260445.593626]  [&lt;ffffffffa07eb5cd&gt;] __btrfs_cow_block+0x12d/0x5b0 [btrfs]
  [260445.593654]  [&lt;ffffffffa07ebbff&gt;] btrfs_cow_block+0x11f/0x1c0 [btrfs]
  [260445.593682]  [&lt;ffffffffa07ef8c7&gt;] btrfs_search_slot+0x1e7/0xa00 [btrfs]
  [260445.593724]  [&lt;ffffffffa08389df&gt;] ? free_extent_buffer+0x4f/0x90 [btrfs]
  [260445.593752]  [&lt;ffffffffa07f1a06&gt;] btrfs_insert_empty_items+0x66/0xc0 [btrfs]
  [260445.593830]  [&lt;ffffffffa07ea94a&gt;] ? btrfs_alloc_path+0x1a/0x20 [btrfs]
  [260445.593905]  [&lt;ffffffffa08403b9&gt;] btrfs_finish_chunk_alloc+0x1c9/0x570 [btrfs]
  [260445.593946]  [&lt;ffffffffa08002ab&gt;] btrfs_create_pending_block_groups+0x11b/0x200 [btrfs]
  [260445.593990]  [&lt;ffffffffa0815798&gt;] btrfs_commit_transaction+0xa8/0xb40 [btrfs]
  [260445.594042]  [&lt;ffffffffa085abcd&gt;] ? btrfs_log_dentry_safe+0x6d/0x80 [btrfs]
  [260445.594089]  [&lt;ffffffffa082bc84&gt;] btrfs_sync_file+0x294/0x350 [btrfs]
  [260445.594115]  [&lt;ffffffff8123e29b&gt;] vfs_fsync_range+0x3b/0xa0
  [260445.594133]  [&lt;ffffffff81023891&gt;] ? syscall_trace_enter_phase1+0x131/0x180
  [260445.594149]  [&lt;ffffffff8123e35d&gt;] do_fsync+0x3d/0x70
  [260445.594169]  [&lt;ffffffff81023bb8&gt;] ? syscall_trace_leave+0xb8/0x110
  [260445.594187]  [&lt;ffffffff8123e600&gt;] SyS_fsync+0x10/0x20
  [260445.594204]  [&lt;ffffffff8175de6e&gt;] entry_SYSCALL_64_fastpath+0x12/0x71

This happened because the same transaction handle created a large number
of block groups and while finalizing their creation (inserting new items
and updating existing items in the chunk and device trees) a new metadata
extent had to be allocated and no free space was found in the current
metadata block groups, which made find_free_extent() attempt to allocate
a new block group via do_chunk_alloc(). However at do_chunk_alloc() we
ended up allocating a new system chunk too and exceeded the threshold
of 2Mb of reserved chunk bytes, which makes do_chunk_alloc() enter the
final part of block group creation again (at
btrfs_create_pending_block_groups()) and attempt to lock again the root
of the chunk tree when it's already write locked by the same task.

Similarly we can deadlock on extent tree nodes/leafs if while we are
running delayed references we end up creating a new metadata block group
in order to allocate a new node/leaf for the extent tree (as part of
a CoW operation or growing the tree), as btrfs_create_pending_block_groups
inserts items into the extent tree as well. In this case we get the
following trace:

  [14242.773581] fio             D ffff880428ca3418     0  3615   3100 0x00000084
  [14242.773588]  ffff880428ca3418 ffff88042d66b000 ffff88042a03c800 ffff880428ca3438
  [14242.773594]  ffff880428ca4000 ffff8803e4b20190 ffff8803e4b201a8 ffff880428ca3460
  [14242.773600]  ffff8803e4b20188 ffff880428ca3438 ffffffff8175a437 ffff8803e4b20190
  [14242.773606] Call Trace:
  [14242.773613]  [&lt;ffffffff8175a437&gt;] schedule+0x37/0x80
  [14242.773656]  [&lt;ffffffffa057ff07&gt;] btrfs_tree_lock+0xa7/0x1f0 [btrfs]
  [14242.773664]  [&lt;ffffffff810db7c0&gt;] ? prepare_to_wait_event+0xf0/0xf0
  [14242.773692]  [&lt;ffffffffa0519c44&gt;] btrfs_lock_root_node+0x34/0x50 [btrfs]
  [14242.773720]  [&lt;ffffffffa051ef6b&gt;] btrfs_search_slot+0x88b/0xa00 [btrfs]
  [14242.773750]  [&lt;ffffffffa0520a06&gt;] btrfs_insert_empty_items+0x66/0xc0 [btrfs]
  [14242.773758]  [&lt;ffffffff811ef4a2&gt;] ? kmem_cache_alloc+0x1d2/0x200
  [14242.773786]  [&lt;ffffffffa0520ad1&gt;] btrfs_insert_item+0x71/0xf0 [btrfs]
  [14242.773818]  [&lt;ffffffffa052f292&gt;] btrfs_create_pending_block_groups+0x102/0x200 [btrfs]
  [14242.773850]  [&lt;ffffffffa052f96e&gt;] do_chunk_alloc+0x2ae/0x2f0 [btrfs]
  [14242.773934]  [&lt;ffffffffa0532825&gt;] find_free_extent+0xa55/0xd90 [btrfs]
  [14242.773998]  [&lt;ffffffffa0532c22&gt;] btrfs_reserve_extent+0xc2/0x1d0 [btrfs]
  [14242.774041]  [&lt;ffffffffa0532e38&gt;] btrfs_alloc_tree_block+0x108/0x4a0 [btrfs]
  [14242.774078]  [&lt;ffffffffa051a5cd&gt;] __btrfs_cow_block+0x12d/0x5b0 [btrfs]
  [14242.774118]  [&lt;ffffffffa051abff&gt;] btrfs_cow_block+0x11f/0x1c0 [btrfs]
  [14242.774155]  [&lt;ffffffffa051e8c7&gt;] btrfs_search_slot+0x1e7/0xa00 [btrfs]
  [14242.774194]  [&lt;ffffffffa0528021&gt;] ? __btrfs_free_extent.isra.70+0x2e1/0xcb0 [btrfs]
  [14242.774235]  [&lt;ffffffffa0520a06&gt;] btrfs_insert_empty_items+0x66/0xc0 [btrfs]
  [14242.774274]  [&lt;ffffffffa051994a&gt;] ? btrfs_alloc_path+0x1a/0x20 [btrfs]
  [14242.774318]  [&lt;ffffffffa052c433&gt;] __btrfs_run_delayed_refs+0xbb3/0x1020 [btrfs]
  [14242.774358]  [&lt;ffffffffa052f404&gt;] btrfs_run_delayed_refs.part.78+0x74/0x280 [btrfs]
  [14242.774391]  [&lt;ffffffffa052f627&gt;] btrfs_run_delayed_refs+0x17/0x20 [btrfs]
  [14242.774432]  [&lt;ffffffffa05be236&gt;] commit_cowonly_roots+0x8d/0x2bd [btrfs]
  [14242.774474]  [&lt;ffffffffa059d07f&gt;] ? __btrfs_run_delayed_items+0x1cf/0x210 [btrfs]
  [14242.774516]  [&lt;ffffffffa05adac3&gt;] ? btrfs_qgroup_account_extents+0x83/0x130 [btrfs]
  [14242.774558]  [&lt;ffffffffa0544c40&gt;] btrfs_commit_transaction+0x590/0xb40 [btrfs]
  [14242.774599]  [&lt;ffffffffa0589b9d&gt;] ? btrfs_log_dentry_safe+0x6d/0x80 [btrfs]
  [14242.774642]  [&lt;ffffffffa055ac54&gt;] btrfs_sync_file+0x294/0x350 [btrfs]
  [14242.774650]  [&lt;ffffffff8123e29b&gt;] vfs_fsync_range+0x3b/0xa0
  [14242.774657]  [&lt;ffffffff81023891&gt;] ? syscall_trace_enter_phase1+0x131/0x180
  [14242.774663]  [&lt;ffffffff8123e35d&gt;] do_fsync+0x3d/0x70
  [14242.774669]  [&lt;ffffffff81023bb8&gt;] ? syscall_trace_leave+0xb8/0x110
  [14242.774675]  [&lt;ffffffff8123e600&gt;] SyS_fsync+0x10/0x20
  [14242.774681]  [&lt;ffffffff8175de6e&gt;] entry_SYSCALL_64_fastpath+0x12/0x71

Fix this by never recursing into the finalization phase of block group
creation and making sure we never trigger the finalization of block group
creation while running delayed references.

Reported-by: Josef Bacik &lt;jbacik@fb.com&gt;
Fixes: 00d80e342c0f ("Btrfs: fix quick exhaustion of the system array in the superblock")
Signed-off-by: Filipe Manana &lt;fdmanana@suse.com&gt;
</pre>
</div>
</content>
</entry>
</feed>
