Re: [RFC v3 4/5] virtio_ring: add event idx support in packed ring

From: Jason Wang
Date: Tue May 08 2018 - 01:41:29 EST




On 2018å05æ08æ 11:05, Jason Wang wrote:

Because in virtqueue_enable_cb_delayed(), we may set an
event_off which is bigger than new and both of them have
wrapped. And in this case, although new is smaller than
event_off (i.e. the third param -- old), new shouldn't
add vq->num, and actually we are expecting a very big
idx diff.

Yes, so to calculate distance correctly between event and new, we just need to compare the warp counter and return false if it doesn't match without the need to try to add vq.num here.

Thanks

Sorry, looks like the following should work, we need add vq.num if used_wrap_counter does not match:

static bool vhost_vring_packed_need_event(struct vhost_virtqueue *vq,
ÂÂÂ ÂÂÂ ÂÂÂ ÂÂÂ ÂÂÂ Â __u16 off_wrap, __u16 new,
ÂÂÂ ÂÂÂ ÂÂÂ ÂÂÂ ÂÂÂ Â __u16 old)
{
ÂÂÂ bool wrap = off_wrap >> 15;
ÂÂÂ int off = off_wrap & ~(1 << 15);
ÂÂÂ __u16 d1, d2;

ÂÂÂ if (wrap != vq->used_wrap_counter)
ÂÂÂ ÂÂÂ d1 = new + vq->num - off - 1;
ÂÂÂ else
ÂÂÂ ÂÂÂ d1 = new - off - 1;

ÂÂÂ if (new > old)
ÂÂÂ ÂÂÂ d2 = new - old;
ÂÂÂ else
ÂÂÂ ÂÂÂ d2 = new + vq->num - old;

ÂÂÂ return d1 < d2;
}

Thanks