]> xenbits.xensource.com Git - people/aperard/qemu-dm.git/commitdiff
virtio-balloon: Fix wrong sign extension of PFNs
authorDavid Hildenbrand <david@redhat.com>
Mon, 22 Jul 2019 13:41:03 +0000 (15:41 +0200)
committerMichael S. Tsirkin <mst@redhat.com>
Thu, 25 Jul 2019 11:57:49 +0000 (07:57 -0400)
If we directly cast from int to uint64_t, we will first sign-extend to
an int64_t, which is wrong. We actually want to treat the PFNs like
unsigned values.

As far as I can see, this dates back to the initial virtio-balloon
commit, but wasn't triggered as fairly big guests would be required.

Cc: qemu-stable@nongnu.org
Reported-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
Message-Id: <20190722134108.22151-2-david@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
hw/virtio/virtio-balloon.c

index e85d1c0d5c5ad6fc886250530b05989fbfa7ba91..515abf655308b93ad6b4072d80a0e71504233a93 100644 (file)
@@ -343,8 +343,8 @@ static void virtio_balloon_handle_output(VirtIODevice *vdev, VirtQueue *vq)
         }
 
         while (iov_to_buf(elem->out_sg, elem->out_num, offset, &pfn, 4) == 4) {
+            unsigned int p = virtio_ldl_p(vdev, &pfn);
             hwaddr pa;
-            int p = virtio_ldl_p(vdev, &pfn);
 
             pa = (hwaddr) p << VIRTIO_BALLOON_PFN_SHIFT;
             offset += 4;