All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] btrfs: Only require sector size alignment for parent eb bytenr
@ 2020-03-26  5:54 Qu Wenruo
  2020-04-03  8:11   ` Dan Carpenter
  0 siblings, 1 reply; 10+ messages in thread
From: Qu Wenruo @ 2020-03-26  5:54 UTC (permalink / raw)
  To: linux-btrfs

[BUG]
A completely sane converted fs will cause kernel warning at balance
time:

[ 1557.188633] BTRFS info (device sda7): relocating block group 8162107392 flags data
[ 1563.358078] BTRFS info (device sda7): found 11722 extents
[ 1563.358277] BTRFS info (device sda7): leaf 7989321728 gen 95 total ptrs 213 free space 3458 owner 2
[ 1563.358280] 	item 0 key (7984947200 169 0) itemoff 16250 itemsize 33
[ 1563.358281] 		extent refs 1 gen 90 flags 2
[ 1563.358282] 		ref#0: tree block backref root 4
[ 1563.358285] 	item 1 key (7985602560 169 0) itemoff 16217 itemsize 33
[ 1563.358286] 		extent refs 1 gen 93 flags 258
[ 1563.358287] 		ref#0: shared block backref parent 7985602560
[ 1563.358288] 			(parent 7985602560 is NOT ALIGNED to nodesize 16384)
[ 1563.358290] 	item 2 key (7985635328 169 0) itemoff 16184 itemsize 33
...
[ 1563.358995] BTRFS error (device sda7): eb 7989321728 invalid extent inline ref type 182
[ 1563.358996] ------------[ cut here ]------------
[ 1563.359005] WARNING: CPU: 14 PID: 2930 at 0xffffffff9f231766

Then with transaction abort, and obviously failed to balance the fs.

[CAUSE]
That mentioned inline ref type 182 is completely sane, it's
BTRFS_SHARED_BLOCK_REF_KEY, it's some extra check making kernel to
believe it's invalid.

Commit 64ecdb647ddb ("Btrfs: add one more sanity check for shared ref
type") introduced extra checks for backref type.

One of the requirement is, parent bytenr must be aligned to node size,
which is not correct, especially for converted fs.

As converted fs could created metadata chunk at bytenr aligned to sector
size, but not aligned to node size.
Then new metadata extents in that chunk would only be aligned to sector
size, with only offset inside the chunk is aligned to node size.

One tree block can start at any bytenr aligned to sector size. Node size
should never be an alignment requirement.
Thus such bad check is causing above bug.

[FIX]
Change the alignment requirement from node size alignment to sector size
alignment.

Also, to make our lives a little easier, also output @iref when
btrfs_get_extent_inline_ref_type() failed, so we can locate the item
easier.

Link: https://bugzilla.kernel.org/show_bug.cgi?id=205475
Fixes: 64ecdb647ddb ("Btrfs: add one more sanity check for shared ref type")
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
Changelog:
v2:
- Update commit message
  Remove the mention for mixed fs, as it's not the cause.
  Add more explanation on how converted fs is causing the problem.

- Fix print-tree comment and alignment check
---
 fs/btrfs/extent-tree.c | 13 +++++++------
 fs/btrfs/print-tree.c  | 18 ++++++++++--------
 2 files changed, 17 insertions(+), 14 deletions(-)

diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 54a64d1e18c6..6b9e7e050995 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -401,10 +401,10 @@ int btrfs_get_extent_inline_ref_type(const struct extent_buffer *eb,
 				/*
 				 * Every shared one has parent tree
 				 * block, which must be aligned to
-				 * nodesize.
+				 * sector size.
 				 */
 				if (offset &&
-				    IS_ALIGNED(offset, eb->fs_info->nodesize))
+				    IS_ALIGNED(offset, eb->fs_info->sectorsize))
 					return type;
 			}
 		} else if (is_data == BTRFS_REF_TYPE_DATA) {
@@ -415,10 +415,10 @@ int btrfs_get_extent_inline_ref_type(const struct extent_buffer *eb,
 				/*
 				 * Every shared one has parent tree
 				 * block, which must be aligned to
-				 * nodesize.
+				 * sector size.
 				 */
 				if (offset &&
-				    IS_ALIGNED(offset, eb->fs_info->nodesize))
+				    IS_ALIGNED(offset, eb->fs_info->sectorsize))
 					return type;
 			}
 		} else {
@@ -428,8 +428,9 @@ int btrfs_get_extent_inline_ref_type(const struct extent_buffer *eb,
 	}
 
 	btrfs_print_leaf((struct extent_buffer *)eb);
-	btrfs_err(eb->fs_info, "eb %llu invalid extent inline ref type %d",
-		  eb->start, type);
+	btrfs_err(eb->fs_info,
+		  "eb %llu iref 0x%lu invalid extent inline ref type %d",
+		  eb->start, (unsigned long)iref, type);
 	WARN_ON(1);
 
 	return BTRFS_REF_TYPE_INVALID;
diff --git a/fs/btrfs/print-tree.c b/fs/btrfs/print-tree.c
index 61f44e78e3c9..aa1636abde90 100644
--- a/fs/btrfs/print-tree.c
+++ b/fs/btrfs/print-tree.c
@@ -93,11 +93,12 @@ static void print_extent_item(struct extent_buffer *eb, int slot, int type)
 			pr_cont("shared block backref parent %llu\n", offset);
 			/*
 			 * offset is supposed to be a tree block which
-			 * must be aligned to nodesize.
+			 * must be aligned to sector size.
 			 */
-			if (!IS_ALIGNED(offset, eb->fs_info->nodesize))
-				pr_info("\t\t\t(parent %llu is NOT ALIGNED to nodesize %llu)\n",
-					offset, (unsigned long long)eb->fs_info->nodesize);
+			if (!IS_ALIGNED(offset, eb->fs_info->sectorsize))
+				pr_info(
+		"\t\t\t(parent %llu is NOT ALIGNED to sectorsize %u)\n",
+					offset, eb->fs_info->sectorsize);
 			break;
 		case BTRFS_EXTENT_DATA_REF_KEY:
 			dref = (struct btrfs_extent_data_ref *)(&iref->offset);
@@ -109,11 +110,12 @@ static void print_extent_item(struct extent_buffer *eb, int slot, int type)
 			       offset, btrfs_shared_data_ref_count(eb, sref));
 			/*
 			 * offset is supposed to be a tree block which
-			 * must be aligned to nodesize.
+			 * must be aligned to sector size.
 			 */
-			if (!IS_ALIGNED(offset, eb->fs_info->nodesize))
-				pr_info("\t\t\t(parent %llu is NOT ALIGNED to nodesize %llu)\n",
-				     offset, (unsigned long long)eb->fs_info->nodesize);
+			if (!IS_ALIGNED(offset, eb->fs_info->sectorsize))
+				pr_info(
+		"\t\t\t(parent %llu is NOT ALIGNED to sectorsize %u)\n",
+				     offset, eb->fs_info->sectorsize);
 			break;
 		default:
 			pr_cont("(extent %llu has INVALID ref type %d)\n",
-- 
2.26.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH v2] btrfs: Only require sector size alignment for parent eb bytenr
  2020-03-26  5:54 [PATCH v2] btrfs: Only require sector size alignment for parent eb bytenr Qu Wenruo
  2020-04-03  8:11   ` Dan Carpenter
@ 2020-04-03  8:11   ` Dan Carpenter
  0 siblings, 0 replies; 10+ messages in thread
From: Dan Carpenter @ 2020-04-03  8:11 UTC (permalink / raw)
  To: kbuild, Qu Wenruo; +Cc: kbuild-all, linux-btrfs

Hi Qu,

url:    https://github.com/0day-ci/linux/commits/Qu-Wenruo/btrfs-Only-require-sector-size-alignment-for-parent-eb-bytenr/20200327-034045
base:   https://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs.git next

If you fix the issue, kindly add following tag
Reported-by: kbuild test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

New smatch warnings:
fs/btrfs/extent-tree.c:1178 btrfs_get_extent_inline_ref_type() warn: '0x' prefix is confusing together with '%lu' specifier
fs/btrfs/extent-tree.c:1178 btrfs_get_extent_inline_ref_type() warn: argument 4 to %lu specifier is cast from pointer

Old smatch warnings:
fs/btrfs/extent-tree.c:6343 update_block_group() warn: inconsistent indenting
fs/btrfs/extent-tree.c:7620 find_free_extent() warn: inconsistent indenting

# https://github.com/0day-ci/linux/commit/8a07080e7e5051c75e67e30bf635fc230b2ab720
git remote add linux-review https://github.com/0day-ci/linux
git remote update linux-review
git checkout 8a07080e7e5051c75e67e30bf635fc230b2ab720
vim +1178 fs/btrfs/extent-tree.c

64ecdb647ddb83 Liu Bo    2017-08-18  1166  				 */
64ecdb647ddb83 Liu Bo    2017-08-18  1167  				if (offset &&
8a07080e7e5051 Qu Wenruo 2020-03-26  1168  				    IS_ALIGNED(offset, eb->fs_info->sectorsize))
64ecdb647ddb83 Liu Bo    2017-08-18  1169  					return type;
64ecdb647ddb83 Liu Bo    2017-08-18  1170  			}
167ce953ca55bd Liu Bo    2017-08-18  1171  		} else {
167ce953ca55bd Liu Bo    2017-08-18  1172  			ASSERT(is_data == BTRFS_REF_TYPE_ANY);
167ce953ca55bd Liu Bo    2017-08-18  1173  			return type;
167ce953ca55bd Liu Bo    2017-08-18  1174  		}
167ce953ca55bd Liu Bo    2017-08-18  1175  	}
167ce953ca55bd Liu Bo    2017-08-18  1176  
167ce953ca55bd Liu Bo    2017-08-18  1177  	btrfs_print_leaf((struct extent_buffer *)eb);
8a07080e7e5051 Qu Wenruo 2020-03-26 @1178  	btrfs_err(eb->fs_info,
8a07080e7e5051 Qu Wenruo 2020-03-26  1179  		  "eb %llu iref 0x%lu invalid extent inline ref type %d",
                                                                        ^^^^^

8a07080e7e5051 Qu Wenruo 2020-03-26  1180  		  eb->start, (unsigned long)iref, type);
                                                                     ^^^^^^^^^^^^^^^^^^^
0x indicates hex, but this is decimal.  But use %p for pointers so that
the can be hidden to people without enough privilege.  #kernelHardenning

167ce953ca55bd Liu Bo    2017-08-18  1181  	WARN_ON(1);
167ce953ca55bd Liu Bo    2017-08-18  1182  
167ce953ca55bd Liu Bo    2017-08-18  1183  	return BTRFS_REF_TYPE_INVALID;
167ce953ca55bd Liu Bo    2017-08-18  1184  }

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2] btrfs: Only require sector size alignment for parent eb bytenr
@ 2020-04-03  8:11   ` Dan Carpenter
  0 siblings, 0 replies; 10+ messages in thread
From: Dan Carpenter @ 2020-04-03  8:11 UTC (permalink / raw)
  To: kbuild

[-- Attachment #1: Type: text/plain, Size: 2779 bytes --]

Hi Qu,

url:    https://github.com/0day-ci/linux/commits/Qu-Wenruo/btrfs-Only-require-sector-size-alignment-for-parent-eb-bytenr/20200327-034045
base:   https://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs.git next

If you fix the issue, kindly add following tag
Reported-by: kbuild test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

New smatch warnings:
fs/btrfs/extent-tree.c:1178 btrfs_get_extent_inline_ref_type() warn: '0x' prefix is confusing together with '%lu' specifier
fs/btrfs/extent-tree.c:1178 btrfs_get_extent_inline_ref_type() warn: argument 4 to %lu specifier is cast from pointer

Old smatch warnings:
fs/btrfs/extent-tree.c:6343 update_block_group() warn: inconsistent indenting
fs/btrfs/extent-tree.c:7620 find_free_extent() warn: inconsistent indenting

# https://github.com/0day-ci/linux/commit/8a07080e7e5051c75e67e30bf635fc230b2ab720
git remote add linux-review https://github.com/0day-ci/linux
git remote update linux-review
git checkout 8a07080e7e5051c75e67e30bf635fc230b2ab720
vim +1178 fs/btrfs/extent-tree.c

64ecdb647ddb83 Liu Bo    2017-08-18  1166  				 */
64ecdb647ddb83 Liu Bo    2017-08-18  1167  				if (offset &&
8a07080e7e5051 Qu Wenruo 2020-03-26  1168  				    IS_ALIGNED(offset, eb->fs_info->sectorsize))
64ecdb647ddb83 Liu Bo    2017-08-18  1169  					return type;
64ecdb647ddb83 Liu Bo    2017-08-18  1170  			}
167ce953ca55bd Liu Bo    2017-08-18  1171  		} else {
167ce953ca55bd Liu Bo    2017-08-18  1172  			ASSERT(is_data == BTRFS_REF_TYPE_ANY);
167ce953ca55bd Liu Bo    2017-08-18  1173  			return type;
167ce953ca55bd Liu Bo    2017-08-18  1174  		}
167ce953ca55bd Liu Bo    2017-08-18  1175  	}
167ce953ca55bd Liu Bo    2017-08-18  1176  
167ce953ca55bd Liu Bo    2017-08-18  1177  	btrfs_print_leaf((struct extent_buffer *)eb);
8a07080e7e5051 Qu Wenruo 2020-03-26 @1178  	btrfs_err(eb->fs_info,
8a07080e7e5051 Qu Wenruo 2020-03-26  1179  		  "eb %llu iref 0x%lu invalid extent inline ref type %d",
                                                                        ^^^^^

8a07080e7e5051 Qu Wenruo 2020-03-26  1180  		  eb->start, (unsigned long)iref, type);
                                                                     ^^^^^^^^^^^^^^^^^^^
0x indicates hex, but this is decimal.  But use %p for pointers so that
the can be hidden to people without enough privilege.  #kernelHardenning

167ce953ca55bd Liu Bo    2017-08-18  1181  	WARN_ON(1);
167ce953ca55bd Liu Bo    2017-08-18  1182  
167ce953ca55bd Liu Bo    2017-08-18  1183  	return BTRFS_REF_TYPE_INVALID;
167ce953ca55bd Liu Bo    2017-08-18  1184  }

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2] btrfs: Only require sector size alignment for parent eb bytenr
@ 2020-04-03  8:11   ` Dan Carpenter
  0 siblings, 0 replies; 10+ messages in thread
From: Dan Carpenter @ 2020-04-03  8:11 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 2779 bytes --]

Hi Qu,

url:    https://github.com/0day-ci/linux/commits/Qu-Wenruo/btrfs-Only-require-sector-size-alignment-for-parent-eb-bytenr/20200327-034045
base:   https://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs.git next

If you fix the issue, kindly add following tag
Reported-by: kbuild test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

New smatch warnings:
fs/btrfs/extent-tree.c:1178 btrfs_get_extent_inline_ref_type() warn: '0x' prefix is confusing together with '%lu' specifier
fs/btrfs/extent-tree.c:1178 btrfs_get_extent_inline_ref_type() warn: argument 4 to %lu specifier is cast from pointer

Old smatch warnings:
fs/btrfs/extent-tree.c:6343 update_block_group() warn: inconsistent indenting
fs/btrfs/extent-tree.c:7620 find_free_extent() warn: inconsistent indenting

# https://github.com/0day-ci/linux/commit/8a07080e7e5051c75e67e30bf635fc230b2ab720
git remote add linux-review https://github.com/0day-ci/linux
git remote update linux-review
git checkout 8a07080e7e5051c75e67e30bf635fc230b2ab720
vim +1178 fs/btrfs/extent-tree.c

64ecdb647ddb83 Liu Bo    2017-08-18  1166  				 */
64ecdb647ddb83 Liu Bo    2017-08-18  1167  				if (offset &&
8a07080e7e5051 Qu Wenruo 2020-03-26  1168  				    IS_ALIGNED(offset, eb->fs_info->sectorsize))
64ecdb647ddb83 Liu Bo    2017-08-18  1169  					return type;
64ecdb647ddb83 Liu Bo    2017-08-18  1170  			}
167ce953ca55bd Liu Bo    2017-08-18  1171  		} else {
167ce953ca55bd Liu Bo    2017-08-18  1172  			ASSERT(is_data == BTRFS_REF_TYPE_ANY);
167ce953ca55bd Liu Bo    2017-08-18  1173  			return type;
167ce953ca55bd Liu Bo    2017-08-18  1174  		}
167ce953ca55bd Liu Bo    2017-08-18  1175  	}
167ce953ca55bd Liu Bo    2017-08-18  1176  
167ce953ca55bd Liu Bo    2017-08-18  1177  	btrfs_print_leaf((struct extent_buffer *)eb);
8a07080e7e5051 Qu Wenruo 2020-03-26 @1178  	btrfs_err(eb->fs_info,
8a07080e7e5051 Qu Wenruo 2020-03-26  1179  		  "eb %llu iref 0x%lu invalid extent inline ref type %d",
                                                                        ^^^^^

8a07080e7e5051 Qu Wenruo 2020-03-26  1180  		  eb->start, (unsigned long)iref, type);
                                                                     ^^^^^^^^^^^^^^^^^^^
0x indicates hex, but this is decimal.  But use %p for pointers so that
the can be hidden to people without enough privilege.  #kernelHardenning

167ce953ca55bd Liu Bo    2017-08-18  1181  	WARN_ON(1);
167ce953ca55bd Liu Bo    2017-08-18  1182  
167ce953ca55bd Liu Bo    2017-08-18  1183  	return BTRFS_REF_TYPE_INVALID;
167ce953ca55bd Liu Bo    2017-08-18  1184  }

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2] btrfs: Only require sector size alignment for parent eb bytenr
  2020-08-26  9:26 Qu Wenruo
  2020-08-26 14:18 ` Josef Bacik
  2020-09-03 11:44 ` David Sterba
@ 2020-09-03 11:53 ` David Sterba
  2 siblings, 0 replies; 10+ messages in thread
From: David Sterba @ 2020-09-03 11:53 UTC (permalink / raw)
  To: Qu Wenruo; +Cc: linux-btrfs

On Wed, Aug 26, 2020 at 05:26:43PM +0800, Qu Wenruo wrote:
> @@ -429,8 +429,9 @@ int btrfs_get_extent_inline_ref_type(const struct extent_buffer *eb,
>  	}
>  
>  	btrfs_print_leaf((struct extent_buffer *)eb);
> -	btrfs_err(eb->fs_info, "eb %llu invalid extent inline ref type %d",
> -		  eb->start, type);
> +	btrfs_err(eb->fs_info,
> +		  "eb %llu iref 0x%lu invalid extent inline ref type %d",

So I replied to the previous v2 post by accident but now I see that the
0x%lu problem was reported back then and still present in this v2.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2] btrfs: Only require sector size alignment for parent eb bytenr
  2020-08-26  9:26 Qu Wenruo
  2020-08-26 14:18 ` Josef Bacik
@ 2020-09-03 11:44 ` David Sterba
  2020-09-03 11:53 ` David Sterba
  2 siblings, 0 replies; 10+ messages in thread
From: David Sterba @ 2020-09-03 11:44 UTC (permalink / raw)
  To: Qu Wenruo; +Cc: linux-btrfs

On Wed, Aug 26, 2020 at 05:26:43PM +0800, Qu Wenruo wrote:
> @@ -429,8 +429,9 @@ int btrfs_get_extent_inline_ref_type(const struct extent_buffer *eb,
>  	}
>  
>  	btrfs_print_leaf((struct extent_buffer *)eb);
> -	btrfs_err(eb->fs_info, "eb %llu invalid extent inline ref type %d",
> -		  eb->start, type);
> +	btrfs_err(eb->fs_info,
> +		  "eb %llu iref 0x%lu invalid extent inline ref type %d",

0x needs %lx, fixed and added to misc-next, thanks.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2] btrfs: Only require sector size alignment for parent eb bytenr
  2020-08-26 14:18 ` Josef Bacik
@ 2020-08-26 22:51   ` Qu Wenruo
  0 siblings, 0 replies; 10+ messages in thread
From: Qu Wenruo @ 2020-08-26 22:51 UTC (permalink / raw)
  To: Josef Bacik, Qu Wenruo, linux-btrfs


[-- Attachment #1.1: Type: text/plain, Size: 2270 bytes --]



On 2020/8/26 下午10:18, Josef Bacik wrote:
> On 8/26/20 5:26 AM, Qu Wenruo wrote:
>> [BUG]
>> A completely sane converted fs will cause kernel warning at balance
>> time:
>>
>> [ 1557.188633] BTRFS info (device sda7): relocating block group
>> 8162107392 flags data
>> [ 1563.358078] BTRFS info (device sda7): found 11722 extents
>> [ 1563.358277] BTRFS info (device sda7): leaf 7989321728 gen 95 total
>> ptrs 213 free space 3458 owner 2
>> [ 1563.358280]     item 0 key (7984947200 169 0) itemoff 16250
>> itemsize 33
>> [ 1563.358281]         extent refs 1 gen 90 flags 2
>> [ 1563.358282]         ref#0: tree block backref root 4
>> [ 1563.358285]     item 1 key (7985602560 169 0) itemoff 16217
>> itemsize 33
>> [ 1563.358286]         extent refs 1 gen 93 flags 258
>> [ 1563.358287]         ref#0: shared block backref parent 7985602560
>> [ 1563.358288]             (parent 7985602560 is NOT ALIGNED to
>> nodesize 16384)
>> [ 1563.358290]     item 2 key (7985635328 169 0) itemoff 16184
>> itemsize 33
>> ...
>> [ 1563.358995] BTRFS error (device sda7): eb 7989321728 invalid extent
>> inline ref type 182
>> [ 1563.358996] ------------[ cut here ]------------
>> [ 1563.359005] WARNING: CPU: 14 PID: 2930 at 0xffffffff9f231766
>>
>> Then with transaction abort, and obviously failed to balance the fs.
>>
>> [CAUSE]
>> That mentioned inline ref type 182 is completely sane, it's
>> BTRFS_SHARED_BLOCK_REF_KEY, it's some extra check making kernel to
>> believe it's invalid.
>>
>> Commit 64ecdb647ddb ("Btrfs: add one more sanity check for shared ref
>> type") introduced extra checks for backref type.
>>
>> One of the requirement is, parent bytenr must be aligned to node size,
>> which is not correct.
>>
>> One example is like this:
>>
>> 0    1G  1G+4K        2G 2G+4K
>>     |   |///////////////////|//|  <- A chunk starts at 1G+4K
>>              |   |    <- A tree block get reserved at bytenr 1G+4K
>>
> 
> This only happens with convert right?  Can we just fix convert to not do
> this? Thanks,

Yes, but the damage is already done, thus we still need to handle them.

Thanks,
Qu

> 
> Josef


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2] btrfs: Only require sector size alignment for parent eb bytenr
@ 2020-08-26 18:51 kernel test robot
  0 siblings, 0 replies; 10+ messages in thread
From: kernel test robot @ 2020-08-26 18:51 UTC (permalink / raw)
  To: kbuild

[-- Attachment #1: Type: text/plain, Size: 16716 bytes --]

CC: kbuild-all(a)lists.01.org
In-Reply-To: <20200826092643.113881-1-wqu@suse.com>
References: <20200826092643.113881-1-wqu@suse.com>
TO: Qu Wenruo <wqu@suse.com>
TO: linux-btrfs(a)vger.kernel.org

Hi Qu,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on kdave/for-next]
[also build test WARNING on v5.9-rc2 next-20200826]
[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/Qu-Wenruo/btrfs-Only-require-sector-size-alignment-for-parent-eb-bytenr/20200826-172817
base:   https://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux.git for-next
:::::: branch date: 9 hours ago
:::::: commit date: 9 hours ago
config: x86_64-randconfig-m001-20200826 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

smatch warnings:
fs/btrfs/extent-tree.c:432 btrfs_get_extent_inline_ref_type() warn: '0x' prefix is confusing together with '%lu' specifier
fs/btrfs/extent-tree.c:432 btrfs_get_extent_inline_ref_type() warn: argument 4 to %lu specifier is cast from pointer

# https://github.com/0day-ci/linux/commit/45e82350ded690823247b2902c1cca52b4a4ead8
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Qu-Wenruo/btrfs-Only-require-sector-size-alignment-for-parent-eb-bytenr/20200826-172817
git checkout 45e82350ded690823247b2902c1cca52b4a4ead8
vim +432 fs/btrfs/extent-tree.c

a22285a6a32390 Yan, Zheng         2010-05-16  274  
d8d5f3e16d1ae4 Chris Mason        2007-12-11  275  /*
d8d5f3e16d1ae4 Chris Mason        2007-12-11  276   * Back reference rules.  Back refs have three main goals:
d8d5f3e16d1ae4 Chris Mason        2007-12-11  277   *
d8d5f3e16d1ae4 Chris Mason        2007-12-11  278   * 1) differentiate between all holders of references to an extent so that
d8d5f3e16d1ae4 Chris Mason        2007-12-11  279   *    when a reference is dropped we can make sure it was a valid reference
d8d5f3e16d1ae4 Chris Mason        2007-12-11  280   *    before freeing the extent.
d8d5f3e16d1ae4 Chris Mason        2007-12-11  281   *
d8d5f3e16d1ae4 Chris Mason        2007-12-11  282   * 2) Provide enough information to quickly find the holders of an extent
d8d5f3e16d1ae4 Chris Mason        2007-12-11  283   *    if we notice a given block is corrupted or bad.
d8d5f3e16d1ae4 Chris Mason        2007-12-11  284   *
d8d5f3e16d1ae4 Chris Mason        2007-12-11  285   * 3) Make it easy to migrate blocks for FS shrinking or storage pool
d8d5f3e16d1ae4 Chris Mason        2007-12-11  286   *    maintenance.  This is actually the same as #2, but with a slightly
d8d5f3e16d1ae4 Chris Mason        2007-12-11  287   *    different use case.
d8d5f3e16d1ae4 Chris Mason        2007-12-11  288   *
5d4f98a28c7d33 Yan Zheng          2009-06-10  289   * There are two kinds of back refs. The implicit back refs is optimized
5d4f98a28c7d33 Yan Zheng          2009-06-10  290   * for pointers in non-shared tree blocks. For a given pointer in a block,
5d4f98a28c7d33 Yan Zheng          2009-06-10  291   * back refs of this kind provide information about the block's owner tree
5d4f98a28c7d33 Yan Zheng          2009-06-10  292   * and the pointer's key. These information allow us to find the block by
5d4f98a28c7d33 Yan Zheng          2009-06-10  293   * b-tree searching. The full back refs is for pointers in tree blocks not
5d4f98a28c7d33 Yan Zheng          2009-06-10  294   * referenced by their owner trees. The location of tree block is recorded
5d4f98a28c7d33 Yan Zheng          2009-06-10  295   * in the back refs. Actually the full back refs is generic, and can be
5d4f98a28c7d33 Yan Zheng          2009-06-10  296   * used in all cases the implicit back refs is used. The major shortcoming
5d4f98a28c7d33 Yan Zheng          2009-06-10  297   * of the full back refs is its overhead. Every time a tree block gets
5d4f98a28c7d33 Yan Zheng          2009-06-10  298   * COWed, we have to update back refs entry for all pointers in it.
5d4f98a28c7d33 Yan Zheng          2009-06-10  299   *
5d4f98a28c7d33 Yan Zheng          2009-06-10  300   * For a newly allocated tree block, we use implicit back refs for
5d4f98a28c7d33 Yan Zheng          2009-06-10  301   * pointers in it. This means most tree related operations only involve
5d4f98a28c7d33 Yan Zheng          2009-06-10  302   * implicit back refs. For a tree block created in old transaction, the
5d4f98a28c7d33 Yan Zheng          2009-06-10  303   * only way to drop a reference to it is COW it. So we can detect the
5d4f98a28c7d33 Yan Zheng          2009-06-10  304   * event that tree block loses its owner tree's reference and do the
5d4f98a28c7d33 Yan Zheng          2009-06-10  305   * back refs conversion.
5d4f98a28c7d33 Yan Zheng          2009-06-10  306   *
0132761017e012 Nicholas D Steeves 2016-05-19  307   * When a tree block is COWed through a tree, there are four cases:
5d4f98a28c7d33 Yan Zheng          2009-06-10  308   *
5d4f98a28c7d33 Yan Zheng          2009-06-10  309   * The reference count of the block is one and the tree is the block's
5d4f98a28c7d33 Yan Zheng          2009-06-10  310   * owner tree. Nothing to do in this case.
5d4f98a28c7d33 Yan Zheng          2009-06-10  311   *
5d4f98a28c7d33 Yan Zheng          2009-06-10  312   * The reference count of the block is one and the tree is not the
5d4f98a28c7d33 Yan Zheng          2009-06-10  313   * block's owner tree. In this case, full back refs is used for pointers
5d4f98a28c7d33 Yan Zheng          2009-06-10  314   * in the block. Remove these full back refs, add implicit back refs for
5d4f98a28c7d33 Yan Zheng          2009-06-10  315   * every pointers in the new block.
5d4f98a28c7d33 Yan Zheng          2009-06-10  316   *
5d4f98a28c7d33 Yan Zheng          2009-06-10  317   * The reference count of the block is greater than one and the tree is
5d4f98a28c7d33 Yan Zheng          2009-06-10  318   * the block's owner tree. In this case, implicit back refs is used for
5d4f98a28c7d33 Yan Zheng          2009-06-10  319   * pointers in the block. Add full back refs for every pointers in the
5d4f98a28c7d33 Yan Zheng          2009-06-10  320   * block, increase lower level extents' reference counts. The original
5d4f98a28c7d33 Yan Zheng          2009-06-10  321   * implicit back refs are entailed to the new block.
5d4f98a28c7d33 Yan Zheng          2009-06-10  322   *
5d4f98a28c7d33 Yan Zheng          2009-06-10  323   * The reference count of the block is greater than one and the tree is
5d4f98a28c7d33 Yan Zheng          2009-06-10  324   * not the block's owner tree. Add implicit back refs for every pointer in
5d4f98a28c7d33 Yan Zheng          2009-06-10  325   * the new block, increase lower level extents' reference count.
5d4f98a28c7d33 Yan Zheng          2009-06-10  326   *
5d4f98a28c7d33 Yan Zheng          2009-06-10  327   * Back Reference Key composing:
5d4f98a28c7d33 Yan Zheng          2009-06-10  328   *
5d4f98a28c7d33 Yan Zheng          2009-06-10  329   * The key objectid corresponds to the first byte in the extent,
5d4f98a28c7d33 Yan Zheng          2009-06-10  330   * The key type is used to differentiate between types of back refs.
5d4f98a28c7d33 Yan Zheng          2009-06-10  331   * There are different meanings of the key offset for different types
5d4f98a28c7d33 Yan Zheng          2009-06-10  332   * of back refs.
5d4f98a28c7d33 Yan Zheng          2009-06-10  333   *
d8d5f3e16d1ae4 Chris Mason        2007-12-11  334   * File extents can be referenced by:
d8d5f3e16d1ae4 Chris Mason        2007-12-11  335   *
d8d5f3e16d1ae4 Chris Mason        2007-12-11  336   * - multiple snapshots, subvolumes, or different generations in one subvol
31840ae1a6b433 Zheng Yan          2008-09-23  337   * - different files inside a single subvolume
d8d5f3e16d1ae4 Chris Mason        2007-12-11  338   * - different offsets inside a file (bookend extents in file.c)
d8d5f3e16d1ae4 Chris Mason        2007-12-11  339   *
5d4f98a28c7d33 Yan Zheng          2009-06-10  340   * The extent ref structure for the implicit back refs has fields for:
d8d5f3e16d1ae4 Chris Mason        2007-12-11  341   *
d8d5f3e16d1ae4 Chris Mason        2007-12-11  342   * - Objectid of the subvolume root
d8d5f3e16d1ae4 Chris Mason        2007-12-11  343   * - objectid of the file holding the reference
5d4f98a28c7d33 Yan Zheng          2009-06-10  344   * - original offset in the file
5d4f98a28c7d33 Yan Zheng          2009-06-10  345   * - how many bookend extents
d8d5f3e16d1ae4 Chris Mason        2007-12-11  346   *
5d4f98a28c7d33 Yan Zheng          2009-06-10  347   * The key offset for the implicit back refs is hash of the first
5d4f98a28c7d33 Yan Zheng          2009-06-10  348   * three fields.
d8d5f3e16d1ae4 Chris Mason        2007-12-11  349   *
5d4f98a28c7d33 Yan Zheng          2009-06-10  350   * The extent ref structure for the full back refs has field for:
d8d5f3e16d1ae4 Chris Mason        2007-12-11  351   *
5d4f98a28c7d33 Yan Zheng          2009-06-10  352   * - number of pointers in the tree leaf
d8d5f3e16d1ae4 Chris Mason        2007-12-11  353   *
5d4f98a28c7d33 Yan Zheng          2009-06-10  354   * The key offset for the implicit back refs is the first byte of
5d4f98a28c7d33 Yan Zheng          2009-06-10  355   * the tree leaf
d8d5f3e16d1ae4 Chris Mason        2007-12-11  356   *
5d4f98a28c7d33 Yan Zheng          2009-06-10  357   * When a file extent is allocated, The implicit back refs is used.
5d4f98a28c7d33 Yan Zheng          2009-06-10  358   * the fields are filled in:
d8d5f3e16d1ae4 Chris Mason        2007-12-11  359   *
5d4f98a28c7d33 Yan Zheng          2009-06-10  360   *     (root_key.objectid, inode objectid, offset in file, 1)
d8d5f3e16d1ae4 Chris Mason        2007-12-11  361   *
5d4f98a28c7d33 Yan Zheng          2009-06-10  362   * When a file extent is removed file truncation, we find the
5d4f98a28c7d33 Yan Zheng          2009-06-10  363   * corresponding implicit back refs and check the following fields:
d8d5f3e16d1ae4 Chris Mason        2007-12-11  364   *
5d4f98a28c7d33 Yan Zheng          2009-06-10  365   *     (btrfs_header_owner(leaf), inode objectid, offset in file)
d8d5f3e16d1ae4 Chris Mason        2007-12-11  366   *
5d4f98a28c7d33 Yan Zheng          2009-06-10  367   * Btree extents can be referenced by:
d8d5f3e16d1ae4 Chris Mason        2007-12-11  368   *
5d4f98a28c7d33 Yan Zheng          2009-06-10  369   * - Different subvolumes
d8d5f3e16d1ae4 Chris Mason        2007-12-11  370   *
5d4f98a28c7d33 Yan Zheng          2009-06-10  371   * Both the implicit back refs and the full back refs for tree blocks
5d4f98a28c7d33 Yan Zheng          2009-06-10  372   * only consist of key. The key offset for the implicit back refs is
5d4f98a28c7d33 Yan Zheng          2009-06-10  373   * objectid of block's owner tree. The key offset for the full back refs
5d4f98a28c7d33 Yan Zheng          2009-06-10  374   * is the first byte of parent block.
d8d5f3e16d1ae4 Chris Mason        2007-12-11  375   *
5d4f98a28c7d33 Yan Zheng          2009-06-10  376   * When implicit back refs is used, information about the lowest key and
5d4f98a28c7d33 Yan Zheng          2009-06-10  377   * level of the tree block are required. These information are stored in
5d4f98a28c7d33 Yan Zheng          2009-06-10  378   * tree block info structure.
d8d5f3e16d1ae4 Chris Mason        2007-12-11  379   */
31840ae1a6b433 Zheng Yan          2008-09-23  380  
167ce953ca55bd Liu Bo             2017-08-18  381  /*
167ce953ca55bd Liu Bo             2017-08-18  382   * is_data == BTRFS_REF_TYPE_BLOCK, tree block type is required,
52042d8e82ff50 Andrea Gelmini     2018-11-28  383   * is_data == BTRFS_REF_TYPE_DATA, data type is requiried,
167ce953ca55bd Liu Bo             2017-08-18  384   * is_data == BTRFS_REF_TYPE_ANY, either type is OK.
167ce953ca55bd Liu Bo             2017-08-18  385   */
167ce953ca55bd Liu Bo             2017-08-18  386  int btrfs_get_extent_inline_ref_type(const struct extent_buffer *eb,
167ce953ca55bd Liu Bo             2017-08-18  387  				     struct btrfs_extent_inline_ref *iref,
167ce953ca55bd Liu Bo             2017-08-18  388  				     enum btrfs_inline_ref_type is_data)
167ce953ca55bd Liu Bo             2017-08-18  389  {
167ce953ca55bd Liu Bo             2017-08-18  390  	int type = btrfs_extent_inline_ref_type(eb, iref);
64ecdb647ddb83 Liu Bo             2017-08-18  391  	u64 offset = btrfs_extent_inline_ref_offset(eb, iref);
167ce953ca55bd Liu Bo             2017-08-18  392  
167ce953ca55bd Liu Bo             2017-08-18  393  	if (type == BTRFS_TREE_BLOCK_REF_KEY ||
167ce953ca55bd Liu Bo             2017-08-18  394  	    type == BTRFS_SHARED_BLOCK_REF_KEY ||
167ce953ca55bd Liu Bo             2017-08-18  395  	    type == BTRFS_SHARED_DATA_REF_KEY ||
167ce953ca55bd Liu Bo             2017-08-18  396  	    type == BTRFS_EXTENT_DATA_REF_KEY) {
167ce953ca55bd Liu Bo             2017-08-18  397  		if (is_data == BTRFS_REF_TYPE_BLOCK) {
64ecdb647ddb83 Liu Bo             2017-08-18  398  			if (type == BTRFS_TREE_BLOCK_REF_KEY)
167ce953ca55bd Liu Bo             2017-08-18  399  				return type;
64ecdb647ddb83 Liu Bo             2017-08-18  400  			if (type == BTRFS_SHARED_BLOCK_REF_KEY) {
64ecdb647ddb83 Liu Bo             2017-08-18  401  				ASSERT(eb->fs_info);
64ecdb647ddb83 Liu Bo             2017-08-18  402  				/*
64ecdb647ddb83 Liu Bo             2017-08-18  403  				 * Every shared one has parent tree
64ecdb647ddb83 Liu Bo             2017-08-18  404  				 * block, which must be aligned to
45e82350ded690 Qu Wenruo          2020-08-26  405  				 * sector size.
64ecdb647ddb83 Liu Bo             2017-08-18  406  				 */
64ecdb647ddb83 Liu Bo             2017-08-18  407  				if (offset &&
45e82350ded690 Qu Wenruo          2020-08-26  408  				    IS_ALIGNED(offset, eb->fs_info->sectorsize))
64ecdb647ddb83 Liu Bo             2017-08-18  409  					return type;
64ecdb647ddb83 Liu Bo             2017-08-18  410  			}
167ce953ca55bd Liu Bo             2017-08-18  411  		} else if (is_data == BTRFS_REF_TYPE_DATA) {
64ecdb647ddb83 Liu Bo             2017-08-18  412  			if (type == BTRFS_EXTENT_DATA_REF_KEY)
167ce953ca55bd Liu Bo             2017-08-18  413  				return type;
64ecdb647ddb83 Liu Bo             2017-08-18  414  			if (type == BTRFS_SHARED_DATA_REF_KEY) {
64ecdb647ddb83 Liu Bo             2017-08-18  415  				ASSERT(eb->fs_info);
64ecdb647ddb83 Liu Bo             2017-08-18  416  				/*
64ecdb647ddb83 Liu Bo             2017-08-18  417  				 * Every shared one has parent tree
64ecdb647ddb83 Liu Bo             2017-08-18  418  				 * block, which must be aligned to
45e82350ded690 Qu Wenruo          2020-08-26  419  				 * sector size.
64ecdb647ddb83 Liu Bo             2017-08-18  420  				 */
64ecdb647ddb83 Liu Bo             2017-08-18  421  				if (offset &&
45e82350ded690 Qu Wenruo          2020-08-26  422  				    IS_ALIGNED(offset, eb->fs_info->sectorsize))
64ecdb647ddb83 Liu Bo             2017-08-18  423  					return type;
64ecdb647ddb83 Liu Bo             2017-08-18  424  			}
167ce953ca55bd Liu Bo             2017-08-18  425  		} else {
167ce953ca55bd Liu Bo             2017-08-18  426  			ASSERT(is_data == BTRFS_REF_TYPE_ANY);
167ce953ca55bd Liu Bo             2017-08-18  427  			return type;
167ce953ca55bd Liu Bo             2017-08-18  428  		}
167ce953ca55bd Liu Bo             2017-08-18  429  	}
167ce953ca55bd Liu Bo             2017-08-18  430  
167ce953ca55bd Liu Bo             2017-08-18  431  	btrfs_print_leaf((struct extent_buffer *)eb);
45e82350ded690 Qu Wenruo          2020-08-26 @432  	btrfs_err(eb->fs_info,
45e82350ded690 Qu Wenruo          2020-08-26  433  		  "eb %llu iref 0x%lu invalid extent inline ref type %d",
45e82350ded690 Qu Wenruo          2020-08-26  434  		  eb->start, (unsigned long)iref, type);
167ce953ca55bd Liu Bo             2017-08-18  435  	WARN_ON(1);
167ce953ca55bd Liu Bo             2017-08-18  436  
167ce953ca55bd Liu Bo             2017-08-18  437  	return BTRFS_REF_TYPE_INVALID;
167ce953ca55bd Liu Bo             2017-08-18  438  }
167ce953ca55bd Liu Bo             2017-08-18  439  

---
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: 40919 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2] btrfs: Only require sector size alignment for parent eb bytenr
  2020-08-26  9:26 Qu Wenruo
@ 2020-08-26 14:18 ` Josef Bacik
  2020-08-26 22:51   ` Qu Wenruo
  2020-09-03 11:44 ` David Sterba
  2020-09-03 11:53 ` David Sterba
  2 siblings, 1 reply; 10+ messages in thread
From: Josef Bacik @ 2020-08-26 14:18 UTC (permalink / raw)
  To: Qu Wenruo, linux-btrfs

On 8/26/20 5:26 AM, Qu Wenruo wrote:
> [BUG]
> A completely sane converted fs will cause kernel warning at balance
> time:
> 
> [ 1557.188633] BTRFS info (device sda7): relocating block group 8162107392 flags data
> [ 1563.358078] BTRFS info (device sda7): found 11722 extents
> [ 1563.358277] BTRFS info (device sda7): leaf 7989321728 gen 95 total ptrs 213 free space 3458 owner 2
> [ 1563.358280] 	item 0 key (7984947200 169 0) itemoff 16250 itemsize 33
> [ 1563.358281] 		extent refs 1 gen 90 flags 2
> [ 1563.358282] 		ref#0: tree block backref root 4
> [ 1563.358285] 	item 1 key (7985602560 169 0) itemoff 16217 itemsize 33
> [ 1563.358286] 		extent refs 1 gen 93 flags 258
> [ 1563.358287] 		ref#0: shared block backref parent 7985602560
> [ 1563.358288] 			(parent 7985602560 is NOT ALIGNED to nodesize 16384)
> [ 1563.358290] 	item 2 key (7985635328 169 0) itemoff 16184 itemsize 33
> ...
> [ 1563.358995] BTRFS error (device sda7): eb 7989321728 invalid extent inline ref type 182
> [ 1563.358996] ------------[ cut here ]------------
> [ 1563.359005] WARNING: CPU: 14 PID: 2930 at 0xffffffff9f231766
> 
> Then with transaction abort, and obviously failed to balance the fs.
> 
> [CAUSE]
> That mentioned inline ref type 182 is completely sane, it's
> BTRFS_SHARED_BLOCK_REF_KEY, it's some extra check making kernel to
> believe it's invalid.
> 
> Commit 64ecdb647ddb ("Btrfs: add one more sanity check for shared ref
> type") introduced extra checks for backref type.
> 
> One of the requirement is, parent bytenr must be aligned to node size,
> which is not correct.
> 
> One example is like this:
> 
> 0	1G  1G+4K		2G 2G+4K
> 	|   |///////////////////|//|  <- A chunk starts at 1G+4K
>              |   |	<- A tree block get reserved at bytenr 1G+4K
> 

This only happens with convert right?  Can we just fix convert to not do this? 
Thanks,

Josef

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v2] btrfs: Only require sector size alignment for parent eb bytenr
@ 2020-08-26  9:26 Qu Wenruo
  2020-08-26 14:18 ` Josef Bacik
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Qu Wenruo @ 2020-08-26  9:26 UTC (permalink / raw)
  To: linux-btrfs

[BUG]
A completely sane converted fs will cause kernel warning at balance
time:

[ 1557.188633] BTRFS info (device sda7): relocating block group 8162107392 flags data
[ 1563.358078] BTRFS info (device sda7): found 11722 extents
[ 1563.358277] BTRFS info (device sda7): leaf 7989321728 gen 95 total ptrs 213 free space 3458 owner 2
[ 1563.358280] 	item 0 key (7984947200 169 0) itemoff 16250 itemsize 33
[ 1563.358281] 		extent refs 1 gen 90 flags 2
[ 1563.358282] 		ref#0: tree block backref root 4
[ 1563.358285] 	item 1 key (7985602560 169 0) itemoff 16217 itemsize 33
[ 1563.358286] 		extent refs 1 gen 93 flags 258
[ 1563.358287] 		ref#0: shared block backref parent 7985602560
[ 1563.358288] 			(parent 7985602560 is NOT ALIGNED to nodesize 16384)
[ 1563.358290] 	item 2 key (7985635328 169 0) itemoff 16184 itemsize 33
...
[ 1563.358995] BTRFS error (device sda7): eb 7989321728 invalid extent inline ref type 182
[ 1563.358996] ------------[ cut here ]------------
[ 1563.359005] WARNING: CPU: 14 PID: 2930 at 0xffffffff9f231766

Then with transaction abort, and obviously failed to balance the fs.

[CAUSE]
That mentioned inline ref type 182 is completely sane, it's
BTRFS_SHARED_BLOCK_REF_KEY, it's some extra check making kernel to
believe it's invalid.

Commit 64ecdb647ddb ("Btrfs: add one more sanity check for shared ref
type") introduced extra checks for backref type.

One of the requirement is, parent bytenr must be aligned to node size,
which is not correct.

One example is like this:

0	1G  1G+4K		2G 2G+4K
	|   |///////////////////|//|  <- A chunk starts at 1G+4K
            |   |	<- A tree block get reserved at bytenr 1G+4K

Then we have a valid tree block at bytenr 1G+4K, but not aligned to
nodesize (16K).

Such chunk is not ideal, but current kernel can handle it pretty well.
We may warn about such tree block in the future, but not reject them.

[FIX]
Change the alignment requirement from node size alignment to sector size
alignment.

Also, to make our lives a little easier, also output @iref when
btrfs_get_extent_inline_ref_type() failed, so we can locate the item
easier.

Link: https://bugzilla.kernel.org/show_bug.cgi?id=205475
Fixes: 64ecdb647ddb ("Btrfs: add one more sanity check for shared ref type")
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
Changelog:
v2:
- Make the commit message more clear on how such case is caused
  The only reason is converted fs, which could create chunk starts at
  sector aligned only bytenr.
---
 fs/btrfs/extent-tree.c | 13 +++++++------
 fs/btrfs/print-tree.c  | 12 +++++++-----
 2 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 73973e6e8ba6..068755468472 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -402,10 +402,10 @@ int btrfs_get_extent_inline_ref_type(const struct extent_buffer *eb,
 				/*
 				 * Every shared one has parent tree
 				 * block, which must be aligned to
-				 * nodesize.
+				 * sector size.
 				 */
 				if (offset &&
-				    IS_ALIGNED(offset, eb->fs_info->nodesize))
+				    IS_ALIGNED(offset, eb->fs_info->sectorsize))
 					return type;
 			}
 		} else if (is_data == BTRFS_REF_TYPE_DATA) {
@@ -416,10 +416,10 @@ int btrfs_get_extent_inline_ref_type(const struct extent_buffer *eb,
 				/*
 				 * Every shared one has parent tree
 				 * block, which must be aligned to
-				 * nodesize.
+				 * sector size.
 				 */
 				if (offset &&
-				    IS_ALIGNED(offset, eb->fs_info->nodesize))
+				    IS_ALIGNED(offset, eb->fs_info->sectorsize))
 					return type;
 			}
 		} else {
@@ -429,8 +429,9 @@ int btrfs_get_extent_inline_ref_type(const struct extent_buffer *eb,
 	}
 
 	btrfs_print_leaf((struct extent_buffer *)eb);
-	btrfs_err(eb->fs_info, "eb %llu invalid extent inline ref type %d",
-		  eb->start, type);
+	btrfs_err(eb->fs_info,
+		  "eb %llu iref 0x%lu invalid extent inline ref type %d",
+		  eb->start, (unsigned long)iref, type);
 	WARN_ON(1);
 
 	return BTRFS_REF_TYPE_INVALID;
diff --git a/fs/btrfs/print-tree.c b/fs/btrfs/print-tree.c
index 61f44e78e3c9..68138e14f039 100644
--- a/fs/btrfs/print-tree.c
+++ b/fs/btrfs/print-tree.c
@@ -95,9 +95,10 @@ static void print_extent_item(struct extent_buffer *eb, int slot, int type)
 			 * offset is supposed to be a tree block which
 			 * must be aligned to nodesize.
 			 */
-			if (!IS_ALIGNED(offset, eb->fs_info->nodesize))
-				pr_info("\t\t\t(parent %llu is NOT ALIGNED to nodesize %llu)\n",
-					offset, (unsigned long long)eb->fs_info->nodesize);
+			if (!IS_ALIGNED(offset, eb->fs_info->sectorsize))
+				pr_info(
+		"\t\t\t(parent %llu is NOT ALIGNED to sectorsize %u)\n",
+					offset, eb->fs_info->sectorsize);
 			break;
 		case BTRFS_EXTENT_DATA_REF_KEY:
 			dref = (struct btrfs_extent_data_ref *)(&iref->offset);
@@ -112,8 +113,9 @@ static void print_extent_item(struct extent_buffer *eb, int slot, int type)
 			 * must be aligned to nodesize.
 			 */
 			if (!IS_ALIGNED(offset, eb->fs_info->nodesize))
-				pr_info("\t\t\t(parent %llu is NOT ALIGNED to nodesize %llu)\n",
-				     offset, (unsigned long long)eb->fs_info->nodesize);
+				pr_info(
+		"\t\t\t(parent %llu is NOT ALIGNED to sectorsize %u)\n",
+				     offset, eb->fs_info->sectorsize);
 			break;
 		default:
 			pr_cont("(extent %llu has INVALID ref type %d)\n",
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2020-09-03 11:55 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-26  5:54 [PATCH v2] btrfs: Only require sector size alignment for parent eb bytenr Qu Wenruo
2020-04-03  8:11 ` Dan Carpenter
2020-04-03  8:11   ` Dan Carpenter
2020-04-03  8:11   ` Dan Carpenter
2020-08-26  9:26 Qu Wenruo
2020-08-26 14:18 ` Josef Bacik
2020-08-26 22:51   ` Qu Wenruo
2020-09-03 11:44 ` David Sterba
2020-09-03 11:53 ` David Sterba
2020-08-26 18:51 kernel test robot

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.