From: Al Viro <viro@ZenIV.linux.org.uk>
To: Vitaly Mayatskikh <v.mayatskih@gmail.com>
Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
Jens Axboe <axboe@kernel.dk>
Subject: Re: [PATCH] fix unbalanced page refcounting in bio_map_user_iov
Date: Sat, 23 Sep 2017 17:39:28 +0100 [thread overview]
Message-ID: <20170923163928.GO32076@ZenIV.linux.org.uk> (raw)
In-Reply-To: <87bmm3xqds.wl-v.mayatskih@gmail.com>
On Fri, Sep 22, 2017 at 01:18:39AM -0400, Vitaly Mayatskikh wrote:
> 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]);
> +
Except that now you've got double-puts on failure exits ;-/
next prev parent reply other threads:[~2017-09-23 16:39 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170923163928.GO32076@ZenIV.linux.org.uk \
--to=viro@zeniv.linux.org.uk \
--cc=axboe@kernel.dk \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=v.mayatskih@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.