virtio_ring.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. /* Virtio ring implementation.
  2. *
  3. * Copyright 2007 Rusty Russell IBM Corporation
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  18. */
  19. #include <linux/virtio.h>
  20. #include <linux/virtio_ring.h>
  21. #include <linux/virtio_config.h>
  22. #include <linux/device.h>
  23. #include <linux/slab.h>
  24. #include <linux/module.h>
  25. /* virtio guest is communicating with a virtual "device" that actually runs on
  26. * a host processor. Memory barriers are used to control SMP effects. */
  27. #ifdef CONFIG_SMP
  28. /* Where possible, use SMP barriers which are more lightweight than mandatory
  29. * barriers, because mandatory barriers control MMIO effects on accesses
  30. * through relaxed memory I/O windows (which virtio-pci does not use). */
  31. #define virtio_mb(vq) \
  32. do { if ((vq)->weak_barriers) smp_mb(); else mb(); } while(0)
  33. #define virtio_rmb(vq) \
  34. do { if ((vq)->weak_barriers) smp_rmb(); else rmb(); } while(0)
  35. #define virtio_wmb(vq) \
  36. do { if ((vq)->weak_barriers) smp_rmb(); else rmb(); } while(0)
  37. #else
  38. /* We must force memory ordering even if guest is UP since host could be
  39. * running on another CPU, but SMP barriers are defined to barrier() in that
  40. * configuration. So fall back to mandatory barriers instead. */
  41. #define virtio_mb(vq) mb()
  42. #define virtio_rmb(vq) rmb()
  43. #define virtio_wmb(vq) wmb()
  44. #endif
  45. #ifdef DEBUG
  46. /* For development, we want to crash whenever the ring is screwed. */
  47. #define BAD_RING(_vq, fmt, args...) \
  48. do { \
  49. dev_err(&(_vq)->vq.vdev->dev, \
  50. "%s:"fmt, (_vq)->vq.name, ##args); \
  51. BUG(); \
  52. } while (0)
  53. /* Caller is supposed to guarantee no reentry. */
  54. #define START_USE(_vq) \
  55. do { \
  56. if ((_vq)->in_use) \
  57. panic("%s:in_use = %i\n", \
  58. (_vq)->vq.name, (_vq)->in_use); \
  59. (_vq)->in_use = __LINE__; \
  60. } while (0)
  61. #define END_USE(_vq) \
  62. do { BUG_ON(!(_vq)->in_use); (_vq)->in_use = 0; } while(0)
  63. #else
  64. #define BAD_RING(_vq, fmt, args...) \
  65. do { \
  66. dev_err(&_vq->vq.vdev->dev, \
  67. "%s:"fmt, (_vq)->vq.name, ##args); \
  68. (_vq)->broken = true; \
  69. } while (0)
  70. #define START_USE(vq)
  71. #define END_USE(vq)
  72. #endif
  73. struct vring_virtqueue
  74. {
  75. struct virtqueue vq;
  76. /* Actual memory layout for this queue */
  77. struct vring vring;
  78. /* Can we use weak barriers? */
  79. bool weak_barriers;
  80. /* Other side has made a mess, don't try any more. */
  81. bool broken;
  82. /* Host supports indirect buffers */
  83. bool indirect;
  84. /* Host publishes avail event idx */
  85. bool event;
  86. /* Number of free buffers */
  87. unsigned int num_free;
  88. /* Head of free buffer list. */
  89. unsigned int free_head;
  90. /* Number we've added since last sync. */
  91. unsigned int num_added;
  92. /* Last used index we've seen. */
  93. u16 last_used_idx;
  94. /* How to notify other side. FIXME: commonalize hcalls! */
  95. void (*notify)(struct virtqueue *vq);
  96. #ifdef DEBUG
  97. /* They're supposed to lock for us. */
  98. unsigned int in_use;
  99. #endif
  100. /* Tokens for callbacks. */
  101. void *data[];
  102. };
  103. #define to_vvq(_vq) container_of(_vq, struct vring_virtqueue, vq)
  104. /* Set up an indirect table of descriptors and add it to the queue. */
  105. static int vring_add_indirect(struct vring_virtqueue *vq,
  106. struct scatterlist sg[],
  107. unsigned int out,
  108. unsigned int in,
  109. gfp_t gfp)
  110. {
  111. struct vring_desc *desc;
  112. unsigned head;
  113. int i;
  114. desc = kmalloc((out + in) * sizeof(struct vring_desc), gfp);
  115. if (!desc)
  116. return -ENOMEM;
  117. /* Transfer entries from the sg list into the indirect page */
  118. for (i = 0; i < out; i++) {
  119. desc[i].flags = VRING_DESC_F_NEXT;
  120. desc[i].addr = sg_phys(sg);
  121. desc[i].len = sg->length;
  122. desc[i].next = i+1;
  123. sg++;
  124. }
  125. for (; i < (out + in); i++) {
  126. desc[i].flags = VRING_DESC_F_NEXT|VRING_DESC_F_WRITE;
  127. desc[i].addr = sg_phys(sg);
  128. desc[i].len = sg->length;
  129. desc[i].next = i+1;
  130. sg++;
  131. }
  132. /* Last one doesn't continue. */
  133. desc[i-1].flags &= ~VRING_DESC_F_NEXT;
  134. desc[i-1].next = 0;
  135. /* We're about to use a buffer */
  136. vq->num_free--;
  137. /* Use a single buffer which doesn't continue */
  138. head = vq->free_head;
  139. vq->vring.desc[head].flags = VRING_DESC_F_INDIRECT;
  140. vq->vring.desc[head].addr = virt_to_phys(desc);
  141. vq->vring.desc[head].len = i * sizeof(struct vring_desc);
  142. /* Update free pointer */
  143. vq->free_head = vq->vring.desc[head].next;
  144. return head;
  145. }
  146. /**
  147. * virtqueue_add_buf - expose buffer to other end
  148. * @vq: the struct virtqueue we're talking about.
  149. * @sg: the description of the buffer(s).
  150. * @out_num: the number of sg readable by other side
  151. * @in_num: the number of sg which are writable (after readable ones)
  152. * @data: the token identifying the buffer.
  153. * @gfp: how to do memory allocations (if necessary).
  154. *
  155. * Caller must ensure we don't call this with other virtqueue operations
  156. * at the same time (except where noted).
  157. *
  158. * Returns remaining capacity of queue or a negative error
  159. * (ie. ENOSPC). Note that it only really makes sense to treat all
  160. * positive return values as "available": indirect buffers mean that
  161. * we can put an entire sg[] array inside a single queue entry.
  162. */
  163. int virtqueue_add_buf(struct virtqueue *_vq,
  164. struct scatterlist sg[],
  165. unsigned int out,
  166. unsigned int in,
  167. void *data,
  168. gfp_t gfp)
  169. {
  170. struct vring_virtqueue *vq = to_vvq(_vq);
  171. unsigned int i, avail, uninitialized_var(prev);
  172. int head;
  173. START_USE(vq);
  174. BUG_ON(data == NULL);
  175. /* If the host supports indirect descriptor tables, and we have multiple
  176. * buffers, then go indirect. FIXME: tune this threshold */
  177. if (vq->indirect && (out + in) > 1 && vq->num_free) {
  178. head = vring_add_indirect(vq, sg, out, in, gfp);
  179. if (likely(head >= 0))
  180. goto add_head;
  181. }
  182. BUG_ON(out + in > vq->vring.num);
  183. BUG_ON(out + in == 0);
  184. if (vq->num_free < out + in) {
  185. pr_debug("Can't add buf len %i - avail = %i\n",
  186. out + in, vq->num_free);
  187. /* FIXME: for historical reasons, we force a notify here if
  188. * there are outgoing parts to the buffer. Presumably the
  189. * host should service the ring ASAP. */
  190. if (out)
  191. vq->notify(&vq->vq);
  192. END_USE(vq);
  193. return -ENOSPC;
  194. }
  195. /* We're about to use some buffers from the free list. */
  196. vq->num_free -= out + in;
  197. head = vq->free_head;
  198. for (i = vq->free_head; out; i = vq->vring.desc[i].next, out--) {
  199. vq->vring.desc[i].flags = VRING_DESC_F_NEXT;
  200. vq->vring.desc[i].addr = sg_phys(sg);
  201. vq->vring.desc[i].len = sg->length;
  202. prev = i;
  203. sg++;
  204. }
  205. for (; in; i = vq->vring.desc[i].next, in--) {
  206. vq->vring.desc[i].flags = VRING_DESC_F_NEXT|VRING_DESC_F_WRITE;
  207. vq->vring.desc[i].addr = sg_phys(sg);
  208. vq->vring.desc[i].len = sg->length;
  209. prev = i;
  210. sg++;
  211. }
  212. /* Last one doesn't continue. */
  213. vq->vring.desc[prev].flags &= ~VRING_DESC_F_NEXT;
  214. /* Update free pointer */
  215. vq->free_head = i;
  216. add_head:
  217. /* Set token. */
  218. vq->data[head] = data;
  219. /* Put entry in available array (but don't update avail->idx until they
  220. * do sync). FIXME: avoid modulus here? */
  221. avail = (vq->vring.avail->idx + vq->num_added++) % vq->vring.num;
  222. vq->vring.avail->ring[avail] = head;
  223. pr_debug("Added buffer head %i to %p\n", head, vq);
  224. END_USE(vq);
  225. return vq->num_free;
  226. }
  227. EXPORT_SYMBOL_GPL(virtqueue_add_buf);
  228. /**
  229. * virtqueue_kick - update after add_buf
  230. * @vq: the struct virtqueue
  231. *
  232. * After one or more virtqueue_add_buf calls, invoke this to kick
  233. * the other side.
  234. *
  235. * Caller must ensure we don't call this with other virtqueue
  236. * operations at the same time (except where noted).
  237. */
  238. void virtqueue_kick(struct virtqueue *_vq)
  239. {
  240. struct vring_virtqueue *vq = to_vvq(_vq);
  241. u16 new, old;
  242. START_USE(vq);
  243. /* Descriptors and available array need to be set before we expose the
  244. * new available array entries. */
  245. virtio_wmb(vq);
  246. old = vq->vring.avail->idx;
  247. new = vq->vring.avail->idx = old + vq->num_added;
  248. vq->num_added = 0;
  249. /* Need to update avail index before checking if we should notify */
  250. virtio_mb(vq);
  251. if (vq->event ?
  252. vring_need_event(vring_avail_event(&vq->vring), new, old) :
  253. !(vq->vring.used->flags & VRING_USED_F_NO_NOTIFY))
  254. /* Prod other side to tell it about changes. */
  255. vq->notify(&vq->vq);
  256. END_USE(vq);
  257. }
  258. EXPORT_SYMBOL_GPL(virtqueue_kick);
  259. static void detach_buf(struct vring_virtqueue *vq, unsigned int head)
  260. {
  261. unsigned int i;
  262. /* Clear data ptr. */
  263. vq->data[head] = NULL;
  264. /* Put back on free list: find end */
  265. i = head;
  266. /* Free the indirect table */
  267. if (vq->vring.desc[i].flags & VRING_DESC_F_INDIRECT)
  268. kfree(phys_to_virt(vq->vring.desc[i].addr));
  269. while (vq->vring.desc[i].flags & VRING_DESC_F_NEXT) {
  270. i = vq->vring.desc[i].next;
  271. vq->num_free++;
  272. }
  273. vq->vring.desc[i].next = vq->free_head;
  274. vq->free_head = head;
  275. /* Plus final descriptor */
  276. vq->num_free++;
  277. }
  278. static inline bool more_used(const struct vring_virtqueue *vq)
  279. {
  280. return vq->last_used_idx != vq->vring.used->idx;
  281. }
  282. /**
  283. * virtqueue_get_buf - get the next used buffer
  284. * @vq: the struct virtqueue we're talking about.
  285. * @len: the length written into the buffer
  286. *
  287. * If the driver wrote data into the buffer, @len will be set to the
  288. * amount written. This means you don't need to clear the buffer
  289. * beforehand to ensure there's no data leakage in the case of short
  290. * writes.
  291. *
  292. * Caller must ensure we don't call this with other virtqueue
  293. * operations at the same time (except where noted).
  294. *
  295. * Returns NULL if there are no used buffers, or the "data" token
  296. * handed to virtqueue_add_buf().
  297. */
  298. void *virtqueue_get_buf(struct virtqueue *_vq, unsigned int *len)
  299. {
  300. struct vring_virtqueue *vq = to_vvq(_vq);
  301. void *ret;
  302. unsigned int i;
  303. START_USE(vq);
  304. if (unlikely(vq->broken)) {
  305. END_USE(vq);
  306. return NULL;
  307. }
  308. if (!more_used(vq)) {
  309. pr_debug("No more buffers in queue\n");
  310. END_USE(vq);
  311. return NULL;
  312. }
  313. /* Only get used array entries after they have been exposed by host. */
  314. virtio_rmb(vq);
  315. i = vq->vring.used->ring[vq->last_used_idx%vq->vring.num].id;
  316. *len = vq->vring.used->ring[vq->last_used_idx%vq->vring.num].len;
  317. if (unlikely(i >= vq->vring.num)) {
  318. BAD_RING(vq, "id %u out of range\n", i);
  319. return NULL;
  320. }
  321. if (unlikely(!vq->data[i])) {
  322. BAD_RING(vq, "id %u is not a head!\n", i);
  323. return NULL;
  324. }
  325. /* detach_buf clears data, so grab it now. */
  326. ret = vq->data[i];
  327. detach_buf(vq, i);
  328. vq->last_used_idx++;
  329. /* If we expect an interrupt for the next entry, tell host
  330. * by writing event index and flush out the write before
  331. * the read in the next get_buf call. */
  332. if (!(vq->vring.avail->flags & VRING_AVAIL_F_NO_INTERRUPT)) {
  333. vring_used_event(&vq->vring) = vq->last_used_idx;
  334. virtio_mb(vq);
  335. }
  336. END_USE(vq);
  337. return ret;
  338. }
  339. EXPORT_SYMBOL_GPL(virtqueue_get_buf);
  340. /**
  341. * virtqueue_disable_cb - disable callbacks
  342. * @vq: the struct virtqueue we're talking about.
  343. *
  344. * Note that this is not necessarily synchronous, hence unreliable and only
  345. * useful as an optimization.
  346. *
  347. * Unlike other operations, this need not be serialized.
  348. */
  349. void virtqueue_disable_cb(struct virtqueue *_vq)
  350. {
  351. struct vring_virtqueue *vq = to_vvq(_vq);
  352. vq->vring.avail->flags |= VRING_AVAIL_F_NO_INTERRUPT;
  353. }
  354. EXPORT_SYMBOL_GPL(virtqueue_disable_cb);
  355. /**
  356. * virtqueue_enable_cb - restart callbacks after disable_cb.
  357. * @vq: the struct virtqueue we're talking about.
  358. *
  359. * This re-enables callbacks; it returns "false" if there are pending
  360. * buffers in the queue, to detect a possible race between the driver
  361. * checking for more work, and enabling callbacks.
  362. *
  363. * Caller must ensure we don't call this with other virtqueue
  364. * operations at the same time (except where noted).
  365. */
  366. bool virtqueue_enable_cb(struct virtqueue *_vq)
  367. {
  368. struct vring_virtqueue *vq = to_vvq(_vq);
  369. START_USE(vq);
  370. /* We optimistically turn back on interrupts, then check if there was
  371. * more to do. */
  372. /* Depending on the VIRTIO_RING_F_EVENT_IDX feature, we need to
  373. * either clear the flags bit or point the event index at the next
  374. * entry. Always do both to keep code simple. */
  375. vq->vring.avail->flags &= ~VRING_AVAIL_F_NO_INTERRUPT;
  376. vring_used_event(&vq->vring) = vq->last_used_idx;
  377. virtio_mb(vq);
  378. if (unlikely(more_used(vq))) {
  379. END_USE(vq);
  380. return false;
  381. }
  382. END_USE(vq);
  383. return true;
  384. }
  385. EXPORT_SYMBOL_GPL(virtqueue_enable_cb);
  386. /**
  387. * virtqueue_enable_cb_delayed - restart callbacks after disable_cb.
  388. * @vq: the struct virtqueue we're talking about.
  389. *
  390. * This re-enables callbacks but hints to the other side to delay
  391. * interrupts until most of the available buffers have been processed;
  392. * it returns "false" if there are many pending buffers in the queue,
  393. * to detect a possible race between the driver checking for more work,
  394. * and enabling callbacks.
  395. *
  396. * Caller must ensure we don't call this with other virtqueue
  397. * operations at the same time (except where noted).
  398. */
  399. bool virtqueue_enable_cb_delayed(struct virtqueue *_vq)
  400. {
  401. struct vring_virtqueue *vq = to_vvq(_vq);
  402. u16 bufs;
  403. START_USE(vq);
  404. /* We optimistically turn back on interrupts, then check if there was
  405. * more to do. */
  406. /* Depending on the VIRTIO_RING_F_USED_EVENT_IDX feature, we need to
  407. * either clear the flags bit or point the event index at the next
  408. * entry. Always do both to keep code simple. */
  409. vq->vring.avail->flags &= ~VRING_AVAIL_F_NO_INTERRUPT;
  410. /* TODO: tune this threshold */
  411. bufs = (u16)(vq->vring.avail->idx - vq->last_used_idx) * 3 / 4;
  412. vring_used_event(&vq->vring) = vq->last_used_idx + bufs;
  413. virtio_mb(vq);
  414. if (unlikely((u16)(vq->vring.used->idx - vq->last_used_idx) > bufs)) {
  415. END_USE(vq);
  416. return false;
  417. }
  418. END_USE(vq);
  419. return true;
  420. }
  421. EXPORT_SYMBOL_GPL(virtqueue_enable_cb_delayed);
  422. /**
  423. * virtqueue_detach_unused_buf - detach first unused buffer
  424. * @vq: the struct virtqueue we're talking about.
  425. *
  426. * Returns NULL or the "data" token handed to virtqueue_add_buf().
  427. * This is not valid on an active queue; it is useful only for device
  428. * shutdown.
  429. */
  430. void *virtqueue_detach_unused_buf(struct virtqueue *_vq)
  431. {
  432. struct vring_virtqueue *vq = to_vvq(_vq);
  433. unsigned int i;
  434. void *buf;
  435. START_USE(vq);
  436. for (i = 0; i < vq->vring.num; i++) {
  437. if (!vq->data[i])
  438. continue;
  439. /* detach_buf clears data, so grab it now. */
  440. buf = vq->data[i];
  441. detach_buf(vq, i);
  442. vq->vring.avail->idx--;
  443. END_USE(vq);
  444. return buf;
  445. }
  446. /* That should have freed everything. */
  447. BUG_ON(vq->num_free != vq->vring.num);
  448. END_USE(vq);
  449. return NULL;
  450. }
  451. EXPORT_SYMBOL_GPL(virtqueue_detach_unused_buf);
  452. irqreturn_t vring_interrupt(int irq, void *_vq)
  453. {
  454. struct vring_virtqueue *vq = to_vvq(_vq);
  455. if (!more_used(vq)) {
  456. pr_debug("virtqueue interrupt with no work for %p\n", vq);
  457. return IRQ_NONE;
  458. }
  459. if (unlikely(vq->broken))
  460. return IRQ_HANDLED;
  461. pr_debug("virtqueue callback for %p (%p)\n", vq, vq->vq.callback);
  462. if (vq->vq.callback)
  463. vq->vq.callback(&vq->vq);
  464. return IRQ_HANDLED;
  465. }
  466. EXPORT_SYMBOL_GPL(vring_interrupt);
  467. struct virtqueue *vring_new_virtqueue(unsigned int num,
  468. unsigned int vring_align,
  469. struct virtio_device *vdev,
  470. bool weak_barriers,
  471. void *pages,
  472. void (*notify)(struct virtqueue *),
  473. void (*callback)(struct virtqueue *),
  474. const char *name)
  475. {
  476. struct vring_virtqueue *vq;
  477. unsigned int i;
  478. /* We assume num is a power of 2. */
  479. if (num & (num - 1)) {
  480. dev_warn(&vdev->dev, "Bad virtqueue length %u\n", num);
  481. return NULL;
  482. }
  483. vq = kmalloc(sizeof(*vq) + sizeof(void *)*num, GFP_KERNEL);
  484. if (!vq)
  485. return NULL;
  486. vring_init(&vq->vring, num, pages, vring_align);
  487. vq->vq.callback = callback;
  488. vq->vq.vdev = vdev;
  489. vq->vq.name = name;
  490. vq->notify = notify;
  491. vq->weak_barriers = weak_barriers;
  492. vq->broken = false;
  493. vq->last_used_idx = 0;
  494. vq->num_added = 0;
  495. list_add_tail(&vq->vq.list, &vdev->vqs);
  496. #ifdef DEBUG
  497. vq->in_use = false;
  498. #endif
  499. vq->indirect = virtio_has_feature(vdev, VIRTIO_RING_F_INDIRECT_DESC);
  500. vq->event = virtio_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX);
  501. /* No callback? Tell other side not to bother us. */
  502. if (!callback)
  503. vq->vring.avail->flags |= VRING_AVAIL_F_NO_INTERRUPT;
  504. /* Put everything in free lists. */
  505. vq->num_free = num;
  506. vq->free_head = 0;
  507. for (i = 0; i < num-1; i++) {
  508. vq->vring.desc[i].next = i+1;
  509. vq->data[i] = NULL;
  510. }
  511. vq->data[i] = NULL;
  512. return &vq->vq;
  513. }
  514. EXPORT_SYMBOL_GPL(vring_new_virtqueue);
  515. void vring_del_virtqueue(struct virtqueue *vq)
  516. {
  517. list_del(&vq->list);
  518. kfree(to_vvq(vq));
  519. }
  520. EXPORT_SYMBOL_GPL(vring_del_virtqueue);
  521. /* Manipulates transport-specific feature bits. */
  522. void vring_transport_features(struct virtio_device *vdev)
  523. {
  524. unsigned int i;
  525. for (i = VIRTIO_TRANSPORT_F_START; i < VIRTIO_TRANSPORT_F_END; i++) {
  526. switch (i) {
  527. case VIRTIO_RING_F_INDIRECT_DESC:
  528. break;
  529. case VIRTIO_RING_F_EVENT_IDX:
  530. break;
  531. default:
  532. /* We don't understand this bit. */
  533. clear_bit(i, vdev->features);
  534. }
  535. }
  536. }
  537. EXPORT_SYMBOL_GPL(vring_transport_features);
  538. /**
  539. * virtqueue_get_vring_size - return the size of the virtqueue's vring
  540. * @vq: the struct virtqueue containing the vring of interest.
  541. *
  542. * Returns the size of the vring. This is mainly used for boasting to
  543. * userspace. Unlike other operations, this need not be serialized.
  544. */
  545. unsigned int virtqueue_get_vring_size(struct virtqueue *_vq)
  546. {
  547. struct vring_virtqueue *vq = to_vvq(_vq);
  548. return vq->vring.num;
  549. }
  550. EXPORT_SYMBOL_GPL(virtqueue_get_vring_size);
  551. MODULE_LICENSE("GPL");