Skip to content

Commit cda8bba

Browse files
Halil Pasicmstsirkin
authored andcommitted
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 2751c98 ("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. Signed-off-by: Halil Pasic <[email protected]> Reported-by: Michael A. Tebolt <[email protected]> Reported-by: Dr. David Alan Gilbert <[email protected]> Fixes: commit 2751c98 ("vhost: cross-endian support for legacy devices") Cc: <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]> Reviewed-by: Greg Kurz <[email protected]> Tested-by: Michael A. Tebolt <[email protected]>
1 parent 0d5415b commit cda8bba

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

drivers/vhost/vhost.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,14 @@ static long vhost_get_vring_endian(struct vhost_virtqueue *vq, u32 idx,
130130

131131
static void vhost_init_is_le(struct vhost_virtqueue *vq)
132132
{
133-
if (vhost_has_feature(vq, VIRTIO_F_VERSION_1))
134-
vq->is_le = true;
133+
vq->is_le = vhost_has_feature(vq, VIRTIO_F_VERSION_1)
134+
|| virtio_legacy_is_little_endian();
135135
}
136136
#endif /* CONFIG_VHOST_CROSS_ENDIAN_LEGACY */
137137

138138
static void vhost_reset_is_le(struct vhost_virtqueue *vq)
139139
{
140-
vq->is_le = virtio_legacy_is_little_endian();
140+
vhost_init_is_le(vq);
141141
}
142142

143143
struct vhost_flush_struct {
@@ -1714,10 +1714,8 @@ int vhost_vq_init_access(struct vhost_virtqueue *vq)
17141714
int r;
17151715
bool is_le = vq->is_le;
17161716

1717-
if (!vq->private_data) {
1718-
vhost_reset_is_le(vq);
1717+
if (!vq->private_data)
17191718
return 0;
1720-
}
17211719

17221720
vhost_init_is_le(vq);
17231721

0 commit comments

Comments
 (0)