Merge tag 'compat-ioctl-5.5' of git://git.kernel.org:/pub/scm/linux/kernel/git/arnd...
[linux-2.6-block.git] / drivers / vhost / vsock.c
index 706c5e8e01ee29a3c68aa217eefb072aa7910f9e..50de0642dea6bf496815eb80329228a25795afc0 100644 (file)
@@ -384,6 +384,49 @@ static bool vhost_vsock_more_replies(struct vhost_vsock *vsock)
        return val < vq->num;
 }
 
+static struct virtio_transport vhost_transport = {
+       .transport = {
+               .module                   = THIS_MODULE,
+
+               .get_local_cid            = vhost_transport_get_local_cid,
+
+               .init                     = virtio_transport_do_socket_init,
+               .destruct                 = virtio_transport_destruct,
+               .release                  = virtio_transport_release,
+               .connect                  = virtio_transport_connect,
+               .shutdown                 = virtio_transport_shutdown,
+               .cancel_pkt               = vhost_transport_cancel_pkt,
+
+               .dgram_enqueue            = virtio_transport_dgram_enqueue,
+               .dgram_dequeue            = virtio_transport_dgram_dequeue,
+               .dgram_bind               = virtio_transport_dgram_bind,
+               .dgram_allow              = virtio_transport_dgram_allow,
+
+               .stream_enqueue           = virtio_transport_stream_enqueue,
+               .stream_dequeue           = virtio_transport_stream_dequeue,
+               .stream_has_data          = virtio_transport_stream_has_data,
+               .stream_has_space         = virtio_transport_stream_has_space,
+               .stream_rcvhiwat          = virtio_transport_stream_rcvhiwat,
+               .stream_is_active         = virtio_transport_stream_is_active,
+               .stream_allow             = virtio_transport_stream_allow,
+
+               .notify_poll_in           = virtio_transport_notify_poll_in,
+               .notify_poll_out          = virtio_transport_notify_poll_out,
+               .notify_recv_init         = virtio_transport_notify_recv_init,
+               .notify_recv_pre_block    = virtio_transport_notify_recv_pre_block,
+               .notify_recv_pre_dequeue  = virtio_transport_notify_recv_pre_dequeue,
+               .notify_recv_post_dequeue = virtio_transport_notify_recv_post_dequeue,
+               .notify_send_init         = virtio_transport_notify_send_init,
+               .notify_send_pre_block    = virtio_transport_notify_send_pre_block,
+               .notify_send_pre_enqueue  = virtio_transport_notify_send_pre_enqueue,
+               .notify_send_post_enqueue = virtio_transport_notify_send_post_enqueue,
+               .notify_buffer_size       = virtio_transport_notify_buffer_size,
+
+       },
+
+       .send_pkt = vhost_transport_send_pkt,
+};
+
 static void vhost_vsock_handle_tx_kick(struct vhost_work *work)
 {
        struct vhost_virtqueue *vq = container_of(work, struct vhost_virtqueue,
@@ -438,7 +481,7 @@ static void vhost_vsock_handle_tx_kick(struct vhost_work *work)
 
                /* Only accept correctly addressed packets */
                if (le64_to_cpu(pkt->hdr.src_cid) == vsock->guest_cid)
-                       virtio_transport_recv_pkt(pkt);
+                       virtio_transport_recv_pkt(&vhost_transport, pkt);
                else
                        virtio_transport_free_pkt(pkt);
 
@@ -675,6 +718,12 @@ static int vhost_vsock_set_cid(struct vhost_vsock *vsock, u64 guest_cid)
        if (guest_cid > U32_MAX)
                return -EINVAL;
 
+       /* Refuse if CID is assigned to the guest->host transport (i.e. nested
+        * VM), to make the loopback work.
+        */
+       if (vsock_find_cid(guest_cid))
+               return -EADDRINUSE;
+
        /* Refuse if CID is already in use */
        mutex_lock(&vhost_vsock_mutex);
        other = vhost_vsock_get(guest_cid);
@@ -776,57 +825,12 @@ static struct miscdevice vhost_vsock_misc = {
        .fops = &vhost_vsock_fops,
 };
 
-static struct virtio_transport vhost_transport = {
-       .transport = {
-               .get_local_cid            = vhost_transport_get_local_cid,
-
-               .init                     = virtio_transport_do_socket_init,
-               .destruct                 = virtio_transport_destruct,
-               .release                  = virtio_transport_release,
-               .connect                  = virtio_transport_connect,
-               .shutdown                 = virtio_transport_shutdown,
-               .cancel_pkt               = vhost_transport_cancel_pkt,
-
-               .dgram_enqueue            = virtio_transport_dgram_enqueue,
-               .dgram_dequeue            = virtio_transport_dgram_dequeue,
-               .dgram_bind               = virtio_transport_dgram_bind,
-               .dgram_allow              = virtio_transport_dgram_allow,
-
-               .stream_enqueue           = virtio_transport_stream_enqueue,
-               .stream_dequeue           = virtio_transport_stream_dequeue,
-               .stream_has_data          = virtio_transport_stream_has_data,
-               .stream_has_space         = virtio_transport_stream_has_space,
-               .stream_rcvhiwat          = virtio_transport_stream_rcvhiwat,
-               .stream_is_active         = virtio_transport_stream_is_active,
-               .stream_allow             = virtio_transport_stream_allow,
-
-               .notify_poll_in           = virtio_transport_notify_poll_in,
-               .notify_poll_out          = virtio_transport_notify_poll_out,
-               .notify_recv_init         = virtio_transport_notify_recv_init,
-               .notify_recv_pre_block    = virtio_transport_notify_recv_pre_block,
-               .notify_recv_pre_dequeue  = virtio_transport_notify_recv_pre_dequeue,
-               .notify_recv_post_dequeue = virtio_transport_notify_recv_post_dequeue,
-               .notify_send_init         = virtio_transport_notify_send_init,
-               .notify_send_pre_block    = virtio_transport_notify_send_pre_block,
-               .notify_send_pre_enqueue  = virtio_transport_notify_send_pre_enqueue,
-               .notify_send_post_enqueue = virtio_transport_notify_send_post_enqueue,
-
-               .set_buffer_size          = virtio_transport_set_buffer_size,
-               .set_min_buffer_size      = virtio_transport_set_min_buffer_size,
-               .set_max_buffer_size      = virtio_transport_set_max_buffer_size,
-               .get_buffer_size          = virtio_transport_get_buffer_size,
-               .get_min_buffer_size      = virtio_transport_get_min_buffer_size,
-               .get_max_buffer_size      = virtio_transport_get_max_buffer_size,
-       },
-
-       .send_pkt = vhost_transport_send_pkt,
-};
-
 static int __init vhost_vsock_init(void)
 {
        int ret;
 
-       ret = vsock_core_init(&vhost_transport.transport);
+       ret = vsock_core_register(&vhost_transport.transport,
+                                 VSOCK_TRANSPORT_F_H2G);
        if (ret < 0)
                return ret;
        return misc_register(&vhost_vsock_misc);
@@ -835,7 +839,7 @@ static int __init vhost_vsock_init(void)
 static void __exit vhost_vsock_exit(void)
 {
        misc_deregister(&vhost_vsock_misc);
-       vsock_core_exit();
+       vsock_core_unregister(&vhost_transport.transport);
 };
 
 module_init(vhost_vsock_init);