[Devel] [PATCH RHEL9 COMMIT] vhost-blk: fix bio allocation failure on excess bio vector count

Konstantin Khorenko khorenko at virtuozzo.com
Fri Nov 15 17:47:07 MSK 2024


The commit is pushed to "branch-rh9-5.14.0-427.37.1.vz9.78.x-ovz" and will appear at git at bitbucket.org:openvz/vzkernel.git
after rh9-5.14.0-427.37.1.vz9.78.4
------>
commit ea734486119b98aa0a5f4bbb8117af839fcaf587
Author: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
Date:   Wed Nov 6 17:20:30 2024 +0800

    vhost-blk: fix bio allocation failure on excess bio vector count
    
    The bio_alloc() function does not allow to allocate bio-s with more than
    BIO_MAX_VECS bio vectors. Currently we give to it the nr_vecs argument
    equal to the number of pages in all iovecs of the processed request,
    which can be much bigger than BIO_MAX_VECS (256), this is incorrect and
    leads to the bug in biovec_slab(): "kernel BUG at block/bio.c:62!".
    
    Fix it by restricting the nr_vecs argument properly by bio_max_segs()
    helper, also let's decrease pages_nr_total by the number of already
    processed pages, so that we can use bio with less vectors when possible.
    
    Fixes: 17bfe6e0400da ("drivers/vhost: vhost-blk accelerator for virtio-blk guests")
    https://virtuozzo.atlassian.net/browse/VSTOR-94596
    Signed-off-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
    
    Feature: vhost-blk: in-kernel accelerator for virtio-blk guests
---
 drivers/vhost/blk.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/vhost/blk.c b/drivers/vhost/blk.c
index cd8d71c28bbd..d77e5fc494de 100644
--- a/drivers/vhost/blk.c
+++ b/drivers/vhost/blk.c
@@ -297,7 +297,7 @@ static int vhost_blk_bio_make(struct vhost_blk_req *req,
 				len = iov_len;
 
 			while (!bio || !bio_add_page(bio, page, len, off)) {
-				bio = bio_alloc(bdev, pages_nr_total,
+				bio = bio_alloc(bdev, bio_max_segs(pages_nr_total),
 						req->bi_opf, GFP_KERNEL);
 				if (!bio)
 					goto fail;
@@ -309,6 +309,7 @@ static int vhost_blk_bio_make(struct vhost_blk_req *req,
 
 			iov_base	+= len;
 			iov_len		-= len;
+			pages_nr_total--;
 
 			pos = (iov_base & VHOST_BLK_SECTOR_MASK) + iov_len;
 			req->sector += pos >> VHOST_BLK_SECTOR_BITS;


More information about the Devel mailing list