lguest: wrap last_avail accesses.

To simplify the transition to when we publish indices in the ring
(and make shuffling my patch queue easier), wrap them in a lg_last_avail()
macro.

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

+11 -5
+11 -5
Documentation/lguest/lguest.c
··· 191 return iov->iov_base; 192 } 193 194 /* The virtio configuration space is defined to be little-endian. x86 is 195 * little-endian too, but it's nice to be explicit so we have these helpers. */ 196 #define cpu_to_le16(v16) (v16) ··· 693 unsigned int *out_num, unsigned int *in_num) 694 { 695 unsigned int i, head; 696 697 /* Check it isn't doing very strange things with descriptor numbers. */ 698 - if ((u16)(vq->vring.avail->idx - vq->last_avail_idx) > vq->vring.num) 699 errx(1, "Guest moved used index from %u to %u", 700 - vq->last_avail_idx, vq->vring.avail->idx); 701 702 /* If there's nothing new since last we looked, return invalid. */ 703 - if (vq->vring.avail->idx == vq->last_avail_idx) 704 return vq->vring.num; 705 706 /* Grab the next descriptor number they're advertising, and increment 707 * the index we've seen. */ 708 - head = vq->vring.avail->ring[vq->last_avail_idx++ % vq->vring.num]; 709 710 /* If their number is silly, that's a fatal mistake. */ 711 if (head >= vq->vring.num) ··· 986 for (vq = dev->vq; vq; vq = vq->next) { 987 memset(vq->vring.desc, 0, 988 vring_size(vq->config.num, getpagesize())); 989 - vq->last_avail_idx = 0; 990 } 991 } else if (dev->desc->status & VIRTIO_CONFIG_S_FAILED) { 992 warnx("Device %s configuration FAILED", dev->name);
··· 191 return iov->iov_base; 192 } 193 194 + /* Wrapper for the last available index. Makes it easier to change. */ 195 + #define lg_last_avail(vq) ((vq)->last_avail_idx) 196 + 197 /* The virtio configuration space is defined to be little-endian. x86 is 198 * little-endian too, but it's nice to be explicit so we have these helpers. */ 199 #define cpu_to_le16(v16) (v16) ··· 690 unsigned int *out_num, unsigned int *in_num) 691 { 692 unsigned int i, head; 693 + u16 last_avail; 694 695 /* Check it isn't doing very strange things with descriptor numbers. */ 696 + last_avail = lg_last_avail(vq); 697 + if ((u16)(vq->vring.avail->idx - last_avail) > vq->vring.num) 698 errx(1, "Guest moved used index from %u to %u", 699 + last_avail, vq->vring.avail->idx); 700 701 /* If there's nothing new since last we looked, return invalid. */ 702 + if (vq->vring.avail->idx == last_avail) 703 return vq->vring.num; 704 705 /* Grab the next descriptor number they're advertising, and increment 706 * the index we've seen. */ 707 + head = vq->vring.avail->ring[last_avail % vq->vring.num]; 708 + lg_last_avail(vq)++; 709 710 /* If their number is silly, that's a fatal mistake. */ 711 if (head >= vq->vring.num) ··· 980 for (vq = dev->vq; vq; vq = vq->next) { 981 memset(vq->vring.desc, 0, 982 vring_size(vq->config.num, getpagesize())); 983 + lg_last_avail(vq) = 0; 984 } 985 } else if (dev->desc->status & VIRTIO_CONFIG_S_FAILED) { 986 warnx("Device %s configuration FAILED", dev->name);