mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Krzysztof Woś" <krzysztof.wos@gmail.com>
To: Stefano Garzarella <sgarzare@redhat.com>
Cc: "Stefan Hajnoczi" <stefanha@redhat.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Bobby Eshleman" <bobbyeshleman@meta.com>,
	"Jason Wang" <jasowangio@gmail.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, 03 Dec 2026 12:13:52 +0000	[thread overview]
Message-ID: <179630003262.439139.12879743486189024236@gmail.com> (raw)
In-Reply-To: <axFG8LeimFx1Zrk9@sgarzare-redhat>

On Thu, Dec 03, 2026 at 11:43:29AM +0100, Stefano Garzarella wrote:
> 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?
>
> Please test those patches already posted, and comment on them if you
> think they are not complete.

Hi Stefano,

My sincere apologies for the duplicate submission and for bundling
multiple changes into a single commit. This is one of my first kernel
submissions: I checked torvalds/linux HEAD (d06ce6f1eb5e) without
checking net-next and lore.kernel.org/netdev first, and I should also
have split distinct changes into separate commits. Going forward I will
always check net-next and lore/Patchwork before posting.

Please drop/ignore this patch in Patchwork in favor of Nguyen Dinh Phi's
merged net-next commit c68d8b4cb2e7 ("vhost/vsock: annotate lockless
accesses to guest_cid") and Bilal Hashim's v2 thread
(179614298864.2872.3567081270371906851@126.com).

Looking through Bilal's v2 and Michael's hlist_nulls follow-up there,
two small notes in case they help that discussion:

1. On Michael's question whether synchronize_rcu() runs on every VM
   boot: on initial VM boot vsock->guest_cid is 0 (kzalloc'd in
   vhost_vsock_dev_open()), so synchronize_rcu() is skipped and only
   triggers if user space calls VHOST_VSOCK_SET_GUEST_CID again to
   reassign an already-configured fd. Still, holding global
   vhost_vsock_mutex across synchronize_rcu() blocks unrelated VMs'
   vhost_vsock_dev_release() and SET_GUEST_CID calls during that grace
   period, and leaving vsock->guest_cid non-zero across synchronize_rcu()
   lets vhost_vsock_handle_tx_kick() keep accepting TX packets with the
   unlinked CID until guest_cid is updated.

2. On Michael's hlist_nulls sketch: get_nulls_value(node) != bucket
   catches cross-bucket moves at end-of-chain, without needing
   synchronize_rcu(), if other == vsock returns early. One subtlety is
   same-bucket CID reassignment (e.g. CID 3 -> 259, both hashing to the
   same 8-bit bucket): if two instances in the same bucket are
   repeatedly re-added at head via hlist_nulls_add_head_rcu() without a
   grace period, a concurrent RCU reader positioned on them can bounce
   between the two nodes without reaching the nulls marker. Also,
   hlist_nulls_add_head_rcu() updates n->next via WRITE_ONCE() before
   publishing head->first, so rehashing an existing live node (unlike a
   freshly allocated SLAB_TYPESAFE_BY_RCU node) needs smp_wmb() between
   updating guest_cid and overwriting n->next.

Thanks, and sorry again for the noise,
Krzysztof Woś

      reply	other threads:[~2026-12-03 13:41 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03  6:22 Krzysztof Woś
2026-12-03 10:43 ` Stefano Garzarella
2026-12-03 12:13   ` Krzysztof Woś [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=179630003262.439139.12879743486189024236@gmail.com \
    --to=krzysztof.wos@gmail.com \
    --cc=bobbyeshleman@meta.com \
    --cc=eperezma@redhat.com \
    --cc=jasowangio@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=sgarzare@redhat.com \
    --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

all inboxes | Powered by JetHome®