linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] block: Fix page refcounts for unaligned buffers in __bio_release_pages()
@ 2024-02-29 18:08 Tony Battersby
  2024-02-29 19:53 ` Matthew Wilcox
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Tony Battersby @ 2024-02-29 18:08 UTC (permalink / raw)
  To: Jens Axboe
  Cc: Matthew Wilcox (Oracle),
	Andrew Morton, Kirill A . Shutemov, Hugh Dickins,
	Hannes Reinecke, Keith Busch, linux-mm, linux-block,
	linux-fsdevel, linux-kernel

Fix an incorrect number of pages being released for buffers that do not
start at the beginning of a page.

Fixes: 1b151e2435fc ("block: Remove special-casing of compound pages")
Cc: stable@vger.kernel.org
Signed-off-by: Tony Battersby <tonyb@cybernetics.com>
---

Tested with 6.1.79.  The 6.1 backport can just use
folio_put_refs(fi.folio, nr_pages) instead of do {...} while.

 block/bio.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/block/bio.c b/block/bio.c
index b9642a41f286..b52b56067e79 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -1152,7 +1152,7 @@ void __bio_release_pages(struct bio *bio, bool mark_dirty)
 
 	bio_for_each_folio_all(fi, bio) {
 		struct page *page;
-		size_t done = 0;
+		size_t nr_pages;
 
 		if (mark_dirty) {
 			folio_lock(fi.folio);
@@ -1160,10 +1160,11 @@ void __bio_release_pages(struct bio *bio, bool mark_dirty)
 			folio_unlock(fi.folio);
 		}
 		page = folio_page(fi.folio, fi.offset / PAGE_SIZE);
+		nr_pages = (fi.offset + fi.length - 1) / PAGE_SIZE -
+			   fi.offset / PAGE_SIZE + 1;
 		do {
 			bio_release_page(bio, page++);
-			done += PAGE_SIZE;
-		} while (done < fi.length);
+		} while (--nr_pages != 0);
 	}
 }
 EXPORT_SYMBOL_GPL(__bio_release_pages);

base-commit: d206a76d7d2726f3b096037f2079ce0bd3ba329b
-- 
2.25.1



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

end of thread, other threads:[~2024-03-06 15:35 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-29 18:08 [PATCH] block: Fix page refcounts for unaligned buffers in __bio_release_pages() Tony Battersby
2024-02-29 19:53 ` Matthew Wilcox
2024-02-29 20:40   ` Tony Battersby
2024-02-29 22:56 ` Greg Edwards
2024-03-06 15:03   ` Tony Battersby
2024-03-06 15:14     ` Jens Axboe
2024-03-06 15:35 ` Jens Axboe

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