Skip to content
Snippets Groups Projects
Commit 1a83e0b9 authored by Alexander Duyck's avatar Alexander Duyck Committed by Michael S. Tsirkin
Browse files

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: default avatarDavid Hildenbrand <david@redhat.com>
Signed-off-by: default avatarAlexander Duyck <alexander.h.duyck@linux.intel.com>
Message-Id: <20200720175122.21935.78013.stgit@localhost.localdomain>
Cc: qemu-stable@nongnu.org
Reviewed-by: default avatarMichael S. Tsirkin <mst@redhat.com>
Signed-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
parent 20a4da0f
No related branches found
No related tags found
No related merge requests found
......@@ -592,6 +592,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;
......@@ -600,6 +602,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);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment