public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] block: fix adding folio to bio
@ 2025-03-12 11:38 Ming Lei
  2025-03-12 12:19 ` Matthew Wilcox
  0 siblings, 1 reply; 3+ messages in thread
From: Ming Lei @ 2025-03-12 11:38 UTC (permalink / raw)
  To: Jens Axboe, linux-block
  Cc: Ming Lei, Kundan Kumar, Matthew Wilcox (Oracle),
	Christoph Hellwig, Luis Chamberlain, Gavin Shan

>4GB folio is possible on some ARCHs, such as aarch64, 16GB hugepage
is supported, then 'offset' of folio can't be held in 'unsigned int',
cause warning in bio_add_folio_nofail() and IO failure.

Fix it by adjusting 'page' & 'offset' so that 'offset' can be stored
in 'unsigned int'.

Fixes: ed9832bc08db ("block: introduce folio awareness and add a bigger size from folio")
Cc: Kundan Kumar <kundan.kumar@samsung.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Luis Chamberlain <mcgrof@kernel.org>
Cc: Gavin Shan <gshan@redhat.com>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
 block/bio.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/block/bio.c b/block/bio.c
index f0c416e5931d..dd61d783717f 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -1026,9 +1026,17 @@ EXPORT_SYMBOL(bio_add_page);
 void bio_add_folio_nofail(struct bio *bio, struct folio *folio, size_t len,
 			  size_t off)
 {
+	struct page *page = &folio->page;
+
 	WARN_ON_ONCE(len > UINT_MAX);
-	WARN_ON_ONCE(off > UINT_MAX);
-	__bio_add_page(bio, &folio->page, len, off);
+	if (unlikely(off > UINT_MAX)) {
+		unsigned long nr = off / PAGE_SIZE;
+
+		page = folio_page(folio, nr);
+		off -= nr * PAGE_SIZE;
+	}
+
+	__bio_add_page(bio, page, len, off);
 }
 EXPORT_SYMBOL_GPL(bio_add_folio_nofail);
 
-- 
2.47.1


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

* Re: [PATCH] block: fix adding folio to bio
  2025-03-12 11:38 [PATCH] block: fix adding folio to bio Ming Lei
@ 2025-03-12 12:19 ` Matthew Wilcox
  2025-03-12 14:02   ` Ming Lei
  0 siblings, 1 reply; 3+ messages in thread
From: Matthew Wilcox @ 2025-03-12 12:19 UTC (permalink / raw)
  To: Ming Lei
  Cc: Jens Axboe, linux-block, Kundan Kumar, Christoph Hellwig,
	Luis Chamberlain, Gavin Shan

On Wed, Mar 12, 2025 at 07:38:05PM +0800, Ming Lei wrote:
> +++ b/block/bio.c
> @@ -1026,9 +1026,17 @@ EXPORT_SYMBOL(bio_add_page);
>  void bio_add_folio_nofail(struct bio *bio, struct folio *folio, size_t len,
>  			  size_t off)
>  {
> +	struct page *page = &folio->page;
> +
>  	WARN_ON_ONCE(len > UINT_MAX);
> -	WARN_ON_ONCE(off > UINT_MAX);
> -	__bio_add_page(bio, &folio->page, len, off);
> +	if (unlikely(off > UINT_MAX)) {

I think we should probably make this:

	if (unlikely(off + len > UINT_MAX))

because I'm not sure that everything will cope well with an I/O that
crosses the 4GB boundary.

Actually, why bother with the conditional?  Let's just do it always.

 {
+	unsigned long nr = off / PAGE_SIZE;
 	WARN_ON_ONCE(len > UINT_MAX);
-	WARN_ON_ONCE(off > UINT_MAX);
-	__bio_add_page(bio, &folio->page, len, off);
+	off = off % PAGE_SIZE;
+	__bio_add_page(bio, folio_page(folio, nr), len, off);
 }

Also you need to do bio_add_folio(), not just the _nofail variant.

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

* Re: [PATCH] block: fix adding folio to bio
  2025-03-12 12:19 ` Matthew Wilcox
@ 2025-03-12 14:02   ` Ming Lei
  0 siblings, 0 replies; 3+ messages in thread
From: Ming Lei @ 2025-03-12 14:02 UTC (permalink / raw)
  To: Matthew Wilcox
  Cc: Jens Axboe, linux-block, Kundan Kumar, Christoph Hellwig,
	Luis Chamberlain, Gavin Shan

On Wed, Mar 12, 2025 at 12:19:12PM +0000, Matthew Wilcox wrote:
> On Wed, Mar 12, 2025 at 07:38:05PM +0800, Ming Lei wrote:
> > +++ b/block/bio.c
> > @@ -1026,9 +1026,17 @@ EXPORT_SYMBOL(bio_add_page);
> >  void bio_add_folio_nofail(struct bio *bio, struct folio *folio, size_t len,
> >  			  size_t off)
> >  {
> > +	struct page *page = &folio->page;
> > +
> >  	WARN_ON_ONCE(len > UINT_MAX);
> > -	WARN_ON_ONCE(off > UINT_MAX);
> > -	__bio_add_page(bio, &folio->page, len, off);
> > +	if (unlikely(off > UINT_MAX)) {
> 
> I think we should probably make this:
> 
> 	if (unlikely(off + len > UINT_MAX))
> 
> because I'm not sure that everything will cope well with an I/O that
> crosses the 4GB boundary.

If hardware doesn't support it, the bio will be splitted before submitting
to the disk, so I think the check isn't needed here.

> 
> Actually, why bother with the conditional?  Let's just do it always.
> 
>  {
> +	unsigned long nr = off / PAGE_SIZE;
>  	WARN_ON_ONCE(len > UINT_MAX);
> -	WARN_ON_ONCE(off > UINT_MAX);
> -	__bio_add_page(bio, &folio->page, len, off);
> +	off = off % PAGE_SIZE;
> +	__bio_add_page(bio, folio_page(folio, nr), len, off);
>  }
> 
> Also you need to do bio_add_folio(), not just the _nofail variant.
 
OK, will cover bio_add_folio() in V2 by the unconditional way.


Thanks,
Ming


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

end of thread, other threads:[~2025-03-12 14:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-12 11:38 [PATCH] block: fix adding folio to bio Ming Lei
2025-03-12 12:19 ` Matthew Wilcox
2025-03-12 14:02   ` Ming Lei

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