From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796137033; b=SHOIn4SXLCKUWjDIotkqcRzIY+9csF8TJVwk/BA2YS72C+YILpv0zEXwF7X/o9s/gf1P nTuctb+995LcLl9saCO17xFVPd4Zx//YlT5qUvI3sGS1qhwIyetRduIPiN6Uw7a6FVDdp Ex3tph19qttbYvfsOWvu/u60fFd5u5qZerz8AvQNJBhbJ9l0KWZ4QiSyLXYj1uxvHwDKI YMXFN4Ug41NZEeZAcFZek5bOxrPcGsoLpJrQrLFpXOvGJn0AqqZQSy7QPinOn5bo6O0/S 4SpaNZ6LcJCXAPme0/Yh4d0zdEvmwpa6JGPG+mpGP6qlZMof+Vtr0R5PBkHaAAqs84g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796137033; h=DMARC-Filter:DKIM-Signature:X-MC-Rep:Received:X-MC-Unique: X-Mimecast-MFC-AGG-ID:Received:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received: X-Received:Received:Date:From:To:Cc:Subject:Message-ID:References: MIME-Version:In-Reply-To:X-Mimecast-Spam-Score:X-Mimecast-MFC-PROC-ID: X-Mimecast-Originator:Content-Type:Content-Disposition; bh=MaZS7WybMW7W0ZwBqeGAPD1oS8DSSeNP8Urn9tWB5Ts=; b=g/BhkPFSXipovhvET+ILtldf4cqpHMgv4ybdREyybVB4MzkEBsLqWlfV2dS7zv53eF/b 7BbfLgnDk9yqRjdRjhmRbegzM2/VnZugLNtzuW8/GnYRPnQ6K9kWQ738iDQgGwdsNGMj5 XfUKXIGWWwsNxSA85jLgGMPJTC5M8mEoP7qcQr7o9l6LTgugdPao1j7LuLntfC/zuvguR DzAf3G+S2wDswsiZTJDzvA2DfQ/ZyzQkRqQyjFfpQoLybRAIQD98lpUIDhbbT77062M7z TrZuGogeCodaUw4X2KjahsTJb++FDzPq6oqQWmi7CICTtShALMgMO5XGEhP68Iljjiw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=HjtWgWFy; arc=none smtp.remote-ip=170.10.133.124 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 82DBC606A68B for ; Tue, 1 Dec 2026 14:57:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 82DBC606A68B Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=HjtWgWFy DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1796137031; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=MaZS7WybMW7W0ZwBqeGAPD1oS8DSSeNP8Urn9tWB5Ts=; b=HjtWgWFyVbOpuKXwSXRFJaU0Nmul0bWrT9u31hBS/H/5kuTttQf/KZM4/7gDUYM1LhJP28 MGK5WGG+tSfOUbEEoQ3fsBg4DPG03TeMDnqzlM7tcV7UEj0Jf6GdOmpEaJd7G0IlsKO4qF 6y0iBOeCEEuVJRncJFaRfiq5KU6lDC4= X-MC-Rep: binary re single Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-314-088e0IL2OuOsfHgbV9zmMA-1; Tue, 1 Dec 2026 14:57:07 +0000 X-MC-Unique: 088e0IL2OuOsfHgbV9zmMA-1 X-Mimecast-MFC-AGG-ID: 088e0IL2OuOsfHgbV9zmMA_1796137026 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-48e1d839ddaso6877672f8f.3 for ; Tue, 01 Dec 2026 06:57:07 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796137026; x=1796741826; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=MaZS7WybMW7W0ZwBqeGAPD1oS8DSSeNP8Urn9tWB5Ts=; b=wvT0sgW+ZtKEdUAwo47fqZwlOiADA9CdxmajEU2cIHzKKOaR5Gw/PhItIdwbrq9DhP Qk7ff1sENaQkfml186vGHYjjiLG0Zynzba4A9nTwfYoIvL3giMjjQxRbkg0/DOB8Z/tv 3vggvZaCFltHdCCfAbph092hLJ9xJ25VfxK7NLkUgz7V3bAEUzCNmGNdphcEN9wQ/7+1 fagmM3LoWE6uzwgb5NJSG9VdcwkSjg7mjespWPVwRMNS53tIUfBKh62lD9khUosiySkv OLezOowUtqt0mMI+NXVa09e9QvR7fUDGvK6y2askxoDCSL0vvBqZgZLskxQbj5IekKZc K5tA== X-Forwarded-Encrypted: i=1; AL+hErH8y0Rxsb+aeYDXJO/Nq57F1sJlNO7fVjdkmaBCifh3ofEbxTdn8Jr0eRm0TQizwPzKOXGy64bMrRHDd0rjFQ==@lists.linux.dev X-Gm-Message-State: APuU4Z+cj9lbW199zJMhJDfh6Feef8Cr6VDd2W0V8unx6+xhL5N3UsHf GMSJ0mfD2UR0pighQSgIQ6iTRccxhKCHCnFJzg8NEXh+plbHbHDiEkRin6ISAeD4OyhpKmK/I1T hf22nIKO+9hpAC+mFExBH3Vzd9NF4il3pn/66foUrNCo8oKxutkeLbC0aQm8M8/hHFA0b X-Gm-Gg: AZFdTZdXX0OGTqqz7fc1eeuEUVdOCYyc+sv+ZsojNMB3daawxZZOUk/+6wGABSBrY8H ip0H92WlsZv1hQlngieib0rvnSnN9Ep+VCr3FTi96v7O7rYAe+RDYEd9wv9NUw4LMkm6/xvDqo1 2Nraexg1cjhhTRjg592D7cU+PtQRGdnuvKjp1kNQ3Hb5AdJkOVryQWqFCumIPM62H3vEJfF4IXW VSw4t+tOfig91J87z7OmOquyboGR/FmNml56rU9ZCT/hepSCQhRqAFWF7Nb/QEhBF8Q2MzlR3hM 47Gx6XSb6nChIbbTyMlUYTqi2BtK3pVAoZ2Sd6lbi/clXlMO3gQewDegoRuiTm55KmrSCFEQ9WE 80QPdWwWYMLpeWcUrEJm3MbFiELVKmvYQnzspSJT4/vywKokUbshJ9ioNqRy7BkJpzdBmarsqux PV5eC6Odo0guECmQ== X-Received: by 2002:a05:6000:27c1:b0:4a5:26ff:13d0 with SMTP id ffacd0b85a97d-4abb0f3b5bdmr47379473f8f.14.1796137026119; Tue, 01 Dec 2026 06:57:06 -0800 (PST) X-Received: by 2002:a05:6000:27c1:b0:4a5:26ff:13d0 with SMTP id ffacd0b85a97d-4abb0f3b5bdmr47379422f8f.14.1796137025567; Tue, 01 Dec 2026 06:57:05 -0800 (PST) Received: from sgarzare-redhat (ip190-139-192-82.pool-bba.aruba.it. [82.192.139.190]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4ab6bb989b3sm71471716f8f.51.2026.12.01.06.57.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 06:57:04 -0800 (PST) Date: Tue, 1 Dec 2026 15:56:58 +0100 From: Stefano Garzarella To: Bilal Hashim Cc: Stefan Hajnoczi , "Michael S. Tsirkin" , Jason Wang , Eugenio Perez , kvm@vger.kernel.org, virtualization@lists.linux.dev, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] vhost/vsock: wait for RCU grace period before rehashing CID Message-ID: References: <179602872770.13688.17108715679213800277@126.com> X-Mailing-List: virtualization@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 In-Reply-To: <179602872770.13688.17108715679213800277@126.com> X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 6bJ6S0s-dYW36vF7ASfZj9XnBA2Ln_WkB-h5R4tOKPc_1796137026 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline On Mon, Nov 30, 2026 at 04:52:07PM +0800, Bilal Hashim wrote: >In vhost_vsock_set_cid(), when a vhost_vsock instance already has a CID >assigned, hash_del_rcu(&vsock->hash) is immediately followed by >hash_add_rcu(vhost_vsock_hash, &vsock->hash, vsock->guest_cid) without >waiting for an RCU grace period. > >Reusing an hlist_node that was just removed with hash_del_rcu() overwrites >its next pointer while concurrent RCU readers in vhost_vsock_get() >(called from vhost_transport_send_pkt(), vhost_transport_cancel_pkt(), >vhost_vsock_reset_orphans(), etc.) may still be traversing that bucket. >This can cause RCU readers to: >- jump to another hash bucket or terminate early, missing unrelated active > vhost_vsock instances (for example causing vhost_vsock_reset_orphans() > to reset healthy connections or vhost_transport_send_pkt() to return > -ENODEV); or >- loop indefinitely inside an RCU read-side critical section (RCU stall / > soft lockup) when two instances in the same bucket are repeatedly > rehashed via VHOST_VSOCK_SET_GUEST_CID. > >Fix this by returning early when the CID is unchanged, calling >synchronize_rcu() after hash_del_rcu() before modifying vsock->guest_cid >and re-inserting into vhost_vsock_hash, and annotating concurrent accesses >to vsock->guest_cid with WRITE_ONCE()/READ_ONCE(). > >Found by manual code inspection. mmm, really, it seems related to https://lore.kernel.org/all/sashiko-outbox-222286@kernel.org/ no? Also why mixing READ_ONCE/WRITE_ONCE in this patch? FYI that is fixed by https://lore.kernel.org/all/20261129050514.1278990-1-phind.uet@gmail.com/ Please, sync with Nguyen about how to handle both patches. The best will be to have a single series, or just rebase this on top of the other patch that I guess is going to be merged. Stefano > >Fixes: 433fc58e6bf2 ("VSOCK: Introduce vhost_vsock.ko") >Cc: stable@vger.kernel.org >Signed-off-by: Bilal Hashim >--- > drivers/vhost/vsock.c | 15 +++++++++++---- > 1 file changed, 11 insertions(+), 4 deletions(-) > >--- a/drivers/vhost/vsock.c >+++ b/drivers/vhost/vsock.c >@@ -78,7 +78,7 @@ static struct vhost_vsock *vhost_vsock_g > > hash_for_each_possible_rcu(vhost_vsock_hash, vsock, hash, guest_cid, > lockdep_is_held(&vhost_vsock_mutex)) { >- u32 other_cid = vsock->guest_cid; >+ u32 other_cid = READ_ONCE(vsock->guest_cid); > > /* Skip instances that have no CID yet */ > if (other_cid == 0) >@@ -572,7 +572,7 @@ static void vhost_vsock_handle_tx_kick(s > hdr = virtio_vsock_hdr(skb); > > /* Only accept correctly addressed packets */ >- if (le64_to_cpu(hdr->src_cid) == vsock->guest_cid && >+ if (le64_to_cpu(hdr->src_cid) == READ_ONCE(vsock->guest_cid) && > le64_to_cpu(hdr->dst_cid) == > vhost_transport_get_local_cid()) > virtio_transport_recv_pkt(&vhost_transport, skb, >@@ -856,10 +856,17 @@ static int vhost_vsock_set_cid(struct vh > return -EADDRINUSE; > } > >- if (vsock->guest_cid) >+ if (vsock->guest_cid == guest_cid) { >+ mutex_unlock(&vhost_vsock_mutex); >+ return 0; >+ } >+ >+ if (vsock->guest_cid) { > hash_del_rcu(&vsock->hash); >+ synchronize_rcu(); >+ } > >- 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); > > >