Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 106982
b: refs/heads/master
c: b511179
h: refs/heads/master
v: v3
  • Loading branch information
Rusty Russell committed Jul 28, 2008
1 parent 912e033 commit 1bf9e77
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: cf485e566bc4a8098680162e1cc2ac1dfbef8a3c
refs/heads/master: b5111790fa6695b1502d4f5d389f6b22b9de10c3
16 changes: 11 additions & 5 deletions trunk/Documentation/lguest/lguest.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ static void *_convert(struct iovec *iov, size_t size, size_t align,
return iov->iov_base;
}

/* Wrapper for the last available index. Makes it easier to change. */
#define lg_last_avail(vq) ((vq)->last_avail_idx)

/* 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. */
#define cpu_to_le16(v16) (v16)
Expand Down Expand Up @@ -690,19 +693,22 @@ static unsigned get_vq_desc(struct virtqueue *vq,
unsigned int *out_num, unsigned int *in_num)
{
unsigned int i, head;
u16 last_avail;

/* Check it isn't doing very strange things with descriptor numbers. */
if ((u16)(vq->vring.avail->idx - vq->last_avail_idx) > vq->vring.num)
last_avail = lg_last_avail(vq);
if ((u16)(vq->vring.avail->idx - last_avail) > vq->vring.num)
errx(1, "Guest moved used index from %u to %u",
vq->last_avail_idx, vq->vring.avail->idx);
last_avail, vq->vring.avail->idx);

/* If there's nothing new since last we looked, return invalid. */
if (vq->vring.avail->idx == vq->last_avail_idx)
if (vq->vring.avail->idx == last_avail)
return vq->vring.num;

/* Grab the next descriptor number they're advertising, and increment
* the index we've seen. */
head = vq->vring.avail->ring[vq->last_avail_idx++ % vq->vring.num];
head = vq->vring.avail->ring[last_avail % vq->vring.num];
lg_last_avail(vq)++;

/* If their number is silly, that's a fatal mistake. */
if (head >= vq->vring.num)
Expand Down Expand Up @@ -980,7 +986,7 @@ static void update_device_status(struct device *dev)
for (vq = dev->vq; vq; vq = vq->next) {
memset(vq->vring.desc, 0,
vring_size(vq->config.num, getpagesize()));
vq->last_avail_idx = 0;
lg_last_avail(vq) = 0;
}
} else if (dev->desc->status & VIRTIO_CONFIG_S_FAILED) {
warnx("Device %s configuration FAILED", dev->name);
Expand Down

0 comments on commit 1bf9e77

Please sign in to comment.