---
 Documentation/lguest/lguest.c |   22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/Documentation/lguest/lguest.c b/Documentation/lguest/lguest.c
--- a/Documentation/lguest/lguest.c
+++ b/Documentation/lguest/lguest.c
@@ -151,9 +151,6 @@ struct virtqueue
 	/* The actual ring of buffers. */
 	struct vring vring;
 
-	/* Last available index we saw. */
-	u16 last_avail_idx;
-
 	/* How many are used since we sent last irq? */
 	unsigned int pending_used;
 
@@ -199,7 +196,7 @@ static void *_convert(struct iovec *iov,
 }
 
 /* Wrapper for the last available index.  Makes it easier to change. */
-#define lg_last_avail(vq)	((vq)->last_avail_idx)
+#define lg_last_avail(vq)	vring_last_avail(&(vq)->vring)
 
 /* The virtio configuration space is defined to be little-endian.  x86 is
  * little-endian too, but it's nice to be explicit so we have these helpers. */
@@ -1045,7 +1042,6 @@ static void _add_virtqueue(struct device
 
 	/* Initialize the virtqueue */
 	vq->next = NULL;
-	vq->last_avail_idx = 0;
 	vq->dev = dev;
 	vq->service = service;
 	vq->thread = (pid_t)-1;
@@ -1091,11 +1087,20 @@ static void add_feature(struct device *d
 	features[bit / CHAR_BIT] |= (1 << (bit % CHAR_BIT));
 }
 
+/* This sets the PUBLISH_INDICES feature for every device. */
+static void finalize_features(struct device *dev)
+{
+	add_feature(dev, VIRTIO_RING_F_PUBLISH_INDICES);
+}
+
 /* This routine sets the configuration fields for an existing device's
  * descriptor.  It only works for the last device, but that's OK because that's
  * how we use it. */
 static void set_config(struct device *dev, unsigned len, const void *conf)
 {
+	/* We have to set features before we set config. */
+	finalize_features(dev);
+
 	/* Check we haven't overflowed our single page. */
 	if (device_config(dev) + len > devices.descpage + getpagesize())
 		errx(1, "Too many devices");
@@ -1134,11 +1139,18 @@ static struct device *new_device(const c
 	return dev;
 }
 
+/* This finalizes features (if set_config() wasn't called) and prints out
+ * information about the device in --verbose mode. */
 static void finalize_device(struct device *dev, const char *fmt, ...)
 {
 	struct virtqueue *vq;
 	va_list ap;
 
+	/* Set that VIRTIO_F_VRING_WKCOUNT feature if not already. */
+	if (dev->desc->config_len == 0)
+		finalize_features(dev);
+
+	/* Print out pretty information about this device, for tourists. */
 	devices.device_num++;
 	verbose("device %u: %s", devices.device_num, dev->name);
 	va_start(ap, fmt);
