Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [High] vhost/vsock: hlist_node reuse in vhost_vsock_set_cid() breaks
  RCU readers [1]
--

commit acdb8244e7111ba9c993f9a479a6926d4b658392
Author: Nguyen Dinh Phi <[email protected]>

vhost/vsock: annotate lockless accesses to guest_cid

This commit annotates the write to vhost_vsock.guest_cid in
vhost_vsock_set_cid() with WRITE_ONCE() and the lockless reads in
vhost_vsock_get() and vhost_vsock_handle_tx_kick() with READ_ONCE() to
avoid KCSAN data-race reports.

> diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c
> index 88a310390eb0a..f26c590130759 100644
> --- a/drivers/vhost/vsock.c
> +++ b/drivers/vhost/vsock.c

[ ... ]

> @@ -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);

[Severity: High]
This problem wasn't introduced by this patch, but can reusing vsock->hash
here without waiting for an RCU grace period break concurrent RCU readers
[1]?

When VHOST_VSOCK_SET_GUEST_CID changes an existing CID, hash_del_rcu()
unlinks vsock->hash from the old bucket and hash_add_rcu() immediately
overwrites vsock->hash.next to insert it into the new bucket.  A
concurrent vhost_vsock_get() traversing the old bucket via
hash_for_each_possible_rcu() can follow the updated next pointer into the
wrong bucket, skipping the rest of the original chain (causing CID lookup
failures and dropped packets) or looping indefinitely if the node is
re-added to the same bucket.

[1] https://sashiko.dev/#/bug/linux-0431a358-6215-4016-8a71-f047effc16b0

-- 
Sashiko AI review ยท 
https://sashiko.dev/#/patchset/[email protected]?part=1

Reply via email to