Re: vhost-net: is there a race for sock in handle_tx/rx?

From: Liu ping fan
Date: Thu May 03 2012 - 05:08:08 EST


Oh, got it. It is a very interesting implement.

Thanks and regards,
pingfan

On Thu, May 3, 2012 at 4:41 PM, Michael S. Tsirkin <mst@xxxxxxxxxx> wrote:
> On Thu, May 03, 2012 at 04:33:55PM +0800, Liu ping fan wrote:
>> Hi,
>>
>> During reading the vhost-net code, I find the following,
>>
>> static void handle_tx(struct vhost_net *net)
>> {
>> Â Â Â struct vhost_virtqueue *vq = &net->dev.vqs[VHOST_NET_VQ_TX];
>> Â Â Â unsigned out, in, s;
>> Â Â Â int head;
>> Â Â Â struct msghdr msg = {
>> Â Â Â Â Â Â Â .msg_name = NULL,
>> Â Â Â Â Â Â Â .msg_namelen = 0,
>> Â Â Â Â Â Â Â .msg_control = NULL,
>> Â Â Â Â Â Â Â .msg_controllen = 0,
>> Â Â Â Â Â Â Â .msg_iov = vq->iov,
>> Â Â Â Â Â Â Â .msg_flags = MSG_DONTWAIT,
>> Â Â Â };
>> Â Â Â size_t len, total_len = 0;
>> Â Â Â int err, wmem;
>> Â Â Â size_t hdr_size;
>> Â Â Â struct socket *sock;
>> Â Â Â struct vhost_ubuf_ref *uninitialized_var(ubufs);
>> Â Â Â bool zcopy;
>>
>> Â Â Â /* TODO: check that we are running from vhost_worker? */
>> Â Â Â sock = rcu_dereference_check(vq->private_data, 1);
>> Â Â Â if (!sock)
>> Â Â Â Â Â Â Â return;
>>
>> Â Â Â Â Â Â--------------------------------> Qemu calls
>> vhost_net_set_backend() to set a new backend fd, and close
>> @oldsock->file. And Âsock->file refcnt==0.
>>
>> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Can vhost_worker prevent
>> itself from such situation? And how?
>>
>> Â Â Â wmem = atomic_read(&sock->sk->sk_wmem_alloc);
>> Â Â Â Â.........................................................................
>>
>> Is it a race?
>>
>> Thanks and regards,
>> pingfan
>
> See comment before void __rcu *private_data in vhost.h
>
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/