net.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221
  1. /* Copyright (C) 2009 Red Hat, Inc.
  2. * Author: Michael S. Tsirkin <mst@redhat.com>
  3. *
  4. * This work is licensed under the terms of the GNU GPL, version 2.
  5. *
  6. * virtio-net server in host kernel.
  7. */
  8. #include <linux/compat.h>
  9. #include <linux/eventfd.h>
  10. #include <linux/vhost.h>
  11. #include <linux/virtio_net.h>
  12. #include <linux/miscdevice.h>
  13. #include <linux/module.h>
  14. #include <linux/moduleparam.h>
  15. #include <linux/mutex.h>
  16. #include <linux/workqueue.h>
  17. #include <linux/file.h>
  18. #include <linux/slab.h>
  19. #include <linux/vmalloc.h>
  20. #include <linux/net.h>
  21. #include <linux/if_packet.h>
  22. #include <linux/if_arp.h>
  23. #include <linux/if_tun.h>
  24. #include <linux/if_macvlan.h>
  25. #include <linux/if_vlan.h>
  26. #include <net/sock.h>
  27. #include "vhost.h"
  28. static int experimental_zcopytx = 1;
  29. module_param(experimental_zcopytx, int, 0444);
  30. MODULE_PARM_DESC(experimental_zcopytx, "Enable Zero Copy TX;"
  31. " 1 -Enable; 0 - Disable");
  32. /* Max number of bytes transferred before requeueing the job.
  33. * Using this limit prevents one virtqueue from starving others. */
  34. #define VHOST_NET_WEIGHT 0x80000
  35. /* MAX number of TX used buffers for outstanding zerocopy */
  36. #define VHOST_MAX_PEND 128
  37. #define VHOST_GOODCOPY_LEN 256
  38. /*
  39. * For transmit, used buffer len is unused; we override it to track buffer
  40. * status internally; used for zerocopy tx only.
  41. */
  42. /* Lower device DMA failed */
  43. #define VHOST_DMA_FAILED_LEN ((__force __virtio32)3)
  44. /* Lower device DMA done */
  45. #define VHOST_DMA_DONE_LEN ((__force __virtio32)2)
  46. /* Lower device DMA in progress */
  47. #define VHOST_DMA_IN_PROGRESS ((__force __virtio32)1)
  48. /* Buffer unused */
  49. #define VHOST_DMA_CLEAR_LEN ((__force __virtio32)0)
  50. #define VHOST_DMA_IS_DONE(len) ((__force u32)(len) >= (__force u32)VHOST_DMA_DONE_LEN)
  51. enum {
  52. VHOST_NET_FEATURES = VHOST_FEATURES |
  53. (1ULL << VHOST_NET_F_VIRTIO_NET_HDR) |
  54. (1ULL << VIRTIO_NET_F_MRG_RXBUF)
  55. };
  56. enum {
  57. VHOST_NET_VQ_RX = 0,
  58. VHOST_NET_VQ_TX = 1,
  59. VHOST_NET_VQ_MAX = 2,
  60. };
  61. struct vhost_net_ubuf_ref {
  62. /* refcount follows semantics similar to kref:
  63. * 0: object is released
  64. * 1: no outstanding ubufs
  65. * >1: outstanding ubufs
  66. */
  67. atomic_t refcount;
  68. wait_queue_head_t wait;
  69. struct vhost_virtqueue *vq;
  70. };
  71. struct vhost_net_virtqueue {
  72. struct vhost_virtqueue vq;
  73. size_t vhost_hlen;
  74. size_t sock_hlen;
  75. /* vhost zerocopy support fields below: */
  76. /* last used idx for outstanding DMA zerocopy buffers */
  77. int upend_idx;
  78. /* first used idx for DMA done zerocopy buffers */
  79. int done_idx;
  80. /* an array of userspace buffers info */
  81. struct ubuf_info *ubuf_info;
  82. /* Reference counting for outstanding ubufs.
  83. * Protected by vq mutex. Writers must also take device mutex. */
  84. struct vhost_net_ubuf_ref *ubufs;
  85. };
  86. struct vhost_net {
  87. struct vhost_dev dev;
  88. struct vhost_net_virtqueue vqs[VHOST_NET_VQ_MAX];
  89. struct vhost_poll poll[VHOST_NET_VQ_MAX];
  90. /* Number of TX recently submitted.
  91. * Protected by tx vq lock. */
  92. unsigned tx_packets;
  93. /* Number of times zerocopy TX recently failed.
  94. * Protected by tx vq lock. */
  95. unsigned tx_zcopy_err;
  96. /* Flush in progress. Protected by tx vq lock. */
  97. bool tx_flush;
  98. };
  99. static unsigned vhost_net_zcopy_mask __read_mostly;
  100. static void vhost_net_enable_zcopy(int vq)
  101. {
  102. vhost_net_zcopy_mask |= 0x1 << vq;
  103. }
  104. static struct vhost_net_ubuf_ref *
  105. vhost_net_ubuf_alloc(struct vhost_virtqueue *vq, bool zcopy)
  106. {
  107. struct vhost_net_ubuf_ref *ubufs;
  108. /* No zero copy backend? Nothing to count. */
  109. if (!zcopy)
  110. return NULL;
  111. ubufs = kmalloc(sizeof(*ubufs), GFP_KERNEL);
  112. if (!ubufs)
  113. return ERR_PTR(-ENOMEM);
  114. atomic_set(&ubufs->refcount, 1);
  115. init_waitqueue_head(&ubufs->wait);
  116. ubufs->vq = vq;
  117. return ubufs;
  118. }
  119. static int vhost_net_ubuf_put(struct vhost_net_ubuf_ref *ubufs)
  120. {
  121. int r = atomic_sub_return(1, &ubufs->refcount);
  122. if (unlikely(!r))
  123. wake_up(&ubufs->wait);
  124. return r;
  125. }
  126. static void vhost_net_ubuf_put_and_wait(struct vhost_net_ubuf_ref *ubufs)
  127. {
  128. vhost_net_ubuf_put(ubufs);
  129. wait_event(ubufs->wait, !atomic_read(&ubufs->refcount));
  130. }
  131. static void vhost_net_ubuf_put_wait_and_free(struct vhost_net_ubuf_ref *ubufs)
  132. {
  133. vhost_net_ubuf_put_and_wait(ubufs);
  134. kfree(ubufs);
  135. }
  136. static void vhost_net_clear_ubuf_info(struct vhost_net *n)
  137. {
  138. int i;
  139. for (i = 0; i < VHOST_NET_VQ_MAX; ++i) {
  140. kfree(n->vqs[i].ubuf_info);
  141. n->vqs[i].ubuf_info = NULL;
  142. }
  143. }
  144. static int vhost_net_set_ubuf_info(struct vhost_net *n)
  145. {
  146. bool zcopy;
  147. int i;
  148. for (i = 0; i < VHOST_NET_VQ_MAX; ++i) {
  149. zcopy = vhost_net_zcopy_mask & (0x1 << i);
  150. if (!zcopy)
  151. continue;
  152. n->vqs[i].ubuf_info = kmalloc(sizeof(*n->vqs[i].ubuf_info) *
  153. UIO_MAXIOV, GFP_KERNEL);
  154. if (!n->vqs[i].ubuf_info)
  155. goto err;
  156. }
  157. return 0;
  158. err:
  159. vhost_net_clear_ubuf_info(n);
  160. return -ENOMEM;
  161. }
  162. static void vhost_net_vq_reset(struct vhost_net *n)
  163. {
  164. int i;
  165. vhost_net_clear_ubuf_info(n);
  166. for (i = 0; i < VHOST_NET_VQ_MAX; i++) {
  167. n->vqs[i].done_idx = 0;
  168. n->vqs[i].upend_idx = 0;
  169. n->vqs[i].ubufs = NULL;
  170. n->vqs[i].vhost_hlen = 0;
  171. n->vqs[i].sock_hlen = 0;
  172. }
  173. }
  174. static void vhost_net_tx_packet(struct vhost_net *net)
  175. {
  176. ++net->tx_packets;
  177. if (net->tx_packets < 1024)
  178. return;
  179. net->tx_packets = 0;
  180. net->tx_zcopy_err = 0;
  181. }
  182. static void vhost_net_tx_err(struct vhost_net *net)
  183. {
  184. ++net->tx_zcopy_err;
  185. }
  186. static bool vhost_net_tx_select_zcopy(struct vhost_net *net)
  187. {
  188. /* TX flush waits for outstanding DMAs to be done.
  189. * Don't start new DMAs.
  190. */
  191. return !net->tx_flush &&
  192. net->tx_packets / 64 >= net->tx_zcopy_err;
  193. }
  194. static bool vhost_sock_zcopy(struct socket *sock)
  195. {
  196. return unlikely(experimental_zcopytx) &&
  197. sock_flag(sock->sk, SOCK_ZEROCOPY);
  198. }
  199. /* In case of DMA done not in order in lower device driver for some reason.
  200. * upend_idx is used to track end of used idx, done_idx is used to track head
  201. * of used idx. Once lower device DMA done contiguously, we will signal KVM
  202. * guest used idx.
  203. */
  204. static void vhost_zerocopy_signal_used(struct vhost_net *net,
  205. struct vhost_virtqueue *vq)
  206. {
  207. struct vhost_net_virtqueue *nvq =
  208. container_of(vq, struct vhost_net_virtqueue, vq);
  209. int i, add;
  210. int j = 0;
  211. for (i = nvq->done_idx; i != nvq->upend_idx; i = (i + 1) % UIO_MAXIOV) {
  212. if (vq->heads[i].len == VHOST_DMA_FAILED_LEN)
  213. vhost_net_tx_err(net);
  214. if (VHOST_DMA_IS_DONE(vq->heads[i].len)) {
  215. vq->heads[i].len = VHOST_DMA_CLEAR_LEN;
  216. ++j;
  217. } else
  218. break;
  219. }
  220. while (j) {
  221. add = min(UIO_MAXIOV - nvq->done_idx, j);
  222. vhost_add_used_and_signal_n(vq->dev, vq,
  223. &vq->heads[nvq->done_idx], add);
  224. nvq->done_idx = (nvq->done_idx + add) % UIO_MAXIOV;
  225. j -= add;
  226. }
  227. }
  228. static void vhost_zerocopy_callback(struct ubuf_info *ubuf, bool success)
  229. {
  230. struct vhost_net_ubuf_ref *ubufs = ubuf->ctx;
  231. struct vhost_virtqueue *vq = ubufs->vq;
  232. int cnt;
  233. rcu_read_lock_bh();
  234. /* set len to mark this desc buffers done DMA */
  235. vq->heads[ubuf->desc].len = success ?
  236. VHOST_DMA_DONE_LEN : VHOST_DMA_FAILED_LEN;
  237. cnt = vhost_net_ubuf_put(ubufs);
  238. /*
  239. * Trigger polling thread if guest stopped submitting new buffers:
  240. * in this case, the refcount after decrement will eventually reach 1.
  241. * We also trigger polling periodically after each 16 packets
  242. * (the value 16 here is more or less arbitrary, it's tuned to trigger
  243. * less than 10% of times).
  244. */
  245. if (cnt <= 1 || !(cnt % 16))
  246. vhost_poll_queue(&vq->poll);
  247. rcu_read_unlock_bh();
  248. }
  249. static inline unsigned long busy_clock(void)
  250. {
  251. return local_clock() >> 10;
  252. }
  253. static bool vhost_can_busy_poll(struct vhost_dev *dev,
  254. unsigned long endtime)
  255. {
  256. return likely(!need_resched()) &&
  257. likely(!time_after(busy_clock(), endtime)) &&
  258. likely(!signal_pending(current)) &&
  259. !vhost_has_work(dev);
  260. }
  261. static void vhost_net_disable_vq(struct vhost_net *n,
  262. struct vhost_virtqueue *vq)
  263. {
  264. struct vhost_net_virtqueue *nvq =
  265. container_of(vq, struct vhost_net_virtqueue, vq);
  266. struct vhost_poll *poll = n->poll + (nvq - n->vqs);
  267. if (!vq->private_data)
  268. return;
  269. vhost_poll_stop(poll);
  270. }
  271. static int vhost_net_enable_vq(struct vhost_net *n,
  272. struct vhost_virtqueue *vq)
  273. {
  274. struct vhost_net_virtqueue *nvq =
  275. container_of(vq, struct vhost_net_virtqueue, vq);
  276. struct vhost_poll *poll = n->poll + (nvq - n->vqs);
  277. struct socket *sock;
  278. sock = vq->private_data;
  279. if (!sock)
  280. return 0;
  281. return vhost_poll_start(poll, sock->file);
  282. }
  283. static int vhost_net_tx_get_vq_desc(struct vhost_net *net,
  284. struct vhost_virtqueue *vq,
  285. struct iovec iov[], unsigned int iov_size,
  286. unsigned int *out_num, unsigned int *in_num)
  287. {
  288. unsigned long uninitialized_var(endtime);
  289. int r = vhost_get_vq_desc(vq, vq->iov, ARRAY_SIZE(vq->iov),
  290. out_num, in_num, NULL, NULL);
  291. if (r == vq->num && vq->busyloop_timeout) {
  292. preempt_disable();
  293. endtime = busy_clock() + vq->busyloop_timeout;
  294. while (vhost_can_busy_poll(vq->dev, endtime) &&
  295. vhost_vq_avail_empty(vq->dev, vq))
  296. cpu_relax_lowlatency();
  297. preempt_enable();
  298. r = vhost_get_vq_desc(vq, vq->iov, ARRAY_SIZE(vq->iov),
  299. out_num, in_num, NULL, NULL);
  300. }
  301. return r;
  302. }
  303. /* Expects to be always run from workqueue - which acts as
  304. * read-size critical section for our kind of RCU. */
  305. static void handle_tx(struct vhost_net *net)
  306. {
  307. struct vhost_net_virtqueue *nvq = &net->vqs[VHOST_NET_VQ_TX];
  308. struct vhost_virtqueue *vq = &nvq->vq;
  309. unsigned out, in;
  310. int head;
  311. struct msghdr msg = {
  312. .msg_name = NULL,
  313. .msg_namelen = 0,
  314. .msg_control = NULL,
  315. .msg_controllen = 0,
  316. .msg_flags = MSG_DONTWAIT,
  317. };
  318. size_t len, total_len = 0;
  319. int err;
  320. size_t hdr_size;
  321. struct socket *sock;
  322. struct vhost_net_ubuf_ref *uninitialized_var(ubufs);
  323. bool zcopy, zcopy_used;
  324. mutex_lock(&vq->mutex);
  325. sock = vq->private_data;
  326. if (!sock)
  327. goto out;
  328. vhost_disable_notify(&net->dev, vq);
  329. hdr_size = nvq->vhost_hlen;
  330. zcopy = nvq->ubufs;
  331. for (;;) {
  332. /* Release DMAs done buffers first */
  333. if (zcopy)
  334. vhost_zerocopy_signal_used(net, vq);
  335. /* If more outstanding DMAs, queue the work.
  336. * Handle upend_idx wrap around
  337. */
  338. if (unlikely((nvq->upend_idx + vq->num - VHOST_MAX_PEND)
  339. % UIO_MAXIOV == nvq->done_idx))
  340. break;
  341. head = vhost_net_tx_get_vq_desc(net, vq, vq->iov,
  342. ARRAY_SIZE(vq->iov),
  343. &out, &in);
  344. /* On error, stop handling until the next kick. */
  345. if (unlikely(head < 0))
  346. break;
  347. /* Nothing new? Wait for eventfd to tell us they refilled. */
  348. if (head == vq->num) {
  349. if (unlikely(vhost_enable_notify(&net->dev, vq))) {
  350. vhost_disable_notify(&net->dev, vq);
  351. continue;
  352. }
  353. break;
  354. }
  355. if (in) {
  356. vq_err(vq, "Unexpected descriptor format for TX: "
  357. "out %d, int %d\n", out, in);
  358. break;
  359. }
  360. /* Skip header. TODO: support TSO. */
  361. len = iov_length(vq->iov, out);
  362. iov_iter_init(&msg.msg_iter, WRITE, vq->iov, out, len);
  363. iov_iter_advance(&msg.msg_iter, hdr_size);
  364. /* Sanity check */
  365. if (!msg_data_left(&msg)) {
  366. vq_err(vq, "Unexpected header len for TX: "
  367. "%zd expected %zd\n",
  368. len, hdr_size);
  369. break;
  370. }
  371. len = msg_data_left(&msg);
  372. zcopy_used = zcopy && len >= VHOST_GOODCOPY_LEN
  373. && (nvq->upend_idx + 1) % UIO_MAXIOV !=
  374. nvq->done_idx
  375. && vhost_net_tx_select_zcopy(net);
  376. /* use msg_control to pass vhost zerocopy ubuf info to skb */
  377. if (zcopy_used) {
  378. struct ubuf_info *ubuf;
  379. ubuf = nvq->ubuf_info + nvq->upend_idx;
  380. vq->heads[nvq->upend_idx].id = cpu_to_vhost32(vq, head);
  381. vq->heads[nvq->upend_idx].len = VHOST_DMA_IN_PROGRESS;
  382. ubuf->callback = vhost_zerocopy_callback;
  383. ubuf->ctx = nvq->ubufs;
  384. ubuf->desc = nvq->upend_idx;
  385. msg.msg_control = ubuf;
  386. msg.msg_controllen = sizeof(ubuf);
  387. ubufs = nvq->ubufs;
  388. atomic_inc(&ubufs->refcount);
  389. nvq->upend_idx = (nvq->upend_idx + 1) % UIO_MAXIOV;
  390. } else {
  391. msg.msg_control = NULL;
  392. ubufs = NULL;
  393. }
  394. /* TODO: Check specific error and bomb out unless ENOBUFS? */
  395. err = sock->ops->sendmsg(sock, &msg, len);
  396. if (unlikely(err < 0)) {
  397. if (zcopy_used) {
  398. vhost_net_ubuf_put(ubufs);
  399. nvq->upend_idx = ((unsigned)nvq->upend_idx - 1)
  400. % UIO_MAXIOV;
  401. }
  402. vhost_discard_vq_desc(vq, 1);
  403. break;
  404. }
  405. if (err != len)
  406. pr_debug("Truncated TX packet: "
  407. " len %d != %zd\n", err, len);
  408. if (!zcopy_used)
  409. vhost_add_used_and_signal(&net->dev, vq, head, 0);
  410. else
  411. vhost_zerocopy_signal_used(net, vq);
  412. total_len += len;
  413. vhost_net_tx_packet(net);
  414. if (unlikely(total_len >= VHOST_NET_WEIGHT)) {
  415. vhost_poll_queue(&vq->poll);
  416. break;
  417. }
  418. }
  419. out:
  420. mutex_unlock(&vq->mutex);
  421. }
  422. static int peek_head_len(struct sock *sk)
  423. {
  424. struct socket *sock = sk->sk_socket;
  425. struct sk_buff *head;
  426. int len = 0;
  427. unsigned long flags;
  428. if (sock->ops->peek_len)
  429. return sock->ops->peek_len(sock);
  430. spin_lock_irqsave(&sk->sk_receive_queue.lock, flags);
  431. head = skb_peek(&sk->sk_receive_queue);
  432. if (likely(head)) {
  433. len = head->len;
  434. if (skb_vlan_tag_present(head))
  435. len += VLAN_HLEN;
  436. }
  437. spin_unlock_irqrestore(&sk->sk_receive_queue.lock, flags);
  438. return len;
  439. }
  440. static int sk_has_rx_data(struct sock *sk)
  441. {
  442. struct socket *sock = sk->sk_socket;
  443. if (sock->ops->peek_len)
  444. return sock->ops->peek_len(sock);
  445. return skb_queue_empty(&sk->sk_receive_queue);
  446. }
  447. static int vhost_net_rx_peek_head_len(struct vhost_net *net, struct sock *sk)
  448. {
  449. struct vhost_net_virtqueue *nvq = &net->vqs[VHOST_NET_VQ_TX];
  450. struct vhost_virtqueue *vq = &nvq->vq;
  451. unsigned long uninitialized_var(endtime);
  452. int len = peek_head_len(sk);
  453. if (!len && vq->busyloop_timeout) {
  454. /* Both tx vq and rx socket were polled here */
  455. mutex_lock(&vq->mutex);
  456. vhost_disable_notify(&net->dev, vq);
  457. preempt_disable();
  458. endtime = busy_clock() + vq->busyloop_timeout;
  459. while (vhost_can_busy_poll(&net->dev, endtime) &&
  460. !sk_has_rx_data(sk) &&
  461. vhost_vq_avail_empty(&net->dev, vq))
  462. cpu_relax_lowlatency();
  463. preempt_enable();
  464. if (vhost_enable_notify(&net->dev, vq))
  465. vhost_poll_queue(&vq->poll);
  466. mutex_unlock(&vq->mutex);
  467. len = peek_head_len(sk);
  468. }
  469. return len;
  470. }
  471. /* This is a multi-buffer version of vhost_get_desc, that works if
  472. * vq has read descriptors only.
  473. * @vq - the relevant virtqueue
  474. * @datalen - data length we'll be reading
  475. * @iovcount - returned count of io vectors we fill
  476. * @log - vhost log
  477. * @log_num - log offset
  478. * @quota - headcount quota, 1 for big buffer
  479. * returns number of buffer heads allocated, negative on error
  480. */
  481. static int get_rx_bufs(struct vhost_virtqueue *vq,
  482. struct vring_used_elem *heads,
  483. int datalen,
  484. unsigned *iovcount,
  485. struct vhost_log *log,
  486. unsigned *log_num,
  487. unsigned int quota)
  488. {
  489. unsigned int out, in;
  490. int seg = 0;
  491. int headcount = 0;
  492. unsigned d;
  493. int r, nlogs = 0;
  494. /* len is always initialized before use since we are always called with
  495. * datalen > 0.
  496. */
  497. u32 uninitialized_var(len);
  498. while (datalen > 0 && headcount < quota) {
  499. if (unlikely(seg >= UIO_MAXIOV)) {
  500. r = -ENOBUFS;
  501. goto err;
  502. }
  503. r = vhost_get_vq_desc(vq, vq->iov + seg,
  504. ARRAY_SIZE(vq->iov) - seg, &out,
  505. &in, log, log_num);
  506. if (unlikely(r < 0))
  507. goto err;
  508. d = r;
  509. if (d == vq->num) {
  510. r = 0;
  511. goto err;
  512. }
  513. if (unlikely(out || in <= 0)) {
  514. vq_err(vq, "unexpected descriptor format for RX: "
  515. "out %d, in %d\n", out, in);
  516. r = -EINVAL;
  517. goto err;
  518. }
  519. if (unlikely(log)) {
  520. nlogs += *log_num;
  521. log += *log_num;
  522. }
  523. heads[headcount].id = cpu_to_vhost32(vq, d);
  524. len = iov_length(vq->iov + seg, in);
  525. heads[headcount].len = cpu_to_vhost32(vq, len);
  526. datalen -= len;
  527. ++headcount;
  528. seg += in;
  529. }
  530. heads[headcount - 1].len = cpu_to_vhost32(vq, len + datalen);
  531. *iovcount = seg;
  532. if (unlikely(log))
  533. *log_num = nlogs;
  534. /* Detect overrun */
  535. if (unlikely(datalen > 0)) {
  536. r = UIO_MAXIOV + 1;
  537. goto err;
  538. }
  539. return headcount;
  540. err:
  541. vhost_discard_vq_desc(vq, headcount);
  542. return r;
  543. }
  544. /* Expects to be always run from workqueue - which acts as
  545. * read-size critical section for our kind of RCU. */
  546. static void handle_rx(struct vhost_net *net)
  547. {
  548. struct vhost_net_virtqueue *nvq = &net->vqs[VHOST_NET_VQ_RX];
  549. struct vhost_virtqueue *vq = &nvq->vq;
  550. unsigned uninitialized_var(in), log;
  551. struct vhost_log *vq_log;
  552. struct msghdr msg = {
  553. .msg_name = NULL,
  554. .msg_namelen = 0,
  555. .msg_control = NULL, /* FIXME: get and handle RX aux data. */
  556. .msg_controllen = 0,
  557. .msg_flags = MSG_DONTWAIT,
  558. };
  559. struct virtio_net_hdr hdr = {
  560. .flags = 0,
  561. .gso_type = VIRTIO_NET_HDR_GSO_NONE
  562. };
  563. size_t total_len = 0;
  564. int err, mergeable;
  565. s16 headcount;
  566. size_t vhost_hlen, sock_hlen;
  567. size_t vhost_len, sock_len;
  568. struct socket *sock;
  569. struct iov_iter fixup;
  570. __virtio16 num_buffers;
  571. mutex_lock(&vq->mutex);
  572. sock = vq->private_data;
  573. if (!sock)
  574. goto out;
  575. vhost_disable_notify(&net->dev, vq);
  576. vhost_net_disable_vq(net, vq);
  577. vhost_hlen = nvq->vhost_hlen;
  578. sock_hlen = nvq->sock_hlen;
  579. vq_log = unlikely(vhost_has_feature(vq, VHOST_F_LOG_ALL)) ?
  580. vq->log : NULL;
  581. mergeable = vhost_has_feature(vq, VIRTIO_NET_F_MRG_RXBUF);
  582. while ((sock_len = vhost_net_rx_peek_head_len(net, sock->sk))) {
  583. sock_len += sock_hlen;
  584. vhost_len = sock_len + vhost_hlen;
  585. headcount = get_rx_bufs(vq, vq->heads, vhost_len,
  586. &in, vq_log, &log,
  587. likely(mergeable) ? UIO_MAXIOV : 1);
  588. /* On error, stop handling until the next kick. */
  589. if (unlikely(headcount < 0))
  590. goto out;
  591. /* On overrun, truncate and discard */
  592. if (unlikely(headcount > UIO_MAXIOV)) {
  593. iov_iter_init(&msg.msg_iter, READ, vq->iov, 1, 1);
  594. err = sock->ops->recvmsg(sock, &msg,
  595. 1, MSG_DONTWAIT | MSG_TRUNC);
  596. pr_debug("Discarded rx packet: len %zd\n", sock_len);
  597. continue;
  598. }
  599. /* OK, now we need to know about added descriptors. */
  600. if (!headcount) {
  601. if (unlikely(vhost_enable_notify(&net->dev, vq))) {
  602. /* They have slipped one in as we were
  603. * doing that: check again. */
  604. vhost_disable_notify(&net->dev, vq);
  605. continue;
  606. }
  607. /* Nothing new? Wait for eventfd to tell us
  608. * they refilled. */
  609. goto out;
  610. }
  611. /* We don't need to be notified again. */
  612. iov_iter_init(&msg.msg_iter, READ, vq->iov, in, vhost_len);
  613. fixup = msg.msg_iter;
  614. if (unlikely((vhost_hlen))) {
  615. /* We will supply the header ourselves
  616. * TODO: support TSO.
  617. */
  618. iov_iter_advance(&msg.msg_iter, vhost_hlen);
  619. }
  620. err = sock->ops->recvmsg(sock, &msg,
  621. sock_len, MSG_DONTWAIT | MSG_TRUNC);
  622. /* Userspace might have consumed the packet meanwhile:
  623. * it's not supposed to do this usually, but might be hard
  624. * to prevent. Discard data we got (if any) and keep going. */
  625. if (unlikely(err != sock_len)) {
  626. pr_debug("Discarded rx packet: "
  627. " len %d, expected %zd\n", err, sock_len);
  628. vhost_discard_vq_desc(vq, headcount);
  629. continue;
  630. }
  631. /* Supply virtio_net_hdr if VHOST_NET_F_VIRTIO_NET_HDR */
  632. if (unlikely(vhost_hlen)) {
  633. if (copy_to_iter(&hdr, sizeof(hdr),
  634. &fixup) != sizeof(hdr)) {
  635. vq_err(vq, "Unable to write vnet_hdr "
  636. "at addr %p\n", vq->iov->iov_base);
  637. goto out;
  638. }
  639. } else {
  640. /* Header came from socket; we'll need to patch
  641. * ->num_buffers over if VIRTIO_NET_F_MRG_RXBUF
  642. */
  643. iov_iter_advance(&fixup, sizeof(hdr));
  644. }
  645. /* TODO: Should check and handle checksum. */
  646. num_buffers = cpu_to_vhost16(vq, headcount);
  647. if (likely(mergeable) &&
  648. copy_to_iter(&num_buffers, sizeof num_buffers,
  649. &fixup) != sizeof num_buffers) {
  650. vq_err(vq, "Failed num_buffers write");
  651. vhost_discard_vq_desc(vq, headcount);
  652. goto out;
  653. }
  654. vhost_add_used_and_signal_n(&net->dev, vq, vq->heads,
  655. headcount);
  656. if (unlikely(vq_log))
  657. vhost_log_write(vq, vq_log, log, vhost_len);
  658. total_len += vhost_len;
  659. if (unlikely(total_len >= VHOST_NET_WEIGHT)) {
  660. vhost_poll_queue(&vq->poll);
  661. goto out;
  662. }
  663. }
  664. vhost_net_enable_vq(net, vq);
  665. out:
  666. mutex_unlock(&vq->mutex);
  667. }
  668. static void handle_tx_kick(struct vhost_work *work)
  669. {
  670. struct vhost_virtqueue *vq = container_of(work, struct vhost_virtqueue,
  671. poll.work);
  672. struct vhost_net *net = container_of(vq->dev, struct vhost_net, dev);
  673. handle_tx(net);
  674. }
  675. static void handle_rx_kick(struct vhost_work *work)
  676. {
  677. struct vhost_virtqueue *vq = container_of(work, struct vhost_virtqueue,
  678. poll.work);
  679. struct vhost_net *net = container_of(vq->dev, struct vhost_net, dev);
  680. handle_rx(net);
  681. }
  682. static void handle_tx_net(struct vhost_work *work)
  683. {
  684. struct vhost_net *net = container_of(work, struct vhost_net,
  685. poll[VHOST_NET_VQ_TX].work);
  686. handle_tx(net);
  687. }
  688. static void handle_rx_net(struct vhost_work *work)
  689. {
  690. struct vhost_net *net = container_of(work, struct vhost_net,
  691. poll[VHOST_NET_VQ_RX].work);
  692. handle_rx(net);
  693. }
  694. static int vhost_net_open(struct inode *inode, struct file *f)
  695. {
  696. struct vhost_net *n;
  697. struct vhost_dev *dev;
  698. struct vhost_virtqueue **vqs;
  699. int i;
  700. n = kmalloc(sizeof *n, GFP_KERNEL | __GFP_NOWARN | __GFP_REPEAT);
  701. if (!n) {
  702. n = vmalloc(sizeof *n);
  703. if (!n)
  704. return -ENOMEM;
  705. }
  706. vqs = kmalloc(VHOST_NET_VQ_MAX * sizeof(*vqs), GFP_KERNEL);
  707. if (!vqs) {
  708. kvfree(n);
  709. return -ENOMEM;
  710. }
  711. dev = &n->dev;
  712. vqs[VHOST_NET_VQ_TX] = &n->vqs[VHOST_NET_VQ_TX].vq;
  713. vqs[VHOST_NET_VQ_RX] = &n->vqs[VHOST_NET_VQ_RX].vq;
  714. n->vqs[VHOST_NET_VQ_TX].vq.handle_kick = handle_tx_kick;
  715. n->vqs[VHOST_NET_VQ_RX].vq.handle_kick = handle_rx_kick;
  716. for (i = 0; i < VHOST_NET_VQ_MAX; i++) {
  717. n->vqs[i].ubufs = NULL;
  718. n->vqs[i].ubuf_info = NULL;
  719. n->vqs[i].upend_idx = 0;
  720. n->vqs[i].done_idx = 0;
  721. n->vqs[i].vhost_hlen = 0;
  722. n->vqs[i].sock_hlen = 0;
  723. }
  724. vhost_dev_init(dev, vqs, VHOST_NET_VQ_MAX);
  725. vhost_poll_init(n->poll + VHOST_NET_VQ_TX, handle_tx_net, POLLOUT, dev);
  726. vhost_poll_init(n->poll + VHOST_NET_VQ_RX, handle_rx_net, POLLIN, dev);
  727. f->private_data = n;
  728. return 0;
  729. }
  730. static struct socket *vhost_net_stop_vq(struct vhost_net *n,
  731. struct vhost_virtqueue *vq)
  732. {
  733. struct socket *sock;
  734. mutex_lock(&vq->mutex);
  735. sock = vq->private_data;
  736. vhost_net_disable_vq(n, vq);
  737. vq->private_data = NULL;
  738. mutex_unlock(&vq->mutex);
  739. return sock;
  740. }
  741. static void vhost_net_stop(struct vhost_net *n, struct socket **tx_sock,
  742. struct socket **rx_sock)
  743. {
  744. *tx_sock = vhost_net_stop_vq(n, &n->vqs[VHOST_NET_VQ_TX].vq);
  745. *rx_sock = vhost_net_stop_vq(n, &n->vqs[VHOST_NET_VQ_RX].vq);
  746. }
  747. static void vhost_net_flush_vq(struct vhost_net *n, int index)
  748. {
  749. vhost_poll_flush(n->poll + index);
  750. vhost_poll_flush(&n->vqs[index].vq.poll);
  751. }
  752. static void vhost_net_flush(struct vhost_net *n)
  753. {
  754. vhost_net_flush_vq(n, VHOST_NET_VQ_TX);
  755. vhost_net_flush_vq(n, VHOST_NET_VQ_RX);
  756. if (n->vqs[VHOST_NET_VQ_TX].ubufs) {
  757. mutex_lock(&n->vqs[VHOST_NET_VQ_TX].vq.mutex);
  758. n->tx_flush = true;
  759. mutex_unlock(&n->vqs[VHOST_NET_VQ_TX].vq.mutex);
  760. /* Wait for all lower device DMAs done. */
  761. vhost_net_ubuf_put_and_wait(n->vqs[VHOST_NET_VQ_TX].ubufs);
  762. mutex_lock(&n->vqs[VHOST_NET_VQ_TX].vq.mutex);
  763. n->tx_flush = false;
  764. atomic_set(&n->vqs[VHOST_NET_VQ_TX].ubufs->refcount, 1);
  765. mutex_unlock(&n->vqs[VHOST_NET_VQ_TX].vq.mutex);
  766. }
  767. }
  768. static int vhost_net_release(struct inode *inode, struct file *f)
  769. {
  770. struct vhost_net *n = f->private_data;
  771. struct socket *tx_sock;
  772. struct socket *rx_sock;
  773. vhost_net_stop(n, &tx_sock, &rx_sock);
  774. vhost_net_flush(n);
  775. vhost_dev_stop(&n->dev);
  776. vhost_dev_cleanup(&n->dev, false);
  777. vhost_net_vq_reset(n);
  778. if (tx_sock)
  779. sockfd_put(tx_sock);
  780. if (rx_sock)
  781. sockfd_put(rx_sock);
  782. /* Make sure no callbacks are outstanding */
  783. synchronize_rcu_bh();
  784. /* We do an extra flush before freeing memory,
  785. * since jobs can re-queue themselves. */
  786. vhost_net_flush(n);
  787. kfree(n->dev.vqs);
  788. kvfree(n);
  789. return 0;
  790. }
  791. static struct socket *get_raw_socket(int fd)
  792. {
  793. struct {
  794. struct sockaddr_ll sa;
  795. char buf[MAX_ADDR_LEN];
  796. } uaddr;
  797. int uaddr_len = sizeof uaddr, r;
  798. struct socket *sock = sockfd_lookup(fd, &r);
  799. if (!sock)
  800. return ERR_PTR(-ENOTSOCK);
  801. /* Parameter checking */
  802. if (sock->sk->sk_type != SOCK_RAW) {
  803. r = -ESOCKTNOSUPPORT;
  804. goto err;
  805. }
  806. r = sock->ops->getname(sock, (struct sockaddr *)&uaddr.sa,
  807. &uaddr_len, 0);
  808. if (r)
  809. goto err;
  810. if (uaddr.sa.sll_family != AF_PACKET) {
  811. r = -EPFNOSUPPORT;
  812. goto err;
  813. }
  814. return sock;
  815. err:
  816. sockfd_put(sock);
  817. return ERR_PTR(r);
  818. }
  819. static struct socket *get_tap_socket(int fd)
  820. {
  821. struct file *file = fget(fd);
  822. struct socket *sock;
  823. if (!file)
  824. return ERR_PTR(-EBADF);
  825. sock = tun_get_socket(file);
  826. if (!IS_ERR(sock))
  827. return sock;
  828. sock = macvtap_get_socket(file);
  829. if (IS_ERR(sock))
  830. fput(file);
  831. return sock;
  832. }
  833. static struct socket *get_socket(int fd)
  834. {
  835. struct socket *sock;
  836. /* special case to disable backend */
  837. if (fd == -1)
  838. return NULL;
  839. sock = get_raw_socket(fd);
  840. if (!IS_ERR(sock))
  841. return sock;
  842. sock = get_tap_socket(fd);
  843. if (!IS_ERR(sock))
  844. return sock;
  845. return ERR_PTR(-ENOTSOCK);
  846. }
  847. static long vhost_net_set_backend(struct vhost_net *n, unsigned index, int fd)
  848. {
  849. struct socket *sock, *oldsock;
  850. struct vhost_virtqueue *vq;
  851. struct vhost_net_virtqueue *nvq;
  852. struct vhost_net_ubuf_ref *ubufs, *oldubufs = NULL;
  853. int r;
  854. mutex_lock(&n->dev.mutex);
  855. r = vhost_dev_check_owner(&n->dev);
  856. if (r)
  857. goto err;
  858. if (index >= VHOST_NET_VQ_MAX) {
  859. r = -ENOBUFS;
  860. goto err;
  861. }
  862. vq = &n->vqs[index].vq;
  863. nvq = &n->vqs[index];
  864. mutex_lock(&vq->mutex);
  865. /* Verify that ring has been setup correctly. */
  866. if (!vhost_vq_access_ok(vq)) {
  867. r = -EFAULT;
  868. goto err_vq;
  869. }
  870. sock = get_socket(fd);
  871. if (IS_ERR(sock)) {
  872. r = PTR_ERR(sock);
  873. goto err_vq;
  874. }
  875. /* start polling new socket */
  876. oldsock = vq->private_data;
  877. if (sock != oldsock) {
  878. ubufs = vhost_net_ubuf_alloc(vq,
  879. sock && vhost_sock_zcopy(sock));
  880. if (IS_ERR(ubufs)) {
  881. r = PTR_ERR(ubufs);
  882. goto err_ubufs;
  883. }
  884. vhost_net_disable_vq(n, vq);
  885. vq->private_data = sock;
  886. r = vhost_vq_init_access(vq);
  887. if (r)
  888. goto err_used;
  889. r = vhost_net_enable_vq(n, vq);
  890. if (r)
  891. goto err_used;
  892. oldubufs = nvq->ubufs;
  893. nvq->ubufs = ubufs;
  894. n->tx_packets = 0;
  895. n->tx_zcopy_err = 0;
  896. n->tx_flush = false;
  897. }
  898. mutex_unlock(&vq->mutex);
  899. if (oldubufs) {
  900. vhost_net_ubuf_put_wait_and_free(oldubufs);
  901. mutex_lock(&vq->mutex);
  902. vhost_zerocopy_signal_used(n, vq);
  903. mutex_unlock(&vq->mutex);
  904. }
  905. if (oldsock) {
  906. vhost_net_flush_vq(n, index);
  907. sockfd_put(oldsock);
  908. }
  909. mutex_unlock(&n->dev.mutex);
  910. return 0;
  911. err_used:
  912. vq->private_data = oldsock;
  913. vhost_net_enable_vq(n, vq);
  914. if (ubufs)
  915. vhost_net_ubuf_put_wait_and_free(ubufs);
  916. err_ubufs:
  917. sockfd_put(sock);
  918. err_vq:
  919. mutex_unlock(&vq->mutex);
  920. err:
  921. mutex_unlock(&n->dev.mutex);
  922. return r;
  923. }
  924. static long vhost_net_reset_owner(struct vhost_net *n)
  925. {
  926. struct socket *tx_sock = NULL;
  927. struct socket *rx_sock = NULL;
  928. long err;
  929. struct vhost_memory *memory;
  930. mutex_lock(&n->dev.mutex);
  931. err = vhost_dev_check_owner(&n->dev);
  932. if (err)
  933. goto done;
  934. memory = vhost_dev_reset_owner_prepare();
  935. if (!memory) {
  936. err = -ENOMEM;
  937. goto done;
  938. }
  939. vhost_net_stop(n, &tx_sock, &rx_sock);
  940. vhost_net_flush(n);
  941. vhost_dev_reset_owner(&n->dev, memory);
  942. vhost_net_vq_reset(n);
  943. done:
  944. mutex_unlock(&n->dev.mutex);
  945. if (tx_sock)
  946. sockfd_put(tx_sock);
  947. if (rx_sock)
  948. sockfd_put(rx_sock);
  949. return err;
  950. }
  951. static int vhost_net_set_features(struct vhost_net *n, u64 features)
  952. {
  953. size_t vhost_hlen, sock_hlen, hdr_len;
  954. int i;
  955. hdr_len = (features & ((1ULL << VIRTIO_NET_F_MRG_RXBUF) |
  956. (1ULL << VIRTIO_F_VERSION_1))) ?
  957. sizeof(struct virtio_net_hdr_mrg_rxbuf) :
  958. sizeof(struct virtio_net_hdr);
  959. if (features & (1 << VHOST_NET_F_VIRTIO_NET_HDR)) {
  960. /* vhost provides vnet_hdr */
  961. vhost_hlen = hdr_len;
  962. sock_hlen = 0;
  963. } else {
  964. /* socket provides vnet_hdr */
  965. vhost_hlen = 0;
  966. sock_hlen = hdr_len;
  967. }
  968. mutex_lock(&n->dev.mutex);
  969. if ((features & (1 << VHOST_F_LOG_ALL)) &&
  970. !vhost_log_access_ok(&n->dev)) {
  971. mutex_unlock(&n->dev.mutex);
  972. return -EFAULT;
  973. }
  974. for (i = 0; i < VHOST_NET_VQ_MAX; ++i) {
  975. mutex_lock(&n->vqs[i].vq.mutex);
  976. n->vqs[i].vq.acked_features = features;
  977. n->vqs[i].vhost_hlen = vhost_hlen;
  978. n->vqs[i].sock_hlen = sock_hlen;
  979. mutex_unlock(&n->vqs[i].vq.mutex);
  980. }
  981. mutex_unlock(&n->dev.mutex);
  982. return 0;
  983. }
  984. static long vhost_net_set_owner(struct vhost_net *n)
  985. {
  986. int r;
  987. mutex_lock(&n->dev.mutex);
  988. if (vhost_dev_has_owner(&n->dev)) {
  989. r = -EBUSY;
  990. goto out;
  991. }
  992. r = vhost_net_set_ubuf_info(n);
  993. if (r)
  994. goto out;
  995. r = vhost_dev_set_owner(&n->dev);
  996. if (r)
  997. vhost_net_clear_ubuf_info(n);
  998. vhost_net_flush(n);
  999. out:
  1000. mutex_unlock(&n->dev.mutex);
  1001. return r;
  1002. }
  1003. static long vhost_net_ioctl(struct file *f, unsigned int ioctl,
  1004. unsigned long arg)
  1005. {
  1006. struct vhost_net *n = f->private_data;
  1007. void __user *argp = (void __user *)arg;
  1008. u64 __user *featurep = argp;
  1009. struct vhost_vring_file backend;
  1010. u64 features;
  1011. int r;
  1012. switch (ioctl) {
  1013. case VHOST_NET_SET_BACKEND:
  1014. if (copy_from_user(&backend, argp, sizeof backend))
  1015. return -EFAULT;
  1016. return vhost_net_set_backend(n, backend.index, backend.fd);
  1017. case VHOST_GET_FEATURES:
  1018. features = VHOST_NET_FEATURES;
  1019. if (copy_to_user(featurep, &features, sizeof features))
  1020. return -EFAULT;
  1021. return 0;
  1022. case VHOST_SET_FEATURES:
  1023. if (copy_from_user(&features, featurep, sizeof features))
  1024. return -EFAULT;
  1025. if (features & ~VHOST_NET_FEATURES)
  1026. return -EOPNOTSUPP;
  1027. return vhost_net_set_features(n, features);
  1028. case VHOST_RESET_OWNER:
  1029. return vhost_net_reset_owner(n);
  1030. case VHOST_SET_OWNER:
  1031. return vhost_net_set_owner(n);
  1032. default:
  1033. mutex_lock(&n->dev.mutex);
  1034. r = vhost_dev_ioctl(&n->dev, ioctl, argp);
  1035. if (r == -ENOIOCTLCMD)
  1036. r = vhost_vring_ioctl(&n->dev, ioctl, argp);
  1037. else
  1038. vhost_net_flush(n);
  1039. mutex_unlock(&n->dev.mutex);
  1040. return r;
  1041. }
  1042. }
  1043. #ifdef CONFIG_COMPAT
  1044. static long vhost_net_compat_ioctl(struct file *f, unsigned int ioctl,
  1045. unsigned long arg)
  1046. {
  1047. return vhost_net_ioctl(f, ioctl, (unsigned long)compat_ptr(arg));
  1048. }
  1049. #endif
  1050. static const struct file_operations vhost_net_fops = {
  1051. .owner = THIS_MODULE,
  1052. .release = vhost_net_release,
  1053. .unlocked_ioctl = vhost_net_ioctl,
  1054. #ifdef CONFIG_COMPAT
  1055. .compat_ioctl = vhost_net_compat_ioctl,
  1056. #endif
  1057. .open = vhost_net_open,
  1058. .llseek = noop_llseek,
  1059. };
  1060. static struct miscdevice vhost_net_misc = {
  1061. .minor = VHOST_NET_MINOR,
  1062. .name = "vhost-net",
  1063. .fops = &vhost_net_fops,
  1064. };
  1065. static int vhost_net_init(void)
  1066. {
  1067. if (experimental_zcopytx)
  1068. vhost_net_enable_zcopy(VHOST_NET_VQ_TX);
  1069. return misc_register(&vhost_net_misc);
  1070. }
  1071. module_init(vhost_net_init);
  1072. static void vhost_net_exit(void)
  1073. {
  1074. misc_deregister(&vhost_net_misc);
  1075. }
  1076. module_exit(vhost_net_exit);
  1077. MODULE_VERSION("0.0.1");
  1078. MODULE_LICENSE("GPL v2");
  1079. MODULE_AUTHOR("Michael S. Tsirkin");
  1080. MODULE_DESCRIPTION("Host kernel accelerator for virtio net");
  1081. MODULE_ALIAS_MISCDEV(VHOST_NET_MINOR);
  1082. MODULE_ALIAS("devname:vhost-net");