Skip to content

Commit beee7fd

Browse files
emuslnmstsirkin
authored andcommitted
vhost_vdpa: 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-4-shannon.nelson@amd.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Acked-by: Jason Wang <jasowang@redhat.com>
1 parent 55d8122 commit beee7fd

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

drivers/vhost/vdpa.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,14 @@ static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd,
607607
if (r)
608608
return r;
609609

610-
vq->last_avail_idx = vq_state.split.avail_index;
610+
if (vhost_has_feature(vq, VIRTIO_F_RING_PACKED)) {
611+
vq->last_avail_idx = vq_state.packed.last_avail_idx |
612+
(vq_state.packed.last_avail_counter << 15);
613+
vq->last_used_idx = vq_state.packed.last_used_idx |
614+
(vq_state.packed.last_used_counter << 15);
615+
} else {
616+
vq->last_avail_idx = vq_state.split.avail_index;
617+
}
611618
break;
612619
}
613620

@@ -625,9 +632,15 @@ static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd,
625632
break;
626633

627634
case VHOST_SET_VRING_BASE:
628-
vq_state.split.avail_index = vq->last_avail_idx;
629-
if (ops->set_vq_state(vdpa, idx, &vq_state))
630-
r = -EINVAL;
635+
if (vhost_has_feature(vq, VIRTIO_F_RING_PACKED)) {
636+
vq_state.packed.last_avail_idx = vq->last_avail_idx & 0x7fff;
637+
vq_state.packed.last_avail_counter = !!(vq->last_avail_idx & 0x8000);
638+
vq_state.packed.last_used_idx = vq->last_used_idx & 0x7fff;
639+
vq_state.packed.last_used_counter = !!(vq->last_used_idx & 0x8000);
640+
} else {
641+
vq_state.split.avail_index = vq->last_avail_idx;
642+
}
643+
r = ops->set_vq_state(vdpa, idx, &vq_state);
631644
break;
632645

633646
case VHOST_SET_VRING_CALL:

0 commit comments

Comments
 (0)