All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fix unbalanced page refcounting in bio_map_user_iov
@ 2017-09-22  5:18 Vitaly Mayatskikh
  2017-09-22  5:24 ` Vitaly Mayatskikh
  2017-09-23 16:39 ` Al Viro
  0 siblings, 2 replies; 9+ messages in thread
From: Vitaly Mayatskikh @ 2017-09-22  5:18 UTC (permalink / raw)
  To: linux-block, linux-kernel; +Cc: Jens Axboe

bio_map_user_iov and bio_unmap_user do unbalanced pages refcounting if
IO vector has small consecutive buffers belonging to the same page.
bio_add_pc_page merges them into one, but the page reference is never
dropped.

Signed-off-by: Vitaly Mayatskikh <v.mayatskih@gmail.com>

diff --git a/block/bio.c b/block/bio.c
index b38e962fa83e..10cd3b6bed27 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -1383,6 +1383,7 @@ struct bio *bio_map_user_iov(struct request_queue *q,
 		offset = offset_in_page(uaddr);
 		for (j = cur_page; j < page_limit; j++) {
 			unsigned int bytes = PAGE_SIZE - offset;
+			unsigned short prev_bi_vcnt = bio->bi_vcnt;
 
 			if (len <= 0)
 				break;
@@ -1397,6 +1398,13 @@ struct bio *bio_map_user_iov(struct request_queue *q,
 					    bytes)
 				break;
 
+			/*
+			 * check if vector was merged with previous
+			 * drop page reference if needed
+			 */
+			if (bio->bi_vcnt == prev_bi_vcnt)
+				put_page(pages[j]);
+
 			len -= bytes;
 			offset = 0;
 		}

-- 
wbr, Vitaly

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

end of thread, other threads:[~2017-09-25  1:48 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-22  5:18 [PATCH] fix unbalanced page refcounting in bio_map_user_iov Vitaly Mayatskikh
2017-09-22  5:24 ` Vitaly Mayatskikh
2017-09-23 16:39 ` Al Viro
2017-09-23 16:55   ` Al Viro
2017-09-23 17:19     ` Al Viro
2017-09-23 20:33       ` Al Viro
2017-09-24 14:27         ` Al Viro
2017-09-24 17:15           ` Al Viro
2017-09-25  1:48           ` Vitaly Mayatskikh

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.