[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[qemu-xen staging-4.14] virtio-balloon: Add locking to prevent possible race when starting hinting



commit 7eb63fccf4cc533249bde484daba6e40264d74f9
Author:     Alexander Duyck <alexander.h.duyck@xxxxxxxxxxxxxxx>
AuthorDate: Mon Jul 20 10:51:22 2020 -0700
Commit:     Michael Roth <mdroth@xxxxxxxxxxxxxxxxxx>
CommitDate: Wed Sep 2 19:06:19 2020 -0500

    virtio-balloon: Add locking to prevent possible race when starting hinting
    
    There is already locking in place when we are stopping free page hinting
    but there is not similar protections in place when we start. I can only
    assume this was overlooked as in most cases the page hinting should not be
    occurring when we are starting the hinting, however there is still a chance
    we could be processing hints by the time we get back around to restarting
    the hinting so we are better off making sure to protect the state with the
    mutex lock rather than just updating the value with no protections.
    
    Based on feedback from Peter Maydell this issue had also been spotted by
    Coverity: CID 1430269
    
    Acked-by: David Hildenbrand <david@xxxxxxxxxx>
    Signed-off-by: Alexander Duyck <alexander.h.duyck@xxxxxxxxxxxxxxx>
    Message-Id: <20200720175122.21935.78013.stgit@localhost.localdomain>
    Cc: qemu-stable@xxxxxxxxxx
    Reviewed-by: Michael S. Tsirkin <mst@xxxxxxxxxx>
    Signed-off-by: Michael S. Tsirkin <mst@xxxxxxxxxx>
    (cherry picked from commit 1a83e0b9c492a0eaeacd6fbb858fc81d04ab9c3e)
    Signed-off-by: Michael Roth <mdroth@xxxxxxxxxxxxxxxxxx>
---
 hw/virtio/virtio-balloon.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c
index a30a0c7bfa..d6e31de1d9 100644
--- a/hw/virtio/virtio-balloon.c
+++ b/hw/virtio/virtio-balloon.c
@@ -532,6 +532,8 @@ static void virtio_balloon_free_page_start(VirtIOBalloon *s)
         return;
     }
 
+    qemu_mutex_lock(&s->free_page_lock);
+
     if (s->free_page_report_cmd_id == UINT_MAX) {
         s->free_page_report_cmd_id =
                        VIRTIO_BALLOON_FREE_PAGE_REPORT_CMD_ID_MIN;
@@ -540,6 +542,8 @@ static void virtio_balloon_free_page_start(VirtIOBalloon *s)
     }
 
     s->free_page_report_status = FREE_PAGE_REPORT_S_REQUESTED;
+    qemu_mutex_unlock(&s->free_page_lock);
+
     virtio_notify_config(vdev);
 }
 
--
generated by git-patchbot for /home/xen/git/qemu-xen.git#staging-4.14



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.