Re: "btrfs: harden agaist duplicate fsid" spams syslog

2019-07-10 Thread Anand Jain
Right. It happened even without this patch but we just know it now. In the original investigations of the patch, the moment you copy a device image into another device, the autoscan would scan the new device into the btrfs kernel and created a mess. Now with this patch we won't replace the device

[PATCH 3/5] Btrfs: only associate the locked page with one async_cow struct

2019-07-10 Thread Tejun Heo
From: Chris Mason The btrfs writepages function collects a large range of pages flagged for delayed allocation, and then sends them down through the COW code for processing. When compression is on, we allocate one async_cow structure for every 512K, and then run those pages through the compressi

[PATCHSET v3 btrfs/for-next] btrfs: fix cgroup writeback support

2019-07-10 Thread Tejun Heo
Hello, This patchset contains only the btrfs part of the following patchset. [1] [PATCHSET v2 btrfs/for-next] blkcg, btrfs: fix cgroup writeback support The block part has already been applied to https://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux-block.git/ for-linus with some na

[PATCH 1/5] Btrfs: stop using btrfs_schedule_bio()

2019-07-10 Thread Tejun Heo
From: Chris Mason btrfs_schedule_bio() hands IO off to a helper thread to do the actual submit_bio() call. This has been used to make sure async crc and compression helpers don't get stuck on IO submission. To maintain good performance, over time the IO submission threads duplicated some IO sch

[PATCH 4/5] Btrfs: use REQ_CGROUP_PUNT for worker thread submitted bios

2019-07-10 Thread Tejun Heo
From: Chris Mason Async CRCs and compression submit IO through helper threads, which means they have IO priority inversions when cgroup IO controllers are in use. This flags all of the writes submitted by btrfs helper threads as REQ_CGROUP_PUNT. submit_bio() will punt these to dedicated per-blk

[PATCH 5/5] Btrfs: extent_write_locked_range() should attach inode->i_wb

2019-07-10 Thread Tejun Heo
From: Chris Mason extent_write_locked_range() is used when we're falling back to buffered IO from inside of compression. It allocates its own wbc and should associate it with the inode's i_wb to make sure the IO goes down from the correct cgroup. Signed-off-by: Chris Mason Reviewed-by: Josef B

[PATCH 2/5] Btrfs: delete the entire async bio submission framework

2019-07-10 Thread Tejun Heo
From: Chris Mason Now that we're not using btrfs_schedule_bio() anymore, delete all the code that supported it. Signed-off-by: Chris Mason Reviewed-by: Josef Bacik --- fs/btrfs/ctree.h | 1 - fs/btrfs/disk-io.c | 13 +-- fs/btrfs/super.c | 1 - fs/btrfs/volumes.c | 209 --

"btrfs: harden agaist duplicate fsid" spams syslog

2019-07-10 Thread Graham Cobb
Anand's Nov 2018 patch "btrfs: harden agaist duplicate fsid" has recently percolated through to my Debian buster server system. And it is spamming my log files. Each of my btrfs filesystem devices logs 4 messages every 2 minutes. Here is an example of the 4 messages related to one device: Jul 10

Re: [PATCH 5/5] btrfs: ctree: Checking key orders before merged tree blocks

2019-07-10 Thread Nikolay Borisov
On 10.07.19 г. 15:02 ч., Qu Wenruo wrote: > > > On 2019/7/10 下午7:19, Nikolay Borisov wrote: >> >> > [...] >>> +static int check_cross_tree_key_order(struct extent_buffer *left, >>> + struct extent_buffer *right) >>> +{ >>> + struct btrfs_key left_last; >>> +

Re: [PATCH 5/5] btrfs: ctree: Checking key orders before merged tree blocks

2019-07-10 Thread Qu Wenruo
On 2019/7/10 下午7:19, Nikolay Borisov wrote: > > [...] >> +static int check_cross_tree_key_order(struct extent_buffer *left, >> + struct extent_buffer *right) >> +{ >> +struct btrfs_key left_last; >> +struct btrfs_key right_first; >> +int level = btrfs

Re: [PATCH 5/5] btrfs: ctree: Checking key orders before merged tree blocks

2019-07-10 Thread Nikolay Borisov
On 10.07.19 г. 11:02 ч., Qu Wenruo wrote: > [BUG] > With crafted image, btrfs can panic at btrfs_del_csums(). > kernel BUG at fs/btrfs/ctree.c:3188! > invalid opcode: [#1] SMP PTI > CPU: 0 PID: 1156 Comm: btrfs-transacti Not tainted 5.0.0-rc8+ #9 > RIP: 0010:btrfs_set_item_key_safe+

Re: [PATCH 4/5] btrfs: extent-tree: Kill the BUG_ON() in insert_inline_extent_backref()

2019-07-10 Thread Nikolay Borisov
On 10.07.19 г. 11:02 ч., Qu Wenruo wrote: > [BUG] > With crafted image, btrfs can panic at insert_inline_extent_backref(): > kernel BUG at fs/btrfs/extent-tree.c:1857! > invalid opcode: [#1] SMP PTI > CPU: 0 PID: 1117 Comm: btrfs-transacti Not tainted 5.0.0-rc8+ #9 > RIP: 0010:inser

Re: [PATCH 1/5] btrfs: extent_io: Do extra check for extent buffer read write functions

2019-07-10 Thread WenRuo Qu
On 2019/7/10 下午6:42, Nikolay Borisov wrote: > > [...] >> >> +/* >> + * Check if the [start, start + len) range is valid before reading/writing >> + * the eb. >> + * >> + * Caller should not touch the dst/src memory if this function returns >> error. >> + */ >> +static int check_eb_range(cons

Re: [PATCH 2/5] btrfs: extent-tree: Kill BUG_ON() in __btrfs_free_extent() and do better comment

2019-07-10 Thread WenRuo Qu
On 2019/7/10 下午6:48, Nikolay Borisov wrote: > > > On 10.07.19 г. 11:02 ч., Qu Wenruo wrote: >> __btrfs_free_extent() is one of the best cases to show how optimization >> could make a function hard to read. >> >> In fact __btrfs_free_extent() is only doing two major works: >> 1. Reduce the refs

Re: [PATCH 3/5] btrfs: Detect unbalanced tree with empty leaf before crashing btree operations

2019-07-10 Thread Nikolay Borisov
On 10.07.19 г. 11:02 ч., Qu Wenruo wrote: > [BUG] > With crafted image, btrfs will panic at btree operations: > kernel BUG at fs/btrfs/ctree.c:3894! > invalid opcode: [#1] SMP PTI > CPU: 0 PID: 1138 Comm: btrfs-transacti Not tainted 5.0.0-rc8+ #9 > RIP: 0010:__push_leaf_left+0x6b6/0

Re: [PATCH 2/5] btrfs: extent-tree: Kill BUG_ON() in __btrfs_free_extent() and do better comment

2019-07-10 Thread Nikolay Borisov
On 10.07.19 г. 11:02 ч., Qu Wenruo wrote: > __btrfs_free_extent() is one of the best cases to show how optimization > could make a function hard to read. > > In fact __btrfs_free_extent() is only doing two major works: > 1. Reduce the refs number of an extent backref >Either it's an inlined

Re: [PATCH 1/5] btrfs: extent_io: Do extra check for extent buffer read write functions

2019-07-10 Thread Nikolay Borisov
On 10.07.19 г. 11:02 ч., Qu Wenruo wrote: > Although we have start, len check for extent buffer reader/write (e.g. > read_extent_buffer()), those checks has its limitations: > - No overflow check > Values like start = 1024 len = -1024 can still pass the basic >(start + len) > eb->len check

[PATCH 1/5] btrfs: extent_io: Do extra check for extent buffer read write functions

2019-07-10 Thread Qu Wenruo
Although we have start, len check for extent buffer reader/write (e.g. read_extent_buffer()), those checks has its limitations: - No overflow check Values like start = 1024 len = -1024 can still pass the basic (start + len) > eb->len check. - Checks are not consistent For read_extent_buffer

[PATCH 2/5] btrfs: extent-tree: Kill BUG_ON() in __btrfs_free_extent() and do better comment

2019-07-10 Thread Qu Wenruo
__btrfs_free_extent() is one of the best cases to show how optimization could make a function hard to read. In fact __btrfs_free_extent() is only doing two major works: 1. Reduce the refs number of an extent backref Either it's an inlined extent backref (inside EXTENT/METADATA item) or a key

[PATCH 5/5] btrfs: ctree: Checking key orders before merged tree blocks

2019-07-10 Thread Qu Wenruo
[BUG] With crafted image, btrfs can panic at btrfs_del_csums(). kernel BUG at fs/btrfs/ctree.c:3188! invalid opcode: [#1] SMP PTI CPU: 0 PID: 1156 Comm: btrfs-transacti Not tainted 5.0.0-rc8+ #9 RIP: 0010:btrfs_set_item_key_safe+0x16c/0x180 Code: b7 48 8d 7d bf 4c 89 fe 48 89 45 c8 0

[PATCH 3/5] btrfs: Detect unbalanced tree with empty leaf before crashing btree operations

2019-07-10 Thread Qu Wenruo
[BUG] With crafted image, btrfs will panic at btree operations: kernel BUG at fs/btrfs/ctree.c:3894! invalid opcode: [#1] SMP PTI CPU: 0 PID: 1138 Comm: btrfs-transacti Not tainted 5.0.0-rc8+ #9 RIP: 0010:__push_leaf_left+0x6b6/0x6e0 Code: 00 00 48 98 48 8d 04 80 48 8d 74 80 65 e8 42

[PATCH 4/5] btrfs: extent-tree: Kill the BUG_ON() in insert_inline_extent_backref()

2019-07-10 Thread Qu Wenruo
[BUG] With crafted image, btrfs can panic at insert_inline_extent_backref(): kernel BUG at fs/btrfs/extent-tree.c:1857! invalid opcode: [#1] SMP PTI CPU: 0 PID: 1117 Comm: btrfs-transacti Not tainted 5.0.0-rc8+ #9 RIP: 0010:insert_inline_extent_backref+0xcc/0xe0 Code: 45 20 49 8b 7e

[PATCH 0/5] btrfs: Enhanced runtime defence against fuzzed images

2019-07-10 Thread Qu Wenruo
Another wave of defence enhancment, including: - Enhanced eb accessors Not really needed for the fuzzed images, as 448de471cd4c ("btrfs: Check the first key and level for cached extent buffer") already fixed half of the reported images. Just add a final layer of safe net. - BUG_ON() hunt