From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796137031; b=ectIjs4Dlbr/AWhQpKDPdLaTyfjHK+9MjnVEZ4KxSjJeH/yrV/7bAApey1zmlOpyG4Ao jKmkI/eYQg/kRYv07wa8qBNmFNyZgkRwgZYe+R5LjdOtzleb3zHRLv9OAxI1TqRSeATn5 j9v4MyAOncs5h92ere9p0vF/VO4QknB5hJtoapM6j3Vzi3BP6/KtxVHvl6Bcz3pVOB8Ti SotHrsvedGyWAVaOKZeRFlBBRDMLq8lhoMkg2OoDj/fhAqij3mbmEaz+ZfYhm3wqhdTz2 CbPTtZrWE9U39hiFH+CXtLRfT5GrkqQtpSQ4BsAsJGOm8RtAior8Lsse9vzQh/9tR5w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796137031; h=DMARC-Filter:DKIM-Signature:Received:X-MC-Unique: X-Mimecast-MFC-AGG-ID:Received:DKIM-Signature: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:Content-Type:Content-Disposition:In-Reply-To; bh=MaZS7WybMW7W0ZwBqeGAPD1oS8DSSeNP8Urn9tWB5Ts=; b=Y4Aj5oIdewx0CalQNX1z0EGoz7VKqTtVJlm/11mWgavDqpcwrUc+IFrUnti2YGVAcK76 WncYZ2eep2JepTwzqnZmP8+Kk86GSqi1ZwJcjil7PrnISa0oDaxwpoJkoVfLm/W9f9M7F tacGrjgHFeVLLbKSQmkFbG3RKj6YLb96juvdKbolU2nrNPZ+YyngZGBpjUNfj/1AKBfHe uWILkCdAk3z8HgRw0OS479qDF3yzGkmymtZnXGUohe2wJyHIFbEdizvaOwaX8KGNvXiAP E8WxjHXxgQ9I8Iv1r4sHlVX62rwFfPeia7FE3bFz5rIKelL82jByj3pYzi9+Cs+FroQ== 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=U3xIJ1qn; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=google header.b=VJDFFMC8; arc=none smtp.remote-ip=170.10.129.124 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 6E296606A332 for ; Tue, 1 Dec 2026 14:57:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6E296606A332 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=U3xIJ1qn; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=google header.b=VJDFFMC8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1796137029; 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=U3xIJ1qnuRKRD8RP7WBo/LmiCfGYbj+Rp7zP5hx4qJBdfobGH4mnC67/ZIF4HL1XeVl+xV wp2npXYa7zSjSjx9qwZUehH7xfHGmevZoIyOwQsDvKtgJjv7+DEIhse65qcqB4b592pBh3 NSouRwP4NtsS+d/N9VktmZoNm7eV1rI= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-361-pUISQIWDMEqSnNFUd0OsWQ-1; Tue, 1 Dec 2026 14:57:07 +0000 X-MC-Unique: pUISQIWDMEqSnNFUd0OsWQ-1 X-Mimecast-MFC-AGG-ID: pUISQIWDMEqSnNFUd0OsWQ_1796137026 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-4925ef75fc4so7340978f8f.1 for ; Tue, 01 Dec 2026 06:57:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1796137026; x=1796741826; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=MaZS7WybMW7W0ZwBqeGAPD1oS8DSSeNP8Urn9tWB5Ts=; b=VJDFFMC80PUeEz+X0WxtHJtzXftmWmutywtDy0BnYnRWkALPutaz8RD8v9sfcvLu9g DY0M3LHhDqgiLDRhjaQeygu/YuVaNkwQ3I29RZW7L97qkMPs7DFvPspfEohkTXNoQwxQ k3vBr3uJqSwbemV8RF61IFYCwliacGt4UQ3Q0mQAaUSZBwnarQNCUsL+GAVUcVk0YvYo JxYYxIp2XDoXdB3UDfHAnxn+E1e/HIUHVIQ/10g2woxLJ0ywOdE8PZGdm2enOaCAJhMu p5jrkv8/mSimbi4emqVcb277t/3+MBIacJTaYRGcdvVZXptCcJCrmBd8XX1f0kHab8gw ks+g== 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=EQ2S8VVsjN91Xv7Xotnlx7MNAxQQ9OgrzPfnmG3+WZgWwFzHpp2up63eP/tuWY5QGT z/BaKQdieo+5yiS7qnXlETMqQhUWH5Pcf3teeDC3DloYT8vBbURl3qoRzPyEkFgHlQJV qLlaI1x3uLkasOiHAlJuf+UPXtTy6yZzE7HpT7TDB6lh9i3GPx7OgSrZxKFqCHtvzuxu 8ijxbH4788sCGANnikm0ZyAl21O32As4Jo3kGVt0sKBBNmKe8P0fOlvw7jpiNX1rACUv DAyjcVdkutUQIHJBYCigrBo6Fj2BmVQ81Upv9ysfsgW/mWO576qj6V5YuBCi9wl6TaM4 Dd9A== X-Forwarded-Encrypted: i=1; AL+hErFtYyo2c4WU4JxesJBIOBtWvXM/x02e8dYb35yRLiHlzbGXwY6IveY/DcAHuFJ11y2EvMlOiczxSlne+zU=@vger.kernel.org X-Gm-Message-State: APuU4Z9nZ46bdC30kqIsl3B8c0Su0cyr7qgT1s4LRiUJkQdaHMNhpNOl 1Q6Yjs1MW96VeyRidyTG+O2HKLU9QyaivsTvz8VZkdkxc+dqZZk3yp90xroG4zmASypwPGwYcZE fLsi1Ll4YKykGJMAEMQMJn19A98ktnwytqpeZF52OGkNXpX7GtCTC/ZfUMfwZR6NfXg== X-Gm-Gg: AZFdTZdmOtxvvZXOSEcqva9RYBX4aOeUewDXX35xLQch9VqEu50/wS8bnZUti04bCM8 qwVuYBeqa04kVG/ZWp5rZ/bdvXd/u3kUepeVnKtqb6Zi1KZoU/6V53M1Q477cQPSBGk//MsJP9p REsxw7tdWymb3a4Y1F7x8dsFlMaf/Md1TQceBGqJuZoEPTK9qldmepCUQ1eKSPw2e+rdmoEIWuM smhuNIyLHkGTnig2tZzrTlWogJrORL35KsuxZ+EB1C0YOmgd8hafO1koQv8pRDagEnlCVTKl6iy T4w/CSBJuZH4iDBDcLC9hM3LexErwvBFGMvIuPpkT29FkPN5/d8Tz8JmWY7WRwG45q8uMPLVqPl dira1t+YmKZowgk8fMgtH9qCeoc0m9+Gm3x0HmSsRG9Wu2ClfDOPee410qT2QyGV7Z+8rNQChaI 0i46lpStPtetb2/w== X-Received: by 2002:a05:6000:27c1:b0:4a5:26ff:13d0 with SMTP id ffacd0b85a97d-4abb0f3b5bdmr47379470f8f.14.1796137026114; 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: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <179602872770.13688.17108715679213800277@126.com> 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); > > >