Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
vhost-vdpa: add support for svq asid
Signed-off-by: Si-Wei Liu <si-wei.liu@oracle.com>
  • Loading branch information
siwliu-kernel committed Aug 16, 2023
1 parent 39f2c29 commit 8135183
Show file tree
Hide file tree
Showing 7 changed files with 219 additions and 27 deletions.
26 changes: 17 additions & 9 deletions hw/virtio/vhost-shadow-virtqueue.c
Expand Up @@ -136,7 +136,7 @@ static bool vhost_svq_translate_addr(const VhostShadowVirtqueue *svq,
* Return true if success, false otherwise and print error.
*/
static bool vhost_svq_vring_write_descs(VhostShadowVirtqueue *svq, hwaddr *sg,
const struct iovec *iovec, size_t num,
const struct iovec *iovec, hwaddr *addr, size_t num,
bool more_descs, bool write)
{
uint16_t i = svq->free_head, last = svq->free_head;
Expand All @@ -149,8 +149,15 @@ static bool vhost_svq_vring_write_descs(VhostShadowVirtqueue *svq, hwaddr *sg,
return true;
}

ok = vhost_svq_translate_addr(svq, sg, iovec, num);
if (unlikely(!ok)) {
if (svq->iova_tree) {
ok = vhost_svq_translate_addr(svq, sg, iovec, num);
if (unlikely(!ok)) {
return false;
}
} else if (!addr) {
qemu_log_mask(LOG_GUEST_ERROR,
"No translation found for vaddr 0x%p\n",
iovec[0].iov_base);
return false;
}

Expand All @@ -161,7 +168,7 @@ static bool vhost_svq_vring_write_descs(VhostShadowVirtqueue *svq, hwaddr *sg,
} else {
descs[i].flags = flags;
}
descs[i].addr = cpu_to_le64(sg[n]);
descs[i].addr = cpu_to_le64(svq->iova_tree ? sg[n] : addr[n]);
descs[i].len = cpu_to_le32(iovec[n].iov_len);

last = i;
Expand All @@ -173,8 +180,8 @@ static bool vhost_svq_vring_write_descs(VhostShadowVirtqueue *svq, hwaddr *sg,
}

static bool vhost_svq_add_split(VhostShadowVirtqueue *svq,
const struct iovec *out_sg, size_t out_num,
const struct iovec *in_sg, size_t in_num,
const struct iovec *out_sg, hwaddr *out_addr, size_t out_num,
const struct iovec *in_sg, hwaddr *in_addr, size_t in_num,
unsigned *head)
{
unsigned avail_idx;
Expand All @@ -191,13 +198,13 @@ static bool vhost_svq_add_split(VhostShadowVirtqueue *svq,
return false;
}

ok = vhost_svq_vring_write_descs(svq, sgs, out_sg, out_num, in_num > 0,
ok = vhost_svq_vring_write_descs(svq, sgs, out_sg, out_addr, out_num, in_num > 0,
false);
if (unlikely(!ok)) {
return false;
}

ok = vhost_svq_vring_write_descs(svq, sgs, in_sg, in_num, false, true);
ok = vhost_svq_vring_write_descs(svq, sgs, in_sg, in_addr, in_num, false, true);
if (unlikely(!ok)) {
return false;
}
Expand Down Expand Up @@ -258,7 +265,8 @@ int vhost_svq_add(VhostShadowVirtqueue *svq, const struct iovec *out_sg,
return -ENOSPC;
}

ok = vhost_svq_add_split(svq, out_sg, out_num, in_sg, in_num, &qemu_head);
ok = vhost_svq_add_split(svq, out_sg, elem ? elem->out_addr : NULL, out_num,
in_sg, elem ? elem->in_addr : NULL, in_num, &qemu_head);
if (unlikely(!ok)) {
return -EINVAL;
}
Expand Down
3 changes: 2 additions & 1 deletion hw/virtio/vhost-vdpa.c
Expand Up @@ -1210,7 +1210,8 @@ static bool vhost_vdpa_svqs_start(struct vhost_dev *dev)
goto err;
}

vhost_svq_start(svq, dev->vdev, vq, v->iova_tree);
vhost_svq_start(svq, dev->vdev, vq,
v->desc_group >= 0 && v->address_space_id ? NULL : v->iova_tree);
ok = vhost_vdpa_svq_map_rings(dev, svq, &addr, &err);
if (unlikely(!ok)) {
goto err_map;
Expand Down
1 change: 1 addition & 0 deletions include/hw/virtio/vhost-vdpa.h
Expand Up @@ -49,6 +49,7 @@ typedef struct vhost_vdpa {
GPtrArray *shadow_vqs;
const VhostShadowVirtqueueOps *shadow_vq_ops;
void *shadow_vq_ops_opaque;
int64_t desc_group;
struct vhost_dev *dev;
Error *migration_blocker;
VhostVDPAHostNotifier notifier[VIRTIO_QUEUE_MAX];
Expand Down
5 changes: 5 additions & 0 deletions include/standard-headers/linux/vhost_types.h
Expand Up @@ -181,5 +181,10 @@ struct vhost_vdpa_iova_range {
#define VHOST_BACKEND_F_SUSPEND 0x4
/* Device can be resumed */
#define VHOST_BACKEND_F_RESUME 0x5
/* Device may expose the descriptor table, avail and used ring in a
* different group for ASID binding than the buffers it contains.
* Requires VHOST_BACKEND_F_IOTLB_ASID.
*/
#define VHOST_BACKEND_F_DESC_ASID 0x6

#endif
9 changes: 9 additions & 0 deletions linux-headers/linux/vhost.h
Expand Up @@ -219,4 +219,13 @@
*/
#define VHOST_VDPA_RESUME _IO(VHOST_VIRTIO, 0x7E)

/* Get the dedicated group for the descriptor table of a virtqueue:
* read index, write group in num.
* The virtqueue index is stored in the index field of vhost_vring_state.
* The group id for the descriptor table of this specific virtqueue
* is returned via num field of vhost_vring_state.
*/
#define VHOST_VDPA_GET_VRING_DESC_GROUP _IOWR(VHOST_VIRTIO, 0x7F, \
struct vhost_vring_state)

#endif
3 changes: 3 additions & 0 deletions net/trace-events
Expand Up @@ -23,3 +23,6 @@ colo_compare_tcp_info(const char *pkt, uint32_t seq, uint32_t ack, int hdlen, in
# filter-rewriter.c
colo_filter_rewriter_pkt_info(const char *func, const char *src, const char *dst, uint32_t seq, uint32_t ack, uint32_t flag) "%s: src/dst: %s/%s p: seq/ack=%u/%u flags=0x%x"
colo_filter_rewriter_conn_offset(uint32_t offset) ": offset=%u"

# vhost-vdpa.c
vhost_vdpa_set_address_space_id(void *v, unsigned vq_group, unsigned asid_num) "vhost_vdpa: %p vq_group: %u asid: %u"

0 comments on commit 8135183

Please sign in to comment.