All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH U-boot v2] fs: btrfs: fix the false alert of decompression failure
@ 2021-04-17 12:52 ` Qu Wenruo
  0 siblings, 0 replies; 4+ messages in thread
From: Qu Wenruo @ 2021-04-17 12:52 UTC (permalink / raw)
  To: u-boot; +Cc: linux-btrfs, Matwey Kornilov

There are some cases where decompressed sectors can have padding zeros.

In kernel code, we have lines to address such situation:

        /*
         * btrfs_getblock is doing a zero on the tail of the page too,
         * but this will cover anything missing from the decompressed
         * data.
         */
        if (bytes < destlen)
                memset(kaddr+bytes, 0, destlen-bytes);
        kunmap_local(kaddr);

But not in U-boot code, thus we have some reports of U-boot failed to
read compressed files in btrfs.

Fix it by doing the same thing of the kernel, for both inline and
regular compressed extents.

Reported-by: Matwey Kornilov <matwey.kornilov@gmail.com>
Link: https://bugzilla.suse.com/show_bug.cgi?id=1183717
Fixes: a26a6bedafcf ("fs: btrfs: Introduce btrfs_read_extent_inline() and btrfs_read_extent_reg()")
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
Changelog:
v2:
- Fix the bug for regular and inline compressed extents
---
 fs/btrfs/inode.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 019d532a1a4b..2c2379303d74 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -390,10 +390,16 @@ int btrfs_read_extent_inline(struct btrfs_path *path,
 			   csize);
 	ret = btrfs_decompress(btrfs_file_extent_compression(leaf, fi),
 			       cbuf, csize, dbuf, dsize);
-	if (ret < 0 || ret != dsize) {
+	if (ret == (u32)-1) {
 		ret = -EIO;
 		goto out;
 	}
+	/*
+	 * The compressed part ends before sector boundary, the remaining needs
+	 * to be zeroed out.
+	 */
+	if (ret < dsize)
+		memset(dbuf + ret, 0, dsize - ret);
 	memcpy(dest, dbuf, dsize);
 	ret = dsize;
 out:
@@ -494,10 +500,16 @@ int btrfs_read_extent_reg(struct btrfs_path *path,
 
 	ret = btrfs_decompress(btrfs_file_extent_compression(leaf, fi), cbuf,
 			       csize, dbuf, dsize);
-	if (ret != dsize) {
+	if (ret == (u32)-1) {
 		ret = -EIO;
 		goto out;
 	}
+	/*
+	 * The compressed part ends before sector boundary, the remaining needs
+	 * to be zeroed out.
+	 */
+	if (ret < dsize)
+		memset(dbuf + ret, 0, dsize - ret);
 	/* Then copy the needed part */
 	memcpy(dest, dbuf + btrfs_file_extent_offset(leaf, fi), len);
 	ret = len;
-- 
2.31.1


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

* [PATCH U-boot v2] fs: btrfs: fix the false alert of decompression failure
@ 2021-04-17 12:52 ` Qu Wenruo
  0 siblings, 0 replies; 4+ messages in thread
From: Qu Wenruo @ 2021-04-17 12:52 UTC (permalink / raw)
  To: u-boot

There are some cases where decompressed sectors can have padding zeros.

In kernel code, we have lines to address such situation:

        /*
         * btrfs_getblock is doing a zero on the tail of the page too,
         * but this will cover anything missing from the decompressed
         * data.
         */
        if (bytes < destlen)
                memset(kaddr+bytes, 0, destlen-bytes);
        kunmap_local(kaddr);

But not in U-boot code, thus we have some reports of U-boot failed to
read compressed files in btrfs.

Fix it by doing the same thing of the kernel, for both inline and
regular compressed extents.

Reported-by: Matwey Kornilov <matwey.kornilov@gmail.com>
Link: https://bugzilla.suse.com/show_bug.cgi?id=1183717
Fixes: a26a6bedafcf ("fs: btrfs: Introduce btrfs_read_extent_inline() and btrfs_read_extent_reg()")
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
Changelog:
v2:
- Fix the bug for regular and inline compressed extents
---
 fs/btrfs/inode.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 019d532a1a4b..2c2379303d74 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -390,10 +390,16 @@ int btrfs_read_extent_inline(struct btrfs_path *path,
 			   csize);
 	ret = btrfs_decompress(btrfs_file_extent_compression(leaf, fi),
 			       cbuf, csize, dbuf, dsize);
-	if (ret < 0 || ret != dsize) {
+	if (ret == (u32)-1) {
 		ret = -EIO;
 		goto out;
 	}
+	/*
+	 * The compressed part ends before sector boundary, the remaining needs
+	 * to be zeroed out.
+	 */
+	if (ret < dsize)
+		memset(dbuf + ret, 0, dsize - ret);
 	memcpy(dest, dbuf, dsize);
 	ret = dsize;
 out:
@@ -494,10 +500,16 @@ int btrfs_read_extent_reg(struct btrfs_path *path,
 
 	ret = btrfs_decompress(btrfs_file_extent_compression(leaf, fi), cbuf,
 			       csize, dbuf, dsize);
-	if (ret != dsize) {
+	if (ret == (u32)-1) {
 		ret = -EIO;
 		goto out;
 	}
+	/*
+	 * The compressed part ends before sector boundary, the remaining needs
+	 * to be zeroed out.
+	 */
+	if (ret < dsize)
+		memset(dbuf + ret, 0, dsize - ret);
 	/* Then copy the needed part */
 	memcpy(dest, dbuf + btrfs_file_extent_offset(leaf, fi), len);
 	ret = len;
-- 
2.31.1

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

* Re: [PATCH U-boot v2] fs: btrfs: fix the false alert of decompression failure
  2021-04-17 12:52 ` Qu Wenruo
@ 2021-04-27 16:46   ` Tom Rini
  -1 siblings, 0 replies; 4+ messages in thread
From: Tom Rini @ 2021-04-27 16:46 UTC (permalink / raw)
  To: Qu Wenruo; +Cc: u-boot, linux-btrfs, Matwey Kornilov

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

On Sat, Apr 17, 2021 at 08:52:13PM +0800, Qu Wenruo wrote:

> There are some cases where decompressed sectors can have padding zeros.
> 
> In kernel code, we have lines to address such situation:
> 
>         /*
>          * btrfs_getblock is doing a zero on the tail of the page too,
>          * but this will cover anything missing from the decompressed
>          * data.
>          */
>         if (bytes < destlen)
>                 memset(kaddr+bytes, 0, destlen-bytes);
>         kunmap_local(kaddr);
> 
> But not in U-boot code, thus we have some reports of U-boot failed to
> read compressed files in btrfs.
> 
> Fix it by doing the same thing of the kernel, for both inline and
> regular compressed extents.
> 
> Reported-by: Matwey Kornilov <matwey.kornilov@gmail.com>
> Link: https://bugzilla.suse.com/show_bug.cgi?id=1183717
> Fixes: a26a6bedafcf ("fs: btrfs: Introduce btrfs_read_extent_inline() and btrfs_read_extent_reg()")
> Signed-off-by: Qu Wenruo <wqu@suse.com>

Applied to u-boot/master, thanks!

-- 
Tom

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]

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

* [PATCH U-boot v2] fs: btrfs: fix the false alert of decompression failure
@ 2021-04-27 16:46   ` Tom Rini
  0 siblings, 0 replies; 4+ messages in thread
From: Tom Rini @ 2021-04-27 16:46 UTC (permalink / raw)
  To: u-boot

On Sat, Apr 17, 2021 at 08:52:13PM +0800, Qu Wenruo wrote:

> There are some cases where decompressed sectors can have padding zeros.
> 
> In kernel code, we have lines to address such situation:
> 
>         /*
>          * btrfs_getblock is doing a zero on the tail of the page too,
>          * but this will cover anything missing from the decompressed
>          * data.
>          */
>         if (bytes < destlen)
>                 memset(kaddr+bytes, 0, destlen-bytes);
>         kunmap_local(kaddr);
> 
> But not in U-boot code, thus we have some reports of U-boot failed to
> read compressed files in btrfs.
> 
> Fix it by doing the same thing of the kernel, for both inline and
> regular compressed extents.
> 
> Reported-by: Matwey Kornilov <matwey.kornilov@gmail.com>
> Link: https://bugzilla.suse.com/show_bug.cgi?id=1183717
> Fixes: a26a6bedafcf ("fs: btrfs: Introduce btrfs_read_extent_inline() and btrfs_read_extent_reg()")
> Signed-off-by: Qu Wenruo <wqu@suse.com>

Applied to u-boot/master, thanks!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210427/fb1903d9/attachment.sig>

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

end of thread, other threads:[~2021-04-27 16:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-17 12:52 [PATCH U-boot v2] fs: btrfs: fix the false alert of decompression failure Qu Wenruo
2021-04-17 12:52 ` Qu Wenruo
2021-04-27 16:46 ` Tom Rini
2021-04-27 16:46   ` Tom Rini

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.