Re: [PATCH] block: fix adding folio to bio

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.




[Index of Archives]     [Linux RAID]     [Linux SCSI]     [Linux ATA RAID]     [IDE]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Device Mapper]

  Powered by Linux