Skip to contentSkip to conversation

[PATCH V2 0/4]

PATCH Superseded Jason Wang 2 participants 12 messages Jun 2, 2021

Subsystems (7)
lore
Share & tools
lore

Jason Wang

author
#0 lore raw

v2 cover [PATCH V2 0/4]

*** 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(-)
Signature · 1 line
2.25.1
author
#1 lore raw

PATCH v2 1/4 vdpa: support packed virtqueue for set/get_vq_state()

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.

---
 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(-)
drivers/vdpa/ifcvf/ifcvf_main.c +2 -2
index ab0ab5cf0f6e..5d3891b1ca28 100644
@@ -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,
drivers/vdpa/mlx5/net/mlx5_vnet.c +4 -4
index 189e4385df40..e5505d760bca 100644
@@ -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;
 }
 
drivers/vdpa/vdpa_sim/vdpa_sim.c +2 -2
index 98f793bc9376..14e024de5cbf 100644
@@ -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;
 }
 
drivers/vhost/vdpa.c +2 -2
index fb41db3da611..210ab35a7ebf 100644
@@ -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;
include/linux/vdpa.h +23 -2
index f311d227aa1b..3357ac98878d 100644
@@ -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;
 
 /**
Signature · 1 line
2.25.1
author
#2 lore raw

PATCH v2 2/4 virtio-pci library: introduce vp_modern_get_driver_features()

In reply to Jason Wang

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

---
 drivers/virtio/virtio_pci_modern_dev.c | 21 +++++++++++++++++++++
 include/linux/virtio_pci_modern.h      |  1 +
 2 files changed, 22 insertions(+)
drivers/virtio/virtio_pci_modern_dev.c +21 -0
index 54f297028586..e11ed748e661 100644
@@ -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
include/linux/virtio_pci_modern.h +1 -0
index 6a95b58fd0f4..eb2bd9b4077d 100644
@@ -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);
Signature · 1 line
2.25.1
author
#3 lore raw

PATCH v2 3/4 vp_vdpa: allow set vq state to initial state after reset

In reply to Jason Wang

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.

---
 drivers/vdpa/virtio_pci/vp_vdpa.c | 42 ++++++++++++++++++++++++++++---
 1 file changed, 39 insertions(+), 3 deletions(-)
drivers/vdpa/virtio_pci/vp_vdpa.c +39 -3
index c76ebb531212..18bf4a422772 100644
@@ -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;
 }
 
Signature · 6 lines
2.25.1

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
#4 lore raw

Re: [PATCH V2 3/4] vp_vdpa: allow set vq state to initial state after reset

Quoted 27 lines · Jason Wang

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.

---
 drivers/vdpa/virtio_pci/vp_vdpa.c | 42 ++++++++++++++++++++++++++++---
 1 file changed, 39 insertions(+), 3 deletions(-)
drivers/vdpa/virtio_pci/vp_vdpa.c +7 -0
index c76ebb531212..18bf4a422772 100644
@@ -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;

drivers/vdpa/virtio_pci/vp_vdpa.c static int vp_vdpa_get_vq_state(struct vdpa_device *vdpa, u16 qid, · line 229

Quoted 10 lines
drivers/vdpa/virtio_pci/vp_vdpa.c +10 -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?

Quoted 35 lines
drivers/vdpa/virtio_pci/vp_vdpa.c +22 -3
+	    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;
 }
 
Signature · 1 line
2.25.1
author
#5 lore raw

Re: [PATCH V2 3/4] vp_vdpa: allow set vq state to initial state after reset

Quoted 32 lines · Eli Cohen
Quoted 31 lines · Jason Wang

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.

---
  drivers/vdpa/virtio_pci/vp_vdpa.c | 42 ++++++++++++++++++++++++++++---
  1 file changed, 39 insertions(+), 3 deletions(-)
drivers/vdpa/virtio_pci/vp_vdpa.c +11 -0
index c76ebb531212..18bf4a422772 100644
@@ -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;
+}
+
Quoted 8 lines

drivers/vdpa/virtio_pci/vp_vdpa.c static int vp_vdpa_get_vq_state(struct vdpa_device *vdpa, u16 qid, · line 229

Quoted 6 lines
drivers/vdpa/virtio_pci/vp_vdpa.c +6 -0
+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

Quoted 36 lines
Quoted 36 lines
drivers/vdpa/virtio_pci/vp_vdpa.c +22 -3
+	    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;
  }
 
Signature · 1 line
2.25.1
#6 lore raw

Re: [PATCH V2 3/4] vp_vdpa: allow set vq state to initial state after reset

Quoted 51 lines · Jason Wang
Quoted 31 lines · Eli Cohen
Quoted 30 lines · Jason Wang

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.

---
  drivers/vdpa/virtio_pci/vp_vdpa.c | 42 ++++++++++++++++++++++++++++---
  1 file changed, 39 insertions(+), 3 deletions(-)
drivers/vdpa/virtio_pci/vp_vdpa.c +11 -0
index c76ebb531212..18bf4a422772 100644
@@ -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;
+}
+
Quoted 8 lines

drivers/vdpa/virtio_pci/vp_vdpa.c static int vp_vdpa_get_vq_state(struct vdpa_device *vdpa, u16 qid, · line 229

Quoted 6 lines
drivers/vdpa/virtio_pci/vp_vdpa.c +6 -0
+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.
"

Quoted 3 lines

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.

Quoted 40 lines

Thanks

Quoted 35 lines
Quoted 35 lines
drivers/vdpa/virtio_pci/vp_vdpa.c +22 -3
+	    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;
  }
Signature · 1 line
2.25.1
author
#7 lore raw

PATCH v2 4/4 virtio/vdpa: clear the virtqueue state during probe

In reply to Jason Wang

From: Eli Cohen <[email protected]>

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")
---
 drivers/virtio/virtio_vdpa.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
drivers/virtio/virtio_vdpa.c +15 -0
index e28acf482e0c..e1a141135992 100644
@@ -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;
Signature · 6 lines
2.25.1

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
#8 lore raw

Re: [PATCH V2 4/4] virtio/vdpa: clear the virtqueue state during probe

Quoted 28 lines · Jason Wang

From: Eli Cohen <[email protected]>

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")
---
 drivers/virtio/virtio_vdpa.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
drivers/virtio/virtio_vdpa.c +2 -0
index e28acf482e0c..e1a141135992 100644
@@ -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;

drivers/virtio/virtio_vdpa.c virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index, · line 201

Quoted 9 lines
drivers/virtio/virtio_vdpa.c +6 -0
@@ -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

drivers/virtio/virtio_vdpa.c virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index, · line 203

Quoted 2 lines
drivers/virtio/virtio_vdpa.c +2 -0
+		s->last_used_counter = 1;
+		s->last_used_idx = 0;

already 0

Quoted 11 lines
drivers/virtio/virtio_vdpa.c +5 -0
+	}
+	err = ops->set_vq_state(vdpa, index, &state);
+	if (err)
+		goto err_vq;
+
 	ops->set_vq_ready(vdpa, index, 1);
 
 	vq->priv = info;
Signature · 1 line
2.25.1
author
#9 lore raw

Re: [PATCH V2 4/4] virtio/vdpa: clear the virtqueue state during probe

Quoted 40 lines · Eli Cohen
Quoted 28 lines · Jason Wang

From: Eli Cohen <[email protected]>

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")
---
  drivers/virtio/virtio_vdpa.c | 15 +++++++++++++++
  1 file changed, 15 insertions(+)
drivers/virtio/virtio_vdpa.c +2 -0
index e28acf482e0c..e1a141135992 100644
@@ -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;

drivers/virtio/virtio_vdpa.c virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index, · line 201

Quoted 9 lines
drivers/virtio/virtio_vdpa.c +6 -0
@@ -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

Quoted 3 lines

drivers/virtio/virtio_vdpa.c virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index, · line 203

Quoted 2 lines
drivers/virtio/virtio_vdpa.c +2 -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

Quoted 12 lines
Quoted 12 lines
drivers/virtio/virtio_vdpa.c +5 -0
+	}
+	err = ops->set_vq_state(vdpa, index, &state);
+	if (err)
+		goto err_vq;
+
  	ops->set_vq_ready(vdpa, index, 1);
 
  	vq->priv = info;
Signature · 1 line
2.25.1
#10 lore raw

Re: [PATCH V2 4/4] virtio/vdpa: clear the virtqueue state during probe

Quoted 41 lines · Jason Wang
Quoted 39 lines · Eli Cohen
Quoted 28 lines · Jason Wang

From: Eli Cohen <[email protected]>

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")
---
  drivers/virtio/virtio_vdpa.c | 15 +++++++++++++++
  1 file changed, 15 insertions(+)
drivers/virtio/virtio_vdpa.c +2 -0
index e28acf482e0c..e1a141135992 100644
@@ -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;

drivers/virtio/virtio_vdpa.c virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index, · line 200

Quoted 8 lines
drivers/virtio/virtio_vdpa.c +6 -0
@@ -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

Quoted 8 lines
Quoted 3 lines

drivers/virtio/virtio_vdpa.c virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index, · line 203

Quoted 2 lines
drivers/virtio/virtio_vdpa.c +2 -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.

Quoted 15 lines

Thanks

Quoted 11 lines
Quoted 11 lines
drivers/virtio/virtio_vdpa.c +5 -0
+	}
+	err = ops->set_vq_state(vdpa, index, &state);
+	if (err)
+		goto err_vq;
+
  	ops->set_vq_ready(vdpa, index, 1);
  	vq->priv = info;
Signature · 1 line
2.25.1
author
#11 lore raw
In reply to Jason Wang
Quoted 1 line · Jason Wang

*** BLURB HERE ***

Missing blurb...

Will resend a new version.

Thanks

Quoted 20 lines

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(-)