~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/net/vmw_vsock/vsock_loopback.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-only
  2 /* loopback transport for vsock using virtio_transport_common APIs
  3  *
  4  * Copyright (C) 2013-2019 Red Hat, Inc.
  5  * Authors: Asias He <asias@redhat.com>
  6  *          Stefan Hajnoczi <stefanha@redhat.com>
  7  *          Stefano Garzarella <sgarzare@redhat.com>
  8  *
  9  */
 10 #include <linux/spinlock.h>
 11 #include <linux/module.h>
 12 #include <linux/list.h>
 13 #include <linux/virtio_vsock.h>
 14 
 15 struct vsock_loopback {
 16         struct workqueue_struct *workqueue;
 17 
 18         struct sk_buff_head pkt_queue;
 19         struct work_struct pkt_work;
 20 };
 21 
 22 static struct vsock_loopback the_vsock_loopback;
 23 
 24 static u32 vsock_loopback_get_local_cid(void)
 25 {
 26         return VMADDR_CID_LOCAL;
 27 }
 28 
 29 static int vsock_loopback_send_pkt(struct sk_buff *skb)
 30 {
 31         struct vsock_loopback *vsock = &the_vsock_loopback;
 32         int len = skb->len;
 33 
 34         virtio_vsock_skb_queue_tail(&vsock->pkt_queue, skb);
 35         queue_work(vsock->workqueue, &vsock->pkt_work);
 36 
 37         return len;
 38 }
 39 
 40 static int vsock_loopback_cancel_pkt(struct vsock_sock *vsk)
 41 {
 42         struct vsock_loopback *vsock = &the_vsock_loopback;
 43 
 44         virtio_transport_purge_skbs(vsk, &vsock->pkt_queue);
 45 
 46         return 0;
 47 }
 48 
 49 static bool vsock_loopback_seqpacket_allow(u32 remote_cid);
 50 static bool vsock_loopback_msgzerocopy_allow(void)
 51 {
 52         return true;
 53 }
 54 
 55 static struct virtio_transport loopback_transport = {
 56         .transport = {
 57                 .module                   = THIS_MODULE,
 58 
 59                 .get_local_cid            = vsock_loopback_get_local_cid,
 60 
 61                 .init                     = virtio_transport_do_socket_init,
 62                 .destruct                 = virtio_transport_destruct,
 63                 .release                  = virtio_transport_release,
 64                 .connect                  = virtio_transport_connect,
 65                 .shutdown                 = virtio_transport_shutdown,
 66                 .cancel_pkt               = vsock_loopback_cancel_pkt,
 67 
 68                 .dgram_bind               = virtio_transport_dgram_bind,
 69                 .dgram_dequeue            = virtio_transport_dgram_dequeue,
 70                 .dgram_enqueue            = virtio_transport_dgram_enqueue,
 71                 .dgram_allow              = virtio_transport_dgram_allow,
 72 
 73                 .stream_dequeue           = virtio_transport_stream_dequeue,
 74                 .stream_enqueue           = virtio_transport_stream_enqueue,
 75                 .stream_has_data          = virtio_transport_stream_has_data,
 76                 .stream_has_space         = virtio_transport_stream_has_space,
 77                 .stream_rcvhiwat          = virtio_transport_stream_rcvhiwat,
 78                 .stream_is_active         = virtio_transport_stream_is_active,
 79                 .stream_allow             = virtio_transport_stream_allow,
 80 
 81                 .seqpacket_dequeue        = virtio_transport_seqpacket_dequeue,
 82                 .seqpacket_enqueue        = virtio_transport_seqpacket_enqueue,
 83                 .seqpacket_allow          = vsock_loopback_seqpacket_allow,
 84                 .seqpacket_has_data       = virtio_transport_seqpacket_has_data,
 85 
 86                 .msgzerocopy_allow        = vsock_loopback_msgzerocopy_allow,
 87 
 88                 .notify_poll_in           = virtio_transport_notify_poll_in,
 89                 .notify_poll_out          = virtio_transport_notify_poll_out,
 90                 .notify_recv_init         = virtio_transport_notify_recv_init,
 91                 .notify_recv_pre_block    = virtio_transport_notify_recv_pre_block,
 92                 .notify_recv_pre_dequeue  = virtio_transport_notify_recv_pre_dequeue,
 93                 .notify_recv_post_dequeue = virtio_transport_notify_recv_post_dequeue,
 94                 .notify_send_init         = virtio_transport_notify_send_init,
 95                 .notify_send_pre_block    = virtio_transport_notify_send_pre_block,
 96                 .notify_send_pre_enqueue  = virtio_transport_notify_send_pre_enqueue,
 97                 .notify_send_post_enqueue = virtio_transport_notify_send_post_enqueue,
 98                 .notify_buffer_size       = virtio_transport_notify_buffer_size,
 99                 .notify_set_rcvlowat      = virtio_transport_notify_set_rcvlowat,
100 
101                 .read_skb = virtio_transport_read_skb,
102         },
103 
104         .send_pkt = vsock_loopback_send_pkt,
105 };
106 
107 static bool vsock_loopback_seqpacket_allow(u32 remote_cid)
108 {
109         return true;
110 }
111 
112 static void vsock_loopback_work(struct work_struct *work)
113 {
114         struct vsock_loopback *vsock =
115                 container_of(work, struct vsock_loopback, pkt_work);
116         struct sk_buff_head pkts;
117         struct sk_buff *skb;
118 
119         skb_queue_head_init(&pkts);
120 
121         spin_lock_bh(&vsock->pkt_queue.lock);
122         skb_queue_splice_init(&vsock->pkt_queue, &pkts);
123         spin_unlock_bh(&vsock->pkt_queue.lock);
124 
125         while ((skb = __skb_dequeue(&pkts))) {
126                 virtio_transport_deliver_tap_pkt(skb);
127                 virtio_transport_recv_pkt(&loopback_transport, skb);
128         }
129 }
130 
131 static int __init vsock_loopback_init(void)
132 {
133         struct vsock_loopback *vsock = &the_vsock_loopback;
134         int ret;
135 
136         vsock->workqueue = alloc_workqueue("vsock-loopback", 0, 0);
137         if (!vsock->workqueue)
138                 return -ENOMEM;
139 
140         skb_queue_head_init(&vsock->pkt_queue);
141         INIT_WORK(&vsock->pkt_work, vsock_loopback_work);
142 
143         ret = vsock_core_register(&loopback_transport.transport,
144                                   VSOCK_TRANSPORT_F_LOCAL);
145         if (ret)
146                 goto out_wq;
147 
148         return 0;
149 
150 out_wq:
151         destroy_workqueue(vsock->workqueue);
152         return ret;
153 }
154 
155 static void __exit vsock_loopback_exit(void)
156 {
157         struct vsock_loopback *vsock = &the_vsock_loopback;
158 
159         vsock_core_unregister(&loopback_transport.transport);
160 
161         flush_work(&vsock->pkt_work);
162 
163         virtio_vsock_skb_queue_purge(&vsock->pkt_queue);
164 
165         destroy_workqueue(vsock->workqueue);
166 }
167 
168 module_init(vsock_loopback_init);
169 module_exit(vsock_loopback_exit);
170 MODULE_LICENSE("GPL v2");
171 MODULE_AUTHOR("Stefano Garzarella <sgarzare@redhat.com>");
172 MODULE_DESCRIPTION("loopback transport for vsock");
173 MODULE_ALIAS_NETPROTO(PF_VSOCK);
174 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php