]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
virtio_balloon: fix up endian-ness for free cmd id
authorMichael S. Tsirkin <mst@redhat.com>
Mon, 27 Jul 2020 16:01:27 +0000 (12:01 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 5 Aug 2020 07:58:37 +0000 (09:58 +0200)
commit 168c358af2f8c5a37f8b5f877ba2cc93995606ee upstream.

free cmd id is read using virtio endian, spec says all fields
in balloon are LE. Fix it up.

Fixes: 86a559787e6f ("virtio-balloon: VIRTIO_BALLOON_F_FREE_PAGE_HINT")
Cc: stable@vger.kernel.org
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Acked-by: Jason Wang <jasowang@redhat.com>
Reviewed-by: Wei Wang <wei.w.wang@intel.com>
Acked-by: David Hildenbrand <david@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/virtio/virtio_balloon.c

index 1f157d2f495264f725023c41070bd228574f3c56..67b002ade3e752ec119c75acdf8b46e576488efa 100644 (file)
@@ -578,10 +578,14 @@ static int init_vqs(struct virtio_balloon *vb)
 static u32 virtio_balloon_cmd_id_received(struct virtio_balloon *vb)
 {
        if (test_and_clear_bit(VIRTIO_BALLOON_CONFIG_READ_CMD_ID,
-                              &vb->config_read_bitmap))
+                              &vb->config_read_bitmap)) {
                virtio_cread(vb->vdev, struct virtio_balloon_config,
                             free_page_hint_cmd_id,
                             &vb->cmd_id_received_cache);
+               /* Legacy balloon config space is LE, unlike all other devices. */
+               if (!virtio_has_feature(vb->vdev, VIRTIO_F_VERSION_1))
+                       vb->cmd_id_received_cache = le32_to_cpu((__force __le32)vb->cmd_id_received_cache);
+       }
 
        return vb->cmd_id_received_cache;
 }