[PATCH 0/4] btrfs: fix property bugs

2019-03-13 Thread Anand Jain
1/4 Fixes a bug that we were applying an incomplete string zstd. 2/4 Fixes a bug that the compression property gets reset to NULL after a failed attempt to change the compression parameter on the object. 3/4 preparatory patch so that btrfs_set_prop_trans() can be merged with btrfs_set_prop(

[PATCH 1/4] btrfs: fix zstd compression parameter

2019-03-13 Thread Anand Jain
We let to pass zstd compression parameter even if its not fully written. For example: btrfs prop set /btrfs compression zst btrfs prop get /btrfs compression compression=zst zlib and lzo are fine. Fix it by using the expected number of char in strncmp(). Signed-off-by: Anand Jain Revie

[PATCH 2/4] btrfs: fix vanished compression property after failed set

2019-03-13 Thread Anand Jain
The compression property resets to NULL, instead of the old value if we fail to set the new compression parameter. btrfs prop get /btrfs compression compression=lzo btrfs prop set /btrfs compression zli ERROR: failed to set compression for /btrfs: Invalid argument btrfs prop get /btrfs compres

[PATCH 3/4] btrfs: open code btrfs_set_prop in inherit_prop

2019-03-13 Thread Anand Jain
When an inode inherits property from its parent, we call btrfs_set_prop(). btrfs_set_prop() does an elaborate checks, which is not required in the context of inheriting a property. Instead just open-code only the required items from btrfs_set_prop() and then call btrfs_setxattr() directly. So now t

[PATCH 4/4] btrfs: fix property validate fail should not increment generation

2019-03-13 Thread Anand Jain
When the property fails to pass the prop_handlers::validate() check, the thread should exit with no changes in the kernel, but as we are starting the transaction too early, we have just updated the generation even if there is no change. For example: btrfs prop get /btrfs compression compression=l

Re: [PATCH 2/2] btrfs: fix vanished compression property after failed set

2019-03-13 Thread Anand Jain
On 3/14/19 1:45 AM, David Sterba wrote: On Wed, Mar 13, 2019 at 06:33:50PM +0800, Anand Jain wrote: On 3/13/19 1:36 PM, Anand Jain wrote: The compression property resets to NULL, instead of the old value if we fail to set the new compression parameter. btrfs prop get /btrfs compression

Re: Balancing raid5 after adding another disk does not move/use any data on it

2019-03-13 Thread Jakub Husák
Sorry, fighting with this technology called "email" :) Hopefully better wrapped outputs: On 13. 03. 19 22:58, Jakub Husák wrote: Hi, I added another disk to my 3-disk raid5 and ran a balance command. After few hours I looked to output of `fi usage` to see that no data are being used on th

Balancing raid5 after adding another disk does not move/use any data on it

2019-03-13 Thread Jakub Husák
Hi, I added another disk to my 3-disk raid5 and ran a balance command. After few hours I looked to output of `fi usage` to see that no data are being used on the new disk. I got the same result even when balancing my raid5 data or metadata. Next I tried to convert my raid5 metadata to raid1

Re: [PATCH] btrfs: Correctly free extent buffer in case btree_read_extent_buffer_pages fails

2019-03-13 Thread David Sterba
On Tue, Mar 12, 2019 at 03:18:47PM +0200, Nikolay Borisov wrote: > If a an eb fails to be read for whatever reason - it's corrupted on disk > and parent transid/key validations fail or IO for eb pages fail then > this buffer must be removed from the buffer cache. Currently the code > calls free_ext

Re: [PATCH 2/2] btrfs: fix vanished compression property after failed set

2019-03-13 Thread David Sterba
On Wed, Mar 13, 2019 at 06:33:50PM +0800, Anand Jain wrote: > > > > On 3/13/19 1:36 PM, Anand Jain wrote: > > The compression property resets to NULL, instead of the old value if we > > fail to set the new compression parameter. > > > > btrfs prop get /btrfs compression > >compression=lzo >

Re: [PATCH 2/2] btrfs: fix vanished compression property after failed set

2019-03-13 Thread David Sterba
On Wed, Mar 13, 2019 at 06:49:27PM +0800, Anand Jain wrote: > > > On 3/13/19 6:33 PM, Anand Jain wrote: > > > > > > > > On 3/13/19 1:36 PM, Anand Jain wrote: > >> The compression property resets to NULL, instead of the old value if we > >> fail to set the new compression parameter. > >> > >> b

Re: [PATCH 2/2] btrfs: fix vanished compression property after failed set

2019-03-13 Thread David Sterba
On Wed, Mar 13, 2019 at 04:49:54PM +0800, Anand Jain wrote: > > > On 3/13/19 3:22 PM, Nikolay Borisov wrote: > > > > > > On 13.03.19 г. 9:20 ч., Nikolay Borisov wrote: > >> > >> > >> On 13.03.19 г. 7:36 ч., Anand Jain wrote: > >>> The compression property resets to NULL, instead of the old valu

Re: [PATCH] btrfs: Exploit the fact pages passed to extent_readpages are always contiguous

2019-03-13 Thread David Sterba
On Mon, Mar 11, 2019 at 09:55:38AM +0200, Nikolay Borisov wrote: > Currently extent_readpages (called from btrfs_redpages) will always call > __extent_readpages which tries to create contiguous range of pages and > call __do_contiguous_readpages when such contiguous range is created. > > It turns

[PATCH 5/9] btrfs: add assertion helpers for extent buffer read lock counters

2019-03-13 Thread David Sterba
The read_locks are a simple counter to track locking balance and used to assert tree locks. Add helpers to make it conditionally work only in DEBUG builds. Will be used in followup patches. Signed-off-by: David Sterba --- fs/btrfs/locking.c | 25 ++--- 1 file changed, 18 in

[PATCH 3/9] btrfs: add assertion helpers for spinning readers

2019-03-13 Thread David Sterba
Add helpers for conditional DEBUG build to assert that the extent buffer spinning_readers constraints are met. Will be used in followup patches. Signed-off-by: David Sterba --- fs/btrfs/locking.c | 13 + 1 file changed, 13 insertions(+) diff --git a/fs/btrfs/locking.c b/fs/btrfs/loc

[PATCH 2/9] btrfs: use assertion helpers for spinning writers

2019-03-13 Thread David Sterba
Use the helpers where open coded. On non-debug builds, the warnings will not trigger and extent_buffer::spining_writers become unused and can be moved to the appropriate section, saving a few bytes. Signed-off-by: David Sterba --- fs/btrfs/extent_io.c | 5 - fs/btrfs/extent_io.h | 2 +- fs

[PATCH 4/9] btrfs: use assertion helpers for spinning readers

2019-03-13 Thread David Sterba
Use the helpers where open coded. On non-debug builds, the warnings will not trigger and extent_buffer::spining_readers become unused and can be moved to the appropriate section, saving a few bytes. Signed-off-by: David Sterba --- fs/btrfs/extent_io.c | 2 +- fs/btrfs/extent_io.h | 2 +- fs/bt

[PATCH 6/9] btrfs: use assertion helpers for extent buffer read lock counters

2019-03-13 Thread David Sterba
Use the helpers where open coded. On non-debug builds, the warnings will not trigger and extent_buffer::read_locks become unused and can be moved to the appropriate section, saving a few bytes. Signed-off-by: David Sterba --- fs/btrfs/extent_io.c | 2 +- fs/btrfs/extent_io.h | 2 +- fs/btrfs/l

[PATCH 9/9] btrfs: switch extent_buffer::lock_nested to bool

2019-03-13 Thread David Sterba
The member is tracking simple status of the lock, we can use bool for that and make some room for further space reduction in the structure. Signed-off-by: David Sterba --- fs/btrfs/extent_io.c | 2 +- fs/btrfs/extent_io.h | 2 +- fs/btrfs/locking.c | 6 +++--- 3 files changed, 5 insertions(+),

[PATCH 7/9] btrfs: add assertion helpers for extent buffer write lock counters

2019-03-13 Thread David Sterba
The write_locks are a simple counter to track locking balance and used to assert tree locks. Add helpers to make it conditionally work only in DEBUG builds. Will be used in followup patches. Signed-off-by: David Sterba --- fs/btrfs/locking.c | 23 ++- 1 file changed, 18 ins

[PATCH 8/9] btrfs: use assertion helpers for extent buffer write lock counters

2019-03-13 Thread David Sterba
Use the helpers where open coded. On non-debug builds, the warnings will not trigger and extent_buffer::write_locks become unused and can be moved to the appropriate section, saving a few bytes. Signed-off-by: David Sterba --- fs/btrfs/extent_io.c | 2 +- fs/btrfs/extent_io.h | 3 +-- fs/btrfs/l

[PATCH 1/9] btrfs: add assertion helpers for spinning writers

2019-03-13 Thread David Sterba
Add helpers for conditional DEBUG build to assert that the extent buffer spinning_writers constraints are met. Will be used in followup patches. Signed-off-by: David Sterba --- fs/btrfs/locking.c | 24 1 file changed, 24 insertions(+) diff --git a/fs/btrfs/locking.c b/f

[PATCH 0/9] Extent buffer locking cleanups

2019-03-13 Thread David Sterba
The series moves several atomic counters under CONFIG_BTRFS_DEBUG. The selected counters are not essential for the extent buffer locking to work. There's some space saving (4x 4B at least) and the cachelines are less stressed on non-debugging builds. The final size is 264 from 280, getting to 256

Re: [PATCH v4 0/7] Compress path cleanups

2019-03-13 Thread David Sterba
On Tue, Mar 12, 2019 at 05:20:23PM +0200, Nikolay Borisov wrote: > Here is the v4 of the compress path cleanups, this version incorporates > feeback from v3, namely: > > * Use struct_size when calculating the size of the struct to allocated in > cow_file_range_async > > * Reinstated the comme

Re: [PATCH v5.1 10/12] btrfs: extent_io: Kill the BUG_ON() in extent_write_cache_pages()

2019-03-13 Thread Qu Wenruo
On 2019/3/13 下午7:31, David Sterba wrote: > On Tue, Mar 12, 2019 at 08:42:12AM +0800, Qu Wenruo wrote: >> >> >> On 2019/3/12 上午8:33, David Sterba wrote: >>> On Mon, Feb 18, 2019 at 01:27:51PM +0800, Qu Wenruo wrote: Signed-off-by: Qu Wenruo Reviewed-by: Johannes Thumshirn ---

Re: [PATCH v5.1 10/12] btrfs: extent_io: Kill the BUG_ON() in extent_write_cache_pages()

2019-03-13 Thread David Sterba
On Tue, Mar 12, 2019 at 08:42:12AM +0800, Qu Wenruo wrote: > > > On 2019/3/12 上午8:33, David Sterba wrote: > > On Mon, Feb 18, 2019 at 01:27:51PM +0800, Qu Wenruo wrote: > >> Signed-off-by: Qu Wenruo > >> Reviewed-by: Johannes Thumshirn > >> --- > >> fs/btrfs/extent_io.c | 10 -- > >> 1

Re: [PATCH 2/2] btrfs: fix vanished compression property after failed set

2019-03-13 Thread Anand Jain
On 3/13/19 6:33 PM, Anand Jain wrote: On 3/13/19 1:36 PM, Anand Jain wrote: The compression property resets to NULL, instead of the old value if we fail to set the new compression parameter. btrfs prop get /btrfs compression    compression=lzo btrfs prop set /btrfs compression zli    ERRO

Re: [PATCH 2/2] btrfs: fix vanished compression property after failed set

2019-03-13 Thread Anand Jain
On 3/13/19 1:36 PM, Anand Jain wrote: The compression property resets to NULL, instead of the old value if we fail to set the new compression parameter. btrfs prop get /btrfs compression compression=lzo btrfs prop set /btrfs compression zli ERROR: failed to set compression for /btrfs:

Re: [PATCH 6/6] btrfs: inode: Verify inode mode to avoid NULL pointer dereference

2019-03-13 Thread Nikolay Borisov
On 13.03.19 г. 10:55 ч., Qu Wenruo wrote: > [BUG] > When access a file on a crafted image, btrfs can crash in block layer: > > BUG: unable to handle kernel NULL pointer dereference at 0008 > PGD 136501067 P4D 136501067 PUD 124519067 PMD 0 > CPU: 3 PID: 0 Comm: swapper/3 Not tainted

Re: [PATCH 5/6] btrfs: tree-checker: Verify inode item

2019-03-13 Thread Nikolay Borisov
On 13.03.19 г. 10:55 ч., Qu Wenruo wrote: > There is a report in kernel bugzilla about mismatch file type in dir > item and inode item. > > This inspires us to check inode mode in inode item. > > This patch will check the following members: > - inode key objectid > Should be ROOT_DIR_DIR or

Re: [PATCH 3/6] btrfs: Check the first key and level for cached extent buffer

2019-03-13 Thread Nikolay Borisov
On 13.03.19 г. 10:55 ч., Qu Wenruo wrote: > [BUG] > When reading a file from a fuzzed image, kernel can panic like: > BTRFS warning (device loop0): csum failed root 5 ino 270 off 0 csum > 0x98f94189 expected csum 0x mirror 1 > assertion failed: !memcmp_extent_buffer(b, &disk_key, of

Re: [PATCH 2/6] btrfs: tree-checker: Verify dev item

2019-03-13 Thread Nikolay Borisov
On 13.03.19 г. 10:55 ч., Qu Wenruo wrote: > [BUG] > For fuzzed image whose DEV_ITEM has invalid total_bytes as 0, then > kernel will just panic: > BUG: unable to handle kernel NULL pointer dereference at 0098 > #PF error: [normal kernel read fault] > PGD 80022b2bd067 P4D 80

Re: [PATCH 1/6] btrfs: tree-checker: Verify chunk items

2019-03-13 Thread Nikolay Borisov
On 13.03.19 г. 10:55 ч., Qu Wenruo wrote: > We already have btrfs_check_chunk_valid() to verify each chunk before > tree-checker. > > Merge that function into tree-checker, and update its error message to > be more readable. > > Old error message would be something like: > BTRFS error (devic

Re: [PATCH 4/6] btrfs: tree-checker: Enhance chunk checker to validate chunk profiler

2019-03-13 Thread Nikolay Borisov
On 13.03.19 г. 10:55 ч., Qu Wenruo wrote: > Btrfs-progs already has comprehensive type checker, to ensure there is > only 0 (SINGLE profile) or 1 (DUP/RAID0/1/5/6/10) bit set for chunk > profile bits. > > Do the same work for kernel. > > Reported-by: Yoon Jungyeon > Link: https://bugzilla.ker

Re: [PATCH 0/6] btrfs: Enhance tree checker and runtime checker to handle the new wave of fuzzed image attack

2019-03-13 Thread Qu Wenruo
Just forgot the repo: It can be fetched from github: https://github.com/adam900710/linux/tree/tree_checker_enhancement Which is based on my previous write time tree checker patchset. Although the patchset itself can also be applied to v5.0-rc7 tag without manual modification. Thanks, Qu On 2019

[PATCH 6/6] btrfs: inode: Verify inode mode to avoid NULL pointer dereference

2019-03-13 Thread Qu Wenruo
[BUG] When access a file on a crafted image, btrfs can crash in block layer: BUG: unable to handle kernel NULL pointer dereference at 0008 PGD 136501067 P4D 136501067 PUD 124519067 PMD 0 CPU: 3 PID: 0 Comm: swapper/3 Not tainted 5.0.0-rc8-default #252 RIP: 0010:end_bio_extent_readpage+

[PATCH 4/6] btrfs: tree-checker: Enhance chunk checker to validate chunk profiler

2019-03-13 Thread Qu Wenruo
Btrfs-progs already has comprehensive type checker, to ensure there is only 0 (SINGLE profile) or 1 (DUP/RAID0/1/5/6/10) bit set for chunk profile bits. Do the same work for kernel. Reported-by: Yoon Jungyeon Link: https://bugzilla.kernel.org/show_bug.cgi?id=202765 Signed-off-by: Qu Wenruo ---

[PATCH 3/6] btrfs: Check the first key and level for cached extent buffer

2019-03-13 Thread Qu Wenruo
[BUG] When reading a file from a fuzzed image, kernel can panic like: BTRFS warning (device loop0): csum failed root 5 ino 270 off 0 csum 0x98f94189 expected csum 0x mirror 1 assertion failed: !memcmp_extent_buffer(b, &disk_key, offsetof(struct btrfs_leaf, items[0].key), sizeof(disk_k

[PATCH 5/6] btrfs: tree-checker: Verify inode item

2019-03-13 Thread Qu Wenruo
There is a report in kernel bugzilla about mismatch file type in dir item and inode item. This inspires us to check inode mode in inode item. This patch will check the following members: - inode key objectid Should be ROOT_DIR_DIR or [256, (u64)-256] or FREE_INO. - inode key offset Should be

[PATCH 0/6] btrfs: Enhance tree checker and runtime checker to handle the new wave of fuzzed image attack

2019-03-13 Thread Qu Wenruo
Thanks for the report from Yoon Jungyeon , we have more fuzzed image to torture btrfs. Those images exposed the following problems: - Chunk check is not comprehensive nor early enough Chunk item check lacks profile bits check (e.g RAID|DUP profile is invalid). And for certain fuzzed image,

[PATCH 1/6] btrfs: tree-checker: Verify chunk items

2019-03-13 Thread Qu Wenruo
We already have btrfs_check_chunk_valid() to verify each chunk before tree-checker. Merge that function into tree-checker, and update its error message to be more readable. Old error message would be something like: BTRFS error (device dm-3): invalid chunk num_stipres: 0 New error message woul

[PATCH 2/6] btrfs: tree-checker: Verify dev item

2019-03-13 Thread Qu Wenruo
[BUG] For fuzzed image whose DEV_ITEM has invalid total_bytes as 0, then kernel will just panic: BUG: unable to handle kernel NULL pointer dereference at 0098 #PF error: [normal kernel read fault] PGD 80022b2bd067 P4D 80022b2bd067 PUD 22b2bc067 PMD 0 Oops: [#1] SMP

Re: [PATCH 2/2] btrfs: fix vanished compression property after failed set

2019-03-13 Thread Anand Jain
On 3/13/19 3:22 PM, Nikolay Borisov wrote: On 13.03.19 г. 9:20 ч., Nikolay Borisov wrote: On 13.03.19 г. 7:36 ч., Anand Jain wrote: The compression property resets to NULL, instead of the old value if we fail to set the new compression parameter. btrfs prop get /btrfs compression com

Re: [PATCH 2/2] btrfs: fix vanished compression property after failed set

2019-03-13 Thread Nikolay Borisov
On 13.03.19 г. 9:20 ч., Nikolay Borisov wrote: > > > On 13.03.19 г. 7:36 ч., Anand Jain wrote: >> The compression property resets to NULL, instead of the old value if we >> fail to set the new compression parameter. >> >> btrfs prop get /btrfs compression >> compression=lzo >> btrfs prop set

Re: [PATCH 2/2] btrfs: fix vanished compression property after failed set

2019-03-13 Thread Nikolay Borisov
On 13.03.19 г. 7:36 ч., Anand Jain wrote: > The compression property resets to NULL, instead of the old value if we > fail to set the new compression parameter. > > btrfs prop get /btrfs compression > compression=lzo > btrfs prop set /btrfs compression zli > ERROR: failed to set compression

Re: [PATCH 1/2] btrfs: fix zstd compression parameter

2019-03-13 Thread Nikolay Borisov
On 13.03.19 г. 7:36 ч., Anand Jain wrote: > We let to pass zstd compression parameter even if its not fully written. > For example: > btrfs prop set /btrfs compression zst > btrfs prop get /btrfs compression > compression=zst > > zlib and lzo are fine. > > Fix it by using the expected