On Sat, Apr 22, 2023 at 3:57 AM Shannon Nelson <shannon.nelson@xxxxxxx> wrote: > > Use the right structs for PACKED or split vqs when setting and > getting the vring base. > > Signed-off-by: Shannon Nelson <shannon.nelson@xxxxxxx> > --- > drivers/vhost/vhost.c | 18 +++++++++++++----- > 1 file changed, 13 insertions(+), 5 deletions(-) > > diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c > index f11bdbe4c2c5..f64efda48f21 100644 > --- a/drivers/vhost/vhost.c > +++ b/drivers/vhost/vhost.c > @@ -1633,17 +1633,25 @@ long vhost_vring_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *arg > r = -EFAULT; > break; > } > - if (s.num > 0xffff) { > - r = -EINVAL; > - break; > + if (vhost_has_feature(vq, VIRTIO_F_RING_PACKED)) { > + vq->last_avail_idx = s.num & 0xffff; > + vq->last_used_idx = (s.num >> 16) & 0xffff; I think we need to tweak the comment around last_avail_idx and last_used_idx: /* Last available index we saw. */ u16 last_avail_idx; /* Last index we used. */ u16 last_used_idx; To describe that it contains wrap counters as well in the case of packed virtqueue or maybe it's time to rename them (since they are invented for split virtqueue). Thanks > + } else { > + if (s.num > 0xffff) { > + r = -EINVAL; > + break; > + } > + vq->last_avail_idx = s.num; > } > - vq->last_avail_idx = s.num; > /* Forget the cached index value. */ > vq->avail_idx = vq->last_avail_idx; > break; > case VHOST_GET_VRING_BASE: > s.index = idx; > - s.num = vq->last_avail_idx; > + if (vhost_has_feature(vq, VIRTIO_F_RING_PACKED)) > + s.num = (u32)vq->last_avail_idx | ((u32)vq->last_used_idx << 16); > + else > + s.num = vq->last_avail_idx; > if (copy_to_user(argp, &s, sizeof s)) > r = -EFAULT; > break; > -- > 2.17.1 > _______________________________________________ Virtualization mailing list Virtualization@xxxxxxxxxxxxxxxxxxxxxxxxxx https://lists.linuxfoundation.org/mailman/listinfo/virtualization