All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH V2 0/4]
@ 2021-06-02  2:10 ` Jason Wang
  0 siblings, 0 replies; 20+ messages in thread
From: Jason Wang @ 2021-06-02  2:10 UTC (permalink / raw)
  To: mst, jasowang, virtualization, linux-kernel, kvm, netdev; +Cc: eli

*** BLURB HERE ***

Eli Cohen (1):
  virtio/vdpa: clear the virtqueue state during probe

Jason Wang (3):
  vdpa: support packed virtqueue for set/get_vq_state()
  virtio-pci library: introduce vp_modern_get_driver_features()
  vp_vdpa: allow set vq state to initial state after reset

 drivers/vdpa/ifcvf/ifcvf_main.c        |  4 +--
 drivers/vdpa/mlx5/net/mlx5_vnet.c      |  8 ++---
 drivers/vdpa/vdpa_sim/vdpa_sim.c       |  4 +--
 drivers/vdpa/virtio_pci/vp_vdpa.c      | 42 ++++++++++++++++++++++++--
 drivers/vhost/vdpa.c                   |  4 +--
 drivers/virtio/virtio_pci_modern_dev.c | 21 +++++++++++++
 drivers/virtio/virtio_vdpa.c           | 15 +++++++++
 include/linux/vdpa.h                   | 25 +++++++++++++--
 include/linux/virtio_pci_modern.h      |  1 +
 9 files changed, 109 insertions(+), 15 deletions(-)

-- 
2.25.1


^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH V2 0/4]
@ 2021-06-02  2:10 ` Jason Wang
  0 siblings, 0 replies; 20+ messages in thread
From: Jason Wang @ 2021-06-02  2:10 UTC (permalink / raw)
  To: mst, jasowang, virtualization, linux-kernel, kvm, netdev; +Cc: eli

*** BLURB HERE ***

Eli Cohen (1):
  virtio/vdpa: clear the virtqueue state during probe

Jason Wang (3):
  vdpa: support packed virtqueue for set/get_vq_state()
  virtio-pci library: introduce vp_modern_get_driver_features()
  vp_vdpa: allow set vq state to initial state after reset

 drivers/vdpa/ifcvf/ifcvf_main.c        |  4 +--
 drivers/vdpa/mlx5/net/mlx5_vnet.c      |  8 ++---
 drivers/vdpa/vdpa_sim/vdpa_sim.c       |  4 +--
 drivers/vdpa/virtio_pci/vp_vdpa.c      | 42 ++++++++++++++++++++++++--
 drivers/vhost/vdpa.c                   |  4 +--
 drivers/virtio/virtio_pci_modern_dev.c | 21 +++++++++++++
 drivers/virtio/virtio_vdpa.c           | 15 +++++++++
 include/linux/vdpa.h                   | 25 +++++++++++++--
 include/linux/virtio_pci_modern.h      |  1 +
 9 files changed, 109 insertions(+), 15 deletions(-)

-- 
2.25.1

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH V2 1/4] vdpa: support packed virtqueue for set/get_vq_state()
  2021-06-02  2:10 ` Jason Wang
@ 2021-06-02  2:10   ` Jason Wang
  -1 siblings, 0 replies; 20+ messages in thread
From: Jason Wang @ 2021-06-02  2:10 UTC (permalink / raw)
  To: mst, jasowang, virtualization, linux-kernel, kvm, netdev; +Cc: eli

This patch extends the vdpa_vq_state to support packed virtqueue
state which is basically the device/driver ring wrap counters and the
avail and used index. This will be used for the virito-vdpa support
for the packed virtqueue and the future vhost/vhost-vdpa support for
the packed virtqueue.

Signed-off-by: Jason Wang <jasowang@redhat.com>
---
 drivers/vdpa/ifcvf/ifcvf_main.c   |  4 ++--
 drivers/vdpa/mlx5/net/mlx5_vnet.c |  8 ++++----
 drivers/vdpa/vdpa_sim/vdpa_sim.c  |  4 ++--
 drivers/vhost/vdpa.c              |  4 ++--
 include/linux/vdpa.h              | 25 +++++++++++++++++++++++--
 5 files changed, 33 insertions(+), 12 deletions(-)

diff --git a/drivers/vdpa/ifcvf/ifcvf_main.c b/drivers/vdpa/ifcvf/ifcvf_main.c
index ab0ab5cf0f6e..5d3891b1ca28 100644
--- a/drivers/vdpa/ifcvf/ifcvf_main.c
+++ b/drivers/vdpa/ifcvf/ifcvf_main.c
@@ -264,7 +264,7 @@ static int ifcvf_vdpa_get_vq_state(struct vdpa_device *vdpa_dev, u16 qid,
 {
 	struct ifcvf_hw *vf = vdpa_to_vf(vdpa_dev);
 
-	state->avail_index = ifcvf_get_vq_state(vf, qid);
+	state->split.avail_index = ifcvf_get_vq_state(vf, qid);
 	return 0;
 }
 
@@ -273,7 +273,7 @@ static int ifcvf_vdpa_set_vq_state(struct vdpa_device *vdpa_dev, u16 qid,
 {
 	struct ifcvf_hw *vf = vdpa_to_vf(vdpa_dev);
 
-	return ifcvf_set_vq_state(vf, qid, state->avail_index);
+	return ifcvf_set_vq_state(vf, qid, state->split.avail_index);
 }
 
 static void ifcvf_vdpa_set_vq_cb(struct vdpa_device *vdpa_dev, u16 qid,
diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c
index 189e4385df40..e5505d760bca 100644
--- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
+++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
@@ -1427,8 +1427,8 @@ static int mlx5_vdpa_set_vq_state(struct vdpa_device *vdev, u16 idx,
 		return -EINVAL;
 	}
 
-	mvq->used_idx = state->avail_index;
-	mvq->avail_idx = state->avail_index;
+	mvq->used_idx = state->split.avail_index;
+	mvq->avail_idx = state->split.avail_index;
 	return 0;
 }
 
@@ -1449,7 +1449,7 @@ static int mlx5_vdpa_get_vq_state(struct vdpa_device *vdev, u16 idx, struct vdpa
 		 * Since both values should be identical, we take the value of
 		 * used_idx which is reported correctly.
 		 */
-		state->avail_index = mvq->used_idx;
+		state->split.avail_index = mvq->used_idx;
 		return 0;
 	}
 
@@ -1458,7 +1458,7 @@ static int mlx5_vdpa_get_vq_state(struct vdpa_device *vdev, u16 idx, struct vdpa
 		mlx5_vdpa_warn(mvdev, "failed to query virtqueue\n");
 		return err;
 	}
-	state->avail_index = attr.used_index;
+	state->split.avail_index = attr.used_index;
 	return 0;
 }
 
diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c
index 98f793bc9376..14e024de5cbf 100644
--- a/drivers/vdpa/vdpa_sim/vdpa_sim.c
+++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c
@@ -374,7 +374,7 @@ static int vdpasim_set_vq_state(struct vdpa_device *vdpa, u16 idx,
 	struct vringh *vrh = &vq->vring;
 
 	spin_lock(&vdpasim->lock);
-	vrh->last_avail_idx = state->avail_index;
+	vrh->last_avail_idx = state->split.avail_index;
 	spin_unlock(&vdpasim->lock);
 
 	return 0;
@@ -387,7 +387,7 @@ static int vdpasim_get_vq_state(struct vdpa_device *vdpa, u16 idx,
 	struct vdpasim_virtqueue *vq = &vdpasim->vqs[idx];
 	struct vringh *vrh = &vq->vring;
 
-	state->avail_index = vrh->last_avail_idx;
+	state->split.avail_index = vrh->last_avail_idx;
 	return 0;
 }
 
diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
index fb41db3da611..210ab35a7ebf 100644
--- a/drivers/vhost/vdpa.c
+++ b/drivers/vhost/vdpa.c
@@ -383,7 +383,7 @@ static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd,
 		if (r)
 			return r;
 
-		vq->last_avail_idx = vq_state.avail_index;
+		vq->last_avail_idx = vq_state.split.avail_index;
 		break;
 	}
 
@@ -401,7 +401,7 @@ static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd,
 		break;
 
 	case VHOST_SET_VRING_BASE:
-		vq_state.avail_index = vq->last_avail_idx;
+		vq_state.split.avail_index = vq->last_avail_idx;
 		if (ops->set_vq_state(vdpa, idx, &vq_state))
 			r = -EINVAL;
 		break;
diff --git a/include/linux/vdpa.h b/include/linux/vdpa.h
index f311d227aa1b..3357ac98878d 100644
--- a/include/linux/vdpa.h
+++ b/include/linux/vdpa.h
@@ -28,13 +28,34 @@ struct vdpa_notification_area {
 };
 
 /**
- * struct vdpa_vq_state - vDPA vq_state definition
+ * struct vdpa_vq_state_split - vDPA split virtqueue state
  * @avail_index: available index
  */
-struct vdpa_vq_state {
+struct vdpa_vq_state_split {
 	u16	avail_index;
 };
 
+/**
+ * struct vdpa_vq_state_packed - vDPA packed virtqueue state
+ * @last_avail_counter: last driver ring wrap counter observed by device
+ * @last_avail_idx: device available index
+ * @last_used_counter: device ring wrap counter
+ * @last_used_idx: used index
+ */
+struct vdpa_vq_state_packed {
+        u16	last_avail_counter:1;
+        u16	last_avail_idx:15;
+        u16	last_used_counter:1;
+        u16	last_used_idx:15;
+};
+
+struct vdpa_vq_state {
+     union {
+          struct vdpa_vq_state_split split;
+          struct vdpa_vq_state_packed packed;
+     };
+};
+
 struct vdpa_mgmt_dev;
 
 /**
-- 
2.25.1


^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH V2 1/4] vdpa: support packed virtqueue for set/get_vq_state()
@ 2021-06-02  2:10   ` Jason Wang
  0 siblings, 0 replies; 20+ messages in thread
From: Jason Wang @ 2021-06-02  2:10 UTC (permalink / raw)
  To: mst, jasowang, virtualization, linux-kernel, kvm, netdev; +Cc: eli

This patch extends the vdpa_vq_state to support packed virtqueue
state which is basically the device/driver ring wrap counters and the
avail and used index. This will be used for the virito-vdpa support
for the packed virtqueue and the future vhost/vhost-vdpa support for
the packed virtqueue.

Signed-off-by: Jason Wang <jasowang@redhat.com>
---
 drivers/vdpa/ifcvf/ifcvf_main.c   |  4 ++--
 drivers/vdpa/mlx5/net/mlx5_vnet.c |  8 ++++----
 drivers/vdpa/vdpa_sim/vdpa_sim.c  |  4 ++--
 drivers/vhost/vdpa.c              |  4 ++--
 include/linux/vdpa.h              | 25 +++++++++++++++++++++++--
 5 files changed, 33 insertions(+), 12 deletions(-)

diff --git a/drivers/vdpa/ifcvf/ifcvf_main.c b/drivers/vdpa/ifcvf/ifcvf_main.c
index ab0ab5cf0f6e..5d3891b1ca28 100644
--- a/drivers/vdpa/ifcvf/ifcvf_main.c
+++ b/drivers/vdpa/ifcvf/ifcvf_main.c
@@ -264,7 +264,7 @@ static int ifcvf_vdpa_get_vq_state(struct vdpa_device *vdpa_dev, u16 qid,
 {
 	struct ifcvf_hw *vf = vdpa_to_vf(vdpa_dev);
 
-	state->avail_index = ifcvf_get_vq_state(vf, qid);
+	state->split.avail_index = ifcvf_get_vq_state(vf, qid);
 	return 0;
 }
 
@@ -273,7 +273,7 @@ static int ifcvf_vdpa_set_vq_state(struct vdpa_device *vdpa_dev, u16 qid,
 {
 	struct ifcvf_hw *vf = vdpa_to_vf(vdpa_dev);
 
-	return ifcvf_set_vq_state(vf, qid, state->avail_index);
+	return ifcvf_set_vq_state(vf, qid, state->split.avail_index);
 }
 
 static void ifcvf_vdpa_set_vq_cb(struct vdpa_device *vdpa_dev, u16 qid,
diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c
index 189e4385df40..e5505d760bca 100644
--- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
+++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
@@ -1427,8 +1427,8 @@ static int mlx5_vdpa_set_vq_state(struct vdpa_device *vdev, u16 idx,
 		return -EINVAL;
 	}
 
-	mvq->used_idx = state->avail_index;
-	mvq->avail_idx = state->avail_index;
+	mvq->used_idx = state->split.avail_index;
+	mvq->avail_idx = state->split.avail_index;
 	return 0;
 }
 
@@ -1449,7 +1449,7 @@ static int mlx5_vdpa_get_vq_state(struct vdpa_device *vdev, u16 idx, struct vdpa
 		 * Since both values should be identical, we take the value of
 		 * used_idx which is reported correctly.
 		 */
-		state->avail_index = mvq->used_idx;
+		state->split.avail_index = mvq->used_idx;
 		return 0;
 	}
 
@@ -1458,7 +1458,7 @@ static int mlx5_vdpa_get_vq_state(struct vdpa_device *vdev, u16 idx, struct vdpa
 		mlx5_vdpa_warn(mvdev, "failed to query virtqueue\n");
 		return err;
 	}
-	state->avail_index = attr.used_index;
+	state->split.avail_index = attr.used_index;
 	return 0;
 }
 
diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c
index 98f793bc9376..14e024de5cbf 100644
--- a/drivers/vdpa/vdpa_sim/vdpa_sim.c
+++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c
@@ -374,7 +374,7 @@ static int vdpasim_set_vq_state(struct vdpa_device *vdpa, u16 idx,
 	struct vringh *vrh = &vq->vring;
 
 	spin_lock(&vdpasim->lock);
-	vrh->last_avail_idx = state->avail_index;
+	vrh->last_avail_idx = state->split.avail_index;
 	spin_unlock(&vdpasim->lock);
 
 	return 0;
@@ -387,7 +387,7 @@ static int vdpasim_get_vq_state(struct vdpa_device *vdpa, u16 idx,
 	struct vdpasim_virtqueue *vq = &vdpasim->vqs[idx];
 	struct vringh *vrh = &vq->vring;
 
-	state->avail_index = vrh->last_avail_idx;
+	state->split.avail_index = vrh->last_avail_idx;
 	return 0;
 }
 
diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
index fb41db3da611..210ab35a7ebf 100644
--- a/drivers/vhost/vdpa.c
+++ b/drivers/vhost/vdpa.c
@@ -383,7 +383,7 @@ static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd,
 		if (r)
 			return r;
 
-		vq->last_avail_idx = vq_state.avail_index;
+		vq->last_avail_idx = vq_state.split.avail_index;
 		break;
 	}
 
@@ -401,7 +401,7 @@ static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd,
 		break;
 
 	case VHOST_SET_VRING_BASE:
-		vq_state.avail_index = vq->last_avail_idx;
+		vq_state.split.avail_index = vq->last_avail_idx;
 		if (ops->set_vq_state(vdpa, idx, &vq_state))
 			r = -EINVAL;
 		break;
diff --git a/include/linux/vdpa.h b/include/linux/vdpa.h
index f311d227aa1b..3357ac98878d 100644
--- a/include/linux/vdpa.h
+++ b/include/linux/vdpa.h
@@ -28,13 +28,34 @@ struct vdpa_notification_area {
 };
 
 /**
- * struct vdpa_vq_state - vDPA vq_state definition
+ * struct vdpa_vq_state_split - vDPA split virtqueue state
  * @avail_index: available index
  */
-struct vdpa_vq_state {
+struct vdpa_vq_state_split {
 	u16	avail_index;
 };
 
+/**
+ * struct vdpa_vq_state_packed - vDPA packed virtqueue state
+ * @last_avail_counter: last driver ring wrap counter observed by device
+ * @last_avail_idx: device available index
+ * @last_used_counter: device ring wrap counter
+ * @last_used_idx: used index
+ */
+struct vdpa_vq_state_packed {
+        u16	last_avail_counter:1;
+        u16	last_avail_idx:15;
+        u16	last_used_counter:1;
+        u16	last_used_idx:15;
+};
+
+struct vdpa_vq_state {
+     union {
+          struct vdpa_vq_state_split split;
+          struct vdpa_vq_state_packed packed;
+     };
+};
+
 struct vdpa_mgmt_dev;
 
 /**
-- 
2.25.1

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH V2 2/4] virtio-pci library: introduce vp_modern_get_driver_features()
  2021-06-02  2:10 ` Jason Wang
@ 2021-06-02  2:10   ` Jason Wang
  -1 siblings, 0 replies; 20+ messages in thread
From: Jason Wang @ 2021-06-02  2:10 UTC (permalink / raw)
  To: mst, jasowang, virtualization, linux-kernel, kvm, netdev; +Cc: eli

This patch introduce a helper to get driver/guest features from the
device.

Signed-off-by: Jason Wang <jasowang@redhat.com>
---
 drivers/virtio/virtio_pci_modern_dev.c | 21 +++++++++++++++++++++
 include/linux/virtio_pci_modern.h      |  1 +
 2 files changed, 22 insertions(+)

diff --git a/drivers/virtio/virtio_pci_modern_dev.c b/drivers/virtio/virtio_pci_modern_dev.c
index 54f297028586..e11ed748e661 100644
--- a/drivers/virtio/virtio_pci_modern_dev.c
+++ b/drivers/virtio/virtio_pci_modern_dev.c
@@ -383,6 +383,27 @@ u64 vp_modern_get_features(struct virtio_pci_modern_device *mdev)
 }
 EXPORT_SYMBOL_GPL(vp_modern_get_features);
 
+/*
+ * vp_modern_get_driver_features - get driver features from device
+ * @mdev: the modern virtio-pci device
+ *
+ * Returns the driver features read from the device
+ */
+u64 vp_modern_get_driver_features(struct virtio_pci_modern_device *mdev)
+{
+	struct virtio_pci_common_cfg __iomem *cfg = mdev->common;
+
+	u64 features;
+
+	vp_iowrite32(0, &cfg->guest_feature_select);
+	features = vp_ioread32(&cfg->guest_feature);
+	vp_iowrite32(1, &cfg->guest_feature_select);
+	features |= ((u64)vp_ioread32(&cfg->guest_feature) << 32);
+
+	return features;
+}
+EXPORT_SYMBOL_GPL(vp_modern_get_driver_features);
+
 /*
  * vp_modern_set_features - set features to device
  * @mdev: the modern virtio-pci device
diff --git a/include/linux/virtio_pci_modern.h b/include/linux/virtio_pci_modern.h
index 6a95b58fd0f4..eb2bd9b4077d 100644
--- a/include/linux/virtio_pci_modern.h
+++ b/include/linux/virtio_pci_modern.h
@@ -79,6 +79,7 @@ static inline void vp_iowrite64_twopart(u64 val,
 }
 
 u64 vp_modern_get_features(struct virtio_pci_modern_device *mdev);
+u64 vp_modern_get_driver_features(struct virtio_pci_modern_device *mdev);
 void vp_modern_set_features(struct virtio_pci_modern_device *mdev,
 		     u64 features);
 u32 vp_modern_generation(struct virtio_pci_modern_device *mdev);
-- 
2.25.1


^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH V2 2/4] virtio-pci library: introduce vp_modern_get_driver_features()
@ 2021-06-02  2:10   ` Jason Wang
  0 siblings, 0 replies; 20+ messages in thread
From: Jason Wang @ 2021-06-02  2:10 UTC (permalink / raw)
  To: mst, jasowang, virtualization, linux-kernel, kvm, netdev; +Cc: eli

This patch introduce a helper to get driver/guest features from the
device.

Signed-off-by: Jason Wang <jasowang@redhat.com>
---
 drivers/virtio/virtio_pci_modern_dev.c | 21 +++++++++++++++++++++
 include/linux/virtio_pci_modern.h      |  1 +
 2 files changed, 22 insertions(+)

diff --git a/drivers/virtio/virtio_pci_modern_dev.c b/drivers/virtio/virtio_pci_modern_dev.c
index 54f297028586..e11ed748e661 100644
--- a/drivers/virtio/virtio_pci_modern_dev.c
+++ b/drivers/virtio/virtio_pci_modern_dev.c
@@ -383,6 +383,27 @@ u64 vp_modern_get_features(struct virtio_pci_modern_device *mdev)
 }
 EXPORT_SYMBOL_GPL(vp_modern_get_features);
 
+/*
+ * vp_modern_get_driver_features - get driver features from device
+ * @mdev: the modern virtio-pci device
+ *
+ * Returns the driver features read from the device
+ */
+u64 vp_modern_get_driver_features(struct virtio_pci_modern_device *mdev)
+{
+	struct virtio_pci_common_cfg __iomem *cfg = mdev->common;
+
+	u64 features;
+
+	vp_iowrite32(0, &cfg->guest_feature_select);
+	features = vp_ioread32(&cfg->guest_feature);
+	vp_iowrite32(1, &cfg->guest_feature_select);
+	features |= ((u64)vp_ioread32(&cfg->guest_feature) << 32);
+
+	return features;
+}
+EXPORT_SYMBOL_GPL(vp_modern_get_driver_features);
+
 /*
  * vp_modern_set_features - set features to device
  * @mdev: the modern virtio-pci device
diff --git a/include/linux/virtio_pci_modern.h b/include/linux/virtio_pci_modern.h
index 6a95b58fd0f4..eb2bd9b4077d 100644
--- a/include/linux/virtio_pci_modern.h
+++ b/include/linux/virtio_pci_modern.h
@@ -79,6 +79,7 @@ static inline void vp_iowrite64_twopart(u64 val,
 }
 
 u64 vp_modern_get_features(struct virtio_pci_modern_device *mdev);
+u64 vp_modern_get_driver_features(struct virtio_pci_modern_device *mdev);
 void vp_modern_set_features(struct virtio_pci_modern_device *mdev,
 		     u64 features);
 u32 vp_modern_generation(struct virtio_pci_modern_device *mdev);
-- 
2.25.1

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH V2 3/4] vp_vdpa: allow set vq state to initial state after reset
  2021-06-02  2:10 ` Jason Wang
@ 2021-06-02  2:10   ` Jason Wang
  -1 siblings, 0 replies; 20+ messages in thread
From: Jason Wang @ 2021-06-02  2:10 UTC (permalink / raw)
  To: mst, jasowang, virtualization, linux-kernel, kvm, netdev; +Cc: eli

We used to fail the set_vq_state() since it was not supported yet by
the virtio spec. But if the bus tries to set the state which is equal
to the device initial state after reset, we can let it go.

This is a must for virtio_vdpa() to set vq state during probe which is
required for some vDPA parents.

Signed-off-by: Jason Wang <jasowang@redhat.com>
---
 drivers/vdpa/virtio_pci/vp_vdpa.c | 42 ++++++++++++++++++++++++++++---
 1 file changed, 39 insertions(+), 3 deletions(-)

diff --git a/drivers/vdpa/virtio_pci/vp_vdpa.c b/drivers/vdpa/virtio_pci/vp_vdpa.c
index c76ebb531212..18bf4a422772 100644
--- a/drivers/vdpa/virtio_pci/vp_vdpa.c
+++ b/drivers/vdpa/virtio_pci/vp_vdpa.c
@@ -210,13 +210,49 @@ static int vp_vdpa_get_vq_state(struct vdpa_device *vdpa, u16 qid,
 	return -EOPNOTSUPP;
 }
 
+static int vp_vdpa_set_vq_state_split(struct vdpa_device *vdpa,
+				      const struct vdpa_vq_state *state)
+{
+	const struct vdpa_vq_state_split *split = &state->split;
+
+	if (split->avail_index == 0)
+		return 0;
+
+	return -EOPNOTSUPP;
+}
+
+static int vp_vdpa_set_vq_state_packed(struct vdpa_device *vdpa,
+				       const struct vdpa_vq_state *state)
+{
+	const struct vdpa_vq_state_packed *packed = &state->packed;
+
+	if (packed->last_avail_counter == 1 &&
+	    packed->last_avail_idx == 0 &&
+	    packed->last_used_counter == 1 &&
+	    packed->last_used_idx == 0)
+		return 0;
+
+	return -EOPNOTSUPP;
+}
+
 static int vp_vdpa_set_vq_state(struct vdpa_device *vdpa, u16 qid,
 				const struct vdpa_vq_state *state)
 {
-	/* Note that this is not supported by virtio specification, so
-	 * we return -ENOPOTSUPP here. This means we can't support live
-	 * migration, vhost device start/stop.
+	struct virtio_pci_modern_device *mdev = vdpa_to_mdev(vdpa);
+
+	/* Note that this is not supported by virtio specification.
+	 * But if the state is by chance equal to the device initial
+	 * state, we can let it go.
 	 */
+	if ((vp_modern_get_status(mdev) & VIRTIO_CONFIG_S_FEATURES_OK) &&
+	    !vp_modern_get_queue_enable(mdev, qid)) {
+		if (vp_modern_get_driver_features(mdev) &
+		    BIT_ULL(VIRTIO_F_RING_PACKED))
+			return vp_vdpa_set_vq_state_packed(vdpa, state);
+		else
+			return vp_vdpa_set_vq_state_split(vdpa,	state);
+	}
+
 	return -EOPNOTSUPP;
 }
 
-- 
2.25.1


^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH V2 3/4] vp_vdpa: allow set vq state to initial state after reset
@ 2021-06-02  2:10   ` Jason Wang
  0 siblings, 0 replies; 20+ messages in thread
From: Jason Wang @ 2021-06-02  2:10 UTC (permalink / raw)
  To: mst, jasowang, virtualization, linux-kernel, kvm, netdev; +Cc: eli

We used to fail the set_vq_state() since it was not supported yet by
the virtio spec. But if the bus tries to set the state which is equal
to the device initial state after reset, we can let it go.

This is a must for virtio_vdpa() to set vq state during probe which is
required for some vDPA parents.

Signed-off-by: Jason Wang <jasowang@redhat.com>
---
 drivers/vdpa/virtio_pci/vp_vdpa.c | 42 ++++++++++++++++++++++++++++---
 1 file changed, 39 insertions(+), 3 deletions(-)

diff --git a/drivers/vdpa/virtio_pci/vp_vdpa.c b/drivers/vdpa/virtio_pci/vp_vdpa.c
index c76ebb531212..18bf4a422772 100644
--- a/drivers/vdpa/virtio_pci/vp_vdpa.c
+++ b/drivers/vdpa/virtio_pci/vp_vdpa.c
@@ -210,13 +210,49 @@ static int vp_vdpa_get_vq_state(struct vdpa_device *vdpa, u16 qid,
 	return -EOPNOTSUPP;
 }
 
+static int vp_vdpa_set_vq_state_split(struct vdpa_device *vdpa,
+				      const struct vdpa_vq_state *state)
+{
+	const struct vdpa_vq_state_split *split = &state->split;
+
+	if (split->avail_index == 0)
+		return 0;
+
+	return -EOPNOTSUPP;
+}
+
+static int vp_vdpa_set_vq_state_packed(struct vdpa_device *vdpa,
+				       const struct vdpa_vq_state *state)
+{
+	const struct vdpa_vq_state_packed *packed = &state->packed;
+
+	if (packed->last_avail_counter == 1 &&
+	    packed->last_avail_idx == 0 &&
+	    packed->last_used_counter == 1 &&
+	    packed->last_used_idx == 0)
+		return 0;
+
+	return -EOPNOTSUPP;
+}
+
 static int vp_vdpa_set_vq_state(struct vdpa_device *vdpa, u16 qid,
 				const struct vdpa_vq_state *state)
 {
-	/* Note that this is not supported by virtio specification, so
-	 * we return -ENOPOTSUPP here. This means we can't support live
-	 * migration, vhost device start/stop.
+	struct virtio_pci_modern_device *mdev = vdpa_to_mdev(vdpa);
+
+	/* Note that this is not supported by virtio specification.
+	 * But if the state is by chance equal to the device initial
+	 * state, we can let it go.
 	 */
+	if ((vp_modern_get_status(mdev) & VIRTIO_CONFIG_S_FEATURES_OK) &&
+	    !vp_modern_get_queue_enable(mdev, qid)) {
+		if (vp_modern_get_driver_features(mdev) &
+		    BIT_ULL(VIRTIO_F_RING_PACKED))
+			return vp_vdpa_set_vq_state_packed(vdpa, state);
+		else
+			return vp_vdpa_set_vq_state_split(vdpa,	state);
+	}
+
 	return -EOPNOTSUPP;
 }
 
-- 
2.25.1

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH V2 4/4] virtio/vdpa: clear the virtqueue state during probe
  2021-06-02  2:10 ` Jason Wang
@ 2021-06-02  2:10   ` Jason Wang
  -1 siblings, 0 replies; 20+ messages in thread
From: Jason Wang @ 2021-06-02  2:10 UTC (permalink / raw)
  To: mst, jasowang, virtualization, linux-kernel, kvm, netdev; +Cc: eli, Eli Cohen

From: Eli Cohen <elic@nvidia.com>

Clear the available index as part of the initialization process to
clear and values that might be left from previous usage of the device.
For example, if the device was previously used by vhost_vdpa and now
probed by vhost_vdpa, you want to start with indices.

Fixes: c043b4a8cf3b ("virtio: introduce a vDPA based transport")
Signed-off-by: Eli Cohen <elic@nvidia.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
---
 drivers/virtio/virtio_vdpa.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/drivers/virtio/virtio_vdpa.c b/drivers/virtio/virtio_vdpa.c
index e28acf482e0c..e1a141135992 100644
--- a/drivers/virtio/virtio_vdpa.c
+++ b/drivers/virtio/virtio_vdpa.c
@@ -142,6 +142,8 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index,
 	struct vdpa_callback cb;
 	struct virtqueue *vq;
 	u64 desc_addr, driver_addr, device_addr;
+	/* Assume split virtqueue, switch to packed if necessary */
+	struct vdpa_vq_state state = {0};
 	unsigned long flags;
 	u32 align, num;
 	int err;
@@ -191,6 +193,19 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index,
 		goto err_vq;
 	}
 
+	/* reset virtqueue state index */
+	if (virtio_has_feature(vdev, VIRTIO_F_RING_PACKED)) {
+		struct vdpa_vq_state_packed *s = &state.packed;
+
+		s->last_avail_counter = 1;
+		s->last_avail_idx = 0;
+		s->last_used_counter = 1;
+		s->last_used_idx = 0;
+	}
+	err = ops->set_vq_state(vdpa, index, &state);
+	if (err)
+		goto err_vq;
+
 	ops->set_vq_ready(vdpa, index, 1);
 
 	vq->priv = info;
-- 
2.25.1


^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH V2 4/4] virtio/vdpa: clear the virtqueue state during probe
@ 2021-06-02  2:10   ` Jason Wang
  0 siblings, 0 replies; 20+ messages in thread
From: Jason Wang @ 2021-06-02  2:10 UTC (permalink / raw)
  To: mst, jasowang, virtualization, linux-kernel, kvm, netdev; +Cc: Eli Cohen, eli

From: Eli Cohen <elic@nvidia.com>

Clear the available index as part of the initialization process to
clear and values that might be left from previous usage of the device.
For example, if the device was previously used by vhost_vdpa and now
probed by vhost_vdpa, you want to start with indices.

Fixes: c043b4a8cf3b ("virtio: introduce a vDPA based transport")
Signed-off-by: Eli Cohen <elic@nvidia.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
---
 drivers/virtio/virtio_vdpa.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/drivers/virtio/virtio_vdpa.c b/drivers/virtio/virtio_vdpa.c
index e28acf482e0c..e1a141135992 100644
--- a/drivers/virtio/virtio_vdpa.c
+++ b/drivers/virtio/virtio_vdpa.c
@@ -142,6 +142,8 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index,
 	struct vdpa_callback cb;
 	struct virtqueue *vq;
 	u64 desc_addr, driver_addr, device_addr;
+	/* Assume split virtqueue, switch to packed if necessary */
+	struct vdpa_vq_state state = {0};
 	unsigned long flags;
 	u32 align, num;
 	int err;
@@ -191,6 +193,19 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index,
 		goto err_vq;
 	}
 
+	/* reset virtqueue state index */
+	if (virtio_has_feature(vdev, VIRTIO_F_RING_PACKED)) {
+		struct vdpa_vq_state_packed *s = &state.packed;
+
+		s->last_avail_counter = 1;
+		s->last_avail_idx = 0;
+		s->last_used_counter = 1;
+		s->last_used_idx = 0;
+	}
+	err = ops->set_vq_state(vdpa, index, &state);
+	if (err)
+		goto err_vq;
+
 	ops->set_vq_ready(vdpa, index, 1);
 
 	vq->priv = info;
-- 
2.25.1

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH V2 0/4]
  2021-06-02  2:10 ` Jason Wang
@ 2021-06-02  2:15   ` Jason Wang
  -1 siblings, 0 replies; 20+ messages in thread
From: Jason Wang @ 2021-06-02  2:15 UTC (permalink / raw)
  To: mst, virtualization, linux-kernel, kvm, netdev; +Cc: eli


在 2021/6/2 上午10:10, Jason Wang 写道:
> *** BLURB HERE ***


Missing blurb...

Will resend a new version.

Thanks


>
> Eli Cohen (1):
>    virtio/vdpa: clear the virtqueue state during probe
>
> Jason Wang (3):
>    vdpa: support packed virtqueue for set/get_vq_state()
>    virtio-pci library: introduce vp_modern_get_driver_features()
>    vp_vdpa: allow set vq state to initial state after reset
>
>   drivers/vdpa/ifcvf/ifcvf_main.c        |  4 +--
>   drivers/vdpa/mlx5/net/mlx5_vnet.c      |  8 ++---
>   drivers/vdpa/vdpa_sim/vdpa_sim.c       |  4 +--
>   drivers/vdpa/virtio_pci/vp_vdpa.c      | 42 ++++++++++++++++++++++++--
>   drivers/vhost/vdpa.c                   |  4 +--
>   drivers/virtio/virtio_pci_modern_dev.c | 21 +++++++++++++
>   drivers/virtio/virtio_vdpa.c           | 15 +++++++++
>   include/linux/vdpa.h                   | 25 +++++++++++++--
>   include/linux/virtio_pci_modern.h      |  1 +
>   9 files changed, 109 insertions(+), 15 deletions(-)
>


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH V2 0/4]
@ 2021-06-02  2:15   ` Jason Wang
  0 siblings, 0 replies; 20+ messages in thread
From: Jason Wang @ 2021-06-02  2:15 UTC (permalink / raw)
  To: mst, virtualization, linux-kernel, kvm, netdev; +Cc: eli


在 2021/6/2 上午10:10, Jason Wang 写道:
> *** BLURB HERE ***


Missing blurb...

Will resend a new version.

Thanks


>
> Eli Cohen (1):
>    virtio/vdpa: clear the virtqueue state during probe
>
> Jason Wang (3):
>    vdpa: support packed virtqueue for set/get_vq_state()
>    virtio-pci library: introduce vp_modern_get_driver_features()
>    vp_vdpa: allow set vq state to initial state after reset
>
>   drivers/vdpa/ifcvf/ifcvf_main.c        |  4 +--
>   drivers/vdpa/mlx5/net/mlx5_vnet.c      |  8 ++---
>   drivers/vdpa/vdpa_sim/vdpa_sim.c       |  4 +--
>   drivers/vdpa/virtio_pci/vp_vdpa.c      | 42 ++++++++++++++++++++++++--
>   drivers/vhost/vdpa.c                   |  4 +--
>   drivers/virtio/virtio_pci_modern_dev.c | 21 +++++++++++++
>   drivers/virtio/virtio_vdpa.c           | 15 +++++++++
>   include/linux/vdpa.h                   | 25 +++++++++++++--
>   include/linux/virtio_pci_modern.h      |  1 +
>   9 files changed, 109 insertions(+), 15 deletions(-)
>

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH V2 3/4] vp_vdpa: allow set vq state to initial state after reset
  2021-06-02  2:10   ` Jason Wang
  (?)
@ 2021-06-02  6:13   ` Eli Cohen
  2021-06-02  7:05       ` Jason Wang
  -1 siblings, 1 reply; 20+ messages in thread
From: Eli Cohen @ 2021-06-02  6:13 UTC (permalink / raw)
  To: Jason Wang; +Cc: mst, virtualization, linux-kernel, kvm, netdev, eli

On Wed, Jun 02, 2021 at 10:10:42AM +0800, Jason Wang wrote:
> We used to fail the set_vq_state() since it was not supported yet by
> the virtio spec. But if the bus tries to set the state which is equal
> to the device initial state after reset, we can let it go.
> 
> This is a must for virtio_vdpa() to set vq state during probe which is
> required for some vDPA parents.
> 
> Signed-off-by: Jason Wang <jasowang@redhat.com>
> ---
>  drivers/vdpa/virtio_pci/vp_vdpa.c | 42 ++++++++++++++++++++++++++++---
>  1 file changed, 39 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/vdpa/virtio_pci/vp_vdpa.c b/drivers/vdpa/virtio_pci/vp_vdpa.c
> index c76ebb531212..18bf4a422772 100644
> --- a/drivers/vdpa/virtio_pci/vp_vdpa.c
> +++ b/drivers/vdpa/virtio_pci/vp_vdpa.c
> @@ -210,13 +210,49 @@ static int vp_vdpa_get_vq_state(struct vdpa_device *vdpa, u16 qid,
>  	return -EOPNOTSUPP;
>  }
>  
> +static int vp_vdpa_set_vq_state_split(struct vdpa_device *vdpa,
> +				      const struct vdpa_vq_state *state)
> +{
> +	const struct vdpa_vq_state_split *split = &state->split;
> +
> +	if (split->avail_index == 0)
> +		return 0;
> +
> +	return -EOPNOTSUPP;
> +}
> +
> +static int vp_vdpa_set_vq_state_packed(struct vdpa_device *vdpa,
> +				       const struct vdpa_vq_state *state)
> +{
> +	const struct vdpa_vq_state_packed *packed = &state->packed;
> +
> +	if (packed->last_avail_counter == 1 &&
Can you elaborate on the requirement on last_avail_counter and
last_used_counter?

> +	    packed->last_avail_idx == 0 &&
> +	    packed->last_used_counter == 1 &&
> +	    packed->last_used_idx == 0)
> +		return 0;
> +
> +	return -EOPNOTSUPP;
> +}
> +
>  static int vp_vdpa_set_vq_state(struct vdpa_device *vdpa, u16 qid,
>  				const struct vdpa_vq_state *state)
>  {
> -	/* Note that this is not supported by virtio specification, so
> -	 * we return -ENOPOTSUPP here. This means we can't support live
> -	 * migration, vhost device start/stop.
> +	struct virtio_pci_modern_device *mdev = vdpa_to_mdev(vdpa);
> +
> +	/* Note that this is not supported by virtio specification.
> +	 * But if the state is by chance equal to the device initial
> +	 * state, we can let it go.
>  	 */
> +	if ((vp_modern_get_status(mdev) & VIRTIO_CONFIG_S_FEATURES_OK) &&
> +	    !vp_modern_get_queue_enable(mdev, qid)) {
> +		if (vp_modern_get_driver_features(mdev) &
> +		    BIT_ULL(VIRTIO_F_RING_PACKED))
> +			return vp_vdpa_set_vq_state_packed(vdpa, state);
> +		else
> +			return vp_vdpa_set_vq_state_split(vdpa,	state);
> +	}
> +
>  	return -EOPNOTSUPP;
>  }
>  
> -- 
> 2.25.1
> 

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH V2 4/4] virtio/vdpa: clear the virtqueue state during probe
  2021-06-02  2:10   ` Jason Wang
  (?)
@ 2021-06-02  6:17   ` Eli Cohen
  2021-06-02  7:07       ` Jason Wang
  -1 siblings, 1 reply; 20+ messages in thread
From: Eli Cohen @ 2021-06-02  6:17 UTC (permalink / raw)
  To: Jason Wang; +Cc: mst, virtualization, linux-kernel, kvm, netdev, eli

On Wed, Jun 02, 2021 at 10:10:43AM +0800, Jason Wang wrote:
> From: Eli Cohen <elic@nvidia.com>
> 
> Clear the available index as part of the initialization process to
> clear and values that might be left from previous usage of the device.
> For example, if the device was previously used by vhost_vdpa and now
> probed by vhost_vdpa, you want to start with indices.
> 
> Fixes: c043b4a8cf3b ("virtio: introduce a vDPA based transport")
> Signed-off-by: Eli Cohen <elic@nvidia.com>
> Signed-off-by: Jason Wang <jasowang@redhat.com>
> ---
>  drivers/virtio/virtio_vdpa.c | 15 +++++++++++++++
>  1 file changed, 15 insertions(+)
> 
> diff --git a/drivers/virtio/virtio_vdpa.c b/drivers/virtio/virtio_vdpa.c
> index e28acf482e0c..e1a141135992 100644
> --- a/drivers/virtio/virtio_vdpa.c
> +++ b/drivers/virtio/virtio_vdpa.c
> @@ -142,6 +142,8 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index,
>  	struct vdpa_callback cb;
>  	struct virtqueue *vq;
>  	u64 desc_addr, driver_addr, device_addr;
> +	/* Assume split virtqueue, switch to packed if necessary */
> +	struct vdpa_vq_state state = {0};
>  	unsigned long flags;
>  	u32 align, num;
>  	int err;
> @@ -191,6 +193,19 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index,
>  		goto err_vq;
>  	}
>  
> +	/* reset virtqueue state index */
> +	if (virtio_has_feature(vdev, VIRTIO_F_RING_PACKED)) {
> +		struct vdpa_vq_state_packed *s = &state.packed;
> +
> +		s->last_avail_counter = 1;
> +		s->last_avail_idx = 0;

It's already 0

> +		s->last_used_counter = 1;
> +		s->last_used_idx = 0;

already 0

> +	}
> +	err = ops->set_vq_state(vdpa, index, &state);
> +	if (err)
> +		goto err_vq;
> +
>  	ops->set_vq_ready(vdpa, index, 1);
>  
>  	vq->priv = info;
> -- 
> 2.25.1
> 

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH V2 3/4] vp_vdpa: allow set vq state to initial state after reset
  2021-06-02  6:13   ` Eli Cohen
@ 2021-06-02  7:05       ` Jason Wang
  0 siblings, 0 replies; 20+ messages in thread
From: Jason Wang @ 2021-06-02  7:05 UTC (permalink / raw)
  To: Eli Cohen; +Cc: mst, virtualization, linux-kernel, kvm, netdev, eli


在 2021/6/2 下午2:13, Eli Cohen 写道:
> On Wed, Jun 02, 2021 at 10:10:42AM +0800, Jason Wang wrote:
>> We used to fail the set_vq_state() since it was not supported yet by
>> the virtio spec. But if the bus tries to set the state which is equal
>> to the device initial state after reset, we can let it go.
>>
>> This is a must for virtio_vdpa() to set vq state during probe which is
>> required for some vDPA parents.
>>
>> Signed-off-by: Jason Wang <jasowang@redhat.com>
>> ---
>>   drivers/vdpa/virtio_pci/vp_vdpa.c | 42 ++++++++++++++++++++++++++++---
>>   1 file changed, 39 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/vdpa/virtio_pci/vp_vdpa.c b/drivers/vdpa/virtio_pci/vp_vdpa.c
>> index c76ebb531212..18bf4a422772 100644
>> --- a/drivers/vdpa/virtio_pci/vp_vdpa.c
>> +++ b/drivers/vdpa/virtio_pci/vp_vdpa.c
>> @@ -210,13 +210,49 @@ static int vp_vdpa_get_vq_state(struct vdpa_device *vdpa, u16 qid,
>>   	return -EOPNOTSUPP;
>>   }
>>   
>> +static int vp_vdpa_set_vq_state_split(struct vdpa_device *vdpa,
>> +				      const struct vdpa_vq_state *state)
>> +{
>> +	const struct vdpa_vq_state_split *split = &state->split;
>> +
>> +	if (split->avail_index == 0)
>> +		return 0;
>> +
>> +	return -EOPNOTSUPP;
>> +}
>> +
>> +static int vp_vdpa_set_vq_state_packed(struct vdpa_device *vdpa,
>> +				       const struct vdpa_vq_state *state)
>> +{
>> +	const struct vdpa_vq_state_packed *packed = &state->packed;
>> +
>> +	if (packed->last_avail_counter == 1 &&
> Can you elaborate on the requirement on last_avail_counter and
> last_used_counter?


This is required by the virtio spec:

"
2.7.1 Driver and Device Ring Wrap Counters
Each of the driver and the device are expected to maintain, internally, 
a single-bit ring wrap counter initialized to 1.
"

For virtio-pci device, since there's no way to assign the value of those 
counters, the counters will be reset to 1 after reset, otherwise the 
driver can't work.

Thanks


>
>> +	    packed->last_avail_idx == 0 &&
>> +	    packed->last_used_counter == 1 &&
>> +	    packed->last_used_idx == 0)
>> +		return 0;
>> +
>> +	return -EOPNOTSUPP;
>> +}
>> +
>>   static int vp_vdpa_set_vq_state(struct vdpa_device *vdpa, u16 qid,
>>   				const struct vdpa_vq_state *state)
>>   {
>> -	/* Note that this is not supported by virtio specification, so
>> -	 * we return -ENOPOTSUPP here. This means we can't support live
>> -	 * migration, vhost device start/stop.
>> +	struct virtio_pci_modern_device *mdev = vdpa_to_mdev(vdpa);
>> +
>> +	/* Note that this is not supported by virtio specification.
>> +	 * But if the state is by chance equal to the device initial
>> +	 * state, we can let it go.
>>   	 */
>> +	if ((vp_modern_get_status(mdev) & VIRTIO_CONFIG_S_FEATURES_OK) &&
>> +	    !vp_modern_get_queue_enable(mdev, qid)) {
>> +		if (vp_modern_get_driver_features(mdev) &
>> +		    BIT_ULL(VIRTIO_F_RING_PACKED))
>> +			return vp_vdpa_set_vq_state_packed(vdpa, state);
>> +		else
>> +			return vp_vdpa_set_vq_state_split(vdpa,	state);
>> +	}
>> +
>>   	return -EOPNOTSUPP;
>>   }
>>   
>> -- 
>> 2.25.1
>>


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH V2 3/4] vp_vdpa: allow set vq state to initial state after reset
@ 2021-06-02  7:05       ` Jason Wang
  0 siblings, 0 replies; 20+ messages in thread
From: Jason Wang @ 2021-06-02  7:05 UTC (permalink / raw)
  To: Eli Cohen; +Cc: kvm, mst, netdev, linux-kernel, virtualization, eli


在 2021/6/2 下午2:13, Eli Cohen 写道:
> On Wed, Jun 02, 2021 at 10:10:42AM +0800, Jason Wang wrote:
>> We used to fail the set_vq_state() since it was not supported yet by
>> the virtio spec. But if the bus tries to set the state which is equal
>> to the device initial state after reset, we can let it go.
>>
>> This is a must for virtio_vdpa() to set vq state during probe which is
>> required for some vDPA parents.
>>
>> Signed-off-by: Jason Wang <jasowang@redhat.com>
>> ---
>>   drivers/vdpa/virtio_pci/vp_vdpa.c | 42 ++++++++++++++++++++++++++++---
>>   1 file changed, 39 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/vdpa/virtio_pci/vp_vdpa.c b/drivers/vdpa/virtio_pci/vp_vdpa.c
>> index c76ebb531212..18bf4a422772 100644
>> --- a/drivers/vdpa/virtio_pci/vp_vdpa.c
>> +++ b/drivers/vdpa/virtio_pci/vp_vdpa.c
>> @@ -210,13 +210,49 @@ static int vp_vdpa_get_vq_state(struct vdpa_device *vdpa, u16 qid,
>>   	return -EOPNOTSUPP;
>>   }
>>   
>> +static int vp_vdpa_set_vq_state_split(struct vdpa_device *vdpa,
>> +				      const struct vdpa_vq_state *state)
>> +{
>> +	const struct vdpa_vq_state_split *split = &state->split;
>> +
>> +	if (split->avail_index == 0)
>> +		return 0;
>> +
>> +	return -EOPNOTSUPP;
>> +}
>> +
>> +static int vp_vdpa_set_vq_state_packed(struct vdpa_device *vdpa,
>> +				       const struct vdpa_vq_state *state)
>> +{
>> +	const struct vdpa_vq_state_packed *packed = &state->packed;
>> +
>> +	if (packed->last_avail_counter == 1 &&
> Can you elaborate on the requirement on last_avail_counter and
> last_used_counter?


This is required by the virtio spec:

"
2.7.1 Driver and Device Ring Wrap Counters
Each of the driver and the device are expected to maintain, internally, 
a single-bit ring wrap counter initialized to 1.
"

For virtio-pci device, since there's no way to assign the value of those 
counters, the counters will be reset to 1 after reset, otherwise the 
driver can't work.

Thanks


>
>> +	    packed->last_avail_idx == 0 &&
>> +	    packed->last_used_counter == 1 &&
>> +	    packed->last_used_idx == 0)
>> +		return 0;
>> +
>> +	return -EOPNOTSUPP;
>> +}
>> +
>>   static int vp_vdpa_set_vq_state(struct vdpa_device *vdpa, u16 qid,
>>   				const struct vdpa_vq_state *state)
>>   {
>> -	/* Note that this is not supported by virtio specification, so
>> -	 * we return -ENOPOTSUPP here. This means we can't support live
>> -	 * migration, vhost device start/stop.
>> +	struct virtio_pci_modern_device *mdev = vdpa_to_mdev(vdpa);
>> +
>> +	/* Note that this is not supported by virtio specification.
>> +	 * But if the state is by chance equal to the device initial
>> +	 * state, we can let it go.
>>   	 */
>> +	if ((vp_modern_get_status(mdev) & VIRTIO_CONFIG_S_FEATURES_OK) &&
>> +	    !vp_modern_get_queue_enable(mdev, qid)) {
>> +		if (vp_modern_get_driver_features(mdev) &
>> +		    BIT_ULL(VIRTIO_F_RING_PACKED))
>> +			return vp_vdpa_set_vq_state_packed(vdpa, state);
>> +		else
>> +			return vp_vdpa_set_vq_state_split(vdpa,	state);
>> +	}
>> +
>>   	return -EOPNOTSUPP;
>>   }
>>   
>> -- 
>> 2.25.1
>>

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH V2 4/4] virtio/vdpa: clear the virtqueue state during probe
  2021-06-02  6:17   ` Eli Cohen
@ 2021-06-02  7:07       ` Jason Wang
  0 siblings, 0 replies; 20+ messages in thread
From: Jason Wang @ 2021-06-02  7:07 UTC (permalink / raw)
  To: Eli Cohen; +Cc: mst, virtualization, linux-kernel, kvm, netdev, eli


在 2021/6/2 下午2:17, Eli Cohen 写道:
> On Wed, Jun 02, 2021 at 10:10:43AM +0800, Jason Wang wrote:
>> From: Eli Cohen <elic@nvidia.com>
>>
>> Clear the available index as part of the initialization process to
>> clear and values that might be left from previous usage of the device.
>> For example, if the device was previously used by vhost_vdpa and now
>> probed by vhost_vdpa, you want to start with indices.
>>
>> Fixes: c043b4a8cf3b ("virtio: introduce a vDPA based transport")
>> Signed-off-by: Eli Cohen <elic@nvidia.com>
>> Signed-off-by: Jason Wang <jasowang@redhat.com>
>> ---
>>   drivers/virtio/virtio_vdpa.c | 15 +++++++++++++++
>>   1 file changed, 15 insertions(+)
>>
>> diff --git a/drivers/virtio/virtio_vdpa.c b/drivers/virtio/virtio_vdpa.c
>> index e28acf482e0c..e1a141135992 100644
>> --- a/drivers/virtio/virtio_vdpa.c
>> +++ b/drivers/virtio/virtio_vdpa.c
>> @@ -142,6 +142,8 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index,
>>   	struct vdpa_callback cb;
>>   	struct virtqueue *vq;
>>   	u64 desc_addr, driver_addr, device_addr;
>> +	/* Assume split virtqueue, switch to packed if necessary */
>> +	struct vdpa_vq_state state = {0};
>>   	unsigned long flags;
>>   	u32 align, num;
>>   	int err;
>> @@ -191,6 +193,19 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index,
>>   		goto err_vq;
>>   	}
>>   
>> +	/* reset virtqueue state index */
>> +	if (virtio_has_feature(vdev, VIRTIO_F_RING_PACKED)) {
>> +		struct vdpa_vq_state_packed *s = &state.packed;
>> +
>> +		s->last_avail_counter = 1;
>> +		s->last_avail_idx = 0;
> It's already 0
>
>> +		s->last_used_counter = 1;
>> +		s->last_used_idx = 0;
> already 0


Yes, but for completeness and make code easy to read, it's no harm to 
keep them I think.

Thanks


>
>> +	}
>> +	err = ops->set_vq_state(vdpa, index, &state);
>> +	if (err)
>> +		goto err_vq;
>> +
>>   	ops->set_vq_ready(vdpa, index, 1);
>>   
>>   	vq->priv = info;
>> -- 
>> 2.25.1
>>


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH V2 4/4] virtio/vdpa: clear the virtqueue state during probe
@ 2021-06-02  7:07       ` Jason Wang
  0 siblings, 0 replies; 20+ messages in thread
From: Jason Wang @ 2021-06-02  7:07 UTC (permalink / raw)
  To: Eli Cohen; +Cc: kvm, mst, netdev, linux-kernel, virtualization, eli


在 2021/6/2 下午2:17, Eli Cohen 写道:
> On Wed, Jun 02, 2021 at 10:10:43AM +0800, Jason Wang wrote:
>> From: Eli Cohen <elic@nvidia.com>
>>
>> Clear the available index as part of the initialization process to
>> clear and values that might be left from previous usage of the device.
>> For example, if the device was previously used by vhost_vdpa and now
>> probed by vhost_vdpa, you want to start with indices.
>>
>> Fixes: c043b4a8cf3b ("virtio: introduce a vDPA based transport")
>> Signed-off-by: Eli Cohen <elic@nvidia.com>
>> Signed-off-by: Jason Wang <jasowang@redhat.com>
>> ---
>>   drivers/virtio/virtio_vdpa.c | 15 +++++++++++++++
>>   1 file changed, 15 insertions(+)
>>
>> diff --git a/drivers/virtio/virtio_vdpa.c b/drivers/virtio/virtio_vdpa.c
>> index e28acf482e0c..e1a141135992 100644
>> --- a/drivers/virtio/virtio_vdpa.c
>> +++ b/drivers/virtio/virtio_vdpa.c
>> @@ -142,6 +142,8 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index,
>>   	struct vdpa_callback cb;
>>   	struct virtqueue *vq;
>>   	u64 desc_addr, driver_addr, device_addr;
>> +	/* Assume split virtqueue, switch to packed if necessary */
>> +	struct vdpa_vq_state state = {0};
>>   	unsigned long flags;
>>   	u32 align, num;
>>   	int err;
>> @@ -191,6 +193,19 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index,
>>   		goto err_vq;
>>   	}
>>   
>> +	/* reset virtqueue state index */
>> +	if (virtio_has_feature(vdev, VIRTIO_F_RING_PACKED)) {
>> +		struct vdpa_vq_state_packed *s = &state.packed;
>> +
>> +		s->last_avail_counter = 1;
>> +		s->last_avail_idx = 0;
> It's already 0
>
>> +		s->last_used_counter = 1;
>> +		s->last_used_idx = 0;
> already 0


Yes, but for completeness and make code easy to read, it's no harm to 
keep them I think.

Thanks


>
>> +	}
>> +	err = ops->set_vq_state(vdpa, index, &state);
>> +	if (err)
>> +		goto err_vq;
>> +
>>   	ops->set_vq_ready(vdpa, index, 1);
>>   
>>   	vq->priv = info;
>> -- 
>> 2.25.1
>>

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH V2 3/4] vp_vdpa: allow set vq state to initial state after reset
  2021-06-02  7:05       ` Jason Wang
  (?)
@ 2021-06-02  7:42       ` Eli Cohen
  -1 siblings, 0 replies; 20+ messages in thread
From: Eli Cohen @ 2021-06-02  7:42 UTC (permalink / raw)
  To: Jason Wang; +Cc: mst, virtualization, linux-kernel, kvm, netdev, eli

On Wed, Jun 02, 2021 at 03:05:35PM +0800, Jason Wang wrote:
> 
> 在 2021/6/2 下午2:13, Eli Cohen 写道:
> > On Wed, Jun 02, 2021 at 10:10:42AM +0800, Jason Wang wrote:
> > > We used to fail the set_vq_state() since it was not supported yet by
> > > the virtio spec. But if the bus tries to set the state which is equal
> > > to the device initial state after reset, we can let it go.
> > > 
> > > This is a must for virtio_vdpa() to set vq state during probe which is
> > > required for some vDPA parents.
> > > 
> > > Signed-off-by: Jason Wang <jasowang@redhat.com>
> > > ---
> > >   drivers/vdpa/virtio_pci/vp_vdpa.c | 42 ++++++++++++++++++++++++++++---
> > >   1 file changed, 39 insertions(+), 3 deletions(-)
> > > 
> > > diff --git a/drivers/vdpa/virtio_pci/vp_vdpa.c b/drivers/vdpa/virtio_pci/vp_vdpa.c
> > > index c76ebb531212..18bf4a422772 100644
> > > --- a/drivers/vdpa/virtio_pci/vp_vdpa.c
> > > +++ b/drivers/vdpa/virtio_pci/vp_vdpa.c
> > > @@ -210,13 +210,49 @@ static int vp_vdpa_get_vq_state(struct vdpa_device *vdpa, u16 qid,
> > >   	return -EOPNOTSUPP;
> > >   }
> > > +static int vp_vdpa_set_vq_state_split(struct vdpa_device *vdpa,
> > > +				      const struct vdpa_vq_state *state)
> > > +{
> > > +	const struct vdpa_vq_state_split *split = &state->split;
> > > +
> > > +	if (split->avail_index == 0)
> > > +		return 0;
> > > +
> > > +	return -EOPNOTSUPP;
> > > +}
> > > +
> > > +static int vp_vdpa_set_vq_state_packed(struct vdpa_device *vdpa,
> > > +				       const struct vdpa_vq_state *state)
> > > +{
> > > +	const struct vdpa_vq_state_packed *packed = &state->packed;
> > > +
> > > +	if (packed->last_avail_counter == 1 &&
> > Can you elaborate on the requirement on last_avail_counter and
> > last_used_counter?
> 
> 
> This is required by the virtio spec:
> 
> "
> 2.7.1 Driver and Device Ring Wrap Counters
> Each of the driver and the device are expected to maintain, internally, a
> single-bit ring wrap counter initialized to 1.
> "
> 
> For virtio-pci device, since there's no way to assign the value of those
> counters, the counters will be reset to 1 after reset, otherwise the driver
> can't work.

I see, thanks for the explanation.

> 
> Thanks
> 
> 
> > 
> > > +	    packed->last_avail_idx == 0 &&
> > > +	    packed->last_used_counter == 1 &&
> > > +	    packed->last_used_idx == 0)
> > > +		return 0;
> > > +
> > > +	return -EOPNOTSUPP;
> > > +}
> > > +
> > >   static int vp_vdpa_set_vq_state(struct vdpa_device *vdpa, u16 qid,
> > >   				const struct vdpa_vq_state *state)
> > >   {
> > > -	/* Note that this is not supported by virtio specification, so
> > > -	 * we return -ENOPOTSUPP here. This means we can't support live
> > > -	 * migration, vhost device start/stop.
> > > +	struct virtio_pci_modern_device *mdev = vdpa_to_mdev(vdpa);
> > > +
> > > +	/* Note that this is not supported by virtio specification.
> > > +	 * But if the state is by chance equal to the device initial
> > > +	 * state, we can let it go.
> > >   	 */
> > > +	if ((vp_modern_get_status(mdev) & VIRTIO_CONFIG_S_FEATURES_OK) &&
> > > +	    !vp_modern_get_queue_enable(mdev, qid)) {
> > > +		if (vp_modern_get_driver_features(mdev) &
> > > +		    BIT_ULL(VIRTIO_F_RING_PACKED))
> > > +			return vp_vdpa_set_vq_state_packed(vdpa, state);
> > > +		else
> > > +			return vp_vdpa_set_vq_state_split(vdpa,	state);
> > > +	}
> > > +
> > >   	return -EOPNOTSUPP;
> > >   }
> > > -- 
> > > 2.25.1
> > > 
> 

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH V2 4/4] virtio/vdpa: clear the virtqueue state during probe
  2021-06-02  7:07       ` Jason Wang
  (?)
@ 2021-06-02  7:43       ` Eli Cohen
  -1 siblings, 0 replies; 20+ messages in thread
From: Eli Cohen @ 2021-06-02  7:43 UTC (permalink / raw)
  To: Jason Wang; +Cc: mst, virtualization, linux-kernel, kvm, netdev, eli

On Wed, Jun 02, 2021 at 03:07:00PM +0800, Jason Wang wrote:
> 
> 在 2021/6/2 下午2:17, Eli Cohen 写道:
> > On Wed, Jun 02, 2021 at 10:10:43AM +0800, Jason Wang wrote:
> > > From: Eli Cohen <elic@nvidia.com>
> > > 
> > > Clear the available index as part of the initialization process to
> > > clear and values that might be left from previous usage of the device.
> > > For example, if the device was previously used by vhost_vdpa and now
> > > probed by vhost_vdpa, you want to start with indices.
> > > 
> > > Fixes: c043b4a8cf3b ("virtio: introduce a vDPA based transport")
> > > Signed-off-by: Eli Cohen <elic@nvidia.com>
> > > Signed-off-by: Jason Wang <jasowang@redhat.com>
> > > ---
> > >   drivers/virtio/virtio_vdpa.c | 15 +++++++++++++++
> > >   1 file changed, 15 insertions(+)
> > > 
> > > diff --git a/drivers/virtio/virtio_vdpa.c b/drivers/virtio/virtio_vdpa.c
> > > index e28acf482e0c..e1a141135992 100644
> > > --- a/drivers/virtio/virtio_vdpa.c
> > > +++ b/drivers/virtio/virtio_vdpa.c
> > > @@ -142,6 +142,8 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index,
> > >   	struct vdpa_callback cb;
> > >   	struct virtqueue *vq;
> > >   	u64 desc_addr, driver_addr, device_addr;
> > > +	/* Assume split virtqueue, switch to packed if necessary */
> > > +	struct vdpa_vq_state state = {0};
> > >   	unsigned long flags;
> > >   	u32 align, num;
> > >   	int err;
> > > @@ -191,6 +193,19 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index,
> > >   		goto err_vq;
> > >   	}
> > > +	/* reset virtqueue state index */
> > > +	if (virtio_has_feature(vdev, VIRTIO_F_RING_PACKED)) {
> > > +		struct vdpa_vq_state_packed *s = &state.packed;
> > > +
> > > +		s->last_avail_counter = 1;
> > > +		s->last_avail_idx = 0;
> > It's already 0
> > 
> > > +		s->last_used_counter = 1;
> > > +		s->last_used_idx = 0;
> > already 0
> 
> 
> Yes, but for completeness and make code easy to read, it's no harm to keep
> them I think.
> 

OK.

> Thanks
> 
> 
> > 
> > > +	}
> > > +	err = ops->set_vq_state(vdpa, index, &state);
> > > +	if (err)
> > > +		goto err_vq;
> > > +
> > >   	ops->set_vq_ready(vdpa, index, 1);
> > >   	vq->priv = info;
> > > -- 
> > > 2.25.1
> > > 
> 

^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2021-06-02  7:43 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-02  2:10 [PATCH V2 0/4] Jason Wang
2021-06-02  2:10 ` Jason Wang
2021-06-02  2:10 ` [PATCH V2 1/4] vdpa: support packed virtqueue for set/get_vq_state() Jason Wang
2021-06-02  2:10   ` Jason Wang
2021-06-02  2:10 ` [PATCH V2 2/4] virtio-pci library: introduce vp_modern_get_driver_features() Jason Wang
2021-06-02  2:10   ` Jason Wang
2021-06-02  2:10 ` [PATCH V2 3/4] vp_vdpa: allow set vq state to initial state after reset Jason Wang
2021-06-02  2:10   ` Jason Wang
2021-06-02  6:13   ` Eli Cohen
2021-06-02  7:05     ` Jason Wang
2021-06-02  7:05       ` Jason Wang
2021-06-02  7:42       ` Eli Cohen
2021-06-02  2:10 ` [PATCH V2 4/4] virtio/vdpa: clear the virtqueue state during probe Jason Wang
2021-06-02  2:10   ` Jason Wang
2021-06-02  6:17   ` Eli Cohen
2021-06-02  7:07     ` Jason Wang
2021-06-02  7:07       ` Jason Wang
2021-06-02  7:43       ` Eli Cohen
2021-06-02  2:15 ` [PATCH V2 0/4] Jason Wang
2021-06-02  2:15   ` Jason Wang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.