diff options
author | Halil Pasic <pasic@linux.vnet.ibm.com> | 2017-01-30 05:09:36 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2017-02-09 02:08:28 -0500 |
commit | 1594edd9ea0d75ef106bffc23c2b07b509f3301c (patch) | |
tree | ec2760fe2cc9bbc64112b8aa4ece1d45a57f5efd | |
parent | 04eb7db25bb1bcf4ee1631d1099fc03308929c12 (diff) |
vhost: fix initialization for vq->is_le
commit cda8bba0f99d25d2061c531113c14fa41effc3ae upstream.
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.
Signed-off-by: Halil Pasic <pasic@linux.vnet.ibm.com>
Reported-by: Michael A. Tebolt <miket@us.ibm.com>
Reported-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Fixes: commit 2751c9882b94 ("vhost: cross-endian support for legacy devices")
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Greg Kurz <groug@kaod.org>
Tested-by: Michael A. Tebolt <miket@us.ibm.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/vhost/vhost.c | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index c6f2d89c0e97..64613fbf5cf8 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c | |||
@@ -130,14 +130,14 @@ static long vhost_get_vring_endian(struct vhost_virtqueue *vq, u32 idx, | |||
130 | 130 | ||
131 | static void vhost_init_is_le(struct vhost_virtqueue *vq) | 131 | static void vhost_init_is_le(struct vhost_virtqueue *vq) |
132 | { | 132 | { |
133 | if (vhost_has_feature(vq, VIRTIO_F_VERSION_1)) | 133 | vq->is_le = vhost_has_feature(vq, VIRTIO_F_VERSION_1) |
134 | vq->is_le = true; | 134 | || virtio_legacy_is_little_endian(); |
135 | } | 135 | } |
136 | #endif /* CONFIG_VHOST_CROSS_ENDIAN_LEGACY */ | 136 | #endif /* CONFIG_VHOST_CROSS_ENDIAN_LEGACY */ |
137 | 137 | ||
138 | static void vhost_reset_is_le(struct vhost_virtqueue *vq) | 138 | static void vhost_reset_is_le(struct vhost_virtqueue *vq) |
139 | { | 139 | { |
140 | vq->is_le = virtio_legacy_is_little_endian(); | 140 | vhost_init_is_le(vq); |
141 | } | 141 | } |
142 | 142 | ||
143 | struct vhost_flush_struct { | 143 | struct vhost_flush_struct { |
@@ -1713,10 +1713,8 @@ int vhost_vq_init_access(struct vhost_virtqueue *vq) | |||
1713 | int r; | 1713 | int r; |
1714 | bool is_le = vq->is_le; | 1714 | bool is_le = vq->is_le; |
1715 | 1715 | ||
1716 | if (!vq->private_data) { | 1716 | if (!vq->private_data) |
1717 | vhost_reset_is_le(vq); | ||
1718 | return 0; | 1717 | return 0; |
1719 | } | ||
1720 | 1718 | ||
1721 | vhost_init_is_le(vq); | 1719 | vhost_init_is_le(vq); |
1722 | 1720 | ||