Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Nguyen Dinh Phi" <phind.uet@gmail.com>
Cc: kvm@vger.kernel.org, virtualization@lists.linux.dev,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Eugenio Perez" <eperezma@redhat.com>
Subject: Re: [PATCH net] vhost/vsock: annotate lockless accesses to guest_cid
Date: Thu, 19 Nov 2026 01:38:45 +0000	[thread overview]
Message-ID: <sashiko-outbox-222286@kernel.org> (raw)
In-Reply-To: <20261117164916.2332953-1-phind.uet@gmail.com>

Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [High] vhost/vsock: hlist_node reuse in vhost_vsock_set_cid() breaks
  RCU readers [1]
--

commit acdb8244e7111ba9c993f9a479a6926d4b658392
Author: Nguyen Dinh Phi <phind.uet@gmail.com>

vhost/vsock: annotate lockless accesses to guest_cid

This commit annotates the write to vhost_vsock.guest_cid in
vhost_vsock_set_cid() with WRITE_ONCE() and the lockless reads in
vhost_vsock_get() and vhost_vsock_handle_tx_kick() with READ_ONCE() to
avoid KCSAN data-race reports.

> diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c
> index 88a310390eb0a..f26c590130759 100644
> --- a/drivers/vhost/vsock.c
> +++ b/drivers/vhost/vsock.c

[ ... ]

> @@ -859,7 +859,7 @@ static int vhost_vsock_set_cid(struct vhost_vsock *vsock, u64 guest_cid)
>  	if (vsock->guest_cid)
>  		hash_del_rcu(&vsock->hash);
>  
> -	vsock->guest_cid = guest_cid;
> +	WRITE_ONCE(vsock->guest_cid, guest_cid);
>  	hash_add_rcu(vhost_vsock_hash, &vsock->hash, vsock->guest_cid);
>  	mutex_unlock(&vhost_vsock_mutex);

[Severity: High]
This problem wasn't introduced by this patch, but can reusing vsock->hash
here without waiting for an RCU grace period break concurrent RCU readers
[1]?

When VHOST_VSOCK_SET_GUEST_CID changes an existing CID, hash_del_rcu()
unlinks vsock->hash from the old bucket and hash_add_rcu() immediately
overwrites vsock->hash.next to insert it into the new bucket.  A
concurrent vhost_vsock_get() traversing the old bucket via
hash_for_each_possible_rcu() can follow the updated next pointer into the
wrong bucket, skipping the rest of the original chain (causing CID lookup
failures and dropped packets) or looping indefinitely if the node is
re-added to the same bucket.

[1] https://sashiko.dev/#/bug/linux-0431a358-6215-4016-8a71-f047effc16b0

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261117164916.2332953-1-phind.uet@gmail.com?part=1

      parent reply	other threads:[~2026-11-19  1:38 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17 16:48 [PATCH net] vhost/vsock: annotate lockless accesses to guest_cid Nguyen Dinh Phi
2026-11-18  6:33 ` Michael S. Tsirkin
2026-11-19  1:38 ` 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=sashiko-outbox-222286@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=eperezma@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=phind.uet@gmail.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=virtualization@lists.linux.dev \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox