aboutsummaryrefslogtreecommitdiff
path: root/blockjob.c
diff options
context:
space:
mode:
authorJeff Cody <jcody@redhat.com>2017-11-17 22:26:16 -0500
committerJeff Cody <jcody@redhat.com>2017-11-21 11:51:18 -0500
commit4afeffc8572f40d8844b946a30c00b10da4442b1 (patch)
treef877425b21bc20e94e3560a3036ebe15be460a7a /blockjob.c
parent7c3d1917fd7a3de906170fa3d6d3d4c5918b1e49 (diff)
downloadqemu-4afeffc8572f40d8844b946a30c00b10da4442b1.zip
qemu-4afeffc8572f40d8844b946a30c00b10da4442b1.tar.gz
qemu-4afeffc8572f40d8844b946a30c00b10da4442b1.tar.bz2
blockjob: do not allow coroutine double entry or entry-after-completion
When block_job_sleep_ns() is called, the co-routine is scheduled for future execution. If we allow the job to be re-entered prior to the scheduled time, we present a race condition in which a coroutine can be entered recursively, or even entered after the coroutine is deleted. The job->busy flag is used by blockjobs when a coroutine is busy executing. The function 'block_job_enter()' obeys the busy flag, and will not enter a coroutine if set. If we sleep a job, we need to leave the busy flag set, so that subsequent calls to block_job_enter() are prevented. This changes the prior behavior of block_job_cancel() being able to immediately wake up and cancel a job; in practice, this should not be an issue, as the coroutine sleep times are generally very small, and the cancel will occur the next time the coroutine wakes up. This fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1508708 Signed-off-by: Jeff Cody <jcody@redhat.com> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Diffstat (limited to 'blockjob.c')
-rw-r--r--blockjob.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/blockjob.c b/blockjob.c
index 3a0c491..ff9a614 100644
--- a/blockjob.c
+++ b/blockjob.c
@@ -797,11 +797,14 @@ void block_job_sleep_ns(BlockJob *job, QEMUClockType type, int64_t ns)
return;
}
- job->busy = false;
+ /* We need to leave job->busy set here, because when we have
+ * put a coroutine to 'sleep', we have scheduled it to run in
+ * the future. We cannot enter that same coroutine again before
+ * it wakes and runs, otherwise we risk double-entry or entry after
+ * completion. */
if (!block_job_should_pause(job)) {
co_aio_sleep_ns(blk_get_aio_context(job->blk), type, ns);
}
- job->busy = true;
block_job_pause_point(job);
}