From: Stefano Garzarella <sgarzare@redhat.com>
To: "Krzysztof Woś" <krzysztof.wos@gmail.com>
Cc: "Stefan Hajnoczi" <stefanha@redhat.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
"Bobby Eshleman" <bobbyeshleman@meta.com>,
"Jason Wang" <jasowang@redhat.com>,
"Eugenio Pérez" <eperezma@redhat.com>,
virtualization@lists.linux.dev, netdev@vger.kernel.org,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: Re: [PATCH] vhost/vsock: wait for RCU grace period before rehashing guest_cid
Date: Thu, 3 Dec 2026 11:43:29 +0100 [thread overview]
Message-ID: <axFG8LeimFx1Zrk9@sgarzare-redhat> (raw)
In-Reply-To: <179627895906.335073.17960904565008606745@gmail.com>
On Thu, Dec 03, 2026 at 06:22:39AM +0000, Krzysztof Woś wrote:
>vhost_vsock_set_cid() (drivers/vhost/vsock.c:832-867) updates a struct
>vhost_vsock's guest_cid and re-inserts its embedded struct hlist_node
>hash into the global 256-bucket RCU hash table vhost_vsock_hash
>(DEFINE_READ_MOSTLY_HASHTABLE(vhost_vsock_hash, 8), line 46) by calling
>hash_del_rcu(&vsock->hash) followed immediately by
>hash_add_rcu(vhost_vsock_hash, &vsock->hash, vsock->guest_cid) with no
>intervening synchronize_rcu() grace period.
>
>In addition:
>
>1. No early return when other == vsock: Re-invoking
> VHOST_VSOCK_SET_GUEST_CID with the device's existing CID falls
> through to hash_del_rcu() + hash_add_rcu() on the same bucket without
> a grace period.
>2. Unsynchronized plain accesses to vsock->guest_cid:
> vhost_vsock_set_cid() performs a plain store (vsock->guest_cid =
> guest_cid;, line 862) while vhost_vsock_get() (line 81, under
> rcu_read_lock()) and vhost_vsock_handle_tx_kick() (line 575, under
> vq->mutex only) perform plain loads without READ_ONCE()/WRITE_ONCE().
> (By contrast, vsock->ever_started in the same file already uses
> READ_ONCE() at line 311 and WRITE_ONCE() at line 640.)
>
>Overwriting vsock->hash.next via hash_add_rcu() before active RCU
>readers have exited their read-side critical sections violates the core
>hlist_del_rcu() contract: readers currently positioned on the rehashed
>node are silently redirected into the destination bucket (or back to the
>head of the same bucket). As a result, concurrent lockless lookups for
>unrelated live VMs sharing the same 8-bit hash bucket can falsely return
>NULL—causing dropped packets (-ENODEV), missed cancel_pkt purges,
>erroneous ECONNRESET teardown of healthy VMs' sockets in
>vhost_vsock_reset_orphans(), or repeated/looping traversal within an
>rcu_read_lock() critical section.
>
>Fix summary:
>
>- Return 0 immediately when other == vsock (eliminates redundant
> same-CID rehash).
>- Serialize per-device CID updates with vsock->dev.mutex.
>- When reassigning an already-hashed vsock (vsock->guest_cid != 0):
> unlink via hash_del_rcu(), clear vsock->guest_cid to 0 (WRITE_ONCE),
> release vhost_vsock_mutex, call synchronize_rcu(), re-check
> vsock_find_cid(guest_cid) and (under vhost_vsock_mutex)
> vhost_vsock_get(guest_cid, vsock->net) before re-inserting. Clearing
> vsock->guest_cid to 0 while unlinked ensures that if the re-check
> loses a race (-EADDRINUSE), vhost_vsock_dev_release() will not
> double-delete &vsock->hash.
>- Use READ_ONCE()/WRITE_ONCE() for vsock->guest_cid on lockless
> read/write paths.
1 commit for all of those fixes?
BTW it seems your LLMs are founding the same issue in the last weeks,
so, please, before posting a patch, can you check if there are patches
fixing the same issue?
https://lore.kernel.org/netdev/20261129050514.1278990-1-phind.uet@gmail.com/
https://lore.kernel.org/netdev/179602872770.13688.17108715679213800277@126.com/
Please test those patches already posted, and comment on them if you
think they are not complete.
Stefano
prev parent reply other threads:[~2026-12-03 10:43 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 6:22 [PATCH] vhost/vsock: wait for RCU grace period before rehashing guest_cid Krzysztof Woś
2026-12-03 10:43 ` Stefano Garzarella [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=axFG8LeimFx1Zrk9@sgarzare-redhat \
--to=sgarzare@redhat.com \
--cc=bobbyeshleman@meta.com \
--cc=eperezma@redhat.com \
--cc=jasowang@redhat.com \
--cc=krzysztof.wos@gmail.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mst@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=stefanha@redhat.com \
--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