All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] squashfs: avoid bio_alloc() failure with 1Mbyte blocks
@ 2020-08-15  3:56 Phillip Lougher
  2020-08-15  4:30 ` Guenter Roeck
  0 siblings, 1 reply; 3+ messages in thread
From: Phillip Lougher @ 2020-08-15  3:56 UTC (permalink / raw)
  To: linux-kernel
  Cc: akpm, pliard, hch, adrien+dev, groeck, drosen, Phillip Lougher,
	Nicolas Prochazka, Tomoatsu Shimada

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.

Reported-by: Nicolas Prochazka <nicolas.prochazka@gmail.com>
Reported-by: Tomoatsu Shimada <shimada@walbrix.com>
Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
---
 fs/squashfs/block.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/fs/squashfs/block.c b/fs/squashfs/block.c
index 76bb1c846845..8a19773b5a0b 100644
--- a/fs/squashfs/block.c
+++ b/fs/squashfs/block.c
@@ -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


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

* Re: [PATCH] squashfs: avoid bio_alloc() failure with 1Mbyte blocks
  2020-08-15  3:56 [PATCH] squashfs: avoid bio_alloc() failure with 1Mbyte blocks Phillip Lougher
@ 2020-08-15  4:30 ` Guenter Roeck
  2020-08-19  3:13   ` Andrew Morton
  0 siblings, 1 reply; 3+ messages in thread
From: Guenter Roeck @ 2020-08-15  4:30 UTC (permalink / raw)
  To: Phillip Lougher
  Cc: linux-kernel, Andrew Morton, Philippe Liard, hch, adrien+dev,
	Guenter Roeck, Daniel Rosenberg, Nicolas Prochazka,
	Tomoatsu Shimada

On Fri, Aug 14, 2020 at 8:57 PM Phillip Lougher <phillip@squashfs.org.uk> wrote:
>
> 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.
>
> Reported-by: Nicolas Prochazka <nicolas.prochazka@gmail.com>
> Reported-by: Tomoatsu Shimada <shimada@walbrix.com>
> Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>

Fixes: 93e72b3c612a ("squashfs: migrate from ll_rw_block usage to BIO")
Reviewed-by: Guenter Roeck <groeck@chromium.org>

> ---
>  fs/squashfs/block.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/fs/squashfs/block.c b/fs/squashfs/block.c
> index 76bb1c846845..8a19773b5a0b 100644
> --- a/fs/squashfs/block.c
> +++ b/fs/squashfs/block.c
> @@ -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
>

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

* Re: [PATCH] squashfs: avoid bio_alloc() failure with 1Mbyte blocks
  2020-08-15  4:30 ` Guenter Roeck
@ 2020-08-19  3:13   ` Andrew Morton
  0 siblings, 0 replies; 3+ messages in thread
From: Andrew Morton @ 2020-08-19  3:13 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: Phillip Lougher, linux-kernel, Philippe Liard, hch, adrien+dev,
	Guenter Roeck, Daniel Rosenberg, Nicolas Prochazka,
	Tomoatsu Shimada

On Fri, 14 Aug 2020 21:30:33 -0700 Guenter Roeck <groeck@google.com> wrote:

> On Fri, Aug 14, 2020 at 8:57 PM Phillip Lougher <phillip@squashfs.org.uk> wrote:
> >
> > 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.
> >
> > Reported-by: Nicolas Prochazka <nicolas.prochazka@gmail.com>
> > Reported-by: Tomoatsu Shimada <shimada@walbrix.com>
> > Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
> 
> Fixes: 93e72b3c612a ("squashfs: migrate from ll_rw_block usage to BIO")
> Reviewed-by: Guenter Roeck <groeck@chromium.org>

Thanks.  I added cc:stable also.

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

end of thread, other threads:[~2020-08-19  3:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-15  3:56 [PATCH] squashfs: avoid bio_alloc() failure with 1Mbyte blocks Phillip Lougher
2020-08-15  4:30 ` Guenter Roeck
2020-08-19  3:13   ` Andrew Morton

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.