Skip to contentSkip to conversation

squashfs: avoid bio_alloc() failure with 1Mbyte blocks

PATCH Applied Phillip Lougher 3 participants 3 messages Aug 15, 2020 – Aug 19, 2020 SquashFS file system

lore
Share & tools
lore

Phillip Lougher

author maintainer
#0 lore raw

PATCH 1/1 squashfs: avoid bio_alloc() failure with 1Mbyte blocks

This is a regression introduced by the "migrate from ll_rw_block usage to BIO" patch.

Bio_alloc() is limited to 256 pages (1 Mbyte). This can cause a
failure when reading 1 Mbyte block filesystems. The problem is a datablock can be fully (or almost uncompressed), requiring 256 pages, but, because blocks are not aligned to page boundaries, it may require 257 pages to read.

Bio_kmalloc() can handle 1024 pages, and so use this for the edge condition.

---
 fs/squashfs/block.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
fs/squashfs/block.c +5 -1
index 76bb1c846845..8a19773b5a0b 100644
@@ -87,7 +87,11 @@ static int squashfs_bio_read(struct super_block *sb, u64 index, int length,
 	int error, i;
 	struct bio *bio;
 
-	bio = bio_alloc(GFP_NOIO, page_count);
+	if (page_count <= BIO_MAX_PAGES)
+		bio = bio_alloc(GFP_NOIO, page_count);
+	else
+		bio = bio_kmalloc(GFP_NOIO, page_count);
+
 	if (!bio)
 		return -ENOMEM;
 
Signature · 1 line
2.20.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Phillip Lougher

This is a regression introduced by the "migrate from ll_rw_block usage to BIO" patch.

Bio_alloc() is limited to 256 pages (1 Mbyte). This can cause a
failure when reading 1 Mbyte block filesystems. The problem is a datablock can be fully (or almost uncompressed), requiring 256 pages, but, because blocks are not aligned to page boundaries, it may require 257 pages to read.

Quoted 6 lines

Bio_kmalloc() can handle 1024 pages, and so use this for the edge condition.

Fixes 93e72b3c612a ("squashfs: migrate from ll_rw_block usage to BIO")
Quoted 24 lines
---
 fs/squashfs/block.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
fs/squashfs/block.c +5 -2
index 76bb1c846845..8a19773b5a0b 100644
@@ -87,7 +87,11 @@ static int squashfs_bio_read(struct super_block *sb, u64 index, int length,
        int error, i;
        struct bio *bio;
 
-       bio = bio_alloc(GFP_NOIO, page_count);
+       if (page_count <= BIO_MAX_PAGES)
+               bio = bio_alloc(GFP_NOIO, page_count);
+       else
+               bio = bio_kmalloc(GFP_NOIO, page_count);
+
        if (!bio)
                return -ENOMEM;
 
--

2.20.1

#2 lore raw
Quoted 14 lines · On Fri, 14 Aug 2020 21:30:33 -0700 Guenter Roeck <[email protected]> wrote:
Quoted 13 lines · Phillip Lougher

This is a regression introduced by the "migrate from ll_rw_block usage to BIO" patch.

Bio_alloc() is limited to 256 pages (1 Mbyte). This can cause a
failure when reading 1 Mbyte block filesystems. The problem is a datablock can be fully (or almost uncompressed), requiring 256 pages, but, because blocks are not aligned to page boundaries, it may require 257 pages to read.

Bio_kmalloc() can handle 1024 pages, and so use this for the edge condition.

Quoted 6 lines
Quoted 3 lines
Fixes 93e72b3c612a ("squashfs: migrate from ll_rw_block usage to BIO")

Thanks. I added cc:stable also.