All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Octavian Purdila" <tavip@google.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH net v2 2/2] vsock/virtio: restore msg_iter on transmission failure
Date: Sun, 14 Jun 2026 00:10:33 +0000	[thread overview]
Message-ID: <20260614001033.A96051F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260613000953.467473-3-tavip@google.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Use of `iov_iter_restore` causes spurious `WARN_ON_ONCE` for `ITER_KVEC` iterators and lacks support for `ITER_FOLIOQ`, risking state corruption.
--

commit adc9013e2e0f53e4c04e792c4d6b248a3f5afb54
Author: Octavian Purdila <tavip@google.com>

vsock/virtio: restore msg_iter on transmission failure

This commit addresses an iterator desync issue when packet allocation or
transmission fails by saving the msg_iter state before attempting to allocate
and send, and restoring it if an error occurs.

> --- a/net/vmw_vsock/virtio_transport_common.c
> +++ b/net/vmw_vsock/virtio_transport_common.c
> @@ -368,8 +369,17 @@ static int virtio_transport_send_pkt_info(struct vsock_sock *vsk,
>  		struct sk_buff *skb;
>  		size_t skb_len;
>  
> +		/* Save iterator state in case allocation or transmission fails
> +		 * so we can restore it and retry.
> +		 */
> +		if (info->msg)
> +			iov_iter_save_state(&info->msg->msg_iter, &msg_iter_state);
> +
>  		skb_len = min(max_skb_len, rest_len);
>  
> +		/* Note: virtio_transport_alloc_skb() can advance info->msg->msg_iter
> +		 * even if it fails (e.g. partial GUP success).
> +		 */
>  		skb = virtio_transport_alloc_skb(info, skb_len, can_zcopy,
>  						 uarg,
>  						 src_cid, src_port,

[ ... ]

> @@ -399,6 +409,9 @@ static int virtio_transport_send_pkt_info(struct vsock_sock *vsk,
>  			break;
>  	} while (rest_len);
>  
> +	if (info->msg && ret < 0)
> +		iov_iter_restore(&info->msg->msg_iter, &msg_iter_state);
> +

[Severity: Medium]
Does this iov_iter_restore() call risk triggering a spurious warning for
ITER_KVEC iterators or silently failing for ITER_FOLIOQ?

In-kernel socket consumers, such as the Network Block Device, actively
construct ITER_KVEC iterators for request headers and send them via
sock_sendmsg(). Users can configure NBD over a vsock socket.

If memory pressure causes virtio_transport_alloc_skb() to fail during an
NBD transmission, the error path invokes iov_iter_restore() which evaluates
the following condition:

lib/iov_iter.c:iov_iter_restore() {
	if (WARN_ON_ONCE(!iov_iter_is_bvec(i) && !iter_is_iovec(i) &&
			 !iter_is_ubuf(i)) && !iov_iter_is_kvec(i))
		return;
...
}

For ITER_KVEC iterators, the first part of the expression evaluates to true,
unconditionally triggering a kernel warning before restoring the iterator. On
systems with panic_on_warn enabled, this could lead to a kernel panic.

Additionally, iov_iter_restore() explicitly ignores ITER_FOLIOQ iterators,
meaning it would silently fail to restore the state if the VFS passes such
an iterator, potentially leading to infinite loops and desynchronization.

Could tracking the number of bytes advanced and using iov_iter_revert()
provide a safer way to handle this rollback?

>  	virtio_transport_put_credit(vvs, rest_len);
>  
>  	/* msg_zerocopy_realloc() initializes the ubuf_info refcnt to 1.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260613000953.467473-1-tavip@google.com?part=2

      reply	other threads:[~2026-06-14  0:10 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-13  0:09 [PATCH net v2 0/2] vsock/virtio: fix msg_iter desync on transmission failure Octavian Purdila
2026-06-13  0:09 ` [PATCH net v2 1/2] iov_iter: export iov_iter_restore Octavian Purdila
2026-06-14  0:10   ` sashiko-bot
2026-06-13  0:09 ` [PATCH net v2 2/2] vsock/virtio: restore msg_iter on transmission failure Octavian Purdila
2026-06-14  0:10   ` sashiko-bot [this message]

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=20260614001033.A96051F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=tavip@google.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.