Skip to contentSkip to conversation

vhost: packed ring support completion

PATCH Superseded Maxime Coquelin 1 participant 3 messages Oct 18, 2018

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover vhost: packed ring support completion

In this v3, the vring state num field structure is changed to store both used and avail indexes and their wrap counters.

Initial series ading packed ring layout support to the vhost library was missing the save and restore of the wrap counters and indexs on vring base requests used for migration.

First patch saves/restores the used and avail indexes and their wrap counters values into/from the vring state num field.

Patch 2 advertise support for the packed ring.

Maxime Coquelin (2):
vhost: add packed ring support to vring base requests
vhost: advertize packed ring layout support

 lib/librte_vhost/vhost.h      |  3 ++-
 lib/librte_vhost/vhost_user.c | 41 ++++++++++++++++++++++++++++++-----
 2 files changed, 37 insertions(+), 7 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH v3 1/2 vhost: add packed ring support to vring base requests

For packed ring layout, we need save and restore avail and used indexes, and their wrap counter values.

---
 lib/librte_vhost/vhost_user.c | 41 ++++++++++++++++++++++++++++++-----
 1 file changed, 35 insertions(+), 6 deletions(-)
lib/librte_vhost/vhost_user.c +35 -6
index 508228a3c..ff80bef8e 100644
@@ -696,10 +696,24 @@ vhost_user_set_vring_base(struct virtio_net **pdev,
 			int main_fd __rte_unused)
 {
 	struct virtio_net *dev = *pdev;
-	dev->virtqueue[msg->payload.state.index]->last_used_idx  =
-			msg->payload.state.num;
-	dev->virtqueue[msg->payload.state.index]->last_avail_idx =
-			msg->payload.state.num;
+	struct vhost_virtqueue *vq = dev->virtqueue[msg->payload.state.index];
+	uint64_t val = msg->payload.state.num;
+
+	if (vq_is_packed(dev)) {
+		/*
+		 * Bit[0:14]: avail index
+		 * Bit[15]: avail wrap counter
+		 * Bit[16:30]: used index
+		 * Bit[31]: used wrap counter
+		 */
+		vq->last_avail_idx = val & 0x7fff;
+		vq->avail_wrap_counter = (val & (0x1 << 15)) >> 15;
+		vq->last_used_idx = (val & (0x7fff << 16)) >> 16;
+		vq->used_wrap_counter = (val & (0x1 << 31)) >> 31;
+	} else {
+		vq->last_used_idx = msg->payload.state.num;
+		vq->last_avail_idx = msg->payload.state.num;
+	}
 
 	return VH_RESULT_OK;
 }
@@ -1208,6 +1222,7 @@ vhost_user_get_vring_base(struct virtio_net **pdev,
 {
 	struct virtio_net *dev = *pdev;
 	struct vhost_virtqueue *vq = dev->virtqueue[msg->payload.state.index];
+	uint64_t val;
 
 	/* We have to stop the queue (virtio) if it is running. */
 	vhost_destroy_device_notify(dev);
@@ -1215,8 +1230,22 @@ vhost_user_get_vring_base(struct virtio_net **pdev,
 	dev->flags &= ~VIRTIO_DEV_READY;
 	dev->flags &= ~VIRTIO_DEV_VDPA_CONFIGURED;
 
-	/* Here we are safe to get the last avail index */
-	msg->payload.state.num = vq->last_avail_idx;
+	/* Here we are safe to get the indexes */
+	if (vq_is_packed(dev)) {
+		/*
+		 * Bit[0:14]: avail index
+		 * Bit[15]: avail wrap counter
+		 * Bit[16:30]: used index
+		 * Bit[31]: used wrap counter
+		 */
+		val = vq->last_avail_idx & 0x7fff;
+		val |= vq->avail_wrap_counter << 15;
+		val |= (vq->last_used_idx & 0x7fff) << 16;
+		val |= vq->used_wrap_counter << 31;
+		msg->payload.state.num = val;
+	} else {
+		msg->payload.state.num = vq->last_avail_idx;
+	}
 
 	RTE_LOG(INFO, VHOST_CONFIG,
 		"vring base idx:%d file:%d\n", msg->payload.state.index,
Signature · 1 line
2.17.1
#2 lore raw

PATCH v3 2/2 vhost: advertize packed ring layout support

In reply to Maxime Coquelin
---
 lib/librte_vhost/vhost.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
lib/librte_vhost/vhost.h +2 -1
index b4abad30c..760f42192 100644
@@ -275,7 +275,8 @@ struct vring_packed_desc_event {
 				(1ULL << VIRTIO_RING_F_EVENT_IDX) | \
 				(1ULL << VIRTIO_NET_F_MTU)  | \
 				(1ULL << VIRTIO_F_IN_ORDER) | \
-				(1ULL << VIRTIO_F_IOMMU_PLATFORM))
+				(1ULL << VIRTIO_F_IOMMU_PLATFORM) | \
+				(1ULL << VIRTIO_F_RING_PACKED))
 
 
 struct guest_page {
Signature · 1 line
2.17.1