mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v3] fs/buffer: remove the min and max limit checks in __getblk_slow()
@ 2025-06-25  8:37 Pankaj Raghav
  2025-06-25 10:16 ` Jan Kara
  0 siblings, 1 reply; 4+ messages in thread
From: Pankaj Raghav @ 2025-06-25  8:37 UTC (permalink / raw)
  To: Alexander Viro, Jan Kara, mcgrof, Christian Brauner
  Cc: kernel, linux-fsdevel, linux-kernel, gost.dev, Pankaj Raghav,
	Matthew Wilcox

All filesystems will already check the max and min value of their block
size during their initialization. __getblk_slow() is a very low-level
function to have these checks. Remove them and only check for logical
block size alignment.

Suggested-by: Matthew Wilcox <willy@infradead.org>
Signed-off-by: Pankaj Raghav <p.raghav@samsung.com>
---
Changes since v2:
- Removed the max and min checks in __getblk_slow().

 fs/buffer.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/fs/buffer.c b/fs/buffer.c
index a14d281c6a74..a1aa01ebc0ce 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -1122,13 +1122,9 @@ __getblk_slow(struct block_device *bdev, sector_t block,
 {
 	bool blocking = gfpflags_allow_blocking(gfp);
 
-	if (unlikely(size & (bdev_logical_block_size(bdev) - 1) ||
-		     (size < 512 || size > PAGE_SIZE))) {
-		printk(KERN_ERR "getblk(): invalid block size %d requested\n",
-					size);
-		printk(KERN_ERR "logical block size: %d\n",
-					bdev_logical_block_size(bdev));
-
+	if (unlikely(size & (bdev_logical_block_size(bdev) - 1))) {
+		printk(KERN_ERR "getblk(): block size %d not aligned to logical block size %d\n",
+		       size, bdev_logical_block_size(bdev));
 		dump_stack();
 		return NULL;
 	}

base-commit: 6ae58121126dcf8efcc2611f216a36a5e50b8ad9
-- 
2.49.0


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

* Re: [PATCH v3] fs/buffer: remove the min and max limit checks in __getblk_slow()
  2025-06-25  8:37 [PATCH v3] fs/buffer: remove the min and max limit checks in __getblk_slow() Pankaj Raghav
@ 2025-06-25 10:16 ` Jan Kara
  2025-06-25 10:53   ` Pankaj Raghav (Samsung)
  0 siblings, 1 reply; 4+ messages in thread
From: Jan Kara @ 2025-06-25 10:16 UTC (permalink / raw)
  To: Pankaj Raghav
  Cc: Alexander Viro, Jan Kara, mcgrof, Christian Brauner, kernel,
	linux-fsdevel, linux-kernel, gost.dev, Matthew Wilcox

On Wed 25-06-25 10:37:04, Pankaj Raghav wrote:
> All filesystems will already check the max and min value of their block
> size during their initialization. __getblk_slow() is a very low-level
> function to have these checks. Remove them and only check for logical
> block size alignment.
> 
> Suggested-by: Matthew Wilcox <willy@infradead.org>
> Signed-off-by: Pankaj Raghav <p.raghav@samsung.com>

I know this is a bikeshedding but FWIW this is in the should never trigger
territory so I'd be inclined to just make it WARN_ON_ONCE() and completely
delete it once we refactor bh apis to make sure nobody can call bh
functions with anything else than sb->s_blocksize.

								Honza

> ---
> Changes since v2:
> - Removed the max and min checks in __getblk_slow().
> 
>  fs/buffer.c | 10 +++-------
>  1 file changed, 3 insertions(+), 7 deletions(-)
> 
> diff --git a/fs/buffer.c b/fs/buffer.c
> index a14d281c6a74..a1aa01ebc0ce 100644
> --- a/fs/buffer.c
> +++ b/fs/buffer.c
> @@ -1122,13 +1122,9 @@ __getblk_slow(struct block_device *bdev, sector_t block,
>  {
>  	bool blocking = gfpflags_allow_blocking(gfp);
>  
> -	if (unlikely(size & (bdev_logical_block_size(bdev) - 1) ||
> -		     (size < 512 || size > PAGE_SIZE))) {
> -		printk(KERN_ERR "getblk(): invalid block size %d requested\n",
> -					size);
> -		printk(KERN_ERR "logical block size: %d\n",
> -					bdev_logical_block_size(bdev));
> -
> +	if (unlikely(size & (bdev_logical_block_size(bdev) - 1))) {
> +		printk(KERN_ERR "getblk(): block size %d not aligned to logical block size %d\n",
> +		       size, bdev_logical_block_size(bdev));
>  		dump_stack();
>  		return NULL;
>  	}
> 
> base-commit: 6ae58121126dcf8efcc2611f216a36a5e50b8ad9
> -- 
> 2.49.0
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

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

* Re: [PATCH v3] fs/buffer: remove the min and max limit checks in __getblk_slow()
  2025-06-25 10:16 ` Jan Kara
@ 2025-06-25 10:53   ` Pankaj Raghav (Samsung)
  2025-06-26  7:19     ` Jan Kara
  0 siblings, 1 reply; 4+ messages in thread
From: Pankaj Raghav (Samsung) @ 2025-06-25 10:53 UTC (permalink / raw)
  To: Jan Kara
  Cc: Pankaj Raghav, Alexander Viro, mcgrof, Christian Brauner,
	linux-fsdevel, linux-kernel, gost.dev, Matthew Wilcox

On Wed, Jun 25, 2025 at 12:16:49PM +0200, Jan Kara wrote:
> On Wed 25-06-25 10:37:04, Pankaj Raghav wrote:
> > All filesystems will already check the max and min value of their block
> > size during their initialization. __getblk_slow() is a very low-level
> > function to have these checks. Remove them and only check for logical
> > block size alignment.
> > 
> > Suggested-by: Matthew Wilcox <willy@infradead.org>
> > Signed-off-by: Pankaj Raghav <p.raghav@samsung.com>
> 
> I know this is a bikeshedding but FWIW this is in the should never trigger
> territory so I'd be inclined to just make it WARN_ON_ONCE() and completely
> delete it once we refactor bh apis to make sure nobody can call bh
> functions with anything else than sb->s_blocksize.
> 
Something like this:

diff --git a/fs/buffer.c b/fs/buffer.c
index a1aa01ebc0ce..a49b4be37c62 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -1122,10 +1122,9 @@ __getblk_slow(struct block_device *bdev, sector_t block,
 {
        bool blocking = gfpflags_allow_blocking(gfp);
 
-       if (unlikely(size & (bdev_logical_block_size(bdev) - 1))) {
+       if (WARN_ON_ONCE(size & (bdev_logical_block_size(bdev) - 1))) {
                printk(KERN_ERR "getblk(): block size %d not aligned to logical block size %d\n",
                       size, bdev_logical_block_size(bdev));
-               dump_stack();
                return NULL;
        }

I assume we don't need the dump_stack() anymore as we will print them
with WARN_ON_ONCE anyway?

--
Pankaj

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

* Re: [PATCH v3] fs/buffer: remove the min and max limit checks in __getblk_slow()
  2025-06-25 10:53   ` Pankaj Raghav (Samsung)
@ 2025-06-26  7:19     ` Jan Kara
  0 siblings, 0 replies; 4+ messages in thread
From: Jan Kara @ 2025-06-26  7:19 UTC (permalink / raw)
  To: Pankaj Raghav (Samsung)
  Cc: Jan Kara, Pankaj Raghav, Alexander Viro, mcgrof,
	Christian Brauner, linux-fsdevel, linux-kernel, gost.dev,
	Matthew Wilcox

On Wed 25-06-25 12:53:54, Pankaj Raghav (Samsung) wrote:
> On Wed, Jun 25, 2025 at 12:16:49PM +0200, Jan Kara wrote:
> > On Wed 25-06-25 10:37:04, Pankaj Raghav wrote:
> > > All filesystems will already check the max and min value of their block
> > > size during their initialization. __getblk_slow() is a very low-level
> > > function to have these checks. Remove them and only check for logical
> > > block size alignment.
> > > 
> > > Suggested-by: Matthew Wilcox <willy@infradead.org>
> > > Signed-off-by: Pankaj Raghav <p.raghav@samsung.com>
> > 
> > I know this is a bikeshedding but FWIW this is in the should never trigger
> > territory so I'd be inclined to just make it WARN_ON_ONCE() and completely
> > delete it once we refactor bh apis to make sure nobody can call bh
> > functions with anything else than sb->s_blocksize.
> > 
> Something like this:
> 
> diff --git a/fs/buffer.c b/fs/buffer.c
> index a1aa01ebc0ce..a49b4be37c62 100644
> --- a/fs/buffer.c
> +++ b/fs/buffer.c
> @@ -1122,10 +1122,9 @@ __getblk_slow(struct block_device *bdev, sector_t block,
>  {
>         bool blocking = gfpflags_allow_blocking(gfp);
>  
> -       if (unlikely(size & (bdev_logical_block_size(bdev) - 1))) {
> +       if (WARN_ON_ONCE(size & (bdev_logical_block_size(bdev) - 1))) {
>                 printk(KERN_ERR "getblk(): block size %d not aligned to logical block size %d\n",
>                        size, bdev_logical_block_size(bdev));
> -               dump_stack();
>                 return NULL;
>         }
> 
> I assume we don't need the dump_stack() anymore as we will print them
> with WARN_ON_ONCE anyway?

Correct. Thanks! Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

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

end of thread, other threads:[~2025-06-26  7:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-06-25  8:37 [PATCH v3] fs/buffer: remove the min and max limit checks in __getblk_slow() Pankaj Raghav
2025-06-25 10:16 ` Jan Kara
2025-06-25 10:53   ` Pankaj Raghav (Samsung)
2025-06-26  7:19     ` Jan Kara

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®