Skip to contentSkip to conversation

vhost: fix initialization for vq->is_le

PATCH In review Halil Pasic 4 participants 9 messages Jan 30, 2017 – Feb 4, 2017

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vhost: fix initialization for vq->is_le

Currently, under certain circumstances vhost_init_is_le does just a part of the initialization job, and depends on vhost_reset_is_le being called too. For this reason vhost_vq_init_access used to call vhost_reset_is_le when vq->private_data is NULL. This is not only counter intuitive, but also real a problem because it breaks vhost_net. The bug was introduced to vhost_net with commit 2751c9882b94 ("vhost: cross-endian support for legacy devices"). The symptom is corruption of the vq's used.idx field (virtio) after VHOST_NET_SET_BACKEND was issued as a part of the vhost shutdown on a vq with pending descriptors.

Let us make sure the outcome of vhost_init_is_le never depend on the state it is actually supposed to initialize, and fix virtio_net by removing the reset from vhost_vq_init_access.

With the above, there is no reason for vhost_reset_is_le to do just half of the job. Let us make vhost_reset_is_le reinitialize is_le.

Fixes commit 2751c9882b94 ("vhost: cross-endian support for legacy devices")

---

The bug was already discussed here:
http://www.spinics.net/lists/kvm/msg144365.html
This is a follow up patch.

---
 drivers/vhost/vhost.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/vhost/vhost.c +4 -6
index d643260..8f99fe0 100644
@@ -130,14 +130,14 @@ static long vhost_get_vring_endian(struct vhost_virtqueue *vq, u32 idx,
 
 static void vhost_init_is_le(struct vhost_virtqueue *vq)
 {
-	if (vhost_has_feature(vq, VIRTIO_F_VERSION_1))
-		vq->is_le = true;
+	vq->is_le = vhost_has_feature(vq, VIRTIO_F_VERSION_1)
+		|| virtio_legacy_is_little_endian();
 }
 #endif /* CONFIG_VHOST_CROSS_ENDIAN_LEGACY */
 
 static void vhost_reset_is_le(struct vhost_virtqueue *vq)
 {
-	vq->is_le = virtio_legacy_is_little_endian();
+	vhost_init_is_le(vq);
 }
 
 struct vhost_flush_struct {
@@ -1714,10 +1714,8 @@ int vhost_vq_init_access(struct vhost_virtqueue *vq)
 	int r;
 	bool is_le = vq->is_le;
 
-	if (!vq->private_data) {
-		vhost_reset_is_le(vq);
+	if (!vq->private_data)
 		return 0;
-	}
 
 	vhost_init_is_le(vq);
 
Signature · 1 line
2.8.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 14 lines · On Mon, 30 Jan 2017 11:09:36 +0100 Halil Pasic <[email protected]> wrote:

Currently, under certain circumstances vhost_init_is_le does just a part of the initialization job, and depends on vhost_reset_is_le being called too. For this reason vhost_vq_init_access used to call vhost_reset_is_le when vq->private_data is NULL. This is not only counter intuitive, but also real a problem because it breaks vhost_net. The bug was introduced to vhost_net with commit 2751c9882b94 ("vhost: cross-endian support for legacy devices"). The symptom is corruption of the vq's used.idx field (virtio) after VHOST_NET_SET_BACKEND was issued as a part of the vhost shutdown on a vq with pending descriptors.

Let us make sure the outcome of vhost_init_is_le never depend on the state it is actually supposed to initialize, and fix virtio_net by removing the reset from vhost_vq_init_access.

Quoted 8 lines

With the above, there is no reason for vhost_reset_is_le to do just half of the job. Let us make vhost_reset_is_le reinitialize is_le.

Fixes commit 2751c9882b94 ("vhost: cross-endian support for legacy devices")

---

Quoted 43 lines

The bug was already discussed here:
http://www.spinics.net/lists/kvm/msg144365.html
This is a follow up patch.

---
 drivers/vhost/vhost.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/vhost/vhost.c +4 -6
index d643260..8f99fe0 100644
@@ -130,14 +130,14 @@ static long vhost_get_vring_endian(struct vhost_virtqueue *vq, u32 idx,
 
 static void vhost_init_is_le(struct vhost_virtqueue *vq)
 {
-	if (vhost_has_feature(vq, VIRTIO_F_VERSION_1))
-		vq->is_le = true;
+	vq->is_le = vhost_has_feature(vq, VIRTIO_F_VERSION_1)
+		|| virtio_legacy_is_little_endian();
 }
 #endif /* CONFIG_VHOST_CROSS_ENDIAN_LEGACY */
 
 static void vhost_reset_is_le(struct vhost_virtqueue *vq)
 {
-	vq->is_le = virtio_legacy_is_little_endian();
+	vhost_init_is_le(vq);
 }
 
 struct vhost_flush_struct {
@@ -1714,10 +1714,8 @@ int vhost_vq_init_access(struct vhost_virtqueue *vq)
 	int r;
 	bool is_le = vq->is_le;
 
-	if (!vq->private_data) {
-		vhost_reset_is_le(vq);
+	if (!vq->private_data)
 		return 0;
-	}
 
 	vhost_init_is_le(vq);
 
Reviewed-by on v1 1/1
#2 lore raw
In reply to Halil Pasic
Quoted 14 lines · On Mon, 30 Jan 2017 11:09:36 +0100 Halil Pasic <[email protected]> wrote:

Currently, under certain circumstances vhost_init_is_le does just a part of the initialization job, and depends on vhost_reset_is_le being called too. For this reason vhost_vq_init_access used to call vhost_reset_is_le when vq->private_data is NULL. This is not only counter intuitive, but also real a problem because it breaks vhost_net. The bug was introduced to vhost_net with commit 2751c9882b94 ("vhost: cross-endian support for legacy devices"). The symptom is corruption of the vq's used.idx field (virtio) after VHOST_NET_SET_BACKEND was issued as a part of the vhost shutdown on a vq with pending descriptors.

Let us make sure the outcome of vhost_init_is_le never depend on the state it is actually supposed to initialize, and fix virtio_net by removing the reset from vhost_vq_init_access.

Quoted 8 lines

With the above, there is no reason for vhost_reset_is_le to do just half of the job. Let us make vhost_reset_is_le reinitialize is_le.

Fixes commit 2751c9882b94 ("vhost: cross-endian support for legacy devices")

---

Quoted 43 lines

The bug was already discussed here:
http://www.spinics.net/lists/kvm/msg144365.html
This is a follow up patch.

---
 drivers/vhost/vhost.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/vhost/vhost.c +4 -6
index d643260..8f99fe0 100644
@@ -130,14 +130,14 @@ static long vhost_get_vring_endian(struct vhost_virtqueue *vq, u32 idx,
 
 static void vhost_init_is_le(struct vhost_virtqueue *vq)
 {
-	if (vhost_has_feature(vq, VIRTIO_F_VERSION_1))
-		vq->is_le = true;
+	vq->is_le = vhost_has_feature(vq, VIRTIO_F_VERSION_1)
+		|| virtio_legacy_is_little_endian();
 }
 #endif /* CONFIG_VHOST_CROSS_ENDIAN_LEGACY */
 
 static void vhost_reset_is_le(struct vhost_virtqueue *vq)
 {
-	vq->is_le = virtio_legacy_is_little_endian();
+	vhost_init_is_le(vq);
 }
 
 struct vhost_flush_struct {
@@ -1714,10 +1714,8 @@ int vhost_vq_init_access(struct vhost_virtqueue *vq)
 	int r;
 	bool is_le = vq->is_le;
 
-	if (!vq->private_data) {
-		vhost_reset_is_le(vq);
+	if (!vq->private_data)
 		return 0;
-	}
 
 	vhost_init_is_le(vq);
 
#3 lore raw
Quoted 17 lines · Greg Kurz
Quoted 17 lines

Currently, under certain circumstances vhost_init_is_le does just a part of the initialization job, and depends on vhost_reset_is_le being called too. For this reason vhost_vq_init_access used to call vhost_reset_is_le when vq->private_data is NULL. This is not only counter intuitive, but also real a problem because it breaks vhost_net. The bug was introduced to vhost_net with commit 2751c9882b94 ("vhost: cross-endian support for legacy devices"). The symptom is corruption of the vq's used.idx field (virtio) after VHOST_NET_SET_BACKEND was issued as a part of the vhost shutdown on a vq with pending descriptors.

Let us make sure the outcome of vhost_init_is_le never depend on the state it is actually supposed to initialize, and fix virtio_net by removing the reset from vhost_vq_init_access.

With the above, there is no reason for vhost_reset_is_le to do just half of the job. Let us make vhost_reset_is_le reinitialize is_le.

Quoted 7 lines
Quoted 5 lines
Fixes commit 2751c9882b94 ("vhost: cross-endian support for legacy devices")

---

Thanks!

We have some tests on s390x (that is BE) running, but I won't be able to test the change with cross endian and legacy.

What do you think, should I/we RFT or are we fine without?

Regards,
Halil

#4 lore raw
Quoted 30 lines · Halil Pasic
Quoted 17 lines · Greg Kurz
Quoted 17 lines

Currently, under certain circumstances vhost_init_is_le does just a part of the initialization job, and depends on vhost_reset_is_le being called too. For this reason vhost_vq_init_access used to call vhost_reset_is_le when vq->private_data is NULL. This is not only counter intuitive, but also real a problem because it breaks vhost_net. The bug was introduced to vhost_net with commit 2751c9882b94 ("vhost: cross-endian support for legacy devices"). The symptom is corruption of the vq's used.idx field (virtio) after VHOST_NET_SET_BACKEND was issued as a part of the vhost shutdown on a vq with pending descriptors.

Let us make sure the outcome of vhost_init_is_le never depend on the state it is actually supposed to initialize, and fix virtio_net by removing the reset from vhost_vq_init_access.

With the above, there is no reason for vhost_reset_is_le to do just half of the job. Let us make vhost_reset_is_le reinitialize is_le.

Quoted 7 lines
Quoted 5 lines
Fixes commit 2751c9882b94 ("vhost: cross-endian support for legacy devices")

---

Thanks!

Quoted 7 lines

We have some tests on s390x (that is BE) running, but I won't be able to test the change with cross endian and legacy.

What do you think, should I/we RFT or are we fine without?

Regards,
Halil

More testing can't hurt. I can merge this meanwhile.

Signature · 1 line
MST
author Tested-by Michael A. Tebolt
#5 lore raw
Quoted 34 lines · Michael S. Tsirkin
Quoted 33 lines · Halil Pasic
Quoted 17 lines · Greg Kurz
Quoted 17 lines

Currently, under certain circumstances vhost_init_is_le does just a part of the initialization job, and depends on vhost_reset_is_le being called too. For this reason vhost_vq_init_access used to call vhost_reset_is_le when vq->private_data is NULL. This is not only counter intuitive, but also real a problem because it breaks vhost_net. The bug was introduced to vhost_net with commit 2751c9882b94 ("vhost: cross-endian support for legacy devices"). The symptom is corruption of the vq's used.idx field (virtio) after VHOST_NET_SET_BACKEND was issued as a part of the vhost shutdown on a vq with pending descriptors.

Let us make sure the outcome of vhost_init_is_le never depend on the state it is actually supposed to initialize, and fix virtio_net by removing the reset from vhost_vq_init_access.

With the above, there is no reason for vhost_reset_is_le to do just half of the job. Let us make vhost_reset_is_le reinitialize is_le.

Quoted 7 lines
Quoted 5 lines
Fixes commit 2751c9882b94 ("vhost: cross-endian support for legacy devices")

---

Thanks!

We have some tests on s390x (that is BE) running, but I won't be able to test the change with cross endian and legacy.

Quoted 7 lines
Quoted 4 lines

What do you think, should I/we RFT or are we fine without?

Regards,
Halil

More testing can't hurt. I can merge this meanwhile.

I received a word from our test team. No problems discovered with
a mix of legacy and virtio 1 guests on s390x (was reliably
reproducible without this patch with the same setup). Could you please add:

Regards,
Halil

#6 lore raw
In reply to Halil Pasic
Quoted 23 lines · On Tue, 31 Jan 2017 16:56:13 +0100 Halil Pasic <[email protected]> wrote:
Quoted 22 lines · Greg Kurz
Quoted 22 lines

Currently, under certain circumstances vhost_init_is_le does just a part of the initialization job, and depends on vhost_reset_is_le being called too. For this reason vhost_vq_init_access used to call vhost_reset_is_le when vq->private_data is NULL. This is not only counter intuitive, but also real a problem because it breaks vhost_net. The bug was introduced to vhost_net with commit 2751c9882b94 ("vhost: cross-endian support for legacy devices"). The symptom is corruption of the vq's used.idx field (virtio) after VHOST_NET_SET_BACKEND was issued as a part of the vhost shutdown on a vq with pending descriptors.

Let us make sure the outcome of vhost_init_is_le never depend on the state it is actually supposed to initialize, and fix virtio_net by removing the reset from vhost_vq_init_access.

With the above, there is no reason for vhost_reset_is_le to do just half of the job. Let us make vhost_reset_is_le reinitialize is_le.

Fixes commit 2751c9882b94 ("vhost: cross-endian support for legacy devices")

---

Quoted 8 lines
Quoted 2 lines

Thanks!

We have some tests on s390x (that is BE) running, but I won't be able to test the change with cross endian and legacy.

I'll try to find some time to run such tests on ppc.

Cheers.

--
Greg

Quoted 5 lines

What do you think, should I/we RFT or are we fine without?

Regards,
Halil

#7 lore raw
In reply to Halil Pasic
Quoted 23 lines · On Tue, 31 Jan 2017 16:56:13 +0100 Halil Pasic <[email protected]> wrote:
Quoted 22 lines · Greg Kurz
Quoted 22 lines

Currently, under certain circumstances vhost_init_is_le does just a part of the initialization job, and depends on vhost_reset_is_le being called too. For this reason vhost_vq_init_access used to call vhost_reset_is_le when vq->private_data is NULL. This is not only counter intuitive, but also real a problem because it breaks vhost_net. The bug was introduced to vhost_net with commit 2751c9882b94 ("vhost: cross-endian support for legacy devices"). The symptom is corruption of the vq's used.idx field (virtio) after VHOST_NET_SET_BACKEND was issued as a part of the vhost shutdown on a vq with pending descriptors.

Let us make sure the outcome of vhost_init_is_le never depend on the state it is actually supposed to initialize, and fix virtio_net by removing the reset from vhost_vq_init_access.

With the above, there is no reason for vhost_reset_is_le to do just half of the job. Let us make vhost_reset_is_le reinitialize is_le.

Fixes commit 2751c9882b94 ("vhost: cross-endian support for legacy devices")

---

Quoted 8 lines
Quoted 2 lines

Thanks!

We have some tests on s390x (that is BE) running, but I won't be able to test the change with cross endian and legacy.

I'll try to find some time to run such tests on ppc.

Cheers.

--
Greg

Quoted 5 lines

What do you think, should I/we RFT or are we fine without?

Regards,
Halil

Acked-by on v1 1/1
#8 lore raw
In reply to Halil Pasic
Quoted 55 lines · Halil Pasic

Currently, under certain circumstances vhost_init_is_le does just a part of the initialization job, and depends on vhost_reset_is_le being called too. For this reason vhost_vq_init_access used to call vhost_reset_is_le when vq->private_data is NULL. This is not only counter intuitive, but also real a problem because it breaks vhost_net. The bug was introduced to vhost_net with commit 2751c9882b94 ("vhost: cross-endian support for legacy devices"). The symptom is corruption of the vq's used.idx field (virtio) after VHOST_NET_SET_BACKEND was issued as a part of the vhost shutdown on a vq with pending descriptors.

Let us make sure the outcome of vhost_init_is_le never depend on the state it is actually supposed to initialize, and fix virtio_net by removing the reset from vhost_vq_init_access.

With the above, there is no reason for vhost_reset_is_le to do just half of the job. Let us make vhost_reset_is_le reinitialize is_le.

Fixes commit 2751c9882b94 ("vhost: cross-endian support for legacy devices")

---

The bug was already discussed here:
http://www.spinics.net/lists/kvm/msg144365.html
This is a follow up patch.

---
  drivers/vhost/vhost.c | 10 ++++------
  1 file changed, 4 insertions(+), 6 deletions(-)
drivers/vhost/vhost.c +3 -3
index d643260..8f99fe0 100644
@@ -130,14 +130,14 @@ static long vhost_get_vring_endian(struct vhost_virtqueue *vq, u32 idx,
 
  static void vhost_init_is_le(struct vhost_virtqueue *vq)
  {
-	if (vhost_has_feature(vq, VIRTIO_F_VERSION_1))
-		vq->is_le = true;
+	vq->is_le = vhost_has_feature(vq, VIRTIO_F_VERSION_1)
+		|| virtio_legacy_is_little_endian();
  }
  #endif /* CONFIG_VHOST_CROSS_ENDIAN_LEGACY */
 
  static void vhost_reset_is_le(struct vhost_virtqueue *vq)
  {
-	vq->is_le = virtio_legacy_is_little_endian();
+	vhost_init_is_le(vq);
  }
 
  struct vhost_flush_struct {
@@ -1714,10 +1714,8 @@ int vhost_vq_init_access(struct vhost_virtqueue *vq)
  	int r;

drivers/vhost/vhost.c int vhost_vq_init_access(struct vhost_virtqueue *vq) · line 1721

Quoted 10 lines
drivers/vhost/vhost.c +1 -3
  	bool is_le = vq->is_le;
 
-	if (!vq->private_data) {
-		vhost_reset_is_le(vq);
+	if (!vq->private_data)
  		return 0;
-	}
 
  	vhost_init_is_le(vq);
 

We can probably just drop vhost_reset_is_le() and just use vhost_init_is_le() instead.

Thanks
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization