[Devel] [PATCH hci-8.2 6/9] dm-rq: complete dm-qcow2 requests directly in task context

no-reply at sashiko.virtuozzo.com no-reply at sashiko.virtuozzo.com
Tue Dec 1 03:35:38 MSK 2026


Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] dm-rq: dm_complete_request_direct() gates inline completion
  on in_task(), not preemptible()
--

commit 6b8fa61333058b203793f7fad936707219ef0649
Author: Denis V. Lunev <den at openvz.org>

dm-rq: complete dm-qcow2 requests directly in task context

This adds dm_complete_request_direct(). In task context it runs dm_softirq_done() inline through blk_mq_complete_request_direct(). It otherwise falls back to blk_mq_complete_request(). dm-qcow2's qrq_endio() now uses it.

https://virtuozzo.atlassian.net/browse/VSTOR-95494

> diff --git a/drivers/md/dm-rq.c b/drivers/md/dm-rq.c
> index 5a8cd59ec257..0d31fcf84aed 100644
> --- a/drivers/md/dm-rq.c
> +++ b/drivers/md/dm-rq.c
> @@ -294,6 +294,26 @@ void dm_complete_request(struct request *rq, blk_status_t error)
>  }
>  EXPORT_SYMBOL(dm_complete_request);
>  
> +/*
> + * Raising BLOCK_SOFTIRQ from a task wakes ksoftirqd. Complete inline
> + * if affinity permits. The caller must not hold a lock that completion
> + * of the original request may take.
> + */
> +void dm_complete_request_direct(struct request *rq, blk_status_t error)
> +{
> +	struct dm_rq_target_io *tio = tio_from_request(rq);
> +
> +	tio->error = error;
> +	if (unlikely(blk_should_fake_timeout(rq->q)))
> +		return;
> +
> +	if (in_task() && !test_bit(QUEUE_FLAG_SAME_FORCE, &rq->q->queue_flags))
> +		blk_mq_complete_request_direct(rq, dm_softirq_done);

[Severity: Medium]
Is in_task() a strong enough condition for running the original request's end_io inline here?

in_task() stays true while a spinlock is held, with preemption or BH disabled, and inside an RCU read-side section. Before this patch, blk_mq_complete_request() never ran the end_io on the caller's stack in those contexts.

dm-qcow2 itself looks safe. qrq_endio() is only reached after the target has dropped its locks, or from workqueues. The problem is on the lower-layer side. qcow2_aio_complete() is the ki_complete callback for the backing file. qcow2_call_rw_iter() also calls it synchronously. The target can't tell what context the lower layer completes the kiocb in.

If a lower layer completes in task context with a lock, preemption or RCU held, the end_io now runs there. That could cause a self-deadlock, a sleep in atomic context, or deep stack recursion.

blk_mq_complete_request_direct() is meant for preemptible callers. Would it be better to also require preemptible(), which implies !irqs_disabled(), or to take an explicit flag from the caller as scsi_done_direct() does?

-- 
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261125012525.681662-1-den@openvz.org?part=6



More information about the Devel mailing list