Commit 426e3e0af5d2473e67d4256fc1340b7faebd1cc7

Authored by Rusty Russell
1 parent 3309daaad7

virtio: clarify NO_NOTIFY flag usage

The other side (host) can set the NO_NOTIFY flag as an optimization,
to say "no need to kick me when you add things".  Make it clear that
this is advisory only; especially that we should always notify when
the ring is full.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>

Showing 3 changed files with 13 additions and 6 deletions Side-by-side Diff

Documentation/lguest/lguest.c
... ... @@ -923,10 +923,10 @@
923 923 /* Check each virtqueue. */
924 924 for (i = devices.dev; i; i = i->next) {
925 925 for (vq = i->vq; vq; vq = vq->next) {
926   - if (vq->config.pfn == addr/getpagesize()
927   - && vq->handle_output) {
  926 + if (vq->config.pfn == addr/getpagesize()) {
928 927 verbose("Output to %s\n", vq->dev->name);
929   - vq->handle_output(fd, vq);
  928 + if (vq->handle_output)
  929 + vq->handle_output(fd, vq);
930 930 return;
931 931 }
932 932 }
... ... @@ -1068,7 +1068,8 @@
1068 1068 * virtqueue. */
1069 1069 vq->handle_output = handle_output;
1070 1070  
1071   - /* Set the "Don't Notify Me" flag if we don't have a handler */
  1071 + /* As an optimization, set the advisory "Don't Notify Me" flag if we
  1072 + * don't have a handler */
1072 1073 if (!handle_output)
1073 1074 vq->vring.used->flags = VRING_USED_F_NO_NOTIFY;
1074 1075 }
drivers/virtio/virtio_ring.c
... ... @@ -87,6 +87,8 @@
87 87 if (vq->num_free < out + in) {
88 88 pr_debug("Can't add buf len %i - avail = %i\n",
89 89 out + in, vq->num_free);
  90 + /* We notify *even if* VRING_USED_F_NO_NOTIFY is set here. */
  91 + vq->notify(&vq->vq);
90 92 END_USE(vq);
91 93 return -ENOSPC;
92 94 }
include/linux/virtio_ring.h
... ... @@ -15,9 +15,13 @@
15 15 /* This marks a buffer as write-only (otherwise read-only). */
16 16 #define VRING_DESC_F_WRITE 2
17 17  
18   -/* This means don't notify other side when buffer added. */
  18 +/* The Host uses this in used->flags to advise the Guest: don't kick me when
  19 + * you add a buffer. It's unreliable, so it's simply an optimization. Guest
  20 + * will still kick if it's out of buffers. */
19 21 #define VRING_USED_F_NO_NOTIFY 1
20   -/* This means don't interrupt guest when buffer consumed. */
  22 +/* The Guest uses this in avail->flags to advise the Host: don't interrupt me
  23 + * when you consume a buffer. It's unreliable, so it's simply an
  24 + * optimization. */
21 25 #define VRING_AVAIL_F_NO_INTERRUPT 1
22 26  
23 27 /* Virtio ring descriptors: 16 bytes. These can chain together via "next". */