All Virtuozzo development lists (kernel + QEMU)
 help / color / mirror / Atom feed
From: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
To: no-reply@sashiko.virtuozzo.com, andrey.zhadchenko@virtuozzo.com
Cc: devel@openvz.org
Subject: Re: [Devel] [PATCH hci-8.2 v2 3/4] drivers/vhost/blk: hold requests failed with ENOSPC
Date: Tue, 1 Dec 2026 09:16:44 +0100	[thread overview]
Message-ID: <2acf4bac-f5b4-4f02-9bcb-2a78fd27a347@virtuozzo.com> (raw)
In-Reply-To: <010701a22f2c4847-38bad130-c982-4aca-b188-34cef50a16a0-000000@eu-central-1.amazonses.com>

>> +static long vhost_blk_get_held_reqs(struct vhost_blk *blk,
>> +				    struct vhost_blk_held_reqs __user *argp)
>> +{
>> +	long ret;
>> +	u32 nr;
>> +
>> +	ret = vhost_blk_get_held_nr(argp, &nr);
>> +	if (ret)
>> +		return ret;
>> +
>> +	mutex_lock(&blk->held_mutex);
>> +	if (nr < blk->nr_held)
>> +		ret = -E2BIG;
>> +	else if (copy_to_user(argp->reqs, blk->held,
>> +			      blk->nr_held * sizeof(*blk->held)))
>> +		ret = -EFAULT;
>> +
>> +	if (ret != -EFAULT && put_user(blk->nr_held, &argp->nr))
>> +		ret = -EFAULT;
>> +	mutex_unlock(&blk->held_mutex);
>> +
>> +	return ret;
>> +}
> [Severity: Low]
> Can the copy_to_user() and put_user() calls here stall the vhost worker? Both can fault and sleep for an unbounded time while held_mutex is held, for example on a userfaultfd-registered or swapped-out buffer.
>
> Meanwhile vhost_blk_handle_host_kick() -> vhost_blk_hold_req() takes the same held_mutex with vq->mutex held. The worker then blocks, and completions on that virtqueue are delayed with it.
>
> Only the device owner can issue this ioctl, so it mostly hurts its own device. Would it be cleaner to snapshot the list under held_mutex and copy to user space after dropping it?
Agreed, the copy will go out of held_mutex in the next revision.

No snapshot is needed though: only nr_held is read under held_mutex.
blk->held is freed or replaced only by SET_BACKEND and RESET_OWNER,
both under dev.mutex, which this ioctl holds too, and the kick handler
only appends past nr_held, so the entries below it do not change while
they are copied.
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

  reply	other threads:[~2026-12-01  8:18 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 16:25 [Devel] [PATCH hci-8.2 v2 0/4] drivers/vhost/blk: hold requests failed with ENOSPC until QEMU resubmits them Alexander Ivanov
2026-11-30 16:25 ` [Devel] [PATCH hci-8.2 v2 1/4] drivers/vhost: split the descriptor chain walk out of vhost_get_vq_desc() Alexander Ivanov
2026-12-01  1:11   ` no-reply
2026-11-30 16:25 ` [Devel] [PATCH hci-8.2 v2 2/4] drivers/vhost/blk: split request parsing out of the guest kick handler Alexander Ivanov
2026-12-01  1:11   ` no-reply
2026-11-30 16:25 ` [Devel] [PATCH hci-8.2 v2 3/4] drivers/vhost/blk: hold requests failed with ENOSPC Alexander Ivanov
2026-12-01  1:16   ` no-reply
2026-12-01  8:16     ` Alexander Ivanov [this message]
2026-11-30 16:25 ` [Devel] [PATCH hci-8.2 v2 4/4] drivers/vhost/blk: add the VHOST_BLK_RESUBMIT ioctl Alexander Ivanov
2026-12-01  1:19   ` no-reply
2026-12-01  8:23     ` Alexander Ivanov

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=2acf4bac-f5b4-4f02-9bcb-2a78fd27a347@virtuozzo.com \
    --to=alexander.ivanov@virtuozzo.com \
    --cc=andrey.zhadchenko@virtuozzo.com \
    --cc=devel@openvz.org \
    --cc=no-reply@sashiko.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.