All Virtuozzo development lists (kernel + QEMU)
 help / color / mirror / Atom feed
From: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
Subject: [Devel] [PATCH VZ10] drivers/vhost/blk: fix vhost_blk_req_done() softirq handling
Date: Mon, 17 Aug 2026 03:02:34 +0300	[thread overview]
Message-ID: <20260817000234.337030-1-andrey.zhadchenko@virtuozzo.com> (raw)

vhost_blk_req_done() does bio_release_pages(), which may sleep on
folio_lock() when we need to dirty pages. So we get this:

[ 9120.053244] BUG: scheduling while atomic: swapper/1/0/0x00000102
...
[ 9120.079613] Hardware name: Acronis OpenStack Compute/Virtuozzo, BIOS 1.16.1-1.vz9.2 04/01/2014
[ 9120.079629] Call Trace:
[ 9120.079632]  <IRQ>
[ 9120.079638]  dump_stack_lvl+0x4e/0x70
[ 9120.079646]  __schedule_bug.cold+0x3e/0x4a
[ 9120.079650]  schedule_debug.isra.0+0x93/0xc0
[ 9120.079655]  __schedule+0x7a/0x630
[ 9120.079659]  ? enqueue_task_fair+0x150/0x710
[ 9120.079664]  schedule+0x27/0x80
[ 9120.079666]  io_schedule+0x46/0x70
[ 9120.079669]  folio_wait_bit_common+0x13a/0x340
[ 9120.079686]  ? __pfx_wake_page_function+0x10/0x10
[ 9120.079690]  __bio_release_pages+0x25b/0x280
[ 9120.079698]  vhost_blk_req_done+0x98/0xa0 [vhost_blk]
[ 9120.079702]  blk_update_request+0x17c/0x420
[ 9120.079707]  blk_mq_end_request+0x1c/0x30
[ 9120.079711]  dm_softirq_done+0x158/0x280 [dm_mod]
[ 9120.079737]  blk_complete_reqs+0x40/0x50
[ 9120.079740]  handle_softirqs+0xe5/0x2a0
[ 9120.079744]  __irq_exit_rcu+0xbd/0xe0
[ 9120.079746]  sysvec_call_function_single+0x71/0x90
[ 9120.079750]  </IRQ>
[ 9120.079751]  <TASK>
[ 9120.079752]  asm_sysvec_call_function_single+0x1a/0x20

Kernel already has a suitable helper: bio_check_pages_dirty(). It
takes bio ownership and dirties pages/puts bio later in some
workqueue (see bio_set_pages_dirty() annotation).
Also we should manually mark the pages dirty from
vhost_blk_bio_send(), as they can be modified through DMA.

While at here, move request posting below bio_put. I don't expect
the worker could process and reuse the request before we access
req->bb and req->bi_opf, but better be safe then sorry.

https://virtuozzo.atlassian.net/browse/VSTOR-141284
Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
---
 drivers/vhost/blk.c | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/drivers/vhost/blk.c b/drivers/vhost/blk.c
index c03945ac04234..dac03566bfca5 100644
--- a/drivers/vhost/blk.c
+++ b/drivers/vhost/blk.c
@@ -156,19 +156,22 @@ static void vhost_blk_req_done(struct bio *bio)
 	if (err)
 		req->bio_err = err;
 
-	if (atomic_dec_and_test(&req->bio_nr)) {
-		llist_add(&req->llnode, &req->blk_vq->llhead);
-		vhost_vq_work_queue(&req->blk_vq->vq, &req->blk_vq->work);
-	}
-
 	/*
 	 * Bounce buffer adds kvec to bio (instead of user backed memory),
 	 * so there is no reference/pin to bio pages in this case.
 	 */
-	if (!req->bb)
-		bio_release_pages(bio, !req->bi_opf);
+	if (!req->bb && req->bi_opf == REQ_OP_READ) {
+		bio_check_pages_dirty(bio);
+	} else {
+		if (!req->bb)
+			bio_release_pages(bio, false);
+		bio_put(bio);
+	}
 
-	bio_put(bio);
+	if (atomic_dec_and_test(&req->bio_nr)) {
+		llist_add(&req->llnode, &req->blk_vq->llhead);
+		vhost_vq_work_queue(&req->blk_vq->vq, &req->blk_vq->work);
+	}
 }
 
 static void vhost_blk_req_cleanup(struct vhost_blk_req *req)
@@ -387,8 +390,11 @@ static inline void vhost_blk_bio_send(struct vhost_blk_req *req)
 
 	bio_nr = atomic_read(&req->bio_nr);
 	blk_start_plug(&plug);
-	for (i = 0; i < bio_nr; i++)
+	for (i = 0; i < bio_nr; i++) {
+		if (!req->bb && req->bi_opf == REQ_OP_READ)
+			bio_set_pages_dirty(req->bio[i]);
 		submit_bio(req->bio[i]);
+	}
 
 	blk_finish_plug(&plug);
 }
-- 
2.43.5


             reply	other threads:[~2026-08-17  0:02 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-17  0:02 Andrey Zhadchenko [this message]
2026-08-18  8:53 ` Vasileios Almpanis
2026-08-25 11:03 ` [Devel] [PATCH RHEL10 COMMIT] " Konstantin Khorenko

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=20260817000234.337030-1-andrey.zhadchenko@virtuozzo.com \
    --to=andrey.zhadchenko@virtuozzo.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.