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=1794983615; b=Y8fH4usWjYJvnKgj5lKZHgnUUq1QSf9p+x++ZczDDedqetcNCxjuSXYqdfqhMIv6ppfH bUM2SwD2ogMmkksE15meWCYdKONRRdXR5caHMNPo/1GnYd89F6m9GeBz/phV6duPoYNK9 uDJQvNcNDUqrTXhEOYN7OBtFi52qAdzHy/BcSvERhxYjX15qJuad+THtJeWvt9a5Qhe8B /99sm9frXYlui6uQSbPqlQ4b3dzS/Ha3RibPA3C/QoIW0fF9OPEddgK6WjqigPyV1RqOY F/6q2HC0KrbDPjtuhNrgMSf7oqT10LijWLDchB/B2gFm1WiG0zsiKcQ7n/9xSekcZsA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794983615; 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=jm9UtSkj5qTjc2aQp3GV2uLJyBITV/apzUIo7FVG7gI=; b=AqnffawiIb2FdJuR5NxLPLGxAk6LD5AmvvV1+BbUJrrUm7XRFlLVC9siSJQxokbCo0jz DKu6rlIb5mROETlcJXTW7kwMqLq8TJYvZAgXQQ87OJgQ8Z948dmS/C3JmtwolKaK177T7 hUyXoMh37rgurlTyxbSk5hHIpeOjeQJjXlI//ti7CrNEeG5mfnLhCzbxxi2xqizauWgaT 4VGthChbrLyrDTDyjUo/RhQotd0JO2oVsXuel0XQomN9R79aZbfWm5lnTZtnOK0rcwj8A 4ghLlmWI5fI4FStnUC/59hO98+J1eSPfLuim0lL/tyzWvJeyVaT8ex7HuUlMvKvSI0A== 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=ivQghRHa; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=google header.b=Fp4fJ3jX; 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 80C04606A32C for ; Wed, 18 Nov 2026 06:33:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 80C04606A32C 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=ivQghRHa; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=google header.b=Fp4fJ3jX DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1794983613; 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=jm9UtSkj5qTjc2aQp3GV2uLJyBITV/apzUIo7FVG7gI=; b=ivQghRHa7aHXycTCAk13nbpBx5z3W1dNgH+vQvlGMON2X+QF8CBPBJYbgBV97RbUwDRtir exKvSiGE3g88NUClB4MN3HXn5hqkE0eHVgrayFvP8p0bUp39vPsN01tn3Pl+j+4cRTPjmT esvnfSTamqwBk1Sndn3g4AOGQaE90ak= 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-625-XTjLNstQPEa8JAzq4L6qRA-1; Wed, 18 Nov 2026 01:33:31 -0500 X-MC-Unique: XTjLNstQPEa8JAzq4L6qRA-1 X-Mimecast-MFC-AGG-ID: XTjLNstQPEa8JAzq4L6qRA_1794983610 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-4901562b819so439939f8f.3 for ; Tue, 17 Nov 2026 22:33:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1794983610; x=1795588410; 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=jm9UtSkj5qTjc2aQp3GV2uLJyBITV/apzUIo7FVG7gI=; b=Fp4fJ3jX8fL3RkP2MYtSO/q5wVOjCaqut2mwdt3VSNCGIWBmalQYnQEsH/v/Wp7w36 ppoCCpu6jqoQWcmpIKe6gsQnZUMBvAzBMk+W71ojaWP9ncG6lGw10PhcK8nDDi9gcukU 8Xce9Ujz27J7Nr2MYnUTyRls4WOCxuIfejnwF+RLNtpsMWAjeDrWOXEfombtByHcmuAc O52cL4ND9OMyLIYVc5jvbt1NjWIeAjHn2noPkhTb+vstAcWbNJypjGOPXDNkxhVCbL4I /OU8BKWNVeCeLR44YJJsrBPcx7A7FoNv+frcRCsKviZfdVJBvdyooV1r7cUcUUNE/ycW 7zHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794983610; x=1795588410; 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=jm9UtSkj5qTjc2aQp3GV2uLJyBITV/apzUIo7FVG7gI=; b=zPXQFXnYkcqvt/knxUhKI7SkSNV/IrBbQO60xB3xCCeupO3WgOvh9H4GegnpuawyZA 9zkcVkmWLthXHfoNAgxLNxSE41YU6mumtwv9TYE7djONIGYrHH50+m/QKJxZz79qcELB 0ZiSoqTU5FG72ml5Gzurojg/dNKxjyO/i/17gAOC1ptma1r3PdS4O1fdXMwh4IHjJlgA ZIi0YJklbsIJ3L7RVrh7KgwFzpYCJB1hlvSe+sZ9i+aV6CmKzK6RJYvfJJUImyxm2VfY RO5TRyZP/DtWtuHNFq9yOXfxpgQ2H1Y53WwGMFa6ioUoCYNCkUvtLnPSLvkG8gkGrg9T kn6g== X-Forwarded-Encrypted: i=1; AL+hErGCtVjnWWPpLEGsEmUWc+qWLbdwt4H392vAogGYBsVn0KRUClH8I6v1LdK4PhgNH/G/HBKMAAlr6ybaWcQ=@vger.kernel.org X-Gm-Message-State: APuU4Z/4UtA5+cnfMU07XNgB/Cn+SbmnRdU88qa2/gTPs5VCksJgCSym I/2WfsejhAq7mb/wIzyK4QC4eZclcbpcXkGVJUdZPbHZ2vMt7MSzS9ofexV5e/H+wHbaXi9Wg4L M4pogwl1e08XOIfD21Vh4kjbsJ7pXiXDYsDbDuBj5XtF0OgccHIBxmK+7pwUzYWecZA== X-Gm-Gg: AZFdTZeZN7hupBcvBiAmd1ntUEsEYLdgkzr31yo7iu5iiyN4IVmoZaatKk370VZJG1C 61bdL/WR2KM0AGPfWiH0KoUU1v20fjHJLLyMcPiSVNaDQ1629uhBOYEeTI0i88+lfQM7oWISp1N DFCNTE48KiGXVm2Et+lgbmFof8Nm58FZqS7Yn85owqGB+ccr8HGHbcWd9H3b9RxXczKCVxHVA/b nNFCHYeEog9Qo5dtP0g+bFvfpq5OfE57t79cGCyU1zOfkBYEumUQGqWW6EU181G12fJczAF9fV6 YcZvGAQs6G4sxObDhpvbHG5CyuWvvNJiI7olH/OarZuhcW0qXsJaz4Grruj9/Z8jDVysVg6I3ek 7JpZlpTj7vyk4V9iUQc9iD8SqSvGQjXD6/iOs1U7vLw4= X-Received: by 2002:a5d:5d0d:0:b0:4a7:9630:7b5a with SMTP id ffacd0b85a97d-4a7963080e7mr331956f8f.47.1794983610321; Tue, 17 Nov 2026 22:33:30 -0800 (PST) X-Received: by 2002:a5d:5d0d:0:b0:4a7:9630:7b5a with SMTP id ffacd0b85a97d-4a7963080e7mr331922f8f.47.1794983609777; Tue, 17 Nov 2026 22:33:29 -0800 (PST) Received: from redhat.com ([2a0d:6fc0:1520:4400:d78d:7b2d:2f5d:e08f]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4a65560b5f1sm2935743f8f.21.2026.11.17.22.33.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Nov 2026 22:33:28 -0800 (PST) Date: Wed, 18 Nov 2026 01:33:26 -0500 From: "Michael S. Tsirkin" To: Nguyen Dinh Phi Cc: Stefan Hajnoczi , Stefano Garzarella , Bobby Eshleman , Jason Wang , Eugenio =?iso-8859-1?Q?P=E9rez?= , Asias He , kvm@vger.kernel.org, virtualization@lists.linux.dev, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH net] vhost/vsock: annotate lockless accesses to guest_cid Message-ID: <20261118012321-mutt-send-email-mst@kernel.org> References: <20261117164916.2332953-1-phind.uet@gmail.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 Content-Disposition: inline In-Reply-To: <20261117164916.2332953-1-phind.uet@gmail.com> On Wed, Nov 18, 2026 at 12:48:43AM +0800, Nguyen Dinh Phi wrote: > vhost_vsock.guest_cid is written by vhost_vsock_set_cid() under > vhost_vsock_mutex, but It is also read without that mutex in > vhost_vsock_handle_tx_kick(), and vhost_vsock_get(). > > KCSAN will report data-race if we issue VHOST_VSOCK_SET_GUEST_CID > ioctl while the device has TX traffic. For example: > > write to 0xffff88810f1596ac of 4 bytes by task 7914 on cpu 1: > vhost_vsock_dev_ioctl+0x25f/0x720 > __x64_sys_ioctl+0xc2/0x110 > x64_sys_call+0x299/0x20a0 > do_syscall_64+0xc9/0x510 > entry_SYSCALL_64_after_hwframe+0x76/0x7e > > read to 0xffff88810f1596ac of 4 bytes by task 7910 on cpu 3: > vhost_vsock_handle_tx_kick+0x41b/0x740 > vhost_run_work_list+0x97/0xc0 > vhost_task_fn+0x98/0x1f0 > ret_from_fork+0x2e2/0x3c0 > ret_from_fork_asm+0x1a/0x30 > > value changed: 0x0000004d -> 0x00000032 > > Both readers load the CID once and works correctly with either the > old or the new value. > > Mark the store with WRITE_ONCE() and the two lockless loads with > READ_ONCE(), so KCSAN knows the race is intentional. You make it sounds like it is just KCSAN false positive. Is it? if yes, this should be data_race. If no, document why. > > Fixes: 433fc58e6bf2 ("VSOCK: Introduce vhost_vsock.ko") > Signed-off-by: Nguyen Dinh Phi > --- > drivers/vhost/vsock.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c > index 88a310390eb0..f26c59013075 100644 > --- a/drivers/vhost/vsock.c > +++ b/drivers/vhost/vsock.c > @@ -78,7 +78,7 @@ static struct vhost_vsock *vhost_vsock_get(u32 guest_cid, struct net *net) > > 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(struct vhost_work *work) > 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, Will prevent compiler from hoisting the reads out of the loops. Does it matter? > @@ -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); > > -- > 2.53.0