Skip to content

Commit 55d8122

Browse files
emuslnmstsirkin
authored andcommitted
vhost: support PACKED when setting-getting vring_base
Use the right structs for PACKED or split vqs when setting and getting the vring base. Fixes: 4c8cf31 ("vhost: introduce vDPA-based backend") Signed-off-by: Shannon Nelson <shannon.nelson@amd.com> Message-Id: <20230424225031.18947-3-shannon.nelson@amd.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Acked-by: Jason Wang <jasowang@redhat.com>
1 parent 4b13cbe commit 55d8122

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

drivers/vhost/vhost.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1600,17 +1600,25 @@ long vhost_vring_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *arg
16001600
r = -EFAULT;
16011601
break;
16021602
}
1603-
if (s.num > 0xffff) {
1604-
r = -EINVAL;
1605-
break;
1603+
if (vhost_has_feature(vq, VIRTIO_F_RING_PACKED)) {
1604+
vq->last_avail_idx = s.num & 0xffff;
1605+
vq->last_used_idx = (s.num >> 16) & 0xffff;
1606+
} else {
1607+
if (s.num > 0xffff) {
1608+
r = -EINVAL;
1609+
break;
1610+
}
1611+
vq->last_avail_idx = s.num;
16061612
}
1607-
vq->last_avail_idx = s.num;
16081613
/* Forget the cached index value. */
16091614
vq->avail_idx = vq->last_avail_idx;
16101615
break;
16111616
case VHOST_GET_VRING_BASE:
16121617
s.index = idx;
1613-
s.num = vq->last_avail_idx;
1618+
if (vhost_has_feature(vq, VIRTIO_F_RING_PACKED))
1619+
s.num = (u32)vq->last_avail_idx | ((u32)vq->last_used_idx << 16);
1620+
else
1621+
s.num = vq->last_avail_idx;
16141622
if (copy_to_user(argp, &s, sizeof s))
16151623
r = -EFAULT;
16161624
break;

drivers/vhost/vhost.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,17 @@ struct vhost_virtqueue {
9292
/* The routine to call when the Guest pings us, or timeout. */
9393
vhost_work_fn_t handle_kick;
9494

95-
/* Last available index we saw. */
95+
/* Last available index we saw.
96+
* Values are limited to 0x7fff, and the high bit is used as
97+
* a wrap counter when using VIRTIO_F_RING_PACKED. */
9698
u16 last_avail_idx;
9799

98100
/* Caches available index value from user. */
99101
u16 avail_idx;
100102

101-
/* Last index we used. */
103+
/* Last index we used.
104+
* Values are limited to 0x7fff, and the high bit is used as
105+
* a wrap counter when using VIRTIO_F_RING_PACKED. */
102106
u16 last_used_idx;
103107

104108
/* Used flags */

0 commit comments

Comments
 (0)